]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/6g: let the compiler use R15 when it is not needed for GOT indirection
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Fri, 17 Apr 2015 06:36:11 +0000 (08:36 +0200)
committerIan Lance Taylor <iant@golang.org>
Mon, 20 Apr 2015 23:20:15 +0000 (23:20 +0000)
Thanks to Russ for the hints.

Change-Id: Ie35a71d432b9d68bd30c7a364b4dce1bd3db806e
Reviewed-on: https://go-review.googlesource.com/9102
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/6g/prog.go
src/cmd/6g/reg.go

index 4c41d87ccbd44d317f2b2e8463b4880e8562a16f..5aeaeaa4ed4f56db0e7c9a1f1c5875cab7bdd049 100644 (file)
@@ -293,4 +293,16 @@ func proginfo(p *obj.Prog) {
        if p.To.Index != x86.REG_NONE {
                info.Regindex |= RtoB(int(p.To.Index))
        }
+       if gc.Ctxt.Flag_dynlink {
+               // When -dynlink is passed, many operations on external names (and
+               // also calling duffzero/duffcopy) use R15 as a scratch register.
+               if p.As == x86.ALEAQ || info.Flags == gc.Pseudo || p.As == obj.ACALL || p.As == obj.ARET || p.As == obj.AJMP {
+                       return
+               }
+               if p.As == obj.ADUFFZERO || p.As == obj.ADUFFCOPY || p.From.Name == obj.NAME_EXTERN || p.To.Name == obj.NAME_EXTERN {
+                       info.Reguse |= R15
+                       info.Regset |= R15
+                       return
+               }
+       }
 }
index ebca28262ef5946a62fce6320a734c7c1f8e1705..cab07b5b4ebfe07cd241e150b85e7f071cf9b4ea 100644 (file)
@@ -102,12 +102,13 @@ func doregbits(r int) uint64 {
 
 // For ProgInfo.
 const (
-       AX = 1 << (x86.REG_AX - x86.REG_AX)
-       BX = 1 << (x86.REG_BX - x86.REG_AX)
-       CX = 1 << (x86.REG_CX - x86.REG_AX)
-       DX = 1 << (x86.REG_DX - x86.REG_AX)
-       DI = 1 << (x86.REG_DI - x86.REG_AX)
-       SI = 1 << (x86.REG_SI - x86.REG_AX)
+       AX  = 1 << (x86.REG_AX - x86.REG_AX)
+       BX  = 1 << (x86.REG_BX - x86.REG_AX)
+       CX  = 1 << (x86.REG_CX - x86.REG_AX)
+       DX  = 1 << (x86.REG_DX - x86.REG_AX)
+       DI  = 1 << (x86.REG_DI - x86.REG_AX)
+       SI  = 1 << (x86.REG_SI - x86.REG_AX)
+       R15 = 1 << (x86.REG_R15 - x86.REG_AX)
 )
 
 func RtoB(r int) uint64 {
@@ -125,9 +126,6 @@ func BtoR(b uint64) int {
                // BP is part of the calling convention if framepointer_enabled.
                b &^= (1 << (x86.REG_BP - x86.REG_AX))
        }
-       if gc.Ctxt.Flag_dynlink {
-               b &^= (1 << (x86.REG_R15 - x86.REG_AX))
-       }
        if b == 0 {
                return 0
        }