Skip to content

Commit 9ba9371

Browse files
committed
[OpenMP] Add parsing/sema support for omp_all_memory reserved locator
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
1 parent 8527f9e commit 9ba9371

File tree

14 files changed

+239
-157
lines changed

14 files changed

+239
-157
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4746,14 +4746,24 @@ class OMPDependClause final
47464746
friend OMPVarListClause;
47474747
friend TrailingObjects;
47484748

4749-
/// Dependency type (one of in, out, inout).
4750-
OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
4749+
public:
4750+
struct DependDataTy final {
4751+
/// Dependency type (one of in, out, inout).
4752+
OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
47514753

4752-
/// Dependency type location.
4753-
SourceLocation DepLoc;
4754+
/// Dependency type location.
4755+
SourceLocation DepLoc;
47544756

4755-
/// Colon location.
4756-
SourceLocation ColonLoc;
4757+
/// Colon location.
4758+
SourceLocation ColonLoc;
4759+
4760+
/// Location of 'omp_all_memory'.
4761+
SourceLocation OmpAllMemoryLoc;
4762+
};
4763+
4764+
private:
4765+
/// Dependency type and source locations.
4766+
DependDataTy Data;
47574767

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

47864796
/// Set dependency kind.
4787-
void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
4797+
void setDependencyKind(OpenMPDependClauseKind K) { Data.DepKind = K; }
47884798

47894799
/// Set dependency kind and its location.
4790-
void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
4800+
void setDependencyLoc(SourceLocation Loc) { Data.DepLoc = Loc; }
47914801

47924802
/// Set colon location.
4793-
void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4803+
void setColonLoc(SourceLocation Loc) { Data.ColonLoc = Loc; }
4804+
4805+
/// Set the 'omp_all_memory' location.
4806+
void setOmpAllMemoryLoc(SourceLocation Loc) { Data.OmpAllMemoryLoc = Loc; }
47944807

47954808
/// Sets optional dependency modifier.
47964809
void setModifier(Expr *DepModifier);
@@ -4802,18 +4815,15 @@ class OMPDependClause final
48024815
/// \param StartLoc Starting location of the clause.
48034816
/// \param LParenLoc Location of '('.
48044817
/// \param EndLoc Ending location of the clause.
4805-
/// \param DepKind Dependency type.
4806-
/// \param DepLoc Location of the dependency type.
4807-
/// \param ColonLoc Colon location.
4818+
/// \param Data Dependency type and source locations.
48084819
/// \param VL List of references to the variables.
48094820
/// \param NumLoops Number of loops that is associated with this depend
48104821
/// clause.
48114822
static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
48124823
SourceLocation LParenLoc,
4813-
SourceLocation EndLoc, Expr *DepModifier,
4814-
OpenMPDependClauseKind DepKind,
4815-
SourceLocation DepLoc, SourceLocation ColonLoc,
4816-
ArrayRef<Expr *> VL, unsigned NumLoops);
4824+
SourceLocation EndLoc, DependDataTy Data,
4825+
Expr *DepModifier, ArrayRef<Expr *> VL,
4826+
unsigned NumLoops);
48174827

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

48274837
/// Get dependency type.
4828-
OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
4838+
OpenMPDependClauseKind getDependencyKind() const { return Data.DepKind; }
4839+
4840+
/// Get dependency type location.
4841+
SourceLocation getDependencyLoc() const { return Data.DepLoc; }
4842+
4843+
/// Get colon location.
4844+
SourceLocation getColonLoc() const { return Data.ColonLoc; }
4845+
4846+
/// Get 'omp_all_memory' location.
4847+
SourceLocation getOmpAllMemoryLoc() const { return Data.OmpAllMemoryLoc; }
48294848

48304849
/// Return optional depend modifier.
48314850
Expr *getModifier();
48324851
const Expr *getModifier() const {
48334852
return const_cast<OMPDependClause *>(this)->getModifier();
48344853
}
48354854

4836-
/// Get dependency type location.
4837-
SourceLocation getDependencyLoc() const { return DepLoc; }
4838-
4839-
/// Get colon location.
4840-
SourceLocation getColonLoc() const { return ColonLoc; }
4841-
48424855
/// Get number of loops associated with the clause.
48434856
unsigned getNumLoops() const { return NumLoops; }
48444857

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,12 @@ def warn_omp51_compat_attributes : Warning<
14641464
def err_omp_expected_colon : Error<"missing ':' in %0">;
14651465
def err_omp_expected_context_selector
14661466
: Error<"expected valid context selector in %0">;
1467+
def err_omp_requires_out_inout_depend_type : Error<
1468+
"reserved locator 'omp_all_memory' requires 'out' or 'inout' "
1469+
"dependency types">;
1470+
def warn_omp_more_one_omp_all_memory : Warning<
1471+
"reserved locator 'omp_all_memory' cannot be specified more than once">,
1472+
InGroup<OpenMPClauses>;
14671473

14681474
// Pragma loop support.
14691475
def err_pragma_loop_missing_argument : Error<

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ OPENMP_DEPEND_KIND(depobj)
106106
OPENMP_DEPEND_KIND(source)
107107
OPENMP_DEPEND_KIND(sink)
108108
OPENMP_DEPEND_KIND(inoutset)
109+
OPENMP_DEPEND_KIND(outallmemory)
110+
OPENMP_DEPEND_KIND(inoutallmemory)
109111

110112
// Modifiers for 'linear' clause.
111113
OPENMP_LINEAR_KIND(val)

clang/include/clang/Parse/Parser.h

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,42 +3332,26 @@ class Parser : public CodeCompletionHandler {
33323332
ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc,
33333333
bool IsAddressOfOperand = false);
33343334

3335-
/// Data used for parsing list of variables in OpenMP clauses.
3336-
struct OpenMPVarListDataTy {
3337-
Expr *DepModOrTailExpr = nullptr;
3338-
SourceLocation ColonLoc;
3339-
SourceLocation RLoc;
3340-
CXXScopeSpec ReductionOrMapperIdScopeSpec;
3341-
DeclarationNameInfo ReductionOrMapperId;
3342-
int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or
3343-
///< lastprivate clause.
3344-
SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
3345-
MapTypeModifiers;
3346-
SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers>
3347-
MapTypeModifiersLoc;
3348-
SmallVector<OpenMPMotionModifierKind, NumberOfOMPMotionModifiers>
3349-
MotionModifiers;
3350-
SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc;
3351-
bool IsMapTypeImplicit = false;
3352-
SourceLocation ExtraModifierLoc;
3353-
};
3354-
3335+
/// Parses a reserved locator like 'omp_all_memory'.
3336+
bool ParseOpenMPReservedLocator(OpenMPClauseKind Kind,
3337+
Sema::OpenMPVarListDataTy &Data,
3338+
const LangOptions &LangOpts);
33553339
/// Parses clauses with list.
33563340
bool ParseOpenMPVarList(OpenMPDirectiveKind DKind, OpenMPClauseKind Kind,
33573341
SmallVectorImpl<Expr *> &Vars,
3358-
OpenMPVarListDataTy &Data);
3342+
Sema::OpenMPVarListDataTy &Data);
33593343
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType,
33603344
bool ObjectHadErrors, bool EnteringContext,
33613345
bool AllowDestructorName, bool AllowConstructorName,
33623346
bool AllowDeductionGuide,
33633347
SourceLocation *TemplateKWLoc, UnqualifiedId &Result);
33643348

33653349
/// Parses the mapper modifier in map, to, and from clauses.
3366-
bool parseMapperModifier(OpenMPVarListDataTy &Data);
3350+
bool parseMapperModifier(Sema::OpenMPVarListDataTy &Data);
33673351
/// Parses map-type-modifiers in map clause.
33683352
/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list)
33693353
/// where, map-type-modifier ::= always | close | mapper(mapper-identifier)
3370-
bool parseMapTypeModifiers(OpenMPVarListDataTy &Data);
3354+
bool parseMapTypeModifiers(Sema::OpenMPVarListDataTy &Data);
33713355

33723356
private:
33733357
//===--------------------------------------------------------------------===//

clang/include/clang/Sema/Sema.h

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11435,16 +11435,31 @@ class Sema final {
1143511435
OpenMPAtomicDefaultMemOrderClauseKind Kind, SourceLocation KindLoc,
1143611436
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc);
1143711437

11438-
OMPClause *ActOnOpenMPVarListClause(
11439-
OpenMPClauseKind Kind, ArrayRef<Expr *> Vars, Expr *DepModOrTailExpr,
11440-
const OMPVarListLocTy &Locs, SourceLocation ColonLoc,
11441-
CXXScopeSpec &ReductionOrMapperIdScopeSpec,
11442-
DeclarationNameInfo &ReductionOrMapperId, int ExtraModifier,
11443-
ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
11444-
ArrayRef<SourceLocation> MapTypeModifiersLoc, bool IsMapTypeImplicit,
11445-
SourceLocation ExtraModifierLoc,
11446-
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
11447-
ArrayRef<SourceLocation> MotionModifiersLoc);
11438+
/// Data used for processing a list of variables in OpenMP clauses.
11439+
struct OpenMPVarListDataTy final {
11440+
Expr *DepModOrTailExpr = nullptr;
11441+
SourceLocation ColonLoc;
11442+
SourceLocation RLoc;
11443+
CXXScopeSpec ReductionOrMapperIdScopeSpec;
11444+
DeclarationNameInfo ReductionOrMapperId;
11445+
int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or
11446+
///< lastprivate clause.
11447+
SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
11448+
MapTypeModifiers;
11449+
SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers>
11450+
MapTypeModifiersLoc;
11451+
SmallVector<OpenMPMotionModifierKind, NumberOfOMPMotionModifiers>
11452+
MotionModifiers;
11453+
SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc;
11454+
bool IsMapTypeImplicit = false;
11455+
SourceLocation ExtraModifierLoc;
11456+
SourceLocation OmpAllMemoryLoc;
11457+
};
11458+
11459+
OMPClause *ActOnOpenMPVarListClause(OpenMPClauseKind Kind,
11460+
ArrayRef<Expr *> Vars,
11461+
const OMPVarListLocTy &Locs,
11462+
OpenMPVarListDataTy &Data);
1144811463
/// Called on well-formed 'inclusive' clause.
1144911464
OMPClause *ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList,
1145011465
SourceLocation StartLoc,
@@ -11535,11 +11550,12 @@ class Sema final {
1153511550
SourceLocation LParenLoc,
1153611551
SourceLocation EndLoc);
1153711552
/// Called on well-formed 'depend' clause.
11538-
OMPClause *
11539-
ActOnOpenMPDependClause(Expr *DepModifier, OpenMPDependClauseKind DepKind,
11540-
SourceLocation DepLoc, SourceLocation ColonLoc,
11541-
ArrayRef<Expr *> VarList, SourceLocation StartLoc,
11542-
SourceLocation LParenLoc, SourceLocation EndLoc);
11553+
OMPClause *ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data,
11554+
Expr *DepModifier,
11555+
ArrayRef<Expr *> VarList,
11556+
SourceLocation StartLoc,
11557+
SourceLocation LParenLoc,
11558+
SourceLocation EndLoc);
1154311559
/// Called on well-formed 'device' clause.
1154411560
OMPClause *ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier,
1154511561
Expr *Device, SourceLocation StartLoc,

clang/lib/AST/OpenMPClause.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,19 +1040,19 @@ OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) {
10401040
OMPDependClause *
10411041
OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
10421042
SourceLocation LParenLoc, SourceLocation EndLoc,
1043-
Expr *DepModifier, OpenMPDependClauseKind DepKind,
1044-
SourceLocation DepLoc, SourceLocation ColonLoc,
1043+
DependDataTy Data, Expr *DepModifier,
10451044
ArrayRef<Expr *> VL, unsigned NumLoops) {
10461045
void *Mem = C.Allocate(
10471046
totalSizeToAlloc<Expr *>(VL.size() + /*depend-modifier*/ 1 + NumLoops),
10481047
alignof(OMPDependClause));
10491048
OMPDependClause *Clause = new (Mem)
10501049
OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
1051-
Clause->setVarRefs(VL);
1052-
Clause->setDependencyKind(DepKind);
1053-
Clause->setDependencyLoc(DepLoc);
1054-
Clause->setColonLoc(ColonLoc);
1050+
Clause->setDependencyKind(Data.DepKind);
1051+
Clause->setDependencyLoc(Data.DepLoc);
1052+
Clause->setColonLoc(Data.ColonLoc);
1053+
Clause->setOmpAllMemoryLoc(Data.OmpAllMemoryLoc);
10551054
Clause->setModifier(DepModifier);
1055+
Clause->setVarRefs(VL);
10561056
for (unsigned I = 0 ; I < NumLoops; ++I)
10571057
Clause->setLoopData(I, nullptr);
10581058
return Clause;
@@ -2183,11 +2183,23 @@ void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
21832183
DepModifier->printPretty(OS, nullptr, Policy);
21842184
OS << ", ";
21852185
}
2186-
OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
2187-
Node->getDependencyKind());
2188-
if (!Node->varlist_empty()) {
2186+
OpenMPDependClauseKind DepKind = Node->getDependencyKind();
2187+
OpenMPDependClauseKind PrintKind = DepKind;
2188+
bool IsOmpAllMemory = false;
2189+
if (PrintKind == OMPC_DEPEND_outallmemory) {
2190+
PrintKind = OMPC_DEPEND_out;
2191+
IsOmpAllMemory = true;
2192+
} else if (PrintKind == OMPC_DEPEND_inoutallmemory) {
2193+
PrintKind = OMPC_DEPEND_inout;
2194+
IsOmpAllMemory = true;
2195+
}
2196+
OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), PrintKind);
2197+
if (!Node->varlist_empty() || IsOmpAllMemory)
21892198
OS << " :";
2190-
VisitOMPClauseList(Node, ' ');
2199+
VisitOMPClauseList(Node, ' ');
2200+
if (IsOmpAllMemory) {
2201+
OS << (Node->varlist_empty() ? " " : ",");
2202+
OS << "omp_all_memory";
21912203
}
21922204
OS << ")";
21932205
}

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4534,6 +4534,8 @@ static RTLDependenceKindTy translateDependencyKind(OpenMPDependClauseKind K) {
45344534
case OMPC_DEPEND_source:
45354535
case OMPC_DEPEND_sink:
45364536
case OMPC_DEPEND_depobj:
4537+
case OMPC_DEPEND_outallmemory:
4538+
case OMPC_DEPEND_inoutallmemory:
45374539
case OMPC_DEPEND_unknown:
45384540
llvm_unreachable("Unknown task dependence type");
45394541
}

0 commit comments

Comments
 (0)