aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/go-gcc.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2016-09-22 20:32:16 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2016-09-22 20:32:16 +0000
commit0cb904afbe28927d4efb343558e641e35580d72c (patch)
treec603e6261575dd4da3b11d23174440467f68b4db /gcc/go/go-gcc.cc
parent1c681c7bf7e28ceeeb50e90444b89f833f7bcc23 (diff)
downloadgcc-0cb904afbe28927d4efb343558e641e35580d72c.zip
gcc-0cb904afbe28927d4efb343558e641e35580d72c.tar.gz
gcc-0cb904afbe28927d4efb343558e641e35580d72c.tar.bz2
compiler: compile runtime.getcaller{pc,sp} into builtin functions
The runtime functions runtime.getcallerpc and runtime.getcallersp are intended to be efficient ways to get the return and frame address of the caller (that is, the caller of runtime.getcallerpc). In the C code that is implemented by simply using C macros: This patch essentially implements those macros in the Go code. It would be nice if we could just use //extern for this, but it doesn't work because the runtime code passes the right argument. Of course we could change the runtime code, but these are common enough that I'd prefer to avoid the difference from the gc version of the runtime code. This patch corrects the existing declaration of __builtin_return_address to use uint32, rather than uint, for the parameter type. The builtin functions take the C type "unsigned int", which for the targets we use corresponds to the Go type uint32. Not that it should matter, really. Reviewed-on: https://go-review.googlesource.com/29653 From-SVN: r240382
Diffstat (limited to 'gcc/go/go-gcc.cc')
-rw-r--r--gcc/go/go-gcc.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
index a332831..f9ba9d5 100644
--- a/gcc/go/go-gcc.cc
+++ b/gcc/go/go-gcc.cc
@@ -818,13 +818,14 @@ Gcc_backend::Gcc_backend()
math_function_type_long, true, false);
// We use __builtin_return_address in the thunk we build for
- // functions which call recover.
+ // functions which call recover, and for runtime.getcallerpc.
+ t = build_function_type_list(ptr_type_node, unsigned_type_node, NULL_TREE);
this->define_builtin(BUILT_IN_RETURN_ADDRESS, "__builtin_return_address",
- NULL,
- build_function_type_list(ptr_type_node,
- unsigned_type_node,
- NULL_TREE),
- false, false);
+ NULL, t, false, false);
+
+ // The runtime calls __builtin_frame_address for runtime.getcallersp.
+ this->define_builtin(BUILT_IN_FRAME_ADDRESS, "__builtin_frame_address",
+ NULL, t, false, false);
// The compiler uses __builtin_trap for some exception handling
// cases.