]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/ssa: use Compare instead of Equal
authorJosh Bleecher Snyder <josharian@gmail.com>
Sun, 3 Apr 2016 21:44:29 +0000 (14:44 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sun, 17 Apr 2016 04:50:45 +0000 (04:50 +0000)
They have different semantics.

Equal is stricter and is designed for the front-end.
Compare is looser and cheaper and is designed for the back-end.
To avoid possible regression, remove Equal from ssa.Type.

Updates #15043

Change-Id: Ie23ce75ff6b4d01b7982e0a89e6f81b5d099d8d6
Reviewed-on: https://go-review.googlesource.com/21483
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>

src/cmd/compile/internal/gc/type.go
src/cmd/compile/internal/ssa/TODO
src/cmd/compile/internal/ssa/cse.go
src/cmd/compile/internal/ssa/func.go
src/cmd/compile/internal/ssa/stackalloc.go
src/cmd/compile/internal/ssa/type.go

index a44a85bed8bcb52f3c77e709207dd859837fc3f3..855b070af6f754852b1eedc8ae839b915bc19651 100644 (file)
@@ -863,19 +863,12 @@ func (t *Type) SimpleString() string {
        return Econv(t.Etype)
 }
 
-func (t *Type) Equal(u ssa.Type) bool {
-       x, ok := u.(*Type)
-       return ok && Eqtype(t, x)
-}
-
 // Compare compares types for purposes of the SSA back
 // end, returning an ssa.Cmp (one of CMPlt, CMPeq, CMPgt).
 // The answers are correct for an optimizer
-// or code generator, but not for Go source.
-// For example, "type gcDrainFlags int" results in
-// two Go-different types that Compare equal.
-// The order chosen is also arbitrary, only division into
-// equivalence classes (Types that compare CMPeq) matters.
+// or code generator, but not necessarily typechecking.
+// The order chosen is arbitrary, only consistency and division
+// into equivalence classes (Types that compare CMPeq) matters.
 func (t *Type) Compare(u ssa.Type) ssa.Cmp {
        x, ok := u.(*Type)
        // ssa.CompilerType is smaller than gc.Type
index e081856bd3973a53dd8c728e73893d346f9be965..dad4880994ba31d7c9c2bcddbc4fd0af4007b4ff 100644 (file)
@@ -41,8 +41,6 @@ Future/other
 ------------
 - Start another architecture (arm?)
 - 64-bit ops on 32-bit machines
-- Investigate type equality. During SSA generation, should we use n.Type or (say) TypeBool?
 - Should we get rid of named types in favor of underlying types during SSA generation?
-- Should we introduce a new type equality routine that is less strict than the frontend's?
 - Infrastructure for enabling/disabling/configuring passes
 - Modify logging for at least pass=1, to be Warnl compatible
index e3f1a1d07d53307f3e5823b4571b0a7af8f173c0..d501f75e02ac2d63716a7e8c6bd5c3551d348429 100644 (file)
@@ -108,7 +108,7 @@ func cse(f *Func) {
                                                break
                                        }
                                }
-                               if !equivalent || !v.Type.Equal(w.Type) {
+                               if !equivalent || v.Type.Compare(w.Type) != CMPeq {
                                        // w is not equivalent to v.
                                        // move it to the end and shrink e.
                                        e[j], e[len(e)-1] = e[len(e)-1], e[j]
index da44f26106e1d8a6ef168c91b74088d88aae4079..11ff8d37928d7a4ef2d25b8fa472d4de6bed4d4a 100644 (file)
@@ -318,7 +318,7 @@ func (f *Func) constVal(line int32, op Op, t Type, c int64, setAux bool) *Value
        }
        vv := f.constants[c]
        for _, v := range vv {
-               if v.Op == op && v.Type.Equal(t) {
+               if v.Op == op && v.Type.Compare(t) == CMPeq {
                        if setAux && v.AuxInt != c {
                                panic(fmt.Sprintf("cached const %s should have AuxInt of %d", v.LongString(), c))
                        }
index e3ef66ab1ba1ef4b3ea77d5b5a7f4624972027d8..44f4096cb24f96f6854ba69b71f4c7bf48d6c909 100644 (file)
@@ -201,7 +201,7 @@ func (s *stackAllocState) stackalloc() {
                        } else {
                                name = names[v.ID]
                        }
-                       if name.N != nil && v.Type.Equal(name.Type) {
+                       if name.N != nil && v.Type.Compare(name.Type) == CMPeq {
                                for _, id := range s.interfere[v.ID] {
                                        h := f.getHome(id)
                                        if h != nil && h.(LocalSlot).N == name.N && h.(LocalSlot).Off == name.Off {
@@ -372,7 +372,7 @@ func (s *stackAllocState) buildInterferenceGraph() {
                        if s.values[v.ID].needSlot {
                                live.remove(v.ID)
                                for _, id := range live.contents() {
-                                       if s.values[v.ID].typ.Equal(s.values[id].typ) {
+                                       if s.values[v.ID].typ.Compare(s.values[id].typ) == CMPeq {
                                                s.interfere[v.ID] = append(s.interfere[v.ID], id)
                                                s.interfere[id] = append(s.interfere[id], v.ID)
                                        }
index 2a3de282cb5a093621a83ac68a52728ba0849ead..91a4efe78f3b8ecdfd25d52720e2e9ff495a2af6 100644 (file)
@@ -40,8 +40,7 @@ type Type interface {
 
        String() string
        SimpleString() string // a coarser generic description of T, e.g. T's underlying type
-       Equal(Type) bool
-       Compare(Type) Cmp // compare types, returning one of CMPlt, CMPeq, CMPgt.
+       Compare(Type) Cmp     // compare types, returning one of CMPlt, CMPeq, CMPgt.
 }
 
 // Special compiler-only types.
@@ -117,14 +116,6 @@ func (t *CompilerType) Compare(u Type) Cmp {
        return CMPlt
 }
 
-func (t *CompilerType) Equal(u Type) bool {
-       x, ok := u.(*CompilerType)
-       if !ok {
-               return false
-       }
-       return x == t
-}
-
 var (
        TypeInvalid = &CompilerType{Name: "invalid"}
        TypeMem     = &CompilerType{Name: "mem", Memory: true}