Skip to content

Commit 1785d49

Browse files
author
git apple-llvm automerger
committed
Merge commit '1e1215689656' from llvm.org/main into next
2 parents 906919f + 1e12156 commit 1785d49

File tree

4 files changed

+46
-38
lines changed

4 files changed

+46
-38
lines changed

openmp/libomptarget/DeviceRTL/include/State.h

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,56 +40,61 @@ enum ValueKind {
4040
};
4141

4242
/// TODO
43-
void enterDataEnvironment();
43+
void enterDataEnvironment(IdentTy *Ident);
4444

4545
/// TODO
4646
void exitDataEnvironment();
4747

4848
/// TODO
4949
struct DateEnvironmentRAII {
50-
DateEnvironmentRAII() { enterDataEnvironment(); }
50+
DateEnvironmentRAII(IdentTy *Ident) { enterDataEnvironment(Ident); }
5151
~DateEnvironmentRAII() { exitDataEnvironment(); }
5252
};
5353

5454
/// TODO
5555
void resetStateForThread(uint32_t TId);
5656

57-
uint32_t &lookup32(ValueKind VK, bool IsReadonly);
57+
uint32_t &lookup32(ValueKind VK, bool IsReadonly, IdentTy *Ident);
5858
void *&lookupPtr(ValueKind VK, bool IsReadonly);
5959

6060
/// A class without actual state used to provide a nice interface to lookup and
6161
/// update ICV values we can declare in global scope.
6262
template <typename Ty, ValueKind Kind> struct Value {
6363
__attribute__((flatten, always_inline)) operator Ty() {
64-
return lookup(/* IsReadonly */ true);
64+
return lookup(/* IsReadonly */ true, /* IdentTy */ nullptr);
6565
}
6666

6767
__attribute__((flatten, always_inline)) Value &operator=(const Ty &Other) {
68-
set(Other);
68+
set(Other, /* IdentTy */ nullptr);
6969
return *this;
7070
}
7171

7272
__attribute__((flatten, always_inline)) Value &operator++() {
73-
inc(1);
73+
inc(1, /* IdentTy */ nullptr);
7474
return *this;
7575
}
7676

7777
__attribute__((flatten, always_inline)) Value &operator--() {
78-
inc(-1);
78+
inc(-1, /* IdentTy */ nullptr);
7979
return *this;
8080
}
8181

8282
private:
83-
Ty &lookup(bool IsReadonly) {
84-
Ty &t = lookup32(Kind, IsReadonly);
83+
__attribute__((flatten, always_inline)) Ty &lookup(bool IsReadonly,
84+
IdentTy *Ident) {
85+
Ty &t = lookup32(Kind, IsReadonly, Ident);
8586
return t;
8687
}
8788

88-
Ty &inc(int UpdateVal) {
89-
return (lookup(/* IsReadonly */ false) += UpdateVal);
89+
__attribute__((flatten, always_inline)) Ty &inc(int UpdateVal,
90+
IdentTy *Ident) {
91+
return (lookup(/* IsReadonly */ false, Ident) += UpdateVal);
9092
}
9193

92-
Ty &set(Ty UpdateVal) { return (lookup(/* IsReadonly */ false) = UpdateVal); }
94+
__attribute__((flatten, always_inline)) Ty &set(Ty UpdateVal,
95+
IdentTy *Ident) {
96+
return (lookup(/* IsReadonly */ false, Ident) = UpdateVal);
97+
}
9398

9499
template <typename VTy, typename Ty2> friend struct ValueRAII;
95100
};
@@ -99,7 +104,7 @@ template <typename Ty, ValueKind Kind> struct Value {
99104
/// we can declare in global scope.
100105
template <typename Ty, ValueKind Kind> struct PtrValue {
101106
__attribute__((flatten, always_inline)) operator Ty() {
102-
return lookup(/* IsReadonly */ true);
107+
return lookup(/* IsReadonly */ true, /* IdentTy */ nullptr);
103108
}
104109

105110
__attribute__((flatten, always_inline)) PtrValue &operator=(const Ty Other) {
@@ -108,17 +113,19 @@ template <typename Ty, ValueKind Kind> struct PtrValue {
108113
}
109114

110115
private:
111-
Ty &lookup(bool IsReadonly) { return lookupPtr(Kind, IsReadonly); }
116+
Ty &lookup(bool IsReadonly, IdentTy *) { return lookupPtr(Kind, IsReadonly); }
112117

113-
Ty &set(Ty UpdateVal) { return (lookup(/* IsReadonly */ false) = UpdateVal); }
118+
Ty &set(Ty UpdateVal) {
119+
return (lookup(/* IsReadonly */ false, /* IdentTy */ nullptr) = UpdateVal);
120+
}
114121

115122
template <typename VTy, typename Ty2> friend struct ValueRAII;
116123
};
117124

118125
template <typename VTy, typename Ty> struct ValueRAII {
119-
ValueRAII(VTy &V, Ty NewValue, Ty OldValue, bool Active)
120-
: Ptr(Active ? V.lookup(/* IsReadonly */ false) : Val), Val(OldValue),
121-
Active(Active) {
126+
ValueRAII(VTy &V, Ty NewValue, Ty OldValue, bool Active, IdentTy *Ident)
127+
: Ptr(Active ? V.lookup(/* IsReadonly */ false, Ident) : Val),
128+
Val(OldValue), Active(Active) {
122129
if (!Active)
123130
return;
124131
ASSERT(Ptr == OldValue && "ValueRAII initialization with wrong old value!");

openmp/libomptarget/DeviceRTL/src/Parallelism.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void __kmpc_parallel_51(IdentTy *ident, int32_t, int32_t if_expr,
8787
uint32_t TId = mapping::getThreadIdInBlock();
8888
// Handle the serialized case first, same for SPMD/non-SPMD.
8989
if (OMP_UNLIKELY(!if_expr || icv::Level)) {
90-
state::enterDataEnvironment();
90+
state::DateEnvironmentRAII DERAII(ident);
9191
++icv::Level;
9292
invokeMicrotask(TId, 0, fn, args, nargs);
9393
state::exitDataEnvironment();
@@ -104,9 +104,10 @@ void __kmpc_parallel_51(IdentTy *ident, int32_t, int32_t if_expr,
104104
// last or the other updates will cause a thread specific state to be
105105
// created.
106106
state::ValueRAII ParallelTeamSizeRAII(state::ParallelTeamSize, NumThreads,
107-
1u, TId == 0);
108-
state::ValueRAII ActiveLevelRAII(icv::ActiveLevel, 1u, 0u, TId == 0);
109-
state::ValueRAII LevelRAII(icv::Level, 1u, 0u, TId == 0);
107+
1u, TId == 0, ident);
108+
state::ValueRAII ActiveLevelRAII(icv::ActiveLevel, 1u, 0u, TId == 0,
109+
ident);
110+
state::ValueRAII LevelRAII(icv::Level, 1u, 0u, TId == 0, ident);
110111

111112
// Synchronize all threads after the main thread (TId == 0) set up the
112113
// team state properly.
@@ -142,7 +143,7 @@ void __kmpc_parallel_51(IdentTy *ident, int32_t, int32_t if_expr,
142143

143144
bool IsActiveParallelRegion = NumThreads > 1;
144145
if (!IsActiveParallelRegion) {
145-
state::ValueRAII LevelRAII(icv::Level, 1u, 0u, true);
146+
state::ValueRAII LevelRAII(icv::Level, 1u, 0u, true, ident);
146147
invokeMicrotask(TId, 0, fn, args, nargs);
147148
return;
148149
}
@@ -160,11 +161,11 @@ void __kmpc_parallel_51(IdentTy *ident, int32_t, int32_t if_expr,
160161
// last or the other updates will cause a thread specific state to be
161162
// created.
162163
state::ValueRAII ParallelTeamSizeRAII(state::ParallelTeamSize, NumThreads,
163-
1u, true);
164+
1u, true, ident);
164165
state::ValueRAII ParallelRegionFnRAII(state::ParallelRegionFn, wrapper_fn,
165-
(void *)nullptr, true);
166-
state::ValueRAII ActiveLevelRAII(icv::ActiveLevel, 1u, 0u, true);
167-
state::ValueRAII LevelRAII(icv::Level, 1u, 0u, true);
166+
(void *)nullptr, true, ident);
167+
state::ValueRAII ActiveLevelRAII(icv::ActiveLevel, 1u, 0u, true, ident);
168+
state::ValueRAII LevelRAII(icv::Level, 1u, 0u, true, ident);
168169

169170
// Master signals work to activate workers.
170171
synchronize::threads();

openmp/libomptarget/DeviceRTL/src/State.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ __attribute__((loader_uninitialized))
281281
ThreadStateTy *ThreadStates[mapping::MaxThreadsPerTeam];
282282
#pragma omp allocate(ThreadStates) allocator(omp_pteam_mem_alloc)
283283

284-
uint32_t &lookupForModify32Impl(uint32_t ICVStateTy::*Var) {
284+
uint32_t &lookupForModify32Impl(uint32_t ICVStateTy::*Var, IdentTy *Ident) {
285285
if (OMP_LIKELY(TeamState.ICVState.LevelVar == 0))
286286
return TeamState.ICVState.*Var;
287287
uint32_t TId = mapping::getThreadIdInBlock();
@@ -322,32 +322,32 @@ int returnValIfLevelIsActive(int Level, int Val, int DefaultVal,
322322

323323
} // namespace
324324

325-
uint32_t &state::lookup32(ValueKind Kind, bool IsReadonly) {
325+
uint32_t &state::lookup32(ValueKind Kind, bool IsReadonly, IdentTy *Ident) {
326326
switch (Kind) {
327327
case state::VK_NThreads:
328328
if (IsReadonly)
329329
return lookup32Impl(&ICVStateTy::NThreadsVar);
330-
return lookupForModify32Impl(&ICVStateTy::NThreadsVar);
330+
return lookupForModify32Impl(&ICVStateTy::NThreadsVar, Ident);
331331
case state::VK_Level:
332332
if (IsReadonly)
333333
return lookup32Impl(&ICVStateTy::LevelVar);
334-
return lookupForModify32Impl(&ICVStateTy::LevelVar);
334+
return lookupForModify32Impl(&ICVStateTy::LevelVar, Ident);
335335
case state::VK_ActiveLevel:
336336
if (IsReadonly)
337337
return lookup32Impl(&ICVStateTy::ActiveLevelVar);
338-
return lookupForModify32Impl(&ICVStateTy::ActiveLevelVar);
338+
return lookupForModify32Impl(&ICVStateTy::ActiveLevelVar, Ident);
339339
case state::VK_MaxActiveLevels:
340340
if (IsReadonly)
341341
return lookup32Impl(&ICVStateTy::MaxActiveLevelsVar);
342-
return lookupForModify32Impl(&ICVStateTy::MaxActiveLevelsVar);
342+
return lookupForModify32Impl(&ICVStateTy::MaxActiveLevelsVar, Ident);
343343
case state::VK_RunSched:
344344
if (IsReadonly)
345345
return lookup32Impl(&ICVStateTy::RunSchedVar);
346-
return lookupForModify32Impl(&ICVStateTy::RunSchedVar);
346+
return lookupForModify32Impl(&ICVStateTy::RunSchedVar, Ident);
347347
case state::VK_RunSchedChunk:
348348
if (IsReadonly)
349349
return lookup32Impl(&ICVStateTy::RunSchedChunkVar);
350-
return lookupForModify32Impl(&ICVStateTy::RunSchedChunkVar);
350+
return lookupForModify32Impl(&ICVStateTy::RunSchedChunkVar, Ident);
351351
case state::VK_ParallelTeamSize:
352352
return TeamState.ParallelTeamSize;
353353
default:
@@ -376,7 +376,7 @@ void state::init(bool IsSPMD) {
376376
ThreadStates[mapping::getThreadIdInBlock()] = nullptr;
377377
}
378378

379-
void state::enterDataEnvironment() {
379+
void state::enterDataEnvironment(IdentTy *Ident) {
380380
unsigned TId = mapping::getThreadIdInBlock();
381381
ThreadStateTy *NewThreadState =
382382
static_cast<ThreadStateTy *>(__kmpc_alloc_shared(sizeof(ThreadStateTy)));

openmp/libomptarget/DeviceRTL/src/Tasking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int32_t __kmpc_omp_task_with_deps(IdentTy *Loc, uint32_t TId,
4949
TaskDescriptorTy *TaskDescriptor, int32_t,
5050
void *, int32_t, void *) {
5151
FunctionTracingRAII();
52-
state::DateEnvironmentRAII DERAII;
52+
state::DateEnvironmentRAII DERAII(Loc);
5353

5454
TaskDescriptor->TaskFn(0, TaskDescriptor);
5555

@@ -60,7 +60,7 @@ int32_t __kmpc_omp_task_with_deps(IdentTy *Loc, uint32_t TId,
6060
void __kmpc_omp_task_begin_if0(IdentTy *Loc, uint32_t TId,
6161
TaskDescriptorTy *TaskDescriptor) {
6262
FunctionTracingRAII();
63-
state::enterDataEnvironment();
63+
state::enterDataEnvironment(Loc);
6464
}
6565

6666
void __kmpc_omp_task_complete_if0(IdentTy *Loc, uint32_t TId,

0 commit comments

Comments
 (0)