Skip to content

Commit 79a3482

Browse files
committed
cmd/compile: remove support for untyped ssa rules
This change removes support in rulegen for untyped -> ssa rules. Change-Id: I202018e191fc74f027243351bc8cf96145f2482c Reviewed-on: https://go-review.googlesource.com/c/go/+/264679 Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Trust: Alberto Donizetti <alb.donizetti@gmail.com>
1 parent c515852 commit 79a3482

File tree

1 file changed

+22
-65
lines changed

1 file changed

+22
-65
lines changed

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

Lines changed: 22 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ import (
3535
)
3636

3737
// rule syntax:
38-
// sexpr [&& extra conditions] -> [@block] sexpr (untyped)
39-
// sexpr [&& extra conditions] => [@block] sexpr (typed)
38+
// sexpr [&& extra conditions] => [@block] sexpr
4039
//
4140
// sexpr are s-expressions (lisp-like parenthesized groupings)
4241
// sexpr ::= [variable:](opcode sexpr*)
@@ -79,22 +78,16 @@ func normalizeSpaces(s string) string {
7978
}
8079

8180
// parse returns the matching part of the rule, additional conditions, and the result.
82-
// parse also reports whether the generated code should use strongly typed aux and auxint fields.
83-
func (r Rule) parse() (match, cond, result string, typed bool) {
84-
arrow := "->"
85-
if strings.Contains(r.Rule, "=>") {
86-
arrow = "=>"
87-
typed = true
88-
}
89-
s := strings.Split(r.Rule, arrow)
81+
func (r Rule) parse() (match, cond, result string) {
82+
s := strings.Split(r.Rule, "=>")
9083
match = normalizeSpaces(s[0])
9184
result = normalizeSpaces(s[1])
9285
cond = ""
9386
if i := strings.Index(match, "&&"); i >= 0 {
9487
cond = normalizeSpaces(match[i+2:])
9588
match = normalizeSpaces(match[:i])
9689
}
97-
return match, cond, result, typed
90+
return match, cond, result
9891
}
9992

10093
func genRules(arch arch) { genRulesSuffix(arch, "") }
@@ -120,7 +113,7 @@ func genRulesSuffix(arch arch, suff string) {
120113
scanner := bufio.NewScanner(text)
121114
rule := ""
122115
var lineno int
123-
var ruleLineno int // line number of "->" or "=>"
116+
var ruleLineno int // line number of "=>"
124117
for scanner.Scan() {
125118
lineno++
126119
line := scanner.Text()
@@ -134,13 +127,13 @@ func genRulesSuffix(arch arch, suff string) {
134127
if rule == "" {
135128
continue
136129
}
137-
if !strings.Contains(rule, "->") && !strings.Contains(rule, "=>") {
130+
if !strings.Contains(rule, "=>") {
138131
continue
139132
}
140133
if ruleLineno == 0 {
141134
ruleLineno = lineno
142135
}
143-
if strings.HasSuffix(rule, "->") || strings.HasSuffix(rule, "=>") {
136+
if strings.HasSuffix(rule, "=>") {
144137
continue // continue on the next line
145138
}
146139
if n := balance(rule); n > 0 {
@@ -157,7 +150,7 @@ func genRulesSuffix(arch arch, suff string) {
157150
continue
158151
}
159152
// Do fancier value op matching.
160-
match, _, _, _ := r.parse()
153+
match, _, _ := r.parse()
161154
op, oparch, _, _, _, _ := parseValue(match, arch, loc)
162155
opname := fmt.Sprintf("Op%s%s", oparch, op.name)
163156
oprules[opname] = append(oprules[opname], r)
@@ -231,7 +224,7 @@ func genRulesSuffix(arch arch, suff string) {
231224
log.Fatalf("unconditional rule %s is followed by other rules", rr.Match)
232225
}
233226
rr = &RuleRewrite{Loc: rule.Loc}
234-
rr.Match, rr.Cond, rr.Result, rr.Typed = rule.parse()
227+
rr.Match, rr.Cond, rr.Result = rule.parse()
235228
pos, _ := genMatch(rr, arch, rr.Match, fn.ArgLen >= 0)
236229
if pos == "" {
237230
pos = "v.Pos"
@@ -790,7 +783,6 @@ type (
790783
Alloc int // for unique var names
791784
Loc string // file name & line number of the original rule
792785
CommuteDepth int // used to track depth of commute loops
793-
Typed bool // aux and auxint fields should be strongly typed
794786
}
795787
Declare struct {
796788
Name string
@@ -844,7 +836,7 @@ func breakf(format string, a ...interface{}) *CondBreak {
844836

845837
func genBlockRewrite(rule Rule, arch arch, data blockData) *RuleRewrite {
846838
rr := &RuleRewrite{Loc: rule.Loc}
847-
rr.Match, rr.Cond, rr.Result, rr.Typed = rule.parse()
839+
rr.Match, rr.Cond, rr.Result = rule.parse()
848840
_, _, auxint, aux, s := extract(rr.Match) // remove parens, then split
849841

850842
// check match of control values
@@ -888,15 +880,6 @@ func genBlockRewrite(rule Rule, arch arch, data blockData) *RuleRewrite {
888880
if e.name == "" {
889881
continue
890882
}
891-
if !rr.Typed {
892-
if !token.IsIdentifier(e.name) || rr.declared(e.name) {
893-
// code or variable
894-
rr.add(breakf("b.%s != %s", e.field, e.name))
895-
} else {
896-
rr.add(declf(e.name, "b.%s", e.field))
897-
}
898-
continue
899-
}
900883

901884
if e.dclType == "" {
902885
log.Fatalf("op %s has no declared type for %s", data.name, e.field)
@@ -965,20 +948,12 @@ func genBlockRewrite(rule Rule, arch arch, data blockData) *RuleRewrite {
965948
}
966949

967950
if auxint != "" {
968-
if rr.Typed {
969-
// Make sure auxint value has the right type.
970-
rr.add(stmtf("b.AuxInt = %sToAuxInt(%s)", unTitle(outdata.auxIntType()), auxint))
971-
} else {
972-
rr.add(stmtf("b.AuxInt = %s", auxint))
973-
}
951+
// Make sure auxint value has the right type.
952+
rr.add(stmtf("b.AuxInt = %sToAuxInt(%s)", unTitle(outdata.auxIntType()), auxint))
974953
}
975954
if aux != "" {
976-
if rr.Typed {
977-
// Make sure aux value has the right type.
978-
rr.add(stmtf("b.Aux = %sToAux(%s)", unTitle(outdata.auxType()), aux))
979-
} else {
980-
rr.add(stmtf("b.Aux = %s", aux))
981-
}
955+
// Make sure aux value has the right type.
956+
rr.add(stmtf("b.Aux = %sToAux(%s)", unTitle(outdata.auxType()), aux))
982957
}
983958

984959
succChanged := false
@@ -1046,15 +1021,6 @@ func genMatch0(rr *RuleRewrite, arch arch, match, v string, cnt map[string]int,
10461021
if e.name == "" {
10471022
continue
10481023
}
1049-
if !rr.Typed {
1050-
if !token.IsIdentifier(e.name) || rr.declared(e.name) {
1051-
// code or variable
1052-
rr.add(breakf("%s.%s != %s", v, e.field, e.name))
1053-
} else {
1054-
rr.add(declf(e.name, "%s.%s", v, e.field))
1055-
}
1056-
continue
1057-
}
10581024

10591025
if e.dclType == "" {
10601026
log.Fatalf("op %s has no declared type for %s", op.name, e.field)
@@ -1244,20 +1210,12 @@ func genResult0(rr *RuleRewrite, arch arch, result string, top, move bool, pos s
12441210
}
12451211

12461212
if auxint != "" {
1247-
if rr.Typed {
1248-
// Make sure auxint value has the right type.
1249-
rr.add(stmtf("%s.AuxInt = %sToAuxInt(%s)", v, unTitle(op.auxIntType()), auxint))
1250-
} else {
1251-
rr.add(stmtf("%s.AuxInt = %s", v, auxint))
1252-
}
1213+
// Make sure auxint value has the right type.
1214+
rr.add(stmtf("%s.AuxInt = %sToAuxInt(%s)", v, unTitle(op.auxIntType()), auxint))
12531215
}
12541216
if aux != "" {
1255-
if rr.Typed {
1256-
// Make sure aux value has the right type.
1257-
rr.add(stmtf("%s.Aux = %sToAux(%s)", v, unTitle(op.auxType()), aux))
1258-
} else {
1259-
rr.add(stmtf("%s.Aux = %s", v, aux))
1260-
}
1217+
// Make sure aux value has the right type.
1218+
rr.add(stmtf("%s.Aux = %sToAux(%s)", v, unTitle(op.auxType()), aux))
12611219
}
12621220
all := new(strings.Builder)
12631221
for i, arg := range args {
@@ -1538,7 +1496,7 @@ func excludeFromExpansion(s string, idx []int) bool {
15381496
return true
15391497
}
15401498
right := s[idx[1]:]
1541-
if strings.Contains(left, "&&") && (strings.Contains(right, "->") || strings.Contains(right, "=>")) {
1499+
if strings.Contains(left, "&&") && strings.Contains(right, "=>") {
15421500
// Inside && conditions.
15431501
return true
15441502
}
@@ -1640,7 +1598,6 @@ func normalizeWhitespace(x string) string {
16401598
x = strings.Replace(x, " )", ")", -1)
16411599
x = strings.Replace(x, "[ ", "[", -1)
16421600
x = strings.Replace(x, " ]", "]", -1)
1643-
x = strings.Replace(x, ")->", ") ->", -1)
16441601
x = strings.Replace(x, ")=>", ") =>", -1)
16451602
return x
16461603
}
@@ -1697,7 +1654,7 @@ func parseEllipsisRules(rules []Rule, arch arch) (newop string, ok bool) {
16971654
return "", false
16981655
}
16991656
rule := rules[0]
1700-
match, cond, result, _ := rule.parse()
1657+
match, cond, result := rule.parse()
17011658
if cond != "" || !isEllipsisValue(match) || !isEllipsisValue(result) {
17021659
if strings.Contains(rule.Rule, "...") {
17031660
log.Fatalf("%s: found ellipsis in non-ellipsis rule", rule.Loc)
@@ -1722,7 +1679,7 @@ func isEllipsisValue(s string) bool {
17221679
}
17231680

17241681
func checkEllipsisRuleCandidate(rule Rule, arch arch) {
1725-
match, cond, result, _ := rule.parse()
1682+
match, cond, result := rule.parse()
17261683
if cond != "" {
17271684
return
17281685
}
@@ -1732,7 +1689,7 @@ func checkEllipsisRuleCandidate(rule Rule, arch arch) {
17321689
var usingCopy string
17331690
var eop opData
17341691
if result[0] != '(' {
1735-
// Check for (Foo x) -> x, which can be converted to (Foo ...) -> (Copy ...).
1692+
// Check for (Foo x) => x, which can be converted to (Foo ...) => (Copy ...).
17361693
args2 = []string{result}
17371694
usingCopy = " using Copy"
17381695
} else {

0 commit comments

Comments
 (0)