cmd/compile: optimize abi.Type.GCData loads

This fires in just one place; stkframe.go's stkobjinit. But, it does
make the struct literal entirely constants.

Change-Id: Ice76cb3cddd97adee011fdaab40597839da2e89f
Reviewed-on: https://go-review.googlesource.com/c/go/+/701300
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
This commit is contained in:
Jake Bailey 2025-09-05 14:47:31 -07:00 committed by Gopher Robot
parent dc960d0bfe
commit f1fd13016a
3 changed files with 10 additions and 4 deletions

View file

@ -1493,7 +1493,7 @@ func (lv *Liveness) emitStackObjects() *obj.LSym {
if sz != int64(int32(sz)) {
base.Fatalf("stack object too big: %v of type %v, size %d", v, t, sz)
}
lsym, ptrBytes := reflectdata.GCSym(t)
lsym, ptrBytes := reflectdata.GCSym(t, false)
off = objw.Uint32(x, off, uint32(sz))
off = objw.Uint32(x, off, uint32(ptrBytes))
off = objw.SymPtrOff(x, off, lsym)

View file

@ -1229,7 +1229,7 @@ func typesStrCmp(a, b typeAndStr) int {
// GC information is always a bitmask, never a gc program.
// GCSym may be called in concurrent backend, so it does not emit the symbol
// content.
func GCSym(t *types.Type) (lsym *obj.LSym, ptrdata int64) {
func GCSym(t *types.Type, onDemandAllowed bool) (lsym *obj.LSym, ptrdata int64) {
// Record that we need to emit the GC symbol.
gcsymmu.Lock()
if _, ok := gcsymset[t]; !ok {
@ -1237,7 +1237,7 @@ func GCSym(t *types.Type) (lsym *obj.LSym, ptrdata int64) {
}
gcsymmu.Unlock()
lsym, _, ptrdata = dgcsym(t, false, false)
lsym, _, ptrdata = dgcsym(t, false, onDemandAllowed)
return
}

View file

@ -2067,7 +2067,7 @@ func isFixedLoad(v *Value, sym Sym, off int64) bool {
for _, f := range rttype.Type.Fields() {
if f.Offset == off && copyCompatibleType(v.Type, f.Type) {
switch f.Sym.Name {
case "Size_", "PtrBytes", "Hash", "Kind_":
case "Size_", "PtrBytes", "Hash", "Kind_", "GCData":
return true
default:
// fmt.Println("unknown field", f.Sym.Name)
@ -2147,6 +2147,12 @@ func rewriteFixedLoad(v *Value, sym Sym, sb *Value, off int64) *Value {
v.reset(OpConst8)
v.AuxInt = int64(reflectdata.ABIKindOfType(t))
return v
case "GCData":
gcdata, _ := reflectdata.GCSym(t, true)
v.reset(OpAddr)
v.Aux = symToAux(gcdata)
v.AddArg(sb)
return v
default:
base.Fatalf("unknown field %s for fixedLoad of %s at offset %d", f.Sym.Name, lsym.Name, off)
}