Skip to content

Commit db65ba9

Browse files
committed
Revert "[offload][OpenMP] Remove device code for num_threads strict (llvm#157893)"
This reverts commit 23302a2.
1 parent c2d3d17 commit db65ba9

16 files changed

+6725
-676
lines changed

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,9 +1429,9 @@ void CGOpenMPRuntimeGPU::emitParallelCall(
14291429
if (!CGF.HaveInsertPoint())
14301430
return;
14311431

1432-
auto &&ParallelGen = [this, Loc, OutlinedFn, CapturedVars, IfCond,
1433-
NumThreads](CodeGenFunction &CGF,
1434-
PrePostActionTy &Action) {
1432+
auto &&ParallelGen = [this, Loc, OutlinedFn, CapturedVars, IfCond, NumThreads,
1433+
NumThreadsModifier, Severity, Message](
1434+
CodeGenFunction &CGF, PrePostActionTy &Action) {
14351435
CGBuilderTy &Bld = CGF.Builder;
14361436
llvm::Value *NumThreadsVal = NumThreads;
14371437
llvm::Function *WFn = WrapperFunctionsMap[OutlinedFn];
@@ -1479,21 +1479,22 @@ void CGOpenMPRuntimeGPU::emitParallelCall(
14791479
NumThreadsVal = Bld.CreateZExtOrTrunc(NumThreadsVal, CGF.Int32Ty);
14801480

14811481
assert(IfCondVal && "Expected a value");
1482+
RuntimeFunction FnID = OMPRTL___kmpc_parallel_51;
14821483
llvm::Value *RTLoc = emitUpdateLocation(CGF, Loc);
1483-
llvm::Value *Args[] = {
1484-
RTLoc,
1485-
getThreadID(CGF, Loc),
1486-
IfCondVal,
1487-
NumThreadsVal,
1488-
llvm::ConstantInt::get(CGF.Int32Ty, -1),
1489-
FnPtr,
1490-
ID,
1491-
Bld.CreateBitOrPointerCast(CapturedVarsAddrs.emitRawPointer(CGF),
1492-
CGF.VoidPtrPtrTy),
1493-
llvm::ConstantInt::get(CGM.SizeTy, CapturedVars.size())};
1494-
CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
1495-
CGM.getModule(), OMPRTL___kmpc_parallel_51),
1496-
Args);
1484+
llvm::SmallVector<llvm::Value *, 10> Args(
1485+
{RTLoc, getThreadID(CGF, Loc), IfCondVal, NumThreadsVal,
1486+
llvm::ConstantInt::get(CGF.Int32Ty, -1), FnPtr, ID,
1487+
Bld.CreateBitOrPointerCast(CapturedVarsAddrs.emitRawPointer(CGF),
1488+
CGF.VoidPtrPtrTy),
1489+
llvm::ConstantInt::get(CGM.SizeTy, CapturedVars.size())});
1490+
if (NumThreadsModifier == OMPC_NUMTHREADS_strict) {
1491+
FnID = OMPRTL___kmpc_parallel_60;
1492+
Args.append({llvm::ConstantInt::get(CGM.Int32Ty, true),
1493+
emitSeverityClause(Severity),
1494+
emitMessageClause(CGF, Message)});
1495+
}
1496+
CGF.EmitRuntimeCall(
1497+
OMPBuilder.getOrCreateRuntimeFunction(CGM.getModule(), FnID), Args);
14971498
};
14981499

14991500
RegionCodeGenTy RCG(ParallelGen);

clang/lib/CodeGen/CGOpenMPRuntimeGPU.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ class CGOpenMPRuntimeGPU : public CGOpenMPRuntime {
224224
/// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
225225
/// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
226226
/// clause.
227+
/// If the modifier 'strict' is given:
228+
/// Emits call to void __kmpc_push_num_threads_strict(ident_t *loc, kmp_int32
229+
/// global_tid, kmp_int32 num_threads, int severity, const char *message) to
230+
/// generate code for 'num_threads' clause with 'strict' modifier.
231+
/// \param NumThreads An integer value of threads.
227232
void emitNumThreadsClause(
228233
CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
229234
OpenMPNumThreadsClauseModifier Modifier = OMPC_NUMTHREADS_unknown,
@@ -292,11 +297,11 @@ class CGOpenMPRuntimeGPU : public CGOpenMPRuntime {
292297
/// \param NumThreads The value corresponding to the num_threads clause, if
293298
/// any, or nullptr.
294299
/// \param NumThreadsModifier The modifier of the num_threads clause, if
295-
/// any, ignored otherwise. Currently unused on the device.
300+
/// any, ignored otherwise.
296301
/// \param Severity The severity corresponding to the num_threads clause, if
297-
/// any, ignored otherwise. Currently unused on the device.
302+
/// any, ignored otherwise.
298303
/// \param Message The message string corresponding to the num_threads clause,
299-
/// if any, or nullptr. Currently unused on the device.
304+
/// if any, or nullptr.
300305
void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
301306
llvm::Function *OutlinedFn,
302307
ArrayRef<llvm::Value *> CapturedVars,

clang/test/AST/ByteCode/openmp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ extern int omp_get_thread_num(void);
1717

1818
int test2() {
1919
int x = 0;
20-
int result[N] = {0};
20+
int device_result[N] = {0};
2121

22-
#pragma omp parallel loop num_threads(strict: N) severity(warning) message("msg")
22+
#pragma omp target parallel loop num_threads(strict: N) severity(warning) message("msg")
2323
for (int i = 0; i < N; i++) {
2424
x = omp_get_thread_num();
25-
result[i] = i + x;
25+
device_result[i] = i + x;
2626
}
2727
}
2828

clang/test/OpenMP/amdgcn_target_parallel_num_threads_codegen.cpp

Lines changed: 1095 additions & 0 deletions
Large diffs are not rendered by default.

clang/test/OpenMP/nvptx_target_codegen.cpp

Lines changed: 847 additions & 66 deletions
Large diffs are not rendered by default.

clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp

Lines changed: 725 additions & 35 deletions
Large diffs are not rendered by default.

clang/test/OpenMP/target_parallel_generic_loop_codegen.cpp

Lines changed: 418 additions & 18 deletions
Large diffs are not rendered by default.

clang/test/OpenMP/target_parallel_num_threads_strict_codegen.cpp

Lines changed: 2956 additions & 0 deletions
Large diffs are not rendered by default.

clang/test/OpenMP/target_teams_generic_loop_codegen_as_parallel_for.cpp

Lines changed: 92 additions & 90 deletions
Large diffs are not rendered by default.

clang/test/OpenMP/xteam_red_callee.cpp

Lines changed: 122 additions & 116 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)