mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
Fix bugs in node splitting or irreducible graphs
This commit is contained in:
parent
6551f3eb68
commit
1b78ef99a6
|
@ -114,10 +114,6 @@ public class DJGraph {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominatorTree getDomTree() {
|
|
||||||
return domTree;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MutableDirectedGraph getCfg() {
|
public MutableDirectedGraph getCfg() {
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +132,17 @@ public class DJGraph {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDomEdge(int i, int j) {
|
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) {
|
public boolean isJoinEdge(int i, int j) {
|
||||||
|
|
|
@ -84,7 +84,7 @@ class IrreducibleGraphConverter {
|
||||||
// Find shared dominator
|
// Find shared dominator
|
||||||
int sharedDom = scc[0];
|
int sharedDom = scc[0];
|
||||||
for (int i = 1; i < scc.length; ++i) {
|
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) {
|
for (int i = 0; i < scc.length; ++i) {
|
||||||
|
@ -103,7 +103,7 @@ class IrreducibleGraphConverter {
|
||||||
}
|
}
|
||||||
for (int i = 0; i < scc.length; ++i) {
|
for (int i = 0; i < scc.length; ++i) {
|
||||||
int node = scc[i];
|
int node = scc[i];
|
||||||
int idom = djGraph.getDomTree().immediateDominatorOf(node);
|
int idom = djGraph.immediateDominatorOf(node);
|
||||||
if (idom != sharedDom) {
|
if (idom != sharedDom) {
|
||||||
partitions.union(i, sccBack[idom]);
|
partitions.union(i, sccBack[idom]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ import com.carrotsearch.hppc.IntSet;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.function.IntPredicate;
|
import java.util.function.IntPredicate;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class GraphTest {
|
public class GraphTest {
|
||||||
|
@ -172,12 +171,10 @@ public class GraphTest {
|
||||||
|
|
||||||
assertTrue("Should be irreducible", GraphUtils.isIrreducible(graph));
|
assertTrue("Should be irreducible", GraphUtils.isIrreducible(graph));
|
||||||
assertFalse("Should be reducible", GraphUtils.isIrreducible(result));
|
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
|
@Test
|
||||||
@Ignore
|
|
||||||
public void irreducibleGraphSplit3() {
|
public void irreducibleGraphSplit3() {
|
||||||
GraphBuilder builder = new GraphBuilder();
|
GraphBuilder builder = new GraphBuilder();
|
||||||
builder.addEdge(0, 1);
|
builder.addEdge(0, 1);
|
||||||
|
@ -232,8 +229,8 @@ public class GraphTest {
|
||||||
private IntPredicate filter = (int node) -> true;
|
private IntPredicate filter = (int node) -> true;
|
||||||
|
|
||||||
private void sortSccs(int[][] sccs) {
|
private void sortSccs(int[][] sccs) {
|
||||||
for (int i = 0; i < sccs.length; ++i) {
|
for (int[] scc : sccs) {
|
||||||
Arrays.sort(sccs[i]);
|
Arrays.sort(scc);
|
||||||
}
|
}
|
||||||
Arrays.sort(sccs, Comparator.comparingInt(o -> o[0]));
|
Arrays.sort(sccs, Comparator.comparingInt(o -> o[0]));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user