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