1
0
mirror of https://github.com/golang/go synced 2024-10-05 16:41:21 -06:00

[dev.ssa] cmd/compile: handle addr of PARAM nodes

Turns out that these do occur after all, so did the obvious
refactoring into the addr method.

Also added better debugging for the case of unhandled
closure args.

Change-Id: I1cd8ac58f78848bae0b995736f1c744fd20a6c95
Reviewed-on: https://go-review.googlesource.com/15640
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: David Chase <drchase@google.com>
This commit is contained in:
David Chase 2015-10-08 17:14:12 -04:00
parent 8824dccc28
commit 32ffbf7e0f

View File

@ -1250,22 +1250,8 @@ func (s *state) expr(n *Node) *ssa.Value {
aux := &ssa.ExternSymbol{n.Type, n.Left.Sym}
return s.entryNewValue1A(ssa.OpAddr, n.Type, aux, s.sb)
case OPARAM:
// Reach through param to expected ONAME w/ PHEAP|PARAM class
// to reference the incoming parameter. Used in initialization
// of heap storage allocated for escaping params, where it appears
// as the RHS of an OAS node. No point doing SSA for this variable,
// this is the only use.
p := n.Left
if p.Op != ONAME || !(p.Class == PPARAM|PHEAP || p.Class == PPARAMOUT|PHEAP) {
s.Fatalf("OPARAM not of ONAME,{PPARAM,PPARAMOUT}|PHEAP, instead %s", nodedump(p, 0))
}
// Recover original offset to address passed-in param value.
original_p := *p
original_p.Xoffset = n.Xoffset
aux := &ssa.ArgSymbol{Typ: n.Type, Node: &original_p}
addr := s.entryNewValue1A(ssa.OpAddr, Ptrto(n.Type), aux, s.sp)
return s.newValue2(ssa.OpLoad, p.Type, addr, s.mem())
addr := s.addr(n)
return s.newValue2(ssa.OpLoad, n.Left.Type, addr, s.mem())
case ONAME:
if n.Class == PFUNC {
// "value" of a function is the address of the function's closure
@ -2287,6 +2273,17 @@ func (s *state) addr(n *Node) *ssa.Value {
return s.newValue2(ssa.OpAddPtr, Ptrto(n.Type),
s.entryNewValue0(ssa.OpGetClosurePtr, Types[TUINTPTR]),
s.constIntPtr(Types[TUINTPTR], n.Xoffset))
case OPARAM:
p := n.Left
if p.Op != ONAME || !(p.Class == PPARAM|PHEAP || p.Class == PPARAMOUT|PHEAP) {
s.Fatalf("OPARAM not of ONAME,{PPARAM,PPARAMOUT}|PHEAP, instead %s", nodedump(p, 0))
}
// Recover original offset to address passed-in param value.
original_p := *p
original_p.Xoffset = n.Xoffset
aux := &ssa.ArgSymbol{Typ: n.Type, Node: &original_p}
return s.entryNewValue1A(ssa.OpAddr, Ptrto(n.Type), aux, s.sp)
default:
s.Unimplementedf("unhandled addr %v", Oconv(int(n.Op), 0))
return nil
@ -3072,7 +3069,7 @@ func (s *state) lookupVarIncoming(b *ssa.Block, t ssa.Type, name *Node) *ssa.Val
addr := s.decladdrs[name]
if addr == nil {
// TODO: closure args reach here.
s.Unimplementedf("unhandled closure arg")
s.Unimplementedf("unhandled closure arg %s at entry to function %s", name, b.Func.Name)
}
if _, ok := addr.Aux.(*ssa.ArgSymbol); !ok {
s.Fatalf("variable live at start of function %s is not an argument %s", b.Func.Name, name)