IsValid reports whether the cond and exit node candidates of prim form a valid post-test loop in g. Control flow graph: cond ↘ ↓ ↖↲ ↓ exit
(g graph.Directed, dom cfg.DominatorTree)
| 98 | // ↓ |
| 99 | // exit |
| 100 | func (prim PostLoop) IsValid(g graph.Directed, dom cfg.DominatorTree) bool { |
| 101 | // Dominator sanity check. |
| 102 | cond, exit := prim.Cond, prim.Exit |
| 103 | if !dom.Dominates(cond, exit) { |
| 104 | return false |
| 105 | } |
| 106 | |
| 107 | // Verify that cond has two successors (cond and exit). |
| 108 | condSuccs := g.From(cond) |
| 109 | if len(condSuccs) != 2 || !g.HasEdgeFromTo(cond, cond) || !g.HasEdgeFromTo(cond, exit) { |
| 110 | return false |
| 111 | } |
| 112 | |
| 113 | // Verify that exit has one predecessor (cond). |
| 114 | exitPreds := g.To(exit) |
| 115 | return len(exitPreds) == 1 |
| 116 | } |
no test coverage detected