]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: reduce rulegen's for loop verbosity
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 13 Mar 2019 11:57:29 +0000 (11:57 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 22 Mar 2019 15:41:51 +0000 (15:41 +0000)
commit0fbf6818407366d79a7a388b58718f6c32ef16d2
tree0f77bd0051e176e7fa09fcefe78df6f1e1a8a7fe
parentb06d2122eec394a044d7b04a011b5b79318dc4c0
cmd/compile: reduce rulegen's for loop verbosity

A lot of the naked for loops begin like:

for {
v := b.Control
if v.Op != OpConstBool {
break
}
...
return true
}

Instead, write them out in a more compact and readable way:

for v.Op == OpConstBool {
...
return true
}

This requires the addition of two bytes.Buffer writers, as this helps us
make a decision based on future pieces of generated code. This probably
makes rulegen slightly slower, but that's not noticeable; the code
generation still takes ~3.5s on my laptop, excluding build time.

The "v := b.Control" declaration can be moved to the top of each
function. Even though the rules can modify b.Control when firing, they
also make the function return, so v can't be used again.

While at it, remove three unnecessary lines from the top of each
rewriteBlock func.

In total, this results in ~4k lines removed from the generated code, and
a slight improvement in readability.

Change-Id: I317e4c6a4842c64df506f4513375475fad2aeec5
Reviewed-on: https://go-review.googlesource.com/c/go/+/167399
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
16 files changed:
src/cmd/compile/internal/ssa/gen/rulegen.go
src/cmd/compile/internal/ssa/rewrite386.go
src/cmd/compile/internal/ssa/rewrite386splitload.go
src/cmd/compile/internal/ssa/rewriteAMD64.go
src/cmd/compile/internal/ssa/rewriteAMD64splitload.go
src/cmd/compile/internal/ssa/rewriteARM.go
src/cmd/compile/internal/ssa/rewriteARM64.go
src/cmd/compile/internal/ssa/rewriteMIPS.go
src/cmd/compile/internal/ssa/rewriteMIPS64.go
src/cmd/compile/internal/ssa/rewritePPC64.go
src/cmd/compile/internal/ssa/rewriteS390X.go
src/cmd/compile/internal/ssa/rewriteWasm.go
src/cmd/compile/internal/ssa/rewritedec.go
src/cmd/compile/internal/ssa/rewritedec64.go
src/cmd/compile/internal/ssa/rewritedecArgs.go
src/cmd/compile/internal/ssa/rewritegeneric.go