Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1 | //===--- ParseOpenMP.cpp - OpenMP directives parsing ----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements parsing of all OpenMP directives and clauses. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 14 | #include "RAIIObjectsForParser.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTConsumer.h" |
| 16 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 17 | #include "clang/AST/StmtOpenMP.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/Parse/ParseDiagnostic.h" |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 19 | #include "clang/Parse/Parser.h" |
| 20 | #include "clang/Sema/Scope.h" |
| 21 | #include "llvm/ADT/PointerIntPair.h" |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 22 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 23 | using namespace clang; |
| 24 | |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | // OpenMP declarative directives. |
| 27 | //===----------------------------------------------------------------------===// |
| 28 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 29 | namespace { |
| 30 | enum OpenMPDirectiveKindEx { |
| 31 | OMPD_cancellation = OMPD_unknown + 1, |
| 32 | OMPD_data, |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 33 | OMPD_declare, |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 34 | OMPD_end, |
| 35 | OMPD_end_declare, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 36 | OMPD_enter, |
| 37 | OMPD_exit, |
| 38 | OMPD_point, |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 39 | OMPD_reduction, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 40 | OMPD_target_enter, |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 41 | OMPD_target_exit, |
| 42 | OMPD_update, |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 43 | OMPD_distribute_parallel |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 44 | }; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 45 | |
| 46 | class ThreadprivateListParserHelper final { |
| 47 | SmallVector<Expr *, 4> Identifiers; |
| 48 | Parser *P; |
| 49 | |
| 50 | public: |
| 51 | ThreadprivateListParserHelper(Parser *P) : P(P) {} |
| 52 | void operator()(CXXScopeSpec &SS, DeclarationNameInfo NameInfo) { |
| 53 | ExprResult Res = |
| 54 | P->getActions().ActOnOpenMPIdExpression(P->getCurScope(), SS, NameInfo); |
| 55 | if (Res.isUsable()) |
| 56 | Identifiers.push_back(Res.get()); |
| 57 | } |
| 58 | llvm::ArrayRef<Expr *> getIdentifiers() const { return Identifiers; } |
| 59 | }; |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 60 | } // namespace |
| 61 | |
| 62 | // Map token string to extended OMP token kind that are |
| 63 | // OpenMPDirectiveKind + OpenMPDirectiveKindEx. |
| 64 | static unsigned getOpenMPDirectiveKindEx(StringRef S) { |
| 65 | auto DKind = getOpenMPDirectiveKind(S); |
| 66 | if (DKind != OMPD_unknown) |
| 67 | return DKind; |
| 68 | |
| 69 | return llvm::StringSwitch<unsigned>(S) |
| 70 | .Case("cancellation", OMPD_cancellation) |
| 71 | .Case("data", OMPD_data) |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 72 | .Case("declare", OMPD_declare) |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 73 | .Case("end", OMPD_end) |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 74 | .Case("enter", OMPD_enter) |
| 75 | .Case("exit", OMPD_exit) |
| 76 | .Case("point", OMPD_point) |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 77 | .Case("reduction", OMPD_reduction) |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 78 | .Case("update", OMPD_update) |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 79 | .Default(OMPD_unknown); |
| 80 | } |
| 81 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 82 | static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) { |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 83 | // Array of foldings: F[i][0] F[i][1] ===> F[i][2]. |
| 84 | // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd |
| 85 | // TODO: add other combined directives in topological order. |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 86 | static const unsigned F[][3] = { |
| 87 | { OMPD_cancellation, OMPD_point, OMPD_cancellation_point }, |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 88 | { OMPD_declare, OMPD_reduction, OMPD_declare_reduction }, |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 89 | { OMPD_declare, OMPD_simd, OMPD_declare_simd }, |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 90 | { OMPD_declare, OMPD_target, OMPD_declare_target }, |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 91 | { OMPD_distribute, OMPD_parallel, OMPD_distribute_parallel }, |
| 92 | { OMPD_distribute_parallel, OMPD_for, OMPD_distribute_parallel_for }, |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 93 | { OMPD_distribute_parallel_for, OMPD_simd, |
| 94 | OMPD_distribute_parallel_for_simd }, |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 95 | { OMPD_distribute, OMPD_simd, OMPD_distribute_simd }, |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 96 | { OMPD_end, OMPD_declare, OMPD_end_declare }, |
| 97 | { OMPD_end_declare, OMPD_target, OMPD_end_declare_target }, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 98 | { OMPD_target, OMPD_data, OMPD_target_data }, |
| 99 | { OMPD_target, OMPD_enter, OMPD_target_enter }, |
| 100 | { OMPD_target, OMPD_exit, OMPD_target_exit }, |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 101 | { OMPD_target, OMPD_update, OMPD_target_update }, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 102 | { OMPD_target_enter, OMPD_data, OMPD_target_enter_data }, |
| 103 | { OMPD_target_exit, OMPD_data, OMPD_target_exit_data }, |
| 104 | { OMPD_for, OMPD_simd, OMPD_for_simd }, |
| 105 | { OMPD_parallel, OMPD_for, OMPD_parallel_for }, |
| 106 | { OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd }, |
| 107 | { OMPD_parallel, OMPD_sections, OMPD_parallel_sections }, |
| 108 | { OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd }, |
| 109 | { OMPD_target, OMPD_parallel, OMPD_target_parallel }, |
| 110 | { OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for } |
| 111 | }; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 112 | enum { CancellationPoint = 0, DeclareReduction = 1, TargetData = 2 }; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 113 | auto Tok = P.getCurToken(); |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 114 | unsigned DKind = |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 115 | Tok.isAnnotation() |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 116 | ? static_cast<unsigned>(OMPD_unknown) |
| 117 | : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok)); |
| 118 | if (DKind == OMPD_unknown) |
| 119 | return OMPD_unknown; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 120 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 121 | for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) { |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 122 | if (DKind != F[i][0]) |
| 123 | continue; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 124 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 125 | Tok = P.getPreprocessor().LookAhead(0); |
| 126 | unsigned SDKind = |
| 127 | Tok.isAnnotation() |
| 128 | ? static_cast<unsigned>(OMPD_unknown) |
| 129 | : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok)); |
| 130 | if (SDKind == OMPD_unknown) |
| 131 | continue; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 132 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 133 | if (SDKind == F[i][1]) { |
| 134 | P.ConsumeToken(); |
| 135 | DKind = F[i][2]; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 138 | return DKind < OMPD_unknown ? static_cast<OpenMPDirectiveKind>(DKind) |
| 139 | : OMPD_unknown; |
| 140 | } |
| 141 | |
| 142 | static DeclarationName parseOpenMPReductionId(Parser &P) { |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 143 | Token Tok = P.getCurToken(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 144 | Sema &Actions = P.getActions(); |
| 145 | OverloadedOperatorKind OOK = OO_None; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 146 | // Allow to use 'operator' keyword for C++ operators |
| 147 | bool WithOperator = false; |
| 148 | if (Tok.is(tok::kw_operator)) { |
| 149 | P.ConsumeToken(); |
| 150 | Tok = P.getCurToken(); |
| 151 | WithOperator = true; |
| 152 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 153 | switch (Tok.getKind()) { |
| 154 | case tok::plus: // '+' |
| 155 | OOK = OO_Plus; |
| 156 | break; |
| 157 | case tok::minus: // '-' |
| 158 | OOK = OO_Minus; |
| 159 | break; |
| 160 | case tok::star: // '*' |
| 161 | OOK = OO_Star; |
| 162 | break; |
| 163 | case tok::amp: // '&' |
| 164 | OOK = OO_Amp; |
| 165 | break; |
| 166 | case tok::pipe: // '|' |
| 167 | OOK = OO_Pipe; |
| 168 | break; |
| 169 | case tok::caret: // '^' |
| 170 | OOK = OO_Caret; |
| 171 | break; |
| 172 | case tok::ampamp: // '&&' |
| 173 | OOK = OO_AmpAmp; |
| 174 | break; |
| 175 | case tok::pipepipe: // '||' |
| 176 | OOK = OO_PipePipe; |
| 177 | break; |
| 178 | case tok::identifier: // identifier |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 179 | if (!WithOperator) |
| 180 | break; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 181 | default: |
| 182 | P.Diag(Tok.getLocation(), diag::err_omp_expected_reduction_identifier); |
| 183 | P.SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 184 | Parser::StopBeforeMatch); |
| 185 | return DeclarationName(); |
| 186 | } |
| 187 | P.ConsumeToken(); |
| 188 | auto &DeclNames = Actions.getASTContext().DeclarationNames; |
| 189 | return OOK == OO_None ? DeclNames.getIdentifier(Tok.getIdentifierInfo()) |
| 190 | : DeclNames.getCXXOperatorName(OOK); |
| 191 | } |
| 192 | |
| 193 | /// \brief Parse 'omp declare reduction' construct. |
| 194 | /// |
| 195 | /// declare-reduction-directive: |
| 196 | /// annot_pragma_openmp 'declare' 'reduction' |
| 197 | /// '(' <reduction_id> ':' <type> {',' <type>} ':' <expression> ')' |
| 198 | /// ['initializer' '(' ('omp_priv' '=' <expression>)|<function_call> ')'] |
| 199 | /// annot_pragma_openmp_end |
| 200 | /// <reduction_id> is either a base language identifier or one of the following |
| 201 | /// operators: '+', '-', '*', '&', '|', '^', '&&' and '||'. |
| 202 | /// |
| 203 | Parser::DeclGroupPtrTy |
| 204 | Parser::ParseOpenMPDeclareReductionDirective(AccessSpecifier AS) { |
| 205 | // Parse '('. |
| 206 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 207 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 208 | getOpenMPDirectiveName(OMPD_declare_reduction))) { |
| 209 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 210 | return DeclGroupPtrTy(); |
| 211 | } |
| 212 | |
| 213 | DeclarationName Name = parseOpenMPReductionId(*this); |
| 214 | if (Name.isEmpty() && Tok.is(tok::annot_pragma_openmp_end)) |
| 215 | return DeclGroupPtrTy(); |
| 216 | |
| 217 | // Consume ':'. |
| 218 | bool IsCorrect = !ExpectAndConsume(tok::colon); |
| 219 | |
| 220 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 221 | return DeclGroupPtrTy(); |
| 222 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 223 | IsCorrect = IsCorrect && !Name.isEmpty(); |
| 224 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 225 | if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) { |
| 226 | Diag(Tok.getLocation(), diag::err_expected_type); |
| 227 | IsCorrect = false; |
| 228 | } |
| 229 | |
| 230 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 231 | return DeclGroupPtrTy(); |
| 232 | |
| 233 | SmallVector<std::pair<QualType, SourceLocation>, 8> ReductionTypes; |
| 234 | // Parse list of types until ':' token. |
| 235 | do { |
| 236 | ColonProtectionRAIIObject ColonRAII(*this); |
| 237 | SourceRange Range; |
| 238 | TypeResult TR = ParseTypeName(&Range, Declarator::PrototypeContext, AS); |
| 239 | if (TR.isUsable()) { |
| 240 | auto ReductionType = |
| 241 | Actions.ActOnOpenMPDeclareReductionType(Range.getBegin(), TR); |
| 242 | if (!ReductionType.isNull()) { |
| 243 | ReductionTypes.push_back( |
| 244 | std::make_pair(ReductionType, Range.getBegin())); |
| 245 | } |
| 246 | } else { |
| 247 | SkipUntil(tok::comma, tok::colon, tok::annot_pragma_openmp_end, |
| 248 | StopBeforeMatch); |
| 249 | } |
| 250 | |
| 251 | if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) |
| 252 | break; |
| 253 | |
| 254 | // Consume ','. |
| 255 | if (ExpectAndConsume(tok::comma)) { |
| 256 | IsCorrect = false; |
| 257 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 258 | Diag(Tok.getLocation(), diag::err_expected_type); |
| 259 | return DeclGroupPtrTy(); |
| 260 | } |
| 261 | } |
| 262 | } while (Tok.isNot(tok::annot_pragma_openmp_end)); |
| 263 | |
| 264 | if (ReductionTypes.empty()) { |
| 265 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 266 | return DeclGroupPtrTy(); |
| 267 | } |
| 268 | |
| 269 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 270 | return DeclGroupPtrTy(); |
| 271 | |
| 272 | // Consume ':'. |
| 273 | if (ExpectAndConsume(tok::colon)) |
| 274 | IsCorrect = false; |
| 275 | |
| 276 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 277 | Diag(Tok.getLocation(), diag::err_expected_expression); |
| 278 | return DeclGroupPtrTy(); |
| 279 | } |
| 280 | |
| 281 | DeclGroupPtrTy DRD = Actions.ActOnOpenMPDeclareReductionDirectiveStart( |
| 282 | getCurScope(), Actions.getCurLexicalContext(), Name, ReductionTypes, AS); |
| 283 | |
| 284 | // Parse <combiner> expression and then parse initializer if any for each |
| 285 | // correct type. |
| 286 | unsigned I = 0, E = ReductionTypes.size(); |
| 287 | for (auto *D : DRD.get()) { |
| 288 | TentativeParsingAction TPA(*this); |
| 289 | ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope | |
| 290 | Scope::OpenMPDirectiveScope); |
| 291 | // Parse <combiner> expression. |
| 292 | Actions.ActOnOpenMPDeclareReductionCombinerStart(getCurScope(), D); |
| 293 | ExprResult CombinerResult = |
| 294 | Actions.ActOnFinishFullExpr(ParseAssignmentExpression().get(), |
| 295 | D->getLocation(), /*DiscardedValue=*/true); |
| 296 | Actions.ActOnOpenMPDeclareReductionCombinerEnd(D, CombinerResult.get()); |
| 297 | |
| 298 | if (CombinerResult.isInvalid() && Tok.isNot(tok::r_paren) && |
| 299 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 300 | TPA.Commit(); |
| 301 | IsCorrect = false; |
| 302 | break; |
| 303 | } |
| 304 | IsCorrect = !T.consumeClose() && IsCorrect && CombinerResult.isUsable(); |
| 305 | ExprResult InitializerResult; |
| 306 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 307 | // Parse <initializer> expression. |
| 308 | if (Tok.is(tok::identifier) && |
| 309 | Tok.getIdentifierInfo()->isStr("initializer")) |
| 310 | ConsumeToken(); |
| 311 | else { |
| 312 | Diag(Tok.getLocation(), diag::err_expected) << "'initializer'"; |
| 313 | TPA.Commit(); |
| 314 | IsCorrect = false; |
| 315 | break; |
| 316 | } |
| 317 | // Parse '('. |
| 318 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 319 | tok::annot_pragma_openmp_end); |
| 320 | IsCorrect = |
| 321 | !T.expectAndConsume(diag::err_expected_lparen_after, "initializer") && |
| 322 | IsCorrect; |
| 323 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 324 | ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope | |
| 325 | Scope::OpenMPDirectiveScope); |
| 326 | // Parse expression. |
| 327 | Actions.ActOnOpenMPDeclareReductionInitializerStart(getCurScope(), D); |
| 328 | InitializerResult = Actions.ActOnFinishFullExpr( |
| 329 | ParseAssignmentExpression().get(), D->getLocation(), |
| 330 | /*DiscardedValue=*/true); |
| 331 | Actions.ActOnOpenMPDeclareReductionInitializerEnd( |
| 332 | D, InitializerResult.get()); |
| 333 | if (InitializerResult.isInvalid() && Tok.isNot(tok::r_paren) && |
| 334 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 335 | TPA.Commit(); |
| 336 | IsCorrect = false; |
| 337 | break; |
| 338 | } |
| 339 | IsCorrect = |
| 340 | !T.consumeClose() && IsCorrect && !InitializerResult.isInvalid(); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | ++I; |
| 345 | // Revert parsing if not the last type, otherwise accept it, we're done with |
| 346 | // parsing. |
| 347 | if (I != E) |
| 348 | TPA.Revert(); |
| 349 | else |
| 350 | TPA.Commit(); |
| 351 | } |
| 352 | return Actions.ActOnOpenMPDeclareReductionDirectiveEnd(getCurScope(), DRD, |
| 353 | IsCorrect); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 356 | namespace { |
| 357 | /// RAII that recreates function context for correct parsing of clauses of |
| 358 | /// 'declare simd' construct. |
| 359 | /// OpenMP, 2.8.2 declare simd Construct |
| 360 | /// The expressions appearing in the clauses of this directive are evaluated in |
| 361 | /// the scope of the arguments of the function declaration or definition. |
| 362 | class FNContextRAII final { |
| 363 | Parser &P; |
| 364 | Sema::CXXThisScopeRAII *ThisScope; |
| 365 | Parser::ParseScope *TempScope; |
| 366 | Parser::ParseScope *FnScope; |
| 367 | bool HasTemplateScope = false; |
| 368 | bool HasFunScope = false; |
| 369 | FNContextRAII() = delete; |
| 370 | FNContextRAII(const FNContextRAII &) = delete; |
| 371 | FNContextRAII &operator=(const FNContextRAII &) = delete; |
| 372 | |
| 373 | public: |
| 374 | FNContextRAII(Parser &P, Parser::DeclGroupPtrTy Ptr) : P(P) { |
| 375 | Decl *D = *Ptr.get().begin(); |
| 376 | NamedDecl *ND = dyn_cast<NamedDecl>(D); |
| 377 | RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext()); |
| 378 | Sema &Actions = P.getActions(); |
| 379 | |
| 380 | // Allow 'this' within late-parsed attributes. |
| 381 | ThisScope = new Sema::CXXThisScopeRAII(Actions, RD, /*TypeQuals=*/0, |
| 382 | ND && ND->isCXXInstanceMember()); |
| 383 | |
| 384 | // If the Decl is templatized, add template parameters to scope. |
| 385 | HasTemplateScope = D->isTemplateDecl(); |
| 386 | TempScope = |
| 387 | new Parser::ParseScope(&P, Scope::TemplateParamScope, HasTemplateScope); |
| 388 | if (HasTemplateScope) |
| 389 | Actions.ActOnReenterTemplateScope(Actions.getCurScope(), D); |
| 390 | |
| 391 | // If the Decl is on a function, add function parameters to the scope. |
| 392 | HasFunScope = D->isFunctionOrFunctionTemplate(); |
| 393 | FnScope = new Parser::ParseScope(&P, Scope::FnScope | Scope::DeclScope, |
| 394 | HasFunScope); |
| 395 | if (HasFunScope) |
| 396 | Actions.ActOnReenterFunctionContext(Actions.getCurScope(), D); |
| 397 | } |
| 398 | ~FNContextRAII() { |
| 399 | if (HasFunScope) { |
| 400 | P.getActions().ActOnExitFunctionContext(); |
| 401 | FnScope->Exit(); // Pop scope, and remove Decls from IdResolver |
| 402 | } |
| 403 | if (HasTemplateScope) |
| 404 | TempScope->Exit(); |
| 405 | delete FnScope; |
| 406 | delete TempScope; |
| 407 | delete ThisScope; |
| 408 | } |
| 409 | }; |
| 410 | } // namespace |
| 411 | |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 412 | /// Parses clauses for 'declare simd' directive. |
| 413 | /// clause: |
| 414 | /// 'inbranch' | 'notinbranch' |
| 415 | /// 'simdlen' '(' <expr> ')' |
| 416 | /// { 'uniform' '(' <argument_list> ')' } |
| 417 | /// { 'aligned '(' <argument_list> [ ':' <alignment> ] ')' } |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 418 | /// { 'linear '(' <argument_list> [ ':' <step> ] ')' } |
| 419 | static bool parseDeclareSimdClauses( |
| 420 | Parser &P, OMPDeclareSimdDeclAttr::BranchStateTy &BS, ExprResult &SimdLen, |
| 421 | SmallVectorImpl<Expr *> &Uniforms, SmallVectorImpl<Expr *> &Aligneds, |
| 422 | SmallVectorImpl<Expr *> &Alignments, SmallVectorImpl<Expr *> &Linears, |
| 423 | SmallVectorImpl<unsigned> &LinModifiers, SmallVectorImpl<Expr *> &Steps) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 424 | SourceRange BSRange; |
| 425 | const Token &Tok = P.getCurToken(); |
| 426 | bool IsError = false; |
| 427 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 428 | if (Tok.isNot(tok::identifier)) |
| 429 | break; |
| 430 | OMPDeclareSimdDeclAttr::BranchStateTy Out; |
| 431 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 432 | StringRef ClauseName = II->getName(); |
| 433 | // Parse 'inranch|notinbranch' clauses. |
| 434 | if (OMPDeclareSimdDeclAttr::ConvertStrToBranchStateTy(ClauseName, Out)) { |
| 435 | if (BS != OMPDeclareSimdDeclAttr::BS_Undefined && BS != Out) { |
| 436 | P.Diag(Tok, diag::err_omp_declare_simd_inbranch_notinbranch) |
| 437 | << ClauseName |
| 438 | << OMPDeclareSimdDeclAttr::ConvertBranchStateTyToStr(BS) << BSRange; |
| 439 | IsError = true; |
| 440 | } |
| 441 | BS = Out; |
| 442 | BSRange = SourceRange(Tok.getLocation(), Tok.getEndLoc()); |
| 443 | P.ConsumeToken(); |
| 444 | } else if (ClauseName.equals("simdlen")) { |
| 445 | if (SimdLen.isUsable()) { |
| 446 | P.Diag(Tok, diag::err_omp_more_one_clause) |
| 447 | << getOpenMPDirectiveName(OMPD_declare_simd) << ClauseName << 0; |
| 448 | IsError = true; |
| 449 | } |
| 450 | P.ConsumeToken(); |
| 451 | SourceLocation RLoc; |
| 452 | SimdLen = P.ParseOpenMPParensExpr(ClauseName, RLoc); |
| 453 | if (SimdLen.isInvalid()) |
| 454 | IsError = true; |
| 455 | } else { |
| 456 | OpenMPClauseKind CKind = getOpenMPClauseKind(ClauseName); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 457 | if (CKind == OMPC_uniform || CKind == OMPC_aligned || |
| 458 | CKind == OMPC_linear) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 459 | Parser::OpenMPVarListDataTy Data; |
| 460 | auto *Vars = &Uniforms; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 461 | if (CKind == OMPC_aligned) |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 462 | Vars = &Aligneds; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 463 | else if (CKind == OMPC_linear) |
| 464 | Vars = &Linears; |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 465 | |
| 466 | P.ConsumeToken(); |
| 467 | if (P.ParseOpenMPVarList(OMPD_declare_simd, |
| 468 | getOpenMPClauseKind(ClauseName), *Vars, Data)) |
| 469 | IsError = true; |
| 470 | if (CKind == OMPC_aligned) |
| 471 | Alignments.append(Aligneds.size() - Alignments.size(), Data.TailExpr); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 472 | else if (CKind == OMPC_linear) { |
| 473 | if (P.getActions().CheckOpenMPLinearModifier(Data.LinKind, |
| 474 | Data.DepLinMapLoc)) |
| 475 | Data.LinKind = OMPC_LINEAR_val; |
| 476 | LinModifiers.append(Linears.size() - LinModifiers.size(), |
| 477 | Data.LinKind); |
| 478 | Steps.append(Linears.size() - Steps.size(), Data.TailExpr); |
| 479 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 480 | } else |
| 481 | // TODO: add parsing of other clauses. |
| 482 | break; |
| 483 | } |
| 484 | // Skip ',' if any. |
| 485 | if (Tok.is(tok::comma)) |
| 486 | P.ConsumeToken(); |
| 487 | } |
| 488 | return IsError; |
| 489 | } |
| 490 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 491 | /// Parse clauses for '#pragma omp declare simd'. |
| 492 | Parser::DeclGroupPtrTy |
| 493 | Parser::ParseOMPDeclareSimdClauses(Parser::DeclGroupPtrTy Ptr, |
| 494 | CachedTokens &Toks, SourceLocation Loc) { |
| 495 | PP.EnterToken(Tok); |
| 496 | PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true); |
| 497 | // Consume the previously pushed token. |
| 498 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
| 499 | |
| 500 | FNContextRAII FnContext(*this, Ptr); |
| 501 | OMPDeclareSimdDeclAttr::BranchStateTy BS = |
| 502 | OMPDeclareSimdDeclAttr::BS_Undefined; |
| 503 | ExprResult Simdlen; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 504 | SmallVector<Expr *, 4> Uniforms; |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 505 | SmallVector<Expr *, 4> Aligneds; |
| 506 | SmallVector<Expr *, 4> Alignments; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 507 | SmallVector<Expr *, 4> Linears; |
| 508 | SmallVector<unsigned, 4> LinModifiers; |
| 509 | SmallVector<Expr *, 4> Steps; |
| 510 | bool IsError = |
| 511 | parseDeclareSimdClauses(*this, BS, Simdlen, Uniforms, Aligneds, |
| 512 | Alignments, Linears, LinModifiers, Steps); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 513 | // Need to check for extra tokens. |
| 514 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 515 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 516 | << getOpenMPDirectiveName(OMPD_declare_simd); |
| 517 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 518 | ConsumeAnyToken(); |
| 519 | } |
| 520 | // Skip the last annot_pragma_openmp_end. |
| 521 | SourceLocation EndLoc = ConsumeToken(); |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 522 | if (!IsError) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 523 | return Actions.ActOnOpenMPDeclareSimdDirective( |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 524 | Ptr, BS, Simdlen.get(), Uniforms, Aligneds, Alignments, Linears, |
| 525 | LinModifiers, Steps, SourceRange(Loc, EndLoc)); |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 526 | } |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 527 | return Ptr; |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 530 | /// \brief Parsing of declarative OpenMP directives. |
| 531 | /// |
| 532 | /// threadprivate-directive: |
| 533 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 534 | /// annot_pragma_openmp_end |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 535 | /// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 536 | /// declare-reduction-directive: |
| 537 | /// annot_pragma_openmp 'declare' 'reduction' [...] |
| 538 | /// annot_pragma_openmp_end |
| 539 | /// |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 540 | /// declare-simd-directive: |
| 541 | /// annot_pragma_openmp 'declare simd' {<clause> [,]} |
| 542 | /// annot_pragma_openmp_end |
| 543 | /// <function declaration/definition> |
| 544 | /// |
| 545 | Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( |
| 546 | AccessSpecifier &AS, ParsedAttributesWithRange &Attrs, |
| 547 | DeclSpec::TST TagType, Decl *Tag) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 548 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 549 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 550 | |
| 551 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 552 | auto DKind = ParseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 553 | |
| 554 | switch (DKind) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 555 | case OMPD_threadprivate: { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 556 | ConsumeToken(); |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 557 | ThreadprivateListParserHelper Helper(this); |
| 558 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Helper, true)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 559 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 560 | // extra tokens. |
| 561 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 562 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 563 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 564 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 565 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 566 | // Skip the last annot_pragma_openmp_end. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 567 | ConsumeToken(); |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 568 | return Actions.ActOnOpenMPThreadprivateDirective(Loc, |
| 569 | Helper.getIdentifiers()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 570 | } |
| 571 | break; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 572 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 573 | case OMPD_declare_reduction: |
| 574 | ConsumeToken(); |
| 575 | if (auto Res = ParseOpenMPDeclareReductionDirective(AS)) { |
| 576 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 577 | // extra tokens. |
| 578 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 579 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 580 | << getOpenMPDirectiveName(OMPD_declare_reduction); |
| 581 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 582 | ConsumeAnyToken(); |
| 583 | } |
| 584 | // Skip the last annot_pragma_openmp_end. |
| 585 | ConsumeToken(); |
| 586 | return Res; |
| 587 | } |
| 588 | break; |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 589 | case OMPD_declare_simd: { |
| 590 | // The syntax is: |
| 591 | // { #pragma omp declare simd } |
| 592 | // <function-declaration-or-definition> |
| 593 | // |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 594 | ConsumeToken(); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 595 | CachedTokens Toks; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 596 | while(Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 597 | Toks.push_back(Tok); |
| 598 | ConsumeAnyToken(); |
| 599 | } |
| 600 | Toks.push_back(Tok); |
| 601 | ConsumeAnyToken(); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 602 | |
| 603 | DeclGroupPtrTy Ptr; |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 604 | if (Tok.is(tok::annot_pragma_openmp)) |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 605 | Ptr = ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs, TagType, Tag); |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 606 | else if (Tok.isNot(tok::r_brace) && !isEofOrEom()) { |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 607 | // Here we expect to see some function declaration. |
| 608 | if (AS == AS_none) { |
| 609 | assert(TagType == DeclSpec::TST_unspecified); |
| 610 | MaybeParseCXX11Attributes(Attrs); |
| 611 | MaybeParseMicrosoftAttributes(Attrs); |
| 612 | ParsingDeclSpec PDS(*this); |
| 613 | Ptr = ParseExternalDeclaration(Attrs, &PDS); |
| 614 | } else { |
| 615 | Ptr = |
| 616 | ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag); |
| 617 | } |
| 618 | } |
| 619 | if (!Ptr) { |
| 620 | Diag(Loc, diag::err_omp_decl_in_declare_simd); |
| 621 | return DeclGroupPtrTy(); |
| 622 | } |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 623 | return ParseOMPDeclareSimdClauses(Ptr, Toks, Loc); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 624 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 625 | case OMPD_declare_target: { |
| 626 | SourceLocation DTLoc = ConsumeAnyToken(); |
| 627 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 628 | // OpenMP 4.5 syntax with list of entities. |
| 629 | llvm::SmallSetVector<const NamedDecl*, 16> SameDirectiveDecls; |
| 630 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 631 | OMPDeclareTargetDeclAttr::MapTypeTy MT = |
| 632 | OMPDeclareTargetDeclAttr::MT_To; |
| 633 | if (Tok.is(tok::identifier)) { |
| 634 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 635 | StringRef ClauseName = II->getName(); |
| 636 | // Parse 'to|link' clauses. |
| 637 | if (!OMPDeclareTargetDeclAttr::ConvertStrToMapTypeTy(ClauseName, |
| 638 | MT)) { |
| 639 | Diag(Tok, diag::err_omp_declare_target_unexpected_clause) |
| 640 | << ClauseName; |
| 641 | break; |
| 642 | } |
| 643 | ConsumeToken(); |
| 644 | } |
| 645 | auto Callback = [this, MT, &SameDirectiveDecls]( |
| 646 | CXXScopeSpec &SS, DeclarationNameInfo NameInfo) { |
| 647 | Actions.ActOnOpenMPDeclareTargetName(getCurScope(), SS, NameInfo, MT, |
| 648 | SameDirectiveDecls); |
| 649 | }; |
| 650 | if (ParseOpenMPSimpleVarList(OMPD_declare_target, Callback, true)) |
| 651 | break; |
| 652 | |
| 653 | // Consume optional ','. |
| 654 | if (Tok.is(tok::comma)) |
| 655 | ConsumeToken(); |
| 656 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 657 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 658 | ConsumeAnyToken(); |
| 659 | return DeclGroupPtrTy(); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 660 | } |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 661 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 662 | // Skip the last annot_pragma_openmp_end. |
| 663 | ConsumeAnyToken(); |
| 664 | |
| 665 | if (!Actions.ActOnStartOpenMPDeclareTargetDirective(DTLoc)) |
| 666 | return DeclGroupPtrTy(); |
| 667 | |
| 668 | DKind = ParseOpenMPDirectiveKind(*this); |
| 669 | while (DKind != OMPD_end_declare_target && DKind != OMPD_declare_target && |
| 670 | Tok.isNot(tok::eof) && Tok.isNot(tok::r_brace)) { |
| 671 | ParsedAttributesWithRange attrs(AttrFactory); |
| 672 | MaybeParseCXX11Attributes(attrs); |
| 673 | MaybeParseMicrosoftAttributes(attrs); |
| 674 | ParseExternalDeclaration(attrs); |
| 675 | if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) { |
| 676 | TentativeParsingAction TPA(*this); |
| 677 | ConsumeToken(); |
| 678 | DKind = ParseOpenMPDirectiveKind(*this); |
| 679 | if (DKind != OMPD_end_declare_target) |
| 680 | TPA.Revert(); |
| 681 | else |
| 682 | TPA.Commit(); |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | if (DKind == OMPD_end_declare_target) { |
| 687 | ConsumeAnyToken(); |
| 688 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 689 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 690 | << getOpenMPDirectiveName(OMPD_end_declare_target); |
| 691 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 692 | } |
| 693 | // Skip the last annot_pragma_openmp_end. |
| 694 | ConsumeAnyToken(); |
| 695 | } else { |
| 696 | Diag(Tok, diag::err_expected_end_declare_target); |
| 697 | Diag(DTLoc, diag::note_matching) << "'#pragma omp declare target'"; |
| 698 | } |
| 699 | Actions.ActOnFinishOpenMPDeclareTargetDirective(); |
| 700 | return DeclGroupPtrTy(); |
| 701 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 702 | case OMPD_unknown: |
| 703 | Diag(Tok, diag::err_omp_unknown_directive); |
| 704 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 705 | case OMPD_parallel: |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 706 | case OMPD_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 707 | case OMPD_task: |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 708 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 709 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 710 | case OMPD_taskwait: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 711 | case OMPD_taskgroup: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 712 | case OMPD_flush: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 713 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 714 | case OMPD_for_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 715 | case OMPD_sections: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 716 | case OMPD_section: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 717 | case OMPD_single: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 718 | case OMPD_master: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 719 | case OMPD_ordered: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 720 | case OMPD_critical: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 721 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 722 | case OMPD_parallel_for_simd: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 723 | case OMPD_parallel_sections: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 724 | case OMPD_atomic: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 725 | case OMPD_target: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 726 | case OMPD_teams: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 727 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 728 | case OMPD_cancel: |
Samuel Antao | 5b0688e | 2015-07-22 16:02:46 +0000 | [diff] [blame] | 729 | case OMPD_target_data: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 730 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 731 | case OMPD_target_exit_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 732 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 733 | case OMPD_target_parallel_for: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 734 | case OMPD_taskloop: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 735 | case OMPD_taskloop_simd: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 736 | case OMPD_distribute: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 737 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 738 | case OMPD_target_update: |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 739 | case OMPD_distribute_parallel_for: |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 740 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 741 | case OMPD_distribute_simd: |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 742 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 743 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 744 | break; |
| 745 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 746 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 747 | ConsumeAnyToken(); |
| 748 | ConsumeAnyToken(); |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 749 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 752 | /// \brief Parsing of declarative or executable OpenMP directives. |
| 753 | /// |
| 754 | /// threadprivate-directive: |
| 755 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
| 756 | /// annot_pragma_openmp_end |
| 757 | /// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 758 | /// declare-reduction-directive: |
| 759 | /// annot_pragma_openmp 'declare' 'reduction' '(' <reduction_id> ':' |
| 760 | /// <type> {',' <type>} ':' <expression> ')' ['initializer' '(' |
| 761 | /// ('omp_priv' '=' <expression>|<function_call>) ')'] |
| 762 | /// annot_pragma_openmp_end |
| 763 | /// |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 764 | /// executable-directive: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 765 | /// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 766 | /// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] | |
| 767 | /// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 768 | /// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 769 | /// 'for simd' | 'parallel for simd' | 'target' | 'target data' | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 770 | /// 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 771 | /// 'distribute' | 'target enter data' | 'target exit data' | |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 772 | /// 'target parallel' | 'target parallel for' | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 773 | /// 'target update' | 'distribute parallel for' | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 774 | /// 'distribute paralle for simd' | 'distribute simd' {clause} |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 775 | /// annot_pragma_openmp_end |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 776 | /// |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 777 | StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( |
| 778 | AllowedContsructsKind Allowed) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 779 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 780 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 781 | SmallVector<OMPClause *, 5> Clauses; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 782 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 783 | FirstClauses(OMPC_unknown + 1); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 784 | unsigned ScopeFlags = |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 785 | Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 786 | SourceLocation Loc = ConsumeToken(), EndLoc; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 787 | auto DKind = ParseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 788 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 789 | // Name of critical directive. |
| 790 | DeclarationNameInfo DirName; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 791 | StmtResult Directive = StmtError(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 792 | bool HasAssociatedStatement = true; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 793 | bool FlushHasClause = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 794 | |
| 795 | switch (DKind) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 796 | case OMPD_threadprivate: { |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 797 | if (Allowed != ACK_Any) { |
| 798 | Diag(Tok, diag::err_omp_immediate_directive) |
| 799 | << getOpenMPDirectiveName(DKind) << 0; |
| 800 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 801 | ConsumeToken(); |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 802 | ThreadprivateListParserHelper Helper(this); |
| 803 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Helper, false)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 804 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 805 | // extra tokens. |
| 806 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 807 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 808 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 809 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 810 | } |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 811 | DeclGroupPtrTy Res = Actions.ActOnOpenMPThreadprivateDirective( |
| 812 | Loc, Helper.getIdentifiers()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 813 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 814 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 815 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 816 | break; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 817 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 818 | case OMPD_declare_reduction: |
| 819 | ConsumeToken(); |
| 820 | if (auto Res = ParseOpenMPDeclareReductionDirective(/*AS=*/AS_none)) { |
| 821 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 822 | // extra tokens. |
| 823 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 824 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 825 | << getOpenMPDirectiveName(OMPD_declare_reduction); |
| 826 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 827 | ConsumeAnyToken(); |
| 828 | } |
| 829 | ConsumeAnyToken(); |
| 830 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 831 | } else |
| 832 | SkipUntil(tok::annot_pragma_openmp_end); |
| 833 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 834 | case OMPD_flush: |
| 835 | if (PP.LookAhead(0).is(tok::l_paren)) { |
| 836 | FlushHasClause = true; |
| 837 | // Push copy of the current token back to stream to properly parse |
| 838 | // pseudo-clause OMPFlushClause. |
| 839 | PP.EnterToken(Tok); |
| 840 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 841 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 842 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 843 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 844 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 845 | case OMPD_cancel: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 846 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 847 | case OMPD_target_exit_data: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 848 | case OMPD_target_update: |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 849 | if (Allowed == ACK_StatementsOpenMPNonStandalone) { |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 850 | Diag(Tok, diag::err_omp_immediate_directive) |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 851 | << getOpenMPDirectiveName(DKind) << 0; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 852 | } |
| 853 | HasAssociatedStatement = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 854 | // Fall through for further analysis. |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 855 | case OMPD_parallel: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 856 | case OMPD_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 857 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 858 | case OMPD_for_simd: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 859 | case OMPD_sections: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 860 | case OMPD_single: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 861 | case OMPD_section: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 862 | case OMPD_master: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 863 | case OMPD_critical: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 864 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 865 | case OMPD_parallel_for_simd: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 866 | case OMPD_parallel_sections: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 867 | case OMPD_task: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 868 | case OMPD_ordered: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 869 | case OMPD_atomic: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 870 | case OMPD_target: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 871 | case OMPD_teams: |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 872 | case OMPD_taskgroup: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 873 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 874 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 875 | case OMPD_target_parallel_for: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 876 | case OMPD_taskloop: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 877 | case OMPD_taskloop_simd: |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 878 | case OMPD_distribute: |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 879 | case OMPD_distribute_parallel_for: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 880 | case OMPD_distribute_parallel_for_simd: |
| 881 | case OMPD_distribute_simd: { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 882 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 883 | // Parse directive name of the 'critical' directive if any. |
| 884 | if (DKind == OMPD_critical) { |
| 885 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 886 | tok::annot_pragma_openmp_end); |
| 887 | if (!T.consumeOpen()) { |
| 888 | if (Tok.isAnyIdentifier()) { |
| 889 | DirName = |
| 890 | DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 891 | ConsumeAnyToken(); |
| 892 | } else { |
| 893 | Diag(Tok, diag::err_omp_expected_identifier_for_critical); |
| 894 | } |
| 895 | T.consumeClose(); |
| 896 | } |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 897 | } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 898 | CancelRegion = ParseOpenMPDirectiveKind(*this); |
| 899 | if (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 900 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 901 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 902 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 903 | if (isOpenMPLoopDirective(DKind)) |
| 904 | ScopeFlags |= Scope::OpenMPLoopDirectiveScope; |
| 905 | if (isOpenMPSimdDirective(DKind)) |
| 906 | ScopeFlags |= Scope::OpenMPSimdDirectiveScope; |
| 907 | ParseScope OMPDirectiveScope(this, ScopeFlags); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 908 | Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 909 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 910 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 911 | OpenMPClauseKind CKind = |
| 912 | Tok.isAnnotation() |
| 913 | ? OMPC_unknown |
| 914 | : FlushHasClause ? OMPC_flush |
| 915 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 916 | Actions.StartOpenMPClause(CKind); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 917 | FlushHasClause = false; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 918 | OMPClause *Clause = |
| 919 | ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 920 | FirstClauses[CKind].setInt(true); |
| 921 | if (Clause) { |
| 922 | FirstClauses[CKind].setPointer(Clause); |
| 923 | Clauses.push_back(Clause); |
| 924 | } |
| 925 | |
| 926 | // Skip ',' if any. |
| 927 | if (Tok.is(tok::comma)) |
| 928 | ConsumeToken(); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 929 | Actions.EndOpenMPClause(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 930 | } |
| 931 | // End location of the directive. |
| 932 | EndLoc = Tok.getLocation(); |
| 933 | // Consume final annot_pragma_openmp_end. |
| 934 | ConsumeToken(); |
| 935 | |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 936 | // OpenMP [2.13.8, ordered Construct, Syntax] |
| 937 | // If the depend clause is specified, the ordered construct is a stand-alone |
| 938 | // directive. |
| 939 | if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) { |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 940 | if (Allowed == ACK_StatementsOpenMPNonStandalone) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 941 | Diag(Loc, diag::err_omp_immediate_directive) |
| 942 | << getOpenMPDirectiveName(DKind) << 1 |
| 943 | << getOpenMPClauseName(OMPC_depend); |
| 944 | } |
| 945 | HasAssociatedStatement = false; |
| 946 | } |
| 947 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 948 | StmtResult AssociatedStmt; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 949 | if (HasAssociatedStatement) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 950 | // The body is a block scope like in Lambdas and Blocks. |
| 951 | Sema::CompoundScopeRAII CompoundScope(Actions); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 952 | Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 953 | Actions.ActOnStartOfCompoundStmt(); |
| 954 | // Parse statement |
| 955 | AssociatedStmt = ParseStatement(); |
| 956 | Actions.ActOnFinishOfCompoundStmt(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 957 | AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 958 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 959 | Directive = Actions.ActOnOpenMPExecutableDirective( |
| 960 | DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc, |
| 961 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 962 | |
| 963 | // Exit scope. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 964 | Actions.EndOpenMPDSABlock(Directive.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 965 | OMPDirectiveScope.Exit(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 966 | break; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 967 | } |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 968 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 969 | case OMPD_declare_target: |
| 970 | case OMPD_end_declare_target: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 971 | Diag(Tok, diag::err_omp_unexpected_directive) |
| 972 | << getOpenMPDirectiveName(DKind); |
| 973 | SkipUntil(tok::annot_pragma_openmp_end); |
| 974 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 975 | case OMPD_unknown: |
| 976 | Diag(Tok, diag::err_omp_unknown_directive); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 977 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 978 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 979 | } |
| 980 | return Directive; |
| 981 | } |
| 982 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 983 | // Parses simple list: |
| 984 | // simple-variable-list: |
| 985 | // '(' id-expression {, id-expression} ')' |
| 986 | // |
| 987 | bool Parser::ParseOpenMPSimpleVarList( |
| 988 | OpenMPDirectiveKind Kind, |
| 989 | const llvm::function_ref<void(CXXScopeSpec &, DeclarationNameInfo)> & |
| 990 | Callback, |
| 991 | bool AllowScopeSpecifier) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 992 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 993 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 994 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 995 | getOpenMPDirectiveName(Kind))) |
| 996 | return true; |
| 997 | bool IsCorrect = true; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 998 | bool NoIdentIsFound = true; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 999 | |
| 1000 | // Read tokens while ')' or annot_pragma_openmp_end is not found. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1001 | while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1002 | CXXScopeSpec SS; |
| 1003 | SourceLocation TemplateKWLoc; |
| 1004 | UnqualifiedId Name; |
| 1005 | // Read var name. |
| 1006 | Token PrevTok = Tok; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1007 | NoIdentIsFound = false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1008 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1009 | if (AllowScopeSpecifier && getLangOpts().CPlusPlus && |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 1010 | ParseOptionalCXXScopeSpecifier(SS, nullptr, false)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1011 | IsCorrect = false; |
| 1012 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1013 | StopBeforeMatch); |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 1014 | } else if (ParseUnqualifiedId(SS, false, false, false, nullptr, |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1015 | TemplateKWLoc, Name)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1016 | IsCorrect = false; |
| 1017 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1018 | StopBeforeMatch); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1019 | } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) && |
| 1020 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1021 | IsCorrect = false; |
| 1022 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1023 | StopBeforeMatch); |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1024 | Diag(PrevTok.getLocation(), diag::err_expected) |
| 1025 | << tok::identifier |
| 1026 | << SourceRange(PrevTok.getLocation(), PrevTokLocation); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1027 | } else { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1028 | Callback(SS, Actions.GetNameFromUnqualifiedId(Name)); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1029 | } |
| 1030 | // Consume ','. |
| 1031 | if (Tok.is(tok::comma)) { |
| 1032 | ConsumeToken(); |
| 1033 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1036 | if (NoIdentIsFound) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1037 | Diag(Tok, diag::err_expected) << tok::identifier; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1038 | IsCorrect = false; |
| 1039 | } |
| 1040 | |
| 1041 | // Parse ')'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1042 | IsCorrect = !T.consumeClose() && IsCorrect; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1043 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1044 | return !IsCorrect; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1045 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1046 | |
| 1047 | /// \brief Parsing of OpenMP clauses. |
| 1048 | /// |
| 1049 | /// clause: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1050 | /// if-clause | final-clause | num_threads-clause | safelen-clause | |
| 1051 | /// default-clause | private-clause | firstprivate-clause | shared-clause |
| 1052 | /// | linear-clause | aligned-clause | collapse-clause | |
| 1053 | /// lastprivate-clause | reduction-clause | proc_bind-clause | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 1054 | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 1055 | /// mergeable-clause | flush-clause | read-clause | write-clause | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1056 | /// update-clause | capture-clause | seq_cst-clause | device-clause | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 1057 | /// simdlen-clause | threads-clause | simd-clause | num_teams-clause | |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1058 | /// thread_limit-clause | priority-clause | grainsize-clause | |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1059 | /// nogroup-clause | num_tasks-clause | hint-clause | to-clause | |
| 1060 | /// from-clause |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1061 | /// |
| 1062 | OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, |
| 1063 | OpenMPClauseKind CKind, bool FirstClause) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1064 | OMPClause *Clause = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1065 | bool ErrorFound = false; |
| 1066 | // Check if clause is allowed for the given directive. |
| 1067 | if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1068 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 1069 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1070 | ErrorFound = true; |
| 1071 | } |
| 1072 | |
| 1073 | switch (CKind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1074 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1075 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1076 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1077 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1078 | case OMPC_collapse: |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 1079 | case OMPC_ordered: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 1080 | case OMPC_device: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1081 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 1082 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1083 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1084 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 1085 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 1086 | case OMPC_hint: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1087 | // OpenMP [2.5, Restrictions] |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1088 | // At most one num_threads clause can appear on the directive. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1089 | // OpenMP [2.8.1, simd construct, Restrictions] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1090 | // Only one safelen clause can appear on a simd directive. |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1091 | // Only one simdlen clause can appear on a simd directive. |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1092 | // Only one collapse clause can appear on a simd directive. |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 1093 | // OpenMP [2.9.1, target data construct, Restrictions] |
| 1094 | // At most one device clause can appear on the directive. |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1095 | // OpenMP [2.11.1, task Construct, Restrictions] |
| 1096 | // At most one if clause can appear on the directive. |
| 1097 | // At most one final clause can appear on the directive. |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1098 | // OpenMP [teams Construct, Restrictions] |
| 1099 | // At most one num_teams clause can appear on the directive. |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 1100 | // At most one thread_limit clause can appear on the directive. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1101 | // OpenMP [2.9.1, task Construct, Restrictions] |
| 1102 | // At most one priority clause can appear on the directive. |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1103 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 1104 | // At most one grainsize clause can appear on the directive. |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 1105 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 1106 | // At most one num_tasks clause can appear on the directive. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1107 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1108 | Diag(Tok, diag::err_omp_more_one_clause) |
| 1109 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1110 | ErrorFound = true; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 1113 | if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren)) |
| 1114 | Clause = ParseOpenMPClause(CKind); |
| 1115 | else |
| 1116 | Clause = ParseOpenMPSingleExprClause(CKind); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1117 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1118 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1119 | case OMPC_proc_bind: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1120 | // OpenMP [2.14.3.1, Restrictions] |
| 1121 | // Only a single default clause may be specified on a parallel, task or |
| 1122 | // teams directive. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1123 | // OpenMP [2.5, parallel Construct, Restrictions] |
| 1124 | // At most one proc_bind clause can appear on the directive. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1125 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1126 | Diag(Tok, diag::err_omp_more_one_clause) |
| 1127 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1128 | ErrorFound = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | Clause = ParseOpenMPSimpleClause(CKind); |
| 1132 | break; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1133 | case OMPC_schedule: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 1134 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 1135 | case OMPC_defaultmap: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1136 | // OpenMP [2.7.1, Restrictions, p. 3] |
| 1137 | // Only one schedule clause can appear on a loop directive. |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 1138 | // OpenMP [2.10.4, Restrictions, p. 106] |
| 1139 | // At most one defaultmap clause can appear on the directive. |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1140 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1141 | Diag(Tok, diag::err_omp_more_one_clause) |
| 1142 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1143 | ErrorFound = true; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1146 | case OMPC_if: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1147 | Clause = ParseOpenMPSingleExprWithArgClause(CKind); |
| 1148 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 1149 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 1150 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 1151 | case OMPC_mergeable: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 1152 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1153 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 1154 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 1155 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 1156 | case OMPC_seq_cst: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 1157 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1158 | case OMPC_simd: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 1159 | case OMPC_nogroup: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1160 | // OpenMP [2.7.1, Restrictions, p. 9] |
| 1161 | // Only one ordered clause can appear on a loop directive. |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 1162 | // OpenMP [2.7.1, Restrictions, C/C++, p. 4] |
| 1163 | // Only one nowait clause can appear on a for directive. |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1164 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1165 | Diag(Tok, diag::err_omp_more_one_clause) |
| 1166 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1167 | ErrorFound = true; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | Clause = ParseOpenMPClause(CKind); |
| 1171 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1172 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1173 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1174 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1175 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1176 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1177 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1178 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1179 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1180 | case OMPC_copyprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1181 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1182 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1183 | case OMPC_map: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 1184 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1185 | case OMPC_from: |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1186 | Clause = ParseOpenMPVarListClause(DKind, CKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1187 | break; |
| 1188 | case OMPC_unknown: |
| 1189 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1190 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1191 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1192 | break; |
| 1193 | case OMPC_threadprivate: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1194 | case OMPC_uniform: |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1195 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 1196 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1197 | SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1198 | break; |
| 1199 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1200 | return ErrorFound ? nullptr : Clause; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 1203 | /// Parses simple expression in parens for single-expression clauses of OpenMP |
| 1204 | /// constructs. |
| 1205 | /// \param RLoc Returned location of right paren. |
| 1206 | ExprResult Parser::ParseOpenMPParensExpr(StringRef ClauseName, |
| 1207 | SourceLocation &RLoc) { |
| 1208 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 1209 | if (T.expectAndConsume(diag::err_expected_lparen_after, ClauseName.data())) |
| 1210 | return ExprError(); |
| 1211 | |
| 1212 | SourceLocation ELoc = Tok.getLocation(); |
| 1213 | ExprResult LHS(ParseCastExpression( |
| 1214 | /*isUnaryExpression=*/false, /*isAddressOfOperand=*/false, NotTypeCast)); |
| 1215 | ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); |
| 1216 | Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc); |
| 1217 | |
| 1218 | // Parse ')'. |
| 1219 | T.consumeClose(); |
| 1220 | |
| 1221 | RLoc = T.getCloseLocation(); |
| 1222 | return Val; |
| 1223 | } |
| 1224 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1225 | /// \brief Parsing of OpenMP clauses with single expressions like 'final', |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1226 | /// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams', |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 1227 | /// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1228 | /// |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1229 | /// final-clause: |
| 1230 | /// 'final' '(' expression ')' |
| 1231 | /// |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1232 | /// num_threads-clause: |
| 1233 | /// 'num_threads' '(' expression ')' |
| 1234 | /// |
| 1235 | /// safelen-clause: |
| 1236 | /// 'safelen' '(' expression ')' |
| 1237 | /// |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1238 | /// simdlen-clause: |
| 1239 | /// 'simdlen' '(' expression ')' |
| 1240 | /// |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1241 | /// collapse-clause: |
| 1242 | /// 'collapse' '(' expression ')' |
| 1243 | /// |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1244 | /// priority-clause: |
| 1245 | /// 'priority' '(' expression ')' |
| 1246 | /// |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1247 | /// grainsize-clause: |
| 1248 | /// 'grainsize' '(' expression ')' |
| 1249 | /// |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 1250 | /// num_tasks-clause: |
| 1251 | /// 'num_tasks' '(' expression ')' |
| 1252 | /// |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 1253 | /// hint-clause: |
| 1254 | /// 'hint' '(' expression ')' |
| 1255 | /// |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1256 | OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) { |
| 1257 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 1258 | SourceLocation LLoc = Tok.getLocation(); |
| 1259 | SourceLocation RLoc; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1260 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 1261 | ExprResult Val = ParseOpenMPParensExpr(getOpenMPClauseName(Kind), RLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1262 | |
| 1263 | if (Val.isInvalid()) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1264 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1265 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 1266 | return Actions.ActOnOpenMPSingleExprClause(Kind, Val.get(), Loc, LLoc, RLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1269 | /// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1270 | /// |
| 1271 | /// default-clause: |
| 1272 | /// 'default' '(' 'none' | 'shared' ') |
| 1273 | /// |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1274 | /// proc_bind-clause: |
| 1275 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 1276 | /// |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1277 | OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) { |
| 1278 | SourceLocation Loc = Tok.getLocation(); |
| 1279 | SourceLocation LOpen = ConsumeToken(); |
| 1280 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1281 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1282 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1283 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1284 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1285 | |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1286 | unsigned Type = getOpenMPSimpleClauseType( |
| 1287 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1288 | SourceLocation TypeLoc = Tok.getLocation(); |
| 1289 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1290 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1291 | ConsumeAnyToken(); |
| 1292 | |
| 1293 | // Parse ')'. |
| 1294 | T.consumeClose(); |
| 1295 | |
| 1296 | return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc, |
| 1297 | Tok.getLocation()); |
| 1298 | } |
| 1299 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1300 | /// \brief Parsing of OpenMP clauses like 'ordered'. |
| 1301 | /// |
| 1302 | /// ordered-clause: |
| 1303 | /// 'ordered' |
| 1304 | /// |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 1305 | /// nowait-clause: |
| 1306 | /// 'nowait' |
| 1307 | /// |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 1308 | /// untied-clause: |
| 1309 | /// 'untied' |
| 1310 | /// |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 1311 | /// mergeable-clause: |
| 1312 | /// 'mergeable' |
| 1313 | /// |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 1314 | /// read-clause: |
| 1315 | /// 'read' |
| 1316 | /// |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 1317 | /// threads-clause: |
| 1318 | /// 'threads' |
| 1319 | /// |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1320 | /// simd-clause: |
| 1321 | /// 'simd' |
| 1322 | /// |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 1323 | /// nogroup-clause: |
| 1324 | /// 'nogroup' |
| 1325 | /// |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1326 | OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) { |
| 1327 | SourceLocation Loc = Tok.getLocation(); |
| 1328 | ConsumeAnyToken(); |
| 1329 | |
| 1330 | return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation()); |
| 1331 | } |
| 1332 | |
| 1333 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1334 | /// \brief Parsing of OpenMP clauses with single expressions and some additional |
| 1335 | /// argument like 'schedule' or 'dist_schedule'. |
| 1336 | /// |
| 1337 | /// schedule-clause: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1338 | /// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ] |
| 1339 | /// ')' |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1340 | /// |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1341 | /// if-clause: |
| 1342 | /// 'if' '(' [ directive-name-modifier ':' ] expression ')' |
| 1343 | /// |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 1344 | /// defaultmap: |
| 1345 | /// 'defaultmap' '(' modifier ':' kind ')' |
| 1346 | /// |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1347 | OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) { |
| 1348 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1349 | SourceLocation DelimLoc; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1350 | // Parse '('. |
| 1351 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 1352 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1353 | getOpenMPClauseName(Kind))) |
| 1354 | return nullptr; |
| 1355 | |
| 1356 | ExprResult Val; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1357 | SmallVector<unsigned, 4> Arg; |
| 1358 | SmallVector<SourceLocation, 4> KLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1359 | if (Kind == OMPC_schedule) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1360 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 1361 | Arg.resize(NumberOfElements); |
| 1362 | KLoc.resize(NumberOfElements); |
| 1363 | Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 1364 | Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 1365 | Arg[ScheduleKind] = OMPC_SCHEDULE_unknown; |
| 1366 | auto KindModifier = getOpenMPSimpleClauseType( |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1367 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1368 | if (KindModifier > OMPC_SCHEDULE_unknown) { |
| 1369 | // Parse 'modifier' |
| 1370 | Arg[Modifier1] = KindModifier; |
| 1371 | KLoc[Modifier1] = Tok.getLocation(); |
| 1372 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1373 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1374 | ConsumeAnyToken(); |
| 1375 | if (Tok.is(tok::comma)) { |
| 1376 | // Parse ',' 'modifier' |
| 1377 | ConsumeAnyToken(); |
| 1378 | KindModifier = getOpenMPSimpleClauseType( |
| 1379 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 1380 | Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown |
| 1381 | ? KindModifier |
Aaron Ballman | ad8a104 | 2015-12-28 15:52:46 +0000 | [diff] [blame] | 1382 | : (unsigned)OMPC_SCHEDULE_unknown; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1383 | KLoc[Modifier2] = Tok.getLocation(); |
| 1384 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1385 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1386 | ConsumeAnyToken(); |
| 1387 | } |
| 1388 | // Parse ':' |
| 1389 | if (Tok.is(tok::colon)) |
| 1390 | ConsumeAnyToken(); |
| 1391 | else |
| 1392 | Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier"; |
| 1393 | KindModifier = getOpenMPSimpleClauseType( |
| 1394 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 1395 | } |
| 1396 | Arg[ScheduleKind] = KindModifier; |
| 1397 | KLoc[ScheduleKind] = Tok.getLocation(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1398 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1399 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1400 | ConsumeAnyToken(); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1401 | if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static || |
| 1402 | Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic || |
| 1403 | Arg[ScheduleKind] == OMPC_SCHEDULE_guided) && |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1404 | Tok.is(tok::comma)) |
| 1405 | DelimLoc = ConsumeAnyToken(); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 1406 | } else if (Kind == OMPC_dist_schedule) { |
| 1407 | Arg.push_back(getOpenMPSimpleClauseType( |
| 1408 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 1409 | KLoc.push_back(Tok.getLocation()); |
| 1410 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1411 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1412 | ConsumeAnyToken(); |
| 1413 | if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma)) |
| 1414 | DelimLoc = ConsumeAnyToken(); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 1415 | } else if (Kind == OMPC_defaultmap) { |
| 1416 | // Get a defaultmap modifier |
| 1417 | Arg.push_back(getOpenMPSimpleClauseType( |
| 1418 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 1419 | KLoc.push_back(Tok.getLocation()); |
| 1420 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1421 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1422 | ConsumeAnyToken(); |
| 1423 | // Parse ':' |
| 1424 | if (Tok.is(tok::colon)) |
| 1425 | ConsumeAnyToken(); |
| 1426 | else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown) |
| 1427 | Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier"; |
| 1428 | // Get a defaultmap kind |
| 1429 | Arg.push_back(getOpenMPSimpleClauseType( |
| 1430 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 1431 | KLoc.push_back(Tok.getLocation()); |
| 1432 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1433 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1434 | ConsumeAnyToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1435 | } else { |
| 1436 | assert(Kind == OMPC_if); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1437 | KLoc.push_back(Tok.getLocation()); |
| 1438 | Arg.push_back(ParseOpenMPDirectiveKind(*this)); |
| 1439 | if (Arg.back() != OMPD_unknown) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1440 | ConsumeToken(); |
| 1441 | if (Tok.is(tok::colon)) |
| 1442 | DelimLoc = ConsumeToken(); |
| 1443 | else |
| 1444 | Diag(Tok, diag::warn_pragma_expected_colon) |
| 1445 | << "directive name modifier"; |
| 1446 | } |
| 1447 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1448 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 1449 | bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) || |
| 1450 | (Kind == OMPC_dist_schedule && DelimLoc.isValid()) || |
| 1451 | Kind == OMPC_if; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1452 | if (NeedAnExpression) { |
| 1453 | SourceLocation ELoc = Tok.getLocation(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1454 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 1455 | Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1456 | Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | // Parse ')'. |
| 1460 | T.consumeClose(); |
| 1461 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1462 | if (NeedAnExpression && Val.isInvalid()) |
| 1463 | return nullptr; |
| 1464 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1465 | return Actions.ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1466 | Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1467 | T.getCloseLocation()); |
| 1468 | } |
| 1469 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1470 | static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, |
| 1471 | UnqualifiedId &ReductionId) { |
| 1472 | SourceLocation TemplateKWLoc; |
| 1473 | if (ReductionIdScopeSpec.isEmpty()) { |
| 1474 | auto OOK = OO_None; |
| 1475 | switch (P.getCurToken().getKind()) { |
| 1476 | case tok::plus: |
| 1477 | OOK = OO_Plus; |
| 1478 | break; |
| 1479 | case tok::minus: |
| 1480 | OOK = OO_Minus; |
| 1481 | break; |
| 1482 | case tok::star: |
| 1483 | OOK = OO_Star; |
| 1484 | break; |
| 1485 | case tok::amp: |
| 1486 | OOK = OO_Amp; |
| 1487 | break; |
| 1488 | case tok::pipe: |
| 1489 | OOK = OO_Pipe; |
| 1490 | break; |
| 1491 | case tok::caret: |
| 1492 | OOK = OO_Caret; |
| 1493 | break; |
| 1494 | case tok::ampamp: |
| 1495 | OOK = OO_AmpAmp; |
| 1496 | break; |
| 1497 | case tok::pipepipe: |
| 1498 | OOK = OO_PipePipe; |
| 1499 | break; |
| 1500 | default: |
| 1501 | break; |
| 1502 | } |
| 1503 | if (OOK != OO_None) { |
| 1504 | SourceLocation OpLoc = P.ConsumeToken(); |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1505 | SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()}; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1506 | ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations); |
| 1507 | return false; |
| 1508 | } |
| 1509 | } |
| 1510 | return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false, |
| 1511 | /*AllowDestructorName*/ false, |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 1512 | /*AllowConstructorName*/ false, nullptr, |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1513 | TemplateKWLoc, ReductionId); |
| 1514 | } |
| 1515 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1516 | /// Parses clauses with list. |
| 1517 | bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind, |
| 1518 | OpenMPClauseKind Kind, |
| 1519 | SmallVectorImpl<Expr *> &Vars, |
| 1520 | OpenMPVarListDataTy &Data) { |
| 1521 | UnqualifiedId UnqualifiedReductionId; |
| 1522 | bool InvalidReductionId = false; |
| 1523 | bool MapTypeModifierSpecified = false; |
| 1524 | |
| 1525 | // Parse '('. |
| 1526 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 1527 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1528 | getOpenMPClauseName(Kind))) |
| 1529 | return true; |
| 1530 | |
| 1531 | bool NeedRParenForLinear = false; |
| 1532 | BalancedDelimiterTracker LinearT(*this, tok::l_paren, |
| 1533 | tok::annot_pragma_openmp_end); |
| 1534 | // Handle reduction-identifier for reduction clause. |
| 1535 | if (Kind == OMPC_reduction) { |
| 1536 | ColonProtectionRAIIObject ColonRAII(*this); |
| 1537 | if (getLangOpts().CPlusPlus) |
| 1538 | ParseOptionalCXXScopeSpecifier(Data.ReductionIdScopeSpec, |
| 1539 | /*ObjectType=*/nullptr, |
| 1540 | /*EnteringContext=*/false); |
| 1541 | InvalidReductionId = ParseReductionId(*this, Data.ReductionIdScopeSpec, |
| 1542 | UnqualifiedReductionId); |
| 1543 | if (InvalidReductionId) { |
| 1544 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 1545 | StopBeforeMatch); |
| 1546 | } |
| 1547 | if (Tok.is(tok::colon)) |
| 1548 | Data.ColonLoc = ConsumeToken(); |
| 1549 | else |
| 1550 | Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier"; |
| 1551 | if (!InvalidReductionId) |
| 1552 | Data.ReductionId = |
| 1553 | Actions.GetNameFromUnqualifiedId(UnqualifiedReductionId); |
| 1554 | } else if (Kind == OMPC_depend) { |
| 1555 | // Handle dependency type for depend clause. |
| 1556 | ColonProtectionRAIIObject ColonRAII(*this); |
| 1557 | Data.DepKind = |
| 1558 | static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType( |
| 1559 | Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : "")); |
| 1560 | Data.DepLinMapLoc = Tok.getLocation(); |
| 1561 | |
| 1562 | if (Data.DepKind == OMPC_DEPEND_unknown) { |
| 1563 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 1564 | StopBeforeMatch); |
| 1565 | } else { |
| 1566 | ConsumeToken(); |
| 1567 | // Special processing for depend(source) clause. |
| 1568 | if (DKind == OMPD_ordered && Data.DepKind == OMPC_DEPEND_source) { |
| 1569 | // Parse ')'. |
| 1570 | T.consumeClose(); |
| 1571 | return false; |
| 1572 | } |
| 1573 | } |
| 1574 | if (Tok.is(tok::colon)) |
| 1575 | Data.ColonLoc = ConsumeToken(); |
| 1576 | else { |
| 1577 | Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren |
| 1578 | : diag::warn_pragma_expected_colon) |
| 1579 | << "dependency type"; |
| 1580 | } |
| 1581 | } else if (Kind == OMPC_linear) { |
| 1582 | // Try to parse modifier if any. |
| 1583 | if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) { |
| 1584 | Data.LinKind = static_cast<OpenMPLinearClauseKind>( |
| 1585 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))); |
| 1586 | Data.DepLinMapLoc = ConsumeToken(); |
| 1587 | LinearT.consumeOpen(); |
| 1588 | NeedRParenForLinear = true; |
| 1589 | } |
| 1590 | } else if (Kind == OMPC_map) { |
| 1591 | // Handle map type for map clause. |
| 1592 | ColonProtectionRAIIObject ColonRAII(*this); |
| 1593 | |
| 1594 | /// The map clause modifier token can be either a identifier or the C++ |
| 1595 | /// delete keyword. |
| 1596 | auto &&IsMapClauseModifierToken = [](const Token &Tok) -> bool { |
| 1597 | return Tok.isOneOf(tok::identifier, tok::kw_delete); |
| 1598 | }; |
| 1599 | |
| 1600 | // The first identifier may be a list item, a map-type or a |
| 1601 | // map-type-modifier. The map modifier can also be delete which has the same |
| 1602 | // spelling of the C++ delete keyword. |
| 1603 | Data.MapType = |
| 1604 | IsMapClauseModifierToken(Tok) |
| 1605 | ? static_cast<OpenMPMapClauseKind>( |
| 1606 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))) |
| 1607 | : OMPC_MAP_unknown; |
| 1608 | Data.DepLinMapLoc = Tok.getLocation(); |
| 1609 | bool ColonExpected = false; |
| 1610 | |
| 1611 | if (IsMapClauseModifierToken(Tok)) { |
| 1612 | if (PP.LookAhead(0).is(tok::colon)) { |
| 1613 | if (Data.MapType == OMPC_MAP_unknown) |
| 1614 | Diag(Tok, diag::err_omp_unknown_map_type); |
| 1615 | else if (Data.MapType == OMPC_MAP_always) |
| 1616 | Diag(Tok, diag::err_omp_map_type_missing); |
| 1617 | ConsumeToken(); |
| 1618 | } else if (PP.LookAhead(0).is(tok::comma)) { |
| 1619 | if (IsMapClauseModifierToken(PP.LookAhead(1)) && |
| 1620 | PP.LookAhead(2).is(tok::colon)) { |
| 1621 | Data.MapTypeModifier = Data.MapType; |
| 1622 | if (Data.MapTypeModifier != OMPC_MAP_always) { |
| 1623 | Diag(Tok, diag::err_omp_unknown_map_type_modifier); |
| 1624 | Data.MapTypeModifier = OMPC_MAP_unknown; |
| 1625 | } else |
| 1626 | MapTypeModifierSpecified = true; |
| 1627 | |
| 1628 | ConsumeToken(); |
| 1629 | ConsumeToken(); |
| 1630 | |
| 1631 | Data.MapType = |
| 1632 | IsMapClauseModifierToken(Tok) |
| 1633 | ? static_cast<OpenMPMapClauseKind>( |
| 1634 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))) |
| 1635 | : OMPC_MAP_unknown; |
| 1636 | if (Data.MapType == OMPC_MAP_unknown || |
| 1637 | Data.MapType == OMPC_MAP_always) |
| 1638 | Diag(Tok, diag::err_omp_unknown_map_type); |
| 1639 | ConsumeToken(); |
| 1640 | } else { |
| 1641 | Data.MapType = OMPC_MAP_tofrom; |
| 1642 | Data.IsMapTypeImplicit = true; |
| 1643 | } |
| 1644 | } else { |
| 1645 | Data.MapType = OMPC_MAP_tofrom; |
| 1646 | Data.IsMapTypeImplicit = true; |
| 1647 | } |
| 1648 | } else { |
| 1649 | Data.MapType = OMPC_MAP_tofrom; |
| 1650 | Data.IsMapTypeImplicit = true; |
| 1651 | } |
| 1652 | |
| 1653 | if (Tok.is(tok::colon)) |
| 1654 | Data.ColonLoc = ConsumeToken(); |
| 1655 | else if (ColonExpected) |
| 1656 | Diag(Tok, diag::warn_pragma_expected_colon) << "map type"; |
| 1657 | } |
| 1658 | |
| 1659 | bool IsComma = |
| 1660 | (Kind != OMPC_reduction && Kind != OMPC_depend && Kind != OMPC_map) || |
| 1661 | (Kind == OMPC_reduction && !InvalidReductionId) || |
| 1662 | (Kind == OMPC_map && Data.MapType != OMPC_MAP_unknown && |
| 1663 | (!MapTypeModifierSpecified || |
| 1664 | Data.MapTypeModifier == OMPC_MAP_always)) || |
| 1665 | (Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown); |
| 1666 | const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned); |
| 1667 | while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) && |
| 1668 | Tok.isNot(tok::annot_pragma_openmp_end))) { |
| 1669 | ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail); |
| 1670 | // Parse variable |
| 1671 | ExprResult VarExpr = |
| 1672 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
| 1673 | if (VarExpr.isUsable()) |
| 1674 | Vars.push_back(VarExpr.get()); |
| 1675 | else { |
| 1676 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 1677 | StopBeforeMatch); |
| 1678 | } |
| 1679 | // Skip ',' if any |
| 1680 | IsComma = Tok.is(tok::comma); |
| 1681 | if (IsComma) |
| 1682 | ConsumeToken(); |
| 1683 | else if (Tok.isNot(tok::r_paren) && |
| 1684 | Tok.isNot(tok::annot_pragma_openmp_end) && |
| 1685 | (!MayHaveTail || Tok.isNot(tok::colon))) |
| 1686 | Diag(Tok, diag::err_omp_expected_punc) |
| 1687 | << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush) |
| 1688 | : getOpenMPClauseName(Kind)) |
| 1689 | << (Kind == OMPC_flush); |
| 1690 | } |
| 1691 | |
| 1692 | // Parse ')' for linear clause with modifier. |
| 1693 | if (NeedRParenForLinear) |
| 1694 | LinearT.consumeClose(); |
| 1695 | |
| 1696 | // Parse ':' linear-step (or ':' alignment). |
| 1697 | const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon); |
| 1698 | if (MustHaveTail) { |
| 1699 | Data.ColonLoc = Tok.getLocation(); |
| 1700 | SourceLocation ELoc = ConsumeToken(); |
| 1701 | ExprResult Tail = ParseAssignmentExpression(); |
| 1702 | Tail = Actions.ActOnFinishFullExpr(Tail.get(), ELoc); |
| 1703 | if (Tail.isUsable()) |
| 1704 | Data.TailExpr = Tail.get(); |
| 1705 | else |
| 1706 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 1707 | StopBeforeMatch); |
| 1708 | } |
| 1709 | |
| 1710 | // Parse ')'. |
| 1711 | T.consumeClose(); |
| 1712 | if ((Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown && |
| 1713 | Vars.empty()) || |
| 1714 | (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) || |
| 1715 | (MustHaveTail && !Data.TailExpr) || InvalidReductionId) |
| 1716 | return true; |
| 1717 | return false; |
| 1718 | } |
| 1719 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1720 | /// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate', |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1721 | /// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1722 | /// |
| 1723 | /// private-clause: |
| 1724 | /// 'private' '(' list ')' |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1725 | /// firstprivate-clause: |
| 1726 | /// 'firstprivate' '(' list ')' |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1727 | /// lastprivate-clause: |
| 1728 | /// 'lastprivate' '(' list ')' |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1729 | /// shared-clause: |
| 1730 | /// 'shared' '(' list ')' |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1731 | /// linear-clause: |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1732 | /// 'linear' '(' linear-list [ ':' linear-step ] ')' |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1733 | /// aligned-clause: |
| 1734 | /// 'aligned' '(' list [ ':' alignment ] ')' |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1735 | /// reduction-clause: |
| 1736 | /// 'reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1737 | /// copyprivate-clause: |
| 1738 | /// 'copyprivate' '(' list ')' |
| 1739 | /// flush-clause: |
| 1740 | /// 'flush' '(' list ')' |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1741 | /// depend-clause: |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1742 | /// 'depend' '(' in | out | inout : list | source ')' |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1743 | /// map-clause: |
| 1744 | /// 'map' '(' [ [ always , ] |
| 1745 | /// to | from | tofrom | alloc | release | delete ':' ] list ')'; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 1746 | /// to-clause: |
| 1747 | /// 'to' '(' list ')' |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1748 | /// from-clause: |
| 1749 | /// 'from' '(' list ')' |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1750 | /// |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1751 | /// For 'linear' clause linear-list may have the following forms: |
| 1752 | /// list |
| 1753 | /// modifier(list) |
| 1754 | /// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++). |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1755 | OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, |
| 1756 | OpenMPClauseKind Kind) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1757 | SourceLocation Loc = Tok.getLocation(); |
| 1758 | SourceLocation LOpen = ConsumeToken(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1759 | SmallVector<Expr *, 4> Vars; |
| 1760 | OpenMPVarListDataTy Data; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1761 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1762 | if (ParseOpenMPVarList(DKind, Kind, Vars, Data)) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1763 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1764 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1765 | return Actions.ActOnOpenMPVarListClause( |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1766 | Kind, Vars, Data.TailExpr, Loc, LOpen, Data.ColonLoc, Tok.getLocation(), |
| 1767 | Data.ReductionIdScopeSpec, Data.ReductionId, Data.DepKind, Data.LinKind, |
| 1768 | Data.MapTypeModifier, Data.MapType, Data.IsMapTypeImplicit, |
| 1769 | Data.DepLinMapLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |