]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: getg needs a memory arg
authorKeith Randall <khr@golang.org>
Tue, 20 Oct 2015 01:54:40 +0000 (18:54 -0700)
committerKeith Randall <khr@golang.org>
Tue, 20 Oct 2015 03:41:03 +0000 (03:41 +0000)
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>

src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/ssa/gen/AMD64.rules
src/cmd/compile/internal/ssa/gen/AMD64Ops.go
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/gen/genericOps.go
src/cmd/compile/internal/ssa/regalloc.go
src/cmd/compile/internal/ssa/rewriteAMD64.go
src/cmd/compile/internal/ssa/rewritegeneric.go

index 7219ffd653af4bde9752711a1676d318da32b7c1..3ef82322e5483c1c0254565e8fdcf1c3edcd9358 100644 (file)
@@ -1870,7 +1870,7 @@ func (s *state) expr(n *Node) *ssa.Value {
                return s.call(n, callNormal)
 
        case OGETG:
-               return s.newValue0(ssa.OpGetG, n.Type)
+               return s.newValue1(ssa.OpGetG, n.Type, s.mem())
 
        case OAPPEND:
                // append(s, e1, e2, e3).  Compile like:
index f160ce81af67e292c80f7233a4f2816fdf93d1f2..b30df5f8d4515345ca004ac2059604124e2a592d 100644 (file)
 (IsSliceInBounds idx len) -> (SETBE (CMPQ idx len))
 
 (PanicNilCheck ptr mem) -> (LoweredPanicNilCheck ptr mem)
-(GetG) -> (LoweredGetG)
+(GetG mem) -> (LoweredGetG mem)
 (GetClosurePtr) -> (LoweredGetClosurePtr)
 
 (Move [size] dst src mem) -> (REPMOVSB dst src (MOVQconst <config.Frontend().TypeUInt64()> [size]) mem)
index 5d171dc87a22ee61003b246d8438cb52335df7a5..e9414238b0feebbe41c1602cd0cd4ffb03ba0d58 100644 (file)
@@ -423,7 +423,7 @@ func init() {
 
                // Pseudo-ops
                {name: "LoweredPanicNilCheck", reg: gp10},
-               {name: "LoweredGetG", reg: gp01},
+               {name: "LoweredGetG", reg: gp01}, // arg0=mem
                // Scheduler ensures LoweredGetClosurePtr occurs only in entry block,
                // and sorts it to the very beginning of the block to prevent other
                // use of DX (the closure pointer)
index 01026042bf36b3f91fb45f8af56408f182f6980c..42eec3dd756bc6560e885baf661999ebf630c0e0 100644 (file)
 (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))
 
-(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 (ConstBool [c]) yes no) && c == 1 -> (First nil yes no)
index 1ee38103ac23f74638535e494607b947e62ad339..5881596441808ccdfc6d6a210ea4889f6410bcd0 100644 (file)
@@ -326,7 +326,7 @@ var genericOps = []opData{
 
        // Pseudo-ops
        {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
 
        // Indexing operations
index 72b056cd8d2009a2b65b7b7e978b1d99451b3471..9cf589b215b3c27c608b161de262d536014712c6 100644 (file)
@@ -982,11 +982,6 @@ func (v *Value) rematerializeable() bool {
                // which can't be moved.
                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 {
                return true
        }
index 4ac4744b645c31db8923b09b2bf22111ce0db519..5fad78aa3cd750b771bb96c202a509bcd62a1a19 100644 (file)
@@ -2412,18 +2412,20 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
        end6fd0b53f0acb4d35e7d7fa78d2ca1392:
                ;
        case OpGetG:
-               // match: (GetG)
+               // match: (GetG mem)
                // cond:
-               // result: (LoweredGetG)
+               // result: (LoweredGetG mem)
                {
+                       mem := v.Args[0]
                        v.Op = OpAMD64LoweredGetG
                        v.AuxInt = 0
                        v.Aux = nil
                        v.resetArgs()
+                       v.AddArg(mem)
                        return true
                }
-               goto endb17140e71dd641aa4d89e14479160260
-       endb17140e71dd641aa4d89e14479160260:
+               goto endf543eaaf68c4bef1d4cdc8ba19683723
+       endf543eaaf68c4bef1d4cdc8ba19683723:
                ;
        case OpGoCall:
                // match: (GoCall [argwid] mem)
index 46d97b57e305ad04a0e0fad147517686dec197b5..7f9c8559488db01c6e6d282050f3d3ce4d14e3a1 100644 (file)
@@ -1697,16 +1697,16 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
 func rewriteBlockgeneric(b *Block) bool {
        switch b.Kind {
        case BlockIf:
-               // match: (If (IsNonNil (GetG)) yes no)
+               // match: (If (IsNonNil (GetG _)) yes no)
                // cond:
                // result: (First nil yes no)
                {
                        v := b.Control
                        if v.Op != OpIsNonNil {
-                               goto endafdc4e2525f9933ab0ae7effc3559597
+                               goto end41b95d88b4cebdb0ce392bd3c1c89e95
                        }
                        if v.Args[0].Op != OpGetG {
-                               goto endafdc4e2525f9933ab0ae7effc3559597
+                               goto end41b95d88b4cebdb0ce392bd3c1c89e95
                        }
                        yes := b.Succs[0]
                        no := b.Succs[1]
@@ -1716,8 +1716,8 @@ func rewriteBlockgeneric(b *Block) bool {
                        b.Succs[1] = no
                        return true
                }
-               goto endafdc4e2525f9933ab0ae7effc3559597
-       endafdc4e2525f9933ab0ae7effc3559597:
+               goto end41b95d88b4cebdb0ce392bd3c1c89e95
+       end41b95d88b4cebdb0ce392bd3c1c89e95:
                ;
                // match: (If (Not cond) yes no)
                // cond: