Mercurial > hg > truffle
comparison 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 |
comparison
equal
deleted
inserted
replaced
2601:224e8b4007bd | 2602:0c6564c254af |
---|---|
22 */ | 22 */ |
23 package com.sun.c1x.ir; | 23 package com.sun.c1x.ir; |
24 | 24 |
25 import java.util.*; | 25 import java.util.*; |
26 | 26 |
27 import com.sun.c1x.util.*; | 27 import com.oracle.graal.graph.*; |
28 import com.sun.c1x.value.*; | 28 import com.sun.c1x.value.*; |
29 import com.sun.cri.ci.*; | 29 import com.sun.cri.ci.*; |
30 | 30 |
31 /** | 31 /** |
32 * The {@code BlockEnd} instruction is a base class for all instructions that end a basic | 32 * The {@code BlockEnd} instruction is a base class for all instructions that end a basic |
33 * block, including branches, switches, throws, and goto's. | 33 * block, including branches, switches, throws, and goto's. |
34 */ | 34 */ |
35 public abstract class BlockEnd extends Instruction { | 35 public abstract class BlockEnd extends Instruction { |
36 | 36 |
37 private static final int INPUT_COUNT = 0; | |
38 | |
39 private final int blockSuccessorCount; | |
40 | |
41 @Override | |
42 protected int inputCount() { | |
43 return super.inputCount() + INPUT_COUNT; | |
44 } | |
45 | |
46 @Override | |
47 protected int successorCount() { | |
48 return super.successorCount() + blockSuccessorCount; | |
49 } | |
50 | |
51 /** | |
52 * The list of instructions that produce input for this instruction. | |
53 */ | |
54 public BlockBegin blockSuccessor(int index) { | |
55 assert index >= 0 && index < blockSuccessorCount; | |
56 return (BlockBegin) successors().get(super.successorCount() + index); | |
57 } | |
58 | |
59 public BlockBegin setBlockSuccessor(int index, BlockBegin n) { | |
60 assert index >= 0 && index < blockSuccessorCount; | |
61 return (BlockBegin) successors().set(super.successorCount() + index, n); | |
62 } | |
63 | |
64 public int blockSuccessorCount() { | |
65 return blockSuccessorCount; | |
66 } | |
67 | |
37 BlockBegin begin; | 68 BlockBegin begin; |
38 final List<BlockBegin> successors; | |
39 FrameState stateAfter; | 69 FrameState stateAfter; |
40 boolean isSafepoint; | 70 boolean isSafepoint; |
41 | 71 |
42 /** | 72 /** |
43 * Constructs a new block end with the specified value type. | 73 * Constructs a new block end with the specified value type. |
44 * @param kind the type of the value produced by this instruction | 74 * @param kind the type of the value produced by this instruction |
45 * @param stateAfter the frame state at the end of this block | 75 * @param stateAfter the frame state at the end of this block |
46 * @param isSafepoint {@code true} if this instruction is a safepoint instruction | 76 * @param isSafepoint {@code true} if this instruction is a safepoint instruction |
47 * @param successors the list of successor blocks. If {@code null}, a new one will be created. | 77 * @param successors the list of successor blocks. If {@code null}, a new one will be created. |
48 */ | 78 */ |
49 public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint, List<BlockBegin> successors) { | 79 public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint, List<BlockBegin> blockSuccessors, int inputCount, int successorCount, Graph graph) { |
50 super(kind); | 80 this(kind, stateAfter, isSafepoint, blockSuccessors.size(), inputCount, successorCount, graph); |
51 this.successors = successors == null ? new ArrayList<BlockBegin>(2) : successors; | 81 for (int i = 0; i < blockSuccessors.size(); i++) { |
82 setBlockSuccessor(i, blockSuccessors.get(i)); | |
83 } | |
84 } | |
85 | |
86 public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint, int blockSuccessorCount, int inputCount, int successorCount, Graph graph) { | |
87 super(kind, inputCount + INPUT_COUNT, successorCount + blockSuccessorCount, graph); | |
88 this.blockSuccessorCount = blockSuccessorCount; | |
52 setStateAfter(stateAfter); | 89 setStateAfter(stateAfter); |
53 this.isSafepoint = isSafepoint; | 90 this.isSafepoint = isSafepoint; |
54 } | 91 } |
55 | 92 |
56 public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint) { | 93 public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint, Graph graph) { |
57 this(kind, stateAfter, isSafepoint, null); | 94 this(kind, stateAfter, isSafepoint, 2, 0, 0, graph); |
58 } | 95 } |
59 | 96 |
60 /** | 97 /** |
61 * Gets the state after the end of this block. | 98 * Gets the state after the end of this block. |
62 */ | 99 */ |
101 * @param oldSucc the old successor to replace | 138 * @param oldSucc the old successor to replace |
102 * @param newSucc the new successor | 139 * @param newSucc the new successor |
103 */ | 140 */ |
104 public void substituteSuccessor(BlockBegin oldSucc, BlockBegin newSucc) { | 141 public void substituteSuccessor(BlockBegin oldSucc, BlockBegin newSucc) { |
105 assert newSucc != null; | 142 assert newSucc != null; |
106 Util.replaceAllInList(oldSucc, newSucc, successors); | 143 for (int i = 0; i < blockSuccessorCount; i++) { |
144 if (blockSuccessor(i) == oldSucc) { | |
145 setBlockSuccessor(i, newSucc); | |
146 } | |
147 } | |
107 } | 148 } |
108 | 149 |
109 /** | 150 /** |
110 * Gets the successor corresponding to the default (fall through) case. | 151 * Gets the successor corresponding to the default (fall through) case. |
111 * @return the default successor | 152 * @return the default successor |
112 */ | 153 */ |
113 public BlockBegin defaultSuccessor() { | 154 public BlockBegin defaultSuccessor() { |
114 return successors.get(successors.size() - 1); | 155 return blockSuccessor(blockSuccessorCount - 1); |
115 } | 156 } |
116 | 157 |
117 /** | 158 /** |
118 * Searches for the specified successor and returns its index into the | 159 * Searches for the specified successor and returns its index into the |
119 * successor list if found. | 160 * successor list if found. |
120 * @param b the block to search for in the successor list | 161 * @param b the block to search for in the successor list |
121 * @return the index of the block in the list if found; <code>-1</code> otherwise | 162 * @return the index of the block in the list if found; <code>-1</code> otherwise |
122 */ | 163 */ |
123 public int successorIndex(BlockBegin b) { | 164 public int successorIndex(BlockBegin b) { |
124 final int max = successors.size(); | 165 for (int i = 0; i < blockSuccessorCount; i++) { |
125 for (int i = 0; i < max; i++) { | 166 if (blockSuccessor(i) == b) { |
126 if (successors.get(i) == b) { | |
127 return i; | 167 return i; |
128 } | 168 } |
129 } | 169 } |
130 return -1; | 170 return -1; |
131 } | 171 } |
133 /** | 173 /** |
134 * Gets this block end's list of successors. | 174 * Gets this block end's list of successors. |
135 * @return the successor list | 175 * @return the successor list |
136 */ | 176 */ |
137 public List<BlockBegin> blockSuccessors() { | 177 public List<BlockBegin> blockSuccessors() { |
138 return successors; | 178 List<BlockBegin> list = (List) successors().subList(super.successorCount(), super.successorCount() + blockSuccessorCount); |
179 return Collections.unmodifiableList(list); | |
139 } | 180 } |
140 | 181 |
141 /** | |
142 * Gets the successor at a specified index. | |
143 * @param index the index of the successor | |
144 * @return the successor | |
145 */ | |
146 public BlockBegin suxAt(int index) { | |
147 return successors.get(index); | |
148 } | |
149 } | 182 } |