aboutsummaryrefslogtreecommitdiff
path: root/openmp
diff options
context:
space:
mode:
authorJonathan Peyton <jonathan.l.peyton@intel.com>2022-08-01 14:12:29 -0500
committerJonathan Peyton <jonathan.l.peyton@intel.com>2022-09-08 16:17:20 -0500
commite5ac98fa0150c29ed9463460b17e085adb9b977b (patch)
tree6b348ae75f77e4c723c4e8ce75f40d52dd9c2c88 /openmp
parent1cf5c7fe8ce21b3add80972e6aaeb30a1f61bff9 (diff)
downloadllvm-e5ac98fa0150c29ed9463460b17e085adb9b977b.zip
llvm-e5ac98fa0150c29ed9463460b17e085adb9b977b.tar.gz
llvm-e5ac98fa0150c29ed9463460b17e085adb9b977b.tar.bz2
[OpenMP][libomp] Cleanup __kmpc_flush() code
Have it be simple KMP_MFENCE() which incorporates x86-specific logic and reduces to KMP_MB() for other architectures. Differential Revision: https://reviews.llvm.org/D130928
Diffstat (limited to 'openmp')
-rw-r--r--openmp/runtime/src/kmp_csupport.cpp40
-rw-r--r--openmp/runtime/src/kmp_os.h10
2 files changed, 11 insertions, 39 deletions
diff --git a/openmp/runtime/src/kmp_csupport.cpp b/openmp/runtime/src/kmp_csupport.cpp
index c932d45..72031a2 100644
--- a/openmp/runtime/src/kmp_csupport.cpp
+++ b/openmp/runtime/src/kmp_csupport.cpp
@@ -668,45 +668,7 @@ void __kmpc_flush(ident_t *loc) {
KC_TRACE(10, ("__kmpc_flush: called\n"));
/* need explicit __mf() here since use volatile instead in library */
- KMP_MB(); /* Flush all pending memory write invalidates. */
-
-#if (KMP_ARCH_X86 || KMP_ARCH_X86_64)
-#if KMP_MIC
-// fence-style instructions do not exist, but lock; xaddl $0,(%rsp) can be used.
-// We shouldn't need it, though, since the ABI rules require that
-// * If the compiler generates NGO stores it also generates the fence
-// * If users hand-code NGO stores they should insert the fence
-// therefore no incomplete unordered stores should be visible.
-#else
- // C74404
- // This is to address non-temporal store instructions (sfence needed).
- // The clflush instruction is addressed either (mfence needed).
- // Probably the non-temporal load monvtdqa instruction should also be
- // addressed.
- // mfence is a SSE2 instruction. Do not execute it if CPU is not SSE2.
- if (!__kmp_cpuinfo.initialized) {
- __kmp_query_cpuid(&__kmp_cpuinfo);
- }
- if (!__kmp_cpuinfo.flags.sse2) {
- // CPU cannot execute SSE2 instructions.
- } else {
-#if KMP_COMPILER_ICC || KMP_COMPILER_ICX
- _mm_mfence();
-#elif KMP_COMPILER_MSVC
- MemoryBarrier();
-#else
- __sync_synchronize();
-#endif // KMP_COMPILER_ICC || KMP_COMPILER_ICX
- }
-#endif // KMP_MIC
-#elif (KMP_ARCH_ARM || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS || KMP_ARCH_MIPS64 || \
- KMP_ARCH_RISCV64)
-// Nothing to see here move along
-#elif KMP_ARCH_PPC64
-// Nothing needed here (we have a real MB above).
-#else
-#error Unknown or unsupported architecture
-#endif
+ KMP_MFENCE(); /* Flush all pending memory write invalidates. */
#if OMPT_SUPPORT && OMPT_OPTIONAL
if (ompt_enabled.ompt_callback_flush) {
diff --git a/openmp/runtime/src/kmp_os.h b/openmp/runtime/src/kmp_os.h
index 02efaa1b..97cb0a1 100644
--- a/openmp/runtime/src/kmp_os.h
+++ b/openmp/runtime/src/kmp_os.h
@@ -1058,6 +1058,15 @@ extern kmp_real64 __kmp_xchg_real64(volatile kmp_real64 *p, kmp_real64 v);
#endif
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
+#if KMP_MIC
+// fence-style instructions do not exist, but lock; xaddl $0,(%rsp) can be used.
+// We shouldn't need it, though, since the ABI rules require that
+// * If the compiler generates NGO stores it also generates the fence
+// * If users hand-code NGO stores they should insert the fence
+// therefore no incomplete unordered stores should be visible.
+#define KMP_MFENCE() /* Nothing */
+#define KMP_SFENCE() /* Nothing */
+#else
#if KMP_COMPILER_ICC || KMP_COMPILER_ICX
#define KMP_MFENCE_() _mm_mfence()
#define KMP_SFENCE_() _mm_sfence()
@@ -1076,6 +1085,7 @@ extern kmp_real64 __kmp_xchg_real64(volatile kmp_real64 *p, kmp_real64 v);
KMP_MFENCE_(); \
}
#define KMP_SFENCE() KMP_SFENCE_()
+#endif
#else
#define KMP_MFENCE() KMP_MB()
#define KMP_SFENCE() KMP_MB()