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