changeset 2787:9253df721472

Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
author Peter Hofer <peter.hofer@jku.at>
date Wed, 25 May 2011 17:48:56 +0200
parents 39a9d62e4c60
children 2f3258e3800e
files graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java graal/GraalCompiler/src/com/sun/c1x/ir/Local.java graal/GraalGraph/src/com/oracle/graal/graph/Node.java
diffstat 3 files changed, 45 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java	Wed May 25 17:10:53 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java	Wed May 25 17:48:56 2011 +0200
@@ -24,6 +24,7 @@
 
 import java.io.*;
 import java.util.*;
+import java.util.Map.Entry;
 
 import com.oracle.graal.graph.*;
 
@@ -129,17 +130,26 @@
                 continue;
             }
 
-            String name;
-            if (shortNames) {
-                name = node.shortName();
-            } else {
-                name = node.toString();
+            stream.printf("   <node id='%d'><properties>%n", node.id());
+            stream.printf("    <p name='idx'>%d</p>%n", node.id());
+
+            Map<Object, Object> props = node.getDebugProperties();
+            if (!props.containsKey("name")) {
+                String name;
+                if (shortNames) {
+                    name = node.shortName();
+                } else {
+                    name = node.toString();
+                }
+                stream.printf("    <p name='name'>%s</p>%n", escape(name));
+            }
+            for (Entry<Object, Object> entry : props.entrySet()) {
+                String key = entry.getKey().toString();
+                String value = entry.getValue().toString();
+                stream.printf("    <p name='%s'>%s</p>%n", escape(key), escape(value));
             }
 
-            stream.printf("   <node id='%d'><properties>", node.id());
-            stream.printf("<p name='idx'>%d</p>", node.id());
-            stream.printf("<p name='name'>%s</p>", escape(name));
-            stream.println("</properties></node>");
+            stream.println("   </properties></node>");
 
             // successors
             int fromIndex = 0;
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Local.java	Wed May 25 17:10:53 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Local.java	Wed May 25 17:48:56 2011 +0200
@@ -34,6 +34,7 @@
 public final class Local extends Value {
 
     private static final int INPUT_COUNT = 1;
+
     private static final int SUCCESSOR_COUNT = 0;
 
     private final int index;
@@ -84,4 +85,14 @@
     public void print(LogStream out) {
         out.print("local[index ").print(index()).print(']');
     }
+
+    @Override
+    protected int inputCount() {
+        return super.inputCount() + INPUT_COUNT;
+    }
+
+    @Override
+    protected int successorCount() {
+        return super.successorCount() + SUCCESSOR_COUNT;
+    }
 }
--- a/graal/GraalGraph/src/com/oracle/graal/graph/Node.java	Wed May 25 17:10:53 2011 +0200
+++ b/graal/GraalGraph/src/com/oracle/graal/graph/Node.java	Wed May 25 17:48:56 2011 +0200
@@ -24,7 +24,9 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 public abstract class Node {
 
@@ -141,6 +143,19 @@
         return 0;
     }
 
+    /**
+     * Provides a {@link Map} of properties of this node for use in debugging (e.g., to view in the ideal graph
+     * visualizer). Subclasses overriding this method should add to the map returned by their superclass.
+     */
+    public Map<Object, Object> getDebugProperties() {
+        Map<Object, Object> map = new HashMap<Object, Object>();
+        map.put("inputCount", inputCount());
+        map.put("usageCount", usages.size());
+        map.put("successorCount", successorCount());
+        map.put("predecessorCount", predecessors.size());
+        return map;
+    }
+
     @Override
     public String toString() {
         return this.getClass().getSimpleName() + "-" + this.id();