cmd/compile: cache CFG-dependent computations

We compute a lot of stuff based off the CFG: postorder traversal,
dominators, dominator tree, loop nest.  Multiple phases use this
information and we end up recomputing some of it.  Add a cache
for this information so if the CFG hasn't changed, we can reuse
the previous computation.

Change-Id: I9b5b58af06830bd120afbee9cfab395a0a2f74b2
Reviewed-on: https://go-review.googlesource.com/29356
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Keith Randall 2016-09-16 13:50:18 -07:00
parent 2679282da4
commit 75ce89c20d
18 changed files with 83 additions and 59 deletions

View file

@ -463,13 +463,15 @@ func prove(f *Func) {
})
ft := newFactsTable()
idom := f.idom()
sdom := f.sdom()
// DFS on the dominator tree.
for len(work) > 0 {
node := work[len(work)-1]
work = work[:len(work)-1]
parent := f.idom[node.block.ID]
branch := getBranch(f.sdom, parent, node.block)
parent := idom[node.block.ID]
branch := getBranch(sdom, parent, node.block)
switch node.state {
case descend:
@ -488,7 +490,7 @@ func prove(f *Func) {
block: node.block,
state: simplify,
})
for s := f.sdom.Child(node.block); s != nil; s = f.sdom.Sibling(s) {
for s := sdom.Child(node.block); s != nil; s = sdom.Sibling(s) {
work = append(work, bp{
block: s,
state: descend,