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