Skip to content

Commit 6769966

Browse files
mdempskypull[bot]
authored andcommitted
cmd/compile/internal/escape: flip transient to !persists
I want to add more location properties (e.g., to track indirect stores and calls), and it's easier to reason about them if they're all consistent that "true" means more consequences than less. Change-Id: I3f8674bb11877ba33082a0f5f7d8e55ad6d7a4cc Reviewed-on: https://go-review.googlesource.com/c/go/+/520257 Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Matthew Dempsky <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent 7584a19 commit 6769966

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

src/cmd/compile/internal/escape/call.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ func (e *escape) copyExpr(pos src.XPos, expr ir.Node, init *ir.Nodes, fn *ir.Fun
430430
init.Append(stmts...)
431431

432432
if analyze {
433-
e.newLoc(tmp, false)
433+
e.newLoc(tmp, true)
434434
e.stmts(stmts)
435435
}
436436

src/cmd/compile/internal/escape/escape.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func Batch(fns []*ir.Func, recursive bool) {
130130

131131
var b batch
132132
b.heapLoc.escapes = true
133-
b.blankLoc.transient = true
133+
b.heapLoc.persists = true
134134

135135
// Construct data-flow graph from syntax trees.
136136
for _, fn := range fns {
@@ -185,14 +185,14 @@ func (b *batch) initFunc(fn *ir.Func) {
185185

186186
// Allocate locations for local variables.
187187
for _, n := range fn.Dcl {
188-
e.newLoc(n, false)
188+
e.newLoc(n, true)
189189
}
190190

191191
// Also for hidden parameters (e.g., the ".this" parameter to a
192192
// method value wrapper).
193193
if fn.OClosure == nil {
194194
for _, n := range fn.ClosureVars {
195-
e.newLoc(n.Canonical(), false)
195+
e.newLoc(n.Canonical(), true)
196196
}
197197
}
198198

@@ -324,7 +324,7 @@ func (b *batch) finish(fns []*ir.Func) {
324324
base.WarnfAt(n.Pos(), "%v does not escape", n)
325325
}
326326
n.SetEsc(ir.EscNone)
327-
if loc.transient {
327+
if !loc.persists {
328328
switch n.Op() {
329329
case ir.OCLOSURE:
330330
n := n.(*ir.ClosureExpr)

src/cmd/compile/internal/escape/expr.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) {
250250
// analysis (happens for escape analysis called
251251
// from reflectdata.methodWrapper)
252252
if n.Op() == ir.ONAME && n.Opt == nil {
253-
e.with(fn).newLoc(n, false)
253+
e.with(fn).newLoc(n, true)
254254
}
255255
}
256256
e.walkFunc(fn)
@@ -335,7 +335,7 @@ func (e *escape) discards(l ir.Nodes) {
335335
// its address to k, and returns a hole that flows values to it. It's
336336
// intended for use with most expressions that allocate storage.
337337
func (e *escape) spill(k hole, n ir.Node) hole {
338-
loc := e.newLoc(n, true)
338+
loc := e.newLoc(n, false)
339339
e.flow(k.addr(n, "spill"), loc)
340340
return loc.asHole()
341341
}

src/cmd/compile/internal/escape/graph.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ type location struct {
7171
// allocated.
7272
escapes bool
7373

74-
// transient reports whether the represented expression's
75-
// address does not outlive the statement; that is, whether
76-
// its storage can be immediately reused.
77-
transient bool
74+
// persists reports whether the represented expression's address
75+
// outlives the statement; that is, whether its storage cannot be
76+
// immediately reused.
77+
persists bool
7878

7979
// paramEsc records the represented parameter's leak set.
8080
paramEsc leaks
@@ -213,7 +213,7 @@ func (b *batch) oldLoc(n *ir.Name) *location {
213213
return n.Canonical().Opt.(*location)
214214
}
215215

216-
func (e *escape) newLoc(n ir.Node, transient bool) *location {
216+
func (e *escape) newLoc(n ir.Node, persists bool) *location {
217217
if e.curfn == nil {
218218
base.Fatalf("e.curfn isn't set")
219219
}
@@ -230,7 +230,7 @@ func (e *escape) newLoc(n ir.Node, transient bool) *location {
230230
n: n,
231231
curfn: e.curfn,
232232
loopDepth: e.loopDepth,
233-
transient: transient,
233+
persists: persists,
234234
}
235235
e.allLocs = append(e.allLocs, loc)
236236
if n != nil {
@@ -265,7 +265,7 @@ func (e *escape) teeHole(ks ...hole) hole {
265265
// Given holes "l1 = _", "l2 = **_", "l3 = *_", ..., create a
266266
// new temporary location ltmp, wire it into place, and return
267267
// a hole for "ltmp = _".
268-
loc := e.newLoc(nil, true)
268+
loc := e.newLoc(nil, false)
269269
for _, k := range ks {
270270
// N.B., "p = &q" and "p = &tmp; tmp = q" are not
271271
// semantically equivalent. To combine holes like "l1
@@ -285,7 +285,7 @@ func (e *escape) teeHole(ks ...hole) hole {
285285
// Its main effect is to prevent immediate reuse of temporary
286286
// variables introduced during Order.
287287
func (e *escape) later(k hole) hole {
288-
loc := e.newLoc(nil, false)
288+
loc := e.newLoc(nil, true)
289289
e.flow(k, loc)
290290
return loc.asHole()
291291
}

src/cmd/compile/internal/escape/solve.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (b *batch) walkAll() {
2121
//
2222
// We walk once from each location (including the heap), and
2323
// then re-enqueue each location on its transition from
24-
// transient->!transient and !escapes->escapes, which can each
24+
// !persists->persists and !escapes->escapes, which can each
2525
// happen at most once. So we take Θ(len(e.allLocs)) walks.
2626

2727
// LIFO queue, has enough room for e.allLocs and e.heapLoc.
@@ -77,11 +77,10 @@ func (b *batch) walkOne(root *location, walkgen uint32, enqueue func(*location))
7777
// derefs at 0.
7878
derefs = 0
7979

80-
// If l's address flows to a non-transient
81-
// location, then l can't be transiently
82-
// allocated.
83-
if !root.transient && l.transient {
84-
l.transient = false
80+
// If l's address flows to a persistent location, then l needs
81+
// to persist too.
82+
if root.persists && !l.persists {
83+
l.persists = true
8584
enqueue(l)
8685
}
8786
}

src/cmd/compile/internal/escape/stmt.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ func (e *escape) stmt(n ir.Node) {
9292
n := n.(*ir.RangeStmt)
9393
base.Assert(!n.DistinctVars) // Should all be rewritten before escape analysis
9494

95-
// X is evaluated outside the loop.
96-
tmp := e.newLoc(nil, false)
95+
// X is evaluated outside the loop and persists until the loop
96+
// terminates.
97+
tmp := e.newLoc(nil, true)
9798
e.expr(tmp.asHole(), n.X)
9899

99100
e.loopDepth++

0 commit comments

Comments
 (0)