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