Skip to content

Commit 099c502

Browse files
committed
[OpenMP] Add parser/semantic support for dyn_groupprivate clause
1 parent bc2cc8b commit 099c502

File tree

18 files changed

+605
-8
lines changed

18 files changed

+605
-8
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9768,6 +9768,161 @@ class OMPXDynCGroupMemClause
97689768
Expr *getSize() const { return getStmtAs<Expr>(); }
97699769
};
97709770

9771+
/// This represents 'dyn_groupprivate' clause in '#pragma omp target ...'
9772+
/// and '#pragma omp teams ...' directives.
9773+
///
9774+
/// \code
9775+
/// #pragma omp target [...] dyn_groupprivate(a,b: N)
9776+
/// \endcode
9777+
class OMPDynGroupprivateClause : public OMPClause, public OMPClauseWithPreInit {
9778+
friend class OMPClauseReader;
9779+
9780+
/// Location of '('.
9781+
SourceLocation LParenLoc;
9782+
9783+
/// Modifiers for 'dyn_groupprivate' clause.
9784+
enum { FIRST, SECOND, NUM_MODIFIERS };
9785+
OpenMPDynGroupprivateClauseModifier Modifiers[NUM_MODIFIERS];
9786+
9787+
/// Locations of modifiers.
9788+
SourceLocation ModifiersLoc[NUM_MODIFIERS];
9789+
9790+
/// The size of the dyn_groupprivate.
9791+
Expr *Size = nullptr;
9792+
9793+
/// Set the first dyn_groupprivate modifier.
9794+
///
9795+
/// \param M The modifier.
9796+
void setFirstDynGroupprivateModifier(OpenMPDynGroupprivateClauseModifier M) {
9797+
Modifiers[FIRST] = M;
9798+
}
9799+
9800+
/// Set the second dyn_groupprivate modifier.
9801+
///
9802+
/// \param M The modifier.
9803+
void setSecondDynGroupprivateModifier(OpenMPDynGroupprivateClauseModifier M) {
9804+
Modifiers[SECOND] = M;
9805+
}
9806+
9807+
/// Set location of the first dyn_groupprivate modifier.
9808+
void setFirstDynGroupprivateModifierLoc(SourceLocation Loc) {
9809+
ModifiersLoc[FIRST] = Loc;
9810+
}
9811+
9812+
/// Set location of the second dyn_groupprivate modifier.
9813+
void setSecondDynGroupprivateModifierLoc(SourceLocation Loc) {
9814+
ModifiersLoc[SECOND] = Loc;
9815+
}
9816+
9817+
/// Set dyn_groupprivate modifier location.
9818+
///
9819+
/// \param M The modifier location.
9820+
void setDynGroupprivateModifer(OpenMPDynGroupprivateClauseModifier M) {
9821+
if (Modifiers[FIRST] == OMPC_DYN_GROUPPRIVATE_unknown)
9822+
Modifiers[FIRST] = M;
9823+
else {
9824+
assert(Modifiers[SECOND] == OMPC_DYN_GROUPPRIVATE_unknown);
9825+
Modifiers[SECOND] = M;
9826+
}
9827+
}
9828+
9829+
/// Sets the location of '('.
9830+
///
9831+
/// \param Loc Location of '('.
9832+
void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
9833+
9834+
/// Set size.
9835+
///
9836+
/// \param E Size.
9837+
void setSize(Expr *E) { Size = E; }
9838+
9839+
public:
9840+
/// Build 'dyn_groupprivate' clause with a size expression \a Size.
9841+
///
9842+
/// \param StartLoc Starting location of the clause.
9843+
/// \param LParenLoc Location of '('.
9844+
/// \param EndLoc Ending location of the clause.
9845+
/// \param Size Size.
9846+
/// \param M1 The first modifier applied to 'dyn_groupprivate' clause.
9847+
/// \param M1Loc Location of the first modifier.
9848+
/// \param M2 The second modifier applied to 'dyn_groupprivate' clause.
9849+
/// \param M2Loc Location of the second modifier.
9850+
OMPDynGroupprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
9851+
SourceLocation EndLoc, Expr *Size, Stmt *HelperSize,
9852+
OpenMPDirectiveKind CaptureRegion,
9853+
OpenMPDynGroupprivateClauseModifier M1,
9854+
SourceLocation M1Loc,
9855+
OpenMPDynGroupprivateClauseModifier M2,
9856+
SourceLocation M2Loc)
9857+
: OMPClause(llvm::omp::OMPC_dyn_groupprivate, StartLoc, EndLoc),
9858+
OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Size(Size) {
9859+
setPreInitStmt(HelperSize, CaptureRegion);
9860+
Modifiers[FIRST] = M1;
9861+
Modifiers[SECOND] = M2;
9862+
ModifiersLoc[FIRST] = M1Loc;
9863+
ModifiersLoc[SECOND] = M2Loc;
9864+
}
9865+
9866+
/// Build an empty clause.
9867+
explicit OMPDynGroupprivateClause()
9868+
: OMPClause(llvm::omp::OMPC_dyn_groupprivate, SourceLocation(),
9869+
SourceLocation()),
9870+
OMPClauseWithPreInit(this) {
9871+
Modifiers[FIRST] = OMPC_DYN_GROUPPRIVATE_unknown;
9872+
Modifiers[SECOND] = OMPC_DYN_GROUPPRIVATE_unknown;
9873+
}
9874+
9875+
/// Get the first modifier of the clause.
9876+
OpenMPDynGroupprivateClauseModifier getFirstDynGroupprivateModifier() const {
9877+
return Modifiers[FIRST];
9878+
}
9879+
9880+
/// Get the second modifier of the clause.
9881+
OpenMPDynGroupprivateClauseModifier getSecondDynGroupprivateModifier() const {
9882+
return Modifiers[SECOND];
9883+
}
9884+
9885+
/// Get location of '('.
9886+
SourceLocation getLParenLoc() { return LParenLoc; }
9887+
9888+
/// Get the first modifier location.
9889+
SourceLocation getFirstDynGroupprivateModifierLoc() const {
9890+
return ModifiersLoc[FIRST];
9891+
}
9892+
9893+
/// Get the second modifier location.
9894+
SourceLocation getSecondDynGroupprivateModifierLoc() const {
9895+
return ModifiersLoc[SECOND];
9896+
}
9897+
9898+
/// Get size.
9899+
Expr *getSize() { return Size; }
9900+
9901+
/// Get size.
9902+
const Expr *getSize() const { return Size; }
9903+
9904+
child_range children() {
9905+
return child_range(reinterpret_cast<Stmt **>(&Size),
9906+
reinterpret_cast<Stmt **>(&Size) + 1);
9907+
}
9908+
9909+
const_child_range children() const {
9910+
auto Children = const_cast<OMPDynGroupprivateClause *>(this)->children();
9911+
return const_child_range(Children.begin(), Children.end());
9912+
}
9913+
9914+
child_range used_children() {
9915+
return child_range(child_iterator(), child_iterator());
9916+
}
9917+
const_child_range used_children() const {
9918+
return const_child_range(const_child_iterator(), const_child_iterator());
9919+
}
9920+
9921+
static bool classof(const OMPClause *T) {
9922+
return T->getClauseKind() == llvm::omp::OMPC_dyn_groupprivate;
9923+
}
9924+
};
9925+
97719926
/// This represents the 'doacross' clause for the '#pragma omp ordered'
97729927
/// directive.
97739928
///

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,6 +4060,14 @@ bool RecursiveASTVisitor<Derived>::VisitOMPXDynCGroupMemClause(
40604060
return true;
40614061
}
40624062

4063+
template <typename Derived>
4064+
bool RecursiveASTVisitor<Derived>::VisitOMPDynGroupprivateClause(
4065+
OMPDynGroupprivateClause *C) {
4066+
TRY_TO(VisitOMPClauseWithPreInit(C));
4067+
TRY_TO(TraverseStmt(C->getSize()));
4068+
return true;
4069+
}
4070+
40634071
template <typename Derived>
40644072
bool RecursiveASTVisitor<Derived>::VisitOMPDoacrossClause(
40654073
OMPDoacrossClause *C) {

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11995,6 +11995,9 @@ def err_omp_unexpected_schedule_modifier : Error<
1199511995
"modifier '%0' cannot be used along with modifier '%1'">;
1199611996
def err_omp_schedule_nonmonotonic_static : Error<
1199711997
"'nonmonotonic' modifier can only be specified with 'dynamic' or 'guided' schedule kind">;
11998+
def err_omp_unexpected_dyn_groupprivate_modifier
11999+
: Error<"modifier '%0' cannot be used along with modifier '%1' in "
12000+
"dyn_groupprivate">;
1199812001
def err_omp_simple_clause_incompatible_with_ordered : Error<
1199912002
"'%0' clause with '%1' modifier cannot be specified if an 'ordered' clause is specified">;
1200012003
def err_omp_ordered_simd : Error<

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@
8383
#ifndef OPENMP_GRAINSIZE_MODIFIER
8484
#define OPENMP_GRAINSIZE_MODIFIER(Name)
8585
#endif
86+
#ifndef OPENMP_DYN_GROUPPRIVATE_MODIFIER
87+
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name)
88+
#endif
8689
#ifndef OPENMP_NUMTASKS_MODIFIER
8790
#define OPENMP_NUMTASKS_MODIFIER(Name)
8891
#endif
@@ -227,6 +230,11 @@ OPENMP_BIND_KIND(thread)
227230
// Modifiers for the 'grainsize' clause.
228231
OPENMP_GRAINSIZE_MODIFIER(strict)
229232

233+
// Modifiers for the 'dyn_groupprivate' clause.
234+
OPENMP_DYN_GROUPPRIVATE_MODIFIER(cgroup)
235+
OPENMP_DYN_GROUPPRIVATE_MODIFIER(strict)
236+
OPENMP_DYN_GROUPPRIVATE_MODIFIER(fallback)
237+
230238
// Modifiers for the 'num_tasks' clause.
231239
OPENMP_NUMTASKS_MODIFIER(strict)
232240

@@ -245,6 +253,7 @@ OPENMP_DOACROSS_MODIFIER(source_omp_cur_iteration)
245253

246254
#undef OPENMP_NUMTASKS_MODIFIER
247255
#undef OPENMP_NUMTHREADS_MODIFIER
256+
#undef OPENMP_DYN_GROUPPRIVATE_MODIFIER
248257
#undef OPENMP_GRAINSIZE_MODIFIER
249258
#undef OPENMP_BIND_KIND
250259
#undef OPENMP_ADJUST_ARGS_KIND

clang/include/clang/Basic/OpenMPKinds.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,16 @@ enum OpenMPGrainsizeClauseModifier {
217217
OMPC_GRAINSIZE_unknown
218218
};
219219

220+
enum OpenMPDynGroupprivateClauseModifier {
221+
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name) OMPC_DYN_GROUPPRIVATE_##Name,
222+
#include "clang/Basic/OpenMPKinds.def"
223+
OMPC_DYN_GROUPPRIVATE_unknown
224+
};
225+
226+
/// Number of allowed dyn_groupprivate-modifiers.
227+
static constexpr unsigned NumberOfOMPDynGroupprivateClauseModifiers =
228+
OMPC_DYN_GROUPPRIVATE_unknown;
229+
220230
enum OpenMPNumTasksClauseModifier {
221231
#define OPENMP_NUMTASKS_MODIFIER(Name) OMPC_NUMTASKS_##Name,
222232
#include "clang/Basic/OpenMPKinds.def"

clang/include/clang/Sema/SemaOpenMP.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,13 @@ class SemaOpenMP : public SemaBase {
13851385
SourceLocation LParenLoc,
13861386
SourceLocation EndLoc);
13871387

1388+
/// Called on a well-formed 'dyn_groupprivate' clause.
1389+
OMPClause *ActOnOpenMPDynGroupprivateClause(
1390+
OpenMPDynGroupprivateClauseModifier M1,
1391+
OpenMPDynGroupprivateClauseModifier M2, Expr *Size,
1392+
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc,
1393+
SourceLocation M2Loc, SourceLocation EndLoc);
1394+
13881395
/// Called on well-formed 'doacross' clause.
13891396
OMPClause *
13901397
ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType,

clang/lib/AST/OpenMPClause.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
104104
return static_cast<const OMPFilterClause *>(C);
105105
case OMPC_ompx_dyn_cgroup_mem:
106106
return static_cast<const OMPXDynCGroupMemClause *>(C);
107+
case OMPC_dyn_groupprivate:
108+
return static_cast<const OMPDynGroupprivateClause *>(C);
107109
case OMPC_default:
108110
case OMPC_proc_bind:
109111
case OMPC_safelen:
@@ -2725,6 +2727,25 @@ void OMPClausePrinter::VisitOMPXDynCGroupMemClause(
27252727
OS << ")";
27262728
}
27272729

2730+
void OMPClausePrinter::VisitOMPDynGroupprivateClause(
2731+
OMPDynGroupprivateClause *Node) {
2732+
OS << "dyn_groupprivate(";
2733+
if (Node->getFirstDynGroupprivateModifier() !=
2734+
OMPC_DYN_GROUPPRIVATE_unknown) {
2735+
OS << getOpenMPSimpleClauseTypeName(
2736+
OMPC_dyn_groupprivate, Node->getFirstDynGroupprivateModifier());
2737+
if (Node->getSecondDynGroupprivateModifier() !=
2738+
OMPC_DYN_GROUPPRIVATE_unknown) {
2739+
OS << ", ";
2740+
OS << getOpenMPSimpleClauseTypeName(
2741+
OMPC_dyn_groupprivate, Node->getSecondDynGroupprivateModifier());
2742+
}
2743+
OS << ": ";
2744+
}
2745+
Node->getSize()->printPretty(OS, nullptr, Policy, 0);
2746+
OS << ')';
2747+
}
2748+
27282749
void OMPClausePrinter::VisitOMPDoacrossClause(OMPDoacrossClause *Node) {
27292750
OS << "doacross(";
27302751
OpenMPDoacrossClauseModifier DepType = Node->getDependenceType();

clang/lib/AST/StmtProfile.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,12 @@ void OMPClauseProfiler::VisitOMPXDynCGroupMemClause(
957957
if (Expr *Size = C->getSize())
958958
Profiler->VisitStmt(Size);
959959
}
960+
void OMPClauseProfiler::VisitOMPDynGroupprivateClause(
961+
const OMPDynGroupprivateClause *C) {
962+
VistOMPClauseWithPreInit(C);
963+
if (auto *Size = C->getSize())
964+
Profiler->VisitStmt(Size);
965+
}
960966
void OMPClauseProfiler::VisitOMPDoacrossClause(const OMPDoacrossClause *C) {
961967
VisitOMPClauseList(C);
962968
}

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
171171
return OMPC_GRAINSIZE_unknown;
172172
return Type;
173173
}
174+
case OMPC_dyn_groupprivate: {
175+
return llvm::StringSwitch<unsigned>(Str)
176+
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name) \
177+
.Case(#Name, OMPC_DYN_GROUPPRIVATE_##Name)
178+
#include "clang/Basic/OpenMPKinds.def"
179+
.Default(OMPC_DYN_GROUPPRIVATE_unknown);
180+
}
174181
case OMPC_num_tasks: {
175182
unsigned Type = llvm::StringSwitch<unsigned>(Str)
176183
#define OPENMP_NUMTASKS_MODIFIER(Name) .Case(#Name, OMPC_NUMTASKS_##Name)
@@ -508,6 +515,16 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
508515
#include "clang/Basic/OpenMPKinds.def"
509516
}
510517
llvm_unreachable("Invalid OpenMP 'grainsize' clause modifier");
518+
case OMPC_dyn_groupprivate:
519+
switch (Type) {
520+
case OMPC_DYN_GROUPPRIVATE_unknown:
521+
return "unknown";
522+
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name) \
523+
case OMPC_DYN_GROUPPRIVATE_##Name: \
524+
return #Name;
525+
#include "clang/Basic/OpenMPKinds.def"
526+
}
527+
llvm_unreachable("Invalid OpenMP 'dyn_groupprivate' clause modifier");
511528
case OMPC_num_tasks:
512529
switch (Type) {
513530
case OMPC_NUMTASKS_unknown:

0 commit comments

Comments
 (0)