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