Mercurial > hg > graal-compiler
diff graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java @ 2809:b003ea36fa12
Add block structure to ideal graph visualizer
author | Gilles Duboscq <gilles.duboscq@oracle.com> |
---|---|
date | Mon, 30 May 2011 14:55:09 +0200 |
parents | d3fc4fe063bf |
children | 6fb5a1bf819f 31e0786a986c |
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java Mon May 30 13:42:23 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java Mon May 30 14:55:09 2011 +0200 @@ -27,6 +27,7 @@ import java.util.Map.Entry; import com.oracle.graal.graph.*; +import com.oracle.max.graal.schedule.*; /** * Generates a representation of {@link Graph Graphs} that can be visualized and inspected with the <a @@ -50,6 +51,7 @@ private final HashSet<Class<?>> omittedClasses = new HashSet<Class<?>>(); private final PrintStream stream; + private final List<Node> noBlockNodes = new LinkedList<Node>(); /** * Creates a new {@link IdealGraphPrinter} that writes to the specified output stream. @@ -109,8 +111,10 @@ public void print(Graph graph, String title, boolean shortNames) { stream.printf(" <graph name='%s'>%n", escape(title)); + Schedule schedule = new Schedule(graph); + stream.println(" <nodes>"); - List<Edge> edges = printNodes(graph.getNodes(), shortNames); + List<Edge> edges = printNodes(graph.getNodes(), shortNames, schedule.getNodeToBlock()); stream.println(" </nodes>"); stream.println(" <edges>"); @@ -119,10 +123,17 @@ } stream.println(" </edges>"); + stream.println(" <controlFlow>"); + for (Block block : schedule.getBlocks()) { + printBlock(block); + } + printNoBlock(); + stream.println(" </controlFlow>"); + stream.println(" </graph>"); } - private List<Edge> printNodes(Collection<Node> nodes, boolean shortNames) { + private List<Edge> printNodes(Collection<Node> nodes, boolean shortNames, NodeMap<Block> nodeToBlock) { ArrayList<Edge> edges = new ArrayList<Edge>(); for (Node node : nodes) { @@ -143,6 +154,13 @@ } stream.printf(" <p name='name'>%s</p>%n", escape(name)); } + Block block = nodeToBlock.get(node); + if (block != null) { + stream.printf(" <p name='block'>%d</p>%n", block.blockID()); + } else { + stream.printf(" <p name='block'>noBlock</p>%n"); + noBlockNodes.add(node); + } for (Entry<Object, Object> entry : props.entrySet()) { String key = entry.getKey().toString(); String value = entry.getValue().toString(); @@ -177,6 +195,33 @@ stream.printf(" <edge from='%d' fromIndex='%d' to='%d' toIndex='%d'/>%n", edge.from, edge.fromIndex, edge.to, edge.toIndex); } + private void printBlock(Block block) { + stream.printf(" <block name='%d'>%n", block.blockID()); + stream.printf(" <successors>%n"); + for (Block sux : block.getSuccessors()) { + stream.printf(" <successor name='%d'/>%n", sux.blockID()); + } + stream.printf(" </successors>%n"); + stream.printf(" <nodes>%n"); + for (Node node : block.getInstructions()) { + stream.printf(" <node id='%d'/>%n", node.id()); + } + stream.printf(" </nodes>%n"); + stream.printf(" </block>%n", block.blockID()); + } + + private void printNoBlock() { + if (!noBlockNodes.isEmpty()) { + stream.printf(" <block name='noBlock'>%n"); + stream.printf(" <nodes>%n"); + for (Node node : noBlockNodes) { + stream.printf(" <node id='%d'/>%n", node.id()); + } + stream.printf(" </nodes>%n"); + stream.printf(" </block>%n"); + } + } + private String escape(String s) { s = s.replace("&", "&"); s = s.replace("<", "<");