mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 00:36:34 +00:00
[openmp][WebAssembly] Allow openmp to compile and run under emscripten toolchain (#95169)
* Separate wasi and emscripten as they have different constraints and abilities * Emscripten mimics Linux/POSIX by statically linking the musl runtime. This allow nearly all KMP_OS_LINUX code paths to work correctly. There are only a few places that need to be adjusted related to dynamic linking (dl_open) * Internally link openmp globals * With CommonLinkage it is needed to emit them in an assembly file, now they are defined and used within each compilation unit * With ExternalLinkage they suffer from duplicate symbols during linking for unnamed globals like reduction/critical * Interestingly this aligns with the TODO comment above this code
This commit is contained in:
parent
6f8e8faa12
commit
f7b2c2e49f
@ -7211,7 +7211,7 @@ OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
|
||||
// create different versions of the function for different OMP internal
|
||||
// variables.
|
||||
auto Linkage = this->M.getTargetTriple().rfind("wasm32") == 0
|
||||
? GlobalValue::ExternalLinkage
|
||||
? GlobalValue::InternalLinkage
|
||||
: GlobalValue::CommonLinkage;
|
||||
auto *GV = new GlobalVariable(M, Ty, /*IsConstant=*/false, Linkage,
|
||||
Constant::getNullValue(Ty), Elem.first(),
|
||||
|
@ -77,7 +77,7 @@
|
||||
|
||||
#if (KMP_OS_LINUX || KMP_OS_WINDOWS || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
|
||||
KMP_OS_DRAGONFLY || KMP_OS_AIX) && \
|
||||
!KMP_OS_WASI
|
||||
!KMP_OS_WASI && !KMP_OS_EMSCRIPTEN
|
||||
#define KMP_AFFINITY_SUPPORTED 1
|
||||
#if KMP_OS_WINDOWS && KMP_ARCH_X86_64
|
||||
#define KMP_GROUP_AFFINITY 1
|
||||
@ -1293,7 +1293,7 @@ bool __kmp_atomic_compare_store_rel(std::atomic<T> *p, T expected, T desired) {
|
||||
extern void *__kmp_lookup_symbol(const char *name, bool next = false);
|
||||
#define KMP_DLSYM(name) __kmp_lookup_symbol(name)
|
||||
#define KMP_DLSYM_NEXT(name) __kmp_lookup_symbol(name, true)
|
||||
#elif KMP_OS_WASI
|
||||
#elif KMP_OS_WASI || KMP_OS_EMSCRIPTEN
|
||||
#define KMP_DLSYM(name) nullptr
|
||||
#define KMP_DLSYM_NEXT(name) nullptr
|
||||
#else
|
||||
|
@ -25,6 +25,7 @@
|
||||
#define KMP_OS_HURD 0
|
||||
#define KMP_OS_SOLARIS 0
|
||||
#define KMP_OS_WASI 0
|
||||
#define KMP_OS_EMSCRIPTEN 0
|
||||
#define KMP_OS_UNIX 0 /* disjunction of KMP_OS_LINUX, KMP_OS_DARWIN etc. */
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -44,6 +45,11 @@
|
||||
#elif (defined __linux__)
|
||||
#undef KMP_OS_LINUX
|
||||
#define KMP_OS_LINUX 1
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
#undef KMP_OS_LINUX
|
||||
#undef KMP_OS_EMSCRIPTEN
|
||||
#define KMP_OS_LINUX 1
|
||||
#define KMP_OS_EMSCRIPTEN 1
|
||||
#else
|
||||
#endif
|
||||
|
||||
@ -77,7 +83,7 @@
|
||||
#define KMP_OS_SOLARIS 1
|
||||
#endif
|
||||
|
||||
#if (defined __wasi__) || (defined __EMSCRIPTEN__)
|
||||
#if (defined __wasi__)
|
||||
#undef KMP_OS_WASI
|
||||
#define KMP_OS_WASI 1
|
||||
#endif
|
||||
|
@ -2452,23 +2452,3 @@ KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr):
|
||||
.section .note.GNU-stack,"",@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
|
||||
|
Loading…
x
Reference in New Issue
Block a user