use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(InvokeInstruction call) {
final Type targetType = call.getType();
int argumentCount = getArgumentCount(call.getArgumentCount(), targetType);
final LLVMExpressionNode[] argNodes = new LLVMExpressionNode[argumentCount];
final Type[] argTypes = new Type[argumentCount];
int argIndex = 0;
argNodes[argIndex] = nodeFactory.createFrameRead(runtime, PointerType.VOID, getStackSlot());
argTypes[argIndex] = new PointerType(null);
argIndex++;
if (targetType instanceof StructureType) {
argTypes[argIndex] = new PointerType(targetType);
argNodes[argIndex] = nodeFactory.createAlloca(runtime, targetType);
argIndex++;
}
for (int i = 0; argIndex < argumentCount; i++, argIndex++) {
argNodes[argIndex] = symbols.resolve(call.getArgument(i));
argTypes[argIndex] = call.getArgument(i).getType();
final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
if (isByValue(paramAttr)) {
argNodes[argIndex] = capsuleAddressByValue(argNodes[argIndex], argTypes[argIndex], paramAttr);
}
}
final SymbolImpl target = call.getCallTarget();
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, argNodes, argCount, null);
if (function == null) {
function = symbols.resolve(target);
}
LLVMControlFlowNode result = nodeFactory.createFunctionInvoke(runtime, getSlot(call.getName()), function, argNodes, new FunctionType(targetType, argTypes, false), regularIndex, unwindIndex, normalPhi, unwindPhi, source);
setControlFlowNode(result);
}
use of com.oracle.truffle.api.frame.FrameSlot in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visitDebugIntrinsic.
private void visitDebugIntrinsic(SymbolImpl value, SourceVariable variable, MDExpression expression, long index, boolean isDeclaration) {
FrameSlot valueSlot = null;
if (value instanceof ValueInstruction) {
valueSlot = frame.findFrameSlot(((ValueInstruction) value).getName());
} else if (value instanceof FunctionParameter) {
valueSlot = frame.findFrameSlot(((FunctionParameter) value).getName());
}
if (valueSlot != null) {
final LLVMExpressionNode typeNode = nodeFactory.registerSourceType(valueSlot, variable.getSourceType());
if (typeNode != null) {
addInstructionUnchecked(typeNode);
}
}
final LLVMExpressionNode dbgIntrinsic = dbgInfoHandler.handleDebugIntrinsic(value, variable, expression, index, isDeclaration);
if (dbgIntrinsic != null) {
addInstructionUnchecked(dbgIntrinsic);
}
handleNullerInfo();
}
use of com.oracle.truffle.api.frame.FrameSlot 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.api.frame.FrameSlot in project TrufflePascal by Aspect26.
the class LexicalScope method createInitializationNode.
private StatementNode createInitializationNode(String identifier, TypeDescriptor typeDescriptor, VirtualFrame frame) {
Object defaultValue = typeDescriptor.getDefaultValue();
if (defaultValue == null) {
return null;
}
FrameSlot frameSlot = this.localIdentifiers.getFrameSlot(identifier);
return InitializationNodeFactory.create(frameSlot, typeDescriptor.getDefaultValue(), frame);
}
use of com.oracle.truffle.api.frame.FrameSlot in project TrufflePascal by Aspect26.
the class NodeFactory method createSimpleAssignment.
private StatementNode createSimpleAssignment(Token identifierToken, ExpressionNode valueNode) {
String variableIdentifier = this.getIdentifierFromToken(identifierToken);
FrameSlot frameSlot = this.doLookup(variableIdentifier, LexicalScope::getLocalSlot, true);
TypeDescriptor targetType = this.doLookup(variableIdentifier, LexicalScope::getIdentifierDescriptor, true);
this.checkTypesAreCompatible(valueNode.getType(), targetType);
return (targetType instanceof ReferenceDescriptor) ? AssignReferenceNodeGen.create(valueNode, frameSlot) : SimpleAssignmentNodeGen.create(valueNode, frameSlot);
}
Aggregations