@@ -14111,6 +14111,25 @@ structures and the code to increment the appropriate value, in a
14111
14111
format that can be written out by a compiler runtime and consumed via
14112
14112
the ``llvm-profdata`` tool.
14113
14113
14114
+ .. FIXME: write complete doc on contextual instrumentation and link from here
14115
+ .. and from llvm.instrprof.callsite.
14116
+
14117
+ The intrinsic is lowered differently for contextual profiling by the
14118
+ ``-ctx-instr-lower`` pass. Here:
14119
+
14120
+ * the entry basic block increment counter is lowered as a call to compiler-rt,
14121
+ to either ``__llvm_ctx_profile_start_context`` or
14122
+ ``__llvm_ctx_profile_get_context``. Either returns a pointer to a context object
14123
+ which contains a buffer into which counter increments can happen. Note that the
14124
+ pointer value returned by compiler-rt may have its LSB set - counter increments
14125
+ happen offset from the address with the LSB cleared.
14126
+
14127
+ * all the other lowerings of ``llvm.instrprof.increment[.step]`` happen within
14128
+ that context.
14129
+
14130
+ * the context is assumed to be a local value to the function, and no concurrency
14131
+ concerns need to be handled by LLVM.
14132
+
14114
14133
'``llvm.instrprof.increment.step``' Intrinsic
14115
14134
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14116
14135
@@ -14156,10 +14175,10 @@ Syntax:
14156
14175
Overview:
14157
14176
"""""""""
14158
14177
14159
- .. FIXME: detail when it's emitted once the support is added
14160
-
14161
14178
The '``llvm.instrprof.callsite``' intrinsic should be emitted before a callsite
14162
- that's not to a "fake" callee (like another intrinsic or asm).
14179
+ that's not to a "fake" callee (like another intrinsic or asm). It is used by
14180
+ contextual profiling and has side-effects. Its lowering happens in IR, and
14181
+ target-specific backends should never encounter it.
14163
14182
14164
14183
Arguments:
14165
14184
""""""""""
@@ -14172,9 +14191,28 @@ The last argument is the called value of the callsite this intrinsic precedes.
14172
14191
14173
14192
Semantics:
14174
14193
""""""""""
14175
- .. FIXME: detail how when the lowering pass is added.
14176
14194
14177
- This is lowered by contextual profiling.
14195
+ This is lowered by contextual profiling. In contextual profiling, functions get,
14196
+ from compiler-rt, a pointer to a context object. The context object consists of
14197
+ a buffer LLVM can use to perform counter increments (i.e. the lowering of
14198
+ ``llvm.instrprof.increment[.step]``. The address range following the counter
14199
+ buffer, ``<num-counters>`` x ``sizeof(ptr)`` - sized, is expected to contain
14200
+ pointers to contexts of functions called from this function ("subcontexts").
14201
+ LLVM does not dereference into that memory region, just calculates GEPs.
14202
+
14203
+ The lowering of ``llvm.instrprof.callsite`` consists of:
14204
+
14205
+ * write to ``__llvm_ctx_profile_expected_callee`` the ``<callsite>`` value;
14206
+
14207
+ * write to ``__llvm_ctx_profile_callsite`` the address into this function's
14208
+ context of the ``<index>`` position into the subcontexts region.
14209
+
14210
+
14211
+ ``__llvm_ctx_profile_{expected_callee|callsite}`` are initialized by compiler-rt
14212
+ and are TLS. They are both vectors of pointers of size 2. The index into each is
14213
+ determined when the current function obtains the pointer to its context from
14214
+ compiler-rt. The pointer's LSB gives the index.
14215
+
14178
14216
14179
14217
'``llvm.instrprof.timestamp``' Intrinsic
14180
14218
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0 commit comments