Skip to content

Commit bdf0fe5

Browse files
committed
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í <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 95b8cbf commit bdf0fe5

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

src/cmd/compile/internal/ssa/gen/rulegen.go

+13-21
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func genRulesSuffix(arch arch, suff string) {
237237
// so we can make this one function with a switch.
238238
fn = &Func{kind: "Block"}
239239
fn.add(declf("config", "b.Func.Config"))
240-
fn.add(declf("typ", "&config.Types"))
240+
fn.add(declf("typ", "&b.Func.Config.Types"))
241241
fn.add(declf("v", "b.Control"))
242242

243243
sw = &Switch{expr: exprf("b.Kind")}
@@ -851,28 +851,21 @@ func genMatch0(rr *RuleRewrite, arch arch, match, v string) (pos, checkOp string
851851
pos = v + ".Pos"
852852
}
853853

854-
if typ != "" {
855-
if !token.IsIdentifier(typ) || rr.declared(typ) {
856-
// code or variable
857-
rr.add(breakf("%s.Type != %s", v, typ))
858-
} else {
859-
rr.add(declf(typ, "%s.Type", v))
860-
}
861-
}
862-
if auxint != "" {
863-
if !token.IsIdentifier(auxint) || rr.declared(auxint) {
864-
// code or variable
865-
rr.add(breakf("%s.AuxInt != %s", v, auxint))
866-
} else {
867-
rr.add(declf(auxint, "%s.AuxInt", v))
854+
for _, e := range []struct {
855+
name, field string
856+
}{
857+
{typ, "Type"},
858+
{auxint, "AuxInt"},
859+
{aux, "Aux"},
860+
} {
861+
if e.name == "" {
862+
continue
868863
}
869-
}
870-
if aux != "" {
871-
if !token.IsIdentifier(aux) || rr.declared(aux) {
864+
if !token.IsIdentifier(e.name) || rr.declared(e.name) {
872865
// code or variable
873-
rr.add(breakf("%s.Aux != %s", v, aux))
866+
rr.add(breakf("%s.%s != %s", v, e.field, e.name))
874867
} else {
875-
rr.add(declf(aux, "%s.Aux", v))
868+
rr.add(declf(e.name, "%s.%s", v, e.field))
876869
}
877870
}
878871

@@ -921,7 +914,6 @@ func genMatch0(rr *RuleRewrite, arch arch, match, v string) (pos, checkOp string
921914
rr.add(declf(argname, "%s.Args[%d]", v, i))
922915
bexpr := exprf("%s.Op != addLater", argname)
923916
rr.add(&CondBreak{expr: bexpr})
924-
rr.canFail = true // since we're not using breakf
925917
argPos, argCheckOp := genMatch0(rr, arch, arg, argname)
926918
bexpr.(*ast.BinaryExpr).Y.(*ast.Ident).Name = argCheckOp
927919

src/cmd/compile/internal/ssa/rewriteS390X.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)