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 | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 34 | OMPD_enter, |
| 35 | OMPD_exit, |
| 36 | OMPD_point, |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame^] | 37 | OMPD_reduction, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 38 | OMPD_target_enter, |
| 39 | OMPD_target_exit |
| 40 | }; |
| 41 | } // namespace |
| 42 | |
| 43 | // Map token string to extended OMP token kind that are |
| 44 | // OpenMPDirectiveKind + OpenMPDirectiveKindEx. |
| 45 | static unsigned getOpenMPDirectiveKindEx(StringRef S) { |
| 46 | auto DKind = getOpenMPDirectiveKind(S); |
| 47 | if (DKind != OMPD_unknown) |
| 48 | return DKind; |
| 49 | |
| 50 | return llvm::StringSwitch<unsigned>(S) |
| 51 | .Case("cancellation", OMPD_cancellation) |
| 52 | .Case("data", OMPD_data) |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame^] | 53 | .Case("declare", OMPD_declare) |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 54 | .Case("enter", OMPD_enter) |
| 55 | .Case("exit", OMPD_exit) |
| 56 | .Case("point", OMPD_point) |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame^] | 57 | .Case("reduction", OMPD_reduction) |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 58 | .Default(OMPD_unknown); |
| 59 | } |
| 60 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 61 | static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) { |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 62 | // Array of foldings: F[i][0] F[i][1] ===> F[i][2]. |
| 63 | // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd |
| 64 | // TODO: add other combined directives in topological order. |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 65 | static const unsigned F[][3] = { |
| 66 | { OMPD_cancellation, OMPD_point, OMPD_cancellation_point }, |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame^] | 67 | { OMPD_declare, OMPD_reduction, OMPD_declare_reduction }, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 68 | { OMPD_target, OMPD_data, OMPD_target_data }, |
| 69 | { OMPD_target, OMPD_enter, OMPD_target_enter }, |
| 70 | { OMPD_target, OMPD_exit, OMPD_target_exit }, |
| 71 | { OMPD_target_enter, OMPD_data, OMPD_target_enter_data }, |
| 72 | { OMPD_target_exit, OMPD_data, OMPD_target_exit_data }, |
| 73 | { OMPD_for, OMPD_simd, OMPD_for_simd }, |
| 74 | { OMPD_parallel, OMPD_for, OMPD_parallel_for }, |
| 75 | { OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd }, |
| 76 | { OMPD_parallel, OMPD_sections, OMPD_parallel_sections }, |
| 77 | { OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd }, |
| 78 | { OMPD_target, OMPD_parallel, OMPD_target_parallel }, |
| 79 | { OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for } |
| 80 | }; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame^] | 81 | enum { CancellationPoint = 0, DeclareReduction = 1, TargetData = 2 }; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 82 | auto Tok = P.getCurToken(); |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 83 | unsigned DKind = |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 84 | Tok.isAnnotation() |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 85 | ? static_cast<unsigned>(OMPD_unknown) |
| 86 | : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok)); |
| 87 | if (DKind == OMPD_unknown) |
| 88 | return OMPD_unknown; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 89 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 90 | for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) { |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 91 | if (DKind != F[i][0]) |
| 92 | continue; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 93 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 94 | Tok = P.getPreprocessor().LookAhead(0); |
| 95 | unsigned SDKind = |
| 96 | Tok.isAnnotation() |
| 97 | ? static_cast<unsigned>(OMPD_unknown) |
| 98 | : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok)); |
| 99 | if (SDKind == OMPD_unknown) |
| 100 | continue; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 101 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 102 | if (SDKind == F[i][1]) { |
| 103 | P.ConsumeToken(); |
| 104 | DKind = F[i][2]; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 105 | } |
| 106 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame^] | 107 | return DKind < OMPD_unknown ? static_cast<OpenMPDirectiveKind>(DKind) |
| 108 | : OMPD_unknown; |
| 109 | } |
| 110 | |
| 111 | static DeclarationName parseOpenMPReductionId(Parser &P) { |
| 112 | const Token Tok = P.getCurToken(); |
| 113 | Sema &Actions = P.getActions(); |
| 114 | OverloadedOperatorKind OOK = OO_None; |
| 115 | switch (Tok.getKind()) { |
| 116 | case tok::plus: // '+' |
| 117 | OOK = OO_Plus; |
| 118 | break; |
| 119 | case tok::minus: // '-' |
| 120 | OOK = OO_Minus; |
| 121 | break; |
| 122 | case tok::star: // '*' |
| 123 | OOK = OO_Star; |
| 124 | break; |
| 125 | case tok::amp: // '&' |
| 126 | OOK = OO_Amp; |
| 127 | break; |
| 128 | case tok::pipe: // '|' |
| 129 | OOK = OO_Pipe; |
| 130 | break; |
| 131 | case tok::caret: // '^' |
| 132 | OOK = OO_Caret; |
| 133 | break; |
| 134 | case tok::ampamp: // '&&' |
| 135 | OOK = OO_AmpAmp; |
| 136 | break; |
| 137 | case tok::pipepipe: // '||' |
| 138 | OOK = OO_PipePipe; |
| 139 | break; |
| 140 | case tok::identifier: // identifier |
| 141 | break; |
| 142 | default: |
| 143 | P.Diag(Tok.getLocation(), diag::err_omp_expected_reduction_identifier); |
| 144 | P.SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 145 | Parser::StopBeforeMatch); |
| 146 | return DeclarationName(); |
| 147 | } |
| 148 | P.ConsumeToken(); |
| 149 | auto &DeclNames = Actions.getASTContext().DeclarationNames; |
| 150 | return OOK == OO_None ? DeclNames.getIdentifier(Tok.getIdentifierInfo()) |
| 151 | : DeclNames.getCXXOperatorName(OOK); |
| 152 | } |
| 153 | |
| 154 | /// \brief Parse 'omp declare reduction' construct. |
| 155 | /// |
| 156 | /// declare-reduction-directive: |
| 157 | /// annot_pragma_openmp 'declare' 'reduction' |
| 158 | /// '(' <reduction_id> ':' <type> {',' <type>} ':' <expression> ')' |
| 159 | /// ['initializer' '(' ('omp_priv' '=' <expression>)|<function_call> ')'] |
| 160 | /// annot_pragma_openmp_end |
| 161 | /// <reduction_id> is either a base language identifier or one of the following |
| 162 | /// operators: '+', '-', '*', '&', '|', '^', '&&' and '||'. |
| 163 | /// |
| 164 | Parser::DeclGroupPtrTy |
| 165 | Parser::ParseOpenMPDeclareReductionDirective(AccessSpecifier AS) { |
| 166 | // Parse '('. |
| 167 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 168 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 169 | getOpenMPDirectiveName(OMPD_declare_reduction))) { |
| 170 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 171 | return DeclGroupPtrTy(); |
| 172 | } |
| 173 | |
| 174 | DeclarationName Name = parseOpenMPReductionId(*this); |
| 175 | if (Name.isEmpty() && Tok.is(tok::annot_pragma_openmp_end)) |
| 176 | return DeclGroupPtrTy(); |
| 177 | |
| 178 | // Consume ':'. |
| 179 | bool IsCorrect = !ExpectAndConsume(tok::colon); |
| 180 | |
| 181 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 182 | return DeclGroupPtrTy(); |
| 183 | |
| 184 | if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) { |
| 185 | Diag(Tok.getLocation(), diag::err_expected_type); |
| 186 | IsCorrect = false; |
| 187 | } |
| 188 | |
| 189 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 190 | return DeclGroupPtrTy(); |
| 191 | |
| 192 | SmallVector<std::pair<QualType, SourceLocation>, 8> ReductionTypes; |
| 193 | // Parse list of types until ':' token. |
| 194 | do { |
| 195 | ColonProtectionRAIIObject ColonRAII(*this); |
| 196 | SourceRange Range; |
| 197 | TypeResult TR = ParseTypeName(&Range, Declarator::PrototypeContext, AS); |
| 198 | if (TR.isUsable()) { |
| 199 | auto ReductionType = |
| 200 | Actions.ActOnOpenMPDeclareReductionType(Range.getBegin(), TR); |
| 201 | if (!ReductionType.isNull()) { |
| 202 | ReductionTypes.push_back( |
| 203 | std::make_pair(ReductionType, Range.getBegin())); |
| 204 | } |
| 205 | } else { |
| 206 | SkipUntil(tok::comma, tok::colon, tok::annot_pragma_openmp_end, |
| 207 | StopBeforeMatch); |
| 208 | } |
| 209 | |
| 210 | if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) |
| 211 | break; |
| 212 | |
| 213 | // Consume ','. |
| 214 | if (ExpectAndConsume(tok::comma)) { |
| 215 | IsCorrect = false; |
| 216 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 217 | Diag(Tok.getLocation(), diag::err_expected_type); |
| 218 | return DeclGroupPtrTy(); |
| 219 | } |
| 220 | } |
| 221 | } while (Tok.isNot(tok::annot_pragma_openmp_end)); |
| 222 | |
| 223 | if (ReductionTypes.empty()) { |
| 224 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 225 | return DeclGroupPtrTy(); |
| 226 | } |
| 227 | |
| 228 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 229 | return DeclGroupPtrTy(); |
| 230 | |
| 231 | // Consume ':'. |
| 232 | if (ExpectAndConsume(tok::colon)) |
| 233 | IsCorrect = false; |
| 234 | |
| 235 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 236 | Diag(Tok.getLocation(), diag::err_expected_expression); |
| 237 | return DeclGroupPtrTy(); |
| 238 | } |
| 239 | |
| 240 | DeclGroupPtrTy DRD = Actions.ActOnOpenMPDeclareReductionDirectiveStart( |
| 241 | getCurScope(), Actions.getCurLexicalContext(), Name, ReductionTypes, AS); |
| 242 | |
| 243 | // Parse <combiner> expression and then parse initializer if any for each |
| 244 | // correct type. |
| 245 | unsigned I = 0, E = ReductionTypes.size(); |
| 246 | for (auto *D : DRD.get()) { |
| 247 | TentativeParsingAction TPA(*this); |
| 248 | ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope | |
| 249 | Scope::OpenMPDirectiveScope); |
| 250 | // Parse <combiner> expression. |
| 251 | Actions.ActOnOpenMPDeclareReductionCombinerStart(getCurScope(), D); |
| 252 | ExprResult CombinerResult = |
| 253 | Actions.ActOnFinishFullExpr(ParseAssignmentExpression().get(), |
| 254 | D->getLocation(), /*DiscardedValue=*/true); |
| 255 | Actions.ActOnOpenMPDeclareReductionCombinerEnd(D, CombinerResult.get()); |
| 256 | |
| 257 | if (CombinerResult.isInvalid() && Tok.isNot(tok::r_paren) && |
| 258 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 259 | TPA.Commit(); |
| 260 | IsCorrect = false; |
| 261 | break; |
| 262 | } |
| 263 | IsCorrect = !T.consumeClose() && IsCorrect && CombinerResult.isUsable(); |
| 264 | ExprResult InitializerResult; |
| 265 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 266 | // Parse <initializer> expression. |
| 267 | if (Tok.is(tok::identifier) && |
| 268 | Tok.getIdentifierInfo()->isStr("initializer")) |
| 269 | ConsumeToken(); |
| 270 | else { |
| 271 | Diag(Tok.getLocation(), diag::err_expected) << "'initializer'"; |
| 272 | TPA.Commit(); |
| 273 | IsCorrect = false; |
| 274 | break; |
| 275 | } |
| 276 | // Parse '('. |
| 277 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 278 | tok::annot_pragma_openmp_end); |
| 279 | IsCorrect = |
| 280 | !T.expectAndConsume(diag::err_expected_lparen_after, "initializer") && |
| 281 | IsCorrect; |
| 282 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 283 | ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope | |
| 284 | Scope::OpenMPDirectiveScope); |
| 285 | // Parse expression. |
| 286 | Actions.ActOnOpenMPDeclareReductionInitializerStart(getCurScope(), D); |
| 287 | InitializerResult = Actions.ActOnFinishFullExpr( |
| 288 | ParseAssignmentExpression().get(), D->getLocation(), |
| 289 | /*DiscardedValue=*/true); |
| 290 | Actions.ActOnOpenMPDeclareReductionInitializerEnd( |
| 291 | D, InitializerResult.get()); |
| 292 | if (InitializerResult.isInvalid() && Tok.isNot(tok::r_paren) && |
| 293 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 294 | TPA.Commit(); |
| 295 | IsCorrect = false; |
| 296 | break; |
| 297 | } |
| 298 | IsCorrect = |
| 299 | !T.consumeClose() && IsCorrect && !InitializerResult.isInvalid(); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | ++I; |
| 304 | // Revert parsing if not the last type, otherwise accept it, we're done with |
| 305 | // parsing. |
| 306 | if (I != E) |
| 307 | TPA.Revert(); |
| 308 | else |
| 309 | TPA.Commit(); |
| 310 | } |
| 311 | return Actions.ActOnOpenMPDeclareReductionDirectiveEnd(getCurScope(), DRD, |
| 312 | IsCorrect); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 315 | /// \brief Parsing of declarative OpenMP directives. |
| 316 | /// |
| 317 | /// threadprivate-directive: |
| 318 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame^] | 319 | /// annot_pragma_openmp_end |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 320 | /// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame^] | 321 | /// declare-reduction-directive: |
| 322 | /// annot_pragma_openmp 'declare' 'reduction' [...] |
| 323 | /// annot_pragma_openmp_end |
| 324 | /// |
| 325 | Parser::DeclGroupPtrTy |
| 326 | Parser::ParseOpenMPDeclarativeDirective(AccessSpecifier AS) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 327 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 328 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 329 | |
| 330 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 331 | SmallVector<Expr *, 5> Identifiers; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 332 | auto DKind = ParseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 333 | |
| 334 | switch (DKind) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 335 | case OMPD_threadprivate: |
| 336 | ConsumeToken(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 337 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 338 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 339 | // extra tokens. |
| 340 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 341 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 342 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 343 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 344 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 345 | // Skip the last annot_pragma_openmp_end. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 346 | ConsumeToken(); |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 347 | return Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 348 | } |
| 349 | break; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame^] | 350 | case OMPD_declare_reduction: |
| 351 | ConsumeToken(); |
| 352 | if (auto Res = ParseOpenMPDeclareReductionDirective(AS)) { |
| 353 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 354 | // extra tokens. |
| 355 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 356 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 357 | << getOpenMPDirectiveName(OMPD_declare_reduction); |
| 358 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 359 | ConsumeAnyToken(); |
| 360 | } |
| 361 | // Skip the last annot_pragma_openmp_end. |
| 362 | ConsumeToken(); |
| 363 | return Res; |
| 364 | } |
| 365 | break; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 366 | case OMPD_unknown: |
| 367 | Diag(Tok, diag::err_omp_unknown_directive); |
| 368 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 369 | case OMPD_parallel: |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 370 | case OMPD_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 371 | case OMPD_task: |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 372 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 373 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 374 | case OMPD_taskwait: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 375 | case OMPD_taskgroup: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 376 | case OMPD_flush: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 377 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 378 | case OMPD_for_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 379 | case OMPD_sections: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 380 | case OMPD_section: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 381 | case OMPD_single: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 382 | case OMPD_master: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 383 | case OMPD_ordered: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 384 | case OMPD_critical: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 385 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 386 | case OMPD_parallel_for_simd: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 387 | case OMPD_parallel_sections: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 388 | case OMPD_atomic: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 389 | case OMPD_target: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 390 | case OMPD_teams: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 391 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 392 | case OMPD_cancel: |
Samuel Antao | 5b0688e | 2015-07-22 16:02:46 +0000 | [diff] [blame] | 393 | case OMPD_target_data: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 394 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 395 | case OMPD_target_exit_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 396 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 397 | case OMPD_target_parallel_for: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 398 | case OMPD_taskloop: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 399 | case OMPD_taskloop_simd: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 400 | case OMPD_distribute: |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 401 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 402 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 403 | break; |
| 404 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame^] | 405 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 406 | ConsumeAnyToken(); |
| 407 | ConsumeAnyToken(); |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 408 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 411 | /// \brief Parsing of declarative or executable OpenMP directives. |
| 412 | /// |
| 413 | /// threadprivate-directive: |
| 414 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
| 415 | /// annot_pragma_openmp_end |
| 416 | /// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame^] | 417 | /// declare-reduction-directive: |
| 418 | /// annot_pragma_openmp 'declare' 'reduction' '(' <reduction_id> ':' |
| 419 | /// <type> {',' <type>} ':' <expression> ')' ['initializer' '(' |
| 420 | /// ('omp_priv' '=' <expression>|<function_call>) ')'] |
| 421 | /// annot_pragma_openmp_end |
| 422 | /// |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 423 | /// executable-directive: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 424 | /// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 425 | /// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] | |
| 426 | /// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 427 | /// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 428 | /// 'for simd' | 'parallel for simd' | 'target' | 'target data' | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 429 | /// 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 430 | /// 'distribute' | 'target enter data' | 'target exit data' | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 431 | /// 'target parallel' | 'target parallel for' {clause} |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 432 | /// annot_pragma_openmp_end |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 433 | /// |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 434 | StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( |
| 435 | AllowedContsructsKind Allowed) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 436 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 437 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 438 | SmallVector<Expr *, 5> Identifiers; |
| 439 | SmallVector<OMPClause *, 5> Clauses; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 440 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 441 | FirstClauses(OMPC_unknown + 1); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 442 | unsigned ScopeFlags = |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 443 | Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 444 | SourceLocation Loc = ConsumeToken(), EndLoc; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 445 | auto DKind = ParseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 446 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 447 | // Name of critical directive. |
| 448 | DeclarationNameInfo DirName; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 449 | StmtResult Directive = StmtError(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 450 | bool HasAssociatedStatement = true; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 451 | bool FlushHasClause = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 452 | |
| 453 | switch (DKind) { |
| 454 | case OMPD_threadprivate: |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 455 | if (Allowed != ACK_Any) { |
| 456 | Diag(Tok, diag::err_omp_immediate_directive) |
| 457 | << getOpenMPDirectiveName(DKind) << 0; |
| 458 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 459 | ConsumeToken(); |
| 460 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) { |
| 461 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 462 | // extra tokens. |
| 463 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 464 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 465 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 466 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 467 | } |
| 468 | DeclGroupPtrTy Res = |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 469 | Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 470 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 471 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 472 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 473 | break; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame^] | 474 | case OMPD_declare_reduction: |
| 475 | ConsumeToken(); |
| 476 | if (auto Res = ParseOpenMPDeclareReductionDirective(/*AS=*/AS_none)) { |
| 477 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 478 | // extra tokens. |
| 479 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 480 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 481 | << getOpenMPDirectiveName(OMPD_declare_reduction); |
| 482 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 483 | ConsumeAnyToken(); |
| 484 | } |
| 485 | ConsumeAnyToken(); |
| 486 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 487 | } else |
| 488 | SkipUntil(tok::annot_pragma_openmp_end); |
| 489 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 490 | case OMPD_flush: |
| 491 | if (PP.LookAhead(0).is(tok::l_paren)) { |
| 492 | FlushHasClause = true; |
| 493 | // Push copy of the current token back to stream to properly parse |
| 494 | // pseudo-clause OMPFlushClause. |
| 495 | PP.EnterToken(Tok); |
| 496 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 497 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 498 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 499 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 500 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 501 | case OMPD_cancel: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 502 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 503 | case OMPD_target_exit_data: |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 504 | if (Allowed == ACK_StatementsOpenMPNonStandalone) { |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 505 | Diag(Tok, diag::err_omp_immediate_directive) |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 506 | << getOpenMPDirectiveName(DKind) << 0; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 507 | } |
| 508 | HasAssociatedStatement = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 509 | // Fall through for further analysis. |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 510 | case OMPD_parallel: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 511 | case OMPD_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 512 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 513 | case OMPD_for_simd: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 514 | case OMPD_sections: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 515 | case OMPD_single: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 516 | case OMPD_section: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 517 | case OMPD_master: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 518 | case OMPD_critical: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 519 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 520 | case OMPD_parallel_for_simd: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 521 | case OMPD_parallel_sections: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 522 | case OMPD_task: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 523 | case OMPD_ordered: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 524 | case OMPD_atomic: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 525 | case OMPD_target: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 526 | case OMPD_teams: |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 527 | case OMPD_taskgroup: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 528 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 529 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 530 | case OMPD_target_parallel_for: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 531 | case OMPD_taskloop: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 532 | case OMPD_taskloop_simd: |
| 533 | case OMPD_distribute: { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 534 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 535 | // Parse directive name of the 'critical' directive if any. |
| 536 | if (DKind == OMPD_critical) { |
| 537 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 538 | tok::annot_pragma_openmp_end); |
| 539 | if (!T.consumeOpen()) { |
| 540 | if (Tok.isAnyIdentifier()) { |
| 541 | DirName = |
| 542 | DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 543 | ConsumeAnyToken(); |
| 544 | } else { |
| 545 | Diag(Tok, diag::err_omp_expected_identifier_for_critical); |
| 546 | } |
| 547 | T.consumeClose(); |
| 548 | } |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 549 | } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 550 | CancelRegion = ParseOpenMPDirectiveKind(*this); |
| 551 | if (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 552 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 553 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 554 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 555 | if (isOpenMPLoopDirective(DKind)) |
| 556 | ScopeFlags |= Scope::OpenMPLoopDirectiveScope; |
| 557 | if (isOpenMPSimdDirective(DKind)) |
| 558 | ScopeFlags |= Scope::OpenMPSimdDirectiveScope; |
| 559 | ParseScope OMPDirectiveScope(this, ScopeFlags); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 560 | Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 561 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 562 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 563 | OpenMPClauseKind CKind = |
| 564 | Tok.isAnnotation() |
| 565 | ? OMPC_unknown |
| 566 | : FlushHasClause ? OMPC_flush |
| 567 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 568 | Actions.StartOpenMPClause(CKind); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 569 | FlushHasClause = false; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 570 | OMPClause *Clause = |
| 571 | ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 572 | FirstClauses[CKind].setInt(true); |
| 573 | if (Clause) { |
| 574 | FirstClauses[CKind].setPointer(Clause); |
| 575 | Clauses.push_back(Clause); |
| 576 | } |
| 577 | |
| 578 | // Skip ',' if any. |
| 579 | if (Tok.is(tok::comma)) |
| 580 | ConsumeToken(); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 581 | Actions.EndOpenMPClause(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 582 | } |
| 583 | // End location of the directive. |
| 584 | EndLoc = Tok.getLocation(); |
| 585 | // Consume final annot_pragma_openmp_end. |
| 586 | ConsumeToken(); |
| 587 | |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 588 | // OpenMP [2.13.8, ordered Construct, Syntax] |
| 589 | // If the depend clause is specified, the ordered construct is a stand-alone |
| 590 | // directive. |
| 591 | if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) { |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 592 | if (Allowed == ACK_StatementsOpenMPNonStandalone) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 593 | Diag(Loc, diag::err_omp_immediate_directive) |
| 594 | << getOpenMPDirectiveName(DKind) << 1 |
| 595 | << getOpenMPClauseName(OMPC_depend); |
| 596 | } |
| 597 | HasAssociatedStatement = false; |
| 598 | } |
| 599 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 600 | StmtResult AssociatedStmt; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 601 | if (HasAssociatedStatement) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 602 | // The body is a block scope like in Lambdas and Blocks. |
| 603 | Sema::CompoundScopeRAII CompoundScope(Actions); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 604 | Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 605 | Actions.ActOnStartOfCompoundStmt(); |
| 606 | // Parse statement |
| 607 | AssociatedStmt = ParseStatement(); |
| 608 | Actions.ActOnFinishOfCompoundStmt(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 609 | AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 610 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 611 | Directive = Actions.ActOnOpenMPExecutableDirective( |
| 612 | DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc, |
| 613 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 614 | |
| 615 | // Exit scope. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 616 | Actions.EndOpenMPDSABlock(Directive.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 617 | OMPDirectiveScope.Exit(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 618 | break; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 619 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 620 | case OMPD_unknown: |
| 621 | Diag(Tok, diag::err_omp_unknown_directive); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 622 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 623 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 624 | } |
| 625 | return Directive; |
| 626 | } |
| 627 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 628 | /// \brief Parses list of simple variables for '#pragma omp threadprivate' |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 629 | /// directive. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 630 | /// |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 631 | /// simple-variable-list: |
| 632 | /// '(' id-expression {, id-expression} ')' |
| 633 | /// |
| 634 | bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, |
| 635 | SmallVectorImpl<Expr *> &VarList, |
| 636 | bool AllowScopeSpecifier) { |
| 637 | VarList.clear(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 638 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 639 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 640 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 641 | getOpenMPDirectiveName(Kind))) |
| 642 | return true; |
| 643 | bool IsCorrect = true; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 644 | bool NoIdentIsFound = true; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 645 | |
| 646 | // Read tokens while ')' or annot_pragma_openmp_end is not found. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 647 | 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] | 648 | CXXScopeSpec SS; |
| 649 | SourceLocation TemplateKWLoc; |
| 650 | UnqualifiedId Name; |
| 651 | // Read var name. |
| 652 | Token PrevTok = Tok; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 653 | NoIdentIsFound = false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 654 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 655 | if (AllowScopeSpecifier && getLangOpts().CPlusPlus && |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 656 | ParseOptionalCXXScopeSpecifier(SS, nullptr, false)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 657 | IsCorrect = false; |
| 658 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 659 | StopBeforeMatch); |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 660 | } else if (ParseUnqualifiedId(SS, false, false, false, nullptr, |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 661 | TemplateKWLoc, Name)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 662 | IsCorrect = false; |
| 663 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 664 | StopBeforeMatch); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 665 | } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) && |
| 666 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 667 | IsCorrect = false; |
| 668 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 669 | StopBeforeMatch); |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 670 | Diag(PrevTok.getLocation(), diag::err_expected) |
| 671 | << tok::identifier |
| 672 | << SourceRange(PrevTok.getLocation(), PrevTokLocation); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 673 | } else { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 674 | DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name); |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 675 | ExprResult Res = |
| 676 | Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 677 | if (Res.isUsable()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 678 | VarList.push_back(Res.get()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 679 | } |
| 680 | // Consume ','. |
| 681 | if (Tok.is(tok::comma)) { |
| 682 | ConsumeToken(); |
| 683 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 684 | } |
| 685 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 686 | if (NoIdentIsFound) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 687 | Diag(Tok, diag::err_expected) << tok::identifier; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 688 | IsCorrect = false; |
| 689 | } |
| 690 | |
| 691 | // Parse ')'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 692 | IsCorrect = !T.consumeClose() && IsCorrect; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 693 | |
| 694 | return !IsCorrect && VarList.empty(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 695 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 696 | |
| 697 | /// \brief Parsing of OpenMP clauses. |
| 698 | /// |
| 699 | /// clause: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 700 | /// if-clause | final-clause | num_threads-clause | safelen-clause | |
| 701 | /// default-clause | private-clause | firstprivate-clause | shared-clause |
| 702 | /// | linear-clause | aligned-clause | collapse-clause | |
| 703 | /// lastprivate-clause | reduction-clause | proc_bind-clause | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 704 | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 705 | /// mergeable-clause | flush-clause | read-clause | write-clause | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 706 | /// update-clause | capture-clause | seq_cst-clause | device-clause | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 707 | /// simdlen-clause | threads-clause | simd-clause | num_teams-clause | |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 708 | /// thread_limit-clause | priority-clause | grainsize-clause | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 709 | /// nogroup-clause | num_tasks-clause | hint-clause |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 710 | /// |
| 711 | OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, |
| 712 | OpenMPClauseKind CKind, bool FirstClause) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 713 | OMPClause *Clause = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 714 | bool ErrorFound = false; |
| 715 | // Check if clause is allowed for the given directive. |
| 716 | if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 717 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 718 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 719 | ErrorFound = true; |
| 720 | } |
| 721 | |
| 722 | switch (CKind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 723 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 724 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 725 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 726 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 727 | case OMPC_collapse: |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 728 | case OMPC_ordered: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 729 | case OMPC_device: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 730 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 731 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 732 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 733 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 734 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 735 | case OMPC_hint: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 736 | // OpenMP [2.5, Restrictions] |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 737 | // At most one num_threads clause can appear on the directive. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 738 | // OpenMP [2.8.1, simd construct, Restrictions] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 739 | // Only one safelen clause can appear on a simd directive. |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 740 | // Only one simdlen clause can appear on a simd directive. |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 741 | // Only one collapse clause can appear on a simd directive. |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 742 | // OpenMP [2.9.1, target data construct, Restrictions] |
| 743 | // At most one device clause can appear on the directive. |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 744 | // OpenMP [2.11.1, task Construct, Restrictions] |
| 745 | // At most one if clause can appear on the directive. |
| 746 | // At most one final clause can appear on the directive. |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 747 | // OpenMP [teams Construct, Restrictions] |
| 748 | // At most one num_teams clause can appear on the directive. |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 749 | // At most one thread_limit clause can appear on the directive. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 750 | // OpenMP [2.9.1, task Construct, Restrictions] |
| 751 | // At most one priority clause can appear on the directive. |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 752 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 753 | // At most one grainsize clause can appear on the directive. |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 754 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 755 | // At most one num_tasks clause can appear on the directive. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 756 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 757 | Diag(Tok, diag::err_omp_more_one_clause) |
| 758 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 759 | ErrorFound = true; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 762 | if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren)) |
| 763 | Clause = ParseOpenMPClause(CKind); |
| 764 | else |
| 765 | Clause = ParseOpenMPSingleExprClause(CKind); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 766 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 767 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 768 | case OMPC_proc_bind: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 769 | // OpenMP [2.14.3.1, Restrictions] |
| 770 | // Only a single default clause may be specified on a parallel, task or |
| 771 | // teams directive. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 772 | // OpenMP [2.5, parallel Construct, Restrictions] |
| 773 | // At most one proc_bind clause can appear on the directive. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 774 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 775 | Diag(Tok, diag::err_omp_more_one_clause) |
| 776 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 777 | ErrorFound = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | Clause = ParseOpenMPSimpleClause(CKind); |
| 781 | break; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 782 | case OMPC_schedule: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 783 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 784 | case OMPC_defaultmap: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 785 | // OpenMP [2.7.1, Restrictions, p. 3] |
| 786 | // Only one schedule clause can appear on a loop directive. |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 787 | // OpenMP [2.10.4, Restrictions, p. 106] |
| 788 | // At most one defaultmap clause can appear on the directive. |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 789 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 790 | Diag(Tok, diag::err_omp_more_one_clause) |
| 791 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 792 | ErrorFound = true; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 795 | case OMPC_if: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 796 | Clause = ParseOpenMPSingleExprWithArgClause(CKind); |
| 797 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 798 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 799 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 800 | case OMPC_mergeable: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 801 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 802 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 803 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 804 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 805 | case OMPC_seq_cst: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 806 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 807 | case OMPC_simd: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 808 | case OMPC_nogroup: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 809 | // OpenMP [2.7.1, Restrictions, p. 9] |
| 810 | // Only one ordered clause can appear on a loop directive. |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 811 | // OpenMP [2.7.1, Restrictions, C/C++, p. 4] |
| 812 | // Only one nowait clause can appear on a for directive. |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 813 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 814 | Diag(Tok, diag::err_omp_more_one_clause) |
| 815 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 816 | ErrorFound = true; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | Clause = ParseOpenMPClause(CKind); |
| 820 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 821 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 822 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 823 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 824 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 825 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 826 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 827 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 828 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 829 | case OMPC_copyprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 830 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 831 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 832 | case OMPC_map: |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 833 | Clause = ParseOpenMPVarListClause(DKind, CKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 834 | break; |
| 835 | case OMPC_unknown: |
| 836 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 837 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 838 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 839 | break; |
| 840 | case OMPC_threadprivate: |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 841 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 842 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 843 | SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 844 | break; |
| 845 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 846 | return ErrorFound ? nullptr : Clause; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 847 | } |
| 848 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 849 | /// \brief Parsing of OpenMP clauses with single expressions like 'final', |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 850 | /// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams', |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 851 | /// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 852 | /// |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 853 | /// final-clause: |
| 854 | /// 'final' '(' expression ')' |
| 855 | /// |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 856 | /// num_threads-clause: |
| 857 | /// 'num_threads' '(' expression ')' |
| 858 | /// |
| 859 | /// safelen-clause: |
| 860 | /// 'safelen' '(' expression ')' |
| 861 | /// |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 862 | /// simdlen-clause: |
| 863 | /// 'simdlen' '(' expression ')' |
| 864 | /// |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 865 | /// collapse-clause: |
| 866 | /// 'collapse' '(' expression ')' |
| 867 | /// |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 868 | /// priority-clause: |
| 869 | /// 'priority' '(' expression ')' |
| 870 | /// |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 871 | /// grainsize-clause: |
| 872 | /// 'grainsize' '(' expression ')' |
| 873 | /// |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 874 | /// num_tasks-clause: |
| 875 | /// 'num_tasks' '(' expression ')' |
| 876 | /// |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 877 | /// hint-clause: |
| 878 | /// 'hint' '(' expression ')' |
| 879 | /// |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 880 | OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) { |
| 881 | SourceLocation Loc = ConsumeToken(); |
| 882 | |
| 883 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 884 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 885 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 886 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 887 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 888 | SourceLocation ELoc = Tok.getLocation(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 889 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 890 | ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 891 | Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 892 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 893 | // Parse ')'. |
| 894 | T.consumeClose(); |
| 895 | |
| 896 | if (Val.isInvalid()) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 897 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 898 | |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 899 | return Actions.ActOnOpenMPSingleExprClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 900 | Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation()); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 903 | /// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 904 | /// |
| 905 | /// default-clause: |
| 906 | /// 'default' '(' 'none' | 'shared' ') |
| 907 | /// |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 908 | /// proc_bind-clause: |
| 909 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 910 | /// |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 911 | OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) { |
| 912 | SourceLocation Loc = Tok.getLocation(); |
| 913 | SourceLocation LOpen = ConsumeToken(); |
| 914 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 915 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 916 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 917 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 918 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 919 | |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 920 | unsigned Type = getOpenMPSimpleClauseType( |
| 921 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 922 | SourceLocation TypeLoc = Tok.getLocation(); |
| 923 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 924 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 925 | ConsumeAnyToken(); |
| 926 | |
| 927 | // Parse ')'. |
| 928 | T.consumeClose(); |
| 929 | |
| 930 | return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc, |
| 931 | Tok.getLocation()); |
| 932 | } |
| 933 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 934 | /// \brief Parsing of OpenMP clauses like 'ordered'. |
| 935 | /// |
| 936 | /// ordered-clause: |
| 937 | /// 'ordered' |
| 938 | /// |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 939 | /// nowait-clause: |
| 940 | /// 'nowait' |
| 941 | /// |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 942 | /// untied-clause: |
| 943 | /// 'untied' |
| 944 | /// |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 945 | /// mergeable-clause: |
| 946 | /// 'mergeable' |
| 947 | /// |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 948 | /// read-clause: |
| 949 | /// 'read' |
| 950 | /// |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 951 | /// threads-clause: |
| 952 | /// 'threads' |
| 953 | /// |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 954 | /// simd-clause: |
| 955 | /// 'simd' |
| 956 | /// |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 957 | /// nogroup-clause: |
| 958 | /// 'nogroup' |
| 959 | /// |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 960 | OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) { |
| 961 | SourceLocation Loc = Tok.getLocation(); |
| 962 | ConsumeAnyToken(); |
| 963 | |
| 964 | return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation()); |
| 965 | } |
| 966 | |
| 967 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 968 | /// \brief Parsing of OpenMP clauses with single expressions and some additional |
| 969 | /// argument like 'schedule' or 'dist_schedule'. |
| 970 | /// |
| 971 | /// schedule-clause: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 972 | /// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ] |
| 973 | /// ')' |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 974 | /// |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 975 | /// if-clause: |
| 976 | /// 'if' '(' [ directive-name-modifier ':' ] expression ')' |
| 977 | /// |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 978 | /// defaultmap: |
| 979 | /// 'defaultmap' '(' modifier ':' kind ')' |
| 980 | /// |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 981 | OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) { |
| 982 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 983 | SourceLocation DelimLoc; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 984 | // Parse '('. |
| 985 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 986 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 987 | getOpenMPClauseName(Kind))) |
| 988 | return nullptr; |
| 989 | |
| 990 | ExprResult Val; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 991 | SmallVector<unsigned, 4> Arg; |
| 992 | SmallVector<SourceLocation, 4> KLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 993 | if (Kind == OMPC_schedule) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 994 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 995 | Arg.resize(NumberOfElements); |
| 996 | KLoc.resize(NumberOfElements); |
| 997 | Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 998 | Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 999 | Arg[ScheduleKind] = OMPC_SCHEDULE_unknown; |
| 1000 | auto KindModifier = getOpenMPSimpleClauseType( |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1001 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1002 | if (KindModifier > OMPC_SCHEDULE_unknown) { |
| 1003 | // Parse 'modifier' |
| 1004 | Arg[Modifier1] = KindModifier; |
| 1005 | KLoc[Modifier1] = Tok.getLocation(); |
| 1006 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1007 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1008 | ConsumeAnyToken(); |
| 1009 | if (Tok.is(tok::comma)) { |
| 1010 | // Parse ',' 'modifier' |
| 1011 | ConsumeAnyToken(); |
| 1012 | KindModifier = getOpenMPSimpleClauseType( |
| 1013 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 1014 | Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown |
| 1015 | ? KindModifier |
Aaron Ballman | ad8a104 | 2015-12-28 15:52:46 +0000 | [diff] [blame] | 1016 | : (unsigned)OMPC_SCHEDULE_unknown; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1017 | KLoc[Modifier2] = Tok.getLocation(); |
| 1018 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1019 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1020 | ConsumeAnyToken(); |
| 1021 | } |
| 1022 | // Parse ':' |
| 1023 | if (Tok.is(tok::colon)) |
| 1024 | ConsumeAnyToken(); |
| 1025 | else |
| 1026 | Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier"; |
| 1027 | KindModifier = getOpenMPSimpleClauseType( |
| 1028 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 1029 | } |
| 1030 | Arg[ScheduleKind] = KindModifier; |
| 1031 | KLoc[ScheduleKind] = Tok.getLocation(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1032 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1033 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1034 | ConsumeAnyToken(); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1035 | if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static || |
| 1036 | Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic || |
| 1037 | Arg[ScheduleKind] == OMPC_SCHEDULE_guided) && |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1038 | Tok.is(tok::comma)) |
| 1039 | DelimLoc = ConsumeAnyToken(); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 1040 | } else if (Kind == OMPC_dist_schedule) { |
| 1041 | Arg.push_back(getOpenMPSimpleClauseType( |
| 1042 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 1043 | KLoc.push_back(Tok.getLocation()); |
| 1044 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1045 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1046 | ConsumeAnyToken(); |
| 1047 | if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma)) |
| 1048 | DelimLoc = ConsumeAnyToken(); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 1049 | } else if (Kind == OMPC_defaultmap) { |
| 1050 | // Get a defaultmap modifier |
| 1051 | Arg.push_back(getOpenMPSimpleClauseType( |
| 1052 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 1053 | KLoc.push_back(Tok.getLocation()); |
| 1054 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1055 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1056 | ConsumeAnyToken(); |
| 1057 | // Parse ':' |
| 1058 | if (Tok.is(tok::colon)) |
| 1059 | ConsumeAnyToken(); |
| 1060 | else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown) |
| 1061 | Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier"; |
| 1062 | // Get a defaultmap kind |
| 1063 | Arg.push_back(getOpenMPSimpleClauseType( |
| 1064 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 1065 | KLoc.push_back(Tok.getLocation()); |
| 1066 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1067 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1068 | ConsumeAnyToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1069 | } else { |
| 1070 | assert(Kind == OMPC_if); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1071 | KLoc.push_back(Tok.getLocation()); |
| 1072 | Arg.push_back(ParseOpenMPDirectiveKind(*this)); |
| 1073 | if (Arg.back() != OMPD_unknown) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1074 | ConsumeToken(); |
| 1075 | if (Tok.is(tok::colon)) |
| 1076 | DelimLoc = ConsumeToken(); |
| 1077 | else |
| 1078 | Diag(Tok, diag::warn_pragma_expected_colon) |
| 1079 | << "directive name modifier"; |
| 1080 | } |
| 1081 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1082 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 1083 | bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) || |
| 1084 | (Kind == OMPC_dist_schedule && DelimLoc.isValid()) || |
| 1085 | Kind == OMPC_if; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1086 | if (NeedAnExpression) { |
| 1087 | SourceLocation ELoc = Tok.getLocation(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1088 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 1089 | Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1090 | Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | // Parse ')'. |
| 1094 | T.consumeClose(); |
| 1095 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1096 | if (NeedAnExpression && Val.isInvalid()) |
| 1097 | return nullptr; |
| 1098 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1099 | return Actions.ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1100 | Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1101 | T.getCloseLocation()); |
| 1102 | } |
| 1103 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1104 | static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, |
| 1105 | UnqualifiedId &ReductionId) { |
| 1106 | SourceLocation TemplateKWLoc; |
| 1107 | if (ReductionIdScopeSpec.isEmpty()) { |
| 1108 | auto OOK = OO_None; |
| 1109 | switch (P.getCurToken().getKind()) { |
| 1110 | case tok::plus: |
| 1111 | OOK = OO_Plus; |
| 1112 | break; |
| 1113 | case tok::minus: |
| 1114 | OOK = OO_Minus; |
| 1115 | break; |
| 1116 | case tok::star: |
| 1117 | OOK = OO_Star; |
| 1118 | break; |
| 1119 | case tok::amp: |
| 1120 | OOK = OO_Amp; |
| 1121 | break; |
| 1122 | case tok::pipe: |
| 1123 | OOK = OO_Pipe; |
| 1124 | break; |
| 1125 | case tok::caret: |
| 1126 | OOK = OO_Caret; |
| 1127 | break; |
| 1128 | case tok::ampamp: |
| 1129 | OOK = OO_AmpAmp; |
| 1130 | break; |
| 1131 | case tok::pipepipe: |
| 1132 | OOK = OO_PipePipe; |
| 1133 | break; |
| 1134 | default: |
| 1135 | break; |
| 1136 | } |
| 1137 | if (OOK != OO_None) { |
| 1138 | SourceLocation OpLoc = P.ConsumeToken(); |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1139 | SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()}; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1140 | ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations); |
| 1141 | return false; |
| 1142 | } |
| 1143 | } |
| 1144 | return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false, |
| 1145 | /*AllowDestructorName*/ false, |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 1146 | /*AllowConstructorName*/ false, nullptr, |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1147 | TemplateKWLoc, ReductionId); |
| 1148 | } |
| 1149 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1150 | /// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate', |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1151 | /// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1152 | /// |
| 1153 | /// private-clause: |
| 1154 | /// 'private' '(' list ')' |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1155 | /// firstprivate-clause: |
| 1156 | /// 'firstprivate' '(' list ')' |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1157 | /// lastprivate-clause: |
| 1158 | /// 'lastprivate' '(' list ')' |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1159 | /// shared-clause: |
| 1160 | /// 'shared' '(' list ')' |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1161 | /// linear-clause: |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1162 | /// 'linear' '(' linear-list [ ':' linear-step ] ')' |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1163 | /// aligned-clause: |
| 1164 | /// 'aligned' '(' list [ ':' alignment ] ')' |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1165 | /// reduction-clause: |
| 1166 | /// 'reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1167 | /// copyprivate-clause: |
| 1168 | /// 'copyprivate' '(' list ')' |
| 1169 | /// flush-clause: |
| 1170 | /// 'flush' '(' list ')' |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1171 | /// depend-clause: |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1172 | /// 'depend' '(' in | out | inout : list | source ')' |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1173 | /// map-clause: |
| 1174 | /// 'map' '(' [ [ always , ] |
| 1175 | /// to | from | tofrom | alloc | release | delete ':' ] list ')'; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1176 | /// |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1177 | /// For 'linear' clause linear-list may have the following forms: |
| 1178 | /// list |
| 1179 | /// modifier(list) |
| 1180 | /// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++). |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1181 | OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, |
| 1182 | OpenMPClauseKind Kind) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1183 | SourceLocation Loc = Tok.getLocation(); |
| 1184 | SourceLocation LOpen = ConsumeToken(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1185 | SourceLocation ColonLoc = SourceLocation(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1186 | // Optional scope specifier and unqualified id for reduction identifier. |
| 1187 | CXXScopeSpec ReductionIdScopeSpec; |
| 1188 | UnqualifiedId ReductionId; |
| 1189 | bool InvalidReductionId = false; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1190 | OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1191 | // OpenMP 4.1 [2.15.3.7, linear Clause] |
| 1192 | // If no modifier is specified it is assumed to be val. |
| 1193 | OpenMPLinearClauseKind LinearModifier = OMPC_LINEAR_val; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1194 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown; |
| 1195 | OpenMPMapClauseKind MapTypeModifier = OMPC_MAP_unknown; |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 1196 | bool MapTypeIsImplicit = false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1197 | bool MapTypeModifierSpecified = false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1198 | SourceLocation DepLinMapLoc; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1199 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1200 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1201 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1202 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1203 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1204 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1205 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1206 | bool NeedRParenForLinear = false; |
| 1207 | BalancedDelimiterTracker LinearT(*this, tok::l_paren, |
| 1208 | tok::annot_pragma_openmp_end); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1209 | // Handle reduction-identifier for reduction clause. |
| 1210 | if (Kind == OMPC_reduction) { |
| 1211 | ColonProtectionRAIIObject ColonRAII(*this); |
| 1212 | if (getLangOpts().CPlusPlus) { |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 1213 | ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, nullptr, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1214 | } |
| 1215 | InvalidReductionId = |
| 1216 | ParseReductionId(*this, ReductionIdScopeSpec, ReductionId); |
| 1217 | if (InvalidReductionId) { |
| 1218 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 1219 | StopBeforeMatch); |
| 1220 | } |
| 1221 | if (Tok.is(tok::colon)) { |
| 1222 | ColonLoc = ConsumeToken(); |
| 1223 | } else { |
| 1224 | Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier"; |
| 1225 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1226 | } else if (Kind == OMPC_depend) { |
| 1227 | // Handle dependency type for depend clause. |
| 1228 | ColonProtectionRAIIObject ColonRAII(*this); |
| 1229 | DepKind = static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType( |
| 1230 | Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : "")); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1231 | DepLinMapLoc = Tok.getLocation(); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1232 | |
| 1233 | if (DepKind == OMPC_DEPEND_unknown) { |
| 1234 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 1235 | StopBeforeMatch); |
| 1236 | } else { |
| 1237 | ConsumeToken(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1238 | // Special processing for depend(source) clause. |
| 1239 | if (DKind == OMPD_ordered && DepKind == OMPC_DEPEND_source) { |
| 1240 | // Parse ')'. |
| 1241 | T.consumeClose(); |
| 1242 | return Actions.ActOnOpenMPVarListClause( |
| 1243 | Kind, llvm::None, /*TailExpr=*/nullptr, Loc, LOpen, |
| 1244 | /*ColonLoc=*/SourceLocation(), Tok.getLocation(), |
| 1245 | ReductionIdScopeSpec, DeclarationNameInfo(), DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 1246 | LinearModifier, MapTypeModifier, MapType, MapTypeIsImplicit, |
| 1247 | DepLinMapLoc); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1248 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1249 | } |
| 1250 | if (Tok.is(tok::colon)) { |
| 1251 | ColonLoc = ConsumeToken(); |
| 1252 | } else { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1253 | Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren |
| 1254 | : diag::warn_pragma_expected_colon) |
| 1255 | << "dependency type"; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1256 | } |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1257 | } else if (Kind == OMPC_linear) { |
| 1258 | // Try to parse modifier if any. |
| 1259 | if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) { |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1260 | LinearModifier = static_cast<OpenMPLinearClauseKind>( |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 1261 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1262 | DepLinMapLoc = ConsumeToken(); |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1263 | LinearT.consumeOpen(); |
| 1264 | NeedRParenForLinear = true; |
| 1265 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1266 | } else if (Kind == OMPC_map) { |
| 1267 | // Handle map type for map clause. |
| 1268 | ColonProtectionRAIIObject ColonRAII(*this); |
| 1269 | |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame] | 1270 | /// The map clause modifier token can be either a identifier or the C++ |
| 1271 | /// delete keyword. |
| 1272 | auto IsMapClauseModifierToken = [](const Token &Tok) { |
| 1273 | return Tok.isOneOf(tok::identifier, tok::kw_delete); |
| 1274 | }; |
| 1275 | |
| 1276 | // The first identifier may be a list item, a map-type or a |
| 1277 | // map-type-modifier. The map modifier can also be delete which has the same |
| 1278 | // spelling of the C++ delete keyword. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1279 | MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType( |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame] | 1280 | Kind, IsMapClauseModifierToken(Tok) ? PP.getSpelling(Tok) : "")); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1281 | DepLinMapLoc = Tok.getLocation(); |
| 1282 | bool ColonExpected = false; |
| 1283 | |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame] | 1284 | if (IsMapClauseModifierToken(Tok)) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1285 | if (PP.LookAhead(0).is(tok::colon)) { |
| 1286 | MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType( |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame] | 1287 | Kind, IsMapClauseModifierToken(Tok) ? PP.getSpelling(Tok) : "")); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1288 | if (MapType == OMPC_MAP_unknown) { |
| 1289 | Diag(Tok, diag::err_omp_unknown_map_type); |
| 1290 | } else if (MapType == OMPC_MAP_always) { |
| 1291 | Diag(Tok, diag::err_omp_map_type_missing); |
| 1292 | } |
| 1293 | ConsumeToken(); |
| 1294 | } else if (PP.LookAhead(0).is(tok::comma)) { |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame] | 1295 | if (IsMapClauseModifierToken(PP.LookAhead(1)) && |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1296 | PP.LookAhead(2).is(tok::colon)) { |
| 1297 | MapTypeModifier = |
| 1298 | static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType( |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame] | 1299 | Kind, |
| 1300 | IsMapClauseModifierToken(Tok) ? PP.getSpelling(Tok) : "")); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1301 | if (MapTypeModifier != OMPC_MAP_always) { |
| 1302 | Diag(Tok, diag::err_omp_unknown_map_type_modifier); |
| 1303 | MapTypeModifier = OMPC_MAP_unknown; |
| 1304 | } else { |
| 1305 | MapTypeModifierSpecified = true; |
| 1306 | } |
| 1307 | |
| 1308 | ConsumeToken(); |
| 1309 | ConsumeToken(); |
| 1310 | |
| 1311 | MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType( |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame] | 1312 | Kind, IsMapClauseModifierToken(Tok) ? PP.getSpelling(Tok) : "")); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1313 | if (MapType == OMPC_MAP_unknown || MapType == OMPC_MAP_always) { |
| 1314 | Diag(Tok, diag::err_omp_unknown_map_type); |
| 1315 | } |
| 1316 | ConsumeToken(); |
| 1317 | } else { |
| 1318 | MapType = OMPC_MAP_tofrom; |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 1319 | MapTypeIsImplicit = true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1320 | } |
| 1321 | } else { |
| 1322 | MapType = OMPC_MAP_tofrom; |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 1323 | MapTypeIsImplicit = true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1324 | } |
| 1325 | } else { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 1326 | MapType = OMPC_MAP_tofrom; |
| 1327 | MapTypeIsImplicit = true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | if (Tok.is(tok::colon)) { |
| 1331 | ColonLoc = ConsumeToken(); |
| 1332 | } else if (ColonExpected) { |
| 1333 | Diag(Tok, diag::warn_pragma_expected_colon) << "map type"; |
| 1334 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1337 | SmallVector<Expr *, 5> Vars; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1338 | bool IsComma = |
| 1339 | ((Kind != OMPC_reduction) && (Kind != OMPC_depend) && |
| 1340 | (Kind != OMPC_map)) || |
| 1341 | ((Kind == OMPC_reduction) && !InvalidReductionId) || |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 1342 | ((Kind == OMPC_map) && (MapType != OMPC_MAP_unknown) && |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1343 | (!MapTypeModifierSpecified || |
| 1344 | (MapTypeModifierSpecified && MapTypeModifier == OMPC_MAP_always))) || |
| 1345 | ((Kind == OMPC_depend) && DepKind != OMPC_DEPEND_unknown); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1346 | const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1347 | while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) && |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1348 | Tok.isNot(tok::annot_pragma_openmp_end))) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1349 | ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1350 | // Parse variable |
Kaelyn Takata | 1586782 | 2014-11-21 18:48:04 +0000 | [diff] [blame] | 1351 | ExprResult VarExpr = |
| 1352 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1353 | if (VarExpr.isUsable()) { |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1354 | Vars.push_back(VarExpr.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1355 | } else { |
| 1356 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1357 | StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1358 | } |
| 1359 | // Skip ',' if any |
| 1360 | IsComma = Tok.is(tok::comma); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1361 | if (IsComma) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1362 | ConsumeToken(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1363 | else if (Tok.isNot(tok::r_paren) && |
| 1364 | Tok.isNot(tok::annot_pragma_openmp_end) && |
| 1365 | (!MayHaveTail || Tok.isNot(tok::colon))) |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1366 | Diag(Tok, diag::err_omp_expected_punc) |
| 1367 | << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush) |
| 1368 | : getOpenMPClauseName(Kind)) |
| 1369 | << (Kind == OMPC_flush); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1372 | // Parse ')' for linear clause with modifier. |
| 1373 | if (NeedRParenForLinear) |
| 1374 | LinearT.consumeClose(); |
| 1375 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1376 | // Parse ':' linear-step (or ':' alignment). |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1377 | Expr *TailExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1378 | const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon); |
| 1379 | if (MustHaveTail) { |
| 1380 | ColonLoc = Tok.getLocation(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1381 | SourceLocation ELoc = ConsumeToken(); |
| 1382 | ExprResult Tail = ParseAssignmentExpression(); |
| 1383 | Tail = Actions.ActOnFinishFullExpr(Tail.get(), ELoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1384 | if (Tail.isUsable()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1385 | TailExpr = Tail.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1386 | else |
| 1387 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 1388 | StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | // Parse ')'. |
| 1392 | T.consumeClose(); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1393 | if ((Kind == OMPC_depend && DepKind != OMPC_DEPEND_unknown && Vars.empty()) || |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 1394 | (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) || |
| 1395 | (MustHaveTail && !TailExpr) || InvalidReductionId) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1396 | return nullptr; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1397 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1398 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1399 | return Actions.ActOnOpenMPVarListClause( |
| 1400 | Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(), |
| 1401 | ReductionIdScopeSpec, |
| 1402 | ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId) |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1403 | : DeclarationNameInfo(), |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 1404 | DepKind, LinearModifier, MapTypeModifier, MapType, MapTypeIsImplicit, |
| 1405 | DepLinMapLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1406 | } |
| 1407 | |