Skip to content

Commit 6493e84

Browse files
committed
[offload][OpenMP] Re-enable strict modifier for num_threads
This commit re-enables the support for the strict modifier in num_threads within target regions. The message and severity clauses remain unsupported. When the strict check fails, the program terminates without displaying any meaningful message, but it is still compliant with the OpenMP standard (i.e., when no message clause is specified).
1 parent 4446aa7 commit 6493e84

16 files changed

+17330
-7320
lines changed

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -922,13 +922,6 @@ void CGOpenMPRuntimeGPU::emitNumThreadsClause(
922922
OpenMPNumThreadsClauseModifier Modifier, OpenMPSeverityClauseKind Severity,
923923
SourceLocation SeverityLoc, const Expr *Message,
924924
SourceLocation MessageLoc) {
925-
if (Modifier == OMPC_NUMTHREADS_strict) {
926-
CGM.getDiags().Report(Loc,
927-
diag::warn_omp_gpu_unsupported_modifier_for_clause)
928-
<< "strict" << getOpenMPClauseName(OMPC_num_threads);
929-
return;
930-
}
931-
932925
// Nothing to do.
933926
}
934927

@@ -1236,9 +1229,9 @@ void CGOpenMPRuntimeGPU::emitParallelCall(
12361229
if (!CGF.HaveInsertPoint())
12371230
return;
12381231

1239-
auto &&ParallelGen = [this, Loc, OutlinedFn, CapturedVars, IfCond,
1240-
NumThreads](CodeGenFunction &CGF,
1241-
PrePostActionTy &Action) {
1232+
auto &&ParallelGen = [this, Loc, OutlinedFn, CapturedVars, IfCond, NumThreads,
1233+
NumThreadsModifier](CodeGenFunction &CGF,
1234+
PrePostActionTy &Action) {
12421235
CGBuilderTy &Bld = CGF.Builder;
12431236
llvm::Value *NumThreadsVal = NumThreads;
12441237
llvm::Function *WFn = WrapperFunctionsMap[OutlinedFn];
@@ -1289,21 +1282,20 @@ void CGOpenMPRuntimeGPU::emitParallelCall(
12891282
NumThreadsVal = Bld.CreateZExtOrTrunc(NumThreadsVal, CGF.Int32Ty);
12901283

12911284
assert(IfCondVal && "Expected a value");
1285+
RuntimeFunction FnID = OMPRTL___kmpc_parallel_51;
12921286
llvm::Value *RTLoc = emitUpdateLocation(CGF, Loc);
1293-
llvm::Value *Args[] = {
1294-
RTLoc,
1295-
getThreadID(CGF, Loc),
1296-
IfCondVal,
1297-
NumThreadsVal,
1298-
llvm::ConstantInt::get(CGF.Int32Ty, -1),
1299-
FnPtr,
1300-
ID,
1301-
Bld.CreateBitOrPointerCast(CapturedVarsAddrs.emitRawPointer(CGF),
1302-
CGF.VoidPtrPtrTy),
1303-
llvm::ConstantInt::get(CGM.SizeTy, CapturedVars.size())};
1304-
CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
1305-
CGM.getModule(), OMPRTL___kmpc_parallel_51),
1306-
Args);
1287+
llvm::SmallVector<llvm::Value *, 10> Args(
1288+
{RTLoc, getThreadID(CGF, Loc), IfCondVal, NumThreadsVal,
1289+
llvm::ConstantInt::get(CGF.Int32Ty, -1), FnPtr, ID,
1290+
Bld.CreateBitOrPointerCast(CapturedVarsAddrs.emitRawPointer(CGF),
1291+
CGF.VoidPtrPtrTy),
1292+
llvm::ConstantInt::get(CGM.SizeTy, CapturedVars.size())});
1293+
if (NumThreadsModifier == OMPC_NUMTHREADS_strict) {
1294+
FnID = OMPRTL___kmpc_parallel_60;
1295+
Args.append({llvm::ConstantInt::get(CGM.Int32Ty, true)});
1296+
}
1297+
CGF.EmitRuntimeCall(
1298+
OMPBuilder.getOrCreateRuntimeFunction(CGM.getModule(), FnID), Args);
13071299
};
13081300

13091301
RegionCodeGenTy RCG(ParallelGen);

clang/lib/CodeGen/CGOpenMPRuntimeGPU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class CGOpenMPRuntimeGPU : public CGOpenMPRuntime {
245245
/// \param NumThreads The value corresponding to the num_threads clause, if
246246
/// any, or nullptr.
247247
/// \param NumThreadsModifier The modifier of the num_threads clause, if
248-
/// any, ignored otherwise. Currently unused on the device.
248+
/// any, ignored otherwise.
249249
/// \param Severity The severity corresponding to the num_threads clause, if
250250
/// any, ignored otherwise. Currently unused on the device.
251251
/// \param Message The message string corresponding to the num_threads clause,

clang/test/AST/ByteCode/openmp.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +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)
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

29-

clang/test/OpenMP/amdgcn_parallel_num_threads_strict_messages.cpp

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)