1
0
mirror of https://github.com/golang/go synced 2024-10-05 22:21:23 -06:00

[dev.ssa] cmd/compile: don't alloc new CSE classes

This reduces the time to compile
test/slice3.go on my laptop from ~12s to ~3.8s.
It reduces the max memory use from ~4.8gb to
~450mb.

This is still considerably worse than tip,
at 1s and 300mb respectively, but it's
getting closer.

Hopefully this will fix the build at long last.

Change-Id: Iac26b52023f408438cba3ea1b81dcd82ca402b90
Reviewed-on: https://go-review.googlesource.com/12566
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2015-07-22 21:21:50 -07:00
parent 317226e61c
commit 851ceebceb

View File

@ -85,18 +85,22 @@ func cse(f *Func) {
e := partition[i] e := partition[i]
v := e[0] v := e[0]
// all values in this equiv class that are not equivalent to v get moved // all values in this equiv class that are not equivalent to v get moved
// into another equiv class q. // into another equiv class.
var q eqclass // To avoid allocating while building that equivalence class,
// move the values equivalent to v to the beginning of e,
// other values to the end of e, and track where the split is.
allvals := e
split := len(e)
eqloop: eqloop:
for j := 1; j < len(e); { for j := 1; j < len(e); {
w := e[j] w := e[j]
for i := 0; i < len(v.Args); i++ { for i := 0; i < len(v.Args); i++ {
if valueEqClass[v.Args[i].ID] != valueEqClass[w.Args[i].ID] || !v.Type.Equal(w.Type) { if valueEqClass[v.Args[i].ID] != valueEqClass[w.Args[i].ID] || !v.Type.Equal(w.Type) {
// w is not equivalent to v. // w is not equivalent to v.
// remove w from e // move it to the end, shrink e, and move the split.
e, e[j] = e[:len(e)-1], e[len(e)-1] e[j], e[len(e)-1] = e[len(e)-1], e[j]
// add w to q e = e[:len(e)-1]
q = append(q, w) split--
valueEqClass[w.ID] = len(partition) valueEqClass[w.ID] = len(partition)
changed = true changed = true
continue eqloop continue eqloop
@ -106,8 +110,8 @@ func cse(f *Func) {
j++ j++
} }
partition[i] = e partition[i] = e
if q != nil { if split < len(allvals) {
partition = append(partition, q) partition = append(partition, allvals[split:])
} }
} }