findLoop: mark fdel

This commit is contained in:
xushiwei
2024-06-05 14:14:12 +08:00
parent 519e69a7f8
commit a226a70383
3 changed files with 24 additions and 10 deletions

View File

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

View File

@@ -26,6 +26,8 @@ type Info struct {
Next int
}
// var debug = false
// -----------------------------------------------------------------------------
type blockState struct {
@@ -62,9 +64,12 @@ func findLoop(states []*blockState, path []int, from, iblk int) []int {
if states[succ].fdel {
continue
}
if succ == from {
if pos := find(path, succ); pos >= 0 {
path = path[pos:]
for _, i := range path {
states[i].loop = true
s := states[i]
s.loop = true
s.fdel = true
}
return path
}
@@ -153,4 +158,13 @@ func isEnd(blk *ssa.BasicBlock) bool {
return len(blk.Succs) == 0 && (len(blk.Preds) > 0 || blk.Index == 0)
}
func find(path []int, fv int) int {
for i, v := range path {
if v == fv {
return i
}
}
return -1
}
// -----------------------------------------------------------------------------

View File

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