changeset 2621:dd115f80acf8

changed stateAfter FrameState to successor (instead of input), checkstyle fixes, added fixed root node to graph
author Lukas Stadler <lukas.stadler@jku.at>
date Tue, 10 May 2011 11:55:12 +0200
parents a7ae14997372
children 91d3952f7eb7 8e44074058af
files graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.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/BlockEnd.java graal/GraalCompiler/src/com/sun/c1x/ir/MonitorEnter.java graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java graal/GraalCompiler/src/com/sun/c1x/value/FrameStateAccess.java graal/GraalGraph/src/com/oracle/graal/graph/Graph.java graal/GraalGraph/src/com/oracle/graal/graph/Root.java graal/GraalGraphviz/src/com/oracle/graal/graph/vis/GraphvizPrinter.java
diffstat 10 files changed, 149 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java	Mon May 09 19:12:55 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java	Tue May 10 11:55:12 2011 +0200
@@ -33,8 +33,6 @@
  * An edge between two blocks {@code A} and {@code B} is "critical" if {@code A}
  * has more than one successor and {@code B} has more than one predecessor. Such
  * edges are split by adding a block between the two blocks.
- *
- * @author Thomas Wuerthinger
  */
 public class CriticalEdgeFinder implements BlockClosure {
 
--- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java	Mon May 09 19:12:55 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java	Tue May 10 11:55:12 2011 +0200
@@ -44,9 +44,6 @@
  * The {@code GraphBuilder} class parses the bytecode of a method and builds the IR graph.
  * A number of optimizations may be performed during parsing of the bytecode, including value
  * numbering, inlining, constant folding, strength reduction, etc.
- *
- * @author Ben L. Titzer
- * @author Doug Simon
  */
 public final class GraphBuilder {
 
@@ -165,6 +162,7 @@
         // 1. create the start block
         ir.startBlock = new BlockBegin(0, ir.nextBlockNumber(), graph);
         BlockBegin startBlock = ir.startBlock;
+        graph.root().setStart(startBlock);
 
         // 2. compute the block map, setup exception handlers and get the entrypoint(s)
         blockMap = compilation.getBlockMap(rootMethod);
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java	Mon May 09 19:12:55 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java	Tue May 10 11:55:12 2011 +0200
@@ -44,7 +44,8 @@
     private static final int INPUT_COUNT = 1;
     private static final int INPUT_STATE_BEFORE = 0;
 
-    private static final int SUCCESSOR_COUNT = 0;
+    private static final int SUCCESSOR_COUNT = 1;
+    private static final int SUCCESSOR_END = 0;
 
     @Override
     protected int inputCount() {
@@ -69,6 +70,33 @@
         return (FrameState) inputs().set(super.inputCount() + INPUT_STATE_BEFORE, n);
     }
 
+    /**
+     * The last node in the block (which contains the successors).
+     */
+    public BlockEnd end() {
+        return (BlockEnd) successors().get(super.successorCount() + SUCCESSOR_END);
+    }
+
+    public void setEnd(BlockEnd end) {
+        assert end != null;
+        BlockEnd old = this.end();
+        if (old != end) {
+            if (old != null) {
+                // disconnect this block from the old end
+                old.setBegin(null);
+                // disconnect this block from its current successors
+                for (BlockBegin s : old.blockSuccessors()) {
+                    s.blockPredecessors().remove(this);
+                }
+            }
+            successors().set(super.successorCount() + SUCCESSOR_END, end);
+            end.setBegin(this);
+            for (BlockBegin s : end.blockSuccessors()) {
+                s.addPredecessor(this);
+            }
+        }
+    }
+
     private static final List<BlockBegin> NO_HANDLERS = Collections.emptyList();
 
     /**
@@ -101,11 +129,6 @@
     private int blockFlags;
 
     /**
-     * A link to the last node in the block (which contains the successors).
-     */
-    private BlockEnd end;
-
-    /**
      * The {@link BlockBegin} nodes for which this node is a successor.
      */
     private final List<BlockBegin> predecessors;
@@ -195,14 +218,6 @@
     }
 
     /**
-     * Gets the block end associated with this basic block.
-     * @return the block end
-     */
-    public BlockEnd end() {
-        return end;
-    }
-
-    /**
      * Gets the exception handlers that cover one or more instructions of this basic block.
      *
      * @return the exception handlers
@@ -233,32 +248,6 @@
     }
 
     /**
-     * Set the block end for this block begin. This method will
-     * reset this block's successor list and rebuild it to be equivalent
-     * to the successor list of the specified block end.
-     * @param end the new block end for this block begin
-     */
-    public void setEnd(BlockEnd end) {
-        assert end != null;
-        BlockEnd old = this.end;
-        if (old != end) {
-            if (old != null) {
-                // disconnect this block from the old end
-                old.setBegin(null);
-                // disconnect this block from its current successors
-                for (BlockBegin s : old.blockSuccessors()) {
-                    s.blockPredecessors().remove(this);
-                }
-            }
-            this.end = end;
-            end.setBegin(this);
-            for (BlockBegin s : end.blockSuccessors()) {
-                s.addPredecessor(this);
-            }
-        }
-    }
-
-    /**
      * Set a flag on this block.
      * @param flag the flag to set
      */
@@ -310,7 +299,7 @@
         while ((block = queue.poll()) != null) {
             closure.apply(block);
             queueBlocks(queue, block.exceptionHandlerBlocks(), mark);
-            queueBlocks(queue, block.end.blockSuccessors(), mark);
+            queueBlocks(queue, block.end().blockSuccessors(), mark);
             queueBlocks(queue, predecessors ? block.predecessors : null, mark);
         }
     }
@@ -595,10 +584,10 @@
         }
 
         builder.append("]");
-        if (end != null) {
+        if (end() != null) {
             builder.append(" -> ");
             boolean hasSucc = false;
-            for (BlockBegin s : end.blockSuccessors()) {
+            for (BlockBegin s : end().blockSuccessors()) {
                 if (hasSucc) {
                     builder.append(", ");
                 }
@@ -615,7 +604,7 @@
      * @return the number of successors
      */
     public int numberOfSux() {
-        return end.blockSuccessorCount();
+        return end().blockSuccessorCount();
     }
 
     /**
@@ -624,7 +613,7 @@
      * @return the successor
      */
     public BlockBegin suxAt(int i) {
-        return end.blockSuccessor(i);
+        return end().blockSuccessor(i);
     }
 
     /**
@@ -768,7 +757,7 @@
         boolean hasPhisInLocals = false;
         boolean hasPhisOnStack = false;
 
-        if (end != null && end.stateAfter() != null) {
+        if (end() != null && end().stateAfter() != null) {
             FrameState state = stateBefore();
 
             int i = 0;
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java	Mon May 09 19:12:55 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java	Tue May 10 11:55:12 2011 +0200
@@ -34,9 +34,10 @@
  */
 public abstract class BlockEnd extends Instruction {
 
-    private static final int INPUT_COUNT = 1;
-    private static final int INPUT_STATE_AFTER = 0;
+    private static final int INPUT_COUNT = 0;
 
+    private static final int SUCCESSOR_COUNT = 1;
+    private static final int SUCCESSOR_STATE_AFTER = 0;
     private final int blockSuccessorCount;
 
     @Override
@@ -46,7 +47,7 @@
 
     @Override
     protected int successorCount() {
-        return super.successorCount() + blockSuccessorCount;
+        return super.successorCount() + blockSuccessorCount + SUCCESSOR_COUNT;
     }
 
     /**
@@ -54,23 +55,24 @@
      */
      @Override
     public FrameState stateAfter() {
-        return (FrameState) inputs().get(super.inputCount() + INPUT_STATE_AFTER);
+        return (FrameState) successors().get(super.successorCount() + SUCCESSOR_STATE_AFTER);
     }
 
     public FrameState setStateAfter(FrameState n) {
-        return (FrameState) inputs().set(super.inputCount() + INPUT_STATE_AFTER, n);
+        return (FrameState) successors().set(super.successorCount() + SUCCESSOR_STATE_AFTER, n);
     }
+
     /**
      * The list of instructions that produce input for this instruction.
      */
     public BlockBegin blockSuccessor(int index) {
         assert index >= 0 && index < blockSuccessorCount;
-        return (BlockBegin) successors().get(super.successorCount() + index);
+        return (BlockBegin) successors().get(super.successorCount() + SUCCESSOR_COUNT + index);
     }
 
     public BlockBegin setBlockSuccessor(int index, BlockBegin n) {
         assert index >= 0 && index < blockSuccessorCount;
-        return (BlockBegin) successors().set(super.successorCount() + index, n);
+        return (BlockBegin) successors().set(super.successorCount() + SUCCESSOR_COUNT + index, n);
     }
 
     public int blockSuccessorCount() {
@@ -95,7 +97,7 @@
     }
 
     public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint, int blockSuccessorCount, int inputCount, int successorCount, Graph graph) {
-        super(kind, inputCount + INPUT_COUNT, successorCount + blockSuccessorCount, graph);
+        super(kind, inputCount + INPUT_COUNT, successorCount + blockSuccessorCount + SUCCESSOR_COUNT, graph);
         this.blockSuccessorCount = blockSuccessorCount;
         setStateAfter(stateAfter);
         this.isSafepoint = isSafepoint;
@@ -174,7 +176,7 @@
      * @return the successor list
      */
     public List<BlockBegin> blockSuccessors() {
-        List<BlockBegin> list = (List) successors().subList(super.successorCount(), super.successorCount() + blockSuccessorCount);
+        List<BlockBegin> list = (List) successors().subList(super.successorCount() + SUCCESSOR_COUNT, super.successorCount() + blockSuccessorCount + SUCCESSOR_COUNT);
         return Collections.unmodifiableList(list);
     }
 
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/MonitorEnter.java	Mon May 09 19:12:55 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/MonitorEnter.java	Tue May 10 11:55:12 2011 +0200
@@ -31,10 +31,10 @@
  */
 public final class MonitorEnter extends AccessMonitor {
 
-    private static final int INPUT_COUNT = 1;
-    private static final int INPUT_STATE_AFTER = 0;
+    private static final int INPUT_COUNT = 0;
 
-    private static final int SUCCESSOR_COUNT = 0;
+    private static final int SUCCESSOR_COUNT = 1;
+    private static final int SUCCESSOR_STATE_AFTER = 0;
 
     @Override
     protected int inputCount() {
@@ -51,11 +51,11 @@
      */
      @Override
     public FrameState stateAfter() {
-        return (FrameState) inputs().get(super.inputCount() + INPUT_STATE_AFTER);
+        return (FrameState) successors().get(super.successorCount() + SUCCESSOR_STATE_AFTER);
     }
 
     public FrameState setStateAfter(FrameState n) {
-        return (FrameState) inputs().set(super.inputCount() + INPUT_STATE_AFTER, n);
+        return (FrameState) successors().set(super.successorCount() + SUCCESSOR_STATE_AFTER, n);
     }
 
     /**
--- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java	Mon May 09 19:12:55 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java	Tue May 10 11:55:12 2011 +0200
@@ -449,5 +449,12 @@
         return new FrameState(bci, localsSize, stackSize, locksSize, graph());
     }
 
+    @Override
+    public String shortName() {
+        return "FrameState@" + bci;
+    }
+
+
+
 
 }
--- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameStateAccess.java	Mon May 09 19:12:55 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameStateAccess.java	Tue May 10 11:55:12 2011 +0200
@@ -28,18 +28,18 @@
 
     FrameState duplicate();
 
-    Value valueAt(int i);
+    int localsSize();
 
     int stackSize();
 
-    int localsSize();
+    int locksSize();
+
+    Value valueAt(int i);
+
+    Value localAt(int i);
+
+    Value lockAt(int i);
 
     Value stackAt(int i);
 
-    Value lockAt(int i);
-
-    int locksSize();
-
-    Value localAt(int i);
-
 }
--- a/graal/GraalGraph/src/com/oracle/graal/graph/Graph.java	Mon May 09 19:12:55 2011 +0200
+++ b/graal/GraalGraph/src/com/oracle/graal/graph/Graph.java	Tue May 10 11:55:12 2011 +0200
@@ -29,10 +29,12 @@
 public class Graph {
 
     private final ArrayList<Node> nodes;
+    private final Root root;
     private int nextId;
 
     public Graph() {
         nodes = new ArrayList<Node>();
+        root = new Root(this);
     }
 
     public Collection<Node> getNodes() {
@@ -48,4 +50,8 @@
     void unregister(Node node) {
         nodes.set(node.id(), Node.Null);
     }
+
+    public Root root() {
+        return root;
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/GraalGraph/src/com/oracle/graal/graph/Root.java	Tue May 10 11:55:12 2011 +0200
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.graph;
+
+public class Root extends Node {
+
+    private static final int INPUT_COUNT = 0;
+
+    private static final int SUCCESSOR_COUNT = 1;
+    private static final int SUCCESSOR_START = 0;
+
+    @Override
+    protected int inputCount() {
+        return super.inputCount() + INPUT_COUNT;
+    }
+
+    @Override
+    protected int successorCount() {
+        return super.successorCount() + SUCCESSOR_COUNT;
+    }
+
+    public Node start() {
+        return (Node) successors().get(super.successorCount() + SUCCESSOR_START);
+    }
+
+    public Node setStart(Node next) {
+        return successors().set(super.successorCount() + SUCCESSOR_START, next);
+    }
+
+    Root(Graph graph) {
+        super(INPUT_COUNT, SUCCESSOR_COUNT, graph);
+    }
+
+    @Override
+    public void replace(Node other) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void delete() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    protected Object clone() throws CloneNotSupportedException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Node copy(Graph into) {
+        throw new UnsupportedOperationException();
+    }
+
+}
--- a/graal/GraalGraphviz/src/com/oracle/graal/graph/vis/GraphvizPrinter.java	Mon May 09 19:12:55 2011 +0200
+++ b/graal/GraalGraphviz/src/com/oracle/graal/graph/vis/GraphvizPrinter.java	Tue May 10 11:55:12 2011 +0200
@@ -159,11 +159,11 @@
     }
 
     private void printControlEdge(int from, int fromPort, int to) {
-        out.println("n" + from + ":succ" + fromPort + " -> n" + to + ":predecessors:n [color=red];");
+        out.println("n" + from + ":succ" + fromPort + " -> n" + to + ":predecessors:n [color=red, weight=10];");
     }
 
     private void printDataEdge(int from, int fromPort, int to) {
-        out.println("n" + to + ":usages -> n" + from + ":in" + fromPort + ":n [color=black,dir=back];");
+        out.println("n" + to + ":usages:s -> n" + from + ":in" + fromPort + ":n [color=black,dir=back];");
     }
 
 }