Search in sources :

Example 1 with LabelOp

use of org.graalvm.compiler.lir.StandardOp.LabelOp in project graal by oracle.

the class HotSpotBackend method gatherDestroyedCallerRegisters.

/**
 * Finds all the registers that are defined by some given LIR.
 *
 * @param lir the LIR to examine
 * @return the registers that are defined by or used as temps for any instruction in {@code lir}
 */
protected final EconomicSet<Register> gatherDestroyedCallerRegisters(LIR lir) {
    final EconomicSet<Register> destroyedRegisters = EconomicSet.create(Equivalence.IDENTITY);
    ValueConsumer defConsumer = new ValueConsumer() {

        @Override
        public void visitValue(Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
            if (ValueUtil.isRegister(value)) {
                final Register reg = ValueUtil.asRegister(value);
                destroyedRegisters.add(reg);
            }
        }
    };
    for (AbstractBlockBase<?> block : lir.codeEmittingOrder()) {
        if (block == null) {
            continue;
        }
        for (LIRInstruction op : lir.getLIRforBlock(block)) {
            if (op instanceof LabelOp) {
            // Don't consider this as a definition
            } else {
                op.visitEachTemp(defConsumer);
                op.visitEachOutput(defConsumer);
            }
        }
    }
    return translateToCallerRegisters(destroyedRegisters);
}
Also used : LabelOp(org.graalvm.compiler.lir.StandardOp.LabelOp) Register(jdk.vm.ci.code.Register) ValueConsumer(org.graalvm.compiler.lir.ValueConsumer) EnumSet(java.util.EnumSet) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) Value(jdk.vm.ci.meta.Value) OperandMode(org.graalvm.compiler.lir.LIRInstruction.OperandMode)

Example 2 with LabelOp

use of org.graalvm.compiler.lir.StandardOp.LabelOp in project graal by oracle.

the class SSALinearScanLifetimeAnalysisPhase method addRegisterHint.

@Override
protected void addRegisterHint(final LIRInstruction op, final Value targetValue, OperandMode mode, EnumSet<OperandFlag> flags, final boolean hintAtDef) {
    super.addRegisterHint(op, targetValue, mode, flags, hintAtDef);
    if (hintAtDef && op instanceof LabelOp) {
        LabelOp label = (LabelOp) op;
        Interval to = allocator.getOrCreateInterval((AllocatableValue) targetValue);
        SSAUtil.forEachPhiRegisterHint(allocator.getLIR(), allocator.blockForId(label.id()), label, targetValue, mode, (ValueConsumer) (registerHint, valueMode, valueFlags) -> {
            if (LinearScan.isVariableOrRegister(registerHint)) {
                Interval from = allocator.getOrCreateInterval((AllocatableValue) registerHint);
                setHint(debug, op, to, from);
                setHint(debug, op, from, to);
            }
        });
    }
}
Also used : OperandMode(org.graalvm.compiler.lir.LIRInstruction.OperandMode) Interval(org.graalvm.compiler.lir.alloc.lsra.Interval) ValueConsumer(org.graalvm.compiler.lir.ValueConsumer) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) RegisterPriority(org.graalvm.compiler.lir.alloc.lsra.Interval.RegisterPriority) Value(jdk.vm.ci.meta.Value) OperandFlag(org.graalvm.compiler.lir.LIRInstruction.OperandFlag) DebugContext(org.graalvm.compiler.debug.DebugContext) LinearScan(org.graalvm.compiler.lir.alloc.lsra.LinearScan) LinearScanLifetimeAnalysisPhase(org.graalvm.compiler.lir.alloc.lsra.LinearScanLifetimeAnalysisPhase) SSAUtil(org.graalvm.compiler.lir.ssa.SSAUtil) EnumSet(java.util.EnumSet) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) LabelOp(org.graalvm.compiler.lir.StandardOp.LabelOp) LabelOp(org.graalvm.compiler.lir.StandardOp.LabelOp) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) Interval(org.graalvm.compiler.lir.alloc.lsra.Interval)

Example 3 with LabelOp

use of org.graalvm.compiler.lir.StandardOp.LabelOp 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 4 with LabelOp

use of org.graalvm.compiler.lir.StandardOp.LabelOp in project graal by oracle.

the class MoveProfiler method doBlock.

private void doBlock(AbstractBlockBase<?> block) {
    ArrayList<LIRInstruction> instructions = lir.getLIRforBlock(block);
    assert instructions.size() >= 2 : "Malformed block: " + block + ", " + instructions;
    assert instructions.get(instructions.size() - 1) instanceof BlockEndOp : "Not a BlockEndOp: " + instructions.get(instructions.size() - 1);
    assert !(instructions.get(instructions.size() - 2) instanceof BlockEndOp) : "Is a BlockEndOp: " + instructions.get(instructions.size() - 2);
    assert instructions.get(0) instanceof LabelOp : "Not a LabelOp: " + instructions.get(0);
    assert !(instructions.get(1) instanceof LabelOp) : "Is a LabelOp: " + instructions.get(1);
    MoveStatistics stats = null;
    // analysis phase
    for (LIRInstruction inst : instructions) {
        if (MoveOp.isMoveOp(inst)) {
            if (stats == null) {
                stats = new MoveStatistics();
                blockMap.put(block, stats);
            }
            stats.add(MoveType.get(inst));
        }
    }
}
Also used : BlockEndOp(org.graalvm.compiler.lir.StandardOp.BlockEndOp) LabelOp(org.graalvm.compiler.lir.StandardOp.LabelOp) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction)

Example 5 with LabelOp

use of org.graalvm.compiler.lir.StandardOp.LabelOp in project graal by oracle.

the class SSAUtil method removePhiIn.

public static void removePhiIn(LIR lir, AbstractBlockBase<?> block) {
    LabelOp label = phiIn(lir, block);
    label.clearIncomingValues();
}
Also used : LabelOp(org.graalvm.compiler.lir.StandardOp.LabelOp)

Aggregations

LabelOp (org.graalvm.compiler.lir.StandardOp.LabelOp)8 Value (jdk.vm.ci.meta.Value)4 LIRInstruction (org.graalvm.compiler.lir.LIRInstruction)4 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)3 DebugContext (org.graalvm.compiler.debug.DebugContext)3 EnumSet (java.util.EnumSet)2 OperandMode (org.graalvm.compiler.lir.LIRInstruction.OperandMode)2 JumpOp (org.graalvm.compiler.lir.StandardOp.JumpOp)2 ValueConsumer (org.graalvm.compiler.lir.ValueConsumer)2 Register (jdk.vm.ci.code.Register)1 RegisterValue (jdk.vm.ci.code.RegisterValue)1 ValueUtil.asRegisterValue (jdk.vm.ci.code.ValueUtil.asRegisterValue)1 ComplexMatchValue (org.graalvm.compiler.core.match.ComplexMatchValue)1 GraalError (org.graalvm.compiler.debug.GraalError)1 Indent (org.graalvm.compiler.debug.Indent)1 GraalGraphError (org.graalvm.compiler.graph.GraalGraphError)1 Node (org.graalvm.compiler.graph.Node)1 OperandFlag (org.graalvm.compiler.lir.LIRInstruction.OperandFlag)1 LIRValueUtil.isConstantValue (org.graalvm.compiler.lir.LIRValueUtil.isConstantValue)1 LIRValueUtil.isStackSlotValue (org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue)1