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