Search in sources :

Example 1 with SPARCLIRInstructionMixin

use of org.graalvm.compiler.lir.sparc.SPARCLIRInstructionMixin 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)

Aggregations

DebugContext (org.graalvm.compiler.debug.DebugContext)1 LIRInstruction (org.graalvm.compiler.lir.LIRInstruction)1 SPARCLIRInstructionMixin (org.graalvm.compiler.lir.sparc.SPARCLIRInstructionMixin)1 SizeEstimate (org.graalvm.compiler.lir.sparc.SPARCLIRInstructionMixin.SizeEstimate)1 SPARCTailDelayedLIRInstruction (org.graalvm.compiler.lir.sparc.SPARCTailDelayedLIRInstruction)1