Mercurial > hg > truffle
comparison graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/cfg/ControlFlowGraph.java @ 4522:cf13124efdd9
Restructure phi functions in LIR; Re-enabled C1Visualizer output
author | Christian Wimmer <Christian.Wimmer@Oracle.com> |
---|---|
date | Wed, 08 Feb 2012 15:35:21 -0800 |
parents | 57cb8ec5f6bb |
children | dcc8f5c6f394 |
comparison
equal
deleted
inserted
replaced
4521:333896b40999 | 4522:cf13124efdd9 |
---|---|
22 */ | 22 */ |
23 package com.oracle.max.graal.compiler.cfg; | 23 package com.oracle.max.graal.compiler.cfg; |
24 | 24 |
25 import java.util.*; | 25 import java.util.*; |
26 | 26 |
27 import com.oracle.max.graal.compiler.util.*; | |
27 import com.oracle.max.graal.graph.*; | 28 import com.oracle.max.graal.graph.*; |
28 import com.oracle.max.graal.nodes.*; | 29 import com.oracle.max.graal.nodes.*; |
29 | 30 |
30 public class ControlFlowGraph { | 31 public class ControlFlowGraph { |
31 | 32 |
76 } | 77 } |
77 | 78 |
78 public Loop[] getLoops() { | 79 public Loop[] getLoops() { |
79 return loops; | 80 return loops; |
80 } | 81 } |
82 | |
83 protected static final int BLOCK_ID_INITIAL = -1; | |
84 protected static final int BLOCK_ID_VISITED = -2; | |
81 | 85 |
82 private void identifyBlocks() { | 86 private void identifyBlocks() { |
83 // Find all block headers | 87 // Find all block headers |
84 int numBlocks = 0; | 88 int numBlocks = 0; |
85 for (Node node : graph.getNodes()) { | 89 for (Node node : graph.getNodes()) { |
127 ArrayList<Block> stack = new ArrayList<>(); | 131 ArrayList<Block> stack = new ArrayList<>(); |
128 stack.add(blockFor(graph.start())); | 132 stack.add(blockFor(graph.start())); |
129 | 133 |
130 do { | 134 do { |
131 Block block = stack.get(stack.size() - 1); | 135 Block block = stack.get(stack.size() - 1); |
132 if (block.id == -1) { | 136 if (block.id == BLOCK_ID_INITIAL) { |
133 // First time we see this block: push all successors. | 137 // First time we see this block: push all successors. |
134 for (Node suxNode : block.getEndNode().cfgSuccessors()) { | 138 for (Node suxNode : block.getEndNode().cfgSuccessors()) { |
135 Block suxBlock = blockFor(suxNode); | 139 Block suxBlock = blockFor(suxNode); |
136 if (suxBlock.id < 0) { | 140 assert suxBlock.id != BLOCK_ID_VISITED; |
141 if (suxBlock.id == BLOCK_ID_INITIAL) { | |
137 stack.add(suxBlock); | 142 stack.add(suxBlock); |
138 } | 143 } |
139 } | 144 } |
140 block.id = -2; | 145 block.id = BLOCK_ID_VISITED; |
146 } else if (block.id == BLOCK_ID_VISITED) { | |
147 // Second time we see this block: All successors haved been processed, so insert block into reverse postorder list. | |
148 stack.remove(stack.size() - 1); | |
149 reversePostOrder[reversePostOrderId] = block; | |
150 block.id = reversePostOrderId; | |
151 reversePostOrderId--; | |
141 } else { | 152 } else { |
142 // Second time we see this block: All successors haved been processed, so insert block into reverse postorder list. | 153 throw Util.shouldNotReachHere(); |
143 assert block.id == -2; | |
144 stack.remove(stack.size() - 1); | |
145 block.id = reversePostOrderId; | |
146 reversePostOrder[reversePostOrderId] = block; | |
147 reversePostOrderId--; | |
148 } | 154 } |
149 } while (!stack.isEmpty()); | 155 } while (!stack.isEmpty()); |
150 assert reversePostOrderId == -1; | 156 assert reversePostOrderId == -1; |
151 } | 157 } |
152 | 158 |