[Clang][OpenMP] Add parsing for dims modifier in num_teams and thread_limit
Add parsing for dims modifier (OpenMP 6.1) in num_teams and thread_limit clauses. Examples:
constexpr int N = 2;
#pragma omp teams num_teams(dims(3): x, y, z) thread_limit(dims(N): a, b)
{ ... }
@llvm/pr-subscribers-clang-modules
Author: Kevin Sala Penades (kevinsala)
Changes
Add parsing for dims modifier (OpenMP 6.1) in num_teams and thread_limit clauses. Examples:
constexpr int N = 2;
#pragma omp teams num_teams(dims(3): x, y, z) thread_limit(dims(N): a, b)
{ ... }
Patch is 61.34 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/206412.diff
20 Files Affected:
- (modified) clang/include/clang/AST/OpenMPClause.h (+61-19)
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+11-4)
- (modified) clang/include/clang/Basic/OpenMPKinds.def (+8)
- (modified) clang/include/clang/Basic/OpenMPKinds.h (+6)
- (modified) clang/include/clang/Sema/SemaOpenMP.h (+22-10)
- (modified) clang/lib/AST/OpenMPClause.cpp (+23-6)
- (modified) clang/lib/AST/StmtProfile.cpp (+3)
- (modified) clang/lib/Basic/OpenMPKinds.cpp (+19-2)
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+63-21)
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+161-70)
- (modified) clang/lib/Sema/TreeTransform.h (+23-11)
- (modified) clang/lib/Serialization/ASTReader.cpp (+3)
- (modified) clang/lib/Serialization/ASTWriter.cpp (+3)
- (added) clang/test/OpenMP/dims_modifier_ast_print.cpp (+40)
- (added) clang/test/OpenMP/dims_modifier_messages.cpp (+124)
- (modified) clang/test/OpenMP/ompx_bare_messages.c (+1-1)
- (modified) clang/test/OpenMP/target_teams_distribute_num_teams_messages.cpp (+8-8)
- (modified) clang/test/OpenMP/target_teams_distribute_parallel_for_num_teams_messages.cpp (+4-4)
- (modified) clang/test/OpenMP/teams_num_teams_messages.cpp (+10-10)
- (modified) clang/tools/libclang/CIndex.cpp (+2)
diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h
index bae396d883dc8..bd58a41d4df1e 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -6982,6 +6982,13 @@ class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
/// single expression 'n' as upper-bound and modifier expression 'm' as
/// lower-bound.
///
+/// \code
+/// #pragma omp teams num_teams(dims(2): x, y)
+/// \endcode
+/// In this example directive '#pragma omp teams' has clause 'num_teams' with
+/// the 'dims' modifier specifying two dimensions. The list specifies the number
+/// of teams in each dimension.
+///
/// When 'ompx_bare' clause exists on a 'target' directive, 'num_teams' clause
/// can accept up to three expressions.
///
@@ -6995,9 +7002,6 @@ class OMPNumTeamsClause final
friend OMPVarListClause;
friend TrailingObjects;
- /// Location of '('.
- SourceLocation LParenLoc;
-
/// Modifier that was specified.
OpenMPNumTeamsClauseModifier Modifier = OMPC_NUMTEAMS_unknown;
@@ -7041,12 +7045,6 @@ class OMPNumTeamsClause final
/// \param N The number of variables.
static OMPNumTeamsClause *CreateEmpty(const ASTContext &C, unsigned N);
- /// Sets the location of '('.
- void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
-
- /// Returns the location of '('.
- SourceLocation getLParenLoc() const { return LParenLoc; }
-
/// Return NumTeams expressions.
ArrayRef<Expr *> getNumTeams() { return getVarRefs(); }
@@ -7070,6 +7068,13 @@ class OMPNumTeamsClause final
/// Set the expression of the modifier.
void setModifierExpr(Expr *E) { *varlist_end() = E; }
+ /// Get the expression of the modifier if it is the dims modifier.
+ const Expr *getDimsModifierExpr() const {
+ if (Modifier == OMPC_NUMTEAMS_dims)
+ return getModifierExpr();
+ return nullptr;
+ }
+
/// Get the location of the modifier.
SourceLocation getModifierLoc() const { return ModifierLoc; }
@@ -7106,6 +7111,13 @@ class OMPNumTeamsClause final
/// In this example directive '#pragma omp teams' has clause 'thread_limit'
/// with single expression 'n'.
///
+/// \code
+/// #pragma omp teams thread_limit(dims(2): x, y)
+/// \endcode
+/// In this example directive '#pragma omp teams' has clause 'thread_limit' with
+/// the 'dims' modifier specifying two dimensions. The list specifies the limit
+/// on the number of threads in each dimension.
+///
/// When 'ompx_bare' clause exists on a 'target' directive, 'thread_limit'
/// clause can accept up to three expressions.
///
@@ -7119,8 +7131,11 @@ class OMPThreadLimitClause final
friend OMPVarListClause;
friend TrailingObjects;
- /// Location of '('.
- SourceLocation LParenLoc;
+ /// Modifier that was specified.
+ OpenMPThreadLimitClauseModifier Modifier = OMPC_THREADLIMIT_unknown;
+
+ /// Location of the modifier.
+ SourceLocation ModifierLoc;
OMPThreadLimitClause(const ASTContext &C, SourceLocation StartLoc,
SourceLocation LParenLoc, SourceLocation EndLoc,
@@ -7143,11 +7158,16 @@ class OMPThreadLimitClause final
/// \param LParenLoc Location of '('.
/// \param EndLoc Ending location of the clause.
/// \param VL List of references to the variables.
+ /// \param Modifier The modifier specified in the clause.
+ /// \param ModifierExpr The expression of the modifier.
+ /// \param ModifierLoc Location of the modifier.
/// \param PreInit
static OMPThreadLimitClause *
Create(const ASTContext &C, OpenMPDirectiveKind CaptureRegion,
SourceLocation StartLoc, SourceLocation LParenLoc,
- SourceLocation EndLoc, ArrayRef<Expr *> VL, Stmt *PreInit);
+ SourceLocation EndLoc, ArrayRef<Expr *> VL,
+ OpenMPThreadLimitClauseModifier Modifier, Expr *ModifierExpr,
+ SourceLocation ModifierLoc, Stmt *PreInit);
/// Creates an empty clause with \a N variables.
///
@@ -7155,12 +7175,6 @@ class OMPThreadLimitClause final
/// \param N The number of variables.
static OMPThreadLimitClause *CreateEmpty(const ASTContext &C, unsigned N);
- /// Sets the location of '('.
- void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
-
- /// Returns the location of '('.
- SourceLocation getLParenLoc() const { return LParenLoc; }
-
/// Return ThreadLimit expressions.
ArrayRef<Expr *> getThreadLimit() { return getVarRefs(); }
@@ -7169,9 +7183,37 @@ class OMPThreadLimitClause final
return const_cast<OMPThreadLimitClause *>(this)->getThreadLimit();
}
+ /// Get the modifier.
+ OpenMPThreadLimitClauseModifier getModifier() const { return Modifier; }
+
+ /// Set the modifier.
+ void setModifier(OpenMPThreadLimitClauseModifier M) { Modifier = M; }
+
+ /// Get the expression of the modifier.
+ const Expr *getModifierExpr() const { return *varlist_end(); }
+
+ /// Get the expression of the modifier.
+ Expr *getModifierExpr() { return *varlist_end(); }
+
+ /// Set the expression of the modifier.
+ void setModifierExpr(Expr *E) { *varlist_end() = E; }
+
+ /// Get the expression of the modifier if it is the dims modifier.
+ const Expr *getDimsModifierExpr() const {
+ if (Modifier == OMPC_THREADLIMIT_dims)
+ return getModifierExpr();
+ return nullptr;
+ }
+
+ /// Get the location of the modifier.
+ SourceLocation getModifierLoc() const { return ModifierLoc; }
+
+ /// Set the location of the modifier.
+ void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
+
child_range children() {
return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
- reinterpret_cast<Stmt **>(varlist_end()));
+ reinterpret_cast<Stmt **>(varlist_end()) + 1);
}
const_child_range children() const {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6b2d78881d4e2..15f97e5e2abc6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12779,9 +12779,11 @@ def warn_omp_unterminated_declare_target : Warning<
"expected '#pragma omp end declare target' at end of file to match '#pragma omp %0'">,
InGroup<SourceUsesOpenMP>;
def err_ompx_bare_no_grid : Error<
- "'ompx_bare' clauses requires explicit grid size via 'num_teams' and 'thread_limit' clauses">;
-def err_omp_multi_expr_not_allowed: Error<"only one expression allowed in '%0' clause">;
-def err_ompx_more_than_three_expr_not_allowed: Error<"at most three expressions are allowed in '%0' clause in 'target teams ompx_bare' construct">;
+ "'ompx_bare' clause requires explicit grid size via 'num_teams' and 'thread_limit' clauses">;
+def err_ompx_bare_no_dims : Error<
+ "'ompx_bare' clause cannot be specified with 'dims' modifier in 'num_teams' and 'thread_limit' clauses">;
+def err_omp_multi_expr_not_allowed : Error<"only one expression allowed in '%0' clause">;
+def err_omp_max_three_exprs: Error<"maximum three expressions are supported in '%0' clause">;
def err_omp_transparent_invalid_value : Error<"invalid value for transparent clause,"
" expected one of: omp_not_impex, omp_import, omp_export, omp_impex">;
def err_omp_transparent_invalid_type : Error<
@@ -12790,6 +12792,12 @@ def err_omp_num_teams_lower_bound_larger
: Error<"lower bound is greater than upper bound in 'num_teams' clause">;
def err_omp_modifier_requires_version : Error<
"'%0' modifier in '%1' clause requires OpenMP %2 or later">;
+def err_omp_unexpected_num_exprs
+ : Error<"unexpected number of expressions in '%0' clause">;
+def err_omp_max_supported_dims
+ : Error<"at most three dimensions are supported in '%0' clause">;
+def err_omp_incompatible_modifiers
+ : Error<"'%0' modifier cannot be specified with '%1' modifier in '%2' clause">;
} // end of OpenMP category
let CategoryName = "Related Result Type Issue" in {
@@ -12816,7 +12824,6 @@ def note_related_result_type_explicit : Note<
"%select{| and is expected to return an instance of its class type}0">;
def err_invalid_type_for_program_scope_var : Error<
"the %0 type cannot be used to declare a program scope variable">;
-
}
let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Basic/OpenMPKinds.def b/clang/include/clang/Basic/OpenMPKinds.def
index 079ff4a583f9f..5c396a5d2d4b3 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -101,6 +101,9 @@
#ifndef OPENMP_NUMTHREADS_MODIFIER
#define OPENMP_NUMTHREADS_MODIFIER(Name)
#endif
+#ifndef OPENMP_THREADLIMIT_MODIFIER
+#define OPENMP_THREADLIMIT_MODIFIER(Name)
+#endif
#ifndef OPENMP_DOACROSS_MODIFIER
#define OPENMP_DOACROSS_MODIFIER(Name)
#endif
@@ -273,10 +276,14 @@ OPENMP_NUMTASKS_MODIFIER(strict)
// Modifiers for the 'num_teams' clause.
OPENMP_NUMTEAMS_MODIFIER(lower_bound)
+OPENMP_NUMTEAMS_MODIFIER(dims)
// Modifiers for the 'num_tasks' clause.
OPENMP_NUMTHREADS_MODIFIER(strict)
+// Modifiers for the 'thread_limit' clause.
+OPENMP_THREADLIMIT_MODIFIER(dims)
+
// Modifiers for 'allocate' clause.
OPENMP_ALLOCATE_MODIFIER(allocator)
OPENMP_ALLOCATE_MODIFIER(align)
@@ -301,6 +308,7 @@ OPENMP_USE_DEVICE_PTR_FALLBACK_MODIFIER(fb_preserve)
#undef OPENMP_NUMTASKS_MODIFIER
#undef OPENMP_NUMTEAMS_MODIFIER
#undef OPENMP_NUMTHREADS_MODIFIER
+#undef OPENMP_THREADLIMIT_MODIFIER
#undef OPENMP_DYN_GROUPPRIVATE_MODIFIER
#undef OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER
#undef OPENMP_GRAINSIZE_MODIFIER
diff --git a/clang/include/clang/Basic/OpenMPKinds.h b/clang/include/clang/Basic/OpenMPKinds.h
index 3ee6cb83a431e..36c388668a455 100644
--- a/clang/include/clang/Basic/OpenMPKinds.h
+++ b/clang/include/clang/Basic/OpenMPKinds.h
@@ -274,6 +274,12 @@ enum OpenMPNumThreadsClauseModifier {
OMPC_NUMTHREADS_unknown
};
+enum OpenMPThreadLimitClauseModifier {
+#define OPENMP_THREADLIMIT_MODIFIER(Name) OMPC_THREADLIMIT_##Name,
+#include "clang/Basic/OpenMPKinds.def"
+ OMPC_THREADLIMIT_unknown
+};
+
/// OpenMP dependence types for 'doacross' clause.
enum OpenMPDoacrossClauseModifier {
#define OPENMP_DOACROSS_MODIFIER(Name) OMPC_DOACROSS_##Name,
diff --git a/clang/include/clang/Sema/SemaOpenMP.h b/clang/include/clang/Sema/SemaOpenMP.h
index f689e227866a7..726ac8539c66b 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -1188,10 +1188,15 @@ class SemaOpenMP : public SemaBase {
SourceLocation RLoc;
CXXScopeSpec ReductionOrMapperIdScopeSpec;
DeclarationNameInfo ReductionOrMapperId;
- int ExtraModifier =
- -1; ///< Additional modifier for linear, map, depend,
- ///< lastprivate, use_device_ptr, or num_teams clause.
- Expr *ExtraModifierExpr = nullptr;
+ SmallVector<int, 2> ExtraModifierArray = {-1, -1};
+ SmallVector<Expr *, 2> ExtraModifierExprArray = {nullptr, nullptr};
+ SmallVector<SourceLocation, 2> ExtraModifierLocArray = {SourceLocation(),
+ SourceLocation()};
+ /// Additional modifier for linear, map, depend, lastprivate,
+ /// use_device_ptr, or num_teams clause.
+ int &ExtraModifier = ExtraModifierArray[0];
+ Expr *&ExtraModifierExpr = ExtraModifierExprArray[0];
+ SourceLocation &ExtraModifierLoc = ExtraModifierLocArray[0];
int OriginalSharingModifier = 0; // Default is shared
int NeedDevicePtrModifier = 0;
SourceLocation NeedDevicePtrModifierLoc;
@@ -1203,7 +1208,6 @@ class SemaOpenMP : public SemaBase {
MotionModifiers;
SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc;
bool IsMapTypeImplicit = false;
- SourceLocation ExtraModifierLoc;
SourceLocation OriginalSharingModifierLoc;
SourceLocation OmpAllMemoryLoc;
SourceLocation
@@ -1345,13 +1349,15 @@ class SemaOpenMP : public SemaBase {
/// Called on well-formed 'num_teams' clause.
OMPClause *ActOnOpenMPNumTeamsClause(
ArrayRef<Expr *> VarList, OpenMPNumTeamsClauseModifier Modifier,
- Expr *ModifierExpr, SourceLocation ModifierLoc, SourceLocation StartLoc,
+ Expr *ModifierExpr, SourceLocation ModifierLoc,
+ OpenMPNumTeamsClauseModifier ModifierExtra, Expr *ModifierExtraExpr,
+ SourceLocation ModifierExtraLoc, SourceLocation StartLoc,
SourceLocation LParenLoc, SourceLocation EndLoc);
/// Called on well-formed 'thread_limit' clause.
- OMPClause *ActOnOpenMPThreadLimitClause(ArrayRef<Expr *> VarList,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc);
+ OMPClause *ActOnOpenMPThreadLimitClause(
+ ArrayRef<Expr *> VarList, OpenMPThreadLimitClauseModifier Modifier,
+ Expr *ModifierExpr, SourceLocation ModifierLoc, SourceLocation StartLoc,
+ SourceLocation LParenLoc, SourceLocation EndLoc);
/// Called on well-formed 'priority' clause.
OMPClause *ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
SourceLocation LParenLoc,
@@ -1484,6 +1490,12 @@ class SemaOpenMP : public SemaBase {
SourceLocation LLoc, SourceLocation RLoc,
ArrayRef<OMPIteratorData> Data);
+ ExprResult ActOnOpenMPDimsModifier(OpenMPClauseKind Kind, int Modifier,
+ Expr *ModifierExpr,
+ SourceLocation ModifierLoc,
+ ArrayRef<Expr *> VarList,
+ SourceLocation VarListEndLoc);
+
void handleOMPAssumeAttr(Decl *D, const ParsedAttr &AL);
/// Setter and getter functions for device_num.
diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index f3e548e898b39..d451255bf5845 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -1978,18 +1978,24 @@ OMPNumTeamsClause *OMPNumTeamsClause::CreateEmpty(const ASTContext &C,
OMPThreadLimitClause *OMPThreadLimitClause::Create(
const ASTContext &C, OpenMPDirectiveKind CaptureRegion,
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
- ArrayRef<Expr *> VL, Stmt *PreInit) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
+ ArrayRef<Expr *> VL, OpenMPThreadLimitClauseModifier Modifier,
+ Expr *ModifierExpr, SourceLocation ModifierLoc, Stmt *PreInit) {
+ // Reserve space for an extra modifier expression.
+ void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
OMPThreadLimitClause *Clause =
new (Mem) OMPThreadLimitClause(C, StartLoc, LParenLoc, EndLoc, VL.size());
Clause->setVarRefs(VL);
+ Clause->setModifier(Modifier);
+ Clause->setModifierExpr(ModifierExpr);
+ Clause->setModifierLoc(ModifierLoc);
Clause->setPreInitStmt(PreInit, CaptureRegion);
return Clause;
}
OMPThreadLimitClause *OMPThreadLimitClause::CreateEmpty(const ASTContext &C,
unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
+ // Reserve space for an extra modifier expression.
+ void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
return new (Mem) OMPThreadLimitClause(N);
}
@@ -2373,9 +2379,13 @@ void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
if (!Node->varlist_empty()) {
OS << "num_teams";
- if (const Expr *LowerBound = Node->getModifierExpr()) {
+ if (Node->getModifier() != OMPC_NUMTEAMS_unknown) {
OS << "(";
- LowerBound->printPretty(OS, nullptr, Policy, 0);
+ if (Node->getModifier() == OMPC_NUMTEAMS_dims)
+ OS << "dims(";
+ Node->getModifierExpr()->printPretty(OS, nullptr, Policy, 0);
+ if (Node->getModifier() == OMPC_NUMTEAMS_dims)
+ OS << ")";
VisitOMPClauseList(Node, ':');
} else {
VisitOMPClauseList(Node, '(');
@@ -2387,7 +2397,14 @@ void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
if (!Node->varlist_empty()) {
OS << "thread_limit";
- VisitOMPClauseList(Node, '(');
+ if (Node->getModifier() == OMPC_THREADLIMIT_dims) {
+ OS << "(dims(";
+ Node->getModifierExpr()->printPretty(OS, nullptr, Policy, 0);
+ OS << ")";
+ VisitOMPClauseList(Node, ':');
+ } else {
+ VisitOMPClauseList(Node, '(');
+ }
OS << ")";
}
}
diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index a7e7006c98a1b..291c72385518e 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -920,6 +920,9 @@ void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
}
void OMPClauseProfiler::VisitOMPThreadLimitClause(
const OMPThreadLimitClause *C) {
+ Profiler->VisitInteger(C->getModifier());
+ if (const Expr *Modifier = C->getModifierExpr())
+ Profiler->VisitStmt(Modifier);
VisitOMPClauseList(C);
VisitOMPClauseWithPreInit(C);
}
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index c590113578081..890ed0d29a7c6 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -224,6 +224,15 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
return OMPC_NUMTEAMS_unknown;
return Type;
}
+ case OMPC_thread_limit: {
+ unsigned Type = llvm::StringSwitch<unsigned>(Str)
+#define OPENMP_THREADLIMIT_MODIFIER(Name) .Case(#Name, OMPC_THREADLIMIT_##Name)
+#include "clang/Basic/OpenMPKinds.def"
+ .Default(OMPC_THREADLIMIT_unknown);
+ if (LangOpts.OpenMP < 61)
+ return OMPC_THREADLIMIT_unknown;
+ return Type;
+ }
case OMPC_allocate:
return llvm::StringSwitch<OpenMPAllocateClauseModifier>(Str)
#define OPENMP_ALLOCATE_MODIFIER(Name) .Case(#Name, OMPC_ALLOCATE_##Name)
@@ -294,7 +303,6 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
case OMPC_relaxed:
case OMPC_threads:
case OMPC_simd:
- case OMPC_thread_limit:
case OMPC_priority:
case OMPC_nogroup:
case OMPC_hint:
@@ -606,6 +614,16 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
#include "clang/Basic/OpenMPKinds.def"
}
llvm_unreachable("Invalid OpenMP 'num_teams' clause modifier");
+ case OMPC_thread_limit:
+ switch (Type) {
+ case OMPC_THREADLIMIT_unknown:
+ return "unknown";
+#define OPENMP_THREADLIMIT_MODIFIER(Name) \
+ case OMPC_THREADLIMIT_##Name: \
+ return #Name;
+#include "clang/Basic/OpenMPKinds.def"
+ }
+ llvm_unreachable("Invalid OpenMP 'thread_limit' clause modifier");
case OMPC_allocate:
switch (Type) {
case OMPC_ALLOCATE_unknown:
@@ -683,7 +701,6 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
case OMPC_relaxed:
case OMPC_threads:
case OMPC_simd:
- case OMPC_thread_limit:
case OMPC_priority:
case OMPC_nogroup:
case OMPC_hint:
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 62715da7966d0..2206d153badfd 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -5289,29 +5289,71 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
Diag(Tok, diag::err_modifier_expected_colon) << "fallback";
}
}
- } else if (Kind == OMPC_num_teams) {
- // Handle optional lower-bound modifier for num_teams clause.
- Data.ExtraModifier = OMPC_NUMTEAMS_unknown;
- TentativeParsingAction TPA(*this);
- SourceLocation TLoc = Tok.getLocation();
- ExprResult FirstExpr = ParseAssignmentExpression();
- if (FirstExpr.isInvalid()) {
- SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch);
- Data.RLoc = Tok.getLocation();
- if (!T.consumeClose())
- Data.RLoc = T.getCloseLocation();
- TPA.Commit();
- return true;
+ } else if (Kind == OMPC_num_teams || Kind == OMPC_thread_limit) {
+ int Mod = 0;
+ // Handle optional dims and lower-bound modifiers for num_teams clause, and
+ // the optional dims modifier ...
[truncated]
@llvm/pr-subscribers-clang
Author: Kevin Sala Penades (kevinsala)
Changes
Add parsing for dims modifier (OpenMP 6.1) in num_teams and thread_limit clauses. Examples:
constexpr int N = 2;
#pragma omp teams num_teams(dims(3): x, y, z) thread_limit(dims(N): a, b)
{ ... }
Patch is 61.34 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/206412.diff
20 Files Affected:
- (modified) clang/include/clang/AST/OpenMPClause.h (+61-19)
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+11-4)
- (modified) clang/include/clang/Basic/OpenMPKinds.def (+8)
- (modified) clang/include/clang/Basic/OpenMPKinds.h (+6)
- (modified) clang/include/clang/Sema/SemaOpenMP.h (+22-10)
- (modified) clang/lib/AST/OpenMPClause.cpp (+23-6)
- (modified) clang/lib/AST/StmtProfile.cpp (+3)
- (modified) clang/lib/Basic/OpenMPKinds.cpp (+19-2)
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+63-21)
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+161-70)
- (modified) clang/lib/Sema/TreeTransform.h (+23-11)
- (modified) clang/lib/Serialization/ASTReader.cpp (+3)
- (modified) clang/lib/Serialization/ASTWriter.cpp (+3)
- (added) clang/test/OpenMP/dims_modifier_ast_print.cpp (+40)
- (added) clang/test/OpenMP/dims_modifier_messages.cpp (+124)
- (modified) clang/test/OpenMP/ompx_bare_messages.c (+1-1)
- (modified) clang/test/OpenMP/target_teams_distribute_num_teams_messages.cpp (+8-8)
- (modified) clang/test/OpenMP/target_teams_distribute_parallel_for_num_teams_messages.cpp (+4-4)
- (modified) clang/test/OpenMP/teams_num_teams_messages.cpp (+10-10)
- (modified) clang/tools/libclang/CIndex.cpp (+2)
diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h
index bae396d883dc8..bd58a41d4df1e 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -6982,6 +6982,13 @@ class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
/// single expression 'n' as upper-bound and modifier expression 'm' as
/// lower-bound.
///
+/// \code
+/// #pragma omp teams num_teams(dims(2): x, y)
+/// \endcode
+/// In this example directive '#pragma omp teams' has clause 'num_teams' with
+/// the 'dims' modifier specifying two dimensions. The list specifies the number
+/// of teams in each dimension.
+///
/// When 'ompx_bare' clause exists on a 'target' directive, 'num_teams' clause
/// can accept up to three expressions.
///
@@ -6995,9 +7002,6 @@ class OMPNumTeamsClause final
friend OMPVarListClause;
friend TrailingObjects;
- /// Location of '('.
- SourceLocation LParenLoc;
-
/// Modifier that was specified.
OpenMPNumTeamsClauseModifier Modifier = OMPC_NUMTEAMS_unknown;
@@ -7041,12 +7045,6 @@ class OMPNumTeamsClause final
/// \param N The number of variables.
static OMPNumTeamsClause *CreateEmpty(const ASTContext &C, unsigned N);
- /// Sets the location of '('.
- void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
-
- /// Returns the location of '('.
- SourceLocation getLParenLoc() const { return LParenLoc; }
-
/// Return NumTeams expressions.
ArrayRef<Expr *> getNumTeams() { return getVarRefs(); }
@@ -7070,6 +7068,13 @@ class OMPNumTeamsClause final
/// Set the expression of the modifier.
void setModifierExpr(Expr *E) { *varlist_end() = E; }
+ /// Get the expression of the modifier if it is the dims modifier.
+ const Expr *getDimsModifierExpr() const {
+ if (Modifier == OMPC_NUMTEAMS_dims)
+ return getModifierExpr();
+ return nullptr;
+ }
+
/// Get the location of the modifier.
SourceLocation getModifierLoc() const { return ModifierLoc; }
@@ -7106,6 +7111,13 @@ class OMPNumTeamsClause final
/// In this example directive '#pragma omp teams' has clause 'thread_limit'
/// with single expression 'n'.
///
+/// \code
+/// #pragma omp teams thread_limit(dims(2): x, y)
+/// \endcode
+/// In this example directive '#pragma omp teams' has clause 'thread_limit' with
+/// the 'dims' modifier specifying two dimensions. The list specifies the limit
+/// on the number of threads in each dimension.
+///
/// When 'ompx_bare' clause exists on a 'target' directive, 'thread_limit'
/// clause can accept up to three expressions.
///
@@ -7119,8 +7131,11 @@ class OMPThreadLimitClause final
friend OMPVarListClause;
friend TrailingObjects;
- /// Location of '('.
- SourceLocation LParenLoc;
+ /// Modifier that was specified.
+ OpenMPThreadLimitClauseModifier Modifier = OMPC_THREADLIMIT_unknown;
+
+ /// Location of the modifier.
+ SourceLocation ModifierLoc;
OMPThreadLimitClause(const ASTContext &C, SourceLocation StartLoc,
SourceLocation LParenLoc, SourceLocation EndLoc,
@@ -7143,11 +7158,16 @@ class OMPThreadLimitClause final
/// \param LParenLoc Location of '('.
/// \param EndLoc Ending location of the clause.
/// \param VL List of references to the variables.
+ /// \param Modifier The modifier specified in the clause.
+ /// \param ModifierExpr The expression of the modifier.
+ /// \param ModifierLoc Location of the modifier.
/// \param PreInit
static OMPThreadLimitClause *
Create(const ASTContext &C, OpenMPDirectiveKind CaptureRegion,
SourceLocation StartLoc, SourceLocation LParenLoc,
- SourceLocation EndLoc, ArrayRef<Expr *> VL, Stmt *PreInit);
+ SourceLocation EndLoc, ArrayRef<Expr *> VL,
+ OpenMPThreadLimitClauseModifier Modifier, Expr *ModifierExpr,
+ SourceLocation ModifierLoc, Stmt *PreInit);
/// Creates an empty clause with \a N variables.
///
@@ -7155,12 +7175,6 @@ class OMPThreadLimitClause final
/// \param N The number of variables.
static OMPThreadLimitClause *CreateEmpty(const ASTContext &C, unsigned N);
- /// Sets the location of '('.
- void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
-
- /// Returns the location of '('.
- SourceLocation getLParenLoc() const { return LParenLoc; }
-
/// Return ThreadLimit expressions.
ArrayRef<Expr *> getThreadLimit() { return getVarRefs(); }
@@ -7169,9 +7183,37 @@ class OMPThreadLimitClause final
return const_cast<OMPThreadLimitClause *>(this)->getThreadLimit();
}
+ /// Get the modifier.
+ OpenMPThreadLimitClauseModifier getModifier() const { return Modifier; }
+
+ /// Set the modifier.
+ void setModifier(OpenMPThreadLimitClauseModifier M) { Modifier = M; }
+
+ /// Get the expression of the modifier.
+ const Expr *getModifierExpr() const { return *varlist_end(); }
+
+ /// Get the expression of the modifier.
+ Expr *getModifierExpr() { return *varlist_end(); }
+
+ /// Set the expression of the modifier.
+ void setModifierExpr(Expr *E) { *varlist_end() = E; }
+
+ /// Get the expression of the modifier if it is the dims modifier.
+ const Expr *getDimsModifierExpr() const {
+ if (Modifier == OMPC_THREADLIMIT_dims)
+ return getModifierExpr();
+ return nullptr;
+ }
+
+ /// Get the location of the modifier.
+ SourceLocation getModifierLoc() const { return ModifierLoc; }
+
+ /// Set the location of the modifier.
+ void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
+
child_range children() {
return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
- reinterpret_cast<Stmt **>(varlist_end()));
+ reinterpret_cast<Stmt **>(varlist_end()) + 1);
}
const_child_range children() const {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6b2d78881d4e2..15f97e5e2abc6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12779,9 +12779,11 @@ def warn_omp_unterminated_declare_target : Warning<
"expected '#pragma omp end declare target' at end of file to match '#pragma omp %0'">,
InGroup<SourceUsesOpenMP>;
def err_ompx_bare_no_grid : Error<
- "'ompx_bare' clauses requires explicit grid size via 'num_teams' and 'thread_limit' clauses">;
-def err_omp_multi_expr_not_allowed: Error<"only one expression allowed in '%0' clause">;
-def err_ompx_more_than_three_expr_not_allowed: Error<"at most three expressions are allowed in '%0' clause in 'target teams ompx_bare' construct">;
+ "'ompx_bare' clause requires explicit grid size via 'num_teams' and 'thread_limit' clauses">;
+def err_ompx_bare_no_dims : Error<
+ "'ompx_bare' clause cannot be specified with 'dims' modifier in 'num_teams' and 'thread_limit' clauses">;
+def err_omp_multi_expr_not_allowed : Error<"only one expression allowed in '%0' clause">;
+def err_omp_max_three_exprs: Error<"maximum three expressions are supported in '%0' clause">;
def err_omp_transparent_invalid_value : Error<"invalid value for transparent clause,"
" expected one of: omp_not_impex, omp_import, omp_export, omp_impex">;
def err_omp_transparent_invalid_type : Error<
@@ -12790,6 +12792,12 @@ def err_omp_num_teams_lower_bound_larger
: Error<"lower bound is greater than upper bound in 'num_teams' clause">;
def err_omp_modifier_requires_version : Error<
"'%0' modifier in '%1' clause requires OpenMP %2 or later">;
+def err_omp_unexpected_num_exprs
+ : Error<"unexpected number of expressions in '%0' clause">;
+def err_omp_max_supported_dims
+ : Error<"at most three dimensions are supported in '%0' clause">;
+def err_omp_incompatible_modifiers
+ : Error<"'%0' modifier cannot be specified with '%1' modifier in '%2' clause">;
} // end of OpenMP category
let CategoryName = "Related Result Type Issue" in {
@@ -12816,7 +12824,6 @@ def note_related_result_type_explicit : Note<
"%select{| and is expected to return an instance of its class type}0">;
def err_invalid_type_for_program_scope_var : Error<
"the %0 type cannot be used to declare a program scope variable">;
-
}
let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Basic/OpenMPKinds.def b/clang/include/clang/Basic/OpenMPKinds.def
index 079ff4a583f9f..5c396a5d2d4b3 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -101,6 +101,9 @@
#ifndef OPENMP_NUMTHREADS_MODIFIER
#define OPENMP_NUMTHREADS_MODIFIER(Name)
#endif
+#ifndef OPENMP_THREADLIMIT_MODIFIER
+#define OPENMP_THREADLIMIT_MODIFIER(Name)
+#endif
#ifndef OPENMP_DOACROSS_MODIFIER
#define OPENMP_DOACROSS_MODIFIER(Name)
#endif
@@ -273,10 +276,14 @@ OPENMP_NUMTASKS_MODIFIER(strict)
// Modifiers for the 'num_teams' clause.
OPENMP_NUMTEAMS_MODIFIER(lower_bound)
+OPENMP_NUMTEAMS_MODIFIER(dims)
// Modifiers for the 'num_tasks' clause.
OPENMP_NUMTHREADS_MODIFIER(strict)
+// Modifiers for the 'thread_limit' clause.
+OPENMP_THREADLIMIT_MODIFIER(dims)
+
// Modifiers for 'allocate' clause.
OPENMP_ALLOCATE_MODIFIER(allocator)
OPENMP_ALLOCATE_MODIFIER(align)
@@ -301,6 +308,7 @@ OPENMP_USE_DEVICE_PTR_FALLBACK_MODIFIER(fb_preserve)
#undef OPENMP_NUMTASKS_MODIFIER
#undef OPENMP_NUMTEAMS_MODIFIER
#undef OPENMP_NUMTHREADS_MODIFIER
+#undef OPENMP_THREADLIMIT_MODIFIER
#undef OPENMP_DYN_GROUPPRIVATE_MODIFIER
#undef OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER
#undef OPENMP_GRAINSIZE_MODIFIER
diff --git a/clang/include/clang/Basic/OpenMPKinds.h b/clang/include/clang/Basic/OpenMPKinds.h
index 3ee6cb83a431e..36c388668a455 100644
--- a/clang/include/clang/Basic/OpenMPKinds.h
+++ b/clang/include/clang/Basic/OpenMPKinds.h
@@ -274,6 +274,12 @@ enum OpenMPNumThreadsClauseModifier {
OMPC_NUMTHREADS_unknown
};
+enum OpenMPThreadLimitClauseModifier {
+#define OPENMP_THREADLIMIT_MODIFIER(Name) OMPC_THREADLIMIT_##Name,
+#include "clang/Basic/OpenMPKinds.def"
+ OMPC_THREADLIMIT_unknown
+};
+
/// OpenMP dependence types for 'doacross' clause.
enum OpenMPDoacrossClauseModifier {
#define OPENMP_DOACROSS_MODIFIER(Name) OMPC_DOACROSS_##Name,
diff --git a/clang/include/clang/Sema/SemaOpenMP.h b/clang/include/clang/Sema/SemaOpenMP.h
index f689e227866a7..726ac8539c66b 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -1188,10 +1188,15 @@ class SemaOpenMP : public SemaBase {
SourceLocation RLoc;
CXXScopeSpec ReductionOrMapperIdScopeSpec;
DeclarationNameInfo ReductionOrMapperId;
- int ExtraModifier =
- -1; ///< Additional modifier for linear, map, depend,
- ///< lastprivate, use_device_ptr, or num_teams clause.
- Expr *ExtraModifierExpr = nullptr;
+ SmallVector<int, 2> ExtraModifierArray = {-1, -1};
+ SmallVector<Expr *, 2> ExtraModifierExprArray = {nullptr, nullptr};
+ SmallVector<SourceLocation, 2> ExtraModifierLocArray = {SourceLocation(),
+ SourceLocation()};
+ /// Additional modifier for linear, map, depend, lastprivate,
+ /// use_device_ptr, or num_teams clause.
+ int &ExtraModifier = ExtraModifierArray[0];
+ Expr *&ExtraModifierExpr = ExtraModifierExprArray[0];
+ SourceLocation &ExtraModifierLoc = ExtraModifierLocArray[0];
int OriginalSharingModifier = 0; // Default is shared
int NeedDevicePtrModifier = 0;
SourceLocation NeedDevicePtrModifierLoc;
@@ -1203,7 +1208,6 @@ class SemaOpenMP : public SemaBase {
MotionModifiers;
SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc;
bool IsMapTypeImplicit = false;
- SourceLocation ExtraModifierLoc;
SourceLocation OriginalSharingModifierLoc;
SourceLocation OmpAllMemoryLoc;
SourceLocation
@@ -1345,13 +1349,15 @@ class SemaOpenMP : public SemaBase {
/// Called on well-formed 'num_teams' clause.
OMPClause *ActOnOpenMPNumTeamsClause(
ArrayRef<Expr *> VarList, OpenMPNumTeamsClauseModifier Modifier,
- Expr *ModifierExpr, SourceLocation ModifierLoc, SourceLocation StartLoc,
+ Expr *ModifierExpr, SourceLocation ModifierLoc,
+ OpenMPNumTeamsClauseModifier ModifierExtra, Expr *ModifierExtraExpr,
+ SourceLocation ModifierExtraLoc, SourceLocation StartLoc,
SourceLocation LParenLoc, SourceLocation EndLoc);
/// Called on well-formed 'thread_limit' clause.
- OMPClause *ActOnOpenMPThreadLimitClause(ArrayRef<Expr *> VarList,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc);
+ OMPClause *ActOnOpenMPThreadLimitClause(
+ ArrayRef<Expr *> VarList, OpenMPThreadLimitClauseModifier Modifier,
+ Expr *ModifierExpr, SourceLocation ModifierLoc, SourceLocation StartLoc,
+ SourceLocation LParenLoc, SourceLocation EndLoc);
/// Called on well-formed 'priority' clause.
OMPClause *ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
SourceLocation LParenLoc,
@@ -1484,6 +1490,12 @@ class SemaOpenMP : public SemaBase {
SourceLocation LLoc, SourceLocation RLoc,
ArrayRef<OMPIteratorData> Data);
+ ExprResult ActOnOpenMPDimsModifier(OpenMPClauseKind Kind, int Modifier,
+ Expr *ModifierExpr,
+ SourceLocation ModifierLoc,
+ ArrayRef<Expr *> VarList,
+ SourceLocation VarListEndLoc);
+
void handleOMPAssumeAttr(Decl *D, const ParsedAttr &AL);
/// Setter and getter functions for device_num.
diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index f3e548e898b39..d451255bf5845 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -1978,18 +1978,24 @@ OMPNumTeamsClause *OMPNumTeamsClause::CreateEmpty(const ASTContext &C,
OMPThreadLimitClause *OMPThreadLimitClause::Create(
const ASTContext &C, OpenMPDirectiveKind CaptureRegion,
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
- ArrayRef<Expr *> VL, Stmt *PreInit) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
+ ArrayRef<Expr *> VL, OpenMPThreadLimitClauseModifier Modifier,
+ Expr *ModifierExpr, SourceLocation ModifierLoc, Stmt *PreInit) {
+ // Reserve space for an extra modifier expression.
+ void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
OMPThreadLimitClause *Clause =
new (Mem) OMPThreadLimitClause(C, StartLoc, LParenLoc, EndLoc, VL.size());
Clause->setVarRefs(VL);
+ Clause->setModifier(Modifier);
+ Clause->setModifierExpr(ModifierExpr);
+ Clause->setModifierLoc(ModifierLoc);
Clause->setPreInitStmt(PreInit, CaptureRegion);
return Clause;
}
OMPThreadLimitClause *OMPThreadLimitClause::CreateEmpty(const ASTContext &C,
unsigned N) {
- void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
+ // Reserve space for an extra modifier expression.
+ void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
return new (Mem) OMPThreadLimitClause(N);
}
@@ -2373,9 +2379,13 @@ void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
if (!Node->varlist_empty()) {
OS << "num_teams";
- if (const Expr *LowerBound = Node->getModifierExpr()) {
+ if (Node->getModifier() != OMPC_NUMTEAMS_unknown) {
OS << "(";
- LowerBound->printPretty(OS, nullptr, Policy, 0);
+ if (Node->getModifier() == OMPC_NUMTEAMS_dims)
+ OS << "dims(";
+ Node->getModifierExpr()->printPretty(OS, nullptr, Policy, 0);
+ if (Node->getModifier() == OMPC_NUMTEAMS_dims)
+ OS << ")";
VisitOMPClauseList(Node, ':');
} else {
VisitOMPClauseList(Node, '(');
@@ -2387,7 +2397,14 @@ void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
if (!Node->varlist_empty()) {
OS << "thread_limit";
- VisitOMPClauseList(Node, '(');
+ if (Node->getModifier() == OMPC_THREADLIMIT_dims) {
+ OS << "(dims(";
+ Node->getModifierExpr()->printPretty(OS, nullptr, Policy, 0);
+ OS << ")";
+ VisitOMPClauseList(Node, ':');
+ } else {
+ VisitOMPClauseList(Node, '(');
+ }
OS << ")";
}
}
diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index a7e7006c98a1b..291c72385518e 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -920,6 +920,9 @@ void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
}
void OMPClauseProfiler::VisitOMPThreadLimitClause(
const OMPThreadLimitClause *C) {
+ Profiler->VisitInteger(C->getModifier());
+ if (const Expr *Modifier = C->getModifierExpr())
+ Profiler->VisitStmt(Modifier);
VisitOMPClauseList(C);
VisitOMPClauseWithPreInit(C);
}
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index c590113578081..890ed0d29a7c6 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -224,6 +224,15 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
return OMPC_NUMTEAMS_unknown;
return Type;
}
+ case OMPC_thread_limit: {
+ unsigned Type = llvm::StringSwitch<unsigned>(Str)
+#define OPENMP_THREADLIMIT_MODIFIER(Name) .Case(#Name, OMPC_THREADLIMIT_##Name)
+#include "clang/Basic/OpenMPKinds.def"
+ .Default(OMPC_THREADLIMIT_unknown);
+ if (LangOpts.OpenMP < 61)
+ return OMPC_THREADLIMIT_unknown;
+ return Type;
+ }
case OMPC_allocate:
return llvm::StringSwitch<OpenMPAllocateClauseModifier>(Str)
#define OPENMP_ALLOCATE_MODIFIER(Name) .Case(#Name, OMPC_ALLOCATE_##Name)
@@ -294,7 +303,6 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
case OMPC_relaxed:
case OMPC_threads:
case OMPC_simd:
- case OMPC_thread_limit:
case OMPC_priority:
case OMPC_nogroup:
case OMPC_hint:
@@ -606,6 +614,16 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
#include "clang/Basic/OpenMPKinds.def"
}
llvm_unreachable("Invalid OpenMP 'num_teams' clause modifier");
+ case OMPC_thread_limit:
+ switch (Type) {
+ case OMPC_THREADLIMIT_unknown:
+ return "unknown";
+#define OPENMP_THREADLIMIT_MODIFIER(Name) \
+ case OMPC_THREADLIMIT_##Name: \
+ return #Name;
+#include "clang/Basic/OpenMPKinds.def"
+ }
+ llvm_unreachable("Invalid OpenMP 'thread_limit' clause modifier");
case OMPC_allocate:
switch (Type) {
case OMPC_ALLOCATE_unknown:
@@ -683,7 +701,6 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
case OMPC_relaxed:
case OMPC_threads:
case OMPC_simd:
- case OMPC_thread_limit:
case OMPC_priority:
case OMPC_nogroup:
case OMPC_hint:
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 62715da7966d0..2206d153badfd 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -5289,29 +5289,71 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
Diag(Tok, diag::err_modifier_expected_colon) << "fallback";
}
}
- } else if (Kind == OMPC_num_teams) {
- // Handle optional lower-bound modifier for num_teams clause.
- Data.ExtraModifier = OMPC_NUMTEAMS_unknown;
- TentativeParsingAction TPA(*this);
- SourceLocation TLoc = Tok.getLocation();
- ExprResult FirstExpr = ParseAssignmentExpression();
- if (FirstExpr.isInvalid()) {
- SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch);
- Data.RLoc = Tok.getLocation();
- if (!T.consumeClose())
- Data.RLoc = T.getCloseLocation();
- TPA.Commit();
- return true;
+ } else if (Kind == OMPC_num_teams || Kind == OMPC_thread_limit) {
+ int Mod = 0;
+ // Handle optional dims and lower-bound modifiers for num_teams clause, and
+ // the optional dims modifier ...
[truncated]
Ping.
Hi @kevinsala
Are the changes to support multi-dim clauses in ompIRBuilder (TargetKernelDefaultAttrs and TargetKernelRuntimeAttrs) be part of another PR?
Hi @kevinsala
Are the changes to support multi-dim clauses in ompIRBuilder (TargetKernelDefaultAttrs and TargetKernelRuntimeAttrs) be part of another PR?
@skc7 Yes. They will be in another PR, likely this week.
Those files should be updated now. Thanks for pointing it out.
I've updated the auxiliary functions that verify the multidim clauses. They have been adapted for a follow-up PR that will add support for dims in num_threads clause, reusing the same logic.
Rebase
Rebased, and fixed comments.
Any more comments on this PR?