Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 20 additions & 39 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -1865,62 +1865,43 @@ class OMPSeverityClause final : public OMPClause {
/// \endcode
/// In this example directive '#pragma omp error' has simple
/// 'message' clause with user error message of "GNU compiler required.".
class OMPMessageClause final : public OMPClause {
class OMPMessageClause final
: public OMPOneStmtClause<llvm::omp::OMPC_message, OMPClause>,
public OMPClauseWithPreInit {
friend class OMPClauseReader;

/// Location of '('
SourceLocation LParenLoc;

// Expression of the 'message' clause.
Stmt *MessageString = nullptr;

/// Set message string of the clause.
void setMessageString(Expr *MS) { MessageString = MS; }

/// Sets the location of '('.
void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
void setMessageString(Expr *MS) { setStmt(MS); }

public:
/// Build 'message' clause with message string argument
///
/// \param MS Argument of the clause (message string).
/// \param HelperMS Helper statement for the construct.
/// \param CaptureRegion Innermost OpenMP region where expressions in this
/// clause must be captured.
/// \param StartLoc Starting location of the clause.
/// \param LParenLoc Location of '('.
/// \param EndLoc Ending location of the clause.
OMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc,
OMPMessageClause(Expr *MS, Stmt *HelperMS, OpenMPDirectiveKind CaptureRegion,
SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc)
: OMPClause(llvm::omp::OMPC_message, StartLoc, EndLoc),
LParenLoc(LParenLoc), MessageString(MS) {}

/// Build an empty clause.
OMPMessageClause()
: OMPClause(llvm::omp::OMPC_message, SourceLocation(), SourceLocation()) {
: OMPOneStmtClause(MS, StartLoc, LParenLoc, EndLoc),
OMPClauseWithPreInit(this) {
setPreInitStmt(HelperMS, CaptureRegion);
}

/// Returns the locaiton of '('.
SourceLocation getLParenLoc() const { return LParenLoc; }
/// Build an empty clause.
OMPMessageClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {}

/// Returns message string of the clause.
Expr *getMessageString() const { return cast_or_null<Expr>(MessageString); }

child_range children() {
return child_range(&MessageString, &MessageString + 1);
}

const_child_range children() const {
return const_child_range(&MessageString, &MessageString + 1);
}

child_range used_children() {
return child_range(child_iterator(), child_iterator());
}

const_child_range used_children() const {
return const_child_range(const_child_iterator(), const_child_iterator());
}
Expr *getMessageString() const { return getStmtAs<Expr>(); }

static bool classof(const OMPClause *T) {
return T->getClauseKind() == llvm::omp::OMPC_message;
/// Try to evaluate the message string at compile time.
std::optional<std::string> tryEvaluateString(ASTContext &Ctx) const {
if (Expr *MessageExpr = getMessageString())
return MessageExpr->tryEvaluateString(Ctx);
return std::nullopt;
}
};

Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,10 @@ def err_omp_unexpected_directive : Error<
"unexpected OpenMP directive %select{|'#pragma omp %1'}0">;
def err_omp_expected_punc : Error<
"expected ',' or ')' in '%0' %select{clause|directive}1">;
def warn_clause_expected_string : Warning<
def warn_clause_expected_string_literal : Warning<
"expected string literal in 'clause %0' - ignoring">, InGroup<IgnoredPragmas>;
def warn_clause_expected_string: Warning<
"expected string in 'clause %0' - ignoring">, InGroup<IgnoredPragmas>;
def err_omp_unexpected_clause : Error<
"unexpected OpenMP clause '%0' in directive '#pragma omp %1'">;
def err_omp_unexpected_clause_extension_only : Error<
Expand Down
9 changes: 6 additions & 3 deletions clang/lib/AST/OpenMPClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
return static_cast<const OMPFilterClause *>(C);
case OMPC_ompx_dyn_cgroup_mem:
return static_cast<const OMPXDynCGroupMemClause *>(C);
case OMPC_message:
return static_cast<const OMPMessageClause *>(C);
case OMPC_default:
case OMPC_proc_bind:
case OMPC_safelen:
Expand Down Expand Up @@ -158,7 +160,6 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
case OMPC_self_maps:
case OMPC_at:
case OMPC_severity:
case OMPC_message:
case OMPC_device_type:
case OMPC_match:
case OMPC_nontemporal:
Expand Down Expand Up @@ -1963,8 +1964,10 @@ void OMPClausePrinter::VisitOMPSeverityClause(OMPSeverityClause *Node) {
}

void OMPClausePrinter::VisitOMPMessageClause(OMPMessageClause *Node) {
OS << "message(\""
<< cast<StringLiteral>(Node->getMessageString())->getString() << "\")";
OS << "message(";
if (Expr *E = Node->getMessageString())
E->printPretty(OS, nullptr, Policy);
OS << ")";
}

void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
Expand Down
87 changes: 61 additions & 26 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1845,11 +1845,11 @@ void CGOpenMPRuntime::emitIfClause(CodeGenFunction &CGF, const Expr *Cond,
CGF.EmitBlock(ContBlock, /*IsFinished=*/true);
}

void CGOpenMPRuntime::emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
llvm::Function *OutlinedFn,
ArrayRef<llvm::Value *> CapturedVars,
const Expr *IfCond,
llvm::Value *NumThreads) {
void CGOpenMPRuntime::emitParallelCall(
CodeGenFunction &CGF, SourceLocation Loc, llvm::Function *OutlinedFn,
ArrayRef<llvm::Value *> CapturedVars, const Expr *IfCond,
llvm::Value *NumThreads, OpenMPNumThreadsClauseModifier NumThreadsModifier,
OpenMPSeverityClauseKind Severity, const Expr *Message) {
if (!CGF.HaveInsertPoint())
return;
llvm::Value *RTLoc = emitUpdateLocation(CGF, Loc);
Expand Down Expand Up @@ -2372,9 +2372,8 @@ void CGOpenMPRuntime::emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,

void CGOpenMPRuntime::emitErrorCall(CodeGenFunction &CGF, SourceLocation Loc,
Expr *ME, bool IsFatal) {
llvm::Value *MVL =
ME ? CGF.EmitStringLiteralLValue(cast<StringLiteral>(ME)).getPointer(CGF)
: llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
llvm::Value *MVL = ME ? CGF.EmitScalarExpr(ME)
: llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
// Build call void __kmpc_error(ident_t *loc, int severity, const char
// *message)
llvm::Value *Args[] = {
Expand Down Expand Up @@ -2699,18 +2698,54 @@ llvm::Value *CGOpenMPRuntime::emitForNext(CodeGenFunction &CGF,
CGF.getContext().BoolTy, Loc);
}

void CGOpenMPRuntime::emitNumThreadsClause(CodeGenFunction &CGF,
llvm::Value *NumThreads,
SourceLocation Loc) {
llvm::Value *CGOpenMPRuntime::emitMessageClause(CodeGenFunction &CGF,
const Expr *Message) {
if (!Message)
return llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
return CGF.EmitScalarExpr(Message);
}

llvm::Value *
CGOpenMPRuntime::emitMessageClause(CodeGenFunction &CGF,
const OMPMessageClause *MessageClause) {
return emitMessageClause(
CGF, MessageClause ? MessageClause->getMessageString() : nullptr);
}

llvm::Value *
CGOpenMPRuntime::emitSeverityClause(OpenMPSeverityClauseKind Severity) {
// OpenMP 6.0, 10.4: "If no severity clause is specified then the effect is
// as if sev-level is fatal."
return llvm::ConstantInt::get(CGM.Int32Ty,
Severity == OMPC_SEVERITY_warning ? 1 : 2);
}

llvm::Value *
CGOpenMPRuntime::emitSeverityClause(const OMPSeverityClause *SeverityClause) {
return emitSeverityClause(SeverityClause ? SeverityClause->getSeverityKind()
: OMPC_SEVERITY_unknown);
}

void CGOpenMPRuntime::emitNumThreadsClause(
CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
OpenMPNumThreadsClauseModifier Modifier, OpenMPSeverityClauseKind Severity,
const Expr *Message) {
if (!CGF.HaveInsertPoint())
return;
llvm::SmallVector<llvm::Value *, 4> Args(
{emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc),
CGF.Builder.CreateIntCast(NumThreads, CGF.Int32Ty, /*isSigned*/ true)});
// Build call __kmpc_push_num_threads(&loc, global_tid, num_threads)
llvm::Value *Args[] = {
emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc),
CGF.Builder.CreateIntCast(NumThreads, CGF.Int32Ty, /*isSigned*/ true)};
CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
CGM.getModule(), OMPRTL___kmpc_push_num_threads),
Args);
// or __kmpc_push_num_threads_strict(&loc, global_tid, num_threads, severity,
// messsage) if strict modifier is used.
RuntimeFunction FnID = OMPRTL___kmpc_push_num_threads;
if (Modifier == OMPC_NUMTHREADS_strict) {
FnID = OMPRTL___kmpc_push_num_threads_strict;
Args.push_back(emitSeverityClause(Severity));
Args.push_back(emitMessageClause(CGF, Message));
}
CGF.EmitRuntimeCall(
OMPBuilder.getOrCreateRuntimeFunction(CGM.getModule(), FnID), Args);
}

void CGOpenMPRuntime::emitProcBindClause(CodeGenFunction &CGF,
Expand Down Expand Up @@ -12100,12 +12135,11 @@ llvm::Function *CGOpenMPSIMDRuntime::emitTaskOutlinedFunction(
llvm_unreachable("Not supported in SIMD-only mode");
}

void CGOpenMPSIMDRuntime::emitParallelCall(CodeGenFunction &CGF,
SourceLocation Loc,
llvm::Function *OutlinedFn,
ArrayRef<llvm::Value *> CapturedVars,
const Expr *IfCond,
llvm::Value *NumThreads) {
void CGOpenMPSIMDRuntime::emitParallelCall(
CodeGenFunction &CGF, SourceLocation Loc, llvm::Function *OutlinedFn,
ArrayRef<llvm::Value *> CapturedVars, const Expr *IfCond,
llvm::Value *NumThreads, OpenMPNumThreadsClauseModifier NumThreadsModifier,
OpenMPSeverityClauseKind Severity, const Expr *Message) {
llvm_unreachable("Not supported in SIMD-only mode");
}

Expand Down Expand Up @@ -12208,9 +12242,10 @@ llvm::Value *CGOpenMPSIMDRuntime::emitForNext(CodeGenFunction &CGF,
llvm_unreachable("Not supported in SIMD-only mode");
}

void CGOpenMPSIMDRuntime::emitNumThreadsClause(CodeGenFunction &CGF,
llvm::Value *NumThreads,
SourceLocation Loc) {
void CGOpenMPSIMDRuntime::emitNumThreadsClause(
CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
OpenMPNumThreadsClauseModifier Modifier, OpenMPSeverityClauseKind Severity,
const Expr *Message) {
llvm_unreachable("Not supported in SIMD-only mode");
}

Expand Down
63 changes: 53 additions & 10 deletions clang/lib/CodeGen/CGOpenMPRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,22 @@ class CGOpenMPRuntime {
/// specified, nullptr otherwise.
/// \param NumThreads The value corresponding to the num_threads clause, if
/// any, or nullptr.
/// \param NumThreadsModifier The modifier of the num_threads clause, if
/// any, ignored otherwise.
/// \param Severity The severity corresponding to the num_threads clause, if
/// any, ignored otherwise.
/// \param Message The message string corresponding to the num_threads clause,
/// if any, or nullptr.
///
virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
llvm::Function *OutlinedFn,
ArrayRef<llvm::Value *> CapturedVars,
const Expr *IfCond, llvm::Value *NumThreads);
virtual void
emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
llvm::Function *OutlinedFn,
ArrayRef<llvm::Value *> CapturedVars, const Expr *IfCond,
llvm::Value *NumThreads,
OpenMPNumThreadsClauseModifier NumThreadsModifier =
OMPC_NUMTHREADS_unknown,
OpenMPSeverityClauseKind Severity = OMPC_SEVERITY_fatal,
const Expr *Message = nullptr);

/// Emits a critical region.
/// \param CriticalName Name of the critical region.
Expand Down Expand Up @@ -1037,13 +1048,28 @@ class CGOpenMPRuntime {
Address IL, Address LB,
Address UB, Address ST);

virtual llvm::Value *emitMessageClause(CodeGenFunction &CGF,
const Expr *Message);
virtual llvm::Value *emitMessageClause(CodeGenFunction &CGF,
const OMPMessageClause *MessageClause);

virtual llvm::Value *emitSeverityClause(OpenMPSeverityClauseKind Severity);
virtual llvm::Value *
emitSeverityClause(const OMPSeverityClause *SeverityClause);

/// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
/// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
/// clause.
/// If the modifier 'strict' is given:
/// Emits call to void __kmpc_push_num_threads_strict(ident_t *loc, kmp_int32
/// global_tid, kmp_int32 num_threads, int severity, const char *message) to
/// generate code for 'num_threads' clause with 'strict' modifier.
/// \param NumThreads An integer value of threads.
virtual void emitNumThreadsClause(CodeGenFunction &CGF,
llvm::Value *NumThreads,
SourceLocation Loc);
virtual void emitNumThreadsClause(
CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
OpenMPNumThreadsClauseModifier Modifier = OMPC_NUMTHREADS_unknown,
OpenMPSeverityClauseKind Severity = OMPC_SEVERITY_fatal,
const Expr *Message = nullptr);

/// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
/// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
Expand Down Expand Up @@ -1737,11 +1763,21 @@ class CGOpenMPSIMDRuntime final : public CGOpenMPRuntime {
/// specified, nullptr otherwise.
/// \param NumThreads The value corresponding to the num_threads clause, if
/// any, or nullptr.
/// \param NumThreadsModifier The modifier of the num_threads clause, if
/// any, ignored otherwise.
/// \param Severity The severity corresponding to the num_threads clause, if
/// any, ignored otherwise.
/// \param Message The message string corresponding to the num_threads clause,
/// if any, or nullptr.
///
void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
llvm::Function *OutlinedFn,
ArrayRef<llvm::Value *> CapturedVars,
const Expr *IfCond, llvm::Value *NumThreads) override;
const Expr *IfCond, llvm::Value *NumThreads,
OpenMPNumThreadsClauseModifier NumThreadsModifier =
OMPC_NUMTHREADS_unknown,
OpenMPSeverityClauseKind Severity = OMPC_SEVERITY_fatal,
const Expr *Message = nullptr) override;

/// Emits a critical region.
/// \param CriticalName Name of the critical region.
Expand Down Expand Up @@ -1911,9 +1947,16 @@ class CGOpenMPSIMDRuntime final : public CGOpenMPRuntime {
/// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
/// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
/// clause.
/// If the modifier 'strict' is given:
/// Emits call to void __kmpc_push_num_threads_strict(ident_t *loc, kmp_int32
/// global_tid, kmp_int32 num_threads, int severity, const char *message) to
/// generate code for 'num_threads' clause with 'strict' modifier.
/// \param NumThreads An integer value of threads.
void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads,
SourceLocation Loc) override;
void emitNumThreadsClause(
CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
OpenMPNumThreadsClauseModifier Modifier = OMPC_NUMTHREADS_unknown,
OpenMPSeverityClauseKind Severity = OMPC_SEVERITY_fatal,
const Expr *Message = nullptr) override;

/// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
/// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
Expand Down
Loading