Commit 0b6332eb authored by David Chase's avatar David Chase

cmd/compile: fix another bug in dominator computation

Here, "fix" means "replace".  The new dominator computation
is the "simple" algorithm from Lengauer and Tarjan's TOPLAS
paper, with minimal changes.

Also included is a test that tweaks the fixed error.

Change-Id: I0abdf53d5d64df1e67e4e62f55e88957045cd63b
Reviewed-on: https://go-review.googlesource.com/22401
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarKeith Randall <khr@golang.org>
parent 6b02a192
This diff is collapsed.
......@@ -372,32 +372,6 @@ func TestDominatorsMultPred(t *testing.T) {
verifyDominators(t, fun, dominatorsSimple, doms)
}
func TestPostDominators(t *testing.T) {
c := testConfig(t)
fun := Fun(c, "entry",
Bloc("entry",
Valu("mem", OpInitMem, TypeMem, 0, nil),
Valu("p", OpConstBool, TypeBool, 1, nil),
If("p", "a", "c")),
Bloc("a",
If("p", "b", "c")),
Bloc("b",
Goto("c")),
Bloc("c",
If("p", "b", "exit")),
Bloc("exit",
Exit("mem")))
doms := map[string]string{"entry": "c",
"a": "c",
"b": "c",
"c": "exit",
}
CheckFunc(fun.f)
verifyDominators(t, fun, postDominators, doms)
}
func TestInfiniteLoop(t *testing.T) {
c := testConfig(t)
// note lack of an exit block
......@@ -415,10 +389,6 @@ func TestInfiniteLoop(t *testing.T) {
doms := map[string]string{"a": "entry",
"b": "a"}
verifyDominators(t, fun, dominators, doms)
// no exit block, so there are no post-dominators
postDoms := map[string]string{}
verifyDominators(t, fun, postDominators, postDoms)
}
func TestDomTricky(t *testing.T) {
......@@ -465,3 +435,138 @@ func TestDomTricky(t *testing.T) {
verifyDominators(t, fun, dominatorsSimple, doms)
}
}
// generateDominatorMap uses dominatorsSimple to obtain a
// reference dominator tree for testing faster algorithms.
func generateDominatorMap(fut fun) map[string]string {
blockNames := map[*Block]string{}
for n, b := range fut.blocks {
blockNames[b] = n
}
referenceDom := dominatorsSimple(fut.f)
doms := make(map[string]string)
for _, b := range fut.f.Blocks {
if d := referenceDom[b.ID]; d != nil {
doms[blockNames[b]] = blockNames[d]
}
}
return doms
}
func TestDominatorsPostTricky(t *testing.T) {
c := testConfig(t)
fun := Fun(c, "b1",
Bloc("b1",
Valu("mem", OpInitMem, TypeMem, 0, nil),
Valu("p", OpConstBool, TypeBool, 1, nil),
If("p", "b3", "b2")),
Bloc("b3",
If("p", "b5", "b6")),
Bloc("b5",
Goto("b7")),
Bloc("b7",
If("p", "b8", "b11")),
Bloc("b8",
Goto("b13")),
Bloc("b13",
If("p", "b14", "b15")),
Bloc("b14",
Goto("b10")),
Bloc("b15",
Goto("b16")),
Bloc("b16",
Goto("b9")),
Bloc("b9",
Goto("b7")),
Bloc("b11",
Goto("b12")),
Bloc("b12",
If("p", "b10", "b8")),
Bloc("b10",
Goto("b6")),
Bloc("b6",
Goto("b17")),
Bloc("b17",
Goto("b18")),
Bloc("b18",
If("p", "b22", "b19")),
Bloc("b22",
Goto("b23")),
Bloc("b23",
If("p", "b21", "b19")),
Bloc("b19",
If("p", "b24", "b25")),
Bloc("b24",
Goto("b26")),
Bloc("b26",
Goto("b25")),
Bloc("b25",
If("p", "b27", "b29")),
Bloc("b27",
Goto("b30")),
Bloc("b30",
Goto("b28")),
Bloc("b29",
Goto("b31")),
Bloc("b31",
Goto("b28")),
Bloc("b28",
If("p", "b32", "b33")),
Bloc("b32",
Goto("b21")),
Bloc("b21",
Goto("b47")),
Bloc("b47",
If("p", "b45", "b46")),
Bloc("b45",
Goto("b48")),
Bloc("b48",
Goto("b49")),
Bloc("b49",
If("p", "b50", "b51")),
Bloc("b50",
Goto("b52")),
Bloc("b52",
Goto("b53")),
Bloc("b53",
Goto("b51")),
Bloc("b51",
Goto("b54")),
Bloc("b54",
Goto("b46")),
Bloc("b46",
Exit("mem")),
Bloc("b33",
Goto("b34")),
Bloc("b34",
Goto("b37")),
Bloc("b37",
If("p", "b35", "b36")),
Bloc("b35",
Goto("b38")),
Bloc("b38",
Goto("b39")),
Bloc("b39",
If("p", "b40", "b41")),
Bloc("b40",
Goto("b42")),
Bloc("b42",
Goto("b43")),
Bloc("b43",
Goto("b41")),
Bloc("b41",
Goto("b44")),
Bloc("b44",
Goto("b36")),
Bloc("b36",
Goto("b20")),
Bloc("b20",
Goto("b18")),
Bloc("b2",
Goto("b4")),
Bloc("b4",
Exit("mem")))
CheckFunc(fun.f)
doms := generateDominatorMap(fun)
verifyDominators(t, fun, dominators, doms)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment