changeset 4617:113d66f7454d

Add merge-before-loopend simplification for merges
author Gilles Duboscq <duboscq@ssw.jku.at>
date Thu, 16 Feb 2012 14:43:05 +0100
parents 53168434d0df
children d8e84cf186a4
files graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/LoopBeginNode.java graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/MergeNode.java src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/filters/color.filter
diffstat 3 files changed, 50 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/LoopBeginNode.java	Thu Feb 16 13:48:47 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/LoopBeginNode.java	Thu Feb 16 14:43:05 2012 +0100
@@ -83,6 +83,7 @@
                     le.setEndIndex(leIdx - 1);
                 }
             }
+            nextEndIndex--;
         } else {
             super.deleteEnd(end);
         }
@@ -98,7 +99,7 @@
         if (pred instanceof LoopEndNode) {
             LoopEndNode loopEnd = (LoopEndNode) pred;
             if (loopEnd.loopBegin() == this) {
-                assert loopEnd.endIndex() < loopEnds().count();
+                assert loopEnd.endIndex() < loopEnds().count() : "Invalid endIndex : " + loopEnd;
                 return loopEnd.endIndex() + forwardEndCount();
             }
         } else {
@@ -139,4 +140,9 @@
     public int nextEndIndex() {
         return nextEndIndex++;
     }
+
+    @Override
+    public void simplify(SimplifierTool tool) {
+        // nothing yet
+    }
 }
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/MergeNode.java	Thu Feb 16 13:48:47 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/MergeNode.java	Thu Feb 16 14:43:05 2012 +0100
@@ -22,6 +22,9 @@
  */
 package com.oracle.max.graal.nodes;
 
+import static com.oracle.max.graal.graph.iterators.NodePredicates.*;
+
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.graph.iterators.*;
 import com.oracle.max.graal.nodes.spi.*;
@@ -114,4 +117,43 @@
     public NodeIterable<PhiNode> phis() {
         return this.usages().filter(PhiNode.class);
     }
+
+    @Override
+    public void simplify(SimplifierTool tool) {
+        FixedNode next = next();
+        if (next instanceof LoopEndNode) {
+            LoopEndNode origLoopEnd = (LoopEndNode) next;
+            LoopBeginNode begin = origLoopEnd.loopBegin();
+            for (PhiNode phi : phis()) {
+                for (Node usage : phi.usages().filter(isNotA(FrameState.class))) {
+                    if (!begin.isPhiAtMerge(usage)) {
+                        return;
+                    }
+                }
+            }
+            Debug.log("Split %s into loop ends for %s", this, begin);
+            int numEnds = this.forwardEndCount();
+            StructuredGraph graph = (StructuredGraph) graph();
+            for (int i = 0; i < numEnds - 1; i++) {
+                EndNode end = forwardEndAt(numEnds - 1 - i);
+                LoopEndNode loopEnd = graph.add(new LoopEndNode(begin));
+                for (PhiNode phi : begin.phis()) {
+                    ValueNode v = phi.valueAt(origLoopEnd);
+                    ValueNode newInput;
+                    if (isPhiAtMerge(v)) {
+                        PhiNode endPhi = (PhiNode) v;
+                        newInput = endPhi.valueAt(end);
+                    } else {
+                        newInput = v;
+                    }
+                    phi.addInput(newInput);
+                }
+                this.removeEnd(end);
+                end.replaceAtPredecessors(loopEnd);
+                end.safeDelete();
+                tool.addToWorkList(loopEnd.predecessor());
+            }
+            graph.reduceTrivialMerge(this);
+        }
+    }
 }
--- a/src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/filters/color.filter	Thu Feb 16 13:48:47 2012 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/filters/color.filter	Thu Feb 16 14:43:05 2012 +0100
@@ -5,7 +5,7 @@
 colorize("name", "If|Merge", pink);
 colorize("name", "const.*", new java.awt.Color(0.7, 0.7, 0.7));
 colorize("name", "Local", new java.awt.Color(0.85, 0.85, 0.85));
-colorize("name", "\\+|-|\\*|/", cyan);
+colorize("name", "\\+|-|\\*|/|&|\\||<<|>>|>>>", cyan);
 colorize("name", "Comp .*", yellow);
 
 colorize("notInOwnBlock", "true", red);
\ No newline at end of file