Search in sources :

Example 6 with LLVMControlFlowNode

use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode in project sulong by graalvm.

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(ReturnInstruction ret) {
    LLVMControlFlowNode node;
    if (ret.getValue() == null) {
        node = nodeFactory.createRetVoid(runtime, sourceFunction.getSourceLocation(ret));
    } else {
        final Type type = ret.getValue().getType();
        final LLVMExpressionNode value = symbols.resolve(ret.getValue());
        node = nodeFactory.createNonVoidRet(runtime, value, type, sourceFunction.getSourceLocation(ret));
    }
    setControlFlowNode(node);
}
Also used : LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMControlFlowNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)

Example 7 with LLVMControlFlowNode

use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode in project sulong by graalvm.

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(BranchInstruction branch) {
    LLVMControlFlowNode unconditionalBranchNode = nodeFactory.createUnconditionalBranch(runtime, branch.getSuccessor().getBlockIndex(), getPhiWriteNodes(branch)[0], sourceFunction.getSourceLocation(branch));
    setControlFlowNode(unconditionalBranchNode);
}
Also used : LLVMControlFlowNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode)

Example 8 with LLVMControlFlowNode

use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode in project sulong by graalvm.

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(ConditionalBranchInstruction branch) {
    LLVMExpressionNode conditionNode = symbols.resolve(branch.getCondition());
    int trueIndex = branch.getTrueSuccessor().getBlockIndex();
    int falseIndex = branch.getFalseSuccessor().getBlockIndex();
    LLVMExpressionNode[] phiWriteNodes = getPhiWriteNodes(branch);
    LLVMControlFlowNode node = nodeFactory.createConditionalBranch(runtime, trueIndex, falseIndex, conditionNode, phiWriteNodes[0], phiWriteNodes[1], sourceFunction.getSourceLocation(branch));
    setControlFlowNode(node);
}
Also used : LLVMControlFlowNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)

Example 9 with LLVMControlFlowNode

use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode in project sulong by graalvm.

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(SwitchOldInstruction zwitch) {
    LLVMExpressionNode cond = symbols.resolve(zwitch.getCondition());
    int[] successors = new int[zwitch.getCaseCount() + 1];
    for (int i = 0; i < successors.length - 1; i++) {
        successors[i] = zwitch.getCaseBlock(i).getBlockIndex();
    }
    successors[successors.length - 1] = zwitch.getDefaultBlock().getBlockIndex();
    final PrimitiveType llvmType = (PrimitiveType) zwitch.getCondition().getType();
    final LLVMExpressionNode[] cases = new LLVMExpressionNode[zwitch.getCaseCount()];
    for (int i = 0; i < cases.length; i++) {
        // casts to smaller types in the factoryfacade won't work
        switch(llvmType.getPrimitiveKind()) {
            case I8:
                cases[i] = nodeFactory.createLiteral(runtime, (byte) zwitch.getCaseValue(i), llvmType);
                break;
            case I16:
                cases[i] = nodeFactory.createLiteral(runtime, (short) zwitch.getCaseValue(i), llvmType);
                break;
            case I32:
                cases[i] = nodeFactory.createLiteral(runtime, (int) zwitch.getCaseValue(i), llvmType);
                break;
            default:
                cases[i] = nodeFactory.createLiteral(runtime, zwitch.getCaseValue(i), llvmType);
        }
    }
    LLVMControlFlowNode node = nodeFactory.createSwitch(runtime, cond, successors, cases, llvmType, getPhiWriteNodes(zwitch), sourceFunction.getSourceLocation(zwitch));
    setControlFlowNode(node);
}
Also used : LLVMControlFlowNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType)

Example 10 with LLVMControlFlowNode

use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode 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);
}
Also used : LLVMControlFlowNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) ArrayList(java.util.ArrayList) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) Phi(com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)

Aggregations

LLVMControlFlowNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode)10 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)7 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)5 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)4 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)4 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)4 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)4 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)4 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)4 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)4 Type (com.oracle.truffle.llvm.runtime.types.Type)4 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2 Phi (com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi)2 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)2 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)2 LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)2 ArrayList (java.util.ArrayList)2 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)1 LLVMBasicBlockNode (com.oracle.truffle.llvm.nodes.base.LLVMBasicBlockNode)1 LLVMInvokeNode (com.oracle.truffle.llvm.nodes.func.LLVMInvokeNode)1