Skip to content

Commit 1a54d76

Browse files
committed
[OpenMP][Offload] Add support for cgroup modifier in dyn_groupprivate
1 parent eb44bba commit 1a54d76

File tree

14 files changed

+243
-119
lines changed

14 files changed

+243
-119
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 128 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9772,63 +9772,155 @@ class OMPXDynCGroupMemClause
97729772
/// and '#pragma omp teams ...' directives.
97739773
///
97749774
/// \code
9775-
/// #pragma omp target [...] dyn_groupprivate(N)
9775+
/// #pragma omp target [...] dyn_groupprivate(a,b: N)
97769776
/// \endcode
9777-
class OMPDynGroupprivateClause
9778-
: public OMPOneStmtClause<llvm::omp::OMPC_dyn_groupprivate, OMPClause>,
9779-
public OMPClauseWithPreInit {
9777+
class OMPDynGroupprivateClause : public OMPClause, public OMPClauseWithPreInit {
97809778
friend class OMPClauseReader;
97819779

9782-
/// Modifiers for 'grainsize' clause.
9783-
OpenMPDynGroupprivateClauseModifier Modifier = OMPC_DYN_GROUPPRIVATE_unknown;
9780+
/// Location of '('.
9781+
SourceLocation LParenLoc;
97849782

9785-
/// Location of the modifier.
9786-
SourceLocation ModifierLoc;
9783+
/// Modifiers for 'dyn_groupprivate' clause.
9784+
enum {FIRST, SECOND, NUM_MODIFIERS};
9785+
OpenMPDynGroupprivateClauseModifier Modifiers[NUM_MODIFIERS];
97879786

9788-
/// Set size.
9789-
void setSize(Expr *E) { setStmt(E); }
9787+
/// Locations of modifiers.
9788+
SourceLocation ModifiersLoc[NUM_MODIFIERS];
97909789

9791-
/// Sets modifier.
9792-
void setModifier(OpenMPDynGroupprivateClauseModifier M) { Modifier = M; }
9790+
/// The size of the dyn_groupprivate.
9791+
Expr *Size = nullptr;
97939792

9794-
/// Sets modifier location.
9795-
void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
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; }
97969838

97979839
public:
9798-
/// Build 'dyn_groupprivate' clause.
9840+
/// Build 'dyn_groupprivate' clause with a size expression \a Size.
97999841
///
9800-
/// \param Modifier Clause modifier.
9801-
/// \param Size Size expression.
9802-
/// \param HelperSize Helper Size expression
9803-
/// \param CaptureRegion Innermost OpenMP region where expressions in this
98049842
/// \param StartLoc Starting location of the clause.
98059843
/// \param LParenLoc Location of '('.
9806-
/// \param ModifierLoc Modifier location.
98079844
/// \param EndLoc Ending location of the clause.
9808-
OMPDynGroupprivateClause(OpenMPDynGroupprivateClauseModifier Modifier,
9809-
Expr *Size, Stmt *HelperSize,
9810-
OpenMPDirectiveKind CaptureRegion,
9811-
SourceLocation StartLoc, SourceLocation LParenLoc,
9812-
SourceLocation ModifierLoc, SourceLocation EndLoc)
9813-
: OMPOneStmtClause(Size, StartLoc, LParenLoc, EndLoc),
9814-
OMPClauseWithPreInit(this), Modifier(Modifier), ModifierLoc(ModifierLoc) {
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,
9852+
Expr *Size, Stmt *HelperSize,
9853+
OpenMPDirectiveKind CaptureRegion,
9854+
OpenMPDynGroupprivateClauseModifier M1,
9855+
SourceLocation M1Loc,
9856+
OpenMPDynGroupprivateClauseModifier M2,
9857+
SourceLocation M2Loc)
9858+
: OMPClause(llvm::omp::OMPC_dyn_groupprivate, StartLoc, EndLoc),
9859+
OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Size(Size) {
98159860
setPreInitStmt(HelperSize, CaptureRegion);
9861+
Modifiers[FIRST] = M1;
9862+
Modifiers[SECOND] = M2;
9863+
ModifiersLoc[FIRST] = M1Loc;
9864+
ModifiersLoc[SECOND] = M2Loc;
98169865
}
98179866

98189867
/// Build an empty clause.
9819-
OMPDynGroupprivateClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {}
9868+
explicit OMPDynGroupprivateClause()
9869+
: OMPClause(llvm::omp::OMPC_dyn_groupprivate, SourceLocation(), SourceLocation()),
9870+
OMPClauseWithPreInit(this) {
9871+
Modifiers[FIRST] = OMPC_DYN_GROUPPRIVATE_unknown;
9872+
Modifiers[SECOND] = OMPC_DYN_GROUPPRIVATE_unknown;
9873+
}
98209874

9821-
/// Return the size expression.
9822-
Expr *getSize() { return getStmtAs<Expr>(); }
9875+
/// Get the first modifier of the clause.
9876+
OpenMPDynGroupprivateClauseModifier getFirstDynGroupprivateModifier() const {
9877+
return Modifiers[FIRST];
9878+
}
98239879

9824-
/// Return the size expression.
9825-
Expr *getSize() const { return getStmtAs<Expr>(); }
9880+
/// Get the second modifier of the clause.
9881+
OpenMPDynGroupprivateClauseModifier getSecondDynGroupprivateModifier() const {
9882+
return Modifiers[SECOND];
9883+
}
98269884

9827-
/// Gets modifier.
9828-
OpenMPDynGroupprivateClauseModifier getModifier() const { return Modifier; }
9885+
/// Get location of '('.
9886+
SourceLocation getLParenLoc() { return LParenLoc; }
98299887

9830-
/// Gets modifier location.
9831-
SourceLocation getModifierLoc() const { return ModifierLoc; }
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+
}
98329924
};
98339925

98349926
/// This represents the 'doacross' clause for the '#pragma omp ordered'

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11995,6 +11995,8 @@ 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 : Error<
11999+
"modifier '%0' cannot be used along with modifier '%1' in dyn_groupprivate">;
1199812000
def err_omp_simple_clause_incompatible_with_ordered : Error<
1199912001
"'%0' clause with '%1' modifier cannot be specified if an 'ordered' clause is specified">;
1200012002
def err_omp_ordered_simd : Error<

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ OPENMP_BIND_KIND(thread)
231231
OPENMP_GRAINSIZE_MODIFIER(strict)
232232

233233
// Modifiers for the 'dyn_groupprivate' clause.
234+
OPENMP_DYN_GROUPPRIVATE_MODIFIER(cgroup)
234235
OPENMP_DYN_GROUPPRIVATE_MODIFIER(strict)
235236
OPENMP_DYN_GROUPPRIVATE_MODIFIER(fallback)
236237

clang/include/clang/Basic/OpenMPKinds.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ enum OpenMPDynGroupprivateClauseModifier {
223223
OMPC_DYN_GROUPPRIVATE_unknown
224224
};
225225

226+
/// Number of allowed dyn_groupprivate-modifiers.
227+
static constexpr unsigned NumberOfOMPDynGroupprivateClauseModifiers =
228+
OMPC_DYN_GROUPPRIVATE_unknown;
229+
226230
enum OpenMPNumTasksClauseModifier {
227231
#define OPENMP_NUMTASKS_MODIFIER(Name) OMPC_NUMTASKS_##Name,
228232
#include "clang/Basic/OpenMPKinds.def"

clang/include/clang/Sema/SemaOpenMP.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,11 +1386,10 @@ class SemaOpenMP : public SemaBase {
13861386
SourceLocation EndLoc);
13871387

13881388
/// Called on a well-formed 'dyn_groupprivate' clause.
1389-
OMPClause *
1390-
ActOnOpenMPDynGroupprivateClause(OpenMPDynGroupprivateClauseModifier Modifier,
1391-
Expr *Size, SourceLocation StartLoc,
1392-
SourceLocation LParenLoc,
1393-
SourceLocation ModifierLoc, SourceLocation EndLoc);
1389+
OMPClause *ActOnOpenMPDynGroupprivateClause(
1390+
OpenMPDynGroupprivateClauseModifier M1, OpenMPDynGroupprivateClauseModifier M2,
1391+
Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc,
1392+
SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation EndLoc);
13941393

13951394
/// Called on well-formed 'doacross' clause.
13961395
OMPClause *

clang/lib/AST/OpenMPClause.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,13 +2727,17 @@ void OMPClausePrinter::VisitOMPXDynCGroupMemClause(
27272727
OS << ")";
27282728
}
27292729

2730-
void OMPClausePrinter::VisitOMPDynGroupprivateClause(
2731-
OMPDynGroupprivateClause *Node) {
2730+
void OMPClausePrinter::VisitOMPDynGroupprivateClause(OMPDynGroupprivateClause *Node) {
27322731
OS << "dyn_groupprivate(";
2733-
OpenMPDynGroupprivateClauseModifier Modifier = Node->getModifier();
2734-
if (Modifier != OMPC_DYN_GROUPPRIVATE_unknown) {
2735-
OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier)
2736-
<< ": ";
2732+
if (Node->getFirstDynGroupprivateModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
2733+
OS << getOpenMPSimpleClauseTypeName(OMPC_dyn_groupprivate,
2734+
Node->getFirstDynGroupprivateModifier());
2735+
if (Node->getSecondDynGroupprivateModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
2736+
OS << ", ";
2737+
OS << getOpenMPSimpleClauseTypeName(OMPC_dyn_groupprivate,
2738+
Node->getSecondDynGroupprivateModifier());
2739+
}
2740+
OS << ": ";
27372741
}
27382742
Node->getSize()->printPretty(OS, nullptr, Policy, 0);
27392743
OS << ")";

clang/lib/AST/StmtProfile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ void OMPClauseProfiler::VisitOMPXDynCGroupMemClause(
960960
void OMPClauseProfiler::VisitOMPDynGroupprivateClause(
961961
const OMPDynGroupprivateClause *C) {
962962
VistOMPClauseWithPreInit(C);
963-
if (Expr *Size = C->getSize())
963+
if (auto *Size = C->getSize())
964964
Profiler->VisitStmt(Size);
965965
}
966966
void OMPClauseProfiler::VisitOMPDoacrossClause(const OMPDoacrossClause *C) {

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9500,8 +9500,8 @@ static std::pair<llvm::Value *, bool> emitDynCGroupMem(const OMPExecutableDirect
95009500
DynGPClause->getSize(), /*IgnoreResultAssign=*/true);
95019501
DynGP = CGF.Builder.CreateIntCast(DynGPVal, CGF.Int32Ty,
95029502
/*isSigned=*/false);
9503-
DynGPFallback = (DynGPClause->getModifier() == OMPC_DYN_GROUPPRIVATE_fallback ||
9504-
OMPC_DYN_GROUPPRIVATE_unknown);
9503+
DynGPFallback = (DynGPClause->getFirstDynGroupprivateModifier() != OMPC_DYN_GROUPPRIVATE_strict &&
9504+
DynGPClause->getSecondDynGroupprivateModifier() != OMPC_DYN_GROUPPRIVATE_strict);
95059505
} else if (auto *OMPXDynCGClause = D.getSingleClause<OMPXDynCGroupMemClause>()) {
95069506
CodeGenFunction::RunCleanupsScope DynCGMemScope(CGF);
95079507
llvm::Value *DynCGMemVal = CGF.EmitScalarExpr(

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3837,35 +3837,37 @@ OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
38373837
KLoc.emplace_back();
38383838
}
38393839
} else if (Kind == OMPC_dyn_groupprivate) {
3840-
// Parse optional <dyn_groupprivate modifier> ':'
3841-
OpenMPDynGroupprivateClauseModifier Modifier =
3842-
static_cast<OpenMPDynGroupprivateClauseModifier>(getOpenMPSimpleClauseType(
3843-
Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok),
3844-
getLangOpts()));
3845-
if (getLangOpts().OpenMP >= 51) {
3846-
if (NextToken().is(tok::colon)) {
3847-
Arg.push_back(Modifier);
3848-
KLoc.push_back(Tok.getLocation());
3849-
// Parse modifier
3840+
enum { Modifier1, Modifier2, NumberOfElements };
3841+
Arg.resize(NumberOfElements);
3842+
KLoc.resize(NumberOfElements);
3843+
Arg[Modifier1] = OMPC_DYN_GROUPPRIVATE_unknown;
3844+
Arg[Modifier2] = OMPC_DYN_GROUPPRIVATE_unknown;
3845+
unsigned Modifier = getOpenMPSimpleClauseType(
3846+
Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok), getLangOpts());
3847+
3848+
if (Modifier < OMPC_DYN_GROUPPRIVATE_unknown) {
3849+
// Parse 'modifier'
3850+
Arg[Modifier1] = Modifier;
3851+
KLoc[Modifier1] = Tok.getLocation();
3852+
if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
3853+
Tok.isNot(tok::annot_pragma_openmp_end))
38503854
ConsumeAnyToken();
3851-
// Parse ':'
3855+
if (Tok.is(tok::comma)) {
3856+
// Parse ',' 'modifier'
38523857
ConsumeAnyToken();
3853-
} else {
3854-
if (Modifier == OMPC_DYN_GROUPPRIVATE_strict) {
3855-
Diag(Tok, diag::err_modifier_expected_colon) << "strict";
3856-
// Parse modifier
3857-
ConsumeAnyToken();
3858-
} else if (Modifier == OMPC_DYN_GROUPPRIVATE_fallback) {
3859-
Diag(Tok, diag::err_modifier_expected_colon) << "fallback";
3860-
// Parse modifier
3858+
Modifier = getOpenMPSimpleClauseType(
3859+
Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok), getLangOpts());
3860+
Arg[Modifier2] = Modifier;
3861+
KLoc[Modifier2] = Tok.getLocation();
3862+
if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
3863+
Tok.isNot(tok::annot_pragma_openmp_end))
38613864
ConsumeAnyToken();
3862-
}
3863-
Arg.push_back(OMPC_DYN_GROUPPRIVATE_unknown);
3864-
KLoc.emplace_back();
38653865
}
3866-
} else {
3867-
Arg.push_back(OMPC_DYN_GROUPPRIVATE_unknown);
3868-
KLoc.emplace_back();
3866+
// Parse ':'
3867+
if (Tok.is(tok::colon))
3868+
ConsumeAnyToken();
3869+
else
3870+
Diag(Tok, diag::warn_pragma_expected_colon) << "dyn_groupprivate modifier";
38693871
}
38703872
} else if (Kind == OMPC_num_tasks) {
38713873
// Parse optional <num_tasks modifier> ':'

0 commit comments

Comments
 (0)