Commit 87008075 authored by Daniel Martí's avatar Daniel Martí

cmd/compile: reduce rulegen's output by 200 KiB

First, renove unnecessary "// cond:" lines from the generated files.
This shaves off about ~7k lines.

Second, join "if cond { break }" statements via "||", which allows us to
deduplicate a large number of them. This shaves off another ~25k lines.

This change is not for readability or simplicity; but rather, to avoid
unnecessary verbosity that makes the generated files larger. All in all,
git reports that the generated files overall weigh ~200KiB less, or
about 2.7% less.

While at it, add a -trace flag to rulegen.

Updates #33644.

Change-Id: I3fac0290a6066070cc62400bf970a4ae0929470a
Reviewed-on: https://go-review.googlesource.com/c/go/+/196498
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent 34fe8295
...@@ -20,6 +20,7 @@ import ( ...@@ -20,6 +20,7 @@ import (
"regexp" "regexp"
"runtime" "runtime"
"runtime/pprof" "runtime/pprof"
"runtime/trace"
"sort" "sort"
"strings" "strings"
"sync" "sync"
...@@ -101,6 +102,7 @@ var archs []arch ...@@ -101,6 +102,7 @@ var archs []arch
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`") var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
var memprofile = flag.String("memprofile", "", "write memory profile to `file`") var memprofile = flag.String("memprofile", "", "write memory profile to `file`")
var tracefile = flag.String("trace", "", "write trace to `file`")
func main() { func main() {
flag.Parse() flag.Parse()
...@@ -115,6 +117,23 @@ func main() { ...@@ -115,6 +117,23 @@ func main() {
} }
defer pprof.StopCPUProfile() defer pprof.StopCPUProfile()
} }
if *tracefile != "" {
f, err := os.Create(*tracefile)
if err != nil {
log.Fatalf("failed to create trace output file: %v", err)
}
defer func() {
if err := f.Close(); err != nil {
log.Fatalf("failed to close trace file: %v", err)
}
}()
if err := trace.Start(f); err != nil {
log.Fatalf("failed to start trace: %v", err)
}
defer trace.Stop()
}
sort.Sort(ArchsByName(archs)) sort.Sort(ArchsByName(archs))
// The generate tasks are run concurrently, since they are CPU-intensive // The generate tasks are run concurrently, since they are CPU-intensive
......
...@@ -587,7 +587,9 @@ func fprint(w io.Writer, n Node) { ...@@ -587,7 +587,9 @@ func fprint(w io.Writer, n Node) {
} }
case *RuleRewrite: case *RuleRewrite:
fmt.Fprintf(w, "// match: %s\n", n.match) fmt.Fprintf(w, "// match: %s\n", n.match)
if n.cond != "" {
fmt.Fprintf(w, "// cond: %s\n", n.cond) fmt.Fprintf(w, "// cond: %s\n", n.cond)
}
fmt.Fprintf(w, "// result: %s\n", n.result) fmt.Fprintf(w, "// result: %s\n", n.result)
if n.checkOp != "" { if n.checkOp != "" {
fmt.Fprintf(w, "for v.Op == %s {\n", n.checkOp) fmt.Fprintf(w, "for v.Op == %s {\n", n.checkOp)
...@@ -636,13 +638,26 @@ type bodyBase struct { ...@@ -636,13 +638,26 @@ type bodyBase struct {
canFail bool canFail bool
} }
func (w *bodyBase) add(nodes ...Statement) { func (w *bodyBase) add(node Statement) {
w.list = append(w.list, nodes...) var last Statement
for _, node := range nodes { if len(w.list) > 0 {
if _, ok := node.(*CondBreak); ok { last = w.list[len(w.list)-1]
}
if node, ok := node.(*CondBreak); ok {
w.canFail = true w.canFail = true
if last, ok := last.(*CondBreak); ok {
// Add to the previous "if <cond> { break }" via a
// logical OR, which will save verbosity.
last.expr = &ast.BinaryExpr{
Op: token.LOR,
X: last.expr,
Y: node.expr,
} }
return
} }
}
w.list = append(w.list, node)
} }
// declared reports if the body contains a Declare with the given name. // declared reports if the body contains a Declare with the given name.
......
This diff is collapsed.
...@@ -24,7 +24,6 @@ func rewriteValue386splitload_Op386CMPBconstload_0(v *Value) bool { ...@@ -24,7 +24,6 @@ func rewriteValue386splitload_Op386CMPBconstload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPBconstload {sym} [vo] ptr mem) // match: (CMPBconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPBconst (MOVBload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)]) // result: (CMPBconst (MOVBload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for { for {
vo := v.AuxInt vo := v.AuxInt
...@@ -46,7 +45,6 @@ func rewriteValue386splitload_Op386CMPBload_0(v *Value) bool { ...@@ -46,7 +45,6 @@ func rewriteValue386splitload_Op386CMPBload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPBload {sym} [off] ptr x mem) // match: (CMPBload {sym} [off] ptr x mem)
// cond:
// result: (CMPB (MOVBload {sym} [off] ptr mem) x) // result: (CMPB (MOVBload {sym} [off] ptr mem) x)
for { for {
off := v.AuxInt off := v.AuxInt
...@@ -69,7 +67,6 @@ func rewriteValue386splitload_Op386CMPLconstload_0(v *Value) bool { ...@@ -69,7 +67,6 @@ func rewriteValue386splitload_Op386CMPLconstload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPLconstload {sym} [vo] ptr mem) // match: (CMPLconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPLconst (MOVLload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)]) // result: (CMPLconst (MOVLload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for { for {
vo := v.AuxInt vo := v.AuxInt
...@@ -91,7 +88,6 @@ func rewriteValue386splitload_Op386CMPLload_0(v *Value) bool { ...@@ -91,7 +88,6 @@ func rewriteValue386splitload_Op386CMPLload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPLload {sym} [off] ptr x mem) // match: (CMPLload {sym} [off] ptr x mem)
// cond:
// result: (CMPL (MOVLload {sym} [off] ptr mem) x) // result: (CMPL (MOVLload {sym} [off] ptr mem) x)
for { for {
off := v.AuxInt off := v.AuxInt
...@@ -114,7 +110,6 @@ func rewriteValue386splitload_Op386CMPWconstload_0(v *Value) bool { ...@@ -114,7 +110,6 @@ func rewriteValue386splitload_Op386CMPWconstload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPWconstload {sym} [vo] ptr mem) // match: (CMPWconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPWconst (MOVWload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)]) // result: (CMPWconst (MOVWload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for { for {
vo := v.AuxInt vo := v.AuxInt
...@@ -136,7 +131,6 @@ func rewriteValue386splitload_Op386CMPWload_0(v *Value) bool { ...@@ -136,7 +131,6 @@ func rewriteValue386splitload_Op386CMPWload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPWload {sym} [off] ptr x mem) // match: (CMPWload {sym} [off] ptr x mem)
// cond:
// result: (CMPW (MOVWload {sym} [off] ptr mem) x) // result: (CMPW (MOVWload {sym} [off] ptr mem) x)
for { for {
off := v.AuxInt off := v.AuxInt
......
...@@ -28,7 +28,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPBconstload_0(v *Value) bool { ...@@ -28,7 +28,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPBconstload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPBconstload {sym} [vo] ptr mem) // match: (CMPBconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPBconst (MOVBload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)]) // result: (CMPBconst (MOVBload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for { for {
vo := v.AuxInt vo := v.AuxInt
...@@ -50,7 +49,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPBload_0(v *Value) bool { ...@@ -50,7 +49,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPBload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPBload {sym} [off] ptr x mem) // match: (CMPBload {sym} [off] ptr x mem)
// cond:
// result: (CMPB (MOVBload {sym} [off] ptr mem) x) // result: (CMPB (MOVBload {sym} [off] ptr mem) x)
for { for {
off := v.AuxInt off := v.AuxInt
...@@ -73,7 +71,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPLconstload_0(v *Value) bool { ...@@ -73,7 +71,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPLconstload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPLconstload {sym} [vo] ptr mem) // match: (CMPLconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPLconst (MOVLload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)]) // result: (CMPLconst (MOVLload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for { for {
vo := v.AuxInt vo := v.AuxInt
...@@ -95,7 +92,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPLload_0(v *Value) bool { ...@@ -95,7 +92,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPLload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPLload {sym} [off] ptr x mem) // match: (CMPLload {sym} [off] ptr x mem)
// cond:
// result: (CMPL (MOVLload {sym} [off] ptr mem) x) // result: (CMPL (MOVLload {sym} [off] ptr mem) x)
for { for {
off := v.AuxInt off := v.AuxInt
...@@ -118,7 +114,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPQconstload_0(v *Value) bool { ...@@ -118,7 +114,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPQconstload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPQconstload {sym} [vo] ptr mem) // match: (CMPQconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPQconst (MOVQload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)]) // result: (CMPQconst (MOVQload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for { for {
vo := v.AuxInt vo := v.AuxInt
...@@ -140,7 +135,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPQload_0(v *Value) bool { ...@@ -140,7 +135,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPQload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPQload {sym} [off] ptr x mem) // match: (CMPQload {sym} [off] ptr x mem)
// cond:
// result: (CMPQ (MOVQload {sym} [off] ptr mem) x) // result: (CMPQ (MOVQload {sym} [off] ptr mem) x)
for { for {
off := v.AuxInt off := v.AuxInt
...@@ -163,7 +157,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPWconstload_0(v *Value) bool { ...@@ -163,7 +157,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPWconstload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPWconstload {sym} [vo] ptr mem) // match: (CMPWconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPWconst (MOVWload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)]) // result: (CMPWconst (MOVWload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for { for {
vo := v.AuxInt vo := v.AuxInt
...@@ -185,7 +178,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPWload_0(v *Value) bool { ...@@ -185,7 +178,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPWload_0(v *Value) bool {
b := v.Block b := v.Block
typ := &b.Func.Config.Types typ := &b.Func.Config.Types
// match: (CMPWload {sym} [off] ptr x mem) // match: (CMPWload {sym} [off] ptr x mem)
// cond:
// result: (CMPW (MOVWload {sym} [off] ptr mem) x) // result: (CMPW (MOVWload {sym} [off] ptr mem) x)
for { for {
off := v.AuxInt off := v.AuxInt
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -34,7 +34,6 @@ func rewriteValuedec(v *Value) bool { ...@@ -34,7 +34,6 @@ func rewriteValuedec(v *Value) bool {
} }
func rewriteValuedec_OpComplexImag_0(v *Value) bool { func rewriteValuedec_OpComplexImag_0(v *Value) bool {
// match: (ComplexImag (ComplexMake _ imag)) // match: (ComplexImag (ComplexMake _ imag))
// cond:
// result: imag // result: imag
for { for {
v_0 := v.Args[0] v_0 := v.Args[0]
...@@ -51,7 +50,6 @@ func rewriteValuedec_OpComplexImag_0(v *Value) bool { ...@@ -51,7 +50,6 @@ func rewriteValuedec_OpComplexImag_0(v *Value) bool {
} }
func rewriteValuedec_OpComplexReal_0(v *Value) bool { func rewriteValuedec_OpComplexReal_0(v *Value) bool {
// match: (ComplexReal (ComplexMake real _)) // match: (ComplexReal (ComplexMake real _))
// cond:
// result: real // result: real
for { for {
v_0 := v.Args[0] v_0 := v.Args[0]
...@@ -69,7 +67,6 @@ func rewriteValuedec_OpComplexReal_0(v *Value) bool { ...@@ -69,7 +67,6 @@ func rewriteValuedec_OpComplexReal_0(v *Value) bool {
} }
func rewriteValuedec_OpIData_0(v *Value) bool { func rewriteValuedec_OpIData_0(v *Value) bool {
// match: (IData (IMake _ data)) // match: (IData (IMake _ data))
// cond:
// result: data // result: data
for { for {
v_0 := v.Args[0] v_0 := v.Args[0]
...@@ -86,7 +83,6 @@ func rewriteValuedec_OpIData_0(v *Value) bool { ...@@ -86,7 +83,6 @@ func rewriteValuedec_OpIData_0(v *Value) bool {
} }
func rewriteValuedec_OpITab_0(v *Value) bool { func rewriteValuedec_OpITab_0(v *Value) bool {
// match: (ITab (IMake itab _)) // match: (ITab (IMake itab _))
// cond:
// result: itab // result: itab
for { for {
v_0 := v.Args[0] v_0 := v.Args[0]
...@@ -237,7 +233,6 @@ func rewriteValuedec_OpLoad_0(v *Value) bool { ...@@ -237,7 +233,6 @@ func rewriteValuedec_OpLoad_0(v *Value) bool {
} }
func rewriteValuedec_OpSliceCap_0(v *Value) bool { func rewriteValuedec_OpSliceCap_0(v *Value) bool {
// match: (SliceCap (SliceMake _ _ cap)) // match: (SliceCap (SliceMake _ _ cap))
// cond:
// result: cap // result: cap
for { for {
v_0 := v.Args[0] v_0 := v.Args[0]
...@@ -254,7 +249,6 @@ func rewriteValuedec_OpSliceCap_0(v *Value) bool { ...@@ -254,7 +249,6 @@ func rewriteValuedec_OpSliceCap_0(v *Value) bool {
} }
func rewriteValuedec_OpSliceLen_0(v *Value) bool { func rewriteValuedec_OpSliceLen_0(v *Value) bool {
// match: (SliceLen (SliceMake _ len _)) // match: (SliceLen (SliceMake _ len _))
// cond:
// result: len // result: len
for { for {
v_0 := v.Args[0] v_0 := v.Args[0]
...@@ -272,7 +266,6 @@ func rewriteValuedec_OpSliceLen_0(v *Value) bool { ...@@ -272,7 +266,6 @@ func rewriteValuedec_OpSliceLen_0(v *Value) bool {
} }
func rewriteValuedec_OpSlicePtr_0(v *Value) bool { func rewriteValuedec_OpSlicePtr_0(v *Value) bool {
// match: (SlicePtr (SliceMake ptr _ _)) // match: (SlicePtr (SliceMake ptr _ _))
// cond:
// result: ptr // result: ptr
for { for {
v_0 := v.Args[0] v_0 := v.Args[0]
...@@ -355,7 +348,6 @@ func rewriteValuedec_OpStore_0(v *Value) bool { ...@@ -355,7 +348,6 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
return true return true
} }
// match: (Store dst (StringMake ptr len) mem) // match: (Store dst (StringMake ptr len) mem)
// cond:
// result: (Store {typ.Int} (OffPtr <typ.IntPtr> [config.PtrSize] dst) len (Store {typ.BytePtr} dst ptr mem)) // result: (Store {typ.Int} (OffPtr <typ.IntPtr> [config.PtrSize] dst) len (Store {typ.BytePtr} dst ptr mem))
for { for {
mem := v.Args[2] mem := v.Args[2]
...@@ -382,7 +374,6 @@ func rewriteValuedec_OpStore_0(v *Value) bool { ...@@ -382,7 +374,6 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
return true return true
} }
// match: (Store dst (SliceMake ptr len cap) mem) // match: (Store dst (SliceMake ptr len cap) mem)
// cond:
// result: (Store {typ.Int} (OffPtr <typ.IntPtr> [2*config.PtrSize] dst) cap (Store {typ.Int} (OffPtr <typ.IntPtr> [config.PtrSize] dst) len (Store {typ.BytePtr} dst ptr mem))) // result: (Store {typ.Int} (OffPtr <typ.IntPtr> [2*config.PtrSize] dst) cap (Store {typ.Int} (OffPtr <typ.IntPtr> [config.PtrSize] dst) len (Store {typ.BytePtr} dst ptr mem)))
for { for {
mem := v.Args[2] mem := v.Args[2]
...@@ -418,7 +409,6 @@ func rewriteValuedec_OpStore_0(v *Value) bool { ...@@ -418,7 +409,6 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
return true return true
} }
// match: (Store dst (IMake itab data) mem) // match: (Store dst (IMake itab data) mem)
// cond:
// result: (Store {typ.BytePtr} (OffPtr <typ.BytePtrPtr> [config.PtrSize] dst) data (Store {typ.Uintptr} dst itab mem)) // result: (Store {typ.BytePtr} (OffPtr <typ.BytePtrPtr> [config.PtrSize] dst) data (Store {typ.Uintptr} dst itab mem))
for { for {
mem := v.Args[2] mem := v.Args[2]
...@@ -448,7 +438,6 @@ func rewriteValuedec_OpStore_0(v *Value) bool { ...@@ -448,7 +438,6 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
} }
func rewriteValuedec_OpStringLen_0(v *Value) bool { func rewriteValuedec_OpStringLen_0(v *Value) bool {
// match: (StringLen (StringMake _ len)) // match: (StringLen (StringMake _ len))
// cond:
// result: len // result: len
for { for {
v_0 := v.Args[0] v_0 := v.Args[0]
...@@ -465,7 +454,6 @@ func rewriteValuedec_OpStringLen_0(v *Value) bool { ...@@ -465,7 +454,6 @@ func rewriteValuedec_OpStringLen_0(v *Value) bool {
} }
func rewriteValuedec_OpStringPtr_0(v *Value) bool { func rewriteValuedec_OpStringPtr_0(v *Value) bool {
// match: (StringPtr (StringMake ptr _)) // match: (StringPtr (StringMake ptr _))
// cond:
// result: ptr // result: ptr
for { for {
v_0 := v.Args[0] v_0 := v.Args[0]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment