Skip to content

Commit 63828a3

Browse files
committed
[OPENMP50]Bassic support for exclusive clause.
Added basic support (parsing/sema/serialization) for exclusive clause in scan directives.
1 parent ae04446 commit 63828a3

File tree

16 files changed

+237
-14
lines changed

16 files changed

+237
-14
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6985,6 +6985,80 @@ class OMPInclusiveClause final
69856985
}
69866986
};
69876987

6988+
/// This represents clause 'exclusive' in the '#pragma omp scan' directive.
6989+
///
6990+
/// \code
6991+
/// #pragma omp scan exclusive(a,b)
6992+
/// \endcode
6993+
/// In this example directive '#pragma omp scan' has clause 'exclusive'
6994+
/// with the variables 'a' and 'b'.
6995+
class OMPExclusiveClause final
6996+
: public OMPVarListClause<OMPExclusiveClause>,
6997+
private llvm::TrailingObjects<OMPExclusiveClause, Expr *> {
6998+
friend class OMPClauseReader;
6999+
friend OMPVarListClause;
7000+
friend TrailingObjects;
7001+
7002+
/// Build clause with number of variables \a N.
7003+
///
7004+
/// \param StartLoc Starting location of the clause.
7005+
/// \param LParenLoc Location of '('.
7006+
/// \param EndLoc Ending location of the clause.
7007+
/// \param N Number of the variables in the clause.
7008+
OMPExclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
7009+
SourceLocation EndLoc, unsigned N)
7010+
: OMPVarListClause<OMPExclusiveClause>(OMPC_exclusive, StartLoc,
7011+
LParenLoc, EndLoc, N) {}
7012+
7013+
/// Build an empty clause.
7014+
///
7015+
/// \param N Number of variables.
7016+
explicit OMPExclusiveClause(unsigned N)
7017+
: OMPVarListClause<OMPExclusiveClause>(OMPC_exclusive, SourceLocation(),
7018+
SourceLocation(), SourceLocation(),
7019+
N) {}
7020+
7021+
public:
7022+
/// Creates clause with a list of variables \a VL.
7023+
///
7024+
/// \param C AST context.
7025+
/// \param StartLoc Starting location of the clause.
7026+
/// \param LParenLoc Location of '('.
7027+
/// \param EndLoc Ending location of the clause.
7028+
/// \param VL List of references to the original variables.
7029+
static OMPExclusiveClause *Create(const ASTContext &C,
7030+
SourceLocation StartLoc,
7031+
SourceLocation LParenLoc,
7032+
SourceLocation EndLoc, ArrayRef<Expr *> VL);
7033+
7034+
/// Creates an empty clause with the place for \a N variables.
7035+
///
7036+
/// \param C AST context.
7037+
/// \param N The number of variables.
7038+
static OMPExclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
7039+
7040+
child_range children() {
7041+
return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
7042+
reinterpret_cast<Stmt **>(varlist_end()));
7043+
}
7044+
7045+
const_child_range children() const {
7046+
auto Children = const_cast<OMPExclusiveClause *>(this)->children();
7047+
return const_child_range(Children.begin(), Children.end());
7048+
}
7049+
7050+
child_range used_children() {
7051+
return child_range(child_iterator(), child_iterator());
7052+
}
7053+
const_child_range used_children() const {
7054+
return const_child_range(const_child_iterator(), const_child_iterator());
7055+
}
7056+
7057+
static bool classof(const OMPClause *T) {
7058+
return T->getClauseKind() == OMPC_exclusive;
7059+
}
7060+
};
7061+
69887062
/// This class implements a simple visitor for OMPClause
69897063
/// subclasses.
69907064
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
@@ -3190,6 +3190,13 @@ bool RecursiveASTVisitor<Derived>::VisitOMPInclusiveClause(
31903190
return true;
31913191
}
31923192

3193+
template <typename Derived>
3194+
bool RecursiveASTVisitor<Derived>::VisitOMPExclusiveClause(
3195+
OMPExclusiveClause *C) {
3196+
TRY_TO(VisitOMPClauseList(C));
3197+
return true;
3198+
}
3199+
31933200
template <typename Derived>
31943201
bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
31953202
TRY_TO(VisitOMPClauseList(C));

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ OPENMP_CLAUSE(depobj, OMPDepobjClause)
285285
OPENMP_CLAUSE(destroy, OMPDestroyClause)
286286
OPENMP_CLAUSE(detach, OMPDetachClause)
287287
OPENMP_CLAUSE(inclusive, OMPInclusiveClause)
288+
OPENMP_CLAUSE(exclusive, OMPExclusiveClause)
288289

289290
// Clauses allowed for OpenMP directive 'scan'.
290291
OPENMP_SCAN_CLAUSE(inclusive)
292+
OPENMP_SCAN_CLAUSE(exclusive)
291293

292294
// Clauses allowed for OpenMP directive 'parallel'.
293295
OPENMP_PARALLEL_CLAUSE(if)

clang/include/clang/Sema/Sema.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10506,6 +10506,11 @@ class Sema final {
1050610506
SourceLocation StartLoc,
1050710507
SourceLocation LParenLoc,
1050810508
SourceLocation EndLoc);
10509+
/// Called on well-formed 'exclusive' clause.
10510+
OMPClause *ActOnOpenMPExclusiveClause(ArrayRef<Expr *> VarList,
10511+
SourceLocation StartLoc,
10512+
SourceLocation LParenLoc,
10513+
SourceLocation EndLoc);
1050910514
/// Called on well-formed 'allocate' clause.
1051010515
OMPClause *
1051110516
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
@@ -147,6 +147,7 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
147147
case OMPC_destroy:
148148
case OMPC_detach:
149149
case OMPC_inclusive:
150+
case OMPC_exclusive:
150151
break;
151152
}
152153

@@ -235,6 +236,7 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C)
235236
case OMPC_destroy:
236237
case OMPC_detach:
237238
case OMPC_inclusive:
239+
case OMPC_exclusive:
238240
break;
239241
}
240242

@@ -1268,6 +1270,24 @@ OMPInclusiveClause *OMPInclusiveClause::CreateEmpty(const ASTContext &C,
12681270
return new (Mem) OMPInclusiveClause(N);
12691271
}
12701272

1273+
OMPExclusiveClause *OMPExclusiveClause::Create(const ASTContext &C,
1274+
SourceLocation StartLoc,
1275+
SourceLocation LParenLoc,
1276+
SourceLocation EndLoc,
1277+
ArrayRef<Expr *> VL) {
1278+
void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
1279+
auto *Clause =
1280+
new (Mem) OMPExclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size());
1281+
Clause->setVarRefs(VL);
1282+
return Clause;
1283+
}
1284+
1285+
OMPExclusiveClause *OMPExclusiveClause::CreateEmpty(const ASTContext &C,
1286+
unsigned N) {
1287+
void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
1288+
return new (Mem) OMPExclusiveClause(N);
1289+
}
1290+
12711291
//===----------------------------------------------------------------------===//
12721292
// OpenMP clauses printing methods
12731293
//===----------------------------------------------------------------------===//
@@ -1833,6 +1853,14 @@ void OMPClausePrinter::VisitOMPInclusiveClause(OMPInclusiveClause *Node) {
18331853
}
18341854
}
18351855

1856+
void OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause *Node) {
1857+
if (!Node->varlist_empty()) {
1858+
OS << "exclusive";
1859+
VisitOMPClauseList(Node, '(');
1860+
OS << ")";
1861+
}
1862+
}
1863+
18361864
void OMPTraitInfo::getAsVariantMatchInfo(
18371865
ASTContext &ASTCtx, llvm::omp::VariantMatchInfo &VMI) const {
18381866
for (const OMPTraitSet &Set : Sets) {

clang/lib/AST/StmtProfile.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,9 @@ void OMPClauseProfiler::VisitOMPNontemporalClause(
798798
void OMPClauseProfiler::VisitOMPInclusiveClause(const OMPInclusiveClause *C) {
799799
VisitOMPClauseList(C);
800800
}
801+
void OMPClauseProfiler::VisitOMPExclusiveClause(const OMPExclusiveClause *C) {
802+
VisitOMPClauseList(C);
803+
}
801804
void OMPClauseProfiler::VisitOMPOrderClause(const OMPOrderClause *C) {}
802805
} // namespace
803806

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
213213
case OMPC_destroy:
214214
case OMPC_detach:
215215
case OMPC_inclusive:
216+
case OMPC_exclusive:
216217
break;
217218
}
218219
llvm_unreachable("Invalid OpenMP simple clause kind");
@@ -449,6 +450,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
449450
case OMPC_destroy:
450451
case OMPC_detach:
451452
case OMPC_inclusive:
453+
case OMPC_exclusive:
452454
break;
453455
}
454456
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
@@ -4617,6 +4617,7 @@ static void emitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind,
46174617
case OMPC_destroy:
46184618
case OMPC_detach:
46194619
case OMPC_inclusive:
4620+
case OMPC_exclusive:
46204621
llvm_unreachable("Clause is not allowed in 'omp atomic'.");
46214622
}
46224623
}

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,8 @@ 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 | inclusive-clause
2347+
/// depobj-clause | destroy-clause | detach-clause | inclusive-clause |
2348+
/// exclusive-clause
23482349
///
23492350
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
23502351
OpenMPClauseKind CKind, bool FirstClause) {
@@ -2514,6 +2515,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
25142515
case OMPC_allocate:
25152516
case OMPC_nontemporal:
25162517
case OMPC_inclusive:
2518+
case OMPC_exclusive:
25172519
Clause = ParseOpenMPVarListClause(DKind, CKind, WrongDirective);
25182520
break;
25192521
case OMPC_device_type:
@@ -3239,7 +3241,7 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
32393241

32403242
/// Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
32413243
/// 'shared', 'copyin', 'copyprivate', 'flush', 'reduction', 'task_reduction',
3242-
/// 'in_reduction', 'nontemporal' or 'inclusive'.
3244+
/// 'in_reduction', 'nontemporal', 'exclusive' or 'inclusive'.
32433245
///
32443246
/// private-clause:
32453247
/// 'private' '(' list ')'
@@ -3283,6 +3285,8 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
32833285
/// 'nontemporal' '(' list ')'
32843286
/// inclusive-clause:
32853287
/// 'inclusive' '(' list ')'
3288+
/// exclusive-clause:
3289+
/// 'exclusive' '(' list ')'
32863290
///
32873291
/// For 'linear' clause linear-list may have the following forms:
32883292
/// list

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5100,6 +5100,7 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
51005100
case OMPC_order:
51015101
case OMPC_destroy:
51025102
case OMPC_inclusive:
5103+
case OMPC_exclusive:
51035104
continue;
51045105
case OMPC_allocator:
51055106
case OMPC_flush:
@@ -11084,6 +11085,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
1108411085
case OMPC_order:
1108511086
case OMPC_destroy:
1108611087
case OMPC_inclusive:
11088+
case OMPC_exclusive:
1108711089
llvm_unreachable("Clause is not allowed.");
1108811090
}
1108911091
return Res;
@@ -11820,6 +11822,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
1182011822
case OMPC_destroy:
1182111823
case OMPC_detach:
1182211824
case OMPC_inclusive:
11825+
case OMPC_exclusive:
1182311826
llvm_unreachable("Unexpected OpenMP clause.");
1182411827
}
1182511828
return CaptureRegion;
@@ -12258,6 +12261,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause(
1225812261
case OMPC_destroy:
1225912262
case OMPC_detach:
1226012263
case OMPC_inclusive:
12264+
case OMPC_exclusive:
1226112265
llvm_unreachable("Clause is not allowed.");
1226212266
}
1226312267
return Res;
@@ -12482,6 +12486,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause(
1248212486
case OMPC_destroy:
1248312487
case OMPC_detach:
1248412488
case OMPC_inclusive:
12489+
case OMPC_exclusive:
1248512490
llvm_unreachable("Clause is not allowed.");
1248612491
}
1248712492
return Res;
@@ -12713,6 +12718,7 @@ OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind,
1271312718
case OMPC_order:
1271412719
case OMPC_detach:
1271512720
case OMPC_inclusive:
12721+
case OMPC_exclusive:
1271612722
llvm_unreachable("Clause is not allowed.");
1271712723
}
1271812724
return Res;
@@ -12923,6 +12929,9 @@ OMPClause *Sema::ActOnOpenMPVarListClause(
1292312929
case OMPC_inclusive:
1292412930
Res = ActOnOpenMPInclusiveClause(VarList, StartLoc, LParenLoc, EndLoc);
1292512931
break;
12932+
case OMPC_exclusive:
12933+
Res = ActOnOpenMPExclusiveClause(VarList, StartLoc, LParenLoc, EndLoc);
12934+
break;
1292612935
case OMPC_if:
1292712936
case OMPC_depobj:
1292812937
case OMPC_final:
@@ -18008,3 +18017,31 @@ OMPClause *Sema::ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList,
1800818017

1800918018
return OMPInclusiveClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars);
1801018019
}
18020+
18021+
OMPClause *Sema::ActOnOpenMPExclusiveClause(ArrayRef<Expr *> VarList,
18022+
SourceLocation StartLoc,
18023+
SourceLocation LParenLoc,
18024+
SourceLocation EndLoc) {
18025+
SmallVector<Expr *, 8> Vars;
18026+
for (Expr *RefExpr : VarList) {
18027+
assert(RefExpr && "NULL expr in OpenMP nontemporal clause.");
18028+
SourceLocation ELoc;
18029+
SourceRange ERange;
18030+
Expr *SimpleRefExpr = RefExpr;
18031+
auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange,
18032+
/*AllowArraySection=*/true);
18033+
if (Res.second)
18034+
// It will be analyzed later.
18035+
Vars.push_back(RefExpr);
18036+
ValueDecl *D = Res.first;
18037+
if (!D)
18038+
continue;
18039+
18040+
Vars.push_back(RefExpr);
18041+
}
18042+
18043+
if (Vars.empty())
18044+
return nullptr;
18045+
18046+
return OMPExclusiveClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars);
18047+
}

0 commit comments

Comments
 (0)