changeset 11711:f12b418ebc74

Allow only single input for value anchors.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Thu, 19 Sep 2013 02:20:46 +0200
parents 8d8a7d7f0259
children 0d16339188ef
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FixedGuardNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/TailDuplicationPhase.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ValueAnchorCleanupPhase.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/TypeCastNode.java
diffstat 7 files changed, 31 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FixedGuardNode.java	Thu Sep 19 01:50:08 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FixedGuardNode.java	Thu Sep 19 02:20:46 2013 +0200
@@ -108,9 +108,9 @@
     @Override
     public void lower(LoweringTool tool) {
         if (graph().getGuardsStage() == StructuredGraph.GuardsStage.FLOATING_GUARDS) {
-            GuardingNode guard = tool.createGuard(condition(), getReason(), getAction(), isNegated());
+            ValueNode guard = tool.createGuard(condition(), getReason(), getAction(), isNegated()).asNode();
+            this.replaceAtUsages(guard);
             ValueAnchorNode newAnchor = graph().add(new ValueAnchorNode(guard.asNode()));
-            this.replaceAtUsages(guard.asNode());
             graph().replaceFixedWithFixed(this, newAnchor);
         } else {
             FixedNode next = next();
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java	Thu Sep 19 01:50:08 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java	Thu Sep 19 02:20:46 2013 +0200
@@ -22,8 +22,6 @@
  */
 package com.oracle.graal.nodes.extended;
 
-import static com.oracle.graal.graph.iterators.NodePredicates.*;
-
 import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.spi.*;
@@ -34,11 +32,11 @@
  */
 public final class ValueAnchorNode extends FixedWithNextNode implements Canonicalizable, LIRLowerable, IterableNodeType, Virtualizable, GuardingNode {
 
-    @Input private final NodeInputList<ValueNode> anchored;
+    @Input private ValueNode anchored;
 
-    public ValueAnchorNode(ValueNode... values) {
+    public ValueAnchorNode(ValueNode value) {
         super(StampFactory.dependency());
-        this.anchored = new NodeInputList<>(this, values);
+        this.anchored = value;
     }
 
     @Override
@@ -46,51 +44,39 @@
         // Nothing to emit, since this node is used for structural purposes only.
     }
 
-    public void addAnchoredNode(ValueNode value) {
-        if (!anchored.contains(value)) {
-            this.anchored.add(value);
-        }
-    }
-
-    public void removeAnchoredNode(ValueNode value) {
-        this.anchored.remove(value);
-    }
-
-    public NodeInputList<ValueNode> getAnchoredNodes() {
+    public ValueNode getAnchoredNode() {
         return anchored;
     }
 
     @Override
     public ValueNode canonical(CanonicalizerTool tool) {
-        if (this.predecessor() instanceof ValueAnchorNode) {
-            ValueAnchorNode previousAnchor = (ValueAnchorNode) this.predecessor();
-            if (previousAnchor.usages().isEmpty()) { // avoid creating cycles
-                // transfer values and remove
-                for (ValueNode node : anchored.nonNull().distinct()) {
-                    previousAnchor.addAnchoredNode(node);
-                }
-                return previousAnchor;
-            }
+        if (anchored != null && !anchored.isConstant()) {
+            // Found entry that needs this anchor.
+            return this;
         }
-        for (Node node : anchored.nonNull().and(isNotA(FixedNode.class))) {
-            if (!(node instanceof ConstantNode)) {
-                return this; // still necessary
-            }
+
+        if (usages().isNotEmpty()) {
+            // A not uses this anchor => anchor is necessary.
+            return this;
         }
-        if (usages().isEmpty()) {
-            return null; // no node which require an anchor found
-        }
-        return this;
+
+        // Anchor is not necessary any more => remove.
+        return null;
     }
 
     @Override
     public void virtualize(VirtualizerTool tool) {
-        for (ValueNode node : anchored.nonNull().and(isNotA(AbstractBeginNode.class))) {
-            State state = tool.getObjectState(node);
+        if (anchored != null && !(anchored instanceof AbstractBeginNode)) {
+            State state = tool.getObjectState(anchored);
             if (state == null || state.getState() != EscapeState.Virtual) {
                 return;
             }
         }
         tool.delete();
     }
+
+    public void removeAnchoredNode() {
+        this.updateUsages(anchored, null);
+        this.anchored = null;
+    }
 }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java	Thu Sep 19 01:50:08 2013 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java	Thu Sep 19 02:20:46 2013 +0200
@@ -505,7 +505,7 @@
                     }
                     ValueAnchorNode anchor = null;
                     if (replacementAnchor == null) {
-                        anchor = graph.add(new ValueAnchorNode());
+                        anchor = graph.add(new ValueAnchorNode(null));
                         replacementAnchor = anchor;
                     }
                     PiNode piNode;
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/TailDuplicationPhase.java	Thu Sep 19 01:50:08 2013 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/TailDuplicationPhase.java	Thu Sep 19 02:20:46 2013 +0200
@@ -309,7 +309,7 @@
          * @return The new {@link ValueAnchorNode} that was created.
          */
         private ValueAnchorNode addValueAnchor() {
-            ValueAnchorNode anchor = graph.add(new ValueAnchorNode());
+            ValueAnchorNode anchor = graph.add(new ValueAnchorNode(null));
             graph.addAfterFixed(merge, anchor);
             for (Node usage : merge.usages().snapshot()) {
                 if (usage instanceof PhiNode && ((PhiNode) usage).merge() == merge) {
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ValueAnchorCleanupPhase.java	Thu Sep 19 01:50:08 2013 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ValueAnchorCleanupPhase.java	Thu Sep 19 02:20:46 2013 +0200
@@ -73,14 +73,15 @@
         protected void node(FixedNode node) {
             if (node instanceof ValueAnchorNode) {
                 ValueAnchorNode anchor = (ValueAnchorNode) node;
-                for (ValueNode anchored : anchor.getAnchoredNodes().snapshot()) {
+                ValueNode anchored = anchor.getAnchoredNode();
+                if (anchored != null) {
                     if (state.anchoredValues.contains(anchored)) {
-                        anchor.removeAnchoredNode(anchored);
+                        anchor.removeAnchoredNode();
                     } else {
                         state.anchoredValues.add(anchored);
                     }
                 }
-                if (anchor.getAnchoredNodes().isEmpty() && anchor.usages().isEmpty()) {
+                if (anchor.getAnchoredNode() == null && anchor.usages().isEmpty()) {
                     node.graph().removeFixed(anchor);
                 }
             }
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java	Thu Sep 19 01:50:08 2013 +0200
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java	Thu Sep 19 02:20:46 2013 +0200
@@ -302,7 +302,7 @@
     private static void checkCheckCastUsage(StructuredGraph graph, Node intrinsifiedNode, Node input, Node usage) {
         if (usage instanceof ValueAnchorNode) {
             ValueAnchorNode valueAnchorNode = (ValueAnchorNode) usage;
-            valueAnchorNode.removeAnchoredNode((ValueNode) input);
+            valueAnchorNode.removeAnchoredNode();
             Debug.log("%s: Removed a ValueAnchor input", Debug.contextSnapshot(JavaMethod.class));
         } else if (usage instanceof UnboxNode) {
             UnboxNode unbox = (UnboxNode) usage;
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/TypeCastNode.java	Thu Sep 19 01:50:08 2013 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/TypeCastNode.java	Thu Sep 19 02:20:46 2013 +0200
@@ -61,7 +61,7 @@
 
     public void lower(LoweringTool tool) {
         if (graph().getGuardsStage() == StructuredGraph.GuardsStage.FLOATING_GUARDS) {
-            ValueAnchorNode valueAnchorNode = graph().add(new ValueAnchorNode());
+            ValueAnchorNode valueAnchorNode = graph().add(new ValueAnchorNode(null));
             UnsafeCastNode unsafeCast = graph().unique(new UnsafeCastNode(object, this.stamp(), (GuardingNode) valueAnchorNode));
             this.replaceAtUsages(unsafeCast);
             graph().replaceFixedWithFixed(this, valueAnchorNode);