Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7bec4d1
Adding support for iterator in motion clauses
Sep 16, 2025
64ff74c
Merge branch 'main' into target_update_iterator
ShashwathiNavada Sep 16, 2025
d7aa585
Formatting
Sep 16, 2025
52a2504
Merge commit
Sep 16, 2025
41159a3
Merge branch 'main' into target_update_iterator
ShashwathiNavada Sep 17, 2025
98eebb6
Update ParseOpenMP.cpp
ShashwathiNavada Sep 17, 2025
2ce56c2
Fixed the error
Sep 17, 2025
f32b8c8
modifications done
Oct 7, 2025
b0cc40d
updated
Oct 7, 2025
de3f3ef
Merge branch 'llvm:main' into target_update_iterator
ShashwathiNavada Oct 8, 2025
00426db
Codegen implementation
Nov 12, 2025
36cf3bf
Merge branch 'main' into target_update_iterator
ShashwathiNavada Nov 12, 2025
b7cfefc
Merge branch 'main' into target_update_iterator
ShashwathiNavada Nov 12, 2025
37ab249
Format
Nov 14, 2025
3c01455
Minor change
Nov 14, 2025
75078b3
Added suggested changes
Nov 20, 2025
823fe2a
Update OpenMPSupport.rst
ShashwathiNavada Nov 20, 2025
67b2d49
Update OpenMPSupport.rst
ShashwathiNavada Nov 20, 2025
cb9caa2
Simple change
Nov 20, 2025
ea1f8ca
Formatting changes
Nov 20, 2025
0d40925
Merge branch 'main' into target_update_iterator
ShashwathiNavada Nov 20, 2025
a71c558
Merge branch 'main' into target_update_iterator
ShashwathiNavada Nov 24, 2025
94bf5df
Merge branch 'llvm:main' into target_update_iterator
ShashwathiNavada Nov 24, 2025
dfd4859
Changes
Nov 24, 2025
d62cf40
Changes
Nov 24, 2025
5b34ad2
Merge branch 'llvm:main' into target_update_iterator
ShashwathiNavada Nov 25, 2025
997b82a
update
Nov 25, 2025
7d10156
update
Nov 25, 2025
93dced1
update
Nov 25, 2025
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
2 changes: 1 addition & 1 deletion clang/docs/OpenMPSupport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ implementation.
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| device | has_device_addr clause on target construct | :none:`unclaimed` | |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| device | iterators in map clause or motion clauses | :none:`unclaimed` | |
| device | iterators in map clause or motion clauses | :none:`done` | https://github.com/llvm/llvm-project/pull/159112 |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| device | indirect clause on declare target directive | :part:`In Progress` | |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
Expand Down
44 changes: 27 additions & 17 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -7582,7 +7582,8 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,

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

/// Location of motion-modifiers for the 'to' clause.
SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
Expand Down Expand Up @@ -7654,6 +7655,9 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
MotionModifiersLoc[I] = TLoc;
}

void setIteratorModifier(Expr *IteratorModifier) {
getTrailingObjects<Expr *>()[2 * varlist_size()] = IteratorModifier;
}
/// Set colon location.
void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }

Expand All @@ -7662,7 +7666,7 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
size_t numTrailingObjects(OverloadToken<Expr *>) const {
// There are varlist_size() of expressions, and varlist_size() of
// user-defined mappers.
return 2 * varlist_size();
return 2 * varlist_size() + 1;
}
size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
return getUniqueDeclarationsNum();
Expand All @@ -7688,15 +7692,14 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
/// \param UDMQualifierLoc C++ nested name specifier for the associated
/// user-defined mapper.
/// \param MapperId The identifier of associated user-defined mapper.
static OMPToClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs,
ArrayRef<Expr *> Vars,
ArrayRef<ValueDecl *> Declarations,
MappableExprComponentListsRef ComponentLists,
ArrayRef<Expr *> UDMapperRefs,
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
ArrayRef<SourceLocation> MotionModifiersLoc,
NestedNameSpecifierLoc UDMQualifierLoc,
DeclarationNameInfo MapperId);
static OMPToClause *
Create(const ASTContext &C, const OMPVarListLocTy &Locs,
ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
MappableExprComponentListsRef ComponentLists,
ArrayRef<Expr *> UDMapperRefs, Expr *IteratorModifier,
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
ArrayRef<SourceLocation> MotionModifiersLoc,
NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId);

/// Creates an empty clause with the place for \a NumVars variables.
///
Expand All @@ -7717,7 +7720,9 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
"Requested modifier exceeds the total number of modifiers.");
return MotionModifiers[Cnt];
}

Expr *getIteratorModifier() const {
return getTrailingObjects<Expr *>()[2 * varlist_size()];
}
/// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
/// locations.
///
Expand Down Expand Up @@ -7782,7 +7787,8 @@ class OMPFromClause final

/// Motion-modifiers for the 'from' clause.
OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown};
OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown,
OMPC_MOTION_MODIFIER_unknown};

/// Location of motion-modifiers for the 'from' clause.
SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
Expand Down Expand Up @@ -7843,7 +7849,9 @@ class OMPFromClause final
"Unexpected index to store motion modifier, exceeds array size.");
MotionModifiers[I] = T;
}

void setIteratorModifier(Expr *IteratorModifier) {
getTrailingObjects<Expr *>()[2 * varlist_size()] = IteratorModifier;
}
/// Set location for the motion-modifier.
///
/// \param I index for motion-modifier location.
Expand All @@ -7862,7 +7870,7 @@ class OMPFromClause final
size_t numTrailingObjects(OverloadToken<Expr *>) const {
// There are varlist_size() of expressions, and varlist_size() of
// user-defined mappers.
return 2 * varlist_size();
return 2 * varlist_size() + 1;
}
size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
return getUniqueDeclarationsNum();
Expand Down Expand Up @@ -7892,7 +7900,7 @@ class OMPFromClause final
Create(const ASTContext &C, const OMPVarListLocTy &Locs,
ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
MappableExprComponentListsRef ComponentLists,
ArrayRef<Expr *> UDMapperRefs,
ArrayRef<Expr *> UDMapperRefs, Expr *IteratorExpr,
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
ArrayRef<SourceLocation> MotionModifiersLoc,
NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId);
Expand All @@ -7916,7 +7924,9 @@ class OMPFromClause final
"Requested modifier exceeds the total number of modifiers.");
return MotionModifiers[Cnt];
}

Expr *getIteratorModifier() const {
return getTrailingObjects<Expr *>()[2 * varlist_size()];
}
/// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
/// locations.
///
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/OpenMPKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ OPENMP_MAP_MODIFIER_KIND(ompx_hold)

// Modifiers for 'to' or 'from' clause.
OPENMP_MOTION_MODIFIER_KIND(mapper)
OPENMP_MOTION_MODIFIER_KIND(iterator)
OPENMP_MOTION_MODIFIER_KIND(present)

// Static attributes for 'dist_schedule' clause.
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Sema/SemaOpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -1349,15 +1349,15 @@ class SemaOpenMP : public SemaBase {
OMPClause *
ActOnOpenMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
ArrayRef<SourceLocation> MotionModifiersLoc,
CXXScopeSpec &MapperIdScopeSpec,
Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec,
DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
ArrayRef<Expr *> UnresolvedMappers = {});
/// Called on well-formed 'from' clause.
OMPClause *
ActOnOpenMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
ArrayRef<SourceLocation> MotionModifiersLoc,
CXXScopeSpec &MapperIdScopeSpec,
Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec,
DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
ArrayRef<Expr *> UnresolvedMappers = {});
Expand Down
38 changes: 24 additions & 14 deletions clang/lib/AST/OpenMPClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ OMPToClause *OMPToClause::Create(
const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
ArrayRef<ValueDecl *> Declarations,
MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
Expr *IteratorModifier, ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
ArrayRef<SourceLocation> MotionModifiersLoc,
NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
OMPMappableExprListSizeTy Sizes;
Expand All @@ -1343,7 +1343,7 @@ OMPToClause *OMPToClause::Create(
void *Mem = C.Allocate(
totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
OMPClauseMappableExprCommon::MappableComponent>(
2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations,
Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
Sizes.NumComponents));

Expand All @@ -1353,6 +1353,7 @@ OMPToClause *OMPToClause::Create(
Clause->setVarRefs(Vars);
Clause->setUDMapperRefs(UDMapperRefs);
Clause->setClauseInfo(Declarations, ComponentLists);
Clause->setIteratorModifier(IteratorModifier);
return Clause;
}

Expand All @@ -1361,17 +1362,19 @@ OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
void *Mem = C.Allocate(
totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
OMPClauseMappableExprCommon::MappableComponent>(
2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations,
Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
Sizes.NumComponents));
return new (Mem) OMPToClause(Sizes);
OMPToClause *Clause = new (Mem) OMPToClause(Sizes);
Clause->setIteratorModifier(nullptr);
return Clause;
}

OMPFromClause *OMPFromClause::Create(
const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
ArrayRef<ValueDecl *> Declarations,
MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
Expr *IteratorModifier, ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
ArrayRef<SourceLocation> MotionModifiersLoc,
NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
OMPMappableExprListSizeTy Sizes;
Expand All @@ -1393,7 +1396,7 @@ OMPFromClause *OMPFromClause::Create(
void *Mem = C.Allocate(
totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
OMPClauseMappableExprCommon::MappableComponent>(
2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations,
Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
Sizes.NumComponents));

Expand All @@ -1404,6 +1407,7 @@ OMPFromClause *OMPFromClause::Create(
Clause->setVarRefs(Vars);
Clause->setUDMapperRefs(UDMapperRefs);
Clause->setClauseInfo(Declarations, ComponentLists);
Clause->setIteratorModifier(IteratorModifier);
return Clause;
}

Expand All @@ -1413,10 +1417,12 @@ OMPFromClause::CreateEmpty(const ASTContext &C,
void *Mem = C.Allocate(
totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
OMPClauseMappableExprCommon::MappableComponent>(
2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations,
Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
Sizes.NumComponents));
return new (Mem) OMPFromClause(Sizes);
OMPFromClause *Clause = new (Mem) OMPFromClause(Sizes);
Clause->setIteratorModifier(nullptr);
return Clause;
}

void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
Expand Down Expand Up @@ -2694,12 +2700,16 @@ template <typename T> void OMPClausePrinter::VisitOMPMotionClause(T *Node) {
OS << '(';
for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) {
if (Node->getMotionModifier(I) != OMPC_MOTION_MODIFIER_unknown) {
OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
Node->getMotionModifier(I));
if (Node->getMotionModifier(I) == OMPC_MOTION_MODIFIER_mapper)
PrintMapper(OS, Node, Policy);
if (I < ModifierCount - 1)
OS << ", ";
if (Node->getMotionModifier(I) == OMPC_MOTION_MODIFIER_iterator) {
PrintIterator(OS, Node, Policy);
} else {
OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
Node->getMotionModifier(I));
if (Node->getMotionModifier(I) == OMPC_MOTION_MODIFIER_mapper)
PrintMapper(OS, Node, Policy);
if (I < ModifierCount - 1)
OS << ", ";
}
}
}
OS << ':';
Expand Down
18 changes: 18 additions & 0 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8634,6 +8634,15 @@ class MappableExprsHandler {
if (llvm::is_contained(C->getMotionModifiers(),
OMPC_MOTION_MODIFIER_present))
Kind = Present;
if (llvm::is_contained(C->getMotionModifiers(),
OMPC_MOTION_MODIFIER_iterator)) {
if (auto *IteratorExpr = dyn_cast<OMPIteratorExpr>(
C->getIteratorModifier()->IgnoreParenImpCasts())) {
const auto *VD = cast<VarDecl>(IteratorExpr->getIteratorDecl(0));
CGF.EmitVarDecl(*VD);
}
}

const auto *EI = C->getVarRefs().begin();
for (const auto L : C->component_lists()) {
InfoGen(std::get<0>(L), Kind, std::get<1>(L), OMPC_MAP_to, {},
Expand All @@ -8650,6 +8659,15 @@ class MappableExprsHandler {
if (llvm::is_contained(C->getMotionModifiers(),
OMPC_MOTION_MODIFIER_present))
Kind = Present;
if (llvm::is_contained(C->getMotionModifiers(),
OMPC_MOTION_MODIFIER_iterator)) {
if (auto *IteratorExpr = dyn_cast<OMPIteratorExpr>(
C->getIteratorModifier()->IgnoreParenImpCasts())) {
const auto *VD = cast<VarDecl>(IteratorExpr->getIteratorDecl(0));
CGF.EmitVarDecl(*VD);
}
}

const auto *EI = C->getVarRefs().begin();
for (const auto L : C->component_lists()) {
InfoGen(std::get<0>(L), Kind, std::get<1>(L), OMPC_MAP_from, {},
Expand Down
31 changes: 20 additions & 11 deletions clang/lib/Parse/ParseOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4925,19 +4925,28 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
break;
Data.MotionModifiers.push_back(Modifier);
Data.MotionModifiersLoc.push_back(Tok.getLocation());
ConsumeToken();
if (Modifier == OMPC_MOTION_MODIFIER_mapper) {
IsInvalidMapperModifier = parseMapperModifier(Data);
if (IsInvalidMapperModifier)
if (PP.getSpelling(Tok) == "iterator" && getLangOpts().OpenMP >= 51) {
ExprResult Tail;
Tail = ParseOpenMPIteratorsExpr();
Tail = Actions.ActOnFinishFullExpr(Tail.get(), T.getOpenLocation(),
/*DiscardedValue=*/false);
if (Tail.isUsable())
Data.IteratorExpr = Tail.get();
} else {
ConsumeToken();
if (Modifier == OMPC_MOTION_MODIFIER_mapper) {
IsInvalidMapperModifier = parseMapperModifier(Data);
if (IsInvalidMapperModifier)
break;
}
// OpenMP < 5.1 doesn't permit a ',' or additional modifiers.
if (getLangOpts().OpenMP < 51)
break;
// OpenMP 5.1 accepts an optional ',' even if the next character is ':'.
// TODO: Is that intentional?
if (Tok.is(tok::comma))
ConsumeToken();
}
// OpenMP < 5.1 doesn't permit a ',' or additional modifiers.
if (getLangOpts().OpenMP < 51)
break;
// OpenMP 5.1 accepts an optional ',' even if the next character is ':'.
// TODO: Is that intentional?
if (Tok.is(tok::comma))
ConsumeToken();
}
if (!Data.MotionModifiers.empty() && Tok.isNot(tok::colon)) {
if (!IsInvalidMapperModifier) {
Expand Down
Loading