Mercurial > hg > graal-jvmci-8
comparison graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java @ 2814:31e0786a986c
IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Mon, 30 May 2011 15:19:26 +0200 |
parents | b003ea36fa12 |
children | 878bbf7dbf31 |
comparison
equal
deleted
inserted
replaced
2809:b003ea36fa12 | 2814:31e0786a986c |
---|---|
26 import java.util.*; | 26 import java.util.*; |
27 import java.util.Map.Entry; | 27 import java.util.Map.Entry; |
28 | 28 |
29 import com.oracle.graal.graph.*; | 29 import com.oracle.graal.graph.*; |
30 import com.oracle.max.graal.schedule.*; | 30 import com.oracle.max.graal.schedule.*; |
31 import com.sun.c1x.ir.*; | |
31 | 32 |
32 /** | 33 /** |
33 * Generates a representation of {@link Graph Graphs} that can be visualized and inspected with the <a | 34 * Generates a representation of {@link Graph Graphs} that can be visualized and inspected with the <a |
34 * href="http://kenai.com/projects/igv">Ideal Graph Visualizer</a>. | 35 * href="http://kenai.com/projects/igv">Ideal Graph Visualizer</a>. |
35 */ | 36 */ |
123 } | 124 } |
124 stream.println(" </edges>"); | 125 stream.println(" </edges>"); |
125 | 126 |
126 stream.println(" <controlFlow>"); | 127 stream.println(" <controlFlow>"); |
127 for (Block block : schedule.getBlocks()) { | 128 for (Block block : schedule.getBlocks()) { |
128 printBlock(block); | 129 printBlock(graph, block); |
129 } | 130 } |
130 printNoBlock(); | 131 printNoBlock(); |
131 stream.println(" </controlFlow>"); | 132 stream.println(" </controlFlow>"); |
132 | 133 |
133 stream.println(" </graph>"); | 134 stream.println(" </graph>"); |
135 | 136 |
136 private List<Edge> printNodes(Collection<Node> nodes, boolean shortNames, NodeMap<Block> nodeToBlock) { | 137 private List<Edge> printNodes(Collection<Node> nodes, boolean shortNames, NodeMap<Block> nodeToBlock) { |
137 ArrayList<Edge> edges = new ArrayList<Edge>(); | 138 ArrayList<Edge> edges = new ArrayList<Edge>(); |
138 | 139 |
139 for (Node node : nodes) { | 140 for (Node node : nodes) { |
140 if (node == Node.Null || omittedClasses.contains(node)) { | 141 if (node == Node.Null || omittedClasses.contains(node.getClass())) { |
141 continue; | 142 continue; |
142 } | 143 } |
143 | 144 |
144 stream.printf(" <node id='%d'><properties>%n", node.id()); | 145 stream.printf(" <node id='%d'><properties>%n", node.id()); |
145 stream.printf(" <p name='idx'>%d</p>%n", node.id()); | 146 stream.printf(" <p name='idx'>%d</p>%n", node.id()); |
193 | 194 |
194 private void printEdge(Edge edge) { | 195 private void printEdge(Edge edge) { |
195 stream.printf(" <edge from='%d' fromIndex='%d' to='%d' toIndex='%d'/>%n", edge.from, edge.fromIndex, edge.to, edge.toIndex); | 196 stream.printf(" <edge from='%d' fromIndex='%d' to='%d' toIndex='%d'/>%n", edge.from, edge.fromIndex, edge.to, edge.toIndex); |
196 } | 197 } |
197 | 198 |
198 private void printBlock(Block block) { | 199 private void printBlock(Graph graph, Block block) { |
199 stream.printf(" <block name='%d'>%n", block.blockID()); | 200 stream.printf(" <block name='%d'>%n", block.blockID()); |
200 stream.printf(" <successors>%n"); | 201 stream.printf(" <successors>%n"); |
201 for (Block sux : block.getSuccessors()) { | 202 for (Block sux : block.getSuccessors()) { |
202 stream.printf(" <successor name='%d'/>%n", sux.blockID()); | 203 stream.printf(" <successor name='%d'/>%n", sux.blockID()); |
203 } | 204 } |
204 stream.printf(" </successors>%n"); | 205 stream.printf(" </successors>%n"); |
205 stream.printf(" <nodes>%n"); | 206 stream.printf(" <nodes>%n"); |
207 | |
208 ArrayList<Node> nodes = new ArrayList<Node>(block.getInstructions()); | |
209 // if this is the first block: add all locals to this block | |
210 if (nodes.get(0) == graph.start()) { | |
211 for (Node node : graph.getNodes()) { | |
212 if (node instanceof Local) { | |
213 nodes.add(node); | |
214 } | |
215 } | |
216 } | |
217 // add all framestates and phis to their blocks | |
206 for (Node node : block.getInstructions()) { | 218 for (Node node : block.getInstructions()) { |
207 stream.printf(" <node id='%d'/>%n", node.id()); | 219 if (node instanceof Instruction && ((Instruction) node).stateAfter() != null) { |
220 nodes.add(((Instruction) node).stateAfter()); | |
221 } | |
222 if (node instanceof Merge) { | |
223 Merge merge = (Merge) node; | |
224 if (merge.stateBefore() != null) { | |
225 nodes.add(merge.stateBefore()); | |
226 } | |
227 for (Node usage : merge.usages()) { | |
228 if (usage instanceof Phi) { | |
229 nodes.add(usage); | |
230 } | |
231 } | |
232 } | |
233 } | |
234 | |
235 for (Node node : nodes) { | |
236 if (!omittedClasses.contains(node.getClass())) { | |
237 stream.printf(" <node id='%d'/>%n", node.id()); | |
238 } | |
208 } | 239 } |
209 stream.printf(" </nodes>%n"); | 240 stream.printf(" </nodes>%n"); |
210 stream.printf(" </block>%n", block.blockID()); | 241 stream.printf(" </block>%n", block.blockID()); |
211 } | 242 } |
212 | 243 |