Search in sources :

Example 11 with LLVMValueRef

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

the class NodeLLVMBuilder method emitSwitch.

@Override
public void emitSwitch(SwitchNode switchNode) {
    if (switchNode instanceof TypeSwitchNode) {
        emitTypeSwitch((TypeSwitchNode) switchNode);
        return;
    }
    int numCases = switchNode.keyCount();
    LLVMValueRef[] values = new LLVMValueRef[numCases];
    LLVMBasicBlockRef[] blocks = new LLVMBasicBlockRef[numCases];
    LLVMValueRef[] weights = new LLVMValueRef[numCases + 1];
    int defaultProbability = expandProbability(switchNode.probability(switchNode.defaultSuccessor()));
    weights[0] = builder.constantInt(defaultProbability);
    for (int i = 0; i < numCases; ++i) {
        JavaConstant key = (JavaConstant) switchNode.keyAt(i);
        values[i] = builder.constantInt(key.asInt());
        blocks[i] = gen.getBlock(switchNode.keySuccessor(i));
        int keyProbability = expandProbability(switchNode.probability(switchNode.keySuccessor(i)));
        weights[i + 1] = builder.constantInt(keyProbability);
    }
    LLVMValueRef switchInstr = builder.buildSwitch(llvmOperand(switchNode.value()), gen.getBlock(switchNode.defaultSuccessor()), values, blocks);
    LLVMValueRef branchWeights = builder.branchWeights(weights);
    builder.setMetadata(switchInstr, "prof", branchWeights);
}
Also used : TypeSwitchNode(org.graalvm.compiler.nodes.java.TypeSwitchNode) LLVMBasicBlockRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) JavaConstant(jdk.vm.ci.meta.JavaConstant) Safepoint(com.oracle.svm.core.thread.Safepoint)

Example 12 with LLVMValueRef

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

the class LLVMGenerator method emitCacheWriteback.

@Override
public void emitCacheWriteback(Value address) {
    int cacheLineSize = getDataCacheLineFlushSize();
    if (cacheLineSize == 0) {
        throw shouldNotReachHere("cache writeback with cache line size of 0");
    }
    LLVMValueRef start = builder.buildBitcast(getVal(address), builder.rawPointerType());
    LLVMValueRef end = builder.buildGEP(start, builder.constantInt(cacheLineSize));
    builder.buildClearCache(start, end);
}
Also used : LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) InlineAssemblyConstraint(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.InlineAssemblyConstraint)

Example 13 with LLVMValueRef

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

the class LLVMGenerator method buildExplicitSelect.

/*
     * Select has to be manually created sometimes because of a bug in LLVM 8 and below which makes
     * it incompatible with statepoint emission in rare cases.
     */
private LLVMValueRef buildExplicitSelect(LLVMValueRef condition, LLVMValueRef trueVal, LLVMValueRef falseVal) {
    LLVMBasicBlockRef trueBlock = builder.appendBasicBlock(currentBlock.toString() + "_select_true");
    LLVMBasicBlockRef falseBlock = builder.appendBasicBlock(currentBlock.toString() + "_select_false");
    LLVMBasicBlockRef mergeBlock = builder.appendBasicBlock(currentBlock.toString() + "_select_end");
    splitBlockEndMap.put(currentBlock, mergeBlock);
    assert LLVMIRBuilder.compatibleTypes(typeOf(trueVal), typeOf(falseVal));
    builder.buildIf(condition, trueBlock, falseBlock);
    builder.positionAtEnd(trueBlock);
    builder.buildBranch(mergeBlock);
    builder.positionAtEnd(falseBlock);
    builder.buildBranch(mergeBlock);
    builder.positionAtEnd(mergeBlock);
    LLVMValueRef[] incomingValues = new LLVMValueRef[] { trueVal, falseVal };
    LLVMBasicBlockRef[] incomingBlocks = new LLVMBasicBlockRef[] { trueBlock, falseBlock };
    return builder.buildPhi(typeOf(trueVal), incomingValues, incomingBlocks);
}
Also used : LLVMBasicBlockRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef)

Example 14 with LLVMValueRef

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

the class NodeLLVMBuilder method emitReadExceptionObject.

/* Other nodes */
@Override
public void emitReadExceptionObject(ValueNode node) {
    LLVMValueRef retrieveExceptionFunction = gen.getFunction(LLVMExceptionUnwind.getRetrieveExceptionMethod(gen.getMetaAccess()));
    LLVMValueRef[] arguments = gen.getCallArguments(new LLVMValueRef[0], SubstrateCallingConventionKind.Java.toType(true));
    LLVMValueRef exception = gen.buildStatepointCall(retrieveExceptionFunction, false, LLVMGenerator.nextPatchpointId.getAndIncrement(), arguments);
    setResult(node, exception);
}
Also used : LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef)

Example 15 with LLVMValueRef

use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef 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)

Aggregations

LLVMValueRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef)51 LLVMBasicBlockRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef)17 LLVMTypeRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef)14 LLVMVariable (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMVariable)9 InlineAssemblyConstraint (com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.InlineAssemblyConstraint)7 Safepoint (com.oracle.svm.core.thread.Safepoint)4 SpecialRegister (com.oracle.svm.core.graal.llvm.LLVMGenerator.SpecialRegister)3 SubstrateCallingConventionType (com.oracle.svm.core.graal.code.SubstrateCallingConventionType)2 LLVMKind (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMKind)2 LLVMPendingSpecialRegisterRead (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMPendingSpecialRegisterRead)2 SafepointCheckNode (com.oracle.svm.core.nodes.SafepointCheckNode)2 DebugInfo (jdk.vm.ci.code.DebugInfo)2 RegisterValue (jdk.vm.ci.code.RegisterValue)2 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 Value (jdk.vm.ci.meta.Value)2 DirectCallTargetNode (org.graalvm.compiler.nodes.DirectCallTargetNode)2 IndirectCallTargetNode (org.graalvm.compiler.nodes.IndirectCallTargetNode)2 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)2 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)2