Skip to content

Commit 9f2f3b9

Browse files
committed
[OpenMP] Implement TR8 present motion modifier in Clang (1/2)
This patch implements Clang front end support for the OpenMP TR8 `present` motion modifier for `omp target update` directives. The next patch in this series implements OpenMP runtime support. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D84711
1 parent 4a10029 commit 9f2f3b9

19 files changed

+898
-152
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 176 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6329,8 +6329,20 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
63296329
friend OMPVarListClause;
63306330
friend TrailingObjects;
63316331

6332+
/// Motion-modifiers for the 'to' clause.
6333+
OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
6334+
OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown};
6335+
6336+
/// Location of motion-modifiers for the 'to' clause.
6337+
SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
6338+
6339+
/// Colon location.
6340+
SourceLocation ColonLoc;
6341+
63326342
/// Build clause with number of variables \a NumVars.
63336343
///
6344+
/// \param TheMotionModifiers Motion-modifiers.
6345+
/// \param TheMotionModifiersLoc Locations of motion-modifiers.
63346346
/// \param MapperQualifierLoc C++ nested name specifier for the associated
63356347
/// user-defined mapper.
63366348
/// \param MapperIdInfo The identifier of associated user-defined mapper.
@@ -6342,13 +6354,24 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
63426354
/// NumUniqueDeclarations: number of unique base declarations in this clause;
63436355
/// 3) NumComponentLists: number of component lists in this clause; and 4)
63446356
/// NumComponents: total number of expression components in the clause.
6345-
explicit OMPToClause(NestedNameSpecifierLoc MapperQualifierLoc,
6357+
explicit OMPToClause(ArrayRef<OpenMPMotionModifierKind> TheMotionModifiers,
6358+
ArrayRef<SourceLocation> TheMotionModifiersLoc,
6359+
NestedNameSpecifierLoc MapperQualifierLoc,
63466360
DeclarationNameInfo MapperIdInfo,
63476361
const OMPVarListLocTy &Locs,
63486362
const OMPMappableExprListSizeTy &Sizes)
63496363
: OMPMappableExprListClause(llvm::omp::OMPC_to, Locs, Sizes,
63506364
/*SupportsMapper=*/true, &MapperQualifierLoc,
6351-
&MapperIdInfo) {}
6365+
&MapperIdInfo) {
6366+
assert(llvm::array_lengthof(MotionModifiers) == TheMotionModifiers.size() &&
6367+
"Unexpected number of motion modifiers.");
6368+
llvm::copy(TheMotionModifiers, std::begin(MotionModifiers));
6369+
6370+
assert(llvm::array_lengthof(MotionModifiersLoc) ==
6371+
TheMotionModifiersLoc.size() &&
6372+
"Unexpected number of motion modifier locations.");
6373+
llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc));
6374+
}
63526375

63536376
/// Build an empty clause.
63546377
///
@@ -6361,6 +6384,29 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
63616384
: OMPMappableExprListClause(llvm::omp::OMPC_to, OMPVarListLocTy(), Sizes,
63626385
/*SupportsMapper=*/true) {}
63636386

6387+
/// Set motion-modifier for the clause.
6388+
///
6389+
/// \param I index for motion-modifier.
6390+
/// \param T motion-modifier for the clause.
6391+
void setMotionModifier(unsigned I, OpenMPMotionModifierKind T) {
6392+
assert(I < NumberOfOMPMotionModifiers &&
6393+
"Unexpected index to store motion modifier, exceeds array size.");
6394+
MotionModifiers[I] = T;
6395+
}
6396+
6397+
/// Set location for the motion-modifier.
6398+
///
6399+
/// \param I index for motion-modifier location.
6400+
/// \param TLoc motion-modifier location.
6401+
void setMotionModifierLoc(unsigned I, SourceLocation TLoc) {
6402+
assert(I < NumberOfOMPMotionModifiers &&
6403+
"Index to store motion modifier location exceeds array size.");
6404+
MotionModifiersLoc[I] = TLoc;
6405+
}
6406+
6407+
/// Set colon location.
6408+
void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
6409+
63646410
/// Define the sizes of each trailing object array except the last one. This
63656411
/// is required for TrailingObjects to work properly.
63666412
size_t numTrailingObjects(OverloadToken<Expr *>) const {
@@ -6385,6 +6431,8 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
63856431
/// \param Vars The original expression used in the clause.
63866432
/// \param Declarations Declarations used in the clause.
63876433
/// \param ComponentLists Component lists used in the clause.
6434+
/// \param MotionModifiers Motion-modifiers.
6435+
/// \param MotionModifiersLoc Location of motion-modifiers.
63886436
/// \param UDMapperRefs References to user-defined mappers associated with
63896437
/// expressions used in the clause.
63906438
/// \param UDMQualifierLoc C++ nested name specifier for the associated
@@ -6395,6 +6443,8 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
63956443
ArrayRef<ValueDecl *> Declarations,
63966444
MappableExprComponentListsRef ComponentLists,
63976445
ArrayRef<Expr *> UDMapperRefs,
6446+
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
6447+
ArrayRef<SourceLocation> MotionModifiersLoc,
63986448
NestedNameSpecifierLoc UDMQualifierLoc,
63996449
DeclarationNameInfo MapperId);
64006450

@@ -6409,6 +6459,38 @@ class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
64096459
static OMPToClause *CreateEmpty(const ASTContext &C,
64106460
const OMPMappableExprListSizeTy &Sizes);
64116461

6462+
/// Fetches the motion-modifier at 'Cnt' index of array of modifiers.
6463+
///
6464+
/// \param Cnt index for motion-modifier.
6465+
OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY {
6466+
assert(Cnt < NumberOfOMPMotionModifiers &&
6467+
"Requested modifier exceeds the total number of modifiers.");
6468+
return MotionModifiers[Cnt];
6469+
}
6470+
6471+
/// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
6472+
/// locations.
6473+
///
6474+
/// \param Cnt index for motion-modifier location.
6475+
SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY {
6476+
assert(Cnt < NumberOfOMPMotionModifiers &&
6477+
"Requested modifier location exceeds total number of modifiers.");
6478+
return MotionModifiersLoc[Cnt];
6479+
}
6480+
6481+
/// Fetches ArrayRef of motion-modifiers.
6482+
ArrayRef<OpenMPMotionModifierKind> getMotionModifiers() const LLVM_READONLY {
6483+
return llvm::makeArrayRef(MotionModifiers);
6484+
}
6485+
6486+
/// Fetches ArrayRef of location of motion-modifiers.
6487+
ArrayRef<SourceLocation> getMotionModifiersLoc() const LLVM_READONLY {
6488+
return llvm::makeArrayRef(MotionModifiersLoc);
6489+
}
6490+
6491+
/// Get colon location.
6492+
SourceLocation getColonLoc() const { return ColonLoc; }
6493+
64126494
child_range children() {
64136495
return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
64146496
reinterpret_cast<Stmt **>(varlist_end()));
@@ -6449,8 +6531,20 @@ class OMPFromClause final
64496531
friend OMPVarListClause;
64506532
friend TrailingObjects;
64516533

6534+
/// Motion-modifiers for the 'from' clause.
6535+
OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
6536+
OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown};
6537+
6538+
/// Location of motion-modifiers for the 'from' clause.
6539+
SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
6540+
6541+
/// Colon location.
6542+
SourceLocation ColonLoc;
6543+
64526544
/// Build clause with number of variables \a NumVars.
64536545
///
6546+
/// \param TheMotionModifiers Motion-modifiers.
6547+
/// \param TheMotionModifiersLoc Locations of motion-modifiers.
64546548
/// \param MapperQualifierLoc C++ nested name specifier for the associated
64556549
/// user-defined mapper.
64566550
/// \param MapperIdInfo The identifier of associated user-defined mapper.
@@ -6462,13 +6556,24 @@ class OMPFromClause final
64626556
/// NumUniqueDeclarations: number of unique base declarations in this clause;
64636557
/// 3) NumComponentLists: number of component lists in this clause; and 4)
64646558
/// NumComponents: total number of expression components in the clause.
6465-
explicit OMPFromClause(NestedNameSpecifierLoc MapperQualifierLoc,
6559+
explicit OMPFromClause(ArrayRef<OpenMPMotionModifierKind> TheMotionModifiers,
6560+
ArrayRef<SourceLocation> TheMotionModifiersLoc,
6561+
NestedNameSpecifierLoc MapperQualifierLoc,
64666562
DeclarationNameInfo MapperIdInfo,
64676563
const OMPVarListLocTy &Locs,
64686564
const OMPMappableExprListSizeTy &Sizes)
64696565
: OMPMappableExprListClause(llvm::omp::OMPC_from, Locs, Sizes,
64706566
/*SupportsMapper=*/true, &MapperQualifierLoc,
6471-
&MapperIdInfo) {}
6567+
&MapperIdInfo) {
6568+
assert(llvm::array_lengthof(MotionModifiers) == TheMotionModifiers.size() &&
6569+
"Unexpected number of motion modifiers.");
6570+
llvm::copy(TheMotionModifiers, std::begin(MotionModifiers));
6571+
6572+
assert(llvm::array_lengthof(MotionModifiersLoc) ==
6573+
TheMotionModifiersLoc.size() &&
6574+
"Unexpected number of motion modifier locations.");
6575+
llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc));
6576+
}
64726577

64736578
/// Build an empty clause.
64746579
///
@@ -6481,6 +6586,29 @@ class OMPFromClause final
64816586
: OMPMappableExprListClause(llvm::omp::OMPC_from, OMPVarListLocTy(),
64826587
Sizes, /*SupportsMapper=*/true) {}
64836588

6589+
/// Set motion-modifier for the clause.
6590+
///
6591+
/// \param I index for motion-modifier.
6592+
/// \param T motion-modifier for the clause.
6593+
void setMotionModifier(unsigned I, OpenMPMotionModifierKind T) {
6594+
assert(I < NumberOfOMPMotionModifiers &&
6595+
"Unexpected index to store motion modifier, exceeds array size.");
6596+
MotionModifiers[I] = T;
6597+
}
6598+
6599+
/// Set location for the motion-modifier.
6600+
///
6601+
/// \param I index for motion-modifier location.
6602+
/// \param TLoc motion-modifier location.
6603+
void setMotionModifierLoc(unsigned I, SourceLocation TLoc) {
6604+
assert(I < NumberOfOMPMotionModifiers &&
6605+
"Index to store motion modifier location exceeds array size.");
6606+
MotionModifiersLoc[I] = TLoc;
6607+
}
6608+
6609+
/// Set colon location.
6610+
void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
6611+
64846612
/// Define the sizes of each trailing object array except the last one. This
64856613
/// is required for TrailingObjects to work properly.
64866614
size_t numTrailingObjects(OverloadToken<Expr *>) const {
@@ -6505,18 +6633,21 @@ class OMPFromClause final
65056633
/// \param Vars The original expression used in the clause.
65066634
/// \param Declarations Declarations used in the clause.
65076635
/// \param ComponentLists Component lists used in the clause.
6636+
/// \param MotionModifiers Motion-modifiers.
6637+
/// \param MotionModifiersLoc Location of motion-modifiers.
65086638
/// \param UDMapperRefs References to user-defined mappers associated with
65096639
/// expressions used in the clause.
65106640
/// \param UDMQualifierLoc C++ nested name specifier for the associated
65116641
/// user-defined mapper.
65126642
/// \param MapperId The identifier of associated user-defined mapper.
6513-
static OMPFromClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs,
6514-
ArrayRef<Expr *> Vars,
6515-
ArrayRef<ValueDecl *> Declarations,
6516-
MappableExprComponentListsRef ComponentLists,
6517-
ArrayRef<Expr *> UDMapperRefs,
6518-
NestedNameSpecifierLoc UDMQualifierLoc,
6519-
DeclarationNameInfo MapperId);
6643+
static OMPFromClause *
6644+
Create(const ASTContext &C, const OMPVarListLocTy &Locs,
6645+
ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
6646+
MappableExprComponentListsRef ComponentLists,
6647+
ArrayRef<Expr *> UDMapperRefs,
6648+
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
6649+
ArrayRef<SourceLocation> MotionModifiersLoc,
6650+
NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId);
65206651

65216652
/// Creates an empty clause with the place for \a NumVars variables.
65226653
///
@@ -6529,6 +6660,38 @@ class OMPFromClause final
65296660
static OMPFromClause *CreateEmpty(const ASTContext &C,
65306661
const OMPMappableExprListSizeTy &Sizes);
65316662

6663+
/// Fetches the motion-modifier at 'Cnt' index of array of modifiers.
6664+
///
6665+
/// \param Cnt index for motion-modifier.
6666+
OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY {
6667+
assert(Cnt < NumberOfOMPMotionModifiers &&
6668+
"Requested modifier exceeds the total number of modifiers.");
6669+
return MotionModifiers[Cnt];
6670+
}
6671+
6672+
/// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
6673+
/// locations.
6674+
///
6675+
/// \param Cnt index for motion-modifier location.
6676+
SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY {
6677+
assert(Cnt < NumberOfOMPMotionModifiers &&
6678+
"Requested modifier location exceeds total number of modifiers.");
6679+
return MotionModifiersLoc[Cnt];
6680+
}
6681+
6682+
/// Fetches ArrayRef of motion-modifiers.
6683+
ArrayRef<OpenMPMotionModifierKind> getMotionModifiers() const LLVM_READONLY {
6684+
return llvm::makeArrayRef(MotionModifiers);
6685+
}
6686+
6687+
/// Fetches ArrayRef of location of motion-modifiers.
6688+
ArrayRef<SourceLocation> getMotionModifiersLoc() const LLVM_READONLY {
6689+
return llvm::makeArrayRef(MotionModifiersLoc);
6690+
}
6691+
6692+
/// Get colon location.
6693+
SourceLocation getColonLoc() const { return ColonLoc; }
6694+
65326695
child_range children() {
65336696
return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
65346697
reinterpret_cast<Stmt **>(varlist_end()));
@@ -7623,6 +7786,8 @@ class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> {
76237786

76247787
/// Process clauses with list of variables.
76257788
template <typename T> void VisitOMPClauseList(T *Node, char StartSym);
7789+
/// Process motion clauses.
7790+
template <typename T> void VisitOMPMotionClause(T *Node);
76267791

76277792
public:
76287793
OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9805,6 +9805,8 @@ def err_omp_multiple_array_items_in_map_clause : Error<
98059805
"multiple array elements associated with the same variable are not allowed in map clauses of the same construct">;
98069806
def err_omp_duplicate_map_type_modifier : Error<
98079807
"same map type modifier has been specified more than once">;
9808+
def err_omp_duplicate_motion_modifier : Error<
9809+
"same motion modifier has been specified more than once">;
98089810
def err_omp_pointer_mapped_along_with_derived_section : Error<
98099811
"pointer cannot be mapped along with a section derived from itself">;
98109812
def err_omp_original_storage_is_shared_and_does_not_contain : Error<

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ OPENMP_MAP_MODIFIER_KIND(present)
125125

126126
// Modifiers for 'to' or 'from' clause.
127127
OPENMP_MOTION_MODIFIER_KIND(mapper)
128+
OPENMP_MOTION_MODIFIER_KIND(present)
128129

129130
// Static attributes for 'dist_schedule' clause.
130131
OPENMP_DIST_SCHEDULE_KIND(static)

clang/include/clang/Basic/OpenMPKinds.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ enum OpenMPMotionModifierKind {
9494
OMPC_MOTION_MODIFIER_unknown
9595
};
9696

97+
/// Number of allowed motion-modifiers.
98+
static constexpr unsigned NumberOfOMPMotionModifiers =
99+
OMPC_MOTION_MODIFIER_unknown;
100+
97101
/// OpenMP attributes for 'dist_schedule' clause.
98102
enum OpenMPDistScheduleClauseKind {
99103
#define OPENMP_DIST_SCHEDULE_KIND(Name) OMPC_DIST_SCHEDULE_##Name,

clang/include/clang/Parse/Parser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,6 +3221,9 @@ class Parser : public CodeCompletionHandler {
32213221
MapTypeModifiers;
32223222
SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers>
32233223
MapTypeModifiersLoc;
3224+
SmallVector<OpenMPMotionModifierKind, NumberOfOMPMotionModifiers>
3225+
MotionModifiers;
3226+
SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc;
32243227
bool IsMapTypeImplicit = false;
32253228
SourceLocation ExtraModifierLoc;
32263229
};

clang/include/clang/Sema/Sema.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10725,7 +10725,9 @@ class Sema final {
1072510725
DeclarationNameInfo &ReductionOrMapperId, int ExtraModifier,
1072610726
ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1072710727
ArrayRef<SourceLocation> MapTypeModifiersLoc, bool IsMapTypeImplicit,
10728-
SourceLocation ExtraModifierLoc);
10728+
SourceLocation ExtraModifierLoc,
10729+
ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
10730+
ArrayRef<SourceLocation> MotionModifiersLoc);
1072910731
/// Called on well-formed 'inclusive' clause.
1073010732
OMPClause *ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList,
1073110733
SourceLocation StartLoc,
@@ -10862,15 +10864,20 @@ class Sema final {
1086210864
SourceLocation KindLoc, SourceLocation EndLoc);
1086310865
/// Called on well-formed 'to' clause.
1086410866
OMPClause *
10865-
ActOnOpenMPToClause(ArrayRef<Expr *> VarList, CXXScopeSpec &MapperIdScopeSpec,
10866-
DeclarationNameInfo &MapperId,
10867-
const OMPVarListLocTy &Locs,
10867+
ActOnOpenMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
10868+
ArrayRef<SourceLocation> MotionModifiersLoc,
10869+
CXXScopeSpec &MapperIdScopeSpec,
10870+
DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
10871+
ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
1086810872
ArrayRef<Expr *> UnresolvedMappers = llvm::None);
1086910873
/// Called on well-formed 'from' clause.
10870-
OMPClause *ActOnOpenMPFromClause(
10871-
ArrayRef<Expr *> VarList, CXXScopeSpec &MapperIdScopeSpec,
10872-
DeclarationNameInfo &MapperId, const OMPVarListLocTy &Locs,
10873-
ArrayRef<Expr *> UnresolvedMappers = llvm::None);
10874+
OMPClause *
10875+
ActOnOpenMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
10876+
ArrayRef<SourceLocation> MotionModifiersLoc,
10877+
CXXScopeSpec &MapperIdScopeSpec,
10878+
DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
10879+
ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
10880+
ArrayRef<Expr *> UnresolvedMappers = llvm::None);
1087410881
/// Called on well-formed 'use_device_ptr' clause.
1087510882
OMPClause *ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1087610883
const OMPVarListLocTy &Locs);

0 commit comments

Comments
 (0)