2015-02-13 14:40:36 -05:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
|
|
import (
|
2015-05-28 13:49:20 -07:00
|
|
|
"cmd/compile/internal/ssa"
|
2015-02-13 14:40:36 -05:00
|
|
|
"cmd/internal/obj"
|
2016-04-06 12:01:40 -07:00
|
|
|
"cmd/internal/sys"
|
2015-02-13 14:40:36 -05:00
|
|
|
"fmt"
|
2016-02-25 10:35:19 -08:00
|
|
|
"sort"
|
2015-02-13 14:40:36 -05:00
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// "Portable" code generation.
|
|
|
|
|
|
2016-03-19 18:17:58 -07:00
|
|
|
var makefuncdatasym_nsym int
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-19 18:17:58 -07:00
|
|
|
func makefuncdatasym(nameprefix string, funcdatakind int64) *Sym {
|
2015-02-13 14:40:36 -05:00
|
|
|
var nod Node
|
|
|
|
|
|
2016-03-19 18:17:58 -07:00
|
|
|
sym := LookupN(nameprefix, makefuncdatasym_nsym)
|
2015-02-13 14:40:36 -05:00
|
|
|
makefuncdatasym_nsym++
|
2015-02-23 16:07:24 -05:00
|
|
|
pnod := newname(sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
pnod.Class = PEXTERN
|
|
|
|
|
Nodconst(&nod, Types[TINT32], funcdatakind)
|
|
|
|
|
Thearch.Gins(obj.AFUNCDATA, &nod, pnod)
|
|
|
|
|
return sym
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// gvardef inserts a VARDEF for n into the instruction stream.
|
|
|
|
|
// VARDEF is an annotation for the liveness analysis, marking a place
|
|
|
|
|
// where a complete initialization (definition) of a variable begins.
|
|
|
|
|
// Since the liveness analysis can see initialization of single-word
|
|
|
|
|
// variables quite easy, gvardef is usually only called for multi-word
|
|
|
|
|
// or 'fat' variables, those satisfying isfat(n->type).
|
|
|
|
|
// However, gvardef is also called when a non-fat variable is initialized
|
|
|
|
|
// via a block move; the only time this happens is when you have
|
|
|
|
|
// return f()
|
|
|
|
|
// for a function with multiple return values exactly matching the return
|
|
|
|
|
// types of the current function.
|
|
|
|
|
//
|
|
|
|
|
// A 'VARDEF x' annotation in the instruction stream tells the liveness
|
|
|
|
|
// analysis to behave as though the variable x is being initialized at that
|
|
|
|
|
// point in the instruction stream. The VARDEF must appear before the
|
|
|
|
|
// actual (multi-instruction) initialization, and it must also appear after
|
|
|
|
|
// any uses of the previous value, if any. For example, if compiling:
|
|
|
|
|
//
|
|
|
|
|
// x = x[1:]
|
|
|
|
|
//
|
|
|
|
|
// it is important to generate code like:
|
|
|
|
|
//
|
|
|
|
|
// base, len, cap = pieces of x[1:]
|
|
|
|
|
// VARDEF x
|
|
|
|
|
// x = {base, len, cap}
|
|
|
|
|
//
|
|
|
|
|
// If instead the generated code looked like:
|
|
|
|
|
//
|
|
|
|
|
// VARDEF x
|
|
|
|
|
// base, len, cap = pieces of x[1:]
|
|
|
|
|
// x = {base, len, cap}
|
|
|
|
|
//
|
|
|
|
|
// then the liveness analysis would decide the previous value of x was
|
|
|
|
|
// unnecessary even though it is about to be used by the x[1:] computation.
|
|
|
|
|
// Similarly, if the generated code looked like:
|
|
|
|
|
//
|
|
|
|
|
// base, len, cap = pieces of x[1:]
|
|
|
|
|
// x = {base, len, cap}
|
|
|
|
|
// VARDEF x
|
|
|
|
|
//
|
|
|
|
|
// then the liveness analysis will not preserve the new value of x, because
|
|
|
|
|
// the VARDEF appears to have "overwritten" it.
|
|
|
|
|
//
|
|
|
|
|
// VARDEF is a bit of a kludge to work around the fact that the instruction
|
|
|
|
|
// stream is working on single-word values but the liveness analysis
|
|
|
|
|
// wants to work on individual variables, which might be multi-word
|
|
|
|
|
// aggregates. It might make sense at some point to look into letting
|
|
|
|
|
// the liveness analysis work on single-word values as well, although
|
|
|
|
|
// there are complications around interface values, slices, and strings,
|
|
|
|
|
// all of which cannot be treated as individual words.
|
|
|
|
|
//
|
|
|
|
|
// VARKILL is the opposite of VARDEF: it marks a value as no longer needed,
|
|
|
|
|
// even if its address has been taken. That is, a VARKILL annotation asserts
|
|
|
|
|
// that its argument is certainly dead, for use when the liveness analysis
|
|
|
|
|
// would not otherwise be able to deduce that fact.
|
|
|
|
|
|
2016-03-07 18:00:08 -08:00
|
|
|
func gvardefx(n *Node, as obj.As) {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n == nil {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("gvardef nil")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if n.Op != ONAME {
|
2016-04-27 14:46:09 +10:00
|
|
|
Yyerror("gvardef %v; %v", oconv(n.Op, FmtSharp), n)
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch n.Class {
|
2015-04-01 09:38:44 -07:00
|
|
|
case PAUTO, PPARAM, PPARAMOUT:
|
cmd/compile: recognize Syscall-like functions for liveness analysis
Consider this code:
func f(*int)
func g() {
p := new(int)
f(p)
}
where f is an assembly function.
In general liveness analysis assumes that during the call to f, p is dead
in this frame. If f has retained p, p will be found alive in f's frame and keep
the new(int) from being garbage collected. This is all correct and works.
We use the Go func declaration for f to give the assembly function
liveness information (the arguments are assumed live for the entire call).
Now consider this code:
func h1() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
}
Here syscall.Syscall is taking the place of f, but because its arguments
are uintptr, the liveness analysis and the garbage collector ignore them.
Since p is no longer live in h once the call starts, if the garbage collector
scans the stack while the system call is blocked, it will find no reference
to the new(int) and reclaim it. If the kernel is going to write to *p once
the call finishes, reclaiming the memory is a mistake.
We can't change the arguments or the liveness information for
syscall.Syscall itself, both for compatibility and because sometimes the
arguments really are integers, and the garbage collector will get quite upset
if it finds an integer where it expects a pointer. The problem is that
these arguments are fundamentally untyped.
The solution we have taken in the syscall package's wrappers in past
releases is to insert a call to a dummy function named "use", to make
it look like the argument is live during the call to syscall.Syscall:
func h2() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
use(unsafe.Pointer(p))
}
Keeping p alive during the call means that if the garbage collector
scans the stack during the system call now, it will find the reference to p.
Unfortunately, this approach is not available to users outside syscall,
because 'use' is unexported, and people also have to realize they need
to use it and do so. There is much existing code using syscall.Syscall
without a 'use'-like function. That code will fail very occasionally in
mysterious ways (see #13372).
This CL fixes all that existing code by making the compiler do the right
thing automatically, without any code modifications. That is, it takes h1
above, which is incorrect code today, and makes it correct code.
Specifically, if the compiler sees a foreign func definition (one
without a body) that has uintptr arguments, it marks those arguments
as "unsafe uintptrs". If it later sees the function being called
with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x
as having escaped, and it makes sure to hold x in a live temporary
variable until the call returns, so that the garbage collector cannot
reclaim whatever heap memory x points to.
For now I am leaving the explicit calls to use in package syscall,
but they can be removed early in a future cycle (likely Go 1.7).
The rule has no effect on escape analysis, only on liveness analysis.
Fixes #13372.
Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500
Reviewed-on: https://go-review.googlesource.com/18584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-13 00:46:28 -05:00
|
|
|
if as == obj.AVARLIVE {
|
|
|
|
|
Thearch.Gins(as, n, nil)
|
|
|
|
|
} else {
|
|
|
|
|
Thearch.Gins(as, nil, n)
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Gvardef(n *Node) {
|
|
|
|
|
gvardefx(n, obj.AVARDEF)
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
func Gvarkill(n *Node) {
|
2015-02-13 14:40:36 -05:00
|
|
|
gvardefx(n, obj.AVARKILL)
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
func Gvarlive(n *Node) {
|
cmd/compile: recognize Syscall-like functions for liveness analysis
Consider this code:
func f(*int)
func g() {
p := new(int)
f(p)
}
where f is an assembly function.
In general liveness analysis assumes that during the call to f, p is dead
in this frame. If f has retained p, p will be found alive in f's frame and keep
the new(int) from being garbage collected. This is all correct and works.
We use the Go func declaration for f to give the assembly function
liveness information (the arguments are assumed live for the entire call).
Now consider this code:
func h1() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
}
Here syscall.Syscall is taking the place of f, but because its arguments
are uintptr, the liveness analysis and the garbage collector ignore them.
Since p is no longer live in h once the call starts, if the garbage collector
scans the stack while the system call is blocked, it will find no reference
to the new(int) and reclaim it. If the kernel is going to write to *p once
the call finishes, reclaiming the memory is a mistake.
We can't change the arguments or the liveness information for
syscall.Syscall itself, both for compatibility and because sometimes the
arguments really are integers, and the garbage collector will get quite upset
if it finds an integer where it expects a pointer. The problem is that
these arguments are fundamentally untyped.
The solution we have taken in the syscall package's wrappers in past
releases is to insert a call to a dummy function named "use", to make
it look like the argument is live during the call to syscall.Syscall:
func h2() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
use(unsafe.Pointer(p))
}
Keeping p alive during the call means that if the garbage collector
scans the stack during the system call now, it will find the reference to p.
Unfortunately, this approach is not available to users outside syscall,
because 'use' is unexported, and people also have to realize they need
to use it and do so. There is much existing code using syscall.Syscall
without a 'use'-like function. That code will fail very occasionally in
mysterious ways (see #13372).
This CL fixes all that existing code by making the compiler do the right
thing automatically, without any code modifications. That is, it takes h1
above, which is incorrect code today, and makes it correct code.
Specifically, if the compiler sees a foreign func definition (one
without a body) that has uintptr arguments, it marks those arguments
as "unsafe uintptrs". If it later sees the function being called
with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x
as having escaped, and it makes sure to hold x in a live temporary
variable until the call returns, so that the garbage collector cannot
reclaim whatever heap memory x points to.
For now I am leaving the explicit calls to use in package syscall,
but they can be removed early in a future cycle (likely Go 1.7).
The rule has no effect on escape analysis, only on liveness analysis.
Fixes #13372.
Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500
Reviewed-on: https://go-review.googlesource.com/18584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-13 00:46:28 -05:00
|
|
|
gvardefx(n, obj.AVARLIVE)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
func removevardef(firstp *obj.Prog) {
|
2015-02-23 16:07:24 -05:00
|
|
|
for p := firstp; p != nil; p = p.Link {
|
cmd/compile: recognize Syscall-like functions for liveness analysis
Consider this code:
func f(*int)
func g() {
p := new(int)
f(p)
}
where f is an assembly function.
In general liveness analysis assumes that during the call to f, p is dead
in this frame. If f has retained p, p will be found alive in f's frame and keep
the new(int) from being garbage collected. This is all correct and works.
We use the Go func declaration for f to give the assembly function
liveness information (the arguments are assumed live for the entire call).
Now consider this code:
func h1() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
}
Here syscall.Syscall is taking the place of f, but because its arguments
are uintptr, the liveness analysis and the garbage collector ignore them.
Since p is no longer live in h once the call starts, if the garbage collector
scans the stack while the system call is blocked, it will find no reference
to the new(int) and reclaim it. If the kernel is going to write to *p once
the call finishes, reclaiming the memory is a mistake.
We can't change the arguments or the liveness information for
syscall.Syscall itself, both for compatibility and because sometimes the
arguments really are integers, and the garbage collector will get quite upset
if it finds an integer where it expects a pointer. The problem is that
these arguments are fundamentally untyped.
The solution we have taken in the syscall package's wrappers in past
releases is to insert a call to a dummy function named "use", to make
it look like the argument is live during the call to syscall.Syscall:
func h2() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
use(unsafe.Pointer(p))
}
Keeping p alive during the call means that if the garbage collector
scans the stack during the system call now, it will find the reference to p.
Unfortunately, this approach is not available to users outside syscall,
because 'use' is unexported, and people also have to realize they need
to use it and do so. There is much existing code using syscall.Syscall
without a 'use'-like function. That code will fail very occasionally in
mysterious ways (see #13372).
This CL fixes all that existing code by making the compiler do the right
thing automatically, without any code modifications. That is, it takes h1
above, which is incorrect code today, and makes it correct code.
Specifically, if the compiler sees a foreign func definition (one
without a body) that has uintptr arguments, it marks those arguments
as "unsafe uintptrs". If it later sees the function being called
with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x
as having escaped, and it makes sure to hold x in a live temporary
variable until the call returns, so that the garbage collector cannot
reclaim whatever heap memory x points to.
For now I am leaving the explicit calls to use in package syscall,
but they can be removed early in a future cycle (likely Go 1.7).
The rule has no effect on escape analysis, only on liveness analysis.
Fixes #13372.
Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500
Reviewed-on: https://go-review.googlesource.com/18584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-13 00:46:28 -05:00
|
|
|
for p.Link != nil && (p.Link.As == obj.AVARDEF || p.Link.As == obj.AVARKILL || p.Link.As == obj.AVARLIVE) {
|
2015-02-13 14:40:36 -05:00
|
|
|
p.Link = p.Link.Link
|
|
|
|
|
}
|
|
|
|
|
if p.To.Type == obj.TYPE_BRANCH {
|
cmd/compile: recognize Syscall-like functions for liveness analysis
Consider this code:
func f(*int)
func g() {
p := new(int)
f(p)
}
where f is an assembly function.
In general liveness analysis assumes that during the call to f, p is dead
in this frame. If f has retained p, p will be found alive in f's frame and keep
the new(int) from being garbage collected. This is all correct and works.
We use the Go func declaration for f to give the assembly function
liveness information (the arguments are assumed live for the entire call).
Now consider this code:
func h1() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
}
Here syscall.Syscall is taking the place of f, but because its arguments
are uintptr, the liveness analysis and the garbage collector ignore them.
Since p is no longer live in h once the call starts, if the garbage collector
scans the stack while the system call is blocked, it will find no reference
to the new(int) and reclaim it. If the kernel is going to write to *p once
the call finishes, reclaiming the memory is a mistake.
We can't change the arguments or the liveness information for
syscall.Syscall itself, both for compatibility and because sometimes the
arguments really are integers, and the garbage collector will get quite upset
if it finds an integer where it expects a pointer. The problem is that
these arguments are fundamentally untyped.
The solution we have taken in the syscall package's wrappers in past
releases is to insert a call to a dummy function named "use", to make
it look like the argument is live during the call to syscall.Syscall:
func h2() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
use(unsafe.Pointer(p))
}
Keeping p alive during the call means that if the garbage collector
scans the stack during the system call now, it will find the reference to p.
Unfortunately, this approach is not available to users outside syscall,
because 'use' is unexported, and people also have to realize they need
to use it and do so. There is much existing code using syscall.Syscall
without a 'use'-like function. That code will fail very occasionally in
mysterious ways (see #13372).
This CL fixes all that existing code by making the compiler do the right
thing automatically, without any code modifications. That is, it takes h1
above, which is incorrect code today, and makes it correct code.
Specifically, if the compiler sees a foreign func definition (one
without a body) that has uintptr arguments, it marks those arguments
as "unsafe uintptrs". If it later sees the function being called
with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x
as having escaped, and it makes sure to hold x in a live temporary
variable until the call returns, so that the garbage collector cannot
reclaim whatever heap memory x points to.
For now I am leaving the explicit calls to use in package syscall,
but they can be removed early in a future cycle (likely Go 1.7).
The rule has no effect on escape analysis, only on liveness analysis.
Fixes #13372.
Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500
Reviewed-on: https://go-review.googlesource.com/18584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-13 00:46:28 -05:00
|
|
|
for p.To.Val.(*obj.Prog) != nil && (p.To.Val.(*obj.Prog).As == obj.AVARDEF || p.To.Val.(*obj.Prog).As == obj.AVARKILL || p.To.Val.(*obj.Prog).As == obj.AVARLIVE) {
|
2015-03-16 15:54:44 -04:00
|
|
|
p.To.Val = p.To.Val.(*obj.Prog).Link
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func emitptrargsmap() {
|
2015-11-04 15:54:41 -05:00
|
|
|
if Curfn.Func.Nname.Sym.Name == "_" {
|
|
|
|
|
return
|
|
|
|
|
}
|
2015-05-27 10:42:55 -04:00
|
|
|
sym := Lookup(fmt.Sprintf("%s.args_stackmap", Curfn.Func.Nname.Sym.Name))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-28 14:31:57 -07:00
|
|
|
nptr := int(Curfn.Type.ArgWidth() / int64(Widthptr))
|
2015-02-23 16:07:24 -05:00
|
|
|
bv := bvalloc(int32(nptr) * 2)
|
|
|
|
|
nbitmap := 1
|
2016-03-17 01:47:16 -07:00
|
|
|
if Curfn.Type.Results().NumFields() > 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
nbitmap = 2
|
|
|
|
|
}
|
2015-02-23 16:07:24 -05:00
|
|
|
off := duint32(sym, 0, uint32(nbitmap))
|
2015-02-13 14:40:36 -05:00
|
|
|
off = duint32(sym, off, uint32(bv.n))
|
2015-02-23 16:07:24 -05:00
|
|
|
var xoffset int64
|
2016-03-17 01:47:16 -07:00
|
|
|
if Curfn.Type.Recv() != nil {
|
2015-02-13 14:40:36 -05:00
|
|
|
xoffset = 0
|
2016-03-09 20:54:59 -08:00
|
|
|
onebitwalktype1(Curfn.Type.Recvs(), &xoffset, bv)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-17 01:47:16 -07:00
|
|
|
if Curfn.Type.Params().NumFields() > 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
xoffset = 0
|
2016-03-08 16:31:28 -08:00
|
|
|
onebitwalktype1(Curfn.Type.Params(), &xoffset, bv)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
for j := 0; int32(j) < bv.n; j += 32 {
|
2015-02-13 14:40:36 -05:00
|
|
|
off = duint32(sym, off, bv.b[j/32])
|
|
|
|
|
}
|
2016-03-17 01:47:16 -07:00
|
|
|
if Curfn.Type.Results().NumFields() > 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
xoffset = 0
|
2016-03-08 16:31:28 -08:00
|
|
|
onebitwalktype1(Curfn.Type.Results(), &xoffset, bv)
|
2015-02-23 16:07:24 -05:00
|
|
|
for j := 0; int32(j) < bv.n; j += 32 {
|
2015-02-13 14:40:36 -05:00
|
|
|
off = duint32(sym, off, bv.b[j/32])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-18 08:14:08 +12:00
|
|
|
ggloblsym(sym, int32(off), obj.RODATA|obj.LOCAL)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-09-15 21:43:53 +02:00
|
|
|
// cmpstackvarlt reports whether the stack variable a sorts before b.
|
2015-09-19 23:55:27 +02:00
|
|
|
//
|
2015-02-13 14:40:36 -05:00
|
|
|
// Sort the list of stack variables. Autos after anything else,
|
|
|
|
|
// within autos, unused after used, within used, things with
|
|
|
|
|
// pointers first, zeroed things first, and then decreasing size.
|
|
|
|
|
// Because autos are laid out in decreasing addresses
|
|
|
|
|
// on the stack, pointers first, zeroed things first and decreasing size
|
|
|
|
|
// really means, in memory, things with pointers needing zeroing at
|
|
|
|
|
// the top of the stack and increasing in size.
|
|
|
|
|
// Non-autos sort on offset.
|
2015-09-19 23:55:27 +02:00
|
|
|
func cmpstackvarlt(a, b *Node) bool {
|
2016-02-20 21:36:12 -08:00
|
|
|
if (a.Class == PAUTO) != (b.Class == PAUTO) {
|
|
|
|
|
return b.Class == PAUTO
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if a.Class != PAUTO {
|
2016-02-20 21:36:12 -08:00
|
|
|
return a.Xoffset < b.Xoffset
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-06 21:18:41 +11:00
|
|
|
if a.Used != b.Used {
|
2015-09-19 23:55:27 +02:00
|
|
|
return a.Used
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-09-19 23:55:27 +02:00
|
|
|
ap := haspointers(a.Type)
|
|
|
|
|
bp := haspointers(b.Type)
|
2015-02-13 14:40:36 -05:00
|
|
|
if ap != bp {
|
2015-09-19 23:55:27 +02:00
|
|
|
return ap
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-09-19 23:55:27 +02:00
|
|
|
ap = a.Name.Needzero
|
|
|
|
|
bp = b.Name.Needzero
|
2015-02-13 14:40:36 -05:00
|
|
|
if ap != bp {
|
2015-09-19 23:55:27 +02:00
|
|
|
return ap
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-02-20 21:36:12 -08:00
|
|
|
if a.Type.Width != b.Type.Width {
|
|
|
|
|
return a.Type.Width > b.Type.Width
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-09-19 23:55:27 +02:00
|
|
|
return a.Sym.Name < b.Sym.Name
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-02-25 10:35:19 -08:00
|
|
|
// byStackvar implements sort.Interface for []*Node using cmpstackvarlt.
|
|
|
|
|
type byStackVar []*Node
|
|
|
|
|
|
|
|
|
|
func (s byStackVar) Len() int { return len(s) }
|
|
|
|
|
func (s byStackVar) Less(i, j int) bool { return cmpstackvarlt(s[i], s[j]) }
|
|
|
|
|
func (s byStackVar) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
|
|
|
|
|
2015-05-26 21:30:20 -04:00
|
|
|
// stkdelta records the stack offset delta for a node
|
|
|
|
|
// during the compaction of the stack frame to remove
|
|
|
|
|
// unused stack slots.
|
|
|
|
|
var stkdelta = map[*Node]int64{}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
// TODO(lvd) find out where the PAUTO/OLITERAL nodes come from.
|
|
|
|
|
func allocauto(ptxt *obj.Prog) {
|
|
|
|
|
Stksize = 0
|
|
|
|
|
stkptrsize = 0
|
|
|
|
|
|
2016-02-25 10:35:19 -08:00
|
|
|
if len(Curfn.Func.Dcl) == 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mark the PAUTO's unused.
|
2016-02-25 10:35:19 -08:00
|
|
|
for _, ln := range Curfn.Func.Dcl {
|
|
|
|
|
if ln.Class == PAUTO {
|
|
|
|
|
ln.Used = false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
markautoused(ptxt)
|
|
|
|
|
|
2016-02-25 10:35:19 -08:00
|
|
|
sort.Sort(byStackVar(Curfn.Func.Dcl))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// Unused autos are at the end, chop 'em off.
|
2016-02-25 10:35:19 -08:00
|
|
|
n := Curfn.Func.Dcl[0]
|
2015-03-06 21:18:41 +11:00
|
|
|
if n.Class == PAUTO && n.Op == ONAME && !n.Used {
|
2015-02-13 14:40:36 -05:00
|
|
|
// No locals used at all
|
2015-03-25 19:33:01 -07:00
|
|
|
Curfn.Func.Dcl = nil
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
fixautoused(ptxt)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-25 10:35:19 -08:00
|
|
|
for i := 1; i < len(Curfn.Func.Dcl); i++ {
|
|
|
|
|
n = Curfn.Func.Dcl[i]
|
2015-03-06 21:18:41 +11:00
|
|
|
if n.Class == PAUTO && n.Op == ONAME && !n.Used {
|
2016-02-25 10:35:19 -08:00
|
|
|
Curfn.Func.Dcl = Curfn.Func.Dcl[:i]
|
2015-02-13 14:40:36 -05:00
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reassign stack offsets of the locals that are still there.
|
2015-02-23 16:07:24 -05:00
|
|
|
var w int64
|
2016-02-25 10:35:19 -08:00
|
|
|
for _, n := range Curfn.Func.Dcl {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Class != PAUTO || n.Op != ONAME {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dowidth(n.Type)
|
|
|
|
|
w = n.Type.Width
|
|
|
|
|
if w >= Thearch.MAXWIDTH || w < 0 {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("bad width")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
Stksize += w
|
|
|
|
|
Stksize = Rnd(Stksize, int64(n.Type.Align))
|
|
|
|
|
if haspointers(n.Type) {
|
|
|
|
|
stkptrsize = Stksize
|
|
|
|
|
}
|
2016-04-12 12:26:17 -04:00
|
|
|
if Thearch.LinkArch.InFamily(sys.MIPS64, sys.ARM, sys.ARM64, sys.PPC64, sys.S390X) {
|
2015-02-13 14:40:36 -05:00
|
|
|
Stksize = Rnd(Stksize, int64(Widthptr))
|
|
|
|
|
}
|
|
|
|
|
if Stksize >= 1<<31 {
|
|
|
|
|
setlineno(Curfn)
|
|
|
|
|
Yyerror("stack frame too large (>2GB)")
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 21:30:20 -04:00
|
|
|
stkdelta[n] = -Stksize - n.Xoffset
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Stksize = Rnd(Stksize, int64(Widthreg))
|
|
|
|
|
stkptrsize = Rnd(stkptrsize, int64(Widthreg))
|
|
|
|
|
|
|
|
|
|
fixautoused(ptxt)
|
|
|
|
|
|
|
|
|
|
// The debug information needs accurate offsets on the symbols.
|
2016-02-25 10:35:19 -08:00
|
|
|
for _, ln := range Curfn.Func.Dcl {
|
|
|
|
|
if ln.Class != PAUTO || ln.Op != ONAME {
|
2015-02-13 14:40:36 -05:00
|
|
|
continue
|
|
|
|
|
}
|
2016-02-25 10:35:19 -08:00
|
|
|
ln.Xoffset += stkdelta[ln]
|
|
|
|
|
delete(stkdelta, ln)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Cgen_checknil(n *Node) {
|
|
|
|
|
if Disable_checknil != 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ideally we wouldn't see any integer types here, but we do.
|
2016-03-30 15:09:25 -07:00
|
|
|
if n.Type == nil || (!n.Type.IsPtr() && !n.Type.IsInteger() && n.Type.Etype != TUNSAFEPTR) {
|
2015-02-13 14:40:36 -05:00
|
|
|
Dump("checknil", n)
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("bad checknil")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-04-12 10:27:16 -04:00
|
|
|
// Most architectures require that the address to be checked is
|
|
|
|
|
// in a register (it could be in memory).
|
|
|
|
|
needsReg := !Thearch.LinkArch.InFamily(sys.AMD64, sys.I386)
|
|
|
|
|
|
|
|
|
|
// Move the address to be checked into a register if necessary.
|
|
|
|
|
if (needsReg && n.Op != OREGISTER) || !n.Addable || n.Op == OLITERAL {
|
2015-02-23 16:07:24 -05:00
|
|
|
var reg Node
|
2015-03-18 17:26:36 -04:00
|
|
|
Regalloc(®, Types[Tptr], n)
|
|
|
|
|
Cgen(n, ®)
|
2015-02-13 14:40:36 -05:00
|
|
|
Thearch.Gins(obj.ACHECKNIL, ®, nil)
|
2015-03-18 17:26:36 -04:00
|
|
|
Regfree(®)
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Thearch.Gins(obj.ACHECKNIL, n, nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func compile(fn *Node) {
|
|
|
|
|
if Newproc == nil {
|
|
|
|
|
Newproc = Sysfunc("newproc")
|
|
|
|
|
Deferproc = Sysfunc("deferproc")
|
|
|
|
|
Deferreturn = Sysfunc("deferreturn")
|
|
|
|
|
Panicindex = Sysfunc("panicindex")
|
|
|
|
|
panicslice = Sysfunc("panicslice")
|
2015-10-28 13:55:46 -04:00
|
|
|
panicdivide = Sysfunc("panicdivide")
|
2015-02-13 14:40:36 -05:00
|
|
|
throwreturn = Sysfunc("throwreturn")
|
2015-09-18 15:11:30 -07:00
|
|
|
growslice = Sysfunc("growslice")
|
2016-01-25 17:06:54 -08:00
|
|
|
writebarrierptr = Sysfunc("writebarrierptr")
|
|
|
|
|
typedmemmove = Sysfunc("typedmemmove")
|
2015-09-18 15:11:30 -07:00
|
|
|
panicdottype = Sysfunc("panicdottype")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-07 22:05:49 -08:00
|
|
|
defer func(lno int32) {
|
|
|
|
|
lineno = lno
|
|
|
|
|
}(setlineno(fn))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
Curfn = fn
|
|
|
|
|
dowidth(Curfn.Type)
|
|
|
|
|
|
2016-04-24 13:50:26 -07:00
|
|
|
if fn.Nbody.Len() == 0 {
|
2016-04-13 18:37:18 -07:00
|
|
|
if pure_go || strings.HasPrefix(fn.Func.Nname.Sym.Name, "init.") {
|
2015-05-27 10:42:55 -04:00
|
|
|
Yyerror("missing function body for %q", fn.Func.Nname.Sym.Name)
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if Debug['A'] != 0 {
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
emitptrargsmap()
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveerrors()
|
|
|
|
|
|
|
|
|
|
// set up domain for labels
|
|
|
|
|
clearlabels()
|
|
|
|
|
|
2016-04-01 20:11:30 -07:00
|
|
|
if Curfn.Type.FuncType().Outnamed {
|
2015-02-13 14:40:36 -05:00
|
|
|
// add clearing of the output parameters
|
2016-03-17 01:32:18 -07:00
|
|
|
for _, t := range Curfn.Type.Results().Fields().Slice() {
|
2015-02-13 14:40:36 -05:00
|
|
|
if t.Nname != nil {
|
2016-03-07 22:05:49 -08:00
|
|
|
n := Nod(OAS, t.Nname, nil)
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
n = typecheck(n, Etop)
|
2016-02-27 14:31:33 -08:00
|
|
|
Curfn.Nbody.Set(append([]*Node{n}, Curfn.Nbody.Slice()...))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
order(Curfn)
|
|
|
|
|
if nerrors != 0 {
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-09-07 22:19:30 +02:00
|
|
|
hasdefer = false
|
2015-02-13 14:40:36 -05:00
|
|
|
walk(Curfn)
|
|
|
|
|
if nerrors != 0 {
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-10-20 10:00:07 -07:00
|
|
|
if instrumenting {
|
|
|
|
|
instrument(Curfn)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if nerrors != 0 {
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-12 11:01:13 -07:00
|
|
|
// Build an SSA backend function.
|
2016-03-07 22:05:49 -08:00
|
|
|
var ssafn *ssa.Func
|
2015-12-11 20:41:52 -08:00
|
|
|
if shouldssa(Curfn) {
|
|
|
|
|
ssafn = buildssa(Curfn)
|
2015-10-19 11:36:07 -04:00
|
|
|
}
|
2015-04-15 15:51:25 -07:00
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
continpc = nil
|
|
|
|
|
breakpc = nil
|
|
|
|
|
|
2016-03-07 22:05:49 -08:00
|
|
|
pl := newplist()
|
2015-05-27 10:42:55 -04:00
|
|
|
pl.Name = Linksym(Curfn.Func.Nname.Sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
setlineno(Curfn)
|
|
|
|
|
|
2016-03-07 22:05:49 -08:00
|
|
|
var nod1 Node
|
2015-02-13 14:40:36 -05:00
|
|
|
Nodconst(&nod1, Types[TINT32], 0)
|
2016-03-07 22:05:49 -08:00
|
|
|
nam := Curfn.Func.Nname
|
2015-02-13 14:40:36 -05:00
|
|
|
if isblank(nam) {
|
|
|
|
|
nam = nil
|
|
|
|
|
}
|
2016-03-07 22:05:49 -08:00
|
|
|
ptxt := Thearch.Gins(obj.ATEXT, nam, &nod1)
|
2015-06-07 21:45:39 -04:00
|
|
|
Afunclit(&ptxt.From, Curfn.Func.Nname)
|
2015-05-27 15:01:44 -04:00
|
|
|
ptxt.From3 = new(obj.Addr)
|
2015-03-25 19:33:01 -07:00
|
|
|
if fn.Func.Dupok {
|
2015-02-13 14:40:36 -05:00
|
|
|
ptxt.From3.Offset |= obj.DUPOK
|
|
|
|
|
}
|
2015-03-25 19:33:01 -07:00
|
|
|
if fn.Func.Wrapper {
|
2015-02-13 14:40:36 -05:00
|
|
|
ptxt.From3.Offset |= obj.WRAPPER
|
|
|
|
|
}
|
2015-03-25 19:33:01 -07:00
|
|
|
if fn.Func.Needctxt {
|
2015-02-13 14:40:36 -05:00
|
|
|
ptxt.From3.Offset |= obj.NEEDCTXT
|
|
|
|
|
}
|
2016-02-26 13:32:28 -08:00
|
|
|
if fn.Func.Pragma&Nosplit != 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
ptxt.From3.Offset |= obj.NOSPLIT
|
|
|
|
|
}
|
2016-03-10 16:15:26 -05:00
|
|
|
if fn.Func.ReflectMethod {
|
|
|
|
|
ptxt.From3.Offset |= obj.REFLECTMETHOD
|
|
|
|
|
}
|
2016-02-26 13:32:28 -08:00
|
|
|
if fn.Func.Pragma&Systemstack != 0 {
|
2016-03-28 11:34:37 +02:00
|
|
|
ptxt.From.Sym.Cfunc = true
|
2015-06-07 21:45:39 -04:00
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// Clumsy but important.
|
|
|
|
|
// See test/recover.go for test cases and src/reflect/value.go
|
|
|
|
|
// for the actual functions being considered.
|
2016-03-07 22:05:49 -08:00
|
|
|
if myimportpath == "reflect" {
|
2015-05-27 10:42:55 -04:00
|
|
|
if Curfn.Func.Nname.Sym.Name == "callReflect" || Curfn.Func.Nname.Sym.Name == "callMethod" {
|
2015-02-13 14:40:36 -05:00
|
|
|
ptxt.From3.Offset |= obj.WRAPPER
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-18 17:26:36 -04:00
|
|
|
ginit()
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-19 18:17:58 -07:00
|
|
|
gcargs := makefuncdatasym("gcargs·", obj.FUNCDATA_ArgsPointerMaps)
|
|
|
|
|
gclocals := makefuncdatasym("gclocals·", obj.FUNCDATA_LocalsPointerMaps)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-10 16:15:44 -08:00
|
|
|
if obj.Fieldtrack_enabled != 0 && len(Curfn.Func.FieldTrack) > 0 {
|
|
|
|
|
trackSyms := make([]*Sym, 0, len(Curfn.Func.FieldTrack))
|
|
|
|
|
for sym := range Curfn.Func.FieldTrack {
|
|
|
|
|
trackSyms = append(trackSyms, sym)
|
|
|
|
|
}
|
|
|
|
|
sort.Sort(symByName(trackSyms))
|
|
|
|
|
for _, sym := range trackSyms {
|
|
|
|
|
gtrack(sym)
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-02-25 10:35:19 -08:00
|
|
|
for _, n := range fn.Func.Dcl {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Op != ONAME { // might be OTYPE or OLITERAL
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
switch n.Class {
|
2015-04-01 09:38:44 -07:00
|
|
|
case PAUTO, PPARAM, PPARAMOUT:
|
2016-02-25 10:35:19 -08:00
|
|
|
Nodconst(&nod1, Types[TUINTPTR], n.Type.Width)
|
2016-03-07 22:05:49 -08:00
|
|
|
p := Thearch.Gins(obj.ATYPE, n, &nod1)
|
2016-02-25 10:35:19 -08:00
|
|
|
p.From.Gotype = Linksym(ngotype(n))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-11 20:41:52 -08:00
|
|
|
if ssafn != nil {
|
2015-05-12 11:06:44 -07:00
|
|
|
genssa(ssafn, ptxt, gcargs, gclocals)
|
2016-01-28 13:46:30 -08:00
|
|
|
ssafn.Free()
|
2016-03-07 22:05:49 -08:00
|
|
|
} else {
|
|
|
|
|
genlegacy(ptxt, gcargs, gclocals)
|
2015-05-12 11:06:44 -07:00
|
|
|
}
|
2016-03-07 22:05:49 -08:00
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
type symByName []*Sym
|
|
|
|
|
|
|
|
|
|
func (a symByName) Len() int { return len(a) }
|
|
|
|
|
func (a symByName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
|
|
|
|
func (a symByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
|
|
|
|
2016-03-07 22:05:49 -08:00
|
|
|
// genlegacy compiles Curfn using the legacy non-SSA code generator.
|
|
|
|
|
func genlegacy(ptxt *obj.Prog, gcargs, gclocals *Sym) {
|
2016-03-03 15:08:25 -08:00
|
|
|
Genlist(Curfn.Func.Enter)
|
|
|
|
|
Genlist(Curfn.Nbody)
|
2015-03-18 17:26:36 -04:00
|
|
|
gclean()
|
2015-02-13 14:40:36 -05:00
|
|
|
checklabels()
|
|
|
|
|
if nerrors != 0 {
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-03-25 19:33:01 -07:00
|
|
|
if Curfn.Func.Endlineno != 0 {
|
|
|
|
|
lineno = Curfn.Func.Endlineno
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-17 01:47:16 -07:00
|
|
|
if Curfn.Type.Results().NumFields() != 0 {
|
2015-03-18 17:26:36 -04:00
|
|
|
Ginscall(throwreturn, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-18 17:26:36 -04:00
|
|
|
ginit()
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// TODO: Determine when the final cgen_ret can be omitted. Perhaps always?
|
2015-03-18 17:26:36 -04:00
|
|
|
cgen_ret(nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-09-07 22:19:30 +02:00
|
|
|
if hasdefer {
|
2015-02-13 14:40:36 -05:00
|
|
|
// deferreturn pretends to have one uintptr argument.
|
|
|
|
|
// Reserve space for it so stack scanner is happy.
|
|
|
|
|
if Maxarg < int64(Widthptr) {
|
|
|
|
|
Maxarg = int64(Widthptr)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-18 17:26:36 -04:00
|
|
|
gclean()
|
2015-02-13 14:40:36 -05:00
|
|
|
if nerrors != 0 {
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Pc.As = obj.ARET // overwrite AEND
|
|
|
|
|
Pc.Lineno = lineno
|
|
|
|
|
|
|
|
|
|
fixjmp(ptxt)
|
2015-02-17 22:13:49 -05:00
|
|
|
if Debug['N'] == 0 || Debug['R'] != 0 || Debug['P'] != 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
regopt(ptxt)
|
|
|
|
|
nilopt(ptxt)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Thearch.Expandchecks(ptxt)
|
|
|
|
|
|
|
|
|
|
allocauto(ptxt)
|
|
|
|
|
|
|
|
|
|
setlineno(Curfn)
|
2016-03-03 15:49:04 -08:00
|
|
|
if Stksize+Maxarg > 1<<31 {
|
2015-02-13 14:40:36 -05:00
|
|
|
Yyerror("stack frame too large (>2GB)")
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Emit garbage collection symbols.
|
|
|
|
|
liveness(Curfn, ptxt, gcargs, gclocals)
|
|
|
|
|
|
|
|
|
|
Thearch.Defframe(ptxt)
|
|
|
|
|
|
|
|
|
|
if Debug['f'] != 0 {
|
|
|
|
|
frame(0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove leftover instrumentation from the instruction stream.
|
|
|
|
|
removevardef(ptxt)
|
|
|
|
|
}
|