Skip to content

Commit 459dec0

Browse files
committed
[OPENMP] Initial parsing and sema analysis for clause 'capture' in 'atomic' directive.
llvm-svn: 213842
1 parent 65f8732 commit 459dec0

17 files changed

+199
-19
lines changed

clang/include/clang/AST/DataRecursiveASTVisitor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,11 @@ bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
24352435
return true;
24362436
}
24372437

2438+
template <typename Derived>
2439+
bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
2440+
return true;
2441+
}
2442+
24382443
template <typename Derived>
24392444
template <typename T>
24402445
bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {

clang/include/clang/AST/OpenMPClause.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,36 @@ class OMPUpdateClause : public OMPClause {
857857
StmtRange children() { return StmtRange(); }
858858
};
859859

860+
/// \brief This represents 'capture' clause in the '#pragma omp atomic'
861+
/// directive.
862+
///
863+
/// \code
864+
/// #pragma omp atomic capture
865+
/// \endcode
866+
/// In this example directive '#pragma omp atomic' has 'capture' clause.
867+
///
868+
class OMPCaptureClause : public OMPClause {
869+
public:
870+
/// \brief Build 'capture' clause.
871+
///
872+
/// \param StartLoc Starting location of the clause.
873+
/// \param EndLoc Ending location of the clause.
874+
///
875+
OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
876+
: OMPClause(OMPC_capture, StartLoc, EndLoc) {}
877+
878+
/// \brief Build an empty clause.
879+
///
880+
OMPCaptureClause()
881+
: OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
882+
883+
static bool classof(const OMPClause *T) {
884+
return T->getClauseKind() == OMPC_capture;
885+
}
886+
887+
StmtRange children() { return StmtRange(); }
888+
};
889+
860890
/// \brief This represents clause 'private' in the '#pragma omp ...' directives.
861891
///
862892
/// \code

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,11 @@ bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
24572457
return true;
24582458
}
24592459

2460+
template <typename Derived>
2461+
bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
2462+
return true;
2463+
}
2464+
24602465
template <typename Derived>
24612466
template <typename T>
24622467
bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7157,6 +7157,14 @@ def err_omp_atomic_write_not_expression_statement : Error<
71577157
def err_omp_atomic_update_not_expression_statement : Error<
71587158
"the statement for 'atomic%select{| update}0' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x',"
71597159
" where x is an l-value expression with scalar type">;
7160+
def err_omp_atomic_capture_not_expression_statement : Error<
7161+
"the statement for 'atomic capture' must be an expression statement of form 'v = ++x;', 'v = --x;', 'v = x++;', 'v = x--;', 'v = x binop= expr;', 'v = x = x binop expr' or 'v = x = expr binop x',"
7162+
" where x and v are both l-value expressions with scalar type">;
7163+
def err_omp_atomic_capture_not_compound_statement : Error<
7164+
"the statement for 'atomic capture' must be a compound statement of form '{v = x; x binop= expr;}', '{x binop= expr; v = x;}',"
7165+
" '{v = x; x = x binop expr;}', '{v = x; x = expr binop x;}', '{x = x binop expr; v = x;}', '{x = expr binop x; v = x;}' or '{v = x; x = expr;}',"
7166+
" '{v = x; x++;}', '{v = x; ++x;}', '{++x; v = x;}', '{x++; v = x;}', '{v = x; x--;}', '{v = x; --x;}', '{--x; v = x;}', '{x--; v = x;}'"
7167+
" where x is an l-value expression with scalar type">;
71607168
def err_omp_atomic_several_clauses : Error<
71617169
"directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update' or 'capture' clause">;
71627170
def note_omp_atomic_previous_clause : Note<

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ OPENMP_CLAUSE(flush, OMPFlushClause)
104104
OPENMP_CLAUSE(read, OMPReadClause)
105105
OPENMP_CLAUSE(write, OMPWriteClause)
106106
OPENMP_CLAUSE(update, OMPUpdateClause)
107+
OPENMP_CLAUSE(capture, OMPCaptureClause)
107108

108109
// Clauses allowed for OpenMP directive 'parallel'.
109110
OPENMP_PARALLEL_CLAUSE(if)
@@ -205,6 +206,7 @@ OPENMP_TASK_CLAUSE(mergeable)
205206
OPENMP_ATOMIC_CLAUSE(read)
206207
OPENMP_ATOMIC_CLAUSE(write)
207208
OPENMP_ATOMIC_CLAUSE(update)
209+
OPENMP_ATOMIC_CLAUSE(capture)
208210

209211
#undef OPENMP_SCHEDULE_KIND
210212
#undef OPENMP_PROC_BIND_KIND

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7491,6 +7491,9 @@ class Sema {
74917491
/// \brief Called on well-formed 'update' clause.
74927492
OMPClause *ActOnOpenMPUpdateClause(SourceLocation StartLoc,
74937493
SourceLocation EndLoc);
7494+
/// \brief Called on well-formed 'capture' clause.
7495+
OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc,
7496+
SourceLocation EndLoc);
74947497

74957498
OMPClause *
74967499
ActOnOpenMPVarListClause(OpenMPClauseKind Kind, ArrayRef<Expr *> Vars,

clang/lib/AST/StmtPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
673673
OS << "update";
674674
}
675675

676+
void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
677+
OS << "capture";
678+
}
679+
676680
template<typename T>
677681
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
678682
for (typename T::varlist_iterator I = Node->varlist_begin(),

clang/lib/AST/StmtProfile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
316316

317317
void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
318318

319+
void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
320+
319321
template<typename T>
320322
void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
321323
for (auto *I : Node->varlists())

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
111111
case OMPC_read:
112112
case OMPC_write:
113113
case OMPC_update:
114+
case OMPC_capture:
114115
break;
115116
}
116117
llvm_unreachable("Invalid OpenMP simple clause kind");
@@ -173,6 +174,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
173174
case OMPC_read:
174175
case OMPC_write:
175176
case OMPC_update:
177+
case OMPC_capture:
176178
break;
177179
}
178180
llvm_unreachable("Invalid OpenMP simple clause kind");

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
343343
/// lastprivate-clause | reduction-clause | proc_bind-clause |
344344
/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
345345
/// mergeable-clause | flush-clause | read-clause | write-clause |
346-
/// update-clause
346+
/// update-clause | capture-clause
347347
///
348348
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
349349
OpenMPClauseKind CKind, bool FirstClause) {
@@ -412,6 +412,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
412412
case OMPC_read:
413413
case OMPC_write:
414414
case OMPC_update:
415+
case OMPC_capture:
415416
// OpenMP [2.7.1, Restrictions, p. 9]
416417
// Only one ordered clause can appear on a loop directive.
417418
// OpenMP [2.7.1, Restrictions, C/C++, p. 4]

0 commit comments

Comments
 (0)