mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/walk: merge operations
Change-Id: I018872da519dfb4aa6c252ea28fc09289c2d9711
GitHub-Last-Rev: 5969776197
GitHub-Pull-Request: golang/go#45795
Reviewed-on: https://go-review.googlesource.com/c/go/+/313550
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Keith Randall <khr@golang.org>
This commit is contained in:
parent
13e87cda00
commit
b9dfaf77f5
1 changed files with 10 additions and 22 deletions
|
|
@ -118,9 +118,7 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
|
||||||
tmp.SetBounded(true)
|
tmp.SetBounded(true)
|
||||||
// Use OAS2 to correctly handle assignments
|
// Use OAS2 to correctly handle assignments
|
||||||
// of the form "v1, a[v1] := range".
|
// of the form "v1, a[v1] := range".
|
||||||
a := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
|
a := ir.NewAssignListStmt(base.Pos, ir.OAS2, []ir.Node{v1, v2}, []ir.Node{hv1, tmp})
|
||||||
a.Lhs = []ir.Node{v1, v2}
|
|
||||||
a.Rhs = []ir.Node{hv1, tmp}
|
|
||||||
body = []ir.Node{a}
|
body = []ir.Node{a}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -148,9 +146,7 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
|
||||||
|
|
||||||
// Use OAS2 to correctly handle assignments
|
// Use OAS2 to correctly handle assignments
|
||||||
// of the form "v1, a[v1] := range".
|
// of the form "v1, a[v1] := range".
|
||||||
a := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
|
a := ir.NewAssignListStmt(base.Pos, ir.OAS2, []ir.Node{v1, v2}, []ir.Node{hv1, ir.NewStarExpr(base.Pos, hp)})
|
||||||
a.Lhs = []ir.Node{v1, v2}
|
|
||||||
a.Rhs = []ir.Node{hv1, ir.NewStarExpr(base.Pos, hp)}
|
|
||||||
body = append(body, a)
|
body = append(body, a)
|
||||||
|
|
||||||
// Advance pointer as part of the late increment.
|
// Advance pointer as part of the late increment.
|
||||||
|
|
@ -190,9 +186,7 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
|
||||||
body = []ir.Node{ir.NewAssignStmt(base.Pos, v1, key)}
|
body = []ir.Node{ir.NewAssignStmt(base.Pos, v1, key)}
|
||||||
} else {
|
} else {
|
||||||
elem := ir.NewStarExpr(base.Pos, ir.NewSelectorExpr(base.Pos, ir.ODOT, hit, elemsym))
|
elem := ir.NewStarExpr(base.Pos, ir.NewSelectorExpr(base.Pos, ir.ODOT, hit, elemsym))
|
||||||
a := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
|
a := ir.NewAssignListStmt(base.Pos, ir.OAS2, []ir.Node{v1, v2}, []ir.Node{key, elem})
|
||||||
a.Lhs = []ir.Node{v1, v2}
|
|
||||||
a.Rhs = []ir.Node{key, elem}
|
|
||||||
body = []ir.Node{a}
|
body = []ir.Node{a}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,10 +202,10 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
|
||||||
hb := typecheck.Temp(types.Types[types.TBOOL])
|
hb := typecheck.Temp(types.Types[types.TBOOL])
|
||||||
|
|
||||||
nfor.Cond = ir.NewBinaryExpr(base.Pos, ir.ONE, hb, ir.NewBool(false))
|
nfor.Cond = ir.NewBinaryExpr(base.Pos, ir.ONE, hb, ir.NewBool(false))
|
||||||
a := ir.NewAssignListStmt(base.Pos, ir.OAS2RECV, nil, nil)
|
lhs := []ir.Node{hv1, hb}
|
||||||
|
rhs := []ir.Node{ir.NewUnaryExpr(base.Pos, ir.ORECV, ha)}
|
||||||
|
a := ir.NewAssignListStmt(base.Pos, ir.OAS2RECV, lhs, rhs)
|
||||||
a.SetTypecheck(1)
|
a.SetTypecheck(1)
|
||||||
a.Lhs = []ir.Node{hv1, hb}
|
|
||||||
a.Rhs = []ir.Node{ir.NewUnaryExpr(base.Pos, ir.ORECV, ha)}
|
|
||||||
nfor.Cond = ir.InitExpr([]ir.Node{a}, nfor.Cond)
|
nfor.Cond = ir.InitExpr([]ir.Node{a}, nfor.Cond)
|
||||||
if v1 == nil {
|
if v1 == nil {
|
||||||
body = nil
|
body = nil
|
||||||
|
|
@ -270,24 +264,18 @@ func walkRange(nrange *ir.RangeStmt) ir.Node {
|
||||||
nif.Body = []ir.Node{ir.NewAssignStmt(base.Pos, hv1, ir.NewBinaryExpr(base.Pos, ir.OADD, hv1, ir.NewInt(1)))}
|
nif.Body = []ir.Node{ir.NewAssignStmt(base.Pos, hv1, ir.NewBinaryExpr(base.Pos, ir.OADD, hv1, ir.NewInt(1)))}
|
||||||
|
|
||||||
// } else {
|
// } else {
|
||||||
eif := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
|
|
||||||
|
|
||||||
// hv2, hv1 = decoderune(ha, hv1)
|
// hv2, hv1 = decoderune(ha, hv1)
|
||||||
eif.Lhs = []ir.Node{hv2, hv1}
|
|
||||||
fn := typecheck.LookupRuntime("decoderune")
|
fn := typecheck.LookupRuntime("decoderune")
|
||||||
var fnInit ir.Nodes
|
call := mkcall1(fn, fn.Type().Results(), &nif.Else, ha, hv1)
|
||||||
eif.Rhs = []ir.Node{mkcall1(fn, fn.Type().Results(), &fnInit, ha, hv1)}
|
a := ir.NewAssignListStmt(base.Pos, ir.OAS2, []ir.Node{hv2, hv1}, []ir.Node{call})
|
||||||
fnInit.Append(eif)
|
nif.Else.Append(a)
|
||||||
nif.Else = fnInit
|
|
||||||
|
|
||||||
body = append(body, nif)
|
body = append(body, nif)
|
||||||
|
|
||||||
if v1 != nil {
|
if v1 != nil {
|
||||||
if v2 != nil {
|
if v2 != nil {
|
||||||
// v1, v2 = hv1t, hv2
|
// v1, v2 = hv1t, hv2
|
||||||
a := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil)
|
a := ir.NewAssignListStmt(base.Pos, ir.OAS2, []ir.Node{v1, v2}, []ir.Node{hv1t, hv2})
|
||||||
a.Lhs = []ir.Node{v1, v2}
|
|
||||||
a.Rhs = []ir.Node{hv1t, hv2}
|
|
||||||
body = append(body, a)
|
body = append(body, a)
|
||||||
} else {
|
} else {
|
||||||
// v1 = hv1t
|
// v1 = hv1t
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue