# HG changeset patch # User Tom Rodriguez # Date 1425080083 28800 # Node ID 5e31fe50d3300d5c3bbb3c4efd7ca727e773eb54 # Parent 5762e1d007b6f8b3a3df1c57625c99dfc691adf2 Make isDominatedBy faster diff -r 5762e1d007b6 -r 5e31fe50d330 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/cfg/AbstractControlFlowGraph.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/cfg/AbstractControlFlowGraph.java Fri Feb 27 20:17:59 2015 +0100 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/cfg/AbstractControlFlowGraph.java Fri Feb 27 15:34:43 2015 -0800 @@ -24,8 +24,6 @@ import java.util.*; -import com.oracle.graal.compiler.common.*; - public interface AbstractControlFlowGraph> { int BLOCK_ID_INITIAL = -1; @@ -73,26 +71,22 @@ * True if block {@code a} is dominated by block {@code b}. */ static boolean isDominatedBy(AbstractBlockBase a, AbstractBlockBase b) { - assert a != null; - AbstractBlockBase dominator = a; - int i = 0; - while (dominator != null) { - if (i++ == Integer.MAX_VALUE) { // For safety - throw GraalInternalError.shouldNotReachHere(); - } - if (dominator == b) { - return true; - } - dominator = dominator.getDominator(); + assert a != null && b != null; + if (a == b) { + return true; } - return false; + if (a.getDominatorDepth() < b.getDominatorDepth()) { + return false; + } + + return b == (AbstractBlockBase) a.getDominator(a.getDominatorDepth() - b.getDominatorDepth()); } /** * True if block {@code a} dominates block {@code b}. */ static boolean dominates(AbstractBlockBase a, AbstractBlockBase b) { - assert a != null; + assert a != null && b != null; return isDominatedBy(b, a); }