@@ -9,9 +9,12 @@ import (
9
9
)
10
10
11
11
// findlive returns the reachable blocks and live values in f.
12
+ // The caller should call f.retDeadcodeLive(live) when it is done with it.
12
13
func findlive (f * Func ) (reachable []bool , live []bool ) {
13
14
reachable = ReachableBlocks (f )
14
- live , _ = liveValues (f , reachable )
15
+ var order []* Value
16
+ live , order = liveValues (f , reachable )
17
+ f .retDeadcodeLiveOrderStmts (order )
15
18
return
16
19
}
17
20
@@ -48,8 +51,21 @@ func ReachableBlocks(f *Func) []bool {
48
51
// to be statements in reversed data flow order.
49
52
// The second result is used to help conserve statement boundaries for debugging.
50
53
// reachable is a map from block ID to whether the block is reachable.
54
+ // The caller should call f.retDeadcodeLive(live) and f.retDeadcodeLiveOrderStmts(liveOrderStmts)
55
+ // when they are done with the return values.
51
56
func liveValues (f * Func , reachable []bool ) (live []bool , liveOrderStmts []* Value ) {
52
- live = make ([]bool , f .NumValues ())
57
+ live = f .newDeadcodeLive ()
58
+ if cap (live ) < f .NumValues () {
59
+ live = make ([]bool , f .NumValues ())
60
+ } else {
61
+ live = live [:f .NumValues ()]
62
+ for i := range live {
63
+ live [i ] = false
64
+ }
65
+ }
66
+
67
+ liveOrderStmts = f .newDeadcodeLiveOrderStmts ()
68
+ liveOrderStmts = liveOrderStmts [:0 ]
53
69
54
70
// After regalloc, consider all values to be live.
55
71
// See the comment at the top of regalloc.go and in deadcode for details.
@@ -61,7 +77,8 @@ func liveValues(f *Func, reachable []bool) (live []bool, liveOrderStmts []*Value
61
77
}
62
78
63
79
// Find all live values
64
- q := make ([]* Value , 0 , 64 ) // stack-like worklist of unscanned values
80
+ q := f .Cache .deadcode .q [:0 ]
81
+ defer func () { f .Cache .deadcode .q = q }()
65
82
66
83
// Starting set: all control values of reachable blocks are live.
67
84
// Calls are live (because callee can observe the memory state).
@@ -163,6 +180,8 @@ func deadcode(f *Func) {
163
180
164
181
// Find live values.
165
182
live , order := liveValues (f , reachable )
183
+ defer f .retDeadcodeLive (live )
184
+ defer f .retDeadcodeLiveOrderStmts (order )
166
185
167
186
// Remove dead & duplicate entries from namedValues map.
168
187
s := f .newSparseSet (f .NumValues ())
0 commit comments