mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.ssa] cmd/compile: speed up liveness analysis
This reduces the wall time to run test/slice3.go on my laptop from >10m to ~20s. This could perhaps be further reduced by using a worklist of blocks and/or implementing the suggestion in the comment in this CL, but at this point, it's fast enough that there is no need. Change-Id: I741119e0c8310051d7185459f78be8b89237b85b Reviewed-on: https://go-review.googlesource.com/12564 Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
e61e7c96f7
commit
d5297f7261
1 changed files with 13 additions and 2 deletions
|
|
@ -419,13 +419,24 @@ func live(f *Func) [][]ID {
|
||||||
|
|
||||||
s := newSparseSet(f.NumValues())
|
s := newSparseSet(f.NumValues())
|
||||||
t := newSparseSet(f.NumValues())
|
t := newSparseSet(f.NumValues())
|
||||||
|
|
||||||
|
// Instead of iterating over f.Blocks, iterate over their postordering.
|
||||||
|
// Liveness information flows backward, so starting at the end
|
||||||
|
// increases the probability that we will stabilize quickly.
|
||||||
|
// TODO: Do a better job yet. Here's one possibility:
|
||||||
|
// Calculate the dominator tree and locate all strongly connected components.
|
||||||
|
// If a value is live in one block of an SCC, it is live in all.
|
||||||
|
// Walk the dominator tree from end to beginning, just once, treating SCC
|
||||||
|
// components as single blocks, duplicated calculated liveness information
|
||||||
|
// out to all of them.
|
||||||
|
po := postorder(f)
|
||||||
for {
|
for {
|
||||||
for _, b := range f.Blocks {
|
for _, b := range po {
|
||||||
f.Logf("live %s %v\n", b, live[b.ID])
|
f.Logf("live %s %v\n", b, live[b.ID])
|
||||||
}
|
}
|
||||||
changed := false
|
changed := false
|
||||||
|
|
||||||
for _, b := range f.Blocks {
|
for _, b := range po {
|
||||||
// Start with known live values at the end of the block
|
// Start with known live values at the end of the block
|
||||||
s.clear()
|
s.clear()
|
||||||
s.addAll(live[b.ID])
|
s.addAll(live[b.ID])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue