mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: attempt to preserve statement marks when empty blocks are trimmed.
This was a cause of some statements being lost. Change-Id: Ia4805c2dafd7a880d485a678a48427de8930d57e Reviewed-on: https://go-review.googlesource.com/c/go/+/198482 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
parent
3ce29b44bb
commit
91b55b4fa3
1 changed files with 23 additions and 0 deletions
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
package ssa
|
package ssa
|
||||||
|
|
||||||
|
import "cmd/internal/src"
|
||||||
|
|
||||||
// trim removes blocks with no code in them.
|
// trim removes blocks with no code in them.
|
||||||
// These blocks were inserted to remove critical edges.
|
// These blocks were inserted to remove critical edges.
|
||||||
func trim(f *Func) {
|
func trim(f *Func) {
|
||||||
|
|
@ -15,6 +17,9 @@ func trim(f *Func) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bPos := b.Pos
|
||||||
|
bIsStmt := bPos.IsStmt() == src.PosIsStmt
|
||||||
|
|
||||||
// Splice b out of the graph. NOTE: `mergePhi` depends on the
|
// Splice b out of the graph. NOTE: `mergePhi` depends on the
|
||||||
// order, in which the predecessors edges are merged here.
|
// order, in which the predecessors edges are merged here.
|
||||||
p, i := b.Preds[0].b, b.Preds[0].i
|
p, i := b.Preds[0].b, b.Preds[0].i
|
||||||
|
|
@ -29,6 +34,23 @@ func trim(f *Func) {
|
||||||
s.Preds = append(s.Preds, Edge{p, i})
|
s.Preds = append(s.Preds, Edge{p, i})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attempt to preserve a statement boundary
|
||||||
|
if bIsStmt {
|
||||||
|
sawStmt := false
|
||||||
|
for _, v := range s.Values {
|
||||||
|
if isPoorStatementOp(v.Op) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if v.Pos.SameFileAndLine(bPos) {
|
||||||
|
v.Pos = v.Pos.WithIsStmt()
|
||||||
|
}
|
||||||
|
sawStmt = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if !sawStmt && s.Pos.SameFileAndLine(bPos) {
|
||||||
|
s.Pos = s.Pos.WithIsStmt()
|
||||||
|
}
|
||||||
|
}
|
||||||
// If `s` had more than one predecessor, update its phi-ops to
|
// If `s` had more than one predecessor, update its phi-ops to
|
||||||
// account for the merge.
|
// account for the merge.
|
||||||
if ns > 1 {
|
if ns > 1 {
|
||||||
|
|
@ -36,6 +58,7 @@ func trim(f *Func) {
|
||||||
if v.Op == OpPhi {
|
if v.Op == OpPhi {
|
||||||
mergePhi(v, j, b)
|
mergePhi(v, j, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Remove the phi-ops from `b` if they were merged into the
|
// Remove the phi-ops from `b` if they were merged into the
|
||||||
// phi-ops of `s`.
|
// phi-ops of `s`.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue