Commit 0b281872 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: rename ssa.Type's Elem method to ElemType

I would like to add a

    func (t *Type) Elem() *Type

method to package gc, but that would collide with the existing

    func (t *Type) Elem() ssa.Type

method needed to make *gc.Type implement ssa.Type.  Because the latter
is much less widely used right now than the former will be, this CL
renames it to ElemType.

Longer term, hopefully gc and ssa will share a common Type interface,
and ElemType can go away.

Change-Id: I270008515dc4c01ef531cf715637a924659c4735
Reviewed-on: https://go-review.googlesource.com/20546
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent e4571d33
...@@ -1953,7 +1953,7 @@ func (s *state) expr(n *Node) *ssa.Value { ...@@ -1953,7 +1953,7 @@ func (s *state) expr(n *Node) *ssa.Value {
for !data.Type.IsPtr() { for !data.Type.IsPtr() {
switch { switch {
case data.Type.IsArray(): case data.Type.IsArray():
data = s.newValue1I(ssa.OpArrayIndex, data.Type.Elem(), 0, data) data = s.newValue1I(ssa.OpArrayIndex, data.Type.ElemType(), 0, data)
case data.Type.IsStruct(): case data.Type.IsStruct():
for i := data.Type.NumFields() - 1; i >= 0; i-- { for i := data.Type.NumFields() - 1; i >= 0; i-- {
f := data.Type.FieldType(i) f := data.Type.FieldType(i)
......
...@@ -584,8 +584,12 @@ func (t *Type) IsInterface() bool { ...@@ -584,8 +584,12 @@ func (t *Type) IsInterface() bool {
return t.Etype == TINTER return t.Etype == TINTER
} }
func (t *Type) Elem() ssa.Type { func (t *Type) ElemType() ssa.Type {
switch t.Etype {
case TARRAY, TPTR32, TPTR64:
return t.Type return t.Type
}
panic(fmt.Sprintf("ElemType on invalid type %v", t))
} }
func (t *Type) PtrTo() ssa.Type { func (t *Type) PtrTo() ssa.Type {
return Ptrto(t) return Ptrto(t)
......
...@@ -88,7 +88,7 @@ func dse(f *Func) { ...@@ -88,7 +88,7 @@ func dse(f *Func) {
v.SetArgs1(v.Args[2]) v.SetArgs1(v.Args[2])
} else { } else {
// zero addr mem // zero addr mem
sz := v.Args[0].Type.Elem().Size() sz := v.Args[0].Type.ElemType().Size()
if v.AuxInt != sz { if v.AuxInt != sz {
f.Fatalf("mismatched zero/store sizes: %d and %d [%s]", f.Fatalf("mismatched zero/store sizes: %d and %d [%s]",
v.AuxInt, sz, v.LongString()) v.AuxInt, sz, v.LongString())
......
...@@ -417,8 +417,8 @@ ...@@ -417,8 +417,8 @@
// indexing operations // indexing operations
// Note: bounds check has already been done // Note: bounds check has already been done
(ArrayIndex <t> [0] (Load ptr mem)) -> @v.Args[0].Block (Load <t> ptr mem) (ArrayIndex <t> [0] (Load ptr mem)) -> @v.Args[0].Block (Load <t> ptr mem)
(PtrIndex <t> ptr idx) && config.PtrSize == 4 -> (AddPtr ptr (Mul32 <config.fe.TypeInt()> idx (Const32 <config.fe.TypeInt()> [t.Elem().Size()]))) (PtrIndex <t> ptr idx) && config.PtrSize == 4 -> (AddPtr ptr (Mul32 <config.fe.TypeInt()> idx (Const32 <config.fe.TypeInt()> [t.ElemType().Size()])))
(PtrIndex <t> ptr idx) && config.PtrSize == 8 -> (AddPtr ptr (Mul64 <config.fe.TypeInt()> idx (Const64 <config.fe.TypeInt()> [t.Elem().Size()]))) (PtrIndex <t> ptr idx) && config.PtrSize == 8 -> (AddPtr ptr (Mul64 <config.fe.TypeInt()> idx (Const64 <config.fe.TypeInt()> [t.ElemType().Size()])))
// struct operations // struct operations
(StructSelect (StructMake1 x)) -> x (StructSelect (StructMake1 x)) -> x
......
...@@ -5325,7 +5325,7 @@ func rewriteValuegeneric_OpPtrIndex(v *Value, config *Config) bool { ...@@ -5325,7 +5325,7 @@ func rewriteValuegeneric_OpPtrIndex(v *Value, config *Config) bool {
_ = b _ = b
// match: (PtrIndex <t> ptr idx) // match: (PtrIndex <t> ptr idx)
// cond: config.PtrSize == 4 // cond: config.PtrSize == 4
// result: (AddPtr ptr (Mul32 <config.fe.TypeInt()> idx (Const32 <config.fe.TypeInt()> [t.Elem().Size()]))) // result: (AddPtr ptr (Mul32 <config.fe.TypeInt()> idx (Const32 <config.fe.TypeInt()> [t.ElemType().Size()])))
for { for {
t := v.Type t := v.Type
ptr := v.Args[0] ptr := v.Args[0]
...@@ -5338,14 +5338,14 @@ func rewriteValuegeneric_OpPtrIndex(v *Value, config *Config) bool { ...@@ -5338,14 +5338,14 @@ func rewriteValuegeneric_OpPtrIndex(v *Value, config *Config) bool {
v0 := b.NewValue0(v.Line, OpMul32, config.fe.TypeInt()) v0 := b.NewValue0(v.Line, OpMul32, config.fe.TypeInt())
v0.AddArg(idx) v0.AddArg(idx)
v1 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt()) v1 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
v1.AuxInt = t.Elem().Size() v1.AuxInt = t.ElemType().Size()
v0.AddArg(v1) v0.AddArg(v1)
v.AddArg(v0) v.AddArg(v0)
return true return true
} }
// match: (PtrIndex <t> ptr idx) // match: (PtrIndex <t> ptr idx)
// cond: config.PtrSize == 8 // cond: config.PtrSize == 8
// result: (AddPtr ptr (Mul64 <config.fe.TypeInt()> idx (Const64 <config.fe.TypeInt()> [t.Elem().Size()]))) // result: (AddPtr ptr (Mul64 <config.fe.TypeInt()> idx (Const64 <config.fe.TypeInt()> [t.ElemType().Size()])))
for { for {
t := v.Type t := v.Type
ptr := v.Args[0] ptr := v.Args[0]
...@@ -5358,7 +5358,7 @@ func rewriteValuegeneric_OpPtrIndex(v *Value, config *Config) bool { ...@@ -5358,7 +5358,7 @@ func rewriteValuegeneric_OpPtrIndex(v *Value, config *Config) bool {
v0 := b.NewValue0(v.Line, OpMul64, config.fe.TypeInt()) v0 := b.NewValue0(v.Line, OpMul64, config.fe.TypeInt())
v0.AddArg(idx) v0.AddArg(idx)
v1 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt()) v1 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
v1.AuxInt = t.Elem().Size() v1.AuxInt = t.ElemType().Size()
v0.AddArg(v1) v0.AddArg(v1)
v.AddArg(v0) v.AddArg(v0)
return true return true
......
...@@ -28,7 +28,7 @@ type Type interface { ...@@ -28,7 +28,7 @@ type Type interface {
IsFlags() bool IsFlags() bool
IsVoid() bool IsVoid() bool
Elem() Type // given []T or *T or [n]T, return T ElemType() Type // given []T or *T or [n]T, return T
PtrTo() Type // given T, return *T PtrTo() Type // given T, return *T
NumFields() int64 // # of fields of a struct NumFields() int64 // # of fields of a struct
...@@ -71,7 +71,7 @@ func (t *CompilerType) IsFlags() bool { return t.Flags } ...@@ -71,7 +71,7 @@ func (t *CompilerType) IsFlags() bool { return t.Flags }
func (t *CompilerType) IsVoid() bool { return t.Void } func (t *CompilerType) IsVoid() bool { return t.Void }
func (t *CompilerType) String() string { return t.Name } func (t *CompilerType) String() string { return t.Name }
func (t *CompilerType) SimpleString() string { return t.Name } func (t *CompilerType) SimpleString() string { return t.Name }
func (t *CompilerType) Elem() Type { panic("not implemented") } func (t *CompilerType) ElemType() Type { panic("not implemented") }
func (t *CompilerType) PtrTo() Type { panic("not implemented") } func (t *CompilerType) PtrTo() Type { panic("not implemented") }
func (t *CompilerType) NumFields() int64 { panic("not implemented") } func (t *CompilerType) NumFields() int64 { panic("not implemented") }
func (t *CompilerType) FieldType(i int64) Type { panic("not implemented") } func (t *CompilerType) FieldType(i int64) Type { panic("not implemented") }
......
...@@ -42,7 +42,7 @@ func (t *TypeImpl) IsFlags() bool { return false } ...@@ -42,7 +42,7 @@ func (t *TypeImpl) IsFlags() bool { return false }
func (t *TypeImpl) IsVoid() bool { return false } func (t *TypeImpl) IsVoid() bool { return false }
func (t *TypeImpl) String() string { return t.Name } func (t *TypeImpl) String() string { return t.Name }
func (t *TypeImpl) SimpleString() string { return t.Name } func (t *TypeImpl) SimpleString() string { return t.Name }
func (t *TypeImpl) Elem() Type { return t.Elem_ } func (t *TypeImpl) ElemType() Type { return t.Elem_ }
func (t *TypeImpl) PtrTo() Type { panic("not implemented") } func (t *TypeImpl) PtrTo() Type { panic("not implemented") }
func (t *TypeImpl) NumFields() int64 { panic("not implemented") } func (t *TypeImpl) NumFields() int64 { panic("not implemented") }
func (t *TypeImpl) FieldType(i int64) Type { panic("not implemented") } func (t *TypeImpl) FieldType(i int64) Type { panic("not implemented") }
......
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