mirror of
https://github.com/golang/go
synced 2024-11-18 16:14:46 -07:00
cmd/compile: generalize isfat to handle 1-field structs and 1-element arrays
After CL 192979, it is safe now to optimize isfat slightly to handle 1-field structs and 1-element arrays. Change-Id: Ie3bc30299abbcef36eee7a0681997cc2f88ed6a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/192980 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
55c0ad4b62
commit
3f0437e175
@ -304,7 +304,7 @@ func (lv *Liveness) valueEffects(v *ssa.Value) (int32, liveEffect) {
|
||||
var effect liveEffect
|
||||
// Read is a read, obviously.
|
||||
//
|
||||
// Addr is a read also, as any subseqent holder of the pointer must be able
|
||||
// Addr is a read also, as any subsequent holder of the pointer must be able
|
||||
// to see all the values (including initialization) written so far.
|
||||
// This also prevents a variable from "coming back from the dead" and presenting
|
||||
// stale pointers to the garbage collector. See issue 28445.
|
||||
@ -1450,12 +1450,25 @@ func liveness(e *ssafn, f *ssa.Func, pp *Progs) LivenessMap {
|
||||
return lv.livenessMap
|
||||
}
|
||||
|
||||
// TODO(cuonglm,mdempsky): Revisit after #24416 is fixed.
|
||||
func isfat(t *types.Type) bool {
|
||||
if t != nil {
|
||||
switch t.Etype {
|
||||
case TSTRUCT, TARRAY, TSLICE, TSTRING,
|
||||
case TSLICE, TSTRING,
|
||||
TINTER: // maybe remove later
|
||||
return true
|
||||
case TARRAY:
|
||||
// Array of 1 element, check if element is fat
|
||||
if t.NumElem() == 1 {
|
||||
return isfat(t.Elem())
|
||||
}
|
||||
return true
|
||||
case TSTRUCT:
|
||||
// Struct with 1 field, check if field is fat
|
||||
if t.NumFields() == 1 {
|
||||
return isfat(t.Field(0).Type)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user