Search in sources :

Example 1 with LIRInstruction

use of org.graalvm.compiler.lir.LIRInstruction 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 LIRInstruction

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

the class HotSpotInstructionProfiling method countInstructions.

/**
 * After assembly the {@link HotSpotBackend#profileInstructions(LIR, CompilationResultBuilder)}
 * calls this method for patching the instruction counts into the counter increment code.
 */
public static void countInstructions(LIR lir, Assembler asm) {
    InstructionCounterOp lastOp = null;
    InstructionCounter counter = asm.getInstructionCounter();
    for (AbstractBlockBase<?> block : lir.codeEmittingOrder()) {
        if (block == null) {
            continue;
        }
        for (LIRInstruction inst : lir.getLIRforBlock(block)) {
            if (inst instanceof InstructionCounterOp) {
                InstructionCounterOp currentOp = (InstructionCounterOp) inst;
                if (lastOp != null) {
                    int beginPc = lastOp.countOffsetEnd;
                    int endPc = currentOp.countOffsetBegin;
                    int[] instructionCounts = counter.countInstructions(lastOp.instructionsToProfile, beginPc, endPc);
                    lastOp.delegate.patchCounterIncrement(asm, instructionCounts);
                }
                lastOp = ((InstructionCounterOp) inst);
            }
        }
    }
    if (lastOp != null) {
        assert lastOp.countOffsetBegin < asm.position();
        int beginPc = lastOp.countOffsetBegin;
        int endPc = asm.position();
        int[] instructionCounts = counter.countInstructions(lastOp.instructionsToProfile, beginPc, endPc);
        lastOp.delegate.patchCounterIncrement(asm, instructionCounts);
    }
}
Also used : LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) InstructionCounter(org.graalvm.compiler.asm.Assembler.InstructionCounter)

Example 3 with LIRInstruction

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

the class HotSpotZapRegistersPhase method processBlock.

@SuppressWarnings("try")
private static void processBlock(DiagnosticLIRGeneratorTool diagnosticLirGenTool, HotSpotLIRGenerationResult res, LIR lir, LIRInsertionBuffer buffer, AbstractBlockBase<?> block, boolean zapRegisters, boolean zapStack) {
    DebugContext debug = lir.getDebug();
    try (Indent indent = debug.logAndIndent("Process block %s", block)) {
        ArrayList<LIRInstruction> instructions = lir.getLIRforBlock(block);
        buffer.init(instructions);
        for (int index = 0; index < instructions.size(); index++) {
            LIRInstruction inst = instructions.get(index);
            if (zapStack && inst instanceof ZapStackArgumentSpaceBeforeInstruction) {
                LIRInstruction zap = diagnosticLirGenTool.zapArgumentSpace();
                if (zap != null) {
                    buffer.append(index, zap);
                }
            }
            if (zapRegisters && inst instanceof ZapRegistersAfterInstruction) {
                LIRFrameState state = getLIRState(inst);
                if (state != null) {
                    SaveRegistersOp zap = diagnosticLirGenTool.createZapRegisters();
                    SaveRegistersOp old = res.getCalleeSaveInfo().put(state, zap);
                    assert old == null : "Already another SaveRegisterOp registered! " + old;
                    buffer.append(index + 1, (LIRInstruction) zap);
                    debug.log("Insert ZapRegister after %s", inst);
                }
            }
        }
        buffer.finish();
    }
}
Also used : LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) Indent(org.graalvm.compiler.debug.Indent) ZapRegistersAfterInstruction(org.graalvm.compiler.lir.gen.DiagnosticLIRGeneratorTool.ZapRegistersAfterInstruction) ZapStackArgumentSpaceBeforeInstruction(org.graalvm.compiler.lir.gen.DiagnosticLIRGeneratorTool.ZapStackArgumentSpaceBeforeInstruction) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) DebugContext(org.graalvm.compiler.debug.DebugContext) SaveRegistersOp(org.graalvm.compiler.lir.StandardOp.SaveRegistersOp)

Example 4 with LIRInstruction

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

the class CompositeValueReplacementTest1 method replaceCompValueTest0.

@Test
public void replaceCompValueTest0() {
    DummyValue dummyValue1 = new DummyValue();
    DummyValue dummyValue2 = new DummyValue();
    DummyValue dummyValue3 = new DummyValue();
    TestCompositeValue compValue1 = new TestCompositeValue(dummyValue1);
    LIRInstruction op1 = new TestOp(compValue1);
    LIRInstruction op2 = new TestOp(compValue1);
    op1.forEachInput((instruction, value, mode, flags) -> {
        assertEquals(dummyValue1, value);
        return dummyValue2;
    });
    op2.forEachInput((instruction, value, mode, flags) -> {
        assertEquals(dummyValue1, value);
        return dummyValue3;
    });
    op1.visitEachInput((instruction, value, mode, flags) -> assertEquals(dummyValue2, value));
    op2.visitEachInput((instruction, value, mode, flags) -> assertEquals(dummyValue3, value));
}
Also used : LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) Test(org.junit.Test)

Example 5 with LIRInstruction

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

the class MoveResolver method insertMove.

private LIRInstruction insertMove(Interval fromInterval, Interval toInterval) {
    assert !fromInterval.operand.equals(toInterval.operand) : "from and to interval equal: " + fromInterval;
    assert LIRKind.verifyMoveKinds(toInterval.kind(), fromInterval.kind(), allocator.getRegisterAllocationConfig()) : "move between different types";
    assert insertIdx != -1 : "must setup insert position first";
    LIRInstruction move = createMove(fromInterval.operand, toInterval.operand, fromInterval.location(), toInterval.location());
    insertionBuffer.append(insertIdx, move);
    DebugContext debug = allocator.getDebug();
    if (debug.isLogEnabled()) {
        debug.log("insert move from %s to %s at %d", fromInterval, toInterval, insertIdx);
    }
    return move;
}
Also used : LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) DebugContext(org.graalvm.compiler.debug.DebugContext)

Aggregations

LIRInstruction (org.graalvm.compiler.lir.LIRInstruction)55 DebugContext (org.graalvm.compiler.debug.DebugContext)25 Indent (org.graalvm.compiler.debug.Indent)19 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)15 Value (jdk.vm.ci.meta.Value)15 OperandMode (org.graalvm.compiler.lir.LIRInstruction.OperandMode)10 EnumSet (java.util.EnumSet)8 Register (jdk.vm.ci.code.Register)8 AbstractBlockBase (org.graalvm.compiler.core.common.cfg.AbstractBlockBase)8 OperandFlag (org.graalvm.compiler.lir.LIRInstruction.OperandFlag)7 BitSet (java.util.BitSet)6 GraalError (org.graalvm.compiler.debug.GraalError)6 InstructionValueConsumer (org.graalvm.compiler.lir.InstructionValueConsumer)6 LIR (org.graalvm.compiler.lir.LIR)6 LIRInsertionBuffer (org.graalvm.compiler.lir.LIRInsertionBuffer)6 ValueConsumer (org.graalvm.compiler.lir.ValueConsumer)6 ArrayList (java.util.ArrayList)5 ValueUtil.asRegister (jdk.vm.ci.code.ValueUtil.asRegister)5 ValueUtil.isRegister (jdk.vm.ci.code.ValueUtil.isRegister)5 LoadConstantOp (org.graalvm.compiler.lir.StandardOp.LoadConstantOp)5