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 | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame^] | 789 | /// Parse context selector for 'implementation' selector set: |
| 790 | /// 'vendor' '(' <vendor> ')' |
| 791 | static void |
| 792 | parseImplementationSelector(Parser &P, |
| 793 | Sema::OpenMPDeclareVariantCtsSelectorData &Data) { |
| 794 | const Token &Tok = P.getCurToken(); |
| 795 | // Parse inner context selector set name, if any. |
| 796 | if (!Tok.is(tok::identifier)) { |
| 797 | P.Diag(Tok.getLocation(), diag::warn_omp_declare_variant_cs_name_expected) |
| 798 | << "implementation"; |
| 799 | // Skip until either '}', ')', or end of directive. |
| 800 | while (!P.SkipUntil(tok::r_brace, tok::r_paren, |
| 801 | tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 802 | ; |
| 803 | return; |
| 804 | } |
| 805 | SmallString<16> Buffer; |
| 806 | StringRef CtxSelectorName = P.getPreprocessor().getSpelling(Tok, Buffer); |
| 807 | OMPDeclareVariantAttr::CtxSelectorType CSKind = |
| 808 | OMPDeclareVariantAttr::CtxUnknown; |
| 809 | (void)OMPDeclareVariantAttr::ConvertStrToCtxSelectorType(CtxSelectorName, |
| 810 | CSKind); |
| 811 | (void)P.ConsumeToken(); |
| 812 | switch (CSKind) { |
| 813 | case OMPDeclareVariantAttr::CtxVendor: { |
| 814 | // Parse '('. |
| 815 | BalancedDelimiterTracker T(P, tok::l_paren, tok::annot_pragma_openmp_end); |
| 816 | (void)T.expectAndConsume(diag::err_expected_lparen_after, |
| 817 | CtxSelectorName.data()); |
| 818 | // Parse <vendor>. |
| 819 | StringRef VendorName; |
| 820 | if (Tok.is(tok::identifier)) { |
| 821 | VendorName = P.getPreprocessor().getSpelling(P.getCurToken(), Buffer); |
| 822 | (void)P.ConsumeToken(); |
| 823 | } else { |
| 824 | P.Diag(Tok.getLocation(), diag::err_omp_declare_variant_item_expected) |
| 825 | << "vendor identifier" << "vendor" << "implementation"; |
| 826 | } |
| 827 | // Parse ')'. |
| 828 | (void)T.consumeClose(); |
| 829 | if (!VendorName.empty()) |
| 830 | Data.ImplVendor = VendorName; |
| 831 | break; |
| 832 | } |
| 833 | case OMPDeclareVariantAttr::CtxUnknown: |
| 834 | P.Diag(Tok.getLocation(), diag::warn_omp_declare_variant_cs_name_expected) |
| 835 | << "implementation"; |
| 836 | // Skip until either '}', ')', or end of directive. |
| 837 | while (!P.SkipUntil(tok::r_brace, tok::r_paren, |
| 838 | tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 839 | ; |
| 840 | return; |
| 841 | } |
| 842 | Data.CtxSet = OMPDeclareVariantAttr::CtxSetImplementation; |
| 843 | Data.Ctx = CSKind; |
| 844 | } |
| 845 | |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 846 | /// Parses clauses for 'declare variant' directive. |
| 847 | /// clause: |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 848 | /// <selector_set_name> '=' '{' <context_selectors> '}' |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 849 | /// [ ',' <selector_set_name> '=' '{' <context_selectors> '}' ] |
| 850 | bool Parser::parseOpenMPContextSelectors( |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame^] | 851 | SourceLocation Loc, |
| 852 | llvm::function_ref<void(SourceRange, |
| 853 | const Sema::OpenMPDeclareVariantCtsSelectorData &)> |
| 854 | Callback) { |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 855 | do { |
| 856 | // Parse inner context selector set name. |
| 857 | if (!Tok.is(tok::identifier)) { |
| 858 | Diag(Tok.getLocation(), diag::err_omp_declare_variant_no_ctx_selector) |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 859 | << getOpenMPClauseName(OMPC_match); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 860 | return true; |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 861 | } |
| 862 | SmallString<16> Buffer; |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame^] | 863 | StringRef CtxSelectorSetName = PP.getSpelling(Tok, Buffer); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 864 | // Parse '='. |
| 865 | (void)ConsumeToken(); |
| 866 | if (Tok.isNot(tok::equal)) { |
| 867 | Diag(Tok.getLocation(), diag::err_omp_declare_variant_equal_expected) |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame^] | 868 | << CtxSelectorSetName; |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 869 | return true; |
| 870 | } |
| 871 | (void)ConsumeToken(); |
| 872 | // TBD: add parsing of known context selectors. |
| 873 | // Unknown selector - just ignore it completely. |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame^] | 874 | Sema::OpenMPDeclareVariantCtsSelectorData Data; |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 875 | { |
| 876 | // Parse '{'. |
| 877 | BalancedDelimiterTracker TBr(*this, tok::l_brace, |
| 878 | tok::annot_pragma_openmp_end); |
| 879 | if (TBr.expectAndConsume(diag::err_expected_lbrace_after, "=")) |
| 880 | return true; |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame^] | 881 | OMPDeclareVariantAttr::CtxSelectorSetType CSSKind = |
| 882 | OMPDeclareVariantAttr::CtxSetUnknown; |
| 883 | (void)OMPDeclareVariantAttr::ConvertStrToCtxSelectorSetType( |
| 884 | CtxSelectorSetName, CSSKind); |
| 885 | switch (CSSKind) { |
| 886 | case OMPDeclareVariantAttr::CtxSetImplementation: |
| 887 | parseImplementationSelector(*this, Data); |
| 888 | break; |
| 889 | case OMPDeclareVariantAttr::CtxSetUnknown: |
| 890 | // Skip until either '}', ')', or end of directive. |
| 891 | while (!SkipUntil(tok::r_brace, tok::r_paren, |
| 892 | tok::annot_pragma_openmp_end, StopBeforeMatch)) |
| 893 | ; |
| 894 | break; |
| 895 | } |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 896 | // Parse '}'. |
| 897 | (void)TBr.consumeClose(); |
| 898 | } |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame^] | 899 | Callback(SourceRange(Loc, Tok.getLocation()), Data); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 900 | // Consume ',' |
| 901 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) |
| 902 | (void)ExpectAndConsume(tok::comma); |
| 903 | } while (Tok.isAnyIdentifier()); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 904 | return false; |
| 905 | } |
| 906 | |
| 907 | /// Parse clauses for '#pragma omp declare variant ( variant-func-id ) clause'. |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 908 | void Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr, |
| 909 | CachedTokens &Toks, |
| 910 | SourceLocation Loc) { |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 911 | PP.EnterToken(Tok, /*IsReinject*/ true); |
| 912 | PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true, |
| 913 | /*IsReinject*/ true); |
| 914 | // Consume the previously pushed token. |
| 915 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
| 916 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
| 917 | |
| 918 | FNContextRAII FnContext(*this, Ptr); |
| 919 | // Parse function declaration id. |
| 920 | SourceLocation RLoc; |
| 921 | // Parse with IsAddressOfOperand set to true to parse methods as DeclRefExprs |
| 922 | // instead of MemberExprs. |
| 923 | ExprResult AssociatedFunction = |
| 924 | ParseOpenMPParensExpr(getOpenMPDirectiveName(OMPD_declare_variant), RLoc, |
| 925 | /*IsAddressOfOperand=*/true); |
| 926 | if (!AssociatedFunction.isUsable()) { |
| 927 | if (!Tok.is(tok::annot_pragma_openmp_end)) |
| 928 | while (!SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch)) |
| 929 | ; |
| 930 | // Skip the last annot_pragma_openmp_end. |
| 931 | (void)ConsumeAnnotationToken(); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 932 | return; |
| 933 | } |
| 934 | Optional<std::pair<FunctionDecl *, Expr *>> DeclVarData = |
| 935 | Actions.checkOpenMPDeclareVariantFunction( |
| 936 | Ptr, AssociatedFunction.get(), SourceRange(Loc, Tok.getLocation())); |
| 937 | |
| 938 | // Parse 'match'. |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 939 | OpenMPClauseKind CKind = Tok.isAnnotation() |
| 940 | ? OMPC_unknown |
| 941 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 942 | if (CKind != OMPC_match) { |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 943 | Diag(Tok.getLocation(), diag::err_omp_declare_variant_wrong_clause) |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 944 | << getOpenMPClauseName(OMPC_match); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 945 | while (!SkipUntil(tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 946 | ; |
| 947 | // Skip the last annot_pragma_openmp_end. |
| 948 | (void)ConsumeAnnotationToken(); |
| 949 | return; |
| 950 | } |
| 951 | (void)ConsumeToken(); |
| 952 | // Parse '('. |
| 953 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 954 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 955 | getOpenMPClauseName(OMPC_match))) { |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 956 | while (!SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch)) |
| 957 | ; |
| 958 | // Skip the last annot_pragma_openmp_end. |
| 959 | (void)ConsumeAnnotationToken(); |
| 960 | return; |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 961 | } |
| 962 | |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 963 | // Parse inner context selectors. |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame^] | 964 | if (!parseOpenMPContextSelectors( |
| 965 | Loc, [this, &DeclVarData]( |
| 966 | SourceRange SR, |
| 967 | const Sema::OpenMPDeclareVariantCtsSelectorData &Data) { |
| 968 | if (DeclVarData.hasValue()) |
| 969 | Actions.ActOnOpenMPDeclareVariantDirective( |
| 970 | DeclVarData.getValue().first, DeclVarData.getValue().second, |
| 971 | SR, Data); |
| 972 | })) { |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 973 | // Parse ')'. |
| 974 | (void)T.consumeClose(); |
| 975 | // Need to check for extra tokens. |
| 976 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 977 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 978 | << getOpenMPDirectiveName(OMPD_declare_variant); |
| 979 | } |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 980 | } |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 981 | |
| 982 | // Skip last tokens. |
| 983 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 984 | ConsumeAnyToken(); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 985 | // Skip the last annot_pragma_openmp_end. |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 986 | (void)ConsumeAnnotationToken(); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 987 | } |
| 988 | |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 989 | /// Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
| 990 | /// |
| 991 | /// default-clause: |
| 992 | /// 'default' '(' 'none' | 'shared' ') |
| 993 | /// |
| 994 | /// proc_bind-clause: |
| 995 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 996 | /// |
| 997 | /// device_type-clause: |
| 998 | /// 'device_type' '(' 'host' | 'nohost' | 'any' )' |
| 999 | namespace { |
| 1000 | struct SimpleClauseData { |
| 1001 | unsigned Type; |
| 1002 | SourceLocation Loc; |
| 1003 | SourceLocation LOpen; |
| 1004 | SourceLocation TypeLoc; |
| 1005 | SourceLocation RLoc; |
| 1006 | SimpleClauseData(unsigned Type, SourceLocation Loc, SourceLocation LOpen, |
| 1007 | SourceLocation TypeLoc, SourceLocation RLoc) |
| 1008 | : Type(Type), Loc(Loc), LOpen(LOpen), TypeLoc(TypeLoc), RLoc(RLoc) {} |
| 1009 | }; |
| 1010 | } // anonymous namespace |
| 1011 | |
| 1012 | static Optional<SimpleClauseData> |
| 1013 | parseOpenMPSimpleClause(Parser &P, OpenMPClauseKind Kind) { |
| 1014 | const Token &Tok = P.getCurToken(); |
| 1015 | SourceLocation Loc = Tok.getLocation(); |
| 1016 | SourceLocation LOpen = P.ConsumeToken(); |
| 1017 | // Parse '('. |
| 1018 | BalancedDelimiterTracker T(P, tok::l_paren, tok::annot_pragma_openmp_end); |
| 1019 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1020 | getOpenMPClauseName(Kind))) |
| 1021 | return llvm::None; |
| 1022 | |
| 1023 | unsigned Type = getOpenMPSimpleClauseType( |
| 1024 | Kind, Tok.isAnnotation() ? "" : P.getPreprocessor().getSpelling(Tok)); |
| 1025 | SourceLocation TypeLoc = Tok.getLocation(); |
| 1026 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1027 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1028 | P.ConsumeAnyToken(); |
| 1029 | |
| 1030 | // Parse ')'. |
| 1031 | SourceLocation RLoc = Tok.getLocation(); |
| 1032 | if (!T.consumeClose()) |
| 1033 | RLoc = T.getCloseLocation(); |
| 1034 | |
| 1035 | return SimpleClauseData(Type, Loc, LOpen, TypeLoc, RLoc); |
| 1036 | } |
| 1037 | |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1038 | Parser::DeclGroupPtrTy Parser::ParseOMPDeclareTargetClauses() { |
| 1039 | // OpenMP 4.5 syntax with list of entities. |
| 1040 | Sema::NamedDeclSetType SameDirectiveDecls; |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1041 | SmallVector<std::tuple<OMPDeclareTargetDeclAttr::MapTypeTy, SourceLocation, |
| 1042 | NamedDecl *>, |
| 1043 | 4> |
| 1044 | DeclareTargetDecls; |
| 1045 | OMPDeclareTargetDeclAttr::DevTypeTy DT = OMPDeclareTargetDeclAttr::DT_Any; |
| 1046 | SourceLocation DeviceTypeLoc; |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1047 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1048 | OMPDeclareTargetDeclAttr::MapTypeTy MT = OMPDeclareTargetDeclAttr::MT_To; |
| 1049 | if (Tok.is(tok::identifier)) { |
| 1050 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1051 | StringRef ClauseName = II->getName(); |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1052 | bool IsDeviceTypeClause = |
| 1053 | getLangOpts().OpenMP >= 50 && |
| 1054 | getOpenMPClauseKind(ClauseName) == OMPC_device_type; |
| 1055 | // Parse 'to|link|device_type' clauses. |
| 1056 | if (!OMPDeclareTargetDeclAttr::ConvertStrToMapTypeTy(ClauseName, MT) && |
| 1057 | !IsDeviceTypeClause) { |
| 1058 | Diag(Tok, diag::err_omp_declare_target_unexpected_clause) |
| 1059 | << ClauseName << (getLangOpts().OpenMP >= 50 ? 1 : 0); |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1060 | break; |
| 1061 | } |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1062 | // Parse 'device_type' clause and go to next clause if any. |
| 1063 | if (IsDeviceTypeClause) { |
| 1064 | Optional<SimpleClauseData> DevTypeData = |
| 1065 | parseOpenMPSimpleClause(*this, OMPC_device_type); |
| 1066 | if (DevTypeData.hasValue()) { |
| 1067 | if (DeviceTypeLoc.isValid()) { |
| 1068 | // We already saw another device_type clause, diagnose it. |
| 1069 | Diag(DevTypeData.getValue().Loc, |
| 1070 | diag::warn_omp_more_one_device_type_clause); |
| 1071 | } |
| 1072 | switch(static_cast<OpenMPDeviceType>(DevTypeData.getValue().Type)) { |
| 1073 | case OMPC_DEVICE_TYPE_any: |
| 1074 | DT = OMPDeclareTargetDeclAttr::DT_Any; |
| 1075 | break; |
| 1076 | case OMPC_DEVICE_TYPE_host: |
| 1077 | DT = OMPDeclareTargetDeclAttr::DT_Host; |
| 1078 | break; |
| 1079 | case OMPC_DEVICE_TYPE_nohost: |
| 1080 | DT = OMPDeclareTargetDeclAttr::DT_NoHost; |
| 1081 | break; |
| 1082 | case OMPC_DEVICE_TYPE_unknown: |
| 1083 | llvm_unreachable("Unexpected device_type"); |
| 1084 | } |
| 1085 | DeviceTypeLoc = DevTypeData.getValue().Loc; |
| 1086 | } |
| 1087 | continue; |
| 1088 | } |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1089 | ConsumeToken(); |
| 1090 | } |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1091 | auto &&Callback = [this, MT, &DeclareTargetDecls, &SameDirectiveDecls]( |
| 1092 | CXXScopeSpec &SS, DeclarationNameInfo NameInfo) { |
| 1093 | NamedDecl *ND = Actions.lookupOpenMPDeclareTargetName( |
| 1094 | getCurScope(), SS, NameInfo, SameDirectiveDecls); |
| 1095 | if (ND) |
| 1096 | DeclareTargetDecls.emplace_back(MT, NameInfo.getLoc(), ND); |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1097 | }; |
| 1098 | if (ParseOpenMPSimpleVarList(OMPD_declare_target, Callback, |
| 1099 | /*AllowScopeSpecifier=*/true)) |
| 1100 | break; |
| 1101 | |
| 1102 | // Consume optional ','. |
| 1103 | if (Tok.is(tok::comma)) |
| 1104 | ConsumeToken(); |
| 1105 | } |
| 1106 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 1107 | ConsumeAnyToken(); |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1108 | for (auto &MTLocDecl : DeclareTargetDecls) { |
| 1109 | OMPDeclareTargetDeclAttr::MapTypeTy MT; |
| 1110 | SourceLocation Loc; |
| 1111 | NamedDecl *ND; |
| 1112 | std::tie(MT, Loc, ND) = MTLocDecl; |
| 1113 | // device_type clause is applied only to functions. |
| 1114 | Actions.ActOnOpenMPDeclareTargetName( |
| 1115 | ND, Loc, MT, isa<VarDecl>(ND) ? OMPDeclareTargetDeclAttr::DT_Any : DT); |
| 1116 | } |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1117 | SmallVector<Decl *, 4> Decls(SameDirectiveDecls.begin(), |
| 1118 | SameDirectiveDecls.end()); |
| 1119 | if (Decls.empty()) |
| 1120 | return DeclGroupPtrTy(); |
| 1121 | return Actions.BuildDeclaratorGroup(Decls); |
| 1122 | } |
| 1123 | |
| 1124 | void Parser::ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind DKind, |
| 1125 | SourceLocation DTLoc) { |
| 1126 | if (DKind != OMPD_end_declare_target) { |
| 1127 | Diag(Tok, diag::err_expected_end_declare_target); |
| 1128 | Diag(DTLoc, diag::note_matching) << "'#pragma omp declare target'"; |
| 1129 | return; |
| 1130 | } |
| 1131 | ConsumeAnyToken(); |
| 1132 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1133 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1134 | << getOpenMPDirectiveName(OMPD_end_declare_target); |
| 1135 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 1136 | } |
| 1137 | // Skip the last annot_pragma_openmp_end. |
| 1138 | ConsumeAnyToken(); |
| 1139 | } |
| 1140 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1141 | /// Parsing of declarative OpenMP directives. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1142 | /// |
| 1143 | /// threadprivate-directive: |
| 1144 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1145 | /// annot_pragma_openmp_end |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1146 | /// |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1147 | /// allocate-directive: |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1148 | /// annot_pragma_openmp 'allocate' simple-variable-list [<clause>] |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1149 | /// annot_pragma_openmp_end |
| 1150 | /// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1151 | /// declare-reduction-directive: |
| 1152 | /// annot_pragma_openmp 'declare' 'reduction' [...] |
| 1153 | /// annot_pragma_openmp_end |
| 1154 | /// |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 1155 | /// declare-mapper-directive: |
| 1156 | /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifer> ':'] |
| 1157 | /// <type> <var> ')' [<clause>[[,] <clause>] ... ] |
| 1158 | /// annot_pragma_openmp_end |
| 1159 | /// |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1160 | /// declare-simd-directive: |
| 1161 | /// annot_pragma_openmp 'declare simd' {<clause> [,]} |
| 1162 | /// annot_pragma_openmp_end |
| 1163 | /// <function declaration/definition> |
| 1164 | /// |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1165 | /// requires directive: |
| 1166 | /// annot_pragma_openmp 'requires' <clause> [[[,] <clause>] ... ] |
| 1167 | /// annot_pragma_openmp_end |
| 1168 | /// |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1169 | Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( |
| 1170 | AccessSpecifier &AS, ParsedAttributesWithRange &Attrs, |
| 1171 | DeclSpec::TST TagType, Decl *Tag) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1172 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1173 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1174 | |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1175 | SourceLocation Loc = ConsumeAnnotationToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1176 | OpenMPDirectiveKind DKind = parseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1177 | |
| 1178 | switch (DKind) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1179 | case OMPD_threadprivate: { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1180 | ConsumeToken(); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1181 | DeclDirectiveListParserHelper Helper(this, DKind); |
| 1182 | if (!ParseOpenMPSimpleVarList(DKind, Helper, |
| 1183 | /*AllowScopeSpecifier=*/true)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1184 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1185 | // extra tokens. |
| 1186 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1187 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1188 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1189 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1190 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1191 | // Skip the last annot_pragma_openmp_end. |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1192 | ConsumeAnnotationToken(); |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1193 | return Actions.ActOnOpenMPThreadprivateDirective(Loc, |
| 1194 | Helper.getIdentifiers()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1195 | } |
| 1196 | break; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1197 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1198 | case OMPD_allocate: { |
| 1199 | ConsumeToken(); |
| 1200 | DeclDirectiveListParserHelper Helper(this, DKind); |
| 1201 | if (!ParseOpenMPSimpleVarList(DKind, Helper, |
| 1202 | /*AllowScopeSpecifier=*/true)) { |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1203 | SmallVector<OMPClause *, 1> Clauses; |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1204 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1205 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, |
| 1206 | OMPC_unknown + 1> |
| 1207 | FirstClauses(OMPC_unknown + 1); |
| 1208 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1209 | OpenMPClauseKind CKind = |
| 1210 | Tok.isAnnotation() ? OMPC_unknown |
| 1211 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 1212 | Actions.StartOpenMPClause(CKind); |
| 1213 | OMPClause *Clause = ParseOpenMPClause(OMPD_allocate, CKind, |
| 1214 | !FirstClauses[CKind].getInt()); |
| 1215 | SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, |
| 1216 | StopBeforeMatch); |
| 1217 | FirstClauses[CKind].setInt(true); |
| 1218 | if (Clause != nullptr) |
| 1219 | Clauses.push_back(Clause); |
| 1220 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 1221 | Actions.EndOpenMPClause(); |
| 1222 | break; |
| 1223 | } |
| 1224 | // Skip ',' if any. |
| 1225 | if (Tok.is(tok::comma)) |
| 1226 | ConsumeToken(); |
| 1227 | Actions.EndOpenMPClause(); |
| 1228 | } |
| 1229 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1230 | // extra tokens. |
| 1231 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1232 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1233 | << getOpenMPDirectiveName(DKind); |
| 1234 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 1235 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1236 | } |
| 1237 | // Skip the last annot_pragma_openmp_end. |
| 1238 | ConsumeAnnotationToken(); |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1239 | return Actions.ActOnOpenMPAllocateDirective(Loc, Helper.getIdentifiers(), |
| 1240 | Clauses); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1241 | } |
| 1242 | break; |
| 1243 | } |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1244 | case OMPD_requires: { |
| 1245 | SourceLocation StartLoc = ConsumeToken(); |
| 1246 | SmallVector<OMPClause *, 5> Clauses; |
| 1247 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
| 1248 | FirstClauses(OMPC_unknown + 1); |
| 1249 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
Ilya Biryukov | ff2a997 | 2019-02-26 11:01:50 +0000 | [diff] [blame] | 1250 | Diag(Tok, diag::err_omp_expected_clause) |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1251 | << getOpenMPDirectiveName(OMPD_requires); |
| 1252 | break; |
| 1253 | } |
| 1254 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1255 | OpenMPClauseKind CKind = Tok.isAnnotation() |
| 1256 | ? OMPC_unknown |
| 1257 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 1258 | Actions.StartOpenMPClause(CKind); |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1259 | OMPClause *Clause = ParseOpenMPClause(OMPD_requires, CKind, |
| 1260 | !FirstClauses[CKind].getInt()); |
| 1261 | SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, |
| 1262 | StopBeforeMatch); |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1263 | FirstClauses[CKind].setInt(true); |
| 1264 | if (Clause != nullptr) |
| 1265 | Clauses.push_back(Clause); |
| 1266 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 1267 | Actions.EndOpenMPClause(); |
| 1268 | break; |
| 1269 | } |
| 1270 | // Skip ',' if any. |
| 1271 | if (Tok.is(tok::comma)) |
| 1272 | ConsumeToken(); |
| 1273 | Actions.EndOpenMPClause(); |
| 1274 | } |
| 1275 | // Consume final annot_pragma_openmp_end |
| 1276 | if (Clauses.size() == 0) { |
| 1277 | Diag(Tok, diag::err_omp_expected_clause) |
| 1278 | << getOpenMPDirectiveName(OMPD_requires); |
| 1279 | ConsumeAnnotationToken(); |
| 1280 | return nullptr; |
| 1281 | } |
| 1282 | ConsumeAnnotationToken(); |
| 1283 | return Actions.ActOnOpenMPRequiresDirective(StartLoc, Clauses); |
| 1284 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1285 | case OMPD_declare_reduction: |
| 1286 | ConsumeToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1287 | if (DeclGroupPtrTy Res = ParseOpenMPDeclareReductionDirective(AS)) { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1288 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1289 | // extra tokens. |
| 1290 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1291 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1292 | << getOpenMPDirectiveName(OMPD_declare_reduction); |
| 1293 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1294 | ConsumeAnyToken(); |
| 1295 | } |
| 1296 | // Skip the last annot_pragma_openmp_end. |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1297 | ConsumeAnnotationToken(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1298 | return Res; |
| 1299 | } |
| 1300 | break; |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 1301 | case OMPD_declare_mapper: { |
| 1302 | ConsumeToken(); |
| 1303 | if (DeclGroupPtrTy Res = ParseOpenMPDeclareMapperDirective(AS)) { |
| 1304 | // Skip the last annot_pragma_openmp_end. |
| 1305 | ConsumeAnnotationToken(); |
| 1306 | return Res; |
| 1307 | } |
| 1308 | break; |
| 1309 | } |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1310 | case OMPD_declare_variant: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1311 | case OMPD_declare_simd: { |
| 1312 | // The syntax is: |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1313 | // { #pragma omp declare {simd|variant} } |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1314 | // <function-declaration-or-definition> |
| 1315 | // |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 1316 | CachedTokens Toks; |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1317 | Toks.push_back(Tok); |
| 1318 | ConsumeToken(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1319 | while(Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1320 | Toks.push_back(Tok); |
| 1321 | ConsumeAnyToken(); |
| 1322 | } |
| 1323 | Toks.push_back(Tok); |
| 1324 | ConsumeAnyToken(); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1325 | |
| 1326 | DeclGroupPtrTy Ptr; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1327 | if (Tok.is(tok::annot_pragma_openmp)) { |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1328 | Ptr = ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs, TagType, Tag); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1329 | } else if (Tok.isNot(tok::r_brace) && !isEofOrEom()) { |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1330 | // Here we expect to see some function declaration. |
| 1331 | if (AS == AS_none) { |
| 1332 | assert(TagType == DeclSpec::TST_unspecified); |
| 1333 | MaybeParseCXX11Attributes(Attrs); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1334 | ParsingDeclSpec PDS(*this); |
| 1335 | Ptr = ParseExternalDeclaration(Attrs, &PDS); |
| 1336 | } else { |
| 1337 | Ptr = |
| 1338 | ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag); |
| 1339 | } |
| 1340 | } |
| 1341 | if (!Ptr) { |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1342 | Diag(Loc, diag::err_omp_decl_in_declare_simd_variant) |
| 1343 | << (DKind == OMPD_declare_simd ? 0 : 1); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1344 | return DeclGroupPtrTy(); |
| 1345 | } |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1346 | if (DKind == OMPD_declare_simd) |
| 1347 | return ParseOMPDeclareSimdClauses(Ptr, Toks, Loc); |
| 1348 | assert(DKind == OMPD_declare_variant && |
| 1349 | "Expected declare variant directive only"); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1350 | ParseOMPDeclareVariantClauses(Ptr, Toks, Loc); |
| 1351 | return Ptr; |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1352 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1353 | case OMPD_declare_target: { |
| 1354 | SourceLocation DTLoc = ConsumeAnyToken(); |
| 1355 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1356 | return ParseOMPDeclareTargetClauses(); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1357 | } |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1358 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1359 | // Skip the last annot_pragma_openmp_end. |
| 1360 | ConsumeAnyToken(); |
| 1361 | |
| 1362 | if (!Actions.ActOnStartOpenMPDeclareTargetDirective(DTLoc)) |
| 1363 | return DeclGroupPtrTy(); |
| 1364 | |
Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 1365 | llvm::SmallVector<Decl *, 4> Decls; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1366 | DKind = parseOpenMPDirectiveKind(*this); |
Kelvin Li | bc38e63 | 2018-09-10 02:07:09 +0000 | [diff] [blame] | 1367 | while (DKind != OMPD_end_declare_target && Tok.isNot(tok::eof) && |
| 1368 | Tok.isNot(tok::r_brace)) { |
Alexey Bataev | 502ec49 | 2017-10-03 20:00:00 +0000 | [diff] [blame] | 1369 | DeclGroupPtrTy Ptr; |
| 1370 | // Here we expect to see some function declaration. |
| 1371 | if (AS == AS_none) { |
| 1372 | assert(TagType == DeclSpec::TST_unspecified); |
| 1373 | MaybeParseCXX11Attributes(Attrs); |
| 1374 | ParsingDeclSpec PDS(*this); |
| 1375 | Ptr = ParseExternalDeclaration(Attrs, &PDS); |
| 1376 | } else { |
| 1377 | Ptr = |
| 1378 | ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag); |
| 1379 | } |
Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 1380 | if (Ptr) { |
| 1381 | DeclGroupRef Ref = Ptr.get(); |
| 1382 | Decls.append(Ref.begin(), Ref.end()); |
| 1383 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1384 | if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) { |
| 1385 | TentativeParsingAction TPA(*this); |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1386 | ConsumeAnnotationToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1387 | DKind = parseOpenMPDirectiveKind(*this); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1388 | if (DKind != OMPD_end_declare_target) |
| 1389 | TPA.Revert(); |
| 1390 | else |
| 1391 | TPA.Commit(); |
| 1392 | } |
| 1393 | } |
| 1394 | |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1395 | ParseOMPEndDeclareTargetDirective(DKind, DTLoc); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1396 | Actions.ActOnFinishOpenMPDeclareTargetDirective(); |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 1397 | return Actions.BuildDeclaratorGroup(Decls); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1398 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1399 | case OMPD_unknown: |
| 1400 | Diag(Tok, diag::err_omp_unknown_directive); |
| 1401 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1402 | case OMPD_parallel: |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1403 | case OMPD_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1404 | case OMPD_task: |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1405 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1406 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1407 | case OMPD_taskwait: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1408 | case OMPD_taskgroup: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1409 | case OMPD_flush: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1410 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1411 | case OMPD_for_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1412 | case OMPD_sections: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1413 | case OMPD_section: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1414 | case OMPD_single: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1415 | case OMPD_master: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1416 | case OMPD_ordered: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1417 | case OMPD_critical: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1418 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1419 | case OMPD_parallel_for_simd: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1420 | case OMPD_parallel_sections: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1421 | case OMPD_atomic: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1422 | case OMPD_target: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1423 | case OMPD_teams: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1424 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1425 | case OMPD_cancel: |
Samuel Antao | 5b0688e | 2015-07-22 16:02:46 +0000 | [diff] [blame] | 1426 | case OMPD_target_data: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1427 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1428 | case OMPD_target_exit_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1429 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1430 | case OMPD_target_parallel_for: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1431 | case OMPD_taskloop: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1432 | case OMPD_taskloop_simd: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1433 | case OMPD_distribute: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1434 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1435 | case OMPD_target_update: |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1436 | case OMPD_distribute_parallel_for: |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1437 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1438 | case OMPD_distribute_simd: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1439 | case OMPD_target_parallel_for_simd: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1440 | case OMPD_target_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1441 | case OMPD_teams_distribute: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 1442 | case OMPD_teams_distribute_simd: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 1443 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 1444 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 1445 | case OMPD_target_teams: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 1446 | case OMPD_target_teams_distribute: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 1447 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 1448 | case OMPD_target_teams_distribute_parallel_for_simd: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 1449 | case OMPD_target_teams_distribute_simd: |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1450 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | 96dae81 | 2018-02-16 18:36:44 +0000 | [diff] [blame] | 1451 | << 1 << getOpenMPDirectiveName(DKind); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1452 | break; |
| 1453 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1454 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1455 | ConsumeAnyToken(); |
| 1456 | ConsumeAnyToken(); |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1457 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1460 | /// Parsing of declarative or executable OpenMP directives. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1461 | /// |
| 1462 | /// threadprivate-directive: |
| 1463 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
| 1464 | /// annot_pragma_openmp_end |
| 1465 | /// |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1466 | /// allocate-directive: |
| 1467 | /// annot_pragma_openmp 'allocate' simple-variable-list |
| 1468 | /// annot_pragma_openmp_end |
| 1469 | /// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1470 | /// declare-reduction-directive: |
| 1471 | /// annot_pragma_openmp 'declare' 'reduction' '(' <reduction_id> ':' |
| 1472 | /// <type> {',' <type>} ':' <expression> ')' ['initializer' '(' |
| 1473 | /// ('omp_priv' '=' <expression>|<function_call>) ')'] |
| 1474 | /// annot_pragma_openmp_end |
| 1475 | /// |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 1476 | /// declare-mapper-directive: |
| 1477 | /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifer> ':'] |
| 1478 | /// <type> <var> ')' [<clause>[[,] <clause>] ... ] |
| 1479 | /// annot_pragma_openmp_end |
| 1480 | /// |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1481 | /// executable-directive: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1482 | /// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1483 | /// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] | |
| 1484 | /// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1485 | /// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1486 | /// 'for simd' | 'parallel for simd' | 'target' | 'target data' | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1487 | /// 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1488 | /// 'distribute' | 'target enter data' | 'target exit data' | |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1489 | /// 'target parallel' | 'target parallel for' | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1490 | /// 'target update' | 'distribute parallel for' | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1491 | /// 'distribute paralle for simd' | 'distribute simd' | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1492 | /// 'target parallel for simd' | 'target simd' | |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 1493 | /// 'teams distribute' | 'teams distribute simd' | |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 1494 | /// 'teams distribute parallel for simd' | |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 1495 | /// 'teams distribute parallel for' | 'target teams' | |
| 1496 | /// 'target teams distribute' | |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 1497 | /// 'target teams distribute parallel for' | |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 1498 | /// 'target teams distribute parallel for simd' | |
| 1499 | /// 'target teams distribute simd' {clause} |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1500 | /// annot_pragma_openmp_end |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1501 | /// |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 1502 | StmtResult |
| 1503 | Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1504 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1505 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1506 | SmallVector<OMPClause *, 5> Clauses; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 1507 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1508 | FirstClauses(OMPC_unknown + 1); |
Momchil Velikov | 57c681f | 2017-08-10 15:43:06 +0000 | [diff] [blame] | 1509 | unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope | |
| 1510 | Scope::CompoundStmtScope | Scope::OpenMPDirectiveScope; |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1511 | SourceLocation Loc = ConsumeAnnotationToken(), EndLoc; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1512 | OpenMPDirectiveKind DKind = parseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1513 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1514 | // Name of critical directive. |
| 1515 | DeclarationNameInfo DirName; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1516 | StmtResult Directive = StmtError(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1517 | bool HasAssociatedStatement = true; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1518 | bool FlushHasClause = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1519 | |
| 1520 | switch (DKind) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1521 | case OMPD_threadprivate: { |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 1522 | // FIXME: Should this be permitted in C++? |
| 1523 | if ((StmtCtx & ParsedStmtContext::AllowDeclarationsInC) == |
| 1524 | ParsedStmtContext()) { |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 1525 | Diag(Tok, diag::err_omp_immediate_directive) |
| 1526 | << getOpenMPDirectiveName(DKind) << 0; |
| 1527 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1528 | ConsumeToken(); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1529 | DeclDirectiveListParserHelper Helper(this, DKind); |
| 1530 | if (!ParseOpenMPSimpleVarList(DKind, Helper, |
| 1531 | /*AllowScopeSpecifier=*/false)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1532 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1533 | // extra tokens. |
| 1534 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1535 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1536 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1537 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1538 | } |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1539 | DeclGroupPtrTy Res = Actions.ActOnOpenMPThreadprivateDirective( |
| 1540 | Loc, Helper.getIdentifiers()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1541 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 1542 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1543 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1544 | break; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1545 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1546 | case OMPD_allocate: { |
| 1547 | // FIXME: Should this be permitted in C++? |
| 1548 | if ((StmtCtx & ParsedStmtContext::AllowDeclarationsInC) == |
| 1549 | ParsedStmtContext()) { |
| 1550 | Diag(Tok, diag::err_omp_immediate_directive) |
| 1551 | << getOpenMPDirectiveName(DKind) << 0; |
| 1552 | } |
| 1553 | ConsumeToken(); |
| 1554 | DeclDirectiveListParserHelper Helper(this, DKind); |
| 1555 | if (!ParseOpenMPSimpleVarList(DKind, Helper, |
| 1556 | /*AllowScopeSpecifier=*/false)) { |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1557 | SmallVector<OMPClause *, 1> Clauses; |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1558 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1559 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, |
| 1560 | OMPC_unknown + 1> |
| 1561 | FirstClauses(OMPC_unknown + 1); |
| 1562 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1563 | OpenMPClauseKind CKind = |
| 1564 | Tok.isAnnotation() ? OMPC_unknown |
| 1565 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 1566 | Actions.StartOpenMPClause(CKind); |
| 1567 | OMPClause *Clause = ParseOpenMPClause(OMPD_allocate, CKind, |
| 1568 | !FirstClauses[CKind].getInt()); |
| 1569 | SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, |
| 1570 | StopBeforeMatch); |
| 1571 | FirstClauses[CKind].setInt(true); |
| 1572 | if (Clause != nullptr) |
| 1573 | Clauses.push_back(Clause); |
| 1574 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 1575 | Actions.EndOpenMPClause(); |
| 1576 | break; |
| 1577 | } |
| 1578 | // Skip ',' if any. |
| 1579 | if (Tok.is(tok::comma)) |
| 1580 | ConsumeToken(); |
| 1581 | Actions.EndOpenMPClause(); |
| 1582 | } |
| 1583 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1584 | // extra tokens. |
| 1585 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1586 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1587 | << getOpenMPDirectiveName(DKind); |
| 1588 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 1589 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1590 | } |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1591 | DeclGroupPtrTy Res = Actions.ActOnOpenMPAllocateDirective( |
| 1592 | Loc, Helper.getIdentifiers(), Clauses); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1593 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 1594 | } |
| 1595 | SkipUntil(tok::annot_pragma_openmp_end); |
| 1596 | break; |
| 1597 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1598 | case OMPD_declare_reduction: |
| 1599 | ConsumeToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1600 | if (DeclGroupPtrTy Res = |
| 1601 | ParseOpenMPDeclareReductionDirective(/*AS=*/AS_none)) { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1602 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1603 | // extra tokens. |
| 1604 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1605 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1606 | << getOpenMPDirectiveName(OMPD_declare_reduction); |
| 1607 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1608 | ConsumeAnyToken(); |
| 1609 | } |
| 1610 | ConsumeAnyToken(); |
| 1611 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1612 | } else { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1613 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1614 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1615 | break; |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 1616 | case OMPD_declare_mapper: { |
| 1617 | ConsumeToken(); |
| 1618 | if (DeclGroupPtrTy Res = |
| 1619 | ParseOpenMPDeclareMapperDirective(/*AS=*/AS_none)) { |
| 1620 | // Skip the last annot_pragma_openmp_end. |
| 1621 | ConsumeAnnotationToken(); |
| 1622 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 1623 | } else { |
| 1624 | SkipUntil(tok::annot_pragma_openmp_end); |
| 1625 | } |
| 1626 | break; |
| 1627 | } |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1628 | case OMPD_flush: |
| 1629 | if (PP.LookAhead(0).is(tok::l_paren)) { |
| 1630 | FlushHasClause = true; |
| 1631 | // Push copy of the current token back to stream to properly parse |
| 1632 | // pseudo-clause OMPFlushClause. |
Ilya Biryukov | 929af67 | 2019-05-17 09:32:05 +0000 | [diff] [blame] | 1633 | PP.EnterToken(Tok, /*IsReinject*/ true); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1634 | } |
Galina Kistanova | 474f2ce | 2017-06-01 21:26:38 +0000 | [diff] [blame] | 1635 | LLVM_FALLTHROUGH; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1636 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1637 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1638 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1639 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1640 | case OMPD_cancel: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1641 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1642 | case OMPD_target_exit_data: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1643 | case OMPD_target_update: |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 1644 | if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) == |
| 1645 | ParsedStmtContext()) { |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1646 | Diag(Tok, diag::err_omp_immediate_directive) |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1647 | << getOpenMPDirectiveName(DKind) << 0; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1648 | } |
| 1649 | HasAssociatedStatement = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1650 | // Fall through for further analysis. |
Galina Kistanova | 474f2ce | 2017-06-01 21:26:38 +0000 | [diff] [blame] | 1651 | LLVM_FALLTHROUGH; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1652 | case OMPD_parallel: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1653 | case OMPD_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1654 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1655 | case OMPD_for_simd: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1656 | case OMPD_sections: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1657 | case OMPD_single: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1658 | case OMPD_section: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1659 | case OMPD_master: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1660 | case OMPD_critical: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1661 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1662 | case OMPD_parallel_for_simd: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1663 | case OMPD_parallel_sections: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1664 | case OMPD_task: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1665 | case OMPD_ordered: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1666 | case OMPD_atomic: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1667 | case OMPD_target: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1668 | case OMPD_teams: |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1669 | case OMPD_taskgroup: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1670 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1671 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1672 | case OMPD_target_parallel_for: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1673 | case OMPD_taskloop: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1674 | case OMPD_taskloop_simd: |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1675 | case OMPD_distribute: |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1676 | case OMPD_distribute_parallel_for: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1677 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1678 | case OMPD_distribute_simd: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1679 | case OMPD_target_parallel_for_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1680 | case OMPD_target_simd: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 1681 | case OMPD_teams_distribute: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 1682 | case OMPD_teams_distribute_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 1683 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 1684 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 1685 | case OMPD_target_teams: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 1686 | case OMPD_target_teams_distribute: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 1687 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 1688 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 1689 | case OMPD_target_teams_distribute_simd: { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1690 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1691 | // Parse directive name of the 'critical' directive if any. |
| 1692 | if (DKind == OMPD_critical) { |
| 1693 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 1694 | tok::annot_pragma_openmp_end); |
| 1695 | if (!T.consumeOpen()) { |
| 1696 | if (Tok.isAnyIdentifier()) { |
| 1697 | DirName = |
| 1698 | DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 1699 | ConsumeAnyToken(); |
| 1700 | } else { |
| 1701 | Diag(Tok, diag::err_omp_expected_identifier_for_critical); |
| 1702 | } |
| 1703 | T.consumeClose(); |
| 1704 | } |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1705 | } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) { |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1706 | CancelRegion = parseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1707 | if (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1708 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1709 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1710 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1711 | if (isOpenMPLoopDirective(DKind)) |
| 1712 | ScopeFlags |= Scope::OpenMPLoopDirectiveScope; |
| 1713 | if (isOpenMPSimdDirective(DKind)) |
| 1714 | ScopeFlags |= Scope::OpenMPSimdDirectiveScope; |
| 1715 | ParseScope OMPDirectiveScope(this, ScopeFlags); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1716 | Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1717 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1718 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1719 | OpenMPClauseKind CKind = |
| 1720 | Tok.isAnnotation() |
| 1721 | ? OMPC_unknown |
| 1722 | : FlushHasClause ? OMPC_flush |
| 1723 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1724 | Actions.StartOpenMPClause(CKind); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1725 | FlushHasClause = false; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1726 | OMPClause *Clause = |
| 1727 | ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1728 | FirstClauses[CKind].setInt(true); |
| 1729 | if (Clause) { |
| 1730 | FirstClauses[CKind].setPointer(Clause); |
| 1731 | Clauses.push_back(Clause); |
| 1732 | } |
| 1733 | |
| 1734 | // Skip ',' if any. |
| 1735 | if (Tok.is(tok::comma)) |
| 1736 | ConsumeToken(); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1737 | Actions.EndOpenMPClause(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1738 | } |
| 1739 | // End location of the directive. |
| 1740 | EndLoc = Tok.getLocation(); |
| 1741 | // Consume final annot_pragma_openmp_end. |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1742 | ConsumeAnnotationToken(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1743 | |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1744 | // OpenMP [2.13.8, ordered Construct, Syntax] |
| 1745 | // If the depend clause is specified, the ordered construct is a stand-alone |
| 1746 | // directive. |
| 1747 | if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) { |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 1748 | if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) == |
| 1749 | ParsedStmtContext()) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1750 | Diag(Loc, diag::err_omp_immediate_directive) |
| 1751 | << getOpenMPDirectiveName(DKind) << 1 |
| 1752 | << getOpenMPClauseName(OMPC_depend); |
| 1753 | } |
| 1754 | HasAssociatedStatement = false; |
| 1755 | } |
| 1756 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1757 | StmtResult AssociatedStmt; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1758 | if (HasAssociatedStatement) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1759 | // The body is a block scope like in Lambdas and Blocks. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1760 | Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); |
Richard Smith | 6eb9b9e | 2018-02-03 00:44:57 +0000 | [diff] [blame] | 1761 | // FIXME: We create a bogus CompoundStmt scope to hold the contents of |
| 1762 | // the captured region. Code elsewhere assumes that any FunctionScopeInfo |
| 1763 | // should have at least one compound statement scope within it. |
| 1764 | AssociatedStmt = (Sema::CompoundScopeRAII(Actions), ParseStatement()); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1765 | AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); |
Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 1766 | } else if (DKind == OMPD_target_update || DKind == OMPD_target_enter_data || |
| 1767 | DKind == OMPD_target_exit_data) { |
Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 1768 | Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); |
Richard Smith | 6eb9b9e | 2018-02-03 00:44:57 +0000 | [diff] [blame] | 1769 | AssociatedStmt = (Sema::CompoundScopeRAII(Actions), |
| 1770 | Actions.ActOnCompoundStmt(Loc, Loc, llvm::None, |
| 1771 | /*isStmtExpr=*/false)); |
Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 1772 | AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1773 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1774 | Directive = Actions.ActOnOpenMPExecutableDirective( |
| 1775 | DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc, |
| 1776 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1777 | |
| 1778 | // Exit scope. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1779 | Actions.EndOpenMPDSABlock(Directive.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1780 | OMPDirectiveScope.Exit(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1781 | break; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1782 | } |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1783 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1784 | case OMPD_declare_target: |
| 1785 | case OMPD_end_declare_target: |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1786 | case OMPD_requires: |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1787 | case OMPD_declare_variant: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1788 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | 96dae81 | 2018-02-16 18:36:44 +0000 | [diff] [blame] | 1789 | << 1 << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1790 | SkipUntil(tok::annot_pragma_openmp_end); |
| 1791 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1792 | case OMPD_unknown: |
| 1793 | Diag(Tok, diag::err_omp_unknown_directive); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1794 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1795 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1796 | } |
| 1797 | return Directive; |
| 1798 | } |
| 1799 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1800 | // Parses simple list: |
| 1801 | // simple-variable-list: |
| 1802 | // '(' id-expression {, id-expression} ')' |
| 1803 | // |
| 1804 | bool Parser::ParseOpenMPSimpleVarList( |
| 1805 | OpenMPDirectiveKind Kind, |
| 1806 | const llvm::function_ref<void(CXXScopeSpec &, DeclarationNameInfo)> & |
| 1807 | Callback, |
| 1808 | bool AllowScopeSpecifier) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1809 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1810 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1811 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1812 | getOpenMPDirectiveName(Kind))) |
| 1813 | return true; |
| 1814 | bool IsCorrect = true; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1815 | bool NoIdentIsFound = true; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1816 | |
| 1817 | // Read tokens while ')' or annot_pragma_openmp_end is not found. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1818 | 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] | 1819 | CXXScopeSpec SS; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1820 | UnqualifiedId Name; |
| 1821 | // Read var name. |
| 1822 | Token PrevTok = Tok; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1823 | NoIdentIsFound = false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1824 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1825 | if (AllowScopeSpecifier && getLangOpts().CPlusPlus && |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 1826 | ParseOptionalCXXScopeSpecifier(SS, nullptr, false)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1827 | IsCorrect = false; |
| 1828 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1829 | StopBeforeMatch); |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1830 | } else if (ParseUnqualifiedId(SS, false, false, false, false, nullptr, |
Richard Smith | c08b693 | 2018-04-27 02:00:13 +0000 | [diff] [blame] | 1831 | nullptr, Name)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1832 | IsCorrect = false; |
| 1833 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1834 | StopBeforeMatch); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1835 | } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) && |
| 1836 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1837 | IsCorrect = false; |
| 1838 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1839 | StopBeforeMatch); |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1840 | Diag(PrevTok.getLocation(), diag::err_expected) |
| 1841 | << tok::identifier |
| 1842 | << SourceRange(PrevTok.getLocation(), PrevTokLocation); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1843 | } else { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1844 | Callback(SS, Actions.GetNameFromUnqualifiedId(Name)); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1845 | } |
| 1846 | // Consume ','. |
| 1847 | if (Tok.is(tok::comma)) { |
| 1848 | ConsumeToken(); |
| 1849 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1852 | if (NoIdentIsFound) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1853 | Diag(Tok, diag::err_expected) << tok::identifier; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1854 | IsCorrect = false; |
| 1855 | } |
| 1856 | |
| 1857 | // Parse ')'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1858 | IsCorrect = !T.consumeClose() && IsCorrect; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1859 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1860 | return !IsCorrect; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1861 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1862 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1863 | /// Parsing of OpenMP clauses. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1864 | /// |
| 1865 | /// clause: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1866 | /// if-clause | final-clause | num_threads-clause | safelen-clause | |
| 1867 | /// default-clause | private-clause | firstprivate-clause | shared-clause |
| 1868 | /// | linear-clause | aligned-clause | collapse-clause | |
| 1869 | /// lastprivate-clause | reduction-clause | proc_bind-clause | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 1870 | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 1871 | /// mergeable-clause | flush-clause | read-clause | write-clause | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1872 | /// update-clause | capture-clause | seq_cst-clause | device-clause | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 1873 | /// simdlen-clause | threads-clause | simd-clause | num_teams-clause | |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1874 | /// thread_limit-clause | priority-clause | grainsize-clause | |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1875 | /// nogroup-clause | num_tasks-clause | hint-clause | to-clause | |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1876 | /// from-clause | is_device_ptr-clause | task_reduction-clause | |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 1877 | /// in_reduction-clause | allocator-clause | allocate-clause |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1878 | /// |
| 1879 | OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, |
| 1880 | OpenMPClauseKind CKind, bool FirstClause) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1881 | OMPClause *Clause = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1882 | bool ErrorFound = false; |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 1883 | bool WrongDirective = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1884 | // Check if clause is allowed for the given directive. |
| 1885 | if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1886 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 1887 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1888 | ErrorFound = true; |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 1889 | WrongDirective = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | switch (CKind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1893 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1894 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1895 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1896 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1897 | case OMPC_collapse: |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 1898 | case OMPC_ordered: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 1899 | case OMPC_device: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1900 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 1901 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1902 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1903 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 1904 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 1905 | case OMPC_hint: |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1906 | case OMPC_allocator: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1907 | // OpenMP [2.5, Restrictions] |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1908 | // At most one num_threads clause can appear on the directive. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1909 | // OpenMP [2.8.1, simd construct, Restrictions] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1910 | // Only one safelen clause can appear on a simd directive. |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1911 | // Only one simdlen clause can appear on a simd directive. |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1912 | // Only one collapse clause can appear on a simd directive. |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 1913 | // OpenMP [2.9.1, target data construct, Restrictions] |
| 1914 | // At most one device clause can appear on the directive. |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1915 | // OpenMP [2.11.1, task Construct, Restrictions] |
| 1916 | // At most one if clause can appear on the directive. |
| 1917 | // At most one final clause can appear on the directive. |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1918 | // OpenMP [teams Construct, Restrictions] |
| 1919 | // At most one num_teams clause can appear on the directive. |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 1920 | // At most one thread_limit clause can appear on the directive. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1921 | // OpenMP [2.9.1, task Construct, Restrictions] |
| 1922 | // At most one priority clause can appear on the directive. |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1923 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 1924 | // At most one grainsize clause can appear on the directive. |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 1925 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 1926 | // At most one num_tasks clause can appear on the directive. |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1927 | // OpenMP [2.11.3, allocate Directive, Restrictions] |
| 1928 | // At most one allocator clause can appear on the directive. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1929 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1930 | Diag(Tok, diag::err_omp_more_one_clause) |
| 1931 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1932 | ErrorFound = true; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 1935 | if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren)) |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 1936 | Clause = ParseOpenMPClause(CKind, WrongDirective); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 1937 | else |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 1938 | Clause = ParseOpenMPSingleExprClause(CKind, WrongDirective); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1939 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1940 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1941 | case OMPC_proc_bind: |
Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 1942 | case OMPC_atomic_default_mem_order: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1943 | // OpenMP [2.14.3.1, Restrictions] |
| 1944 | // Only a single default clause may be specified on a parallel, task or |
| 1945 | // teams directive. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1946 | // OpenMP [2.5, parallel Construct, Restrictions] |
| 1947 | // At most one proc_bind clause can appear on the directive. |
Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 1948 | // OpenMP [5.0, Requires directive, Restrictions] |
| 1949 | // At most one atomic_default_mem_order clause can appear |
| 1950 | // on the directive |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1951 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1952 | Diag(Tok, diag::err_omp_more_one_clause) |
| 1953 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1954 | ErrorFound = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1955 | } |
| 1956 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 1957 | Clause = ParseOpenMPSimpleClause(CKind, WrongDirective); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1958 | break; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1959 | case OMPC_schedule: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 1960 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 1961 | case OMPC_defaultmap: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1962 | // OpenMP [2.7.1, Restrictions, p. 3] |
| 1963 | // Only one schedule clause can appear on a loop directive. |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 1964 | // OpenMP [2.10.4, Restrictions, p. 106] |
| 1965 | // At most one defaultmap clause can appear on the directive. |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1966 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1967 | Diag(Tok, diag::err_omp_more_one_clause) |
| 1968 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1969 | ErrorFound = true; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1970 | } |
Galina Kistanova | 474f2ce | 2017-06-01 21:26:38 +0000 | [diff] [blame] | 1971 | LLVM_FALLTHROUGH; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1972 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1973 | case OMPC_if: |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 1974 | Clause = ParseOpenMPSingleExprWithArgClause(CKind, WrongDirective); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1975 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 1976 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 1977 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 1978 | case OMPC_mergeable: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 1979 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1980 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 1981 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 1982 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 1983 | case OMPC_seq_cst: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 1984 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1985 | case OMPC_simd: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 1986 | case OMPC_nogroup: |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1987 | case OMPC_unified_address: |
Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 1988 | case OMPC_unified_shared_memory: |
Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 1989 | case OMPC_reverse_offload: |
Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 1990 | case OMPC_dynamic_allocators: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1991 | // OpenMP [2.7.1, Restrictions, p. 9] |
| 1992 | // Only one ordered clause can appear on a loop directive. |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 1993 | // OpenMP [2.7.1, Restrictions, C/C++, p. 4] |
| 1994 | // Only one nowait clause can appear on a for directive. |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1995 | // OpenMP [5.0, Requires directive, Restrictions] |
| 1996 | // 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] | 1997 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1998 | Diag(Tok, diag::err_omp_more_one_clause) |
| 1999 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 2000 | ErrorFound = true; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2003 | Clause = ParseOpenMPClause(CKind, WrongDirective); |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2004 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2005 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2006 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2007 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2008 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2009 | case OMPC_reduction: |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 2010 | case OMPC_task_reduction: |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2011 | case OMPC_in_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 2012 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 2013 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 2014 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2015 | case OMPC_copyprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2016 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 2017 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 2018 | case OMPC_map: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 2019 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 2020 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 2021 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 2022 | case OMPC_is_device_ptr: |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 2023 | case OMPC_allocate: |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2024 | Clause = ParseOpenMPVarListClause(DKind, CKind, WrongDirective); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2025 | break; |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 2026 | case OMPC_device_type: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2027 | case OMPC_unknown: |
| 2028 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 2029 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 2030 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2031 | break; |
| 2032 | case OMPC_threadprivate: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2033 | case OMPC_uniform: |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 2034 | case OMPC_match: |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2035 | if (!WrongDirective) |
| 2036 | Diag(Tok, diag::err_omp_unexpected_clause) |
| 2037 | << getOpenMPClauseName(CKind) << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 2038 | SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2039 | break; |
| 2040 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2041 | return ErrorFound ? nullptr : Clause; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2042 | } |
| 2043 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2044 | /// Parses simple expression in parens for single-expression clauses of OpenMP |
| 2045 | /// constructs. |
| 2046 | /// \param RLoc Returned location of right paren. |
| 2047 | ExprResult Parser::ParseOpenMPParensExpr(StringRef ClauseName, |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 2048 | SourceLocation &RLoc, |
| 2049 | bool IsAddressOfOperand) { |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2050 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 2051 | if (T.expectAndConsume(diag::err_expected_lparen_after, ClauseName.data())) |
| 2052 | return ExprError(); |
| 2053 | |
| 2054 | SourceLocation ELoc = Tok.getLocation(); |
| 2055 | ExprResult LHS(ParseCastExpression( |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 2056 | /*isUnaryExpression=*/false, IsAddressOfOperand, NotTypeCast)); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2057 | ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); |
Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 2058 | Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc, /*DiscardedValue*/ false); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2059 | |
| 2060 | // Parse ')'. |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 2061 | RLoc = Tok.getLocation(); |
| 2062 | if (!T.consumeClose()) |
| 2063 | RLoc = T.getCloseLocation(); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2064 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2065 | return Val; |
| 2066 | } |
| 2067 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2068 | /// Parsing of OpenMP clauses with single expressions like 'final', |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 2069 | /// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams', |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2070 | /// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2071 | /// |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 2072 | /// final-clause: |
| 2073 | /// 'final' '(' expression ')' |
| 2074 | /// |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 2075 | /// num_threads-clause: |
| 2076 | /// 'num_threads' '(' expression ')' |
| 2077 | /// |
| 2078 | /// safelen-clause: |
| 2079 | /// 'safelen' '(' expression ')' |
| 2080 | /// |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 2081 | /// simdlen-clause: |
| 2082 | /// 'simdlen' '(' expression ')' |
| 2083 | /// |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 2084 | /// collapse-clause: |
| 2085 | /// 'collapse' '(' expression ')' |
| 2086 | /// |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 2087 | /// priority-clause: |
| 2088 | /// 'priority' '(' expression ')' |
| 2089 | /// |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 2090 | /// grainsize-clause: |
| 2091 | /// 'grainsize' '(' expression ')' |
| 2092 | /// |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 2093 | /// num_tasks-clause: |
| 2094 | /// 'num_tasks' '(' expression ')' |
| 2095 | /// |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2096 | /// hint-clause: |
| 2097 | /// 'hint' '(' expression ')' |
| 2098 | /// |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2099 | /// allocator-clause: |
| 2100 | /// 'allocator' '(' expression ')' |
| 2101 | /// |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2102 | OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind, |
| 2103 | bool ParseOnly) { |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2104 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2105 | SourceLocation LLoc = Tok.getLocation(); |
| 2106 | SourceLocation RLoc; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2107 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2108 | ExprResult Val = ParseOpenMPParensExpr(getOpenMPClauseName(Kind), RLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2109 | |
| 2110 | if (Val.isInvalid()) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2111 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2112 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2113 | if (ParseOnly) |
| 2114 | return nullptr; |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2115 | return Actions.ActOnOpenMPSingleExprClause(Kind, Val.get(), Loc, LLoc, RLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2118 | /// Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2119 | /// |
| 2120 | /// default-clause: |
| 2121 | /// 'default' '(' 'none' | 'shared' ') |
| 2122 | /// |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 2123 | /// proc_bind-clause: |
| 2124 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 2125 | /// |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2126 | OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind, |
| 2127 | bool ParseOnly) { |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 2128 | llvm::Optional<SimpleClauseData> Val = parseOpenMPSimpleClause(*this, Kind); |
| 2129 | if (!Val || ParseOnly) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2130 | return nullptr; |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 2131 | return Actions.ActOnOpenMPSimpleClause( |
| 2132 | Kind, Val.getValue().Type, Val.getValue().TypeLoc, Val.getValue().LOpen, |
| 2133 | Val.getValue().Loc, Val.getValue().RLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2136 | /// Parsing of OpenMP clauses like 'ordered'. |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2137 | /// |
| 2138 | /// ordered-clause: |
| 2139 | /// 'ordered' |
| 2140 | /// |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 2141 | /// nowait-clause: |
| 2142 | /// 'nowait' |
| 2143 | /// |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 2144 | /// untied-clause: |
| 2145 | /// 'untied' |
| 2146 | /// |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 2147 | /// mergeable-clause: |
| 2148 | /// 'mergeable' |
| 2149 | /// |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 2150 | /// read-clause: |
| 2151 | /// 'read' |
| 2152 | /// |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2153 | /// threads-clause: |
| 2154 | /// 'threads' |
| 2155 | /// |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2156 | /// simd-clause: |
| 2157 | /// 'simd' |
| 2158 | /// |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 2159 | /// nogroup-clause: |
| 2160 | /// 'nogroup' |
| 2161 | /// |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2162 | OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind, bool ParseOnly) { |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2163 | SourceLocation Loc = Tok.getLocation(); |
| 2164 | ConsumeAnyToken(); |
| 2165 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2166 | if (ParseOnly) |
| 2167 | return nullptr; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2168 | return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation()); |
| 2169 | } |
| 2170 | |
| 2171 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2172 | /// Parsing of OpenMP clauses with single expressions and some additional |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2173 | /// argument like 'schedule' or 'dist_schedule'. |
| 2174 | /// |
| 2175 | /// schedule-clause: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2176 | /// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ] |
| 2177 | /// ')' |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2178 | /// |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2179 | /// if-clause: |
| 2180 | /// 'if' '(' [ directive-name-modifier ':' ] expression ')' |
| 2181 | /// |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 2182 | /// defaultmap: |
| 2183 | /// 'defaultmap' '(' modifier ':' kind ')' |
| 2184 | /// |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2185 | OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind, |
| 2186 | bool ParseOnly) { |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2187 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2188 | SourceLocation DelimLoc; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2189 | // Parse '('. |
| 2190 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 2191 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 2192 | getOpenMPClauseName(Kind))) |
| 2193 | return nullptr; |
| 2194 | |
| 2195 | ExprResult Val; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2196 | SmallVector<unsigned, 4> Arg; |
| 2197 | SmallVector<SourceLocation, 4> KLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2198 | if (Kind == OMPC_schedule) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2199 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 2200 | Arg.resize(NumberOfElements); |
| 2201 | KLoc.resize(NumberOfElements); |
| 2202 | Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 2203 | Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 2204 | Arg[ScheduleKind] = OMPC_SCHEDULE_unknown; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2205 | unsigned KindModifier = getOpenMPSimpleClauseType( |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2206 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2207 | if (KindModifier > OMPC_SCHEDULE_unknown) { |
| 2208 | // Parse 'modifier' |
| 2209 | Arg[Modifier1] = KindModifier; |
| 2210 | KLoc[Modifier1] = Tok.getLocation(); |
| 2211 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2212 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2213 | ConsumeAnyToken(); |
| 2214 | if (Tok.is(tok::comma)) { |
| 2215 | // Parse ',' 'modifier' |
| 2216 | ConsumeAnyToken(); |
| 2217 | KindModifier = getOpenMPSimpleClauseType( |
| 2218 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 2219 | Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown |
| 2220 | ? KindModifier |
Aaron Ballman | ad8a104 | 2015-12-28 15:52:46 +0000 | [diff] [blame] | 2221 | : (unsigned)OMPC_SCHEDULE_unknown; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2222 | KLoc[Modifier2] = Tok.getLocation(); |
| 2223 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2224 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2225 | ConsumeAnyToken(); |
| 2226 | } |
| 2227 | // Parse ':' |
| 2228 | if (Tok.is(tok::colon)) |
| 2229 | ConsumeAnyToken(); |
| 2230 | else |
| 2231 | Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier"; |
| 2232 | KindModifier = getOpenMPSimpleClauseType( |
| 2233 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 2234 | } |
| 2235 | Arg[ScheduleKind] = KindModifier; |
| 2236 | KLoc[ScheduleKind] = Tok.getLocation(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2237 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2238 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2239 | ConsumeAnyToken(); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2240 | if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static || |
| 2241 | Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic || |
| 2242 | Arg[ScheduleKind] == OMPC_SCHEDULE_guided) && |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2243 | Tok.is(tok::comma)) |
| 2244 | DelimLoc = ConsumeAnyToken(); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 2245 | } else if (Kind == OMPC_dist_schedule) { |
| 2246 | Arg.push_back(getOpenMPSimpleClauseType( |
| 2247 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 2248 | KLoc.push_back(Tok.getLocation()); |
| 2249 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2250 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2251 | ConsumeAnyToken(); |
| 2252 | if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma)) |
| 2253 | DelimLoc = ConsumeAnyToken(); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 2254 | } else if (Kind == OMPC_defaultmap) { |
| 2255 | // Get a defaultmap modifier |
| 2256 | Arg.push_back(getOpenMPSimpleClauseType( |
| 2257 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 2258 | KLoc.push_back(Tok.getLocation()); |
| 2259 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2260 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2261 | ConsumeAnyToken(); |
| 2262 | // Parse ':' |
| 2263 | if (Tok.is(tok::colon)) |
| 2264 | ConsumeAnyToken(); |
| 2265 | else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown) |
| 2266 | Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier"; |
| 2267 | // Get a defaultmap kind |
| 2268 | Arg.push_back(getOpenMPSimpleClauseType( |
| 2269 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 2270 | KLoc.push_back(Tok.getLocation()); |
| 2271 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2272 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2273 | ConsumeAnyToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2274 | } else { |
| 2275 | assert(Kind == OMPC_if); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2276 | KLoc.push_back(Tok.getLocation()); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2277 | TentativeParsingAction TPA(*this); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2278 | Arg.push_back(parseOpenMPDirectiveKind(*this)); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2279 | if (Arg.back() != OMPD_unknown) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2280 | ConsumeToken(); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2281 | if (Tok.is(tok::colon) && getLangOpts().OpenMP > 40) { |
| 2282 | TPA.Commit(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2283 | DelimLoc = ConsumeToken(); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2284 | } else { |
| 2285 | TPA.Revert(); |
| 2286 | Arg.back() = OMPD_unknown; |
| 2287 | } |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2288 | } else { |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2289 | TPA.Revert(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2290 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2291 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2292 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 2293 | bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) || |
| 2294 | (Kind == OMPC_dist_schedule && DelimLoc.isValid()) || |
| 2295 | Kind == OMPC_if; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2296 | if (NeedAnExpression) { |
| 2297 | SourceLocation ELoc = Tok.getLocation(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2298 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 2299 | Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional); |
Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 2300 | Val = |
| 2301 | Actions.ActOnFinishFullExpr(Val.get(), ELoc, /*DiscardedValue*/ false); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | // Parse ')'. |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 2305 | SourceLocation RLoc = Tok.getLocation(); |
| 2306 | if (!T.consumeClose()) |
| 2307 | RLoc = T.getCloseLocation(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2308 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2309 | if (NeedAnExpression && Val.isInvalid()) |
| 2310 | return nullptr; |
| 2311 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2312 | if (ParseOnly) |
| 2313 | return nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2314 | return Actions.ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 2315 | Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc, RLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2316 | } |
| 2317 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2318 | static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, |
| 2319 | UnqualifiedId &ReductionId) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2320 | if (ReductionIdScopeSpec.isEmpty()) { |
| 2321 | auto OOK = OO_None; |
| 2322 | switch (P.getCurToken().getKind()) { |
| 2323 | case tok::plus: |
| 2324 | OOK = OO_Plus; |
| 2325 | break; |
| 2326 | case tok::minus: |
| 2327 | OOK = OO_Minus; |
| 2328 | break; |
| 2329 | case tok::star: |
| 2330 | OOK = OO_Star; |
| 2331 | break; |
| 2332 | case tok::amp: |
| 2333 | OOK = OO_Amp; |
| 2334 | break; |
| 2335 | case tok::pipe: |
| 2336 | OOK = OO_Pipe; |
| 2337 | break; |
| 2338 | case tok::caret: |
| 2339 | OOK = OO_Caret; |
| 2340 | break; |
| 2341 | case tok::ampamp: |
| 2342 | OOK = OO_AmpAmp; |
| 2343 | break; |
| 2344 | case tok::pipepipe: |
| 2345 | OOK = OO_PipePipe; |
| 2346 | break; |
| 2347 | default: |
| 2348 | break; |
| 2349 | } |
| 2350 | if (OOK != OO_None) { |
| 2351 | SourceLocation OpLoc = P.ConsumeToken(); |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2352 | SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()}; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2353 | ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations); |
| 2354 | return false; |
| 2355 | } |
| 2356 | } |
| 2357 | return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false, |
| 2358 | /*AllowDestructorName*/ false, |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 2359 | /*AllowConstructorName*/ false, |
| 2360 | /*AllowDeductionGuide*/ false, |
Richard Smith | c08b693 | 2018-04-27 02:00:13 +0000 | [diff] [blame] | 2361 | nullptr, nullptr, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2364 | /// Checks if the token is a valid map-type-modifier. |
| 2365 | static OpenMPMapModifierKind isMapModifier(Parser &P) { |
| 2366 | Token Tok = P.getCurToken(); |
| 2367 | if (!Tok.is(tok::identifier)) |
| 2368 | return OMPC_MAP_MODIFIER_unknown; |
| 2369 | |
| 2370 | Preprocessor &PP = P.getPreprocessor(); |
| 2371 | OpenMPMapModifierKind TypeModifier = static_cast<OpenMPMapModifierKind>( |
| 2372 | getOpenMPSimpleClauseType(OMPC_map, PP.getSpelling(Tok))); |
| 2373 | return TypeModifier; |
| 2374 | } |
| 2375 | |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2376 | /// Parse the mapper modifier in map, to, and from clauses. |
| 2377 | bool Parser::parseMapperModifier(OpenMPVarListDataTy &Data) { |
| 2378 | // Parse '('. |
| 2379 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::colon); |
| 2380 | if (T.expectAndConsume(diag::err_expected_lparen_after, "mapper")) { |
| 2381 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2382 | StopBeforeMatch); |
| 2383 | return true; |
| 2384 | } |
| 2385 | // Parse mapper-identifier |
| 2386 | if (getLangOpts().CPlusPlus) |
| 2387 | ParseOptionalCXXScopeSpecifier(Data.ReductionOrMapperIdScopeSpec, |
| 2388 | /*ObjectType=*/nullptr, |
| 2389 | /*EnteringContext=*/false); |
| 2390 | if (Tok.isNot(tok::identifier) && Tok.isNot(tok::kw_default)) { |
| 2391 | Diag(Tok.getLocation(), diag::err_omp_mapper_illegal_identifier); |
| 2392 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2393 | StopBeforeMatch); |
| 2394 | return true; |
| 2395 | } |
| 2396 | auto &DeclNames = Actions.getASTContext().DeclarationNames; |
| 2397 | Data.ReductionOrMapperId = DeclarationNameInfo( |
| 2398 | DeclNames.getIdentifier(Tok.getIdentifierInfo()), Tok.getLocation()); |
| 2399 | ConsumeToken(); |
| 2400 | // Parse ')'. |
| 2401 | return T.consumeClose(); |
| 2402 | } |
| 2403 | |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2404 | /// Parse map-type-modifiers in map clause. |
| 2405 | /// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2406 | /// where, map-type-modifier ::= always | close | mapper(mapper-identifier) |
| 2407 | bool Parser::parseMapTypeModifiers(OpenMPVarListDataTy &Data) { |
| 2408 | while (getCurToken().isNot(tok::colon)) { |
| 2409 | OpenMPMapModifierKind TypeModifier = isMapModifier(*this); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2410 | if (TypeModifier == OMPC_MAP_MODIFIER_always || |
| 2411 | TypeModifier == OMPC_MAP_MODIFIER_close) { |
| 2412 | Data.MapTypeModifiers.push_back(TypeModifier); |
| 2413 | Data.MapTypeModifiersLoc.push_back(Tok.getLocation()); |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2414 | ConsumeToken(); |
| 2415 | } else if (TypeModifier == OMPC_MAP_MODIFIER_mapper) { |
| 2416 | Data.MapTypeModifiers.push_back(TypeModifier); |
| 2417 | Data.MapTypeModifiersLoc.push_back(Tok.getLocation()); |
| 2418 | ConsumeToken(); |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2419 | if (parseMapperModifier(Data)) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2420 | return true; |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2421 | } else { |
| 2422 | // For the case of unknown map-type-modifier or a map-type. |
| 2423 | // Map-type is followed by a colon; the function returns when it |
| 2424 | // encounters a token followed by a colon. |
| 2425 | if (Tok.is(tok::comma)) { |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2426 | Diag(Tok, diag::err_omp_map_type_modifier_missing); |
| 2427 | ConsumeToken(); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2428 | continue; |
| 2429 | } |
| 2430 | // Potential map-type token as it is followed by a colon. |
| 2431 | if (PP.LookAhead(0).is(tok::colon)) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2432 | return false; |
| 2433 | Diag(Tok, diag::err_omp_unknown_map_type_modifier); |
| 2434 | ConsumeToken(); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2435 | } |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2436 | if (getCurToken().is(tok::comma)) |
| 2437 | ConsumeToken(); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2438 | } |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2439 | return false; |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | /// Checks if the token is a valid map-type. |
| 2443 | static OpenMPMapClauseKind isMapType(Parser &P) { |
| 2444 | Token Tok = P.getCurToken(); |
| 2445 | // The map-type token can be either an identifier or the C++ delete keyword. |
| 2446 | if (!Tok.isOneOf(tok::identifier, tok::kw_delete)) |
| 2447 | return OMPC_MAP_unknown; |
| 2448 | Preprocessor &PP = P.getPreprocessor(); |
| 2449 | OpenMPMapClauseKind MapType = static_cast<OpenMPMapClauseKind>( |
| 2450 | getOpenMPSimpleClauseType(OMPC_map, PP.getSpelling(Tok))); |
| 2451 | return MapType; |
| 2452 | } |
| 2453 | |
| 2454 | /// Parse map-type in map clause. |
| 2455 | /// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list) |
Ilya Biryukov | ff2a997 | 2019-02-26 11:01:50 +0000 | [diff] [blame] | 2456 | /// where, map-type ::= to | from | tofrom | alloc | release | delete |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2457 | static void parseMapType(Parser &P, Parser::OpenMPVarListDataTy &Data) { |
| 2458 | Token Tok = P.getCurToken(); |
| 2459 | if (Tok.is(tok::colon)) { |
| 2460 | P.Diag(Tok, diag::err_omp_map_type_missing); |
| 2461 | return; |
| 2462 | } |
| 2463 | Data.MapType = isMapType(P); |
| 2464 | if (Data.MapType == OMPC_MAP_unknown) |
| 2465 | P.Diag(Tok, diag::err_omp_unknown_map_type); |
| 2466 | P.ConsumeToken(); |
| 2467 | } |
| 2468 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2469 | /// Parses clauses with list. |
| 2470 | bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind, |
| 2471 | OpenMPClauseKind Kind, |
| 2472 | SmallVectorImpl<Expr *> &Vars, |
| 2473 | OpenMPVarListDataTy &Data) { |
| 2474 | UnqualifiedId UnqualifiedReductionId; |
| 2475 | bool InvalidReductionId = false; |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2476 | bool IsInvalidMapperModifier = false; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2477 | |
| 2478 | // Parse '('. |
| 2479 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 2480 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 2481 | getOpenMPClauseName(Kind))) |
| 2482 | return true; |
| 2483 | |
| 2484 | bool NeedRParenForLinear = false; |
| 2485 | BalancedDelimiterTracker LinearT(*this, tok::l_paren, |
| 2486 | tok::annot_pragma_openmp_end); |
| 2487 | // Handle reduction-identifier for reduction clause. |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2488 | if (Kind == OMPC_reduction || Kind == OMPC_task_reduction || |
| 2489 | Kind == OMPC_in_reduction) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2490 | ColonProtectionRAIIObject ColonRAII(*this); |
| 2491 | if (getLangOpts().CPlusPlus) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2492 | ParseOptionalCXXScopeSpecifier(Data.ReductionOrMapperIdScopeSpec, |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2493 | /*ObjectType=*/nullptr, |
| 2494 | /*EnteringContext=*/false); |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2495 | InvalidReductionId = ParseReductionId( |
| 2496 | *this, Data.ReductionOrMapperIdScopeSpec, UnqualifiedReductionId); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2497 | if (InvalidReductionId) { |
| 2498 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2499 | StopBeforeMatch); |
| 2500 | } |
| 2501 | if (Tok.is(tok::colon)) |
| 2502 | Data.ColonLoc = ConsumeToken(); |
| 2503 | else |
| 2504 | Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier"; |
| 2505 | if (!InvalidReductionId) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2506 | Data.ReductionOrMapperId = |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2507 | Actions.GetNameFromUnqualifiedId(UnqualifiedReductionId); |
| 2508 | } else if (Kind == OMPC_depend) { |
| 2509 | // Handle dependency type for depend clause. |
| 2510 | ColonProtectionRAIIObject ColonRAII(*this); |
| 2511 | Data.DepKind = |
| 2512 | static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType( |
| 2513 | Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : "")); |
| 2514 | Data.DepLinMapLoc = Tok.getLocation(); |
| 2515 | |
| 2516 | if (Data.DepKind == OMPC_DEPEND_unknown) { |
| 2517 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2518 | StopBeforeMatch); |
| 2519 | } else { |
| 2520 | ConsumeToken(); |
| 2521 | // Special processing for depend(source) clause. |
| 2522 | if (DKind == OMPD_ordered && Data.DepKind == OMPC_DEPEND_source) { |
| 2523 | // Parse ')'. |
| 2524 | T.consumeClose(); |
| 2525 | return false; |
| 2526 | } |
| 2527 | } |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2528 | if (Tok.is(tok::colon)) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2529 | Data.ColonLoc = ConsumeToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2530 | } else { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2531 | Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren |
| 2532 | : diag::warn_pragma_expected_colon) |
| 2533 | << "dependency type"; |
| 2534 | } |
| 2535 | } else if (Kind == OMPC_linear) { |
| 2536 | // Try to parse modifier if any. |
| 2537 | if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) { |
| 2538 | Data.LinKind = static_cast<OpenMPLinearClauseKind>( |
| 2539 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))); |
| 2540 | Data.DepLinMapLoc = ConsumeToken(); |
| 2541 | LinearT.consumeOpen(); |
| 2542 | NeedRParenForLinear = true; |
| 2543 | } |
| 2544 | } else if (Kind == OMPC_map) { |
| 2545 | // Handle map type for map clause. |
| 2546 | ColonProtectionRAIIObject ColonRAII(*this); |
| 2547 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2548 | // 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] | 2549 | // 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] | 2550 | // spelling of the C++ delete keyword. |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2551 | Data.DepLinMapLoc = Tok.getLocation(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2552 | |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2553 | // Check for presence of a colon in the map clause. |
| 2554 | TentativeParsingAction TPA(*this); |
| 2555 | bool ColonPresent = false; |
| 2556 | if (SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2557 | StopBeforeMatch)) { |
| 2558 | if (Tok.is(tok::colon)) |
| 2559 | ColonPresent = true; |
| 2560 | } |
| 2561 | TPA.Revert(); |
| 2562 | // Only parse map-type-modifier[s] and map-type if a colon is present in |
| 2563 | // the map clause. |
| 2564 | if (ColonPresent) { |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2565 | IsInvalidMapperModifier = parseMapTypeModifiers(Data); |
| 2566 | if (!IsInvalidMapperModifier) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2567 | parseMapType(*this, Data); |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2568 | else |
| 2569 | SkipUntil(tok::colon, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2570 | } |
| 2571 | if (Data.MapType == OMPC_MAP_unknown) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2572 | Data.MapType = OMPC_MAP_tofrom; |
| 2573 | Data.IsMapTypeImplicit = true; |
| 2574 | } |
| 2575 | |
| 2576 | if (Tok.is(tok::colon)) |
| 2577 | Data.ColonLoc = ConsumeToken(); |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 2578 | } else if (Kind == OMPC_to || Kind == OMPC_from) { |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2579 | if (Tok.is(tok::identifier)) { |
| 2580 | bool IsMapperModifier = false; |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 2581 | if (Kind == OMPC_to) { |
| 2582 | auto Modifier = static_cast<OpenMPToModifierKind>( |
| 2583 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))); |
| 2584 | if (Modifier == OMPC_TO_MODIFIER_mapper) |
| 2585 | IsMapperModifier = true; |
| 2586 | } else { |
| 2587 | auto Modifier = static_cast<OpenMPFromModifierKind>( |
| 2588 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))); |
| 2589 | if (Modifier == OMPC_FROM_MODIFIER_mapper) |
| 2590 | IsMapperModifier = true; |
| 2591 | } |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2592 | if (IsMapperModifier) { |
| 2593 | // Parse the mapper modifier. |
| 2594 | ConsumeToken(); |
| 2595 | IsInvalidMapperModifier = parseMapperModifier(Data); |
| 2596 | if (Tok.isNot(tok::colon)) { |
| 2597 | if (!IsInvalidMapperModifier) |
| 2598 | Diag(Tok, diag::warn_pragma_expected_colon) << ")"; |
| 2599 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2600 | StopBeforeMatch); |
| 2601 | } |
| 2602 | // Consume ':'. |
| 2603 | if (Tok.is(tok::colon)) |
| 2604 | ConsumeToken(); |
| 2605 | } |
| 2606 | } |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 2607 | } else if (Kind == OMPC_allocate) { |
| 2608 | // Handle optional allocator expression followed by colon delimiter. |
| 2609 | ColonProtectionRAIIObject ColonRAII(*this); |
| 2610 | TentativeParsingAction TPA(*this); |
| 2611 | ExprResult Tail = |
| 2612 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
| 2613 | Tail = Actions.ActOnFinishFullExpr(Tail.get(), T.getOpenLocation(), |
| 2614 | /*DiscardedValue=*/false); |
| 2615 | if (Tail.isUsable()) { |
| 2616 | if (Tok.is(tok::colon)) { |
| 2617 | Data.TailExpr = Tail.get(); |
| 2618 | Data.ColonLoc = ConsumeToken(); |
| 2619 | TPA.Commit(); |
| 2620 | } else { |
| 2621 | // colon not found, no allocator specified, parse only list of |
| 2622 | // variables. |
| 2623 | TPA.Revert(); |
| 2624 | } |
| 2625 | } else { |
| 2626 | // Parsing was unsuccessfull, revert and skip to the end of clause or |
| 2627 | // directive. |
| 2628 | TPA.Revert(); |
| 2629 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2630 | StopBeforeMatch); |
| 2631 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2632 | } |
| 2633 | |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2634 | bool IsComma = |
| 2635 | (Kind != OMPC_reduction && Kind != OMPC_task_reduction && |
| 2636 | Kind != OMPC_in_reduction && Kind != OMPC_depend && Kind != OMPC_map) || |
| 2637 | (Kind == OMPC_reduction && !InvalidReductionId) || |
Kelvin Li | da6bc70 | 2018-11-21 19:38:53 +0000 | [diff] [blame] | 2638 | (Kind == OMPC_map && Data.MapType != OMPC_MAP_unknown) || |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2639 | (Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2640 | const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned); |
| 2641 | while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) && |
| 2642 | Tok.isNot(tok::annot_pragma_openmp_end))) { |
| 2643 | ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail); |
| 2644 | // Parse variable |
| 2645 | ExprResult VarExpr = |
| 2646 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2647 | if (VarExpr.isUsable()) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2648 | Vars.push_back(VarExpr.get()); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2649 | } else { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2650 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2651 | StopBeforeMatch); |
| 2652 | } |
| 2653 | // Skip ',' if any |
| 2654 | IsComma = Tok.is(tok::comma); |
| 2655 | if (IsComma) |
| 2656 | ConsumeToken(); |
| 2657 | else if (Tok.isNot(tok::r_paren) && |
| 2658 | Tok.isNot(tok::annot_pragma_openmp_end) && |
| 2659 | (!MayHaveTail || Tok.isNot(tok::colon))) |
| 2660 | Diag(Tok, diag::err_omp_expected_punc) |
| 2661 | << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush) |
| 2662 | : getOpenMPClauseName(Kind)) |
| 2663 | << (Kind == OMPC_flush); |
| 2664 | } |
| 2665 | |
| 2666 | // Parse ')' for linear clause with modifier. |
| 2667 | if (NeedRParenForLinear) |
| 2668 | LinearT.consumeClose(); |
| 2669 | |
| 2670 | // Parse ':' linear-step (or ':' alignment). |
| 2671 | const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon); |
| 2672 | if (MustHaveTail) { |
| 2673 | Data.ColonLoc = Tok.getLocation(); |
| 2674 | SourceLocation ELoc = ConsumeToken(); |
| 2675 | ExprResult Tail = ParseAssignmentExpression(); |
Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 2676 | Tail = |
| 2677 | Actions.ActOnFinishFullExpr(Tail.get(), ELoc, /*DiscardedValue*/ false); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2678 | if (Tail.isUsable()) |
| 2679 | Data.TailExpr = Tail.get(); |
| 2680 | else |
| 2681 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2682 | StopBeforeMatch); |
| 2683 | } |
| 2684 | |
| 2685 | // Parse ')'. |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 2686 | Data.RLoc = Tok.getLocation(); |
| 2687 | if (!T.consumeClose()) |
| 2688 | Data.RLoc = T.getCloseLocation(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2689 | return (Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown && |
| 2690 | Vars.empty()) || |
| 2691 | (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) || |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2692 | (MustHaveTail && !Data.TailExpr) || InvalidReductionId || |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2693 | IsInvalidMapperModifier; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2694 | } |
| 2695 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2696 | /// Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate', |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2697 | /// 'shared', 'copyin', 'copyprivate', 'flush', 'reduction', 'task_reduction' or |
| 2698 | /// 'in_reduction'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2699 | /// |
| 2700 | /// private-clause: |
| 2701 | /// 'private' '(' list ')' |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2702 | /// firstprivate-clause: |
| 2703 | /// 'firstprivate' '(' list ')' |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2704 | /// lastprivate-clause: |
| 2705 | /// 'lastprivate' '(' list ')' |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2706 | /// shared-clause: |
| 2707 | /// 'shared' '(' list ')' |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 2708 | /// linear-clause: |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 2709 | /// 'linear' '(' linear-list [ ':' linear-step ] ')' |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 2710 | /// aligned-clause: |
| 2711 | /// 'aligned' '(' list [ ':' alignment ] ')' |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2712 | /// reduction-clause: |
| 2713 | /// 'reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 2714 | /// task_reduction-clause: |
| 2715 | /// 'task_reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2716 | /// in_reduction-clause: |
| 2717 | /// 'in_reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2718 | /// copyprivate-clause: |
| 2719 | /// 'copyprivate' '(' list ')' |
| 2720 | /// flush-clause: |
| 2721 | /// 'flush' '(' list ')' |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 2722 | /// depend-clause: |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 2723 | /// 'depend' '(' in | out | inout : list | source ')' |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 2724 | /// map-clause: |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2725 | /// 'map' '(' [ [ always [,] ] [ close [,] ] |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2726 | /// [ mapper '(' mapper-identifier ')' [,] ] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 2727 | /// to | from | tofrom | alloc | release | delete ':' ] list ')'; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 2728 | /// to-clause: |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2729 | /// 'to' '(' [ mapper '(' mapper-identifier ')' ':' ] list ')' |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 2730 | /// from-clause: |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 2731 | /// 'from' '(' [ mapper '(' mapper-identifier ')' ':' ] list ')' |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 2732 | /// use_device_ptr-clause: |
| 2733 | /// 'use_device_ptr' '(' list ')' |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 2734 | /// is_device_ptr-clause: |
| 2735 | /// 'is_device_ptr' '(' list ')' |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 2736 | /// allocate-clause: |
| 2737 | /// 'allocate' '(' [ allocator ':' ] list ')' |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2738 | /// |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 2739 | /// For 'linear' clause linear-list may have the following forms: |
| 2740 | /// list |
| 2741 | /// modifier(list) |
| 2742 | /// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++). |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 2743 | OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2744 | OpenMPClauseKind Kind, |
| 2745 | bool ParseOnly) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2746 | SourceLocation Loc = Tok.getLocation(); |
| 2747 | SourceLocation LOpen = ConsumeToken(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2748 | SmallVector<Expr *, 4> Vars; |
| 2749 | OpenMPVarListDataTy Data; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 2750 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2751 | if (ParseOpenMPVarList(DKind, Kind, Vars, Data)) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2752 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2753 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2754 | if (ParseOnly) |
| 2755 | return nullptr; |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2756 | OMPVarListLocTy Locs(Loc, LOpen, Data.RLoc); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2757 | return Actions.ActOnOpenMPVarListClause( |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2758 | Kind, Vars, Data.TailExpr, Locs, Data.ColonLoc, |
| 2759 | Data.ReductionOrMapperIdScopeSpec, Data.ReductionOrMapperId, Data.DepKind, |
| 2760 | Data.LinKind, Data.MapTypeModifiers, Data.MapTypeModifiersLoc, |
| 2761 | Data.MapType, Data.IsMapTypeImplicit, Data.DepLinMapLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2762 | } |
| 2763 | |