findLoop: mark fdel
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
0: always
|
0: always
|
||||||
2: loop
|
1: cond
|
||||||
4: loop
|
2: loop
|
||||||
5: loop
|
5: loop
|
||||||
3: cond
|
4: loop
|
||||||
6: cond
|
6: cond
|
||||||
1: cond
|
3: cond
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ type Info struct {
|
|||||||
Next int
|
Next int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// var debug = false
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
type blockState struct {
|
type blockState struct {
|
||||||
@@ -62,9 +64,12 @@ func findLoop(states []*blockState, path []int, from, iblk int) []int {
|
|||||||
if states[succ].fdel {
|
if states[succ].fdel {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if succ == from {
|
if pos := find(path, succ); pos >= 0 {
|
||||||
|
path = path[pos:]
|
||||||
for _, i := range path {
|
for _, i := range path {
|
||||||
states[i].loop = true
|
s := states[i]
|
||||||
|
s.loop = true
|
||||||
|
s.fdel = true
|
||||||
}
|
}
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
@@ -153,4 +158,13 @@ func isEnd(blk *ssa.BasicBlock) bool {
|
|||||||
return len(blk.Succs) == 0 && (len(blk.Preds) > 0 || blk.Index == 0)
|
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
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import (
|
|||||||
|
|
||||||
func TestTestdefer(t *testing.T) {
|
func TestTestdefer(t *testing.T) {
|
||||||
// debug = true
|
// debug = true
|
||||||
fromDir(t, "loop", "../_testdefer")
|
fromDir(t, "print", "../_testdefer")
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromDir(t *testing.T, sel, relDir string) {
|
func fromDir(t *testing.T, sel, relDir string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user