]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: rename ssa.Type's Elem method to ElemType
authorMatthew Dempsky <mdempsky@google.com>
Thu, 10 Mar 2016 22:35:39 +0000 (14:35 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 10 Mar 2016 23:02:33 +0000 (23:02 +0000)
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: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/type.go
src/cmd/compile/internal/ssa/deadstore.go
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go
src/cmd/compile/internal/ssa/type.go
src/cmd/compile/internal/ssa/type_test.go

index 557564daa47d8d60c54cd71903035676ca3aeb3c..afba7db6381c5917ca355aed51d6a5068a62bd5a 100644 (file)
@@ -1953,7 +1953,7 @@ func (s *state) expr(n *Node) *ssa.Value {
                for !data.Type.IsPtr() {
                        switch {
                        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():
                                for i := data.Type.NumFields() - 1; i >= 0; i-- {
                                        f := data.Type.FieldType(i)
index 8ba625dc860f5415f905ad8a88d56daa3067665e..ec06407ecf937515fb4c8eaeee3d6ce583446bea 100644 (file)
@@ -584,8 +584,12 @@ func (t *Type) IsInterface() bool {
        return t.Etype == TINTER
 }
 
-func (t *Type) Elem() ssa.Type {
-       return t.Type
+func (t *Type) ElemType() ssa.Type {
+       switch t.Etype {
+       case TARRAY, TPTR32, TPTR64:
+               return t.Type
+       }
+       panic(fmt.Sprintf("ElemType on invalid type %v", t))
 }
 func (t *Type) PtrTo() ssa.Type {
        return Ptrto(t)
index 20e8368cd53257fdcf58c0ea7ba17f85ad503f99..5129c171bbf2506ce19befad99ab9a1bdc05ed3e 100644 (file)
@@ -88,7 +88,7 @@ func dse(f *Func) {
                                        v.SetArgs1(v.Args[2])
                                } else {
                                        // zero addr mem
-                                       sz := v.Args[0].Type.Elem().Size()
+                                       sz := v.Args[0].Type.ElemType().Size()
                                        if v.AuxInt != sz {
                                                f.Fatalf("mismatched zero/store sizes: %d and %d [%s]",
                                                        v.AuxInt, sz, v.LongString())
index d99ea5b66e71bc489e98d37a6b14d3c707160781..542c50254af77f0e4dc6096e0a613426e93c6818 100644 (file)
 // indexing operations
 // Note: bounds check has already been done
 (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 == 8 -> (AddPtr ptr (Mul64 <config.fe.TypeInt()> idx (Const64 <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.ElemType().Size()])))
 
 // struct operations
 (StructSelect (StructMake1 x)) -> x
index 95a2caeb1e221eab5edefa9b2e9b245bb2f3a931..331c93d1cfbb2e8999ac66f69da4bba6bf3ba75d 100644 (file)
@@ -5325,7 +5325,7 @@ func rewriteValuegeneric_OpPtrIndex(v *Value, config *Config) bool {
        _ = b
        // match: (PtrIndex <t> ptr idx)
        // 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 {
                t := v.Type
                ptr := v.Args[0]
@@ -5338,14 +5338,14 @@ func rewriteValuegeneric_OpPtrIndex(v *Value, config *Config) bool {
                v0 := b.NewValue0(v.Line, OpMul32, config.fe.TypeInt())
                v0.AddArg(idx)
                v1 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
-               v1.AuxInt = t.Elem().Size()
+               v1.AuxInt = t.ElemType().Size()
                v0.AddArg(v1)
                v.AddArg(v0)
                return true
        }
        // match: (PtrIndex <t> ptr idx)
        // 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 {
                t := v.Type
                ptr := v.Args[0]
@@ -5358,7 +5358,7 @@ func rewriteValuegeneric_OpPtrIndex(v *Value, config *Config) bool {
                v0 := b.NewValue0(v.Line, OpMul64, config.fe.TypeInt())
                v0.AddArg(idx)
                v1 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
-               v1.AuxInt = t.Elem().Size()
+               v1.AuxInt = t.ElemType().Size()
                v0.AddArg(v1)
                v.AddArg(v0)
                return true
index c0174cce4fd916a41b6e648e1a5c5095e1b334b1..427fb011b87bdb124e4acd86fadf49d079dc2c59 100644 (file)
@@ -28,8 +28,8 @@ type Type interface {
        IsFlags() bool
        IsVoid() bool
 
-       Elem() Type  // given []T or *T or [n]T, return T
-       PtrTo() Type // given T, return *T
+       ElemType() Type // given []T or *T or [n]T, return T
+       PtrTo() Type    // given T, return *T
 
        NumFields() int64       // # of fields of a struct
        FieldType(i int64) Type // type of ith field of the struct
@@ -71,7 +71,7 @@ func (t *CompilerType) IsFlags() bool          { return t.Flags }
 func (t *CompilerType) IsVoid() bool           { return t.Void }
 func (t *CompilerType) String() 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) NumFields() int64       { panic("not implemented") }
 func (t *CompilerType) FieldType(i int64) Type { panic("not implemented") }
index 26c8223c6219127e92cde7200fd63f12934c8936..048eda5d6696f016a29fbc32b72bf0ba65dae1c9 100644 (file)
@@ -42,7 +42,7 @@ func (t *TypeImpl) IsFlags() bool          { return false }
 func (t *TypeImpl) IsVoid() bool           { return false }
 func (t *TypeImpl) String() 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) NumFields() int64       { panic("not implemented") }
 func (t *TypeImpl) FieldType(i int64) Type { panic("not implemented") }