Commit e82c925f authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: remove Type haspointers caches

Even very large Types are not very big.
The haspointer cache looks like premature optimization.
Removing them has no detectable compiler performance impact,
and it removes mutable shared state used by the backend.

Updates #15756

Change-Id: I2d2cf03f470f5eef5bcd50ff693ef6a01d481700
Reviewed-on: https://go-review.googlesource.com/38912
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent e8616843
......@@ -11,11 +11,17 @@ import (
)
func typeWithoutPointers() *Type {
return &Type{Etype: TSTRUCT, Extra: &StructType{Haspointers: 1}} // haspointers -> false
t := typ(TSTRUCT)
f := &Field{Type: typ(TINT)}
t.SetFields([]*Field{f})
return t
}
func typeWithPointers() *Type {
return &Type{Etype: TSTRUCT, Extra: &StructType{Haspointers: 2}} // haspointers -> true
t := typ(TSTRUCT)
f := &Field{Type: typ(TPTR64)}
t.SetFields([]*Field{f})
return t
}
// Test all code paths for cmpstackvarlt.
......
......@@ -34,7 +34,7 @@ func TestSizeof(t *testing.T) {
{StructType{}, 12, 24},
{InterType{}, 4, 8},
{ChanType{}, 8, 16},
{ArrayType{}, 16, 24},
{ArrayType{}, 12, 16},
{InterMethType{}, 4, 8},
{DDDFieldType{}, 4, 8},
{FuncArgsType{}, 4, 8},
......
......@@ -245,8 +245,7 @@ type StructType struct {
// Map links such structs back to their map type.
Map *Type
Funarg Funarg // type of function arguments for arg struct
Haspointers uint8 // 0 unknown, 1 no, 2 yes
Funarg Funarg // type of function arguments for arg struct
}
// Fnstruct records the kind of function argument
......@@ -304,9 +303,8 @@ func (t *Type) ChanType() *ChanType {
// ArrayType contains Type fields specific to array types.
type ArrayType struct {
Elem *Type // element type
Bound int64 // number of elements; <0 if unknown yet
Haspointers uint8 // 0 unknown, 1 no, 2 yes
Elem *Type // element type
Bound int64 // number of elements; <0 if unknown yet
}
// SliceType contains Type fields specific to slice types.
......@@ -1315,38 +1313,19 @@ func haspointers(t *Type) bool {
TUINT64, TUINTPTR, TFLOAT32, TFLOAT64, TCOMPLEX64, TCOMPLEX128, TBOOL:
return false
case TSLICE:
return true
case TARRAY:
at := t.Extra.(*ArrayType)
if at.Haspointers != 0 {
return at.Haspointers-1 != 0
}
ret := false
if t.NumElem() != 0 { // non-empty array
ret = haspointers(t.Elem())
if t.NumElem() == 0 { // empty array has no pointers
return false
}
at.Haspointers = 1 + uint8(obj.Bool2int(ret))
return ret
return haspointers(t.Elem())
case TSTRUCT:
st := t.StructType()
if st.Haspointers != 0 {
return st.Haspointers-1 != 0
}
ret := false
for _, t1 := range t.Fields().Slice() {
if haspointers(t1.Type) {
ret = true
break
return true
}
}
st.Haspointers = 1 + uint8(obj.Bool2int(ret))
return ret
return false
}
return true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment