changeset 4311:8e2c4affcd51

more structured graph modification usage
author Lukas Stadler <lukas.stadler@jku.at>
date Thu, 19 Jan 2012 18:53:48 +0100
parents 72d099e5be61
children 8dd27e218e19
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/FindInductionVariablesPhase.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/loop/BasicInductionVariableNode.java graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/loop/DerivedInductionVariableNode.java
diffstat 4 files changed, 41 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/FindInductionVariablesPhase.java	Wed Jan 18 15:09:19 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/FindInductionVariablesPhase.java	Thu Jan 19 18:53:48 2012 +0100
@@ -64,47 +64,44 @@
                 continue;
             }
             if (loopNodes.isMarked(backEdge)) {
-                BinaryNode binary;
                 if (backEdge instanceof IntegerAddNode || backEdge instanceof IntegerSubNode) {
-                    binary = (BinaryNode) backEdge;
-                } else {
-                    continue;
-                }
-                ValueNode stride;
-                if (binary.x() == phi) {
-                    stride = binary.y();
-                } else if (binary.y() == phi) {
-                    stride = binary.x();
-                } else {
-                    continue;
-                }
-                if (loopNodes.isNotNewNotMarked(stride)) {
-                    Graph graph = loopBegin.graph();
-                    if (backEdge instanceof IntegerSubNode) {
-                        stride = graph.unique(new NegateNode(stride));
+                    final IntegerArithmeticNode arithmetic = (IntegerArithmeticNode) backEdge;
+                    ValueNode stride;
+                    if (arithmetic.x() == phi) {
+                        stride = arithmetic.y();
+                    } else if (arithmetic.y() == phi) {
+                        stride = arithmetic.x();
+                    } else {
+                        continue;
                     }
-                    CiKind kind = phi.kind();
-                    LoopCounterNode counter = loopBegin.loopCounter(kind);
-                    BasicInductionVariableNode biv1 = null;
-                    BasicInductionVariableNode biv2 = null;
-                    if (phi.usages().size() > 1) {
-                        biv1 = graph.add(new BasicInductionVariableNode(kind, init, stride, counter));
-                        phi.replaceAndDelete(biv1);
-                    } else {
-                        phi.replaceFirstInput(binary, null);
-                        phi.safeDelete();
-                    }
-                    if (backEdge.usages().size() > 0) {
-                        biv2 = graph.add(new BasicInductionVariableNode(kind, IntegerArithmeticNode.add(init, stride), stride, counter));
-                        backEdge.replaceAndDelete(biv2);
-                    } else {
-                        backEdge.safeDelete();
-                    }
-                    if (biv1 != null) {
-                        findDerivedInductionVariable(biv1, kind, loopNodes);
-                    }
-                    if (biv2 != null) {
-                        findDerivedInductionVariable(biv2, kind, loopNodes);
+                    if (loopNodes.isNotNewNotMarked(stride)) {
+                        Graph graph = loopBegin.graph();
+                        if (arithmetic instanceof IntegerSubNode) {
+                            stride = graph.unique(new NegateNode(stride));
+                        }
+                        CiKind kind = phi.kind();
+                        LoopCounterNode counter = loopBegin.loopCounter(kind);
+                        BasicInductionVariableNode biv1 = null;
+                        BasicInductionVariableNode biv2 = null;
+                        if (phi.usages().size() > 1) {
+                            biv1 = graph.add(new BasicInductionVariableNode(kind, init, stride, counter));
+                            ((StructuredGraph) phi.graph()).replaceFloating(phi, biv1);
+                        } else {
+                            phi.replaceFirstInput(arithmetic, null);
+                            phi.safeDelete();
+                        }
+                        if (arithmetic.usages().size() > 0) {
+                            biv2 = graph.add(new BasicInductionVariableNode(kind, IntegerArithmeticNode.add(init, stride), stride, counter));
+                            ((StructuredGraph) arithmetic.graph()).replaceFloating(arithmetic, biv2);
+                        } else {
+                            arithmetic.safeDelete();
+                        }
+                        if (biv1 != null) {
+                            findDerivedInductionVariable(biv1, kind, loopNodes);
+                        }
+                        if (biv2 != null) {
+                            findDerivedInductionVariable(biv2, kind, loopNodes);
+                        }
                     }
                 }
             }
@@ -141,7 +138,8 @@
                     offset = ConstantNode.forIntegerKind(kind, 0, biv.graph());
                 }
                 DerivedInductionVariableNode div = biv.graph().add(new DerivedInductionVariableNode(kind, offset, scale, biv));
-                node.replaceAndDelete(div);
+                assert node instanceof FloatingNode;
+                ((StructuredGraph) node.graph()).replaceFloating((FloatingNode) node, div);
             }
         }
     }
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java	Wed Jan 18 15:09:19 2012 +0100
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java	Thu Jan 19 18:53:48 2012 +0100
@@ -222,6 +222,7 @@
     private boolean checkReplaceWith(Node other) {
         assert assertFalse(other == this, "cannot replace a node with itself");
         assert assertFalse(isDeleted(), "cannot replace deleted node");
+//        assert assertTrue(other != null, "cannot replace with null node");
         assert assertTrue(other == null || !other.isDeleted(), "cannot replace with deleted node %s", other);
         assert assertTrue(other == null || other.graph() == graph, "cannot replace with node in different graph: %s", other == null ? null : other.graph());
         return true;
@@ -308,10 +309,6 @@
 
     public void safeDelete() {
         assert checkDeletion();
-        delete();
-    }
-
-    private void delete() {
         clearInputs();
         clearSuccessors();
         graph.unregister(this);
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/loop/BasicInductionVariableNode.java	Wed Jan 18 15:09:19 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/loop/BasicInductionVariableNode.java	Thu Jan 19 18:53:48 2012 +0100
@@ -78,7 +78,7 @@
      */
     public DerivedInductionVariableNode toDerivedInductionVariable() {
         DerivedInductionVariableNode newDIV = graph().add(new DerivedInductionVariableNode(kind(), init(), stride(), loopCounter()));
-        this.replaceAndDelete(newDIV);
+        ((StructuredGraph) graph()).replaceFloating(this, newDIV);
         return newDIV;
     }
 
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/loop/DerivedInductionVariableNode.java	Wed Jan 18 15:09:19 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/loop/DerivedInductionVariableNode.java	Thu Jan 19 18:53:48 2012 +0100
@@ -95,7 +95,7 @@
             counter = (LoopCounterNode) b;
         }
         BasicInductionVariableNode newBIV = graph().add(new BasicInductionVariableNode(kind(), init, stride, counter));
-        this.replaceAndDelete(newBIV);
+        ((StructuredGraph) graph()).replaceFloating(this, newBIV);
         return newBIV;
     }