clang 22.0.0git
SemaOpenACCClause.cpp
Go to the documentation of this file.
1//===--- SemaOpenACCClause.cpp - Semantic Analysis for OpenACC clause -----===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file implements semantic analysis for OpenACC clauses.
10///
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/DeclCXX.h"
14#include "clang/AST/ExprCXX.h"
19
20using namespace clang;
21
22namespace {
23bool checkValidAfterDeviceType(
24 SemaOpenACC &S, const OpenACCDeviceTypeClause &DeviceTypeClause,
25 const SemaOpenACC::OpenACCParsedClause &NewClause) {
26 // OpenACC3.3: Section 2.4: Clauses that precede any device_type clause are
27 // default clauses. Clauses that follow a device_type clause up to the end of
28 // the directive or up to the next device_type clause are device-specific
29 // clauses for the device types specified in the device_type argument.
30 //
31 // The above implies that despite what the individual text says, these are
32 // valid.
33 if (NewClause.getClauseKind() == OpenACCClauseKind::DType ||
34 NewClause.getClauseKind() == OpenACCClauseKind::DeviceType)
35 return false;
36
37 // Implement check from OpenACC3.3: section 2.5.4:
38 // Only the async, wait, num_gangs, num_workers, and vector_length clauses may
39 // follow a device_type clause.
40 if (isOpenACCComputeDirectiveKind(NewClause.getDirectiveKind())) {
41 switch (NewClause.getClauseKind()) {
42 case OpenACCClauseKind::Async:
43 case OpenACCClauseKind::Wait:
44 case OpenACCClauseKind::NumGangs:
45 case OpenACCClauseKind::NumWorkers:
46 case OpenACCClauseKind::VectorLength:
47 return false;
48 default:
49 break;
50 }
51 } else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Loop) {
52 // Implement check from OpenACC3.3: section 2.9:
53 // Only the collapse, gang, worker, vector, seq, independent, auto, and tile
54 // clauses may follow a device_type clause.
55 switch (NewClause.getClauseKind()) {
56 case OpenACCClauseKind::Collapse:
57 case OpenACCClauseKind::Gang:
58 case OpenACCClauseKind::Worker:
59 case OpenACCClauseKind::Vector:
60 case OpenACCClauseKind::Seq:
61 case OpenACCClauseKind::Independent:
62 case OpenACCClauseKind::Auto:
63 case OpenACCClauseKind::Tile:
64 return false;
65 default:
66 break;
67 }
68 } else if (isOpenACCCombinedDirectiveKind(NewClause.getDirectiveKind())) {
69 // This seems like it should be the union of 2.9 and 2.5.4 from above.
70 switch (NewClause.getClauseKind()) {
71 case OpenACCClauseKind::Async:
72 case OpenACCClauseKind::Wait:
73 case OpenACCClauseKind::NumGangs:
74 case OpenACCClauseKind::NumWorkers:
75 case OpenACCClauseKind::VectorLength:
76 case OpenACCClauseKind::Collapse:
77 case OpenACCClauseKind::Gang:
78 case OpenACCClauseKind::Worker:
79 case OpenACCClauseKind::Vector:
80 case OpenACCClauseKind::Seq:
81 case OpenACCClauseKind::Independent:
82 case OpenACCClauseKind::Auto:
83 case OpenACCClauseKind::Tile:
84 return false;
85 default:
86 break;
87 }
88 } else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Data) {
89 // OpenACC3.3 section 2.6.5: Only the async and wait clauses may follow a
90 // device_type clause.
91 switch (NewClause.getClauseKind()) {
92 case OpenACCClauseKind::Async:
93 case OpenACCClauseKind::Wait:
94 return false;
95 default:
96 break;
97 }
98 } else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Set ||
99 NewClause.getDirectiveKind() == OpenACCDirectiveKind::Init ||
100 NewClause.getDirectiveKind() == OpenACCDirectiveKind::Shutdown) {
101 // There are no restrictions on 'set', 'init', or 'shutdown'.
102 return false;
103 } else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
104 // OpenACC3.3 section 2.14.4: Only the async and wait clauses may follow a
105 // device_type clause.
106 switch (NewClause.getClauseKind()) {
107 case OpenACCClauseKind::Async:
108 case OpenACCClauseKind::Wait:
109 return false;
110 default:
111 break;
112 }
113 } else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Routine) {
114 // OpenACC 3.3 section 2.15: Only the 'gang', 'worker', 'vector', 'seq', and
115 // 'bind' clauses may follow a device_type clause.
116 switch (NewClause.getClauseKind()) {
117 case OpenACCClauseKind::Gang:
118 case OpenACCClauseKind::Worker:
119 case OpenACCClauseKind::Vector:
120 case OpenACCClauseKind::Seq:
121 case OpenACCClauseKind::Bind:
122 return false;
123 default:
124 break;
125 }
126 }
127 S.Diag(NewClause.getBeginLoc(), diag::err_acc_clause_after_device_type)
128 << NewClause.getClauseKind() << DeviceTypeClause.getClauseKind()
129 << NewClause.getDirectiveKind();
130 S.Diag(DeviceTypeClause.getBeginLoc(),
131 diag::note_acc_active_applies_clause_here)
132 << diag::ACCDeviceTypeApp::Active << DeviceTypeClause.getClauseKind();
133 return true;
134}
135
136// GCC looks through linkage specs, but not the other transparent declaration
137// contexts for 'declare' restrictions, so this helper function helps get us
138// through that.
139const DeclContext *removeLinkageSpecDC(const DeclContext *DC) {
140 while (isa<LinkageSpecDecl>(DC))
141 DC = DC->getParent();
142
143 return DC;
144}
145
146class SemaOpenACCClauseVisitor {
147 SemaOpenACC &SemaRef;
148 ASTContext &Ctx;
149 ArrayRef<const OpenACCClause *> ExistingClauses;
150
151 // OpenACC 3.3 2.9:
152 // A 'gang', 'worker', or 'vector' clause may not appear if a 'seq' clause
153 // appears.
154 bool
155 DiagGangWorkerVectorSeqConflict(SemaOpenACC::OpenACCParsedClause &Clause) {
156 if (Clause.getDirectiveKind() != OpenACCDirectiveKind::Loop &&
158 return false;
159 assert(Clause.getClauseKind() == OpenACCClauseKind::Gang ||
160 Clause.getClauseKind() == OpenACCClauseKind::Worker ||
161 Clause.getClauseKind() == OpenACCClauseKind::Vector);
162 const auto *Itr =
163 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCSeqClause>);
164
165 if (Itr != ExistingClauses.end()) {
166 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_cannot_combine)
167 << Clause.getClauseKind() << (*Itr)->getClauseKind()
168 << Clause.getDirectiveKind();
169 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here)
170 << (*Itr)->getClauseKind();
171
172 return true;
173 }
174 return false;
175 }
176
178 CheckModifierList(SemaOpenACC::OpenACCParsedClause &Clause,
179 OpenACCModifierKind Mods) {
180 auto CheckSingle = [=](OpenACCModifierKind CurMods,
181 OpenACCModifierKind ValidKinds,
183 if (!isOpenACCModifierBitSet(CurMods, Bit) ||
184 isOpenACCModifierBitSet(ValidKinds, Bit))
185 return CurMods;
186
187 SemaRef.Diag(Clause.getLParenLoc(), diag::err_acc_invalid_modifier)
188 << Bit << Clause.getClauseKind();
189
190 return CurMods ^ Bit;
191 };
192 auto Check = [&](OpenACCModifierKind ValidKinds) {
193 if ((Mods | ValidKinds) == ValidKinds)
194 return Mods;
195
196 Mods = CheckSingle(Mods, ValidKinds, OpenACCModifierKind::Always);
197 Mods = CheckSingle(Mods, ValidKinds, OpenACCModifierKind::AlwaysIn);
198 Mods = CheckSingle(Mods, ValidKinds, OpenACCModifierKind::AlwaysOut);
199 Mods = CheckSingle(Mods, ValidKinds, OpenACCModifierKind::Readonly);
200 Mods = CheckSingle(Mods, ValidKinds, OpenACCModifierKind::Zero);
201 Mods = CheckSingle(Mods, ValidKinds, OpenACCModifierKind::Capture);
202 return Mods;
203 };
204
205 // The 'capture' modifier is only valid on copyin, copyout, and create on
206 // structured data or compute constructs (which also includes combined).
207 bool IsStructuredDataOrCompute =
208 Clause.getDirectiveKind() == OpenACCDirectiveKind::Data ||
211
212 switch (Clause.getClauseKind()) {
213 default:
214 llvm_unreachable("Only for copy, copyin, copyout, create");
215 case OpenACCClauseKind::Copy:
216 case OpenACCClauseKind::PCopy:
217 case OpenACCClauseKind::PresentOrCopy:
218 // COPY: Capture always
219 return Check(OpenACCModifierKind::Always | OpenACCModifierKind::AlwaysIn |
220 OpenACCModifierKind::AlwaysOut |
221 OpenACCModifierKind::Capture);
222 case OpenACCClauseKind::CopyIn:
223 case OpenACCClauseKind::PCopyIn:
224 case OpenACCClauseKind::PresentOrCopyIn:
225 // COPYIN: Capture only struct.data & compute
226 return Check(OpenACCModifierKind::Always | OpenACCModifierKind::AlwaysIn |
227 OpenACCModifierKind::Readonly |
228 (IsStructuredDataOrCompute ? OpenACCModifierKind::Capture
229 : OpenACCModifierKind::Invalid));
230 case OpenACCClauseKind::CopyOut:
231 case OpenACCClauseKind::PCopyOut:
232 case OpenACCClauseKind::PresentOrCopyOut:
233 // COPYOUT: Capture only struct.data & compute
234 return Check(OpenACCModifierKind::Always |
235 OpenACCModifierKind::AlwaysOut | OpenACCModifierKind::Zero |
236 (IsStructuredDataOrCompute ? OpenACCModifierKind::Capture
237 : OpenACCModifierKind::Invalid));
238 case OpenACCClauseKind::Create:
239 case OpenACCClauseKind::PCreate:
240 case OpenACCClauseKind::PresentOrCreate:
241 // CREATE: Capture only struct.data & compute
242 return Check(OpenACCModifierKind::Zero |
243 (IsStructuredDataOrCompute ? OpenACCModifierKind::Capture
244 : OpenACCModifierKind::Invalid));
245 }
246 llvm_unreachable("didn't return from switch above?");
247 }
248
249 // Helper for the 'routine' checks during 'new' clause addition. Precondition
250 // is that we already know the new clause is one of the prohbiited ones.
251 template <typename Pred>
252 bool
253 CheckValidRoutineNewClauseHelper(Pred HasPredicate,
255 if (Clause.getDirectiveKind() != OpenACCDirectiveKind::Routine)
256 return false;
257
258 auto *FirstDeviceType =
259 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCDeviceTypeClause>);
260
261 if (FirstDeviceType == ExistingClauses.end()) {
262 // If there isn't a device type yet, ANY duplicate is wrong.
263
264 auto *ExistingProhibitedClause =
265 llvm::find_if(ExistingClauses, HasPredicate);
266
267 if (ExistingProhibitedClause == ExistingClauses.end())
268 return false;
269
270 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_cannot_combine)
271 << Clause.getClauseKind()
272 << (*ExistingProhibitedClause)->getClauseKind()
273 << Clause.getDirectiveKind();
274 SemaRef.Diag((*ExistingProhibitedClause)->getBeginLoc(),
275 diag::note_acc_previous_clause_here)
276 << (*ExistingProhibitedClause)->getClauseKind();
277 return true;
278 }
279
280 // At this point we know that this is 'after' a device type. So this is an
281 // error if: 1- there is one BEFORE the 'device_type' 2- there is one
282 // between this and the previous 'device_type'.
283
284 auto *BeforeDeviceType =
285 std::find_if(ExistingClauses.begin(), FirstDeviceType, HasPredicate);
286 // If there is one before the device_type (and we know we are after a
287 // device_type), than this is ill-formed.
288 if (BeforeDeviceType != FirstDeviceType) {
289 SemaRef.Diag(
290 Clause.getBeginLoc(),
291 diag::err_acc_clause_routine_cannot_combine_before_device_type)
292 << Clause.getClauseKind() << (*BeforeDeviceType)->getClauseKind();
293 SemaRef.Diag((*BeforeDeviceType)->getBeginLoc(),
294 diag::note_acc_previous_clause_here)
295 << (*BeforeDeviceType)->getClauseKind();
296 SemaRef.Diag((*FirstDeviceType)->getBeginLoc(),
297 diag::note_acc_active_applies_clause_here)
298 << diag::ACCDeviceTypeApp::Active
299 << (*FirstDeviceType)->getClauseKind();
300 return true;
301 }
302
303 auto LastDeviceTypeItr =
304 std::find_if(ExistingClauses.rbegin(), ExistingClauses.rend(),
305 llvm::IsaPred<OpenACCDeviceTypeClause>);
306
307 // We already know there is one in the list, so it is nonsensical to not
308 // have one.
309 assert(LastDeviceTypeItr != ExistingClauses.rend());
310
311 // Get the device-type from-the-front (not reverse) iterator from the
312 // reverse iterator.
313 auto *LastDeviceType = LastDeviceTypeItr.base() - 1;
314
315 auto *ExistingProhibitedSinceLastDevice =
316 std::find_if(LastDeviceType, ExistingClauses.end(), HasPredicate);
317
318 // No prohibited ones since the last device-type.
319 if (ExistingProhibitedSinceLastDevice == ExistingClauses.end())
320 return false;
321
322 SemaRef.Diag(Clause.getBeginLoc(),
323 diag::err_acc_clause_routine_cannot_combine_same_device_type)
324 << Clause.getClauseKind()
325 << (*ExistingProhibitedSinceLastDevice)->getClauseKind();
326 SemaRef.Diag((*ExistingProhibitedSinceLastDevice)->getBeginLoc(),
327 diag::note_acc_previous_clause_here)
328 << (*ExistingProhibitedSinceLastDevice)->getClauseKind();
329 SemaRef.Diag((*LastDeviceType)->getBeginLoc(),
330 diag::note_acc_active_applies_clause_here)
331 << diag::ACCDeviceTypeApp::Active << (*LastDeviceType)->getClauseKind();
332 return true;
333 }
334
335 // Routine has a pretty complicated set of rules for how device_type and the
336 // gang, worker, vector, and seq clauses work. So diagnose some of it here.
337 bool CheckValidRoutineGangWorkerVectorSeqNewClause(
339
340 if (Clause.getClauseKind() != OpenACCClauseKind::Gang &&
341 Clause.getClauseKind() != OpenACCClauseKind::Vector &&
342 Clause.getClauseKind() != OpenACCClauseKind::Worker &&
343 Clause.getClauseKind() != OpenACCClauseKind::Seq)
344 return false;
345 auto ProhibitedPred = llvm::IsaPred<OpenACCGangClause, OpenACCWorkerClause,
347
348 return CheckValidRoutineNewClauseHelper(ProhibitedPred, Clause);
349 }
350
351 // Bind should have similar rules on a routine as gang/worker/vector/seq,
352 // except there is no 'must have 1' rule, so we can get all the checking done
353 // here.
354 bool
355 CheckValidRoutineBindNewClause(SemaOpenACC::OpenACCParsedClause &Clause) {
356
357 if (Clause.getClauseKind() != OpenACCClauseKind::Bind)
358 return false;
359
360 auto HasBindPred = llvm::IsaPred<OpenACCBindClause>;
361 return CheckValidRoutineNewClauseHelper(HasBindPred, Clause);
362 }
363
364 // For 'tile' and 'collapse', only allow 1 per 'device_type'.
365 // Also applies to num_worker, num_gangs, vector_length, and async.
366 // This does introspection into the actual device-types to prevent duplicates
367 // across device types as well.
368 template <typename TheClauseTy>
369 bool DisallowSinceLastDeviceType(SemaOpenACC::OpenACCParsedClause &Clause) {
370 auto LastDeviceTypeItr =
371 std::find_if(ExistingClauses.rbegin(), ExistingClauses.rend(),
372 llvm::IsaPred<OpenACCDeviceTypeClause>);
373
374 auto LastSinceDevTy =
375 std::find_if(ExistingClauses.rbegin(), LastDeviceTypeItr,
376 llvm::IsaPred<TheClauseTy>);
377
378 // In this case there is a duplicate since the last device_type/lack of a
379 // device_type. Diagnose these as duplicates.
380 if (LastSinceDevTy != LastDeviceTypeItr) {
381 SemaRef.Diag(Clause.getBeginLoc(),
382 diag::err_acc_clause_since_last_device_type)
383 << Clause.getClauseKind() << Clause.getDirectiveKind()
384 << (LastDeviceTypeItr != ExistingClauses.rend());
385
386 SemaRef.Diag((*LastSinceDevTy)->getBeginLoc(),
387 diag::note_acc_previous_clause_here)
388 << (*LastSinceDevTy)->getClauseKind();
389
390 // Mention the last device_type as well.
391 if (LastDeviceTypeItr != ExistingClauses.rend())
392 SemaRef.Diag((*LastDeviceTypeItr)->getBeginLoc(),
393 diag::note_acc_active_applies_clause_here)
394 << diag::ACCDeviceTypeApp::Active
395 << (*LastDeviceTypeItr)->getClauseKind();
396 return true;
397 }
398
399 // If this isn't in a device_type, and we didn't diagnose that there are
400 // dupes above, just give up, no sense in searching for previous device_type
401 // regions as they don't exist.
402 if (LastDeviceTypeItr == ExistingClauses.rend())
403 return false;
404
405 // The device-type that is active for us, so we can compare to the previous
406 // ones.
407 const auto &ActiveDeviceTypeClause =
408 cast<OpenACCDeviceTypeClause>(**LastDeviceTypeItr);
409
410 auto PrevDeviceTypeItr = LastDeviceTypeItr;
411 auto CurDevTypeItr = LastDeviceTypeItr;
412
413 while ((CurDevTypeItr = std::find_if(
414 std::next(PrevDeviceTypeItr), ExistingClauses.rend(),
415 llvm::IsaPred<OpenACCDeviceTypeClause>)) !=
416 ExistingClauses.rend()) {
417 // At this point, we know that we have a region between two device_types,
418 // as specified by CurDevTypeItr and PrevDeviceTypeItr.
419
420 auto CurClauseKindItr = std::find_if(PrevDeviceTypeItr, CurDevTypeItr,
421 llvm::IsaPred<TheClauseTy>);
422
423 // There are no clauses of the current kind between these device_types, so
424 // continue.
425 if (CurClauseKindItr == CurDevTypeItr) {
426 PrevDeviceTypeItr = CurDevTypeItr;
427 continue;
428 }
429
430 // At this point, we know that this device_type region has a collapse. So
431 // diagnose if the two device_types have any overlap in their
432 // architectures.
433 const auto &CurDeviceTypeClause =
434 cast<OpenACCDeviceTypeClause>(**CurDevTypeItr);
435
436 for (const DeviceTypeArgument &arg :
437 ActiveDeviceTypeClause.getArchitectures()) {
438 for (const DeviceTypeArgument &prevArg :
439 CurDeviceTypeClause.getArchitectures()) {
440
441 // This should catch duplicates * regions, duplicate same-text (thanks
442 // to identifier equiv.) and case insensitive dupes.
443 if (arg.getIdentifierInfo() == prevArg.getIdentifierInfo() ||
444 (arg.getIdentifierInfo() && prevArg.getIdentifierInfo() &&
445 StringRef{arg.getIdentifierInfo()->getName()}.equals_insensitive(
446 prevArg.getIdentifierInfo()->getName()))) {
447 SemaRef.Diag(Clause.getBeginLoc(),
448 diag::err_acc_clause_conflicts_prev_dev_type)
449 << Clause.getClauseKind()
450 << (arg.getIdentifierInfo() ? arg.getIdentifierInfo()->getName()
451 : "*");
452 // mention the active device type.
453 SemaRef.Diag(ActiveDeviceTypeClause.getBeginLoc(),
454 diag::note_acc_active_applies_clause_here)
455 << diag::ACCDeviceTypeApp::Active
456 << ActiveDeviceTypeClause.getClauseKind();
457 // mention the previous clause.
458 SemaRef.Diag((*CurClauseKindItr)->getBeginLoc(),
459 diag::note_acc_previous_clause_here)
460 << (*CurClauseKindItr)->getClauseKind();
461 // mention the previous device type.
462 SemaRef.Diag(CurDeviceTypeClause.getBeginLoc(),
463 diag::note_acc_active_applies_clause_here)
464 << diag::ACCDeviceTypeApp::Applies
465 << CurDeviceTypeClause.getClauseKind();
466 return true;
467 }
468 }
469 }
470
471 PrevDeviceTypeItr = CurDevTypeItr;
472 }
473 return false;
474 }
475
476public:
477 SemaOpenACCClauseVisitor(SemaOpenACC &S,
478 ArrayRef<const OpenACCClause *> ExistingClauses)
479 : SemaRef(S), Ctx(S.getASTContext()), ExistingClauses(ExistingClauses) {}
480
482
483 if (SemaRef.DiagnoseAllowedOnceClauses(
484 Clause.getDirectiveKind(), Clause.getClauseKind(),
485 Clause.getBeginLoc(), ExistingClauses) ||
487 Clause.getClauseKind(),
488 Clause.getBeginLoc(), ExistingClauses))
489 return nullptr;
490 if (CheckValidRoutineGangWorkerVectorSeqNewClause(Clause) ||
491 CheckValidRoutineBindNewClause(Clause))
492 return nullptr;
493
494 switch (Clause.getClauseKind()) {
495 case OpenACCClauseKind::Shortloop:
496 llvm_unreachable("Shortloop shouldn't be generated in clang");
497 case OpenACCClauseKind::Invalid:
498 return nullptr;
499#define VISIT_CLAUSE(CLAUSE_NAME) \
500 case OpenACCClauseKind::CLAUSE_NAME: \
501 return Visit##CLAUSE_NAME##Clause(Clause);
502#define CLAUSE_ALIAS(ALIAS, CLAUSE_NAME, DEPRECATED) \
503 case OpenACCClauseKind::ALIAS: \
504 if (DEPRECATED) \
505 SemaRef.Diag(Clause.getBeginLoc(), diag::warn_acc_deprecated_alias_name) \
506 << Clause.getClauseKind() << OpenACCClauseKind::CLAUSE_NAME; \
507 return Visit##CLAUSE_NAME##Clause(Clause);
508#include "clang/Basic/OpenACCClauses.def"
509 }
510 llvm_unreachable("Invalid clause kind");
511 }
512
513#define VISIT_CLAUSE(CLAUSE_NAME) \
514 OpenACCClause *Visit##CLAUSE_NAME##Clause( \
515 SemaOpenACC::OpenACCParsedClause &Clause);
516#include "clang/Basic/OpenACCClauses.def"
517};
518
519OpenACCClause *SemaOpenACCClauseVisitor::VisitDefaultClause(
521 // Don't add an invalid clause to the AST.
522 if (Clause.getDefaultClauseKind() == OpenACCDefaultClauseKind::Invalid)
523 return nullptr;
524
526 Ctx, Clause.getDefaultClauseKind(), Clause.getBeginLoc(),
527 Clause.getLParenLoc(), Clause.getEndLoc());
528}
529
530OpenACCClause *SemaOpenACCClauseVisitor::VisitTileClause(
532
533 if (DisallowSinceLastDeviceType<OpenACCTileClause>(Clause))
534 return nullptr;
535
536 llvm::SmallVector<Expr *> NewSizeExprs;
537
538 // Make sure these are all positive constant expressions or *.
539 for (Expr *E : Clause.getIntExprs()) {
540 ExprResult Res = SemaRef.CheckTileSizeExpr(E);
541
542 if (!Res.isUsable())
543 return nullptr;
544
545 NewSizeExprs.push_back(Res.get());
546 }
547
548 return OpenACCTileClause::Create(Ctx, Clause.getBeginLoc(),
549 Clause.getLParenLoc(), NewSizeExprs,
550 Clause.getEndLoc());
551}
552
553OpenACCClause *SemaOpenACCClauseVisitor::VisitIfClause(
555
556 // The parser has ensured that we have a proper condition expr, so there
557 // isn't really much to do here.
558
559 // If the 'if' clause is true, it makes the 'self' clause have no effect,
560 // diagnose that here. This only applies on compute/combined constructs.
561 if (Clause.getDirectiveKind() != OpenACCDirectiveKind::Update) {
562 const auto *Itr =
563 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCSelfClause>);
564 if (Itr != ExistingClauses.end()) {
565 SemaRef.Diag(Clause.getBeginLoc(), diag::warn_acc_if_self_conflict);
566 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here)
567 << (*Itr)->getClauseKind();
568 }
569 }
570
571 return OpenACCIfClause::Create(Ctx, Clause.getBeginLoc(),
572 Clause.getLParenLoc(),
573 Clause.getConditionExpr(), Clause.getEndLoc());
574}
575
576OpenACCClause *SemaOpenACCClauseVisitor::VisitSelfClause(
578
579 // If the 'if' clause is true, it makes the 'self' clause have no effect,
580 // diagnose that here. This only applies on compute/combined constructs.
581 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Update)
582 return OpenACCSelfClause::Create(Ctx, Clause.getBeginLoc(),
583 Clause.getLParenLoc(), Clause.getVarList(),
584 Clause.getEndLoc());
585
586 const auto *Itr =
587 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCIfClause>);
588 if (Itr != ExistingClauses.end()) {
589 SemaRef.Diag(Clause.getBeginLoc(), diag::warn_acc_if_self_conflict);
590 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here)
591 << (*Itr)->getClauseKind();
592 }
594 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(),
595 Clause.getConditionExpr(), Clause.getEndLoc());
596}
597
598OpenACCClause *SemaOpenACCClauseVisitor::VisitNumGangsClause(
600
601 if (DisallowSinceLastDeviceType<OpenACCNumGangsClause>(Clause))
602 return nullptr;
603
604 // num_gangs requires at least 1 int expr in all forms. Diagnose here, but
605 // allow us to continue, an empty clause might be useful for future
606 // diagnostics.
607 if (Clause.getIntExprs().empty())
608 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_num_gangs_num_args)
609 << /*NoArgs=*/0;
610
611 unsigned MaxArgs =
612 (Clause.getDirectiveKind() == OpenACCDirectiveKind::Parallel ||
613 Clause.getDirectiveKind() == OpenACCDirectiveKind::ParallelLoop)
614 ? 3
615 : 1;
616 // The max number of args differs between parallel and other constructs.
617 // Again, allow us to continue for the purposes of future diagnostics.
618 if (Clause.getIntExprs().size() > MaxArgs)
619 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_num_gangs_num_args)
620 << /*NoArgs=*/1 << Clause.getDirectiveKind() << MaxArgs
621 << Clause.getIntExprs().size();
622
623 // OpenACC 3.3 Section 2.9.11: A reduction clause may not appear on a loop
624 // directive that has a gang clause and is within a compute construct that has
625 // a num_gangs clause with more than one explicit argument.
626 if (Clause.getIntExprs().size() > 1 &&
628 auto *GangClauseItr =
629 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
630 auto *ReductionClauseItr =
631 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
632
633 if (GangClauseItr != ExistingClauses.end() &&
634 ReductionClauseItr != ExistingClauses.end()) {
635 SemaRef.Diag(Clause.getBeginLoc(),
636 diag::err_acc_gang_reduction_numgangs_conflict)
637 << OpenACCClauseKind::Reduction << OpenACCClauseKind::Gang
638 << Clause.getDirectiveKind() << /*is on combined directive=*/1;
639 SemaRef.Diag((*ReductionClauseItr)->getBeginLoc(),
640 diag::note_acc_previous_clause_here)
641 << (*ReductionClauseItr)->getClauseKind();
642 SemaRef.Diag((*GangClauseItr)->getBeginLoc(),
643 diag::note_acc_previous_clause_here)
644 << (*GangClauseItr)->getClauseKind();
645 return nullptr;
646 }
647 }
648
649 // OpenACC 3.3 Section 2.5.4:
650 // A reduction clause may not appear on a parallel construct with a
651 // num_gangs clause that has more than one argument.
652 if ((Clause.getDirectiveKind() == OpenACCDirectiveKind::Parallel ||
653 Clause.getDirectiveKind() == OpenACCDirectiveKind::ParallelLoop) &&
654 Clause.getIntExprs().size() > 1) {
655 auto *Parallel =
656 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
657
658 if (Parallel != ExistingClauses.end()) {
659 SemaRef.Diag(Clause.getBeginLoc(),
660 diag::err_acc_reduction_num_gangs_conflict)
661 << /*>1 arg in first loc=*/1 << Clause.getClauseKind()
662 << Clause.getDirectiveKind() << OpenACCClauseKind::Reduction;
663 SemaRef.Diag((*Parallel)->getBeginLoc(),
664 diag::note_acc_previous_clause_here)
665 << (*Parallel)->getClauseKind();
666 return nullptr;
667 }
668 }
669
670 // OpenACC 3.3 Section 2.9.2:
671 // An argument with no keyword or with the 'num' keyword is allowed only when
672 // the 'num_gangs' does not appear on the 'kernel' construct.
673 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::KernelsLoop) {
674 auto GangClauses = llvm::make_filter_range(
675 ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
676
677 for (auto *GC : GangClauses) {
678 if (cast<OpenACCGangClause>(GC)->hasExprOfKind(OpenACCGangKind::Num)) {
679 SemaRef.Diag(Clause.getBeginLoc(),
680 diag::err_acc_num_arg_conflict_reverse)
681 << OpenACCClauseKind::NumGangs << OpenACCClauseKind::Gang
682 << /*Num argument*/ 1;
683 SemaRef.Diag(GC->getBeginLoc(), diag::note_acc_previous_clause_here)
684 << GC->getClauseKind();
685 return nullptr;
686 }
687 }
688 }
689
691 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getIntExprs(),
692 Clause.getEndLoc());
693}
694
695OpenACCClause *SemaOpenACCClauseVisitor::VisitNumWorkersClause(
697
698 if (DisallowSinceLastDeviceType<OpenACCNumWorkersClause>(Clause))
699 return nullptr;
700
701 // OpenACC 3.3 Section 2.9.2:
702 // An argument is allowed only when the 'num_workers' does not appear on the
703 // kernels construct.
704 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::KernelsLoop) {
705 auto WorkerClauses = llvm::make_filter_range(
706 ExistingClauses, llvm::IsaPred<OpenACCWorkerClause>);
707
708 for (auto *WC : WorkerClauses) {
709 if (cast<OpenACCWorkerClause>(WC)->hasIntExpr()) {
710 SemaRef.Diag(Clause.getBeginLoc(),
711 diag::err_acc_num_arg_conflict_reverse)
712 << OpenACCClauseKind::NumWorkers << OpenACCClauseKind::Worker
713 << /*num argument*/ 0;
714 SemaRef.Diag(WC->getBeginLoc(), diag::note_acc_previous_clause_here)
715 << WC->getClauseKind();
716 return nullptr;
717 }
718 }
719 }
720
721 assert(Clause.getIntExprs().size() == 1 &&
722 "Invalid number of expressions for NumWorkers");
724 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getIntExprs()[0],
725 Clause.getEndLoc());
726}
727
728OpenACCClause *SemaOpenACCClauseVisitor::VisitVectorLengthClause(
730
731 if (DisallowSinceLastDeviceType<OpenACCVectorLengthClause>(Clause))
732 return nullptr;
733
734 // OpenACC 3.3 Section 2.9.4:
735 // An argument is allowed only when the 'vector_length' does not appear on the
736 // 'kernels' construct.
737 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::KernelsLoop) {
738 auto VectorClauses = llvm::make_filter_range(
739 ExistingClauses, llvm::IsaPred<OpenACCVectorClause>);
740
741 for (auto *VC : VectorClauses) {
742 if (cast<OpenACCVectorClause>(VC)->hasIntExpr()) {
743 SemaRef.Diag(Clause.getBeginLoc(),
744 diag::err_acc_num_arg_conflict_reverse)
745 << OpenACCClauseKind::VectorLength << OpenACCClauseKind::Vector
746 << /*num argument*/ 0;
747 SemaRef.Diag(VC->getBeginLoc(), diag::note_acc_previous_clause_here)
748 << VC->getClauseKind();
749 return nullptr;
750 }
751 }
752 }
753
754 assert(Clause.getIntExprs().size() == 1 &&
755 "Invalid number of expressions for NumWorkers");
757 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getIntExprs()[0],
758 Clause.getEndLoc());
759}
760
761OpenACCClause *SemaOpenACCClauseVisitor::VisitAsyncClause(
763 if (DisallowSinceLastDeviceType<OpenACCAsyncClause>(Clause))
764 return nullptr;
765
766 assert(Clause.getNumIntExprs() < 2 &&
767 "Invalid number of expressions for Async");
769 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(),
770 Clause.getNumIntExprs() != 0 ? Clause.getIntExprs()[0] : nullptr,
771 Clause.getEndLoc());
772}
773
774OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceNumClause(
776 assert(Clause.getNumIntExprs() == 1 &&
777 "Invalid number of expressions for device_num");
779 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getIntExprs()[0],
780 Clause.getEndLoc());
781}
782
783OpenACCClause *SemaOpenACCClauseVisitor::VisitDefaultAsyncClause(
785 assert(Clause.getNumIntExprs() == 1 &&
786 "Invalid number of expressions for default_async");
788 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getIntExprs()[0],
789 Clause.getEndLoc());
790}
791
792OpenACCClause *SemaOpenACCClauseVisitor::VisitPrivateClause(
794 // ActOnVar ensured that everything is a valid variable reference, so there
795 // really isn't anything to do here. GCC does some duplicate-finding, though
796 // it isn't apparent in the standard where this is justified.
797
799
800 // Assemble the recipes list.
801 for (const Expr *VarExpr : Clause.getVarList())
802 InitRecipes.push_back(
803 SemaRef.CreateInitRecipe(OpenACCClauseKind::Private, VarExpr).first);
804
806 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getVarList(),
807 InitRecipes, Clause.getEndLoc());
808}
809
810OpenACCClause *SemaOpenACCClauseVisitor::VisitFirstPrivateClause(
812 // ActOnVar ensured that everything is a valid variable reference, so there
813 // really isn't anything to do here. GCC does some duplicate-finding, though
814 // it isn't apparent in the standard where this is justified.
815
817
818 // Assemble the recipes list.
819 for (const Expr *VarExpr : Clause.getVarList())
820 InitRecipes.push_back(
821 SemaRef.CreateInitRecipe(OpenACCClauseKind::FirstPrivate, VarExpr));
822
824 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getVarList(),
825 InitRecipes, Clause.getEndLoc());
826}
827
828OpenACCClause *SemaOpenACCClauseVisitor::VisitNoCreateClause(
830 // ActOnVar ensured that everything is a valid variable reference, so there
831 // really isn't anything to do here. GCC does some duplicate-finding, though
832 // it isn't apparent in the standard where this is justified.
833
834 return OpenACCNoCreateClause::Create(Ctx, Clause.getBeginLoc(),
835 Clause.getLParenLoc(),
836 Clause.getVarList(), Clause.getEndLoc());
837}
838
839OpenACCClause *SemaOpenACCClauseVisitor::VisitPresentClause(
841 // ActOnVar ensured that everything is a valid variable reference, so there
842 // really isn't anything to do here. GCC does some duplicate-finding, though
843 // it isn't apparent in the standard where this is justified.
844
845 // 'declare' has some restrictions that need to be enforced separately, so
846 // check it here.
847 if (SemaRef.CheckDeclareClause(Clause, OpenACCModifierKind::Invalid))
848 return nullptr;
849
850 return OpenACCPresentClause::Create(Ctx, Clause.getBeginLoc(),
851 Clause.getLParenLoc(),
852 Clause.getVarList(), Clause.getEndLoc());
853}
854
855OpenACCClause *SemaOpenACCClauseVisitor::VisitHostClause(
857 // ActOnVar ensured that everything is a valid variable reference, so there
858 // really isn't anything to do here. GCC does some duplicate-finding, though
859 // it isn't apparent in the standard where this is justified.
860
861 return OpenACCHostClause::Create(Ctx, Clause.getBeginLoc(),
862 Clause.getLParenLoc(), Clause.getVarList(),
863 Clause.getEndLoc());
864}
865
866OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceClause(
868 // ActOnVar ensured that everything is a valid variable reference, so there
869 // really isn't anything to do here. GCC does some duplicate-finding, though
870 // it isn't apparent in the standard where this is justified.
871
872 return OpenACCDeviceClause::Create(Ctx, Clause.getBeginLoc(),
873 Clause.getLParenLoc(), Clause.getVarList(),
874 Clause.getEndLoc());
875}
876
877OpenACCClause *SemaOpenACCClauseVisitor::VisitCopyClause(
879 // ActOnVar ensured that everything is a valid variable reference, so there
880 // really isn't anything to do here. GCC does some duplicate-finding, though
881 // it isn't apparent in the standard where this is justified.
882
883 OpenACCModifierKind NewMods =
884 CheckModifierList(Clause, Clause.getModifierList());
885
886 // 'declare' has some restrictions that need to be enforced separately, so
887 // check it here.
888 if (SemaRef.CheckDeclareClause(Clause, NewMods))
889 return nullptr;
890
892 Ctx, Clause.getClauseKind(), Clause.getBeginLoc(), Clause.getLParenLoc(),
893 Clause.getModifierList(), Clause.getVarList(), Clause.getEndLoc());
894}
895
896OpenACCClause *SemaOpenACCClauseVisitor::VisitLinkClause(
898 // 'declare' has some restrictions that need to be enforced separately, so
899 // check it here.
900 if (SemaRef.CheckDeclareClause(Clause, OpenACCModifierKind::Invalid))
901 return nullptr;
902
903 Clause.setVarListDetails(SemaRef.CheckLinkClauseVarList(Clause.getVarList()),
904 OpenACCModifierKind::Invalid);
905
906 return OpenACCLinkClause::Create(Ctx, Clause.getBeginLoc(),
907 Clause.getLParenLoc(), Clause.getVarList(),
908 Clause.getEndLoc());
909}
910
911OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceResidentClause(
913 // 'declare' has some restrictions that need to be enforced separately, so
914 // check it here.
915 if (SemaRef.CheckDeclareClause(Clause, OpenACCModifierKind::Invalid))
916 return nullptr;
917
919 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getVarList(),
920 Clause.getEndLoc());
921}
922
923OpenACCClause *SemaOpenACCClauseVisitor::VisitCopyInClause(
925 // ActOnVar ensured that everything is a valid variable reference, so there
926 // really isn't anything to do here. GCC does some duplicate-finding, though
927 // it isn't apparent in the standard where this is justified.
928
929 OpenACCModifierKind NewMods =
930 CheckModifierList(Clause, Clause.getModifierList());
931
932 // 'declare' has some restrictions that need to be enforced separately, so
933 // check it here.
934 if (SemaRef.CheckDeclareClause(Clause, NewMods))
935 return nullptr;
936
938 Ctx, Clause.getClauseKind(), Clause.getBeginLoc(), Clause.getLParenLoc(),
939 Clause.getModifierList(), Clause.getVarList(), Clause.getEndLoc());
940}
941
942OpenACCClause *SemaOpenACCClauseVisitor::VisitCopyOutClause(
944 // ActOnVar ensured that everything is a valid variable reference, so there
945 // really isn't anything to do here. GCC does some duplicate-finding, though
946 // it isn't apparent in the standard where this is justified.
947
948 OpenACCModifierKind NewMods =
949 CheckModifierList(Clause, Clause.getModifierList());
950
951 // 'declare' has some restrictions that need to be enforced separately, so
952 // check it here.
953 if (SemaRef.CheckDeclareClause(Clause, NewMods))
954 return nullptr;
955
957 Ctx, Clause.getClauseKind(), Clause.getBeginLoc(), Clause.getLParenLoc(),
958 Clause.getModifierList(), Clause.getVarList(), Clause.getEndLoc());
959}
960
961OpenACCClause *SemaOpenACCClauseVisitor::VisitCreateClause(
963 // ActOnVar ensured that everything is a valid variable reference, so there
964 // really isn't anything to do here. GCC does some duplicate-finding, though
965 // it isn't apparent in the standard where this is justified.
966
967 OpenACCModifierKind NewMods =
968 CheckModifierList(Clause, Clause.getModifierList());
969
970 // 'declare' has some restrictions that need to be enforced separately, so
971 // check it here.
972 if (SemaRef.CheckDeclareClause(Clause, NewMods))
973 return nullptr;
974
976 Ctx, Clause.getClauseKind(), Clause.getBeginLoc(), Clause.getLParenLoc(),
977 Clause.getModifierList(), Clause.getVarList(), Clause.getEndLoc());
978}
979
980OpenACCClause *SemaOpenACCClauseVisitor::VisitAttachClause(
982 // ActOnVar ensured that everything is a valid variable reference, but we
983 // still have to make sure it is a pointer type.
984 llvm::SmallVector<Expr *> VarList{Clause.getVarList()};
985 llvm::erase_if(VarList, [&](Expr *E) {
986 return SemaRef.CheckVarIsPointerType(OpenACCClauseKind::Attach, E);
987 });
988 Clause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
989 return OpenACCAttachClause::Create(Ctx, Clause.getBeginLoc(),
990 Clause.getLParenLoc(), Clause.getVarList(),
991 Clause.getEndLoc());
992}
993
994OpenACCClause *SemaOpenACCClauseVisitor::VisitDetachClause(
996 // ActOnVar ensured that everything is a valid variable reference, but we
997 // still have to make sure it is a pointer type.
998 llvm::SmallVector<Expr *> VarList{Clause.getVarList()};
999 llvm::erase_if(VarList, [&](Expr *E) {
1000 return SemaRef.CheckVarIsPointerType(OpenACCClauseKind::Detach, E);
1001 });
1002 Clause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
1003 return OpenACCDetachClause::Create(Ctx, Clause.getBeginLoc(),
1004 Clause.getLParenLoc(), Clause.getVarList(),
1005 Clause.getEndLoc());
1006}
1007
1008OpenACCClause *SemaOpenACCClauseVisitor::VisitDeleteClause(
1010 // ActOnVar ensured that everything is a valid variable reference, so there
1011 // really isn't anything to do here. GCC does some duplicate-finding, though
1012 // it isn't apparent in the standard where this is justified.
1013 return OpenACCDeleteClause::Create(Ctx, Clause.getBeginLoc(),
1014 Clause.getLParenLoc(), Clause.getVarList(),
1015 Clause.getEndLoc());
1016}
1017
1018OpenACCClause *SemaOpenACCClauseVisitor::VisitUseDeviceClause(
1020 // ActOnVar ensured that everything is a valid variable or array, so nothing
1021 // left to do here.
1023 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getVarList(),
1024 Clause.getEndLoc());
1025}
1026
1027OpenACCClause *SemaOpenACCClauseVisitor::VisitDevicePtrClause(
1029 // ActOnVar ensured that everything is a valid variable reference, but we
1030 // still have to make sure it is a pointer type.
1031 llvm::SmallVector<Expr *> VarList{Clause.getVarList()};
1032 llvm::erase_if(VarList, [&](Expr *E) {
1033 return SemaRef.CheckVarIsPointerType(OpenACCClauseKind::DevicePtr, E);
1034 });
1035 Clause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
1036
1037 // 'declare' has some restrictions that need to be enforced separately, so
1038 // check it here.
1039 if (SemaRef.CheckDeclareClause(Clause, OpenACCModifierKind::Invalid))
1040 return nullptr;
1041
1043 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getVarList(),
1044 Clause.getEndLoc());
1045}
1046
1047OpenACCClause *SemaOpenACCClauseVisitor::VisitWaitClause(
1050 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getDevNumExpr(),
1051 Clause.getQueuesLoc(), Clause.getQueueIdExprs(), Clause.getEndLoc());
1052}
1053
1054OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause(
1056
1057 // OpenACC Pull #550 (https://github.com/OpenACC/openacc-spec/pull/550)
1058 // clarified that Init, Shutdown, and Set only support a single architecture.
1059 // Though the dialect only requires it for 'set' as far as we know, we'll just
1060 // implement all 3 here.
1061 if ((Clause.getDirectiveKind() == OpenACCDirectiveKind::Init ||
1062 Clause.getDirectiveKind() == OpenACCDirectiveKind::Shutdown ||
1063 Clause.getDirectiveKind() == OpenACCDirectiveKind::Set) &&
1064 Clause.getDeviceTypeArchitectures().size() > 1) {
1065 SemaRef.Diag(Clause.getDeviceTypeArchitectures()[1].getLoc(),
1066 diag::err_acc_device_type_multiple_archs)
1067 << Clause.getDirectiveKind();
1068 return nullptr;
1069 }
1070
1071 // The list of valid device_type values. Flang also has these hardcoded in
1072 // openacc_parsers.cpp, as there does not seem to be a reliable backend
1073 // source. The list below is sourced from Flang, though NVC++ supports only
1074 // 'nvidia', 'host', 'multicore', and 'default'.
1075 const std::array<llvm::StringLiteral, 6> ValidValues{
1076 "default", "nvidia", "acc_device_nvidia", "radeon", "host", "multicore"};
1077 // As an optimization, we have a manually maintained list of valid values
1078 // below, rather than trying to calculate from above. These should be kept in
1079 // sync if/when the above list ever changes.
1080 std::string ValidValuesString =
1081 "'default', 'nvidia', 'acc_device_nvidia', 'radeon', 'host', 'multicore'";
1082
1085
1086 // The parser has ensured that we either have a single entry of just '*'
1087 // (represented by a nullptr IdentifierInfo), or a list.
1088
1089 bool Diagnosed = false;
1090 auto FilterPred = [&](const DeviceTypeArgument &Arch) {
1091 // The '*' case.
1092 if (!Arch.getIdentifierInfo())
1093 return false;
1094 return llvm::find_if(ValidValues, [&](StringRef RHS) {
1095 return Arch.getIdentifierInfo()->getName().equals_insensitive(RHS);
1096 }) == ValidValues.end();
1097 };
1098
1099 auto Diagnose = [&](const DeviceTypeArgument &Arch) {
1100 Diagnosed = SemaRef.Diag(Arch.getLoc(), diag::err_acc_invalid_default_type)
1101 << Arch.getIdentifierInfo() << Clause.getClauseKind()
1102 << ValidValuesString;
1103 };
1104
1105 // There aren't stable enumertor versions of 'for-each-then-erase', so do it
1106 // here. We DO keep track of whether we diagnosed something to make sure we
1107 // don't do the 'erase_if' in the event that the first list didn't find
1108 // anything.
1109 llvm::for_each(llvm::make_filter_range(Architectures, FilterPred), Diagnose);
1110 if (Diagnosed)
1111 llvm::erase_if(Architectures, FilterPred);
1112
1114 Ctx, Clause.getClauseKind(), Clause.getBeginLoc(), Clause.getLParenLoc(),
1115 Architectures, Clause.getEndLoc());
1116}
1117
1118OpenACCClause *SemaOpenACCClauseVisitor::VisitAutoClause(
1120
1121 return OpenACCAutoClause::Create(Ctx, Clause.getBeginLoc(),
1122 Clause.getEndLoc());
1123}
1124
1125OpenACCClause *SemaOpenACCClauseVisitor::VisitNoHostClause(
1127 return OpenACCNoHostClause::Create(Ctx, Clause.getBeginLoc(),
1128 Clause.getEndLoc());
1129}
1130
1131OpenACCClause *SemaOpenACCClauseVisitor::VisitIndependentClause(
1133
1134 return OpenACCIndependentClause::Create(Ctx, Clause.getBeginLoc(),
1135 Clause.getEndLoc());
1136}
1137
1138ExprResult CheckGangStaticExpr(SemaOpenACC &S, Expr *E) {
1139 if (isa<OpenACCAsteriskSizeExpr>(E))
1140 return E;
1141 return S.ActOnIntExpr(OpenACCDirectiveKind::Invalid, OpenACCClauseKind::Gang,
1142 E->getBeginLoc(), E);
1143}
1144
1145bool IsOrphanLoop(OpenACCDirectiveKind DK, OpenACCDirectiveKind AssocKind) {
1146 return DK == OpenACCDirectiveKind::Loop &&
1147 AssocKind == OpenACCDirectiveKind::Invalid;
1148}
1149
1150bool HasAssocKind(OpenACCDirectiveKind DK, OpenACCDirectiveKind AssocKind) {
1151 return DK == OpenACCDirectiveKind::Loop &&
1152 AssocKind != OpenACCDirectiveKind::Invalid;
1153}
1154
1155ExprResult DiagIntArgInvalid(SemaOpenACC &S, Expr *E, OpenACCGangKind GK,
1157 OpenACCDirectiveKind AssocKind) {
1158 S.Diag(E->getBeginLoc(), diag::err_acc_int_arg_invalid)
1159 << GK << CK << IsOrphanLoop(DK, AssocKind) << DK
1160 << HasAssocKind(DK, AssocKind) << AssocKind;
1161 return ExprError();
1162}
1163ExprResult DiagIntArgInvalid(SemaOpenACC &S, Expr *E, StringRef TagKind,
1165 OpenACCDirectiveKind AssocKind) {
1166 S.Diag(E->getBeginLoc(), diag::err_acc_int_arg_invalid)
1167 << TagKind << CK << IsOrphanLoop(DK, AssocKind) << DK
1168 << HasAssocKind(DK, AssocKind) << AssocKind;
1169 return ExprError();
1170}
1171
1172ExprResult CheckGangDimExpr(SemaOpenACC &S, Expr *E) {
1173 // OpenACC 3.3 2.9.2: When the parent compute construct is a parallel
1174 // construct, or an orphaned loop construct, the gang clause behaves as
1175 // follows. ... The dim argument must be a constant positive integer value
1176 // 1, 2, or 3.
1177 // -also-
1178 // OpenACC 3.3 2.15: The 'dim' argument must be a constant positive integer
1179 // with value 1, 2, or 3.
1180 if (!E)
1181 return ExprError();
1182 ExprResult Res = S.ActOnIntExpr(OpenACCDirectiveKind::Invalid,
1183 OpenACCClauseKind::Gang, E->getBeginLoc(), E);
1184
1185 if (!Res.isUsable())
1186 return Res;
1187
1188 if (Res.get()->isInstantiationDependent())
1189 return Res;
1190
1191 std::optional<llvm::APSInt> ICE =
1193
1194 if (!ICE || *ICE <= 0 || ICE > 3) {
1195 S.Diag(Res.get()->getBeginLoc(), diag::err_acc_gang_dim_value)
1196 << ICE.has_value() << ICE.value_or(llvm::APSInt{}).getExtValue();
1197 return ExprError();
1198 }
1199
1200 return ExprResult{
1201 ConstantExpr::Create(S.getASTContext(), Res.get(), APValue{*ICE})};
1202}
1203
1204ExprResult CheckGangParallelExpr(SemaOpenACC &S, OpenACCDirectiveKind DK,
1205 OpenACCDirectiveKind AssocKind,
1206 OpenACCGangKind GK, Expr *E) {
1207 switch (GK) {
1208 case OpenACCGangKind::Static:
1209 return CheckGangStaticExpr(S, E);
1210 case OpenACCGangKind::Num:
1211 // OpenACC 3.3 2.9.2: When the parent compute construct is a parallel
1212 // construct, or an orphaned loop construct, the gang clause behaves as
1213 // follows. ... The num argument is not allowed.
1214 return DiagIntArgInvalid(S, E, GK, OpenACCClauseKind::Gang, DK, AssocKind);
1215 case OpenACCGangKind::Dim:
1216 return CheckGangDimExpr(S, E);
1217 }
1218 llvm_unreachable("Unknown gang kind in gang parallel check");
1219}
1220
1221ExprResult CheckGangKernelsExpr(SemaOpenACC &S,
1222 ArrayRef<const OpenACCClause *> ExistingClauses,
1224 OpenACCDirectiveKind AssocKind,
1225 OpenACCGangKind GK, Expr *E) {
1226 switch (GK) {
1227 // OpenACC 3.3 2.9.2: When the parent compute construct is a kernels
1228 // construct, the gang clause behaves as follows. ... The dim argument is
1229 // not allowed.
1230 case OpenACCGangKind::Dim:
1231 return DiagIntArgInvalid(S, E, GK, OpenACCClauseKind::Gang, DK, AssocKind);
1232 case OpenACCGangKind::Num: {
1233 // OpenACC 3.3 2.9.2: When the parent compute construct is a kernels
1234 // construct, the gang clause behaves as follows. ... An argument with no
1235 // keyword or with num keyword is only allowed when num_gangs does not
1236 // appear on the kernels construct. ... The region of a loop with the gang
1237 // clause may not contain another loop with a gang clause unless within a
1238 // nested compute region.
1239
1240 // If this is a 'combined' construct, search the list of existing clauses.
1241 // Else we need to search the containing 'kernel'.
1242 auto Collection = isOpenACCCombinedDirectiveKind(DK)
1243 ? ExistingClauses
1244 : S.getActiveComputeConstructInfo().Clauses;
1245
1246 const auto *Itr =
1247 llvm::find_if(Collection, llvm::IsaPred<OpenACCNumGangsClause>);
1248
1249 if (Itr != Collection.end()) {
1250 S.Diag(E->getBeginLoc(), diag::err_acc_num_arg_conflict)
1251 << "num" << OpenACCClauseKind::Gang << DK
1252 << HasAssocKind(DK, AssocKind) << AssocKind
1253 << OpenACCClauseKind::NumGangs;
1254
1255 S.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here)
1256 << (*Itr)->getClauseKind();
1257 return ExprError();
1258 }
1259 return ExprResult{E};
1260 }
1261 case OpenACCGangKind::Static:
1262 return CheckGangStaticExpr(S, E);
1263 }
1264 llvm_unreachable("Unknown gang kind in gang kernels check");
1265}
1266
1267ExprResult CheckGangSerialExpr(SemaOpenACC &S, OpenACCDirectiveKind DK,
1268 OpenACCDirectiveKind AssocKind,
1269 OpenACCGangKind GK, Expr *E) {
1270 switch (GK) {
1271 // 'dim' and 'num' don't really make sense on serial, and GCC rejects them
1272 // too, so we disallow them too.
1273 case OpenACCGangKind::Dim:
1274 case OpenACCGangKind::Num:
1275 return DiagIntArgInvalid(S, E, GK, OpenACCClauseKind::Gang, DK, AssocKind);
1276 case OpenACCGangKind::Static:
1277 return CheckGangStaticExpr(S, E);
1278 }
1279 llvm_unreachable("Unknown gang kind in gang serial check");
1280}
1281
1282ExprResult CheckGangRoutineExpr(SemaOpenACC &S, OpenACCDirectiveKind DK,
1283 OpenACCDirectiveKind AssocKind,
1284 OpenACCGangKind GK, Expr *E) {
1285 switch (GK) {
1286 // Only 'dim' is allowed on a routine, so diallow num and static.
1287 case OpenACCGangKind::Num:
1288 case OpenACCGangKind::Static:
1289 return DiagIntArgInvalid(S, E, GK, OpenACCClauseKind::Gang, DK, AssocKind);
1290 case OpenACCGangKind::Dim:
1291 return CheckGangDimExpr(S, E);
1292 }
1293 llvm_unreachable("Unknown gang kind in gang serial check");
1294}
1295
1296OpenACCClause *SemaOpenACCClauseVisitor::VisitVectorClause(
1298 if (DiagGangWorkerVectorSeqConflict(Clause))
1299 return nullptr;
1300
1301 Expr *IntExpr =
1302 Clause.getNumIntExprs() != 0 ? Clause.getIntExprs()[0] : nullptr;
1303 if (IntExpr) {
1304 switch (Clause.getDirectiveKind()) {
1305 default:
1306 llvm_unreachable("Invalid directive kind for this clause");
1307 case OpenACCDirectiveKind::Loop:
1308 switch (SemaRef.getActiveComputeConstructInfo().Kind) {
1309 case OpenACCDirectiveKind::Invalid:
1310 case OpenACCDirectiveKind::Parallel:
1311 case OpenACCDirectiveKind::ParallelLoop:
1312 // No restriction on when 'parallel' can contain an argument.
1313 break;
1314 case OpenACCDirectiveKind::Serial:
1315 case OpenACCDirectiveKind::SerialLoop:
1316 // GCC disallows this, and there is no real good reason for us to permit
1317 // it, so disallow until we come up with a use case that makes sense.
1318 DiagIntArgInvalid(SemaRef, IntExpr, "length", OpenACCClauseKind::Vector,
1319 Clause.getDirectiveKind(),
1320 SemaRef.getActiveComputeConstructInfo().Kind);
1321 IntExpr = nullptr;
1322 break;
1323 case OpenACCDirectiveKind::Kernels:
1324 case OpenACCDirectiveKind::KernelsLoop: {
1325 const auto *Itr =
1326 llvm::find_if(SemaRef.getActiveComputeConstructInfo().Clauses,
1327 llvm::IsaPred<OpenACCVectorLengthClause>);
1328 if (Itr != SemaRef.getActiveComputeConstructInfo().Clauses.end()) {
1329 SemaRef.Diag(IntExpr->getBeginLoc(), diag::err_acc_num_arg_conflict)
1330 << "length" << OpenACCClauseKind::Vector
1331 << Clause.getDirectiveKind()
1332 << HasAssocKind(Clause.getDirectiveKind(),
1333 SemaRef.getActiveComputeConstructInfo().Kind)
1334 << SemaRef.getActiveComputeConstructInfo().Kind
1335 << OpenACCClauseKind::VectorLength;
1336 SemaRef.Diag((*Itr)->getBeginLoc(),
1337 diag::note_acc_previous_clause_here)
1338 << (*Itr)->getClauseKind();
1339
1340 IntExpr = nullptr;
1341 }
1342 break;
1343 }
1344 default:
1345 llvm_unreachable("Non compute construct in active compute construct");
1346 }
1347 break;
1348 case OpenACCDirectiveKind::KernelsLoop: {
1349 const auto *Itr = llvm::find_if(ExistingClauses,
1350 llvm::IsaPred<OpenACCVectorLengthClause>);
1351 if (Itr != ExistingClauses.end()) {
1352 SemaRef.Diag(IntExpr->getBeginLoc(), diag::err_acc_num_arg_conflict)
1353 << "length" << OpenACCClauseKind::Vector
1354 << Clause.getDirectiveKind()
1355 << HasAssocKind(Clause.getDirectiveKind(),
1356 SemaRef.getActiveComputeConstructInfo().Kind)
1357 << SemaRef.getActiveComputeConstructInfo().Kind
1358 << OpenACCClauseKind::VectorLength;
1359 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here)
1360 << (*Itr)->getClauseKind();
1361
1362 IntExpr = nullptr;
1363 }
1364 break;
1365 }
1366 case OpenACCDirectiveKind::SerialLoop:
1367 case OpenACCDirectiveKind::Routine:
1368 DiagIntArgInvalid(SemaRef, IntExpr, "length", OpenACCClauseKind::Vector,
1369 Clause.getDirectiveKind(),
1370 SemaRef.getActiveComputeConstructInfo().Kind);
1371 IntExpr = nullptr;
1372 break;
1373 case OpenACCDirectiveKind::ParallelLoop:
1374 break;
1375 case OpenACCDirectiveKind::Invalid:
1376 // This can happen when the directive was not recognized, but we continued
1377 // anyway. Since there is a lot of stuff that can happen (including
1378 // 'allow anything' in the parallel loop case), just skip all checking and
1379 // continue.
1380 break;
1381 }
1382 }
1383
1384 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Loop) {
1385 // OpenACC 3.3 2.9.4: The region of a loop with a 'vector' clause may not
1386 // contain a loop with a gang, worker, or vector clause unless within a
1387 // nested compute region.
1388 if (SemaRef.LoopVectorClauseLoc.isValid()) {
1389 // This handles the 'inner loop' diagnostic, but we cannot set that we're
1390 // on one of these until we get to the end of the construct.
1391 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1392 << OpenACCClauseKind::Vector << OpenACCClauseKind::Vector
1393 << /*skip kernels construct info*/ 0;
1394 SemaRef.Diag(SemaRef.LoopVectorClauseLoc,
1395 diag::note_acc_previous_clause_here)
1396 << "vector";
1397 return nullptr;
1398 }
1399 }
1400
1401 return OpenACCVectorClause::Create(Ctx, Clause.getBeginLoc(),
1402 Clause.getLParenLoc(), IntExpr,
1403 Clause.getEndLoc());
1404}
1405
1406OpenACCClause *SemaOpenACCClauseVisitor::VisitWorkerClause(
1408 if (DiagGangWorkerVectorSeqConflict(Clause))
1409 return nullptr;
1410
1411 Expr *IntExpr =
1412 Clause.getNumIntExprs() != 0 ? Clause.getIntExprs()[0] : nullptr;
1413
1414 if (IntExpr) {
1415 switch (Clause.getDirectiveKind()) {
1416 default:
1417 llvm_unreachable("Invalid directive kind for this clause");
1418 case OpenACCDirectiveKind::Invalid:
1419 // This can happen in cases where the directive was not recognized but we
1420 // continued anyway. Kernels allows kind of any integer argument, so we
1421 // can assume it is that (rather than marking the argument invalid like
1422 // with parallel/serial/routine), and just continue as if nothing
1423 // happened. We'll skip the 'kernels' checking vs num-workers, since this
1424 // MIGHT be something else.
1425 break;
1426 case OpenACCDirectiveKind::Loop:
1427 switch (SemaRef.getActiveComputeConstructInfo().Kind) {
1428 case OpenACCDirectiveKind::Invalid:
1429 case OpenACCDirectiveKind::ParallelLoop:
1430 case OpenACCDirectiveKind::SerialLoop:
1431 case OpenACCDirectiveKind::Parallel:
1432 case OpenACCDirectiveKind::Serial:
1433 DiagIntArgInvalid(SemaRef, IntExpr, OpenACCGangKind::Num,
1434 OpenACCClauseKind::Worker, Clause.getDirectiveKind(),
1435 SemaRef.getActiveComputeConstructInfo().Kind);
1436 IntExpr = nullptr;
1437 break;
1438 case OpenACCDirectiveKind::KernelsLoop:
1439 case OpenACCDirectiveKind::Kernels: {
1440 const auto *Itr =
1441 llvm::find_if(SemaRef.getActiveComputeConstructInfo().Clauses,
1442 llvm::IsaPred<OpenACCNumWorkersClause>);
1443 if (Itr != SemaRef.getActiveComputeConstructInfo().Clauses.end()) {
1444 SemaRef.Diag(IntExpr->getBeginLoc(), diag::err_acc_num_arg_conflict)
1445 << "num" << OpenACCClauseKind::Worker << Clause.getDirectiveKind()
1446 << HasAssocKind(Clause.getDirectiveKind(),
1447 SemaRef.getActiveComputeConstructInfo().Kind)
1448 << SemaRef.getActiveComputeConstructInfo().Kind
1449 << OpenACCClauseKind::NumWorkers;
1450 SemaRef.Diag((*Itr)->getBeginLoc(),
1451 diag::note_acc_previous_clause_here)
1452 << (*Itr)->getClauseKind();
1453
1454 IntExpr = nullptr;
1455 }
1456 break;
1457 }
1458 default:
1459 llvm_unreachable("Non compute construct in active compute construct");
1460 }
1461 break;
1462 case OpenACCDirectiveKind::ParallelLoop:
1463 case OpenACCDirectiveKind::SerialLoop:
1464 case OpenACCDirectiveKind::Routine:
1465 DiagIntArgInvalid(SemaRef, IntExpr, OpenACCGangKind::Num,
1466 OpenACCClauseKind::Worker, Clause.getDirectiveKind(),
1467 SemaRef.getActiveComputeConstructInfo().Kind);
1468 IntExpr = nullptr;
1469 break;
1470 case OpenACCDirectiveKind::KernelsLoop: {
1471 const auto *Itr = llvm::find_if(ExistingClauses,
1472 llvm::IsaPred<OpenACCNumWorkersClause>);
1473 if (Itr != ExistingClauses.end()) {
1474 SemaRef.Diag(IntExpr->getBeginLoc(), diag::err_acc_num_arg_conflict)
1475 << "num" << OpenACCClauseKind::Worker << Clause.getDirectiveKind()
1476 << HasAssocKind(Clause.getDirectiveKind(),
1477 SemaRef.getActiveComputeConstructInfo().Kind)
1478 << SemaRef.getActiveComputeConstructInfo().Kind
1479 << OpenACCClauseKind::NumWorkers;
1480 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here)
1481 << (*Itr)->getClauseKind();
1482
1483 IntExpr = nullptr;
1484 }
1485 }
1486 }
1487 }
1488
1489 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Loop) {
1490 // OpenACC 3.3 2.9.3: The region of a loop with a 'worker' clause may not
1491 // contain a loop with a gang or worker clause unless within a nested
1492 // compute region.
1493 if (SemaRef.LoopWorkerClauseLoc.isValid()) {
1494 // This handles the 'inner loop' diagnostic, but we cannot set that we're
1495 // on one of these until we get to the end of the construct.
1496 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1497 << OpenACCClauseKind::Worker << OpenACCClauseKind::Worker
1498 << /*skip kernels construct info*/ 0;
1499 SemaRef.Diag(SemaRef.LoopWorkerClauseLoc,
1500 diag::note_acc_previous_clause_here)
1501 << "worker";
1502 return nullptr;
1503 }
1504
1505 // OpenACC 3.3 2.9.4: The region of a loop with a 'vector' clause may not
1506 // contain a loop with a gang, worker, or vector clause unless within a
1507 // nested compute region.
1508 if (SemaRef.LoopVectorClauseLoc.isValid()) {
1509 // This handles the 'inner loop' diagnostic, but we cannot set that we're
1510 // on one of these until we get to the end of the construct.
1511 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1512 << OpenACCClauseKind::Worker << OpenACCClauseKind::Vector
1513 << /*skip kernels construct info*/ 0;
1514 SemaRef.Diag(SemaRef.LoopVectorClauseLoc,
1515 diag::note_acc_previous_clause_here)
1516 << "vector";
1517 return nullptr;
1518 }
1519 }
1520
1521 return OpenACCWorkerClause::Create(Ctx, Clause.getBeginLoc(),
1522 Clause.getLParenLoc(), IntExpr,
1523 Clause.getEndLoc());
1524}
1525
1526OpenACCClause *SemaOpenACCClauseVisitor::VisitGangClause(
1528
1529 if (DiagGangWorkerVectorSeqConflict(Clause))
1530 return nullptr;
1531
1532 // OpenACC 3.3 Section 2.9.11: A reduction clause may not appear on a loop
1533 // directive that has a gang clause and is within a compute construct that has
1534 // a num_gangs clause with more than one explicit argument.
1535 if ((Clause.getDirectiveKind() == OpenACCDirectiveKind::Loop &&
1536 SemaRef.getActiveComputeConstructInfo().Kind !=
1537 OpenACCDirectiveKind::Invalid) ||
1539 // num_gangs clause on the active compute construct.
1540 auto ActiveComputeConstructContainer =
1542 ? ExistingClauses
1543 : SemaRef.getActiveComputeConstructInfo().Clauses;
1544 auto *NumGangsClauseItr = llvm::find_if(
1545 ActiveComputeConstructContainer, llvm::IsaPred<OpenACCNumGangsClause>);
1546
1547 if (NumGangsClauseItr != ActiveComputeConstructContainer.end() &&
1548 cast<OpenACCNumGangsClause>(*NumGangsClauseItr)->getIntExprs().size() >
1549 1) {
1550 auto *ReductionClauseItr =
1551 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
1552
1553 if (ReductionClauseItr != ExistingClauses.end()) {
1554 SemaRef.Diag(Clause.getBeginLoc(),
1555 diag::err_acc_gang_reduction_numgangs_conflict)
1556 << OpenACCClauseKind::Gang << OpenACCClauseKind::Reduction
1557 << Clause.getDirectiveKind()
1559 SemaRef.Diag((*ReductionClauseItr)->getBeginLoc(),
1560 diag::note_acc_previous_clause_here)
1561 << (*ReductionClauseItr)->getClauseKind();
1562 SemaRef.Diag((*NumGangsClauseItr)->getBeginLoc(),
1563 diag::note_acc_previous_clause_here)
1564 << (*NumGangsClauseItr)->getClauseKind();
1565 return nullptr;
1566 }
1567 }
1568 }
1569
1572
1573 // Store the existing locations, so we can do duplicate checking. Index is
1574 // the int-value of the OpenACCGangKind enum.
1575 SourceLocation ExistingElemLoc[3];
1576
1577 for (unsigned I = 0; I < Clause.getIntExprs().size(); ++I) {
1578 OpenACCGangKind GK = Clause.getGangKinds()[I];
1579 ExprResult ER =
1580 SemaRef.CheckGangExpr(ExistingClauses, Clause.getDirectiveKind(), GK,
1581 Clause.getIntExprs()[I]);
1582
1583 if (!ER.isUsable())
1584 continue;
1585
1586 // OpenACC 3.3 2.9: 'gang-arg-list' may have at most one num, one dim, and
1587 // one static argument.
1588 if (ExistingElemLoc[static_cast<unsigned>(GK)].isValid()) {
1589 SemaRef.Diag(ER.get()->getBeginLoc(), diag::err_acc_gang_multiple_elt)
1590 << static_cast<unsigned>(GK);
1591 SemaRef.Diag(ExistingElemLoc[static_cast<unsigned>(GK)],
1592 diag::note_acc_previous_expr_here);
1593 continue;
1594 }
1595
1596 ExistingElemLoc[static_cast<unsigned>(GK)] = ER.get()->getBeginLoc();
1597 GangKinds.push_back(GK);
1598 IntExprs.push_back(ER.get());
1599 }
1600
1601 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Loop) {
1602 // OpenACC 3.3 2.9.2: When the parent compute construct is a kernels
1603 // construct, the gang clause behaves as follows. ... The region of a loop
1604 // with a gang clause may not contain another loop with a gang clause unless
1605 // within a nested compute region.
1606 if (SemaRef.LoopGangClauseOnKernel.Loc.isValid()) {
1607 // This handles the 'inner loop' diagnostic, but we cannot set that we're
1608 // on one of these until we get to the end of the construct.
1609 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1610 << OpenACCClauseKind::Gang << OpenACCClauseKind::Gang
1611 << /*kernels construct info*/ 1
1613 SemaRef.Diag(SemaRef.LoopGangClauseOnKernel.Loc,
1614 diag::note_acc_previous_clause_here)
1615 << "gang";
1616 return nullptr;
1617 }
1618
1619 // OpenACC 3.3 2.9.3: The region of a loop with a 'worker' clause may not
1620 // contain a loop with a gang or worker clause unless within a nested
1621 // compute region.
1622 if (SemaRef.LoopWorkerClauseLoc.isValid()) {
1623 // This handles the 'inner loop' diagnostic, but we cannot set that we're
1624 // on one of these until we get to the end of the construct.
1625 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1626 << OpenACCClauseKind::Gang << OpenACCClauseKind::Worker
1627 << /*!kernels construct info*/ 0;
1628 SemaRef.Diag(SemaRef.LoopWorkerClauseLoc,
1629 diag::note_acc_previous_clause_here)
1630 << "worker";
1631 return nullptr;
1632 }
1633
1634 // OpenACC 3.3 2.9.4: The region of a loop with a 'vector' clause may not
1635 // contain a loop with a gang, worker, or vector clause unless within a
1636 // nested compute region.
1637 if (SemaRef.LoopVectorClauseLoc.isValid()) {
1638 // This handles the 'inner loop' diagnostic, but we cannot set that we're
1639 // on one of these until we get to the end of the construct.
1640 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1641 << OpenACCClauseKind::Gang << OpenACCClauseKind::Vector
1642 << /*!kernels construct info*/ 0;
1643 SemaRef.Diag(SemaRef.LoopVectorClauseLoc,
1644 diag::note_acc_previous_clause_here)
1645 << "vector";
1646 return nullptr;
1647 }
1648 }
1649
1650 return SemaRef.CheckGangClause(Clause.getDirectiveKind(), ExistingClauses,
1651 Clause.getBeginLoc(), Clause.getLParenLoc(),
1652 GangKinds, IntExprs, Clause.getEndLoc());
1653}
1654
1655OpenACCClause *SemaOpenACCClauseVisitor::VisitFinalizeClause(
1657 // There isn't anything to do here, this is only valid on one construct, and
1658 // has no associated rules.
1659 return OpenACCFinalizeClause::Create(Ctx, Clause.getBeginLoc(),
1660 Clause.getEndLoc());
1661}
1662
1663OpenACCClause *SemaOpenACCClauseVisitor::VisitIfPresentClause(
1665 // There isn't anything to do here, this is only valid on one construct, and
1666 // has no associated rules.
1667 return OpenACCIfPresentClause::Create(Ctx, Clause.getBeginLoc(),
1668 Clause.getEndLoc());
1669}
1670
1671OpenACCClause *SemaOpenACCClauseVisitor::VisitSeqClause(
1673 // OpenACC 3.3 2.9:
1674 // A 'gang', 'worker', or 'vector' clause may not appear if a 'seq' clause
1675 // appears.
1676 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Loop ||
1678 const auto *Itr = llvm::find_if(
1679 ExistingClauses, llvm::IsaPred<OpenACCGangClause, OpenACCVectorClause,
1681 if (Itr != ExistingClauses.end()) {
1682 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_cannot_combine)
1683 << Clause.getClauseKind() << (*Itr)->getClauseKind()
1684 << Clause.getDirectiveKind();
1685 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here)
1686 << (*Itr)->getClauseKind();
1687 return nullptr;
1688 }
1689 }
1690
1691 return OpenACCSeqClause::Create(Ctx, Clause.getBeginLoc(),
1692 Clause.getEndLoc());
1693}
1694
1695OpenACCClause *SemaOpenACCClauseVisitor::VisitReductionClause(
1697 // OpenACC 3.3 Section 2.9.11: A reduction clause may not appear on a loop
1698 // directive that has a gang clause and is within a compute construct that has
1699 // a num_gangs clause with more than one explicit argument.
1700 if ((Clause.getDirectiveKind() == OpenACCDirectiveKind::Loop &&
1701 SemaRef.getActiveComputeConstructInfo().Kind !=
1702 OpenACCDirectiveKind::Invalid) ||
1704 // num_gangs clause on the active compute construct.
1705 auto ActiveComputeConstructContainer =
1707 ? ExistingClauses
1708 : SemaRef.getActiveComputeConstructInfo().Clauses;
1709 auto *NumGangsClauseItr = llvm::find_if(
1710 ActiveComputeConstructContainer, llvm::IsaPred<OpenACCNumGangsClause>);
1711
1712 if (NumGangsClauseItr != ActiveComputeConstructContainer.end() &&
1713 cast<OpenACCNumGangsClause>(*NumGangsClauseItr)->getIntExprs().size() >
1714 1) {
1715 auto *GangClauseItr =
1716 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
1717
1718 if (GangClauseItr != ExistingClauses.end()) {
1719 SemaRef.Diag(Clause.getBeginLoc(),
1720 diag::err_acc_gang_reduction_numgangs_conflict)
1721 << OpenACCClauseKind::Reduction << OpenACCClauseKind::Gang
1722 << Clause.getDirectiveKind()
1724 SemaRef.Diag((*GangClauseItr)->getBeginLoc(),
1725 diag::note_acc_previous_clause_here)
1726 << (*GangClauseItr)->getClauseKind();
1727 SemaRef.Diag((*NumGangsClauseItr)->getBeginLoc(),
1728 diag::note_acc_previous_clause_here)
1729 << (*NumGangsClauseItr)->getClauseKind();
1730 return nullptr;
1731 }
1732 }
1733 }
1734
1735 // OpenACC3.3 Section 2.9.11: If a variable is involved in a reduction that
1736 // spans multiple nested loops where two or more of those loops have
1737 // associated loop directives, a reduction clause containing that variable
1738 // must appear on each of those loop directives.
1739 //
1740 // This can't really be implemented in the CFE, as this requires a level of
1741 // rechability/useage analysis that we're not really wanting to get into.
1742 // Additionally, I'm alerted that this restriction is one that the middle-end
1743 // can just 'figure out' as an extension and isn't really necessary.
1744 //
1745 // OpenACC3.3 Section 2.9.11: Every 'var' in a reduction clause appearing on
1746 // an orphaned loop construct must be private.
1747 //
1748 // This again is something we cannot really diagnose, as it requires we see
1749 // all the uses/scopes of all variables referenced. The middle end/MLIR might
1750 // be able to diagnose this.
1751
1752 // OpenACC 3.3 Section 2.5.4:
1753 // A reduction clause may not appear on a parallel construct with a
1754 // num_gangs clause that has more than one argument.
1755 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Parallel ||
1756 Clause.getDirectiveKind() == OpenACCDirectiveKind::ParallelLoop) {
1757 auto NumGangsClauses = llvm::make_filter_range(
1758 ExistingClauses, llvm::IsaPred<OpenACCNumGangsClause>);
1759
1760 for (auto *NGC : NumGangsClauses) {
1761 unsigned NumExprs =
1762 cast<OpenACCNumGangsClause>(NGC)->getIntExprs().size();
1763
1764 if (NumExprs > 1) {
1765 SemaRef.Diag(Clause.getBeginLoc(),
1766 diag::err_acc_reduction_num_gangs_conflict)
1767 << /*>1 arg in first loc=*/0 << Clause.getClauseKind()
1768 << Clause.getDirectiveKind() << OpenACCClauseKind::NumGangs;
1769 SemaRef.Diag(NGC->getBeginLoc(), diag::note_acc_previous_clause_here)
1770 << NGC->getClauseKind();
1771 return nullptr;
1772 }
1773 }
1774 }
1775
1776 SmallVector<Expr *> ValidVars;
1778
1779 for (Expr *Var : Clause.getVarList()) {
1780 ExprResult Res = SemaRef.CheckReductionVar(Clause.getDirectiveKind(),
1781 Clause.getReductionOp(), Var);
1782
1783 if (Res.isUsable()) {
1784 ValidVars.push_back(Res.get());
1785
1786 VarDecl *InitRecipe =
1787 SemaRef
1788 .CreateInitRecipe(OpenACCClauseKind::Reduction,
1789 Clause.getReductionOp(), Res.get())
1790 .first;
1791 Recipes.push_back({InitRecipe});
1792 }
1793 }
1794
1795 return SemaRef.CheckReductionClause(
1796 ExistingClauses, Clause.getDirectiveKind(), Clause.getBeginLoc(),
1797 Clause.getLParenLoc(), Clause.getReductionOp(), ValidVars,
1798 Recipes,
1799 Clause.getEndLoc());
1800}
1801
1802OpenACCClause *SemaOpenACCClauseVisitor::VisitCollapseClause(
1804
1805 if (DisallowSinceLastDeviceType<OpenACCCollapseClause>(Clause))
1806 return nullptr;
1807
1808 ExprResult LoopCount = SemaRef.CheckCollapseLoopCount(Clause.getLoopCount());
1809
1810 if (!LoopCount.isUsable())
1811 return nullptr;
1812
1813 return OpenACCCollapseClause::Create(Ctx, Clause.getBeginLoc(),
1814 Clause.getLParenLoc(), Clause.isForce(),
1815 LoopCount.get(), Clause.getEndLoc());
1816}
1817
1818OpenACCClause *SemaOpenACCClauseVisitor::VisitBindClause(
1820
1821 if (std::holds_alternative<StringLiteral *>(Clause.getBindDetails()))
1823 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(),
1824 std::get<StringLiteral *>(Clause.getBindDetails()), Clause.getEndLoc());
1826 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(),
1827 std::get<IdentifierInfo *>(Clause.getBindDetails()), Clause.getEndLoc());
1828}
1829
1830// Return true if the two vars refer to the same variable, for the purposes of
1831// equality checking.
1832bool areVarsEqual(Expr *VarExpr1, Expr *VarExpr2) {
1833 if (VarExpr1->isInstantiationDependent() ||
1834 VarExpr2->isInstantiationDependent())
1835 return false;
1836
1837 VarExpr1 = VarExpr1->IgnoreParenCasts();
1838 VarExpr2 = VarExpr2->IgnoreParenCasts();
1839
1840 // Legal expressions can be: Scalar variable reference, sub-array, array
1841 // element, or composite variable member.
1842
1843 // Sub-array.
1844 if (isa<ArraySectionExpr>(VarExpr1)) {
1845 auto *Expr2AS = dyn_cast<ArraySectionExpr>(VarExpr2);
1846 if (!Expr2AS)
1847 return false;
1848
1849 auto *Expr1AS = cast<ArraySectionExpr>(VarExpr1);
1850
1851 if (!areVarsEqual(Expr1AS->getBase(), Expr2AS->getBase()))
1852 return false;
1853 // We could possibly check to see if the ranges aren't overlapping, but it
1854 // isn't clear that the rules allow this.
1855 return true;
1856 }
1857
1858 // Array-element.
1859 if (isa<ArraySubscriptExpr>(VarExpr1)) {
1860 auto *Expr2AS = dyn_cast<ArraySubscriptExpr>(VarExpr2);
1861 if (!Expr2AS)
1862 return false;
1863
1864 auto *Expr1AS = cast<ArraySubscriptExpr>(VarExpr1);
1865
1866 if (!areVarsEqual(Expr1AS->getBase(), Expr2AS->getBase()))
1867 return false;
1868
1869 // We could possibly check to see if the elements referenced aren't the
1870 // same, but it isn't clear by reading of the standard that this is allowed
1871 // (and that the 'var' refered to isn't the array).
1872 return true;
1873 }
1874
1875 // Scalar variable reference, or composite variable.
1876 if (isa<DeclRefExpr>(VarExpr1)) {
1877 auto *Expr2DRE = dyn_cast<DeclRefExpr>(VarExpr2);
1878 if (!Expr2DRE)
1879 return false;
1880
1881 auto *Expr1DRE = cast<DeclRefExpr>(VarExpr1);
1882
1883 return Expr1DRE->getDecl()->getMostRecentDecl() ==
1884 Expr2DRE->getDecl()->getMostRecentDecl();
1885 }
1886
1887 llvm_unreachable("Unknown variable type encountered");
1888}
1889} // namespace
1890
1893 OpenACCParsedClause &Clause) {
1895 return nullptr;
1896
1897 if (DiagnoseAllowedClauses(Clause.getDirectiveKind(), Clause.getClauseKind(),
1898 Clause.getBeginLoc()))
1899 return nullptr;
1900 //// Diagnose that we don't support this clause on this directive.
1901 // if (!doesClauseApplyToDirective(Clause.getDirectiveKind(),
1902 // Clause.getClauseKind())) {
1903 // Diag(Clause.getBeginLoc(), diag::err_acc_clause_appertainment)
1904 // << Clause.getDirectiveKind() << Clause.getClauseKind();
1905 // return nullptr;
1906 // }
1907
1908 if (const auto *DevTypeClause = llvm::find_if(
1909 ExistingClauses, llvm::IsaPred<OpenACCDeviceTypeClause>);
1910 DevTypeClause != ExistingClauses.end()) {
1911 if (checkValidAfterDeviceType(
1912 *this, *cast<OpenACCDeviceTypeClause>(*DevTypeClause), Clause))
1913 return nullptr;
1914 }
1915
1916 SemaOpenACCClauseVisitor Visitor{*this, ExistingClauses};
1917 OpenACCClause *Result = Visitor.Visit(Clause);
1918 assert((!Result || Result->getClauseKind() == Clause.getClauseKind()) &&
1919 "Created wrong clause?");
1920
1921 return Result;
1922}
1923
1924/// OpenACC 3.3 section 2.5.15:
1925/// At a mininmum, the supported data types include ... the numerical data types
1926/// in C, C++, and Fortran.
1927///
1928/// If the reduction var is a composite variable, each
1929/// member of the composite variable must be a supported datatype for the
1930/// reduction operation.
1932 OpenACCReductionOperator ReductionOp,
1933 Expr *VarExpr) {
1934 // For now, we only support 'scalar' types, or composites/arrays of scalar
1935 // types.
1936 VarExpr = VarExpr->IgnoreParenCasts();
1937 SourceLocation VarLoc = VarExpr->getBeginLoc();
1938
1940 QualType CurType = VarExpr->getType();
1941
1942 // For array like things, the expression can either be an array element
1943 // (subscript expr), array section, or array type. Peel those off, and add
1944 // notes in case we find an illegal kind. We'll allow scalar or composite of
1945 // scalars inside of this.
1946 if (auto *ASE = dyn_cast<ArraySectionExpr>(VarExpr)) {
1948
1949 PartialDiagnostic PD = PDiag(diag::note_acc_reduction_array)
1950 << diag::OACCReductionArray::Section << BaseType;
1951 Notes.push_back({ASE->getBeginLoc(), PD});
1952
1953 CurType = getASTContext().getBaseElementType(BaseType);
1954 } else if (auto *SubExpr = dyn_cast<ArraySubscriptExpr>(VarExpr)) {
1955 // Array subscript already results in the type of the thing as its type, so
1956 // there is no type to change here.
1958 PDiag(diag::note_acc_reduction_array)
1959 << diag::OACCReductionArray::Subscript
1960 << SubExpr->getBase()->IgnoreParenImpCasts()->getType();
1961 Notes.push_back({SubExpr->getBeginLoc(), PD});
1962 } else if (auto *AT = getASTContext().getAsArrayType(CurType)) {
1963 // If we're already the array type, peel off the array and leave the element
1964 // type.
1965 CurType = getASTContext().getBaseElementType(AT);
1966 PartialDiagnostic PD = PDiag(diag::note_acc_reduction_array)
1967 << diag::OACCReductionArray::ArrayTy << CurType;
1968 Notes.push_back({VarLoc, PD});
1969 }
1970
1971 auto IsValidMemberOfComposite = [](QualType Ty) {
1972 return !Ty->isAnyComplexType() &&
1973 (Ty->isDependentType() ||
1974 (Ty->isScalarType() && !Ty->isPointerType()));
1975 };
1976
1977 auto EmitDiags = [&](SourceLocation Loc, PartialDiagnostic PD) {
1978 Diag(Loc, PD);
1979
1980 for (auto [Loc, PD] : Notes)
1981 Diag(Loc, PD);
1982
1983 Diag(VarLoc, diag::note_acc_reduction_type_summary);
1984 };
1985
1986 // If the type is already scalar, or is dependent, just give up.
1987 if (IsValidMemberOfComposite(CurType)) {
1988 // Nothing to do here, is valid.
1989 } else if (auto *RD = CurType->getAsRecordDecl()) {
1990 if (!RD->isStruct() && !RD->isClass()) {
1991 EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
1992 << RD << diag::OACCReductionTy::NotClassStruct);
1993 return ExprError();
1994 }
1995
1996 if (!RD->isCompleteDefinition()) {
1997 EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
1998 << RD << diag::OACCReductionTy::NotComplete);
1999 return ExprError();
2000 }
2001
2002 if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
2003 CXXRD && !CXXRD->isAggregate()) {
2004 EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
2005 << CXXRD << diag::OACCReductionTy::NotAgg);
2006 return ExprError();
2007 }
2008
2009 for (FieldDecl *FD : RD->fields()) {
2010 if (!IsValidMemberOfComposite(FD->getType())) {
2012 PDiag(diag::note_acc_reduction_member_of_composite)
2013 << FD->getName() << RD->getName();
2014 Notes.push_back({FD->getBeginLoc(), PD});
2015 // TODO: member here.note_acc_reduction_member_of_composite
2016 EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
2017 << FD->getType()
2018 << diag::OACCReductionTy::MemberNotScalar);
2019 return ExprError();
2020 }
2021 }
2022 } else {
2023 EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
2024 << CurType << diag::OACCReductionTy::NotScalar);
2025 }
2026
2027 // OpenACC3.3: 2.9.11: Reduction clauses on nested constructs for the same
2028 // reduction 'var' must have the same reduction operator.
2029 if (!VarExpr->isInstantiationDependent()) {
2030
2031 for (const OpenACCReductionClause *RClause : ActiveReductionClauses) {
2032 if (RClause->getReductionOp() == ReductionOp)
2033 break;
2034
2035 for (Expr *OldVarExpr : RClause->getVarList()) {
2036 if (OldVarExpr->isInstantiationDependent())
2037 continue;
2038
2039 if (areVarsEqual(VarExpr, OldVarExpr)) {
2040 Diag(VarExpr->getExprLoc(), diag::err_reduction_op_mismatch)
2041 << ReductionOp << RClause->getReductionOp();
2042 Diag(OldVarExpr->getExprLoc(), diag::note_acc_previous_clause_here)
2043 << RClause->getClauseKind();
2044 return ExprError();
2045 }
2046 }
2047 }
2048 }
2049
2050 return VarExpr;
2051}
2052
2054 if (!SizeExpr)
2055 return ExprError();
2056
2057 assert((SizeExpr->isInstantiationDependent() ||
2058 SizeExpr->getType()->isIntegerType()) &&
2059 "size argument non integer?");
2060
2061 // If dependent, or an asterisk, the expression is fine.
2062 if (SizeExpr->isInstantiationDependent() ||
2063 isa<OpenACCAsteriskSizeExpr>(SizeExpr))
2064 return ExprResult{SizeExpr};
2065
2066 std::optional<llvm::APSInt> ICE =
2068
2069 // OpenACC 3.3 2.9.8
2070 // where each tile size is a constant positive integer expression or asterisk.
2071 if (!ICE || *ICE <= 0) {
2072 Diag(SizeExpr->getBeginLoc(), diag::err_acc_size_expr_value)
2073 << ICE.has_value() << ICE.value_or(llvm::APSInt{}).getExtValue();
2074 return ExprError();
2075 }
2076
2077 return ExprResult{
2078 ConstantExpr::Create(getASTContext(), SizeExpr, APValue{*ICE})};
2079}
2080
2082 if (!LoopCount)
2083 return ExprError();
2084
2085 assert((LoopCount->isInstantiationDependent() ||
2086 LoopCount->getType()->isIntegerType()) &&
2087 "Loop argument non integer?");
2088
2089 // If this is dependent, there really isn't anything we can check.
2090 if (LoopCount->isInstantiationDependent())
2091 return ExprResult{LoopCount};
2092
2093 std::optional<llvm::APSInt> ICE =
2095
2096 // OpenACC 3.3: 2.9.1
2097 // The argument to the collapse clause must be a constant positive integer
2098 // expression.
2099 if (!ICE || *ICE <= 0) {
2100 Diag(LoopCount->getBeginLoc(), diag::err_acc_collapse_loop_count)
2101 << ICE.has_value() << ICE.value_or(llvm::APSInt{}).getExtValue();
2102 return ExprError();
2103 }
2104
2105 return ExprResult{
2106 ConstantExpr::Create(getASTContext(), LoopCount, APValue{*ICE})};
2107}
2108
2112 Expr *E) {
2113 // There are two cases for the enforcement here: the 'current' directive is a
2114 // 'loop', where we need to check the active compute construct kind, or the
2115 // current directive is a 'combined' construct, where we have to check the
2116 // current one.
2117 switch (DK) {
2119 return CheckGangParallelExpr(*this, DK, ActiveComputeConstructInfo.Kind, GK,
2120 E);
2122 return CheckGangSerialExpr(*this, DK, ActiveComputeConstructInfo.Kind, GK,
2123 E);
2125 return CheckGangKernelsExpr(*this, ExistingClauses, DK,
2126 ActiveComputeConstructInfo.Kind, GK, E);
2128 return CheckGangRoutineExpr(*this, DK, ActiveComputeConstructInfo.Kind, GK,
2129 E);
2131 switch (ActiveComputeConstructInfo.Kind) {
2135 return CheckGangParallelExpr(*this, DK, ActiveComputeConstructInfo.Kind,
2136 GK, E);
2139 return CheckGangSerialExpr(*this, DK, ActiveComputeConstructInfo.Kind, GK,
2140 E);
2143 return CheckGangKernelsExpr(*this, ExistingClauses, DK,
2144 ActiveComputeConstructInfo.Kind, GK, E);
2145 default:
2146 llvm_unreachable("Non compute construct in active compute construct?");
2147 }
2149 // This can happen in cases where the the directive was not recognized but
2150 // we continued anyway. Since the validity checking is all-over the place
2151 // (it can be a star/integer, or a constant expr depending on the tag), we
2152 // just give up and return an ExprError here.
2153 return ExprError();
2154 default:
2155 llvm_unreachable("Invalid directive kind for a Gang clause");
2156 }
2157 llvm_unreachable("Compute construct directive not handled?");
2158}
2159
2162 ArrayRef<const OpenACCClause *> ExistingClauses,
2163 SourceLocation BeginLoc, SourceLocation LParenLoc,
2164 ArrayRef<OpenACCGangKind> GangKinds,
2165 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc) {
2166 // Reduction isn't possible on 'routine' so we don't bother checking it here.
2167 if (DirKind != OpenACCDirectiveKind::Routine) {
2168 // OpenACC 3.3 2.9.11: A reduction clause may not appear on a loop directive
2169 // that has a gang clause with a dim: argument whose value is greater
2170 // than 1.
2171 const auto *ReductionItr =
2172 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
2173
2174 if (ReductionItr != ExistingClauses.end()) {
2175 const auto GangZip = llvm::zip_equal(GangKinds, IntExprs);
2176 const auto GangItr = llvm::find_if(GangZip, [](const auto &Tuple) {
2177 return std::get<0>(Tuple) == OpenACCGangKind::Dim;
2178 });
2179
2180 if (GangItr != GangZip.end()) {
2181 const Expr *DimExpr = std::get<1>(*GangItr);
2182
2183 assert((DimExpr->isInstantiationDependent() ||
2184 isa<ConstantExpr>(DimExpr)) &&
2185 "Improperly formed gang argument");
2186 if (const auto *DimVal = dyn_cast<ConstantExpr>(DimExpr);
2187 DimVal && DimVal->getResultAsAPSInt() > 1) {
2188 Diag(DimVal->getBeginLoc(), diag::err_acc_gang_reduction_conflict)
2189 << /*gang/reduction=*/0 << DirKind;
2190 Diag((*ReductionItr)->getBeginLoc(),
2191 diag::note_acc_previous_clause_here)
2192 << (*ReductionItr)->getClauseKind();
2193 return nullptr;
2194 }
2195 }
2196 }
2197 }
2198
2199 return OpenACCGangClause::Create(getASTContext(), BeginLoc, LParenLoc,
2200 GangKinds, IntExprs, EndLoc);
2201}
2202
2204 ArrayRef<const OpenACCClause *> ExistingClauses,
2205 OpenACCDirectiveKind DirectiveKind, SourceLocation BeginLoc,
2206 SourceLocation LParenLoc, OpenACCReductionOperator ReductionOp,
2208 SourceLocation EndLoc) {
2209 if (DirectiveKind == OpenACCDirectiveKind::Loop ||
2210 isOpenACCCombinedDirectiveKind(DirectiveKind)) {
2211 // OpenACC 3.3 2.9.11: A reduction clause may not appear on a loop directive
2212 // that has a gang clause with a dim: argument whose value is greater
2213 // than 1.
2214 const auto GangClauses = llvm::make_filter_range(
2215 ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
2216
2217 for (auto *GC : GangClauses) {
2218 const auto *GangClause = cast<OpenACCGangClause>(GC);
2219 for (unsigned I = 0; I < GangClause->getNumExprs(); ++I) {
2220 std::pair<OpenACCGangKind, const Expr *> EPair = GangClause->getExpr(I);
2221 if (EPair.first != OpenACCGangKind::Dim)
2222 continue;
2223
2224 if (const auto *DimVal = dyn_cast<ConstantExpr>(EPair.second);
2225 DimVal && DimVal->getResultAsAPSInt() > 1) {
2226 Diag(BeginLoc, diag::err_acc_gang_reduction_conflict)
2227 << /*reduction/gang=*/1 << DirectiveKind;
2228 Diag(GangClause->getBeginLoc(), diag::note_acc_previous_clause_here)
2229 << GangClause->getClauseKind();
2230 return nullptr;
2231 }
2232 }
2233 }
2234 }
2235
2237 getASTContext(), BeginLoc, LParenLoc, ReductionOp, Vars, Recipes, EndLoc);
2238 return Ret;
2239}
2240
2243 const DeclContext *DC = removeLinkageSpecDC(getCurContext());
2244
2245 // Link has no special restrictions on its var list unless it is not at NS/TU
2246 // scope.
2247 if (isa<NamespaceDecl, TranslationUnitDecl>(DC))
2248 return llvm::SmallVector<Expr *>(VarExprs);
2249
2250 llvm::SmallVector<Expr *> NewVarList;
2251
2252 for (Expr *VarExpr : VarExprs) {
2253 if (isa<DependentScopeDeclRefExpr, CXXDependentScopeMemberExpr>(VarExpr)) {
2254 NewVarList.push_back(VarExpr);
2255 continue;
2256 }
2257
2258 // Field decls can't be global, nor extern, and declare can't refer to
2259 // non-static fields in class-scope, so this always fails the scope check.
2260 // BUT for now we add this so it gets diagnosed by the general 'declare'
2261 // rules.
2262 if (isa<MemberExpr>(VarExpr)) {
2263 NewVarList.push_back(VarExpr);
2264 continue;
2265 }
2266
2267 const auto *DRE = cast<DeclRefExpr>(VarExpr);
2268 const VarDecl *Var = dyn_cast<VarDecl>(DRE->getDecl());
2269
2270 if (!Var || !Var->hasExternalStorage())
2271 Diag(VarExpr->getBeginLoc(), diag::err_acc_link_not_extern);
2272 else
2273 NewVarList.push_back(VarExpr);
2274 }
2275
2276 return NewVarList;
2277}
2279 OpenACCModifierKind Mods) {
2280
2282 return false;
2283
2284 const DeclContext *DC = removeLinkageSpecDC(getCurContext());
2285
2286 // Whether this is 'create', 'copyin', 'deviceptr', 'device_resident', or
2287 // 'link', which have 2 special rules.
2288 bool IsSpecialClause =
2294
2295 // OpenACC 3.3 2.13:
2296 // In C or C++ global or namespace scope, only 'create',
2297 // 'copyin', 'deviceptr', 'device_resident', or 'link' clauses are
2298 // allowed.
2299 if (!IsSpecialClause && isa<NamespaceDecl, TranslationUnitDecl>(DC)) {
2300 return Diag(Clause.getBeginLoc(), diag::err_acc_declare_clause_at_global)
2301 << Clause.getClauseKind();
2302 }
2303
2304 llvm::SmallVector<Expr *> FilteredVarList;
2305 const DeclaratorDecl *CurDecl = nullptr;
2306 for (Expr *VarExpr : Clause.getVarList()) {
2307 if (isa<DependentScopeDeclRefExpr, CXXDependentScopeMemberExpr>(VarExpr)) {
2308 // There isn't really anything we can do here, so we add them anyway and
2309 // we can check them again when we instantiate this.
2310 } else if (const auto *MemExpr = dyn_cast<MemberExpr>(VarExpr)) {
2311 FieldDecl *FD =
2312 cast<FieldDecl>(MemExpr->getMemberDecl()->getCanonicalDecl());
2313 CurDecl = FD;
2314
2315 if (removeLinkageSpecDC(
2316 FD->getLexicalDeclContext()->getPrimaryContext()) != DC) {
2317 Diag(MemExpr->getBeginLoc(), diag::err_acc_declare_same_scope)
2318 << Clause.getClauseKind();
2319 continue;
2320 }
2321 } else {
2322
2323 const Expr *VarExprTemp = VarExpr;
2324
2325 while (const auto *ASE = dyn_cast<ArraySectionExpr>(VarExprTemp))
2326 VarExprTemp = ASE->getBase()->IgnoreParenImpCasts();
2327
2328 const auto *DRE = cast<DeclRefExpr>(VarExprTemp);
2329 if (const auto *Var = dyn_cast<VarDecl>(DRE->getDecl())) {
2330 CurDecl = Var->getCanonicalDecl();
2331
2332 // OpenACC3.3 2.13:
2333 // A 'declare' directive must be in the same scope as the declaration of
2334 // any var that appears in the clauses of the directive or any scope
2335 // within a C/C++ function.
2336 // We can't really check 'scope' here, so we check declaration context,
2337 // which is a reasonable approximation, but misses scopes inside of
2338 // functions.
2339 if (removeLinkageSpecDC(
2340 Var->getLexicalDeclContext()->getPrimaryContext()) != DC) {
2341 Diag(VarExpr->getBeginLoc(), diag::err_acc_declare_same_scope)
2342 << Clause.getClauseKind();
2343 continue;
2344 }
2345 // OpenACC3.3 2.13:
2346 // C and C++ extern variables may only appear in 'create',
2347 // 'copyin', 'deviceptr', 'device_resident', or 'link' clauses on a
2348 // 'declare' directive.
2349 if (!IsSpecialClause && Var->hasExternalStorage()) {
2350 Diag(VarExpr->getBeginLoc(), diag::err_acc_declare_extern)
2351 << Clause.getClauseKind();
2352 continue;
2353 }
2354 }
2355
2356 // OpenACC3.3 2.13:
2357 // A var may appear at most once in all the clauses of declare
2358 // directives for a function, subroutine, program, or module.
2359
2360 if (CurDecl) {
2361 auto [Itr, Inserted] = DeclareVarReferences.try_emplace(CurDecl);
2362 if (!Inserted) {
2363 Diag(VarExpr->getBeginLoc(), diag::err_acc_multiple_references)
2364 << Clause.getClauseKind();
2365 Diag(Itr->second, diag::note_acc_previous_reference);
2366 continue;
2367 } else {
2368 Itr->second = VarExpr->getBeginLoc();
2369 }
2370 }
2371 }
2372 FilteredVarList.push_back(VarExpr);
2373 }
2374
2375 Clause.setVarListDetails(FilteredVarList, Mods);
2376 return false;
2377}
Expr * E
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
OffloadArch Arch
Definition: OffloadArch.cpp:10
Defines some OpenACC-specific enums and functions.
SourceLocation Loc
Definition: SemaObjC.cpp:754
This file declares semantic analysis for OpenACC constructs and clauses.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
PtrTy get() const
Definition: Ownership.h:171
bool isUsable() const
Definition: Ownership.h:169
static QualType getBaseOriginalType(const Expr *Base)
Return original type of the base expression for array section.
Definition: Expr.cpp:5224
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition: Expr.cpp:346
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1449
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2109
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:1459
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:918
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:978
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:779
This represents one expression.
Definition: Expr.h:112
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:3078
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Definition: Expr.cpp:3073
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition: Expr.h:223
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:273
QualType getType() const
Definition: Expr.h:144
Represents a member of a struct/union/class.
Definition: Decl.h:3157
A simple pair of identifier info and location.
static OpenACCAsyncClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCAttachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCAutoClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCBindClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, const IdentifierInfo *ID, SourceLocation EndLoc)
This is the base type for all OpenACC Clauses.
Definition: OpenACCClause.h:27
OpenACCClauseKind getClauseKind() const
Definition: OpenACCClause.h:40
SourceLocation getBeginLoc() const
Definition: OpenACCClause.h:41
static OpenACCCollapseClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, bool HasForce, Expr *LoopCount, SourceLocation EndLoc)
static OpenACCCopyClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyInClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyOutClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCreateClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDefaultAsyncClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCDefaultClause * Create(const ASTContext &C, OpenACCDefaultClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static OpenACCDeleteClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDetachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceNumClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCDevicePtrClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceResidentClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or an identifier.
static OpenACCDeviceTypeClause * Create(const ASTContext &C, OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< DeviceTypeArgument > Archs, SourceLocation EndLoc)
static OpenACCFinalizeClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCFirstPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, ArrayRef< OpenACCFirstPrivateRecipe > InitRecipes, SourceLocation EndLoc)
static OpenACCGangClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< OpenACCGangKind > GangKinds, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)
static OpenACCHostClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCIfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCIfPresentClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCIndependentClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCLinkClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCNoCreateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCNoHostClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCNumGangsClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)
static OpenACCNumWorkersClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCPresentClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, ArrayRef< VarDecl * > InitRecipes, SourceLocation EndLoc)
static OpenACCReductionClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCReductionOperator Operator, ArrayRef< Expr * > VarList, ArrayRef< OpenACCReductionRecipe > Recipes, SourceLocation EndLoc)
static OpenACCSelfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCSeqClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCTileClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > SizeExprs, SourceLocation EndLoc)
static OpenACCUseDeviceClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCVectorClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCVectorLengthClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCWaitClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef< Expr * > QueueIdExprs, SourceLocation EndLoc)
static OpenACCWorkerClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
A (possibly-)qualified type.
Definition: TypeBase.h:937
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:61
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaBase.cpp:33
ASTContext & getASTContext() const
Definition: SemaBase.cpp:9
DeclContext * getCurContext() const
Definition: SemaBase.cpp:12
A type to represent all the data for an OpenACC Clause that has been parsed, but not yet created/sema...
Definition: SemaOpenACC.h:297
void setVarListDetails(ArrayRef< Expr * > VarList, OpenACCModifierKind ModKind)
Definition: SemaOpenACC.h:628
ArrayRef< Expr * > getQueueIdExprs() const
Definition: SemaOpenACC.h:436
OpenACCDirectiveKind getDirectiveKind() const
Definition: SemaOpenACC.h:358
ArrayRef< OpenACCGangKind > getGangKinds() const
Definition: SemaOpenACC.h:478
OpenACCReductionOperator getReductionOp() const
Definition: SemaOpenACC.h:474
OpenACCClauseKind getClauseKind() const
Definition: SemaOpenACC.h:360
SourceLocation getLParenLoc() const
Definition: SemaOpenACC.h:364
ArrayRef< DeviceTypeArgument > getDeviceTypeArchitectures() const
Definition: SemaOpenACC.h:545
std::variant< std::monostate, clang::StringLiteral *, IdentifierInfo * > getBindDetails() const
Definition: SemaOpenACC.h:553
SourceLocation getBeginLoc() const
Definition: SemaOpenACC.h:362
SourceLocation getQueuesLoc() const
Definition: SemaOpenACC.h:416
OpenACCModifierKind getModifierList() const
Definition: SemaOpenACC.h:529
OpenACCDefaultClauseKind getDefaultClauseKind() const
Definition: SemaOpenACC.h:368
bool CheckDeclareClause(SemaOpenACC::OpenACCParsedClause &Clause, OpenACCModifierKind Mods)
ComputeConstructInfo & getActiveComputeConstructInfo()
Definition: SemaOpenACC.h:257
OpenACCClause * CheckReductionClause(ArrayRef< const OpenACCClause * > ExistingClauses, OpenACCDirectiveKind DirectiveKind, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCReductionOperator ReductionOp, ArrayRef< Expr * > Vars, ArrayRef< OpenACCReductionRecipe > Recipes, SourceLocation EndLoc)
SourceLocation LoopWorkerClauseLoc
If there is a current 'active' loop construct with a 'worker' clause on it (on any sort of construct)...
Definition: SemaOpenACC.h:274
OpenACCClause * ActOnClause(ArrayRef< const OpenACCClause * > ExistingClauses, OpenACCParsedClause &Clause)
Called after parsing an OpenACC Clause so that it can be checked.
bool DiagnoseAllowedOnceClauses(OpenACCDirectiveKind DK, OpenACCClauseKind CK, SourceLocation ClauseLoc, ArrayRef< const OpenACCClause * > Clauses)
bool DiagnoseExclusiveClauses(OpenACCDirectiveKind DK, OpenACCClauseKind CK, SourceLocation ClauseLoc, ArrayRef< const OpenACCClause * > Clauses)
bool CheckVarIsPointerType(OpenACCClauseKind ClauseKind, Expr *VarExpr)
Called to check the 'var' type is a variable of pointer type, necessary for 'deviceptr' and 'attach' ...
struct clang::SemaOpenACC::LoopGangOnKernelTy LoopGangClauseOnKernel
ExprResult CheckReductionVar(OpenACCDirectiveKind DirectiveKind, OpenACCReductionOperator ReductionOp, Expr *VarExpr)
Called while semantically analyzing the reduction clause, ensuring the var is the correct kind of ref...
llvm::SmallVector< Expr * > CheckLinkClauseVarList(ArrayRef< Expr * > VarExpr)
ExprResult CheckCollapseLoopCount(Expr *LoopCount)
Checks the loop depth value for a collapse clause.
SourceLocation LoopVectorClauseLoc
If there is a current 'active' loop construct with a 'vector' clause on it (on any sort of construct)...
Definition: SemaOpenACC.h:279
ExprResult CheckGangExpr(ArrayRef< const OpenACCClause * > ExistingClauses, OpenACCDirectiveKind DK, OpenACCGangKind GK, Expr *E)
OpenACCClause * CheckGangClause(OpenACCDirectiveKind DirKind, ArrayRef< const OpenACCClause * > ExistingClauses, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< OpenACCGangKind > GangKinds, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)
std::pair< VarDecl *, VarDecl * > CreateInitRecipe(OpenACCClauseKind CK, const Expr *VarExpr)
Definition: SemaOpenACC.h:246
ExprResult CheckTileSizeExpr(Expr *SizeExpr)
Checks a single size expr for a tile clause.
ASTContext & getASTContext() const
Definition: Sema.h:918
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:346
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.h:41
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: TypeBase.h:8980
Represents a variable declaration or definition.
Definition: Decl.h:925
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
Definition: Decl.h:1216
StringRef getName(const HeaderType T)
Definition: HeaderFile.h:38
The JSON file list parser is used to communicate input to InstallAPI.
OpenACCDirectiveKind
Definition: OpenACCKinds.h:28
OpenACCReductionOperator
Definition: OpenACCKinds.h:547
bool isOpenACCComputeDirectiveKind(OpenACCDirectiveKind K)
Definition: OpenACCKinds.h:152
bool isOpenACCCombinedDirectiveKind(OpenACCDirectiveKind K)
Definition: OpenACCKinds.h:158
OpenACCModifierKind
Definition: OpenACCKinds.h:641
OpenACCClauseKind
Represents the kind of an OpenACC clause.
Definition: OpenACCKinds.h:207
@ DevicePtr
'deviceptr' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ Link
'link' clause, allowed on 'declare' construct.
@ DeviceResident
'device_resident' clause, allowed on the 'declare' construct.
@ CopyIn
'copyin' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ Result
The result type of a method or function.
ExprResult ExprError()
Definition: Ownership.h:265
bool isOpenACCModifierBitSet(OpenACCModifierKind List, OpenACCModifierKind Bit)
Definition: OpenACCKinds.h:652
OpenACCGangKind
Definition: OpenACCKinds.h:606
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
Definition: complex_cmath.h:40