Skip to content
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
146 changes: 146 additions & 0 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -9988,6 +9988,152 @@ 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 { SIMPLE, FALLBACK, NUM_MODIFIERS };
unsigned 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 setDynGroupprivateModifier(OpenMPDynGroupprivateClauseModifier M) {
Modifiers[SIMPLE] = M;
}

/// Set the second dyn_groupprivate modifier.
///
/// \param M The modifier.
void setDynGroupprivateFallbackModifier(
OpenMPDynGroupprivateClauseFallbackModifier M) {
Modifiers[FALLBACK] = M;
}

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

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

/// 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,
OpenMPDynGroupprivateClauseFallbackModifier M2,
SourceLocation M2Loc)
: OMPClause(llvm::omp::OMPC_dyn_groupprivate, StartLoc, EndLoc),
OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Size(Size) {
setPreInitStmt(HelperSize, CaptureRegion);
Modifiers[SIMPLE] = M1;
Modifiers[FALLBACK] = M2;
ModifiersLoc[SIMPLE] = M1Loc;
ModifiersLoc[FALLBACK] = M2Loc;
}

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

/// Get the first modifier of the clause.
OpenMPDynGroupprivateClauseModifier getDynGroupprivateModifier() const {
return static_cast<OpenMPDynGroupprivateClauseModifier>(Modifiers[SIMPLE]);
}

/// Get the second modifier of the clause.
OpenMPDynGroupprivateClauseFallbackModifier
getDynGroupprivateFallbackModifier() const {
return static_cast<OpenMPDynGroupprivateClauseFallbackModifier>(
Modifiers[FALLBACK]);
}

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

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

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

/// 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 @@ -4159,6 +4159,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 @@ -12124,6 +12124,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_incompatible_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
16 changes: 16 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
#ifndef OPENMP_GRAINSIZE_MODIFIER
#define OPENMP_GRAINSIZE_MODIFIER(Name)
#endif
#ifndef OPENMP_DYN_GROUPPRIVATE_MODIFIER
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name)
#endif
#ifndef OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER
#define OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER(Name)
#endif
#ifndef OPENMP_NUMTASKS_MODIFIER
#define OPENMP_NUMTASKS_MODIFIER(Name)
#endif
Expand Down Expand Up @@ -239,6 +245,14 @@ OPENMP_BIND_KIND(thread)
// Modifiers for the 'grainsize' clause.
OPENMP_GRAINSIZE_MODIFIER(strict)

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

// Fallback modifiers for the 'dyn_groupprivate' clause.
OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER(abort)
OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER(null)
OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER(default_mem)

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

Expand All @@ -257,6 +271,8 @@ OPENMP_DOACROSS_MODIFIER(source_omp_cur_iteration)

#undef OPENMP_NUMTASKS_MODIFIER
#undef OPENMP_NUMTHREADS_MODIFIER
#undef OPENMP_DYN_GROUPPRIVATE_MODIFIER
#undef OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER
#undef OPENMP_GRAINSIZE_MODIFIER
#undef OPENMP_BIND_KIND
#undef OPENMP_ADJUST_ARGS_KIND
Expand Down
14 changes: 14 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@ 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
};

enum OpenMPDynGroupprivateClauseFallbackModifier {
OMPC_DYN_GROUPPRIVATE_FALLBACK_unknown = OMPC_DYN_GROUPPRIVATE_unknown,
#define OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER(Name) \
OMPC_DYN_GROUPPRIVATE_FALLBACK_##Name,
#include "clang/Basic/OpenMPKinds.def"
OMPC_DYN_GROUPPRIVATE_FALLBACK_last
};

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 @@ -1405,6 +1405,13 @@ class SemaOpenMP : public SemaBase {
SourceLocation LParenLoc,
SourceLocation EndLoc);

/// Called on a well-formed 'dyn_groupprivate' clause.
OMPClause *ActOnOpenMPDynGroupprivateClause(
OpenMPDynGroupprivateClauseModifier M1,
OpenMPDynGroupprivateClauseFallbackModifier 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
20 changes: 20 additions & 0 deletions clang/lib/AST/OpenMPClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,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_message:
return static_cast<const OMPMessageClause *>(C);
case OMPC_default:
Expand Down Expand Up @@ -2849,6 +2851,24 @@ void OMPClausePrinter::VisitOMPXDynCGroupMemClause(
OS << ")";
}

void OMPClausePrinter::VisitOMPDynGroupprivateClause(
OMPDynGroupprivateClause *Node) {
OS << "dyn_groupprivate(";
if (Node->getDynGroupprivateModifier() != OMPC_DYN_GROUPPRIVATE_unknown) {
OS << getOpenMPSimpleClauseTypeName(OMPC_dyn_groupprivate,
Node->getDynGroupprivateModifier());
if (Node->getDynGroupprivateFallbackModifier() !=
OMPC_DYN_GROUPPRIVATE_FALLBACK_unknown) {
OS << ", ";
OS << getOpenMPSimpleClauseTypeName(
OMPC_dyn_groupprivate, Node->getDynGroupprivateFallbackModifier());
}
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 @@ -966,6 +966,12 @@ void OMPClauseProfiler::VisitOMPXDynCGroupMemClause(
if (Expr *Size = C->getSize())
Profiler->VisitStmt(Size);
}
void OMPClauseProfiler::VisitOMPDynGroupprivateClause(
const OMPDynGroupprivateClause *C) {
VisitOMPClauseWithPreInit(C);
if (auto *Size = C->getSize())
Profiler->VisitStmt(Size);
}
void OMPClauseProfiler::VisitOMPDoacrossClause(const OMPDoacrossClause *C) {
VisitOMPClauseList(C);
}
Expand Down
24 changes: 24 additions & 0 deletions clang/lib/Basic/OpenMPKinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ 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)
#define OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER(Name) \
.Case(#Name, OMPC_DYN_GROUPPRIVATE_FALLBACK_##Name) \
.Case("fallback(" #Name ")", OMPC_DYN_GROUPPRIVATE_FALLBACK_##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 @@ -535,6 +545,20 @@ 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:
case OMPC_DYN_GROUPPRIVATE_FALLBACK_last:
return "unknown";
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name) \
case OMPC_DYN_GROUPPRIVATE_##Name: \
return #Name;
#define OPENMP_DYN_GROUPPRIVATE_FALLBACK_MODIFIER(Name) \
case OMPC_DYN_GROUPPRIVATE_FALLBACK_##Name: \
return "fallback(" #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