changeset 5272:a44b5ebb28a0

moved loop safepoint insertion from graph building to just before scheduling, removing the need for safepoint elimination
author Doug Simon <doug.simon@oracle.com>
date Mon, 23 Apr 2012 10:27:17 +0200
parents e7f3f0541429
children 7689999f0ea6
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopSafepointInsertionPhase.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/SafepointPollingEliminationPhase.java graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java
diffstat 4 files changed, 57 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java	Fri Apr 20 15:12:10 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java	Mon Apr 23 10:27:17 2012 +0200
@@ -170,9 +170,6 @@
             if (GraalOptions.OptLoopTransform) {
                 new LoopTransformPhase().apply(graph);
             }
-            if (GraalOptions.OptSafepointElimination) {
-                new SafepointPollingEliminationPhase().apply(graph);
-            }
         }
         new RemoveValueProxyPhase().apply(graph);
         if (GraalOptions.OptCanonicalizer) {
@@ -211,6 +208,11 @@
 
         plan.runPhases(PhasePosition.LOW_LEVEL, graph);
 
+        // Add safepoints to loops
+        if (GraalOptions.GenLoopSafepoints) {
+            new LoopSafepointInsertionPhase().apply(graph);
+        }
+
         final SchedulePhase schedule = new SchedulePhase();
         schedule.apply(graph);
         Debug.dump(schedule, "final schedule");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopSafepointInsertionPhase.java	Mon Apr 23 10:27:17 2012 +0200
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.compiler.phases;
+
+import com.oracle.graal.compiler.*;
+import com.oracle.graal.graph.iterators.*;
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.util.*;
+
+/**
+ * Adds safepoints to loops.
+ */
+public class LoopSafepointInsertionPhase extends Phase {
+
+    @Override
+    protected void run(StructuredGraph graph) {
+        nextLoop:
+        for (LoopEndNode loopEnd : graph.getNodes(LoopEndNode.class)) {
+            if (GraalOptions.OptSafepointElimination) {
+                // We 'eliminate' safepoints by simply never placing them into loops that have at least one call
+                NodeIterable<FixedNode> it = NodeIterators.dominators(loopEnd).until(loopEnd.loopBegin());
+                for (FixedNode n : it) {
+                    if (n instanceof Invoke) {
+                        continue nextLoop;
+                    }
+                }
+            }
+            SafepointNode safepoint = graph.add(new SafepointNode());
+            graph.addBeforeFixed(loopEnd, safepoint);
+        }
+    }
+}
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/SafepointPollingEliminationPhase.java	Fri Apr 20 15:12:10 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.compiler.phases;
-
-import com.oracle.graal.graph.iterators.*;
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.util.*;
-
-/**
- * Removes safepoints from loops that include calls.
- * This optimization is conservative; it does not try to remove safepoints from outer loops.
- */
-public class SafepointPollingEliminationPhase extends Phase {
-
-    @Override
-    protected void run(StructuredGraph graph) {
-        for (SafepointNode safepoint : graph.getNodes(SafepointNode.class)) {
-            LoopEndNode loopEnd = safepoint.loopEnd();
-            if (loopEnd != null) {
-                NodeIterable<FixedNode> it = NodeIterators.dominators(loopEnd).until(loopEnd.loopBegin());
-                for (FixedNode n : it) {
-                    if (n instanceof Invoke) {
-                        graph.removeFixed(safepoint);
-                        break;
-                    }
-                }
-            }
-        }
-    }
-}
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Fri Apr 20 15:12:10 2012 +0200
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Mon Apr 23 10:27:17 2012 +0200
@@ -186,14 +186,6 @@
             currentGraph.removeFixed(n);
         }
 
-        // Add safepoints to loop ends
-        if (GraalOptions.GenLoopSafepoints) {
-            for (LoopEndNode loopEnd : currentGraph.getNodes(LoopEndNode.class)) {
-                SafepointNode safepoint = currentGraph.add(new SafepointNode());
-                currentGraph.addBeforeFixed(loopEnd, safepoint);
-            }
-        }
-
         // remove dead FrameStates
         for (Node n : currentGraph.getNodes(FrameState.class)) {
             if (n.usages().size() == 0 && n.predecessor() == null) {