use of com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock in project sulong by graalvm.
the class LLVMLivenessAnalysis method removeBlockFromWorkList.
private static InstructionBlock removeBlockFromWorkList(ArrayDeque<InstructionBlock> workList, BitSet blockOnWorkList) {
InstructionBlock block = workList.removeLast();
blockOnWorkList.clear(block.getBlockIndex());
return block;
}
use of com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock in project sulong by graalvm.
the class Function method createInvoke.
private void createInvoke(long[] args) {
int i = 0;
final AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(args[i++]);
final long ccInfo = args[i++];
final InstructionBlock normalSuccessor = function.getBlock(args[i++]);
final InstructionBlock unwindSuccessor = function.getBlock(args[i++]);
FunctionType functionType = null;
if (((ccInfo >> INVOKE_HASEXPLICITFUNCTIONTYPE_SHIFT) & 1) != 0) {
functionType = (FunctionType) types.get(args[i++]);
}
final int target = getIndex(args[i++]);
final Type calleeType;
if (scope.isValueForwardRef(target)) {
calleeType = types.get(args[i++]);
} else {
calleeType = scope.getValueType(target);
}
if (functionType == null) {
if (calleeType instanceof PointerType) {
functionType = (FunctionType) ((PointerType) calleeType).getPointeeType();
} else if (calleeType instanceof FunctionType) {
functionType = (FunctionType) calleeType;
} else {
throw new AssertionError("Cannot find Type of invoked function: " + calleeType.toString());
}
}
int[] arguments = new int[args.length - i];
int skipped = 0;
int j = 0;
while (j < functionType.getArgumentTypes().length && i < args.length) {
arguments[j++] = getIndex(args[i++]);
}
while (i < args.length) {
int index = getIndex(args[i++]);
arguments[j++] = index;
if (scope.isValueForwardRef(index)) {
i++;
skipped++;
}
}
if (skipped > 0) {
arguments = Arrays.copyOf(arguments, arguments.length - skipped);
}
final Type returnType = functionType.getReturnType();
if (returnType == VoidType.INSTANCE) {
emit(VoidInvokeInstruction.fromSymbols(scope, target, arguments, normalSuccessor, unwindSuccessor, paramAttr));
} else {
emit(InvokeInstruction.fromSymbols(scope, returnType, target, arguments, normalSuccessor, unwindSuccessor, paramAttr));
}
isLastBlockTerminated = true;
}
use of com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock in project sulong by graalvm.
the class Function method createBranch.
private void createBranch(long[] args) {
if (args.length == 1) {
emit(BranchInstruction.fromTarget(function.getBlock(args[0])));
} else {
final int condition = getIndex(args[2]);
final InstructionBlock trueSuccessor = function.getBlock(args[0]);
final InstructionBlock falseSuccessor = function.getBlock(args[1]);
emit(ConditionalBranchInstruction.fromSymbols(scope.getSymbols(), condition, trueSuccessor, falseSuccessor));
}
isLastBlockTerminated = true;
}
use of com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock 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.model.blocks.InstructionBlock in project sulong by graalvm.
the class Function method createPhi.
private void createPhi(long[] args) {
Type type = types.get(args[0]);
int count = (args.length) - 1 >> 1;
int[] values = new int[count];
InstructionBlock[] blocks = new InstructionBlock[count];
for (int i = 0, j = 1; i < count; i++) {
values[i] = getIndex(Records.toSignedValue(args[j++]));
blocks[i] = function.getBlock(args[j++]);
}
emit(PhiInstruction.generate(scope.getSymbols(), type, values, blocks));
}
Aggregations