mirror of
https://github.com/golang/go
synced 2024-11-11 20:30:22 -07:00
[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 <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>
This commit is contained in:
parent
dcec658f6c
commit
1c8943a6ad
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user