changeset 19217:1f2a7647c8e9

LowLevelPhase: add support for LIR dumping.
author Josef Eisl <josef.eisl@jku.at>
date Mon, 09 Feb 2015 11:09:19 +0100
parents baa9fb17fd91
children 58f59bada2c1
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LowLevelPhase.java
diffstat 2 files changed, 43 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- 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<T> c = new LowLevelMidTierPhase.Context<>(codeEmittingOrder, linearScanOrder);
-            try (Scope s = Debug.scope("Allocator")) {
-                if (backend.shouldAllocateRegisters()) {
-                    new LinearScanPhase<T>().apply(target, lirGenRes, c);
-                }
+            if (backend.shouldAllocateRegisters()) {
+                new LinearScanPhase<T>().apply(target, lirGenRes, c);
             }
 
-            try (Scope s1 = Debug.scope("BuildFrameMap")) {
-                // build frame map
-                if (LSStackSlotAllocator.Options.LSStackSlotAllocation.getValue()) {
-                    new LSStackSlotAllocator<T>().apply(target, lirGenRes, c);
-                } else {
-                    new SimpleStackSlotAllocator<T>().apply(target, lirGenRes, c);
-                }
-                Debug.dump(lir, "After FrameMap building");
+            // build frame map
+            if (LSStackSlotAllocator.Options.LSStackSlotAllocation.getValue()) {
+                new LSStackSlotAllocator<T>().apply(target, lirGenRes, c);
+            } else {
+                new SimpleStackSlotAllocator<T>().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<T>().apply(target, lirGenRes, c);
-                }
+            if (backend.shouldAllocateRegisters()) {
+                // currently we mark locations only if we do register allocation
+                new LocationMarker<T>().apply(target, lirGenRes, c);
             }
         }
 
@@ -395,8 +383,6 @@
                 new RedundantMoveElimination<T>().apply(target, lirGenRes, c);
             }
             new NullCheckOptimizer<T>().apply(target, lirGenRes, c);
-
-            Debug.dump(lir, "After control flow optimization");
         }
 
         return lirGenRes;
--- 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<C> {
 
+    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;
+    }
+
 }