changeset 2603:01c5c0443158

new node layout: Phi
author Lukas Stadler <lukas.stadler@jku.at>
date Fri, 06 May 2011 11:18:15 +0200
parents 0c6564c254af
children f21f430a6ef2 39aa89baa165
files graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java graal/GraalCompiler/src/com/sun/c1x/ir/Instruction.java graal/GraalCompiler/src/com/sun/c1x/ir/Local.java graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java graal/GraalCompiler/src/com/sun/c1x/ir/Value.java graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java graal/GraalGraph/src/com/oracle/graal/graph/vis/GraphvizPrinter.java
diffstat 9 files changed, 81 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java	Fri May 06 10:25:37 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java	Fri May 06 11:18:15 2011 +0200
@@ -140,30 +140,32 @@
             final String dotPattern = dot;
             addCompilationObserver(new CompilationObserver() {
                 private Graph graph;
+                private int n;
                 public void compilationStarted(CompilationEvent event) {
+                    n = 0;
                 }
                 public void compilationFinished(CompilationEvent event) {
-                    String name = event.getMethod().holder().name();
-                    name = name.substring(1, name.length() - 1).replace('/', '.');
-                    name = name + "." + event.getMethod().name();
-                    if (name.matches(dotPattern)) {
-                        ByteArrayOutputStream out = new ByteArrayOutputStream();
-                        GraphvizPrinter printer = new GraphvizPrinter(out);
-                        printer.begin("Simple test");
-                        printer.print(graph);
-                        printer.end();
-
-                        try {
-                            GraphvizRunner.process(GraphvizRunner.DOT_COMMAND, new ByteArrayInputStream(out.toByteArray()),
-                                            new FileOutputStream(name + ".pdf"), "pdf");
-                        } catch (Exception e) {
-                            e.printStackTrace();
-                        }
-                    }
                 }
                 public void compilationEvent(CompilationEvent event) {
                     if (event.getStartBlock() != null) {
                         graph = event.getStartBlock().graph();
+                        String name = event.getMethod().holder().name();
+                        name = name.substring(1, name.length() - 1).replace('/', '.');
+                        name = name + "." + event.getMethod().name();
+                        if (name.matches(dotPattern)) {
+                            ByteArrayOutputStream out = new ByteArrayOutputStream();
+                            GraphvizPrinter printer = new GraphvizPrinter(out);
+                            printer.begin(name);
+                            printer.print(graph);
+                            printer.end();
+
+                            try {
+                                GraphvizRunner.process(GraphvizRunner.DOT_COMMAND, new ByteArrayInputStream(out.toByteArray()),
+                                                new FileOutputStream(name + "_" + (n++) + event.getLabel() + ".pdf"), "pdf");
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }
+                        }
                     }
                 }
             });
--- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java	Fri May 06 10:25:37 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java	Fri May 06 11:18:15 2011 +0200
@@ -1217,7 +1217,7 @@
         int index = 0;
         if (!isStatic(method.accessFlags())) {
             // add the receiver and assume it is non null
-            Local local = new Local(method.holder().kind(), index);
+            Local local = new Local(method.holder().kind(), index, graph);
             local.setFlag(Value.Flag.NonNull, true);
             local.setDeclaredType(method.holder());
             state.storeLocal(index, local);
@@ -1229,7 +1229,7 @@
         for (int i = 0; i < max; i++) {
             RiType type = sig.argumentTypeAt(i, accessingClass);
             CiKind kind = type.kind().stackKind();
-            Local local = new Local(kind, index);
+            Local local = new Local(kind, index, graph);
             if (type.isResolved()) {
                 local.setDeclaredType(type);
             }
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java	Fri May 06 10:25:37 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java	Fri May 06 11:18:15 2011 +0200
@@ -443,7 +443,7 @@
                 throw new CiBailout("jsr/ret too complicated");
             }
 
-            existingState.merge(this, newState);
+            existingState.merge(this, newState, graph());
         }
     }
 
@@ -465,13 +465,13 @@
         int stackSize = newState.stackSize();
         for (int i = 0; i < stackSize; i++) {
             // always insert phis for the stack
-            newState.setupPhiForStack(this, i);
+            newState.setupPhiForStack(this, i, graph());
         }
         int localsSize = newState.localsSize();
         for (int i = 0; i < localsSize; i++) {
             Value x = newState.localAt(i);
             if (x != null) {
-                newState.setupPhiForLocal(this, i);
+                newState.setupPhiForLocal(this, i, graph());
             }
         }
     }
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Instruction.java	Fri May 06 10:25:37 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Instruction.java	Fri May 06 11:18:15 2011 +0200
@@ -97,10 +97,6 @@
         C1XMetrics.HIRInstructions++;
     }
 
-    public Instruction(CiKind kind) {
-        this(kind, 0, 0, null);
-    }
-
     /**
      * Gets the bytecode index of this instruction.
      * @return the bytecode index of this instruction
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Local.java	Fri May 06 10:25:37 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Local.java	Fri May 06 11:18:15 2011 +0200
@@ -22,6 +22,7 @@
  */
 package com.sun.c1x.ir;
 
+import com.oracle.graal.graph.*;
 import com.sun.c1x.debug.*;
 import com.sun.cri.ci.*;
 import com.sun.cri.ri.*;
@@ -29,16 +30,17 @@
 /**
  * The {@code Local} instruction is a placeholder for an incoming argument
  * to a function call.
- *
- * @author Ben L. Titzer
  */
 public final class Local extends Value {
 
+    private static final int INPUT_COUNT = 0;
+    private static final int SUCCESSOR_COUNT = 0;
+
     private final int javaIndex;
     private RiType declaredType;
 
-    public Local(CiKind kind, int javaIndex) {
-        super(kind);
+    public Local(CiKind kind, int javaIndex, Graph graph) {
+        super(kind, INPUT_COUNT, SUCCESSOR_COUNT, graph);
         this.javaIndex = javaIndex;
     }
 
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java	Fri May 06 10:25:37 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java	Fri May 06 11:18:15 2011 +0200
@@ -22,6 +22,7 @@
  */
 package com.sun.c1x.ir;
 
+import com.oracle.graal.graph.*;
 import com.sun.c1x.debug.*;
 import com.sun.c1x.value.*;
 import com.sun.cri.ci.*;
@@ -29,12 +30,36 @@
 /**
  * The {@code Phi} instruction represents the merging of dataflow
  * in the instruction graph. It refers to a join block and a variable.
- *
- * @author Ben L. Titzer
  */
 public final class Phi extends Value {
 
-    private final BlockBegin block;
+    private static final int INPUT_COUNT = 1;
+    private static final int INPUT_BLOCK = 0;
+
+    private static final int SUCCESSOR_COUNT = 0;
+
+    @Override
+    protected int inputCount() {
+        return super.inputCount() + INPUT_COUNT;
+    }
+
+    @Override
+    protected int successorCount() {
+        return super.successorCount() + SUCCESSOR_COUNT;
+    }
+
+    /**
+     * The join block for this phi.
+     */
+     @Override
+    public BlockBegin block() {
+        return (BlockBegin) inputs().get(super.inputCount() + INPUT_BLOCK);
+    }
+
+    public BlockBegin setBlock(Value n) {
+        return (BlockBegin) inputs().set(super.inputCount() + INPUT_BLOCK, n);
+    }
+
     private final int index;
 
     /**
@@ -42,20 +67,12 @@
      * @param kind the type of the variable
      * @param block the join point
      * @param index the index into the stack (if < 0) or local variables
+     * @param graph
      */
-    public Phi(CiKind kind, BlockBegin block, int index) {
-        super(kind);
-        this.block = block;
+    public Phi(CiKind kind, BlockBegin block, int index, Graph graph) {
+        super(kind, INPUT_COUNT, SUCCESSOR_COUNT, graph);
         this.index = index;
-    }
-
-    /**
-     * Get the join block for this phi.
-     * @return the join block of this phi
-     */
-    @Override
-    public BlockBegin block() {
-        return block;
+        setBlock(block);
     }
 
     /**
@@ -100,10 +117,10 @@
      */
     public Value inputAt(int i) {
         FrameState state;
-        if (block.isExceptionEntry()) {
-            state = block.exceptionHandlerStates().get(i);
+        if (block().isExceptionEntry()) {
+            state = block().exceptionHandlerStates().get(i);
         } else {
-            state = block.blockPredecessors().get(i).end().stateAfter();
+            state = block().blockPredecessors().get(i).end().stateAfter();
         }
         return inputIn(state);
     }
@@ -126,10 +143,10 @@
      * @return the number of inputs in this phi
      */
     public int phiInputCount() {
-        if (block.isExceptionEntry()) {
-            return block.exceptionHandlerStates().size();
+        if (block().isExceptionEntry()) {
+            return block().exceptionHandlerStates().size();
         } else {
-            return block.blockPredecessors().size();
+            return block().blockPredecessors().size();
         }
     }
 
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Value.java	Fri May 06 10:25:37 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Value.java	Fri May 06 11:18:15 2011 +0200
@@ -72,7 +72,7 @@
      * @param graph
      */
     public Value(CiKind kind, int inputCount, int successorCount, Graph graph) {
-        super(inputCount, successorCount, graph == null ? new Graph() : graph);
+        super(inputCount, successorCount, graph);
         assert kind == kind.stackKind() : kind + " != " + kind.stackKind();
         this.kind = kind;
     }
@@ -80,10 +80,6 @@
     ///////////////
     // TODO: remove when Value class changes are completed
 
-    public Value(CiKind kind) {
-        this(kind, 0, 0, null);
-    }
-
     @Override
     public Node copy(Graph into) {
         throw new UnsupportedOperationException();
--- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java	Fri May 06 10:25:37 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java	Fri May 06 11:18:15 2011 +0200
@@ -24,6 +24,7 @@
 
 import java.util.*;
 
+import com.oracle.graal.graph.*;
 import com.sun.c1x.*;
 import com.sun.c1x.graph.*;
 import com.sun.c1x.ir.*;
@@ -32,8 +33,6 @@
 /**
  * The {@code FrameState} class encapsulates the frame state (i.e. local variables and
  * operand stack) at a particular point in the abstract interpretation.
- *
- * @author Ben L. Titzer
  */
 public abstract class FrameState {
 
@@ -297,8 +296,9 @@
      * Inserts a phi statement into the stack at the specified stack index.
      * @param block the block begin for which we are creating the phi
      * @param i the index into the stack for which to create a phi
+     * @param graph
      */
-    public void setupPhiForStack(BlockBegin block, int i) {
+    public void setupPhiForStack(BlockBegin block, int i, Graph graph) {
         Value p = stackAt(i);
         if (p != null) {
             if (p instanceof Phi) {
@@ -307,7 +307,7 @@
                     return;
                 }
             }
-            values[maxLocals + i] = new Phi(p.kind, block, -i - 1);
+            values[maxLocals + i] = new Phi(p.kind, block, -i - 1, graph);
         }
     }
 
@@ -315,8 +315,9 @@
      * Inserts a phi statement for the local at the specified index.
      * @param block the block begin for which we are creating the phi
      * @param i the index of the local variable for which to create the phi
+     * @param graph
      */
-    public void setupPhiForLocal(BlockBegin block, int i) {
+    public void setupPhiForLocal(BlockBegin block, int i, Graph graph) {
         Value p = values[i];
         if (p instanceof Phi) {
             Phi phi = (Phi) p;
@@ -324,7 +325,7 @@
                 return;
             }
         }
-        storeLocal(i, new Phi(p.kind, block, i));
+        storeLocal(i, new Phi(p.kind, block, i, graph));
     }
 
     /**
@@ -384,7 +385,7 @@
         }
     }
 
-    public void merge(BlockBegin block, FrameState other) {
+    public void merge(BlockBegin block, FrameState other, Graph graph) {
         checkSize(other);
         for (int i = 0; i < valuesSize(); i++) {
             Value x = values[i];
@@ -403,10 +404,10 @@
                     }
                     if (i < maxLocals) {
                         // this a local
-                        setupPhiForLocal(block, i);
+                        setupPhiForLocal(block, i, graph);
                     } else {
                         // this is a stack slot
-                        setupPhiForStack(block, i - maxLocals);
+                        setupPhiForStack(block, i - maxLocals, graph);
                     }
                 }
             }
--- a/graal/GraalGraph/src/com/oracle/graal/graph/vis/GraphvizPrinter.java	Fri May 06 10:25:37 2011 +0200
+++ b/graal/GraalGraph/src/com/oracle/graal/graph/vis/GraphvizPrinter.java	Fri May 06 11:18:15 2011 +0200
@@ -117,7 +117,7 @@
         out.println("    <TD WIDTH=\"15\" HEIGHT=\"5\" PORT=\"predecessors\" BGCOLOR=\"rosybrown1\"></TD></TR></TABLE>");
         out.println("    </TD><TD COLSPAN=\"2\" CELLPADDING=\"0\" ALIGN=\"RIGHT\"><TABLE BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"0\"><TR>");
 
-        if (ninputs == 1 && nsuccessors == 1) {
+        if ((ninputs == 1 && nsuccessors == 1) || (ninputs == 0 && nsuccessors == 0)) {
             out.println("    <TD WIDTH=\"15\" HEIGHT=\"5\"></TD>");
         }
 
@@ -143,7 +143,7 @@
             out.println("    <TD WIDTH=\"15\" HEIGHT=\"5\"></TD>");
         }
 
-        if (ninputs == 1 && nsuccessors == 1) {
+        if ((ninputs == 1 && nsuccessors == 1) || (ninputs == 0 && nsuccessors == 0)) {
             out.println("    <TD WIDTH=\"15\" HEIGHT=\"5\"></TD>");
         }