Skip to content

Commit 68ea91d

Browse files
[openmp][wasm] Allow compiling OpenMP to WebAssembly (#71297)
This change allows building the static OpenMP runtime, `libomp.a`, as WebAssembly. It builds on the work done in [D142593] but goes further in several ways: - it makes the OpenMP CMake files more WebAssembly-aware - it conditions much more code (or code that had been refactored since [D142593]) for `KMP_ARCH_WASM` and `KMP_OS_WASI` - it fixes a Clang crash due to unimplemented common symbols in WebAssembly The commit messages have more details. Please understand this PR as a start, not the completed work, for WebAssembly support in OpenMP. Getting the tests running somehow would be a good next step, e.g.; but what is contained here works, at least with recent versions of [wasi-sdk] and engines that support [wasi-threads]. I suspect the same is true for Emscripten and browsers, but I have not tested that workflow. [D142593]: https://reviews.llvm.org/D142593 [wasi-sdk]: https://github.com/WebAssembly/wasi-sdk [wasi-threads]: https://github.com/WebAssembly/wasi-threads --------- Co-authored-by: Atanas Atanasov <[email protected]>
1 parent 36477f7 commit 68ea91d

File tree

14 files changed

+152
-68
lines changed

14 files changed

+152
-68
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5213,10 +5213,13 @@ OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
52135213
// variable for possibly changing that to internal or private, or maybe
52145214
// create different versions of the function for different OMP internal
52155215
// variables.
5216-
auto *GV = new GlobalVariable(
5217-
M, Ty, /*IsConstant=*/false, GlobalValue::CommonLinkage,
5218-
Constant::getNullValue(Ty), Elem.first(),
5219-
/*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpace);
5216+
auto Linkage = this->M.getTargetTriple().rfind("wasm32") == 0
5217+
? GlobalValue::ExternalLinkage
5218+
: GlobalValue::CommonLinkage;
5219+
auto *GV = new GlobalVariable(M, Ty, /*IsConstant=*/false, Linkage,
5220+
Constant::getNullValue(Ty), Elem.first(),
5221+
/*InsertBefore=*/nullptr,
5222+
GlobalValue::NotThreadLocal, AddressSpace);
52205223
const DataLayout &DL = M.getDataLayout();
52215224
const llvm::Align TypeAlign = DL.getABITypeAlign(Ty);
52225225
const llvm::Align PtrAlign = DL.getPointerABIAlignment(AddressSpace);

openmp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ set(ENABLE_LIBOMPTARGET ON)
9494
# Since the device plugins are only supported on Linux anyway,
9595
# there is no point in trying to compile libomptarget on other OSes.
9696
# 32-bit systems are not supported either.
97-
if (APPLE OR WIN32 OR NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
97+
if (APPLE OR WIN32 OR WASM OR NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
9898
set(ENABLE_LIBOMPTARGET OFF)
9999
endif()
100100

openmp/runtime/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if(${OPENMP_STANDALONE_BUILD})
3030
# If adding a new architecture, take a look at cmake/LibompGetArchitecture.cmake
3131
libomp_get_architecture(LIBOMP_DETECTED_ARCH)
3232
set(LIBOMP_ARCH ${LIBOMP_DETECTED_ARCH} CACHE STRING
33-
"The architecture to build for (x86_64/i386/arm/ppc64/ppc64le/aarch64/mic/mips/mips64/riscv64/loongarch64/ve/s390x).")
33+
"The architecture to build for (x86_64/i386/arm/ppc64/ppc64le/aarch64/mic/mips/mips64/riscv64/loongarch64/ve/s390x/wasm32).")
3434
# Should assertions be enabled? They are on by default.
3535
set(LIBOMP_ENABLE_ASSERTIONS TRUE CACHE BOOL
3636
"enable assertions?")
@@ -67,6 +67,8 @@ else() # Part of LLVM build
6767
set(LIBOMP_ARCH ve)
6868
elseif(LIBOMP_NATIVE_ARCH MATCHES "s390x")
6969
set(LIBOMP_ARCH s390x)
70+
elseif(LIBOMP_NATIVE_ARCH MATCHES "wasm")
71+
set(LIBOMP_ARCH wasm32)
7072
else()
7173
# last ditch effort
7274
libomp_get_architecture(LIBOMP_ARCH)
@@ -87,7 +89,7 @@ if(LIBOMP_ARCH STREQUAL "aarch64")
8789
endif()
8890
endif()
8991

90-
libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 aarch64_a64fx mic mips mips64 riscv64 loongarch64 ve s390x)
92+
libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 aarch64_a64fx mic mips mips64 riscv64 loongarch64 ve s390x wasm32)
9193

9294
set(LIBOMP_LIB_TYPE normal CACHE STRING
9395
"Performance,Profiling,Stubs library (normal/profile/stubs)")
@@ -168,6 +170,7 @@ set(RISCV64 FALSE)
168170
set(LOONGARCH64 FALSE)
169171
set(VE FALSE)
170172
set(S390X FALSE)
173+
set(WASM FALSE)
171174
if("${LIBOMP_ARCH}" STREQUAL "i386" OR "${LIBOMP_ARCH}" STREQUAL "32") # IA-32 architecture
172175
set(IA32 TRUE)
173176
elseif("${LIBOMP_ARCH}" STREQUAL "x86_64" OR "${LIBOMP_ARCH}" STREQUAL "32e") # Intel(R) 64 architecture
@@ -198,6 +201,8 @@ elseif("${LIBOMP_ARCH}" STREQUAL "ve") # VE architecture
198201
set(VE TRUE)
199202
elseif("${LIBOMP_ARCH}" STREQUAL "s390x") # S390x (Z) architecture
200203
set(S390X TRUE)
204+
elseif("${LIBOMP_ARCH}" STREQUAL "wasm32") # WebAssembly architecture
205+
set(WASM TRUE)
201206
endif()
202207

203208
# Set some flags based on build_type
@@ -306,6 +311,11 @@ endif()
306311
set(LIBOMP_ENABLE_SHARED TRUE CACHE BOOL
307312
"Shared library instead of static library?")
308313

314+
if(WASM)
315+
libomp_warning_say("The WebAssembly build currently only supports static libraries; forcing LIBOMP_ENABLE_SHARED to false")
316+
set(LIBOMP_ENABLE_SHARED FALSE)
317+
endif()
318+
309319
if(WIN32 AND NOT LIBOMP_ENABLE_SHARED)
310320
libomp_error_say("Static libraries requested but not available on Windows")
311321
endif()

openmp/runtime/cmake/LibompGetArchitecture.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ function(libomp_get_architecture return_arch)
5353
#error ARCHITECTURE=ve
5454
#elif defined(__s390x__)
5555
#error ARCHITECTURE=s390x
56+
#elif defined(__wasm32__)
57+
#error ARCHITECTURE=wasm32
5658
#else
5759
#error ARCHITECTURE=UnknownArchitecture
5860
#endif

openmp/runtime/cmake/config-ix.cmake

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,20 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Intel" OR CMAKE_C_COMPILER_ID STREQUAL "IntelLL
150150
check_library_exists(irc_pic _intel_fast_memcpy "" LIBOMP_HAVE_IRC_PIC_LIBRARY)
151151
endif()
152152

153-
# Checking Threading requirements
154-
find_package(Threads REQUIRED)
155-
if(WIN32)
156-
if(NOT CMAKE_USE_WIN32_THREADS_INIT)
157-
libomp_error_say("Need Win32 thread interface on Windows.")
158-
endif()
159-
else()
160-
if(NOT CMAKE_USE_PTHREADS_INIT)
161-
libomp_error_say("Need pthread interface on Unix-like systems.")
153+
# Checking threading requirements. Note that compiling to WebAssembly threads
154+
# with either the Emscripten or wasi-threads flavor ends up using the pthreads
155+
# interface in a WebAssembly-compiled libc; CMake does not yet know how to
156+
# detect this.
157+
if (NOT WASM)
158+
find_package(Threads REQUIRED)
159+
if(WIN32)
160+
if(NOT CMAKE_USE_WIN32_THREADS_INIT)
161+
libomp_error_say("Need Win32 thread interface on Windows.")
162+
endif()
163+
else()
164+
if(NOT CMAKE_USE_PTHREADS_INIT)
165+
libomp_error_say("Need pthread interface on Unix-like systems.")
166+
endif()
162167
endif()
163168
endif()
164169

openmp/runtime/src/kmp.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@
6363
#undef KMP_CANCEL_THREADS
6464
#endif
6565

66+
// Some WASI targets (e.g., wasm32-wasi-threads) do not support thread
67+
// cancellation.
68+
#if KMP_OS_WASI
69+
#undef KMP_CANCEL_THREADS
70+
#endif
71+
72+
#if !KMP_OS_WASI
6673
#include <signal.h>
74+
#endif
6775
#include <stdarg.h>
6876
#include <stddef.h>
6977
#include <stdio.h>
@@ -124,7 +132,7 @@ class kmp_stats_list;
124132
#endif
125133
#include "kmp_i18n.h"
126134

127-
#define KMP_HANDLE_SIGNALS (KMP_OS_UNIX || KMP_OS_WINDOWS)
135+
#define KMP_HANDLE_SIGNALS ((KMP_OS_UNIX && !KMP_OS_WASI) || KMP_OS_WINDOWS)
128136

129137
#include "kmp_wrapper_malloc.h"
130138
#if KMP_OS_UNIX
@@ -601,7 +609,9 @@ typedef int PACKED_REDUCTION_METHOD_T;
601609
#endif
602610

603611
#if KMP_OS_UNIX
612+
#if !KMP_OS_WASI
604613
#include <dlfcn.h>
614+
#endif
605615
#include <pthread.h>
606616
#endif
607617

@@ -1340,6 +1350,10 @@ extern kmp_uint64 __kmp_now_nsec();
13401350
/* TODO: tune for KMP_OS_SOLARIS */
13411351
#define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
13421352
#define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
1353+
#elif KMP_OS_WASI
1354+
/* TODO: tune for KMP_OS_WASI */
1355+
#define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
1356+
#define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
13431357
#endif
13441358

13451359
#if KMP_ARCH_X86 || KMP_ARCH_X86_64

openmp/runtime/src/kmp_ftn_entry.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ int FTN_STDCALL KMP_EXPAND_NAME(FTN_GET_THREAD_NUM)(void) {
593593
return 0;
594594
}
595595
--gtid; // We keep (gtid+1) in TLS
596-
#elif KMP_OS_LINUX
596+
#elif KMP_OS_LINUX || KMP_OS_WASI
597597
#ifdef KMP_TDATA_GTID
598598
if (__kmp_gtid_mode >= 3) {
599599
if ((gtid = __kmp_gtid) == KMP_GTID_DNE) {
@@ -1043,7 +1043,7 @@ void FTN_STDCALL KMP_EXPAND_NAME(FTN_SET_DEFAULT_DEVICE)(int KMP_DEREF arg) {
10431043
int FTN_STDCALL KMP_EXPAND_NAME(FTN_GET_NUM_DEVICES)(void)
10441044
KMP_WEAK_ATTRIBUTE_EXTERNAL;
10451045
int FTN_STDCALL KMP_EXPAND_NAME(FTN_GET_NUM_DEVICES)(void) {
1046-
#if KMP_MIC || KMP_OS_DARWIN || defined(KMP_STUB)
1046+
#if KMP_MIC || KMP_OS_DARWIN || KMP_OS_WASI || defined(KMP_STUB)
10471047
return 0;
10481048
#else
10491049
int (*fptr)();
@@ -1558,7 +1558,7 @@ typedef void *omp_interop_t;
15581558

15591559
// libomptarget, if loaded, provides this function
15601560
int FTN_STDCALL FTN_GET_NUM_INTEROP_PROPERTIES(const omp_interop_t interop) {
1561-
#if KMP_OS_DARWIN || defined(KMP_STUB)
1561+
#if KMP_OS_DARWIN || KMP_OS_WASI || defined(KMP_STUB)
15621562
return 0;
15631563
#else
15641564
int (*fptr)(const omp_interop_t);
@@ -1573,7 +1573,7 @@ int FTN_STDCALL FTN_GET_NUM_INTEROP_PROPERTIES(const omp_interop_t interop) {
15731573
intptr_t FTN_STDCALL FTN_GET_INTEROP_INT(const omp_interop_t interop,
15741574
omp_interop_property_t property_id,
15751575
int *err) {
1576-
#if KMP_OS_DARWIN || defined(KMP_STUB)
1576+
#if KMP_OS_DARWIN || KMP_OS_WASI || defined(KMP_STUB)
15771577
return 0;
15781578
#else
15791579
intptr_t (*fptr)(const omp_interop_t, omp_interop_property_t, int *);
@@ -1587,7 +1587,7 @@ intptr_t FTN_STDCALL FTN_GET_INTEROP_INT(const omp_interop_t interop,
15871587
void *FTN_STDCALL FTN_GET_INTEROP_PTR(const omp_interop_t interop,
15881588
omp_interop_property_t property_id,
15891589
int *err) {
1590-
#if KMP_OS_DARWIN || defined(KMP_STUB)
1590+
#if KMP_OS_DARWIN || KMP_OS_WASI || defined(KMP_STUB)
15911591
return nullptr;
15921592
#else
15931593
void *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
@@ -1601,7 +1601,7 @@ void *FTN_STDCALL FTN_GET_INTEROP_PTR(const omp_interop_t interop,
16011601
const char *FTN_STDCALL FTN_GET_INTEROP_STR(const omp_interop_t interop,
16021602
omp_interop_property_t property_id,
16031603
int *err) {
1604-
#if KMP_OS_DARWIN || defined(KMP_STUB)
1604+
#if KMP_OS_DARWIN || KMP_OS_WASI || defined(KMP_STUB)
16051605
return nullptr;
16061606
#else
16071607
const char *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
@@ -1614,7 +1614,7 @@ const char *FTN_STDCALL FTN_GET_INTEROP_STR(const omp_interop_t interop,
16141614
// libomptarget, if loaded, provides this function
16151615
const char *FTN_STDCALL FTN_GET_INTEROP_NAME(
16161616
const omp_interop_t interop, omp_interop_property_t property_id) {
1617-
#if KMP_OS_DARWIN || defined(KMP_STUB)
1617+
#if KMP_OS_DARWIN || KMP_OS_WASI || defined(KMP_STUB)
16181618
return nullptr;
16191619
#else
16201620
const char *(*fptr)(const omp_interop_t, omp_interop_property_t);
@@ -1627,7 +1627,7 @@ const char *FTN_STDCALL FTN_GET_INTEROP_NAME(
16271627
// libomptarget, if loaded, provides this function
16281628
const char *FTN_STDCALL FTN_GET_INTEROP_TYPE_DESC(
16291629
const omp_interop_t interop, omp_interop_property_t property_id) {
1630-
#if KMP_OS_DARWIN || defined(KMP_STUB)
1630+
#if KMP_OS_DARWIN || KMP_OS_WASI || defined(KMP_STUB)
16311631
return nullptr;
16321632
#else
16331633
const char *(*fptr)(const omp_interop_t, omp_interop_property_t);
@@ -1640,7 +1640,7 @@ const char *FTN_STDCALL FTN_GET_INTEROP_TYPE_DESC(
16401640
// libomptarget, if loaded, provides this function
16411641
const char *FTN_STDCALL FTN_GET_INTEROP_RC_DESC(
16421642
const omp_interop_t interop, omp_interop_property_t property_id) {
1643-
#if KMP_OS_DARWIN || defined(KMP_STUB)
1643+
#if KMP_OS_DARWIN || KMP_OS_WASI || defined(KMP_STUB)
16441644
return nullptr;
16451645
#else
16461646
const char *(*fptr)(const omp_interop_t, omp_interop_property_t);

openmp/runtime/src/kmp_gsupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ORDERED_END)(void) {
356356
// They come in two flavors: 64-bit unsigned, and either 32-bit signed
357357
// (IA-32 architecture) or 64-bit signed (Intel(R) 64).
358358

359-
#if KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS
359+
#if KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_WASM
360360
#define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_4
361361
#define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_4
362362
#define KMP_DISPATCH_NEXT __kmpc_dispatch_next_4

openmp/runtime/src/kmp_os.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
#error Unknown compiler
7676
#endif
7777

78-
#if (KMP_OS_LINUX || KMP_OS_WINDOWS || KMP_OS_FREEBSD)
78+
#if (KMP_OS_LINUX || KMP_OS_WINDOWS || KMP_OS_FREEBSD) && !KMP_OS_WASI
7979
#define KMP_AFFINITY_SUPPORTED 1
8080
#if KMP_OS_WINDOWS && KMP_ARCH_X86_64
8181
#define KMP_GROUP_AFFINITY 1
@@ -176,7 +176,7 @@ typedef unsigned long long kmp_uint64;
176176
#define KMP_UINT64_SPEC "llu"
177177
#endif /* KMP_OS_UNIX */
178178

179-
#if KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS
179+
#if KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_WASM
180180
#define KMP_SIZE_T_SPEC KMP_UINT32_SPEC
181181
#elif KMP_ARCH_X86_64 || KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 || \
182182
KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64 || \
@@ -186,7 +186,7 @@ typedef unsigned long long kmp_uint64;
186186
#error "Can't determine size_t printf format specifier."
187187
#endif
188188

189-
#if KMP_ARCH_X86 || KMP_ARCH_ARM
189+
#if KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_WASM
190190
#define KMP_SIZE_T_MAX (0xFFFFFFFF)
191191
#else
192192
#define KMP_SIZE_T_MAX (0xFFFFFFFFFFFFFFFF)
@@ -215,8 +215,8 @@ typedef kmp_uint32 kmp_uint;
215215
#define KMP_INT_MIN ((kmp_int32)0x80000000)
216216

217217
// stdarg handling
218-
#if (KMP_ARCH_ARM || KMP_ARCH_X86_64 || KMP_ARCH_AARCH64) && \
219-
(KMP_OS_FREEBSD || KMP_OS_LINUX)
218+
#if (KMP_ARCH_ARM || KMP_ARCH_X86_64 || KMP_ARCH_AARCH64 || KMP_ARCH_WASM) && \
219+
(KMP_OS_FREEBSD || KMP_OS_LINUX || KMP_OS_WASI)
220220
typedef va_list *kmp_va_list;
221221
#define kmp_va_deref(ap) (*(ap))
222222
#define kmp_va_addr_of(ap) (&(ap))
@@ -1146,7 +1146,7 @@ extern kmp_real64 __kmp_xchg_real64(volatile kmp_real64 *p, kmp_real64 v);
11461146
KMP_COMPARE_AND_STORE_REL64((volatile kmp_int64 *)(volatile void *)&(a), \
11471147
(kmp_int64)(b), (kmp_int64)(c))
11481148

1149-
#if KMP_ARCH_X86 || KMP_ARCH_MIPS
1149+
#if KMP_ARCH_X86 || KMP_ARCH_MIPS || KMP_ARCH_WASM
11501150
// What about ARM?
11511151
#define TCR_PTR(a) ((void *)TCR_4(a))
11521152
#define TCW_PTR(a, b) TCW_4((a), (b))
@@ -1288,6 +1288,9 @@ bool __kmp_atomic_compare_store_rel(std::atomic<T> *p, T expected, T desired) {
12881288
extern void *__kmp_lookup_symbol(const char *name, bool next = false);
12891289
#define KMP_DLSYM(name) __kmp_lookup_symbol(name)
12901290
#define KMP_DLSYM_NEXT(name) __kmp_lookup_symbol(name, true)
1291+
#elif KMP_OS_WASI
1292+
#define KMP_DLSYM(name) nullptr
1293+
#define KMP_DLSYM_NEXT(name) nullptr
12911294
#else
12921295
#define KMP_DLSYM(name) dlsym(RTLD_DEFAULT, name)
12931296
#define KMP_DLSYM_NEXT(name) dlsym(RTLD_NEXT, name)

openmp/runtime/src/kmp_platform.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define KMP_OS_WINDOWS 0
2525
#define KMP_OS_HURD 0
2626
#define KMP_OS_SOLARIS 0
27+
#define KMP_OS_WASI 0
2728
#define KMP_OS_UNIX 0 /* disjunction of KMP_OS_LINUX, KMP_OS_DARWIN etc. */
2829

2930
#ifdef _WIN32
@@ -76,14 +77,20 @@
7677
#define KMP_OS_SOLARIS 1
7778
#endif
7879

80+
#if (defined __wasi__) || (defined __EMSCRIPTEN__)
81+
#undef KMP_OS_WASI
82+
#define KMP_OS_WASI 1
83+
#endif
84+
7985
#if (1 != KMP_OS_LINUX + KMP_OS_DRAGONFLY + KMP_OS_FREEBSD + KMP_OS_NETBSD + \
8086
KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HURD + \
81-
KMP_OS_SOLARIS)
87+
KMP_OS_SOLARIS + KMP_OS_WASI)
8288
#error Unknown OS
8389
#endif
8490

8591
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
86-
KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD || KMP_OS_SOLARIS
92+
KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD || KMP_OS_SOLARIS || \
93+
KMP_OS_WASI
8794
#undef KMP_OS_UNIX
8895
#define KMP_OS_UNIX 1
8996
#endif
@@ -196,6 +203,10 @@
196203
#define KMP_ARCH_ARM 1
197204
#endif
198205

206+
#if defined(__wasm32__)
207+
#define KMP_ARCH_WASM 1
208+
#endif
209+
199210
#if defined(__MIC__) || defined(__MIC2__)
200211
#define KMP_MIC 1
201212
#if __MIC2__ || __KNC__
@@ -212,7 +223,8 @@
212223
#endif
213224

214225
/* Specify 32 bit architectures here */
215-
#define KMP_32_BIT_ARCH (KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS)
226+
#define KMP_32_BIT_ARCH \
227+
(KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_WASM)
216228

217229
// Platforms which support Intel(R) Many Integrated Core Architecture
218230
#define KMP_MIC_SUPPORTED \
@@ -222,7 +234,7 @@
222234
#if (1 != KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 + \
223235
KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 + \
224236
KMP_ARCH_RISCV64 + KMP_ARCH_LOONGARCH64 + KMP_ARCH_VE + \
225-
KMP_ARCH_S390X)
237+
KMP_ARCH_S390X + KMP_ARCH_WASM)
226238
#error Unknown or unsupported architecture
227239
#endif
228240

0 commit comments

Comments
 (0)