changeset 19551:14a30a0f631c

More usages of new acceptInputs and acceptSuccessors methods.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 23 Feb 2015 14:59:12 +0100
parents 3be278f50e4b
children cb7c6ccfff69
files graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Edges.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java
diffstat 3 files changed, 21 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Edges.java	Mon Feb 23 00:29:23 2015 +0100
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Edges.java	Mon Feb 23 14:59:12 2015 +0100
@@ -495,13 +495,13 @@
         return type;
     }
 
-    public void accept(Node node, Consumer<Node> consumer) {
+    public void accept(Node node, BiConsumer<Node, Node> consumer) {
         int index = 0;
         int curDirectCount = this.directCount;
         while (index < curDirectCount) {
             Node curNode = getNode(node, index);
             if (curNode != null) {
-                consumer.accept(curNode);
+                consumer.accept(node, curNode);
             }
             index++;
         }
@@ -512,7 +512,7 @@
                 for (int i = 0; i < list.size(); ++i) {
                     Node curNode = list.get(i);
                     if (curNode != null) {
-                        consumer.accept(curNode);
+                        consumer.accept(node, curNode);
                     }
                 }
             }
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java	Mon Feb 23 00:29:23 2015 +0100
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java	Mon Feb 23 14:59:12 2015 +0100
@@ -295,7 +295,7 @@
      *
      * @param consumer the consumer to be applied to the inputs
      */
-    public void acceptInputs(Consumer<Node> consumer) {
+    public void acceptInputs(BiConsumer<Node, Node> consumer) {
         nodeClass.getInputEdges().accept(this, consumer);
     }
 
@@ -314,7 +314,7 @@
      *
      * @param consumer the consumer to be applied to the inputs
      */
-    public void acceptSuccessors(Consumer<Node> consumer) {
+    public void acceptSuccessors(BiConsumer<Node, Node> consumer) {
         nodeClass.getSuccessorEdges().accept(this, consumer);
     }
 
@@ -402,7 +402,7 @@
      * @param node the node to remove
      * @return whether or not {@code usage} was in the usage list
      */
-    private boolean removeUsage(Node node) {
+    public boolean removeUsage(Node node) {
         assert node != null;
         // It is critical that this method maintains the invariant that
         // the usage list has no null element preceding a non-null element
@@ -520,12 +520,8 @@
         assert assertTrue(id == INITIAL_ID, "unexpected id: %d", id);
         this.graph = newGraph;
         newGraph.register(this);
-        for (Node input : inputs()) {
-            updateUsages(null, input);
-        }
-        for (Node successor : successors()) {
-            updatePredecessor(null, successor);
-        }
+        this.acceptInputs((n, i) -> n.updateUsages(null, i));
+        this.acceptSuccessors((n, s) -> n.updatePredecessor(null, s));
     }
 
     public final NodeClass<? extends Node> getNodeClass() {
@@ -677,7 +673,7 @@
     }
 
     private void unregisterSuccessors() {
-        this.acceptSuccessors(successor -> successor.predecessor = null);
+        this.acceptSuccessors((n, successor) -> successor.predecessor = null);
     }
 
     public void clearSuccessors() {
@@ -699,12 +695,12 @@
      */
     public void safeDelete() {
         assert checkDeletion();
-        unsafeDelete();
+        unregisterInputs();
+        unregisterSuccessors();
+        markDeleted();
     }
 
-    public void unsafeDelete() {
-        unregisterInputs();
-        unregisterSuccessors();
+    public void markDeleted() {
         graph.unregister(this);
         id = DELETED_ID_START - id;
         assert isDeleted();
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java	Mon Feb 23 00:29:23 2015 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java	Mon Feb 23 14:59:12 2015 +0100
@@ -112,13 +112,16 @@
         return FLOATING;
     }
 
-    public static void propagateKill(Node node) {
+    private static void propagateKill(Node node) {
         if (node != null && node.isAlive()) {
-            node.unsafeDelete();
+            node.markDeleted();
 
-            node.acceptInputs(in -> {
-                if (in.isAlive() && in.hasNoUsages() && !(in instanceof FixedNode)) {
-                    killWithUnusedFloatingInputs(in);
+            node.acceptInputs((n, in) -> {
+                if (in.isAlive()) {
+                    in.removeUsage(n);
+                    if (in.hasNoUsages() && !(in instanceof FixedNode)) {
+                        killWithUnusedFloatingInputs(in);
+                    }
                 }
             });