Search in sources :

Example 6 with LLVMTypeRef

use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef in project graal by oracle.

the class LLVMGenerator method emitReturn.

@Override
public void emitReturn(JavaKind javaKind, Value input) {
    if (javaKind == JavaKind.Void) {
        debugInfoPrinter.printRetVoid();
        if (isEntryPoint) {
            builder.buildRetVoid();
        } else {
            LLVMTypeRef[] retTypes = new LLVMTypeRef[SpecialRegister.count()];
            LLVMValueRef[] retValues = new LLVMValueRef[SpecialRegister.count()];
            for (SpecialRegister reg : SpecialRegister.registers()) {
                retTypes[reg.index] = builder.wordType();
                retValues[reg.index] = getSpecialRegisterValue(reg);
            }
            LLVMValueRef retStruct = builder.constantNull(builder.structType(retTypes));
            for (int i = 0; i < retValues.length; ++i) {
                retStruct = builder.buildInsertValue(retStruct, i, retValues[i]);
            }
            builder.buildRet(retStruct);
        }
    } else {
        debugInfoPrinter.printRet(javaKind, input);
        LLVMValueRef retVal = getVal(input);
        if (javaKind == JavaKind.Int) {
            assert LLVMIRBuilder.isIntegerType(typeOf(retVal));
            retVal = arithmetic.emitIntegerConvert(retVal, builder.intType());
        } else if (returnsEnum && javaKind == FrameAccess.getWordKind()) {
            /*
                 * An enum value is represented by a long in the function body, but is returned as
                 * an object (CEnum values are returned as an int)
                 */
            LLVMValueRef result;
            if (returnsCEnum) {
                result = builder.buildTrunc(retVal, JavaKind.Int.getBitCount());
            } else {
                result = builder.buildIntToPtr(retVal, builder.objectType(false));
            }
            retVal = result;
        }
        if (isEntryPoint) {
            builder.buildRet(retVal);
        } else {
            LLVMTypeRef[] retTypes = new LLVMTypeRef[SpecialRegister.count() + 1];
            LLVMValueRef[] retValues = new LLVMValueRef[SpecialRegister.count() + 1];
            for (SpecialRegister reg : SpecialRegister.registers()) {
                retTypes[reg.index] = builder.wordType();
                retValues[reg.index] = getSpecialRegisterValue(reg);
            }
            retTypes[SpecialRegister.count()] = LLVMIRBuilder.typeOf(retVal);
            retValues[SpecialRegister.count()] = retVal;
            LLVMValueRef retStruct = builder.constantNull(builder.structType(retTypes));
            for (int i = 0; i < retValues.length; ++i) {
                retStruct = builder.buildInsertValue(retStruct, i, retValues[i]);
            }
            builder.buildRet(retStruct);
        }
    }
}
Also used : LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef) InlineAssemblyConstraint(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.InlineAssemblyConstraint)

Example 7 with LLVMTypeRef

use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef in project graal by oracle.

the class LLVMGenerator method prependArgumentTypes.

/**
 * Creates a new function type based on the given one with the given argument types prepended to
 * the original ones.
 */
private LLVMTypeRef prependArgumentTypes(LLVMTypeRef functionType, int prefixTypes, LLVMTypeRef... typesToAdd) {
    LLVMTypeRef returnType = LLVMIRBuilder.getReturnType(functionType);
    boolean varargs = LLVMIRBuilder.isFunctionVarArg(functionType);
    LLVMTypeRef[] oldTypes = LLVMIRBuilder.getParamTypes(functionType);
    LLVMTypeRef[] newTypes = new LLVMTypeRef[oldTypes.length + typesToAdd.length];
    System.arraycopy(oldTypes, 0, newTypes, 0, prefixTypes);
    System.arraycopy(typesToAdd, 0, newTypes, prefixTypes, typesToAdd.length);
    System.arraycopy(oldTypes, prefixTypes, newTypes, prefixTypes + typesToAdd.length, oldTypes.length - prefixTypes);
    return builder.functionType(returnType, varargs, newTypes);
}
Also used : LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef)

Example 8 with LLVMTypeRef

use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef in project graal by oracle.

the class NodeLLVMBuilder method getUnknownCallReturnType.

private LLVMTypeRef getUnknownCallReturnType(LoweredCallTargetNode callTarget) {
    LLVMTypeRef retType = gen.getLLVMType(callTarget.returnStamp().getTrustedStamp());
    if (!((SubstrateCallingConventionType) callTarget.callType()).nativeABI()) {
        boolean voidReturnType = LLVMIRBuilder.isVoidType(retType);
        LLVMTypeRef[] returnTypes = new LLVMTypeRef[SpecialRegister.count() + (voidReturnType ? 0 : 1)];
        for (SpecialRegister reg : SpecialRegister.registers()) {
            returnTypes[reg.getIndex()] = builder.wordType();
        }
        if (!voidReturnType) {
            returnTypes[SpecialRegister.count()] = retType;
        }
        retType = builder.structType(returnTypes);
    }
    return retType;
}
Also used : SpecialRegister(com.oracle.svm.core.graal.llvm.LLVMGenerator.SpecialRegister) LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef)

Example 9 with LLVMTypeRef

use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef in project graal by oracle.

the class NodeLLVMBuilder method doBlock.

@Override
public void doBlock(Block block, StructuredGraph graph, BlockMap<List<Node>> blockMap) {
    assert !processedBlocks.contains(block) : "Block already processed " + block;
    assert verifyPredecessors(block);
    gen.beginBlock(block);
    if (block == graph.getLastSchedule().getCFG().getStartBlock()) {
        assert block.getPredecessorCount() == 0;
        long startPatchpointID = LLVMGenerator.nextPatchpointId.getAndIncrement();
        builder.buildStackmap(builder.constantLong(startPatchpointID));
        gen.getCompilationResult().recordInfopoint(NumUtil.safeToInt(startPatchpointID), null, InfopointReason.METHOD_START);
        for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
            int offset = (gen.isEntryPoint() ? 0 : SpecialRegister.count());
            LLVMValueRef paramValue = builder.getFunctionParam(param.index() + offset);
            setResult(param, paramValue);
        }
        for (SpecialRegister reg : SpecialRegister.registers()) {
            gen.setInitialSpecialRegisterValue(reg, gen.isEntryPoint() ? builder.constantNull(builder.wordType()) : builder.getFunctionParam(reg.getIndex()));
        }
        gen.getDebugInfoPrinter().printFunction(graph, this);
    } else {
        assert block.getPredecessorCount() > 0;
        // create phi-in value array
        AbstractBeginNode begin = block.getBeginNode();
        if (begin instanceof AbstractMergeNode) {
            AbstractMergeNode merge = (AbstractMergeNode) begin;
            for (SpecialRegister reg : SpecialRegister.registers()) {
                List<LLVMValueRef> forwardPredValues = new ArrayList<>();
                List<LLVMBasicBlockRef> forwardBlocks = new ArrayList<>();
                for (Block predecessor : block.getPredecessors()) {
                    if (processedBlocks.contains(predecessor)) {
                        forwardPredValues.add(block.isExceptionEntry() ? gen.getHandlerSpecialRegisterValue(reg, predecessor) : gen.getSpecialRegisterValue(reg, predecessor));
                        forwardBlocks.add(gen.getBlockEnd(predecessor));
                    }
                }
                LLVMValueRef registerPhi = builder.buildPhi(builder.wordType(), forwardPredValues.toArray(new LLVMValueRef[0]), forwardBlocks.toArray(new LLVMBasicBlockRef[0]));
                gen.setInitialSpecialRegisterValue(reg, registerPhi);
            }
            for (ValuePhiNode phiNode : merge.valuePhis()) {
                List<LLVMValueRef> forwardPhis = new ArrayList<>();
                List<LLVMBasicBlockRef> forwardBlocks = new ArrayList<>();
                LLVMTypeRef phiType = getLLVMType(phiNode);
                boolean hasBackwardIncomingEdges = false;
                for (Block predecessor : block.getPredecessors()) {
                    if (processedBlocks.contains(predecessor)) {
                        ValueNode phiValue = phiNode.valueAt((AbstractEndNode) predecessor.getEndNode());
                        LLVMValueRef value;
                        if (operand(phiValue) instanceof LLVMPendingSpecialRegisterRead) {
                            /*
                                 * The pending read may need to perform instructions to load the
                                 * value, so we put them at the end of the predecessor block
                                 */
                            Block currentBlock = (Block) gen.getCurrentBlock();
                            gen.editBlock(predecessor);
                            value = llvmOperand(phiValue);
                            gen.resumeBlock(currentBlock);
                        } else {
                            value = llvmOperand(phiValue);
                        }
                        LLVMBasicBlockRef parentBlock = gen.getBlockEnd(predecessor);
                        forwardPhis.add(value);
                        forwardBlocks.add(parentBlock);
                    } else {
                        hasBackwardIncomingEdges = true;
                    }
                }
                LLVMValueRef[] incomingValues = forwardPhis.toArray(new LLVMValueRef[0]);
                LLVMBasicBlockRef[] incomingBlocks = forwardBlocks.toArray(new LLVMBasicBlockRef[0]);
                LLVMValueRef phi = builder.buildPhi(phiType, incomingValues, incomingBlocks);
                if (hasBackwardIncomingEdges) {
                    backwardsPhi.put(phiNode, phi);
                }
                setResult(phiNode, phi);
            }
        } else {
            assert block.getPredecessorCount() == 1;
            Block predecessor = block.getFirstPredecessor();
            for (SpecialRegister reg : SpecialRegister.registers()) {
                gen.setInitialSpecialRegisterValue(reg, block.isExceptionEntry() ? gen.getHandlerSpecialRegisterValue(reg, predecessor) : gen.getSpecialRegisterValue(reg, predecessor));
            }
        }
    }
    gen.getDebugInfoPrinter().printBlock(block);
    for (Node node : blockMap.get(block)) {
        if (node instanceof ValueNode) {
            /*
                 * There can be cases in which the result of an instruction is already set before by
                 * other instructions.
                 */
            if (!valueMap.containsKey(node)) {
                ValueNode valueNode = (ValueNode) node;
                try {
                    gen.getDebugInfoPrinter().printNode(valueNode);
                    emitNode(valueNode);
                } catch (GraalError e) {
                    throw GraalGraphError.transformAndAddContext(e, valueNode);
                } catch (Throwable e) {
                    throw new GraalGraphError(e).addContext(valueNode);
                }
            }
        }
    }
    if (builder.blockTerminator(gen.getBlockEnd(block)) == null) {
        NodeIterable<Node> successors = block.getEndNode().successors();
        assert successors.count() == block.getSuccessorCount();
        if (block.getSuccessorCount() != 1) {
            /*
                 * If we have more than one successor, we cannot just use the first one. Since
                 * successors are unordered, this would be a random choice.
                 */
            throw new GraalError("Block without BlockEndOp: " + block.getEndNode());
        }
        builder.buildBranch(gen.getBlock(block.getFirstSuccessor()));
    }
    processedBlocks.add(block);
}
Also used : LLVMPendingSpecialRegisterRead(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMPendingSpecialRegisterRead) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) IntegerTestNode(org.graalvm.compiler.nodes.calc.IntegerTestNode) TypeSwitchNode(org.graalvm.compiler.nodes.java.TypeSwitchNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) CGlobalDataLoadAddressNode(com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) SafepointCheckNode(com.oracle.svm.core.nodes.SafepointCheckNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) SafepointNode(org.graalvm.compiler.nodes.SafepointNode) BreakpointNode(org.graalvm.compiler.nodes.BreakpointNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ForeignCallWithExceptionNode(org.graalvm.compiler.nodes.extended.ForeignCallWithExceptionNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DirectCallTargetNode(org.graalvm.compiler.nodes.DirectCallTargetNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) SwitchNode(org.graalvm.compiler.nodes.extended.SwitchNode) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) Node(org.graalvm.compiler.graph.Node) ArrayList(java.util.ArrayList) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef) Safepoint(com.oracle.svm.core.thread.Safepoint) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) LLVMBasicBlockRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) GraalError(org.graalvm.compiler.debug.GraalError) GraalGraphError(org.graalvm.compiler.graph.GraalGraphError) ValueNode(org.graalvm.compiler.nodes.ValueNode) Block(org.graalvm.compiler.nodes.cfg.Block) SpecialRegister(com.oracle.svm.core.graal.llvm.LLVMGenerator.SpecialRegister)

Example 10 with LLVMTypeRef

use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef in project graal by oracle.

the class LLVMIRBuilder method buildLoad.

public LLVMValueRef buildLoad(LLVMValueRef address, LLVMTypeRef type) {
    LLVMTypeRef addressType = LLVM.LLVMTypeOf(address);
    if (isObjectType(type) && !isObjectType(addressType)) {
        boolean compressed = isCompressedPointerType(type);
        return buildCall(helpers.getLoadObjectFromUntrackedPointerFunction(compressed), address);
    }
    LLVMValueRef castedAddress = buildBitcast(address, pointerType(type, isObjectType(addressType), false));
    return buildLoad(castedAddress);
}
Also used : LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef)

Aggregations

LLVMTypeRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef)25 LLVMValueRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef)15 InlineAssemblyConstraint (com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.InlineAssemblyConstraint)5 LLVMBasicBlockRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef)4 LLVMKind (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMKind)3 LLVMPendingSpecialRegisterRead (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMPendingSpecialRegisterRead)3 LLVMVariable (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMVariable)3 RegisterValue (jdk.vm.ci.code.RegisterValue)3 Value (jdk.vm.ci.meta.Value)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 SpecialRegister (com.oracle.svm.core.graal.llvm.LLVMGenerator.SpecialRegister)2 LLVMIRBuilder (com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder)2 LLVMValueWrapper (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMValueWrapper)2 DebugInfo (jdk.vm.ci.code.DebugInfo)2 PlatformKind (jdk.vm.ci.meta.PlatformKind)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 LIRFrameState (org.graalvm.compiler.lir.LIRFrameState)2 FrameAccess (com.oracle.svm.core.FrameAccess)1 ReservedRegisters (com.oracle.svm.core.ReservedRegisters)1 SubstrateOptions (com.oracle.svm.core.SubstrateOptions)1