changeset 7123:b914b9b4c578

graal.graph refactorings Common out NodeInputsIterable and NodeSuccessorsIterable Remove NodeUsagesList.size, use .count instead Change return type of Node.usages to NodeIterable<Node>
author Gilles Duboscq <duboscq@ssw.jku.at>
date Mon, 03 Dec 2012 13:53:53 +0100
parents 8f45ab034ff3
children ab65fa23f8e9
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/TypeSystemTest.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClassIterable.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeInputsIterable.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeSuccessorsIterable.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeUsagesList.java graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/EndNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetIntrinsificationPhase.java graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java
diffstat 16 files changed, 124 insertions(+), 148 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java	Mon Dec 03 13:53:53 2012 +0100
@@ -126,7 +126,7 @@
                     canonicalId.set(node, id);
                 }
                 String name = node instanceof ConstantNode ? node.toString(Verbosity.Name) : node.getClass().getSimpleName();
-                result.append("  " + id + "|" + name + "    (" + node.usages().size() + ")\n");
+                result.append("  " + id + "|" + name + "    (" + node.usages().count() + ")\n");
             }
         }
         return result.toString();
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/TypeSystemTest.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/TypeSystemTest.java	Mon Dec 03 13:53:53 2012 +0100
@@ -237,7 +237,7 @@
     }
 
     private static void outputNode(Node node) {
-        System.out.print("  " + node + "    (usage count: " + node.usages().size() + ") (inputs:");
+        System.out.print("  " + node + "    (usage count: " + node.usages().count() + ") (inputs:");
         for (Node input : node.inputs()) {
             System.out.print(" " + input.toString(Verbosity.Id));
         }
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java	Mon Dec 03 13:53:53 2012 +0100
@@ -383,7 +383,7 @@
             }
         }
         if (block.numberOfSux() >= 1 && !endsWithJump(block)) {
-            NodeSuccessorsIterable successors = block.getEndNode().successors();
+            NodeClassIterable successors = block.getEndNode().successors();
             assert successors.isNotEmpty() : "should have at least one successor : " + block.getEndNode();
 
             emitJump(getLIRBlock((FixedNode) successors.first()), null);
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java	Mon Dec 03 13:53:53 2012 +0100
@@ -27,6 +27,7 @@
 
 import com.oracle.graal.graph.Graph.InputChangedListener;
 import com.oracle.graal.graph.NodeClass.*;
+import com.oracle.graal.graph.iterators.*;
 
 
 /**
@@ -131,22 +132,22 @@
     }
 
     /**
-     * Returns an {@link NodeInputsIterable iterable} which can be used to traverse all non-null input edges of this node.
-     * @return an {@link NodeInputsIterable iterable} for all non-null input edges.
+     * Returns an {@link NodeClassIterable iterable} which can be used to traverse all non-null input edges of this node.
+     * @return an {@link NodeClassIterable iterable} for all non-null input edges.
      */
-    public NodeInputsIterable inputs() {
+    public NodeClassIterable inputs() {
         return getNodeClass().getInputIterable(this);
     }
 
     /**
-     * Returns an {@link NodeSuccessorsIterable iterable} which can be used to traverse all non-null successor edges of this node.
-     * @return an {@link NodeSuccessorsIterable iterable} for all non-null successor edges.
+     * Returns an {@link NodeClassIterable iterable} which can be used to traverse all non-null successor edges of this node.
+     * @return an {@link NodeClassIterable iterable} for all non-null successor edges.
      */
-    public NodeSuccessorsIterable successors() {
+    public NodeClassIterable successors() {
         return getNodeClass().getSuccessorIterable(this);
     }
 
-    public final NodeUsagesList usages() {
+    public final NodeIterable<Node> usages() {
         return usages;
     }
 
@@ -551,7 +552,7 @@
         }
 
         if (precision > 0) {
-            if (this.usages.size() > 0) {
+            if (this.usages.count() > 0) {
                 formatter.format(" usages={");
                 int z = 0;
                 for (Node usage : this.usages) {
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java	Mon Dec 03 13:53:53 2012 +0100
@@ -216,6 +216,11 @@
         return str.toString();
     }
 
+    /**
+     * Describes an edge slot for a {@link NodeClass}.
+     * @see NodeClass#get(Node, Position)
+     * @see NodeClass#getName(Position)
+     */
     public static final class Position {
         public final boolean input;
         public final int index;
@@ -566,9 +571,9 @@
         }
     }
 
-    public NodeInputsIterable getInputIterable(final Node node) {
+    public NodeClassIterable getInputIterable(final Node node) {
         assert clazz.isInstance(node);
-        return new NodeInputsIterable() {
+        return new NodeClassIterable() {
 
             @Override
             public NodeClassIterator iterator() {
@@ -582,9 +587,9 @@
         };
     }
 
-    public NodeSuccessorsIterable getSuccessorIterable(final Node node) {
+    public NodeClassIterable getSuccessorIterable(final Node node) {
         assert clazz.isInstance(node);
-        return new NodeSuccessorsIterable() {
+        return new NodeClassIterable() {
             @Override
             public NodeClassIterator iterator() {
                 return new NodeClassIterator(node, successorOffsets, directSuccessorCount);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClassIterable.java	Mon Dec 03 13:53:53 2012 +0100
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.graph;
+
+import com.oracle.graal.graph.NodeClass.NodeClassIterator;
+import com.oracle.graal.graph.NodeClass.Position;
+import com.oracle.graal.graph.iterators.*;
+
+/**
+ * The iterator returned by this iterable can be used to access {@link Position Positions} during iteration using {@link NodeClassIterator#nextPosition()}.
+ */
+public abstract class NodeClassIterable extends AbstractNodeIterable<Node> {
+    @Override
+    public abstract NodeClassIterator iterator();
+}
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeInputsIterable.java	Fri Nov 30 11:39:05 2012 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.graph;
-
-import com.oracle.graal.graph.NodeClass.NodeClassIterator;
-import com.oracle.graal.graph.iterators.*;
-
-public abstract class NodeInputsIterable extends AbstractNodeIterable<Node> {
-    @Override
-    public abstract NodeClassIterator iterator();
-}
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeSuccessorsIterable.java	Fri Nov 30 11:39:05 2012 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.graph;
-
-import com.oracle.graal.graph.NodeClass.NodeClassIterator;
-import com.oracle.graal.graph.iterators.*;
-
-public abstract class NodeSuccessorsIterable extends AbstractNodeIterable<Node> {
-    @Override
-    public abstract NodeClassIterator iterator();
-}
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeUsagesList.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeUsagesList.java	Mon Dec 03 13:53:53 2012 +0100
@@ -44,10 +44,6 @@
         this.nodes = nodes;
     }
 
-    public int size() {
-        return size;
-    }
-
     @Override
     public boolean isEmpty() {
         return size == 0;
@@ -63,63 +59,6 @@
         return size;
     }
 
-    protected void incModCount() {
-        modCount++;
-    }
-
-    public boolean add(Node node) {
-        incModCount();
-        if (size == nodes.length) {
-            nodes = Arrays.copyOf(nodes, nodes.length * 2 + 1);
-        }
-        nodes[size++] = node;
-        return true;
-    }
-
-    void copyAndClear(NodeUsagesList other) {
-        incModCount();
-        other.incModCount();
-        nodes = other.nodes;
-        size = other.size;
-        nodes = EMPTY_NODE_ARRAY;
-        size = 0;
-    }
-
-    public void clear() {
-        incModCount();
-        nodes = EMPTY_NODE_ARRAY;
-        size = 0;
-    }
-
-    boolean remove(Node node) {
-        int i = 0;
-        incModCount();
-        while (i < size && nodes[i] != node) {
-            i++;
-        }
-        if (i < size) {
-            i++;
-            while (i < size) {
-                nodes[i - 1] = nodes[i];
-                i++;
-            }
-            nodes[--size] = null;
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    boolean replaceFirst(Node node, Node other) {
-        for (int i = 0; i < size; i++) {
-            if (nodes[i] == node) {
-                nodes[i] = other;
-                return true;
-            }
-        }
-        return false;
-    }
-
     @Override
     public Iterator<Node> iterator() {
         return new Iterator<Node>() {
@@ -160,6 +99,63 @@
         return Arrays.asList(Arrays.copyOf(NodeUsagesList.this.nodes, NodeUsagesList.this.size));
     }
 
+    private void incModCount() {
+        modCount++;
+    }
+
+    boolean add(Node node) {
+        incModCount();
+        if (size == nodes.length) {
+            nodes = Arrays.copyOf(nodes, nodes.length * 2 + 1);
+        }
+        nodes[size++] = node;
+        return true;
+    }
+
+    void copyAndClear(NodeUsagesList other) {
+        incModCount();
+        other.incModCount();
+        nodes = other.nodes;
+        size = other.size;
+        nodes = EMPTY_NODE_ARRAY;
+        size = 0;
+    }
+
+    void clear() {
+        incModCount();
+        nodes = EMPTY_NODE_ARRAY;
+        size = 0;
+    }
+
+    boolean remove(Node node) {
+        int i = 0;
+        incModCount();
+        while (i < size && nodes[i] != node) {
+            i++;
+        }
+        if (i < size) {
+            i++;
+            while (i < size) {
+                nodes[i - 1] = nodes[i];
+                i++;
+            }
+            nodes[--size] = null;
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    boolean replaceFirst(Node node, Node other) {
+        for (int i = 0; i < size; i++) {
+            if (nodes[i] == node) {
+                nodes[i] = other;
+                return true;
+            }
+        }
+        return false;
+    }
+
     @Override
     public String toString() {
         StringBuilder str = new StringBuilder();
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Mon Dec 03 13:53:53 2012 +0100
@@ -202,7 +202,7 @@
 
         // remove dead FrameStates
         for (Node n : currentGraph.getNodes(FrameState.class)) {
-            if (n.usages().size() == 0 && n.predecessor() == null) {
+            if (n.usages().count() == 0 && n.predecessor() == null) {
                 n.safeDelete();
             }
         }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/EndNode.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/EndNode.java	Mon Dec 03 13:53:53 2012 +0100
@@ -45,7 +45,7 @@
 
     @Override
     public boolean verify() {
-        assertTrue(usages().size() <= 1, "at most one usage");
+        assertTrue(usages().count() <= 1, "at most one usage");
         return super.verify();
     }
 
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java	Mon Dec 03 13:53:53 2012 +0100
@@ -26,6 +26,7 @@
 
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.graph.*;
+import com.oracle.graal.graph.iterators.*;
 import com.oracle.graal.nodes.PhiNode.PhiType;
 import com.oracle.graal.nodes.calc.*;
 import com.oracle.graal.nodes.spi.*;
@@ -238,7 +239,7 @@
         }
 
         // Only consider merges with a single usage that is both a phi and an operand of the comparison
-        NodeUsagesList mergeUsages = merge.usages();
+        NodeIterable<Node> mergeUsages = merge.usages();
         if (mergeUsages.count() != 1) {
             return false;
         }
@@ -249,7 +250,7 @@
 
         // Ensure phi is used by at most the comparison and the merge's frame state (if any)
         PhiNode phi = (PhiNode) singleUsage;
-        NodeUsagesList phiUsages = phi.usages();
+        NodeIterable<Node> phiUsages = phi.usages();
         if (phiUsages.count() > 2) {
             return false;
         }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java	Mon Dec 03 13:53:53 2012 +0100
@@ -98,7 +98,7 @@
 
     @Override
     public boolean verify() {
-        assert usages().size() <= 1 : "call target may only be used by a single invoke";
+        assert usages().count() <= 1 : "call target may only be used by a single invoke";
         for (Node n : usages()) {
             assertTrue(n instanceof Invoke, "call target can only be used from an invoke (%s)", n);
         }
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Mon Dec 03 13:53:53 2012 +0100
@@ -382,7 +382,7 @@
                 writePropertyObject(entry.getValue());
             }
             // successors
-            NodeSuccessorsIterable successors = node.successors();
+            NodeClassIterable successors = node.successors();
             writeShort((char) successors.count());
             NodeClassIterator suxIt = successors.iterator();
             while (suxIt.hasNext()) {
@@ -392,7 +392,7 @@
                 writeShort((char) pos.index);
             }
             //inputs
-            NodeInputsIterable inputs = node.inputs();
+            NodeClassIterable inputs = node.inputs();
             writeShort((char) inputs.count());
             NodeClassIterator inIt = inputs.iterator();
             while (inIt.hasNext()) {
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetIntrinsificationPhase.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetIntrinsificationPhase.java	Mon Dec 03 13:53:53 2012 +0100
@@ -206,13 +206,13 @@
                     Type boundType = typeVariable.getBounds()[0];
                     if (boundType instanceof Class && ((Class) boundType).getSuperclass() == null) {
                         // Unbound generic => try boxing elimination
-                        if (node.usages().size() == 2) {
+                        if (node.usages().count() == 2) {
                             if (node instanceof Invoke) {
                                 Invoke invokeNode = (Invoke) node;
                                 MethodCallTargetNode callTarget = invokeNode.methodCallTarget();
                                 if (pool.isBoxingMethod(callTarget.targetMethod())) {
                                     FrameState stateAfter = invokeNode.stateAfter();
-                                    assert stateAfter.usages().size() == 1;
+                                    assert stateAfter.usages().count() == 1;
                                     invokeNode.node().replaceAtUsages(null);
                                     ValueNode result = callTarget.arguments().get(0);
                                     StructuredGraph graph = (StructuredGraph) node.graph();
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java	Fri Nov 30 11:39:05 2012 -0800
+++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java	Mon Dec 03 13:53:53 2012 +0100
@@ -151,7 +151,7 @@
             StateSplit split = (StateSplit) node;
             FrameState stateAfter = split.stateAfter();
             if (stateAfter != null) {
-                if (stateAfter.usages().size() > 1) {
+                if (stateAfter.usages().count() > 1) {
                     stateAfter = (FrameState) stateAfter.copyWithInputs();
                     split.setStateAfter(stateAfter);
                 }