diff graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java @ 2602:0c6564c254af

new node layout: BlockBegin, BlockEnd -Dc1x.dot=regex for pdf output escape dot graph labels (<, >, &)
author Lukas Stadler <lukas.stadler@jku.at>
date Fri, 06 May 2011 10:25:37 +0200
parents 4a36a0bd6d18
children 3558ca7088c0
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java	Thu May 05 16:33:12 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java	Fri May 06 10:25:37 2011 +0200
@@ -24,7 +24,7 @@
 
 import java.util.*;
 
-import com.sun.c1x.util.*;
+import com.oracle.graal.graph.*;
 import com.sun.c1x.value.*;
 import com.sun.cri.ci.*;
 
@@ -34,8 +34,38 @@
  */
 public abstract class BlockEnd extends Instruction {
 
+    private static final int INPUT_COUNT = 0;
+
+    private final int blockSuccessorCount;
+
+    @Override
+    protected int inputCount() {
+        return super.inputCount() + INPUT_COUNT;
+    }
+
+    @Override
+    protected int successorCount() {
+        return super.successorCount() + blockSuccessorCount;
+    }
+
+    /**
+     * 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);
+    }
+
+    public BlockBegin setBlockSuccessor(int index, BlockBegin n) {
+        assert index >= 0 && index < blockSuccessorCount;
+        return (BlockBegin) successors().set(super.successorCount() + index, n);
+    }
+
+    public int blockSuccessorCount() {
+        return blockSuccessorCount;
+    }
+
     BlockBegin begin;
-    final List<BlockBegin> successors;
     FrameState stateAfter;
     boolean isSafepoint;
 
@@ -46,15 +76,22 @@
      * @param isSafepoint {@code true} if this instruction is a safepoint instruction
      * @param successors the list of successor blocks. If {@code null}, a new one will be created.
      */
-    public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint, List<BlockBegin> successors) {
-        super(kind);
-        this.successors = successors == null ? new ArrayList<BlockBegin>(2) : successors;
+    public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint, List<BlockBegin> blockSuccessors, int inputCount, int successorCount, Graph graph) {
+        this(kind, stateAfter, isSafepoint, blockSuccessors.size(), inputCount, successorCount, graph);
+        for (int i = 0; i < blockSuccessors.size(); i++) {
+            setBlockSuccessor(i, blockSuccessors.get(i));
+        }
+    }
+
+    public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint, int blockSuccessorCount, int inputCount, int successorCount, Graph graph) {
+        super(kind, inputCount + INPUT_COUNT, successorCount + blockSuccessorCount, graph);
+        this.blockSuccessorCount = blockSuccessorCount;
         setStateAfter(stateAfter);
         this.isSafepoint = isSafepoint;
     }
 
-    public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint) {
-        this(kind, stateAfter, isSafepoint, null);
+    public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint, Graph graph) {
+        this(kind, stateAfter, isSafepoint, 2, 0, 0, graph);
     }
 
     /**
@@ -103,7 +140,11 @@
      */
     public void substituteSuccessor(BlockBegin oldSucc, BlockBegin newSucc) {
         assert newSucc != null;
-        Util.replaceAllInList(oldSucc, newSucc, successors);
+        for (int i = 0; i < blockSuccessorCount; i++) {
+            if (blockSuccessor(i) == oldSucc) {
+                setBlockSuccessor(i, newSucc);
+            }
+        }
     }
 
     /**
@@ -111,7 +152,7 @@
      * @return the default successor
      */
     public BlockBegin defaultSuccessor() {
-        return successors.get(successors.size() - 1);
+        return blockSuccessor(blockSuccessorCount - 1);
     }
 
     /**
@@ -121,9 +162,8 @@
      * @return the index of the block in the list if found; <code>-1</code> otherwise
      */
     public int successorIndex(BlockBegin b) {
-        final int max = successors.size();
-        for (int i = 0; i < max; i++) {
-            if (successors.get(i) == b) {
+        for (int i = 0; i < blockSuccessorCount; i++) {
+            if (blockSuccessor(i) == b) {
                 return i;
             }
         }
@@ -135,15 +175,8 @@
      * @return the successor list
      */
     public List<BlockBegin> blockSuccessors() {
-        return successors;
+        List<BlockBegin> list = (List) successors().subList(super.successorCount(), super.successorCount() + blockSuccessorCount);
+        return Collections.unmodifiableList(list);
     }
 
-    /**
-     * Gets the successor at a specified index.
-     * @param index the index of the successor
-     * @return the successor
-     */
-    public BlockBegin suxAt(int index) {
-        return successors.get(index);
-    }
 }