[Openmp-commits] [PATCH] D130114: [OpenMP] Use Undef instead of null as pointer for inactive lanes
Johannes Doerfert via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Tue Jul 19 12:37:29 PDT 2022
jdoerfert created this revision.
jdoerfert added reviewers: tianshilei1992, jhuber6.
Herald added subscribers: guansong, bollu, yaxunl.
Herald added a project: All.
jdoerfert requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: OpenMP.
Our conditional writes in the runtime look like this:
if (active)
*ptr = value;
In the RAII we need to assign `ptr` which comes from a lookup call.
If a thread that is not the main thread calls lookup with the intention
to write the pointer, we'll create a new thread state. As such, we need
to avoid calling lookup for inactive threads. We used to use `nullptr`
as their `ptr` value but that can cause pessimistic reasoning. We now
use `undef` instead.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D130114
Files:
openmp/libomptarget/DeviceRTL/include/State.h
openmp/libomptarget/DeviceRTL/include/Utils.h
Index: openmp/libomptarget/DeviceRTL/include/Utils.h
===================================================================
--- openmp/libomptarget/DeviceRTL/include/Utils.h
+++ openmp/libomptarget/DeviceRTL/include/Utils.h
@@ -14,6 +14,8 @@
#include "Types.h"
+#pragma omp begin declare target device_type(nohost)
+
namespace _OMP {
namespace utils {
@@ -72,10 +74,15 @@
return V - V % Align;
}
+/// A pointer variable that has by design an `undef` value. Use with care.
+__attribute__((loader_uninitialized)) static void *const UndefPtr;
+
#define OMP_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
#define OMP_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
} // namespace utils
} // namespace _OMP
+#pragma omp end declare target
+
#endif
Index: openmp/libomptarget/DeviceRTL/include/State.h
===================================================================
--- openmp/libomptarget/DeviceRTL/include/State.h
+++ openmp/libomptarget/DeviceRTL/include/State.h
@@ -277,7 +277,8 @@
template <typename VTy, typename Ty> struct ValueRAII {
ValueRAII(VTy &V, Ty NewValue, Ty OldValue, bool Active, IdentTy *Ident)
- : Ptr(Active ? &V.lookup(/* IsReadonly */ false, Ident) : nullptr),
+ : Ptr(Active ? &V.lookup(/* IsReadonly */ false, Ident)
+ : (Ty *)utils::UndefPtr),
Val(OldValue), Active(Active) {
if (!Active)
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130114.445910.patch
Type: text/x-patch
Size: 1407 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20220719/81c2b4d9/attachment.bin>
More information about the Openmp-commits
mailing list