[Openmp-commits] [llvm] [openmp] [openmp][wasm] Allow compiling OpenMP to WebAssembly (PR #71297)
Jonathan Peyton via Openmp-commits
openmp-commits at lists.llvm.org
Tue Nov 28 13:32:56 PST 2023
================
@@ -2286,7 +2286,27 @@ KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr):
#if KMP_OS_LINUX
# if KMP_ARCH_ARM || KMP_ARCH_AARCH64
.section .note.GNU-stack,"",%progbits
-# else
+# elif !KMP_ARCH_WASM
.section .note.GNU-stack,"", at progbits
# endif
#endif
+
+#if KMP_ARCH_WASM
+.data
+.global .gomp_critical_user_
+.global .gomp_critical_user_.var
+.global .gomp_critical_user_.reduction.var
+.global __kmp_unnamed_critical_addr
+.gomp_critical_user_:
+.zero 4
+.size .gomp_critical_user_, 4
+.gomp_critical_user_.var:
+.zero 4
+.size .gomp_critical_user_.var, 4
+.gomp_critical_user_.reduction.var:
+.zero 4
+.size .gomp_critical_user_.reduction.var, 4
+__kmp_unnamed_critical_addr:
+ .4byte .gomp_critical_user_
+ .size __kmp_unnamed_critical_addr, 4
+#endif
----------------
jpeyton52 wrote:
To elaborate here a bit, when a parallel region is called, the task corresponding to the parallel region (microtask_t) that is generated by the compiler is sent through:
`__kmpc_fork_call()` -> `__kmp_fork_call()` -> `__kmp_invoke_microtask(microtask_t, gtid, tid, argc, ...)` -> call the microtask with `argc` number of "shareds"
where the varargs component is a list of pointers to shared variables (or firstprivates). There is a limited, platform-independent implementation which WASM is using inside `z_linux_util.cpp` at around line 2492 which can handle up to 15 args. Anymore than that, and the runtime will error out. The test in `openmp/runtime/test/misc_bugs/many-microtask-args.c` is an example of this limitation.
In `z_Linux_asm.S` there are platform-dependent assembly versions of this function. For WASM, it would be best if an assembly version of the `__kmp_invoke_microtask()` function is created to handle any number of "shareds" passed in.
https://github.com/llvm/llvm-project/pull/71297
More information about the Openmp-commits
mailing list