summaryrefslogtreecommitdiff
path: root/src/runtime/funcdata.h
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-09-12 00:18:20 -0400
committerRuss Cox <rsc@golang.org>2014-09-12 00:18:20 -0400
commit01cc50951b57fd695075fa8a7e53025cf6115da0 (patch)
tree470703fc67a92851fd65b76afa1e16a390a2ee59 /src/runtime/funcdata.h
parenta6669fa5e7d26c7e5f9d61a389450d2c1ef79f1c (diff)
downloadgo-01cc50951b57fd695075fa8a7e53025cf6115da0.tar.gz
cmd/gc: turn Go prototypes into ptr liveness maps for assembly functions
The goal here is to allow assembly functions to appear in the middle of a Go stack (having called other code) and still record enough information about their pointers so that stack copying and garbage collection can handle them precisely. Today, these frames are handled only conservatively. If you write func myfunc(x *float64) (y *int) (with no body, an 'extern' declaration), then the Go compiler now emits a liveness bitmap for use from the assembly definition of myfunc. The bitmap symbol is myfunc.args_stackmap and it contains two bitmaps. The first bitmap, in effect at function entry, marks all inputs as live. The second bitmap, not in effect at function entry, marks the outputs live as well. In funcdata.h, define new assembly macros: GO_ARGS opts in to using the Go compiler-generated liveness bitmap for the current function. GO_RESULTS_INITIALIZED indicates that the results have been initialized and need to be kept live for the remainder of the function; it causes a switch to the second generated bitmap for the assembly code that follows. NO_LOCAL_POINTERS indicates that there are no pointers in the local variables being stored in the function's stack frame. LGTM=khr R=khr CC=golang-codereviews https://codereview.appspot.com/137520043
Diffstat (limited to 'src/runtime/funcdata.h')
-rw-r--r--src/runtime/funcdata.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/runtime/funcdata.h b/src/runtime/funcdata.h
index dc9c41363..5ddc877c2 100644
--- a/src/runtime/funcdata.h
+++ b/src/runtime/funcdata.h
@@ -9,6 +9,7 @@
//
// symtab.go also contains a copy of these constants.
+// TODO(rsc): Remove PCDATA_ArgSize, renumber StackMapIndex to 0.
#define PCDATA_ArgSize 0 /* argument size at CALL instruction */
#define PCDATA_StackMapIndex 1
@@ -16,9 +17,34 @@
#define FUNCDATA_LocalsPointerMaps 1
#define FUNCDATA_DeadValueMaps 2
+// TODO(rsc): Remove ARGSIZE.
// To be used in assembly.
#define ARGSIZE(n) PCDATA $PCDATA_ArgSize, $n
+// Pseudo-assembly statements.
+
+// GO_ARGS, GO_RESULTS_INITIALIZED, and NO_LOCAL_POINTERS are macros
+// that communicate to the runtime information about the location and liveness
+// of pointers in an assembly function's arguments, results, and stack frame.
+// This communication is only required in assembly functions that make calls
+// to other functions that might be preempted or grow the stack.
+// NOSPLIT functions that make no calls do not need to use these macros.
+
+// GO_ARGS indicates that the Go prototype for this assembly function
+// defines the pointer map for the function's arguments.
+// GO_ARGS should be the first instruction in a function that uses it.
+// It can be omitted if there are no arguments at all.
+#define GO_ARGS FUNCDATA $FUNCDATA_ArgsPointerMaps, go_args_stackmap(SB)
+
+// GO_RESULTS_INITIALIZED indicates that the assembly function
+// has initialized the stack space for its results and that those results
+// should be considered live for the remainder of the function.
+#define GO_RESULTS_INITIALIZED FUNCDATA PCDATA $PCDATA_StackMapIndex, 1
+
+// NO_LOCAL_POINTERS indicates that the assembly function stores
+// no pointers to heap objects in its local stack variables.
+#define NO_LOCAL_POINTERS FUNCDATA $FUNCDATA_LocalsPointerMaps, runtime·no_pointers_stackmap(SB)
+
// ArgsSizeUnknown is set in Func.argsize to mark all functions
// whose argument size is unknown (C vararg functions, and
// assembly code without an explicit specification).