clang 20.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
14#include "clang/AST/DeclCXX.h"
18
19using namespace clang;
20
21namespace {
22bool doesClauseApplyToDirective(OpenACCDirectiveKind DirectiveKind,
23 OpenACCClauseKind ClauseKind) {
24 switch (ClauseKind) {
25 // FIXME: For each clause as we implement them, we can add the
26 // 'legalization' list here.
27 case OpenACCClauseKind::Default:
28 switch (DirectiveKind) {
29 case OpenACCDirectiveKind::Parallel:
30 case OpenACCDirectiveKind::Serial:
31 case OpenACCDirectiveKind::Kernels:
32 case OpenACCDirectiveKind::ParallelLoop:
33 case OpenACCDirectiveKind::SerialLoop:
34 case OpenACCDirectiveKind::KernelsLoop:
35 case OpenACCDirectiveKind::Data:
36 return true;
37 default:
38 return false;
39 }
40 case OpenACCClauseKind::If:
41 switch (DirectiveKind) {
42 case OpenACCDirectiveKind::Parallel:
43 case OpenACCDirectiveKind::Serial:
44 case OpenACCDirectiveKind::Kernels:
45 case OpenACCDirectiveKind::Data:
46 case OpenACCDirectiveKind::EnterData:
47 case OpenACCDirectiveKind::ExitData:
48 case OpenACCDirectiveKind::HostData:
49 case OpenACCDirectiveKind::Init:
50 case OpenACCDirectiveKind::Shutdown:
51 case OpenACCDirectiveKind::Set:
52 case OpenACCDirectiveKind::Update:
53 case OpenACCDirectiveKind::Wait:
54 case OpenACCDirectiveKind::ParallelLoop:
55 case OpenACCDirectiveKind::SerialLoop:
56 case OpenACCDirectiveKind::KernelsLoop:
57 return true;
58 default:
59 return false;
60 }
61 case OpenACCClauseKind::Self:
62 switch (DirectiveKind) {
63 case OpenACCDirectiveKind::Parallel:
64 case OpenACCDirectiveKind::Serial:
65 case OpenACCDirectiveKind::Kernels:
66 case OpenACCDirectiveKind::Update:
67 case OpenACCDirectiveKind::ParallelLoop:
68 case OpenACCDirectiveKind::SerialLoop:
69 case OpenACCDirectiveKind::KernelsLoop:
70 return true;
71 default:
72 return false;
73 }
74 case OpenACCClauseKind::NumGangs:
75 case OpenACCClauseKind::NumWorkers:
76 case OpenACCClauseKind::VectorLength:
77 switch (DirectiveKind) {
78 case OpenACCDirectiveKind::Parallel:
79 case OpenACCDirectiveKind::Kernels:
80 case OpenACCDirectiveKind::ParallelLoop:
81 case OpenACCDirectiveKind::KernelsLoop:
82 return true;
83 default:
84 return false;
85 }
86 case OpenACCClauseKind::FirstPrivate:
87 switch (DirectiveKind) {
88 case OpenACCDirectiveKind::Parallel:
89 case OpenACCDirectiveKind::Serial:
90 case OpenACCDirectiveKind::ParallelLoop:
91 case OpenACCDirectiveKind::SerialLoop:
92 return true;
93 default:
94 return false;
95 }
96 case OpenACCClauseKind::Private:
97 switch (DirectiveKind) {
98 case OpenACCDirectiveKind::Parallel:
99 case OpenACCDirectiveKind::Serial:
100 case OpenACCDirectiveKind::Loop:
101 case OpenACCDirectiveKind::ParallelLoop:
102 case OpenACCDirectiveKind::SerialLoop:
103 case OpenACCDirectiveKind::KernelsLoop:
104 return true;
105 default:
106 return false;
107 }
108 case OpenACCClauseKind::NoCreate:
109 switch (DirectiveKind) {
110 case OpenACCDirectiveKind::Parallel:
111 case OpenACCDirectiveKind::Serial:
112 case OpenACCDirectiveKind::Kernels:
113 case OpenACCDirectiveKind::Data:
114 case OpenACCDirectiveKind::ParallelLoop:
115 case OpenACCDirectiveKind::SerialLoop:
116 case OpenACCDirectiveKind::KernelsLoop:
117 return true;
118 default:
119 return false;
120 }
121 case OpenACCClauseKind::Present:
122 switch (DirectiveKind) {
123 case OpenACCDirectiveKind::Parallel:
124 case OpenACCDirectiveKind::Serial:
125 case OpenACCDirectiveKind::Kernels:
126 case OpenACCDirectiveKind::Data:
127 case OpenACCDirectiveKind::Declare:
128 case OpenACCDirectiveKind::ParallelLoop:
129 case OpenACCDirectiveKind::SerialLoop:
130 case OpenACCDirectiveKind::KernelsLoop:
131 return true;
132 default:
133 return false;
134 }
135
136 case OpenACCClauseKind::Copy:
137 case OpenACCClauseKind::PCopy:
138 case OpenACCClauseKind::PresentOrCopy:
139 switch (DirectiveKind) {
140 case OpenACCDirectiveKind::Parallel:
141 case OpenACCDirectiveKind::Serial:
142 case OpenACCDirectiveKind::Kernels:
143 case OpenACCDirectiveKind::Data:
144 case OpenACCDirectiveKind::Declare:
145 case OpenACCDirectiveKind::ParallelLoop:
146 case OpenACCDirectiveKind::SerialLoop:
147 case OpenACCDirectiveKind::KernelsLoop:
148 return true;
149 default:
150 return false;
151 }
152 case OpenACCClauseKind::CopyIn:
153 case OpenACCClauseKind::PCopyIn:
154 case OpenACCClauseKind::PresentOrCopyIn:
155 switch (DirectiveKind) {
156 case OpenACCDirectiveKind::Parallel:
157 case OpenACCDirectiveKind::Serial:
158 case OpenACCDirectiveKind::Kernels:
159 case OpenACCDirectiveKind::Data:
160 case OpenACCDirectiveKind::EnterData:
161 case OpenACCDirectiveKind::Declare:
162 case OpenACCDirectiveKind::ParallelLoop:
163 case OpenACCDirectiveKind::SerialLoop:
164 case OpenACCDirectiveKind::KernelsLoop:
165 return true;
166 default:
167 return false;
168 }
169 case OpenACCClauseKind::CopyOut:
170 case OpenACCClauseKind::PCopyOut:
171 case OpenACCClauseKind::PresentOrCopyOut:
172 switch (DirectiveKind) {
173 case OpenACCDirectiveKind::Parallel:
174 case OpenACCDirectiveKind::Serial:
175 case OpenACCDirectiveKind::Kernels:
176 case OpenACCDirectiveKind::Data:
177 case OpenACCDirectiveKind::ExitData:
178 case OpenACCDirectiveKind::Declare:
179 case OpenACCDirectiveKind::ParallelLoop:
180 case OpenACCDirectiveKind::SerialLoop:
181 case OpenACCDirectiveKind::KernelsLoop:
182 return true;
183 default:
184 return false;
185 }
186 case OpenACCClauseKind::Create:
187 case OpenACCClauseKind::PCreate:
188 case OpenACCClauseKind::PresentOrCreate:
189 switch (DirectiveKind) {
190 case OpenACCDirectiveKind::Parallel:
191 case OpenACCDirectiveKind::Serial:
192 case OpenACCDirectiveKind::Kernels:
193 case OpenACCDirectiveKind::Data:
194 case OpenACCDirectiveKind::EnterData:
195 case OpenACCDirectiveKind::ParallelLoop:
196 case OpenACCDirectiveKind::SerialLoop:
197 case OpenACCDirectiveKind::KernelsLoop:
198 return true;
199 default:
200 return false;
201 }
202
203 case OpenACCClauseKind::Attach:
204 switch (DirectiveKind) {
205 case OpenACCDirectiveKind::Parallel:
206 case OpenACCDirectiveKind::Serial:
207 case OpenACCDirectiveKind::Kernels:
208 case OpenACCDirectiveKind::Data:
209 case OpenACCDirectiveKind::EnterData:
210 case OpenACCDirectiveKind::ParallelLoop:
211 case OpenACCDirectiveKind::SerialLoop:
212 case OpenACCDirectiveKind::KernelsLoop:
213 return true;
214 default:
215 return false;
216 }
217 case OpenACCClauseKind::DevicePtr:
218 switch (DirectiveKind) {
219 case OpenACCDirectiveKind::Parallel:
220 case OpenACCDirectiveKind::Serial:
221 case OpenACCDirectiveKind::Kernels:
222 case OpenACCDirectiveKind::Data:
223 case OpenACCDirectiveKind::Declare:
224 case OpenACCDirectiveKind::ParallelLoop:
225 case OpenACCDirectiveKind::SerialLoop:
226 case OpenACCDirectiveKind::KernelsLoop:
227 return true;
228 default:
229 return false;
230 }
231 case OpenACCClauseKind::Async:
232 switch (DirectiveKind) {
233 case OpenACCDirectiveKind::Parallel:
234 case OpenACCDirectiveKind::Serial:
235 case OpenACCDirectiveKind::Kernels:
236 case OpenACCDirectiveKind::Data:
237 case OpenACCDirectiveKind::EnterData:
238 case OpenACCDirectiveKind::ExitData:
239 case OpenACCDirectiveKind::Set:
240 case OpenACCDirectiveKind::Update:
241 case OpenACCDirectiveKind::Wait:
242 case OpenACCDirectiveKind::ParallelLoop:
243 case OpenACCDirectiveKind::SerialLoop:
244 case OpenACCDirectiveKind::KernelsLoop:
245 return true;
246 default:
247 return false;
248 }
249 case OpenACCClauseKind::Wait:
250 switch (DirectiveKind) {
251 case OpenACCDirectiveKind::Parallel:
252 case OpenACCDirectiveKind::Serial:
253 case OpenACCDirectiveKind::Kernels:
254 case OpenACCDirectiveKind::Data:
255 case OpenACCDirectiveKind::EnterData:
256 case OpenACCDirectiveKind::ExitData:
257 case OpenACCDirectiveKind::Update:
258 case OpenACCDirectiveKind::ParallelLoop:
259 case OpenACCDirectiveKind::SerialLoop:
260 case OpenACCDirectiveKind::KernelsLoop:
261 return true;
262 default:
263 return false;
264 }
265
266 case OpenACCClauseKind::Seq:
267 switch (DirectiveKind) {
268 case OpenACCDirectiveKind::Loop:
269 case OpenACCDirectiveKind::Routine:
270 case OpenACCDirectiveKind::ParallelLoop:
271 case OpenACCDirectiveKind::SerialLoop:
272 case OpenACCDirectiveKind::KernelsLoop:
273 return true;
274 default:
275 return false;
276 }
277
278 case OpenACCClauseKind::Independent:
279 case OpenACCClauseKind::Auto:
280 switch (DirectiveKind) {
281 case OpenACCDirectiveKind::Loop:
282 case OpenACCDirectiveKind::ParallelLoop:
283 case OpenACCDirectiveKind::SerialLoop:
284 case OpenACCDirectiveKind::KernelsLoop:
285 return true;
286 default:
287 return false;
288 }
289
290 case OpenACCClauseKind::Reduction:
291 switch (DirectiveKind) {
292 case OpenACCDirectiveKind::Parallel:
293 case OpenACCDirectiveKind::Serial:
294 case OpenACCDirectiveKind::Loop:
295 case OpenACCDirectiveKind::ParallelLoop:
296 case OpenACCDirectiveKind::SerialLoop:
297 case OpenACCDirectiveKind::KernelsLoop:
298 return true;
299 default:
300 return false;
301 }
302
303 case OpenACCClauseKind::DeviceType:
304 case OpenACCClauseKind::DType:
305 switch (DirectiveKind) {
306 case OpenACCDirectiveKind::Parallel:
307 case OpenACCDirectiveKind::Serial:
308 case OpenACCDirectiveKind::Kernels:
309 case OpenACCDirectiveKind::Data:
310 case OpenACCDirectiveKind::Init:
311 case OpenACCDirectiveKind::Shutdown:
312 case OpenACCDirectiveKind::Set:
313 case OpenACCDirectiveKind::Update:
314 case OpenACCDirectiveKind::Loop:
315 case OpenACCDirectiveKind::Routine:
316 case OpenACCDirectiveKind::ParallelLoop:
317 case OpenACCDirectiveKind::SerialLoop:
318 case OpenACCDirectiveKind::KernelsLoop:
319 return true;
320 default:
321 return false;
322 }
323
324 case OpenACCClauseKind::Collapse: {
325 switch (DirectiveKind) {
326 case OpenACCDirectiveKind::Loop:
327 case OpenACCDirectiveKind::ParallelLoop:
328 case OpenACCDirectiveKind::SerialLoop:
329 case OpenACCDirectiveKind::KernelsLoop:
330 return true;
331 default:
332 return false;
333 }
334 }
335 case OpenACCClauseKind::Tile: {
336 switch (DirectiveKind) {
337 case OpenACCDirectiveKind::Loop:
338 case OpenACCDirectiveKind::ParallelLoop:
339 case OpenACCDirectiveKind::SerialLoop:
340 case OpenACCDirectiveKind::KernelsLoop:
341 return true;
342 default:
343 return false;
344 }
345 }
346
347 case OpenACCClauseKind::Gang: {
348 switch (DirectiveKind) {
349 case OpenACCDirectiveKind::Loop:
350 case OpenACCDirectiveKind::ParallelLoop:
351 case OpenACCDirectiveKind::SerialLoop:
352 case OpenACCDirectiveKind::KernelsLoop:
353 case OpenACCDirectiveKind::Routine:
354 return true;
355 default:
356 return false;
357 }
358 case OpenACCClauseKind::Worker: {
359 switch (DirectiveKind) {
360 case OpenACCDirectiveKind::Loop:
361 case OpenACCDirectiveKind::ParallelLoop:
362 case OpenACCDirectiveKind::SerialLoop:
363 case OpenACCDirectiveKind::KernelsLoop:
364 case OpenACCDirectiveKind::Routine:
365 return true;
366 default:
367 return false;
368 }
369 }
370 case OpenACCClauseKind::Vector: {
371 switch (DirectiveKind) {
372 case OpenACCDirectiveKind::Loop:
373 case OpenACCDirectiveKind::ParallelLoop:
374 case OpenACCDirectiveKind::SerialLoop:
375 case OpenACCDirectiveKind::KernelsLoop:
376 case OpenACCDirectiveKind::Routine:
377 return true;
378 default:
379 return false;
380 }
381 }
382 case OpenACCClauseKind::Finalize: {
383 switch (DirectiveKind) {
384 case OpenACCDirectiveKind::ExitData:
385 return true;
386 default:
387 return false;
388 }
389 }
390 case OpenACCClauseKind::IfPresent: {
391 switch (DirectiveKind) {
392 case OpenACCDirectiveKind::HostData:
393 case OpenACCDirectiveKind::Update:
394 return true;
395 default:
396 return false;
397 }
398 }
399 case OpenACCClauseKind::Delete: {
400 switch (DirectiveKind) {
401 case OpenACCDirectiveKind::ExitData:
402 return true;
403 default:
404 return false;
405 }
406 }
407
408 case OpenACCClauseKind::Detach: {
409 switch (DirectiveKind) {
410 case OpenACCDirectiveKind::ExitData:
411 return true;
412 default:
413 return false;
414 }
415 }
416
417 case OpenACCClauseKind::DeviceNum: {
418 switch (DirectiveKind) {
419 case OpenACCDirectiveKind::Init:
420 case OpenACCDirectiveKind::Shutdown:
421 case OpenACCDirectiveKind::Set:
422 return true;
423 default:
424 return false;
425 }
426 }
427
428 case OpenACCClauseKind::UseDevice: {
429 switch (DirectiveKind) {
430 case OpenACCDirectiveKind::HostData:
431 return true;
432 default:
433 return false;
434 }
435 }
436 case OpenACCClauseKind::DefaultAsync: {
437 switch (DirectiveKind) {
438 case OpenACCDirectiveKind::Set:
439 return true;
440 default:
441 return false;
442 }
443 }
444 case OpenACCClauseKind::Device: {
445 switch (DirectiveKind) {
446 case OpenACCDirectiveKind::Update:
447 return true;
448 default:
449 return false;
450 }
451 }
452 case OpenACCClauseKind::Host: {
453 switch (DirectiveKind) {
454 case OpenACCDirectiveKind::Update:
455 return true;
456 default:
457 return false;
458 }
459 }
460 }
461
462 default:
463 // Do nothing so we can go to the 'unimplemented' diagnostic instead.
464 return true;
465 }
466 llvm_unreachable("Invalid clause kind");
467}
468
469bool checkAlreadyHasClauseOfKind(
472 const auto *Itr = llvm::find_if(ExistingClauses, [&](const OpenACCClause *C) {
473 return C->getClauseKind() == Clause.getClauseKind();
474 });
475 if (Itr != ExistingClauses.end()) {
476 S.Diag(Clause.getBeginLoc(), diag::err_acc_duplicate_clause_disallowed)
477 << Clause.getDirectiveKind() << Clause.getClauseKind();
478 S.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
479 return true;
480 }
481 return false;
482}
483bool checkValidAfterDeviceType(
484 SemaOpenACC &S, const OpenACCDeviceTypeClause &DeviceTypeClause,
485 const SemaOpenACC::OpenACCParsedClause &NewClause) {
486 // This is implemented for everything but 'routine', so treat as 'fine' for
487 // that.
488 if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Routine)
489 return false;
490
491 // OpenACC3.3: Section 2.4: Clauses that precede any device_type clause are
492 // default clauses. Clauses that follow a device_type clause up to the end of
493 // the directive or up to the next device_type clause are device-specific
494 // clauses for the device types specified in the device_type argument.
495 //
496 // The above implies that despite what the individual text says, these are
497 // valid.
498 if (NewClause.getClauseKind() == OpenACCClauseKind::DType ||
499 NewClause.getClauseKind() == OpenACCClauseKind::DeviceType)
500 return false;
501
502 // Implement check from OpenACC3.3: section 2.5.4:
503 // Only the async, wait, num_gangs, num_workers, and vector_length clauses may
504 // follow a device_type clause.
505 if (isOpenACCComputeDirectiveKind(NewClause.getDirectiveKind())) {
506 switch (NewClause.getClauseKind()) {
507 case OpenACCClauseKind::Async:
508 case OpenACCClauseKind::Wait:
509 case OpenACCClauseKind::NumGangs:
510 case OpenACCClauseKind::NumWorkers:
511 case OpenACCClauseKind::VectorLength:
512 return false;
513 default:
514 break;
515 }
516 } else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Loop) {
517 // Implement check from OpenACC3.3: section 2.9:
518 // Only the collapse, gang, worker, vector, seq, independent, auto, and tile
519 // clauses may follow a device_type clause.
520 switch (NewClause.getClauseKind()) {
521 case OpenACCClauseKind::Collapse:
522 case OpenACCClauseKind::Gang:
523 case OpenACCClauseKind::Worker:
524 case OpenACCClauseKind::Vector:
525 case OpenACCClauseKind::Seq:
526 case OpenACCClauseKind::Independent:
527 case OpenACCClauseKind::Auto:
528 case OpenACCClauseKind::Tile:
529 return false;
530 default:
531 break;
532 }
533 } else if (isOpenACCCombinedDirectiveKind(NewClause.getDirectiveKind())) {
534 // This seems like it should be the union of 2.9 and 2.5.4 from above.
535 switch (NewClause.getClauseKind()) {
536 case OpenACCClauseKind::Async:
537 case OpenACCClauseKind::Wait:
538 case OpenACCClauseKind::NumGangs:
539 case OpenACCClauseKind::NumWorkers:
540 case OpenACCClauseKind::VectorLength:
541 case OpenACCClauseKind::Collapse:
542 case OpenACCClauseKind::Gang:
543 case OpenACCClauseKind::Worker:
544 case OpenACCClauseKind::Vector:
545 case OpenACCClauseKind::Seq:
546 case OpenACCClauseKind::Independent:
547 case OpenACCClauseKind::Auto:
548 case OpenACCClauseKind::Tile:
549 return false;
550 default:
551 break;
552 }
553 } else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Data) {
554 // OpenACC3.3 section 2.6.5: Only the async and wait clauses may follow a
555 // device_type clause.
556 switch (NewClause.getClauseKind()) {
557 case OpenACCClauseKind::Async:
558 case OpenACCClauseKind::Wait:
559 return false;
560 default:
561 break;
562 }
563 } else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Set ||
564 NewClause.getDirectiveKind() == OpenACCDirectiveKind::Init ||
565 NewClause.getDirectiveKind() == OpenACCDirectiveKind::Shutdown) {
566 // There are no restrictions on 'set', 'init', or 'shutdown'.
567 return false;
568 } else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
569 // OpenACC3.3 section 2.14.4: Only the async and wait clauses may follow a
570 // device_type clause.
571 switch (NewClause.getClauseKind()) {
572 case OpenACCClauseKind::Async:
573 case OpenACCClauseKind::Wait:
574 return false;
575 default:
576 break;
577 }
578 }
579 S.Diag(NewClause.getBeginLoc(), diag::err_acc_clause_after_device_type)
580 << NewClause.getClauseKind() << DeviceTypeClause.getClauseKind()
581 << NewClause.getDirectiveKind();
582 S.Diag(DeviceTypeClause.getBeginLoc(), diag::note_acc_previous_clause_here);
583 return true;
584}
585
586// A temporary function that helps implement the 'not implemented' check at the
587// top of each clause checking function. This should only be used in conjunction
588// with the one being currently implemented/only updated after the entire
589// construct has been implemented.
590bool isDirectiveKindImplemented(OpenACCDirectiveKind DK) {
591 return DK != OpenACCDirectiveKind::Declare &&
592 DK != OpenACCDirectiveKind::Atomic &&
593 DK != OpenACCDirectiveKind::Routine;
594}
595
596class SemaOpenACCClauseVisitor {
597 SemaOpenACC &SemaRef;
598 ASTContext &Ctx;
599 ArrayRef<const OpenACCClause *> ExistingClauses;
600 bool NotImplemented = false;
601
602 OpenACCClause *isNotImplemented() {
603 NotImplemented = true;
604 return nullptr;
605 }
606
607 // OpenACC 3.3 2.9:
608 // A 'gang', 'worker', or 'vector' clause may not appear if a 'seq' clause
609 // appears.
610 bool DiagIfSeqClause(SemaOpenACC::OpenACCParsedClause &Clause) {
611 const auto *Itr =
612 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCSeqClause>);
613
614 if (Itr != ExistingClauses.end()) {
615 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_cannot_combine)
616 << Clause.getClauseKind() << (*Itr)->getClauseKind()
617 << Clause.getDirectiveKind();
618 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
619
620 return true;
621 }
622 return false;
623 }
624
625public:
626 SemaOpenACCClauseVisitor(SemaOpenACC &S,
627 ArrayRef<const OpenACCClause *> ExistingClauses)
628 : SemaRef(S), Ctx(S.getASTContext()), ExistingClauses(ExistingClauses) {}
629 // Once we've implemented everything, we shouldn't need this infrastructure.
630 // But in the meantime, we use this to help decide whether the clause was
631 // handled for this directive.
632 bool diagNotImplemented() { return NotImplemented; }
633
635 switch (Clause.getClauseKind()) {
636#define VISIT_CLAUSE(CLAUSE_NAME) \
637 case OpenACCClauseKind::CLAUSE_NAME: \
638 return Visit##CLAUSE_NAME##Clause(Clause);
639#define CLAUSE_ALIAS(ALIAS, CLAUSE_NAME, DEPRECATED) \
640 case OpenACCClauseKind::ALIAS: \
641 if (DEPRECATED) \
642 SemaRef.Diag(Clause.getBeginLoc(), diag::warn_acc_deprecated_alias_name) \
643 << Clause.getClauseKind() << OpenACCClauseKind::CLAUSE_NAME; \
644 return Visit##CLAUSE_NAME##Clause(Clause);
645#include "clang/Basic/OpenACCClauses.def"
646 default:
647 return isNotImplemented();
648 }
649 llvm_unreachable("Invalid clause kind");
650 }
651
652#define VISIT_CLAUSE(CLAUSE_NAME) \
653 OpenACCClause *Visit##CLAUSE_NAME##Clause( \
654 SemaOpenACC::OpenACCParsedClause &Clause);
655#include "clang/Basic/OpenACCClauses.def"
656};
657
658OpenACCClause *SemaOpenACCClauseVisitor::VisitDefaultClause(
660 // Don't add an invalid clause to the AST.
661 if (Clause.getDefaultClauseKind() == OpenACCDefaultClauseKind::Invalid)
662 return nullptr;
663
664 // OpenACC 3.3, Section 2.5.4:
665 // At most one 'default' clause may appear, and it must have a value of
666 // either 'none' or 'present'.
667 // Second half of the sentence is diagnosed during parsing.
668 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
669 return nullptr;
670
672 Ctx, Clause.getDefaultClauseKind(), Clause.getBeginLoc(),
673 Clause.getLParenLoc(), Clause.getEndLoc());
674}
675
676OpenACCClause *SemaOpenACCClauseVisitor::VisitTileClause(
678
679 // Duplicates here are not really sensible. We could possible permit
680 // multiples if they all had the same value, but there isn't really a good
681 // reason to do so. Also, this simplifies the suppression of duplicates, in
682 // that we know if we 'find' one after instantiation, that it is the same
683 // clause, which simplifies instantiation/checking/etc.
684 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
685 return nullptr;
686
687 llvm::SmallVector<Expr *> NewSizeExprs;
688
689 // Make sure these are all positive constant expressions or *.
690 for (Expr *E : Clause.getIntExprs()) {
691 ExprResult Res = SemaRef.CheckTileSizeExpr(E);
692
693 if (!Res.isUsable())
694 return nullptr;
695
696 NewSizeExprs.push_back(Res.get());
697 }
698
699 return OpenACCTileClause::Create(Ctx, Clause.getBeginLoc(),
700 Clause.getLParenLoc(), NewSizeExprs,
701 Clause.getEndLoc());
702}
703
704OpenACCClause *SemaOpenACCClauseVisitor::VisitIfClause(
706 // There is no prose in the standard that says duplicates aren't allowed,
707 // but this diagnostic is present in other compilers, as well as makes
708 // sense. Prose DOES exist for 'data' and 'host_data', 'set', 'enter data' and
709 // 'exit data' both don't, but other implmementations do this. OpenACC issue
710 // 519 filed for the latter two. Prose also exists for 'update'.
711 // GCC allows this on init/shutdown, presumably for good reason, so we do too.
712 if (Clause.getDirectiveKind() != OpenACCDirectiveKind::Init &&
713 Clause.getDirectiveKind() != OpenACCDirectiveKind::Shutdown &&
714 checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
715 return nullptr;
716
717 // The parser has ensured that we have a proper condition expr, so there
718 // isn't really much to do here.
719
720 // If the 'if' clause is true, it makes the 'self' clause have no effect,
721 // diagnose that here. This only applies on compute/combined constructs.
722 if (Clause.getDirectiveKind() != OpenACCDirectiveKind::Update) {
723 const auto *Itr =
724 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCSelfClause>);
725 if (Itr != ExistingClauses.end()) {
726 SemaRef.Diag(Clause.getBeginLoc(), diag::warn_acc_if_self_conflict);
727 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
728 }
729 }
730
731 return OpenACCIfClause::Create(Ctx, Clause.getBeginLoc(),
732 Clause.getLParenLoc(),
733 Clause.getConditionExpr(), Clause.getEndLoc());
734}
735
736OpenACCClause *SemaOpenACCClauseVisitor::VisitSelfClause(
738 // There is no prose in the standard that says duplicates aren't allowed,
739 // but this diagnostic is present in other compilers, as well as makes
740 // sense.
741 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
742 return nullptr;
743
744 // If the 'if' clause is true, it makes the 'self' clause have no effect,
745 // diagnose that here. This only applies on compute/combined constructs.
746 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Update)
747 return OpenACCSelfClause::Create(Ctx, Clause.getBeginLoc(),
748 Clause.getLParenLoc(), Clause.getVarList(),
749 Clause.getEndLoc());
750
751 const auto *Itr =
752 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCIfClause>);
753 if (Itr != ExistingClauses.end()) {
754 SemaRef.Diag(Clause.getBeginLoc(), diag::warn_acc_if_self_conflict);
755 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
756 }
758 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(),
759 Clause.getConditionExpr(), Clause.getEndLoc());
760}
761
762OpenACCClause *SemaOpenACCClauseVisitor::VisitNumGangsClause(
764 // There is no prose in the standard that says duplicates aren't allowed,
765 // but this diagnostic is present in other compilers, as well as makes
766 // sense.
767 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
768 return nullptr;
769
770 // num_gangs requires at least 1 int expr in all forms. Diagnose here, but
771 // allow us to continue, an empty clause might be useful for future
772 // diagnostics.
773 if (Clause.getIntExprs().empty())
774 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_num_gangs_num_args)
775 << /*NoArgs=*/0;
776
777 unsigned MaxArgs =
778 (Clause.getDirectiveKind() == OpenACCDirectiveKind::Parallel ||
779 Clause.getDirectiveKind() == OpenACCDirectiveKind::ParallelLoop)
780 ? 3
781 : 1;
782 // The max number of args differs between parallel and other constructs.
783 // Again, allow us to continue for the purposes of future diagnostics.
784 if (Clause.getIntExprs().size() > MaxArgs)
785 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_num_gangs_num_args)
786 << /*NoArgs=*/1 << Clause.getDirectiveKind() << MaxArgs
787 << Clause.getIntExprs().size();
788
789 // OpenACC 3.3 Section 2.9.11: A reduction clause may not appear on a loop
790 // directive that has a gang clause and is within a compute construct that has
791 // a num_gangs clause with more than one explicit argument.
792 if (Clause.getIntExprs().size() > 1 &&
794 auto *GangClauseItr =
795 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
796 auto *ReductionClauseItr =
797 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
798
799 if (GangClauseItr != ExistingClauses.end() &&
800 ReductionClauseItr != ExistingClauses.end()) {
801 SemaRef.Diag(Clause.getBeginLoc(),
802 diag::err_acc_gang_reduction_numgangs_conflict)
803 << OpenACCClauseKind::Reduction << OpenACCClauseKind::Gang
804 << Clause.getDirectiveKind() << /*is on combined directive=*/1;
805 SemaRef.Diag((*ReductionClauseItr)->getBeginLoc(),
806 diag::note_acc_previous_clause_here);
807 SemaRef.Diag((*GangClauseItr)->getBeginLoc(),
808 diag::note_acc_previous_clause_here);
809 return nullptr;
810 }
811 }
812
813 // OpenACC 3.3 Section 2.5.4:
814 // A reduction clause may not appear on a parallel construct with a
815 // num_gangs clause that has more than one argument.
816 if ((Clause.getDirectiveKind() == OpenACCDirectiveKind::Parallel ||
817 Clause.getDirectiveKind() == OpenACCDirectiveKind::ParallelLoop) &&
818 Clause.getIntExprs().size() > 1) {
819 auto *Parallel =
820 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
821
822 if (Parallel != ExistingClauses.end()) {
823 SemaRef.Diag(Clause.getBeginLoc(),
824 diag::err_acc_reduction_num_gangs_conflict)
825 << /*>1 arg in first loc=*/1 << Clause.getClauseKind()
826 << Clause.getDirectiveKind() << OpenACCClauseKind::Reduction;
827 SemaRef.Diag((*Parallel)->getBeginLoc(),
828 diag::note_acc_previous_clause_here);
829 return nullptr;
830 }
831 }
832
833 // OpenACC 3.3 Section 2.9.2:
834 // An argument with no keyword or with the 'num' keyword is allowed only when
835 // the 'num_gangs' does not appear on the 'kernel' construct.
836 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::KernelsLoop) {
837 auto GangClauses = llvm::make_filter_range(
838 ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
839
840 for (auto *GC : GangClauses) {
841 if (cast<OpenACCGangClause>(GC)->hasExprOfKind(OpenACCGangKind::Num)) {
842 SemaRef.Diag(Clause.getBeginLoc(),
843 diag::err_acc_num_arg_conflict_reverse)
844 << OpenACCClauseKind::NumGangs << OpenACCClauseKind::Gang
845 << /*Num argument*/ 1;
846 SemaRef.Diag(GC->getBeginLoc(), diag::note_acc_previous_clause_here);
847 return nullptr;
848 }
849 }
850 }
851
853 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getIntExprs(),
854 Clause.getEndLoc());
855}
856
857OpenACCClause *SemaOpenACCClauseVisitor::VisitNumWorkersClause(
859 // There is no prose in the standard that says duplicates aren't allowed,
860 // but this diagnostic is present in other compilers, as well as makes
861 // sense.
862 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
863 return nullptr;
864
865 // OpenACC 3.3 Section 2.9.2:
866 // An argument is allowed only when the 'num_workers' does not appear on the
867 // kernels construct.
868 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::KernelsLoop) {
869 auto WorkerClauses = llvm::make_filter_range(
870 ExistingClauses, llvm::IsaPred<OpenACCWorkerClause>);
871
872 for (auto *WC : WorkerClauses) {
873 if (cast<OpenACCWorkerClause>(WC)->hasIntExpr()) {
874 SemaRef.Diag(Clause.getBeginLoc(),
875 diag::err_acc_num_arg_conflict_reverse)
876 << OpenACCClauseKind::NumWorkers << OpenACCClauseKind::Worker
877 << /*num argument*/ 0;
878 SemaRef.Diag(WC->getBeginLoc(), diag::note_acc_previous_clause_here);
879 return nullptr;
880 }
881 }
882 }
883
884 assert(Clause.getIntExprs().size() == 1 &&
885 "Invalid number of expressions for NumWorkers");
887 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getIntExprs()[0],
888 Clause.getEndLoc());
889}
890
891OpenACCClause *SemaOpenACCClauseVisitor::VisitVectorLengthClause(
893 // There is no prose in the standard that says duplicates aren't allowed,
894 // but this diagnostic is present in other compilers, as well as makes
895 // sense.
896 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
897 return nullptr;
898
899 // OpenACC 3.3 Section 2.9.4:
900 // An argument is allowed only when the 'vector_length' does not appear on the
901 // 'kernels' construct.
902 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::KernelsLoop) {
903 auto VectorClauses = llvm::make_filter_range(
904 ExistingClauses, llvm::IsaPred<OpenACCVectorClause>);
905
906 for (auto *VC : VectorClauses) {
907 if (cast<OpenACCVectorClause>(VC)->hasIntExpr()) {
908 SemaRef.Diag(Clause.getBeginLoc(),
909 diag::err_acc_num_arg_conflict_reverse)
910 << OpenACCClauseKind::VectorLength << OpenACCClauseKind::Vector
911 << /*num argument*/ 0;
912 SemaRef.Diag(VC->getBeginLoc(), diag::note_acc_previous_clause_here);
913 return nullptr;
914 }
915 }
916 }
917
918 assert(Clause.getIntExprs().size() == 1 &&
919 "Invalid number of expressions for NumWorkers");
921 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getIntExprs()[0],
922 Clause.getEndLoc());
923}
924
925OpenACCClause *SemaOpenACCClauseVisitor::VisitAsyncClause(
927 // There is no prose in the standard that says duplicates aren't allowed,
928 // but this diagnostic is present in other compilers, as well as makes
929 // sense.
930 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
931 return nullptr;
932
933 assert(Clause.getNumIntExprs() < 2 &&
934 "Invalid number of expressions for Async");
936 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(),
937 Clause.getNumIntExprs() != 0 ? Clause.getIntExprs()[0] : nullptr,
938 Clause.getEndLoc());
939}
940
941OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceNumClause(
943 // Restrictions only properly implemented on certain constructs, so skip/treat
944 // as unimplemented in those cases.
945 if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
946 return isNotImplemented();
947
948 // OpenACC 3.3 2.14.3: Two instances of the same clause may not appear on the
949 // same directive.
950 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Set &&
951 checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
952 return nullptr;
953
954 assert(Clause.getNumIntExprs() == 1 &&
955 "Invalid number of expressions for device_num");
957 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getIntExprs()[0],
958 Clause.getEndLoc());
959}
960
961OpenACCClause *SemaOpenACCClauseVisitor::VisitDefaultAsyncClause(
963 // OpenACC 3.3 2.14.3: Two instances of the same clause may not appear on the
964 // same directive.
965 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
966 return nullptr;
967
968 assert(Clause.getNumIntExprs() == 1 &&
969 "Invalid number of expressions for default_async");
971 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getIntExprs()[0],
972 Clause.getEndLoc());
973}
974
975OpenACCClause *SemaOpenACCClauseVisitor::VisitPrivateClause(
977 // ActOnVar ensured that everything is a valid variable reference, so there
978 // really isn't anything to do here. GCC does some duplicate-finding, though
979 // it isn't apparent in the standard where this is justified.
980
981 return OpenACCPrivateClause::Create(Ctx, Clause.getBeginLoc(),
982 Clause.getLParenLoc(),
983 Clause.getVarList(), Clause.getEndLoc());
984}
985
986OpenACCClause *SemaOpenACCClauseVisitor::VisitFirstPrivateClause(
988 // ActOnVar ensured that everything is a valid variable reference, so there
989 // really isn't anything to do here. GCC does some duplicate-finding, though
990 // it isn't apparent in the standard where this is justified.
991
993 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getVarList(),
994 Clause.getEndLoc());
995}
996
997OpenACCClause *SemaOpenACCClauseVisitor::VisitNoCreateClause(
999 // ActOnVar ensured that everything is a valid variable reference, so there
1000 // really isn't anything to do here. GCC does some duplicate-finding, though
1001 // it isn't apparent in the standard where this is justified.
1002
1003 return OpenACCNoCreateClause::Create(Ctx, Clause.getBeginLoc(),
1004 Clause.getLParenLoc(),
1005 Clause.getVarList(), Clause.getEndLoc());
1006}
1007
1008OpenACCClause *SemaOpenACCClauseVisitor::VisitPresentClause(
1010 // Restrictions only properly implemented on 'compute'/'combined'/'data'
1011 // constructs, and 'compute'/'combined'/'data' constructs are the only
1012 // construct that can do anything with this yet, so skip/treat as
1013 // unimplemented in this case.
1014 if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
1015 return isNotImplemented();
1016 // ActOnVar ensured that everything is a valid variable reference, so there
1017 // really isn't anything to do here. GCC does some duplicate-finding, though
1018 // it isn't apparent in the standard where this is justified.
1019
1020 return OpenACCPresentClause::Create(Ctx, Clause.getBeginLoc(),
1021 Clause.getLParenLoc(),
1022 Clause.getVarList(), Clause.getEndLoc());
1023}
1024
1025OpenACCClause *SemaOpenACCClauseVisitor::VisitHostClause(
1027 // ActOnVar ensured that everything is a valid variable reference, so there
1028 // really isn't anything to do here. GCC does some duplicate-finding, though
1029 // it isn't apparent in the standard where this is justified.
1030
1031 return OpenACCHostClause::Create(Ctx, Clause.getBeginLoc(),
1032 Clause.getLParenLoc(), Clause.getVarList(),
1033 Clause.getEndLoc());
1034}
1035
1036OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceClause(
1038 // ActOnVar ensured that everything is a valid variable reference, so there
1039 // really isn't anything to do here. GCC does some duplicate-finding, though
1040 // it isn't apparent in the standard where this is justified.
1041
1042 return OpenACCDeviceClause::Create(Ctx, Clause.getBeginLoc(),
1043 Clause.getLParenLoc(), Clause.getVarList(),
1044 Clause.getEndLoc());
1045}
1046
1047OpenACCClause *SemaOpenACCClauseVisitor::VisitCopyClause(
1049 // Restrictions only properly implemented on 'compute'/'combined'/'data'
1050 // constructs, and 'compute'/'combined'/'data' constructs are the only
1051 // construct that can do anything with this yet, so skip/treat as
1052 // unimplemented in this case.
1053 if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
1054 return isNotImplemented();
1055 // ActOnVar ensured that everything is a valid variable reference, so there
1056 // really isn't anything to do here. GCC does some duplicate-finding, though
1057 // it isn't apparent in the standard where this is justified.
1058
1060 Ctx, Clause.getClauseKind(), Clause.getBeginLoc(), Clause.getLParenLoc(),
1061 Clause.getVarList(), Clause.getEndLoc());
1062}
1063
1064OpenACCClause *SemaOpenACCClauseVisitor::VisitCopyInClause(
1066 // Restrictions only properly implemented on 'compute'/'combined'/'data'
1067 // constructs, and 'compute'/'combined'/'data' constructs are the only
1068 // construct that can do anything with this yet, so skip/treat as
1069 // unimplemented in this case.
1070 if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
1071 return isNotImplemented();
1072 // ActOnVar ensured that everything is a valid variable reference, so there
1073 // really isn't anything to do here. GCC does some duplicate-finding, though
1074 // it isn't apparent in the standard where this is justified.
1075
1077 Ctx, Clause.getClauseKind(), Clause.getBeginLoc(), Clause.getLParenLoc(),
1078 Clause.isReadOnly(), Clause.getVarList(), Clause.getEndLoc());
1079}
1080
1081OpenACCClause *SemaOpenACCClauseVisitor::VisitCopyOutClause(
1083 // Restrictions only properly implemented on 'compute'/'combined'/'data'
1084 // constructs, and 'compute'/'combined'/'data' constructs are the only
1085 // construct that can do anything with this yet, so skip/treat as
1086 // unimplemented in this case.
1087 if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
1088 return isNotImplemented();
1089 // ActOnVar ensured that everything is a valid variable reference, so there
1090 // really isn't anything to do here. GCC does some duplicate-finding, though
1091 // it isn't apparent in the standard where this is justified.
1092
1094 Ctx, Clause.getClauseKind(), Clause.getBeginLoc(), Clause.getLParenLoc(),
1095 Clause.isZero(), Clause.getVarList(), Clause.getEndLoc());
1096}
1097
1098OpenACCClause *SemaOpenACCClauseVisitor::VisitCreateClause(
1100 // ActOnVar ensured that everything is a valid variable reference, so there
1101 // really isn't anything to do here. GCC does some duplicate-finding, though
1102 // it isn't apparent in the standard where this is justified.
1103
1105 Ctx, Clause.getClauseKind(), Clause.getBeginLoc(), Clause.getLParenLoc(),
1106 Clause.isZero(), Clause.getVarList(), Clause.getEndLoc());
1107}
1108
1109OpenACCClause *SemaOpenACCClauseVisitor::VisitAttachClause(
1111 // ActOnVar ensured that everything is a valid variable reference, but we
1112 // still have to make sure it is a pointer type.
1113 llvm::SmallVector<Expr *> VarList{Clause.getVarList()};
1114 llvm::erase_if(VarList, [&](Expr *E) {
1115 return SemaRef.CheckVarIsPointerType(OpenACCClauseKind::Attach, E);
1116 });
1117 Clause.setVarListDetails(VarList,
1118 /*IsReadOnly=*/false, /*IsZero=*/false);
1119 return OpenACCAttachClause::Create(Ctx, Clause.getBeginLoc(),
1120 Clause.getLParenLoc(), Clause.getVarList(),
1121 Clause.getEndLoc());
1122}
1123
1124OpenACCClause *SemaOpenACCClauseVisitor::VisitDetachClause(
1126 // ActOnVar ensured that everything is a valid variable reference, but we
1127 // still have to make sure it is a pointer type.
1128 llvm::SmallVector<Expr *> VarList{Clause.getVarList()};
1129 llvm::erase_if(VarList, [&](Expr *E) {
1130 return SemaRef.CheckVarIsPointerType(OpenACCClauseKind::Detach, E);
1131 });
1132 Clause.setVarListDetails(VarList,
1133 /*IsReadOnly=*/false, /*IsZero=*/false);
1134 return OpenACCDetachClause::Create(Ctx, Clause.getBeginLoc(),
1135 Clause.getLParenLoc(), Clause.getVarList(),
1136 Clause.getEndLoc());
1137}
1138
1139OpenACCClause *SemaOpenACCClauseVisitor::VisitDeleteClause(
1141 // ActOnVar ensured that everything is a valid variable reference, so there
1142 // really isn't anything to do here. GCC does some duplicate-finding, though
1143 // it isn't apparent in the standard where this is justified.
1144 return OpenACCDeleteClause::Create(Ctx, Clause.getBeginLoc(),
1145 Clause.getLParenLoc(), Clause.getVarList(),
1146 Clause.getEndLoc());
1147}
1148
1149OpenACCClause *SemaOpenACCClauseVisitor::VisitUseDeviceClause(
1151 // ActOnVar ensured that everything is a valid variable or array, so nothing
1152 // left to do here.
1154 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getVarList(),
1155 Clause.getEndLoc());
1156}
1157
1158OpenACCClause *SemaOpenACCClauseVisitor::VisitDevicePtrClause(
1160 // Restrictions only properly implemented on 'compute'/'combined'/'data'
1161 // constructs, and 'compute'/'combined'/'data' constructs are the only
1162 // construct that can do anything with this yet, so skip/treat as
1163 // unimplemented in this case.
1164 if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
1165 return isNotImplemented();
1166
1167 // ActOnVar ensured that everything is a valid variable reference, but we
1168 // still have to make sure it is a pointer type.
1169 llvm::SmallVector<Expr *> VarList{Clause.getVarList()};
1170 llvm::erase_if(VarList, [&](Expr *E) {
1171 return SemaRef.CheckVarIsPointerType(OpenACCClauseKind::DevicePtr, E);
1172 });
1173 Clause.setVarListDetails(VarList,
1174 /*IsReadOnly=*/false, /*IsZero=*/false);
1175
1177 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getVarList(),
1178 Clause.getEndLoc());
1179}
1180
1181OpenACCClause *SemaOpenACCClauseVisitor::VisitWaitClause(
1184 Ctx, Clause.getBeginLoc(), Clause.getLParenLoc(), Clause.getDevNumExpr(),
1185 Clause.getQueuesLoc(), Clause.getQueueIdExprs(), Clause.getEndLoc());
1186}
1187
1188OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause(
1190 // Restrictions implemented properly on everything except 'routine'.
1191 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Routine)
1192 return isNotImplemented();
1193
1194 // OpenACC 3.3 2.14.3: Two instances of the same clause may not appear on the
1195 // same directive.
1196 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Set &&
1197 checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
1198 return nullptr;
1199
1200 // TODO OpenACC: Once we get enough of the CodeGen implemented that we have
1201 // a source for the list of valid architectures, we need to warn on unknown
1202 // identifiers here.
1203
1205 Ctx, Clause.getClauseKind(), Clause.getBeginLoc(), Clause.getLParenLoc(),
1206 Clause.getDeviceTypeArchitectures(), Clause.getEndLoc());
1207}
1208
1209OpenACCClause *SemaOpenACCClauseVisitor::VisitAutoClause(
1211 // OpenACC 3.3 2.9:
1212 // Only one of the seq, independent, and auto clauses may appear.
1213 const auto *Itr =
1214 llvm::find_if(ExistingClauses,
1215 llvm::IsaPred<OpenACCIndependentClause, OpenACCSeqClause>);
1216 if (Itr != ExistingClauses.end()) {
1217 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_loop_spec_conflict)
1218 << Clause.getClauseKind() << Clause.getDirectiveKind();
1219 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
1220 return nullptr;
1221 }
1222
1223 return OpenACCAutoClause::Create(Ctx, Clause.getBeginLoc(),
1224 Clause.getEndLoc());
1225}
1226
1227OpenACCClause *SemaOpenACCClauseVisitor::VisitIndependentClause(
1229 // OpenACC 3.3 2.9:
1230 // Only one of the seq, independent, and auto clauses may appear.
1231 const auto *Itr = llvm::find_if(
1232 ExistingClauses, llvm::IsaPred<OpenACCAutoClause, OpenACCSeqClause>);
1233 if (Itr != ExistingClauses.end()) {
1234 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_loop_spec_conflict)
1235 << Clause.getClauseKind() << Clause.getDirectiveKind();
1236 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
1237 return nullptr;
1238 }
1239
1240 return OpenACCIndependentClause::Create(Ctx, Clause.getBeginLoc(),
1241 Clause.getEndLoc());
1242}
1243
1244ExprResult CheckGangStaticExpr(SemaOpenACC &S, Expr *E) {
1245 if (isa<OpenACCAsteriskSizeExpr>(E))
1246 return E;
1247 return S.ActOnIntExpr(OpenACCDirectiveKind::Invalid, OpenACCClauseKind::Gang,
1248 E->getBeginLoc(), E);
1249}
1250
1251bool IsOrphanLoop(OpenACCDirectiveKind DK, OpenACCDirectiveKind AssocKind) {
1252 return DK == OpenACCDirectiveKind::Loop &&
1253 AssocKind == OpenACCDirectiveKind::Invalid;
1254}
1255
1256bool HasAssocKind(OpenACCDirectiveKind DK, OpenACCDirectiveKind AssocKind) {
1257 return DK == OpenACCDirectiveKind::Loop &&
1258 AssocKind != OpenACCDirectiveKind::Invalid;
1259}
1260
1261ExprResult DiagIntArgInvalid(SemaOpenACC &S, Expr *E, OpenACCGangKind GK,
1263 OpenACCDirectiveKind AssocKind) {
1264 S.Diag(E->getBeginLoc(), diag::err_acc_int_arg_invalid)
1265 << GK << CK << IsOrphanLoop(DK, AssocKind) << DK
1266 << HasAssocKind(DK, AssocKind) << AssocKind;
1267 return ExprError();
1268}
1269ExprResult DiagIntArgInvalid(SemaOpenACC &S, Expr *E, StringRef TagKind,
1271 OpenACCDirectiveKind AssocKind) {
1272 S.Diag(E->getBeginLoc(), diag::err_acc_int_arg_invalid)
1273 << TagKind << CK << IsOrphanLoop(DK, AssocKind) << DK
1274 << HasAssocKind(DK, AssocKind) << AssocKind;
1275 return ExprError();
1276}
1277
1278ExprResult CheckGangParallelExpr(SemaOpenACC &S, OpenACCDirectiveKind DK,
1279 OpenACCDirectiveKind AssocKind,
1280 OpenACCGangKind GK, Expr *E) {
1281 switch (GK) {
1282 case OpenACCGangKind::Static:
1283 return CheckGangStaticExpr(S, E);
1284 case OpenACCGangKind::Num:
1285 // OpenACC 3.3 2.9.2: When the parent compute construct is a parallel
1286 // construct, or an orphaned loop construct, the gang clause behaves as
1287 // follows. ... The num argument is not allowed.
1288 return DiagIntArgInvalid(S, E, GK, OpenACCClauseKind::Gang, DK, AssocKind);
1289 case OpenACCGangKind::Dim: {
1290 // OpenACC 3.3 2.9.2: When the parent compute construct is a parallel
1291 // construct, or an orphaned loop construct, the gang clause behaves as
1292 // follows. ... The dim argument must be a constant positive integer value
1293 // 1, 2, or 3.
1294 if (!E)
1295 return ExprError();
1296 ExprResult Res =
1297 S.ActOnIntExpr(OpenACCDirectiveKind::Invalid, OpenACCClauseKind::Gang,
1298 E->getBeginLoc(), E);
1299
1300 if (!Res.isUsable())
1301 return Res;
1302
1303 if (Res.get()->isInstantiationDependent())
1304 return Res;
1305
1306 std::optional<llvm::APSInt> ICE =
1308
1309 if (!ICE || *ICE <= 0 || ICE > 3) {
1310 S.Diag(Res.get()->getBeginLoc(), diag::err_acc_gang_dim_value)
1311 << ICE.has_value() << ICE.value_or(llvm::APSInt{}).getExtValue();
1312 return ExprError();
1313 }
1314
1315 return ExprResult{
1316 ConstantExpr::Create(S.getASTContext(), Res.get(), APValue{*ICE})};
1317 }
1318 }
1319 llvm_unreachable("Unknown gang kind in gang parallel check");
1320}
1321
1322ExprResult CheckGangKernelsExpr(SemaOpenACC &S,
1323 ArrayRef<const OpenACCClause *> ExistingClauses,
1325 OpenACCDirectiveKind AssocKind,
1326 OpenACCGangKind GK, Expr *E) {
1327 switch (GK) {
1328 // OpenACC 3.3 2.9.2: When the parent compute construct is a kernels
1329 // construct, the gang clause behaves as follows. ... The dim argument is
1330 // not allowed.
1331 case OpenACCGangKind::Dim:
1332 return DiagIntArgInvalid(S, E, GK, OpenACCClauseKind::Gang, DK, AssocKind);
1333 case OpenACCGangKind::Num: {
1334 // OpenACC 3.3 2.9.2: When the parent compute construct is a kernels
1335 // construct, the gang clause behaves as follows. ... An argument with no
1336 // keyword or with num keyword is only allowed when num_gangs does not
1337 // appear on the kernels construct. ... The region of a loop with the gang
1338 // clause may not contain another loop with a gang clause unless within a
1339 // nested compute region.
1340
1341 // If this is a 'combined' construct, search the list of existing clauses.
1342 // Else we need to search the containing 'kernel'.
1343 auto Collection = isOpenACCCombinedDirectiveKind(DK)
1344 ? ExistingClauses
1345 : S.getActiveComputeConstructInfo().Clauses;
1346
1347 const auto *Itr =
1348 llvm::find_if(Collection, llvm::IsaPred<OpenACCNumGangsClause>);
1349
1350 if (Itr != Collection.end()) {
1351 S.Diag(E->getBeginLoc(), diag::err_acc_num_arg_conflict)
1352 << "num" << OpenACCClauseKind::Gang << DK
1353 << HasAssocKind(DK, AssocKind) << AssocKind
1354 << OpenACCClauseKind::NumGangs;
1355
1356 S.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
1357 return ExprError();
1358 }
1359 return ExprResult{E};
1360 }
1361 case OpenACCGangKind::Static:
1362 return CheckGangStaticExpr(S, E);
1363 return ExprError();
1364 }
1365 llvm_unreachable("Unknown gang kind in gang kernels check");
1366}
1367
1368ExprResult CheckGangSerialExpr(SemaOpenACC &S, OpenACCDirectiveKind DK,
1369 OpenACCDirectiveKind AssocKind,
1370 OpenACCGangKind GK, Expr *E) {
1371 switch (GK) {
1372 // 'dim' and 'num' don't really make sense on serial, and GCC rejects them
1373 // too, so we disallow them too.
1374 case OpenACCGangKind::Dim:
1375 case OpenACCGangKind::Num:
1376 return DiagIntArgInvalid(S, E, GK, OpenACCClauseKind::Gang, DK, AssocKind);
1377 case OpenACCGangKind::Static:
1378 return CheckGangStaticExpr(S, E);
1379 }
1380 llvm_unreachable("Unknown gang kind in gang serial check");
1381}
1382
1383OpenACCClause *SemaOpenACCClauseVisitor::VisitVectorClause(
1385 if (DiagIfSeqClause(Clause))
1386 return nullptr;
1387
1388 // Restrictions only properly implemented on 'loop'/'combined' constructs, and
1389 // it is the only construct that can do anything with this, so skip/treat as
1390 // unimplemented for the routine constructs.
1391 if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
1392 return isNotImplemented();
1393
1394 Expr *IntExpr =
1395 Clause.getNumIntExprs() != 0 ? Clause.getIntExprs()[0] : nullptr;
1396 if (IntExpr) {
1398 switch (SemaRef.getActiveComputeConstructInfo().Kind) {
1399 case OpenACCDirectiveKind::Invalid:
1400 case OpenACCDirectiveKind::Parallel:
1401 // No restriction on when 'parallel' can contain an argument.
1402 break;
1403 case OpenACCDirectiveKind::Serial:
1404 // GCC disallows this, and there is no real good reason for us to permit
1405 // it, so disallow until we come up with a use case that makes sense.
1406 DiagIntArgInvalid(SemaRef, IntExpr, "length", OpenACCClauseKind::Vector,
1407 Clause.getDirectiveKind(),
1408 SemaRef.getActiveComputeConstructInfo().Kind);
1409 IntExpr = nullptr;
1410 break;
1411 case OpenACCDirectiveKind::Kernels: {
1412 const auto *Itr =
1413 llvm::find_if(SemaRef.getActiveComputeConstructInfo().Clauses,
1414 llvm::IsaPred<OpenACCVectorLengthClause>);
1415 if (Itr != SemaRef.getActiveComputeConstructInfo().Clauses.end()) {
1416 SemaRef.Diag(IntExpr->getBeginLoc(), diag::err_acc_num_arg_conflict)
1417 << "length" << OpenACCClauseKind::Vector
1418 << Clause.getDirectiveKind()
1419 << HasAssocKind(Clause.getDirectiveKind(),
1420 SemaRef.getActiveComputeConstructInfo().Kind)
1421 << SemaRef.getActiveComputeConstructInfo().Kind
1422 << OpenACCClauseKind::VectorLength;
1423 SemaRef.Diag((*Itr)->getBeginLoc(),
1424 diag::note_acc_previous_clause_here);
1425
1426 IntExpr = nullptr;
1427 }
1428 break;
1429 }
1430 default:
1431 llvm_unreachable("Non compute construct in active compute construct");
1432 }
1433 } else {
1434 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::SerialLoop) {
1435 DiagIntArgInvalid(SemaRef, IntExpr, "length", OpenACCClauseKind::Vector,
1436 Clause.getDirectiveKind(),
1437 SemaRef.getActiveComputeConstructInfo().Kind);
1438 IntExpr = nullptr;
1439 } else if (Clause.getDirectiveKind() ==
1440 OpenACCDirectiveKind::KernelsLoop) {
1441 const auto *Itr = llvm::find_if(
1442 ExistingClauses, llvm::IsaPred<OpenACCVectorLengthClause>);
1443 if (Itr != ExistingClauses.end()) {
1444 SemaRef.Diag(IntExpr->getBeginLoc(), diag::err_acc_num_arg_conflict)
1445 << "length" << OpenACCClauseKind::Vector
1446 << Clause.getDirectiveKind()
1447 << HasAssocKind(Clause.getDirectiveKind(),
1448 SemaRef.getActiveComputeConstructInfo().Kind)
1449 << SemaRef.getActiveComputeConstructInfo().Kind
1450 << OpenACCClauseKind::VectorLength;
1451 SemaRef.Diag((*Itr)->getBeginLoc(),
1452 diag::note_acc_previous_clause_here);
1453
1454 IntExpr = nullptr;
1455 }
1456 }
1457 }
1458 }
1459
1461 // OpenACC 3.3 2.9.4: The region of a loop with a 'vector' clause may not
1462 // contain a loop with a gang, worker, or vector clause unless within a
1463 // nested compute region.
1464 if (SemaRef.LoopVectorClauseLoc.isValid()) {
1465 // This handles the 'inner loop' diagnostic, but we cannot set that we're
1466 // on one of these until we get to the end of the construct.
1467 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1468 << OpenACCClauseKind::Vector << OpenACCClauseKind::Vector
1469 << /*skip kernels construct info*/ 0;
1470 SemaRef.Diag(SemaRef.LoopVectorClauseLoc,
1471 diag::note_acc_previous_clause_here);
1472 return nullptr;
1473 }
1474 }
1475
1476 return OpenACCVectorClause::Create(Ctx, Clause.getBeginLoc(),
1477 Clause.getLParenLoc(), IntExpr,
1478 Clause.getEndLoc());
1479}
1480
1481OpenACCClause *SemaOpenACCClauseVisitor::VisitWorkerClause(
1483 if (DiagIfSeqClause(Clause))
1484 return nullptr;
1485
1486 // Restrictions only properly implemented on 'loop'/'combined' constructs, and
1487 // it is the only construct that can do anything with this, so skip/treat as
1488 // unimplemented for the routine constructs.
1489 if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
1490 return isNotImplemented();
1491
1492 Expr *IntExpr =
1493 Clause.getNumIntExprs() != 0 ? Clause.getIntExprs()[0] : nullptr;
1494
1495 if (IntExpr) {
1497 switch (SemaRef.getActiveComputeConstructInfo().Kind) {
1498 case OpenACCDirectiveKind::Invalid:
1499 case OpenACCDirectiveKind::ParallelLoop:
1500 case OpenACCDirectiveKind::SerialLoop:
1501 case OpenACCDirectiveKind::Parallel:
1502 case OpenACCDirectiveKind::Serial:
1503 DiagIntArgInvalid(SemaRef, IntExpr, OpenACCGangKind::Num,
1504 OpenACCClauseKind::Worker, Clause.getDirectiveKind(),
1505 SemaRef.getActiveComputeConstructInfo().Kind);
1506 IntExpr = nullptr;
1507 break;
1508 case OpenACCDirectiveKind::KernelsLoop:
1509 case OpenACCDirectiveKind::Kernels: {
1510 const auto *Itr =
1511 llvm::find_if(SemaRef.getActiveComputeConstructInfo().Clauses,
1512 llvm::IsaPred<OpenACCNumWorkersClause>);
1513 if (Itr != SemaRef.getActiveComputeConstructInfo().Clauses.end()) {
1514 SemaRef.Diag(IntExpr->getBeginLoc(), diag::err_acc_num_arg_conflict)
1515 << "num" << OpenACCClauseKind::Worker << Clause.getDirectiveKind()
1516 << HasAssocKind(Clause.getDirectiveKind(),
1517 SemaRef.getActiveComputeConstructInfo().Kind)
1518 << SemaRef.getActiveComputeConstructInfo().Kind
1519 << OpenACCClauseKind::NumWorkers;
1520 SemaRef.Diag((*Itr)->getBeginLoc(),
1521 diag::note_acc_previous_clause_here);
1522
1523 IntExpr = nullptr;
1524 }
1525 break;
1526 }
1527 default:
1528 llvm_unreachable("Non compute construct in active compute construct");
1529 }
1530 } else {
1531 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::ParallelLoop ||
1532 Clause.getDirectiveKind() == OpenACCDirectiveKind::SerialLoop) {
1533 DiagIntArgInvalid(SemaRef, IntExpr, OpenACCGangKind::Num,
1534 OpenACCClauseKind::Worker, Clause.getDirectiveKind(),
1535 SemaRef.getActiveComputeConstructInfo().Kind);
1536 IntExpr = nullptr;
1537 } else {
1538 assert(Clause.getDirectiveKind() == OpenACCDirectiveKind::KernelsLoop &&
1539 "Unknown combined directive kind?");
1540 const auto *Itr = llvm::find_if(ExistingClauses,
1541 llvm::IsaPred<OpenACCNumWorkersClause>);
1542 if (Itr != ExistingClauses.end()) {
1543 SemaRef.Diag(IntExpr->getBeginLoc(), diag::err_acc_num_arg_conflict)
1544 << "num" << OpenACCClauseKind::Worker << Clause.getDirectiveKind()
1545 << HasAssocKind(Clause.getDirectiveKind(),
1546 SemaRef.getActiveComputeConstructInfo().Kind)
1547 << SemaRef.getActiveComputeConstructInfo().Kind
1548 << OpenACCClauseKind::NumWorkers;
1549 SemaRef.Diag((*Itr)->getBeginLoc(),
1550 diag::note_acc_previous_clause_here);
1551
1552 IntExpr = nullptr;
1553 }
1554 }
1555 }
1556 }
1557
1559 // OpenACC 3.3 2.9.3: The region of a loop with a 'worker' clause may not
1560 // contain a loop with a gang or worker clause unless within a nested
1561 // compute region.
1562 if (SemaRef.LoopWorkerClauseLoc.isValid()) {
1563 // This handles the 'inner loop' diagnostic, but we cannot set that we're
1564 // on one of these until we get to the end of the construct.
1565 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1566 << OpenACCClauseKind::Worker << OpenACCClauseKind::Worker
1567 << /*skip kernels construct info*/ 0;
1568 SemaRef.Diag(SemaRef.LoopWorkerClauseLoc,
1569 diag::note_acc_previous_clause_here);
1570 return nullptr;
1571 }
1572
1573 // OpenACC 3.3 2.9.4: The region of a loop with a 'vector' clause may not
1574 // contain a loop with a gang, worker, or vector clause unless within a
1575 // nested compute region.
1576 if (SemaRef.LoopVectorClauseLoc.isValid()) {
1577 // This handles the 'inner loop' diagnostic, but we cannot set that we're
1578 // on one of these until we get to the end of the construct.
1579 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1580 << OpenACCClauseKind::Worker << OpenACCClauseKind::Vector
1581 << /*skip kernels construct info*/ 0;
1582 SemaRef.Diag(SemaRef.LoopVectorClauseLoc,
1583 diag::note_acc_previous_clause_here);
1584 return nullptr;
1585 }
1586 }
1587
1588 return OpenACCWorkerClause::Create(Ctx, Clause.getBeginLoc(),
1589 Clause.getLParenLoc(), IntExpr,
1590 Clause.getEndLoc());
1591}
1592
1593OpenACCClause *SemaOpenACCClauseVisitor::VisitGangClause(
1595 if (DiagIfSeqClause(Clause))
1596 return nullptr;
1597
1598 // Restrictions only properly implemented on 'loop' constructs, and it is
1599 // the only construct that can do anything with this, so skip/treat as
1600 // unimplemented for the combined constructs.
1601 if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
1602 return isNotImplemented();
1603
1604 // OpenACC 3.3 Section 2.9.11: A reduction clause may not appear on a loop
1605 // directive that has a gang clause and is within a compute construct that has
1606 // a num_gangs clause with more than one explicit argument.
1607 if ((Clause.getDirectiveKind() == OpenACCDirectiveKind::Loop &&
1608 SemaRef.getActiveComputeConstructInfo().Kind !=
1609 OpenACCDirectiveKind::Invalid) ||
1611 // num_gangs clause on the active compute construct.
1612 auto ActiveComputeConstructContainer =
1614 ? ExistingClauses
1615 : SemaRef.getActiveComputeConstructInfo().Clauses;
1616 auto *NumGangsClauseItr = llvm::find_if(
1617 ActiveComputeConstructContainer, llvm::IsaPred<OpenACCNumGangsClause>);
1618
1619 if (NumGangsClauseItr != ActiveComputeConstructContainer.end() &&
1620 cast<OpenACCNumGangsClause>(*NumGangsClauseItr)->getIntExprs().size() >
1621 1) {
1622 auto *ReductionClauseItr =
1623 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
1624
1625 if (ReductionClauseItr != ExistingClauses.end()) {
1626 SemaRef.Diag(Clause.getBeginLoc(),
1627 diag::err_acc_gang_reduction_numgangs_conflict)
1628 << OpenACCClauseKind::Gang << OpenACCClauseKind::Reduction
1629 << Clause.getDirectiveKind()
1631 SemaRef.Diag((*ReductionClauseItr)->getBeginLoc(),
1632 diag::note_acc_previous_clause_here);
1633 SemaRef.Diag((*NumGangsClauseItr)->getBeginLoc(),
1634 diag::note_acc_previous_clause_here);
1635 return nullptr;
1636 }
1637 }
1638 }
1639
1642
1643 // Store the existing locations, so we can do duplicate checking. Index is
1644 // the int-value of the OpenACCGangKind enum.
1645 SourceLocation ExistingElemLoc[3];
1646
1647 for (unsigned I = 0; I < Clause.getIntExprs().size(); ++I) {
1648 OpenACCGangKind GK = Clause.getGangKinds()[I];
1649 ExprResult ER =
1650 SemaRef.CheckGangExpr(ExistingClauses, Clause.getDirectiveKind(), GK,
1651 Clause.getIntExprs()[I]);
1652
1653 if (!ER.isUsable())
1654 continue;
1655
1656 // OpenACC 3.3 2.9: 'gang-arg-list' may have at most one num, one dim, and
1657 // one static argument.
1658 if (ExistingElemLoc[static_cast<unsigned>(GK)].isValid()) {
1659 SemaRef.Diag(ER.get()->getBeginLoc(), diag::err_acc_gang_multiple_elt)
1660 << static_cast<unsigned>(GK);
1661 SemaRef.Diag(ExistingElemLoc[static_cast<unsigned>(GK)],
1662 diag::note_acc_previous_expr_here);
1663 continue;
1664 }
1665
1666 ExistingElemLoc[static_cast<unsigned>(GK)] = ER.get()->getBeginLoc();
1667 GangKinds.push_back(GK);
1668 IntExprs.push_back(ER.get());
1669 }
1670
1672 // OpenACC 3.3 2.9.2: When the parent compute construct is a kernels
1673 // construct, the gang clause behaves as follows. ... The region of a loop
1674 // with a gang clause may not contain another loop with a gang clause unless
1675 // within a nested compute region.
1676 if (SemaRef.LoopGangClauseOnKernel.Loc.isValid()) {
1677 // This handles the 'inner loop' diagnostic, but we cannot set that we're
1678 // on one of these until we get to the end of the construct.
1679 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1680 << OpenACCClauseKind::Gang << OpenACCClauseKind::Gang
1681 << /*kernels construct info*/ 1
1683 SemaRef.Diag(SemaRef.LoopGangClauseOnKernel.Loc,
1684 diag::note_acc_previous_clause_here);
1685 return nullptr;
1686 }
1687
1688 // OpenACC 3.3 2.9.3: The region of a loop with a 'worker' clause may not
1689 // contain a loop with a gang or worker clause unless within a nested
1690 // compute region.
1691 if (SemaRef.LoopWorkerClauseLoc.isValid()) {
1692 // This handles the 'inner loop' diagnostic, but we cannot set that we're
1693 // on one of these until we get to the end of the construct.
1694 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1695 << OpenACCClauseKind::Gang << OpenACCClauseKind::Worker
1696 << /*!kernels construct info*/ 0;
1697 SemaRef.Diag(SemaRef.LoopWorkerClauseLoc,
1698 diag::note_acc_previous_clause_here);
1699 return nullptr;
1700 }
1701
1702 // OpenACC 3.3 2.9.4: The region of a loop with a 'vector' clause may not
1703 // contain a loop with a gang, worker, or vector clause unless within a
1704 // nested compute region.
1705 if (SemaRef.LoopVectorClauseLoc.isValid()) {
1706 // This handles the 'inner loop' diagnostic, but we cannot set that we're
1707 // on one of these until we get to the end of the construct.
1708 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1709 << OpenACCClauseKind::Gang << OpenACCClauseKind::Vector
1710 << /*!kernels construct info*/ 0;
1711 SemaRef.Diag(SemaRef.LoopVectorClauseLoc,
1712 diag::note_acc_previous_clause_here);
1713 return nullptr;
1714 }
1715 }
1716
1717 return SemaRef.CheckGangClause(Clause.getDirectiveKind(), ExistingClauses,
1718 Clause.getBeginLoc(), Clause.getLParenLoc(),
1719 GangKinds, IntExprs, Clause.getEndLoc());
1720}
1721
1722OpenACCClause *SemaOpenACCClauseVisitor::VisitFinalizeClause(
1724 // There isn't anything to do here, this is only valid on one construct, and
1725 // has no associated rules.
1726 return OpenACCFinalizeClause::Create(Ctx, Clause.getBeginLoc(),
1727 Clause.getEndLoc());
1728}
1729
1730OpenACCClause *SemaOpenACCClauseVisitor::VisitIfPresentClause(
1732 // There isn't anything to do here, this is only valid on one construct, and
1733 // has no associated rules.
1734 return OpenACCIfPresentClause::Create(Ctx, Clause.getBeginLoc(),
1735 Clause.getEndLoc());
1736}
1737
1738OpenACCClause *SemaOpenACCClauseVisitor::VisitSeqClause(
1740 // Restrictions only properly implemented on 'loop' constructs and combined ,
1741 // and it is the only construct that can do anything with this, so skip/treat
1742 // as unimplemented for the routine constructs.
1743 if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
1744 return isNotImplemented();
1745
1746 // OpenACC 3.3 2.9:
1747 // Only one of the seq, independent, and auto clauses may appear.
1748 const auto *Itr =
1749 llvm::find_if(ExistingClauses,
1750 llvm::IsaPred<OpenACCAutoClause, OpenACCIndependentClause>);
1751 if (Itr != ExistingClauses.end()) {
1752 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_loop_spec_conflict)
1753 << Clause.getClauseKind() << Clause.getDirectiveKind();
1754 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
1755 return nullptr;
1756 }
1757
1758 // OpenACC 3.3 2.9:
1759 // A 'gang', 'worker', or 'vector' clause may not appear if a 'seq' clause
1760 // appears.
1761 Itr = llvm::find_if(ExistingClauses,
1764
1765 if (Itr != ExistingClauses.end()) {
1766 SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_cannot_combine)
1767 << Clause.getClauseKind() << (*Itr)->getClauseKind()
1768 << Clause.getDirectiveKind();
1769 SemaRef.Diag((*Itr)->getBeginLoc(), diag::note_acc_previous_clause_here);
1770 return nullptr;
1771 }
1772
1773 return OpenACCSeqClause::Create(Ctx, Clause.getBeginLoc(),
1774 Clause.getEndLoc());
1775}
1776
1777OpenACCClause *SemaOpenACCClauseVisitor::VisitReductionClause(
1779 // OpenACC 3.3 Section 2.9.11: A reduction clause may not appear on a loop
1780 // directive that has a gang clause and is within a compute construct that has
1781 // a num_gangs clause with more than one explicit argument.
1782 if ((Clause.getDirectiveKind() == OpenACCDirectiveKind::Loop &&
1783 SemaRef.getActiveComputeConstructInfo().Kind !=
1784 OpenACCDirectiveKind::Invalid) ||
1786 // num_gangs clause on the active compute construct.
1787 auto ActiveComputeConstructContainer =
1789 ? ExistingClauses
1790 : SemaRef.getActiveComputeConstructInfo().Clauses;
1791 auto *NumGangsClauseItr = llvm::find_if(
1792 ActiveComputeConstructContainer, llvm::IsaPred<OpenACCNumGangsClause>);
1793
1794 if (NumGangsClauseItr != ActiveComputeConstructContainer.end() &&
1795 cast<OpenACCNumGangsClause>(*NumGangsClauseItr)->getIntExprs().size() >
1796 1) {
1797 auto *GangClauseItr =
1798 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
1799
1800 if (GangClauseItr != ExistingClauses.end()) {
1801 SemaRef.Diag(Clause.getBeginLoc(),
1802 diag::err_acc_gang_reduction_numgangs_conflict)
1803 << OpenACCClauseKind::Reduction << OpenACCClauseKind::Gang
1804 << Clause.getDirectiveKind()
1806 SemaRef.Diag((*GangClauseItr)->getBeginLoc(),
1807 diag::note_acc_previous_clause_here);
1808 SemaRef.Diag((*NumGangsClauseItr)->getBeginLoc(),
1809 diag::note_acc_previous_clause_here);
1810 return nullptr;
1811 }
1812 }
1813 }
1814
1815 // OpenACC3.3 Section 2.9.11: If a variable is involved in a reduction that
1816 // spans multiple nested loops where two or more of those loops have
1817 // associated loop directives, a reduction clause containing that variable
1818 // must appear on each of those loop directives.
1819 //
1820 // This can't really be implemented in the CFE, as this requires a level of
1821 // rechability/useage analysis that we're not really wanting to get into.
1822 // Additionally, I'm alerted that this restriction is one that the middle-end
1823 // can just 'figure out' as an extension and isn't really necessary.
1824 //
1825 // OpenACC3.3 Section 2.9.11: Every 'var' in a reduction clause appearing on
1826 // an orphaned loop construct must be private.
1827 //
1828 // This again is something we cannot really diagnose, as it requires we see
1829 // all the uses/scopes of all variables referenced. The middle end/MLIR might
1830 // be able to diagnose this.
1831
1832 // OpenACC 3.3 Section 2.5.4:
1833 // A reduction clause may not appear on a parallel construct with a
1834 // num_gangs clause that has more than one argument.
1835 if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Parallel ||
1836 Clause.getDirectiveKind() == OpenACCDirectiveKind::ParallelLoop) {
1837 auto NumGangsClauses = llvm::make_filter_range(
1838 ExistingClauses, llvm::IsaPred<OpenACCNumGangsClause>);
1839
1840 for (auto *NGC : NumGangsClauses) {
1841 unsigned NumExprs =
1842 cast<OpenACCNumGangsClause>(NGC)->getIntExprs().size();
1843
1844 if (NumExprs > 1) {
1845 SemaRef.Diag(Clause.getBeginLoc(),
1846 diag::err_acc_reduction_num_gangs_conflict)
1847 << /*>1 arg in first loc=*/0 << Clause.getClauseKind()
1848 << Clause.getDirectiveKind() << OpenACCClauseKind::NumGangs;
1849 SemaRef.Diag(NGC->getBeginLoc(), diag::note_acc_previous_clause_here);
1850 return nullptr;
1851 }
1852 }
1853 }
1854
1855 SmallVector<Expr *> ValidVars;
1856
1857 for (Expr *Var : Clause.getVarList()) {
1858 ExprResult Res = SemaRef.CheckReductionVar(Clause.getDirectiveKind(),
1859 Clause.getReductionOp(), Var);
1860
1861 if (Res.isUsable())
1862 ValidVars.push_back(Res.get());
1863 }
1864
1865 return SemaRef.CheckReductionClause(
1866 ExistingClauses, Clause.getDirectiveKind(), Clause.getBeginLoc(),
1867 Clause.getLParenLoc(), Clause.getReductionOp(), ValidVars,
1868 Clause.getEndLoc());
1869}
1870
1871OpenACCClause *SemaOpenACCClauseVisitor::VisitCollapseClause(
1873 // Duplicates here are not really sensible. We could possible permit
1874 // multiples if they all had the same value, but there isn't really a good
1875 // reason to do so. Also, this simplifies the suppression of duplicates, in
1876 // that we know if we 'find' one after instantiation, that it is the same
1877 // clause, which simplifies instantiation/checking/etc.
1878 if (checkAlreadyHasClauseOfKind(SemaRef, ExistingClauses, Clause))
1879 return nullptr;
1880
1881 ExprResult LoopCount = SemaRef.CheckCollapseLoopCount(Clause.getLoopCount());
1882
1883 if (!LoopCount.isUsable())
1884 return nullptr;
1885
1886 return OpenACCCollapseClause::Create(Ctx, Clause.getBeginLoc(),
1887 Clause.getLParenLoc(), Clause.isForce(),
1888 LoopCount.get(), Clause.getEndLoc());
1889}
1890
1891// Return true if the two vars refer to the same variable, for the purposes of
1892// equality checking.
1893bool areVarsEqual(Expr *VarExpr1, Expr *VarExpr2) {
1894 if (VarExpr1->isInstantiationDependent() ||
1895 VarExpr2->isInstantiationDependent())
1896 return false;
1897
1898 VarExpr1 = VarExpr1->IgnoreParenCasts();
1899 VarExpr2 = VarExpr2->IgnoreParenCasts();
1900
1901 // Legal expressions can be: Scalar variable reference, sub-array, array
1902 // element, or composite variable member.
1903
1904 // Sub-array.
1905 if (isa<ArraySectionExpr>(VarExpr1)) {
1906 auto *Expr2AS = dyn_cast<ArraySectionExpr>(VarExpr2);
1907 if (!Expr2AS)
1908 return false;
1909
1910 auto *Expr1AS = cast<ArraySectionExpr>(VarExpr1);
1911
1912 if (!areVarsEqual(Expr1AS->getBase(), Expr2AS->getBase()))
1913 return false;
1914 // We could possibly check to see if the ranges aren't overlapping, but it
1915 // isn't clear that the rules allow this.
1916 return true;
1917 }
1918
1919 // Array-element.
1920 if (isa<ArraySubscriptExpr>(VarExpr1)) {
1921 auto *Expr2AS = dyn_cast<ArraySubscriptExpr>(VarExpr2);
1922 if (!Expr2AS)
1923 return false;
1924
1925 auto *Expr1AS = cast<ArraySubscriptExpr>(VarExpr1);
1926
1927 if (!areVarsEqual(Expr1AS->getBase(), Expr2AS->getBase()))
1928 return false;
1929
1930 // We could possibly check to see if the elements referenced aren't the
1931 // same, but it isn't clear by reading of the standard that this is allowed
1932 // (and that the 'var' refered to isn't the array).
1933 return true;
1934 }
1935
1936 // Scalar variable reference, or composite variable.
1937 if (isa<DeclRefExpr>(VarExpr1)) {
1938 auto *Expr2DRE = dyn_cast<DeclRefExpr>(VarExpr2);
1939 if (!Expr2DRE)
1940 return false;
1941
1942 auto *Expr1DRE = cast<DeclRefExpr>(VarExpr1);
1943
1944 return Expr1DRE->getDecl()->getMostRecentDecl() ==
1945 Expr2DRE->getDecl()->getMostRecentDecl();
1946 }
1947
1948 llvm_unreachable("Unknown variable type encountered");
1949}
1950} // namespace
1951
1954 OpenACCParsedClause &Clause) {
1956 return nullptr;
1957
1958 // Diagnose that we don't support this clause on this directive.
1959 if (!doesClauseApplyToDirective(Clause.getDirectiveKind(),
1960 Clause.getClauseKind())) {
1961 Diag(Clause.getBeginLoc(), diag::err_acc_clause_appertainment)
1962 << Clause.getDirectiveKind() << Clause.getClauseKind();
1963 return nullptr;
1964 }
1965
1966 if (const auto *DevTypeClause =
1967 llvm::find_if(ExistingClauses,
1968 [&](const OpenACCClause *C) {
1969 return isa<OpenACCDeviceTypeClause>(C);
1970 });
1971 DevTypeClause != ExistingClauses.end()) {
1972 if (checkValidAfterDeviceType(
1973 *this, *cast<OpenACCDeviceTypeClause>(*DevTypeClause), Clause))
1974 return nullptr;
1975 }
1976
1977 SemaOpenACCClauseVisitor Visitor{*this, ExistingClauses};
1978 OpenACCClause *Result = Visitor.Visit(Clause);
1979 assert((!Result || Result->getClauseKind() == Clause.getClauseKind()) &&
1980 "Created wrong clause?");
1981
1982 if (Visitor.diagNotImplemented())
1983 Diag(Clause.getBeginLoc(), diag::warn_acc_clause_unimplemented)
1984 << Clause.getClauseKind();
1985
1986 return Result;
1987
1988}
1989
1990/// OpenACC 3.3 section 2.5.15:
1991/// At a mininmum, the supported data types include ... the numerical data types
1992/// in C, C++, and Fortran.
1993///
1994/// If the reduction var is a composite variable, each
1995/// member of the composite variable must be a supported datatype for the
1996/// reduction operation.
1998 OpenACCReductionOperator ReductionOp,
1999 Expr *VarExpr) {
2000 VarExpr = VarExpr->IgnoreParenCasts();
2001
2002 auto TypeIsValid = [](QualType Ty) {
2003 return Ty->isDependentType() || Ty->isScalarType();
2004 };
2005
2006 if (isa<ArraySectionExpr>(VarExpr)) {
2007 Expr *ASExpr = VarExpr;
2009 QualType EltTy = getASTContext().getBaseElementType(BaseTy);
2010
2011 if (!TypeIsValid(EltTy)) {
2012 Diag(VarExpr->getExprLoc(), diag::err_acc_reduction_type)
2013 << EltTy << /*Sub array base type*/ 1;
2014 return ExprError();
2015 }
2016 } else if (auto *RD = VarExpr->getType()->getAsRecordDecl()) {
2017 if (!RD->isStruct() && !RD->isClass()) {
2018 Diag(VarExpr->getExprLoc(), diag::err_acc_reduction_composite_type)
2019 << /*not class or struct*/ 0 << VarExpr->getType();
2020 return ExprError();
2021 }
2022
2023 if (!RD->isCompleteDefinition()) {
2024 Diag(VarExpr->getExprLoc(), diag::err_acc_reduction_composite_type)
2025 << /*incomplete*/ 1 << VarExpr->getType();
2026 return ExprError();
2027 }
2028 if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
2029 CXXRD && !CXXRD->isAggregate()) {
2030 Diag(VarExpr->getExprLoc(), diag::err_acc_reduction_composite_type)
2031 << /*aggregate*/ 2 << VarExpr->getType();
2032 return ExprError();
2033 }
2034
2035 for (FieldDecl *FD : RD->fields()) {
2036 if (!TypeIsValid(FD->getType())) {
2037 Diag(VarExpr->getExprLoc(),
2038 diag::err_acc_reduction_composite_member_type);
2039 Diag(FD->getLocation(), diag::note_acc_reduction_composite_member_loc);
2040 return ExprError();
2041 }
2042 }
2043 } else if (!TypeIsValid(VarExpr->getType())) {
2044 Diag(VarExpr->getExprLoc(), diag::err_acc_reduction_type)
2045 << VarExpr->getType() << /*Sub array base type*/ 0;
2046 return ExprError();
2047 }
2048
2049 // OpenACC3.3: 2.9.11: Reduction clauses on nested constructs for the same
2050 // reduction 'var' must have the same reduction operator.
2051 if (!VarExpr->isInstantiationDependent()) {
2052
2053 for (const OpenACCReductionClause *RClause : ActiveReductionClauses) {
2054 if (RClause->getReductionOp() == ReductionOp)
2055 break;
2056
2057 for (Expr *OldVarExpr : RClause->getVarList()) {
2058 if (OldVarExpr->isInstantiationDependent())
2059 continue;
2060
2061 if (areVarsEqual(VarExpr, OldVarExpr)) {
2062 Diag(VarExpr->getExprLoc(), diag::err_reduction_op_mismatch)
2063 << ReductionOp << RClause->getReductionOp();
2064 Diag(OldVarExpr->getExprLoc(), diag::note_acc_previous_clause_here);
2065 return ExprError();
2066 }
2067 }
2068 }
2069 }
2070
2071 return VarExpr;
2072}
2073
2075 if (!SizeExpr)
2076 return ExprError();
2077
2078 assert((SizeExpr->isInstantiationDependent() ||
2079 SizeExpr->getType()->isIntegerType()) &&
2080 "size argument non integer?");
2081
2082 // If dependent, or an asterisk, the expression is fine.
2083 if (SizeExpr->isInstantiationDependent() ||
2084 isa<OpenACCAsteriskSizeExpr>(SizeExpr))
2085 return ExprResult{SizeExpr};
2086
2087 std::optional<llvm::APSInt> ICE =
2089
2090 // OpenACC 3.3 2.9.8
2091 // where each tile size is a constant positive integer expression or asterisk.
2092 if (!ICE || *ICE <= 0) {
2093 Diag(SizeExpr->getBeginLoc(), diag::err_acc_size_expr_value)
2094 << ICE.has_value() << ICE.value_or(llvm::APSInt{}).getExtValue();
2095 return ExprError();
2096 }
2097
2098 return ExprResult{
2099 ConstantExpr::Create(getASTContext(), SizeExpr, APValue{*ICE})};
2100}
2101
2103 if (!LoopCount)
2104 return ExprError();
2105
2106 assert((LoopCount->isInstantiationDependent() ||
2107 LoopCount->getType()->isIntegerType()) &&
2108 "Loop argument non integer?");
2109
2110 // If this is dependent, there really isn't anything we can check.
2111 if (LoopCount->isInstantiationDependent())
2112 return ExprResult{LoopCount};
2113
2114 std::optional<llvm::APSInt> ICE =
2116
2117 // OpenACC 3.3: 2.9.1
2118 // The argument to the collapse clause must be a constant positive integer
2119 // expression.
2120 if (!ICE || *ICE <= 0) {
2121 Diag(LoopCount->getBeginLoc(), diag::err_acc_collapse_loop_count)
2122 << ICE.has_value() << ICE.value_or(llvm::APSInt{}).getExtValue();
2123 return ExprError();
2124 }
2125
2126 return ExprResult{
2127 ConstantExpr::Create(getASTContext(), LoopCount, APValue{*ICE})};
2128}
2129
2133 Expr *E) {
2134 // There are two cases for the enforcement here: the 'current' directive is a
2135 // 'loop', where we need to check the active compute construct kind, or the
2136 // current directive is a 'combined' construct, where we have to check the
2137 // current one.
2138 switch (DK) {
2140 return CheckGangParallelExpr(*this, DK, ActiveComputeConstructInfo.Kind, GK,
2141 E);
2143 return CheckGangSerialExpr(*this, DK, ActiveComputeConstructInfo.Kind, GK,
2144 E);
2146 return CheckGangKernelsExpr(*this, ExistingClauses, DK,
2147 ActiveComputeConstructInfo.Kind, GK, E);
2149 switch (ActiveComputeConstructInfo.Kind) {
2153 return CheckGangParallelExpr(*this, DK, ActiveComputeConstructInfo.Kind,
2154 GK, E);
2157 return CheckGangSerialExpr(*this, DK, ActiveComputeConstructInfo.Kind, GK,
2158 E);
2161 return CheckGangKernelsExpr(*this, ExistingClauses, DK,
2162 ActiveComputeConstructInfo.Kind, GK, E);
2163 default:
2164 llvm_unreachable("Non compute construct in active compute construct?");
2165 }
2166 default:
2167 // TODO: OpenACC: when we implement this on 'routine', we'll have to
2168 // implement its checking here.
2169 llvm_unreachable("Invalid directive kind for a Gang clause");
2170 }
2171 llvm_unreachable("Compute construct directive not handled?");
2172}
2173
2176 ArrayRef<const OpenACCClause *> ExistingClauses,
2177 SourceLocation BeginLoc, SourceLocation LParenLoc,
2178 ArrayRef<OpenACCGangKind> GangKinds,
2179 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc) {
2180 // OpenACC 3.3 2.9.11: A reduction clause may not appear on a loop directive
2181 // that has a gang clause with a dim: argument whose value is greater than 1.
2182
2183 const auto *ReductionItr =
2184 llvm::find_if(ExistingClauses, llvm::IsaPred<OpenACCReductionClause>);
2185
2186 if (ReductionItr != ExistingClauses.end()) {
2187 const auto GangZip = llvm::zip_equal(GangKinds, IntExprs);
2188 const auto GangItr = llvm::find_if(GangZip, [](const auto &Tuple) {
2189 return std::get<0>(Tuple) == OpenACCGangKind::Dim;
2190 });
2191
2192 if (GangItr != GangZip.end()) {
2193 const Expr *DimExpr = std::get<1>(*GangItr);
2194
2195 assert(
2196 (DimExpr->isInstantiationDependent() || isa<ConstantExpr>(DimExpr)) &&
2197 "Improperly formed gang argument");
2198 if (const auto *DimVal = dyn_cast<ConstantExpr>(DimExpr);
2199 DimVal && DimVal->getResultAsAPSInt() > 1) {
2200 Diag(DimVal->getBeginLoc(), diag::err_acc_gang_reduction_conflict)
2201 << /*gang/reduction=*/0 << DirKind;
2202 Diag((*ReductionItr)->getBeginLoc(),
2203 diag::note_acc_previous_clause_here);
2204 return nullptr;
2205 }
2206 }
2207 }
2208
2209 return OpenACCGangClause::Create(getASTContext(), BeginLoc, LParenLoc,
2210 GangKinds, IntExprs, EndLoc);
2211}
2212
2214 ArrayRef<const OpenACCClause *> ExistingClauses,
2215 OpenACCDirectiveKind DirectiveKind, SourceLocation BeginLoc,
2216 SourceLocation LParenLoc, OpenACCReductionOperator ReductionOp,
2217 ArrayRef<Expr *> Vars, SourceLocation EndLoc) {
2218 if (DirectiveKind == OpenACCDirectiveKind::Loop ||
2219 isOpenACCCombinedDirectiveKind(DirectiveKind)) {
2220 // OpenACC 3.3 2.9.11: A reduction clause may not appear on a loop directive
2221 // that has a gang clause with a dim: argument whose value is greater
2222 // than 1.
2223 const auto GangClauses = llvm::make_filter_range(
2224 ExistingClauses, llvm::IsaPred<OpenACCGangClause>);
2225
2226 for (auto *GC : GangClauses) {
2227 const auto *GangClause = cast<OpenACCGangClause>(GC);
2228 for (unsigned I = 0; I < GangClause->getNumExprs(); ++I) {
2229 std::pair<OpenACCGangKind, const Expr *> EPair = GangClause->getExpr(I);
2230 if (EPair.first != OpenACCGangKind::Dim)
2231 continue;
2232
2233 if (const auto *DimVal = dyn_cast<ConstantExpr>(EPair.second);
2234 DimVal && DimVal->getResultAsAPSInt() > 1) {
2235 Diag(BeginLoc, diag::err_acc_gang_reduction_conflict)
2236 << /*reduction/gang=*/1 << DirectiveKind;
2237 Diag(GangClause->getBeginLoc(), diag::note_acc_previous_clause_here);
2238 return nullptr;
2239 }
2240 }
2241 }
2242 }
2243
2245 getASTContext(), BeginLoc, LParenLoc, ReductionOp, Vars, EndLoc);
2246 return Ret;
2247}
Expr * E
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines some OpenACC-specific enums and functions.
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:170
bool isUsable() const
Definition: Ownership.h:168
static QualType getBaseOriginalType(const Expr *Base)
Return original type of the base expression for array section.
Definition: Expr.cpp:5184
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition: Expr.cpp:349
This represents one expression.
Definition: Expr.h:110
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:3102
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition: Expr.h:221
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:276
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
QualType getType() const
Definition: Expr.h:142
Represents a member of a struct/union/class.
Definition: Decl.h:3033
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)
This is the base type for all OpenACC Clauses.
Definition: OpenACCClause.h:24
OpenACCClauseKind getClauseKind() const
Definition: OpenACCClause.h:37
SourceLocation getBeginLoc() const
Definition: OpenACCClause.h:38
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, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyInClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsReadOnly, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyOutClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCreateClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero, 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)
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, 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 OpenACCNoCreateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, 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, SourceLocation EndLoc)
static OpenACCReductionClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCReductionOperator Operator, ArrayRef< Expr * > VarList, 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: Type.h:929
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:60
ASTContext & getASTContext() const
Definition: SemaBase.cpp:9
A type to represent all the data for an OpenACC Clause that has been parsed, but not yet created/sema...
Definition: SemaOpenACC.h:202
ArrayRef< Expr * > getQueueIdExprs() const
Definition: SemaOpenACC.h:338
OpenACCDirectiveKind getDirectiveKind() const
Definition: SemaOpenACC.h:260
ArrayRef< OpenACCGangKind > getGangKinds() const
Definition: SemaOpenACC.h:380
OpenACCReductionOperator getReductionOp() const
Definition: SemaOpenACC.h:376
OpenACCClauseKind getClauseKind() const
Definition: SemaOpenACC.h:262
SourceLocation getLParenLoc() const
Definition: SemaOpenACC.h:266
ArrayRef< DeviceTypeArgument > getDeviceTypeArchitectures() const
Definition: SemaOpenACC.h:460
SourceLocation getBeginLoc() const
Definition: SemaOpenACC.h:264
SourceLocation getQueuesLoc() const
Definition: SemaOpenACC.h:318
void setVarListDetails(ArrayRef< Expr * > VarList, bool IsReadOnly, bool IsZero)
Definition: SemaOpenACC.h:536
OpenACCDefaultClauseKind getDefaultClauseKind() const
Definition: SemaOpenACC.h:270
ComputeConstructInfo & getActiveComputeConstructInfo()
Definition: SemaOpenACC.h:162
SourceLocation LoopWorkerClauseLoc
If there is a current 'active' loop construct with a 'worker' clause on it (on any sort of construct)...
Definition: SemaOpenACC.h:179
OpenACCClause * ActOnClause(ArrayRef< const OpenACCClause * > ExistingClauses, OpenACCParsedClause &Clause)
Called after parsing an OpenACC Clause so that it can be checked.
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...
ExprResult CheckCollapseLoopCount(Expr *LoopCount)
Checks the loop depth value for a collapse clause.
OpenACCClause * CheckReductionClause(ArrayRef< const OpenACCClause * > ExistingClauses, OpenACCDirectiveKind DirectiveKind, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCReductionOperator ReductionOp, ArrayRef< Expr * > Vars, SourceLocation EndLoc)
SourceLocation LoopVectorClauseLoc
If there is a current 'active' loop construct with a 'vector' clause on it (on any sort of construct)...
Definition: SemaOpenACC.h:184
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)
ExprResult CheckTileSizeExpr(Expr *SizeExpr)
Checks a single size expr for a tile clause.
ASTContext & getASTContext() const
Definition: Sema.h:532
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:345
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:8555
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1920
The JSON file list parser is used to communicate input to InstallAPI.
OpenACCDirectiveKind
Definition: OpenACCKinds.h:25
OpenACCReductionOperator
Definition: OpenACCKinds.h:509
bool isOpenACCComputeDirectiveKind(OpenACCDirectiveKind K)
Definition: OpenACCKinds.h:149
bool isOpenACCCombinedDirectiveKind(OpenACCDirectiveKind K)
Definition: OpenACCKinds.h:155
OpenACCClauseKind
Represents the kind of an OpenACC clause.
Definition: OpenACCKinds.h:178
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ Result
The result type of a method or function.
ExprResult ExprError()
Definition: Ownership.h:264
OpenACCGangKind
Definition: OpenACCKinds.h:568