blob: f5638773d9046e5d625482e49d2d773debc81c00 [file] [log] [blame]
Alexey Bataeva769e072013-03-22 06:34:35 +00001//===--- ParseOpenMP.cpp - OpenMP directives parsing ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10/// \brief This file implements parsing of all OpenMP directives and clauses.
11///
12//===----------------------------------------------------------------------===//
13
Alexey Bataev9959db52014-05-06 10:08:46 +000014#include "clang/AST/ASTContext.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000015#include "clang/AST/StmtOpenMP.h"
Alexey Bataeva769e072013-03-22 06:34:35 +000016#include "clang/Parse/ParseDiagnostic.h"
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000017#include "clang/Parse/Parser.h"
Vassil Vassilev11ad3392017-03-23 15:11:07 +000018#include "clang/Parse/RAIIObjectsForParser.h"
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000019#include "clang/Sema/Scope.h"
20#include "llvm/ADT/PointerIntPair.h"
Michael Wong65f367f2015-07-21 13:44:28 +000021
Alexey Bataeva769e072013-03-22 06:34:35 +000022using namespace clang;
23
24//===----------------------------------------------------------------------===//
25// OpenMP declarative directives.
26//===----------------------------------------------------------------------===//
27
Dmitry Polukhin82478332016-02-13 06:53:38 +000028namespace {
29enum OpenMPDirectiveKindEx {
30 OMPD_cancellation = OMPD_unknown + 1,
31 OMPD_data,
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000032 OMPD_declare,
Dmitry Polukhin0b0da292016-04-06 11:38:59 +000033 OMPD_end,
34 OMPD_end_declare,
Dmitry Polukhin82478332016-02-13 06:53:38 +000035 OMPD_enter,
36 OMPD_exit,
37 OMPD_point,
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000038 OMPD_reduction,
Dmitry Polukhin82478332016-02-13 06:53:38 +000039 OMPD_target_enter,
Samuel Antao686c70c2016-05-26 17:30:50 +000040 OMPD_target_exit,
41 OMPD_update,
Kelvin Li579e41c2016-11-30 23:51:03 +000042 OMPD_distribute_parallel,
Kelvin Li80e8f562016-12-29 22:16:30 +000043 OMPD_teams_distribute_parallel,
44 OMPD_target_teams_distribute_parallel
Dmitry Polukhin82478332016-02-13 06:53:38 +000045};
Dmitry Polukhind69b5052016-05-09 14:59:13 +000046
47class ThreadprivateListParserHelper final {
48 SmallVector<Expr *, 4> Identifiers;
49 Parser *P;
50
51public:
52 ThreadprivateListParserHelper(Parser *P) : P(P) {}
53 void operator()(CXXScopeSpec &SS, DeclarationNameInfo NameInfo) {
54 ExprResult Res =
55 P->getActions().ActOnOpenMPIdExpression(P->getCurScope(), SS, NameInfo);
56 if (Res.isUsable())
57 Identifiers.push_back(Res.get());
58 }
59 llvm::ArrayRef<Expr *> getIdentifiers() const { return Identifiers; }
60};
Dmitry Polukhin82478332016-02-13 06:53:38 +000061} // namespace
62
63// Map token string to extended OMP token kind that are
64// OpenMPDirectiveKind + OpenMPDirectiveKindEx.
65static unsigned getOpenMPDirectiveKindEx(StringRef S) {
66 auto DKind = getOpenMPDirectiveKind(S);
67 if (DKind != OMPD_unknown)
68 return DKind;
69
70 return llvm::StringSwitch<unsigned>(S)
71 .Case("cancellation", OMPD_cancellation)
72 .Case("data", OMPD_data)
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000073 .Case("declare", OMPD_declare)
Dmitry Polukhin0b0da292016-04-06 11:38:59 +000074 .Case("end", OMPD_end)
Dmitry Polukhin82478332016-02-13 06:53:38 +000075 .Case("enter", OMPD_enter)
76 .Case("exit", OMPD_exit)
77 .Case("point", OMPD_point)
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000078 .Case("reduction", OMPD_reduction)
Samuel Antao686c70c2016-05-26 17:30:50 +000079 .Case("update", OMPD_update)
Dmitry Polukhin82478332016-02-13 06:53:38 +000080 .Default(OMPD_unknown);
81}
82
Alexey Bataev4acb8592014-07-07 13:01:15 +000083static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
Alexander Musmanf82886e2014-09-18 05:12:34 +000084 // Array of foldings: F[i][0] F[i][1] ===> F[i][2].
85 // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd
86 // TODO: add other combined directives in topological order.
Dmitry Polukhin82478332016-02-13 06:53:38 +000087 static const unsigned F[][3] = {
88 { OMPD_cancellation, OMPD_point, OMPD_cancellation_point },
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000089 { OMPD_declare, OMPD_reduction, OMPD_declare_reduction },
Alexey Bataev587e1de2016-03-30 10:43:55 +000090 { OMPD_declare, OMPD_simd, OMPD_declare_simd },
Dmitry Polukhin0b0da292016-04-06 11:38:59 +000091 { OMPD_declare, OMPD_target, OMPD_declare_target },
Carlo Bertolli9925f152016-06-27 14:55:37 +000092 { OMPD_distribute, OMPD_parallel, OMPD_distribute_parallel },
93 { OMPD_distribute_parallel, OMPD_for, OMPD_distribute_parallel_for },
Kelvin Li4a39add2016-07-05 05:00:15 +000094 { OMPD_distribute_parallel_for, OMPD_simd,
95 OMPD_distribute_parallel_for_simd },
Kelvin Li787f3fc2016-07-06 04:45:38 +000096 { OMPD_distribute, OMPD_simd, OMPD_distribute_simd },
Dmitry Polukhin0b0da292016-04-06 11:38:59 +000097 { OMPD_end, OMPD_declare, OMPD_end_declare },
98 { OMPD_end_declare, OMPD_target, OMPD_end_declare_target },
Dmitry Polukhin82478332016-02-13 06:53:38 +000099 { OMPD_target, OMPD_data, OMPD_target_data },
100 { OMPD_target, OMPD_enter, OMPD_target_enter },
101 { OMPD_target, OMPD_exit, OMPD_target_exit },
Samuel Antao686c70c2016-05-26 17:30:50 +0000102 { OMPD_target, OMPD_update, OMPD_target_update },
Dmitry Polukhin82478332016-02-13 06:53:38 +0000103 { OMPD_target_enter, OMPD_data, OMPD_target_enter_data },
104 { OMPD_target_exit, OMPD_data, OMPD_target_exit_data },
105 { OMPD_for, OMPD_simd, OMPD_for_simd },
106 { OMPD_parallel, OMPD_for, OMPD_parallel_for },
107 { OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd },
108 { OMPD_parallel, OMPD_sections, OMPD_parallel_sections },
109 { OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd },
110 { OMPD_target, OMPD_parallel, OMPD_target_parallel },
Kelvin Li986330c2016-07-20 22:57:10 +0000111 { OMPD_target, OMPD_simd, OMPD_target_simd },
Kelvin Lia579b912016-07-14 02:54:56 +0000112 { OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for },
Kelvin Li02532872016-08-05 14:37:37 +0000113 { OMPD_target_parallel_for, OMPD_simd, OMPD_target_parallel_for_simd },
Kelvin Li4e325f72016-10-25 12:50:55 +0000114 { OMPD_teams, OMPD_distribute, OMPD_teams_distribute },
Kelvin Li579e41c2016-11-30 23:51:03 +0000115 { OMPD_teams_distribute, OMPD_simd, OMPD_teams_distribute_simd },
116 { OMPD_teams_distribute, OMPD_parallel, OMPD_teams_distribute_parallel },
117 { OMPD_teams_distribute_parallel, OMPD_for, OMPD_teams_distribute_parallel_for },
Kelvin Libf594a52016-12-17 05:48:59 +0000118 { OMPD_teams_distribute_parallel_for, OMPD_simd, OMPD_teams_distribute_parallel_for_simd },
Kelvin Li83c451e2016-12-25 04:52:54 +0000119 { OMPD_target, OMPD_teams, OMPD_target_teams },
Kelvin Li80e8f562016-12-29 22:16:30 +0000120 { OMPD_target_teams, OMPD_distribute, OMPD_target_teams_distribute },
121 { OMPD_target_teams_distribute, OMPD_parallel, OMPD_target_teams_distribute_parallel },
Kelvin Lida681182017-01-10 18:08:18 +0000122 { OMPD_target_teams_distribute, OMPD_simd, OMPD_target_teams_distribute_simd },
Kelvin Li1851df52017-01-03 05:23:48 +0000123 { OMPD_target_teams_distribute_parallel, OMPD_for, OMPD_target_teams_distribute_parallel_for },
124 { OMPD_target_teams_distribute_parallel_for, OMPD_simd, OMPD_target_teams_distribute_parallel_for_simd }
Dmitry Polukhin82478332016-02-13 06:53:38 +0000125 };
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000126 enum { CancellationPoint = 0, DeclareReduction = 1, TargetData = 2 };
Alexey Bataev4acb8592014-07-07 13:01:15 +0000127 auto Tok = P.getCurToken();
Dmitry Polukhin82478332016-02-13 06:53:38 +0000128 unsigned DKind =
Alexey Bataev4acb8592014-07-07 13:01:15 +0000129 Tok.isAnnotation()
Dmitry Polukhin82478332016-02-13 06:53:38 +0000130 ? static_cast<unsigned>(OMPD_unknown)
131 : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok));
132 if (DKind == OMPD_unknown)
133 return OMPD_unknown;
Michael Wong65f367f2015-07-21 13:44:28 +0000134
Alexander Musmanf82886e2014-09-18 05:12:34 +0000135 for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) {
Dmitry Polukhin82478332016-02-13 06:53:38 +0000136 if (DKind != F[i][0])
137 continue;
Michael Wong65f367f2015-07-21 13:44:28 +0000138
Dmitry Polukhin82478332016-02-13 06:53:38 +0000139 Tok = P.getPreprocessor().LookAhead(0);
140 unsigned SDKind =
141 Tok.isAnnotation()
142 ? static_cast<unsigned>(OMPD_unknown)
143 : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok));
144 if (SDKind == OMPD_unknown)
145 continue;
Michael Wong65f367f2015-07-21 13:44:28 +0000146
Dmitry Polukhin82478332016-02-13 06:53:38 +0000147 if (SDKind == F[i][1]) {
148 P.ConsumeToken();
149 DKind = F[i][2];
Alexey Bataev4acb8592014-07-07 13:01:15 +0000150 }
151 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000152 return DKind < OMPD_unknown ? static_cast<OpenMPDirectiveKind>(DKind)
153 : OMPD_unknown;
154}
155
156static DeclarationName parseOpenMPReductionId(Parser &P) {
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000157 Token Tok = P.getCurToken();
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000158 Sema &Actions = P.getActions();
159 OverloadedOperatorKind OOK = OO_None;
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000160 // Allow to use 'operator' keyword for C++ operators
161 bool WithOperator = false;
162 if (Tok.is(tok::kw_operator)) {
163 P.ConsumeToken();
164 Tok = P.getCurToken();
165 WithOperator = true;
166 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000167 switch (Tok.getKind()) {
168 case tok::plus: // '+'
169 OOK = OO_Plus;
170 break;
171 case tok::minus: // '-'
172 OOK = OO_Minus;
173 break;
174 case tok::star: // '*'
175 OOK = OO_Star;
176 break;
177 case tok::amp: // '&'
178 OOK = OO_Amp;
179 break;
180 case tok::pipe: // '|'
181 OOK = OO_Pipe;
182 break;
183 case tok::caret: // '^'
184 OOK = OO_Caret;
185 break;
186 case tok::ampamp: // '&&'
187 OOK = OO_AmpAmp;
188 break;
189 case tok::pipepipe: // '||'
190 OOK = OO_PipePipe;
191 break;
192 case tok::identifier: // identifier
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000193 if (!WithOperator)
194 break;
Galina Kistanova474f2ce2017-06-01 21:26:38 +0000195 LLVM_FALLTHROUGH;
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000196 default:
197 P.Diag(Tok.getLocation(), diag::err_omp_expected_reduction_identifier);
198 P.SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
199 Parser::StopBeforeMatch);
200 return DeclarationName();
201 }
202 P.ConsumeToken();
203 auto &DeclNames = Actions.getASTContext().DeclarationNames;
204 return OOK == OO_None ? DeclNames.getIdentifier(Tok.getIdentifierInfo())
205 : DeclNames.getCXXOperatorName(OOK);
206}
207
208/// \brief Parse 'omp declare reduction' construct.
209///
210/// declare-reduction-directive:
211/// annot_pragma_openmp 'declare' 'reduction'
212/// '(' <reduction_id> ':' <type> {',' <type>} ':' <expression> ')'
213/// ['initializer' '(' ('omp_priv' '=' <expression>)|<function_call> ')']
214/// annot_pragma_openmp_end
215/// <reduction_id> is either a base language identifier or one of the following
216/// operators: '+', '-', '*', '&', '|', '^', '&&' and '||'.
217///
218Parser::DeclGroupPtrTy
219Parser::ParseOpenMPDeclareReductionDirective(AccessSpecifier AS) {
220 // Parse '('.
221 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
222 if (T.expectAndConsume(diag::err_expected_lparen_after,
223 getOpenMPDirectiveName(OMPD_declare_reduction))) {
224 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
225 return DeclGroupPtrTy();
226 }
227
228 DeclarationName Name = parseOpenMPReductionId(*this);
229 if (Name.isEmpty() && Tok.is(tok::annot_pragma_openmp_end))
230 return DeclGroupPtrTy();
231
232 // Consume ':'.
233 bool IsCorrect = !ExpectAndConsume(tok::colon);
234
235 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
236 return DeclGroupPtrTy();
237
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000238 IsCorrect = IsCorrect && !Name.isEmpty();
239
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000240 if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) {
241 Diag(Tok.getLocation(), diag::err_expected_type);
242 IsCorrect = false;
243 }
244
245 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
246 return DeclGroupPtrTy();
247
248 SmallVector<std::pair<QualType, SourceLocation>, 8> ReductionTypes;
249 // Parse list of types until ':' token.
250 do {
251 ColonProtectionRAIIObject ColonRAII(*this);
252 SourceRange Range;
253 TypeResult TR = ParseTypeName(&Range, Declarator::PrototypeContext, AS);
254 if (TR.isUsable()) {
255 auto ReductionType =
256 Actions.ActOnOpenMPDeclareReductionType(Range.getBegin(), TR);
257 if (!ReductionType.isNull()) {
258 ReductionTypes.push_back(
259 std::make_pair(ReductionType, Range.getBegin()));
260 }
261 } else {
262 SkipUntil(tok::comma, tok::colon, tok::annot_pragma_openmp_end,
263 StopBeforeMatch);
264 }
265
266 if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end))
267 break;
268
269 // Consume ','.
270 if (ExpectAndConsume(tok::comma)) {
271 IsCorrect = false;
272 if (Tok.is(tok::annot_pragma_openmp_end)) {
273 Diag(Tok.getLocation(), diag::err_expected_type);
274 return DeclGroupPtrTy();
275 }
276 }
277 } while (Tok.isNot(tok::annot_pragma_openmp_end));
278
279 if (ReductionTypes.empty()) {
280 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
281 return DeclGroupPtrTy();
282 }
283
284 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
285 return DeclGroupPtrTy();
286
287 // Consume ':'.
288 if (ExpectAndConsume(tok::colon))
289 IsCorrect = false;
290
291 if (Tok.is(tok::annot_pragma_openmp_end)) {
292 Diag(Tok.getLocation(), diag::err_expected_expression);
293 return DeclGroupPtrTy();
294 }
295
296 DeclGroupPtrTy DRD = Actions.ActOnOpenMPDeclareReductionDirectiveStart(
297 getCurScope(), Actions.getCurLexicalContext(), Name, ReductionTypes, AS);
298
299 // Parse <combiner> expression and then parse initializer if any for each
300 // correct type.
301 unsigned I = 0, E = ReductionTypes.size();
302 for (auto *D : DRD.get()) {
303 TentativeParsingAction TPA(*this);
304 ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope |
Momchil Velikov57c681f2017-08-10 15:43:06 +0000305 Scope::CompoundStmtScope |
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000306 Scope::OpenMPDirectiveScope);
307 // Parse <combiner> expression.
308 Actions.ActOnOpenMPDeclareReductionCombinerStart(getCurScope(), D);
309 ExprResult CombinerResult =
310 Actions.ActOnFinishFullExpr(ParseAssignmentExpression().get(),
311 D->getLocation(), /*DiscardedValue=*/true);
312 Actions.ActOnOpenMPDeclareReductionCombinerEnd(D, CombinerResult.get());
313
314 if (CombinerResult.isInvalid() && Tok.isNot(tok::r_paren) &&
315 Tok.isNot(tok::annot_pragma_openmp_end)) {
316 TPA.Commit();
317 IsCorrect = false;
318 break;
319 }
320 IsCorrect = !T.consumeClose() && IsCorrect && CombinerResult.isUsable();
321 ExprResult InitializerResult;
322 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
323 // Parse <initializer> expression.
324 if (Tok.is(tok::identifier) &&
325 Tok.getIdentifierInfo()->isStr("initializer"))
326 ConsumeToken();
327 else {
328 Diag(Tok.getLocation(), diag::err_expected) << "'initializer'";
329 TPA.Commit();
330 IsCorrect = false;
331 break;
332 }
333 // Parse '('.
334 BalancedDelimiterTracker T(*this, tok::l_paren,
335 tok::annot_pragma_openmp_end);
336 IsCorrect =
337 !T.expectAndConsume(diag::err_expected_lparen_after, "initializer") &&
338 IsCorrect;
339 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
340 ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope |
Momchil Velikov57c681f2017-08-10 15:43:06 +0000341 Scope::CompoundStmtScope |
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000342 Scope::OpenMPDirectiveScope);
343 // Parse expression.
344 Actions.ActOnOpenMPDeclareReductionInitializerStart(getCurScope(), D);
345 InitializerResult = Actions.ActOnFinishFullExpr(
346 ParseAssignmentExpression().get(), D->getLocation(),
347 /*DiscardedValue=*/true);
348 Actions.ActOnOpenMPDeclareReductionInitializerEnd(
349 D, InitializerResult.get());
350 if (InitializerResult.isInvalid() && Tok.isNot(tok::r_paren) &&
351 Tok.isNot(tok::annot_pragma_openmp_end)) {
352 TPA.Commit();
353 IsCorrect = false;
354 break;
355 }
356 IsCorrect =
357 !T.consumeClose() && IsCorrect && !InitializerResult.isInvalid();
358 }
359 }
360
361 ++I;
362 // Revert parsing if not the last type, otherwise accept it, we're done with
363 // parsing.
364 if (I != E)
365 TPA.Revert();
366 else
367 TPA.Commit();
368 }
369 return Actions.ActOnOpenMPDeclareReductionDirectiveEnd(getCurScope(), DRD,
370 IsCorrect);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000371}
372
Alexey Bataev2af33e32016-04-07 12:45:37 +0000373namespace {
374/// RAII that recreates function context for correct parsing of clauses of
375/// 'declare simd' construct.
376/// OpenMP, 2.8.2 declare simd Construct
377/// The expressions appearing in the clauses of this directive are evaluated in
378/// the scope of the arguments of the function declaration or definition.
379class FNContextRAII final {
380 Parser &P;
381 Sema::CXXThisScopeRAII *ThisScope;
382 Parser::ParseScope *TempScope;
383 Parser::ParseScope *FnScope;
384 bool HasTemplateScope = false;
385 bool HasFunScope = false;
386 FNContextRAII() = delete;
387 FNContextRAII(const FNContextRAII &) = delete;
388 FNContextRAII &operator=(const FNContextRAII &) = delete;
389
390public:
391 FNContextRAII(Parser &P, Parser::DeclGroupPtrTy Ptr) : P(P) {
392 Decl *D = *Ptr.get().begin();
393 NamedDecl *ND = dyn_cast<NamedDecl>(D);
394 RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext());
395 Sema &Actions = P.getActions();
396
397 // Allow 'this' within late-parsed attributes.
398 ThisScope = new Sema::CXXThisScopeRAII(Actions, RD, /*TypeQuals=*/0,
399 ND && ND->isCXXInstanceMember());
400
401 // If the Decl is templatized, add template parameters to scope.
402 HasTemplateScope = D->isTemplateDecl();
403 TempScope =
404 new Parser::ParseScope(&P, Scope::TemplateParamScope, HasTemplateScope);
405 if (HasTemplateScope)
406 Actions.ActOnReenterTemplateScope(Actions.getCurScope(), D);
407
408 // If the Decl is on a function, add function parameters to the scope.
409 HasFunScope = D->isFunctionOrFunctionTemplate();
Momchil Velikov57c681f2017-08-10 15:43:06 +0000410 FnScope = new Parser::ParseScope(
411 &P, Scope::FnScope | Scope::DeclScope | Scope::CompoundStmtScope,
412 HasFunScope);
Alexey Bataev2af33e32016-04-07 12:45:37 +0000413 if (HasFunScope)
414 Actions.ActOnReenterFunctionContext(Actions.getCurScope(), D);
415 }
416 ~FNContextRAII() {
417 if (HasFunScope) {
418 P.getActions().ActOnExitFunctionContext();
419 FnScope->Exit(); // Pop scope, and remove Decls from IdResolver
420 }
421 if (HasTemplateScope)
422 TempScope->Exit();
423 delete FnScope;
424 delete TempScope;
425 delete ThisScope;
426 }
427};
428} // namespace
429
Alexey Bataevd93d3762016-04-12 09:35:56 +0000430/// Parses clauses for 'declare simd' directive.
431/// clause:
432/// 'inbranch' | 'notinbranch'
433/// 'simdlen' '(' <expr> ')'
434/// { 'uniform' '(' <argument_list> ')' }
435/// { 'aligned '(' <argument_list> [ ':' <alignment> ] ')' }
Alexey Bataevecba70f2016-04-12 11:02:11 +0000436/// { 'linear '(' <argument_list> [ ':' <step> ] ')' }
437static bool parseDeclareSimdClauses(
438 Parser &P, OMPDeclareSimdDeclAttr::BranchStateTy &BS, ExprResult &SimdLen,
439 SmallVectorImpl<Expr *> &Uniforms, SmallVectorImpl<Expr *> &Aligneds,
440 SmallVectorImpl<Expr *> &Alignments, SmallVectorImpl<Expr *> &Linears,
441 SmallVectorImpl<unsigned> &LinModifiers, SmallVectorImpl<Expr *> &Steps) {
Alexey Bataevd93d3762016-04-12 09:35:56 +0000442 SourceRange BSRange;
443 const Token &Tok = P.getCurToken();
444 bool IsError = false;
445 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
446 if (Tok.isNot(tok::identifier))
447 break;
448 OMPDeclareSimdDeclAttr::BranchStateTy Out;
449 IdentifierInfo *II = Tok.getIdentifierInfo();
450 StringRef ClauseName = II->getName();
451 // Parse 'inranch|notinbranch' clauses.
452 if (OMPDeclareSimdDeclAttr::ConvertStrToBranchStateTy(ClauseName, Out)) {
453 if (BS != OMPDeclareSimdDeclAttr::BS_Undefined && BS != Out) {
454 P.Diag(Tok, diag::err_omp_declare_simd_inbranch_notinbranch)
455 << ClauseName
456 << OMPDeclareSimdDeclAttr::ConvertBranchStateTyToStr(BS) << BSRange;
457 IsError = true;
458 }
459 BS = Out;
460 BSRange = SourceRange(Tok.getLocation(), Tok.getEndLoc());
461 P.ConsumeToken();
462 } else if (ClauseName.equals("simdlen")) {
463 if (SimdLen.isUsable()) {
464 P.Diag(Tok, diag::err_omp_more_one_clause)
465 << getOpenMPDirectiveName(OMPD_declare_simd) << ClauseName << 0;
466 IsError = true;
467 }
468 P.ConsumeToken();
469 SourceLocation RLoc;
470 SimdLen = P.ParseOpenMPParensExpr(ClauseName, RLoc);
471 if (SimdLen.isInvalid())
472 IsError = true;
473 } else {
474 OpenMPClauseKind CKind = getOpenMPClauseKind(ClauseName);
Alexey Bataevecba70f2016-04-12 11:02:11 +0000475 if (CKind == OMPC_uniform || CKind == OMPC_aligned ||
476 CKind == OMPC_linear) {
Alexey Bataevd93d3762016-04-12 09:35:56 +0000477 Parser::OpenMPVarListDataTy Data;
478 auto *Vars = &Uniforms;
Alexey Bataevecba70f2016-04-12 11:02:11 +0000479 if (CKind == OMPC_aligned)
Alexey Bataevd93d3762016-04-12 09:35:56 +0000480 Vars = &Aligneds;
Alexey Bataevecba70f2016-04-12 11:02:11 +0000481 else if (CKind == OMPC_linear)
482 Vars = &Linears;
Alexey Bataevd93d3762016-04-12 09:35:56 +0000483
484 P.ConsumeToken();
485 if (P.ParseOpenMPVarList(OMPD_declare_simd,
486 getOpenMPClauseKind(ClauseName), *Vars, Data))
487 IsError = true;
488 if (CKind == OMPC_aligned)
489 Alignments.append(Aligneds.size() - Alignments.size(), Data.TailExpr);
Alexey Bataevecba70f2016-04-12 11:02:11 +0000490 else if (CKind == OMPC_linear) {
491 if (P.getActions().CheckOpenMPLinearModifier(Data.LinKind,
492 Data.DepLinMapLoc))
493 Data.LinKind = OMPC_LINEAR_val;
494 LinModifiers.append(Linears.size() - LinModifiers.size(),
495 Data.LinKind);
496 Steps.append(Linears.size() - Steps.size(), Data.TailExpr);
497 }
Alexey Bataevd93d3762016-04-12 09:35:56 +0000498 } else
499 // TODO: add parsing of other clauses.
500 break;
501 }
502 // Skip ',' if any.
503 if (Tok.is(tok::comma))
504 P.ConsumeToken();
505 }
506 return IsError;
507}
508
Alexey Bataev2af33e32016-04-07 12:45:37 +0000509/// Parse clauses for '#pragma omp declare simd'.
510Parser::DeclGroupPtrTy
511Parser::ParseOMPDeclareSimdClauses(Parser::DeclGroupPtrTy Ptr,
512 CachedTokens &Toks, SourceLocation Loc) {
513 PP.EnterToken(Tok);
514 PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
515 // Consume the previously pushed token.
516 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
517
518 FNContextRAII FnContext(*this, Ptr);
519 OMPDeclareSimdDeclAttr::BranchStateTy BS =
520 OMPDeclareSimdDeclAttr::BS_Undefined;
521 ExprResult Simdlen;
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000522 SmallVector<Expr *, 4> Uniforms;
Alexey Bataevd93d3762016-04-12 09:35:56 +0000523 SmallVector<Expr *, 4> Aligneds;
524 SmallVector<Expr *, 4> Alignments;
Alexey Bataevecba70f2016-04-12 11:02:11 +0000525 SmallVector<Expr *, 4> Linears;
526 SmallVector<unsigned, 4> LinModifiers;
527 SmallVector<Expr *, 4> Steps;
528 bool IsError =
529 parseDeclareSimdClauses(*this, BS, Simdlen, Uniforms, Aligneds,
530 Alignments, Linears, LinModifiers, Steps);
Alexey Bataev2af33e32016-04-07 12:45:37 +0000531 // Need to check for extra tokens.
532 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
533 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
534 << getOpenMPDirectiveName(OMPD_declare_simd);
535 while (Tok.isNot(tok::annot_pragma_openmp_end))
536 ConsumeAnyToken();
537 }
538 // Skip the last annot_pragma_openmp_end.
Richard Smithaf3b3252017-05-18 19:21:48 +0000539 SourceLocation EndLoc = ConsumeAnnotationToken();
Alexey Bataevd93d3762016-04-12 09:35:56 +0000540 if (!IsError) {
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000541 return Actions.ActOnOpenMPDeclareSimdDirective(
Alexey Bataevecba70f2016-04-12 11:02:11 +0000542 Ptr, BS, Simdlen.get(), Uniforms, Aligneds, Alignments, Linears,
543 LinModifiers, Steps, SourceRange(Loc, EndLoc));
Alexey Bataevd93d3762016-04-12 09:35:56 +0000544 }
Alexey Bataev2af33e32016-04-07 12:45:37 +0000545 return Ptr;
Alexey Bataev20dfd772016-04-04 10:12:15 +0000546}
547
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000548/// \brief Parsing of declarative OpenMP directives.
549///
550/// threadprivate-directive:
551/// annot_pragma_openmp 'threadprivate' simple-variable-list
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000552/// annot_pragma_openmp_end
Alexey Bataeva769e072013-03-22 06:34:35 +0000553///
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000554/// declare-reduction-directive:
555/// annot_pragma_openmp 'declare' 'reduction' [...]
556/// annot_pragma_openmp_end
557///
Alexey Bataev587e1de2016-03-30 10:43:55 +0000558/// declare-simd-directive:
559/// annot_pragma_openmp 'declare simd' {<clause> [,]}
560/// annot_pragma_openmp_end
561/// <function declaration/definition>
562///
563Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
564 AccessSpecifier &AS, ParsedAttributesWithRange &Attrs,
565 DeclSpec::TST TagType, Decl *Tag) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000566 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +0000567 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataeva769e072013-03-22 06:34:35 +0000568
Richard Smithaf3b3252017-05-18 19:21:48 +0000569 SourceLocation Loc = ConsumeAnnotationToken();
Alexey Bataev4acb8592014-07-07 13:01:15 +0000570 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000571
572 switch (DKind) {
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000573 case OMPD_threadprivate: {
Alexey Bataeva769e072013-03-22 06:34:35 +0000574 ConsumeToken();
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000575 ThreadprivateListParserHelper Helper(this);
576 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Helper, true)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000577 // The last seen token is annot_pragma_openmp_end - need to check for
578 // extra tokens.
579 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
580 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000581 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000582 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataeva769e072013-03-22 06:34:35 +0000583 }
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000584 // Skip the last annot_pragma_openmp_end.
Richard Smithaf3b3252017-05-18 19:21:48 +0000585 ConsumeAnnotationToken();
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000586 return Actions.ActOnOpenMPThreadprivateDirective(Loc,
587 Helper.getIdentifiers());
Alexey Bataeva769e072013-03-22 06:34:35 +0000588 }
589 break;
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000590 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000591 case OMPD_declare_reduction:
592 ConsumeToken();
593 if (auto Res = ParseOpenMPDeclareReductionDirective(AS)) {
594 // The last seen token is annot_pragma_openmp_end - need to check for
595 // extra tokens.
596 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
597 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
598 << getOpenMPDirectiveName(OMPD_declare_reduction);
599 while (Tok.isNot(tok::annot_pragma_openmp_end))
600 ConsumeAnyToken();
601 }
602 // Skip the last annot_pragma_openmp_end.
Richard Smithaf3b3252017-05-18 19:21:48 +0000603 ConsumeAnnotationToken();
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000604 return Res;
605 }
606 break;
Alexey Bataev587e1de2016-03-30 10:43:55 +0000607 case OMPD_declare_simd: {
608 // The syntax is:
609 // { #pragma omp declare simd }
610 // <function-declaration-or-definition>
611 //
Alexey Bataev587e1de2016-03-30 10:43:55 +0000612 ConsumeToken();
Alexey Bataev2af33e32016-04-07 12:45:37 +0000613 CachedTokens Toks;
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000614 while(Tok.isNot(tok::annot_pragma_openmp_end)) {
615 Toks.push_back(Tok);
616 ConsumeAnyToken();
617 }
618 Toks.push_back(Tok);
619 ConsumeAnyToken();
Alexey Bataev587e1de2016-03-30 10:43:55 +0000620
621 DeclGroupPtrTy Ptr;
Alexey Bataev20dfd772016-04-04 10:12:15 +0000622 if (Tok.is(tok::annot_pragma_openmp))
Alexey Bataev587e1de2016-03-30 10:43:55 +0000623 Ptr = ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs, TagType, Tag);
Alexey Bataev20dfd772016-04-04 10:12:15 +0000624 else if (Tok.isNot(tok::r_brace) && !isEofOrEom()) {
Alexey Bataev587e1de2016-03-30 10:43:55 +0000625 // Here we expect to see some function declaration.
626 if (AS == AS_none) {
627 assert(TagType == DeclSpec::TST_unspecified);
628 MaybeParseCXX11Attributes(Attrs);
Alexey Bataev587e1de2016-03-30 10:43:55 +0000629 ParsingDeclSpec PDS(*this);
630 Ptr = ParseExternalDeclaration(Attrs, &PDS);
631 } else {
632 Ptr =
633 ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag);
634 }
635 }
636 if (!Ptr) {
637 Diag(Loc, diag::err_omp_decl_in_declare_simd);
638 return DeclGroupPtrTy();
639 }
Alexey Bataev2af33e32016-04-07 12:45:37 +0000640 return ParseOMPDeclareSimdClauses(Ptr, Toks, Loc);
Alexey Bataev587e1de2016-03-30 10:43:55 +0000641 }
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000642 case OMPD_declare_target: {
643 SourceLocation DTLoc = ConsumeAnyToken();
644 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000645 // OpenMP 4.5 syntax with list of entities.
646 llvm::SmallSetVector<const NamedDecl*, 16> SameDirectiveDecls;
647 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
648 OMPDeclareTargetDeclAttr::MapTypeTy MT =
649 OMPDeclareTargetDeclAttr::MT_To;
650 if (Tok.is(tok::identifier)) {
651 IdentifierInfo *II = Tok.getIdentifierInfo();
652 StringRef ClauseName = II->getName();
653 // Parse 'to|link' clauses.
654 if (!OMPDeclareTargetDeclAttr::ConvertStrToMapTypeTy(ClauseName,
655 MT)) {
656 Diag(Tok, diag::err_omp_declare_target_unexpected_clause)
657 << ClauseName;
658 break;
659 }
660 ConsumeToken();
661 }
662 auto Callback = [this, MT, &SameDirectiveDecls](
663 CXXScopeSpec &SS, DeclarationNameInfo NameInfo) {
664 Actions.ActOnOpenMPDeclareTargetName(getCurScope(), SS, NameInfo, MT,
665 SameDirectiveDecls);
666 };
667 if (ParseOpenMPSimpleVarList(OMPD_declare_target, Callback, true))
668 break;
669
670 // Consume optional ','.
671 if (Tok.is(tok::comma))
672 ConsumeToken();
673 }
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000674 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000675 ConsumeAnyToken();
676 return DeclGroupPtrTy();
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000677 }
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000678
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000679 // Skip the last annot_pragma_openmp_end.
680 ConsumeAnyToken();
681
682 if (!Actions.ActOnStartOpenMPDeclareTargetDirective(DTLoc))
683 return DeclGroupPtrTy();
684
685 DKind = ParseOpenMPDirectiveKind(*this);
686 while (DKind != OMPD_end_declare_target && DKind != OMPD_declare_target &&
687 Tok.isNot(tok::eof) && Tok.isNot(tok::r_brace)) {
688 ParsedAttributesWithRange attrs(AttrFactory);
689 MaybeParseCXX11Attributes(attrs);
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000690 ParseExternalDeclaration(attrs);
691 if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
692 TentativeParsingAction TPA(*this);
Richard Smithaf3b3252017-05-18 19:21:48 +0000693 ConsumeAnnotationToken();
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000694 DKind = ParseOpenMPDirectiveKind(*this);
695 if (DKind != OMPD_end_declare_target)
696 TPA.Revert();
697 else
698 TPA.Commit();
699 }
700 }
701
702 if (DKind == OMPD_end_declare_target) {
703 ConsumeAnyToken();
704 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
705 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
706 << getOpenMPDirectiveName(OMPD_end_declare_target);
707 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
708 }
709 // Skip the last annot_pragma_openmp_end.
710 ConsumeAnyToken();
711 } else {
712 Diag(Tok, diag::err_expected_end_declare_target);
713 Diag(DTLoc, diag::note_matching) << "'#pragma omp declare target'";
714 }
715 Actions.ActOnFinishOpenMPDeclareTargetDirective();
716 return DeclGroupPtrTy();
717 }
Alexey Bataeva769e072013-03-22 06:34:35 +0000718 case OMPD_unknown:
719 Diag(Tok, diag::err_omp_unknown_directive);
720 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000721 case OMPD_parallel:
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000722 case OMPD_simd:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000723 case OMPD_task:
Alexey Bataev68446b72014-07-18 07:47:19 +0000724 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000725 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +0000726 case OMPD_taskwait:
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000727 case OMPD_taskgroup:
Alexey Bataev6125da92014-07-21 11:26:11 +0000728 case OMPD_flush:
Alexey Bataevf29276e2014-06-18 04:14:57 +0000729 case OMPD_for:
Alexander Musmanf82886e2014-09-18 05:12:34 +0000730 case OMPD_for_simd:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000731 case OMPD_sections:
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000732 case OMPD_section:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000733 case OMPD_single:
Alexander Musman80c22892014-07-17 08:54:58 +0000734 case OMPD_master:
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000735 case OMPD_ordered:
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000736 case OMPD_critical:
Alexey Bataev4acb8592014-07-07 13:01:15 +0000737 case OMPD_parallel_for:
Alexander Musmane4e893b2014-09-23 09:33:00 +0000738 case OMPD_parallel_for_simd:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000739 case OMPD_parallel_sections:
Alexey Bataev0162e452014-07-22 10:10:35 +0000740 case OMPD_atomic:
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000741 case OMPD_target:
Alexey Bataev13314bf2014-10-09 04:18:56 +0000742 case OMPD_teams:
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000743 case OMPD_cancellation_point:
Alexey Bataev80909872015-07-02 11:25:17 +0000744 case OMPD_cancel:
Samuel Antao5b0688e2015-07-22 16:02:46 +0000745 case OMPD_target_data:
Samuel Antaodf67fc42016-01-19 19:15:56 +0000746 case OMPD_target_enter_data:
Samuel Antao72590762016-01-19 20:04:50 +0000747 case OMPD_target_exit_data:
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000748 case OMPD_target_parallel:
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000749 case OMPD_target_parallel_for:
Alexey Bataev49f6e782015-12-01 04:18:41 +0000750 case OMPD_taskloop:
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000751 case OMPD_taskloop_simd:
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000752 case OMPD_distribute:
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000753 case OMPD_end_declare_target:
Samuel Antao686c70c2016-05-26 17:30:50 +0000754 case OMPD_target_update:
Carlo Bertolli9925f152016-06-27 14:55:37 +0000755 case OMPD_distribute_parallel_for:
Kelvin Li4a39add2016-07-05 05:00:15 +0000756 case OMPD_distribute_parallel_for_simd:
Kelvin Li787f3fc2016-07-06 04:45:38 +0000757 case OMPD_distribute_simd:
Kelvin Lia579b912016-07-14 02:54:56 +0000758 case OMPD_target_parallel_for_simd:
Kelvin Li986330c2016-07-20 22:57:10 +0000759 case OMPD_target_simd:
Kelvin Li02532872016-08-05 14:37:37 +0000760 case OMPD_teams_distribute:
Kelvin Li4e325f72016-10-25 12:50:55 +0000761 case OMPD_teams_distribute_simd:
Kelvin Li579e41c2016-11-30 23:51:03 +0000762 case OMPD_teams_distribute_parallel_for_simd:
Kelvin Li7ade93f2016-12-09 03:24:30 +0000763 case OMPD_teams_distribute_parallel_for:
Kelvin Libf594a52016-12-17 05:48:59 +0000764 case OMPD_target_teams:
Kelvin Li83c451e2016-12-25 04:52:54 +0000765 case OMPD_target_teams_distribute:
Kelvin Li80e8f562016-12-29 22:16:30 +0000766 case OMPD_target_teams_distribute_parallel_for:
Kelvin Li1851df52017-01-03 05:23:48 +0000767 case OMPD_target_teams_distribute_parallel_for_simd:
Kelvin Lida681182017-01-10 18:08:18 +0000768 case OMPD_target_teams_distribute_simd:
Alexey Bataeva769e072013-03-22 06:34:35 +0000769 Diag(Tok, diag::err_omp_unexpected_directive)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000770 << getOpenMPDirectiveName(DKind);
Alexey Bataeva769e072013-03-22 06:34:35 +0000771 break;
772 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000773 while (Tok.isNot(tok::annot_pragma_openmp_end))
774 ConsumeAnyToken();
775 ConsumeAnyToken();
David Blaikie0403cb12016-01-15 23:43:25 +0000776 return nullptr;
Alexey Bataeva769e072013-03-22 06:34:35 +0000777}
778
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000779/// \brief Parsing of declarative or executable OpenMP directives.
780///
781/// threadprivate-directive:
782/// annot_pragma_openmp 'threadprivate' simple-variable-list
783/// annot_pragma_openmp_end
784///
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000785/// declare-reduction-directive:
786/// annot_pragma_openmp 'declare' 'reduction' '(' <reduction_id> ':'
787/// <type> {',' <type>} ':' <expression> ')' ['initializer' '('
788/// ('omp_priv' '=' <expression>|<function_call>) ')']
789/// annot_pragma_openmp_end
790///
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000791/// executable-directive:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000792/// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' |
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000793/// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] |
794/// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' |
Alexander Musmanf82886e2014-09-18 05:12:34 +0000795/// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' |
Michael Wong65f367f2015-07-21 13:44:28 +0000796/// 'for simd' | 'parallel for simd' | 'target' | 'target data' |
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000797/// 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' |
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000798/// 'distribute' | 'target enter data' | 'target exit data' |
Samuel Antao686c70c2016-05-26 17:30:50 +0000799/// 'target parallel' | 'target parallel for' |
Kelvin Li4a39add2016-07-05 05:00:15 +0000800/// 'target update' | 'distribute parallel for' |
Kelvin Lia579b912016-07-14 02:54:56 +0000801/// 'distribute paralle for simd' | 'distribute simd' |
Kelvin Li02532872016-08-05 14:37:37 +0000802/// 'target parallel for simd' | 'target simd' |
Kelvin Li579e41c2016-11-30 23:51:03 +0000803/// 'teams distribute' | 'teams distribute simd' |
Kelvin Li7ade93f2016-12-09 03:24:30 +0000804/// 'teams distribute parallel for simd' |
Kelvin Li80e8f562016-12-29 22:16:30 +0000805/// 'teams distribute parallel for' | 'target teams' |
806/// 'target teams distribute' |
Kelvin Li1851df52017-01-03 05:23:48 +0000807/// 'target teams distribute parallel for' |
Kelvin Lida681182017-01-10 18:08:18 +0000808/// 'target teams distribute parallel for simd' |
809/// 'target teams distribute simd' {clause}
Samuel Antao72590762016-01-19 20:04:50 +0000810/// annot_pragma_openmp_end
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000811///
Alexey Bataevc4fad652016-01-13 11:18:54 +0000812StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
Jonathan Roelofsce1db6d2017-03-14 17:29:33 +0000813 AllowedConstructsKind Allowed) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000814 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +0000815 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000816 SmallVector<OMPClause *, 5> Clauses;
Alexey Bataev4ca40ed2014-05-12 04:23:46 +0000817 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1>
Alexey Bataeva55ed262014-05-28 06:15:33 +0000818 FirstClauses(OMPC_unknown + 1);
Momchil Velikov57c681f2017-08-10 15:43:06 +0000819 unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope |
820 Scope::CompoundStmtScope | Scope::OpenMPDirectiveScope;
Richard Smithaf3b3252017-05-18 19:21:48 +0000821 SourceLocation Loc = ConsumeAnnotationToken(), EndLoc;
Alexey Bataev4acb8592014-07-07 13:01:15 +0000822 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000823 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
Alexey Bataev758e55e2013-09-06 18:03:48 +0000824 // Name of critical directive.
825 DeclarationNameInfo DirName;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000826 StmtResult Directive = StmtError();
Alexey Bataev68446b72014-07-18 07:47:19 +0000827 bool HasAssociatedStatement = true;
Alexey Bataev6125da92014-07-21 11:26:11 +0000828 bool FlushHasClause = false;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000829
830 switch (DKind) {
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000831 case OMPD_threadprivate: {
Alexey Bataevc4fad652016-01-13 11:18:54 +0000832 if (Allowed != ACK_Any) {
833 Diag(Tok, diag::err_omp_immediate_directive)
834 << getOpenMPDirectiveName(DKind) << 0;
835 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000836 ConsumeToken();
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000837 ThreadprivateListParserHelper Helper(this);
838 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Helper, false)) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000839 // The last seen token is annot_pragma_openmp_end - need to check for
840 // extra tokens.
841 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
842 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000843 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000844 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000845 }
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000846 DeclGroupPtrTy Res = Actions.ActOnOpenMPThreadprivateDirective(
847 Loc, Helper.getIdentifiers());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000848 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
849 }
Alp Tokerd751fa72013-12-18 19:10:49 +0000850 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000851 break;
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000852 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000853 case OMPD_declare_reduction:
854 ConsumeToken();
855 if (auto Res = ParseOpenMPDeclareReductionDirective(/*AS=*/AS_none)) {
856 // The last seen token is annot_pragma_openmp_end - need to check for
857 // extra tokens.
858 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
859 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
860 << getOpenMPDirectiveName(OMPD_declare_reduction);
861 while (Tok.isNot(tok::annot_pragma_openmp_end))
862 ConsumeAnyToken();
863 }
864 ConsumeAnyToken();
865 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
866 } else
867 SkipUntil(tok::annot_pragma_openmp_end);
868 break;
Alexey Bataev6125da92014-07-21 11:26:11 +0000869 case OMPD_flush:
870 if (PP.LookAhead(0).is(tok::l_paren)) {
871 FlushHasClause = true;
872 // Push copy of the current token back to stream to properly parse
873 // pseudo-clause OMPFlushClause.
874 PP.EnterToken(Tok);
875 }
Galina Kistanova474f2ce2017-06-01 21:26:38 +0000876 LLVM_FALLTHROUGH;
Alexey Bataev68446b72014-07-18 07:47:19 +0000877 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000878 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +0000879 case OMPD_taskwait:
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000880 case OMPD_cancellation_point:
Alexey Bataev80909872015-07-02 11:25:17 +0000881 case OMPD_cancel:
Samuel Antaodf67fc42016-01-19 19:15:56 +0000882 case OMPD_target_enter_data:
Samuel Antao72590762016-01-19 20:04:50 +0000883 case OMPD_target_exit_data:
Samuel Antao686c70c2016-05-26 17:30:50 +0000884 case OMPD_target_update:
Alexey Bataevc4fad652016-01-13 11:18:54 +0000885 if (Allowed == ACK_StatementsOpenMPNonStandalone) {
Alexey Bataev68446b72014-07-18 07:47:19 +0000886 Diag(Tok, diag::err_omp_immediate_directive)
Alexey Bataeveb482352015-12-18 05:05:56 +0000887 << getOpenMPDirectiveName(DKind) << 0;
Alexey Bataev68446b72014-07-18 07:47:19 +0000888 }
889 HasAssociatedStatement = false;
Alexey Bataev6125da92014-07-21 11:26:11 +0000890 // Fall through for further analysis.
Galina Kistanova474f2ce2017-06-01 21:26:38 +0000891 LLVM_FALLTHROUGH;
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000892 case OMPD_parallel:
Alexey Bataevf29276e2014-06-18 04:14:57 +0000893 case OMPD_simd:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000894 case OMPD_for:
Alexander Musmanf82886e2014-09-18 05:12:34 +0000895 case OMPD_for_simd:
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000896 case OMPD_sections:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000897 case OMPD_single:
Alexey Bataev4acb8592014-07-07 13:01:15 +0000898 case OMPD_section:
Alexander Musman80c22892014-07-17 08:54:58 +0000899 case OMPD_master:
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000900 case OMPD_critical:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000901 case OMPD_parallel_for:
Alexander Musmane4e893b2014-09-23 09:33:00 +0000902 case OMPD_parallel_for_simd:
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000903 case OMPD_parallel_sections:
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000904 case OMPD_task:
Alexey Bataev0162e452014-07-22 10:10:35 +0000905 case OMPD_ordered:
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000906 case OMPD_atomic:
Alexey Bataev13314bf2014-10-09 04:18:56 +0000907 case OMPD_target:
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000908 case OMPD_teams:
Michael Wong65f367f2015-07-21 13:44:28 +0000909 case OMPD_taskgroup:
Alexey Bataev49f6e782015-12-01 04:18:41 +0000910 case OMPD_target_data:
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000911 case OMPD_target_parallel:
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000912 case OMPD_target_parallel_for:
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000913 case OMPD_taskloop:
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000914 case OMPD_taskloop_simd:
Carlo Bertolli9925f152016-06-27 14:55:37 +0000915 case OMPD_distribute:
Kelvin Li4a39add2016-07-05 05:00:15 +0000916 case OMPD_distribute_parallel_for:
Kelvin Li787f3fc2016-07-06 04:45:38 +0000917 case OMPD_distribute_parallel_for_simd:
Kelvin Lia579b912016-07-14 02:54:56 +0000918 case OMPD_distribute_simd:
Kelvin Li986330c2016-07-20 22:57:10 +0000919 case OMPD_target_parallel_for_simd:
Kelvin Li02532872016-08-05 14:37:37 +0000920 case OMPD_target_simd:
Kelvin Li4e325f72016-10-25 12:50:55 +0000921 case OMPD_teams_distribute:
Kelvin Li579e41c2016-11-30 23:51:03 +0000922 case OMPD_teams_distribute_simd:
Kelvin Li7ade93f2016-12-09 03:24:30 +0000923 case OMPD_teams_distribute_parallel_for_simd:
Kelvin Libf594a52016-12-17 05:48:59 +0000924 case OMPD_teams_distribute_parallel_for:
Kelvin Li83c451e2016-12-25 04:52:54 +0000925 case OMPD_target_teams:
Kelvin Li80e8f562016-12-29 22:16:30 +0000926 case OMPD_target_teams_distribute:
Kelvin Li1851df52017-01-03 05:23:48 +0000927 case OMPD_target_teams_distribute_parallel_for:
Kelvin Lida681182017-01-10 18:08:18 +0000928 case OMPD_target_teams_distribute_parallel_for_simd:
929 case OMPD_target_teams_distribute_simd: {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000930 ConsumeToken();
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000931 // Parse directive name of the 'critical' directive if any.
932 if (DKind == OMPD_critical) {
933 BalancedDelimiterTracker T(*this, tok::l_paren,
934 tok::annot_pragma_openmp_end);
935 if (!T.consumeOpen()) {
936 if (Tok.isAnyIdentifier()) {
937 DirName =
938 DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation());
939 ConsumeAnyToken();
940 } else {
941 Diag(Tok, diag::err_omp_expected_identifier_for_critical);
942 }
943 T.consumeClose();
944 }
Alexey Bataev80909872015-07-02 11:25:17 +0000945 } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000946 CancelRegion = ParseOpenMPDirectiveKind(*this);
947 if (Tok.isNot(tok::annot_pragma_openmp_end))
948 ConsumeToken();
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000949 }
Alexey Bataev758e55e2013-09-06 18:03:48 +0000950
Alexey Bataevf29276e2014-06-18 04:14:57 +0000951 if (isOpenMPLoopDirective(DKind))
952 ScopeFlags |= Scope::OpenMPLoopDirectiveScope;
953 if (isOpenMPSimdDirective(DKind))
954 ScopeFlags |= Scope::OpenMPSimdDirectiveScope;
955 ParseScope OMPDirectiveScope(this, ScopeFlags);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000956 Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000957
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000958 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataev6125da92014-07-21 11:26:11 +0000959 OpenMPClauseKind CKind =
960 Tok.isAnnotation()
961 ? OMPC_unknown
962 : FlushHasClause ? OMPC_flush
963 : getOpenMPClauseKind(PP.getSpelling(Tok));
Alexey Bataevaac108a2015-06-23 04:51:00 +0000964 Actions.StartOpenMPClause(CKind);
Alexey Bataev6125da92014-07-21 11:26:11 +0000965 FlushHasClause = false;
Alexey Bataeva55ed262014-05-28 06:15:33 +0000966 OMPClause *Clause =
967 ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000968 FirstClauses[CKind].setInt(true);
969 if (Clause) {
970 FirstClauses[CKind].setPointer(Clause);
971 Clauses.push_back(Clause);
972 }
973
974 // Skip ',' if any.
975 if (Tok.is(tok::comma))
976 ConsumeToken();
Alexey Bataevaac108a2015-06-23 04:51:00 +0000977 Actions.EndOpenMPClause();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000978 }
979 // End location of the directive.
980 EndLoc = Tok.getLocation();
981 // Consume final annot_pragma_openmp_end.
Richard Smithaf3b3252017-05-18 19:21:48 +0000982 ConsumeAnnotationToken();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000983
Alexey Bataeveb482352015-12-18 05:05:56 +0000984 // OpenMP [2.13.8, ordered Construct, Syntax]
985 // If the depend clause is specified, the ordered construct is a stand-alone
986 // directive.
987 if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) {
Alexey Bataevc4fad652016-01-13 11:18:54 +0000988 if (Allowed == ACK_StatementsOpenMPNonStandalone) {
Alexey Bataeveb482352015-12-18 05:05:56 +0000989 Diag(Loc, diag::err_omp_immediate_directive)
990 << getOpenMPDirectiveName(DKind) << 1
991 << getOpenMPClauseName(OMPC_depend);
992 }
993 HasAssociatedStatement = false;
994 }
995
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000996 StmtResult AssociatedStmt;
Alexey Bataev68446b72014-07-18 07:47:19 +0000997 if (HasAssociatedStatement) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000998 // The body is a block scope like in Lambdas and Blocks.
999 Sema::CompoundScopeRAII CompoundScope(Actions);
Alexey Bataevbae9a792014-06-27 10:37:06 +00001000 Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001001 Actions.ActOnStartOfCompoundStmt();
1002 // Parse statement
1003 AssociatedStmt = ParseStatement();
1004 Actions.ActOnFinishOfCompoundStmt();
Alexey Bataeva8d4a5432015-04-02 07:48:16 +00001005 AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001006 }
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001007 Directive = Actions.ActOnOpenMPExecutableDirective(
1008 DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc,
1009 EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001010
1011 // Exit scope.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001012 Actions.EndOpenMPDSABlock(Directive.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001013 OMPDirectiveScope.Exit();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001014 break;
Alexey Bataeva55ed262014-05-28 06:15:33 +00001015 }
Alexey Bataev587e1de2016-03-30 10:43:55 +00001016 case OMPD_declare_simd:
Dmitry Polukhin0b0da292016-04-06 11:38:59 +00001017 case OMPD_declare_target:
1018 case OMPD_end_declare_target:
Alexey Bataev587e1de2016-03-30 10:43:55 +00001019 Diag(Tok, diag::err_omp_unexpected_directive)
1020 << getOpenMPDirectiveName(DKind);
1021 SkipUntil(tok::annot_pragma_openmp_end);
1022 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001023 case OMPD_unknown:
1024 Diag(Tok, diag::err_omp_unknown_directive);
Alp Tokerd751fa72013-12-18 19:10:49 +00001025 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001026 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001027 }
1028 return Directive;
1029}
1030
Dmitry Polukhind69b5052016-05-09 14:59:13 +00001031// Parses simple list:
1032// simple-variable-list:
1033// '(' id-expression {, id-expression} ')'
1034//
1035bool Parser::ParseOpenMPSimpleVarList(
1036 OpenMPDirectiveKind Kind,
1037 const llvm::function_ref<void(CXXScopeSpec &, DeclarationNameInfo)> &
1038 Callback,
1039 bool AllowScopeSpecifier) {
Alexey Bataeva769e072013-03-22 06:34:35 +00001040 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +00001041 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001042 if (T.expectAndConsume(diag::err_expected_lparen_after,
1043 getOpenMPDirectiveName(Kind)))
1044 return true;
1045 bool IsCorrect = true;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001046 bool NoIdentIsFound = true;
Alexey Bataeva769e072013-03-22 06:34:35 +00001047
1048 // Read tokens while ')' or annot_pragma_openmp_end is not found.
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001049 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataeva769e072013-03-22 06:34:35 +00001050 CXXScopeSpec SS;
1051 SourceLocation TemplateKWLoc;
1052 UnqualifiedId Name;
1053 // Read var name.
1054 Token PrevTok = Tok;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001055 NoIdentIsFound = false;
Alexey Bataeva769e072013-03-22 06:34:35 +00001056
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001057 if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
David Blaikieefdccaa2016-01-15 23:43:34 +00001058 ParseOptionalCXXScopeSpecifier(SS, nullptr, false)) {
Alexey Bataeva769e072013-03-22 06:34:35 +00001059 IsCorrect = false;
1060 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +00001061 StopBeforeMatch);
Richard Smith35845152017-02-07 01:37:30 +00001062 } else if (ParseUnqualifiedId(SS, false, false, false, false, nullptr,
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001063 TemplateKWLoc, Name)) {
Alexey Bataeva769e072013-03-22 06:34:35 +00001064 IsCorrect = false;
1065 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +00001066 StopBeforeMatch);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001067 } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
1068 Tok.isNot(tok::annot_pragma_openmp_end)) {
1069 IsCorrect = false;
1070 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +00001071 StopBeforeMatch);
Alp Tokerec543272013-12-24 09:48:30 +00001072 Diag(PrevTok.getLocation(), diag::err_expected)
1073 << tok::identifier
1074 << SourceRange(PrevTok.getLocation(), PrevTokLocation);
Alexey Bataeva769e072013-03-22 06:34:35 +00001075 } else {
Dmitry Polukhind69b5052016-05-09 14:59:13 +00001076 Callback(SS, Actions.GetNameFromUnqualifiedId(Name));
Alexey Bataeva769e072013-03-22 06:34:35 +00001077 }
1078 // Consume ','.
1079 if (Tok.is(tok::comma)) {
1080 ConsumeToken();
1081 }
Alexey Bataeva769e072013-03-22 06:34:35 +00001082 }
1083
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001084 if (NoIdentIsFound) {
Alp Tokerec543272013-12-24 09:48:30 +00001085 Diag(Tok, diag::err_expected) << tok::identifier;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001086 IsCorrect = false;
1087 }
1088
1089 // Parse ')'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001090 IsCorrect = !T.consumeClose() && IsCorrect;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001091
Dmitry Polukhind69b5052016-05-09 14:59:13 +00001092 return !IsCorrect;
Alexey Bataeva769e072013-03-22 06:34:35 +00001093}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001094
1095/// \brief Parsing of OpenMP clauses.
1096///
1097/// clause:
Alexey Bataev3778b602014-07-17 07:32:53 +00001098/// if-clause | final-clause | num_threads-clause | safelen-clause |
1099/// default-clause | private-clause | firstprivate-clause | shared-clause
1100/// | linear-clause | aligned-clause | collapse-clause |
1101/// lastprivate-clause | reduction-clause | proc_bind-clause |
Alexey Bataev74ba3a52014-07-17 12:47:03 +00001102/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
Alexey Bataev67a4f222014-07-23 10:25:33 +00001103/// mergeable-clause | flush-clause | read-clause | write-clause |
Alexey Bataev66b15b52015-08-21 11:14:16 +00001104/// update-clause | capture-clause | seq_cst-clause | device-clause |
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001105/// simdlen-clause | threads-clause | simd-clause | num_teams-clause |
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001106/// thread_limit-clause | priority-clause | grainsize-clause |
Samuel Antaoec172c62016-05-26 17:49:04 +00001107/// nogroup-clause | num_tasks-clause | hint-clause | to-clause |
Alexey Bataevfa312f32017-07-21 18:48:21 +00001108/// from-clause | is_device_ptr-clause | task_reduction-clause |
1109/// in_reduction-clause
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001110///
1111OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
1112 OpenMPClauseKind CKind, bool FirstClause) {
Craig Topper161e4db2014-05-21 06:02:52 +00001113 OMPClause *Clause = nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001114 bool ErrorFound = false;
1115 // Check if clause is allowed for the given directive.
1116 if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
Alexey Bataeva55ed262014-05-28 06:15:33 +00001117 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
1118 << getOpenMPDirectiveName(DKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001119 ErrorFound = true;
1120 }
1121
1122 switch (CKind) {
Alexey Bataev3778b602014-07-17 07:32:53 +00001123 case OMPC_final:
Alexey Bataev568a8332014-03-06 06:15:19 +00001124 case OMPC_num_threads:
Alexey Bataev62c87d22014-03-21 04:51:18 +00001125 case OMPC_safelen:
Alexey Bataev66b15b52015-08-21 11:14:16 +00001126 case OMPC_simdlen:
Alexander Musman8bd31e62014-05-27 15:12:19 +00001127 case OMPC_collapse:
Alexey Bataev10e775f2015-07-30 11:36:16 +00001128 case OMPC_ordered:
Michael Wonge710d542015-08-07 16:16:36 +00001129 case OMPC_device:
Kelvin Li099bb8c2015-11-24 20:50:12 +00001130 case OMPC_num_teams:
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001131 case OMPC_thread_limit:
Alexey Bataeva0569352015-12-01 10:17:31 +00001132 case OMPC_priority:
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001133 case OMPC_grainsize:
Alexey Bataev382967a2015-12-08 12:06:20 +00001134 case OMPC_num_tasks:
Alexey Bataev28c75412015-12-15 08:19:24 +00001135 case OMPC_hint:
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001136 // OpenMP [2.5, Restrictions]
Alexey Bataev568a8332014-03-06 06:15:19 +00001137 // At most one num_threads clause can appear on the directive.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001138 // OpenMP [2.8.1, simd construct, Restrictions]
Alexander Musman8bd31e62014-05-27 15:12:19 +00001139 // Only one safelen clause can appear on a simd directive.
Alexey Bataev66b15b52015-08-21 11:14:16 +00001140 // Only one simdlen clause can appear on a simd directive.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001141 // Only one collapse clause can appear on a simd directive.
Michael Wonge710d542015-08-07 16:16:36 +00001142 // OpenMP [2.9.1, target data construct, Restrictions]
1143 // At most one device clause can appear on the directive.
Alexey Bataev3778b602014-07-17 07:32:53 +00001144 // OpenMP [2.11.1, task Construct, Restrictions]
1145 // At most one if clause can appear on the directive.
1146 // At most one final clause can appear on the directive.
Kelvin Li099bb8c2015-11-24 20:50:12 +00001147 // OpenMP [teams Construct, Restrictions]
1148 // At most one num_teams clause can appear on the directive.
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001149 // At most one thread_limit clause can appear on the directive.
Alexey Bataeva0569352015-12-01 10:17:31 +00001150 // OpenMP [2.9.1, task Construct, Restrictions]
1151 // At most one priority clause can appear on the directive.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001152 // OpenMP [2.9.2, taskloop Construct, Restrictions]
1153 // At most one grainsize clause can appear on the directive.
Alexey Bataev382967a2015-12-08 12:06:20 +00001154 // OpenMP [2.9.2, taskloop Construct, Restrictions]
1155 // At most one num_tasks clause can appear on the directive.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001156 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001157 Diag(Tok, diag::err_omp_more_one_clause)
1158 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +00001159 ErrorFound = true;
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001160 }
1161
Alexey Bataev10e775f2015-07-30 11:36:16 +00001162 if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren))
1163 Clause = ParseOpenMPClause(CKind);
1164 else
1165 Clause = ParseOpenMPSingleExprClause(CKind);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001166 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001167 case OMPC_default:
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001168 case OMPC_proc_bind:
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001169 // OpenMP [2.14.3.1, Restrictions]
1170 // Only a single default clause may be specified on a parallel, task or
1171 // teams directive.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001172 // OpenMP [2.5, parallel Construct, Restrictions]
1173 // At most one proc_bind clause can appear on the directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001174 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001175 Diag(Tok, diag::err_omp_more_one_clause)
1176 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +00001177 ErrorFound = true;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001178 }
1179
1180 Clause = ParseOpenMPSimpleClause(CKind);
1181 break;
Alexey Bataev56dafe82014-06-20 07:16:17 +00001182 case OMPC_schedule:
Carlo Bertollib4adf552016-01-15 18:50:31 +00001183 case OMPC_dist_schedule:
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001184 case OMPC_defaultmap:
Alexey Bataev56dafe82014-06-20 07:16:17 +00001185 // OpenMP [2.7.1, Restrictions, p. 3]
1186 // Only one schedule clause can appear on a loop directive.
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001187 // OpenMP [2.10.4, Restrictions, p. 106]
1188 // At most one defaultmap clause can appear on the directive.
Alexey Bataev56dafe82014-06-20 07:16:17 +00001189 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001190 Diag(Tok, diag::err_omp_more_one_clause)
1191 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +00001192 ErrorFound = true;
Alexey Bataev56dafe82014-06-20 07:16:17 +00001193 }
Galina Kistanova474f2ce2017-06-01 21:26:38 +00001194 LLVM_FALLTHROUGH;
Alexey Bataev56dafe82014-06-20 07:16:17 +00001195
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001196 case OMPC_if:
Alexey Bataev56dafe82014-06-20 07:16:17 +00001197 Clause = ParseOpenMPSingleExprWithArgClause(CKind);
1198 break;
Alexey Bataev236070f2014-06-20 11:19:47 +00001199 case OMPC_nowait:
Alexey Bataev7aea99a2014-07-17 12:19:31 +00001200 case OMPC_untied:
Alexey Bataev74ba3a52014-07-17 12:47:03 +00001201 case OMPC_mergeable:
Alexey Bataevf98b00c2014-07-23 02:27:21 +00001202 case OMPC_read:
Alexey Bataevdea47612014-07-23 07:46:59 +00001203 case OMPC_write:
Alexey Bataev67a4f222014-07-23 10:25:33 +00001204 case OMPC_update:
Alexey Bataev459dec02014-07-24 06:46:57 +00001205 case OMPC_capture:
Alexey Bataev82bad8b2014-07-24 08:55:34 +00001206 case OMPC_seq_cst:
Alexey Bataev346265e2015-09-25 10:37:12 +00001207 case OMPC_threads:
Alexey Bataevd14d1e62015-09-28 06:39:35 +00001208 case OMPC_simd:
Alexey Bataevb825de12015-12-07 10:51:44 +00001209 case OMPC_nogroup:
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001210 // OpenMP [2.7.1, Restrictions, p. 9]
1211 // Only one ordered clause can appear on a loop directive.
Alexey Bataev236070f2014-06-20 11:19:47 +00001212 // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
1213 // Only one nowait clause can appear on a for directive.
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001214 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001215 Diag(Tok, diag::err_omp_more_one_clause)
1216 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +00001217 ErrorFound = true;
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001218 }
1219
1220 Clause = ParseOpenMPClause(CKind);
1221 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001222 case OMPC_private:
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001223 case OMPC_firstprivate:
Alexander Musman1bb328c2014-06-04 13:06:39 +00001224 case OMPC_lastprivate:
Alexey Bataev758e55e2013-09-06 18:03:48 +00001225 case OMPC_shared:
Alexey Bataevc5e02582014-06-16 07:08:35 +00001226 case OMPC_reduction:
Alexey Bataev169d96a2017-07-18 20:17:46 +00001227 case OMPC_task_reduction:
Alexey Bataevfa312f32017-07-21 18:48:21 +00001228 case OMPC_in_reduction:
Alexander Musman8dba6642014-04-22 13:09:42 +00001229 case OMPC_linear:
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001230 case OMPC_aligned:
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001231 case OMPC_copyin:
Alexey Bataevbae9a792014-06-27 10:37:06 +00001232 case OMPC_copyprivate:
Alexey Bataev6125da92014-07-21 11:26:11 +00001233 case OMPC_flush:
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001234 case OMPC_depend:
Kelvin Li0bff7af2015-11-23 05:32:03 +00001235 case OMPC_map:
Samuel Antao661c0902016-05-26 17:39:58 +00001236 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +00001237 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +00001238 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +00001239 case OMPC_is_device_ptr:
Alexey Bataeveb482352015-12-18 05:05:56 +00001240 Clause = ParseOpenMPVarListClause(DKind, CKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001241 break;
1242 case OMPC_unknown:
1243 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +00001244 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +00001245 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001246 break;
1247 case OMPC_threadprivate:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001248 case OMPC_uniform:
Alexey Bataeva55ed262014-05-28 06:15:33 +00001249 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
1250 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +00001251 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001252 break;
1253 }
Craig Topper161e4db2014-05-21 06:02:52 +00001254 return ErrorFound ? nullptr : Clause;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001255}
1256
Alexey Bataev2af33e32016-04-07 12:45:37 +00001257/// Parses simple expression in parens for single-expression clauses of OpenMP
1258/// constructs.
1259/// \param RLoc Returned location of right paren.
1260ExprResult Parser::ParseOpenMPParensExpr(StringRef ClauseName,
1261 SourceLocation &RLoc) {
1262 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
1263 if (T.expectAndConsume(diag::err_expected_lparen_after, ClauseName.data()))
1264 return ExprError();
1265
1266 SourceLocation ELoc = Tok.getLocation();
1267 ExprResult LHS(ParseCastExpression(
1268 /*isUnaryExpression=*/false, /*isAddressOfOperand=*/false, NotTypeCast));
1269 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
1270 Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
1271
1272 // Parse ')'.
1273 T.consumeClose();
1274
1275 RLoc = T.getCloseLocation();
1276 return Val;
1277}
1278
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001279/// \brief Parsing of OpenMP clauses with single expressions like 'final',
Alexey Bataeva0569352015-12-01 10:17:31 +00001280/// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams',
Alexey Bataev28c75412015-12-15 08:19:24 +00001281/// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001282///
Alexey Bataev3778b602014-07-17 07:32:53 +00001283/// final-clause:
1284/// 'final' '(' expression ')'
1285///
Alexey Bataev62c87d22014-03-21 04:51:18 +00001286/// num_threads-clause:
1287/// 'num_threads' '(' expression ')'
1288///
1289/// safelen-clause:
1290/// 'safelen' '(' expression ')'
1291///
Alexey Bataev66b15b52015-08-21 11:14:16 +00001292/// simdlen-clause:
1293/// 'simdlen' '(' expression ')'
1294///
Alexander Musman8bd31e62014-05-27 15:12:19 +00001295/// collapse-clause:
1296/// 'collapse' '(' expression ')'
1297///
Alexey Bataeva0569352015-12-01 10:17:31 +00001298/// priority-clause:
1299/// 'priority' '(' expression ')'
1300///
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001301/// grainsize-clause:
1302/// 'grainsize' '(' expression ')'
1303///
Alexey Bataev382967a2015-12-08 12:06:20 +00001304/// num_tasks-clause:
1305/// 'num_tasks' '(' expression ')'
1306///
Alexey Bataev28c75412015-12-15 08:19:24 +00001307/// hint-clause:
1308/// 'hint' '(' expression ')'
1309///
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001310OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
1311 SourceLocation Loc = ConsumeToken();
Alexey Bataev2af33e32016-04-07 12:45:37 +00001312 SourceLocation LLoc = Tok.getLocation();
1313 SourceLocation RLoc;
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001314
Alexey Bataev2af33e32016-04-07 12:45:37 +00001315 ExprResult Val = ParseOpenMPParensExpr(getOpenMPClauseName(Kind), RLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001316
1317 if (Val.isInvalid())
Craig Topper161e4db2014-05-21 06:02:52 +00001318 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001319
Alexey Bataev2af33e32016-04-07 12:45:37 +00001320 return Actions.ActOnOpenMPSingleExprClause(Kind, Val.get(), Loc, LLoc, RLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001321}
1322
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001323/// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001324///
1325/// default-clause:
1326/// 'default' '(' 'none' | 'shared' ')
1327///
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001328/// proc_bind-clause:
1329/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
1330///
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001331OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
1332 SourceLocation Loc = Tok.getLocation();
1333 SourceLocation LOpen = ConsumeToken();
1334 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +00001335 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001336 if (T.expectAndConsume(diag::err_expected_lparen_after,
1337 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +00001338 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001339
Alexey Bataeva55ed262014-05-28 06:15:33 +00001340 unsigned Type = getOpenMPSimpleClauseType(
1341 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001342 SourceLocation TypeLoc = Tok.getLocation();
1343 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1344 Tok.isNot(tok::annot_pragma_openmp_end))
1345 ConsumeAnyToken();
1346
1347 // Parse ')'.
1348 T.consumeClose();
1349
1350 return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
1351 Tok.getLocation());
1352}
1353
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001354/// \brief Parsing of OpenMP clauses like 'ordered'.
1355///
1356/// ordered-clause:
1357/// 'ordered'
1358///
Alexey Bataev236070f2014-06-20 11:19:47 +00001359/// nowait-clause:
1360/// 'nowait'
1361///
Alexey Bataev7aea99a2014-07-17 12:19:31 +00001362/// untied-clause:
1363/// 'untied'
1364///
Alexey Bataev74ba3a52014-07-17 12:47:03 +00001365/// mergeable-clause:
1366/// 'mergeable'
1367///
Alexey Bataevf98b00c2014-07-23 02:27:21 +00001368/// read-clause:
1369/// 'read'
1370///
Alexey Bataev346265e2015-09-25 10:37:12 +00001371/// threads-clause:
1372/// 'threads'
1373///
Alexey Bataevd14d1e62015-09-28 06:39:35 +00001374/// simd-clause:
1375/// 'simd'
1376///
Alexey Bataevb825de12015-12-07 10:51:44 +00001377/// nogroup-clause:
1378/// 'nogroup'
1379///
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001380OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
1381 SourceLocation Loc = Tok.getLocation();
1382 ConsumeAnyToken();
1383
1384 return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
1385}
1386
1387
Alexey Bataev56dafe82014-06-20 07:16:17 +00001388/// \brief Parsing of OpenMP clauses with single expressions and some additional
1389/// argument like 'schedule' or 'dist_schedule'.
1390///
1391/// schedule-clause:
Alexey Bataev6402bca2015-12-28 07:25:51 +00001392/// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ]
1393/// ')'
Alexey Bataev56dafe82014-06-20 07:16:17 +00001394///
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001395/// if-clause:
1396/// 'if' '(' [ directive-name-modifier ':' ] expression ')'
1397///
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001398/// defaultmap:
1399/// 'defaultmap' '(' modifier ':' kind ')'
1400///
Alexey Bataev56dafe82014-06-20 07:16:17 +00001401OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
1402 SourceLocation Loc = ConsumeToken();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001403 SourceLocation DelimLoc;
Alexey Bataev56dafe82014-06-20 07:16:17 +00001404 // Parse '('.
1405 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
1406 if (T.expectAndConsume(diag::err_expected_lparen_after,
1407 getOpenMPClauseName(Kind)))
1408 return nullptr;
1409
1410 ExprResult Val;
Alexey Bataev6402bca2015-12-28 07:25:51 +00001411 SmallVector<unsigned, 4> Arg;
1412 SmallVector<SourceLocation, 4> KLoc;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001413 if (Kind == OMPC_schedule) {
Alexey Bataev6402bca2015-12-28 07:25:51 +00001414 enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements };
1415 Arg.resize(NumberOfElements);
1416 KLoc.resize(NumberOfElements);
1417 Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown;
1418 Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown;
1419 Arg[ScheduleKind] = OMPC_SCHEDULE_unknown;
1420 auto KindModifier = getOpenMPSimpleClauseType(
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001421 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev6402bca2015-12-28 07:25:51 +00001422 if (KindModifier > OMPC_SCHEDULE_unknown) {
1423 // Parse 'modifier'
1424 Arg[Modifier1] = KindModifier;
1425 KLoc[Modifier1] = Tok.getLocation();
1426 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1427 Tok.isNot(tok::annot_pragma_openmp_end))
1428 ConsumeAnyToken();
1429 if (Tok.is(tok::comma)) {
1430 // Parse ',' 'modifier'
1431 ConsumeAnyToken();
1432 KindModifier = getOpenMPSimpleClauseType(
1433 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
1434 Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown
1435 ? KindModifier
Aaron Ballmanad8a1042015-12-28 15:52:46 +00001436 : (unsigned)OMPC_SCHEDULE_unknown;
Alexey Bataev6402bca2015-12-28 07:25:51 +00001437 KLoc[Modifier2] = Tok.getLocation();
1438 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1439 Tok.isNot(tok::annot_pragma_openmp_end))
1440 ConsumeAnyToken();
1441 }
1442 // Parse ':'
1443 if (Tok.is(tok::colon))
1444 ConsumeAnyToken();
1445 else
1446 Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier";
1447 KindModifier = getOpenMPSimpleClauseType(
1448 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
1449 }
1450 Arg[ScheduleKind] = KindModifier;
1451 KLoc[ScheduleKind] = Tok.getLocation();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001452 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1453 Tok.isNot(tok::annot_pragma_openmp_end))
1454 ConsumeAnyToken();
Alexey Bataev6402bca2015-12-28 07:25:51 +00001455 if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static ||
1456 Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic ||
1457 Arg[ScheduleKind] == OMPC_SCHEDULE_guided) &&
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001458 Tok.is(tok::comma))
1459 DelimLoc = ConsumeAnyToken();
Carlo Bertollib4adf552016-01-15 18:50:31 +00001460 } else if (Kind == OMPC_dist_schedule) {
1461 Arg.push_back(getOpenMPSimpleClauseType(
1462 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
1463 KLoc.push_back(Tok.getLocation());
1464 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1465 Tok.isNot(tok::annot_pragma_openmp_end))
1466 ConsumeAnyToken();
1467 if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma))
1468 DelimLoc = ConsumeAnyToken();
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001469 } else if (Kind == OMPC_defaultmap) {
1470 // Get a defaultmap modifier
1471 Arg.push_back(getOpenMPSimpleClauseType(
1472 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
1473 KLoc.push_back(Tok.getLocation());
1474 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1475 Tok.isNot(tok::annot_pragma_openmp_end))
1476 ConsumeAnyToken();
1477 // Parse ':'
1478 if (Tok.is(tok::colon))
1479 ConsumeAnyToken();
1480 else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown)
1481 Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier";
1482 // Get a defaultmap kind
1483 Arg.push_back(getOpenMPSimpleClauseType(
1484 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
1485 KLoc.push_back(Tok.getLocation());
1486 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1487 Tok.isNot(tok::annot_pragma_openmp_end))
1488 ConsumeAnyToken();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001489 } else {
1490 assert(Kind == OMPC_if);
Alexey Bataev6402bca2015-12-28 07:25:51 +00001491 KLoc.push_back(Tok.getLocation());
Alexey Bataev2a6de8c2016-12-20 12:10:05 +00001492 TentativeParsingAction TPA(*this);
Alexey Bataev6402bca2015-12-28 07:25:51 +00001493 Arg.push_back(ParseOpenMPDirectiveKind(*this));
1494 if (Arg.back() != OMPD_unknown) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001495 ConsumeToken();
Alexey Bataev2a6de8c2016-12-20 12:10:05 +00001496 if (Tok.is(tok::colon) && getLangOpts().OpenMP > 40) {
1497 TPA.Commit();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001498 DelimLoc = ConsumeToken();
Alexey Bataev2a6de8c2016-12-20 12:10:05 +00001499 } else {
1500 TPA.Revert();
1501 Arg.back() = OMPD_unknown;
1502 }
1503 } else
1504 TPA.Revert();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001505 }
Alexey Bataev56dafe82014-06-20 07:16:17 +00001506
Carlo Bertollib4adf552016-01-15 18:50:31 +00001507 bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) ||
1508 (Kind == OMPC_dist_schedule && DelimLoc.isValid()) ||
1509 Kind == OMPC_if;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001510 if (NeedAnExpression) {
1511 SourceLocation ELoc = Tok.getLocation();
Alexey Bataev56dafe82014-06-20 07:16:17 +00001512 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
1513 Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001514 Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001515 }
1516
1517 // Parse ')'.
1518 T.consumeClose();
1519
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001520 if (NeedAnExpression && Val.isInvalid())
1521 return nullptr;
1522
Alexey Bataev56dafe82014-06-20 07:16:17 +00001523 return Actions.ActOnOpenMPSingleExprWithArgClause(
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001524 Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc,
Alexey Bataev56dafe82014-06-20 07:16:17 +00001525 T.getCloseLocation());
1526}
1527
Alexey Bataevc5e02582014-06-16 07:08:35 +00001528static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
1529 UnqualifiedId &ReductionId) {
1530 SourceLocation TemplateKWLoc;
1531 if (ReductionIdScopeSpec.isEmpty()) {
1532 auto OOK = OO_None;
1533 switch (P.getCurToken().getKind()) {
1534 case tok::plus:
1535 OOK = OO_Plus;
1536 break;
1537 case tok::minus:
1538 OOK = OO_Minus;
1539 break;
1540 case tok::star:
1541 OOK = OO_Star;
1542 break;
1543 case tok::amp:
1544 OOK = OO_Amp;
1545 break;
1546 case tok::pipe:
1547 OOK = OO_Pipe;
1548 break;
1549 case tok::caret:
1550 OOK = OO_Caret;
1551 break;
1552 case tok::ampamp:
1553 OOK = OO_AmpAmp;
1554 break;
1555 case tok::pipepipe:
1556 OOK = OO_PipePipe;
1557 break;
1558 default:
1559 break;
1560 }
1561 if (OOK != OO_None) {
1562 SourceLocation OpLoc = P.ConsumeToken();
Alexey Bataev23b69422014-06-18 07:08:49 +00001563 SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
Alexey Bataevc5e02582014-06-16 07:08:35 +00001564 ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
1565 return false;
1566 }
1567 }
1568 return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
1569 /*AllowDestructorName*/ false,
Richard Smith35845152017-02-07 01:37:30 +00001570 /*AllowConstructorName*/ false,
1571 /*AllowDeductionGuide*/ false,
1572 nullptr, TemplateKWLoc, ReductionId);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001573}
1574
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001575/// Parses clauses with list.
1576bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
1577 OpenMPClauseKind Kind,
1578 SmallVectorImpl<Expr *> &Vars,
1579 OpenMPVarListDataTy &Data) {
1580 UnqualifiedId UnqualifiedReductionId;
1581 bool InvalidReductionId = false;
1582 bool MapTypeModifierSpecified = false;
1583
1584 // Parse '('.
1585 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
1586 if (T.expectAndConsume(diag::err_expected_lparen_after,
1587 getOpenMPClauseName(Kind)))
1588 return true;
1589
1590 bool NeedRParenForLinear = false;
1591 BalancedDelimiterTracker LinearT(*this, tok::l_paren,
1592 tok::annot_pragma_openmp_end);
1593 // Handle reduction-identifier for reduction clause.
Alexey Bataevfa312f32017-07-21 18:48:21 +00001594 if (Kind == OMPC_reduction || Kind == OMPC_task_reduction ||
1595 Kind == OMPC_in_reduction) {
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001596 ColonProtectionRAIIObject ColonRAII(*this);
1597 if (getLangOpts().CPlusPlus)
1598 ParseOptionalCXXScopeSpecifier(Data.ReductionIdScopeSpec,
1599 /*ObjectType=*/nullptr,
1600 /*EnteringContext=*/false);
1601 InvalidReductionId = ParseReductionId(*this, Data.ReductionIdScopeSpec,
1602 UnqualifiedReductionId);
1603 if (InvalidReductionId) {
1604 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
1605 StopBeforeMatch);
1606 }
1607 if (Tok.is(tok::colon))
1608 Data.ColonLoc = ConsumeToken();
1609 else
1610 Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
1611 if (!InvalidReductionId)
1612 Data.ReductionId =
1613 Actions.GetNameFromUnqualifiedId(UnqualifiedReductionId);
1614 } else if (Kind == OMPC_depend) {
1615 // Handle dependency type for depend clause.
1616 ColonProtectionRAIIObject ColonRAII(*this);
1617 Data.DepKind =
1618 static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType(
1619 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
1620 Data.DepLinMapLoc = Tok.getLocation();
1621
1622 if (Data.DepKind == OMPC_DEPEND_unknown) {
1623 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
1624 StopBeforeMatch);
1625 } else {
1626 ConsumeToken();
1627 // Special processing for depend(source) clause.
1628 if (DKind == OMPD_ordered && Data.DepKind == OMPC_DEPEND_source) {
1629 // Parse ')'.
1630 T.consumeClose();
1631 return false;
1632 }
1633 }
1634 if (Tok.is(tok::colon))
1635 Data.ColonLoc = ConsumeToken();
1636 else {
1637 Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren
1638 : diag::warn_pragma_expected_colon)
1639 << "dependency type";
1640 }
1641 } else if (Kind == OMPC_linear) {
1642 // Try to parse modifier if any.
1643 if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) {
1644 Data.LinKind = static_cast<OpenMPLinearClauseKind>(
1645 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)));
1646 Data.DepLinMapLoc = ConsumeToken();
1647 LinearT.consumeOpen();
1648 NeedRParenForLinear = true;
1649 }
1650 } else if (Kind == OMPC_map) {
1651 // Handle map type for map clause.
1652 ColonProtectionRAIIObject ColonRAII(*this);
1653
1654 /// The map clause modifier token can be either a identifier or the C++
1655 /// delete keyword.
1656 auto &&IsMapClauseModifierToken = [](const Token &Tok) -> bool {
1657 return Tok.isOneOf(tok::identifier, tok::kw_delete);
1658 };
1659
1660 // The first identifier may be a list item, a map-type or a
1661 // map-type-modifier. The map modifier can also be delete which has the same
1662 // spelling of the C++ delete keyword.
1663 Data.MapType =
1664 IsMapClauseModifierToken(Tok)
1665 ? static_cast<OpenMPMapClauseKind>(
1666 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)))
1667 : OMPC_MAP_unknown;
1668 Data.DepLinMapLoc = Tok.getLocation();
1669 bool ColonExpected = false;
1670
1671 if (IsMapClauseModifierToken(Tok)) {
1672 if (PP.LookAhead(0).is(tok::colon)) {
1673 if (Data.MapType == OMPC_MAP_unknown)
1674 Diag(Tok, diag::err_omp_unknown_map_type);
1675 else if (Data.MapType == OMPC_MAP_always)
1676 Diag(Tok, diag::err_omp_map_type_missing);
1677 ConsumeToken();
1678 } else if (PP.LookAhead(0).is(tok::comma)) {
1679 if (IsMapClauseModifierToken(PP.LookAhead(1)) &&
1680 PP.LookAhead(2).is(tok::colon)) {
1681 Data.MapTypeModifier = Data.MapType;
1682 if (Data.MapTypeModifier != OMPC_MAP_always) {
1683 Diag(Tok, diag::err_omp_unknown_map_type_modifier);
1684 Data.MapTypeModifier = OMPC_MAP_unknown;
1685 } else
1686 MapTypeModifierSpecified = true;
1687
1688 ConsumeToken();
1689 ConsumeToken();
1690
1691 Data.MapType =
1692 IsMapClauseModifierToken(Tok)
1693 ? static_cast<OpenMPMapClauseKind>(
1694 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)))
1695 : OMPC_MAP_unknown;
1696 if (Data.MapType == OMPC_MAP_unknown ||
1697 Data.MapType == OMPC_MAP_always)
1698 Diag(Tok, diag::err_omp_unknown_map_type);
1699 ConsumeToken();
1700 } else {
1701 Data.MapType = OMPC_MAP_tofrom;
1702 Data.IsMapTypeImplicit = true;
1703 }
Carlo Bertollid8844b92017-05-03 15:28:48 +00001704 } else if (IsMapClauseModifierToken(PP.LookAhead(0))) {
1705 if (PP.LookAhead(1).is(tok::colon)) {
1706 Data.MapTypeModifier = Data.MapType;
1707 if (Data.MapTypeModifier != OMPC_MAP_always) {
1708 Diag(Tok, diag::err_omp_unknown_map_type_modifier);
1709 Data.MapTypeModifier = OMPC_MAP_unknown;
1710 } else
1711 MapTypeModifierSpecified = true;
1712
1713 ConsumeToken();
1714
1715 Data.MapType =
1716 IsMapClauseModifierToken(Tok)
1717 ? static_cast<OpenMPMapClauseKind>(
1718 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)))
1719 : OMPC_MAP_unknown;
1720 if (Data.MapType == OMPC_MAP_unknown ||
1721 Data.MapType == OMPC_MAP_always)
1722 Diag(Tok, diag::err_omp_unknown_map_type);
1723 ConsumeToken();
1724 } else {
1725 Data.MapType = OMPC_MAP_tofrom;
1726 Data.IsMapTypeImplicit = true;
1727 }
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001728 } else {
1729 Data.MapType = OMPC_MAP_tofrom;
1730 Data.IsMapTypeImplicit = true;
1731 }
1732 } else {
1733 Data.MapType = OMPC_MAP_tofrom;
1734 Data.IsMapTypeImplicit = true;
1735 }
1736
1737 if (Tok.is(tok::colon))
1738 Data.ColonLoc = ConsumeToken();
1739 else if (ColonExpected)
1740 Diag(Tok, diag::warn_pragma_expected_colon) << "map type";
1741 }
1742
Alexey Bataevfa312f32017-07-21 18:48:21 +00001743 bool IsComma =
1744 (Kind != OMPC_reduction && Kind != OMPC_task_reduction &&
1745 Kind != OMPC_in_reduction && Kind != OMPC_depend && Kind != OMPC_map) ||
1746 (Kind == OMPC_reduction && !InvalidReductionId) ||
1747 (Kind == OMPC_map && Data.MapType != OMPC_MAP_unknown &&
1748 (!MapTypeModifierSpecified ||
1749 Data.MapTypeModifier == OMPC_MAP_always)) ||
1750 (Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown);
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001751 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
1752 while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
1753 Tok.isNot(tok::annot_pragma_openmp_end))) {
1754 ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
1755 // Parse variable
1756 ExprResult VarExpr =
1757 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
1758 if (VarExpr.isUsable())
1759 Vars.push_back(VarExpr.get());
1760 else {
1761 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1762 StopBeforeMatch);
1763 }
1764 // Skip ',' if any
1765 IsComma = Tok.is(tok::comma);
1766 if (IsComma)
1767 ConsumeToken();
1768 else if (Tok.isNot(tok::r_paren) &&
1769 Tok.isNot(tok::annot_pragma_openmp_end) &&
1770 (!MayHaveTail || Tok.isNot(tok::colon)))
1771 Diag(Tok, diag::err_omp_expected_punc)
1772 << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
1773 : getOpenMPClauseName(Kind))
1774 << (Kind == OMPC_flush);
1775 }
1776
1777 // Parse ')' for linear clause with modifier.
1778 if (NeedRParenForLinear)
1779 LinearT.consumeClose();
1780
1781 // Parse ':' linear-step (or ':' alignment).
1782 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
1783 if (MustHaveTail) {
1784 Data.ColonLoc = Tok.getLocation();
1785 SourceLocation ELoc = ConsumeToken();
1786 ExprResult Tail = ParseAssignmentExpression();
1787 Tail = Actions.ActOnFinishFullExpr(Tail.get(), ELoc);
1788 if (Tail.isUsable())
1789 Data.TailExpr = Tail.get();
1790 else
1791 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1792 StopBeforeMatch);
1793 }
1794
1795 // Parse ')'.
1796 T.consumeClose();
1797 if ((Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown &&
1798 Vars.empty()) ||
1799 (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) ||
1800 (MustHaveTail && !Data.TailExpr) || InvalidReductionId)
1801 return true;
1802 return false;
1803}
1804
Alexander Musman1bb328c2014-06-04 13:06:39 +00001805/// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
Alexey Bataevfa312f32017-07-21 18:48:21 +00001806/// 'shared', 'copyin', 'copyprivate', 'flush', 'reduction', 'task_reduction' or
1807/// 'in_reduction'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001808///
1809/// private-clause:
1810/// 'private' '(' list ')'
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001811/// firstprivate-clause:
1812/// 'firstprivate' '(' list ')'
Alexander Musman1bb328c2014-06-04 13:06:39 +00001813/// lastprivate-clause:
1814/// 'lastprivate' '(' list ')'
Alexey Bataev758e55e2013-09-06 18:03:48 +00001815/// shared-clause:
1816/// 'shared' '(' list ')'
Alexander Musman8dba6642014-04-22 13:09:42 +00001817/// linear-clause:
Alexey Bataev182227b2015-08-20 10:54:39 +00001818/// 'linear' '(' linear-list [ ':' linear-step ] ')'
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001819/// aligned-clause:
1820/// 'aligned' '(' list [ ':' alignment ] ')'
Alexey Bataevc5e02582014-06-16 07:08:35 +00001821/// reduction-clause:
1822/// 'reduction' '(' reduction-identifier ':' list ')'
Alexey Bataev169d96a2017-07-18 20:17:46 +00001823/// task_reduction-clause:
1824/// 'task_reduction' '(' reduction-identifier ':' list ')'
Alexey Bataevfa312f32017-07-21 18:48:21 +00001825/// in_reduction-clause:
1826/// 'in_reduction' '(' reduction-identifier ':' list ')'
Alexey Bataev6125da92014-07-21 11:26:11 +00001827/// copyprivate-clause:
1828/// 'copyprivate' '(' list ')'
1829/// flush-clause:
1830/// 'flush' '(' list ')'
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001831/// depend-clause:
Alexey Bataeveb482352015-12-18 05:05:56 +00001832/// 'depend' '(' in | out | inout : list | source ')'
Kelvin Li0bff7af2015-11-23 05:32:03 +00001833/// map-clause:
1834/// 'map' '(' [ [ always , ]
1835/// to | from | tofrom | alloc | release | delete ':' ] list ')';
Samuel Antao661c0902016-05-26 17:39:58 +00001836/// to-clause:
1837/// 'to' '(' list ')'
Samuel Antaoec172c62016-05-26 17:49:04 +00001838/// from-clause:
1839/// 'from' '(' list ')'
Carlo Bertolli2404b172016-07-13 15:37:16 +00001840/// use_device_ptr-clause:
1841/// 'use_device_ptr' '(' list ')'
Carlo Bertolli70594e92016-07-13 17:16:49 +00001842/// is_device_ptr-clause:
1843/// 'is_device_ptr' '(' list ')'
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001844///
Alexey Bataev182227b2015-08-20 10:54:39 +00001845/// For 'linear' clause linear-list may have the following forms:
1846/// list
1847/// modifier(list)
1848/// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++).
Alexey Bataeveb482352015-12-18 05:05:56 +00001849OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
1850 OpenMPClauseKind Kind) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001851 SourceLocation Loc = Tok.getLocation();
1852 SourceLocation LOpen = ConsumeToken();
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001853 SmallVector<Expr *, 4> Vars;
1854 OpenMPVarListDataTy Data;
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001855
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001856 if (ParseOpenMPVarList(DKind, Kind, Vars, Data))
Craig Topper161e4db2014-05-21 06:02:52 +00001857 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001858
Alexey Bataevc5e02582014-06-16 07:08:35 +00001859 return Actions.ActOnOpenMPVarListClause(
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001860 Kind, Vars, Data.TailExpr, Loc, LOpen, Data.ColonLoc, Tok.getLocation(),
1861 Data.ReductionIdScopeSpec, Data.ReductionId, Data.DepKind, Data.LinKind,
1862 Data.MapTypeModifier, Data.MapType, Data.IsMapTypeImplicit,
1863 Data.DepLinMapLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001864}
1865