Skip to content

Commit 7bec4d1

Browse files
author
Shashwathi N
committed
Adding support for iterator in motion clauses
1 parent 03c356c commit 7bec4d1

File tree

11 files changed

+130
-42
lines changed

11 files changed

+130
-42
lines changed

clang/docs/OpenMPSupport.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ implementation.
266266
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
267267
| device | has_device_addr clause on target construct | :none:`unclaimed` | |
268268
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
269-
| device | iterators in map clause or motion clauses | :none:`unclaimed` | |
269+
| device | iterators in map clause or motion clauses | :good:`done` | |
270270
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
271271
| device | indirect clause on declare target directive | :part:`In Progress` | |
272272
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+

clang/include/clang/AST/OpenMPClause.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7476,7 +7476,7 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
74767476

74777477
/// Motion-modifiers for the 'to' clause.
74787478
OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
7479-
OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown};
7479+
OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown};
74807480

74817481
/// Location of motion-modifiers for the 'to' clause.
74827482
SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
@@ -7548,6 +7548,9 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
75487548
MotionModifiersLoc[I] = TLoc;
75497549
}
75507550

7551+
void setIteratorModifier(Expr *IteratorModifier) {
7552+
getTrailingObjects<Expr *>()[2 * varlist_size()] = IteratorModifier;
7553+
}
75517554
/// Set colon location.
75527555
void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
75537556

@@ -7556,7 +7559,7 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
75567559
size_t numTrailingObjects(OverloadToken<Expr *>) const {
75577560
// There are varlist_size() of expressions, and varlist_size() of
75587561
// user-defined mappers.
7559-
return 2 * varlist_size();
7562+
return 2 * varlist_size() + 1;
75607563
}
75617564
size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
75627565
return getUniqueDeclarationsNum();
@@ -7586,7 +7589,7 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
75867589
ArrayRef<Expr *> Vars,
75877590
ArrayRef<ValueDecl *> Declarations,
75887591
MappableExprComponentListsRef ComponentLists,
7589-
ArrayRef<Expr *> UDMapperRefs,
7592+
ArrayRef<Expr *> UDMapperRefs,Expr *IteratorModifier,
75907593
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
75917594
ArrayRef<SourceLocation> MotionModifiersLoc,
75927595
NestedNameSpecifierLoc UDMQualifierLoc,
@@ -7611,7 +7614,9 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
76117614
"Requested modifier exceeds the total number of modifiers.");
76127615
return MotionModifiers[Cnt];
76137616
}
7614-
7617+
Expr *getIteratorModifier() {
7618+
return getTrailingObjects<Expr *>()[2 * varlist_size()];
7619+
}
76157620
/// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
76167621
/// locations.
76177622
///
@@ -7677,7 +7682,7 @@ class OMPFromClause final
76777682

76787683
/// Motion-modifiers for the 'from' clause.
76797684
OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
7680-
OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown};
7685+
OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown};
76817686

76827687
/// Location of motion-modifiers for the 'from' clause.
76837688
SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
@@ -7738,7 +7743,9 @@ class OMPFromClause final
77387743
"Unexpected index to store motion modifier, exceeds array size.");
77397744
MotionModifiers[I] = T;
77407745
}
7741-
7746+
void setIteratorModifier(Expr *IteratorModifier) {
7747+
getTrailingObjects<Expr *>()[2 * varlist_size()] = IteratorModifier;
7748+
}
77427749
/// Set location for the motion-modifier.
77437750
///
77447751
/// \param I index for motion-modifier location.
@@ -7757,7 +7764,7 @@ class OMPFromClause final
77577764
size_t numTrailingObjects(OverloadToken<Expr *>) const {
77587765
// There are varlist_size() of expressions, and varlist_size() of
77597766
// user-defined mappers.
7760-
return 2 * varlist_size();
7767+
return 2 * varlist_size() + 1;
77617768
}
77627769
size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
77637770
return getUniqueDeclarationsNum();
@@ -7787,7 +7794,7 @@ class OMPFromClause final
77877794
Create(const ASTContext &C, const OMPVarListLocTy &Locs,
77887795
ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
77897796
MappableExprComponentListsRef ComponentLists,
7790-
ArrayRef<Expr *> UDMapperRefs,
7797+
ArrayRef<Expr *> UDMapperRefs, Expr *IteratorExpr,
77917798
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
77927799
ArrayRef<SourceLocation> MotionModifiersLoc,
77937800
NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId);
@@ -7811,7 +7818,9 @@ class OMPFromClause final
78117818
"Requested modifier exceeds the total number of modifiers.");
78127819
return MotionModifiers[Cnt];
78137820
}
7814-
7821+
Expr *getIteratorModifier() {
7822+
return getTrailingObjects<Expr *>()[2 * varlist_size()];
7823+
}
78157824
/// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
78167825
/// locations.
78177826
///

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ OPENMP_MAP_MODIFIER_KIND(ompx_hold)
194194

195195
// Modifiers for 'to' or 'from' clause.
196196
OPENMP_MOTION_MODIFIER_KIND(mapper)
197+
OPENMP_MOTION_MODIFIER_KIND(iterator)
197198
OPENMP_MOTION_MODIFIER_KIND(present)
198199

199200
// Static attributes for 'dist_schedule' clause.

clang/include/clang/Sema/SemaOpenMP.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,15 +1323,15 @@ class SemaOpenMP : public SemaBase {
13231323
OMPClause *
13241324
ActOnOpenMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
13251325
ArrayRef<SourceLocation> MotionModifiersLoc,
1326-
CXXScopeSpec &MapperIdScopeSpec,
1326+
Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec,
13271327
DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
13281328
ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
13291329
ArrayRef<Expr *> UnresolvedMappers = {});
13301330
/// Called on well-formed 'from' clause.
13311331
OMPClause *
13321332
ActOnOpenMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
13331333
ArrayRef<SourceLocation> MotionModifiersLoc,
1334-
CXXScopeSpec &MapperIdScopeSpec,
1334+
Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec,
13351335
DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
13361336
ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
13371337
ArrayRef<Expr *> UnresolvedMappers = {});

clang/lib/AST/OpenMPClause.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ OMPToClause *OMPToClause::Create(
12181218
const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
12191219
ArrayRef<ValueDecl *> Declarations,
12201220
MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1221-
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
1221+
Expr *IteratorModifier, ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
12221222
ArrayRef<SourceLocation> MotionModifiersLoc,
12231223
NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
12241224
OMPMappableExprListSizeTy Sizes;
@@ -1240,7 +1240,7 @@ OMPToClause *OMPToClause::Create(
12401240
void *Mem = C.Allocate(
12411241
totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
12421242
OMPClauseMappableExprCommon::MappableComponent>(
1243-
2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1243+
2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations,
12441244
Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
12451245
Sizes.NumComponents));
12461246

@@ -1250,6 +1250,7 @@ OMPToClause *OMPToClause::Create(
12501250
Clause->setVarRefs(Vars);
12511251
Clause->setUDMapperRefs(UDMapperRefs);
12521252
Clause->setClauseInfo(Declarations, ComponentLists);
1253+
Clause->setIteratorModifier(IteratorModifier);
12531254
return Clause;
12541255
}
12551256

@@ -1258,17 +1259,19 @@ OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
12581259
void *Mem = C.Allocate(
12591260
totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
12601261
OMPClauseMappableExprCommon::MappableComponent>(
1261-
2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1262+
2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations,
12621263
Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
12631264
Sizes.NumComponents));
1264-
return new (Mem) OMPToClause(Sizes);
1265+
OMPToClause *Clause = new (Mem) OMPToClause(Sizes);
1266+
Clause->setIteratorModifier(nullptr);
1267+
return Clause;
12651268
}
12661269

12671270
OMPFromClause *OMPFromClause::Create(
12681271
const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
12691272
ArrayRef<ValueDecl *> Declarations,
12701273
MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1271-
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
1274+
Expr *IteratorModifier, ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
12721275
ArrayRef<SourceLocation> MotionModifiersLoc,
12731276
NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
12741277
OMPMappableExprListSizeTy Sizes;
@@ -1290,7 +1293,7 @@ OMPFromClause *OMPFromClause::Create(
12901293
void *Mem = C.Allocate(
12911294
totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
12921295
OMPClauseMappableExprCommon::MappableComponent>(
1293-
2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1296+
2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations,
12941297
Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
12951298
Sizes.NumComponents));
12961299

@@ -1301,6 +1304,7 @@ OMPFromClause *OMPFromClause::Create(
13011304
Clause->setVarRefs(Vars);
13021305
Clause->setUDMapperRefs(UDMapperRefs);
13031306
Clause->setClauseInfo(Declarations, ComponentLists);
1307+
Clause->setIteratorModifier(IteratorModifier);
13041308
return Clause;
13051309
}
13061310

@@ -1310,10 +1314,12 @@ OMPFromClause::CreateEmpty(const ASTContext &C,
13101314
void *Mem = C.Allocate(
13111315
totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
13121316
OMPClauseMappableExprCommon::MappableComponent>(
1313-
2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1317+
2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations,
13141318
Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
13151319
Sizes.NumComponents));
1316-
return new (Mem) OMPFromClause(Sizes);
1320+
OMPFromClause *Clause = new (Mem) OMPFromClause(Sizes);
1321+
Clause->setIteratorModifier(nullptr);
1322+
return Clause;
13171323
}
13181324

13191325
void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
@@ -2564,12 +2570,16 @@ template <typename T> void OMPClausePrinter::VisitOMPMotionClause(T *Node) {
25642570
OS << '(';
25652571
for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) {
25662572
if (Node->getMotionModifier(I) != OMPC_MOTION_MODIFIER_unknown) {
2573+
if (Node->getMotionModifier(I) == OMPC_MOTION_MODIFIER_iterator)
2574+
PrintIterator(OS, Node, Policy);
2575+
else {
25672576
OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
25682577
Node->getMotionModifier(I));
25692578
if (Node->getMotionModifier(I) == OMPC_MOTION_MODIFIER_mapper)
25702579
PrintMapper(OS, Node, Policy);
25712580
if (I < ModifierCount - 1)
25722581
OS << ", ";
2582+
}
25732583
}
25742584
}
25752585
OS << ':';

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4699,6 +4699,19 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
46994699
break;
47004700
Data.MotionModifiers.push_back(Modifier);
47014701
Data.MotionModifiersLoc.push_back(Tok.getLocation());
4702+
if (PP.getSpelling(Tok) == "iterator" && getLangOpts().OpenMP >= 51) {
4703+
ColonProtectionRAIIObject ColonRAII(*this);
4704+
TentativeParsingAction TPA(*this);
4705+
ExprResult Tail;
4706+
HasIterator = true;
4707+
EnterScope(Scope::OpenMPDirectiveScope | Scope::DeclScope);
4708+
Tail = ParseOpenMPIteratorsExpr();
4709+
Tail = Actions.ActOnFinishFullExpr(Tail.get(), T.getOpenLocation(),
4710+
/*DiscardedValue=*/false);
4711+
if (Tail.isUsable()) {
4712+
Data.IteratorExpr = Tail.get();
4713+
}
4714+
} else {
47024715
ConsumeToken();
47034716
if (Modifier == OMPC_MOTION_MODIFIER_mapper) {
47044717
IsInvalidMapperModifier = parseMapperModifier(Data);
@@ -4712,6 +4725,7 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
47124725
// TODO: Is that intentional?
47134726
if (Tok.is(tok::comma))
47144727
ConsumeToken();
4728+
}
47154729
}
47164730
if (!Data.MotionModifiers.empty() && Tok.isNot(tok::colon)) {
47174731
if (!IsInvalidMapperModifier) {

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17723,16 +17723,16 @@ OMPClause *SemaOpenMP::ActOnOpenMPVarListClause(OpenMPClauseKind Kind,
1772317723
ExtraModifierLoc, ColonLoc, VarList, Locs);
1772417724
break;
1772517725
case OMPC_to:
17726-
Res =
17727-
ActOnOpenMPToClause(Data.MotionModifiers, Data.MotionModifiersLoc,
17728-
Data.ReductionOrMapperIdScopeSpec,
17729-
Data.ReductionOrMapperId, ColonLoc, VarList, Locs);
17726+
Res = ActOnOpenMPToClause(
17727+
Data.MotionModifiers, Data.MotionModifiersLoc, Data.IteratorExpr,
17728+
Data.ReductionOrMapperIdScopeSpec, Data.ReductionOrMapperId, ColonLoc,
17729+
VarList, Locs);
1773017730
break;
1773117731
case OMPC_from:
17732-
Res = ActOnOpenMPFromClause(Data.MotionModifiers, Data.MotionModifiersLoc,
17733-
Data.ReductionOrMapperIdScopeSpec,
17734-
Data.ReductionOrMapperId, ColonLoc, VarList,
17735-
Locs);
17732+
Res = ActOnOpenMPFromClause(
17733+
Data.MotionModifiers, Data.MotionModifiersLoc, Data.IteratorExpr,
17734+
Data.ReductionOrMapperIdScopeSpec, Data.ReductionOrMapperId, ColonLoc,
17735+
VarList, Locs);
1773617736
break;
1773717737
case OMPC_use_device_ptr:
1773817738
Res = ActOnOpenMPUseDevicePtrClause(VarList, Locs);
@@ -23465,10 +23465,12 @@ void SemaOpenMP::ActOnOpenMPDeclareTargetInitializer(Decl *TargetDecl) {
2346523465
OMPClause *SemaOpenMP::ActOnOpenMPToClause(
2346623466
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
2346723467
ArrayRef<SourceLocation> MotionModifiersLoc,
23468+
Expr *IteratorExpr,
2346823469
CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId,
2346923470
SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2347023471
const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2347123472
OpenMPMotionModifierKind Modifiers[] = {OMPC_MOTION_MODIFIER_unknown,
23473+
OMPC_MOTION_MODIFIER_unknown,
2347223474
OMPC_MOTION_MODIFIER_unknown};
2347323475
SourceLocation ModifiersLoc[NumberOfOMPMotionModifiers];
2347423476

@@ -23492,20 +23494,24 @@ OMPClause *SemaOpenMP::ActOnOpenMPToClause(
2349223494
MapperIdScopeSpec, MapperId, UnresolvedMappers);
2349323495
if (MVLI.ProcessedVarList.empty())
2349423496
return nullptr;
23495-
23497+
if(IteratorExpr)
23498+
if (auto *DRE = dyn_cast<DeclRefExpr>(IteratorExpr))
23499+
if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
23500+
DSAStack->addIteratorVarDecl(VD);
2349623501
return OMPToClause::Create(
2349723502
getASTContext(), Locs, MVLI.ProcessedVarList, MVLI.VarBaseDeclarations,
23498-
MVLI.VarComponents, MVLI.UDMapperList, Modifiers, ModifiersLoc,
23503+
MVLI.VarComponents, MVLI.UDMapperList,IteratorExpr, Modifiers, ModifiersLoc,
2349923504
MapperIdScopeSpec.getWithLocInContext(getASTContext()), MapperId);
2350023505
}
2350123506

2350223507
OMPClause *SemaOpenMP::ActOnOpenMPFromClause(
2350323508
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
23504-
ArrayRef<SourceLocation> MotionModifiersLoc,
23509+
ArrayRef<SourceLocation> MotionModifiersLoc, Expr *IteratorExpr,
2350523510
CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId,
2350623511
SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2350723512
const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2350823513
OpenMPMotionModifierKind Modifiers[] = {OMPC_MOTION_MODIFIER_unknown,
23514+
OMPC_MOTION_MODIFIER_unknown,
2350923515
OMPC_MOTION_MODIFIER_unknown};
2351023516
SourceLocation ModifiersLoc[NumberOfOMPMotionModifiers];
2351123517

@@ -23529,11 +23535,15 @@ OMPClause *SemaOpenMP::ActOnOpenMPFromClause(
2352923535
MapperIdScopeSpec, MapperId, UnresolvedMappers);
2353023536
if (MVLI.ProcessedVarList.empty())
2353123537
return nullptr;
23532-
23538+
if (IteratorExpr)
23539+
if (auto *DRE = dyn_cast<DeclRefExpr>(IteratorExpr))
23540+
if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
23541+
DSAStack->addIteratorVarDecl(VD);
2353323542
return OMPFromClause::Create(
2353423543
getASTContext(), Locs, MVLI.ProcessedVarList, MVLI.VarBaseDeclarations,
23535-
MVLI.VarComponents, MVLI.UDMapperList, Modifiers, ModifiersLoc,
23536-
MapperIdScopeSpec.getWithLocInContext(getASTContext()), MapperId);
23544+
MVLI.VarComponents, MVLI.UDMapperList, IteratorExpr, Modifiers,
23545+
ModifiersLoc, MapperIdScopeSpec.getWithLocInContext(getASTContext()),
23546+
MapperId);
2353723547
}
2353823548

2353923549
OMPClause *

0 commit comments

Comments
 (0)