findLoop: reach

This commit is contained in:
xushiwei
2024-06-05 15:02:11 +08:00
parent a226a70383
commit fd7d2765c8
4 changed files with 28 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
0: always 0: always
1: cond 1: cond
4: loop
2: loop 2: loop
5: loop 5: loop
4: loop
6: cond
3: cond 3: cond
6: cond

View File

@@ -0,0 +1,18 @@
0: always
1: cond
3: cond
4: cond
5: cond
7: loop
6: loop
10: loop
8: loop
9: cond
13: loop
11: loop
12: cond
14: cond
2: cond
17: loop
15: loop
16: always

View File

@@ -26,8 +26,6 @@ type Info struct {
Next int Next int
} }
// var debug = false
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
type blockState struct { type blockState struct {
@@ -36,6 +34,7 @@ type blockState struct {
succs []int succs []int
loop bool loop bool
always bool always bool
reach bool
fdel bool fdel bool
} }
@@ -65,7 +64,9 @@ func findLoop(states []*blockState, path []int, from, iblk int) []int {
continue continue
} }
if pos := find(path, succ); pos >= 0 { if pos := find(path, succ); pos >= 0 {
path = path[pos:] if pos > 0 {
continue
}
for _, i := range path { for _, i := range path {
s := states[i] s := states[i]
s.loop = true s.loop = true
@@ -129,12 +130,14 @@ retry:
} }
if s.preds--; s.preds == 0 { if s.preds--; s.preds == 0 {
order = append(order, succ) order = append(order, succ)
} else {
s.reach = true
} }
} }
} }
if pos < n { if pos < n {
for iblk, state := range states { for iblk, state := range states {
if state.fdel { if state.fdel || !state.reach {
continue continue
} }
if loop := findLoop(states, path, iblk, iblk); len(loop) > 0 { if loop := findLoop(states, path, iblk, iblk); len(loop) > 0 {

View File

@@ -38,7 +38,7 @@ import (
func TestTestdefer(t *testing.T) { func TestTestdefer(t *testing.T) {
// debug = true // debug = true
fromDir(t, "print", "../_testdefer") fromDir(t, "", "../_testdefer")
} }
func fromDir(t *testing.T, sel, relDir string) { func fromDir(t *testing.T, sel, relDir string) {