blob: d9a088595ab73b1b5edffddb7951de2d4d1c44fb [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 |
305 Scope::OpenMPDirectiveScope);
306 // Parse <combiner> expression.
307 Actions.ActOnOpenMPDeclareReductionCombinerStart(getCurScope(), D);
308 ExprResult CombinerResult =
309 Actions.ActOnFinishFullExpr(ParseAssignmentExpression().get(),
310 D->getLocation(), /*DiscardedValue=*/true);
311 Actions.ActOnOpenMPDeclareReductionCombinerEnd(D, CombinerResult.get());
312
313 if (CombinerResult.isInvalid() && Tok.isNot(tok::r_paren) &&
314 Tok.isNot(tok::annot_pragma_openmp_end)) {
315 TPA.Commit();
316 IsCorrect = false;
317 break;
318 }
319 IsCorrect = !T.consumeClose() && IsCorrect && CombinerResult.isUsable();
320 ExprResult InitializerResult;
321 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
322 // Parse <initializer> expression.
323 if (Tok.is(tok::identifier) &&
324 Tok.getIdentifierInfo()->isStr("initializer"))
325 ConsumeToken();
326 else {
327 Diag(Tok.getLocation(), diag::err_expected) << "'initializer'";
328 TPA.Commit();
329 IsCorrect = false;
330 break;
331 }
332 // Parse '('.
333 BalancedDelimiterTracker T(*this, tok::l_paren,
334 tok::annot_pragma_openmp_end);
335 IsCorrect =
336 !T.expectAndConsume(diag::err_expected_lparen_after, "initializer") &&
337 IsCorrect;
338 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
339 ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope |
340 Scope::OpenMPDirectiveScope);
341 // Parse expression.
342 Actions.ActOnOpenMPDeclareReductionInitializerStart(getCurScope(), D);
343 InitializerResult = Actions.ActOnFinishFullExpr(
344 ParseAssignmentExpression().get(), D->getLocation(),
345 /*DiscardedValue=*/true);
346 Actions.ActOnOpenMPDeclareReductionInitializerEnd(
347 D, InitializerResult.get());
348 if (InitializerResult.isInvalid() && Tok.isNot(tok::r_paren) &&
349 Tok.isNot(tok::annot_pragma_openmp_end)) {
350 TPA.Commit();
351 IsCorrect = false;
352 break;
353 }
354 IsCorrect =
355 !T.consumeClose() && IsCorrect && !InitializerResult.isInvalid();
356 }
357 }
358
359 ++I;
360 // Revert parsing if not the last type, otherwise accept it, we're done with
361 // parsing.
362 if (I != E)
363 TPA.Revert();
364 else
365 TPA.Commit();
366 }
367 return Actions.ActOnOpenMPDeclareReductionDirectiveEnd(getCurScope(), DRD,
368 IsCorrect);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000369}
370
Alexey Bataev2af33e32016-04-07 12:45:37 +0000371namespace {
372/// RAII that recreates function context for correct parsing of clauses of
373/// 'declare simd' construct.
374/// OpenMP, 2.8.2 declare simd Construct
375/// The expressions appearing in the clauses of this directive are evaluated in
376/// the scope of the arguments of the function declaration or definition.
377class FNContextRAII final {
378 Parser &P;
379 Sema::CXXThisScopeRAII *ThisScope;
380 Parser::ParseScope *TempScope;
381 Parser::ParseScope *FnScope;
382 bool HasTemplateScope = false;
383 bool HasFunScope = false;
384 FNContextRAII() = delete;
385 FNContextRAII(const FNContextRAII &) = delete;
386 FNContextRAII &operator=(const FNContextRAII &) = delete;
387
388public:
389 FNContextRAII(Parser &P, Parser::DeclGroupPtrTy Ptr) : P(P) {
390 Decl *D = *Ptr.get().begin();
391 NamedDecl *ND = dyn_cast<NamedDecl>(D);
392 RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext());
393 Sema &Actions = P.getActions();
394
395 // Allow 'this' within late-parsed attributes.
396 ThisScope = new Sema::CXXThisScopeRAII(Actions, RD, /*TypeQuals=*/0,
397 ND && ND->isCXXInstanceMember());
398
399 // If the Decl is templatized, add template parameters to scope.
400 HasTemplateScope = D->isTemplateDecl();
401 TempScope =
402 new Parser::ParseScope(&P, Scope::TemplateParamScope, HasTemplateScope);
403 if (HasTemplateScope)
404 Actions.ActOnReenterTemplateScope(Actions.getCurScope(), D);
405
406 // If the Decl is on a function, add function parameters to the scope.
407 HasFunScope = D->isFunctionOrFunctionTemplate();
408 FnScope = new Parser::ParseScope(&P, Scope::FnScope | Scope::DeclScope,
409 HasFunScope);
410 if (HasFunScope)
411 Actions.ActOnReenterFunctionContext(Actions.getCurScope(), D);
412 }
413 ~FNContextRAII() {
414 if (HasFunScope) {
415 P.getActions().ActOnExitFunctionContext();
416 FnScope->Exit(); // Pop scope, and remove Decls from IdResolver
417 }
418 if (HasTemplateScope)
419 TempScope->Exit();
420 delete FnScope;
421 delete TempScope;
422 delete ThisScope;
423 }
424};
425} // namespace
426
Alexey Bataevd93d3762016-04-12 09:35:56 +0000427/// Parses clauses for 'declare simd' directive.
428/// clause:
429/// 'inbranch' | 'notinbranch'
430/// 'simdlen' '(' <expr> ')'
431/// { 'uniform' '(' <argument_list> ')' }
432/// { 'aligned '(' <argument_list> [ ':' <alignment> ] ')' }
Alexey Bataevecba70f2016-04-12 11:02:11 +0000433/// { 'linear '(' <argument_list> [ ':' <step> ] ')' }
434static bool parseDeclareSimdClauses(
435 Parser &P, OMPDeclareSimdDeclAttr::BranchStateTy &BS, ExprResult &SimdLen,
436 SmallVectorImpl<Expr *> &Uniforms, SmallVectorImpl<Expr *> &Aligneds,
437 SmallVectorImpl<Expr *> &Alignments, SmallVectorImpl<Expr *> &Linears,
438 SmallVectorImpl<unsigned> &LinModifiers, SmallVectorImpl<Expr *> &Steps) {
Alexey Bataevd93d3762016-04-12 09:35:56 +0000439 SourceRange BSRange;
440 const Token &Tok = P.getCurToken();
441 bool IsError = false;
442 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
443 if (Tok.isNot(tok::identifier))
444 break;
445 OMPDeclareSimdDeclAttr::BranchStateTy Out;
446 IdentifierInfo *II = Tok.getIdentifierInfo();
447 StringRef ClauseName = II->getName();
448 // Parse 'inranch|notinbranch' clauses.
449 if (OMPDeclareSimdDeclAttr::ConvertStrToBranchStateTy(ClauseName, Out)) {
450 if (BS != OMPDeclareSimdDeclAttr::BS_Undefined && BS != Out) {
451 P.Diag(Tok, diag::err_omp_declare_simd_inbranch_notinbranch)
452 << ClauseName
453 << OMPDeclareSimdDeclAttr::ConvertBranchStateTyToStr(BS) << BSRange;
454 IsError = true;
455 }
456 BS = Out;
457 BSRange = SourceRange(Tok.getLocation(), Tok.getEndLoc());
458 P.ConsumeToken();
459 } else if (ClauseName.equals("simdlen")) {
460 if (SimdLen.isUsable()) {
461 P.Diag(Tok, diag::err_omp_more_one_clause)
462 << getOpenMPDirectiveName(OMPD_declare_simd) << ClauseName << 0;
463 IsError = true;
464 }
465 P.ConsumeToken();
466 SourceLocation RLoc;
467 SimdLen = P.ParseOpenMPParensExpr(ClauseName, RLoc);
468 if (SimdLen.isInvalid())
469 IsError = true;
470 } else {
471 OpenMPClauseKind CKind = getOpenMPClauseKind(ClauseName);
Alexey Bataevecba70f2016-04-12 11:02:11 +0000472 if (CKind == OMPC_uniform || CKind == OMPC_aligned ||
473 CKind == OMPC_linear) {
Alexey Bataevd93d3762016-04-12 09:35:56 +0000474 Parser::OpenMPVarListDataTy Data;
475 auto *Vars = &Uniforms;
Alexey Bataevecba70f2016-04-12 11:02:11 +0000476 if (CKind == OMPC_aligned)
Alexey Bataevd93d3762016-04-12 09:35:56 +0000477 Vars = &Aligneds;
Alexey Bataevecba70f2016-04-12 11:02:11 +0000478 else if (CKind == OMPC_linear)
479 Vars = &Linears;
Alexey Bataevd93d3762016-04-12 09:35:56 +0000480
481 P.ConsumeToken();
482 if (P.ParseOpenMPVarList(OMPD_declare_simd,
483 getOpenMPClauseKind(ClauseName), *Vars, Data))
484 IsError = true;
485 if (CKind == OMPC_aligned)
486 Alignments.append(Aligneds.size() - Alignments.size(), Data.TailExpr);
Alexey Bataevecba70f2016-04-12 11:02:11 +0000487 else if (CKind == OMPC_linear) {
488 if (P.getActions().CheckOpenMPLinearModifier(Data.LinKind,
489 Data.DepLinMapLoc))
490 Data.LinKind = OMPC_LINEAR_val;
491 LinModifiers.append(Linears.size() - LinModifiers.size(),
492 Data.LinKind);
493 Steps.append(Linears.size() - Steps.size(), Data.TailExpr);
494 }
Alexey Bataevd93d3762016-04-12 09:35:56 +0000495 } else
496 // TODO: add parsing of other clauses.
497 break;
498 }
499 // Skip ',' if any.
500 if (Tok.is(tok::comma))
501 P.ConsumeToken();
502 }
503 return IsError;
504}
505
Alexey Bataev2af33e32016-04-07 12:45:37 +0000506/// Parse clauses for '#pragma omp declare simd'.
507Parser::DeclGroupPtrTy
508Parser::ParseOMPDeclareSimdClauses(Parser::DeclGroupPtrTy Ptr,
509 CachedTokens &Toks, SourceLocation Loc) {
510 PP.EnterToken(Tok);
511 PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
512 // Consume the previously pushed token.
513 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
514
515 FNContextRAII FnContext(*this, Ptr);
516 OMPDeclareSimdDeclAttr::BranchStateTy BS =
517 OMPDeclareSimdDeclAttr::BS_Undefined;
518 ExprResult Simdlen;
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000519 SmallVector<Expr *, 4> Uniforms;
Alexey Bataevd93d3762016-04-12 09:35:56 +0000520 SmallVector<Expr *, 4> Aligneds;
521 SmallVector<Expr *, 4> Alignments;
Alexey Bataevecba70f2016-04-12 11:02:11 +0000522 SmallVector<Expr *, 4> Linears;
523 SmallVector<unsigned, 4> LinModifiers;
524 SmallVector<Expr *, 4> Steps;
525 bool IsError =
526 parseDeclareSimdClauses(*this, BS, Simdlen, Uniforms, Aligneds,
527 Alignments, Linears, LinModifiers, Steps);
Alexey Bataev2af33e32016-04-07 12:45:37 +0000528 // Need to check for extra tokens.
529 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
530 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
531 << getOpenMPDirectiveName(OMPD_declare_simd);
532 while (Tok.isNot(tok::annot_pragma_openmp_end))
533 ConsumeAnyToken();
534 }
535 // Skip the last annot_pragma_openmp_end.
Richard Smithaf3b3252017-05-18 19:21:48 +0000536 SourceLocation EndLoc = ConsumeAnnotationToken();
Alexey Bataevd93d3762016-04-12 09:35:56 +0000537 if (!IsError) {
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000538 return Actions.ActOnOpenMPDeclareSimdDirective(
Alexey Bataevecba70f2016-04-12 11:02:11 +0000539 Ptr, BS, Simdlen.get(), Uniforms, Aligneds, Alignments, Linears,
540 LinModifiers, Steps, SourceRange(Loc, EndLoc));
Alexey Bataevd93d3762016-04-12 09:35:56 +0000541 }
Alexey Bataev2af33e32016-04-07 12:45:37 +0000542 return Ptr;
Alexey Bataev20dfd772016-04-04 10:12:15 +0000543}
544
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000545/// \brief Parsing of declarative OpenMP directives.
546///
547/// threadprivate-directive:
548/// annot_pragma_openmp 'threadprivate' simple-variable-list
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000549/// annot_pragma_openmp_end
Alexey Bataeva769e072013-03-22 06:34:35 +0000550///
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000551/// declare-reduction-directive:
552/// annot_pragma_openmp 'declare' 'reduction' [...]
553/// annot_pragma_openmp_end
554///
Alexey Bataev587e1de2016-03-30 10:43:55 +0000555/// declare-simd-directive:
556/// annot_pragma_openmp 'declare simd' {<clause> [,]}
557/// annot_pragma_openmp_end
558/// <function declaration/definition>
559///
560Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
561 AccessSpecifier &AS, ParsedAttributesWithRange &Attrs,
562 DeclSpec::TST TagType, Decl *Tag) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000563 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +0000564 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataeva769e072013-03-22 06:34:35 +0000565
Richard Smithaf3b3252017-05-18 19:21:48 +0000566 SourceLocation Loc = ConsumeAnnotationToken();
Alexey Bataev4acb8592014-07-07 13:01:15 +0000567 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000568
569 switch (DKind) {
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000570 case OMPD_threadprivate: {
Alexey Bataeva769e072013-03-22 06:34:35 +0000571 ConsumeToken();
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000572 ThreadprivateListParserHelper Helper(this);
573 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Helper, true)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000574 // The last seen token is annot_pragma_openmp_end - need to check for
575 // extra tokens.
576 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
577 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000578 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000579 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataeva769e072013-03-22 06:34:35 +0000580 }
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000581 // Skip the last annot_pragma_openmp_end.
Richard Smithaf3b3252017-05-18 19:21:48 +0000582 ConsumeAnnotationToken();
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000583 return Actions.ActOnOpenMPThreadprivateDirective(Loc,
584 Helper.getIdentifiers());
Alexey Bataeva769e072013-03-22 06:34:35 +0000585 }
586 break;
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000587 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000588 case OMPD_declare_reduction:
589 ConsumeToken();
590 if (auto Res = ParseOpenMPDeclareReductionDirective(AS)) {
591 // The last seen token is annot_pragma_openmp_end - need to check for
592 // extra tokens.
593 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
594 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
595 << getOpenMPDirectiveName(OMPD_declare_reduction);
596 while (Tok.isNot(tok::annot_pragma_openmp_end))
597 ConsumeAnyToken();
598 }
599 // Skip the last annot_pragma_openmp_end.
Richard Smithaf3b3252017-05-18 19:21:48 +0000600 ConsumeAnnotationToken();
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000601 return Res;
602 }
603 break;
Alexey Bataev587e1de2016-03-30 10:43:55 +0000604 case OMPD_declare_simd: {
605 // The syntax is:
606 // { #pragma omp declare simd }
607 // <function-declaration-or-definition>
608 //
Alexey Bataev587e1de2016-03-30 10:43:55 +0000609 ConsumeToken();
Alexey Bataev2af33e32016-04-07 12:45:37 +0000610 CachedTokens Toks;
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000611 while(Tok.isNot(tok::annot_pragma_openmp_end)) {
612 Toks.push_back(Tok);
613 ConsumeAnyToken();
614 }
615 Toks.push_back(Tok);
616 ConsumeAnyToken();
Alexey Bataev587e1de2016-03-30 10:43:55 +0000617
618 DeclGroupPtrTy Ptr;
Alexey Bataev20dfd772016-04-04 10:12:15 +0000619 if (Tok.is(tok::annot_pragma_openmp))
Alexey Bataev587e1de2016-03-30 10:43:55 +0000620 Ptr = ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs, TagType, Tag);
Alexey Bataev20dfd772016-04-04 10:12:15 +0000621 else if (Tok.isNot(tok::r_brace) && !isEofOrEom()) {
Alexey Bataev587e1de2016-03-30 10:43:55 +0000622 // Here we expect to see some function declaration.
623 if (AS == AS_none) {
624 assert(TagType == DeclSpec::TST_unspecified);
625 MaybeParseCXX11Attributes(Attrs);
Alexey Bataev587e1de2016-03-30 10:43:55 +0000626 ParsingDeclSpec PDS(*this);
627 Ptr = ParseExternalDeclaration(Attrs, &PDS);
628 } else {
629 Ptr =
630 ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag);
631 }
632 }
633 if (!Ptr) {
634 Diag(Loc, diag::err_omp_decl_in_declare_simd);
635 return DeclGroupPtrTy();
636 }
Alexey Bataev2af33e32016-04-07 12:45:37 +0000637 return ParseOMPDeclareSimdClauses(Ptr, Toks, Loc);
Alexey Bataev587e1de2016-03-30 10:43:55 +0000638 }
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000639 case OMPD_declare_target: {
640 SourceLocation DTLoc = ConsumeAnyToken();
641 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000642 // OpenMP 4.5 syntax with list of entities.
643 llvm::SmallSetVector<const NamedDecl*, 16> SameDirectiveDecls;
644 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
645 OMPDeclareTargetDeclAttr::MapTypeTy MT =
646 OMPDeclareTargetDeclAttr::MT_To;
647 if (Tok.is(tok::identifier)) {
648 IdentifierInfo *II = Tok.getIdentifierInfo();
649 StringRef ClauseName = II->getName();
650 // Parse 'to|link' clauses.
651 if (!OMPDeclareTargetDeclAttr::ConvertStrToMapTypeTy(ClauseName,
652 MT)) {
653 Diag(Tok, diag::err_omp_declare_target_unexpected_clause)
654 << ClauseName;
655 break;
656 }
657 ConsumeToken();
658 }
659 auto Callback = [this, MT, &SameDirectiveDecls](
660 CXXScopeSpec &SS, DeclarationNameInfo NameInfo) {
661 Actions.ActOnOpenMPDeclareTargetName(getCurScope(), SS, NameInfo, MT,
662 SameDirectiveDecls);
663 };
664 if (ParseOpenMPSimpleVarList(OMPD_declare_target, Callback, true))
665 break;
666
667 // Consume optional ','.
668 if (Tok.is(tok::comma))
669 ConsumeToken();
670 }
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000671 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000672 ConsumeAnyToken();
673 return DeclGroupPtrTy();
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000674 }
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000675
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000676 // Skip the last annot_pragma_openmp_end.
677 ConsumeAnyToken();
678
679 if (!Actions.ActOnStartOpenMPDeclareTargetDirective(DTLoc))
680 return DeclGroupPtrTy();
681
682 DKind = ParseOpenMPDirectiveKind(*this);
683 while (DKind != OMPD_end_declare_target && DKind != OMPD_declare_target &&
684 Tok.isNot(tok::eof) && Tok.isNot(tok::r_brace)) {
685 ParsedAttributesWithRange attrs(AttrFactory);
686 MaybeParseCXX11Attributes(attrs);
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000687 ParseExternalDeclaration(attrs);
688 if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
689 TentativeParsingAction TPA(*this);
Richard Smithaf3b3252017-05-18 19:21:48 +0000690 ConsumeAnnotationToken();
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000691 DKind = ParseOpenMPDirectiveKind(*this);
692 if (DKind != OMPD_end_declare_target)
693 TPA.Revert();
694 else
695 TPA.Commit();
696 }
697 }
698
699 if (DKind == OMPD_end_declare_target) {
700 ConsumeAnyToken();
701 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
702 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
703 << getOpenMPDirectiveName(OMPD_end_declare_target);
704 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
705 }
706 // Skip the last annot_pragma_openmp_end.
707 ConsumeAnyToken();
708 } else {
709 Diag(Tok, diag::err_expected_end_declare_target);
710 Diag(DTLoc, diag::note_matching) << "'#pragma omp declare target'";
711 }
712 Actions.ActOnFinishOpenMPDeclareTargetDirective();
713 return DeclGroupPtrTy();
714 }
Alexey Bataeva769e072013-03-22 06:34:35 +0000715 case OMPD_unknown:
716 Diag(Tok, diag::err_omp_unknown_directive);
717 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000718 case OMPD_parallel:
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000719 case OMPD_simd:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000720 case OMPD_task:
Alexey Bataev68446b72014-07-18 07:47:19 +0000721 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000722 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +0000723 case OMPD_taskwait:
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000724 case OMPD_taskgroup:
Alexey Bataev6125da92014-07-21 11:26:11 +0000725 case OMPD_flush:
Alexey Bataevf29276e2014-06-18 04:14:57 +0000726 case OMPD_for:
Alexander Musmanf82886e2014-09-18 05:12:34 +0000727 case OMPD_for_simd:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000728 case OMPD_sections:
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000729 case OMPD_section:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000730 case OMPD_single:
Alexander Musman80c22892014-07-17 08:54:58 +0000731 case OMPD_master:
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000732 case OMPD_ordered:
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000733 case OMPD_critical:
Alexey Bataev4acb8592014-07-07 13:01:15 +0000734 case OMPD_parallel_for:
Alexander Musmane4e893b2014-09-23 09:33:00 +0000735 case OMPD_parallel_for_simd:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000736 case OMPD_parallel_sections:
Alexey Bataev0162e452014-07-22 10:10:35 +0000737 case OMPD_atomic:
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000738 case OMPD_target:
Alexey Bataev13314bf2014-10-09 04:18:56 +0000739 case OMPD_teams:
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000740 case OMPD_cancellation_point:
Alexey Bataev80909872015-07-02 11:25:17 +0000741 case OMPD_cancel:
Samuel Antao5b0688e2015-07-22 16:02:46 +0000742 case OMPD_target_data:
Samuel Antaodf67fc42016-01-19 19:15:56 +0000743 case OMPD_target_enter_data:
Samuel Antao72590762016-01-19 20:04:50 +0000744 case OMPD_target_exit_data:
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000745 case OMPD_target_parallel:
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000746 case OMPD_target_parallel_for:
Alexey Bataev49f6e782015-12-01 04:18:41 +0000747 case OMPD_taskloop:
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000748 case OMPD_taskloop_simd:
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000749 case OMPD_distribute:
Dmitry Polukhin0b0da292016-04-06 11:38:59 +0000750 case OMPD_end_declare_target:
Samuel Antao686c70c2016-05-26 17:30:50 +0000751 case OMPD_target_update:
Carlo Bertolli9925f152016-06-27 14:55:37 +0000752 case OMPD_distribute_parallel_for:
Kelvin Li4a39add2016-07-05 05:00:15 +0000753 case OMPD_distribute_parallel_for_simd:
Kelvin Li787f3fc2016-07-06 04:45:38 +0000754 case OMPD_distribute_simd:
Kelvin Lia579b912016-07-14 02:54:56 +0000755 case OMPD_target_parallel_for_simd:
Kelvin Li986330c2016-07-20 22:57:10 +0000756 case OMPD_target_simd:
Kelvin Li02532872016-08-05 14:37:37 +0000757 case OMPD_teams_distribute:
Kelvin Li4e325f72016-10-25 12:50:55 +0000758 case OMPD_teams_distribute_simd:
Kelvin Li579e41c2016-11-30 23:51:03 +0000759 case OMPD_teams_distribute_parallel_for_simd:
Kelvin Li7ade93f2016-12-09 03:24:30 +0000760 case OMPD_teams_distribute_parallel_for:
Kelvin Libf594a52016-12-17 05:48:59 +0000761 case OMPD_target_teams:
Kelvin Li83c451e2016-12-25 04:52:54 +0000762 case OMPD_target_teams_distribute:
Kelvin Li80e8f562016-12-29 22:16:30 +0000763 case OMPD_target_teams_distribute_parallel_for:
Kelvin Li1851df52017-01-03 05:23:48 +0000764 case OMPD_target_teams_distribute_parallel_for_simd:
Kelvin Lida681182017-01-10 18:08:18 +0000765 case OMPD_target_teams_distribute_simd:
Alexey Bataeva769e072013-03-22 06:34:35 +0000766 Diag(Tok, diag::err_omp_unexpected_directive)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000767 << getOpenMPDirectiveName(DKind);
Alexey Bataeva769e072013-03-22 06:34:35 +0000768 break;
769 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000770 while (Tok.isNot(tok::annot_pragma_openmp_end))
771 ConsumeAnyToken();
772 ConsumeAnyToken();
David Blaikie0403cb12016-01-15 23:43:25 +0000773 return nullptr;
Alexey Bataeva769e072013-03-22 06:34:35 +0000774}
775
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000776/// \brief Parsing of declarative or executable OpenMP directives.
777///
778/// threadprivate-directive:
779/// annot_pragma_openmp 'threadprivate' simple-variable-list
780/// annot_pragma_openmp_end
781///
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000782/// declare-reduction-directive:
783/// annot_pragma_openmp 'declare' 'reduction' '(' <reduction_id> ':'
784/// <type> {',' <type>} ':' <expression> ')' ['initializer' '('
785/// ('omp_priv' '=' <expression>|<function_call>) ')']
786/// annot_pragma_openmp_end
787///
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000788/// executable-directive:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000789/// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' |
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000790/// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] |
791/// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' |
Alexander Musmanf82886e2014-09-18 05:12:34 +0000792/// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' |
Michael Wong65f367f2015-07-21 13:44:28 +0000793/// 'for simd' | 'parallel for simd' | 'target' | 'target data' |
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000794/// 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' |
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000795/// 'distribute' | 'target enter data' | 'target exit data' |
Samuel Antao686c70c2016-05-26 17:30:50 +0000796/// 'target parallel' | 'target parallel for' |
Kelvin Li4a39add2016-07-05 05:00:15 +0000797/// 'target update' | 'distribute parallel for' |
Kelvin Lia579b912016-07-14 02:54:56 +0000798/// 'distribute paralle for simd' | 'distribute simd' |
Kelvin Li02532872016-08-05 14:37:37 +0000799/// 'target parallel for simd' | 'target simd' |
Kelvin Li579e41c2016-11-30 23:51:03 +0000800/// 'teams distribute' | 'teams distribute simd' |
Kelvin Li7ade93f2016-12-09 03:24:30 +0000801/// 'teams distribute parallel for simd' |
Kelvin Li80e8f562016-12-29 22:16:30 +0000802/// 'teams distribute parallel for' | 'target teams' |
803/// 'target teams distribute' |
Kelvin Li1851df52017-01-03 05:23:48 +0000804/// 'target teams distribute parallel for' |
Kelvin Lida681182017-01-10 18:08:18 +0000805/// 'target teams distribute parallel for simd' |
806/// 'target teams distribute simd' {clause}
Samuel Antao72590762016-01-19 20:04:50 +0000807/// annot_pragma_openmp_end
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000808///
Alexey Bataevc4fad652016-01-13 11:18:54 +0000809StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
Jonathan Roelofsce1db6d2017-03-14 17:29:33 +0000810 AllowedConstructsKind Allowed) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000811 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +0000812 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000813 SmallVector<OMPClause *, 5> Clauses;
Alexey Bataev4ca40ed2014-05-12 04:23:46 +0000814 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1>
Alexey Bataeva55ed262014-05-28 06:15:33 +0000815 FirstClauses(OMPC_unknown + 1);
Alexander Musmana8e9d2e2014-06-03 10:16:47 +0000816 unsigned ScopeFlags =
Alexey Bataeva55ed262014-05-28 06:15:33 +0000817 Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope;
Richard Smithaf3b3252017-05-18 19:21:48 +0000818 SourceLocation Loc = ConsumeAnnotationToken(), EndLoc;
Alexey Bataev4acb8592014-07-07 13:01:15 +0000819 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000820 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
Alexey Bataev758e55e2013-09-06 18:03:48 +0000821 // Name of critical directive.
822 DeclarationNameInfo DirName;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000823 StmtResult Directive = StmtError();
Alexey Bataev68446b72014-07-18 07:47:19 +0000824 bool HasAssociatedStatement = true;
Alexey Bataev6125da92014-07-21 11:26:11 +0000825 bool FlushHasClause = false;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000826
827 switch (DKind) {
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000828 case OMPD_threadprivate: {
Alexey Bataevc4fad652016-01-13 11:18:54 +0000829 if (Allowed != ACK_Any) {
830 Diag(Tok, diag::err_omp_immediate_directive)
831 << getOpenMPDirectiveName(DKind) << 0;
832 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000833 ConsumeToken();
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000834 ThreadprivateListParserHelper Helper(this);
835 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Helper, false)) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000836 // The last seen token is annot_pragma_openmp_end - need to check for
837 // extra tokens.
838 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
839 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000840 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000841 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000842 }
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000843 DeclGroupPtrTy Res = Actions.ActOnOpenMPThreadprivateDirective(
844 Loc, Helper.getIdentifiers());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000845 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
846 }
Alp Tokerd751fa72013-12-18 19:10:49 +0000847 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000848 break;
Dmitry Polukhind69b5052016-05-09 14:59:13 +0000849 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000850 case OMPD_declare_reduction:
851 ConsumeToken();
852 if (auto Res = ParseOpenMPDeclareReductionDirective(/*AS=*/AS_none)) {
853 // The last seen token is annot_pragma_openmp_end - need to check for
854 // extra tokens.
855 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
856 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
857 << getOpenMPDirectiveName(OMPD_declare_reduction);
858 while (Tok.isNot(tok::annot_pragma_openmp_end))
859 ConsumeAnyToken();
860 }
861 ConsumeAnyToken();
862 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
863 } else
864 SkipUntil(tok::annot_pragma_openmp_end);
865 break;
Alexey Bataev6125da92014-07-21 11:26:11 +0000866 case OMPD_flush:
867 if (PP.LookAhead(0).is(tok::l_paren)) {
868 FlushHasClause = true;
869 // Push copy of the current token back to stream to properly parse
870 // pseudo-clause OMPFlushClause.
871 PP.EnterToken(Tok);
872 }
Galina Kistanova474f2ce2017-06-01 21:26:38 +0000873 LLVM_FALLTHROUGH;
Alexey Bataev68446b72014-07-18 07:47:19 +0000874 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000875 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +0000876 case OMPD_taskwait:
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000877 case OMPD_cancellation_point:
Alexey Bataev80909872015-07-02 11:25:17 +0000878 case OMPD_cancel:
Samuel Antaodf67fc42016-01-19 19:15:56 +0000879 case OMPD_target_enter_data:
Samuel Antao72590762016-01-19 20:04:50 +0000880 case OMPD_target_exit_data:
Samuel Antao686c70c2016-05-26 17:30:50 +0000881 case OMPD_target_update:
Alexey Bataevc4fad652016-01-13 11:18:54 +0000882 if (Allowed == ACK_StatementsOpenMPNonStandalone) {
Alexey Bataev68446b72014-07-18 07:47:19 +0000883 Diag(Tok, diag::err_omp_immediate_directive)
Alexey Bataeveb482352015-12-18 05:05:56 +0000884 << getOpenMPDirectiveName(DKind) << 0;
Alexey Bataev68446b72014-07-18 07:47:19 +0000885 }
886 HasAssociatedStatement = false;
Alexey Bataev6125da92014-07-21 11:26:11 +0000887 // Fall through for further analysis.
Galina Kistanova474f2ce2017-06-01 21:26:38 +0000888 LLVM_FALLTHROUGH;
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000889 case OMPD_parallel:
Alexey Bataevf29276e2014-06-18 04:14:57 +0000890 case OMPD_simd:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000891 case OMPD_for:
Alexander Musmanf82886e2014-09-18 05:12:34 +0000892 case OMPD_for_simd:
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000893 case OMPD_sections:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000894 case OMPD_single:
Alexey Bataev4acb8592014-07-07 13:01:15 +0000895 case OMPD_section:
Alexander Musman80c22892014-07-17 08:54:58 +0000896 case OMPD_master:
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000897 case OMPD_critical:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000898 case OMPD_parallel_for:
Alexander Musmane4e893b2014-09-23 09:33:00 +0000899 case OMPD_parallel_for_simd:
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000900 case OMPD_parallel_sections:
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000901 case OMPD_task:
Alexey Bataev0162e452014-07-22 10:10:35 +0000902 case OMPD_ordered:
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000903 case OMPD_atomic:
Alexey Bataev13314bf2014-10-09 04:18:56 +0000904 case OMPD_target:
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000905 case OMPD_teams:
Michael Wong65f367f2015-07-21 13:44:28 +0000906 case OMPD_taskgroup:
Alexey Bataev49f6e782015-12-01 04:18:41 +0000907 case OMPD_target_data:
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000908 case OMPD_target_parallel:
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000909 case OMPD_target_parallel_for:
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000910 case OMPD_taskloop:
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000911 case OMPD_taskloop_simd:
Carlo Bertolli9925f152016-06-27 14:55:37 +0000912 case OMPD_distribute:
Kelvin Li4a39add2016-07-05 05:00:15 +0000913 case OMPD_distribute_parallel_for:
Kelvin Li787f3fc2016-07-06 04:45:38 +0000914 case OMPD_distribute_parallel_for_simd:
Kelvin Lia579b912016-07-14 02:54:56 +0000915 case OMPD_distribute_simd:
Kelvin Li986330c2016-07-20 22:57:10 +0000916 case OMPD_target_parallel_for_simd:
Kelvin Li02532872016-08-05 14:37:37 +0000917 case OMPD_target_simd:
Kelvin Li4e325f72016-10-25 12:50:55 +0000918 case OMPD_teams_distribute:
Kelvin Li579e41c2016-11-30 23:51:03 +0000919 case OMPD_teams_distribute_simd:
Kelvin Li7ade93f2016-12-09 03:24:30 +0000920 case OMPD_teams_distribute_parallel_for_simd:
Kelvin Libf594a52016-12-17 05:48:59 +0000921 case OMPD_teams_distribute_parallel_for:
Kelvin Li83c451e2016-12-25 04:52:54 +0000922 case OMPD_target_teams:
Kelvin Li80e8f562016-12-29 22:16:30 +0000923 case OMPD_target_teams_distribute:
Kelvin Li1851df52017-01-03 05:23:48 +0000924 case OMPD_target_teams_distribute_parallel_for:
Kelvin Lida681182017-01-10 18:08:18 +0000925 case OMPD_target_teams_distribute_parallel_for_simd:
926 case OMPD_target_teams_distribute_simd: {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000927 ConsumeToken();
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000928 // Parse directive name of the 'critical' directive if any.
929 if (DKind == OMPD_critical) {
930 BalancedDelimiterTracker T(*this, tok::l_paren,
931 tok::annot_pragma_openmp_end);
932 if (!T.consumeOpen()) {
933 if (Tok.isAnyIdentifier()) {
934 DirName =
935 DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation());
936 ConsumeAnyToken();
937 } else {
938 Diag(Tok, diag::err_omp_expected_identifier_for_critical);
939 }
940 T.consumeClose();
941 }
Alexey Bataev80909872015-07-02 11:25:17 +0000942 } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000943 CancelRegion = ParseOpenMPDirectiveKind(*this);
944 if (Tok.isNot(tok::annot_pragma_openmp_end))
945 ConsumeToken();
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000946 }
Alexey Bataev758e55e2013-09-06 18:03:48 +0000947
Alexey Bataevf29276e2014-06-18 04:14:57 +0000948 if (isOpenMPLoopDirective(DKind))
949 ScopeFlags |= Scope::OpenMPLoopDirectiveScope;
950 if (isOpenMPSimdDirective(DKind))
951 ScopeFlags |= Scope::OpenMPSimdDirectiveScope;
952 ParseScope OMPDirectiveScope(this, ScopeFlags);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000953 Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000954
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000955 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataev6125da92014-07-21 11:26:11 +0000956 OpenMPClauseKind CKind =
957 Tok.isAnnotation()
958 ? OMPC_unknown
959 : FlushHasClause ? OMPC_flush
960 : getOpenMPClauseKind(PP.getSpelling(Tok));
Alexey Bataevaac108a2015-06-23 04:51:00 +0000961 Actions.StartOpenMPClause(CKind);
Alexey Bataev6125da92014-07-21 11:26:11 +0000962 FlushHasClause = false;
Alexey Bataeva55ed262014-05-28 06:15:33 +0000963 OMPClause *Clause =
964 ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000965 FirstClauses[CKind].setInt(true);
966 if (Clause) {
967 FirstClauses[CKind].setPointer(Clause);
968 Clauses.push_back(Clause);
969 }
970
971 // Skip ',' if any.
972 if (Tok.is(tok::comma))
973 ConsumeToken();
Alexey Bataevaac108a2015-06-23 04:51:00 +0000974 Actions.EndOpenMPClause();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000975 }
976 // End location of the directive.
977 EndLoc = Tok.getLocation();
978 // Consume final annot_pragma_openmp_end.
Richard Smithaf3b3252017-05-18 19:21:48 +0000979 ConsumeAnnotationToken();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000980
Alexey Bataeveb482352015-12-18 05:05:56 +0000981 // OpenMP [2.13.8, ordered Construct, Syntax]
982 // If the depend clause is specified, the ordered construct is a stand-alone
983 // directive.
984 if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) {
Alexey Bataevc4fad652016-01-13 11:18:54 +0000985 if (Allowed == ACK_StatementsOpenMPNonStandalone) {
Alexey Bataeveb482352015-12-18 05:05:56 +0000986 Diag(Loc, diag::err_omp_immediate_directive)
987 << getOpenMPDirectiveName(DKind) << 1
988 << getOpenMPClauseName(OMPC_depend);
989 }
990 HasAssociatedStatement = false;
991 }
992
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000993 StmtResult AssociatedStmt;
Alexey Bataev68446b72014-07-18 07:47:19 +0000994 if (HasAssociatedStatement) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000995 // The body is a block scope like in Lambdas and Blocks.
996 Sema::CompoundScopeRAII CompoundScope(Actions);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000997 Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000998 Actions.ActOnStartOfCompoundStmt();
999 // Parse statement
1000 AssociatedStmt = ParseStatement();
1001 Actions.ActOnFinishOfCompoundStmt();
Alexey Bataeva8d4a5432015-04-02 07:48:16 +00001002 AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001003 }
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001004 Directive = Actions.ActOnOpenMPExecutableDirective(
1005 DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc,
1006 EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001007
1008 // Exit scope.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001009 Actions.EndOpenMPDSABlock(Directive.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001010 OMPDirectiveScope.Exit();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001011 break;
Alexey Bataeva55ed262014-05-28 06:15:33 +00001012 }
Alexey Bataev587e1de2016-03-30 10:43:55 +00001013 case OMPD_declare_simd:
Dmitry Polukhin0b0da292016-04-06 11:38:59 +00001014 case OMPD_declare_target:
1015 case OMPD_end_declare_target:
Alexey Bataev587e1de2016-03-30 10:43:55 +00001016 Diag(Tok, diag::err_omp_unexpected_directive)
1017 << getOpenMPDirectiveName(DKind);
1018 SkipUntil(tok::annot_pragma_openmp_end);
1019 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001020 case OMPD_unknown:
1021 Diag(Tok, diag::err_omp_unknown_directive);
Alp Tokerd751fa72013-12-18 19:10:49 +00001022 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001023 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001024 }
1025 return Directive;
1026}
1027
Dmitry Polukhind69b5052016-05-09 14:59:13 +00001028// Parses simple list:
1029// simple-variable-list:
1030// '(' id-expression {, id-expression} ')'
1031//
1032bool Parser::ParseOpenMPSimpleVarList(
1033 OpenMPDirectiveKind Kind,
1034 const llvm::function_ref<void(CXXScopeSpec &, DeclarationNameInfo)> &
1035 Callback,
1036 bool AllowScopeSpecifier) {
Alexey Bataeva769e072013-03-22 06:34:35 +00001037 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +00001038 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001039 if (T.expectAndConsume(diag::err_expected_lparen_after,
1040 getOpenMPDirectiveName(Kind)))
1041 return true;
1042 bool IsCorrect = true;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001043 bool NoIdentIsFound = true;
Alexey Bataeva769e072013-03-22 06:34:35 +00001044
1045 // Read tokens while ')' or annot_pragma_openmp_end is not found.
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001046 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataeva769e072013-03-22 06:34:35 +00001047 CXXScopeSpec SS;
1048 SourceLocation TemplateKWLoc;
1049 UnqualifiedId Name;
1050 // Read var name.
1051 Token PrevTok = Tok;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001052 NoIdentIsFound = false;
Alexey Bataeva769e072013-03-22 06:34:35 +00001053
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001054 if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
David Blaikieefdccaa2016-01-15 23:43:34 +00001055 ParseOptionalCXXScopeSpecifier(SS, nullptr, false)) {
Alexey Bataeva769e072013-03-22 06:34:35 +00001056 IsCorrect = false;
1057 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +00001058 StopBeforeMatch);
Richard Smith35845152017-02-07 01:37:30 +00001059 } else if (ParseUnqualifiedId(SS, false, false, false, false, nullptr,
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001060 TemplateKWLoc, Name)) {
Alexey Bataeva769e072013-03-22 06:34:35 +00001061 IsCorrect = false;
1062 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +00001063 StopBeforeMatch);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001064 } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
1065 Tok.isNot(tok::annot_pragma_openmp_end)) {
1066 IsCorrect = false;
1067 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +00001068 StopBeforeMatch);
Alp Tokerec543272013-12-24 09:48:30 +00001069 Diag(PrevTok.getLocation(), diag::err_expected)
1070 << tok::identifier
1071 << SourceRange(PrevTok.getLocation(), PrevTokLocation);
Alexey Bataeva769e072013-03-22 06:34:35 +00001072 } else {
Dmitry Polukhind69b5052016-05-09 14:59:13 +00001073 Callback(SS, Actions.GetNameFromUnqualifiedId(Name));
Alexey Bataeva769e072013-03-22 06:34:35 +00001074 }
1075 // Consume ','.
1076 if (Tok.is(tok::comma)) {
1077 ConsumeToken();
1078 }
Alexey Bataeva769e072013-03-22 06:34:35 +00001079 }
1080
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001081 if (NoIdentIsFound) {
Alp Tokerec543272013-12-24 09:48:30 +00001082 Diag(Tok, diag::err_expected) << tok::identifier;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001083 IsCorrect = false;
1084 }
1085
1086 // Parse ')'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001087 IsCorrect = !T.consumeClose() && IsCorrect;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00001088
Dmitry Polukhind69b5052016-05-09 14:59:13 +00001089 return !IsCorrect;
Alexey Bataeva769e072013-03-22 06:34:35 +00001090}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001091
1092/// \brief Parsing of OpenMP clauses.
1093///
1094/// clause:
Alexey Bataev3778b602014-07-17 07:32:53 +00001095/// if-clause | final-clause | num_threads-clause | safelen-clause |
1096/// default-clause | private-clause | firstprivate-clause | shared-clause
1097/// | linear-clause | aligned-clause | collapse-clause |
1098/// lastprivate-clause | reduction-clause | proc_bind-clause |
Alexey Bataev74ba3a52014-07-17 12:47:03 +00001099/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
Alexey Bataev67a4f222014-07-23 10:25:33 +00001100/// mergeable-clause | flush-clause | read-clause | write-clause |
Alexey Bataev66b15b52015-08-21 11:14:16 +00001101/// update-clause | capture-clause | seq_cst-clause | device-clause |
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001102/// simdlen-clause | threads-clause | simd-clause | num_teams-clause |
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001103/// thread_limit-clause | priority-clause | grainsize-clause |
Samuel Antaoec172c62016-05-26 17:49:04 +00001104/// nogroup-clause | num_tasks-clause | hint-clause | to-clause |
Alexey Bataev169d96a2017-07-18 20:17:46 +00001105/// from-clause | is_device_ptr-clause | task_reduction-clause
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001106///
1107OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
1108 OpenMPClauseKind CKind, bool FirstClause) {
Craig Topper161e4db2014-05-21 06:02:52 +00001109 OMPClause *Clause = nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001110 bool ErrorFound = false;
1111 // Check if clause is allowed for the given directive.
1112 if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
Alexey Bataeva55ed262014-05-28 06:15:33 +00001113 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
1114 << getOpenMPDirectiveName(DKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001115 ErrorFound = true;
1116 }
1117
1118 switch (CKind) {
Alexey Bataev3778b602014-07-17 07:32:53 +00001119 case OMPC_final:
Alexey Bataev568a8332014-03-06 06:15:19 +00001120 case OMPC_num_threads:
Alexey Bataev62c87d22014-03-21 04:51:18 +00001121 case OMPC_safelen:
Alexey Bataev66b15b52015-08-21 11:14:16 +00001122 case OMPC_simdlen:
Alexander Musman8bd31e62014-05-27 15:12:19 +00001123 case OMPC_collapse:
Alexey Bataev10e775f2015-07-30 11:36:16 +00001124 case OMPC_ordered:
Michael Wonge710d542015-08-07 16:16:36 +00001125 case OMPC_device:
Kelvin Li099bb8c2015-11-24 20:50:12 +00001126 case OMPC_num_teams:
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001127 case OMPC_thread_limit:
Alexey Bataeva0569352015-12-01 10:17:31 +00001128 case OMPC_priority:
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001129 case OMPC_grainsize:
Alexey Bataev382967a2015-12-08 12:06:20 +00001130 case OMPC_num_tasks:
Alexey Bataev28c75412015-12-15 08:19:24 +00001131 case OMPC_hint:
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001132 // OpenMP [2.5, Restrictions]
Alexey Bataev568a8332014-03-06 06:15:19 +00001133 // At most one num_threads clause can appear on the directive.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001134 // OpenMP [2.8.1, simd construct, Restrictions]
Alexander Musman8bd31e62014-05-27 15:12:19 +00001135 // Only one safelen clause can appear on a simd directive.
Alexey Bataev66b15b52015-08-21 11:14:16 +00001136 // Only one simdlen clause can appear on a simd directive.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001137 // Only one collapse clause can appear on a simd directive.
Michael Wonge710d542015-08-07 16:16:36 +00001138 // OpenMP [2.9.1, target data construct, Restrictions]
1139 // At most one device clause can appear on the directive.
Alexey Bataev3778b602014-07-17 07:32:53 +00001140 // OpenMP [2.11.1, task Construct, Restrictions]
1141 // At most one if clause can appear on the directive.
1142 // At most one final clause can appear on the directive.
Kelvin Li099bb8c2015-11-24 20:50:12 +00001143 // OpenMP [teams Construct, Restrictions]
1144 // At most one num_teams clause can appear on the directive.
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001145 // At most one thread_limit clause can appear on the directive.
Alexey Bataeva0569352015-12-01 10:17:31 +00001146 // OpenMP [2.9.1, task Construct, Restrictions]
1147 // At most one priority clause can appear on the directive.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001148 // OpenMP [2.9.2, taskloop Construct, Restrictions]
1149 // At most one grainsize clause can appear on the directive.
Alexey Bataev382967a2015-12-08 12:06:20 +00001150 // OpenMP [2.9.2, taskloop Construct, Restrictions]
1151 // At most one num_tasks clause can appear on the directive.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001152 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001153 Diag(Tok, diag::err_omp_more_one_clause)
1154 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +00001155 ErrorFound = true;
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001156 }
1157
Alexey Bataev10e775f2015-07-30 11:36:16 +00001158 if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren))
1159 Clause = ParseOpenMPClause(CKind);
1160 else
1161 Clause = ParseOpenMPSingleExprClause(CKind);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001162 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001163 case OMPC_default:
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001164 case OMPC_proc_bind:
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001165 // OpenMP [2.14.3.1, Restrictions]
1166 // Only a single default clause may be specified on a parallel, task or
1167 // teams directive.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001168 // OpenMP [2.5, parallel Construct, Restrictions]
1169 // At most one proc_bind clause can appear on the directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001170 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001171 Diag(Tok, diag::err_omp_more_one_clause)
1172 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +00001173 ErrorFound = true;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001174 }
1175
1176 Clause = ParseOpenMPSimpleClause(CKind);
1177 break;
Alexey Bataev56dafe82014-06-20 07:16:17 +00001178 case OMPC_schedule:
Carlo Bertollib4adf552016-01-15 18:50:31 +00001179 case OMPC_dist_schedule:
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001180 case OMPC_defaultmap:
Alexey Bataev56dafe82014-06-20 07:16:17 +00001181 // OpenMP [2.7.1, Restrictions, p. 3]
1182 // Only one schedule clause can appear on a loop directive.
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001183 // OpenMP [2.10.4, Restrictions, p. 106]
1184 // At most one defaultmap clause can appear on the directive.
Alexey Bataev56dafe82014-06-20 07:16:17 +00001185 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001186 Diag(Tok, diag::err_omp_more_one_clause)
1187 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +00001188 ErrorFound = true;
Alexey Bataev56dafe82014-06-20 07:16:17 +00001189 }
Galina Kistanova474f2ce2017-06-01 21:26:38 +00001190 LLVM_FALLTHROUGH;
Alexey Bataev56dafe82014-06-20 07:16:17 +00001191
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001192 case OMPC_if:
Alexey Bataev56dafe82014-06-20 07:16:17 +00001193 Clause = ParseOpenMPSingleExprWithArgClause(CKind);
1194 break;
Alexey Bataev236070f2014-06-20 11:19:47 +00001195 case OMPC_nowait:
Alexey Bataev7aea99a2014-07-17 12:19:31 +00001196 case OMPC_untied:
Alexey Bataev74ba3a52014-07-17 12:47:03 +00001197 case OMPC_mergeable:
Alexey Bataevf98b00c2014-07-23 02:27:21 +00001198 case OMPC_read:
Alexey Bataevdea47612014-07-23 07:46:59 +00001199 case OMPC_write:
Alexey Bataev67a4f222014-07-23 10:25:33 +00001200 case OMPC_update:
Alexey Bataev459dec02014-07-24 06:46:57 +00001201 case OMPC_capture:
Alexey Bataev82bad8b2014-07-24 08:55:34 +00001202 case OMPC_seq_cst:
Alexey Bataev346265e2015-09-25 10:37:12 +00001203 case OMPC_threads:
Alexey Bataevd14d1e62015-09-28 06:39:35 +00001204 case OMPC_simd:
Alexey Bataevb825de12015-12-07 10:51:44 +00001205 case OMPC_nogroup:
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001206 // OpenMP [2.7.1, Restrictions, p. 9]
1207 // Only one ordered clause can appear on a loop directive.
Alexey Bataev236070f2014-06-20 11:19:47 +00001208 // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
1209 // Only one nowait clause can appear on a for directive.
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001210 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001211 Diag(Tok, diag::err_omp_more_one_clause)
1212 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +00001213 ErrorFound = true;
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001214 }
1215
1216 Clause = ParseOpenMPClause(CKind);
1217 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001218 case OMPC_private:
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001219 case OMPC_firstprivate:
Alexander Musman1bb328c2014-06-04 13:06:39 +00001220 case OMPC_lastprivate:
Alexey Bataev758e55e2013-09-06 18:03:48 +00001221 case OMPC_shared:
Alexey Bataevc5e02582014-06-16 07:08:35 +00001222 case OMPC_reduction:
Alexey Bataev169d96a2017-07-18 20:17:46 +00001223 case OMPC_task_reduction:
Alexander Musman8dba6642014-04-22 13:09:42 +00001224 case OMPC_linear:
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001225 case OMPC_aligned:
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001226 case OMPC_copyin:
Alexey Bataevbae9a792014-06-27 10:37:06 +00001227 case OMPC_copyprivate:
Alexey Bataev6125da92014-07-21 11:26:11 +00001228 case OMPC_flush:
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001229 case OMPC_depend:
Kelvin Li0bff7af2015-11-23 05:32:03 +00001230 case OMPC_map:
Samuel Antao661c0902016-05-26 17:39:58 +00001231 case OMPC_to:
Samuel Antaoec172c62016-05-26 17:49:04 +00001232 case OMPC_from:
Carlo Bertolli2404b172016-07-13 15:37:16 +00001233 case OMPC_use_device_ptr:
Carlo Bertolli70594e92016-07-13 17:16:49 +00001234 case OMPC_is_device_ptr:
Alexey Bataeveb482352015-12-18 05:05:56 +00001235 Clause = ParseOpenMPVarListClause(DKind, CKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001236 break;
1237 case OMPC_unknown:
1238 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +00001239 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +00001240 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001241 break;
1242 case OMPC_threadprivate:
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001243 case OMPC_uniform:
Alexey Bataeva55ed262014-05-28 06:15:33 +00001244 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
1245 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +00001246 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001247 break;
1248 }
Craig Topper161e4db2014-05-21 06:02:52 +00001249 return ErrorFound ? nullptr : Clause;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001250}
1251
Alexey Bataev2af33e32016-04-07 12:45:37 +00001252/// Parses simple expression in parens for single-expression clauses of OpenMP
1253/// constructs.
1254/// \param RLoc Returned location of right paren.
1255ExprResult Parser::ParseOpenMPParensExpr(StringRef ClauseName,
1256 SourceLocation &RLoc) {
1257 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
1258 if (T.expectAndConsume(diag::err_expected_lparen_after, ClauseName.data()))
1259 return ExprError();
1260
1261 SourceLocation ELoc = Tok.getLocation();
1262 ExprResult LHS(ParseCastExpression(
1263 /*isUnaryExpression=*/false, /*isAddressOfOperand=*/false, NotTypeCast));
1264 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
1265 Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
1266
1267 // Parse ')'.
1268 T.consumeClose();
1269
1270 RLoc = T.getCloseLocation();
1271 return Val;
1272}
1273
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001274/// \brief Parsing of OpenMP clauses with single expressions like 'final',
Alexey Bataeva0569352015-12-01 10:17:31 +00001275/// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams',
Alexey Bataev28c75412015-12-15 08:19:24 +00001276/// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001277///
Alexey Bataev3778b602014-07-17 07:32:53 +00001278/// final-clause:
1279/// 'final' '(' expression ')'
1280///
Alexey Bataev62c87d22014-03-21 04:51:18 +00001281/// num_threads-clause:
1282/// 'num_threads' '(' expression ')'
1283///
1284/// safelen-clause:
1285/// 'safelen' '(' expression ')'
1286///
Alexey Bataev66b15b52015-08-21 11:14:16 +00001287/// simdlen-clause:
1288/// 'simdlen' '(' expression ')'
1289///
Alexander Musman8bd31e62014-05-27 15:12:19 +00001290/// collapse-clause:
1291/// 'collapse' '(' expression ')'
1292///
Alexey Bataeva0569352015-12-01 10:17:31 +00001293/// priority-clause:
1294/// 'priority' '(' expression ')'
1295///
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001296/// grainsize-clause:
1297/// 'grainsize' '(' expression ')'
1298///
Alexey Bataev382967a2015-12-08 12:06:20 +00001299/// num_tasks-clause:
1300/// 'num_tasks' '(' expression ')'
1301///
Alexey Bataev28c75412015-12-15 08:19:24 +00001302/// hint-clause:
1303/// 'hint' '(' expression ')'
1304///
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001305OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
1306 SourceLocation Loc = ConsumeToken();
Alexey Bataev2af33e32016-04-07 12:45:37 +00001307 SourceLocation LLoc = Tok.getLocation();
1308 SourceLocation RLoc;
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001309
Alexey Bataev2af33e32016-04-07 12:45:37 +00001310 ExprResult Val = ParseOpenMPParensExpr(getOpenMPClauseName(Kind), RLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001311
1312 if (Val.isInvalid())
Craig Topper161e4db2014-05-21 06:02:52 +00001313 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001314
Alexey Bataev2af33e32016-04-07 12:45:37 +00001315 return Actions.ActOnOpenMPSingleExprClause(Kind, Val.get(), Loc, LLoc, RLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001316}
1317
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001318/// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001319///
1320/// default-clause:
1321/// 'default' '(' 'none' | 'shared' ')
1322///
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001323/// proc_bind-clause:
1324/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
1325///
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001326OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
1327 SourceLocation Loc = Tok.getLocation();
1328 SourceLocation LOpen = ConsumeToken();
1329 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +00001330 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001331 if (T.expectAndConsume(diag::err_expected_lparen_after,
1332 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +00001333 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001334
Alexey Bataeva55ed262014-05-28 06:15:33 +00001335 unsigned Type = getOpenMPSimpleClauseType(
1336 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001337 SourceLocation TypeLoc = Tok.getLocation();
1338 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1339 Tok.isNot(tok::annot_pragma_openmp_end))
1340 ConsumeAnyToken();
1341
1342 // Parse ')'.
1343 T.consumeClose();
1344
1345 return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
1346 Tok.getLocation());
1347}
1348
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001349/// \brief Parsing of OpenMP clauses like 'ordered'.
1350///
1351/// ordered-clause:
1352/// 'ordered'
1353///
Alexey Bataev236070f2014-06-20 11:19:47 +00001354/// nowait-clause:
1355/// 'nowait'
1356///
Alexey Bataev7aea99a2014-07-17 12:19:31 +00001357/// untied-clause:
1358/// 'untied'
1359///
Alexey Bataev74ba3a52014-07-17 12:47:03 +00001360/// mergeable-clause:
1361/// 'mergeable'
1362///
Alexey Bataevf98b00c2014-07-23 02:27:21 +00001363/// read-clause:
1364/// 'read'
1365///
Alexey Bataev346265e2015-09-25 10:37:12 +00001366/// threads-clause:
1367/// 'threads'
1368///
Alexey Bataevd14d1e62015-09-28 06:39:35 +00001369/// simd-clause:
1370/// 'simd'
1371///
Alexey Bataevb825de12015-12-07 10:51:44 +00001372/// nogroup-clause:
1373/// 'nogroup'
1374///
Alexey Bataev142e1fc2014-06-20 09:44:06 +00001375OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
1376 SourceLocation Loc = Tok.getLocation();
1377 ConsumeAnyToken();
1378
1379 return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
1380}
1381
1382
Alexey Bataev56dafe82014-06-20 07:16:17 +00001383/// \brief Parsing of OpenMP clauses with single expressions and some additional
1384/// argument like 'schedule' or 'dist_schedule'.
1385///
1386/// schedule-clause:
Alexey Bataev6402bca2015-12-28 07:25:51 +00001387/// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ]
1388/// ')'
Alexey Bataev56dafe82014-06-20 07:16:17 +00001389///
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001390/// if-clause:
1391/// 'if' '(' [ directive-name-modifier ':' ] expression ')'
1392///
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001393/// defaultmap:
1394/// 'defaultmap' '(' modifier ':' kind ')'
1395///
Alexey Bataev56dafe82014-06-20 07:16:17 +00001396OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
1397 SourceLocation Loc = ConsumeToken();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001398 SourceLocation DelimLoc;
Alexey Bataev56dafe82014-06-20 07:16:17 +00001399 // Parse '('.
1400 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
1401 if (T.expectAndConsume(diag::err_expected_lparen_after,
1402 getOpenMPClauseName(Kind)))
1403 return nullptr;
1404
1405 ExprResult Val;
Alexey Bataev6402bca2015-12-28 07:25:51 +00001406 SmallVector<unsigned, 4> Arg;
1407 SmallVector<SourceLocation, 4> KLoc;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001408 if (Kind == OMPC_schedule) {
Alexey Bataev6402bca2015-12-28 07:25:51 +00001409 enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements };
1410 Arg.resize(NumberOfElements);
1411 KLoc.resize(NumberOfElements);
1412 Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown;
1413 Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown;
1414 Arg[ScheduleKind] = OMPC_SCHEDULE_unknown;
1415 auto KindModifier = getOpenMPSimpleClauseType(
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001416 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev6402bca2015-12-28 07:25:51 +00001417 if (KindModifier > OMPC_SCHEDULE_unknown) {
1418 // Parse 'modifier'
1419 Arg[Modifier1] = KindModifier;
1420 KLoc[Modifier1] = Tok.getLocation();
1421 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1422 Tok.isNot(tok::annot_pragma_openmp_end))
1423 ConsumeAnyToken();
1424 if (Tok.is(tok::comma)) {
1425 // Parse ',' 'modifier'
1426 ConsumeAnyToken();
1427 KindModifier = getOpenMPSimpleClauseType(
1428 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
1429 Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown
1430 ? KindModifier
Aaron Ballmanad8a1042015-12-28 15:52:46 +00001431 : (unsigned)OMPC_SCHEDULE_unknown;
Alexey Bataev6402bca2015-12-28 07:25:51 +00001432 KLoc[Modifier2] = Tok.getLocation();
1433 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1434 Tok.isNot(tok::annot_pragma_openmp_end))
1435 ConsumeAnyToken();
1436 }
1437 // Parse ':'
1438 if (Tok.is(tok::colon))
1439 ConsumeAnyToken();
1440 else
1441 Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier";
1442 KindModifier = getOpenMPSimpleClauseType(
1443 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
1444 }
1445 Arg[ScheduleKind] = KindModifier;
1446 KLoc[ScheduleKind] = Tok.getLocation();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001447 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1448 Tok.isNot(tok::annot_pragma_openmp_end))
1449 ConsumeAnyToken();
Alexey Bataev6402bca2015-12-28 07:25:51 +00001450 if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static ||
1451 Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic ||
1452 Arg[ScheduleKind] == OMPC_SCHEDULE_guided) &&
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001453 Tok.is(tok::comma))
1454 DelimLoc = ConsumeAnyToken();
Carlo Bertollib4adf552016-01-15 18:50:31 +00001455 } else if (Kind == OMPC_dist_schedule) {
1456 Arg.push_back(getOpenMPSimpleClauseType(
1457 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
1458 KLoc.push_back(Tok.getLocation());
1459 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1460 Tok.isNot(tok::annot_pragma_openmp_end))
1461 ConsumeAnyToken();
1462 if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma))
1463 DelimLoc = ConsumeAnyToken();
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001464 } else if (Kind == OMPC_defaultmap) {
1465 // Get a defaultmap modifier
1466 Arg.push_back(getOpenMPSimpleClauseType(
1467 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
1468 KLoc.push_back(Tok.getLocation());
1469 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1470 Tok.isNot(tok::annot_pragma_openmp_end))
1471 ConsumeAnyToken();
1472 // Parse ':'
1473 if (Tok.is(tok::colon))
1474 ConsumeAnyToken();
1475 else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown)
1476 Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier";
1477 // Get a defaultmap kind
1478 Arg.push_back(getOpenMPSimpleClauseType(
1479 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
1480 KLoc.push_back(Tok.getLocation());
1481 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1482 Tok.isNot(tok::annot_pragma_openmp_end))
1483 ConsumeAnyToken();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001484 } else {
1485 assert(Kind == OMPC_if);
Alexey Bataev6402bca2015-12-28 07:25:51 +00001486 KLoc.push_back(Tok.getLocation());
Alexey Bataev2a6de8c2016-12-20 12:10:05 +00001487 TentativeParsingAction TPA(*this);
Alexey Bataev6402bca2015-12-28 07:25:51 +00001488 Arg.push_back(ParseOpenMPDirectiveKind(*this));
1489 if (Arg.back() != OMPD_unknown) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001490 ConsumeToken();
Alexey Bataev2a6de8c2016-12-20 12:10:05 +00001491 if (Tok.is(tok::colon) && getLangOpts().OpenMP > 40) {
1492 TPA.Commit();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001493 DelimLoc = ConsumeToken();
Alexey Bataev2a6de8c2016-12-20 12:10:05 +00001494 } else {
1495 TPA.Revert();
1496 Arg.back() = OMPD_unknown;
1497 }
1498 } else
1499 TPA.Revert();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001500 }
Alexey Bataev56dafe82014-06-20 07:16:17 +00001501
Carlo Bertollib4adf552016-01-15 18:50:31 +00001502 bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) ||
1503 (Kind == OMPC_dist_schedule && DelimLoc.isValid()) ||
1504 Kind == OMPC_if;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001505 if (NeedAnExpression) {
1506 SourceLocation ELoc = Tok.getLocation();
Alexey Bataev56dafe82014-06-20 07:16:17 +00001507 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
1508 Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001509 Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001510 }
1511
1512 // Parse ')'.
1513 T.consumeClose();
1514
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001515 if (NeedAnExpression && Val.isInvalid())
1516 return nullptr;
1517
Alexey Bataev56dafe82014-06-20 07:16:17 +00001518 return Actions.ActOnOpenMPSingleExprWithArgClause(
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001519 Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc,
Alexey Bataev56dafe82014-06-20 07:16:17 +00001520 T.getCloseLocation());
1521}
1522
Alexey Bataevc5e02582014-06-16 07:08:35 +00001523static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
1524 UnqualifiedId &ReductionId) {
1525 SourceLocation TemplateKWLoc;
1526 if (ReductionIdScopeSpec.isEmpty()) {
1527 auto OOK = OO_None;
1528 switch (P.getCurToken().getKind()) {
1529 case tok::plus:
1530 OOK = OO_Plus;
1531 break;
1532 case tok::minus:
1533 OOK = OO_Minus;
1534 break;
1535 case tok::star:
1536 OOK = OO_Star;
1537 break;
1538 case tok::amp:
1539 OOK = OO_Amp;
1540 break;
1541 case tok::pipe:
1542 OOK = OO_Pipe;
1543 break;
1544 case tok::caret:
1545 OOK = OO_Caret;
1546 break;
1547 case tok::ampamp:
1548 OOK = OO_AmpAmp;
1549 break;
1550 case tok::pipepipe:
1551 OOK = OO_PipePipe;
1552 break;
1553 default:
1554 break;
1555 }
1556 if (OOK != OO_None) {
1557 SourceLocation OpLoc = P.ConsumeToken();
Alexey Bataev23b69422014-06-18 07:08:49 +00001558 SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
Alexey Bataevc5e02582014-06-16 07:08:35 +00001559 ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
1560 return false;
1561 }
1562 }
1563 return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
1564 /*AllowDestructorName*/ false,
Richard Smith35845152017-02-07 01:37:30 +00001565 /*AllowConstructorName*/ false,
1566 /*AllowDeductionGuide*/ false,
1567 nullptr, TemplateKWLoc, ReductionId);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001568}
1569
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001570/// Parses clauses with list.
1571bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
1572 OpenMPClauseKind Kind,
1573 SmallVectorImpl<Expr *> &Vars,
1574 OpenMPVarListDataTy &Data) {
1575 UnqualifiedId UnqualifiedReductionId;
1576 bool InvalidReductionId = false;
1577 bool MapTypeModifierSpecified = false;
1578
1579 // Parse '('.
1580 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
1581 if (T.expectAndConsume(diag::err_expected_lparen_after,
1582 getOpenMPClauseName(Kind)))
1583 return true;
1584
1585 bool NeedRParenForLinear = false;
1586 BalancedDelimiterTracker LinearT(*this, tok::l_paren,
1587 tok::annot_pragma_openmp_end);
1588 // Handle reduction-identifier for reduction clause.
Alexey Bataev169d96a2017-07-18 20:17:46 +00001589 if (Kind == OMPC_reduction || Kind == OMPC_task_reduction) {
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001590 ColonProtectionRAIIObject ColonRAII(*this);
1591 if (getLangOpts().CPlusPlus)
1592 ParseOptionalCXXScopeSpecifier(Data.ReductionIdScopeSpec,
1593 /*ObjectType=*/nullptr,
1594 /*EnteringContext=*/false);
1595 InvalidReductionId = ParseReductionId(*this, Data.ReductionIdScopeSpec,
1596 UnqualifiedReductionId);
1597 if (InvalidReductionId) {
1598 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
1599 StopBeforeMatch);
1600 }
1601 if (Tok.is(tok::colon))
1602 Data.ColonLoc = ConsumeToken();
1603 else
1604 Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
1605 if (!InvalidReductionId)
1606 Data.ReductionId =
1607 Actions.GetNameFromUnqualifiedId(UnqualifiedReductionId);
1608 } else if (Kind == OMPC_depend) {
1609 // Handle dependency type for depend clause.
1610 ColonProtectionRAIIObject ColonRAII(*this);
1611 Data.DepKind =
1612 static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType(
1613 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
1614 Data.DepLinMapLoc = Tok.getLocation();
1615
1616 if (Data.DepKind == OMPC_DEPEND_unknown) {
1617 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
1618 StopBeforeMatch);
1619 } else {
1620 ConsumeToken();
1621 // Special processing for depend(source) clause.
1622 if (DKind == OMPD_ordered && Data.DepKind == OMPC_DEPEND_source) {
1623 // Parse ')'.
1624 T.consumeClose();
1625 return false;
1626 }
1627 }
1628 if (Tok.is(tok::colon))
1629 Data.ColonLoc = ConsumeToken();
1630 else {
1631 Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren
1632 : diag::warn_pragma_expected_colon)
1633 << "dependency type";
1634 }
1635 } else if (Kind == OMPC_linear) {
1636 // Try to parse modifier if any.
1637 if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) {
1638 Data.LinKind = static_cast<OpenMPLinearClauseKind>(
1639 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)));
1640 Data.DepLinMapLoc = ConsumeToken();
1641 LinearT.consumeOpen();
1642 NeedRParenForLinear = true;
1643 }
1644 } else if (Kind == OMPC_map) {
1645 // Handle map type for map clause.
1646 ColonProtectionRAIIObject ColonRAII(*this);
1647
1648 /// The map clause modifier token can be either a identifier or the C++
1649 /// delete keyword.
1650 auto &&IsMapClauseModifierToken = [](const Token &Tok) -> bool {
1651 return Tok.isOneOf(tok::identifier, tok::kw_delete);
1652 };
1653
1654 // The first identifier may be a list item, a map-type or a
1655 // map-type-modifier. The map modifier can also be delete which has the same
1656 // spelling of the C++ delete keyword.
1657 Data.MapType =
1658 IsMapClauseModifierToken(Tok)
1659 ? static_cast<OpenMPMapClauseKind>(
1660 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)))
1661 : OMPC_MAP_unknown;
1662 Data.DepLinMapLoc = Tok.getLocation();
1663 bool ColonExpected = false;
1664
1665 if (IsMapClauseModifierToken(Tok)) {
1666 if (PP.LookAhead(0).is(tok::colon)) {
1667 if (Data.MapType == OMPC_MAP_unknown)
1668 Diag(Tok, diag::err_omp_unknown_map_type);
1669 else if (Data.MapType == OMPC_MAP_always)
1670 Diag(Tok, diag::err_omp_map_type_missing);
1671 ConsumeToken();
1672 } else if (PP.LookAhead(0).is(tok::comma)) {
1673 if (IsMapClauseModifierToken(PP.LookAhead(1)) &&
1674 PP.LookAhead(2).is(tok::colon)) {
1675 Data.MapTypeModifier = Data.MapType;
1676 if (Data.MapTypeModifier != OMPC_MAP_always) {
1677 Diag(Tok, diag::err_omp_unknown_map_type_modifier);
1678 Data.MapTypeModifier = OMPC_MAP_unknown;
1679 } else
1680 MapTypeModifierSpecified = true;
1681
1682 ConsumeToken();
1683 ConsumeToken();
1684
1685 Data.MapType =
1686 IsMapClauseModifierToken(Tok)
1687 ? static_cast<OpenMPMapClauseKind>(
1688 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)))
1689 : OMPC_MAP_unknown;
1690 if (Data.MapType == OMPC_MAP_unknown ||
1691 Data.MapType == OMPC_MAP_always)
1692 Diag(Tok, diag::err_omp_unknown_map_type);
1693 ConsumeToken();
1694 } else {
1695 Data.MapType = OMPC_MAP_tofrom;
1696 Data.IsMapTypeImplicit = true;
1697 }
Carlo Bertollid8844b92017-05-03 15:28:48 +00001698 } else if (IsMapClauseModifierToken(PP.LookAhead(0))) {
1699 if (PP.LookAhead(1).is(tok::colon)) {
1700 Data.MapTypeModifier = Data.MapType;
1701 if (Data.MapTypeModifier != OMPC_MAP_always) {
1702 Diag(Tok, diag::err_omp_unknown_map_type_modifier);
1703 Data.MapTypeModifier = OMPC_MAP_unknown;
1704 } else
1705 MapTypeModifierSpecified = true;
1706
1707 ConsumeToken();
1708
1709 Data.MapType =
1710 IsMapClauseModifierToken(Tok)
1711 ? static_cast<OpenMPMapClauseKind>(
1712 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)))
1713 : OMPC_MAP_unknown;
1714 if (Data.MapType == OMPC_MAP_unknown ||
1715 Data.MapType == OMPC_MAP_always)
1716 Diag(Tok, diag::err_omp_unknown_map_type);
1717 ConsumeToken();
1718 } else {
1719 Data.MapType = OMPC_MAP_tofrom;
1720 Data.IsMapTypeImplicit = true;
1721 }
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001722 } else {
1723 Data.MapType = OMPC_MAP_tofrom;
1724 Data.IsMapTypeImplicit = true;
1725 }
1726 } else {
1727 Data.MapType = OMPC_MAP_tofrom;
1728 Data.IsMapTypeImplicit = true;
1729 }
1730
1731 if (Tok.is(tok::colon))
1732 Data.ColonLoc = ConsumeToken();
1733 else if (ColonExpected)
1734 Diag(Tok, diag::warn_pragma_expected_colon) << "map type";
1735 }
1736
Alexey Bataev169d96a2017-07-18 20:17:46 +00001737 bool IsComma = (Kind != OMPC_reduction && Kind != OMPC_task_reduction &&
1738 Kind != OMPC_depend && Kind != OMPC_map) ||
1739 (Kind == OMPC_reduction && !InvalidReductionId) ||
1740 (Kind == OMPC_map && Data.MapType != OMPC_MAP_unknown &&
1741 (!MapTypeModifierSpecified ||
1742 Data.MapTypeModifier == OMPC_MAP_always)) ||
1743 (Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown);
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001744 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
1745 while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
1746 Tok.isNot(tok::annot_pragma_openmp_end))) {
1747 ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
1748 // Parse variable
1749 ExprResult VarExpr =
1750 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
1751 if (VarExpr.isUsable())
1752 Vars.push_back(VarExpr.get());
1753 else {
1754 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1755 StopBeforeMatch);
1756 }
1757 // Skip ',' if any
1758 IsComma = Tok.is(tok::comma);
1759 if (IsComma)
1760 ConsumeToken();
1761 else if (Tok.isNot(tok::r_paren) &&
1762 Tok.isNot(tok::annot_pragma_openmp_end) &&
1763 (!MayHaveTail || Tok.isNot(tok::colon)))
1764 Diag(Tok, diag::err_omp_expected_punc)
1765 << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
1766 : getOpenMPClauseName(Kind))
1767 << (Kind == OMPC_flush);
1768 }
1769
1770 // Parse ')' for linear clause with modifier.
1771 if (NeedRParenForLinear)
1772 LinearT.consumeClose();
1773
1774 // Parse ':' linear-step (or ':' alignment).
1775 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
1776 if (MustHaveTail) {
1777 Data.ColonLoc = Tok.getLocation();
1778 SourceLocation ELoc = ConsumeToken();
1779 ExprResult Tail = ParseAssignmentExpression();
1780 Tail = Actions.ActOnFinishFullExpr(Tail.get(), ELoc);
1781 if (Tail.isUsable())
1782 Data.TailExpr = Tail.get();
1783 else
1784 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1785 StopBeforeMatch);
1786 }
1787
1788 // Parse ')'.
1789 T.consumeClose();
1790 if ((Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown &&
1791 Vars.empty()) ||
1792 (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) ||
1793 (MustHaveTail && !Data.TailExpr) || InvalidReductionId)
1794 return true;
1795 return false;
1796}
1797
Alexander Musman1bb328c2014-06-04 13:06:39 +00001798/// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
Alexey Bataev169d96a2017-07-18 20:17:46 +00001799/// 'shared', 'copyin', 'copyprivate', 'flush', 'reduction' or 'task_reduction'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001800///
1801/// private-clause:
1802/// 'private' '(' list ')'
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001803/// firstprivate-clause:
1804/// 'firstprivate' '(' list ')'
Alexander Musman1bb328c2014-06-04 13:06:39 +00001805/// lastprivate-clause:
1806/// 'lastprivate' '(' list ')'
Alexey Bataev758e55e2013-09-06 18:03:48 +00001807/// shared-clause:
1808/// 'shared' '(' list ')'
Alexander Musman8dba6642014-04-22 13:09:42 +00001809/// linear-clause:
Alexey Bataev182227b2015-08-20 10:54:39 +00001810/// 'linear' '(' linear-list [ ':' linear-step ] ')'
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001811/// aligned-clause:
1812/// 'aligned' '(' list [ ':' alignment ] ')'
Alexey Bataevc5e02582014-06-16 07:08:35 +00001813/// reduction-clause:
1814/// 'reduction' '(' reduction-identifier ':' list ')'
Alexey Bataev169d96a2017-07-18 20:17:46 +00001815/// task_reduction-clause:
1816/// 'task_reduction' '(' reduction-identifier ':' list ')'
Alexey Bataev6125da92014-07-21 11:26:11 +00001817/// copyprivate-clause:
1818/// 'copyprivate' '(' list ')'
1819/// flush-clause:
1820/// 'flush' '(' list ')'
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001821/// depend-clause:
Alexey Bataeveb482352015-12-18 05:05:56 +00001822/// 'depend' '(' in | out | inout : list | source ')'
Kelvin Li0bff7af2015-11-23 05:32:03 +00001823/// map-clause:
1824/// 'map' '(' [ [ always , ]
1825/// to | from | tofrom | alloc | release | delete ':' ] list ')';
Samuel Antao661c0902016-05-26 17:39:58 +00001826/// to-clause:
1827/// 'to' '(' list ')'
Samuel Antaoec172c62016-05-26 17:49:04 +00001828/// from-clause:
1829/// 'from' '(' list ')'
Carlo Bertolli2404b172016-07-13 15:37:16 +00001830/// use_device_ptr-clause:
1831/// 'use_device_ptr' '(' list ')'
Carlo Bertolli70594e92016-07-13 17:16:49 +00001832/// is_device_ptr-clause:
1833/// 'is_device_ptr' '(' list ')'
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001834///
Alexey Bataev182227b2015-08-20 10:54:39 +00001835/// For 'linear' clause linear-list may have the following forms:
1836/// list
1837/// modifier(list)
1838/// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++).
Alexey Bataeveb482352015-12-18 05:05:56 +00001839OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
1840 OpenMPClauseKind Kind) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001841 SourceLocation Loc = Tok.getLocation();
1842 SourceLocation LOpen = ConsumeToken();
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001843 SmallVector<Expr *, 4> Vars;
1844 OpenMPVarListDataTy Data;
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001845
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001846 if (ParseOpenMPVarList(DKind, Kind, Vars, Data))
Craig Topper161e4db2014-05-21 06:02:52 +00001847 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001848
Alexey Bataevc5e02582014-06-16 07:08:35 +00001849 return Actions.ActOnOpenMPVarListClause(
Alexey Bataeve48a5fc2016-04-12 05:28:34 +00001850 Kind, Vars, Data.TailExpr, Loc, LOpen, Data.ColonLoc, Tok.getLocation(),
1851 Data.ReductionIdScopeSpec, Data.ReductionId, Data.DepKind, Data.LinKind,
1852 Data.MapTypeModifier, Data.MapType, Data.IsMapTypeImplicit,
1853 Data.DepLinMapLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001854}
1855