]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: introduce FwdRefAux for wrapping ir.Node as ssa.Aux
authorMatthew Dempsky <mdempsky@google.com>
Mon, 7 Dec 2020 02:10:34 +0000 (18:10 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 8 Dec 2020 01:46:48 +0000 (01:46 +0000)
OpFwdRef is the only SSA value that needs the ability to store an
arbitrary ir.Node in its Aux field. Every other SSA value always uses
an *ir.Name.

This CL introduces FwdRefAux, which wraps an ir.Node and implements
the ssa.Aux tag interface, so that a subsequent refactoring can change
ir.Node to not implement ssa.Aux.

Passes buildall w/ toolstash -cmp.

Updates #42982.

Change-Id: Id1475b28847579573cd376e82f28761d84cd1c23
Reviewed-on: https://go-review.googlesource.com/c/go/+/275788
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/gc/phi.go
src/cmd/compile/internal/gc/ssa.go

index 677bfc92df2f1e6693650eeecda82abb4dbe37ca..def11e1be0cb287752bedd0d736660b9761b7cba 100644 (file)
@@ -23,6 +23,14 @@ const smallBlocks = 500
 
 const debugPhi = false
 
+// FwdRefAux wraps an arbitrary ir.Node as an ssa.Aux for use with OpFwdref.
+type FwdRefAux struct {
+       _ [0]func() // ensure ir.Node isn't compared for equality
+       N ir.Node
+}
+
+func (FwdRefAux) CanBeAnSSAAux() {}
+
 // insertPhis finds all the places in the function where a phi is
 // necessary and inserts them.
 // Uses FwdRef ops to find all uses of variables, and s.defvars to find
@@ -79,7 +87,7 @@ func (s *phiState) insertPhis() {
                        if v.Op != ssa.OpFwdRef {
                                continue
                        }
-                       var_ := v.Aux.(ir.Node)
+                       var_ := v.Aux.(FwdRefAux).N
 
                        // Optimization: look back 1 block for the definition.
                        if len(b.Preds) == 1 {
@@ -319,7 +327,7 @@ func (s *phiState) resolveFwdRefs() {
                        if v.Op != ssa.OpFwdRef {
                                continue
                        }
-                       n := s.varnum[v.Aux.(ir.Node)]
+                       n := s.varnum[v.Aux.(FwdRefAux).N]
                        v.Op = ssa.OpCopy
                        v.Aux = nil
                        v.AddArg(values[n])
@@ -450,7 +458,7 @@ func (s *simplePhiState) insertPhis() {
                                continue
                        }
                        s.fwdrefs = append(s.fwdrefs, v)
-                       var_ := v.Aux.(ir.Node)
+                       var_ := v.Aux.(FwdRefAux).N
                        if _, ok := s.defvars[b.ID][var_]; !ok {
                                s.defvars[b.ID][var_] = v // treat FwdDefs as definitions.
                        }
@@ -464,7 +472,7 @@ loop:
                v := s.fwdrefs[len(s.fwdrefs)-1]
                s.fwdrefs = s.fwdrefs[:len(s.fwdrefs)-1]
                b := v.Block
-               var_ := v.Aux.(ir.Node)
+               var_ := v.Aux.(FwdRefAux).N
                if b == s.f.Entry {
                        // No variable should be live at entry.
                        s.s.Fatalf("Value live at entry. It shouldn't be. func %s, node %v, value %v", s.f.Name, var_, v)
@@ -531,7 +539,7 @@ func (s *simplePhiState) lookupVarOutgoing(b *ssa.Block, t *types.Type, var_ ir.
                }
        }
        // Generate a FwdRef for the variable and return that.
-       v := b.NewValue0A(line, ssa.OpFwdRef, t, var_)
+       v := b.NewValue0A(line, ssa.OpFwdRef, t, FwdRefAux{N: var_})
        s.defvars[b.ID][var_] = v
        s.s.addNamedValue(var_, v)
        s.fwdrefs = append(s.fwdrefs, v)
index 2378ea7711b9526b3f3d00af7bc996ace3656b7d..90c754604299c528407d3cb5e9475eed7a5b187c 100644 (file)
@@ -6051,7 +6051,7 @@ func (s *state) variable(name ir.Node, t *types.Type) *ssa.Value {
        }
        // Make a FwdRef, which records a value that's live on block input.
        // We'll find the matching definition as part of insertPhis.
-       v = s.newValue0A(ssa.OpFwdRef, t, name)
+       v = s.newValue0A(ssa.OpFwdRef, t, FwdRefAux{N: name})
        s.fwdVars[name] = v
        s.addNamedValue(name, v)
        return v