mirror of
https://github.com/golang/go
synced 2024-11-23 06:50:05 -07:00
cmd/compile: factor out opIsCommutative from commute1
Change-Id: I989a66c98dcca8168e35dd9834fc1365e0a1d881 Reviewed-on: https://go-review.googlesource.com/c/go/+/213697 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
06fa4c9589
commit
715e8bbe63
@ -1361,26 +1361,7 @@ func commute1(m string, cnt map[string]int, arch arch) []string {
|
||||
s := split(m[1 : len(m)-1])
|
||||
op := s[0]
|
||||
|
||||
// Figure out if the op is commutative or not.
|
||||
commutative := false
|
||||
for _, x := range genericOps {
|
||||
if op == x.name {
|
||||
if x.commutative {
|
||||
commutative = true
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if arch.name != "generic" {
|
||||
for _, x := range arch.ops {
|
||||
if op == x.name {
|
||||
if x.commutative {
|
||||
commutative = true
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
commutative := opIsCommutative(op, arch)
|
||||
var idx0, idx1 int
|
||||
if commutative {
|
||||
// Find indexes of two args we can swap.
|
||||
@ -1483,3 +1464,26 @@ func normalizeWhitespace(x string) string {
|
||||
x = strings.Replace(x, ")->", ") ->", -1)
|
||||
return x
|
||||
}
|
||||
|
||||
// opIsCommutative reports whether op s is commutative.
|
||||
func opIsCommutative(op string, arch arch) bool {
|
||||
for _, x := range genericOps {
|
||||
if op == x.name {
|
||||
if x.commutative {
|
||||
return true
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if arch.name != "generic" {
|
||||
for _, x := range arch.ops {
|
||||
if op == x.name {
|
||||
if x.commutative {
|
||||
return true
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user