use of com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver in project sulong by graalvm.
the class LazyToTruffleConverterImpl method convert.
@Override
public RootCallTarget convert() {
CompilerAsserts.neverPartOfCompilation();
// parse the function block
parser.parse(diProcessor, source);
// prepare the phis
final Map<InstructionBlock, List<Phi>> phis = LLVMPhiManager.getPhis(method);
// setup the frameDescriptor
final FrameDescriptor frame = StackManager.createFrame(method);
LLVMLivenessAnalysisResult liveness = LLVMLivenessAnalysis.computeLiveness(frame, context, phis, method);
LLVMSymbolReadResolver symbols = new LLVMSymbolReadResolver(runtime, frame);
List<FrameSlot> notNullable = new ArrayList<>();
LLVMRuntimeDebugInformation dbgInfoHandler = new LLVMRuntimeDebugInformation(frame, nodeFactory, context, notNullable, symbols, runtime);
dbgInfoHandler.registerStaticDebugSymbols(method);
LLVMBitcodeFunctionVisitor visitor = new LLVMBitcodeFunctionVisitor(runtime, frame, phis, nodeFactory, method.getParameters().size(), symbols, method, liveness, notNullable, dbgInfoHandler);
method.accept(visitor);
FrameSlot[][] nullableBeforeBlock = getNullableFrameSlots(frame, liveness.getNullableBeforeBlock(), notNullable);
FrameSlot[][] nullableAfterBlock = getNullableFrameSlots(frame, liveness.getNullableAfterBlock(), notNullable);
LLVMSourceLocation location = method.getLexicalScope();
List<LLVMExpressionNode> copyArgumentsToFrame = copyArgumentsToFrame(frame);
LLVMExpressionNode[] copyArgumentsToFrameArray = copyArgumentsToFrame.toArray(new LLVMExpressionNode[copyArgumentsToFrame.size()]);
LLVMExpressionNode body = nodeFactory.createFunctionBlockNode(runtime, frame.findFrameSlot(LLVMException.FRAME_SLOT_ID), visitor.getBlocks(), nullableBeforeBlock, nullableAfterBlock, location, copyArgumentsToFrameArray);
RootNode rootNode = nodeFactory.createFunctionStartNode(runtime, body, method.getSourceSection(), frame, method, source, location);
return Truffle.getRuntime().createCallTarget(rootNode);
}
use of com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver in project sulong by graalvm.
the class LLVMParserRuntime method parse.
public static LLVMParserResult parse(Source source, ExternalLibrary library, BitcodeParserResult parserResult, LLVMLanguage language, LLVMContext context, NodeFactory nodeFactory) {
ModelModule model = parserResult.getModel();
TargetDataLayout layout = model.getTargetDataLayout();
assert layout != null;
LLVMModelVisitor module = new LLVMModelVisitor();
model.accept(module);
DataLayoutConverter.DataSpecConverterImpl targetDataLayout = DataLayoutConverter.getConverter(layout.getDataLayout());
context.setDataLayoutConverter(targetDataLayout);
LLVMParserRuntime runtime = new LLVMParserRuntime(source, library, language, context, nodeFactory, module.getAliases());
runtime.registerFunctions(model);
LLVMSymbolReadResolver symbolResolver = new LLVMSymbolReadResolver(runtime, runtime.getGlobalFrameDescriptor());
LLVMExpressionNode[] globals = runtime.createGlobalVariableInitializationNodes(symbolResolver, module.getGlobals());
RootNode globalVarInits = nodeFactory.createStaticInitsRootNode(runtime, globals);
RootCallTarget globalVarInitsTarget = Truffle.getRuntime().createCallTarget(globalVarInits);
LLVMExpressionNode[] deallocs = runtime.getDeallocations();
RootNode globalVarDeallocs = nodeFactory.createStaticInitsRootNode(runtime, deallocs);
RootCallTarget globalVarDeallocsTarget = Truffle.getRuntime().createCallTarget(globalVarDeallocs);
RootCallTarget constructorFunctions = runtime.getConstructors(module.getGlobals());
RootCallTarget destructorFunctions = runtime.getDestructors(module.getGlobals());
if (context.getEnv().getOptions().get(SulongEngineOption.ENABLE_LVI)) {
final LLVMSourceContext sourceContext = context.getSourceContext();
model.getSourceGlobals().forEach((symbol, irValue) -> {
final LLVMExpressionNode node = symbolResolver.resolve(irValue);
final LLVMDebugValue value = nodeFactory.createDebugStaticValue(node);
sourceContext.registerStatic(symbol, value);
});
model.getSourceStaticMembers().forEach(((type, symbol) -> {
final LLVMExpressionNode node = symbolResolver.resolve(symbol);
final LLVMDebugValue value = nodeFactory.createDebugStaticValue(node);
type.setValue(value);
}));
}
RootCallTarget mainFunctionCallTarget = null;
if (runtime.getScope().functionExists("@main")) {
LLVMFunctionDescriptor mainDescriptor = runtime.getScope().getFunctionDescriptor("@main");
LLVMFunctionDescriptor startDescriptor = runtime.getScope().getFunctionDescriptor("@_start");
RootCallTarget startCallTarget = startDescriptor.getLLVMIRFunction();
String applicationPath = source.getPath() == null ? "" : source.getPath().toString();
RootNode globalFunction = nodeFactory.createGlobalRootNode(runtime, startCallTarget, mainDescriptor, applicationPath);
RootCallTarget globalFunctionRoot = Truffle.getRuntime().createCallTarget(globalFunction);
RootNode globalRootNode = nodeFactory.createGlobalRootNodeWrapping(runtime, globalFunctionRoot, startDescriptor.getType().getReturnType());
mainFunctionCallTarget = Truffle.getRuntime().createCallTarget(globalRootNode);
}
return new LLVMParserResult(runtime.getScope(), mainFunctionCallTarget, globalVarInitsTarget, globalVarDeallocsTarget, constructorFunctions, destructorFunctions);
}
Aggregations