Search in sources :

Example 51 with Value

use of jdk.vm.ci.meta.Value in project graal by oracle.

the class NodeLIRBuilder method createPhiOut.

private Value[] createPhiOut(AbstractMergeNode merge, AbstractEndNode pred) {
    List<Value> values = new ArrayList<>();
    for (PhiNode phi : merge.valuePhis()) {
        ValueNode node = phi.valueAt(pred);
        Value value = operand(node);
        assert value != null;
        if (isRegister(value)) {
            /*
                 * Fixed register intervals are not allowed at block boundaries so we introduce a
                 * new Variable.
                 */
            value = gen.emitMove(value);
        } else if (!allowObjectConstantToStackMove() && node instanceof ConstantNode && !LIRKind.isValue(value)) {
            /*
                 * Some constants are not allowed as inputs for PHIs in certain backends. Explicitly
                 * create a copy of this value to force it into a register. The new variable is only
                 * used in the PHI.
                 */
            Variable result = gen.newVariable(value.getValueKind());
            gen.emitMove(result, value);
            value = result;
        }
        values.add(value);
    }
    return values.toArray(new Value[values.size()]);
}
Also used : LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Variable(org.graalvm.compiler.lir.Variable) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) ArrayList(java.util.ArrayList) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 52 with Value

use of jdk.vm.ci.meta.Value in project graal by oracle.

the class NodeLIRBuilder method getExactPhiKind.

protected LIRKind getExactPhiKind(PhiNode phi) {
    LIRKind derivedKind = gen.toRegisterKind(gen.getLIRKind(phi.stamp(NodeView.DEFAULT)));
    /* Collect reference information. */
    for (int i = 0; i < phi.valueCount() && !derivedKind.isUnknownReference(); i++) {
        ValueNode node = phi.valueAt(i);
        Value value = getOperand(node);
        // get ValueKind for input
        final LIRKind valueKind;
        if (value != null) {
            valueKind = value.getValueKind(LIRKind.class);
        } else {
            assert isPhiInputFromBackedge(phi, i) : String.format("Input %s to phi node %s is not yet available although it is not coming from a loop back edge", node, phi);
            LIRKind kind = gen.getLIRKind(node.stamp(NodeView.DEFAULT));
            valueKind = gen.toRegisterKind(kind);
        }
        /* Merge the reference information of the derived kind and the input. */
        derivedKind = LIRKind.mergeReferenceInformation(derivedKind, valueKind);
    }
    return derivedKind;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) LIRKind(org.graalvm.compiler.core.common.LIRKind)

Example 53 with Value

use of jdk.vm.ci.meta.Value in project graal by oracle.

the class NodeLIRBuilder method doBlock.

@Override
@SuppressWarnings("try")
public void doBlock(Block block, StructuredGraph graph, BlockMap<List<Node>> blockMap) {
    OptionValues options = graph.getOptions();
    try (BlockScope blockScope = gen.getBlockScope(block)) {
        setSourcePosition(null);
        if (block == gen.getResult().getLIR().getControlFlowGraph().getStartBlock()) {
            assert block.getPredecessorCount() == 0;
            emitPrologue(graph);
        } else {
            assert block.getPredecessorCount() > 0;
            // create phi-in value array
            AbstractBeginNode begin = block.getBeginNode();
            if (begin instanceof AbstractMergeNode) {
                AbstractMergeNode merge = (AbstractMergeNode) begin;
                LabelOp label = (LabelOp) gen.getResult().getLIR().getLIRforBlock(block).get(0);
                label.setPhiValues(createPhiIn(merge));
                if (Options.PrintIRWithLIR.getValue(options) && !TTY.isSuppressed()) {
                    TTY.println("Created PhiIn: " + label);
                }
            }
        }
        doBlockPrologue(block, options);
        List<Node> nodes = blockMap.get(block);
        // Allow NodeLIRBuilder subclass to specialize code generation of any interesting groups
        // of instructions
        matchComplexExpressions(nodes);
        boolean trace = traceLIRGeneratorLevel >= 3;
        for (int i = 0; i < nodes.size(); i++) {
            Node node = nodes.get(i);
            if (node instanceof ValueNode) {
                DebugContext debug = node.getDebug();
                ValueNode valueNode = (ValueNode) node;
                if (trace) {
                    TTY.println("LIRGen for " + valueNode);
                }
                Value operand = getOperand(valueNode);
                if (operand == null) {
                    if (!peephole(valueNode)) {
                        try {
                            doRoot(valueNode);
                        } catch (GraalError e) {
                            throw GraalGraphError.transformAndAddContext(e, valueNode);
                        } catch (Throwable e) {
                            throw new GraalGraphError(e).addContext(valueNode);
                        }
                    }
                } else if (ComplexMatchValue.INTERIOR_MATCH.equals(operand)) {
                    // Doesn't need to be evaluated
                    debug.log("interior match for %s", valueNode);
                } else if (operand instanceof ComplexMatchValue) {
                    debug.log("complex match for %s", valueNode);
                    ComplexMatchValue match = (ComplexMatchValue) operand;
                    operand = match.evaluate(this);
                    if (operand != null) {
                        setResult(valueNode, operand);
                    }
                } else {
                // There can be cases in which the result of an instruction is already set
                // before by other instructions.
                }
            }
        }
        if (!gen.hasBlockEnd(block)) {
            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());
            }
            gen.emitJump(getLIRBlock((FixedNode) successors.first()));
        }
        assert verifyBlock(gen.getResult().getLIR(), block);
    }
}
Also used : LabelOp(org.graalvm.compiler.lir.StandardOp.LabelOp) OptionValues(org.graalvm.compiler.options.OptionValues) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) IfNode(org.graalvm.compiler.nodes.IfNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) 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) IntegerTestNode(org.graalvm.compiler.nodes.calc.IntegerTestNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) 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) FixedNode(org.graalvm.compiler.nodes.FixedNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) Node(org.graalvm.compiler.graph.Node) PhiNode(org.graalvm.compiler.nodes.PhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LIRGenerationDebugContext(org.graalvm.compiler.lir.debug.LIRGenerationDebugContext) DebugContext(org.graalvm.compiler.debug.DebugContext) FixedNode(org.graalvm.compiler.nodes.FixedNode) ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) GraalError(org.graalvm.compiler.debug.GraalError) BlockScope(org.graalvm.compiler.lir.gen.LIRGeneratorTool.BlockScope) GraalGraphError(org.graalvm.compiler.graph.GraalGraphError) ValueNode(org.graalvm.compiler.nodes.ValueNode) ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Example 54 with Value

use of jdk.vm.ci.meta.Value in project graal by oracle.

the class IndexedValueMap method putAll.

public void putAll(IndexedValueMap stack) {
    Value[] otherValues = stack.values;
    int limit = otherValues.length;
    if (limit > values.length) {
        while (limit > 0) {
            if (otherValues[limit - 1] == null) {
                limit--;
                continue;
            }
            break;
        }
        if (limit > values.length) {
            Value[] newValues = new Value[limit];
            System.arraycopy(values, 0, newValues, 0, values.length);
            values = newValues;
        }
    }
    for (int i = 0; i < limit; i++) {
        Value value = otherValues[i];
        if (value != null) {
            values[i] = value;
        }
    }
}
Also used : Value(jdk.vm.ci.meta.Value)

Example 55 with Value

use of jdk.vm.ci.meta.Value in project graal by oracle.

the class LIRGenerator method emitForeignCall.

@Override
public Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState frameState, Value... args) {
    LIRFrameState state = null;
    if (linkage.needsDebugInfo()) {
        if (frameState != null) {
            state = frameState;
        } else {
            assert needOnlyOopMaps();
            state = new LIRFrameState(null, null, null);
        }
    }
    // move the arguments into the correct location
    CallingConvention linkageCc = linkage.getOutgoingCallingConvention();
    res.getFrameMapBuilder().callsMethod(linkageCc);
    assert linkageCc.getArgumentCount() == args.length : "argument count mismatch";
    Value[] argLocations = new Value[args.length];
    for (int i = 0; i < args.length; i++) {
        Value arg = args[i];
        AllocatableValue loc = linkageCc.getArgument(i);
        emitMove(loc, arg);
        argLocations[i] = loc;
    }
    res.setForeignCall(true);
    emitForeignCallOp(linkage, linkageCc.getReturn(), argLocations, linkage.getTemporaries(), state);
    if (isLegal(linkageCc.getReturn())) {
        return emitMove(linkageCc.getReturn());
    } else {
        return null;
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) ConstantValue(org.graalvm.compiler.lir.ConstantValue) LIRValueUtil.isConstantValue(org.graalvm.compiler.lir.LIRValueUtil.isConstantValue) ValueUtil.asAllocatableValue(jdk.vm.ci.code.ValueUtil.asAllocatableValue) Value(jdk.vm.ci.meta.Value) ValueUtil.isAllocatableValue(jdk.vm.ci.code.ValueUtil.isAllocatableValue) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) ValueUtil.asAllocatableValue(jdk.vm.ci.code.ValueUtil.asAllocatableValue) ValueUtil.isAllocatableValue(jdk.vm.ci.code.ValueUtil.isAllocatableValue) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Aggregations

Value (jdk.vm.ci.meta.Value)151 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)76 RegisterValue (jdk.vm.ci.code.RegisterValue)33 LIRKind (org.graalvm.compiler.core.common.LIRKind)18 LIRInstruction (org.graalvm.compiler.lir.LIRInstruction)14 LIRValueUtil.isConstantValue (org.graalvm.compiler.lir.LIRValueUtil.isConstantValue)14 LIRValueUtil.isStackSlotValue (org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue)14 OperandMode (org.graalvm.compiler.lir.LIRInstruction.OperandMode)12 Variable (org.graalvm.compiler.lir.Variable)12 ComplexMatchValue (org.graalvm.compiler.core.match.ComplexMatchValue)11 Indent (org.graalvm.compiler.debug.Indent)11 EnumSet (java.util.EnumSet)10 DebugContext (org.graalvm.compiler.debug.DebugContext)10 GraalError (org.graalvm.compiler.debug.GraalError)10 LIRFrameState (org.graalvm.compiler.lir.LIRFrameState)10 BitSet (java.util.BitSet)9 Register (jdk.vm.ci.code.Register)9 ConstantValue (org.graalvm.compiler.lir.ConstantValue)9 SPARCAddressValue (org.graalvm.compiler.lir.sparc.SPARCAddressValue)9 ValueNode (org.graalvm.compiler.nodes.ValueNode)9