diff --git a/core/src/main/java/org/teavm/common/DJGraph.java b/core/src/main/java/org/teavm/common/DJGraph.java index 152893c72..7cdbbff5e 100644 --- a/core/src/main/java/org/teavm/common/DJGraph.java +++ b/core/src/main/java/org/teavm/common/DJGraph.java @@ -114,10 +114,6 @@ public class DJGraph { } } - public DominatorTree getDomTree() { - return domTree; - } - public MutableDirectedGraph getCfg() { return cfg; } @@ -136,7 +132,17 @@ public class DJGraph { } public boolean isDomEdge(int i, int j) { - return domTree.immediateDominatorOf(mergeRoot[j]) == mergeRoot[i]; + return immediateDominatorOf(j) == mergeRoot[i]; + } + + public int immediateDominatorOf(int node) { + int dom = domTree.immediateDominatorOf(mergeRoot[node]); + return dom >= 0 ? mergeRoot[dom] : dom; + } + + public int commonDominatorOf(int a, int b) { + int dom = domTree.commonDominatorOf(mergeRoot[a], mergeRoot[b]); + return dom >= 0 ? mergeRoot[dom] : dom; } public boolean isJoinEdge(int i, int j) { diff --git a/core/src/main/java/org/teavm/common/IrreducibleGraphConverter.java b/core/src/main/java/org/teavm/common/IrreducibleGraphConverter.java index 7569e4006..b1eb1ad4f 100644 --- a/core/src/main/java/org/teavm/common/IrreducibleGraphConverter.java +++ b/core/src/main/java/org/teavm/common/IrreducibleGraphConverter.java @@ -84,7 +84,7 @@ class IrreducibleGraphConverter { // Find shared dominator int sharedDom = scc[0]; for (int i = 1; i < scc.length; ++i) { - sharedDom = djGraph.getDomTree().commonDominatorOf(sharedDom, scc[i]); + sharedDom = djGraph.commonDominatorOf(sharedDom, scc[i]); } for (int i = 0; i < scc.length; ++i) { @@ -103,7 +103,7 @@ class IrreducibleGraphConverter { } for (int i = 0; i < scc.length; ++i) { int node = scc[i]; - int idom = djGraph.getDomTree().immediateDominatorOf(node); + int idom = djGraph.immediateDominatorOf(node); if (idom != sharedDom) { partitions.union(i, sccBack[idom]); } diff --git a/core/src/test/java/org/teavm/common/GraphTest.java b/core/src/test/java/org/teavm/common/GraphTest.java index 09300c0e5..fa40f1a81 100644 --- a/core/src/test/java/org/teavm/common/GraphTest.java +++ b/core/src/test/java/org/teavm/common/GraphTest.java @@ -24,7 +24,6 @@ import com.carrotsearch.hppc.IntSet; import java.util.Arrays; import java.util.Comparator; import java.util.function.IntPredicate; -import org.junit.Ignore; import org.junit.Test; public class GraphTest { @@ -172,12 +171,10 @@ public class GraphTest { assertTrue("Should be irreducible", GraphUtils.isIrreducible(graph)); assertFalse("Should be reducible", GraphUtils.isIrreducible(result)); - assertTrue("Should be equialent", isEquialent(backend, graph)); + assertTrue("Should be equivalent", isEquialent(backend, graph)); } - // TODO: fix and unignore @Test - @Ignore public void irreducibleGraphSplit3() { GraphBuilder builder = new GraphBuilder(); builder.addEdge(0, 1); @@ -232,8 +229,8 @@ public class GraphTest { private IntPredicate filter = (int node) -> true; private void sortSccs(int[][] sccs) { - for (int i = 0; i < sccs.length; ++i) { - Arrays.sort(sccs[i]); + for (int[] scc : sccs) { + Arrays.sort(scc); } Arrays.sort(sccs, Comparator.comparingInt(o -> o[0])); }