-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[OpenMP] Remove usage of pointer-to-member in lookup #123671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary: This is buggy and is currently being tracked in llvm#123241. For now, replace it with a macro so that we can use address spaces directly.
@llvm/pr-subscribers-offload Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/123671.diff 1 Files Affected:
diff --git a/offload/DeviceRTL/include/State.h b/offload/DeviceRTL/include/State.h
index 565235cd48a913..c487ff29680faa 100644
--- a/offload/DeviceRTL/include/State.h
+++ b/offload/DeviceRTL/include/State.h
@@ -158,63 +158,61 @@ struct DateEnvironmentRAII {
/// TODO
void resetStateForThread(uint32_t TId);
-inline uint32_t &lookupForModify32Impl(uint32_t state::ICVStateTy::*Var,
- IdentTy *Ident, bool ForceTeamState) {
- if (OMP_LIKELY(ForceTeamState || !config::mayUseThreadStates() ||
- !TeamState.HasThreadState))
- return TeamState.ICVState.*Var;
- uint32_t TId = mapping::getThreadIdInBlock();
- if (OMP_UNLIKELY(!ThreadStates[TId])) {
- ThreadStates[TId] = reinterpret_cast<ThreadStateTy *>(memory::allocGlobal(
- sizeof(ThreadStateTy), "ICV modification outside data environment"));
- ASSERT(ThreadStates[TId] != nullptr, "Nullptr returned by malloc!");
- TeamState.HasThreadState = true;
- ThreadStates[TId]->init();
+// FIXME: https://github.com/llvm/llvm-project/issues/123241.
+#define lookupForModify32Impl(Member, Ident, ForceTeamState) \
+ { \
+ if (OMP_LIKELY(ForceTeamState || !config::mayUseThreadStates() || \
+ !TeamState.HasThreadState)) \
+ return TeamState.ICVState.Member; \
+ uint32_t TId = mapping::getThreadIdInBlock(); \
+ if (OMP_UNLIKELY(!ThreadStates[TId])) { \
+ ThreadStates[TId] = reinterpret_cast<ThreadStateTy *>( \
+ memory::allocGlobal(sizeof(ThreadStateTy), \
+ "ICV modification outside data environment")); \
+ ASSERT(ThreadStates[TId] != nullptr, "Nullptr returned by malloc!"); \
+ TeamState.HasThreadState = true; \
+ ThreadStates[TId]->init(); \
+ } \
+ return ThreadStates[TId]->ICVState.Member; \
}
- return ThreadStates[TId]->ICVState.*Var;
-}
-inline uint32_t &lookupImpl(uint32_t state::ICVStateTy::*Var,
- bool ForceTeamState) {
- auto TId = mapping::getThreadIdInBlock();
- if (OMP_UNLIKELY(!ForceTeamState && config::mayUseThreadStates() &&
- TeamState.HasThreadState && ThreadStates[TId]))
- return ThreadStates[TId]->ICVState.*Var;
- return TeamState.ICVState.*Var;
-}
+// FIXME: https://github.com/llvm/llvm-project/issues/123241.
+#define lookupImpl(Member, ForceTeamState) \
+ { \
+ auto TId = mapping::getThreadIdInBlock(); \
+ if (OMP_UNLIKELY(!ForceTeamState && config::mayUseThreadStates() && \
+ TeamState.HasThreadState && ThreadStates[TId])) \
+ return ThreadStates[TId]->ICVState.Member; \
+ return TeamState.ICVState.Member; \
+ }
[[gnu::always_inline, gnu::flatten]] inline uint32_t &
lookup32(ValueKind Kind, bool IsReadonly, IdentTy *Ident, bool ForceTeamState) {
switch (Kind) {
case state::VK_NThreads:
if (IsReadonly)
- return lookupImpl(&ICVStateTy::NThreadsVar, ForceTeamState);
- return lookupForModify32Impl(&ICVStateTy::NThreadsVar, Ident,
- ForceTeamState);
+ lookupImpl(NThreadsVar, ForceTeamState);
+ lookupForModify32Impl(NThreadsVar, Ident, ForceTeamState);
case state::VK_Level:
if (IsReadonly)
- return lookupImpl(&ICVStateTy::LevelVar, ForceTeamState);
- return lookupForModify32Impl(&ICVStateTy::LevelVar, Ident, ForceTeamState);
+ lookupImpl(LevelVar, ForceTeamState);
+ lookupForModify32Impl(LevelVar, Ident, ForceTeamState);
case state::VK_ActiveLevel:
if (IsReadonly)
- return lookupImpl(&ICVStateTy::ActiveLevelVar, ForceTeamState);
- return lookupForModify32Impl(&ICVStateTy::ActiveLevelVar, Ident,
- ForceTeamState);
+ lookupImpl(ActiveLevelVar, ForceTeamState);
+ lookupForModify32Impl(ActiveLevelVar, Ident, ForceTeamState);
case state::VK_MaxActiveLevels:
if (IsReadonly)
- return lookupImpl(&ICVStateTy::MaxActiveLevelsVar, ForceTeamState);
- return lookupForModify32Impl(&ICVStateTy::MaxActiveLevelsVar, Ident,
- ForceTeamState);
+ lookupImpl(MaxActiveLevelsVar, ForceTeamState);
+ lookupForModify32Impl(MaxActiveLevelsVar, Ident, ForceTeamState);
case state::VK_RunSched:
if (IsReadonly)
- return lookupImpl(&ICVStateTy::RunSchedVar, ForceTeamState);
- return lookupForModify32Impl(&ICVStateTy::RunSchedVar, Ident,
- ForceTeamState);
+ lookupImpl(RunSchedVar, ForceTeamState);
+ lookupForModify32Impl(RunSchedVar, Ident, ForceTeamState);
case state::VK_RunSchedChunk:
if (IsReadonly)
- return lookupImpl(&ICVStateTy::RunSchedChunkVar, ForceTeamState);
- return lookupForModify32Impl(&ICVStateTy::RunSchedChunkVar, Ident,
- ForceTeamState);
+ lookupImpl(RunSchedChunkVar, ForceTeamState);
+ lookupForModify32Impl(RunSchedChunkVar, Ident, ForceTeamState);
case state::VK_ParallelTeamSize:
return TeamState.ParallelTeamSize;
case state::VK_HasThreadState:
|
TeamState.HasThreadState = true; | ||
ThreadStates[TId]->init(); | ||
// FIXME: https://github.com/llvm/llvm-project/issues/123241. | ||
#define lookupForModify32Impl(Member, Ident, ForceTeamState) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just make the function return a pointer instead of a reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically it encodes an enum to a struct member. I could obviously pass offsetof(S, Member)
and return a pointer (or a reference), but I wanted to keep the code as similar as possible. Otherwise, there's no easy way to avoid the member pointer syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I could think of some code reorgnization to avoid macro and pointer-to-member arguments (template, or passing a lamba that looks up the requested field), but that doesn't seem worth it for a workaround.
Summary:
This is buggy and is currently being tracked in
#123241. For now, replace it
with a macro so that we can use address spaces directly.