mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
cmd/compile: debug rewrite
If -d=ssa/PASS/debug=N is specified (N >= 2) for a rewrite pass (e.g. lower), when a Value (or Block) is rewritten, print the Value (or Block) before and after. For #31915. Updates #19013. Change-Id: I80eadd44302ae736bc7daed0ef68529ab7a16776 Reviewed-on: https://go-review.googlesource.com/c/go/+/176718 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
6d63a74f8e
commit
1b15c7f102
@ -23,9 +23,19 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter) {
|
|||||||
// repeat rewrites until we find no more rewrites
|
// repeat rewrites until we find no more rewrites
|
||||||
pendingLines := f.cachedLineStarts // Holds statement boundaries that need to be moved to a new value/block
|
pendingLines := f.cachedLineStarts // Holds statement boundaries that need to be moved to a new value/block
|
||||||
pendingLines.clear()
|
pendingLines.clear()
|
||||||
|
debug := f.pass.debug
|
||||||
|
if debug > 1 {
|
||||||
|
fmt.Printf("%s: rewriting for %s\n", f.pass.name, f.Name)
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
change := false
|
change := false
|
||||||
for _, b := range f.Blocks {
|
for _, b := range f.Blocks {
|
||||||
|
var b0 *Block
|
||||||
|
if debug > 1 {
|
||||||
|
b0 = new(Block)
|
||||||
|
*b0 = *b
|
||||||
|
b0.Succs = append([]Edge{}, b.Succs...) // make a new copy, not aliasing
|
||||||
|
}
|
||||||
for i, c := range b.ControlValues() {
|
for i, c := range b.ControlValues() {
|
||||||
for c.Op == OpCopy {
|
for c.Op == OpCopy {
|
||||||
c = c.Args[0]
|
c = c.Args[0]
|
||||||
@ -34,9 +44,22 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter) {
|
|||||||
}
|
}
|
||||||
if rb(b) {
|
if rb(b) {
|
||||||
change = true
|
change = true
|
||||||
|
if debug > 1 {
|
||||||
|
fmt.Printf("rewriting %s -> %s\n", b0.LongString(), b.LongString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for j, v := range b.Values {
|
for j, v := range b.Values {
|
||||||
change = phielimValue(v) || change
|
var v0 *Value
|
||||||
|
if debug > 1 {
|
||||||
|
v0 = new(Value)
|
||||||
|
*v0 = *v
|
||||||
|
v0.Args = append([]*Value{}, v.Args...) // make a new copy, not aliasing
|
||||||
|
}
|
||||||
|
|
||||||
|
vchange := phielimValue(v)
|
||||||
|
if vchange && debug > 1 {
|
||||||
|
fmt.Printf("rewriting %s -> %s\n", v0.LongString(), v.LongString())
|
||||||
|
}
|
||||||
|
|
||||||
// Eliminate copy inputs.
|
// Eliminate copy inputs.
|
||||||
// If any copy input becomes unused, mark it
|
// If any copy input becomes unused, mark it
|
||||||
@ -70,17 +93,20 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter) {
|
|||||||
}
|
}
|
||||||
a.Pos = a.Pos.WithNotStmt()
|
a.Pos = a.Pos.WithNotStmt()
|
||||||
}
|
}
|
||||||
change = true
|
vchange = true
|
||||||
for a.Uses == 0 {
|
for a.Uses == 0 {
|
||||||
b := a.Args[0]
|
b := a.Args[0]
|
||||||
a.reset(OpInvalid)
|
a.reset(OpInvalid)
|
||||||
a = b
|
a = b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if vchange && debug > 1 {
|
||||||
|
fmt.Printf("rewriting %s -> %s\n", v0.LongString(), v.LongString())
|
||||||
|
}
|
||||||
|
|
||||||
// apply rewrite function
|
// apply rewrite function
|
||||||
if rv(v) {
|
if rv(v) {
|
||||||
change = true
|
vchange = true
|
||||||
// If value changed to a poor choice for a statement boundary, move the boundary
|
// If value changed to a poor choice for a statement boundary, move the boundary
|
||||||
if v.Pos.IsStmt() == src.PosIsStmt {
|
if v.Pos.IsStmt() == src.PosIsStmt {
|
||||||
if k := nextGoodStatementIndex(v, j, b); k != j {
|
if k := nextGoodStatementIndex(v, j, b); k != j {
|
||||||
@ -89,6 +115,11 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
change = change || vchange
|
||||||
|
if vchange && debug > 1 {
|
||||||
|
fmt.Printf("rewriting %s -> %s\n", v0.LongString(), v.LongString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !change {
|
if !change {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// errorcheck -0 -d=ssa/opt/debug=3
|
// errorcheck -0 -d=ssa/opt/debug=1
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user