changeset 22044:5de4a002d097

Schedule: Allow floating reads to be scheduled after loops
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Sun, 21 Jun 2015 18:53:42 +0200
parents 770fdbe70bb3
children e38161633db6
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryScheduleTest.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java mx.graal/suite.py
diffstat 3 files changed, 33 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryScheduleTest.java	Sun Jun 21 22:24:40 2015 +0200
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryScheduleTest.java	Sun Jun 21 18:53:42 2015 +0200
@@ -23,6 +23,9 @@
 package com.oracle.graal.compiler.test;
 
 import static com.oracle.graal.compiler.common.GraalOptions.*;
+import static com.oracle.graal.graph.test.matchers.NodeIterableCount.*;
+import static org.hamcrest.core.IsInstanceOf.*;
+import static org.junit.Assert.*;
 
 import java.util.*;
 
@@ -32,7 +35,7 @@
 import com.oracle.graal.graph.*;
 import com.oracle.graal.graph.iterators.*;
 import com.oracle.graal.nodes.*;
-import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions;
+import com.oracle.graal.nodes.StructuredGraph.*;
 import com.oracle.graal.nodes.cfg.*;
 import com.oracle.graal.nodes.memory.*;
 import com.oracle.graal.nodes.spi.*;
@@ -41,12 +44,12 @@
 import com.oracle.graal.phases.common.*;
 import com.oracle.graal.phases.common.inlining.*;
 import com.oracle.graal.phases.schedule.*;
-import com.oracle.graal.phases.schedule.SchedulePhase.SchedulingStrategy;
+import com.oracle.graal.phases.schedule.SchedulePhase.*;
 import com.oracle.graal.phases.tiers.*;
 import com.oracle.jvmci.debug.*;
-import com.oracle.jvmci.debug.Debug.Scope;
+import com.oracle.jvmci.debug.Debug.*;
 import com.oracle.jvmci.options.*;
-import com.oracle.jvmci.options.OptionValue.OverrideScope;
+import com.oracle.jvmci.options.OptionValue.*;
 
 /**
  * In these test the FrameStates are explicitly cleared out, so that the scheduling of
@@ -342,6 +345,29 @@
     }
 
     /**
+     * Here the read should float after the loop.
+     */
+    public static int testLoop9Snippet(int a, int b) {
+        container.a = b;
+        for (int i = 0; i < a; i++) {
+            container.a = i;
+        }
+        GraalDirectives.controlFlowAnchor();
+        return container.a;
+    }
+
+    @Test
+    public void testLoop9() {
+        SchedulePhase schedule = getFinalSchedule("testLoop9Snippet", TestMode.WITHOUT_FRAMESTATES);
+        StructuredGraph graph = schedule.getCFG().getStartBlock().getBeginNode().graph();
+        assertThat(graph.getNodes(ReturnNode.TYPE), hasCount(1));
+        ReturnNode ret = graph.getNodes(ReturnNode.TYPE).first();
+        assertThat(ret.result(), instanceOf(FloatingReadNode.class));
+        Block readBlock = schedule.getNodeToBlockMap().get(ret.result());
+        Assert.assertEquals(0, readBlock.getLoopDepth());
+    }
+
+    /**
      * Here the read should float to the end (into the same block as the return).
      */
     public static int testArrayCopySnippet(Integer intValue, char[] a, char[] b, int len) {
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java	Sun Jun 21 22:24:40 2015 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java	Sun Jun 21 18:53:42 2015 +0200
@@ -243,12 +243,9 @@
         Block lastBlock = earliestBlock;
         for (int i = dominatorChain.size() - 1; i >= 0; --i) {
             Block currentBlock = dominatorChain.get(i);
-            if (lastBlock.getLoop() != currentBlock.getLoop()) {
-                // We are crossing a loop boundary. Both loops must not kill the location for the
+            if (currentBlock.getLoopDepth() > lastBlock.getLoopDepth()) {
+                // We are entering a loop boundary. The new loops must not kill the location for the
                 // crossing to be safe.
-                if (lastBlock.getLoop() != null && ((HIRLoop) lastBlock.getLoop()).canKill(location)) {
-                    break;
-                }
                 if (currentBlock.getLoop() != null && ((HIRLoop) currentBlock.getLoop()).canKill(location)) {
                     break;
                 }
--- a/mx.graal/suite.py	Sun Jun 21 22:24:40 2015 +0200
+++ b/mx.graal/suite.py	Sun Jun 21 18:53:42 2015 +0200
@@ -1069,6 +1069,7 @@
         "com.oracle.graal.java",
         "com.oracle.graal.test",
         "com.oracle.graal.runtime",
+        "com.oracle.graal.graph.test",
         "JAVA_ALLOCATION_INSTRUMENTER",
       ],
       "checkstyle" : "com.oracle.graal.graph",
@@ -1124,7 +1125,6 @@
       "sourceDirs" : ["src"],
       "dependencies" : [
         "com.oracle.graal.truffle",
-        "com.oracle.graal.graph.test",
         "com.oracle.graal.compiler.test",
         "TRUFFLE_SL",
       ],