diff --git a/teavm-core/src/main/java/org/teavm/common/DominatorTreeBuilder.java b/teavm-core/src/main/java/org/teavm/common/DominatorTreeBuilder.java index 77ad2cde8..06626673a 100644 --- a/teavm-core/src/main/java/org/teavm/common/DominatorTreeBuilder.java +++ b/teavm-core/src/main/java/org/teavm/common/DominatorTreeBuilder.java @@ -45,12 +45,12 @@ class DominatorTreeBuilder { bucket = new IntegerArray[graph.size()]; } - public void build(int[] start) { + public void build() { for (int i = 0; i < labels.length; ++i) { labels[i] = i; } Arrays.fill(ancestors, -1); - dfs(start); + dfs(); for (int i = effectiveSize - 1; i >= 0; --i) { int w = vertices[i]; if (parents[w] < 0) { @@ -120,13 +120,15 @@ class DominatorTreeBuilder { return labels[v]; } - private void dfs(int[] start) { + private void dfs() { Arrays.fill(semidominators, -1); Arrays.fill(vertices, -1); IntegerStack stack = new IntegerStack(graph.size()); - for (int node : start) { - stack.push(node); - parents[node] = -1; + for (int i = graph.size() - 1; i >= 0; --i) { + if (graph.incomingEdgesCount(i) == 0) { + stack.push(i); + parents[i] = -1; + } } int i = 0; while (!stack.isEmpty()) { diff --git a/teavm-core/src/main/java/org/teavm/common/GraphUtils.java b/teavm-core/src/main/java/org/teavm/common/GraphUtils.java index eea85e356..925b6d3a2 100644 --- a/teavm-core/src/main/java/org/teavm/common/GraphUtils.java +++ b/teavm-core/src/main/java/org/teavm/common/GraphUtils.java @@ -161,12 +161,8 @@ public final class GraphUtils { } public static DominatorTree buildDominatorTree(Graph graph) { - return buildDominatorTree(graph, 0); - } - - public static DominatorTree buildDominatorTree(Graph graph, int... start) { DominatorTreeBuilder builder = new DominatorTreeBuilder(graph); - builder.build(start); + builder.build(); return new DefaultDominatorTree(builder.dominators, builder.vertices); } diff --git a/teavm-core/src/main/java/org/teavm/common/irreducible/DJGraph.java b/teavm-core/src/main/java/org/teavm/common/irreducible/DJGraph.java index bf8486266..655c5f765 100644 --- a/teavm-core/src/main/java/org/teavm/common/irreducible/DJGraph.java +++ b/teavm-core/src/main/java/org/teavm/common/irreducible/DJGraph.java @@ -38,9 +38,9 @@ public class DJGraph { private int[] mergeRoot; private IntegerArray[] mergeClasses; - public DJGraph(Graph src, int top) { + public DJGraph(Graph src) { this.cfg = new MutableDirectedGraph(src); - domTree = GraphUtils.buildDominatorTree(src, top); + domTree = GraphUtils.buildDominatorTree(src); buildGraph(src); buildLevels(); dfs(); diff --git a/teavm-core/src/main/java/org/teavm/common/irreducible/IrreducibleGraphConverter.java b/teavm-core/src/main/java/org/teavm/common/irreducible/IrreducibleGraphConverter.java index a84de998b..aa908dba8 100644 --- a/teavm-core/src/main/java/org/teavm/common/irreducible/IrreducibleGraphConverter.java +++ b/teavm-core/src/main/java/org/teavm/common/irreducible/IrreducibleGraphConverter.java @@ -32,7 +32,7 @@ public class IrreducibleGraphConverter { public void convertToReducible(Graph cfg, GraphSplittingBackend backend) { this.backend = backend; - handleLoops(new DJGraph(cfg, 0)); + handleLoops(new DJGraph(cfg)); this.backend = null; }