[Openmp-commits] [llvm] [openmp] [openmp][wasm] Allow openmp to compile under emscripten toolchain (PR #95169)
via Openmp-commits
openmp-commits at lists.llvm.org
Wed Jun 12 07:43:08 PDT 2024
https://github.com/arsnyder16 updated https://github.com/llvm/llvm-project/pull/95169
>From 04a0ec468e18d4639514c1554a168e2535728c4e Mon Sep 17 00:00:00 2001
From: arsnyder16 <arsnyder16 at gmail.com>
Date: Tue, 11 Jun 2024 16:27:08 -0400
Subject: [PATCH 1/4] Update kmp_os.h
---
openmp/runtime/src/kmp_os.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/openmp/runtime/src/kmp_os.h b/openmp/runtime/src/kmp_os.h
index 24b40ed32d988..2252f5e7e97a7 100644
--- a/openmp/runtime/src/kmp_os.h
+++ b/openmp/runtime/src/kmp_os.h
@@ -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
>From e39e7dd4eb5368cd63e109847f90a59fd7b35b5a Mon Sep 17 00:00:00 2001
From: arsnyder16 <arsnyder16 at gmail.com>
Date: Tue, 11 Jun 2024 16:27:58 -0400
Subject: [PATCH 2/4] Update kmp_platform.h
---
openmp/runtime/src/kmp_platform.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/openmp/runtime/src/kmp_platform.h b/openmp/runtime/src/kmp_platform.h
index 200fdf697dd0e..9c2215140467d 100644
--- a/openmp/runtime/src/kmp_platform.h
+++ b/openmp/runtime/src/kmp_platform.h
@@ -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
>From 08cd401e7ee6cd47a5e58963f4cb1665d43ec7ee Mon Sep 17 00:00:00 2001
From: arsnyder16 <arsnyder16 at gmail.com>
Date: Wed, 12 Jun 2024 10:41:56 -0400
Subject: [PATCH 3/4] internal linkage
---
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 92213e19c9d9d..943e73e25a38c 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -5341,7 +5341,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(),
>From 56c7edd01852ce6bb28f40277e560487ed500bd9 Mon Sep 17 00:00:00 2001
From: arsnyder16 <arsnyder16 at gmail.com>
Date: Wed, 12 Jun 2024 10:42:59 -0400
Subject: [PATCH 4/4] remove defining globals, now they are internal
---
openmp/runtime/src/z_Linux_asm.S | 20 --------------------
1 file changed, 20 deletions(-)
diff --git a/openmp/runtime/src/z_Linux_asm.S b/openmp/runtime/src/z_Linux_asm.S
index 5b614e26a8337..f119f64647daa 100644
--- a/openmp/runtime/src/z_Linux_asm.S
+++ b/openmp/runtime/src/z_Linux_asm.S
@@ -2452,23 +2452,3 @@ KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr):
.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
More information about the Openmp-commits
mailing list