LLVM OpenMP
kmp_invoke_microtask.cpp
Go to the documentation of this file.
1#include "kmp.h"
2
3#include <utility>
4
5#if !(KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_MIC || KMP_ARCH_AARCH64 || \
6 KMP_ARCH_PPC64 || KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64 || \
7 KMP_ARCH_ARM || KMP_ARCH_VE || KMP_ARCH_S390X || KMP_ARCH_PPC_XCOFF || \
8 KMP_ARCH_AARCH64_32)
9
10template <size_t> using microtask_argument_t = void *;
11
12template <size_t... Indices>
13static void invokeMicrotask(microtask_t pkfn, int *gtid, int *tid,
14 void *p_argv[], std::index_sequence<Indices...>) {
15 // WebAssembly's `call_indirect` requires the callee type to exactly match the
16 // call site. Cast the variadic microtask_t to the fixed-arity signature that
17 // matches argc before invoking it.
18 using typed_microtask_t =
19 void (*)(int *, int *, microtask_argument_t<Indices>...);
20 (*(typed_microtask_t)pkfn)(gtid, tid, p_argv[Indices]...);
21}
22
23// Keep a bounded set of exact signatures for targets that cannot dynamically
24// construct a variable-argument microtask call.
25int __kmp_invoke_microtask(microtask_t pkfn, int gtid, int tid, int argc,
26 void *p_argv[]
27#if OMPT_SUPPORT
28 ,
29 void **exit_frame_ptr
30#endif
31) {
32#if OMPT_SUPPORT
33 *exit_frame_ptr = OMPT_GET_FRAME_ADDRESS(0);
34#endif
35
36#define KMP_INVOKE_MICROTASK_CASE(N) \
37 case N: \
38 invokeMicrotask(pkfn, &gtid, &tid, p_argv, std::make_index_sequence<N>{}); \
39 break
40
41 switch (argc) {
58 default:
59 fprintf(stderr, "Too many args to microtask: %d!\n", argc);
60 fflush(stderr);
61 exit(-1);
62 }
63
64#undef KMP_INVOKE_MICROTASK_CASE
65
66 return 1;
67}
68
69#endif
void
Definition ittnotify.h:3324
void * microtask_argument_t
#define KMP_INVOKE_MICROTASK_CASE(N)
int __kmp_invoke_microtask(microtask_t pkfn, int gtid, int tid, int argc, void *p_argv[])
static void invokeMicrotask(microtask_t pkfn, int *gtid, int *tid, void *p_argv[], std::index_sequence< Indices... >)
void(* microtask_t)(int *gtid, int *npr,...)
Definition kmp_os.h:1189
#define OMPT_GET_FRAME_ADDRESS(level)