changeset 4203:847e9dcb4980

Add graph builder to the phase plan.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 03 Jan 2012 17:31:23 +0100
parents 93a99ff252d0
children 4df4499e0289
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graphbuilder/GraphBuilderPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/VMExitsNative.java graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/StructuredGraph.java graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/GraphTest.java
diffstat 9 files changed, 54 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java	Tue Jan 03 16:47:54 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java	Tue Jan 03 17:31:23 2012 +0100
@@ -37,7 +37,6 @@
 import com.oracle.max.graal.compiler.alloc.*;
 import com.oracle.max.graal.compiler.asm.*;
 import com.oracle.max.graal.compiler.gen.*;
-import com.oracle.max.graal.compiler.graphbuilder.*;
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.observer.*;
 import com.oracle.max.graal.compiler.phases.*;
@@ -76,7 +75,7 @@
      * @param stats externally supplied statistics object to be used if not {@code null}
      * @param debugInfoLevel TODO
      */
-    public GraalCompilation(GraalContext context, GraalCompiler compiler, RiResolvedMethod method, StructuredGraph graph, int osrBCI, CiStatistics stats, DebugInfoLevel debugInfoLevel) {
+    private GraalCompilation(GraalContext context, GraalCompiler compiler, RiResolvedMethod method, StructuredGraph graph, int osrBCI, CiStatistics stats, DebugInfoLevel debugInfoLevel) {
         if (osrBCI != -1) {
             throw new CiBailout("No OSR supported");
         }
@@ -93,7 +92,7 @@
     }
 
     public GraalCompilation(GraalContext context, GraalCompiler compiler, RiResolvedMethod method, int osrBCI, CiStatistics stats, DebugInfoLevel debugInfoLevel) {
-        this(context, compiler, method, new StructuredGraph(), osrBCI, stats, debugInfoLevel);
+        this(context, compiler, method, new StructuredGraph(method), osrBCI, stats, debugInfoLevel);
     }
 
 
@@ -189,11 +188,7 @@
             context().timers.startScope("HIR");
 
             if (graph.start().next() == null) {
-                GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(compiler.runtime, method, stats);
-                graphBuilderPhase.apply(graph, context());
-
                 plan.runPhases(PhasePosition.AFTER_PARSING, graph, context());
-
                 new DeadCodeEliminationPhase().apply(graph, context());
             } else {
                 if (context().isObserved()) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Tue Jan 03 16:47:54 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Tue Jan 03 17:31:23 2012 +0100
@@ -32,7 +32,6 @@
 import com.oracle.max.graal.compiler.stub.*;
 import com.oracle.max.graal.compiler.target.*;
 import com.oracle.max.graal.cri.*;
-import com.oracle.max.graal.nodes.*;
 
 public class GraalCompiler {
 
@@ -118,12 +117,6 @@
         }
     }
 
-    public CiTargetMethod compileMethod(RiResolvedMethod method, StructuredGraph graph, PhasePlan plan) {
-        assert graph.verify();
-        GraalCompilation compilation = new GraalCompilation(context, this, method, graph, -1, null, CiCompiler.DebugInfoLevel.FULL);
-        return compilation.compile(plan);
-    }
-
     private void init() {
         final List<XirTemplate> xirTemplateStubs = xir.makeTemplates(backend.newXirAssembler());
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graphbuilder/GraphBuilderPhase.java	Tue Jan 03 16:47:54 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graphbuilder/GraphBuilderPhase.java	Tue Jan 03 17:31:23 2012 +0100
@@ -70,11 +70,11 @@
 
     private final CiStatistics stats;
     private final RiRuntime runtime;
-    private final RiResolvedMethod method;
-    private final RiConstantPool constantPool;
+    private RiConstantPool constantPool;
     private RiExceptionHandler[] exceptionHandlers;
+    private RiResolvedMethod method;
 
-    private final BytecodeStream stream;           // the bytecode stream
+    private BytecodeStream stream;           // the bytecode stream
     private final LogStream log;
 
     private FrameStateBuilder frameState;          // the current execution state
@@ -95,8 +95,8 @@
 
     private FixedWithNextNode lastInstr;                 // the last instruction added
 
-    private final Set<Block> blocksOnWorklist = new HashSet<>();
-    private final Set<Block> blocksVisited = new HashSet<>();
+    private Set<Block> blocksOnWorklist;
+    private Set<Block> blocksVisited;
 
     private BitSet canTrapBitSet;
 
@@ -104,27 +104,33 @@
 
     private final GraphBuilderConfiguration config;
 
-    public GraphBuilderPhase(RiRuntime runtime, RiResolvedMethod method) {
-        this(runtime, method, null);
-    }
-
-    public GraphBuilderPhase(RiRuntime runtime, RiResolvedMethod method, CiStatistics stats) {
-        this(runtime, method, stats, GraphBuilderConfiguration.getDefault());
+    public GraphBuilderPhase(RiRuntime runtime) {
+        this(runtime, null);
     }
 
-    public GraphBuilderPhase(RiRuntime runtime, RiResolvedMethod method, CiStatistics stats, GraphBuilderConfiguration config) {
+    public GraphBuilderPhase(RiRuntime runtime, CiStatistics stats) {
+        this(runtime, stats, GraphBuilderConfiguration.getDefault());
+    }
+
+    public GraphBuilderPhase(RiRuntime runtime, CiStatistics stats, GraphBuilderConfiguration config) {
         this.config = config;
         this.runtime = runtime;
-        this.method = method;
         this.stats = stats;
         this.log = GraalOptions.TraceBytecodeParserLevel > 0 ? new LogStream(TTY.out()) : null;
-        assert method.code() != null : "method must contain bytecodes: " + method;
-        this.stream = new BytecodeStream(method.code());
-        this.constantPool = method.getConstantPool();
     }
 
     @Override
     protected void run(StructuredGraph graph) {
+        method = graph.method();
+        assert method.code() != null : "method must contain bytecodes: " + method;
+        this.stream = new BytecodeStream(method.code());
+        this.constantPool = method.getConstantPool();
+        this.blocksOnWorklist = new HashSet<>();
+        this.blocksVisited = new HashSet<>();
+        unwindBlock = null;
+        returnBlock = null;
+        methodSynchronizedObject = null;
+        exceptionHandlers = null;
         assert graph != null;
         this.currentGraph = graph;
         this.frameState = new FrameStateBuilder(method, method.maxLocals(), method.maxStackSize(), graph);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java	Tue Jan 03 16:47:54 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java	Tue Jan 03 17:31:23 2012 +0100
@@ -28,7 +28,6 @@
 import com.oracle.max.criutils.*;
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.graph.*;
-import com.oracle.max.graal.compiler.graphbuilder.*;
 import com.oracle.max.graal.cri.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
@@ -275,18 +274,12 @@
     private final GraalRuntime runtime;
     private final CiAssumptions assumptions;
     private final PhasePlan plan;
-    private final GraphBuilderConfiguration config;
 
     public EscapeAnalysisPhase(CiTarget target, GraalRuntime runtime, CiAssumptions assumptions, PhasePlan plan) {
-        this(target, runtime, assumptions, plan, GraphBuilderConfiguration.getDefault(plan));
-    }
-
-    public EscapeAnalysisPhase(CiTarget target, GraalRuntime runtime, CiAssumptions assumptions, PhasePlan plan, GraphBuilderConfiguration config) {
         this.runtime = runtime;
         this.target = target;
         this.assumptions = assumptions;
         this.plan = plan;
-        this.config = config;
     }
 
     public static class EscapeRecord {
@@ -464,7 +457,7 @@
             if (GraalOptions.TraceEscapeAnalysis || GraalOptions.PrintEscapeAnalysis) {
                 TTY.println("Trying inlining to get a non-escaping object for %s", node);
             }
-            new InliningPhase(target, runtime, invokes, assumptions, plan, config).apply(graph, currentContext);
+            new InliningPhase(target, runtime, invokes, assumptions, plan).apply(graph, currentContext);
             new DeadCodeEliminationPhase().apply(graph, currentContext);
             if (node.isDeleted()) {
                 if (GraalOptions.TraceEscapeAnalysis || GraalOptions.PrintEscapeAnalysis) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Tue Jan 03 16:47:54 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Tue Jan 03 17:31:23 2012 +0100
@@ -55,19 +55,12 @@
 
     private final PhasePlan plan;
 
-    private final GraphBuilderConfiguration config;
-
     public InliningPhase(CiTarget target, GraalRuntime runtime, Collection<Invoke> hints, CiAssumptions assumptions, PhasePlan plan) {
-        this(target, runtime, hints, assumptions, plan, GraphBuilderConfiguration.getDefault(plan));
-    }
-
-    public InliningPhase(CiTarget target, GraalRuntime runtime, Collection<Invoke> hints, CiAssumptions assumptions, PhasePlan plan, GraphBuilderConfiguration config) {
         this.target = target;
         this.runtime = runtime;
         this.hints = hints;
         this.assumptions = assumptions;
         this.plan = plan;
-        this.config = config;
     }
 
     @SuppressWarnings("unchecked")
@@ -166,8 +159,7 @@
 
     @Override
     public StructuredGraph buildGraph(RiResolvedMethod method) {
-        StructuredGraph newGraph = new StructuredGraph();
-        new GraphBuilderPhase(runtime, method, null, config).apply(newGraph, currentContext, false);
+        StructuredGraph newGraph = new StructuredGraph(method);
 
         if (plan != null) {
             plan.runPhases(PhasePosition.AFTER_PARSING, newGraph, currentContext);
@@ -220,8 +212,8 @@
         int count;
         if (GraalOptions.ParseBeforeInlining) {
             if (!parsedMethods.containsKey(method)) {
-                StructuredGraph newGraph = new StructuredGraph();
-                new GraphBuilderPhase(runtime, method, null).apply(newGraph, currentContext, false);
+                StructuredGraph newGraph = new StructuredGraph(method);
+                new GraphBuilderPhase(runtime, null).apply(newGraph, currentContext, false);
                 new CanonicalizerPhase(target, runtime, assumptions).apply(newGraph, currentContext, false);
                 count = graphComplexity(newGraph);
                 parsedMethods.put(method, count);
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/VMExitsNative.java	Tue Jan 03 16:47:54 2012 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/VMExitsNative.java	Tue Jan 03 17:31:23 2012 +0100
@@ -31,7 +31,9 @@
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.criutils.*;
 import com.oracle.max.graal.compiler.*;
+import com.oracle.max.graal.compiler.graphbuilder.*;
 import com.oracle.max.graal.compiler.phases.*;
+import com.oracle.max.graal.compiler.phases.PhasePlan.*;
 import com.oracle.max.graal.hotspot.ri.*;
 import com.oracle.max.graal.hotspot.server.*;
 import com.oracle.max.graal.snippets.*;
@@ -163,7 +165,10 @@
             Runnable runnable = new Runnable() {
                 public void run() {
                     try {
-                        CiTargetMethod result = compiler.getCompiler().compileMethod(method, -1, null, DebugInfoLevel.FULL);
+                        PhasePlan plan = new PhasePlan();
+                        GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(compiler.getRuntime(), null);
+                        plan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase);
+                        CiTargetMethod result = compiler.getCompiler().compileMethod(method, -1, null, DebugInfoLevel.FULL, plan);
                         HotSpotTargetMethod.installMethod(compiler, method, result, true);
                     } catch (CiBailout bailout) {
                         if (GraalOptions.ExitVMOnBailout) {
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/StructuredGraph.java	Tue Jan 03 16:47:54 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/StructuredGraph.java	Tue Jan 03 17:31:23 2012 +0100
@@ -24,6 +24,7 @@
 
 import java.util.*;
 
+import com.oracle.max.cri.ri.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.java.*;
 
@@ -34,26 +35,40 @@
  */
 public class StructuredGraph extends Graph {
     private final BeginNode start;
+    private final RiResolvedMethod method;
 
     /**
      * Creates a new Graph containing a single {@link BeginNode} as the {@link #start() start} node.
      */
     public StructuredGraph(String name) {
+        this(name, null);
+    }
+
+    public StructuredGraph(String name, RiResolvedMethod method) {
         super(name);
         this.start = add(new BeginNode());
+        this.method = method;
     }
 
     /**
      * Creates a new Graph containing a single {@link BeginNode} as the {@link #start() start} node.
      */
     public StructuredGraph() {
-        this(null);
+        this((String) null);
+    }
+
+    public StructuredGraph(RiResolvedMethod method) {
+        this(null, method);
     }
 
     public BeginNode start() {
         return start;
     }
 
+    public RiResolvedMethod method() {
+        return method;
+    }
+
     @Override
     public StructuredGraph copy() {
         return copy(name);
--- a/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java	Tue Jan 03 16:47:54 2012 +0100
+++ b/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java	Tue Jan 03 17:31:23 2012 +0100
@@ -129,8 +129,8 @@
     private static StructuredGraph buildSnippetGraph(RiResolvedMethod snippetRiMethod, GraalRuntime runtime, CiTarget target, GraalContext context, BoxingMethodPool pool, PhasePlan plan, IdealGraphPrinterObserver observer) {
 
         GraphBuilderConfiguration config = GraphBuilderConfiguration.getDeoptFreeDefault();
-        GraphBuilderPhase graphBuilder = new GraphBuilderPhase(runtime, snippetRiMethod, null, config);
-        StructuredGraph graph = new StructuredGraph();
+        GraphBuilderPhase graphBuilder = new GraphBuilderPhase(runtime, null, config);
+        StructuredGraph graph = new StructuredGraph(snippetRiMethod);
         graphBuilder.apply(graph, context);
 
         if (observer != null) {
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/GraphTest.java	Tue Jan 03 16:47:54 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/GraphTest.java	Tue Jan 03 17:31:23 2012 +0100
@@ -100,8 +100,8 @@
      */
     protected StructuredGraph parse(Method m) {
         RiResolvedMethod riMethod = runtime.getRiMethod(m);
-        StructuredGraph graph = new StructuredGraph();
-        new GraphBuilderPhase(runtime, riMethod, null, GraphBuilderConfiguration.getDeoptFreeDefault()).apply(graph);
+        StructuredGraph graph = new StructuredGraph(riMethod);
+        new GraphBuilderPhase(runtime, null, GraphBuilderConfiguration.getDeoptFreeDefault()).apply(graph);
         return graph;
     }