Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 1 | ===================================== |
| 2 | Garbage Collection Safepoints in LLVM |
| 3 | ===================================== |
| 4 | |
| 5 | .. contents:: |
| 6 | :local: |
| 7 | :depth: 2 |
| 8 | |
| 9 | Status |
| 10 | ======= |
| 11 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 12 | This document describes a set of experimental extensions to LLVM. Use |
| 13 | with caution. Because the intrinsics have experimental status, |
| 14 | compatibility across LLVM releases is not guaranteed. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 15 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 16 | LLVM currently supports an alternate mechanism for conservative |
Philip Reames | e0dd0f2 | 2015-02-25 00:18:04 +0000 | [diff] [blame] | 17 | garbage collection support using the ``gcroot`` intrinsic. The mechanism |
| 18 | described here shares little in common with the alternate ``gcroot`` |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 19 | implementation and it is hoped that this mechanism will eventually |
| 20 | replace the gc_root mechanism. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 21 | |
| 22 | Overview |
| 23 | ======== |
| 24 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 25 | To collect dead objects, garbage collectors must be able to identify |
| 26 | any references to objects contained within executing code, and, |
| 27 | depending on the collector, potentially update them. The collector |
| 28 | does not need this information at all points in code - that would make |
| 29 | the problem much harder - but only at well-defined points in the |
| 30 | execution known as 'safepoints' For most collectors, it is sufficient |
| 31 | to track at least one copy of each unique pointer value. However, for |
| 32 | a collector which wishes to relocate objects directly reachable from |
| 33 | running code, a higher standard is required. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 34 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 35 | One additional challenge is that the compiler may compute intermediate |
| 36 | results ("derived pointers") which point outside of the allocation or |
| 37 | even into the middle of another allocation. The eventual use of this |
| 38 | intermediate value must yield an address within the bounds of the |
| 39 | allocation, but such "exterior derived pointers" may be visible to the |
| 40 | collector. Given this, a garbage collector can not safely rely on the |
| 41 | runtime value of an address to indicate the object it is associated |
| 42 | with. If the garbage collector wishes to move any object, the |
| 43 | compiler must provide a mapping, for each pointer, to an indication of |
| 44 | its allocation. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 45 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 46 | To simplify the interaction between a collector and the compiled code, |
| 47 | most garbage collectors are organized in terms of three abstractions: |
| 48 | load barriers, store barriers, and safepoints. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 49 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 50 | #. A load barrier is a bit of code executed immediately after the |
| 51 | machine load instruction, but before any use of the value loaded. |
| 52 | Depending on the collector, such a barrier may be needed for all |
| 53 | loads, merely loads of a particular type (in the original source |
| 54 | language), or none at all. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 55 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 56 | #. Analogously, a store barrier is a code fragement that runs |
| 57 | immediately before the machine store instruction, but after the |
| 58 | computation of the value stored. The most common use of a store |
| 59 | barrier is to update a 'card table' in a generational garbage |
| 60 | collector. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 61 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 62 | #. A safepoint is a location at which pointers visible to the compiled |
| 63 | code (i.e. currently in registers or on the stack) are allowed to |
| 64 | change. After the safepoint completes, the actual pointer value |
| 65 | may differ, but the 'object' (as seen by the source language) |
| 66 | pointed to will not. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 67 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 68 | Note that the term 'safepoint' is somewhat overloaded. It refers to |
| 69 | both the location at which the machine state is parsable and the |
| 70 | coordination protocol involved in bring application threads to a |
| 71 | point at which the collector can safely use that information. The |
| 72 | term "statepoint" as used in this document refers exclusively to the |
| 73 | former. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 74 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 75 | This document focuses on the last item - compiler support for |
| 76 | safepoints in generated code. We will assume that an outside |
| 77 | mechanism has decided where to place safepoints. From our |
| 78 | perspective, all safepoints will be function calls. To support |
| 79 | relocation of objects directly reachable from values in compiled code, |
| 80 | the collector must be able to: |
| 81 | |
| 82 | #. identify every copy of a pointer (including copies introduced by |
| 83 | the compiler itself) at the safepoint, |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 84 | #. identify which object each pointer relates to, and |
| 85 | #. potentially update each of those copies. |
| 86 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 87 | This document describes the mechanism by which an LLVM based compiler |
| 88 | can provide this information to a language runtime/collector, and |
| 89 | ensure that all pointers can be read and updated if desired. The |
| 90 | heart of the approach is to construct (or rewrite) the IR in a manner |
| 91 | where the possible updates performed by the garbage collector are |
| 92 | explicitly visible in the IR. Doing so requires that we: |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 93 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 94 | #. create a new SSA value for each potentially relocated pointer, and |
| 95 | ensure that no uses of the original (non relocated) value is |
| 96 | reachable after the safepoint, |
| 97 | #. specify the relocation in a way which is opaque to the compiler to |
| 98 | ensure that the optimizer can not introduce new uses of an |
| 99 | unrelocated value after a statepoint. This prevents the optimizer |
| 100 | from performing unsound optimizations. |
| 101 | #. recording a mapping of live pointers (and the allocation they're |
| 102 | associated with) for each statepoint. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 103 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 104 | At the most abstract level, inserting a safepoint can be thought of as |
| 105 | replacing a call instruction with a call to a multiple return value |
| 106 | function which both calls the original target of the call, returns |
| 107 | it's result, and returns updated values for any live pointers to |
| 108 | garbage collected objects. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 109 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 110 | Note that the task of identifying all live pointers to garbage |
| 111 | collected values, transforming the IR to expose a pointer giving the |
| 112 | base object for every such live pointer, and inserting all the |
| 113 | intrinsics correctly is explicitly out of scope for this document. |
Philip Reames | c88d732 | 2015-02-25 01:23:59 +0000 | [diff] [blame] | 114 | The recommended approach is to use the :ref:`utility passes |
| 115 | <statepoint-utilities>` described below. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 116 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 117 | This abstract function call is concretely represented by a sequence of |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 118 | intrinsic calls known collectively as a "statepoint relocation sequence". |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 119 | |
| 120 | Let's consider a simple call in LLVM IR: |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 121 | |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 122 | .. code-block:: llvm |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 123 | |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 124 | define i8 addrspace(1)* @test1(i8 addrspace(1)* %obj) |
| 125 | gc "statepoint-example" { |
| 126 | call void ()* @foo() |
| 127 | ret i8 addrspace(1)* %obj |
| 128 | } |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 129 | |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 130 | Depending on our language we may need to allow a safepoint during the execution |
| 131 | of ``foo``. If so, we need to let the collector update local values in the |
| 132 | current frame. If we don't, we'll be accessing a potential invalid reference |
| 133 | once we eventually return from the call. |
| 134 | |
| 135 | In this example, we need to relocate the SSA value ``%obj``. Since we can't |
| 136 | actually change the value in the SSA value ``%obj``, we need to introduce a new |
| 137 | SSA value ``%obj.relocated`` which represents the potentially changed value of |
| 138 | ``%obj`` after the safepoint and update any following uses appropriately. The |
| 139 | resulting relocation sequence is: |
| 140 | |
| 141 | .. code-block:: llvm |
| 142 | |
| 143 | define i8 addrspace(1)* @test1(i8 addrspace(1)* %obj) |
| 144 | gc "statepoint-example" { |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 145 | %0 = call i32 (void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i8 addrspace(1)* %obj) |
Pat Gavlin | cc0431d | 2015-05-08 18:07:42 +0000 | [diff] [blame] | 146 | %obj.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(i32 %0, i32 4, i32 4) |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 147 | ret i8 addrspace(1)* %obj.relocated |
| 148 | } |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 149 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 150 | Ideally, this sequence would have been represented as a M argument, N |
| 151 | return value function (where M is the number of values being |
| 152 | relocated + the original call arguments and N is the original return |
| 153 | value + each relocated value), but LLVM does not easily support such a |
| 154 | representation. |
| 155 | |
| 156 | Instead, the statepoint intrinsic marks the actual site of the |
| 157 | safepoint or statepoint. The statepoint returns a token value (which |
| 158 | exists only at compile time). To get back the original return value |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 159 | of the call, we use the ``gc.result`` intrinsic. To get the relocation |
| 160 | of each pointer in turn, we use the ``gc.relocate`` intrinsic with the |
| 161 | appropriate index. Note that both the ``gc.relocate`` and ``gc.result`` are |
| 162 | tied to the statepoint. The combination forms a "statepoint relocation |
| 163 | sequence" and represents the entitety of a parseable call or 'statepoint'. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 164 | |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 165 | When lowered, this example would generate the following x86 assembly: |
| 166 | |
| 167 | .. code-block:: gas |
| 168 | |
| 169 | .globl test1 |
| 170 | .align 16, 0x90 |
| 171 | pushq %rax |
| 172 | callq foo |
| 173 | .Ltmp1: |
| 174 | movq (%rsp), %rax # This load is redundant (oops!) |
| 175 | popq %rdx |
| 176 | retq |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 177 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 178 | Each of the potentially relocated values has been spilled to the |
| 179 | stack, and a record of that location has been recorded to the |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 180 | :ref:`Stack Map section <stackmap-section>`. If the garbage collector |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 181 | needs to update any of these pointers during the call, it knows |
| 182 | exactly what to change. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 183 | |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 184 | The relevant parts of the StackMap section for our example are: |
| 185 | |
| 186 | .. code-block:: gas |
| 187 | |
| 188 | # This describes the call site |
| 189 | # Stack Maps: callsite 2882400000 |
| 190 | .quad 2882400000 |
| 191 | .long .Ltmp1-test1 |
| 192 | .short 0 |
| 193 | # .. 8 entries skipped .. |
| 194 | # This entry describes the spill slot which is directly addressable |
| 195 | # off RSP with offset 0. Given the value was spilled with a pushq, |
| 196 | # that makes sense. |
| 197 | # Stack Maps: Loc 8: Direct RSP [encoding: .byte 2, .byte 8, .short 7, .int 0] |
| 198 | .byte 2 |
| 199 | .byte 8 |
| 200 | .short 7 |
| 201 | .long 0 |
| 202 | |
| 203 | This example was taken from the tests for the :ref:`RewriteStatepointsForGC` utility pass. As such, it's full StackMap can be easily examined with the following command. |
| 204 | |
| 205 | .. code-block:: bash |
| 206 | |
| 207 | opt -rewrite-statepoints-for-gc test/Transforms/RewriteStatepointsForGC/basics.ll -S | llc -debug-only=stackmaps |
| 208 | |
| 209 | |
Pat Gavlin | cc0431d | 2015-05-08 18:07:42 +0000 | [diff] [blame] | 210 | GC Transitions |
| 211 | ^^^^^^^^^^^^^^^^^^ |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 212 | |
Pat Gavlin | cc0431d | 2015-05-08 18:07:42 +0000 | [diff] [blame] | 213 | As a practical consideration, many garbage-collected systems allow code that is |
| 214 | collector-aware ("managed code") to call code that is not collector-aware |
| 215 | ("unmanaged code"). It is common that such calls must also be safepoints, since |
| 216 | it is desirable to allow the collector to run during the execution of |
| 217 | unmanaged code. Futhermore, it is common that coordinating the transition from |
| 218 | managed to unmanaged code requires extra code generation at the call site to |
| 219 | inform the collector of the transition. In order to support these needs, a |
| 220 | statepoint may be marked as a GC transition, and data that is necessary to |
| 221 | perform the transition (if any) may be provided as additional arguments to the |
| 222 | statepoint. |
| 223 | |
| 224 | Note that although in many cases statepoints may be inferred to be GC |
| 225 | transitions based on the function symbols involved (e.g. a call from a |
| 226 | function with GC strategy "foo" to a function with GC strategy "bar"), |
| 227 | indirect calls that are also GC transitions must also be supported. This |
| 228 | requirement is the driving force behing the decision to require that GC |
| 229 | transitions are explicitly marked. |
| 230 | |
| 231 | Let's revisit the sample given above, this time treating the call to ``@foo`` |
| 232 | as a GC transition. Depending on our target, the transition code may need to |
| 233 | access some extra state in order to inform the collector of the transition. |
| 234 | Let's assume a hypothetical GC--somewhat unimaginatively named "hypothetical-gc" |
| 235 | --that requires that a TLS variable must be written to before and after a call |
| 236 | to unmanaged code. The resulting relocation sequence is: |
| 237 | |
| 238 | .. code-block:: llvm |
| 239 | |
| 240 | @flag = thread_local global i32 0, align 4 |
| 241 | |
| 242 | define i8 addrspace(1)* @test1(i8 addrspace(1) *%obj) |
| 243 | gc "hypothetical-gc" { |
| 244 | |
| 245 | %0 = call i32 (void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo, i32 0, i32 1, i32* @Flag, i32 0, i8 addrspace(1)* %obj) |
| 246 | %obj.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(i32 %0, i32 4, i32 4) |
| 247 | ret i8 addrspace(1)* %obj.relocated |
| 248 | } |
| 249 | |
| 250 | During lowering, this will result in a instruction selection DAG that looks |
| 251 | something like: |
| 252 | |
Pat Gavlin | 7afaed2 | 2015-05-08 18:37:49 +0000 | [diff] [blame] | 253 | :: |
Pat Gavlin | cc0431d | 2015-05-08 18:07:42 +0000 | [diff] [blame] | 254 | |
| 255 | CALLSEQ_START |
| 256 | ... |
| 257 | GC_TRANSITION_START (lowered i32 *@Flag), SRCVALUE i32* Flag |
| 258 | STATEPOINT |
| 259 | GC_TRANSITION_END (lowered i32 *@Flag), SRCVALUE i32 *Flag |
| 260 | ... |
| 261 | CALLSEQ_END |
| 262 | |
| 263 | In order to generate the necessary transition code, the backend for each target |
| 264 | supported by "hypothetical-gc" must be modified to lower ``GC_TRANSITION_START`` |
| 265 | and ``GC_TRANSITION_END`` nodes appropriately when the "hypothetical-gc" |
| 266 | strategy is in use for a particular function. Assuming that such lowering has |
| 267 | been added for X86, the generated assembly would be: |
| 268 | |
| 269 | .. code-block:: gas |
| 270 | |
| 271 | .globl test1 |
| 272 | .align 16, 0x90 |
| 273 | pushq %rax |
| 274 | movl $1, %fs:Flag@TPOFF |
| 275 | callq foo |
| 276 | movl $0, %fs:Flag@TPOFF |
| 277 | .Ltmp1: |
| 278 | movq (%rsp), %rax # This load is redundant (oops!) |
| 279 | popq %rdx |
| 280 | retq |
| 281 | |
| 282 | Note that the design as presented above is not fully implemented: in particular, |
| 283 | strategy-specific lowering is not present, and all GC transitions are emitted as |
| 284 | as single no-op before and after the call instruction. These no-ops are often |
| 285 | removed by the backend during dead machine instruction elimination. |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 286 | |
| 287 | |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 288 | Intrinsics |
| 289 | =========== |
| 290 | |
Philip Reames | c012728 | 2015-02-24 23:57:26 +0000 | [diff] [blame] | 291 | 'llvm.experimental.gc.statepoint' Intrinsic |
| 292 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 293 | |
| 294 | Syntax: |
| 295 | """"""" |
| 296 | |
| 297 | :: |
| 298 | |
| 299 | declare i32 |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 300 | @llvm.experimental.gc.statepoint(i64 <id>, i32 <num patch bytes>, |
| 301 | func_type <target>, |
Pat Gavlin | cc0431d | 2015-05-08 18:07:42 +0000 | [diff] [blame] | 302 | i64 <#call args>. i64 <flags>, |
Philip Reames | c012728 | 2015-02-24 23:57:26 +0000 | [diff] [blame] | 303 | ... (call parameters), |
Pat Gavlin | cc0431d | 2015-05-08 18:07:42 +0000 | [diff] [blame] | 304 | i64 <# transition args>, ... (transition parameters), |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 305 | i64 <# deopt args>, ... (deopt parameters), |
| 306 | ... (gc parameters)) |
| 307 | |
| 308 | Overview: |
| 309 | """"""""" |
| 310 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 311 | The statepoint intrinsic represents a call which is parse-able by the |
| 312 | runtime. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 313 | |
| 314 | Operands: |
| 315 | """"""""" |
| 316 | |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 317 | The 'id' operand is a constant integer that is reported as the ID |
| 318 | field in the generated stackmap. LLVM does not interpret this |
| 319 | parameter in any way and its meaning is up to the statepoint user to |
| 320 | decide. Note that LLVM is free to duplicate code containing |
| 321 | statepoint calls, and this may transform IR that had a unique 'id' per |
| 322 | lexical call to statepoint to IR that does not. |
| 323 | |
| 324 | If 'num patch bytes' is non-zero then the call instruction |
| 325 | corresponding to the statepoint is not emitted and LLVM emits 'num |
| 326 | patch bytes' bytes of nops in its place. LLVM will emit code to |
| 327 | prepare the function arguments and retrieve the function return value |
| 328 | in accordance to the calling convention; the former before the nop |
| 329 | sequence and the latter after the nop sequence. It is expected that |
| 330 | the user will patch over the 'num patch bytes' bytes of nops with a |
| 331 | calling sequence specific to their runtime before executing the |
| 332 | generated machine code. There are no guarantees with respect to the |
| 333 | alignment of the nop sequence. Unlike :doc:`StackMaps` statepoints do |
| 334 | not have a concept of shadow bytes. |
| 335 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 336 | The 'target' operand is the function actually being called. The |
| 337 | target can be specified as either a symbolic LLVM function, or as an |
| 338 | arbitrary Value of appropriate function type. Note that the function |
| 339 | type must match the signature of the callee and the types of the 'call |
Sanjoy Das | a1d39ba | 2015-05-12 23:52:24 +0000 | [diff] [blame] | 340 | parameters' arguments. If 'num patch bytes' is non-zero then 'target' |
| 341 | has to be the constant pointer null of the appropriate function type. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 342 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 343 | The '#call args' operand is the number of arguments to the actual |
| 344 | call. It must exactly match the number of arguments passed in the |
| 345 | 'call parameters' variable length section. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 346 | |
Pat Gavlin | cc0431d | 2015-05-08 18:07:42 +0000 | [diff] [blame] | 347 | The 'flags' operand is used to specify extra information about the |
| 348 | statepoint. This is currently only used to mark certain statepoints |
| 349 | as GC transitions. This operand is a 64-bit integer with the following |
| 350 | layout, where bit 0 is the least significant bit: |
| 351 | |
| 352 | +-------+---------------------------------------------------+ |
| 353 | | Bit # | Usage | |
| 354 | +=======+===================================================+ |
| 355 | | 0 | Set if the statepoint is a GC transition, cleared | |
| 356 | | | otherwise. | |
| 357 | +-------+---------------------------------------------------+ |
| 358 | | 1-63 | Reserved for future use; must be cleared. | |
| 359 | +-------+---------------------------------------------------+ |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 360 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 361 | The 'call parameters' arguments are simply the arguments which need to |
| 362 | be passed to the call target. They will be lowered according to the |
| 363 | specified calling convention and otherwise handled like a normal call |
| 364 | instruction. The number of arguments must exactly match what is |
| 365 | specified in '# call args'. The types must match the signature of |
| 366 | 'target'. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 367 | |
Pat Gavlin | cc0431d | 2015-05-08 18:07:42 +0000 | [diff] [blame] | 368 | The 'transition parameters' arguments contain an arbitrary list of |
| 369 | Values which need to be passed to GC transition code. They will be |
| 370 | lowered and passed as operands to the appropriate GC_TRANSITION nodes |
| 371 | in the selection DAG. It is assumed that these arguments must be |
| 372 | available before and after (but not necessarily during) the execution |
| 373 | of the callee. The '# transition args' field indicates how many operands |
| 374 | are to be interpreted as 'transition parameters'. |
| 375 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 376 | The 'deopt parameters' arguments contain an arbitrary list of Values |
| 377 | which is meaningful to the runtime. The runtime may read any of these |
| 378 | values, but is assumed not to modify them. If the garbage collector |
| 379 | might need to modify one of these values, it must also be listed in |
| 380 | the 'gc pointer' argument list. The '# deopt args' field indicates |
| 381 | how many operands are to be interpreted as 'deopt parameters'. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 382 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 383 | The 'gc parameters' arguments contain every pointer to a garbage |
| 384 | collector object which potentially needs to be updated by the garbage |
| 385 | collector. Note that the argument list must explicitly contain a base |
| 386 | pointer for every derived pointer listed. The order of arguments is |
| 387 | unimportant. Unlike the other variable length parameter sets, this |
| 388 | list is not length prefixed. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 389 | |
| 390 | Semantics: |
| 391 | """""""""" |
| 392 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 393 | A statepoint is assumed to read and write all memory. As a result, |
| 394 | memory operations can not be reordered past a statepoint. It is |
| 395 | illegal to mark a statepoint as being either 'readonly' or 'readnone'. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 396 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 397 | Note that legal IR can not perform any memory operation on a 'gc |
| 398 | pointer' argument of the statepoint in a location statically reachable |
| 399 | from the statepoint. Instead, the explicitly relocated value (from a |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 400 | ``gc.relocate``) must be used. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 401 | |
Philip Reames | c012728 | 2015-02-24 23:57:26 +0000 | [diff] [blame] | 402 | 'llvm.experimental.gc.result' Intrinsic |
| 403 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 404 | |
| 405 | Syntax: |
| 406 | """"""" |
| 407 | |
| 408 | :: |
| 409 | |
| 410 | declare type* |
Philip Reames | c012728 | 2015-02-24 23:57:26 +0000 | [diff] [blame] | 411 | @llvm.experimental.gc.result(i32 %statepoint_token) |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 412 | |
| 413 | Overview: |
| 414 | """"""""" |
| 415 | |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 416 | ``gc.result`` extracts the result of the original call instruction |
| 417 | which was replaced by the ``gc.statepoint``. The ``gc.result`` |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 418 | intrinsic is actually a family of three intrinsics due to an |
| 419 | implementation limitation. Other than the type of the return value, |
| 420 | the semantics are the same. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 421 | |
| 422 | Operands: |
| 423 | """"""""" |
| 424 | |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 425 | The first and only argument is the ``gc.statepoint`` which starts |
| 426 | the safepoint sequence of which this ``gc.result`` is a part. |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 427 | Despite the typing of this as a generic i32, *only* the value defined |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 428 | by a ``gc.statepoint`` is legal here. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 429 | |
| 430 | Semantics: |
| 431 | """""""""" |
| 432 | |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 433 | The ``gc.result`` represents the return value of the call target of |
| 434 | the ``statepoint``. The type of the ``gc.result`` must exactly match |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 435 | the type of the target. If the call target returns void, there will |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 436 | be no ``gc.result``. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 437 | |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 438 | A ``gc.result`` is modeled as a 'readnone' pure function. It has no |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 439 | side effects since it is just a projection of the return value of the |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 440 | previous call represented by the ``gc.statepoint``. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 441 | |
Philip Reames | c012728 | 2015-02-24 23:57:26 +0000 | [diff] [blame] | 442 | 'llvm.experimental.gc.relocate' Intrinsic |
| 443 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 444 | |
| 445 | Syntax: |
| 446 | """"""" |
| 447 | |
| 448 | :: |
| 449 | |
Philip Reames | c012728 | 2015-02-24 23:57:26 +0000 | [diff] [blame] | 450 | declare <pointer type> |
| 451 | @llvm.experimental.gc.relocate(i32 %statepoint_token, |
| 452 | i32 %base_offset, |
| 453 | i32 %pointer_offset) |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 454 | |
| 455 | Overview: |
| 456 | """"""""" |
| 457 | |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 458 | A ``gc.relocate`` returns the potentially relocated value of a pointer |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 459 | at the safepoint. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 460 | |
| 461 | Operands: |
| 462 | """"""""" |
| 463 | |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 464 | The first argument is the ``gc.statepoint`` which starts the |
| 465 | safepoint sequence of which this ``gc.relocation`` is a part. |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 466 | Despite the typing of this as a generic i32, *only* the value defined |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 467 | by a ``gc.statepoint`` is legal here. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 468 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 469 | The second argument is an index into the statepoints list of arguments |
| 470 | which specifies the base pointer for the pointer being relocated. |
| 471 | This index must land within the 'gc parameter' section of the |
| 472 | statepoint's argument list. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 473 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 474 | The third argument is an index into the statepoint's list of arguments |
| 475 | which specify the (potentially) derived pointer being relocated. It |
| 476 | is legal for this index to be the same as the second argument |
| 477 | if-and-only-if a base pointer is being relocated. This index must land |
| 478 | within the 'gc parameter' section of the statepoint's argument list. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 479 | |
| 480 | Semantics: |
| 481 | """""""""" |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 482 | |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 483 | The return value of ``gc.relocate`` is the potentially relocated value |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 484 | of the pointer specified by it's arguments. It is unspecified how the |
| 485 | value of the returned pointer relates to the argument to the |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 486 | ``gc.statepoint`` other than that a) it points to the same source |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 487 | language object with the same offset, and b) the 'based-on' |
| 488 | relationship of the newly relocated pointers is a projection of the |
| 489 | unrelocated pointers. In particular, the integer value of the pointer |
| 490 | returned is unspecified. |
| 491 | |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 492 | A ``gc.relocate`` is modeled as a ``readnone`` pure function. It has no |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 493 | side effects since it is just a way to extract information about work |
Philip Reames | c609a59 | 2015-02-25 00:22:07 +0000 | [diff] [blame] | 494 | done during the actual call modeled by the ``gc.statepoint``. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 495 | |
Philip Reames | e662550 | 2015-02-25 23:22:43 +0000 | [diff] [blame] | 496 | .. _statepoint-stackmap-format: |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 497 | |
Philip Reames | ce5ff37 | 2014-12-04 00:45:23 +0000 | [diff] [blame] | 498 | Stack Map Format |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 499 | ================ |
| 500 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 501 | Locations for each pointer value which may need read and/or updated by |
| 502 | the runtime or collector are provided via the :ref:`Stack Map format |
| 503 | <stackmap-format>` specified in the PatchPoint documentation. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 504 | |
| 505 | Each statepoint generates the following Locations: |
| 506 | |
Pat Gavlin | c7dc6d6ee | 2015-05-12 19:50:19 +0000 | [diff] [blame] | 507 | * Constant which describes the calling convention of the call target. This |
| 508 | constant is a valid :ref:`calling convention identifier <callingconv>` for |
| 509 | the version of LLVM used to generate the stackmap. No additional compatibility |
| 510 | guarantees are made for this constant over what LLVM provides elsewhere w.r.t. |
| 511 | these identifiers. |
| 512 | * Constant which describes the flags passed to the statepoint intrinsic |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 513 | * Constant which describes number of following deopt *Locations* (not |
| 514 | operands) |
| 515 | * Variable number of Locations, one for each deopt parameter listed in |
| 516 | the IR statepoint (same number as described by previous Constant) |
| 517 | * Variable number of Locations pairs, one pair for each unique pointer |
| 518 | which needs relocated. The first Location in each pair describes |
| 519 | the base pointer for the object. The second is the derived pointer |
| 520 | actually being relocated. It is guaranteed that the base pointer |
| 521 | must also appear explicitly as a relocation pair if used after the |
| 522 | statepoint. There may be fewer pairs then gc parameters in the IR |
| 523 | statepoint. Each *unique* pair will occur at least once; duplicates |
| 524 | are possible. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 525 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 526 | Note that the Locations used in each section may describe the same |
| 527 | physical location. e.g. A stack slot may appear as a deopt location, |
| 528 | a gc base pointer, and a gc derived pointer. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 529 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 530 | The LiveOut section of the StkMapRecord will be empty for a statepoint |
| 531 | record. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 532 | |
| 533 | Safepoint Semantics & Verification |
| 534 | ================================== |
| 535 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 536 | The fundamental correctness property for the compiled code's |
| 537 | correctness w.r.t. the garbage collector is a dynamic one. It must be |
| 538 | the case that there is no dynamic trace such that a operation |
| 539 | involving a potentially relocated pointer is observably-after a |
| 540 | safepoint which could relocate it. 'observably-after' is this usage |
| 541 | means that an outside observer could observe this sequence of events |
| 542 | in a way which precludes the operation being performed before the |
| 543 | safepoint. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 544 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 545 | To understand why this 'observable-after' property is required, |
| 546 | consider a null comparison performed on the original copy of a |
| 547 | relocated pointer. Assuming that control flow follows the safepoint, |
| 548 | there is no way to observe externally whether the null comparison is |
| 549 | performed before or after the safepoint. (Remember, the original |
| 550 | Value is unmodified by the safepoint.) The compiler is free to make |
| 551 | either scheduling choice. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 552 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 553 | The actual correctness property implemented is slightly stronger than |
| 554 | this. We require that there be no *static path* on which a |
| 555 | potentially relocated pointer is 'observably-after' it may have been |
| 556 | relocated. This is slightly stronger than is strictly necessary (and |
| 557 | thus may disallow some otherwise valid programs), but greatly |
| 558 | simplifies reasoning about correctness of the compiled code. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 559 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 560 | By construction, this property will be upheld by the optimizer if |
| 561 | correctly established in the source IR. This is a key invariant of |
| 562 | the design. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 563 | |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 564 | The existing IR Verifier pass has been extended to check most of the |
| 565 | local restrictions on the intrinsics mentioned in their respective |
| 566 | documentation. The current implementation in LLVM does not check the |
| 567 | key relocation invariant, but this is ongoing work on developing such |
| 568 | a verifier. Please ask on llvmdev if you're interested in |
| 569 | experimenting with the current version. |
Philip Reames | f612322 | 2014-12-02 19:37:00 +0000 | [diff] [blame] | 570 | |
Philip Reames | c88d732 | 2015-02-25 01:23:59 +0000 | [diff] [blame] | 571 | .. _statepoint-utilities: |
| 572 | |
| 573 | Utility Passes for Safepoint Insertion |
| 574 | ====================================== |
| 575 | |
| 576 | .. _RewriteStatepointsForGC: |
| 577 | |
| 578 | RewriteStatepointsForGC |
| 579 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 580 | |
| 581 | The pass RewriteStatepointsForGC transforms a functions IR by replacing a |
| 582 | ``gc.statepoint`` (with an optional ``gc.result``) with a full relocation |
| 583 | sequence, including all required ``gc.relocates``. To function, the pass |
| 584 | requires that the GC strategy specified for the function be able to reliably |
| 585 | distinguish between GC references and non-GC references in IR it is given. |
| 586 | |
| 587 | As an example, given this code: |
| 588 | |
| 589 | .. code-block:: llvm |
| 590 | |
| 591 | define i8 addrspace(1)* @test1(i8 addrspace(1)* %obj) |
| 592 | gc "statepoint-example" { |
Sanjoy Das | 9158274 | 2015-05-13 20:11:24 +0000 | [diff] [blame^] | 593 | call i32 (i64, i32, void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) |
Philip Reames | c88d732 | 2015-02-25 01:23:59 +0000 | [diff] [blame] | 594 | ret i8 addrspace(1)* %obj |
| 595 | } |
| 596 | |
| 597 | The pass would produce this IR: |
| 598 | |
| 599 | .. code-block:: llvm |
| 600 | |
| 601 | define i8 addrspace(1)* @test1(i8 addrspace(1)* %obj) |
| 602 | gc "statepoint-example" { |
Sanjoy Das | 9158274 | 2015-05-13 20:11:24 +0000 | [diff] [blame^] | 603 | %0 = call i32 (i64, i32, void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i8 addrspace(1)* %obj) |
Philip Reames | c88d732 | 2015-02-25 01:23:59 +0000 | [diff] [blame] | 604 | %obj.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(i32 %0, i32 9, i32 9) |
| 605 | ret i8 addrspace(1)* %obj.relocated |
| 606 | } |
| 607 | |
| 608 | In the above examples, the addrspace(1) marker on the pointers is the mechanism |
| 609 | that the ``statepoint-example`` GC strategy uses to distinguish references from |
| 610 | non references. Address space 1 is not globally reserved for this purpose. |
| 611 | |
| 612 | This pass can be used an utility function by a language frontend that doesn't |
| 613 | want to manually reason about liveness, base pointers, or relocation when |
| 614 | constructing IR. As currently implemented, RewriteStatepointsForGC must be |
| 615 | run after SSA construction (i.e. mem2ref). |
| 616 | |
| 617 | |
| 618 | In practice, RewriteStatepointsForGC can be run much later in the pass |
| 619 | pipeline, after most optimization is already done. This helps to improve |
| 620 | the quality of the generated code when compiled with garbage collection support. |
| 621 | In the long run, this is the intended usage model. At this time, a few details |
| 622 | have yet to be worked out about the semantic model required to guarantee this |
| 623 | is always correct. As such, please use with caution and report bugs. |
| 624 | |
| 625 | .. _PlaceSafepoints: |
| 626 | |
| 627 | PlaceSafepoints |
| 628 | ^^^^^^^^^^^^^^^^ |
| 629 | |
| 630 | The pass PlaceSafepoints transforms a function's IR by replacing any call or |
| 631 | invoke instructions with appropriate ``gc.statepoint`` and ``gc.result`` pairs, |
| 632 | and inserting safepoint polls sufficient to ensure running code checks for a |
| 633 | safepoint request on a timely manner. This pass is expected to be run before |
| 634 | RewriteStatepointsForGC and thus does not produce full relocation sequences. |
| 635 | |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 636 | As an example, given input IR of the following: |
| 637 | |
| 638 | .. code-block:: llvm |
| 639 | |
| 640 | define void @test() gc "statepoint-example" { |
| 641 | call void @foo() |
| 642 | ret void |
| 643 | } |
| 644 | |
| 645 | declare void @do_safepoint() |
| 646 | define void @gc.safepoint_poll() { |
| 647 | call void @do_safepoint() |
| 648 | ret void |
| 649 | } |
| 650 | |
| 651 | |
| 652 | This pass would produce the following IR: |
| 653 | |
| 654 | .. code-block:: llvm |
| 655 | |
| 656 | define void @test() gc "statepoint-example" { |
Sanjoy Das | 9158274 | 2015-05-13 20:11:24 +0000 | [diff] [blame^] | 657 | %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0) |
| 658 | %safepoint_token1 = call i32 (i64, i32, void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0) |
Philip Reames | 5017ab5 | 2015-02-26 01:18:21 +0000 | [diff] [blame] | 659 | ret void |
| 660 | } |
| 661 | |
| 662 | In this case, we've added an (unconditional) entry safepoint poll and converted the call into a ``gc.statepoint``. Note that despite appearances, the entry poll is not necessarily redundant. We'd have to know that ``foo`` and ``test`` were not mutually recursive for the poll to be redundant. In practice, you'd probably want to your poll definition to contain a conditional branch of some form. |
| 663 | |
| 664 | |
Philip Reames | c88d732 | 2015-02-25 01:23:59 +0000 | [diff] [blame] | 665 | At the moment, PlaceSafepoints can insert safepoint polls at method entry and |
| 666 | loop backedges locations. Extending this to work with return polls would be |
| 667 | straight forward if desired. |
| 668 | |
| 669 | PlaceSafepoints includes a number of optimizations to avoid placing safepoint |
| 670 | polls at particular sites unless needed to ensure timely execution of a poll |
| 671 | under normal conditions. PlaceSafepoints does not attempt to ensure timely |
| 672 | execution of a poll under worst case conditions such as heavy system paging. |
| 673 | |
| 674 | The implementation of a safepoint poll action is specified by looking up a |
| 675 | function of the name ``gc.safepoint_poll`` in the containing Module. The body |
| 676 | of this function is inserted at each poll site desired. While calls or invokes |
| 677 | inside this method are transformed to a ``gc.statepoints``, recursive poll |
| 678 | insertion is not performed. |
| 679 | |
| 680 | If you are scheduling the RewriteStatepointsForGC pass late in the pass order, |
| 681 | you should probably schedule this pass immediately before it. The exception |
| 682 | would be if you need to preserve abstract frame information (e.g. for |
| 683 | deoptimization or introspection) at safepoints. In that case, ask on the |
| 684 | llvmdev mailing list for suggestions. |
| 685 | |
| 686 | |
Philip Reames | 8333152 | 2014-12-04 18:33:28 +0000 | [diff] [blame] | 687 | Bugs and Enhancements |
| 688 | ===================== |
Philip Reames | dfc238b | 2015-01-02 19:46:49 +0000 | [diff] [blame] | 689 | |
| 690 | Currently known bugs and enhancements under consideration can be |
| 691 | tracked by performing a `bugzilla search |
| 692 | <http://llvm.org/bugs/buglist.cgi?cmdtype=runnamed&namedcmd=Statepoint%20Bugs&list_id=64342>`_ |
| 693 | for [Statepoint] in the summary field. When filing new bugs, please |
| 694 | use this tag so that interested parties see the newly filed bug. As |
| 695 | with most LLVM features, design discussions take place on `llvmdev |
| 696 | <http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev>`_, and patches |
| 697 | should be sent to `llvm-commits |
| 698 | <http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits>`_ for review. |
Philip Reames | 8333152 | 2014-12-04 18:33:28 +0000 | [diff] [blame] | 699 | |