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