mirror of
https://github.com/golang/go
synced 2024-11-26 08:48:13 -07:00
[dev.regabi] cmd/compile: merge ascompatee, ascompatee1, and reorder3
These functions are interelated and have arbitrarily overlapping responsibilities. By joining them together, we simplify the code and remove some redundancy. Passes toolstash -cmp. Change-Id: I7c42cb7171b3006bc790199be3fd0991e6e985f2 Reviewed-on: https://go-review.googlesource.com/c/go/+/280438 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
4c215c4fa9
commit
c98548e110
@ -297,54 +297,6 @@ func fncall(l ir.Node, rt *types.Type) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func ascompatee(op ir.Op, nl, nr []ir.Node, init *ir.Nodes) []ir.Node {
|
|
||||||
// check assign expression list to
|
|
||||||
// an expression list. called in
|
|
||||||
// expr-list = expr-list
|
|
||||||
|
|
||||||
// ensure order of evaluation for function calls
|
|
||||||
for i := range nl {
|
|
||||||
nl[i] = safeExpr(nl[i], init)
|
|
||||||
}
|
|
||||||
for i1 := range nr {
|
|
||||||
nr[i1] = safeExpr(nr[i1], init)
|
|
||||||
}
|
|
||||||
|
|
||||||
var nn []*ir.AssignStmt
|
|
||||||
i := 0
|
|
||||||
for ; i < len(nl); i++ {
|
|
||||||
if i >= len(nr) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
// Do not generate 'x = x' during return. See issue 4014.
|
|
||||||
if op == ir.ORETURN && ir.SameSafeExpr(nl[i], nr[i]) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
nn = append(nn, ascompatee1(nl[i], nr[i], init))
|
|
||||||
}
|
|
||||||
|
|
||||||
// cannot happen: caller checked that lists had same length
|
|
||||||
if i < len(nl) || i < len(nr) {
|
|
||||||
var nln, nrn ir.Nodes
|
|
||||||
nln.Set(nl)
|
|
||||||
nrn.Set(nr)
|
|
||||||
base.Fatalf("error in shape across %+v %v %+v / %d %d [%s]", nln, op, nrn, len(nl), len(nr), ir.FuncName(ir.CurFunc))
|
|
||||||
}
|
|
||||||
return reorder3(nn)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ascompatee1(l ir.Node, r ir.Node, init *ir.Nodes) *ir.AssignStmt {
|
|
||||||
// convas will turn map assigns into function calls,
|
|
||||||
// making it impossible for reorder3 to work.
|
|
||||||
n := ir.NewAssignStmt(base.Pos, l, r)
|
|
||||||
|
|
||||||
if l.Op() == ir.OINDEXMAP {
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
return convas(n, init)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check assign type list to
|
// check assign type list to
|
||||||
// an expression list. called in
|
// an expression list. called in
|
||||||
// expr-list = func()
|
// expr-list = func()
|
||||||
@ -387,14 +339,23 @@ func ascompatet(nl ir.Nodes, nr *types.Type) []ir.Node {
|
|||||||
return append(nn, mm...)
|
return append(nn, mm...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// reorder3
|
// check assign expression list to
|
||||||
// from ascompatee
|
// an expression list. called in
|
||||||
// a,b = c,d
|
// expr-list = expr-list
|
||||||
// simultaneous assignment. there cannot
|
func ascompatee(op ir.Op, nl, nr []ir.Node, init *ir.Nodes) []ir.Node {
|
||||||
// be later use of an earlier lvalue.
|
// cannot happen: should have been rejected during type checking
|
||||||
//
|
if len(nl) != len(nr) {
|
||||||
// function calls have been removed.
|
base.Fatalf("assignment operands mismatch: %+v / %+v", ir.Nodes(nl), ir.Nodes(nr))
|
||||||
func reorder3(all []*ir.AssignStmt) []ir.Node {
|
}
|
||||||
|
|
||||||
|
// ensure order of evaluation for function calls
|
||||||
|
for i := range nl {
|
||||||
|
nl[i] = safeExpr(nl[i], init)
|
||||||
|
}
|
||||||
|
for i := range nr {
|
||||||
|
nr[i] = safeExpr(nr[i], init)
|
||||||
|
}
|
||||||
|
|
||||||
var assigned ir.NameSet
|
var assigned ir.NameSet
|
||||||
var memWrite bool
|
var memWrite bool
|
||||||
|
|
||||||
@ -425,9 +386,16 @@ func reorder3(all []*ir.AssignStmt) []ir.Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var mapinit ir.Nodes
|
var late []ir.Node
|
||||||
for i, n := range all {
|
for i, l := range nl {
|
||||||
l := n.X
|
r := nr[i]
|
||||||
|
|
||||||
|
// Do not generate 'x = x' during return. See issue 4014.
|
||||||
|
if op == ir.ORETURN && ir.SameSafeExpr(l, r) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
as := ir.NewAssignStmt(base.Pos, l, r)
|
||||||
|
|
||||||
// Save subexpressions needed on left side.
|
// Save subexpressions needed on left side.
|
||||||
// Drill through non-dereferences.
|
// Drill through non-dereferences.
|
||||||
@ -454,19 +422,13 @@ func reorder3(all []*ir.AssignStmt) []ir.Node {
|
|||||||
var name *ir.Name
|
var name *ir.Name
|
||||||
switch l.Op() {
|
switch l.Op() {
|
||||||
default:
|
default:
|
||||||
base.Fatalf("reorder3 unexpected lvalue %v", l.Op())
|
base.Fatalf("unexpected lvalue %v", l.Op())
|
||||||
|
|
||||||
case ir.ONAME:
|
case ir.ONAME:
|
||||||
name = l.(*ir.Name)
|
name = l.(*ir.Name)
|
||||||
|
|
||||||
case ir.OINDEX, ir.OINDEXMAP:
|
case ir.OINDEX, ir.OINDEXMAP:
|
||||||
l := l.(*ir.IndexExpr)
|
l := l.(*ir.IndexExpr)
|
||||||
save(&l.X)
|
save(&l.X)
|
||||||
save(&l.Index)
|
save(&l.Index)
|
||||||
if l.Op() == ir.OINDEXMAP {
|
|
||||||
all[i] = convas(all[i], &mapinit)
|
|
||||||
}
|
|
||||||
|
|
||||||
case ir.ODEREF:
|
case ir.ODEREF:
|
||||||
l := l.(*ir.StarExpr)
|
l := l.(*ir.StarExpr)
|
||||||
save(&l.X)
|
save(&l.X)
|
||||||
@ -476,7 +438,9 @@ func reorder3(all []*ir.AssignStmt) []ir.Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save expression on right side.
|
// Save expression on right side.
|
||||||
save(&all[i].Y)
|
save(&as.Y)
|
||||||
|
|
||||||
|
late = append(late, convas(as, init))
|
||||||
|
|
||||||
if name == nil || name.Addrtaken() || name.Class_ == ir.PEXTERN || name.Class_ == ir.PAUTOHEAP {
|
if name == nil || name.Addrtaken() || name.Class_ == ir.PEXTERN || name.Class_ == ir.PAUTOHEAP {
|
||||||
memWrite = true
|
memWrite = true
|
||||||
@ -489,11 +453,7 @@ func reorder3(all []*ir.AssignStmt) []ir.Node {
|
|||||||
assigned.Add(name)
|
assigned.Add(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
early = append(mapinit, early...)
|
return append(early, late...)
|
||||||
for _, as := range all {
|
|
||||||
early = append(early, as)
|
|
||||||
}
|
|
||||||
return early
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// readsMemory reports whether the evaluation n directly reads from
|
// readsMemory reports whether the evaluation n directly reads from
|
||||||
|
Loading…
Reference in New Issue
Block a user