Skip to content

Commit 06dea73

Browse files
committed
[OPENMP50]Initial support for inclusive clause.
Added parsing/sema/serialization support for inclusive clause in scan directive.
1 parent 7899fe9 commit 06dea73

File tree

18 files changed

+281
-54
lines changed

18 files changed

+281
-54
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6911,6 +6911,80 @@ class OMPDetachClause final : public OMPClause {
69116911
}
69126912
};
69136913

6914+
/// This represents clause 'inclusive' in the '#pragma omp scan' directive.
6915+
///
6916+
/// \code
6917+
/// #pragma omp scan inclusive(a,b)
6918+
/// \endcode
6919+
/// In this example directive '#pragma omp scan' has clause 'inclusive'
6920+
/// with the variables 'a' and 'b'.
6921+
class OMPInclusiveClause final
6922+
: public OMPVarListClause<OMPInclusiveClause>,
6923+
private llvm::TrailingObjects<OMPInclusiveClause, Expr *> {
6924+
friend class OMPClauseReader;
6925+
friend OMPVarListClause;
6926+
friend TrailingObjects;
6927+
6928+
/// Build clause with number of variables \a N.
6929+
///
6930+
/// \param StartLoc Starting location of the clause.
6931+
/// \param LParenLoc Location of '('.
6932+
/// \param EndLoc Ending location of the clause.
6933+
/// \param N Number of the variables in the clause.
6934+
OMPInclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
6935+
SourceLocation EndLoc, unsigned N)
6936+
: OMPVarListClause<OMPInclusiveClause>(OMPC_inclusive, StartLoc,
6937+
LParenLoc, EndLoc, N) {}
6938+
6939+
/// Build an empty clause.
6940+
///
6941+
/// \param N Number of variables.
6942+
explicit OMPInclusiveClause(unsigned N)
6943+
: OMPVarListClause<OMPInclusiveClause>(OMPC_inclusive, SourceLocation(),
6944+
SourceLocation(), SourceLocation(),
6945+
N) {}
6946+
6947+
public:
6948+
/// Creates clause with a list of variables \a VL.
6949+
///
6950+
/// \param C AST context.
6951+
/// \param StartLoc Starting location of the clause.
6952+
/// \param LParenLoc Location of '('.
6953+
/// \param EndLoc Ending location of the clause.
6954+
/// \param VL List of references to the original variables.
6955+
static OMPInclusiveClause *Create(const ASTContext &C,
6956+
SourceLocation StartLoc,
6957+
SourceLocation LParenLoc,
6958+
SourceLocation EndLoc, ArrayRef<Expr *> VL);
6959+
6960+
/// Creates an empty clause with the place for \a N variables.
6961+
///
6962+
/// \param C AST context.
6963+
/// \param N The number of variables.
6964+
static OMPInclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
6965+
6966+
child_range children() {
6967+
return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6968+
reinterpret_cast<Stmt **>(varlist_end()));
6969+
}
6970+
6971+
const_child_range children() const {
6972+
auto Children = const_cast<OMPInclusiveClause *>(this)->children();
6973+
return const_child_range(Children.begin(), Children.end());
6974+
}
6975+
6976+
child_range used_children() {
6977+
return child_range(child_iterator(), child_iterator());
6978+
}
6979+
const_child_range used_children() const {
6980+
return const_child_range(const_child_iterator(), const_child_iterator());
6981+
}
6982+
6983+
static bool classof(const OMPClause *T) {
6984+
return T->getClauseKind() == OMPC_inclusive;
6985+
}
6986+
};
6987+
69146988
/// This class implements a simple visitor for OMPClause
69156989
/// subclasses.
69166990
template<class ImplClass, template <typename> class Ptr, typename RetTy>

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,6 +3183,13 @@ bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
31833183
return true;
31843184
}
31853185

3186+
template <typename Derived>
3187+
bool RecursiveASTVisitor<Derived>::VisitOMPInclusiveClause(
3188+
OMPInclusiveClause *C) {
3189+
TRY_TO(VisitOMPClauseList(C));
3190+
return true;
3191+
}
3192+
31863193
template <typename Derived>
31873194
bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
31883195
TRY_TO(VisitOMPClauseList(C));

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10055,6 +10055,8 @@ def err_omp_depobj_expected : Error<
1005510055
"expected depobj expression">;
1005610056
def err_omp_depobj_single_clause_expected : Error<
1005710057
"exactly one of 'depend', 'destroy', or 'update' clauses is expected">;
10058+
def err_omp_scan_single_clause_expected : Error<
10059+
"exactly one of 'inclusive' or 'exclusive' clauses is expected">;
1005810060
def err_omp_expected_predefined_allocator : Error<
1005910061
"expected one of the predefined allocators for the variables with the static "
1006010062
"storage: 'omp_default_mem_alloc', 'omp_large_cap_mem_alloc', "

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@
215215
#ifndef OPENMP_DEVICE_MODIFIER
216216
#define OPENMP_DEVICE_MODIFIER(Name)
217217
#endif
218+
#ifndef OPENMP_SCAN_CLAUSE
219+
#define OPENMP_SCAN_CLAUSE(Name)
220+
#endif
218221

219222
// OpenMP clauses.
220223
OPENMP_CLAUSE(allocator, OMPAllocatorClause)
@@ -281,6 +284,10 @@ OPENMP_CLAUSE(order, OMPOrderClause)
281284
OPENMP_CLAUSE(depobj, OMPDepobjClause)
282285
OPENMP_CLAUSE(destroy, OMPDestroyClause)
283286
OPENMP_CLAUSE(detach, OMPDetachClause)
287+
OPENMP_CLAUSE(inclusive, OMPInclusiveClause)
288+
289+
// Clauses allowed for OpenMP directive 'scan'.
290+
OPENMP_SCAN_CLAUSE(inclusive)
284291

285292
// Clauses allowed for OpenMP directive 'parallel'.
286293
OPENMP_PARALLEL_CLAUSE(if)
@@ -1098,6 +1105,7 @@ OPENMP_DEPOBJ_CLAUSE(depend)
10981105
OPENMP_DEPOBJ_CLAUSE(destroy)
10991106
OPENMP_DEPOBJ_CLAUSE(update)
11001107

1108+
#undef OPENMP_SCAN_CLAUSE
11011109
#undef OPENMP_DEVICE_MODIFIER
11021110
#undef OPENMP_DEPOBJ_CLAUSE
11031111
#undef OPENMP_FLUSH_CLAUSE

clang/include/clang/Sema/Sema.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10495,6 +10495,11 @@ class Sema final {
1049510495
ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1049610496
ArrayRef<SourceLocation> MapTypeModifiersLoc, bool IsMapTypeImplicit,
1049710497
SourceLocation DepLinMapLastLoc);
10498+
/// Called on well-formed 'inclusive' clause.
10499+
OMPClause *ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList,
10500+
SourceLocation StartLoc,
10501+
SourceLocation LParenLoc,
10502+
SourceLocation EndLoc);
1049810503
/// Called on well-formed 'allocate' clause.
1049910504
OMPClause *
1050010505
ActOnOpenMPAllocateClause(Expr *Allocator, ArrayRef<Expr *> VarList,

clang/lib/AST/OpenMPClause.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
146146
case OMPC_order:
147147
case OMPC_destroy:
148148
case OMPC_detach:
149+
case OMPC_inclusive:
149150
break;
150151
}
151152

@@ -233,6 +234,7 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C)
233234
case OMPC_order:
234235
case OMPC_destroy:
235236
case OMPC_detach:
237+
case OMPC_inclusive:
236238
break;
237239
}
238240

@@ -1248,6 +1250,24 @@ void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
12481250
std::copy(VL.begin(), VL.end(), varlist_end());
12491251
}
12501252

1253+
OMPInclusiveClause *OMPInclusiveClause::Create(const ASTContext &C,
1254+
SourceLocation StartLoc,
1255+
SourceLocation LParenLoc,
1256+
SourceLocation EndLoc,
1257+
ArrayRef<Expr *> VL) {
1258+
void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1259+
auto *Clause =
1260+
new (Mem) OMPInclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
1261+
Clause->setVarRefs(VL);
1262+
return Clause;
1263+
}
1264+
1265+
OMPInclusiveClause *OMPInclusiveClause::CreateEmpty(const ASTContext &C,
1266+
unsigned N) {
1267+
void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1268+
return new (Mem) OMPInclusiveClause(N);
1269+
}
1270+
12511271
//===----------------------------------------------------------------------===//
12521272
// OpenMP clauses printing methods
12531273
//===----------------------------------------------------------------------===//
@@ -1805,6 +1825,14 @@ void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) {
18051825
<< ")";
18061826
}
18071827

1828+
void OMPClausePrinter::VisitOMPInclusiveClause(OMPInclusiveClause *Node) {
1829+
if (!Node->varlist_empty()) {
1830+
OS << "inclusive";
1831+
VisitOMPClauseList(Node, '(');
1832+
OS << ")";
1833+
}
1834+
}
1835+
18081836
void OMPTraitInfo::getAsVariantMatchInfo(
18091837
ASTContext &ASTCtx, llvm::omp::VariantMatchInfo &VMI) const {
18101838
for (const OMPTraitSet &Set : Sets) {

clang/lib/AST/StmtProfile.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,9 @@ void OMPClauseProfiler::VisitOMPNontemporalClause(
795795
for (auto *E : C->private_refs())
796796
Profiler->VisitStmt(E);
797797
}
798+
void OMPClauseProfiler::VisitOMPInclusiveClause(const OMPInclusiveClause *C) {
799+
VisitOMPClauseList(C);
800+
}
798801
void OMPClauseProfiler::VisitOMPOrderClause(const OMPOrderClause *C) {}
799802
} // namespace
800803

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
212212
case OMPC_nontemporal:
213213
case OMPC_destroy:
214214
case OMPC_detach:
215+
case OMPC_inclusive:
215216
break;
216217
}
217218
llvm_unreachable("Invalid OpenMP simple clause kind");
@@ -447,6 +448,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
447448
case OMPC_nontemporal:
448449
case OMPC_destroy:
449450
case OMPC_detach:
451+
case OMPC_inclusive:
450452
break;
451453
}
452454
llvm_unreachable("Invalid OpenMP simple clause kind");

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4616,6 +4616,7 @@ static void emitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind,
46164616
case OMPC_order:
46174617
case OMPC_destroy:
46184618
case OMPC_detach:
4619+
case OMPC_inclusive:
46194620
llvm_unreachable("Clause is not allowed in 'omp atomic'.");
46204621
}
46214622
}

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,7 @@ bool Parser::ParseOpenMPSimpleVarList(
23442344
/// from-clause | is_device_ptr-clause | task_reduction-clause |
23452345
/// in_reduction-clause | allocator-clause | allocate-clause |
23462346
/// acq_rel-clause | acquire-clause | release-clause | relaxed-clause |
2347-
/// depobj-clause | destroy-clause | detach-clause
2347+
/// depobj-clause | destroy-clause | detach-clause | inclusive-clause
23482348
///
23492349
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
23502350
OpenMPClauseKind CKind, bool FirstClause) {
@@ -2513,6 +2513,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
25132513
case OMPC_is_device_ptr:
25142514
case OMPC_allocate:
25152515
case OMPC_nontemporal:
2516+
case OMPC_inclusive:
25162517
Clause = ParseOpenMPVarListClause(DKind, CKind, WrongDirective);
25172518
break;
25182519
case OMPC_device_type:
@@ -3237,8 +3238,8 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
32373238
}
32383239

32393240
/// Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
3240-
/// 'shared', 'copyin', 'copyprivate', 'flush', 'reduction', 'task_reduction' or
3241-
/// 'in_reduction'.
3241+
/// 'shared', 'copyin', 'copyprivate', 'flush', 'reduction', 'task_reduction',
3242+
/// 'in_reduction', 'nontemporal' or 'inclusive'.
32423243
///
32433244
/// private-clause:
32443245
/// 'private' '(' list ')'
@@ -3278,6 +3279,10 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
32783279
/// 'is_device_ptr' '(' list ')'
32793280
/// allocate-clause:
32803281
/// 'allocate' '(' [ allocator ':' ] list ')'
3282+
/// nontemporal-clause:
3283+
/// 'nontemporal' '(' list ')'
3284+
/// inclusive-clause:
3285+
/// 'inclusive' '(' list ')'
32813286
///
32823287
/// For 'linear' clause linear-list may have the following forms:
32833288
/// list

0 commit comments

Comments
 (0)