changeset 5421:ce2398984e39

make ValueAnchorNode able to anchor multiple values, use dependencies for anchored values
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 22 May 2012 11:57:21 +0200
parents 44c378aa4c47
children 4e9723f38034
files graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/NodeIterable.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java
diffstat 2 files changed, 30 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/NodeIterable.java	Tue May 22 11:37:07 2012 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/NodeIterable.java	Tue May 22 11:57:21 2012 +0200
@@ -43,6 +43,9 @@
     public FilteredNodeIterable<T> filter(NodePredicate predicate) {
         return new FilteredNodeIterable<>(this).and(predicate);
     }
+    public FilteredNodeIterable<T> nonNull() {
+        return new FilteredNodeIterable<>(this).and(NodePredicates.isNotNull());
+    }
     public List<T> snapshot() {
         ArrayList<T> list = new ArrayList<>();
         for (T n : this) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java	Tue May 22 11:37:07 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java	Tue May 22 11:57:21 2012 +0200
@@ -22,12 +22,12 @@
  */
 package com.oracle.graal.nodes.extended;
 
-import com.oracle.max.cri.ci.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.calc.*;
 import com.oracle.graal.nodes.spi.*;
 import com.oracle.graal.nodes.type.*;
+import com.oracle.max.cri.ci.*;
 
 /**
  * The ValueAnchor instruction keeps non-CFG (floating) nodes above a certain point in the graph.
@@ -35,15 +35,9 @@
 
 public final class ValueAnchorNode extends FixedWithNextNode implements Canonicalizable, LIRLowerable, Node.IterableNodeType {
 
-    @Input private ValueNode object;
-
-    public ValueNode object() {
-        return object;
-    }
-
-    public ValueAnchorNode(ValueNode object) {
+    public ValueAnchorNode(ValueNode... values) {
         super(StampFactory.illegal());
-        this.object = object;
+        this.dependencies().addAll(values);
     }
 
     @Override
@@ -51,23 +45,36 @@
         // Nothing to emit, since this node is used for structural purposes only.
     }
 
+    public void addAnchoredValue(ValueNode value) {
+        this.dependencies().add(value);
+    }
+
     @Override
     public ValueNode canonical(CanonicalizerTool tool) {
-        if (object == null) {
-            return null;
-        }
-        if (object instanceof ConstantNode) {
+        if (this.predecessor() instanceof ValueAnchorNode) {
+            // transfer values and remove
+            ValueAnchorNode previousAnchor = (ValueAnchorNode) this.predecessor();
+            for (Node node : dependencies().nonNull()) {
+                previousAnchor.dependencies().add(node);
+            }
             return null;
         }
-        if (object instanceof IntegerDivNode || object instanceof IntegerRemNode) {
-            if (((ArithmeticNode) object).y().isConstant()) {
-                CiConstant  constant = ((ArithmeticNode) object).y().asConstant();
-                assert constant.kind == object.kind() : constant.kind + " != " + object.kind();
-                if (constant.asLong() != 0) {
-                    return null;
+        for (Node node : dependencies().nonNull()) {
+            if (node instanceof ConstantNode) {
+                continue;
+            }
+            if (node instanceof IntegerDivNode || node instanceof IntegerRemNode) {
+                ArithmeticNode arithmeticNode = (ArithmeticNode) node;
+                if (arithmeticNode.y().isConstant()) {
+                    CiConstant  constant = arithmeticNode.y().asConstant();
+                    assert constant.kind == arithmeticNode.kind() : constant.kind + " != " + arithmeticNode.kind();
+                    if (constant.asLong() != 0) {
+                        continue;
+                    }
                 }
             }
+            return this; // still necessary
         }
-        return this;
+        return null; // no node which require an anchor found
     }
 }