use of com.oracle.truffle.llvm.runtime.types.Type in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(InsertElementInstruction insert) {
final LLVMExpressionNode vector = symbols.resolve(insert.getVector());
final LLVMExpressionNode index = symbols.resolve(insert.getIndex());
final LLVMExpressionNode element = symbols.resolve(insert.getValue());
final Type type = insert.getType();
final LLVMExpressionNode result = nodeFactory.createInsertElement(runtime, type, vector, element, index);
createFrameWrite(result, insert);
}
use of com.oracle.truffle.llvm.runtime.types.Type in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(VoidInvokeInstruction call) {
final SymbolImpl target = call.getCallTarget();
// stackpointer
final int argumentCount = call.getArgumentCount() + 1;
final LLVMExpressionNode[] args = new LLVMExpressionNode[argumentCount];
final Type[] argsType = new Type[argumentCount];
int argIndex = 0;
args[argIndex] = nodeFactory.createFrameRead(runtime, PointerType.VOID, getStackSlot());
argsType[argIndex] = new PointerType(null);
argIndex++;
for (int i = 0; i < call.getArgumentCount(); i++) {
args[argIndex] = symbols.resolve(call.getArgument(i));
argsType[argIndex] = call.getArgument(i).getType();
final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
if (isByValue(paramAttr)) {
args[argIndex] = capsuleAddressByValue(args[argIndex], argsType[argIndex], paramAttr);
}
argIndex++;
}
int regularIndex = call.normalSuccessor().getBlockIndex();
int unwindIndex = call.unwindSuccessor().getBlockIndex();
List<FrameSlot> normalTo = new ArrayList<>();
List<FrameSlot> unwindTo = new ArrayList<>();
List<Type> normalType = new ArrayList<>();
List<Type> unwindType = new ArrayList<>();
List<LLVMExpressionNode> normalValue = new ArrayList<>();
List<LLVMExpressionNode> unwindValue = new ArrayList<>();
if (blockPhis != null) {
for (Phi phi : blockPhis) {
FrameSlot slot = getSlot(phi.getPhiValue().getName());
LLVMExpressionNode value = symbols.resolve(phi.getValue());
if (call.normalSuccessor() == phi.getBlock()) {
normalTo.add(slot);
normalType.add(phi.getValue().getType());
normalValue.add(value);
} else {
unwindTo.add(slot);
unwindType.add(phi.getValue().getType());
unwindValue.add(value);
}
}
}
LLVMExpressionNode normalPhi = nodeFactory.createPhi(runtime, normalValue.toArray(new LLVMExpressionNode[normalValue.size()]), normalTo.toArray(new FrameSlot[normalTo.size()]), normalType.toArray(Type.EMPTY_ARRAY));
LLVMExpressionNode unwindPhi = nodeFactory.createPhi(runtime, unwindValue.toArray(new LLVMExpressionNode[unwindValue.size()]), unwindTo.toArray(new FrameSlot[unwindTo.size()]), unwindType.toArray(Type.EMPTY_ARRAY));
final LLVMSourceLocation source = sourceFunction.getSourceLocation(call);
LLVMExpressionNode function = nodeFactory.createLLVMBuiltin(runtime, target, args, argCount, null);
if (function == null) {
function = symbols.resolve(target);
}
LLVMControlFlowNode result = nodeFactory.createFunctionInvoke(runtime, null, function, args, new FunctionType(call.getType(), argsType, false), regularIndex, unwindIndex, normalPhi, unwindPhi, source);
setControlFlowNode(result);
}
use of com.oracle.truffle.llvm.runtime.types.Type 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);
}
use of com.oracle.truffle.llvm.runtime.types.Type in project sulong by graalvm.
the class LLVMParserRuntime method createGlobalInitialization.
private LLVMExpressionNode createGlobalInitialization(LLVMSymbolReadResolver symbolResolver, GlobalValueSymbol global) {
if (global == null || global.getValue() == null) {
return null;
}
LLVMExpressionNode constant = symbolResolver.resolve(global.getValue());
if (constant != null) {
final Type type = ((PointerType) global.getType()).getPointeeType();
final int size = getContext().getByteSize(type);
final LLVMExpressionNode globalVarAddress = getGlobalVariable(symbolResolver, global);
if (size != 0) {
final LLVMExpressionNode store;
if (type instanceof ArrayType || type instanceof StructureType) {
store = nodeFactory.createStore(this, globalVarAddress, constant, type, null);
} else {
final Type t = global.getValue().getType();
store = nodeFactory.createStore(this, globalVarAddress, constant, t, null);
}
return store;
}
}
return null;
}
use of com.oracle.truffle.llvm.runtime.types.Type in project sulong by graalvm.
the class LazyToTruffleConverterImpl method copyArgumentsToFrame.
private List<LLVMExpressionNode> copyArgumentsToFrame(FrameDescriptor frame) {
List<FunctionParameter> parameters = method.getParameters();
List<LLVMExpressionNode> formalParamInits = new ArrayList<>();
LLVMExpressionNode stackPointerNode = nodeFactory.createFunctionArgNode(0, PrimitiveType.I64);
formalParamInits.add(nodeFactory.createFrameWrite(runtime, PointerType.VOID, stackPointerNode, frame.findFrameSlot(LLVMStack.FRAME_ID), null));
int argIndex = 1;
if (method.getType().getReturnType() instanceof StructureType) {
argIndex++;
}
for (FunctionParameter parameter : parameters) {
LLVMExpressionNode parameterNode = nodeFactory.createFunctionArgNode(argIndex++, parameter.getType());
FrameSlot slot = frame.findFrameSlot(parameter.getName());
if (isStructByValue(parameter)) {
Type type = ((PointerType) parameter.getType()).getPointeeType();
formalParamInits.add(nodeFactory.createFrameWrite(runtime, parameter.getType(), nodeFactory.createCopyStructByValue(runtime, type, parameterNode), slot, null));
} else {
formalParamInits.add(nodeFactory.createFrameWrite(runtime, parameter.getType(), parameterNode, slot, null));
}
}
return formalParamInits;
}
Aggregations