2013-03-22 14:34:35 +08:00
|
|
|
//===--- ParseOpenMP.cpp - OpenMP directives parsing ----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// \brief This file implements parsing of all OpenMP directives and clauses.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-01-07 19:51:46 +08:00
|
|
|
#include "RAIIObjectsForParser.h"
|
2014-05-06 18:08:46 +08:00
|
|
|
#include "clang/AST/ASTConsumer.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
2013-07-19 11:13:43 +08:00
|
|
|
#include "clang/AST/StmtOpenMP.h"
|
2013-03-22 14:34:35 +08:00
|
|
|
#include "clang/Parse/ParseDiagnostic.h"
|
2013-05-13 12:18:18 +08:00
|
|
|
#include "clang/Parse/Parser.h"
|
|
|
|
#include "clang/Sema/Scope.h"
|
|
|
|
#include "llvm/ADT/PointerIntPair.h"
|
2015-07-21 21:44:28 +08:00
|
|
|
|
2013-03-22 14:34:35 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// OpenMP declarative directives.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-07-07 21:01:15 +08:00
|
|
|
static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
|
2014-09-18 13:12:34 +08:00
|
|
|
// Array of foldings: F[i][0] F[i][1] ===> F[i][2].
|
|
|
|
// E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd
|
|
|
|
// TODO: add other combined directives in topological order.
|
|
|
|
const OpenMPDirectiveKind F[][3] = {
|
2015-07-01 14:57:41 +08:00
|
|
|
{OMPD_unknown /*cancellation*/, OMPD_unknown /*point*/,
|
|
|
|
OMPD_cancellation_point},
|
2015-07-21 21:44:28 +08:00
|
|
|
{OMPD_target, OMPD_unknown /*data*/, OMPD_target_data},
|
2015-07-01 14:57:41 +08:00
|
|
|
{OMPD_for, OMPD_simd, OMPD_for_simd},
|
|
|
|
{OMPD_parallel, OMPD_for, OMPD_parallel_for},
|
|
|
|
{OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd},
|
|
|
|
{OMPD_parallel, OMPD_sections, OMPD_parallel_sections}};
|
2014-07-07 21:01:15 +08:00
|
|
|
auto Tok = P.getCurToken();
|
|
|
|
auto DKind =
|
|
|
|
Tok.isAnnotation()
|
|
|
|
? OMPD_unknown
|
|
|
|
: getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
|
2015-07-21 21:44:28 +08:00
|
|
|
|
2015-07-01 14:57:41 +08:00
|
|
|
bool TokenMatched = false;
|
2014-09-18 13:12:34 +08:00
|
|
|
for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) {
|
2015-07-01 14:57:41 +08:00
|
|
|
if (!Tok.isAnnotation() && DKind == OMPD_unknown) {
|
|
|
|
TokenMatched =
|
|
|
|
(i == 0) &&
|
|
|
|
!P.getPreprocessor().getSpelling(Tok).compare("cancellation");
|
|
|
|
} else {
|
|
|
|
TokenMatched = DKind == F[i][0] && DKind != OMPD_unknown;
|
|
|
|
}
|
2015-07-21 21:44:28 +08:00
|
|
|
|
2015-07-01 14:57:41 +08:00
|
|
|
if (TokenMatched) {
|
2014-09-18 13:12:34 +08:00
|
|
|
Tok = P.getPreprocessor().LookAhead(0);
|
2015-07-21 21:44:28 +08:00
|
|
|
auto TokenIsAnnotation = Tok.isAnnotation();
|
2014-09-18 13:12:34 +08:00
|
|
|
auto SDKind =
|
2015-07-21 21:44:28 +08:00
|
|
|
TokenIsAnnotation
|
2014-09-18 13:12:34 +08:00
|
|
|
? OMPD_unknown
|
|
|
|
: getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
|
2015-07-21 21:44:28 +08:00
|
|
|
|
|
|
|
if (!TokenIsAnnotation && SDKind == OMPD_unknown) {
|
2015-07-01 14:57:41 +08:00
|
|
|
TokenMatched =
|
2015-07-22 00:18:51 +08:00
|
|
|
((i == 0) &&
|
|
|
|
!P.getPreprocessor().getSpelling(Tok).compare("point")) ||
|
|
|
|
((i == 1) && !P.getPreprocessor().getSpelling(Tok).compare("data"));
|
2015-07-01 14:57:41 +08:00
|
|
|
} else {
|
|
|
|
TokenMatched = SDKind == F[i][1] && SDKind != OMPD_unknown;
|
|
|
|
}
|
2015-07-21 21:44:28 +08:00
|
|
|
|
2015-07-01 14:57:41 +08:00
|
|
|
if (TokenMatched) {
|
2014-09-18 13:12:34 +08:00
|
|
|
P.ConsumeToken();
|
|
|
|
DKind = F[i][2];
|
|
|
|
}
|
2014-07-07 21:01:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return DKind;
|
|
|
|
}
|
|
|
|
|
2013-05-13 12:18:18 +08:00
|
|
|
/// \brief Parsing of declarative OpenMP directives.
|
|
|
|
///
|
|
|
|
/// threadprivate-directive:
|
|
|
|
/// annot_pragma_openmp 'threadprivate' simple-variable-list
|
2013-03-22 14:34:35 +08:00
|
|
|
///
|
|
|
|
Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
|
2013-11-18 16:17:37 +08:00
|
|
|
ParenBraceBracketBalancer BalancerRAIIObj(*this);
|
2013-03-22 14:34:35 +08:00
|
|
|
|
|
|
|
SourceLocation Loc = ConsumeToken();
|
2013-05-13 12:18:18 +08:00
|
|
|
SmallVector<Expr *, 5> Identifiers;
|
2014-07-07 21:01:15 +08:00
|
|
|
auto DKind = ParseOpenMPDirectiveKind(*this);
|
2013-05-13 12:18:18 +08:00
|
|
|
|
|
|
|
switch (DKind) {
|
2013-03-22 14:34:35 +08:00
|
|
|
case OMPD_threadprivate:
|
|
|
|
ConsumeToken();
|
2013-05-13 12:18:18 +08:00
|
|
|
if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) {
|
2013-03-22 14:34:35 +08:00
|
|
|
// The last seen token is annot_pragma_openmp_end - need to check for
|
|
|
|
// extra tokens.
|
|
|
|
if (Tok.isNot(tok::annot_pragma_openmp_end)) {
|
|
|
|
Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
|
2014-05-28 14:15:33 +08:00
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate);
|
2013-12-19 03:10:49 +08:00
|
|
|
SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
2013-05-13 12:18:18 +08:00
|
|
|
// Skip the last annot_pragma_openmp_end.
|
2013-03-22 14:34:35 +08:00
|
|
|
ConsumeToken();
|
2014-05-28 14:15:33 +08:00
|
|
|
return Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OMPD_unknown:
|
|
|
|
Diag(Tok, diag::err_omp_unknown_directive);
|
|
|
|
break;
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPD_parallel:
|
2014-02-27 16:29:12 +08:00
|
|
|
case OMPD_simd:
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPD_task:
|
2014-07-18 15:47:19 +08:00
|
|
|
case OMPD_taskyield:
|
2014-07-18 17:11:51 +08:00
|
|
|
case OMPD_barrier:
|
2014-07-18 18:17:07 +08:00
|
|
|
case OMPD_taskwait:
|
2015-06-18 20:14:09 +08:00
|
|
|
case OMPD_taskgroup:
|
2014-07-21 19:26:11 +08:00
|
|
|
case OMPD_flush:
|
2014-06-18 12:14:57 +08:00
|
|
|
case OMPD_for:
|
2014-09-18 13:12:34 +08:00
|
|
|
case OMPD_for_simd:
|
2014-06-25 19:44:49 +08:00
|
|
|
case OMPD_sections:
|
2014-06-26 16:21:58 +08:00
|
|
|
case OMPD_section:
|
2014-06-26 20:05:45 +08:00
|
|
|
case OMPD_single:
|
2014-07-17 16:54:58 +08:00
|
|
|
case OMPD_master:
|
2014-07-22 14:45:04 +08:00
|
|
|
case OMPD_ordered:
|
2014-07-21 17:42:05 +08:00
|
|
|
case OMPD_critical:
|
2014-07-07 21:01:15 +08:00
|
|
|
case OMPD_parallel_for:
|
2014-09-23 17:33:00 +08:00
|
|
|
case OMPD_parallel_for_simd:
|
2014-07-08 16:12:03 +08:00
|
|
|
case OMPD_parallel_sections:
|
2014-07-22 18:10:35 +08:00
|
|
|
case OMPD_atomic:
|
2014-09-19 16:19:49 +08:00
|
|
|
case OMPD_target:
|
2014-10-09 12:18:56 +08:00
|
|
|
case OMPD_teams:
|
2015-07-01 14:57:41 +08:00
|
|
|
case OMPD_cancellation_point:
|
2015-07-02 19:25:17 +08:00
|
|
|
case OMPD_cancel:
|
2015-07-23 00:02:46 +08:00
|
|
|
case OMPD_target_data:
|
2013-03-22 14:34:35 +08:00
|
|
|
Diag(Tok, diag::err_omp_unexpected_directive)
|
2014-05-28 14:15:33 +08:00
|
|
|
<< getOpenMPDirectiveName(DKind);
|
2013-03-22 14:34:35 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-12-19 03:10:49 +08:00
|
|
|
SkipUntil(tok::annot_pragma_openmp_end);
|
2013-03-22 14:34:35 +08:00
|
|
|
return DeclGroupPtrTy();
|
|
|
|
}
|
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
/// \brief Parsing of declarative or executable OpenMP directives.
|
|
|
|
///
|
|
|
|
/// threadprivate-directive:
|
|
|
|
/// annot_pragma_openmp 'threadprivate' simple-variable-list
|
|
|
|
/// annot_pragma_openmp_end
|
|
|
|
///
|
2014-06-25 19:44:49 +08:00
|
|
|
/// executable-directive:
|
2014-06-26 20:05:45 +08:00
|
|
|
/// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' |
|
2014-07-21 17:42:05 +08:00
|
|
|
/// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] |
|
|
|
|
/// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' |
|
2014-09-18 13:12:34 +08:00
|
|
|
/// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' |
|
2015-07-21 21:44:28 +08:00
|
|
|
/// 'for simd' | 'parallel for simd' | 'target' | 'target data' |
|
|
|
|
/// 'taskgroup' | 'teams' {clause}
|
2014-07-22 14:45:04 +08:00
|
|
|
/// annot_pragma_openmp_end
|
2013-07-19 11:13:43 +08:00
|
|
|
///
|
2014-07-18 15:47:19 +08:00
|
|
|
StmtResult
|
|
|
|
Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed) {
|
2013-07-19 11:13:43 +08:00
|
|
|
assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
|
2013-11-18 16:17:37 +08:00
|
|
|
ParenBraceBracketBalancer BalancerRAIIObj(*this);
|
2013-07-19 11:13:43 +08:00
|
|
|
SmallVector<Expr *, 5> Identifiers;
|
|
|
|
SmallVector<OMPClause *, 5> Clauses;
|
2014-05-12 12:23:46 +08:00
|
|
|
SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1>
|
2014-05-28 14:15:33 +08:00
|
|
|
FirstClauses(OMPC_unknown + 1);
|
2014-06-03 18:16:47 +08:00
|
|
|
unsigned ScopeFlags =
|
2014-05-28 14:15:33 +08:00
|
|
|
Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope;
|
2013-07-19 11:13:43 +08:00
|
|
|
SourceLocation Loc = ConsumeToken(), EndLoc;
|
2014-07-07 21:01:15 +08:00
|
|
|
auto DKind = ParseOpenMPDirectiveKind(*this);
|
2015-07-01 14:57:41 +08:00
|
|
|
OpenMPDirectiveKind CancelRegion = OMPD_unknown;
|
2013-09-07 02:03:48 +08:00
|
|
|
// Name of critical directive.
|
|
|
|
DeclarationNameInfo DirName;
|
2013-07-19 11:13:43 +08:00
|
|
|
StmtResult Directive = StmtError();
|
2014-07-18 15:47:19 +08:00
|
|
|
bool HasAssociatedStatement = true;
|
2014-07-21 19:26:11 +08:00
|
|
|
bool FlushHasClause = false;
|
2013-07-19 11:13:43 +08:00
|
|
|
|
|
|
|
switch (DKind) {
|
|
|
|
case OMPD_threadprivate:
|
|
|
|
ConsumeToken();
|
|
|
|
if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) {
|
|
|
|
// The last seen token is annot_pragma_openmp_end - need to check for
|
|
|
|
// extra tokens.
|
|
|
|
if (Tok.isNot(tok::annot_pragma_openmp_end)) {
|
|
|
|
Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
|
2014-05-28 14:15:33 +08:00
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate);
|
2013-12-19 03:10:49 +08:00
|
|
|
SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
|
|
|
DeclGroupPtrTy Res =
|
2014-05-28 14:15:33 +08:00
|
|
|
Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
|
2013-07-19 11:13:43 +08:00
|
|
|
Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
|
|
|
|
}
|
2013-12-19 03:10:49 +08:00
|
|
|
SkipUntil(tok::annot_pragma_openmp_end);
|
2013-07-19 11:13:43 +08:00
|
|
|
break;
|
2014-07-21 19:26:11 +08:00
|
|
|
case OMPD_flush:
|
|
|
|
if (PP.LookAhead(0).is(tok::l_paren)) {
|
|
|
|
FlushHasClause = true;
|
|
|
|
// Push copy of the current token back to stream to properly parse
|
|
|
|
// pseudo-clause OMPFlushClause.
|
|
|
|
PP.EnterToken(Tok);
|
|
|
|
}
|
2014-07-18 15:47:19 +08:00
|
|
|
case OMPD_taskyield:
|
2014-07-18 17:11:51 +08:00
|
|
|
case OMPD_barrier:
|
2014-07-18 18:17:07 +08:00
|
|
|
case OMPD_taskwait:
|
2015-07-01 14:57:41 +08:00
|
|
|
case OMPD_cancellation_point:
|
2015-07-02 19:25:17 +08:00
|
|
|
case OMPD_cancel:
|
2014-07-18 15:47:19 +08:00
|
|
|
if (!StandAloneAllowed) {
|
|
|
|
Diag(Tok, diag::err_omp_immediate_directive)
|
|
|
|
<< getOpenMPDirectiveName(DKind);
|
|
|
|
}
|
|
|
|
HasAssociatedStatement = false;
|
2014-07-21 19:26:11 +08:00
|
|
|
// Fall through for further analysis.
|
2014-02-27 16:29:12 +08:00
|
|
|
case OMPD_parallel:
|
2014-06-18 12:14:57 +08:00
|
|
|
case OMPD_simd:
|
2014-06-25 19:44:49 +08:00
|
|
|
case OMPD_for:
|
2014-09-18 13:12:34 +08:00
|
|
|
case OMPD_for_simd:
|
2014-06-26 16:21:58 +08:00
|
|
|
case OMPD_sections:
|
2014-06-26 20:05:45 +08:00
|
|
|
case OMPD_single:
|
2014-07-07 21:01:15 +08:00
|
|
|
case OMPD_section:
|
2014-07-17 16:54:58 +08:00
|
|
|
case OMPD_master:
|
2014-07-21 17:42:05 +08:00
|
|
|
case OMPD_critical:
|
2014-07-08 16:12:03 +08:00
|
|
|
case OMPD_parallel_for:
|
2014-09-23 17:33:00 +08:00
|
|
|
case OMPD_parallel_for_simd:
|
2014-07-11 19:25:16 +08:00
|
|
|
case OMPD_parallel_sections:
|
2014-07-22 14:45:04 +08:00
|
|
|
case OMPD_task:
|
2014-07-22 18:10:35 +08:00
|
|
|
case OMPD_ordered:
|
2014-09-19 16:19:49 +08:00
|
|
|
case OMPD_atomic:
|
2014-10-09 12:18:56 +08:00
|
|
|
case OMPD_target:
|
2015-06-18 20:14:09 +08:00
|
|
|
case OMPD_teams:
|
2015-07-21 21:44:28 +08:00
|
|
|
case OMPD_taskgroup:
|
|
|
|
case OMPD_target_data: {
|
2013-07-19 11:13:43 +08:00
|
|
|
ConsumeToken();
|
2014-07-21 17:42:05 +08:00
|
|
|
// Parse directive name of the 'critical' directive if any.
|
|
|
|
if (DKind == OMPD_critical) {
|
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren,
|
|
|
|
tok::annot_pragma_openmp_end);
|
|
|
|
if (!T.consumeOpen()) {
|
|
|
|
if (Tok.isAnyIdentifier()) {
|
|
|
|
DirName =
|
|
|
|
DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation());
|
|
|
|
ConsumeAnyToken();
|
|
|
|
} else {
|
|
|
|
Diag(Tok, diag::err_omp_expected_identifier_for_critical);
|
|
|
|
}
|
|
|
|
T.consumeClose();
|
|
|
|
}
|
2015-07-02 19:25:17 +08:00
|
|
|
} else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
|
2015-07-01 14:57:41 +08:00
|
|
|
CancelRegion = ParseOpenMPDirectiveKind(*this);
|
|
|
|
if (Tok.isNot(tok::annot_pragma_openmp_end))
|
|
|
|
ConsumeToken();
|
2014-07-21 17:42:05 +08:00
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
|
2014-06-18 12:14:57 +08:00
|
|
|
if (isOpenMPLoopDirective(DKind))
|
|
|
|
ScopeFlags |= Scope::OpenMPLoopDirectiveScope;
|
|
|
|
if (isOpenMPSimdDirective(DKind))
|
|
|
|
ScopeFlags |= Scope::OpenMPSimdDirectiveScope;
|
|
|
|
ParseScope OMPDirectiveScope(this, ScopeFlags);
|
2014-06-27 18:37:06 +08:00
|
|
|
Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
|
2013-09-07 02:03:48 +08:00
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
while (Tok.isNot(tok::annot_pragma_openmp_end)) {
|
2014-07-21 19:26:11 +08:00
|
|
|
OpenMPClauseKind CKind =
|
|
|
|
Tok.isAnnotation()
|
|
|
|
? OMPC_unknown
|
|
|
|
: FlushHasClause ? OMPC_flush
|
|
|
|
: getOpenMPClauseKind(PP.getSpelling(Tok));
|
2015-06-23 12:51:00 +08:00
|
|
|
Actions.StartOpenMPClause(CKind);
|
2014-07-21 19:26:11 +08:00
|
|
|
FlushHasClause = false;
|
2014-05-28 14:15:33 +08:00
|
|
|
OMPClause *Clause =
|
|
|
|
ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt());
|
2013-07-19 11:13:43 +08:00
|
|
|
FirstClauses[CKind].setInt(true);
|
|
|
|
if (Clause) {
|
|
|
|
FirstClauses[CKind].setPointer(Clause);
|
|
|
|
Clauses.push_back(Clause);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip ',' if any.
|
|
|
|
if (Tok.is(tok::comma))
|
|
|
|
ConsumeToken();
|
2015-06-23 12:51:00 +08:00
|
|
|
Actions.EndOpenMPClause();
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
|
|
|
// End location of the directive.
|
|
|
|
EndLoc = Tok.getLocation();
|
|
|
|
// Consume final annot_pragma_openmp_end.
|
|
|
|
ConsumeToken();
|
|
|
|
|
|
|
|
StmtResult AssociatedStmt;
|
|
|
|
bool CreateDirective = true;
|
2014-07-18 15:47:19 +08:00
|
|
|
if (HasAssociatedStatement) {
|
2013-07-19 11:13:43 +08:00
|
|
|
// The body is a block scope like in Lambdas and Blocks.
|
|
|
|
Sema::CompoundScopeRAII CompoundScope(Actions);
|
2014-06-27 18:37:06 +08:00
|
|
|
Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
|
2013-07-19 11:13:43 +08:00
|
|
|
Actions.ActOnStartOfCompoundStmt();
|
|
|
|
// Parse statement
|
|
|
|
AssociatedStmt = ParseStatement();
|
|
|
|
Actions.ActOnFinishOfCompoundStmt();
|
2015-04-02 15:48:16 +08:00
|
|
|
AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
|
|
|
|
CreateDirective = AssociatedStmt.isUsable();
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
|
|
|
if (CreateDirective)
|
2014-05-28 14:15:33 +08:00
|
|
|
Directive = Actions.ActOnOpenMPExecutableDirective(
|
2015-07-01 14:57:41 +08:00
|
|
|
DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc,
|
|
|
|
EndLoc);
|
2013-07-19 11:13:43 +08:00
|
|
|
|
|
|
|
// Exit scope.
|
2013-09-07 02:03:48 +08:00
|
|
|
Actions.EndOpenMPDSABlock(Directive.get());
|
2013-07-19 11:13:43 +08:00
|
|
|
OMPDirectiveScope.Exit();
|
|
|
|
break;
|
2014-05-28 14:15:33 +08:00
|
|
|
}
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPD_unknown:
|
|
|
|
Diag(Tok, diag::err_omp_unknown_directive);
|
2013-12-19 03:10:49 +08:00
|
|
|
SkipUntil(tok::annot_pragma_openmp_end);
|
2013-07-19 11:13:43 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return Directive;
|
|
|
|
}
|
|
|
|
|
2013-03-22 14:34:35 +08:00
|
|
|
/// \brief Parses list of simple variables for '#pragma omp threadprivate'
|
2013-05-13 12:18:18 +08:00
|
|
|
/// directive.
|
|
|
|
///
|
|
|
|
/// simple-variable-list:
|
|
|
|
/// '(' id-expression {, id-expression} ')'
|
2013-03-22 14:34:35 +08:00
|
|
|
///
|
2013-05-13 12:18:18 +08:00
|
|
|
bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
|
|
|
|
SmallVectorImpl<Expr *> &VarList,
|
|
|
|
bool AllowScopeSpecifier) {
|
|
|
|
VarList.clear();
|
2013-03-22 14:34:35 +08:00
|
|
|
// Parse '('.
|
2013-12-19 03:10:49 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
|
2013-07-19 11:13:43 +08:00
|
|
|
if (T.expectAndConsume(diag::err_expected_lparen_after,
|
|
|
|
getOpenMPDirectiveName(Kind)))
|
|
|
|
return true;
|
|
|
|
bool IsCorrect = true;
|
2013-05-13 12:18:18 +08:00
|
|
|
bool NoIdentIsFound = true;
|
2013-03-22 14:34:35 +08:00
|
|
|
|
|
|
|
// Read tokens while ')' or annot_pragma_openmp_end is not found.
|
2013-05-13 12:18:18 +08:00
|
|
|
while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
|
2013-03-22 14:34:35 +08:00
|
|
|
CXXScopeSpec SS;
|
|
|
|
SourceLocation TemplateKWLoc;
|
|
|
|
UnqualifiedId Name;
|
|
|
|
// Read var name.
|
|
|
|
Token PrevTok = Tok;
|
2013-05-13 12:18:18 +08:00
|
|
|
NoIdentIsFound = false;
|
2013-03-22 14:34:35 +08:00
|
|
|
|
2013-05-13 12:18:18 +08:00
|
|
|
if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
|
|
|
|
ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false)) {
|
2013-03-22 14:34:35 +08:00
|
|
|
IsCorrect = false;
|
|
|
|
SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
|
2013-12-19 03:10:49 +08:00
|
|
|
StopBeforeMatch);
|
2013-05-13 12:18:18 +08:00
|
|
|
} else if (ParseUnqualifiedId(SS, false, false, false, ParsedType(),
|
|
|
|
TemplateKWLoc, Name)) {
|
|
|
|
IsCorrect = false;
|
|
|
|
SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
|
2013-12-19 03:10:49 +08:00
|
|
|
StopBeforeMatch);
|
2013-05-13 12:18:18 +08:00
|
|
|
} else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
|
|
|
|
Tok.isNot(tok::annot_pragma_openmp_end)) {
|
2013-03-22 14:34:35 +08:00
|
|
|
IsCorrect = false;
|
|
|
|
SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
|
2013-12-19 03:10:49 +08:00
|
|
|
StopBeforeMatch);
|
2013-12-24 17:48:30 +08:00
|
|
|
Diag(PrevTok.getLocation(), diag::err_expected)
|
|
|
|
<< tok::identifier
|
|
|
|
<< SourceRange(PrevTok.getLocation(), PrevTokLocation);
|
2013-03-22 14:34:35 +08:00
|
|
|
} else {
|
2013-05-13 12:18:18 +08:00
|
|
|
DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name);
|
2014-05-28 14:15:33 +08:00
|
|
|
ExprResult Res =
|
|
|
|
Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo);
|
2013-05-13 12:18:18 +08:00
|
|
|
if (Res.isUsable())
|
2014-05-29 18:55:11 +08:00
|
|
|
VarList.push_back(Res.get());
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
|
|
|
// Consume ','.
|
|
|
|
if (Tok.is(tok::comma)) {
|
|
|
|
ConsumeToken();
|
|
|
|
}
|
2013-05-13 12:18:18 +08:00
|
|
|
}
|
2013-03-22 14:34:35 +08:00
|
|
|
|
2013-05-13 12:18:18 +08:00
|
|
|
if (NoIdentIsFound) {
|
2013-12-24 17:48:30 +08:00
|
|
|
Diag(Tok, diag::err_expected) << tok::identifier;
|
2013-05-13 12:18:18 +08:00
|
|
|
IsCorrect = false;
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
|
|
|
|
2013-05-13 12:18:18 +08:00
|
|
|
// Parse ')'.
|
2013-07-19 11:13:43 +08:00
|
|
|
IsCorrect = !T.consumeClose() && IsCorrect;
|
2013-05-13 12:18:18 +08:00
|
|
|
|
|
|
|
return !IsCorrect && VarList.empty();
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
2013-07-19 11:13:43 +08:00
|
|
|
|
|
|
|
/// \brief Parsing of OpenMP clauses.
|
|
|
|
///
|
|
|
|
/// clause:
|
2014-07-17 15:32:53 +08:00
|
|
|
/// if-clause | final-clause | num_threads-clause | safelen-clause |
|
|
|
|
/// default-clause | private-clause | firstprivate-clause | shared-clause
|
|
|
|
/// | linear-clause | aligned-clause | collapse-clause |
|
|
|
|
/// lastprivate-clause | reduction-clause | proc_bind-clause |
|
2014-07-17 20:47:03 +08:00
|
|
|
/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
|
2014-07-23 18:25:33 +08:00
|
|
|
/// mergeable-clause | flush-clause | read-clause | write-clause |
|
2015-08-21 19:14:16 +08:00
|
|
|
/// update-clause | capture-clause | seq_cst-clause | device-clause |
|
|
|
|
/// simdlen-clause
|
2013-07-19 11:13:43 +08:00
|
|
|
///
|
|
|
|
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
|
|
|
|
OpenMPClauseKind CKind, bool FirstClause) {
|
2014-05-21 14:02:52 +08:00
|
|
|
OMPClause *Clause = nullptr;
|
2013-07-19 11:13:43 +08:00
|
|
|
bool ErrorFound = false;
|
|
|
|
// Check if clause is allowed for the given directive.
|
|
|
|
if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
|
2014-05-28 14:15:33 +08:00
|
|
|
Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
|
|
|
|
<< getOpenMPDirectiveName(DKind);
|
2013-07-19 11:13:43 +08:00
|
|
|
ErrorFound = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (CKind) {
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_if:
|
2014-07-17 15:32:53 +08:00
|
|
|
case OMPC_final:
|
2014-03-06 14:15:19 +08:00
|
|
|
case OMPC_num_threads:
|
2014-03-21 12:51:18 +08:00
|
|
|
case OMPC_safelen:
|
2015-08-21 19:14:16 +08:00
|
|
|
case OMPC_simdlen:
|
2014-05-27 23:12:19 +08:00
|
|
|
case OMPC_collapse:
|
2015-07-30 19:36:16 +08:00
|
|
|
case OMPC_ordered:
|
2015-08-08 00:16:36 +08:00
|
|
|
case OMPC_device:
|
2014-02-13 13:29:23 +08:00
|
|
|
// OpenMP [2.5, Restrictions]
|
|
|
|
// At most one if clause can appear on the directive.
|
2014-03-06 14:15:19 +08:00
|
|
|
// At most one num_threads clause can appear on the directive.
|
2014-03-21 12:51:18 +08:00
|
|
|
// OpenMP [2.8.1, simd construct, Restrictions]
|
2014-05-27 23:12:19 +08:00
|
|
|
// Only one safelen clause can appear on a simd directive.
|
2015-08-21 19:14:16 +08:00
|
|
|
// Only one simdlen clause can appear on a simd directive.
|
2014-05-27 23:12:19 +08:00
|
|
|
// Only one collapse clause can appear on a simd directive.
|
2015-08-08 00:16:36 +08:00
|
|
|
// OpenMP [2.9.1, target data construct, Restrictions]
|
|
|
|
// At most one device clause can appear on the directive.
|
2014-07-17 15:32:53 +08:00
|
|
|
// OpenMP [2.11.1, task Construct, Restrictions]
|
|
|
|
// At most one if clause can appear on the directive.
|
|
|
|
// At most one final clause can appear on the directive.
|
2014-02-13 13:29:23 +08:00
|
|
|
if (!FirstClause) {
|
2014-05-28 14:15:33 +08:00
|
|
|
Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
|
|
|
|
<< getOpenMPClauseName(CKind);
|
2014-07-23 15:46:59 +08:00
|
|
|
ErrorFound = true;
|
2014-02-13 13:29:23 +08:00
|
|
|
}
|
|
|
|
|
2015-07-30 19:36:16 +08:00
|
|
|
if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren))
|
|
|
|
Clause = ParseOpenMPClause(CKind);
|
|
|
|
else
|
|
|
|
Clause = ParseOpenMPSingleExprClause(CKind);
|
2014-02-13 13:29:23 +08:00
|
|
|
break;
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPC_default:
|
2014-05-06 14:04:14 +08:00
|
|
|
case OMPC_proc_bind:
|
2014-02-13 13:29:23 +08:00
|
|
|
// OpenMP [2.14.3.1, Restrictions]
|
|
|
|
// Only a single default clause may be specified on a parallel, task or
|
|
|
|
// teams directive.
|
2014-05-06 14:04:14 +08:00
|
|
|
// OpenMP [2.5, parallel Construct, Restrictions]
|
|
|
|
// At most one proc_bind clause can appear on the directive.
|
2013-07-19 11:13:43 +08:00
|
|
|
if (!FirstClause) {
|
2014-05-28 14:15:33 +08:00
|
|
|
Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
|
|
|
|
<< getOpenMPClauseName(CKind);
|
2014-07-23 15:46:59 +08:00
|
|
|
ErrorFound = true;
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Clause = ParseOpenMPSimpleClause(CKind);
|
|
|
|
break;
|
2014-06-20 15:16:17 +08:00
|
|
|
case OMPC_schedule:
|
|
|
|
// OpenMP [2.7.1, Restrictions, p. 3]
|
|
|
|
// Only one schedule clause can appear on a loop directive.
|
|
|
|
if (!FirstClause) {
|
|
|
|
Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
|
|
|
|
<< getOpenMPClauseName(CKind);
|
2014-07-23 15:46:59 +08:00
|
|
|
ErrorFound = true;
|
2014-06-20 15:16:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Clause = ParseOpenMPSingleExprWithArgClause(CKind);
|
|
|
|
break;
|
2014-06-20 19:19:47 +08:00
|
|
|
case OMPC_nowait:
|
2014-07-17 20:19:31 +08:00
|
|
|
case OMPC_untied:
|
2014-07-17 20:47:03 +08:00
|
|
|
case OMPC_mergeable:
|
2014-07-23 10:27:21 +08:00
|
|
|
case OMPC_read:
|
2014-07-23 15:46:59 +08:00
|
|
|
case OMPC_write:
|
2014-07-23 18:25:33 +08:00
|
|
|
case OMPC_update:
|
2014-07-24 14:46:57 +08:00
|
|
|
case OMPC_capture:
|
2014-07-24 16:55:34 +08:00
|
|
|
case OMPC_seq_cst:
|
2014-06-20 17:44:06 +08:00
|
|
|
// OpenMP [2.7.1, Restrictions, p. 9]
|
|
|
|
// Only one ordered clause can appear on a loop directive.
|
2014-06-20 19:19:47 +08:00
|
|
|
// OpenMP [2.7.1, Restrictions, C/C++, p. 4]
|
|
|
|
// Only one nowait clause can appear on a for directive.
|
2014-06-20 17:44:06 +08:00
|
|
|
if (!FirstClause) {
|
|
|
|
Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
|
|
|
|
<< getOpenMPClauseName(CKind);
|
2014-07-23 15:46:59 +08:00
|
|
|
ErrorFound = true;
|
2014-06-20 17:44:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Clause = ParseOpenMPClause(CKind);
|
|
|
|
break;
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPC_private:
|
2013-10-01 13:32:34 +08:00
|
|
|
case OMPC_firstprivate:
|
2014-06-04 21:06:39 +08:00
|
|
|
case OMPC_lastprivate:
|
2013-09-07 02:03:48 +08:00
|
|
|
case OMPC_shared:
|
2014-06-16 15:08:35 +08:00
|
|
|
case OMPC_reduction:
|
2014-04-22 21:09:42 +08:00
|
|
|
case OMPC_linear:
|
2014-05-29 22:36:25 +08:00
|
|
|
case OMPC_aligned:
|
2014-03-31 11:36:38 +08:00
|
|
|
case OMPC_copyin:
|
2014-06-27 18:37:06 +08:00
|
|
|
case OMPC_copyprivate:
|
2014-07-21 19:26:11 +08:00
|
|
|
case OMPC_flush:
|
2015-06-23 22:25:19 +08:00
|
|
|
case OMPC_depend:
|
2013-07-19 11:13:43 +08:00
|
|
|
Clause = ParseOpenMPVarListClause(CKind);
|
|
|
|
break;
|
|
|
|
case OMPC_unknown:
|
|
|
|
Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
|
2014-05-28 14:15:33 +08:00
|
|
|
<< getOpenMPDirectiveName(DKind);
|
2013-12-19 03:10:49 +08:00
|
|
|
SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
|
2013-07-19 11:13:43 +08:00
|
|
|
break;
|
|
|
|
case OMPC_threadprivate:
|
2014-05-28 14:15:33 +08:00
|
|
|
Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
|
|
|
|
<< getOpenMPDirectiveName(DKind);
|
2013-12-19 03:10:49 +08:00
|
|
|
SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
|
2013-07-19 11:13:43 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-05-21 14:02:52 +08:00
|
|
|
return ErrorFound ? nullptr : Clause;
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
|
|
|
|
2014-02-13 13:29:23 +08:00
|
|
|
/// \brief Parsing of OpenMP clauses with single expressions like 'if',
|
2015-08-21 19:14:16 +08:00
|
|
|
/// 'final', 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams',
|
|
|
|
/// 'thread_limit' or 'simdlen'.
|
2014-02-13 13:29:23 +08:00
|
|
|
///
|
|
|
|
/// if-clause:
|
|
|
|
/// 'if' '(' expression ')'
|
|
|
|
///
|
2014-07-17 15:32:53 +08:00
|
|
|
/// final-clause:
|
|
|
|
/// 'final' '(' expression ')'
|
|
|
|
///
|
2014-03-21 12:51:18 +08:00
|
|
|
/// num_threads-clause:
|
|
|
|
/// 'num_threads' '(' expression ')'
|
|
|
|
///
|
|
|
|
/// safelen-clause:
|
|
|
|
/// 'safelen' '(' expression ')'
|
|
|
|
///
|
2015-08-21 19:14:16 +08:00
|
|
|
/// simdlen-clause:
|
|
|
|
/// 'simdlen' '(' expression ')'
|
|
|
|
///
|
2014-05-27 23:12:19 +08:00
|
|
|
/// collapse-clause:
|
|
|
|
/// 'collapse' '(' expression ')'
|
|
|
|
///
|
2014-02-13 13:29:23 +08:00
|
|
|
OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
|
|
|
|
SourceLocation Loc = ConsumeToken();
|
|
|
|
|
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
|
|
|
|
if (T.expectAndConsume(diag::err_expected_lparen_after,
|
|
|
|
getOpenMPClauseName(Kind)))
|
2014-05-21 14:02:52 +08:00
|
|
|
return nullptr;
|
2014-02-13 13:29:23 +08:00
|
|
|
|
|
|
|
ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
|
|
|
|
ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
|
|
|
|
|
|
|
|
// Parse ')'.
|
|
|
|
T.consumeClose();
|
|
|
|
|
|
|
|
if (Val.isInvalid())
|
2014-05-21 14:02:52 +08:00
|
|
|
return nullptr;
|
2014-02-13 13:29:23 +08:00
|
|
|
|
2014-05-28 14:15:33 +08:00
|
|
|
return Actions.ActOnOpenMPSingleExprClause(
|
2014-05-29 18:55:11 +08:00
|
|
|
Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation());
|
2014-02-13 13:29:23 +08:00
|
|
|
}
|
|
|
|
|
2014-05-06 14:04:14 +08:00
|
|
|
/// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
|
2013-07-19 11:13:43 +08:00
|
|
|
///
|
|
|
|
/// default-clause:
|
|
|
|
/// 'default' '(' 'none' | 'shared' ')
|
|
|
|
///
|
2014-05-06 14:04:14 +08:00
|
|
|
/// proc_bind-clause:
|
|
|
|
/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
|
|
|
|
///
|
2013-07-19 11:13:43 +08:00
|
|
|
OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
|
|
|
|
SourceLocation Loc = Tok.getLocation();
|
|
|
|
SourceLocation LOpen = ConsumeToken();
|
|
|
|
// Parse '('.
|
2013-12-19 03:10:49 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
|
2013-07-19 11:13:43 +08:00
|
|
|
if (T.expectAndConsume(diag::err_expected_lparen_after,
|
|
|
|
getOpenMPClauseName(Kind)))
|
2014-05-21 14:02:52 +08:00
|
|
|
return nullptr;
|
2013-07-19 11:13:43 +08:00
|
|
|
|
2014-05-28 14:15:33 +08:00
|
|
|
unsigned Type = getOpenMPSimpleClauseType(
|
|
|
|
Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
|
2013-07-19 11:13:43 +08:00
|
|
|
SourceLocation TypeLoc = Tok.getLocation();
|
|
|
|
if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
|
|
|
|
Tok.isNot(tok::annot_pragma_openmp_end))
|
|
|
|
ConsumeAnyToken();
|
|
|
|
|
|
|
|
// Parse ')'.
|
|
|
|
T.consumeClose();
|
|
|
|
|
|
|
|
return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
|
|
|
|
Tok.getLocation());
|
|
|
|
}
|
|
|
|
|
2014-06-20 17:44:06 +08:00
|
|
|
/// \brief Parsing of OpenMP clauses like 'ordered'.
|
|
|
|
///
|
|
|
|
/// ordered-clause:
|
|
|
|
/// 'ordered'
|
|
|
|
///
|
2014-06-20 19:19:47 +08:00
|
|
|
/// nowait-clause:
|
|
|
|
/// 'nowait'
|
|
|
|
///
|
2014-07-17 20:19:31 +08:00
|
|
|
/// untied-clause:
|
|
|
|
/// 'untied'
|
|
|
|
///
|
2014-07-17 20:47:03 +08:00
|
|
|
/// mergeable-clause:
|
|
|
|
/// 'mergeable'
|
|
|
|
///
|
2014-07-23 10:27:21 +08:00
|
|
|
/// read-clause:
|
|
|
|
/// 'read'
|
|
|
|
///
|
2014-06-20 17:44:06 +08:00
|
|
|
OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
|
|
|
|
SourceLocation Loc = Tok.getLocation();
|
|
|
|
ConsumeAnyToken();
|
|
|
|
|
|
|
|
return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-20 15:16:17 +08:00
|
|
|
/// \brief Parsing of OpenMP clauses with single expressions and some additional
|
|
|
|
/// argument like 'schedule' or 'dist_schedule'.
|
|
|
|
///
|
|
|
|
/// schedule-clause:
|
|
|
|
/// 'schedule' '(' kind [',' expression ] ')'
|
|
|
|
///
|
|
|
|
OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
|
|
|
|
SourceLocation Loc = ConsumeToken();
|
|
|
|
SourceLocation CommaLoc;
|
|
|
|
// Parse '('.
|
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
|
|
|
|
if (T.expectAndConsume(diag::err_expected_lparen_after,
|
|
|
|
getOpenMPClauseName(Kind)))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
ExprResult Val;
|
|
|
|
unsigned Type = getOpenMPSimpleClauseType(
|
|
|
|
Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
|
|
|
|
SourceLocation KLoc = Tok.getLocation();
|
|
|
|
if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
|
|
|
|
Tok.isNot(tok::annot_pragma_openmp_end))
|
|
|
|
ConsumeAnyToken();
|
|
|
|
|
|
|
|
if (Kind == OMPC_schedule &&
|
|
|
|
(Type == OMPC_SCHEDULE_static || Type == OMPC_SCHEDULE_dynamic ||
|
|
|
|
Type == OMPC_SCHEDULE_guided) &&
|
|
|
|
Tok.is(tok::comma)) {
|
|
|
|
CommaLoc = ConsumeAnyToken();
|
|
|
|
ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
|
|
|
|
Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
|
|
|
|
if (Val.isInvalid())
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse ')'.
|
|
|
|
T.consumeClose();
|
|
|
|
|
|
|
|
return Actions.ActOnOpenMPSingleExprWithArgClause(
|
|
|
|
Kind, Type, Val.get(), Loc, T.getOpenLocation(), KLoc, CommaLoc,
|
|
|
|
T.getCloseLocation());
|
|
|
|
}
|
|
|
|
|
2014-06-16 15:08:35 +08:00
|
|
|
static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
|
|
|
|
UnqualifiedId &ReductionId) {
|
|
|
|
SourceLocation TemplateKWLoc;
|
|
|
|
if (ReductionIdScopeSpec.isEmpty()) {
|
|
|
|
auto OOK = OO_None;
|
|
|
|
switch (P.getCurToken().getKind()) {
|
|
|
|
case tok::plus:
|
|
|
|
OOK = OO_Plus;
|
|
|
|
break;
|
|
|
|
case tok::minus:
|
|
|
|
OOK = OO_Minus;
|
|
|
|
break;
|
|
|
|
case tok::star:
|
|
|
|
OOK = OO_Star;
|
|
|
|
break;
|
|
|
|
case tok::amp:
|
|
|
|
OOK = OO_Amp;
|
|
|
|
break;
|
|
|
|
case tok::pipe:
|
|
|
|
OOK = OO_Pipe;
|
|
|
|
break;
|
|
|
|
case tok::caret:
|
|
|
|
OOK = OO_Caret;
|
|
|
|
break;
|
|
|
|
case tok::ampamp:
|
|
|
|
OOK = OO_AmpAmp;
|
|
|
|
break;
|
|
|
|
case tok::pipepipe:
|
|
|
|
OOK = OO_PipePipe;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (OOK != OO_None) {
|
|
|
|
SourceLocation OpLoc = P.ConsumeToken();
|
2014-06-18 15:08:49 +08:00
|
|
|
SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
|
2014-06-16 15:08:35 +08:00
|
|
|
ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
|
|
|
|
/*AllowDestructorName*/ false,
|
|
|
|
/*AllowConstructorName*/ false, ParsedType(),
|
|
|
|
TemplateKWLoc, ReductionId);
|
|
|
|
}
|
|
|
|
|
2014-06-04 21:06:39 +08:00
|
|
|
/// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
|
2014-07-21 19:26:11 +08:00
|
|
|
/// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'.
|
2013-07-19 11:13:43 +08:00
|
|
|
///
|
|
|
|
/// private-clause:
|
|
|
|
/// 'private' '(' list ')'
|
2013-10-01 13:32:34 +08:00
|
|
|
/// firstprivate-clause:
|
|
|
|
/// 'firstprivate' '(' list ')'
|
2014-06-04 21:06:39 +08:00
|
|
|
/// lastprivate-clause:
|
|
|
|
/// 'lastprivate' '(' list ')'
|
2013-09-07 02:03:48 +08:00
|
|
|
/// shared-clause:
|
|
|
|
/// 'shared' '(' list ')'
|
2014-04-22 21:09:42 +08:00
|
|
|
/// linear-clause:
|
2015-08-20 18:54:39 +08:00
|
|
|
/// 'linear' '(' linear-list [ ':' linear-step ] ')'
|
2014-05-29 22:36:25 +08:00
|
|
|
/// aligned-clause:
|
|
|
|
/// 'aligned' '(' list [ ':' alignment ] ')'
|
2014-06-16 15:08:35 +08:00
|
|
|
/// reduction-clause:
|
|
|
|
/// 'reduction' '(' reduction-identifier ':' list ')'
|
2014-07-21 19:26:11 +08:00
|
|
|
/// copyprivate-clause:
|
|
|
|
/// 'copyprivate' '(' list ')'
|
|
|
|
/// flush-clause:
|
|
|
|
/// 'flush' '(' list ')'
|
2015-06-23 22:25:19 +08:00
|
|
|
/// depend-clause:
|
|
|
|
/// 'depend' '(' in | out | inout : list ')'
|
2013-07-19 11:13:43 +08:00
|
|
|
///
|
2015-08-20 18:54:39 +08:00
|
|
|
/// For 'linear' clause linear-list may have the following forms:
|
|
|
|
/// list
|
|
|
|
/// modifier(list)
|
|
|
|
/// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++).
|
2013-07-19 11:13:43 +08:00
|
|
|
OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) {
|
|
|
|
SourceLocation Loc = Tok.getLocation();
|
|
|
|
SourceLocation LOpen = ConsumeToken();
|
2014-04-22 21:09:42 +08:00
|
|
|
SourceLocation ColonLoc = SourceLocation();
|
2014-06-16 15:08:35 +08:00
|
|
|
// Optional scope specifier and unqualified id for reduction identifier.
|
|
|
|
CXXScopeSpec ReductionIdScopeSpec;
|
|
|
|
UnqualifiedId ReductionId;
|
|
|
|
bool InvalidReductionId = false;
|
2015-06-23 22:25:19 +08:00
|
|
|
OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
|
2015-08-20 18:54:39 +08:00
|
|
|
// OpenMP 4.1 [2.15.3.7, linear Clause]
|
|
|
|
// If no modifier is specified it is assumed to be val.
|
|
|
|
OpenMPLinearClauseKind LinearModifier = OMPC_LINEAR_val;
|
|
|
|
SourceLocation DepLinLoc;
|
2015-06-23 22:25:19 +08:00
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
// Parse '('.
|
2013-12-19 03:10:49 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
|
2013-07-19 11:13:43 +08:00
|
|
|
if (T.expectAndConsume(diag::err_expected_lparen_after,
|
|
|
|
getOpenMPClauseName(Kind)))
|
2014-05-21 14:02:52 +08:00
|
|
|
return nullptr;
|
2013-07-19 11:13:43 +08:00
|
|
|
|
2015-08-20 18:54:39 +08:00
|
|
|
bool NeedRParenForLinear = false;
|
|
|
|
BalancedDelimiterTracker LinearT(*this, tok::l_paren,
|
|
|
|
tok::annot_pragma_openmp_end);
|
2014-06-16 15:08:35 +08:00
|
|
|
// Handle reduction-identifier for reduction clause.
|
|
|
|
if (Kind == OMPC_reduction) {
|
|
|
|
ColonProtectionRAIIObject ColonRAII(*this);
|
|
|
|
if (getLangOpts().CPlusPlus) {
|
|
|
|
ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, ParsedType(), false);
|
|
|
|
}
|
|
|
|
InvalidReductionId =
|
|
|
|
ParseReductionId(*this, ReductionIdScopeSpec, ReductionId);
|
|
|
|
if (InvalidReductionId) {
|
|
|
|
SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
|
|
|
|
StopBeforeMatch);
|
|
|
|
}
|
|
|
|
if (Tok.is(tok::colon)) {
|
|
|
|
ColonLoc = ConsumeToken();
|
|
|
|
} else {
|
|
|
|
Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
|
|
|
|
}
|
2015-06-23 22:25:19 +08:00
|
|
|
} else if (Kind == OMPC_depend) {
|
|
|
|
// Handle dependency type for depend clause.
|
|
|
|
ColonProtectionRAIIObject ColonRAII(*this);
|
|
|
|
DepKind = static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType(
|
|
|
|
Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
|
2015-08-20 18:54:39 +08:00
|
|
|
DepLinLoc = Tok.getLocation();
|
2015-06-23 22:25:19 +08:00
|
|
|
|
|
|
|
if (DepKind == OMPC_DEPEND_unknown) {
|
|
|
|
SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
|
|
|
|
StopBeforeMatch);
|
|
|
|
} else {
|
|
|
|
ConsumeToken();
|
|
|
|
}
|
|
|
|
if (Tok.is(tok::colon)) {
|
|
|
|
ColonLoc = ConsumeToken();
|
|
|
|
} else {
|
|
|
|
Diag(Tok, diag::warn_pragma_expected_colon) << "dependency type";
|
|
|
|
}
|
2015-08-20 18:54:39 +08:00
|
|
|
} else if (Kind == OMPC_linear) {
|
|
|
|
// Try to parse modifier if any.
|
|
|
|
if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) {
|
|
|
|
LinearModifier = static_cast<OpenMPLinearClauseKind>(
|
2015-08-20 20:15:57 +08:00
|
|
|
getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)));
|
2015-08-20 18:54:39 +08:00
|
|
|
DepLinLoc = ConsumeToken();
|
|
|
|
LinearT.consumeOpen();
|
|
|
|
NeedRParenForLinear = true;
|
|
|
|
}
|
2014-06-16 15:08:35 +08:00
|
|
|
}
|
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
SmallVector<Expr *, 5> Vars;
|
2015-06-23 22:25:19 +08:00
|
|
|
bool IsComma = ((Kind != OMPC_reduction) && (Kind != OMPC_depend)) ||
|
|
|
|
((Kind == OMPC_reduction) && !InvalidReductionId) ||
|
|
|
|
((Kind == OMPC_depend) && DepKind != OMPC_DEPEND_unknown);
|
2014-05-29 22:36:25 +08:00
|
|
|
const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
|
2014-04-22 21:09:42 +08:00
|
|
|
while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
|
2013-07-19 11:13:43 +08:00
|
|
|
Tok.isNot(tok::annot_pragma_openmp_end))) {
|
2014-04-22 21:09:42 +08:00
|
|
|
ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
|
2013-07-19 11:13:43 +08:00
|
|
|
// Parse variable
|
2014-11-22 02:48:04 +08:00
|
|
|
ExprResult VarExpr =
|
|
|
|
Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
|
2013-07-19 11:13:43 +08:00
|
|
|
if (VarExpr.isUsable()) {
|
2014-05-29 18:55:11 +08:00
|
|
|
Vars.push_back(VarExpr.get());
|
2013-07-19 11:13:43 +08:00
|
|
|
} else {
|
|
|
|
SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
|
2013-12-19 03:10:49 +08:00
|
|
|
StopBeforeMatch);
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
|
|
|
// Skip ',' if any
|
|
|
|
IsComma = Tok.is(tok::comma);
|
2014-04-22 21:09:42 +08:00
|
|
|
if (IsComma)
|
2013-07-19 11:13:43 +08:00
|
|
|
ConsumeToken();
|
2014-04-22 21:09:42 +08:00
|
|
|
else if (Tok.isNot(tok::r_paren) &&
|
|
|
|
Tok.isNot(tok::annot_pragma_openmp_end) &&
|
|
|
|
(!MayHaveTail || Tok.isNot(tok::colon)))
|
2014-07-21 19:26:11 +08:00
|
|
|
Diag(Tok, diag::err_omp_expected_punc)
|
|
|
|
<< ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
|
|
|
|
: getOpenMPClauseName(Kind))
|
|
|
|
<< (Kind == OMPC_flush);
|
2014-04-22 21:09:42 +08:00
|
|
|
}
|
|
|
|
|
2015-08-20 18:54:39 +08:00
|
|
|
// Parse ')' for linear clause with modifier.
|
|
|
|
if (NeedRParenForLinear)
|
|
|
|
LinearT.consumeClose();
|
|
|
|
|
2014-05-29 22:36:25 +08:00
|
|
|
// Parse ':' linear-step (or ':' alignment).
|
2014-05-21 14:02:52 +08:00
|
|
|
Expr *TailExpr = nullptr;
|
2014-04-22 21:09:42 +08:00
|
|
|
const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
|
|
|
|
if (MustHaveTail) {
|
|
|
|
ColonLoc = Tok.getLocation();
|
|
|
|
ConsumeToken();
|
2014-11-21 06:06:40 +08:00
|
|
|
ExprResult Tail =
|
|
|
|
Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
|
2014-04-22 21:09:42 +08:00
|
|
|
if (Tail.isUsable())
|
2014-05-29 18:55:11 +08:00
|
|
|
TailExpr = Tail.get();
|
2014-04-22 21:09:42 +08:00
|
|
|
else
|
|
|
|
SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
|
|
|
|
StopBeforeMatch);
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse ')'.
|
|
|
|
T.consumeClose();
|
2015-06-23 22:25:19 +08:00
|
|
|
if ((Kind == OMPC_depend && DepKind != OMPC_DEPEND_unknown && Vars.empty()) ||
|
|
|
|
(Kind != OMPC_depend && Vars.empty()) || (MustHaveTail && !TailExpr) ||
|
|
|
|
InvalidReductionId)
|
2014-05-21 14:02:52 +08:00
|
|
|
return nullptr;
|
2013-07-19 11:13:43 +08:00
|
|
|
|
2014-06-16 15:08:35 +08:00
|
|
|
return Actions.ActOnOpenMPVarListClause(
|
|
|
|
Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(),
|
|
|
|
ReductionIdScopeSpec,
|
|
|
|
ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId)
|
2015-06-23 22:25:19 +08:00
|
|
|
: DeclarationNameInfo(),
|
2015-08-20 18:54:39 +08:00
|
|
|
DepKind, LinearModifier, DepLinLoc);
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
|
|
|
|