Commit 53948127 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: make rulegen magic variable prediction more precise

The sheer length of the generated rules files makes my
editor and git client unhappy.
This change is a small step towards shortening them.

We recognize a few magic variables during rulegen: b, config, fe, typ.
Of these, only b appears prone to false positives.
By tightening the heuristic and fixing one case in MIPS.rules,
we can make the heuristic enough that it has no failures.
That allows us to remove the hedge assignments to _,
removing 3000 pointless lines of code.

Change-Id: I080cde5db28c8277cb3fd9ddcd829306c9a27785
Reviewed-on: https://go-review.googlesource.com/c/go/+/166979
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent f54b8909
......@@ -688,7 +688,7 @@
(GEZ (MOVWconst [c]) yes no) && int32(c) < 0 -> (First nil no yes)
// conditional move
(CMOVZ _ b (MOVWconst [0])) -> b
(CMOVZ _ f (MOVWconst [0])) -> f
(CMOVZ a _ (MOVWconst [c])) && c!=0 -> a
(CMOVZzero _ (MOVWconst [0])) -> (MOVWconst [0])
(CMOVZzero a (MOVWconst [c])) && c!=0 -> a
......
......@@ -238,29 +238,23 @@ func genRules(arch arch) {
}
body := buf.String()
// Do a rough match to predict whether we need b, config, fe, and/or types.
// It's not precise--thus the blank assignments--but it's good enough
// to avoid generating needless code and doing pointless nil checks.
hasb := strings.Contains(body, "b.")
// Figure out whether we need b, config, fe, and/or types; provide them if so.
hasb := strings.Contains(body, " b.")
hasconfig := strings.Contains(body, "config.") || strings.Contains(body, "config)")
hasfe := strings.Contains(body, "fe.")
hastyps := strings.Contains(body, "typ.")
fmt.Fprintf(w, "func rewriteValue%s_%s_%d(v *Value) bool {\n", arch.name, op, chunk)
if hasb || hasconfig || hasfe || hastyps {
fmt.Fprintln(w, "b := v.Block")
fmt.Fprintln(w, "_ = b")
}
if hasconfig {
fmt.Fprintln(w, "config := b.Func.Config")
fmt.Fprintln(w, "_ = config")
}
if hasfe {
fmt.Fprintln(w, "fe := b.Func.fe")
fmt.Fprintln(w, "_ = fe")
}
if hastyps {
fmt.Fprintln(w, "typ := &b.Func.Config.Types")
fmt.Fprintln(w, "_ = typ")
}
fmt.Fprint(w, body)
fmt.Fprintf(w, "}\n")
......@@ -507,6 +501,9 @@ func genMatch0(w io.Writer, arch arch, match, v string, m map[string]struct{}, t
// autogenerated name
argname = fmt.Sprintf("%s_%d", v, i)
}
if argname == "b" {
log.Fatalf("don't name args 'b', it is ambiguous with blocks")
}
fmt.Fprintf(w, "%s := %s.Args[%d]\n", argname, v, i)
argPos, argCanFail := genMatch0(w, arch, arg, argname, m, false, loc)
if argPos != "" {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -97,8 +97,6 @@ func rewriteValuedec_OpIData_0(v *Value) bool {
return false
}
func rewriteValuedec_OpITab_0(v *Value) bool {
b := v.Block
_ = b
// match: (ITab (IMake itab _))
// cond:
// result: itab
......@@ -118,11 +116,8 @@ func rewriteValuedec_OpITab_0(v *Value) bool {
}
func rewriteValuedec_OpLoad_0(v *Value) bool {
b := v.Block
_ = b
config := b.Func.Config
_ = config
typ := &b.Func.Config.Types
_ = typ
// match: (Load <t> ptr mem)
// cond: t.IsComplex() && t.Size() == 8
// result: (ComplexMake (Load <typ.Float32> ptr mem) (Load <typ.Float32> (OffPtr <typ.Float32Ptr> [4] ptr) mem) )
......@@ -313,11 +308,8 @@ func rewriteValuedec_OpSlicePtr_0(v *Value) bool {
}
func rewriteValuedec_OpStore_0(v *Value) bool {
b := v.Block
_ = b
config := b.Func.Config
_ = config
typ := &b.Func.Config.Types
_ = typ
// match: (Store {t} dst (ComplexMake real imag) mem)
// cond: t.(*types.Type).Size() == 8
// result: (Store {typ.Float32} (OffPtr <typ.Float32Ptr> [4] dst) imag (Store {typ.Float32} dst real mem))
......
......@@ -24,13 +24,9 @@ func rewriteValuedecArgs(v *Value) bool {
}
func rewriteValuedecArgs_OpArg_0(v *Value) bool {
b := v.Block
_ = b
config := b.Func.Config
_ = config
fe := b.Func.fe
_ = fe
typ := &b.Func.Config.Types
_ = typ
// match: (Arg {n} [off])
// cond: v.Type.IsString()
// result: (StringMake (Arg <typ.BytePtr> {n} [off]) (Arg <typ.Int> {n} [off+config.PtrSize]))
......@@ -242,9 +238,7 @@ func rewriteValuedecArgs_OpArg_0(v *Value) bool {
}
func rewriteValuedecArgs_OpArg_10(v *Value) bool {
b := v.Block
_ = b
fe := b.Func.fe
_ = fe
// match: (Arg <t>)
// cond: t.IsArray() && t.NumElem() == 0
// result: (ArrayMake0)
......
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