mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: optimize loads from abi.Type.{Size_,PtrBytes,Kind_}
With the previous CL in place, we can now pretty easily optimize a few
more loads from abi.Type. I've done Size_, PtrBytes, and Kind_, which
are easily calculated.
Among std/cmd, this rule fires a number of times:
75 abi.Type field Kind_
50 abi.PtrType field Elem
14 abi.Type field Hash
4 abi.Type field Size_
2 abi.Type field PtrBytes
The other ones that show up when compiling std/cmd are TFlag and GCData,
but these are not trivially calculated. Doing TFlag would probably be a
decent help given it's often used in things like switches where
statically knowing the kind could eliminate a bunch of dead code.
Change-Id: Ic7fd2113fa7479af914d06916edbca60cc71819f
Reviewed-on: https://go-review.googlesource.com/c/go/+/701298
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
b915e14490
commit
5b218461f9
2 changed files with 23 additions and 3 deletions
|
|
@ -414,6 +414,10 @@ var kinds = []abi.Kind{
|
||||||
types.TUNSAFEPTR: abi.UnsafePointer,
|
types.TUNSAFEPTR: abi.UnsafePointer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ABIKindOfType(t *types.Type) abi.Kind {
|
||||||
|
return kinds[t.Kind()]
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
memhashvarlen *obj.LSym
|
memhashvarlen *obj.LSym
|
||||||
memequalvarlen *obj.LSym
|
memequalvarlen *obj.LSym
|
||||||
|
|
@ -512,8 +516,7 @@ func dcommontype(c rttype.Cursor, t *types.Type) {
|
||||||
c.Field("Align_").WriteUint8(uint8(t.Alignment()))
|
c.Field("Align_").WriteUint8(uint8(t.Alignment()))
|
||||||
c.Field("FieldAlign_").WriteUint8(uint8(t.Alignment()))
|
c.Field("FieldAlign_").WriteUint8(uint8(t.Alignment()))
|
||||||
|
|
||||||
kind := kinds[t.Kind()]
|
c.Field("Kind_").WriteUint8(uint8(ABIKindOfType(t)))
|
||||||
c.Field("Kind_").WriteUint8(uint8(kind))
|
|
||||||
|
|
||||||
c.Field("Equal").WritePtr(eqfunc)
|
c.Field("Equal").WritePtr(eqfunc)
|
||||||
c.Field("GCData").WritePtr(gcsym)
|
c.Field("GCData").WritePtr(gcsym)
|
||||||
|
|
|
||||||
|
|
@ -2005,7 +2005,7 @@ func isFixedLoad(v *Value, sym Sym, off int64) bool {
|
||||||
for _, f := range rttype.Type.Fields() {
|
for _, f := range rttype.Type.Fields() {
|
||||||
if f.Offset == off && copyCompatibleType(v.Type, f.Type) {
|
if f.Offset == off && copyCompatibleType(v.Type, f.Type) {
|
||||||
switch f.Sym.Name {
|
switch f.Sym.Name {
|
||||||
case "Hash":
|
case "Size_", "PtrBytes", "Hash", "Kind_":
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
// fmt.Println("unknown field", f.Sym.Name)
|
// fmt.Println("unknown field", f.Sym.Name)
|
||||||
|
|
@ -2061,13 +2061,30 @@ func rewriteFixedLoad(v *Value, sym Sym, sb *Value, off int64) *Value {
|
||||||
|
|
||||||
t := (*lsym.Extra).(*obj.TypeInfo).Type.(*types.Type)
|
t := (*lsym.Extra).(*obj.TypeInfo).Type.(*types.Type)
|
||||||
|
|
||||||
|
ptrSizedOpConst := OpConst64
|
||||||
|
if f.Config.PtrSize == 4 {
|
||||||
|
ptrSizedOpConst = OpConst32
|
||||||
|
}
|
||||||
|
|
||||||
for _, f := range rttype.Type.Fields() {
|
for _, f := range rttype.Type.Fields() {
|
||||||
if f.Offset == off && copyCompatibleType(v.Type, f.Type) {
|
if f.Offset == off && copyCompatibleType(v.Type, f.Type) {
|
||||||
switch f.Sym.Name {
|
switch f.Sym.Name {
|
||||||
|
case "Size_":
|
||||||
|
v.reset(ptrSizedOpConst)
|
||||||
|
v.AuxInt = int64(t.Size())
|
||||||
|
return v
|
||||||
|
case "PtrBytes":
|
||||||
|
v.reset(ptrSizedOpConst)
|
||||||
|
v.AuxInt = int64(types.PtrDataSize(t))
|
||||||
|
return v
|
||||||
case "Hash":
|
case "Hash":
|
||||||
v.reset(OpConst32)
|
v.reset(OpConst32)
|
||||||
v.AuxInt = int64(types.TypeHash(t))
|
v.AuxInt = int64(types.TypeHash(t))
|
||||||
return v
|
return v
|
||||||
|
case "Kind_":
|
||||||
|
v.reset(OpConst8)
|
||||||
|
v.AuxInt = int64(reflectdata.ABIKindOfType(t))
|
||||||
|
return v
|
||||||
default:
|
default:
|
||||||
base.Fatalf("unknown field %s for fixedLoad of %s at offset %d", f.Sym.Name, lsym.Name, off)
|
base.Fatalf("unknown field %s for fixedLoad of %s at offset %d", f.Sym.Name, lsym.Name, off)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue