aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/check.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2016-03-15 20:45:50 -0700
committerKeith Randall <khr@golang.org>2016-03-17 04:20:02 +0000
commit56e0ecc5ea67c4cd71fe894bf9745f35273bcdea (patch)
tree86f6d69a512df3dcaa912b7ffc7840c663578687 /src/cmd/compile/internal/ssa/check.go
parentcb1f2afc99f844be5f78b701adbe0b7b75259a4c (diff)
downloadgo-56e0ecc5ea67c4cd71fe894bf9745f35273bcdea.tar.gz
go-56e0ecc5ea67c4cd71fe894bf9745f35273bcdea.zip
cmd/compile: keep value use counts in SSA
Keep track of how many uses each Value has. Each appearance in Value.Args and in Block.Control counts once. The number of uses of a value is generically useful to constrain rewrite rules. For instance, we might want to prevent merging index operations into loads if the same index expression is used lots of times. But I have one use in particular for which the use count is required. We must make sure we don't combine ops with loads if the load has more than one use. Otherwise, we may split a single load into multiple loads and that breaks perceived behavior in the presence of races. In particular, the load of m.state in sync/mutex.go:Lock can't be done twice. (I have a separate CL which triggers the mutex failure. This CL has a test which demonstrates a similar failure.) Change-Id: Icaafa479239f48632a069d0c3f624e6ebc6b1f0e Reviewed-on: https://go-review.googlesource.com/20790 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Todd Neal <todd@tneal.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/check.go')
-rw-r--r--src/cmd/compile/internal/ssa/check.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/check.go b/src/cmd/compile/internal/ssa/check.go
index 8f8227722c..85cc3eadf4 100644
--- a/src/cmd/compile/internal/ssa/check.go
+++ b/src/cmd/compile/internal/ssa/check.go
@@ -294,6 +294,26 @@ func checkFunc(f *Func) {
}
}
}
+
+ // Check use counts
+ uses := make([]int32, f.NumValues())
+ for _, b := range f.Blocks {
+ for _, v := range b.Values {
+ for _, a := range v.Args {
+ uses[a.ID]++
+ }
+ }
+ if b.Control != nil {
+ uses[b.Control.ID]++
+ }
+ }
+ for _, b := range f.Blocks {
+ for _, v := range b.Values {
+ if v.Uses != uses[v.ID] {
+ f.Fatalf("%s has %d uses, but has Uses=%d", v, uses[v.ID], v.Uses)
+ }
+ }
+ }
}
// domCheck reports whether x dominates y (including x==y).