[dev.ssa] cmd/compile: getg needs a memory arg

getg reads from memory, so it should really have a
memory arg.  It is critical in functions which call setg
to make sure getg gets ordered correctly with setg.

Change-Id: Ief4875421f741fc49c07b0e1f065ce2535232341
Reviewed-on: https://go-review.googlesource.com/16100
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: David Chase <drchase@google.com>
This commit is contained in:
Keith Randall 2015-10-19 18:54:40 -07:00
parent 65df9c4c2b
commit d694f83c21
8 changed files with 16 additions and 19 deletions

View file

@ -1870,7 +1870,7 @@ func (s *state) expr(n *Node) *ssa.Value {
return s.call(n, callNormal) return s.call(n, callNormal)
case OGETG: case OGETG:
return s.newValue0(ssa.OpGetG, n.Type) return s.newValue1(ssa.OpGetG, n.Type, s.mem())
case OAPPEND: case OAPPEND:
// append(s, e1, e2, e3). Compile like: // append(s, e1, e2, e3). Compile like:

View file

@ -287,7 +287,7 @@
(IsSliceInBounds idx len) -> (SETBE (CMPQ idx len)) (IsSliceInBounds idx len) -> (SETBE (CMPQ idx len))
(PanicNilCheck ptr mem) -> (LoweredPanicNilCheck ptr mem) (PanicNilCheck ptr mem) -> (LoweredPanicNilCheck ptr mem)
(GetG) -> (LoweredGetG) (GetG mem) -> (LoweredGetG mem)
(GetClosurePtr) -> (LoweredGetClosurePtr) (GetClosurePtr) -> (LoweredGetClosurePtr)
(Move [size] dst src mem) -> (REPMOVSB dst src (MOVQconst <config.Frontend().TypeUInt64()> [size]) mem) (Move [size] dst src mem) -> (REPMOVSB dst src (MOVQconst <config.Frontend().TypeUInt64()> [size]) mem)

View file

@ -423,7 +423,7 @@ func init() {
// Pseudo-ops // Pseudo-ops
{name: "LoweredPanicNilCheck", reg: gp10}, {name: "LoweredPanicNilCheck", reg: gp10},
{name: "LoweredGetG", reg: gp01}, {name: "LoweredGetG", reg: gp01}, // arg0=mem
// Scheduler ensures LoweredGetClosurePtr occurs only in entry block, // Scheduler ensures LoweredGetClosurePtr occurs only in entry block,
// and sorts it to the very beginning of the block to prevent other // and sorts it to the very beginning of the block to prevent other
// use of DX (the closure pointer) // use of DX (the closure pointer)

View file

@ -180,7 +180,7 @@
(Store [size] dst (Load <t> src mem) mem) && !config.fe.CanSSA(t) -> (Move [size] dst src mem) (Store [size] dst (Load <t> src mem) mem) && !config.fe.CanSSA(t) -> (Move [size] dst src mem)
(Store [size] dst (Load <t> src mem) (VarDef {x} mem)) && !config.fe.CanSSA(t) -> (Move [size] dst src (VarDef {x} mem)) (Store [size] dst (Load <t> src mem) (VarDef {x} mem)) && !config.fe.CanSSA(t) -> (Move [size] dst src (VarDef {x} mem))
(If (IsNonNil (GetG)) yes no) -> (First nil yes no) (If (IsNonNil (GetG _)) yes no) -> (First nil yes no)
(If (Not cond) yes no) -> (If cond no yes) (If (Not cond) yes no) -> (If cond no yes)
(If (ConstBool [c]) yes no) && c == 1 -> (First nil yes no) (If (ConstBool [c]) yes no) && c == 1 -> (First nil yes no)

View file

@ -326,7 +326,7 @@ var genericOps = []opData{
// Pseudo-ops // Pseudo-ops
{name: "PanicNilCheck"}, // trigger a dereference fault; arg0=nil ptr, arg1=mem, returns mem {name: "PanicNilCheck"}, // trigger a dereference fault; arg0=nil ptr, arg1=mem, returns mem
{name: "GetG"}, // runtime.getg() (read g pointer) {name: "GetG"}, // runtime.getg() (read g pointer). arg0=mem
{name: "GetClosurePtr"}, // get closure pointer from dedicated register {name: "GetClosurePtr"}, // get closure pointer from dedicated register
// Indexing operations // Indexing operations

View file

@ -982,11 +982,6 @@ func (v *Value) rematerializeable() bool {
// which can't be moved. // which can't be moved.
return false return false
} }
if v.Op == OpAMD64LoweredGetG {
// It would almost always be ok to rematerialize this op.
// The annoying exception is functions that call runtime.setg.
return false
}
if len(v.Args) == 0 { if len(v.Args) == 0 {
return true return true
} }

View file

@ -2412,18 +2412,20 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
end6fd0b53f0acb4d35e7d7fa78d2ca1392: end6fd0b53f0acb4d35e7d7fa78d2ca1392:
; ;
case OpGetG: case OpGetG:
// match: (GetG) // match: (GetG mem)
// cond: // cond:
// result: (LoweredGetG) // result: (LoweredGetG mem)
{ {
mem := v.Args[0]
v.Op = OpAMD64LoweredGetG v.Op = OpAMD64LoweredGetG
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AddArg(mem)
return true return true
} }
goto endb17140e71dd641aa4d89e14479160260 goto endf543eaaf68c4bef1d4cdc8ba19683723
endb17140e71dd641aa4d89e14479160260: endf543eaaf68c4bef1d4cdc8ba19683723:
; ;
case OpGoCall: case OpGoCall:
// match: (GoCall [argwid] mem) // match: (GoCall [argwid] mem)

View file

@ -1697,16 +1697,16 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
func rewriteBlockgeneric(b *Block) bool { func rewriteBlockgeneric(b *Block) bool {
switch b.Kind { switch b.Kind {
case BlockIf: case BlockIf:
// match: (If (IsNonNil (GetG)) yes no) // match: (If (IsNonNil (GetG _)) yes no)
// cond: // cond:
// result: (First nil yes no) // result: (First nil yes no)
{ {
v := b.Control v := b.Control
if v.Op != OpIsNonNil { if v.Op != OpIsNonNil {
goto endafdc4e2525f9933ab0ae7effc3559597 goto end41b95d88b4cebdb0ce392bd3c1c89e95
} }
if v.Args[0].Op != OpGetG { if v.Args[0].Op != OpGetG {
goto endafdc4e2525f9933ab0ae7effc3559597 goto end41b95d88b4cebdb0ce392bd3c1c89e95
} }
yes := b.Succs[0] yes := b.Succs[0]
no := b.Succs[1] no := b.Succs[1]
@ -1716,8 +1716,8 @@ func rewriteBlockgeneric(b *Block) bool {
b.Succs[1] = no b.Succs[1] = no
return true return true
} }
goto endafdc4e2525f9933ab0ae7effc3559597 goto end41b95d88b4cebdb0ce392bd3c1c89e95
endafdc4e2525f9933ab0ae7effc3559597: end41b95d88b4cebdb0ce392bd3c1c89e95:
; ;
// match: (If (Not cond) yes no) // match: (If (Not cond) yes no)
// cond: // cond: