From bdf0fe54480034cd21e36cfed6e44f10f4cb5c92 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Mon, 23 Sep 2019 23:10:25 +0100 Subject: [PATCH] cmd/compile: minor simplifications in rulegen MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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í Reviewed-by: Keith Randall TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/ssa/gen/rulegen.go | 34 ++++++++------------ src/cmd/compile/internal/ssa/rewriteS390X.go | 3 +- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/rulegen.go b/src/cmd/compile/internal/ssa/gen/rulegen.go index 994e5b932f..7c02778181 100644 --- a/src/cmd/compile/internal/ssa/gen/rulegen.go +++ b/src/cmd/compile/internal/ssa/gen/rulegen.go @@ -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)) - } - } - if auxint != "" { - if !token.IsIdentifier(auxint) || rr.declared(auxint) { - // code or variable - rr.add(breakf("%s.AuxInt != %s", v, auxint)) - } else { - rr.add(declf(auxint, "%s.AuxInt", v)) + for _, e := range []struct { + name, field string + }{ + {typ, "Type"}, + {auxint, "AuxInt"}, + {aux, "Aux"}, + } { + if e.name == "" { + continue } - } - if aux != "" { - if !token.IsIdentifier(aux) || rr.declared(aux) { + if !token.IsIdentifier(e.name) || rr.declared(e.name) { // code or variable - rr.add(breakf("%s.Aux != %s", v, aux)) + rr.add(breakf("%s.%s != %s", v, e.field, e.name)) } 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 diff --git a/src/cmd/compile/internal/ssa/rewriteS390X.go b/src/cmd/compile/internal/ssa/rewriteS390X.go index ac2fbf80b8..84fe1473c0 100644 --- a/src/cmd/compile/internal/ssa/rewriteS390X.go +++ b/src/cmd/compile/internal/ssa/rewriteS390X.go @@ -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: -- 2.50.0