@@ -1869,11 +1869,11 @@ void CGOpenMPRuntime::emitIfClause(CodeGenFunction &CGF, const Expr *Cond,
18691869 CGF.EmitBlock(ContBlock, /*IsFinished=*/true);
18701870}
18711871
1872- void CGOpenMPRuntime::emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
1873- llvm::Function *OutlinedFn,
1874- ArrayRef<llvm::Value *> CapturedVars,
1875- const Expr *IfCond ,
1876- llvm::Value *NumThreads ) {
1872+ void CGOpenMPRuntime::emitParallelCall(
1873+ CodeGenFunction &CGF, SourceLocation Loc, llvm::Function *OutlinedFn,
1874+ ArrayRef<llvm::Value *> CapturedVars, const Expr *IfCond ,
1875+ llvm::Value *NumThreads, OpenMPNumThreadsClauseModifier NumThreadsModifier ,
1876+ OpenMPSeverityClauseKind Severity, const Expr *Message ) {
18771877 if (!CGF.HaveInsertPoint())
18781878 return;
18791879 llvm::Value *RTLoc = emitUpdateLocation(CGF, Loc);
@@ -2396,9 +2396,8 @@ void CGOpenMPRuntime::emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
23962396
23972397void CGOpenMPRuntime::emitErrorCall(CodeGenFunction &CGF, SourceLocation Loc,
23982398 Expr *ME, bool IsFatal) {
2399- llvm::Value *MVL =
2400- ME ? CGF.EmitStringLiteralLValue(cast<StringLiteral>(ME)).getPointer(CGF)
2401- : llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
2399+ llvm::Value *MVL = ME ? CGF.EmitScalarExpr(ME)
2400+ : llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
24022401 // Build call void __kmpc_error(ident_t *loc, int severity, const char
24032402 // *message)
24042403 llvm::Value *Args[] = {
@@ -2746,18 +2745,54 @@ llvm::Value *CGOpenMPRuntime::emitForNext(CodeGenFunction &CGF,
27462745 CGF.getContext().BoolTy, Loc);
27472746}
27482747
2749- void CGOpenMPRuntime::emitNumThreadsClause(CodeGenFunction &CGF,
2750- llvm::Value *NumThreads,
2751- SourceLocation Loc) {
2748+ llvm::Value *CGOpenMPRuntime::emitMessageClause(CodeGenFunction &CGF,
2749+ const Expr *Message) {
2750+ if (!Message)
2751+ return llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
2752+ return CGF.EmitScalarExpr(Message);
2753+ }
2754+
2755+ llvm::Value *
2756+ CGOpenMPRuntime::emitMessageClause(CodeGenFunction &CGF,
2757+ const OMPMessageClause *MessageClause) {
2758+ return emitMessageClause(
2759+ CGF, MessageClause ? MessageClause->getMessageString() : nullptr);
2760+ }
2761+
2762+ llvm::Value *
2763+ CGOpenMPRuntime::emitSeverityClause(OpenMPSeverityClauseKind Severity) {
2764+ // OpenMP 6.0, 10.4: "If no severity clause is specified then the effect is
2765+ // as if sev-level is fatal."
2766+ return llvm::ConstantInt::get(CGM.Int32Ty,
2767+ Severity == OMPC_SEVERITY_warning ? 1 : 2);
2768+ }
2769+
2770+ llvm::Value *
2771+ CGOpenMPRuntime::emitSeverityClause(const OMPSeverityClause *SeverityClause) {
2772+ return emitSeverityClause(SeverityClause ? SeverityClause->getSeverityKind()
2773+ : OMPC_SEVERITY_unknown);
2774+ }
2775+
2776+ void CGOpenMPRuntime::emitNumThreadsClause(
2777+ CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
2778+ OpenMPNumThreadsClauseModifier Modifier, OpenMPSeverityClauseKind Severity,
2779+ const Expr *Message) {
27522780 if (!CGF.HaveInsertPoint())
27532781 return;
2782+ llvm::SmallVector<llvm::Value *, 4> Args(
2783+ {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc),
2784+ CGF.Builder.CreateIntCast(NumThreads, CGF.Int32Ty, /*isSigned*/ true)});
27542785 // Build call __kmpc_push_num_threads(&loc, global_tid, num_threads)
2755- llvm::Value *Args[] = {
2756- emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc),
2757- CGF.Builder.CreateIntCast(NumThreads, CGF.Int32Ty, /*isSigned*/ true)};
2758- CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
2759- CGM.getModule(), OMPRTL___kmpc_push_num_threads),
2760- Args);
2786+ // or __kmpc_push_num_threads_strict(&loc, global_tid, num_threads, severity,
2787+ // messsage) if strict modifier is used.
2788+ RuntimeFunction FnID = OMPRTL___kmpc_push_num_threads;
2789+ if (Modifier == OMPC_NUMTHREADS_strict) {
2790+ FnID = OMPRTL___kmpc_push_num_threads_strict;
2791+ Args.push_back(emitSeverityClause(Severity));
2792+ Args.push_back(emitMessageClause(CGF, Message));
2793+ }
2794+ CGF.EmitRuntimeCall(
2795+ OMPBuilder.getOrCreateRuntimeFunction(CGM.getModule(), FnID), Args);
27612796}
27622797
27632798void CGOpenMPRuntime::emitProcBindClause(CodeGenFunction &CGF,
@@ -12552,12 +12587,11 @@ llvm::Function *CGOpenMPSIMDRuntime::emitTaskOutlinedFunction(
1255212587 llvm_unreachable("Not supported in SIMD-only mode");
1255312588}
1255412589
12555- void CGOpenMPSIMDRuntime::emitParallelCall(CodeGenFunction &CGF,
12556- SourceLocation Loc,
12557- llvm::Function *OutlinedFn,
12558- ArrayRef<llvm::Value *> CapturedVars,
12559- const Expr *IfCond,
12560- llvm::Value *NumThreads) {
12590+ void CGOpenMPSIMDRuntime::emitParallelCall(
12591+ CodeGenFunction &CGF, SourceLocation Loc, llvm::Function *OutlinedFn,
12592+ ArrayRef<llvm::Value *> CapturedVars, const Expr *IfCond,
12593+ llvm::Value *NumThreads, OpenMPNumThreadsClauseModifier NumThreadsModifier,
12594+ OpenMPSeverityClauseKind Severity, const Expr *Message) {
1256112595 llvm_unreachable("Not supported in SIMD-only mode");
1256212596}
1256312597
@@ -12661,9 +12695,10 @@ llvm::Value *CGOpenMPSIMDRuntime::emitForNext(CodeGenFunction &CGF,
1266112695 llvm_unreachable("Not supported in SIMD-only mode");
1266212696}
1266312697
12664- void CGOpenMPSIMDRuntime::emitNumThreadsClause(CodeGenFunction &CGF,
12665- llvm::Value *NumThreads,
12666- SourceLocation Loc) {
12698+ void CGOpenMPSIMDRuntime::emitNumThreadsClause(
12699+ CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
12700+ OpenMPNumThreadsClauseModifier Modifier, OpenMPSeverityClauseKind Severity,
12701+ const Expr *Message) {
1266712702 llvm_unreachable("Not supported in SIMD-only mode");
1266812703}
1266912704
0 commit comments