Search in sources :

Example 1 with InstructionBlock

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;
}
Also used : InstructionBlock(com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock)

Example 2 with InstructionBlock

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;
}
Also used : PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) AttributesCodeEntry(com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) InstructionBlock(com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock)

Example 3 with InstructionBlock

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;
}
Also used : InstructionBlock(com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock)

Example 4 with InstructionBlock

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);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) LLVMLivenessAnalysisResult(com.oracle.truffle.llvm.parser.LLVMLivenessAnalysis.LLVMLivenessAnalysisResult) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) LLVMSymbolReadResolver(com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver) ArrayList(java.util.ArrayList) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) ArrayList(java.util.ArrayList) List(java.util.List) InstructionBlock(com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock)

Example 5 with InstructionBlock

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));
}
Also used : PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) InstructionBlock(com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock)

Aggregations

InstructionBlock (com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock)9 Instruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.Instruction)3 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)3 Type (com.oracle.truffle.llvm.runtime.types.Type)3 ArrayList (java.util.ArrayList)3 FunctionParameter (com.oracle.truffle.llvm.parser.model.functions.FunctionParameter)2 AllocateInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.AllocateInstruction)2 BinaryOperationInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.BinaryOperationInstruction)2 BranchInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.BranchInstruction)2 CallInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.CallInstruction)2 CastInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.CastInstruction)2 CompareExchangeInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.CompareExchangeInstruction)2 CompareInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.CompareInstruction)2 ConditionalBranchInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.ConditionalBranchInstruction)2 DbgDeclareInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.DbgDeclareInstruction)2 DbgValueInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.DbgValueInstruction)2 ExtractElementInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.ExtractElementInstruction)2 ExtractValueInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.ExtractValueInstruction)2 FenceInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.FenceInstruction)2 GetElementPointerInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.GetElementPointerInstruction)2