[dev.link] cmd/compile: make read-only static temps content-addressable

For now, we only do this for symbols without relocations.

Mark static temps "local", as they are not referenced across DSO
boundaries. And deduplicating a local symbol and a non-local
symbol can be problematic.

Change-Id: I0a3dc4138aaeea7fd4f326998f32ab6305da8e4b
Reviewed-on: https://go-review.googlesource.com/c/go/+/243141
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
Cherry Zhang 2020-07-15 20:01:32 -04:00
parent 3dabaa44e8
commit 289c238a33
5 changed files with 22 additions and 18 deletions

View file

@ -356,14 +356,22 @@ func (c initContext) String() string {
var statuniqgen int // name generator for static temps
// staticname returns a name backed by a static data symbol.
// Callers should call n.MarkReadonly on the
// returned node for readonly nodes.
// staticname returns a name backed by a (writable) static data symbol.
// Use readonlystaticname for read-only node.
func staticname(t *types.Type) *Node {
// Don't use lookupN; it interns the resulting string, but these are all unique.
n := newname(lookup(fmt.Sprintf("%s%d", obj.StaticNamePref, statuniqgen)))
statuniqgen++
addvar(n, t, PEXTERN)
n.Sym.Linksym().Set(obj.AttrLocal, true)
return n
}
// readonlystaticname returns a name backed by a (writable) static data symbol.
func readonlystaticname(t *types.Type) *Node {
n := staticname(t)
n.MarkReadonly()
n.Sym.Linksym().Set(obj.AttrContentAddressable, true)
return n
}
@ -627,9 +635,10 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
mode := getdyn(n, true)
if mode&initConst != 0 && !isSmallSliceLit(n) {
vstat = staticname(t)
if ctxt == inInitFunction {
vstat.MarkReadonly()
vstat = readonlystaticname(t)
} else {
vstat = staticname(t)
}
fixedlit(ctxt, initKindStatic, n, vstat, init)
}
@ -773,10 +782,8 @@ func maplit(n *Node, m *Node, init *Nodes) {
dowidth(te)
// make and initialize static arrays
vstatk := staticname(tk)
vstatk.MarkReadonly()
vstate := staticname(te)
vstate.MarkReadonly()
vstatk := readonlystaticname(tk)
vstate := readonlystaticname(te)
datak := nod(OARRAYLIT, nil, nil)
datae := nod(OARRAYLIT, nil, nil)
@ -897,8 +904,7 @@ func anylit(n *Node, var_ *Node, init *Nodes) {
if var_.isSimpleName() && n.List.Len() > 4 {
// lay out static data
vstat := staticname(t)
vstat.MarkReadonly()
vstat := readonlystaticname(t)
ctxt := inInitFunction
if n.Op == OARRAYLIT {