comparison graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java @ 2751:0fe79e7435c3

More scheduling. Removed need for cfg iteration in the phi simplifier.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Fri, 20 May 2011 14:22:22 +0200
parents a3cd5eb68837
children 0d268cf66e24
comparison
equal deleted inserted replaced
2745:114fc809462f 2751:0fe79e7435c3
114 * Gets the list of predecessors of this block. 114 * Gets the list of predecessors of this block.
115 * @return the predecessor list 115 * @return the predecessor list
116 */ 116 */
117 @SuppressWarnings({ "unchecked", "rawtypes" }) 117 @SuppressWarnings({ "unchecked", "rawtypes" })
118 public List<Instruction> blockPredecessors() { 118 public List<Instruction> blockPredecessors() {
119 if (predecessors().size() == 1 && predecessors().get(0) == graph().root()) { 119 if (predecessors().size() == 1 && predecessors().get(0) == graph().start()) {
120 return Collections.EMPTY_LIST; 120 return Collections.EMPTY_LIST;
121 } else { 121 } else {
122 return (List) Collections.unmodifiableList(predecessors()); 122 return (List) Collections.unmodifiableList(predecessors());
123 } 123 }
124 } 124 }
140 * @param closure the closure to apply to each block 140 * @param closure the closure to apply to each block
141 */ 141 */
142 public void iteratePreOrder(BlockClosure closure) { 142 public void iteratePreOrder(BlockClosure closure) {
143 // XXX: identity hash map might be too slow, consider a boolean array or a mark field 143 // XXX: identity hash map might be too slow, consider a boolean array or a mark field
144 iterate(new IdentityHashMap<BlockBegin, BlockBegin>(), closure); 144 iterate(new IdentityHashMap<BlockBegin, BlockBegin>(), closure);
145 }
146
147 /**
148 * Iterate over all blocks transitively reachable from this block.
149 * @param closure the closure to apply to each block
150 * @param predecessors {@code true} if also to include this blocks predecessors
151 */
152 public void iterateAnyOrder(BlockClosure closure, boolean predecessors) {
153 IdentityHashMap<BlockBegin, BlockBegin> mark = new IdentityHashMap<BlockBegin, BlockBegin>();
154 LinkedList<BlockBegin> queue = new LinkedList<BlockBegin>();
155 queue.offer(this);
156 mark.put(this, this);
157 BlockBegin block;
158 while ((block = queue.poll()) != null) {
159 closure.apply(block);
160
161 Instruction inst = block;
162 ArrayList<BlockBegin> excBlocks = new ArrayList<BlockBegin>();
163 while (inst != null) {
164 if (inst instanceof ExceptionEdgeInstruction) {
165 excBlocks.add(((ExceptionEdgeInstruction) inst).exceptionEdge());
166 }
167 inst = inst.next();
168 }
169 while (excBlocks.remove(null)) {
170 // nothing
171 }
172 if (excBlocks.size() > 0) {
173 queueBlocks(queue, excBlocks, mark);
174 }
175
176 queueBlocks(queue, block.end().blockSuccessors(), mark);
177 if (predecessors) {
178 queueBlockEnds(queue, block.blockPredecessors(), mark);
179 }
180 }
181 }
182
183 private void queueBlocks(LinkedList<BlockBegin> queue, List<BlockBegin> list, IdentityHashMap<BlockBegin, BlockBegin> mark) {
184 if (list != null) {
185 for (BlockBegin b : list) {
186 if (!mark.containsKey(b)) {
187 queue.offer(b);
188 mark.put(b, b);
189 }
190 }
191 }
192 }
193
194 private void queueBlockEnds(LinkedList<BlockBegin> queue, List<Instruction> list, IdentityHashMap<BlockBegin, BlockBegin> mark) {
195 if (list != null) {
196 for (Instruction end : list) {
197 BlockBegin b = end.block();
198 if (!mark.containsKey(b)) {
199 queue.offer(b);
200 mark.put(b, b);
201 }
202 }
203 }
204 } 145 }
205 146
206 /** 147 /**
207 * Gets the bytecode index of this instruction. 148 * Gets the bytecode index of this instruction.
208 * @return the bytecode index of this instruction 149 * @return the bytecode index of this instruction
296 * Get the number of predecessors. 237 * Get the number of predecessors.
297 * @return the number of predecessors 238 * @return the number of predecessors
298 */ 239 */
299 public int numberOfPreds() { 240 public int numberOfPreds() {
300 // ignore the graph root 241 // ignore the graph root
301 if (predecessors().size() == 1 && predecessors().get(0) == graph().root()) { 242 if (predecessors().size() == 1 && predecessors().get(0) == graph().start()) {
302 return 0; 243 return 0;
303 } else { 244 } else {
304 return predecessors().size(); 245 return predecessors().size();
305 } 246 }
306 } 247 }