changeset 16013:dd5c15b85f78

Move dominates() and isDominatedBy() from Block to AbstractBlock and make them static methods.
author Josef Eisl <josef.eisl@jku.at>
date Wed, 04 Jun 2014 12:02:36 +0200
parents 0497ead7ec50
children c1a47bf45b66
files graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/cfg/AbstractBlock.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/cfg/Block.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java
diffstat 3 files changed, 29 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/cfg/AbstractBlock.java	Wed Jun 04 11:47:49 2014 +0200
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/cfg/AbstractBlock.java	Wed Jun 04 12:02:36 2014 +0200
@@ -59,4 +59,25 @@
     T getDominator();
 
     double probability();
+
+    /**
+     * True if block {@code a} dominates block {@code b}.
+     */
+    static boolean dominates(AbstractBlock<?> a, AbstractBlock<?> b) {
+        return isDominatedBy(b, a);
+    }
+
+    /**
+     * True if block {@code a} is dominated by block {@code b}.
+     */
+    static boolean isDominatedBy(AbstractBlock<?> a, AbstractBlock<?> b) {
+        if (a == b) {
+            return true;
+        }
+        if (a.getDominator() == null) {
+            return false;
+        }
+        return isDominatedBy(a.getDominator(), b);
+    }
+
 }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/cfg/Block.java	Wed Jun 04 11:47:49 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/cfg/Block.java	Wed Jun 04 12:02:36 2014 +0200
@@ -167,20 +167,6 @@
         return "B" + id;
     }
 
-    public boolean dominates(Block block) {
-        return block.isDominatedBy(this);
-    }
-
-    public boolean isDominatedBy(Block block) {
-        if (block == this) {
-            return true;
-        }
-        if (getDominator() == null) {
-            return false;
-        }
-        return getDominator().isDominatedBy(block);
-    }
-
     public double probability() {
         return probability;
     }
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java	Wed Jun 04 11:47:49 2014 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java	Wed Jun 04 12:02:36 2014 +0200
@@ -25,6 +25,7 @@
 import static com.oracle.graal.api.meta.LocationIdentity.*;
 import static com.oracle.graal.compiler.common.GraalOptions.*;
 import static com.oracle.graal.nodes.cfg.ControlFlowGraph.*;
+import static com.oracle.graal.compiler.common.cfg.AbstractBlock.*;
 
 import java.util.*;
 
@@ -442,7 +443,7 @@
                     FloatingReadNode read = (FloatingReadNode) node;
                     block = optimalBlock(read, strategy);
                     Debug.log("schedule for %s: %s", read, block);
-                    assert earliestBlock.dominates(block) : String.format("%s (%s) cannot be scheduled before earliest schedule (%s). location: %s", read, block, earliestBlock,
+                    assert dominates(earliestBlock, block) : String.format("%s (%s) cannot be scheduled before earliest schedule (%s). location: %s", read, block, earliestBlock,
                                     read.getLocationIdentity());
                 } else {
                     block = latestBlock(node, strategy);
@@ -461,7 +462,7 @@
                         FloatingReadNode read = (FloatingReadNode) node;
                         MemoryNode lastLocationAccess = read.getLastLocationAccess();
                         Block upperBound = blockForMemoryNode(lastLocationAccess);
-                        assert upperBound.dominates(block) : String.format(
+                        assert dominates(upperBound, block) : String.format(
                                         "out of loop movement voilated memory semantics for %s (location %s). moved to %s but upper bound is %s (earliest: %s, latest: %s)", read,
                                         read.getLocationIdentity(), block, upperBound, earliestBlock, latest);
                     }
@@ -470,7 +471,7 @@
             default:
                 throw new GraalInternalError("unknown scheduling strategy");
         }
-        if (!earliestBlock.dominates(block)) {
+        if (!dominates(earliestBlock, block)) {
             throw new SchedulingError("%s: Graph cannot be scheduled : inconsistent for %s, %d usages, (%s needs to dominate %s)", node.graph(), node, node.usages().count(), earliestBlock, block);
         }
         cfg.getNodeToBlock().set(node, block);
@@ -512,10 +513,10 @@
 
         Block upperBoundBlock = blockForMemoryNode(n.getLastLocationAccess());
         Block earliestBlock = earliestBlock(n);
-        assert upperBoundBlock.dominates(earliestBlock) : "upper bound (" + upperBoundBlock + ") should dominate earliest (" + earliestBlock + ")";
+        assert dominates(upperBoundBlock, earliestBlock) : "upper bound (" + upperBoundBlock + ") should dominate earliest (" + earliestBlock + ")";
 
         Block latestBlock = latestBlock(n, strategy);
-        assert latestBlock != null && earliestBlock.dominates(latestBlock) : "earliest (" + earliestBlock + ") should dominate latest block (" + latestBlock + ")";
+        assert latestBlock != null && dominates(earliestBlock, latestBlock) : "earliest (" + earliestBlock + ") should dominate latest block (" + latestBlock + ")";
 
         Debug.log("processing %s (accessing %s): latest %s, earliest %s, upper bound %s (%s)", n, locid, latestBlock, earliestBlock, upperBoundBlock, n.getLastLocationAccess());
         if (earliestBlock == latestBlock) {
@@ -577,7 +578,7 @@
     private static Deque<Block> computePathInDominatorTree(Block earliestBlock, Block latestBlock) {
         Deque<Block> path = new LinkedList<>();
         Block currentBlock = latestBlock;
-        while (currentBlock != null && earliestBlock.dominates(currentBlock)) {
+        while (currentBlock != null && dominates(earliestBlock, currentBlock)) {
             path.push(currentBlock);
             currentBlock = currentBlock.getDominator();
         }
@@ -632,7 +633,7 @@
         }
 
         if (assertionEnabled()) {
-            if (cdbc.block != null && !earliestBlock(node).dominates(cdbc.block)) {
+            if (cdbc.block != null && !dominates(earliestBlock(node), cdbc.block)) {
                 throw new SchedulingError("failed to find correct latest schedule for %s. cdbc: %s, earliest: %s", node, cdbc.block, earliestBlock(node));
             }
         }