From 1c8943a6add218f6ffd86c0952372fe54b0672a4 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sun, 6 Dec 2020 18:10:34 -0800 Subject: [PATCH] [dev.regabi] cmd/compile: introduce FwdRefAux for wrapping ir.Node as ssa.Aux 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 TryBot-Result: Go Bot Trust: Matthew Dempsky Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/gc/phi.go | 18 +++++++++++++----- src/cmd/compile/internal/gc/ssa.go | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/cmd/compile/internal/gc/phi.go b/src/cmd/compile/internal/gc/phi.go index 677bfc92df..def11e1be0 100644 --- a/src/cmd/compile/internal/gc/phi.go +++ b/src/cmd/compile/internal/gc/phi.go @@ -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) diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 2378ea7711..90c7546042 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -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 -- 2.50.0