1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:44:46 -07:00

cmd/compile: minor simplifications in rulegen

First, be consistent about declaring typ as &b.Func.Config.Types and
not &config.Types. Not particularly better, and it barely changes the
output, but we're more consistent now.

Second, remove a bit of duplication when handling the typ, auxint, and
aux variables.

Third and last, remove a stray canFail assignment; we ended up setting
that in add, not breakf, so it's not necessary to set it manually if we
don't use breakf.

Updates #33644.

Change-Id: I75999cb223a201969266fbfeae043599fa27fac5
Reviewed-on: https://go-review.googlesource.com/c/go/+/196803
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Daniel Martí 2019-09-23 23:10:25 +01:00
parent 95b8cbfee9
commit bdf0fe5448
2 changed files with 14 additions and 23 deletions

View File

@ -237,7 +237,7 @@ func genRulesSuffix(arch arch, suff string) {
// so we can make this one function with a switch.
fn = &Func{kind: "Block"}
fn.add(declf("config", "b.Func.Config"))
fn.add(declf("typ", "&config.Types"))
fn.add(declf("typ", "&b.Func.Config.Types"))
fn.add(declf("v", "b.Control"))
sw = &Switch{expr: exprf("b.Kind")}
@ -851,28 +851,21 @@ func genMatch0(rr *RuleRewrite, arch arch, match, v string) (pos, checkOp string
pos = v + ".Pos"
}
if typ != "" {
if !token.IsIdentifier(typ) || rr.declared(typ) {
// code or variable
rr.add(breakf("%s.Type != %s", v, typ))
} else {
rr.add(declf(typ, "%s.Type", v))
for _, e := range []struct {
name, field string
}{
{typ, "Type"},
{auxint, "AuxInt"},
{aux, "Aux"},
} {
if e.name == "" {
continue
}
}
if auxint != "" {
if !token.IsIdentifier(auxint) || rr.declared(auxint) {
if !token.IsIdentifier(e.name) || rr.declared(e.name) {
// code or variable
rr.add(breakf("%s.AuxInt != %s", v, auxint))
rr.add(breakf("%s.%s != %s", v, e.field, e.name))
} else {
rr.add(declf(auxint, "%s.AuxInt", v))
}
}
if aux != "" {
if !token.IsIdentifier(aux) || rr.declared(aux) {
// code or variable
rr.add(breakf("%s.Aux != %s", v, aux))
} else {
rr.add(declf(aux, "%s.Aux", v))
rr.add(declf(e.name, "%s.%s", v, e.field))
}
}
@ -921,7 +914,6 @@ func genMatch0(rr *RuleRewrite, arch arch, match, v string) (pos, checkOp string
rr.add(declf(argname, "%s.Args[%d]", v, i))
bexpr := exprf("%s.Op != addLater", argname)
rr.add(&CondBreak{expr: bexpr})
rr.canFail = true // since we're not using breakf
argPos, argCheckOp := genMatch0(rr, arch, arg, argname)
bexpr.(*ast.BinaryExpr).Y.(*ast.Ident).Name = argCheckOp

View File

@ -36448,8 +36448,7 @@ func rewriteValueS390X_OpZeroExt8to64_0(v *Value) bool {
}
}
func rewriteBlockS390X(b *Block) bool {
config := b.Func.Config
typ := &config.Types
typ := &b.Func.Config.Types
v := b.Control
switch b.Kind {
case BlockS390XBRC: