]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: debug rewrite
authorCherry Zhang <cherryyz@google.com>
Fri, 24 Jan 2020 15:43:09 +0000 (10:43 -0500)
committerCherry Zhang <cherryyz@google.com>
Mon, 13 Apr 2020 21:56:15 +0000 (21:56 +0000)
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>
src/cmd/compile/internal/ssa/rewrite.go
test/devirt.go

index 27036a7244d59a09317b7d85ea6bfb6091a30a18..968ef4edb34e3782f8b56ba311bf56eb9b2d8f92 100644 (file)
@@ -23,9 +23,19 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter) {
        // 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.clear()
+       debug := f.pass.debug
+       if debug > 1 {
+               fmt.Printf("%s: rewriting for %s\n", f.pass.name, f.Name)
+       }
        for {
                change := false
                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 c.Op == OpCopy {
                                        c = c.Args[0]
@@ -34,9 +44,22 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter) {
                        }
                        if rb(b) {
                                change = true
+                               if debug > 1 {
+                                       fmt.Printf("rewriting %s  ->  %s\n", b0.LongString(), b.LongString())
+                               }
                        }
                        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.
                                // 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()
                                        }
-                                       change = true
+                                       vchange = true
                                        for a.Uses == 0 {
                                                b := a.Args[0]
                                                a.reset(OpInvalid)
                                                a = b
                                        }
                                }
+                               if vchange && debug > 1 {
+                                       fmt.Printf("rewriting %s  ->  %s\n", v0.LongString(), v.LongString())
+                               }
 
                                // apply rewrite function
                                if rv(v) {
-                                       change = true
+                                       vchange = true
                                        // If value changed to a poor choice for a statement boundary, move the boundary
                                        if v.Pos.IsStmt() == src.PosIsStmt {
                                                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 {
index 23577098e4953129f3a2f61ab8b38d310938bf77..e0149d8229247fccb35a1c40db8070f7b46c733e 100644 (file)
@@ -1,4 +1,4 @@
-// errorcheck -0 -d=ssa/opt/debug=3
+// errorcheck -0 -d=ssa/opt/debug=1
 
 package main