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