# HG changeset patch # User Doug Simon # Date 1412016517 -7200 # Node ID f1f7b796874f6eabbbc328d793a37f541249adb7 # Parent f735aa886cf660610dc6880aa738a76053c4e3f5 moved Node naming logic to generated nodes diff -r f735aa886cf6 -r f1f7b796874f graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Mon Sep 29 18:46:40 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Mon Sep 29 20:48:37 2014 +0200 @@ -782,6 +782,28 @@ return USE_GENERATED_NODES || getNodeClass().isLeafNode(); } + /** + * Gets the value used by {@link #toString(Verbosity)} to build a {@linkplain Verbosity#Name + * short} name. + */ + public String getShortName() { + String shortName = getClass().getSimpleName().toString(); + if (shortName.endsWith("Node")) { + shortName = shortName.substring(0, shortName.length() - 4); + } + return shortName; + } + + /** + * The template used to build the {@link Verbosity#Name} version. Variable parts are specified + * using {i#inputName} or {p#propertyName}. + * + * The default implementation of this method in {@link Node} returns {@code getShortName()}. + */ + public String getNameTemplate() { + return getShortName(); + } + protected void afterClone(@SuppressWarnings("unused") Node other) { } @@ -908,7 +930,7 @@ case Id: return Integer.toString(id); case Name: - return getNodeClass().shortName(); + return getShortName(); case Short: return toString(Verbosity.Id) + "|" + toString(Verbosity.Name); case Long: diff -r f735aa886cf6 -r f1f7b796874f graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Mon Sep 29 18:46:40 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Mon Sep 29 20:48:37 2014 +0200 @@ -62,7 +62,6 @@ private static final DebugTimer Init_AnnotationParsing = Debug.timer("NodeClass.Init.AnnotationParsing"); private static final DebugTimer Init_Edges = Debug.timer("NodeClass.Init.Edges"); private static final DebugTimer Init_Data = Debug.timer("NodeClass.Init.Data"); - private static final DebugTimer Init_Naming = Debug.timer("NodeClass.Init.Naming"); private static final DebugTimer Init_AllowedUsages = Debug.timer("NodeClass.Init.AllowedUsages"); private static final DebugTimer Init_IterableIds = Debug.timer("NodeClass.Init.IterableIds"); @@ -129,8 +128,6 @@ private final boolean canGVN; private final int startGVNNumber; - private final String shortName; - private final String nameTemplate; private final int iterableId; private final EnumSet allowedUsageTypes; private int[] iterableIds; @@ -191,22 +188,6 @@ startGVNNumber = clazz.hashCode(); NodeInfo info = getAnnotation(clazz, NodeInfo.class); - try (TimerCloseable t1 = Init_Naming.start()) { - String newNameTemplate = null; - String newShortName = clazz.getSimpleName(); - if (newShortName.endsWith("Node") && !newShortName.equals("StartNode") && !newShortName.equals("EndNode")) { - newShortName = newShortName.substring(0, newShortName.length() - 4); - } - assert info != null : "missing " + NodeInfo.class.getSimpleName() + " annotation on " + clazz; - if (!info.shortName().isEmpty()) { - newShortName = info.shortName(); - } - if (!info.nameTemplate().isEmpty()) { - newNameTemplate = info.nameTemplate(); - } - this.nameTemplate = newNameTemplate == null ? newShortName : newNameTemplate; - this.shortName = newShortName; - } try (TimerCloseable t1 = Init_AllowedUsages.start()) { allowedUsageTypes = superNodeClass == null ? EnumSet.noneOf(InputType.class) : superNodeClass.allowedUsageTypes.clone(); allowedUsageTypes.addAll(Arrays.asList(info.allowedUsageTypes())); @@ -234,7 +215,7 @@ this.iterableId = Node.NOT_ITERABLE; this.iterableIds = null; } - nodeIterableCount = Debug.metric("NodeIterable_%s", shortName); + nodeIterableCount = Debug.metric("NodeIterable_%s", clazz); } /** @@ -277,7 +258,7 @@ * *
      *     if (node.getNodeClass().is(BeginNode.class)) { ... }
-     *
+     * 
      *     // Due to generated Node classes, the test below
      *     // is *not* the same as the test above:
      *     if (node.getClass() == BeginNode.class) { ... }
@@ -290,10 +271,6 @@
         return nodeClass == getClazz();
     }
 
-    public String shortName() {
-        return shortName;
-    }
-
     public int[] iterableIds() {
         nodeIterableCount.increment();
         return iterableIds;
@@ -719,16 +696,7 @@
         return getClazz();
     }
 
-    /**
-     * The template used to build the {@link Verbosity#Name} version. Variable part are specified
-     * using {i#inputName} or {p#propertyName}.
-     */
-    public String getNameTemplate() {
-        return nameTemplate;
-    }
-
     interface InplaceUpdateClosure {
-
         Node replacement(Node node, Edges.Type type);
     }
 
diff -r f735aa886cf6 -r f1f7b796874f graal/com.oracle.graal.nodeinfo.processor/src/com/oracle/graal/nodeinfo/processor/GraphNodeGenerator.java
--- a/graal/com.oracle.graal.nodeinfo.processor/src/com/oracle/graal/nodeinfo/processor/GraphNodeGenerator.java	Mon Sep 29 18:46:40 2014 +0200
+++ b/graal/com.oracle.graal.nodeinfo.processor/src/com/oracle/graal/nodeinfo/processor/GraphNodeGenerator.java	Mon Sep 29 20:48:37 2014 +0200
@@ -334,6 +334,9 @@
             if (hasInputs || hasSuccessors) {
                 createIsLeafNodeMethod();
             }
+
+            createGetShortNameMethod(node);
+            createGetNameTemplateMethod(node);
         }
         compilationUnit.add(genClass);
         return compilationUnit;
@@ -420,7 +423,7 @@
         List overriddenMethods = getDeclaredMethodsInSuperTypes(method.getEnclosingClass(), method.getSimpleName().toString(), method.getParameterTypes());
         for (ExecutableElement overriddenMethod : overriddenMethods) {
             if (!overriddenMethod.getEnclosingElement().equals(Node)) {
-                env.message(Kind.WARNING, overriddenMethod, "This method is overridden in a generated subclass will never be called");
+                env.message(Kind.WARNING, overriddenMethod, "This method is overridden in a generated subclass and will never be called");
             }
         }
     }
@@ -432,6 +435,26 @@
         checkOnlyInGenNode(method);
     }
 
+    private void createGetShortNameMethod(TypeElement node) {
+        NodeInfo nodeInfo = node.getAnnotation(NodeInfo.class);
+        if (!nodeInfo.shortName().isEmpty()) {
+            CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), getType(String.class), "getShortName");
+            method.createBuilder().startReturn().string("\"" + nodeInfo.shortName() + "\"").end();
+            genClass.add(method);
+            checkOnlyInGenNode(method);
+        }
+    }
+
+    private void createGetNameTemplateMethod(TypeElement node) {
+        NodeInfo nodeInfo = node.getAnnotation(NodeInfo.class);
+        if (!nodeInfo.nameTemplate().isEmpty()) {
+            CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), getType(String.class), "getNameTemplate");
+            method.createBuilder().startReturn().string("\"" + nodeInfo.nameTemplate() + "\"").end();
+            genClass.add(method);
+            checkOnlyInGenNode(method);
+        }
+    }
+
     private boolean hidesField(String name) {
         for (VariableElement field : concat(inputFields, inputListFields, successorFields, successorListFields, dataFields)) {
             if (field.getSimpleName().contentEquals(name)) {
diff -r f735aa886cf6 -r f1f7b796874f graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/EndNode.java
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/EndNode.java	Mon Sep 29 18:46:40 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/EndNode.java	Mon Sep 29 20:48:37 2014 +0200
@@ -32,4 +32,12 @@
 
     EndNode() {
     }
+
+    @Override
+    public String getShortName() {
+        if (getNodeClass().is(EndNode.class)) {
+            return getClass().getSimpleName();
+        }
+        return super.getShortName();
+    }
 }
diff -r f735aa886cf6 -r f1f7b796874f graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StartNode.java
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StartNode.java	Mon Sep 29 18:46:40 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StartNode.java	Mon Sep 29 20:48:37 2014 +0200
@@ -42,4 +42,12 @@
     public LocationIdentity getLocationIdentity() {
         return LocationIdentity.ANY_LOCATION;
     }
+
+    @Override
+    public String getShortName() {
+        if (getNodeClass().is(StartNode.class)) {
+            return getClass().getSimpleName();
+        }
+        return super.getShortName();
+    }
 }
diff -r f735aa886cf6 -r f1f7b796874f graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Mon Sep 29 18:46:40 2014 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Mon Sep 29 20:48:37 2014 +0200
@@ -231,6 +231,20 @@
         }
     }
 
+    private void writeNodeClass(Node node, NodeClass nodeClass) throws IOException {
+        Character id = constantPool.get(nodeClass);
+        if (id == null) {
+            writeByte(POOL_NODE_CLASS);
+            writeString(nodeClass.getJavaClass().getSimpleName());
+            writeString(node.getNameTemplate());
+            writeEdgesInfo(nodeClass, Inputs);
+            writeEdgesInfo(nodeClass, Successors);
+        } else {
+            writeByte(POOL_NODE_CLASS);
+            writeShort(id.charValue());
+        }
+    }
+
     private void writePoolObject(Object object) throws IOException {
         if (object == null) {
             writeByte(POOL_NULL);
@@ -244,8 +258,6 @@
                 writeByte(POOL_ENUM);
             } else if (object instanceof Class || object instanceof JavaType) {
                 writeByte(POOL_CLASS);
-            } else if (object instanceof NodeClass) {
-                writeByte(POOL_NODE_CLASS);
             } else if (object instanceof ResolvedJavaMethod) {
                 writeByte(POOL_METHOD);
             } else if (object instanceof ResolvedJavaField) {
@@ -267,6 +279,7 @@
     }
 
     private void addPoolEntry(Object object) throws IOException {
+        assert !(object instanceof NodeClass);
         char index = constantPool.add(object);
         writeByte(POOL_NEW);
         writeShort(index);
@@ -293,13 +306,6 @@
             writeByte(POOL_CLASS);
             writeString(type.toJavaName());
             writeByte(KLASS);
-        } else if (object instanceof NodeClass) {
-            NodeClass nodeClass = (NodeClass) object;
-            writeByte(POOL_NODE_CLASS);
-            writeString(nodeClass.getJavaClass().getSimpleName());
-            writeString(nodeClass.getNameTemplate());
-            writeEdgesInfo(nodeClass, Inputs);
-            writeEdgesInfo(nodeClass, Successors);
         } else if (object instanceof ResolvedJavaMethod) {
             writeByte(POOL_METHOD);
             ResolvedJavaMethod method = ((ResolvedJavaMethod) object);
@@ -422,7 +428,7 @@
                 }
             }
             writeInt(getNodeId(node));
-            writePoolObject(nodeClass);
+            writeNodeClass(node, nodeClass);
             writeByte(node.predecessor() == null ? 0 : 1);
             // properties
             writeShort((char) props.size());
diff -r f735aa886cf6 -r f1f7b796874f graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java	Mon Sep 29 18:46:40 2014 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java	Mon Sep 29 20:48:37 2014 +0200
@@ -354,7 +354,7 @@
         out.print(HOVER_END).println(COLUMN_END);
 
         out.print("instruction ");
-        out.print(HOVER_START).print(node.getNodeClass().shortName()).print(HOVER_SEP).print(node.getClass().getName()).print(HOVER_END).print(" ");
+        out.print(HOVER_START).print(node.getShortName()).print(HOVER_SEP).print(node.getClass().getName()).print(HOVER_END).print(" ");
         printNamedNodes(node, node.inputs().iterator(), "", "", "#NDF");
         printNamedNodes(node, node.successors().iterator(), "#", "", "#NDF");
         for (Map.Entry entry : props.entrySet()) {