# HG changeset patch # User Josef Eisl # Date 1423476559 -3600 # Node ID 1f2a7647c8e90c0502f024e6676952962b0ebe60 # Parent baa9fb17fd9174e81f0690574101f171bc715d0b LowLevelPhase: add support for LIR dumping. diff -r baa9fb17fd91 -r 1f2a7647c8e9 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Mon Feb 09 09:41:42 2015 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Mon Feb 09 11:09:19 2015 +0100 @@ -352,37 +352,25 @@ try (Scope s0 = Debug.scope("LowLevelHighTier")) { LowLevelHighTierPhase.Context c = new LowLevelHighTierPhase.Context(lirGen); if (ConstantLoadOptimization.Options.ConstantLoadOptimization.getValue()) { - try (Scope s = Debug.scope("ConstantLoadOptimization", lir)) { - new ConstantLoadOptimization().apply(target, lirGenRes, c); - Debug.dump(lir, "After constant load optimization"); - } catch (Throwable e) { - throw Debug.handle(e); - } + new ConstantLoadOptimization().apply(target, lirGenRes, c); } } try (Scope s0 = Debug.scope("LowLevelMidTier")) { LowLevelMidTierPhase.Context c = new LowLevelMidTierPhase.Context<>(codeEmittingOrder, linearScanOrder); - try (Scope s = Debug.scope("Allocator")) { - if (backend.shouldAllocateRegisters()) { - new LinearScanPhase().apply(target, lirGenRes, c); - } + if (backend.shouldAllocateRegisters()) { + new LinearScanPhase().apply(target, lirGenRes, c); } - try (Scope s1 = Debug.scope("BuildFrameMap")) { - // build frame map - if (LSStackSlotAllocator.Options.LSStackSlotAllocation.getValue()) { - new LSStackSlotAllocator().apply(target, lirGenRes, c); - } else { - new SimpleStackSlotAllocator().apply(target, lirGenRes, c); - } - Debug.dump(lir, "After FrameMap building"); + // build frame map + if (LSStackSlotAllocator.Options.LSStackSlotAllocation.getValue()) { + new LSStackSlotAllocator().apply(target, lirGenRes, c); + } else { + new SimpleStackSlotAllocator().apply(target, lirGenRes, c); } - try (Scope s1 = Debug.scope("MarkLocations")) { - if (backend.shouldAllocateRegisters()) { - // currently we mark locations only if we do register allocation - new LocationMarker().apply(target, lirGenRes, c); - } + if (backend.shouldAllocateRegisters()) { + // currently we mark locations only if we do register allocation + new LocationMarker().apply(target, lirGenRes, c); } } @@ -395,8 +383,6 @@ new RedundantMoveElimination().apply(target, lirGenRes, c); } new NullCheckOptimizer().apply(target, lirGenRes, c); - - Debug.dump(lir, "After control flow optimization"); } return lirGenRes; diff -r baa9fb17fd91 -r 1f2a7647c8e9 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelPhase.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelPhase.java Mon Feb 09 09:41:42 2015 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelPhase.java Mon Feb 09 11:09:19 2015 +0100 @@ -36,6 +36,10 @@ */ public abstract class LowLevelPhase { + private static final int PHASE_DUMP_LEVEL = 2; + + private CharSequence name; + /** * Records time spent within {@link #apply}. */ @@ -47,17 +51,41 @@ private final DebugMemUseTracker memUseTracker; public LowLevelPhase() { - timer = Debug.timer("LowLevelPhaseTime_%s", getClass()); - memUseTracker = Debug.memUseTracker("LowLevelPhaseMemUse_%s", getClass()); + timer = Debug.timer("LowLevelPhaseTime_%s", getName()); + memUseTracker = Debug.memUseTracker("LowLevelPhaseMemUse_%s", getName()); } - public void apply(TargetDescription target, LIRGenerationResult lirGenRes, C context) { - try (TimerCloseable a = timer.start(); Scope s = Debug.scope(getClass(), this); Closeable c = memUseTracker.start()) { + public final void apply(TargetDescription target, LIRGenerationResult lirGenRes, C context) { + apply(target, lirGenRes, context, true); + } + + public final void apply(TargetDescription target, LIRGenerationResult lirGenRes, C context, boolean dumpLIR) { + try (TimerCloseable a = timer.start(); Scope s = Debug.scope(getName(), this); Closeable c = memUseTracker.start()) { run(target, lirGenRes, context); + if (dumpLIR && Debug.isDumpEnabled(PHASE_DUMP_LEVEL)) { + Debug.dump(PHASE_DUMP_LEVEL, lirGenRes.getLIR(), "After phase %s", getName()); + } } catch (Throwable e) { throw Debug.handle(e); } } protected abstract void run(TargetDescription target, LIRGenerationResult lirGenRes, C context); + + protected CharSequence createName() { + String className = LowLevelPhase.this.getClass().getName(); + String s = className.substring(className.lastIndexOf(".") + 1); // strip the package name + if (s.endsWith("Phase")) { + s = s.substring(0, s.length() - "Phase".length()); + } + return s; + } + + public final CharSequence getName() { + if (name == null) { + name = createName(); + } + return name; + } + }