1
0
mirror of https://github.com/golang/go synced 2024-11-18 20:14:43 -07:00
go/pointer
Alan Donovan 5b55a71008 go.tools/pointer: strength reduction during constraint generation.
Motivation: simple constraints---copy and addr---are more
amenable to pre-solver optimizations (forthcoming) than
complex constraints: load, store, and all others.

In code such as the following:

         t0 = new struct { x, y int }
         t1 = &t0.y
         t2 = *t1

there's no need for the full generality of a (complex)
load constraint for t2=*t1 since t1 can only point to t0.y.
All we need is a (simple) copy constraint t2 = (t0.y)
where (t0.y) is the object node label for that field.

For all "addressable" SSA instructions, we tabulate
whether their points-to set is necessarily a singleton.  For
some (e.g. Alloc, MakeSlice, etc) this is always true by
design.  For others (e.g. FieldAddr) it depends on their
operands.

We exploit this information when generating constraints:
all load-form and store-form constraints are reduced to copy
constraints if the pointer's PTS is a singleton.
Similarly all FieldAddr (y=&x.f) and IndexAddr (y=&x[0])
constraints are reduced to offset addition, for singleton
operands.

Here's the constraint mix when running on the oracle itself.
The total number of constraints is unchanged but the fraction
that are complex has gone down to 21% from 53%.

                before    after
--simple--
 addr		20682     46949
 copy        	61454     91211
--complex--
 offsetAddr  	41621     15325
 load        	18769     12925
 store       	30758     6908
 invoke      	758       760
 typeAssert  	1688      1689
total           175832    175869

Also:
- Add Pointer.Context() for local variables,
  since we now plumb cgnodes throughout. Nice.
- Refactor all load-form (load, receive, lookup) and
  store-form (Store, send, MapUpdate) constraints to use
  genLoad and genStore.
- Log counts of constraints by type.
- valNodes split into localval and globalval maps;
  localval is purged after each function.
- analogous maps localobj[v] and globalobj[v] hold sole label
  for pts(v), if singleton.
- fnObj map subsumed by globalobj.
- make{Function/Global/Constant} inlined into objectValue.
  Much cleaner.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13979043
2013-09-27 11:33:01 -04:00
..
testdata go.tools/pointer: reflect, part 2: channels. 2013-09-23 16:13:01 -04:00
analysis.go go.tools/pointer: strength reduction during constraint generation. 2013-09-27 11:33:01 -04:00
api.go go.tools/pointer: strength reduction during constraint generation. 2013-09-27 11:33:01 -04:00
callgraph.go go.tool.pointer: fix regression in pointer.cgraph.Root(). 2013-09-26 09:31:39 -04:00
doc.go go.tools/pointer: reflect, part 2: channels. 2013-09-23 16:13:01 -04:00
example_test.go go.tools/pointer: use new callgraph API. 2013-09-25 17:17:42 -04:00
gen.go go.tools/pointer: strength reduction during constraint generation. 2013-09-27 11:33:01 -04:00
intrinsics.go go.tools/pointer: reflect, part 2: channels. 2013-09-23 16:13:01 -04:00
labels.go go.tools/pointer: use new callgraph API. 2013-09-25 17:17:42 -04:00
pointer_test.go go.tools/pointer: use new callgraph API. 2013-09-25 17:17:42 -04:00
print.go go.tools: add copyright messages to source files. 2013-08-27 18:49:13 -04:00
reflect.go go.tools/pointer: strength reduction during constraint generation. 2013-09-27 11:33:01 -04:00
solve.go go.tools/pointer: strength reduction during constraint generation. 2013-09-27 11:33:01 -04:00
TODO go.tools/pointer: use new callgraph API. 2013-09-25 17:17:42 -04:00
util.go go.tools/pointer: reflect, part 2: channels. 2013-09-23 16:13:01 -04:00