changeset 11456:95a56d151d27

Rewrite compute block order function to be non-recursive due to stack overflow when G1 is used in eclipse
author Christos Kotselidis <christos.kotselidis@oracle.com>
date Thu, 29 Aug 2013 13:52:25 +0200
parents dafee8e3eecd
children fd1383d45420
files graal/com.oracle.graal.alloc/src/com/oracle/graal/alloc/ComputeBlockOrder.java
diffstat 1 files changed, 27 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.alloc/src/com/oracle/graal/alloc/ComputeBlockOrder.java	Wed Aug 28 15:22:51 2013 +0200
+++ b/graal/com.oracle.graal.alloc/src/com/oracle/graal/alloc/ComputeBlockOrder.java	Thu Aug 29 13:52:25 2013 +0200
@@ -152,39 +152,40 @@
     /**
      * Add a linear path to the code emission order greedily following the most likely successor.
      */
-    private static void addPathToCodeEmittingOrder(Block block, List<Block> order, PriorityQueue<Block> worklist, BitSet visitedBlocks, NodesToDoubles nodeProbabilities) {
-
-        // Skip loop headers if there is only a single loop end block to make the backward jump be a
-        // conditional jump.
-        if (!skipLoopHeader(block)) {
+    private static void addPathToCodeEmittingOrder(Block initialBlock, List<Block> order, PriorityQueue<Block> worklist, BitSet visitedBlocks, NodesToDoubles nodeProbabilities) {
+        Block block = initialBlock;
+        while (block != null) {
+            // Skip loop headers if there is only a single loop end block to
+            // make the backward jump be a conditional jump.
+            if (!skipLoopHeader(block)) {
 
-            // Align unskipped loop headers as they are the target of the backward jump.
-            if (block.isLoopHeader()) {
-                block.setAlign(true);
+                // Align unskipped loop headers as they are the target of the backward jump.
+                if (block.isLoopHeader()) {
+                    block.setAlign(true);
+                }
+                addBlock(block, order);
             }
-            addBlock(block, order);
-        }
 
-        Loop loop = block.getLoop();
-        if (block.isLoopEnd() && skipLoopHeader(loop.header)) {
+            Loop loop = block.getLoop();
+            if (block.isLoopEnd() && skipLoopHeader(loop.header)) {
+
+                // This is the only loop end of a skipped loop header.
+                // Add the header immediately afterwards.
+                addBlock(loop.header, order);
 
-            // This is the only loop end of a skipped loop header. Add the header immediately
-            // afterwards.
-            addBlock(loop.header, order);
-
-            // Make sure the loop successors of the loop header are aligned as they are the target
-            // of the backward jump.
-            for (Block successor : loop.header.getSuccessors()) {
-                if (successor.getLoopDepth() == block.getLoopDepth()) {
-                    successor.setAlign(true);
+                // Make sure the loop successors of the loop header are aligned
+                // as they are the target
+                // of the backward jump.
+                for (Block successor : loop.header.getSuccessors()) {
+                    if (successor.getLoopDepth() == block.getLoopDepth()) {
+                        successor.setAlign(true);
+                    }
                 }
             }
-        }
 
-        Block mostLikelySuccessor = findAndMarkMostLikelySuccessor(block, visitedBlocks, nodeProbabilities);
-        enqueueSuccessors(block, worklist, visitedBlocks);
-        if (mostLikelySuccessor != null) {
-            addPathToCodeEmittingOrder(mostLikelySuccessor, order, worklist, visitedBlocks, nodeProbabilities);
+            Block mostLikelySuccessor = findAndMarkMostLikelySuccessor(block, visitedBlocks, nodeProbabilities);
+            enqueueSuccessors(block, worklist, visitedBlocks);
+            block = mostLikelySuccessor;
         }
     }