changeset 2875:3570f1f7903e

Changed GraphBuilder to inherit from Phase.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 08 Jun 2011 10:12:45 +0200
parents d90bf514d647
children c779525b27ad 7f584bf507ed
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/GraphBuilder.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/Inlining.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Or.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameStateBuilder.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java
diffstat 6 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/GraphBuilder.java	Wed Jun 08 08:59:54 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/GraphBuilder.java	Wed Jun 08 10:12:45 2011 +0200
@@ -47,7 +47,7 @@
  * A number of optimizations may be performed during parsing of the bytecode, including value
  * numbering, inlining, constant folding, strength reduction, etc.
  */
-public final class GraphBuilder {
+public final class GraphBuilder extends Phase {
 
     /**
      * The minimum value to which {@link C1XOptions#TraceBytecodeParserLevel} must be set to trace
@@ -62,7 +62,7 @@
     public static final int TRACELEVEL_STATE = 2;
 
     private final C1XCompilation compilation;
-    private final CompilerGraph graph;
+    private CompilerGraph graph;
 
     private final CiStatistics stats;
     private final RiRuntime runtime;
@@ -71,7 +71,7 @@
 
     private final BytecodeStream stream;           // the bytecode stream
     private final LogStream log;
-    private final FrameStateBuilder frameState;          // the current execution state
+    private FrameStateBuilder frameState;          // the current execution state
 
     // bci-to-block mapping
     private Block[] blockFromBci;
@@ -97,6 +97,8 @@
     private final Set<Block> blocksOnWorklist = new HashSet<Block>();
     private final Set<Block> blocksVisited = new HashSet<Block>();
 
+    private final boolean createUnwind;
+
 
     /**
      * Creates a new, initialized, {@code GraphBuilder} instance for a given compilation.
@@ -105,9 +107,8 @@
      * @param ir the IR to build the graph into
      * @param graph
      */
-    public GraphBuilder(C1XCompilation compilation, RiMethod method, CompilerGraph graph) {
+    public GraphBuilder(C1XCompilation compilation, RiMethod method, boolean createUnwind) {
         this.compilation = compilation;
-        this.graph = graph;
 
         this.runtime = compilation.runtime;
         this.method = method;
@@ -116,7 +117,15 @@
         this.stream = new BytecodeStream(method.code());
 
         this.constantPool = runtime.getConstantPool(method);
+        this.createUnwind = createUnwind;
+    }
+
+    @Override
+    protected void run(Graph graph) {
+        assert graph != null;
+        this.graph = (CompilerGraph) graph;
         this.frameState = new FrameStateBuilder(method, graph);
+        build();
     }
 
     /**
@@ -125,7 +134,7 @@
      * @param createUnwind setting this to true will always generate an unwind block, even if there is no exception
      *            handler and the method is not synchronized
      */
-    public void build(boolean createUnwind) {
+    private void build() {
         if (log != null) {
             log.println();
             log.println("Compiling " + method);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java	Wed Jun 08 08:59:54 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java	Wed Jun 08 10:12:45 2011 +0200
@@ -157,7 +157,7 @@
 
     private void buildGraph() {
         // Graph builder must set the startBlock and the osrEntryBlock
-        new GraphBuilder(compilation, compilation.method, compilation.graph).build(false);
+        new GraphBuilder(compilation, compilation.method, false).apply(compilation.graph);
 
 //        CompilerGraph duplicate = new CompilerGraph();
 //        Map<Node, Node> replacements = new HashMap<Node, Node>();
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/Inlining.java	Wed Jun 08 08:59:54 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/Inlining.java	Wed Jun 08 10:12:45 2011 +0200
@@ -158,7 +158,7 @@
         }
 
         CompilerGraph graph = new CompilerGraph();
-        new GraphBuilder(compilation, method, graph).build(true);
+        new GraphBuilder(compilation, method, true).apply(graph);
 
         boolean withReceiver = !Modifier.isStatic(method.accessFlags());
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Or.java	Wed Jun 08 08:59:54 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Or.java	Wed Jun 08 10:12:45 2011 +0200
@@ -52,8 +52,7 @@
 
     @Override
     public Node copy(Graph into) {
-        Or x = new Or(kind, null, null, into);
-        return x;
+        return new Or(kind, null, null, into);
     }
 
     @SuppressWarnings("unchecked")
@@ -68,7 +67,6 @@
     private static class OrCanonicalizerOp implements CanonicalizerOp {
         @Override
         public Node canonical(Node node) {
-            assert node instanceof Or;
             Or or = (Or) node;
             CiKind kind = or.kind;
             Graph graph = or.graph();
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameStateBuilder.java	Wed Jun 08 08:59:54 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameStateBuilder.java	Wed Jun 08 10:12:45 2011 +0200
@@ -46,6 +46,7 @@
     private final RiMethod method;
 
     public FrameStateBuilder(RiMethod method, Graph graph) {
+        assert graph != null;
         this.method = method;
         this.graph = graph;
         this.locals = new Value[method.maxLocals()];
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java	Wed Jun 08 08:59:54 2011 +0200
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java	Wed Jun 08 10:12:45 2011 +0200
@@ -42,7 +42,7 @@
     final ArrayList<Integer> predecessorsIndex;
 
     public Node(int inputCount, int successorCount, Graph graph) {
-        assert graph != null;
+        assert graph != null : "cannot create a node for a null graph";
         this.graph = graph;
         this.id = graph.register(this);
         this.inputs = new NodeArray(this, inputCount);