forked from OSchip/llvm-project
[Clang][OpenMP] Refactor checking for mutually exclusive clauses. NFC.
Multiple clauses are mutually exclusive. This patch refactors the functions that check for pairs of mutually exclusive clauses into a generalized function which also also accepts a list of clause types if which at most one can appear. NFC patch extracted out of D99459 by request. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D103666
This commit is contained in:
parent
b69e16b5cc
commit
c41a8fbfbb
|
@ -10121,14 +10121,14 @@ Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses,
|
|||
DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion());
|
||||
}
|
||||
|
||||
/// detach and mergeable clauses are mutially exclusive, check for it.
|
||||
static bool checkDetachMergeableClauses(Sema &S,
|
||||
ArrayRef<OMPClause *> Clauses) {
|
||||
/// Find and diagnose mutually exclusive clause kinds.
|
||||
static bool checkMutuallyExclusiveClauses(
|
||||
Sema &S, ArrayRef<OMPClause *> Clauses,
|
||||
ArrayRef<OpenMPClauseKind> MutuallyExclusiveClauses) {
|
||||
const OMPClause *PrevClause = nullptr;
|
||||
bool ErrorFound = false;
|
||||
for (const OMPClause *C : Clauses) {
|
||||
if (C->getClauseKind() == OMPC_detach ||
|
||||
C->getClauseKind() == OMPC_mergeable) {
|
||||
if (llvm::is_contained(MutuallyExclusiveClauses, C->getClauseKind())) {
|
||||
if (!PrevClause) {
|
||||
PrevClause = C;
|
||||
} else if (PrevClause->getClauseKind() != C->getClauseKind()) {
|
||||
|
@ -10153,7 +10153,8 @@ StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses,
|
|||
// OpenMP 5.0, 2.10.1 task Construct
|
||||
// If a detach clause appears on the directive, then a mergeable clause cannot
|
||||
// appear on the same directive.
|
||||
if (checkDetachMergeableClauses(*this, Clauses))
|
||||
if (checkMutuallyExclusiveClauses(*this, Clauses,
|
||||
{OMPC_detach, OMPC_mergeable}))
|
||||
return StmtError();
|
||||
|
||||
auto *CS = cast<CapturedStmt>(AStmt);
|
||||
|
@ -11457,28 +11458,6 @@ StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses,
|
|||
CancelRegion);
|
||||
}
|
||||
|
||||
static bool checkGrainsizeNumTasksClauses(Sema &S,
|
||||
ArrayRef<OMPClause *> Clauses) {
|
||||
const OMPClause *PrevClause = nullptr;
|
||||
bool ErrorFound = false;
|
||||
for (const OMPClause *C : Clauses) {
|
||||
if (C->getClauseKind() == OMPC_grainsize ||
|
||||
C->getClauseKind() == OMPC_num_tasks) {
|
||||
if (!PrevClause)
|
||||
PrevClause = C;
|
||||
else if (PrevClause->getClauseKind() != C->getClauseKind()) {
|
||||
S.Diag(C->getBeginLoc(), diag::err_omp_clauses_mutually_exclusive)
|
||||
<< getOpenMPClauseName(C->getClauseKind())
|
||||
<< getOpenMPClauseName(PrevClause->getClauseKind());
|
||||
S.Diag(PrevClause->getBeginLoc(), diag::note_omp_previous_clause)
|
||||
<< getOpenMPClauseName(PrevClause->getClauseKind());
|
||||
ErrorFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ErrorFound;
|
||||
}
|
||||
|
||||
static bool checkReductionClauseWithNogroup(Sema &S,
|
||||
ArrayRef<OMPClause *> Clauses) {
|
||||
const OMPClause *ReductionClause = nullptr;
|
||||
|
@ -11529,7 +11508,8 @@ StmtResult Sema::ActOnOpenMPTaskLoopDirective(
|
|||
// OpenMP, [2.9.2 taskloop Construct, Restrictions]
|
||||
// The grainsize clause and num_tasks clause are mutually exclusive and may
|
||||
// not appear on the same taskloop directive.
|
||||
if (checkGrainsizeNumTasksClauses(*this, Clauses))
|
||||
if (checkMutuallyExclusiveClauses(*this, Clauses,
|
||||
{OMPC_grainsize, OMPC_num_tasks}))
|
||||
return StmtError();
|
||||
// OpenMP, [2.9.2 taskloop Construct, Restrictions]
|
||||
// If a reduction clause is present on the taskloop directive, the nogroup
|
||||
|
@ -11577,7 +11557,8 @@ StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective(
|
|||
// OpenMP, [2.9.2 taskloop Construct, Restrictions]
|
||||
// The grainsize clause and num_tasks clause are mutually exclusive and may
|
||||
// not appear on the same taskloop directive.
|
||||
if (checkGrainsizeNumTasksClauses(*this, Clauses))
|
||||
if (checkMutuallyExclusiveClauses(*this, Clauses,
|
||||
{OMPC_grainsize, OMPC_num_tasks}))
|
||||
return StmtError();
|
||||
// OpenMP, [2.9.2 taskloop Construct, Restrictions]
|
||||
// If a reduction clause is present on the taskloop directive, the nogroup
|
||||
|
@ -11615,7 +11596,8 @@ StmtResult Sema::ActOnOpenMPMasterTaskLoopDirective(
|
|||
// OpenMP, [2.9.2 taskloop Construct, Restrictions]
|
||||
// The grainsize clause and num_tasks clause are mutually exclusive and may
|
||||
// not appear on the same taskloop directive.
|
||||
if (checkGrainsizeNumTasksClauses(*this, Clauses))
|
||||
if (checkMutuallyExclusiveClauses(*this, Clauses,
|
||||
{OMPC_grainsize, OMPC_num_tasks}))
|
||||
return StmtError();
|
||||
// OpenMP, [2.9.2 taskloop Construct, Restrictions]
|
||||
// If a reduction clause is present on the taskloop directive, the nogroup
|
||||
|
@ -11663,7 +11645,8 @@ StmtResult Sema::ActOnOpenMPMasterTaskLoopSimdDirective(
|
|||
// OpenMP, [2.9.2 taskloop Construct, Restrictions]
|
||||
// The grainsize clause and num_tasks clause are mutually exclusive and may
|
||||
// not appear on the same taskloop directive.
|
||||
if (checkGrainsizeNumTasksClauses(*this, Clauses))
|
||||
if (checkMutuallyExclusiveClauses(*this, Clauses,
|
||||
{OMPC_grainsize, OMPC_num_tasks}))
|
||||
return StmtError();
|
||||
// OpenMP, [2.9.2 taskloop Construct, Restrictions]
|
||||
// If a reduction clause is present on the taskloop directive, the nogroup
|
||||
|
@ -11720,7 +11703,8 @@ StmtResult Sema::ActOnOpenMPParallelMasterTaskLoopDirective(
|
|||
// OpenMP, [2.9.2 taskloop Construct, Restrictions]
|
||||
// The grainsize clause and num_tasks clause are mutually exclusive and may
|
||||
// not appear on the same taskloop directive.
|
||||
if (checkGrainsizeNumTasksClauses(*this, Clauses))
|
||||
if (checkMutuallyExclusiveClauses(*this, Clauses,
|
||||
{OMPC_grainsize, OMPC_num_tasks}))
|
||||
return StmtError();
|
||||
// OpenMP, [2.9.2 taskloop Construct, Restrictions]
|
||||
// If a reduction clause is present on the taskloop directive, the nogroup
|
||||
|
@ -11787,7 +11771,8 @@ StmtResult Sema::ActOnOpenMPParallelMasterTaskLoopSimdDirective(
|
|||
// OpenMP, [2.9.2 taskloop Construct, Restrictions]
|
||||
// The grainsize clause and num_tasks clause are mutually exclusive and may
|
||||
// not appear on the same taskloop directive.
|
||||
if (checkGrainsizeNumTasksClauses(*this, Clauses))
|
||||
if (checkMutuallyExclusiveClauses(*this, Clauses,
|
||||
{OMPC_grainsize, OMPC_num_tasks}))
|
||||
return StmtError();
|
||||
// OpenMP, [2.9.2 taskloop Construct, Restrictions]
|
||||
// If a reduction clause is present on the taskloop directive, the nogroup
|
||||
|
|
Loading…
Reference in New Issue