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