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 (
"regexp"
"runtime"
"runtime/pprof"
"runtime/trace"
"sort"
"strings"
"sync"
......@@ -101,6 +102,7 @@ var archs []arch
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
var memprofile = flag.String("memprofile", "", "write memory profile to `file`")
var tracefile = flag.String("trace", "", "write trace to `file`")
func main() {
flag.Parse()
......@@ -115,6 +117,23 @@ func main() {
}
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))
// The generate tasks are run concurrently, since they are CPU-intensive
......
......@@ -587,7 +587,9 @@ func fprint(w io.Writer, n Node) {
}
case *RuleRewrite:
fmt.Fprintf(w, "// match: %s\n", n.match)
fmt.Fprintf(w, "// cond: %s\n", n.cond)
if n.cond != "" {
fmt.Fprintf(w, "// cond: %s\n", n.cond)
}
fmt.Fprintf(w, "// result: %s\n", n.result)
if n.checkOp != "" {
fmt.Fprintf(w, "for v.Op == %s {\n", n.checkOp)
......@@ -636,13 +638,26 @@ type bodyBase struct {
canFail bool
}
func (w *bodyBase) add(nodes ...Statement) {
w.list = append(w.list, nodes...)
for _, node := range nodes {
if _, ok := node.(*CondBreak); ok {
w.canFail = true
func (w *bodyBase) add(node Statement) {
var last Statement
if len(w.list) > 0 {
last = w.list[len(w.list)-1]
}
if node, ok := node.(*CondBreak); ok {
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.
......
This diff is collapsed.
......@@ -24,7 +24,6 @@ func rewriteValue386splitload_Op386CMPBconstload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPBconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPBconst (MOVBload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for {
vo := v.AuxInt
......@@ -46,7 +45,6 @@ func rewriteValue386splitload_Op386CMPBload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPBload {sym} [off] ptr x mem)
// cond:
// result: (CMPB (MOVBload {sym} [off] ptr mem) x)
for {
off := v.AuxInt
......@@ -69,7 +67,6 @@ func rewriteValue386splitload_Op386CMPLconstload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPLconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPLconst (MOVLload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for {
vo := v.AuxInt
......@@ -91,7 +88,6 @@ func rewriteValue386splitload_Op386CMPLload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPLload {sym} [off] ptr x mem)
// cond:
// result: (CMPL (MOVLload {sym} [off] ptr mem) x)
for {
off := v.AuxInt
......@@ -114,7 +110,6 @@ func rewriteValue386splitload_Op386CMPWconstload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPWconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPWconst (MOVWload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for {
vo := v.AuxInt
......@@ -136,7 +131,6 @@ func rewriteValue386splitload_Op386CMPWload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPWload {sym} [off] ptr x mem)
// cond:
// result: (CMPW (MOVWload {sym} [off] ptr mem) x)
for {
off := v.AuxInt
......
......@@ -28,7 +28,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPBconstload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPBconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPBconst (MOVBload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for {
vo := v.AuxInt
......@@ -50,7 +49,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPBload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPBload {sym} [off] ptr x mem)
// cond:
// result: (CMPB (MOVBload {sym} [off] ptr mem) x)
for {
off := v.AuxInt
......@@ -73,7 +71,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPLconstload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPLconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPLconst (MOVLload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for {
vo := v.AuxInt
......@@ -95,7 +92,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPLload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPLload {sym} [off] ptr x mem)
// cond:
// result: (CMPL (MOVLload {sym} [off] ptr mem) x)
for {
off := v.AuxInt
......@@ -118,7 +114,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPQconstload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPQconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPQconst (MOVQload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for {
vo := v.AuxInt
......@@ -140,7 +135,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPQload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPQload {sym} [off] ptr x mem)
// cond:
// result: (CMPQ (MOVQload {sym} [off] ptr mem) x)
for {
off := v.AuxInt
......@@ -163,7 +157,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPWconstload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPWconstload {sym} [vo] ptr mem)
// cond:
// result: (CMPWconst (MOVWload {sym} [offOnly(vo)] ptr mem) [valOnly(vo)])
for {
vo := v.AuxInt
......@@ -185,7 +178,6 @@ func rewriteValueAMD64splitload_OpAMD64CMPWload_0(v *Value) bool {
b := v.Block
typ := &b.Func.Config.Types
// match: (CMPWload {sym} [off] ptr x mem)
// cond:
// result: (CMPW (MOVWload {sym} [off] ptr mem) x)
for {
off := v.AuxInt
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -34,7 +34,6 @@ func rewriteValuedec(v *Value) bool {
}
func rewriteValuedec_OpComplexImag_0(v *Value) bool {
// match: (ComplexImag (ComplexMake _ imag))
// cond:
// result: imag
for {
v_0 := v.Args[0]
......@@ -51,7 +50,6 @@ func rewriteValuedec_OpComplexImag_0(v *Value) bool {
}
func rewriteValuedec_OpComplexReal_0(v *Value) bool {
// match: (ComplexReal (ComplexMake real _))
// cond:
// result: real
for {
v_0 := v.Args[0]
......@@ -69,7 +67,6 @@ func rewriteValuedec_OpComplexReal_0(v *Value) bool {
}
func rewriteValuedec_OpIData_0(v *Value) bool {
// match: (IData (IMake _ data))
// cond:
// result: data
for {
v_0 := v.Args[0]
......@@ -86,7 +83,6 @@ func rewriteValuedec_OpIData_0(v *Value) bool {
}
func rewriteValuedec_OpITab_0(v *Value) bool {
// match: (ITab (IMake itab _))
// cond:
// result: itab
for {
v_0 := v.Args[0]
......@@ -237,7 +233,6 @@ func rewriteValuedec_OpLoad_0(v *Value) bool {
}
func rewriteValuedec_OpSliceCap_0(v *Value) bool {
// match: (SliceCap (SliceMake _ _ cap))
// cond:
// result: cap
for {
v_0 := v.Args[0]
......@@ -254,7 +249,6 @@ func rewriteValuedec_OpSliceCap_0(v *Value) bool {
}
func rewriteValuedec_OpSliceLen_0(v *Value) bool {
// match: (SliceLen (SliceMake _ len _))
// cond:
// result: len
for {
v_0 := v.Args[0]
......@@ -272,7 +266,6 @@ func rewriteValuedec_OpSliceLen_0(v *Value) bool {
}
func rewriteValuedec_OpSlicePtr_0(v *Value) bool {
// match: (SlicePtr (SliceMake ptr _ _))
// cond:
// result: ptr
for {
v_0 := v.Args[0]
......@@ -355,7 +348,6 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
return true
}
// 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))
for {
mem := v.Args[2]
......@@ -382,7 +374,6 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
return true
}
// 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)))
for {
mem := v.Args[2]
......@@ -418,7 +409,6 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
return true
}
// 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))
for {
mem := v.Args[2]
......@@ -448,7 +438,6 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
}
func rewriteValuedec_OpStringLen_0(v *Value) bool {
// match: (StringLen (StringMake _ len))
// cond:
// result: len
for {
v_0 := v.Args[0]
......@@ -465,7 +454,6 @@ func rewriteValuedec_OpStringLen_0(v *Value) bool {
}
func rewriteValuedec_OpStringPtr_0(v *Value) bool {
// match: (StringPtr (StringMake ptr _))
// cond:
// result: ptr
for {
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