Skip to content

Commit

Permalink
[OpenMP] Add parsing/sema support for omp_all_memory reserved locator
Browse files Browse the repository at this point in the history
Adds support for the reserved locator 'omp_all_memory' for use
in depend clauses with 'out' or 'inout' dependence-types.

Differential Revision: https://reviews.llvm.org/D125828
  • Loading branch information
mikerice1969 committed May 24, 2022
1 parent 8527f9e commit 9ba9371
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 157 deletions.
59 changes: 36 additions & 23 deletions clang/include/clang/AST/OpenMPClause.h
Expand Up @@ -4746,14 +4746,24 @@ class OMPDependClause final
friend OMPVarListClause;
friend TrailingObjects;

/// Dependency type (one of in, out, inout).
OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
public:
struct DependDataTy final {
/// Dependency type (one of in, out, inout).
OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;

/// Dependency type location.
SourceLocation DepLoc;
/// Dependency type location.
SourceLocation DepLoc;

/// Colon location.
SourceLocation ColonLoc;
/// Colon location.
SourceLocation ColonLoc;

/// Location of 'omp_all_memory'.
SourceLocation OmpAllMemoryLoc;
};

private:
/// Dependency type and source locations.
DependDataTy Data;

/// Number of loops, associated with the depend clause.
unsigned NumLoops = 0;
Expand Down Expand Up @@ -4784,13 +4794,16 @@ class OMPDependClause final
NumLoops(NumLoops) {}

/// Set dependency kind.
void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
void setDependencyKind(OpenMPDependClauseKind K) { Data.DepKind = K; }

/// Set dependency kind and its location.
void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
void setDependencyLoc(SourceLocation Loc) { Data.DepLoc = Loc; }

/// Set colon location.
void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
void setColonLoc(SourceLocation Loc) { Data.ColonLoc = Loc; }

/// Set the 'omp_all_memory' location.
void setOmpAllMemoryLoc(SourceLocation Loc) { Data.OmpAllMemoryLoc = Loc; }

/// Sets optional dependency modifier.
void setModifier(Expr *DepModifier);
Expand All @@ -4802,18 +4815,15 @@ class OMPDependClause final
/// \param StartLoc Starting location of the clause.
/// \param LParenLoc Location of '('.
/// \param EndLoc Ending location of the clause.
/// \param DepKind Dependency type.
/// \param DepLoc Location of the dependency type.
/// \param ColonLoc Colon location.
/// \param Data Dependency type and source locations.
/// \param VL List of references to the variables.
/// \param NumLoops Number of loops that is associated with this depend
/// clause.
static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc, Expr *DepModifier,
OpenMPDependClauseKind DepKind,
SourceLocation DepLoc, SourceLocation ColonLoc,
ArrayRef<Expr *> VL, unsigned NumLoops);
SourceLocation EndLoc, DependDataTy Data,
Expr *DepModifier, ArrayRef<Expr *> VL,
unsigned NumLoops);

/// Creates an empty clause with \a N variables.
///
Expand All @@ -4825,20 +4835,23 @@ class OMPDependClause final
unsigned NumLoops);

/// Get dependency type.
OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
OpenMPDependClauseKind getDependencyKind() const { return Data.DepKind; }

/// Get dependency type location.
SourceLocation getDependencyLoc() const { return Data.DepLoc; }

/// Get colon location.
SourceLocation getColonLoc() const { return Data.ColonLoc; }

/// Get 'omp_all_memory' location.
SourceLocation getOmpAllMemoryLoc() const { return Data.OmpAllMemoryLoc; }

/// Return optional depend modifier.
Expr *getModifier();
const Expr *getModifier() const {
return const_cast<OMPDependClause *>(this)->getModifier();
}

/// Get dependency type location.
SourceLocation getDependencyLoc() const { return DepLoc; }

/// Get colon location.
SourceLocation getColonLoc() const { return ColonLoc; }

/// Get number of loops associated with the clause.
unsigned getNumLoops() const { return NumLoops; }

Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Expand Up @@ -1464,6 +1464,12 @@ def warn_omp51_compat_attributes : Warning<
def err_omp_expected_colon : Error<"missing ':' in %0">;
def err_omp_expected_context_selector
: Error<"expected valid context selector in %0">;
def err_omp_requires_out_inout_depend_type : Error<
"reserved locator 'omp_all_memory' requires 'out' or 'inout' "
"dependency types">;
def warn_omp_more_one_omp_all_memory : Warning<
"reserved locator 'omp_all_memory' cannot be specified more than once">,
InGroup<OpenMPClauses>;

// Pragma loop support.
def err_pragma_loop_missing_argument : Error<
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.def
Expand Up @@ -106,6 +106,8 @@ OPENMP_DEPEND_KIND(depobj)
OPENMP_DEPEND_KIND(source)
OPENMP_DEPEND_KIND(sink)
OPENMP_DEPEND_KIND(inoutset)
OPENMP_DEPEND_KIND(outallmemory)
OPENMP_DEPEND_KIND(inoutallmemory)

// Modifiers for 'linear' clause.
OPENMP_LINEAR_KIND(val)
Expand Down
30 changes: 7 additions & 23 deletions clang/include/clang/Parse/Parser.h
Expand Up @@ -3332,42 +3332,26 @@ class Parser : public CodeCompletionHandler {
ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc,
bool IsAddressOfOperand = false);

/// Data used for parsing list of variables in OpenMP clauses.
struct OpenMPVarListDataTy {
Expr *DepModOrTailExpr = nullptr;
SourceLocation ColonLoc;
SourceLocation RLoc;
CXXScopeSpec ReductionOrMapperIdScopeSpec;
DeclarationNameInfo ReductionOrMapperId;
int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or
///< lastprivate clause.
SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
MapTypeModifiers;
SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers>
MapTypeModifiersLoc;
SmallVector<OpenMPMotionModifierKind, NumberOfOMPMotionModifiers>
MotionModifiers;
SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc;
bool IsMapTypeImplicit = false;
SourceLocation ExtraModifierLoc;
};

/// Parses a reserved locator like 'omp_all_memory'.
bool ParseOpenMPReservedLocator(OpenMPClauseKind Kind,
Sema::OpenMPVarListDataTy &Data,
const LangOptions &LangOpts);
/// Parses clauses with list.
bool ParseOpenMPVarList(OpenMPDirectiveKind DKind, OpenMPClauseKind Kind,
SmallVectorImpl<Expr *> &Vars,
OpenMPVarListDataTy &Data);
Sema::OpenMPVarListDataTy &Data);
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType,
bool ObjectHadErrors, bool EnteringContext,
bool AllowDestructorName, bool AllowConstructorName,
bool AllowDeductionGuide,
SourceLocation *TemplateKWLoc, UnqualifiedId &Result);

/// Parses the mapper modifier in map, to, and from clauses.
bool parseMapperModifier(OpenMPVarListDataTy &Data);
bool parseMapperModifier(Sema::OpenMPVarListDataTy &Data);
/// Parses map-type-modifiers in map clause.
/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list)
/// where, map-type-modifier ::= always | close | mapper(mapper-identifier)
bool parseMapTypeModifiers(OpenMPVarListDataTy &Data);
bool parseMapTypeModifiers(Sema::OpenMPVarListDataTy &Data);

private:
//===--------------------------------------------------------------------===//
Expand Down
46 changes: 31 additions & 15 deletions clang/include/clang/Sema/Sema.h
Expand Up @@ -11435,16 +11435,31 @@ class Sema final {
OpenMPAtomicDefaultMemOrderClauseKind Kind, SourceLocation KindLoc,
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc);

OMPClause *ActOnOpenMPVarListClause(
OpenMPClauseKind Kind, ArrayRef<Expr *> Vars, Expr *DepModOrTailExpr,
const OMPVarListLocTy &Locs, SourceLocation ColonLoc,
CXXScopeSpec &ReductionOrMapperIdScopeSpec,
DeclarationNameInfo &ReductionOrMapperId, int ExtraModifier,
ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
ArrayRef<SourceLocation> MapTypeModifiersLoc, bool IsMapTypeImplicit,
SourceLocation ExtraModifierLoc,
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
ArrayRef<SourceLocation> MotionModifiersLoc);
/// Data used for processing a list of variables in OpenMP clauses.
struct OpenMPVarListDataTy final {
Expr *DepModOrTailExpr = nullptr;
SourceLocation ColonLoc;
SourceLocation RLoc;
CXXScopeSpec ReductionOrMapperIdScopeSpec;
DeclarationNameInfo ReductionOrMapperId;
int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or
///< lastprivate clause.
SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
MapTypeModifiers;
SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers>
MapTypeModifiersLoc;
SmallVector<OpenMPMotionModifierKind, NumberOfOMPMotionModifiers>
MotionModifiers;
SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc;
bool IsMapTypeImplicit = false;
SourceLocation ExtraModifierLoc;
SourceLocation OmpAllMemoryLoc;
};

OMPClause *ActOnOpenMPVarListClause(OpenMPClauseKind Kind,
ArrayRef<Expr *> Vars,
const OMPVarListLocTy &Locs,
OpenMPVarListDataTy &Data);
/// Called on well-formed 'inclusive' clause.
OMPClause *ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList,
SourceLocation StartLoc,
Expand Down Expand Up @@ -11535,11 +11550,12 @@ class Sema final {
SourceLocation LParenLoc,
SourceLocation EndLoc);
/// Called on well-formed 'depend' clause.
OMPClause *
ActOnOpenMPDependClause(Expr *DepModifier, OpenMPDependClauseKind DepKind,
SourceLocation DepLoc, SourceLocation ColonLoc,
ArrayRef<Expr *> VarList, SourceLocation StartLoc,
SourceLocation LParenLoc, SourceLocation EndLoc);
OMPClause *ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data,
Expr *DepModifier,
ArrayRef<Expr *> VarList,
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc);
/// Called on well-formed 'device' clause.
OMPClause *ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier,
Expr *Device, SourceLocation StartLoc,
Expand Down
32 changes: 22 additions & 10 deletions clang/lib/AST/OpenMPClause.cpp
Expand Up @@ -1040,19 +1040,19 @@ OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) {
OMPDependClause *
OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
SourceLocation LParenLoc, SourceLocation EndLoc,
Expr *DepModifier, OpenMPDependClauseKind DepKind,
SourceLocation DepLoc, SourceLocation ColonLoc,
DependDataTy Data, Expr *DepModifier,
ArrayRef<Expr *> VL, unsigned NumLoops) {
void *Mem = C.Allocate(
totalSizeToAlloc<Expr *>(VL.size() + /*depend-modifier*/ 1 + NumLoops),
alignof(OMPDependClause));
OMPDependClause *Clause = new (Mem)
OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
Clause->setVarRefs(VL);
Clause->setDependencyKind(DepKind);
Clause->setDependencyLoc(DepLoc);
Clause->setColonLoc(ColonLoc);
Clause->setDependencyKind(Data.DepKind);
Clause->setDependencyLoc(Data.DepLoc);
Clause->setColonLoc(Data.ColonLoc);
Clause->setOmpAllMemoryLoc(Data.OmpAllMemoryLoc);
Clause->setModifier(DepModifier);
Clause->setVarRefs(VL);
for (unsigned I = 0 ; I < NumLoops; ++I)
Clause->setLoopData(I, nullptr);
return Clause;
Expand Down Expand Up @@ -2183,11 +2183,23 @@ void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
DepModifier->printPretty(OS, nullptr, Policy);
OS << ", ";
}
OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
Node->getDependencyKind());
if (!Node->varlist_empty()) {
OpenMPDependClauseKind DepKind = Node->getDependencyKind();
OpenMPDependClauseKind PrintKind = DepKind;
bool IsOmpAllMemory = false;
if (PrintKind == OMPC_DEPEND_outallmemory) {
PrintKind = OMPC_DEPEND_out;
IsOmpAllMemory = true;
} else if (PrintKind == OMPC_DEPEND_inoutallmemory) {
PrintKind = OMPC_DEPEND_inout;
IsOmpAllMemory = true;
}
OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), PrintKind);
if (!Node->varlist_empty() || IsOmpAllMemory)
OS << " :";
VisitOMPClauseList(Node, ' ');
VisitOMPClauseList(Node, ' ');
if (IsOmpAllMemory) {
OS << (Node->varlist_empty() ? " " : ",");
OS << "omp_all_memory";
}
OS << ")";
}
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp
Expand Up @@ -4534,6 +4534,8 @@ static RTLDependenceKindTy translateDependencyKind(OpenMPDependClauseKind K) {
case OMPC_DEPEND_source:
case OMPC_DEPEND_sink:
case OMPC_DEPEND_depobj:
case OMPC_DEPEND_outallmemory:
case OMPC_DEPEND_inoutallmemory:
case OMPC_DEPEND_unknown:
llvm_unreachable("Unknown task dependence type");
}
Expand Down

0 comments on commit 9ba9371

Please sign in to comment.