changeset 5215:ae367987a18c

Add options for OptLoopTransform and OptSafepointElimination
author Gilles Duboscq <duboscq@ssw.jku.at>
date Mon, 09 Apr 2012 20:30:41 +0200
parents 1020e363a05d
children b64933dc4830
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/SuperBlock.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopTransformPhase.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java
diffstat 5 files changed, 42 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java	Mon Apr 09 19:59:01 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java	Mon Apr 09 20:30:41 2012 +0200
@@ -168,8 +168,12 @@
             }
         }
         if (GraalOptions.OptLoops) {
-            new LoopTransformPhase().apply(graph);
-            new SafepointPollingEliminationPhase().apply(graph);
+            if (GraalOptions.OptLoopTransform) {
+                new LoopTransformPhase().apply(graph);
+            }
+            if (GraalOptions.OptSafepointElimination) {
+                new SafepointPollingEliminationPhase().apply(graph);
+            }
         }
         new RemoveValueProxyPhase().apply(graph);
         if (GraalOptions.OptCanonicalizer) {
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java	Mon Apr 09 19:59:01 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java	Mon Apr 09 20:30:41 2012 +0200
@@ -193,12 +193,14 @@
     public static boolean OptReadElimination                 = true;
     public static boolean OptGVN                             = true;
     public static boolean OptCanonicalizer                   = true;
-    public static boolean OptLoops                           = ____;
+    public static boolean OptLoops                           = true;
     public static boolean ScheduleOutOfLoops                 = true;
     public static boolean OptReorderLoops                    = true;
     public static boolean OptEliminateGuards                 = true;
     public static boolean OptImplicitNullChecks              = true;
     public static boolean OptLivenessAnalysis                = true;
+    public static boolean OptLoopTransform                   = true;
+    public static boolean OptSafepointElimination            = true;
 
     /**
      * Flag to turn on SSA-based register allocation, which is currently under development.
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/SuperBlock.java	Mon Apr 09 19:59:01 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/SuperBlock.java	Mon Apr 09 20:30:41 2012 +0200
@@ -39,6 +39,7 @@
     protected LoopBeginNode loop;
     protected Map<Node, Node> duplicationMapping;
     protected SuperBlock original;
+    protected NodeBitMap loopNodes;
 
     public SuperBlock(BeginNode entry, BeginNode exit, List<BeginNode> blocks, List<BeginNode> earlyExits, LoopBeginNode loop) {
         this.entry = entry;
@@ -58,8 +59,15 @@
         return entry;
     }
 
+    public NodeBitMap loopNodes() {
+        if (loopNodes == null) {
+            loopNodes = computeNodes();
+        }
+        return loopNodes;
+    }
+
     public SuperBlock duplicate() {
-        NodeBitMap nodes = computeNodes();
+        NodeBitMap nodes = loopNodes();
         Map<Node, Node> replacements = new HashMap<>();
         StructuredGraph graph = (StructuredGraph) entry.graph();
         BeginNode newEntry = graph.add(new BeginNode());
@@ -264,46 +272,46 @@
     }
 
     private NodeBitMap computeNodes() {
-        NodeBitMap loopNodes = entry.graph().createNodeBitMap();
+        NodeBitMap nodes = entry.graph().createNodeBitMap();
         for (BeginNode b : blocks) {
             for (Node n : b.getBlockNodes()) {
                 if (n instanceof Invoke) {
-                    loopNodes.mark(((Invoke) n).callTarget());
+                    nodes.mark(((Invoke) n).callTarget());
                 }
                 if (n instanceof StateSplit) {
                     FrameState stateAfter = ((StateSplit) n).stateAfter();
                     if (stateAfter != null) {
-                        loopNodes.mark(stateAfter);
+                        nodes.mark(stateAfter);
                     }
                 }
-                loopNodes.mark(n);
+                nodes.mark(n);
             }
         }
         for (BeginNode earlyExit : earlyExits) {
             FrameState stateAfter = earlyExit.stateAfter();
             assert stateAfter != null;
-            loopNodes.mark(stateAfter);
-            loopNodes.mark(earlyExit);
+            nodes.mark(stateAfter);
+            nodes.mark(earlyExit);
             for (ValueProxyNode proxy : earlyExit.proxies()) {
-                loopNodes.mark(proxy);
+                nodes.mark(proxy);
             }
         }
 
         for (BeginNode b : blocks) {
             for (Node n : b.getBlockNodes()) {
                 for (Node usage : n.usages()) {
-                    markFloating(usage, loopNodes, "");
+                    markFloating(usage, nodes, "");
                 }
             }
         }
 
         if (entry instanceof LoopBeginNode) {
             for (PhiNode phi : ((LoopBeginNode) entry).phis()) {
-                loopNodes.clear(phi);
+                nodes.clear(phi);
             }
         }
 
-        return loopNodes;
+        return nodes;
     }
 
     private static boolean markFloating(Node n, NodeBitMap loopNodes, String ind) {
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopTransformPhase.java	Mon Apr 09 19:59:01 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopTransformPhase.java	Mon Apr 09 20:30:41 2012 +0200
@@ -36,6 +36,7 @@
         if (graph.hasLoops()) {
             ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false);
             Loop[] loops = cfg.getLoops();
+            // outermost first
             Arrays.sort(loops, new Comparator<Loop>() {
                 @Override
                 public int compare(Loop o1, Loop o2) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java	Mon Apr 09 19:59:01 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java	Mon Apr 09 20:30:41 2012 +0200
@@ -61,27 +61,26 @@
             // This begin node is necessary.
         } else {
             // This begin node can be removed and all guards moved up to the preceding begin node.
-            if (!usages().isEmpty()) {
-                Node prevBegin = prev;
-                while (!(prevBegin instanceof BeginNode)) {
-                    prevBegin = prevBegin.predecessor();
-                }
-                for (Node usage : usages()) {
-                    tool.addToWorkList(usage);
-                }
-                replaceAtUsages(prevBegin);
-            }
+            prepareDelete();
             ((StructuredGraph) graph()).removeFixed(this);
         }
     }
 
+    public static BeginNode prevBegin(FixedNode from) {
+        Node prevBegin = from;
+        while (prevBegin != null) {
+            if (prevBegin instanceof BeginNode) {
+                return (BeginNode) prevBegin;
+            }
+            prevBegin = prevBegin.predecessor();
+        }
+        return null;
+    }
+
     public void evacuateGuards(FixedNode evacuateFrom) {
         if (!usages().isEmpty()) {
-            Node prevBegin = evacuateFrom;
+            BeginNode prevBegin = prevBegin(evacuateFrom);
             assert prevBegin != null;
-            while (!(prevBegin instanceof BeginNode)) {
-                prevBegin = prevBegin.predecessor();
-            }
             for (Node anchored : anchored().snapshot()) {
                 anchored.replaceFirstInput(this, prevBegin);
             }