Search in sources :

Example 31 with LIRInstruction

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

the class SPARCHotSpotBackend method registerSizePredictionValidator.

/**
 * Registers a verifier which checks if the LIRInstructions estimate of constants size is
 * greater or equal to the actual one.
 */
private static boolean registerSizePredictionValidator(final CompilationResultBuilder crb, DebugContext debug) {
    /**
     * Used to hold state between beforeOp and afterOp
     */
    class ValidationState {

        LIRInstruction op;

        final DebugContext debug;

        int constantSizeBefore;

        ValidationState(DebugContext debug) {
            this.debug = debug;
        }

        public void before(LIRInstruction before) {
            assert op == null : "LIRInstruction " + op + " no after call received";
            op = before;
            constantSizeBefore = calculateDataSectionSize(crb.compilationResult.getDataSection());
        }

        public void after(LIRInstruction after) {
            assert after.equals(op) : "Instructions before/after don't match " + op + "/" + after;
            int constantSizeAfter = calculateDataSectionSize(crb.compilationResult.getDataSection());
            int actual = constantSizeAfter - constantSizeBefore;
            if (op instanceof SPARCLIRInstructionMixin) {
                org.graalvm.compiler.lir.sparc.SPARCLIRInstructionMixin.SizeEstimate size = ((SPARCLIRInstructionMixin) op).estimateSize();
                assert size != null : "No size prediction available for op: " + op;
                Class<?> c = op.getClass();
                CONSTANT_ESTIMATED_STATS.add(c, size.constantSize, debug);
                CONSTANT_ACTUAL_STATS.add(c, actual, debug);
                assert size.constantSize >= actual : "Op " + op + " exceeded estimated constant size; predicted: " + size.constantSize + " actual: " + actual;
            } else {
                assert actual == 0 : "Op " + op + " emitted to DataSection without any estimate.";
            }
            op = null;
            constantSizeBefore = 0;
        }
    }
    final ValidationState state = new ValidationState(debug);
    crb.setOpCallback(op -> state.before(op), op -> state.after(op));
    return true;
}
Also used : LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) SPARCTailDelayedLIRInstruction(org.graalvm.compiler.lir.sparc.SPARCTailDelayedLIRInstruction) SPARCLIRInstructionMixin(org.graalvm.compiler.lir.sparc.SPARCLIRInstructionMixin) DebugContext(org.graalvm.compiler.debug.DebugContext) SizeEstimate(org.graalvm.compiler.lir.sparc.SPARCLIRInstructionMixin.SizeEstimate)

Example 32 with LIRInstruction

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

the class AMD64HotSpotLIRGenerator method beforeRegisterAllocation.

@Override
public void beforeRegisterAllocation() {
    super.beforeRegisterAllocation();
    boolean hasDebugInfo = getResult().getLIR().hasDebugInfo();
    AllocatableValue savedRbp = saveRbp.finalize(hasDebugInfo);
    if (hasDebugInfo) {
        getResult().setDeoptimizationRescueSlot(((AMD64FrameMapBuilder) getResult().getFrameMapBuilder()).allocateDeoptimizationRescueSlot());
    }
    getResult().setMaxInterpreterFrameSize(debugInfoBuilder.maxInterpreterFrameSize());
    for (AMD64HotSpotRestoreRbpOp op : epilogueOps) {
        op.setSavedRbp(savedRbp);
    }
    if (BenchmarkCounters.enabled) {
        // ensure that the rescue slot is available
        LIRInstruction op = getOrInitRescueSlotOp();
        // insert dummy instruction into the start block
        LIR lir = getResult().getLIR();
        ArrayList<LIRInstruction> instructions = lir.getLIRforBlock(lir.getControlFlowGraph().getStartBlock());
        instructions.add(1, op);
        lir.getDebug().dump(DebugContext.INFO_LEVEL, lir, "created rescue dummy op");
    }
}
Also used : LIR(org.graalvm.compiler.lir.LIR) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Example 33 with LIRInstruction

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

the class Instance method run.

public void run(LIRGenerationResult lirGenRes) {
    LIR ir = lirGenRes.getLIR();
    DebugContext debug = ir.getDebug();
    FrameMap frameMap = lirGenRes.getFrameMap();
    for (AbstractBlockBase<?> block : ir.linearScanOrder()) {
        for (LIRInstruction op : ir.getLIRforBlock(block)) {
            op.forEachState((instruction, state) -> doState(debug, frameMap, instruction, state));
        }
    }
}
Also used : FrameMap(org.graalvm.compiler.lir.framemap.FrameMap) LIR(org.graalvm.compiler.lir.LIR) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 34 with LIRInstruction

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

the class MatchRuleTest method test1.

/**
 * Verifies, if the match rules in AMD64NodeMatchRules do work on the graphs by compiling and
 * checking if the expected LIR instruction show up.
 */
@Test
public void test1() {
    compile(getResolvedJavaMethod("test1Snippet"), null);
    boolean found = false;
    for (LIRInstruction ins : lir.getLIRforBlock(lir.codeEmittingOrder()[0])) {
        if (ins instanceof MemoryConstOp && ((MemoryConstOp) ins).getOpcode().toString().equals("CMP")) {
            assertFalse("MemoryConstOp expected only once in first block", found);
            found = true;
        }
    }
    assertTrue("Memory compare must be in the LIR", found);
}
Also used : LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) MemoryConstOp(org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer.MemoryConstOp) LIRTest(org.graalvm.compiler.lir.jtt.LIRTest) Test(org.junit.Test)

Example 35 with LIRInstruction

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

the class LinearScanAssignLocationsPhase method debugInfoProcedure.

private Value debugInfoProcedure(LIRInstruction op, Value operand) {
    if (isVirtualStackSlot(operand)) {
        return operand;
    }
    int tempOpId = op.id();
    OperandMode mode = OperandMode.USE;
    AbstractBlockBase<?> block = allocator.blockForId(tempOpId);
    if (block.getSuccessorCount() == 1 && tempOpId == allocator.getLastLirInstructionId(block)) {
        /*
             * Generating debug information for the last instruction of a block. If this instruction
             * is a branch, spill moves are inserted before this branch and so the wrong operand
             * would be returned (spill moves at block boundaries are not considered in the live
             * ranges of intervals).
             *
             * Solution: use the first opId of the branch target block instead.
             */
        final LIRInstruction instr = allocator.getLIR().getLIRforBlock(block).get(allocator.getLIR().getLIRforBlock(block).size() - 1);
        if (instr instanceof StandardOp.JumpOp) {
            if (allocator.getBlockData(block).liveOut.get(allocator.operandNumber(operand))) {
                tempOpId = allocator.getFirstLirInstructionId(block.getSuccessors()[0]);
                mode = OperandMode.DEF;
            }
        }
    }
    /*
         * Get current location of operand. The operand must be live because debug information is
         * considered when building the intervals if the interval is not live, colorLirOperand will
         * cause an assert on failure.
         */
    Value result = colorLirOperand(op, (Variable) operand, mode);
    assert !allocator.hasCall(tempOpId) || isStackSlotValue(result) || isJavaConstant(result) || !allocator.isCallerSave(result) : "cannot have caller-save register operands at calls";
    return result;
}
Also used : LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) LIRValueUtil.isStackSlotValue(org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue) ConstantValue(org.graalvm.compiler.lir.ConstantValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) OperandMode(org.graalvm.compiler.lir.LIRInstruction.OperandMode)

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