changeset 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 189ffb7d1d84
children 6fb5a1bf819f 31e0786a986c
files graal/GraalCompiler/src/com/sun/c1x/C1XCompilation.java graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinterObserver.java graal/GraalCompiler/src/com/sun/c1x/graph/IR.java graal/GraalCompiler/src/com/sun/c1x/observer/CompilationEvent.java
diffstat 7 files changed, 62 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/C1XCompilation.java	Mon May 30 13:42:23 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/C1XCompilation.java	Mon May 30 14:55:09 2011 +0200
@@ -282,7 +282,7 @@
             }
 
             if (compiler.isObserved()) {
-                compiler.fireCompilationEvent(new CompilationEvent(this, "After code generation", hir.getHIRStartBlock(), false, true, targetMethod));
+                compiler.fireCompilationEvent(new CompilationEvent(this, "After code generation", graph, false, true, targetMethod));
             }
 
             if (C1XOptions.PrintTimers) {
--- a/graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java	Mon May 30 13:42:23 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java	Mon May 30 14:55:09 2011 +0200
@@ -2152,7 +2152,7 @@
         }
 
         if (compilation.compiler.isObserved()) {
-            compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, label, compilation.hir().getHIRStartBlock(), hirValid, true));
+            compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, label, compilation.graph, hirValid, true));
         }
     }
 
--- a/graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java	Mon May 30 13:42:23 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java	Mon May 30 14:55:09 2011 +0200
@@ -57,8 +57,8 @@
     }
 
     public void compilationEvent(CompilationEvent event) {
-        if (event.getStartBlock() != null && !TTY.isSuppressed()) {
-            Graph graph = event.getStartBlock().graph();
+        if (event.getGraph() != null && !TTY.isSuppressed()) {
+            Graph graph = event.getGraph();
 
             String name = event.getMethod().holder().name();
             name = name.substring(1, name.length() - 1).replace('/', '.');
--- 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("&", "&amp;");
         s = s.replace("<", "&lt;");
--- a/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinterObserver.java	Mon May 30 13:42:23 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinterObserver.java	Mon May 30 14:55:09 2011 +0200
@@ -140,8 +140,8 @@
 
     @Override
     public void compilationEvent(CompilationEvent event) {
-        if (printer != null && event.getStartBlock() != null) {
-            Graph graph = event.getStartBlock().graph();
+        if (printer != null && event.getGraph() != null) {
+            Graph graph = event.getGraph();
             printer.print(graph, event.getLabel(), true);
         }
     }
--- a/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java	Mon May 30 13:42:23 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java	Mon May 30 14:55:09 2011 +0200
@@ -194,7 +194,7 @@
         }
 
         if (compilation.compiler.isObserved()) {
-            compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, phase, getHIRStartBlock(), true, false));
+            compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, phase, compilation.graph, true, false));
         }
     }
 
--- a/graal/GraalCompiler/src/com/sun/c1x/observer/CompilationEvent.java	Mon May 30 13:42:23 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/observer/CompilationEvent.java	Mon May 30 14:55:09 2011 +0200
@@ -24,10 +24,10 @@
 
 import java.util.*;
 
+import com.oracle.graal.graph.*;
 import com.sun.c1x.*;
 import com.sun.c1x.alloc.*;
 import com.sun.c1x.graph.*;
-import com.sun.c1x.ir.*;
 import com.sun.cri.ci.*;
 import com.sun.cri.ri.*;
 
@@ -43,7 +43,7 @@
 
     private final C1XCompilation compilation;
     private final String label;
-    private Instruction startBlock;
+    private Graph graph;
 
     private BlockMap blockMap;
     private int codeSize = -1;
@@ -67,15 +67,15 @@
         this.compilation = compilation;
     }
 
-    public CompilationEvent(C1XCompilation compilation, String label, Instruction startBlock, boolean hirValid, boolean lirValid) {
+    public CompilationEvent(C1XCompilation compilation, String label, Graph graph, boolean hirValid, boolean lirValid) {
         this(compilation, label);
-        this.startBlock = startBlock;
+        this.graph = graph;
         this.hirValid = hirValid;
         this.lirValid = lirValid;
     }
 
-    public CompilationEvent(C1XCompilation compilation, String label, Instruction startBlock, boolean hirValid, boolean lirValid, CiTargetMethod targetMethod) {
-        this(compilation, label, startBlock, hirValid, lirValid);
+    public CompilationEvent(C1XCompilation compilation, String label, Graph graph, boolean hirValid, boolean lirValid, CiTargetMethod targetMethod) {
+        this(compilation, label, graph, hirValid, lirValid);
         this.targetMethod = targetMethod;
     }
 
@@ -108,8 +108,8 @@
         return blockMap;
     }
 
-    public Instruction getStartBlock() {
-        return startBlock;
+    public Graph getGraph() {
+        return graph;
     }
 
     public LinearScan getAllocator() {