Skip to content

[OpenMP] Add parser/semantic support for dyn_groupprivate clause #152651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
155 changes: 155 additions & 0 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -9768,6 +9768,161 @@ class OMPXDynCGroupMemClause
Expr *getSize() const { return getStmtAs<Expr>(); }
};

/// This represents 'dyn_groupprivate' clause in '#pragma omp target ...'
/// and '#pragma omp teams ...' directives.
///
/// \code
/// #pragma omp target [...] dyn_groupprivate(a,b: N)
/// \endcode
class OMPDynGroupprivateClause : public OMPClause, public OMPClauseWithPreInit {
friend class OMPClauseReader;

/// Location of '('.
SourceLocation LParenLoc;

/// Modifiers for 'dyn_groupprivate' clause.
enum { FIRST, SECOND, NUM_MODIFIERS };
OpenMPDynGroupprivateClauseModifier Modifiers[NUM_MODIFIERS];

/// Locations of modifiers.
SourceLocation ModifiersLoc[NUM_MODIFIERS];

/// The size of the dyn_groupprivate.
Expr *Size = nullptr;

/// Set the first dyn_groupprivate modifier.
///
/// \param M The modifier.
void setFirstDynGroupprivateModifier(OpenMPDynGroupprivateClauseModifier M) {
Modifiers[FIRST] = M;
}

/// Set the second dyn_groupprivate modifier.
///
/// \param M The modifier.
void setSecondDynGroupprivateModifier(OpenMPDynGroupprivateClauseModifier M) {
Modifiers[SECOND] = M;
}

/// Set location of the first dyn_groupprivate modifier.
void setFirstDynGroupprivateModifierLoc(SourceLocation Loc) {
ModifiersLoc[FIRST] = Loc;
}

/// Set location of the second dyn_groupprivate modifier.
void setSecondDynGroupprivateModifierLoc(SourceLocation Loc) {
ModifiersLoc[SECOND] = Loc;
}

/// Set dyn_groupprivate modifier location.
///
/// \param M The modifier location.
void setDynGroupprivateModifer(OpenMPDynGroupprivateClauseModifier M) {
if (Modifiers[FIRST] == OMPC_DYN_GROUPPRIVATE_unknown)
Modifiers[FIRST] = M;
else {
assert(Modifiers[SECOND] == OMPC_DYN_GROUPPRIVATE_unknown);
Modifiers[SECOND] = M;
}
}

/// Sets the location of '('.
///
/// \param Loc Location of '('.
void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }

/// Set size.
///
/// \param E Size.
void setSize(Expr *E) { Size = E; }

public:
/// Build 'dyn_groupprivate' clause with a size expression \a Size.
///
/// \param StartLoc Starting location of the clause.
/// \param LParenLoc Location of '('.
/// \param EndLoc Ending location of the clause.
/// \param Size Size.
/// \param M1 The first modifier applied to 'dyn_groupprivate' clause.
/// \param M1Loc Location of the first modifier.
/// \param M2 The second modifier applied to 'dyn_groupprivate' clause.
/// \param M2Loc Location of the second modifier.
OMPDynGroupprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc, Expr *Size, Stmt *HelperSize,
OpenMPDirectiveKind CaptureRegion,
OpenMPDynGroupprivateClauseModifier M1,
SourceLocation M1Loc,
OpenMPDynGroupprivateClauseModifier M2,
SourceLocation M2Loc)
: OMPClause(llvm::omp::OMPC_dyn_groupprivate, StartLoc, EndLoc),
OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Size(Size) {
setPreInitStmt(HelperSize, CaptureRegion);
Modifiers[FIRST] = M1;
Modifiers[SECOND] = M2;
ModifiersLoc[FIRST] = M1Loc;
ModifiersLoc[SECOND] = M2Loc;
}

/// Build an empty clause.
explicit OMPDynGroupprivateClause()
: OMPClause(llvm::omp::OMPC_dyn_groupprivate, SourceLocation(),
SourceLocation()),
OMPClauseWithPreInit(this) {
Modifiers[FIRST] = OMPC_DYN_GROUPPRIVATE_unknown;
Modifiers[SECOND] = OMPC_DYN_GROUPPRIVATE_unknown;
}

/// Get the first modifier of the clause.
OpenMPDynGroupprivateClauseModifier getFirstDynGroupprivateModifier() const {
return Modifiers[FIRST];
}

/// Get the second modifier of the clause.
OpenMPDynGroupprivateClauseModifier getSecondDynGroupprivateModifier() const {
return Modifiers[SECOND];
}

/// Get location of '('.
SourceLocation getLParenLoc() { return LParenLoc; }

/// Get the first modifier location.
SourceLocation getFirstDynGroupprivateModifierLoc() const {
return ModifiersLoc[FIRST];
}

/// Get the second modifier location.
SourceLocation getSecondDynGroupprivateModifierLoc() const {
return ModifiersLoc[SECOND];
}

/// Get size.
Expr *getSize() { return Size; }

/// Get size.
const Expr *getSize() const { return Size; }

child_range children() {
return child_range(reinterpret_cast<Stmt **>(&Size),
reinterpret_cast<Stmt **>(&Size) + 1);
}

const_child_range children() const {
auto Children = const_cast<OMPDynGroupprivateClause *>(this)->children();
return const_child_range(Children.begin(), Children.end());
}

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());
}

static bool classof(const OMPClause *T) {
return T->getClauseKind() == llvm::omp::OMPC_dyn_groupprivate;
}
};

/// This represents the 'doacross' clause for the '#pragma omp ordered'
/// directive.
///
Expand Down
8 changes: 8 additions & 0 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4060,6 +4060,14 @@ bool RecursiveASTVisitor<Derived>::VisitOMPXDynCGroupMemClause(
return true;
}

template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPDynGroupprivateClause(
OMPDynGroupprivateClause *C) {
TRY_TO(VisitOMPClauseWithPreInit(C));
TRY_TO(TraverseStmt(C->getSize()));
return true;
}

template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPDoacrossClause(
OMPDoacrossClause *C) {
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11995,6 +11995,9 @@ def err_omp_unexpected_schedule_modifier : Error<
"modifier '%0' cannot be used along with modifier '%1'">;
def err_omp_schedule_nonmonotonic_static : Error<
"'nonmonotonic' modifier can only be specified with 'dynamic' or 'guided' schedule kind">;
def err_omp_unexpected_dyn_groupprivate_modifier
: Error<"modifier '%0' cannot be used along with modifier '%1' in "
"dyn_groupprivate">;
def err_omp_simple_clause_incompatible_with_ordered : Error<
"'%0' clause with '%1' modifier cannot be specified if an 'ordered' clause is specified">;
def err_omp_ordered_simd : Error<
Expand Down
9 changes: 9 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
#ifndef OPENMP_GRAINSIZE_MODIFIER
#define OPENMP_GRAINSIZE_MODIFIER(Name)
#endif
#ifndef OPENMP_DYN_GROUPPRIVATE_MODIFIER
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name)
#endif
#ifndef OPENMP_NUMTASKS_MODIFIER
#define OPENMP_NUMTASKS_MODIFIER(Name)
#endif
Expand Down Expand Up @@ -227,6 +230,11 @@ OPENMP_BIND_KIND(thread)
// Modifiers for the 'grainsize' clause.
OPENMP_GRAINSIZE_MODIFIER(strict)

// Modifiers for the 'dyn_groupprivate' clause.
OPENMP_DYN_GROUPPRIVATE_MODIFIER(cgroup)
OPENMP_DYN_GROUPPRIVATE_MODIFIER(strict)
OPENMP_DYN_GROUPPRIVATE_MODIFIER(fallback)

// Modifiers for the 'num_tasks' clause.
OPENMP_NUMTASKS_MODIFIER(strict)

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

#undef OPENMP_NUMTASKS_MODIFIER
#undef OPENMP_NUMTHREADS_MODIFIER
#undef OPENMP_DYN_GROUPPRIVATE_MODIFIER
#undef OPENMP_GRAINSIZE_MODIFIER
#undef OPENMP_BIND_KIND
#undef OPENMP_ADJUST_ARGS_KIND
Expand Down
10 changes: 10 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ enum OpenMPGrainsizeClauseModifier {
OMPC_GRAINSIZE_unknown
};

enum OpenMPDynGroupprivateClauseModifier {
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name) OMPC_DYN_GROUPPRIVATE_##Name,
#include "clang/Basic/OpenMPKinds.def"
OMPC_DYN_GROUPPRIVATE_unknown
};

/// Number of allowed dyn_groupprivate-modifiers.
static constexpr unsigned NumberOfOMPDynGroupprivateClauseModifiers =
OMPC_DYN_GROUPPRIVATE_unknown;

enum OpenMPNumTasksClauseModifier {
#define OPENMP_NUMTASKS_MODIFIER(Name) OMPC_NUMTASKS_##Name,
#include "clang/Basic/OpenMPKinds.def"
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Sema/SemaOpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,13 @@ class SemaOpenMP : public SemaBase {
SourceLocation LParenLoc,
SourceLocation EndLoc);

/// Called on a well-formed 'dyn_groupprivate' clause.
OMPClause *ActOnOpenMPDynGroupprivateClause(
OpenMPDynGroupprivateClauseModifier M1,
OpenMPDynGroupprivateClauseModifier M2, Expr *Size,
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc,
SourceLocation M2Loc, SourceLocation EndLoc);

/// Called on well-formed 'doacross' clause.
OMPClause *
ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType,
Expand Down
21 changes: 21 additions & 0 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_dyn_groupprivate:
return static_cast<const OMPDynGroupprivateClause *>(C);
case OMPC_default:
case OMPC_proc_bind:
case OMPC_safelen:
Expand Down Expand Up @@ -2725,6 +2727,25 @@ void OMPClausePrinter::VisitOMPXDynCGroupMemClause(
OS << ")";
}

void OMPClausePrinter::VisitOMPDynGroupprivateClause(
OMPDynGroupprivateClause *Node) {
OS << "dyn_groupprivate(";
if (Node->getFirstDynGroupprivateModifier() !=
OMPC_DYN_GROUPPRIVATE_unknown) {
OS << getOpenMPSimpleClauseTypeName(
OMPC_dyn_groupprivate, Node->getFirstDynGroupprivateModifier());
if (Node->getSecondDynGroupprivateModifier() !=
OMPC_DYN_GROUPPRIVATE_unknown) {
OS << ", ";
OS << getOpenMPSimpleClauseTypeName(
OMPC_dyn_groupprivate, Node->getSecondDynGroupprivateModifier());
}
OS << ": ";
}
Node->getSize()->printPretty(OS, nullptr, Policy, 0);
OS << ')';
}

void OMPClausePrinter::VisitOMPDoacrossClause(OMPDoacrossClause *Node) {
OS << "doacross(";
OpenMPDoacrossClauseModifier DepType = Node->getDependenceType();
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/AST/StmtProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,12 @@ void OMPClauseProfiler::VisitOMPXDynCGroupMemClause(
if (Expr *Size = C->getSize())
Profiler->VisitStmt(Size);
}
void OMPClauseProfiler::VisitOMPDynGroupprivateClause(
const OMPDynGroupprivateClause *C) {
VistOMPClauseWithPreInit(C);
if (auto *Size = C->getSize())
Profiler->VisitStmt(Size);
}
void OMPClauseProfiler::VisitOMPDoacrossClause(const OMPDoacrossClause *C) {
VisitOMPClauseList(C);
}
Expand Down
17 changes: 17 additions & 0 deletions clang/lib/Basic/OpenMPKinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
return OMPC_GRAINSIZE_unknown;
return Type;
}
case OMPC_dyn_groupprivate: {
return llvm::StringSwitch<unsigned>(Str)
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name) \
.Case(#Name, OMPC_DYN_GROUPPRIVATE_##Name)
#include "clang/Basic/OpenMPKinds.def"
.Default(OMPC_DYN_GROUPPRIVATE_unknown);
}
case OMPC_num_tasks: {
unsigned Type = llvm::StringSwitch<unsigned>(Str)
#define OPENMP_NUMTASKS_MODIFIER(Name) .Case(#Name, OMPC_NUMTASKS_##Name)
Expand Down Expand Up @@ -508,6 +515,16 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
#include "clang/Basic/OpenMPKinds.def"
}
llvm_unreachable("Invalid OpenMP 'grainsize' clause modifier");
case OMPC_dyn_groupprivate:
switch (Type) {
case OMPC_DYN_GROUPPRIVATE_unknown:
return "unknown";
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name) \
case OMPC_DYN_GROUPPRIVATE_##Name: \
return #Name;
#include "clang/Basic/OpenMPKinds.def"
}
llvm_unreachable("Invalid OpenMP 'dyn_groupprivate' clause modifier");
case OMPC_num_tasks:
switch (Type) {
case OMPC_NUMTASKS_unknown:
Expand Down
Loading
Loading