[Openmp-commits] [PATCH] D137168: [OpenMP][mingw] Fix build for aarch64 target
Alvin Wong via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Tue Nov 1 09:26:40 PDT 2022
alvinhochun created this revision.
alvinhochun added reviewers: malharJ, jdoerfert, jlpeyton, mstorsjo.
Herald added subscribers: guansong, kristof.beyls, yaxunl.
Herald added a project: All.
alvinhochun requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.
This patch implements some internal atomic macros using __sync builtins
on aarch64 + __GNUC__, just like the existing ones for Unix, because
mingw-w64 is missing some of the intrinsics which the MSVC codepath is
using.
Then some remaining intel-only functions are removed from dllexport to
fix linking.
This should fix https://github.com/llvm/llvm-project/issues/56349.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137168
Files:
openmp/runtime/src/dllexports
openmp/runtime/src/kmp_os.h
openmp/runtime/src/kmp_utility.cpp
Index: openmp/runtime/src/kmp_utility.cpp
===================================================================
--- openmp/runtime/src/kmp_utility.cpp
+++ openmp/runtime/src/kmp_utility.cpp
@@ -370,7 +370,7 @@
case 'I':
case 'i': {
pid_t id = getpid();
-#if KMP_ARCH_X86_64 && defined(__MINGW32__)
+#if (KMP_ARCH_X86_64 || KMP_ARCH_AARCH64) && defined(__MINGW32__)
snp_result = KMP_SNPRINTF(pos, end - pos + 1, "%0*lld", width, id);
#else
snp_result = KMP_SNPRINTF(pos, end - pos + 1, "%0*d", width, id);
Index: openmp/runtime/src/kmp_os.h
===================================================================
--- openmp/runtime/src/kmp_os.h
+++ openmp/runtime/src/kmp_os.h
@@ -618,6 +618,54 @@
// *)&v); return *(kmp_real64 *)&tmp;
// }
+#elif KMP_ARCH_AARCH64 && defined(__GNUC__)
+
+/* cast p to correct type so that proper intrinsic will be used */
+#define KMP_TEST_THEN_INC64(p) \
+ __sync_fetch_and_add((volatile kmp_int64 *)(p), 1LL)
+#define KMP_TEST_THEN_INC_ACQ64(p) \
+ __sync_fetch_and_add((volatile kmp_int64 *)(p), 1LL)
+#define KMP_TEST_THEN_ADD4_64(p) \
+ __sync_fetch_and_add((volatile kmp_int64 *)(p), 4LL)
+#define KMP_TEST_THEN_ADD4_ACQ64(p) \
+ __sync_fetch_and_add((volatile kmp_int64 *)(p), 4LL)
+#define KMP_TEST_THEN_DEC64(p) \
+ __sync_fetch_and_sub((volatile kmp_int64 *)(p), 1LL)
+#define KMP_TEST_THEN_DEC_ACQ64(p) \
+ __sync_fetch_and_sub((volatile kmp_int64 *)(p), 1LL)
+#define KMP_TEST_THEN_ADD64(p, v) \
+ __sync_fetch_and_add((volatile kmp_int64 *)(p), (kmp_int64)(v))
+#define KMP_COMPARE_AND_STORE_ACQ8(p, cv, sv) \
+ __sync_bool_compare_and_swap((volatile kmp_uint8 *)(p), (kmp_uint8)(cv), \
+ (kmp_uint8)(sv))
+#define KMP_COMPARE_AND_STORE_REL8(p, cv, sv) \
+ __sync_bool_compare_and_swap((volatile kmp_uint8 *)(p), (kmp_uint8)(cv), \
+ (kmp_uint8)(sv))
+#define KMP_COMPARE_AND_STORE_ACQ16(p, cv, sv) \
+ __sync_bool_compare_and_swap((volatile kmp_uint16 *)(p), (kmp_uint16)(cv), \
+ (kmp_uint16)(sv))
+#define KMP_COMPARE_AND_STORE_REL16(p, cv, sv) \
+ __sync_bool_compare_and_swap((volatile kmp_uint16 *)(p), (kmp_uint16)(cv), \
+ (kmp_uint16)(sv))
+#define KMP_COMPARE_AND_STORE_ACQ32(p, cv, sv) \
+ __sync_bool_compare_and_swap((volatile kmp_uint32 *)(p), (kmp_uint32)(cv), \
+ (kmp_uint32)(sv))
+#define KMP_COMPARE_AND_STORE_REL32(p, cv, sv) \
+ __sync_bool_compare_and_swap((volatile kmp_uint32 *)(p), (kmp_uint32)(cv), \
+ (kmp_uint32)(sv))
+#define KMP_COMPARE_AND_STORE_ACQ64(p, cv, sv) \
+ __sync_bool_compare_and_swap((volatile kmp_uint64 *)(p), (kmp_uint64)(cv), \
+ (kmp_uint64)(sv))
+#define KMP_COMPARE_AND_STORE_REL64(p, cv, sv) \
+ __sync_bool_compare_and_swap((volatile kmp_uint64 *)(p), (kmp_uint64)(cv), \
+ (kmp_uint64)(sv))
+#define KMP_COMPARE_AND_STORE_RET64(p, cv, sv) \
+ __sync_val_compare_and_swap((volatile kmp_uint64 *)(p), (kmp_uint64)(cv), \
+ (kmp_uint64)(sv))
+#define KMP_COMPARE_AND_STORE_PTR(p, cv, sv) \
+ __sync_bool_compare_and_swap((void *volatile *)(p), (void *)(cv), \
+ (void *)(sv))
+
#else // !KMP_ARCH_AARCH64
// Routines that we still need to implement in assembly.
Index: openmp/runtime/src/dllexports
===================================================================
--- openmp/runtime/src/dllexports
+++ openmp/runtime/src/dllexports
@@ -1243,7 +1243,6 @@
%ifdef IS_IA_ARCH
__kmpc_atomic_float10_max 2139
__kmpc_atomic_float10_min 2140
- %endif
__kmpc_atomic_float10_max_cpt 2141
__kmpc_atomic_float10_min_cpt 2142
@@ -1263,6 +1262,7 @@
__kmpc_atomic_val_2_cas_cpt 2156
__kmpc_atomic_val_4_cas_cpt 2157
__kmpc_atomic_val_8_cas_cpt 2158
+ %endif
%endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137168.472327.patch
Type: text/x-patch
Size: 4728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20221101/dfd31a5b/attachment.bin>
More information about the Openmp-commits
mailing list