changeset 5784:182d5b57967e

order successors by probability in ComputeLinearScanOrder
author Lukas Stadler <lukas.stadler@jku.at>
date Fri, 06 Jul 2012 16:21:46 +0200
parents 22b0cb49cc60
children e5f0cf5b5627
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/ComputeLinearScanOrder.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/Util.java
diffstat 3 files changed, 36 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/ComputeLinearScanOrder.java	Fri Jul 06 16:20:55 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/ComputeLinearScanOrder.java	Fri Jul 06 16:21:46 2012 +0200
@@ -27,6 +27,7 @@
 
 import com.oracle.max.criutils.*;
 import com.oracle.graal.compiler.*;
+import com.oracle.graal.compiler.util.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.lir.cfg.*;
 import com.oracle.graal.nodes.*;
@@ -304,15 +305,21 @@
             Block cur = workList.remove(workList.size() - 1);
             appendBlock(cur);
 
-            // make the most successor with the highest probability the immediate successor
             Node endNode = cur.getEndNode();
-            if (endNode instanceof IfNode && ((IfNode) endNode).probability() < 0.5) {
-                assert cur.numberOfSux() == 2;
-                if (readyForProcessing(cur.suxAt(1))) {
-                    sortIntoWorkList(cur.suxAt(1));
-                }
-                if (readyForProcessing(cur.suxAt(0))) {
-                    sortIntoWorkList(cur.suxAt(0));
+            if (endNode instanceof ControlSplitNode) {
+                // Sort the successors according to their probabilities:
+                final ControlSplitNode split = (ControlSplitNode) endNode;
+                Integer[] indexes = Util.createSortedPermutation(split.blockSuccessorCount(), new Comparator<Integer>() {
+                    @Override
+                    public int compare(Integer o1, Integer o2) {
+                        return split.probability(o1) < split.probability(o2) ? 1 : split.probability(o1) > split.probability(o2) ? -1 : 0;
+                    }
+                });
+                for (int index : indexes) {
+                    Block sux = cur.getSuccessors().get(indexes[index]);
+                    if (readyForProcessing(sux)) {
+                        sortIntoWorkList(sux);
+                    }
                 }
             } else {
                 for (Block sux : cur.getSuccessors()) {
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java	Fri Jul 06 16:20:55 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java	Fri Jul 06 16:21:46 2012 +0200
@@ -343,6 +343,7 @@
             if (curLocks == null) {
                 curLocks = predLocks;
             } else if (curLocks != predLocks && (!pred.isLoopEnd() || predLocks != null)) {
+//                throw new GraalInternalError("cause: %s", predLocks);
                 throw new BailoutException("unbalanced monitors: predecessor blocks have different monitor states");
             }
         }
@@ -1056,11 +1057,7 @@
 
     private void emitSequentialSwitch(final SwitchNode x, Variable key, LabelRef defaultTarget) {
         int keyCount = x.keyCount();
-        Integer[] indexes = new Integer[keyCount];
-        for (int i = 0; i < keyCount; i++) {
-            indexes[i] = i;
-        }
-        Arrays.sort(indexes, new Comparator<Integer>() {
+        Integer[] indexes = Util.createSortedPermutation(keyCount, new Comparator<Integer>() {
             @Override
             public int compare(Integer o1, Integer o2) {
                 return x.keyProbability(o1) < x.keyProbability(o2) ? 1 : x.keyProbability(o1) > x.keyProbability(o2) ? -1 : 0;
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/Util.java	Fri Jul 06 16:20:55 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/Util.java	Fri Jul 06 16:21:46 2012 +0200
@@ -336,4 +336,23 @@
     public static boolean isFloating(Node n) {
         return n instanceof FloatingNode;
     }
+
+    /**
+     * Creates an array of integers of length "size", in which each number from 0 to (size - 1) occurs exactly once. The
+     * integers are sorted using the given comparator. This can be used to create a sorting for arrays that cannot be
+     * modified directly.
+     *
+     * @param size The size of the range to be sorted.
+     * @param comparator A comparator that is used to compare indexes.
+     * @return An array of integers that contains each number from 0 to (size - 1) exactly once, sorted using the
+     *         comparator.
+     */
+    public static Integer[] createSortedPermutation(int size, Comparator<Integer> comparator) {
+        Integer[] indexes = new Integer[size];
+        for (int i = 0; i < size; i++) {
+            indexes[i] = i;
+        }
+        Arrays.sort(indexes, comparator);
+        return indexes;
+    }
 }