From 94d1589bd2960950bab9e94cdb5db8a5f7ed084d Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 11 Jun 2014 13:19:52 -0400 Subject: [PATCH] go.tools/go/pointer: fix objectNode() bug causing it to return nil spuriously. It was making the unsound assumption that cgn==nil => v is one of {Global,Function,Const,Capture} to avoid checking v's type, which is what it now does. This caused more expensive constraints to be generated, which is suboptimal though not wrong exactly. In one benchmark, this change reduces the number of complex constraints by about 23% of loads and 53% of stores, and increases the number of (simple) copy constraints by about 5%. LGTM=crawshaw R=crawshaw CC=golang-codereviews https://golang.org/cl/106940043 --- go/pointer/gen.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/go/pointer/gen.go b/go/pointer/gen.go index 69eda20a..9d8e2c15 100644 --- a/go/pointer/gen.go +++ b/go/pointer/gen.go @@ -808,7 +808,8 @@ func (a *analysis) genCall(caller *cgnode, instr ssa.CallInstruction) { // down the SSA value graph, e.g IndexAddr(FieldAddr(Alloc))). // func (a *analysis) objectNode(cgn *cgnode, v ssa.Value) nodeid { - if cgn == nil { + switch v.(type) { + case *ssa.Global, *ssa.Function, *ssa.Const, *ssa.Capture: // Global object. obj, ok := a.globalobj[v] if !ok { @@ -822,11 +823,10 @@ func (a *analysis) objectNode(cgn *cgnode, v ssa.Value) nodeid { obj = a.makeFunctionObject(v, nil) case *ssa.Const: - // The only pointer-like Consts are nil. + // not addressable case *ssa.Capture: - // For now, Captures have the same cardinality as globals. - // TODO(adonovan): treat captures context-sensitively. + // not addressable } if a.log != nil { @@ -1178,9 +1178,11 @@ func (a *analysis) genFunc(cgn *cgnode) { params += nodeid(a.sizeof(p.Type())) } - // Free variables are treated like global variables: + // Free variables have global cardinality: // the outer function sets them with MakeClosure; // the inner function accesses them with Capture. + // + // TODO(adonovan): treat captures context-sensitively. // Create value nodes for all value instructions // since SSA may contain forward references.