clang 23.0.0git
OpenMPClause.h
Go to the documentation of this file.
1//===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===//
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//
9/// \file
10/// This file defines OpenMP AST classes for clauses.
11/// There are clauses for executable directives, clauses for declarative
12/// directives and clauses which can be used in both kinds of directives.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H
17#define LLVM_CLANG_AST_OPENMPCLAUSE_H
18
19#include "clang/AST/ASTFwd.h"
20#include "clang/AST/Decl.h"
22#include "clang/AST/Expr.h"
24#include "clang/AST/Stmt.h"
26#include "clang/Basic/LLVM.h"
29#include "llvm/ADT/ArrayRef.h"
30#include "llvm/ADT/MapVector.h"
31#include "llvm/ADT/PointerIntPair.h"
32#include "llvm/ADT/SmallVector.h"
33#include "llvm/ADT/iterator.h"
34#include "llvm/ADT/iterator_range.h"
35#include "llvm/Frontend/OpenMP/OMPAssume.h"
36#include "llvm/Frontend/OpenMP/OMPConstants.h"
37#include "llvm/Frontend/OpenMP/OMPContext.h"
38#include "llvm/Support/Casting.h"
39#include "llvm/Support/Compiler.h"
40#include "llvm/Support/TrailingObjects.h"
41#include <cassert>
42#include <climits>
43#include <cstddef>
44#include <iterator>
45#include <utility>
46
47namespace clang {
48
49class ASTContext;
50
51//===----------------------------------------------------------------------===//
52// AST classes for clauses.
53//===----------------------------------------------------------------------===//
54
55/// This is a basic class for representing single OpenMP clause.
56class OMPClause {
57 /// Starting location of the clause (the clause keyword).
58 SourceLocation StartLoc;
59
60 /// Ending location of the clause.
61 SourceLocation EndLoc;
62
63 /// Kind of the clause.
65
66protected:
68 : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
69
70public:
71 /// Returns the starting location of the clause.
72 SourceLocation getBeginLoc() const { return StartLoc; }
73
74 /// Returns the ending location of the clause.
75 SourceLocation getEndLoc() const { return EndLoc; }
76
77 /// Sets the starting location of the clause.
78 void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
79
80 /// Sets the ending location of the clause.
81 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
82
83 /// Returns kind of OpenMP clause (private, shared, reduction, etc.).
84 OpenMPClauseKind getClauseKind() const { return Kind; }
85
86 bool isImplicit() const { return StartLoc.isInvalid(); }
87
90 using child_range = llvm::iterator_range<child_iterator>;
91 using const_child_range = llvm::iterator_range<const_child_iterator>;
92
95 return const_cast<OMPClause *>(this)->children();
96 }
97
98 /// Get the iterator range for the expressions used in the clauses. Used
99 /// expressions include only the children that must be evaluated at the
100 /// runtime before entering the construct.
103 return const_cast<OMPClause *>(this)->children();
104 }
105
106 static bool classof(const OMPClause *) { return true; }
107};
108
109template <OpenMPClauseKind ClauseKind>
111 /// Build '\p ClauseKind' clause.
112 ///
113 /// \param StartLoc Starting location of the clause.
114 /// \param EndLoc Ending location of the clause.
116 : OMPClause(ClauseKind, StartLoc, EndLoc) {}
117
118 /// Build an empty clause.
121
125
129
136
137 static bool classof(const OMPClause *T) {
138 return T->getClauseKind() == ClauseKind;
139 }
140};
141
142template <OpenMPClauseKind ClauseKind, class Base>
143class OMPOneStmtClause : public Base {
144
145 /// Location of '('.
146 SourceLocation LParenLoc;
147
148 /// Sub-expression.
149 Stmt *S = nullptr;
150
151protected:
152 void setStmt(Stmt *S) { this->S = S; }
153
154public:
156 SourceLocation EndLoc)
157 : Base(ClauseKind, StartLoc, EndLoc), LParenLoc(LParenLoc), S(S) {}
158
160
161 /// Return the associated statement, potentially casted to \p T.
162 template <typename T> T *getStmtAs() const { return cast_or_null<T>(S); }
163
164 /// Sets the location of '('.
165 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
166
167 /// Returns the location of '('.
168 SourceLocation getLParenLoc() const { return LParenLoc; }
169
172 using child_range = llvm::iterator_range<child_iterator>;
173 using const_child_range = llvm::iterator_range<const_child_iterator>;
174
175 child_range children() { return child_range(&S, &S + 1); }
176
177 const_child_range children() const { return const_child_range(&S, &S + 1); }
178
179 // TODO: Consider making the getAddrOfExprAsWritten version the default.
186
187 static bool classof(const OMPClause *T) {
188 return T->getClauseKind() == ClauseKind;
189 }
190};
191
192/// Class that handles pre-initialization statement for some clauses, like
193/// 'schedule', 'firstprivate' etc.
195 friend class OMPClauseReader;
196
197 /// Pre-initialization statement for the clause.
198 Stmt *PreInit = nullptr;
199
200 /// Region that captures the associated stmt.
201 OpenMPDirectiveKind CaptureRegion = llvm::omp::OMPD_unknown;
202
203protected:
205 assert(get(This) && "get is not tuned for pre-init.");
206 }
207
208 /// Set pre-initialization statement for the clause.
209 void
211 OpenMPDirectiveKind ThisRegion = llvm::omp::OMPD_unknown) {
212 PreInit = S;
213 CaptureRegion = ThisRegion;
214 }
215
216public:
217 /// Get pre-initialization statement for the clause.
218 const Stmt *getPreInitStmt() const { return PreInit; }
219
220 /// Get pre-initialization statement for the clause.
221 Stmt *getPreInitStmt() { return PreInit; }
222
223 /// Get capture region for the stmt in the clause.
224 OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
225
227 static const OMPClauseWithPreInit *get(const OMPClause *C);
228};
229
230/// Class that handles post-update expression for some clauses, like
231/// 'lastprivate', 'reduction' etc.
233 friend class OMPClauseReader;
234
235 /// Post-update expression for the clause.
236 Expr *PostUpdate = nullptr;
237
238protected:
240 assert(get(This) && "get is not tuned for post-update.");
241 }
242
243 /// Set pre-initialization statement for the clause.
244 void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
245
246public:
247 /// Get post-update expression for the clause.
248 const Expr *getPostUpdateExpr() const { return PostUpdate; }
249
250 /// Get post-update expression for the clause.
251 Expr *getPostUpdateExpr() { return PostUpdate; }
252
254 static const OMPClauseWithPostUpdate *get(const OMPClause *C);
255};
256
257/// This structure contains most locations needed for by an OMPVarListClause.
259 /// Starting location of the clause (the clause keyword).
261 /// Location of '('.
263 /// Ending location of the clause.
265 OMPVarListLocTy() = default;
269};
270
271/// This represents clauses with the list of variables like 'private',
272/// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
273/// '#pragma omp ...' directives.
274template <class T> class OMPVarListClause : public OMPClause {
275 friend class OMPClauseReader;
276
277 /// Location of '('.
278 SourceLocation LParenLoc;
279
280 /// Number of variables in the list.
281 unsigned NumVars;
282
283protected:
284 /// Build a clause with \a N variables
285 ///
286 /// \param K Kind of the clause.
287 /// \param StartLoc Starting location of the clause (the clause keyword).
288 /// \param LParenLoc Location of '('.
289 /// \param EndLoc Ending location of the clause.
290 /// \param N Number of the variables in the clause.
292 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
293 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
294
295 /// Fetches list of variables associated with this clause.
297 return static_cast<T *>(this)->template getTrailingObjectsNonStrict<Expr *>(
298 NumVars);
299 }
300
301 /// Sets the list of variables for this clause.
303 assert(VL.size() == NumVars &&
304 "Number of variables is not the same as the preallocated buffer");
305 llvm::copy(VL, getVarRefs().begin());
306 }
307
308public:
311 using varlist_range = llvm::iterator_range<varlist_iterator>;
312 using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
313
314 unsigned varlist_size() const { return NumVars; }
315 bool varlist_empty() const { return NumVars == 0; }
316
319
322 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
324
325 /// Sets the location of '('.
326 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
327
328 /// Returns the location of '('.
329 SourceLocation getLParenLoc() const { return LParenLoc; }
330
331 /// Fetches list of all variables in the clause.
333 return static_cast<const T *>(this)
334 ->template getTrailingObjectsNonStrict<Expr *>(NumVars);
335 }
336};
337
338/// Class that represents a list of directive kinds (parallel, target, etc.)
339/// as used in \c absent, \c contains clauses.
340template <class T> class OMPDirectiveListClause : public OMPClause {
341 /// Location of '('.
342 SourceLocation LParenLoc;
343
344protected:
345 /// Number of directive kinds listed in the clause
346 unsigned NumKinds;
347
348public:
349 /// Build a clause with \a NumKinds directive kinds.
350 ///
351 /// \param K The clause kind.
352 /// \param StartLoc Starting location of the clause (the clause keyword).
353 /// \param LParenLoc Location of '('.
354 /// \param EndLoc Ending location of the clause.
355 /// \param NumKinds Number of directive kinds listed in the clause.
357 SourceLocation LParenLoc, SourceLocation EndLoc,
358 unsigned NumKinds)
359 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc),
361
365
369
376
378 return static_cast<T *>(this)
379 ->template getTrailingObjectsNonStrict<OpenMPDirectiveKind>(NumKinds);
380 }
381
383 assert(
384 DK.size() == NumKinds &&
385 "Number of directive kinds is not the same as the preallocated buffer");
386 llvm::copy(DK, getDirectiveKinds().begin());
387 }
388
389 SourceLocation getLParenLoc() { return LParenLoc; }
390
391 void setLParenLoc(SourceLocation S) { LParenLoc = S; }
392};
393
394/// This represents 'allocator' clause in the '#pragma omp ...'
395/// directive.
396///
397/// \code
398/// #pragma omp allocate(a) allocator(omp_default_mem_alloc)
399/// \endcode
400/// In this example directive '#pragma omp allocate' has simple 'allocator'
401/// clause with the allocator 'omp_default_mem_alloc'.
403 : public OMPOneStmtClause<llvm::omp::OMPC_allocator, OMPClause> {
404 friend class OMPClauseReader;
405
406 /// Set allocator.
407 void setAllocator(Expr *A) { setStmt(A); }
408
409public:
410 /// Build 'allocator' clause with the given allocator.
411 ///
412 /// \param A Allocator.
413 /// \param StartLoc Starting location of the clause.
414 /// \param LParenLoc Location of '('.
415 /// \param EndLoc Ending location of the clause.
417 SourceLocation EndLoc)
418 : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {}
419
420 /// Build an empty clause.
422
423 /// Returns allocator.
424 Expr *getAllocator() const { return getStmtAs<Expr>(); }
425};
426
427/// This represents the 'align' clause in the '#pragma omp allocate'
428/// directive.
429///
430/// \code
431/// #pragma omp allocate(a) allocator(omp_default_mem_alloc) align(8)
432/// \endcode
433/// In this example directive '#pragma omp allocate' has simple 'allocator'
434/// clause with the allocator 'omp_default_mem_alloc' and align clause with
435/// value of 8.
436class OMPAlignClause final
437 : public OMPOneStmtClause<llvm::omp::OMPC_align, OMPClause> {
438 friend class OMPClauseReader;
439
440 /// Set alignment value.
441 void setAlignment(Expr *A) { setStmt(A); }
442
443 /// Build 'align' clause with the given alignment
444 ///
445 /// \param A Alignment value.
446 /// \param StartLoc Starting location of the clause.
447 /// \param LParenLoc Location of '('.
448 /// \param EndLoc Ending location of the clause.
449 OMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc,
450 SourceLocation EndLoc)
451 : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {}
452
453 /// Build an empty clause.
454 OMPAlignClause() : OMPOneStmtClause() {}
455
456public:
457 /// Build 'align' clause with the given alignment
458 ///
459 /// \param A Alignment value.
460 /// \param StartLoc Starting location of the clause.
461 /// \param LParenLoc Location of '('.
462 /// \param EndLoc Ending location of the clause.
463 static OMPAlignClause *Create(const ASTContext &C, Expr *A,
464 SourceLocation StartLoc,
465 SourceLocation LParenLoc,
466 SourceLocation EndLoc);
467
468 /// Returns alignment
469 Expr *getAlignment() const { return getStmtAs<Expr>(); }
470};
471
472/// This represents clause 'allocate' in the '#pragma omp ...' directives.
473///
474/// \code
475/// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
476/// \endcode
477/// In this example directive '#pragma omp parallel' has clause 'private'
478/// and clause 'allocate' for the variable 'a', which specifies an explicit
479/// memory allocator.
480class OMPAllocateClause final
481 : public OMPVarListClause<OMPAllocateClause>,
482 private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
483 friend class OMPClauseReader;
484 friend OMPVarListClause;
485 friend TrailingObjects;
486
487 /// Allocator specified in the clause, or 'nullptr' if the default one is
488 /// used.
489 Expr *Allocator = nullptr;
490 /// Alignment specified in the clause, or 'nullptr' if the default one is
491 /// used.
492 Expr *Alignment = nullptr;
493 /// Position of the ':' delimiter in the clause;
494 SourceLocation ColonLoc;
495 /// Modifier of 'allocate' clause.
497 /// Location of allocator modifier if any.
498 SourceLocation AllocatorModifierLoc;
499
500 // ----------------------------------------------------------------------------
501
502 /// Modifiers for 'allocate' clause.
503 enum { FIRST, SECOND, NUM_MODIFIERS };
504 OpenMPAllocateClauseModifier Modifiers[NUM_MODIFIERS];
505
506 /// Locations of modifiers.
507 SourceLocation ModifiersLoc[NUM_MODIFIERS];
508
509 /// Set the first allocate modifier.
510 ///
511 /// \param M Allocate modifier.
512 void setFirstAllocateModifier(OpenMPAllocateClauseModifier M) {
513 Modifiers[FIRST] = M;
514 }
515
516 /// Set the second allocate modifier.
517 ///
518 /// \param M Allocate modifier.
519 void setSecondAllocateModifier(OpenMPAllocateClauseModifier M) {
520 Modifiers[SECOND] = M;
521 }
522
523 /// Set location of the first allocate modifier.
524 void setFirstAllocateModifierLoc(SourceLocation Loc) {
525 ModifiersLoc[FIRST] = Loc;
526 }
527
528 /// Set location of the second allocate modifier.
529 void setSecondAllocateModifierLoc(SourceLocation Loc) {
530 ModifiersLoc[SECOND] = Loc;
531 }
532
533 // ----------------------------------------------------------------------------
534
535 /// Build clause with number of variables \a N.
536 ///
537 /// \param StartLoc Starting location of the clause.
538 /// \param LParenLoc Location of '('.
539 /// \param Allocator Allocator expression.
540 /// \param ColonLoc Location of ':' delimiter.
541 /// \param EndLoc Ending location of the clause.
542 /// \param N Number of the variables in the clause.
543 OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
544 Expr *Allocator, Expr *Alignment, SourceLocation ColonLoc,
546 SourceLocation Modifier1Loc,
548 SourceLocation Modifier2Loc, SourceLocation EndLoc,
549 unsigned N)
550 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate, StartLoc,
551 LParenLoc, EndLoc, N),
552 Allocator(Allocator), Alignment(Alignment), ColonLoc(ColonLoc) {
553 Modifiers[FIRST] = Modifier1;
554 Modifiers[SECOND] = Modifier2;
555 ModifiersLoc[FIRST] = Modifier1Loc;
556 ModifiersLoc[SECOND] = Modifier2Loc;
557 }
558
559 /// Build an empty clause.
560 ///
561 /// \param N Number of variables.
562 explicit OMPAllocateClause(unsigned N)
563 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate,
564 SourceLocation(), SourceLocation(),
565 SourceLocation(), N) {
566 Modifiers[FIRST] = OMPC_ALLOCATE_unknown;
567 Modifiers[SECOND] = OMPC_ALLOCATE_unknown;
568 }
569
570 /// Sets location of ':' symbol in clause.
571 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
572
573 void setAllocator(Expr *A) { Allocator = A; }
574 void setAllocatorModifier(OpenMPAllocateClauseModifier AM) {
575 AllocatorModifier = AM;
576 }
577 void setAlignment(Expr *A) { Alignment = A; }
578
579public:
580 /// Creates clause with a list of variables \a VL.
581 ///
582 /// \param C AST context.
583 /// \param StartLoc Starting location of the clause.
584 /// \param LParenLoc Location of '('.
585 /// \param Allocator Allocator expression.
586 /// \param ColonLoc Location of ':' delimiter.
587 /// \param AllocatorModifier Allocator modifier.
588 /// \param SourceLocation Allocator modifier location.
589 /// \param EndLoc Ending location of the clause.
590 /// \param VL List of references to the variables.
591 static OMPAllocateClause *
592 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
593 Expr *Allocator, Expr *Alignment, SourceLocation ColonLoc,
594 OpenMPAllocateClauseModifier Modifier1, SourceLocation Modifier1Loc,
595 OpenMPAllocateClauseModifier Modifier2, SourceLocation Modifier2Loc,
596 SourceLocation EndLoc, ArrayRef<Expr *> VL);
597
598 /// Returns the allocator expression or nullptr, if no allocator is specified.
599 Expr *getAllocator() const { return Allocator; }
600
601 /// Returns the alignment expression or nullptr, if no alignment specified.
602 Expr *getAlignment() const { return Alignment; }
603
604 /// Return 'allocate' modifier.
606 return AllocatorModifier;
607 }
608
609 /// Get the first modifier of the clause.
611 return Modifiers[FIRST];
612 }
613
614 /// Get location of first modifier of the clause.
616 return ModifiersLoc[FIRST];
617 }
618
619 /// Get the second modifier of the clause.
621 return Modifiers[SECOND];
622 }
623
624 /// Get location of second modifier of the clause.
626 return ModifiersLoc[SECOND];
627 }
628
629 /// Returns the location of the ':' delimiter.
630 SourceLocation getColonLoc() const { return ColonLoc; }
631 /// Return the location of the modifier.
633 return AllocatorModifierLoc;
634 }
635
636 /// Creates an empty clause with the place for \a N variables.
637 ///
638 /// \param C AST context.
639 /// \param N The number of variables.
640 static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
641
643 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
644 reinterpret_cast<Stmt **>(varlist_end()));
645 }
646
648 return const_cast<OMPAllocateClause *>(this)->children();
649 }
650
657
658 static bool classof(const OMPClause *T) {
659 return T->getClauseKind() == llvm::omp::OMPC_allocate;
660 }
661};
662
663/// This represents 'if' clause in the '#pragma omp ...' directive.
664///
665/// \code
666/// #pragma omp parallel if(parallel:a > 5)
667/// \endcode
668/// In this example directive '#pragma omp parallel' has simple 'if' clause with
669/// condition 'a > 5' and directive name modifier 'parallel'.
671 friend class OMPClauseReader;
672
673 /// Location of '('.
674 SourceLocation LParenLoc;
675
676 /// Condition of the 'if' clause.
677 Stmt *Condition = nullptr;
678
679 /// Location of ':' (if any).
680 SourceLocation ColonLoc;
681
682 /// Directive name modifier for the clause.
683 OpenMPDirectiveKind NameModifier = llvm::omp::OMPD_unknown;
684
685 /// Name modifier location.
686 SourceLocation NameModifierLoc;
687
688 /// Set condition.
689 void setCondition(Expr *Cond) { Condition = Cond; }
690
691 /// Set directive name modifier for the clause.
692 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
693
694 /// Set location of directive name modifier for the clause.
695 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
696
697 /// Set location of ':'.
698 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
699
700public:
701 /// Build 'if' clause with condition \a Cond.
702 ///
703 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
704 /// \param Cond Condition of the clause.
705 /// \param HelperCond Helper condition for the clause.
706 /// \param CaptureRegion Innermost OpenMP region where expressions in this
707 /// clause must be captured.
708 /// \param StartLoc Starting location of the clause.
709 /// \param LParenLoc Location of '('.
710 /// \param NameModifierLoc Location of directive name modifier.
711 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
712 /// \param EndLoc Ending location of the clause.
713 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
714 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
715 SourceLocation LParenLoc, SourceLocation NameModifierLoc,
716 SourceLocation ColonLoc, SourceLocation EndLoc)
717 : OMPClause(llvm::omp::OMPC_if, StartLoc, EndLoc),
718 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond),
719 ColonLoc(ColonLoc), NameModifier(NameModifier),
720 NameModifierLoc(NameModifierLoc) {
721 setPreInitStmt(HelperCond, CaptureRegion);
722 }
723
724 /// Build an empty clause.
728
729 /// Sets the location of '('.
730 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
731
732 /// Returns the location of '('.
733 SourceLocation getLParenLoc() const { return LParenLoc; }
734
735 /// Return the location of ':'.
736 SourceLocation getColonLoc() const { return ColonLoc; }
737
738 /// Returns condition.
739 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
740
741 /// Return directive name modifier associated with the clause.
742 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
743
744 /// Return the location of directive name modifier.
745 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
746
747 child_range children() { return child_range(&Condition, &Condition + 1); }
748
750 return const_child_range(&Condition, &Condition + 1);
751 }
752
755 return const_cast<OMPIfClause *>(this)->used_children();
756 }
757
758 static bool classof(const OMPClause *T) {
759 return T->getClauseKind() == llvm::omp::OMPC_if;
760 }
761};
762
763/// This represents 'final' clause in the '#pragma omp ...' directive.
764///
765/// \code
766/// #pragma omp task final(a > 5)
767/// \endcode
768/// In this example directive '#pragma omp task' has simple 'final'
769/// clause with condition 'a > 5'.
770class OMPFinalClause final
771 : public OMPOneStmtClause<llvm::omp::OMPC_final, OMPClause>,
772 public OMPClauseWithPreInit {
773 friend class OMPClauseReader;
774
775 /// Set condition.
776 void setCondition(Expr *Cond) { setStmt(Cond); }
777
778public:
779 /// Build 'final' clause with condition \a Cond.
780 ///
781 /// \param Cond Condition of the clause.
782 /// \param HelperCond Helper condition for the construct.
783 /// \param CaptureRegion Innermost OpenMP region where expressions in this
784 /// clause must be captured.
785 /// \param StartLoc Starting location of the clause.
786 /// \param LParenLoc Location of '('.
787 /// \param EndLoc Ending location of the clause.
789 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
790 SourceLocation LParenLoc, SourceLocation EndLoc)
791 : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc),
793 setPreInitStmt(HelperCond, CaptureRegion);
794 }
795
796 /// Build an empty clause.
798
799 /// Returns condition.
800 Expr *getCondition() const { return getStmtAs<Expr>(); }
801
804 return const_cast<OMPFinalClause *>(this)->used_children();
805 }
806};
807/// This represents 'num_threads' clause in the '#pragma omp ...'
808/// directive.
809///
810/// \code
811/// #pragma omp parallel num_threads(6)
812/// \endcode
813/// In this example directive '#pragma omp parallel' has simple 'num_threads'
814/// clause with number of threads '6'.
816 : public OMPOneStmtClause<llvm::omp::OMPC_num_threads, OMPClause>,
817 public OMPClauseWithPreInit {
818 friend class OMPClauseReader;
819
820 /// Modifiers for 'num_threads' clause.
822
823 /// Location of the modifier.
824 SourceLocation ModifierLoc;
825
826 /// Sets modifier.
827 void setModifier(OpenMPNumThreadsClauseModifier M) { Modifier = M; }
828
829 /// Sets modifier location.
830 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
831
832 /// Set condition.
833 void setNumThreads(Expr *NThreads) { setStmt(NThreads); }
834
835public:
836 /// Build 'num_threads' clause with condition \a NumThreads.
837 ///
838 /// \param Modifier Clause modifier.
839 /// \param NumThreads Number of threads for the construct.
840 /// \param HelperNumThreads Helper Number of threads for the construct.
841 /// \param CaptureRegion Innermost OpenMP region where expressions in this
842 /// clause must be captured.
843 /// \param StartLoc Starting location of the clause.
844 /// \param LParenLoc Location of '('.
845 /// \param ModifierLoc Modifier location.
846 /// \param EndLoc Ending location of the clause.
848 Stmt *HelperNumThreads, OpenMPDirectiveKind CaptureRegion,
849 SourceLocation StartLoc, SourceLocation LParenLoc,
850 SourceLocation ModifierLoc, SourceLocation EndLoc)
851 : OMPOneStmtClause(NumThreads, StartLoc, LParenLoc, EndLoc),
852 OMPClauseWithPreInit(this), Modifier(Modifier),
853 ModifierLoc(ModifierLoc) {
854 setPreInitStmt(HelperNumThreads, CaptureRegion);
855 }
856
857 /// Build an empty clause.
859
860 /// Gets modifier.
861 OpenMPNumThreadsClauseModifier getModifier() const { return Modifier; }
862
863 /// Gets modifier location.
864 SourceLocation getModifierLoc() const { return ModifierLoc; }
865
866 /// Returns number of threads.
867 Expr *getNumThreads() const { return getStmtAs<Expr>(); }
868};
869
870/// This represents 'safelen' clause in the '#pragma omp ...'
871/// directive.
872///
873/// \code
874/// #pragma omp simd safelen(4)
875/// \endcode
876/// In this example directive '#pragma omp simd' has clause 'safelen'
877/// with single expression '4'.
878/// If the safelen clause is used then no two iterations executed
879/// concurrently with SIMD instructions can have a greater distance
880/// in the logical iteration space than its value. The parameter of
881/// the safelen clause must be a constant positive integer expression.
883 : public OMPOneStmtClause<llvm::omp::OMPC_safelen, OMPClause> {
884 friend class OMPClauseReader;
885
886 /// Set safelen.
887 void setSafelen(Expr *Len) { setStmt(Len); }
888
889public:
890 /// Build 'safelen' clause.
891 ///
892 /// \param Len Expression associated with this clause.
893 /// \param StartLoc Starting location of the clause.
894 /// \param EndLoc Ending location of the clause.
896 SourceLocation EndLoc)
897 : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {}
898
899 /// Build an empty clause.
901
902 /// Return safe iteration space distance.
903 Expr *getSafelen() const { return getStmtAs<Expr>(); }
904};
905
906/// This represents 'simdlen' clause in the '#pragma omp ...'
907/// directive.
908///
909/// \code
910/// #pragma omp simd simdlen(4)
911/// \endcode
912/// In this example directive '#pragma omp simd' has clause 'simdlen'
913/// with single expression '4'.
914/// If the 'simdlen' clause is used then it specifies the preferred number of
915/// iterations to be executed concurrently. The parameter of the 'simdlen'
916/// clause must be a constant positive integer expression.
918 : public OMPOneStmtClause<llvm::omp::OMPC_simdlen, OMPClause> {
919 friend class OMPClauseReader;
920
921 /// Set simdlen.
922 void setSimdlen(Expr *Len) { setStmt(Len); }
923
924public:
925 /// Build 'simdlen' clause.
926 ///
927 /// \param Len Expression associated with this clause.
928 /// \param StartLoc Starting location of the clause.
929 /// \param EndLoc Ending location of the clause.
931 SourceLocation EndLoc)
932 : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {}
933
934 /// Build an empty clause.
936
937 /// Return safe iteration space distance.
938 Expr *getSimdlen() const { return getStmtAs<Expr>(); }
939};
940
941/// This represents the 'sizes' clause in the '#pragma omp tile' directive.
942///
943/// \code
944/// #pragma omp tile sizes(5,5)
945/// for (int i = 0; i < 64; ++i)
946/// for (int j = 0; j < 64; ++j)
947/// \endcode
948class OMPSizesClause final
949 : public OMPClause,
950 private llvm::TrailingObjects<OMPSizesClause, Expr *> {
951 friend class OMPClauseReader;
952 friend class llvm::TrailingObjects<OMPSizesClause, Expr *>;
953
954 /// Location of '('.
955 SourceLocation LParenLoc;
956
957 /// Number of tile sizes in the clause.
958 unsigned NumSizes;
959
960 /// Build an empty clause.
961 explicit OMPSizesClause(int NumSizes)
962 : OMPClause(llvm::omp::OMPC_sizes, SourceLocation(), SourceLocation()),
963 NumSizes(NumSizes) {}
964
965public:
966 /// Build a 'sizes' AST node.
967 ///
968 /// \param C Context of the AST.
969 /// \param StartLoc Location of the 'sizes' identifier.
970 /// \param LParenLoc Location of '('.
971 /// \param EndLoc Location of ')'.
972 /// \param Sizes Content of the clause.
973 static OMPSizesClause *Create(const ASTContext &C, SourceLocation StartLoc,
974 SourceLocation LParenLoc, SourceLocation EndLoc,
975 ArrayRef<Expr *> Sizes);
976
977 /// Build an empty 'sizes' AST node for deserialization.
978 ///
979 /// \param C Context of the AST.
980 /// \param NumSizes Number of items in the clause.
981 static OMPSizesClause *CreateEmpty(const ASTContext &C, unsigned NumSizes);
982
983 /// Sets the location of '('.
984 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
985
986 /// Returns the location of '('.
987 SourceLocation getLParenLoc() const { return LParenLoc; }
988
989 /// Returns the number of list items.
990 unsigned getNumSizes() const { return NumSizes; }
991
992 /// Returns the tile size expressions.
994 return getTrailingObjects(NumSizes);
995 }
996 ArrayRef<Expr *> getSizesRefs() const { return getTrailingObjects(NumSizes); }
997
998 /// Sets the tile size expressions.
1000 assert(VL.size() == NumSizes);
1001 llvm::copy(VL, getSizesRefs().begin());
1002 }
1003
1006 return child_range(reinterpret_cast<Stmt **>(Sizes.begin()),
1007 reinterpret_cast<Stmt **>(Sizes.end()));
1008 }
1011 return const_child_range(reinterpret_cast<Stmt *const *>(Sizes.begin()),
1012 reinterpret_cast<Stmt *const *>(Sizes.end()));
1013 }
1014
1021
1022 static bool classof(const OMPClause *T) {
1023 return T->getClauseKind() == llvm::omp::OMPC_sizes;
1024 }
1025};
1026
1027/// This represents the 'counts' clause in the '#pragma omp split' directive.
1028///
1029/// \code
1030/// #pragma omp split counts(3, omp_fill, 2)
1031/// for (int i = 0; i < n; ++i) { ... }
1032/// \endcode
1033class OMPCountsClause final
1034 : public OMPClause,
1035 private llvm::TrailingObjects<OMPCountsClause, Expr *> {
1036 friend class OMPClauseReader;
1037 friend class llvm::TrailingObjects<OMPCountsClause, Expr *>;
1038
1039 /// Location of '('.
1040 SourceLocation LParenLoc;
1041
1042 /// Number of count expressions in the clause.
1043 unsigned NumCounts = 0;
1044
1045 /// 0-based index of the omp_fill list item.
1046 std::optional<unsigned> OmpFillIndex;
1047
1048 /// Source location of the omp_fill keyword.
1049 SourceLocation OmpFillLoc;
1050
1051 /// Build an empty clause.
1052 explicit OMPCountsClause(int NumCounts)
1053 : OMPClause(llvm::omp::OMPC_counts, SourceLocation(), SourceLocation()),
1054 NumCounts(NumCounts) {}
1055
1056 /// Sets the location of '('.
1057 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1058 void setOmpFillIndex(std::optional<unsigned> Idx) { OmpFillIndex = Idx; }
1059 void setOmpFillLoc(SourceLocation Loc) { OmpFillLoc = Loc; }
1060
1061 /// Sets the count expressions.
1062 void setCountsRefs(ArrayRef<Expr *> VL) {
1063 assert(VL.size() == NumCounts);
1064 llvm::copy(VL, getCountsRefs().begin());
1065 }
1066
1067public:
1068 /// Build a 'counts' AST node.
1069 ///
1070 /// \param C Context of the AST.
1071 /// \param StartLoc Location of the 'counts' identifier.
1072 /// \param LParenLoc Location of '('.
1073 /// \param EndLoc Location of ')'.
1074 /// \param Counts Content of the clause.
1075 static OMPCountsClause *Create(const ASTContext &C, SourceLocation StartLoc,
1076 SourceLocation LParenLoc,
1077 SourceLocation EndLoc, ArrayRef<Expr *> Counts,
1078 std::optional<unsigned> FillIdx,
1079 SourceLocation FillLoc);
1080
1081 /// Build an empty 'counts' AST node for deserialization.
1082 ///
1083 /// \param C Context of the AST.
1084 /// \param NumCounts Number of items in the clause.
1085 static OMPCountsClause *CreateEmpty(const ASTContext &C, unsigned NumCounts);
1086
1087 /// Returns the location of '('.
1088 SourceLocation getLParenLoc() const { return LParenLoc; }
1089
1090 /// Returns the number of list items.
1091 unsigned getNumCounts() const { return NumCounts; }
1092
1093 std::optional<unsigned> getOmpFillIndex() const { return OmpFillIndex; }
1094 SourceLocation getOmpFillLoc() const { return OmpFillLoc; }
1095 bool hasOmpFill() const { return OmpFillIndex.has_value(); }
1096
1097 /// Returns the count expressions.
1099 return getTrailingObjects(NumCounts);
1100 }
1102 return getTrailingObjects(NumCounts);
1103 }
1104
1107 return child_range(reinterpret_cast<Stmt **>(Counts.begin()),
1108 reinterpret_cast<Stmt **>(Counts.end()));
1109 }
1112 return const_child_range(reinterpret_cast<Stmt *const *>(Counts.begin()),
1113 reinterpret_cast<Stmt *const *>(Counts.end()));
1114 }
1121
1122 static bool classof(const OMPClause *T) {
1123 return T->getClauseKind() == llvm::omp::OMPC_counts;
1124 }
1125};
1126
1127/// This class represents the 'permutation' clause in the
1128/// '#pragma omp interchange' directive.
1129///
1130/// \code{.c}
1131/// #pragma omp interchange permutation(2,1)
1132/// for (int i = 0; i < 64; ++i)
1133/// for (int j = 0; j < 64; ++j)
1134/// \endcode
1135class OMPPermutationClause final
1136 : public OMPClause,
1137 private llvm::TrailingObjects<OMPSizesClause, Expr *> {
1138 friend class OMPClauseReader;
1139 friend class llvm::TrailingObjects<OMPSizesClause, Expr *>;
1140
1141 /// Location of '('.
1142 SourceLocation LParenLoc;
1143
1144 /// Number of arguments in the clause, and hence also the number of loops to
1145 /// be permuted.
1146 unsigned NumLoops;
1147
1148 /// Sets the permutation index expressions.
1149 void setArgRefs(ArrayRef<Expr *> VL) {
1150 assert(VL.size() == NumLoops && "Expecting one expression per loop");
1151 llvm::copy(VL, getTrailingObjects());
1152 }
1153
1154 /// Build an empty clause.
1155 explicit OMPPermutationClause(int NumLoops)
1156 : OMPClause(llvm::omp::OMPC_permutation, SourceLocation(),
1157 SourceLocation()),
1158 NumLoops(NumLoops) {}
1159
1160public:
1161 /// Build a 'permutation' clause AST node.
1162 ///
1163 /// \param C Context of the AST.
1164 /// \param StartLoc Location of the 'permutation' identifier.
1165 /// \param LParenLoc Location of '('.
1166 /// \param EndLoc Location of ')'.
1167 /// \param Args Content of the clause.
1168 static OMPPermutationClause *
1169 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1170 SourceLocation EndLoc, ArrayRef<Expr *> Args);
1171
1172 /// Build an empty 'permutation' AST node for deserialization.
1173 ///
1174 /// \param C Context of the AST.
1175 /// \param NumLoops Number of arguments in the clause.
1176 static OMPPermutationClause *CreateEmpty(const ASTContext &C,
1177 unsigned NumLoops);
1178
1179 /// Sets the location of '('.
1180 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1181
1182 /// Returns the location of '('.
1183 SourceLocation getLParenLoc() const { return LParenLoc; }
1184
1185 /// Returns the number of list items.
1186 unsigned getNumLoops() const { return NumLoops; }
1187
1188 /// Returns the permutation index expressions.
1189 ///@{
1190 MutableArrayRef<Expr *> getArgsRefs() { return getTrailingObjects(NumLoops); }
1191 ArrayRef<Expr *> getArgsRefs() const { return getTrailingObjects(NumLoops); }
1192 ///@}
1193
1196 return child_range(reinterpret_cast<Stmt **>(Args.begin()),
1197 reinterpret_cast<Stmt **>(Args.end()));
1198 }
1201 return const_child_range(reinterpret_cast<Stmt *const *>(Args.begin()),
1202 reinterpret_cast<Stmt *const *>(Args.end()));
1203 }
1204
1211
1212 static bool classof(const OMPClause *T) {
1213 return T->getClauseKind() == llvm::omp::OMPC_permutation;
1214 }
1215};
1216
1217/// Representation of the 'full' clause of the '#pragma omp unroll' directive.
1218///
1219/// \code
1220/// #pragma omp unroll full
1221/// for (int i = 0; i < 64; ++i)
1222/// \endcode
1223class OMPFullClause final : public OMPNoChildClause<llvm::omp::OMPC_full> {
1224 friend class OMPClauseReader;
1225
1226 /// Build an empty clause.
1227 explicit OMPFullClause() : OMPNoChildClause() {}
1228
1229public:
1230 /// Build an AST node for a 'full' clause.
1231 ///
1232 /// \param C Context of the AST.
1233 /// \param StartLoc Starting location of the clause.
1234 /// \param EndLoc Ending location of the clause.
1235 static OMPFullClause *Create(const ASTContext &C, SourceLocation StartLoc,
1236 SourceLocation EndLoc);
1237
1238 /// Build an empty 'full' AST node for deserialization.
1239 ///
1240 /// \param C Context of the AST.
1241 static OMPFullClause *CreateEmpty(const ASTContext &C);
1242};
1243
1244/// This class represents the 'looprange' clause in the
1245/// '#pragma omp fuse' directive
1246///
1247/// \code {c}
1248/// #pragma omp fuse looprange(1,2)
1249/// {
1250/// for(int i = 0; i < 64; ++i)
1251/// for(int j = 0; j < 256; j+=2)
1252/// for(int k = 127; k >= 0; --k)
1253/// \endcode
1254class OMPLoopRangeClause final : public OMPClause {
1255 friend class OMPClauseReader;
1256 /// Location of '('
1257 SourceLocation LParenLoc;
1258
1259 /// Location of first and count expressions
1260 SourceLocation FirstLoc, CountLoc;
1261
1262 /// Number of looprange arguments (always 2: first, count)
1263 enum { FirstExpr, CountExpr, NumArgs };
1264 Stmt *Args[NumArgs] = {nullptr, nullptr};
1265
1266 /// Set looprange 'first' expression
1267 void setFirst(Expr *E) { Args[FirstExpr] = E; }
1268
1269 /// Set looprange 'count' expression
1270 void setCount(Expr *E) { Args[CountExpr] = E; }
1271
1272 /// Build an empty clause for deserialization.
1273 explicit OMPLoopRangeClause()
1274 : OMPClause(llvm::omp::OMPC_looprange, {}, {}) {}
1275
1276public:
1277 /// Build a 'looprange' clause AST node.
1278 static OMPLoopRangeClause *
1279 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1280 SourceLocation FirstLoc, SourceLocation CountLoc,
1281 SourceLocation EndLoc, Expr *First, Expr *Count);
1282
1283 /// Build an empty 'looprange' clause node.
1284 static OMPLoopRangeClause *CreateEmpty(const ASTContext &C);
1285
1286 // Location getters/setters
1287 SourceLocation getLParenLoc() const { return LParenLoc; }
1288 SourceLocation getFirstLoc() const { return FirstLoc; }
1289 SourceLocation getCountLoc() const { return CountLoc; }
1290
1291 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1292 void setFirstLoc(SourceLocation Loc) { FirstLoc = Loc; }
1293 void setCountLoc(SourceLocation Loc) { CountLoc = Loc; }
1294
1295 /// Get looprange 'first' expression
1296 Expr *getFirst() const { return cast_or_null<Expr>(Args[FirstExpr]); }
1297
1298 /// Get looprange 'count' expression
1299 Expr *getCount() const { return cast_or_null<Expr>(Args[CountExpr]); }
1300
1301 child_range children() { return child_range(Args, Args + NumArgs); }
1303 return const_child_range(Args, Args + NumArgs);
1304 }
1305
1312
1313 static bool classof(const OMPClause *T) {
1314 return T->getClauseKind() == llvm::omp::OMPC_looprange;
1315 }
1316};
1317
1318/// Representation of the 'partial' clause of the '#pragma omp unroll'
1319/// directive.
1320///
1321/// \code
1322/// #pragma omp unroll partial(4)
1323/// for (int i = start; i < end; ++i)
1324/// \endcode
1325class OMPPartialClause final : public OMPClause {
1326 friend class OMPClauseReader;
1327
1328 /// Location of '('.
1329 SourceLocation LParenLoc;
1330
1331 /// Optional argument to the clause (unroll factor).
1332 Stmt *Factor;
1333
1334 /// Build an empty clause.
1335 explicit OMPPartialClause() : OMPClause(llvm::omp::OMPC_partial, {}, {}) {}
1336
1337 /// Set the unroll factor.
1338 void setFactor(Expr *E) { Factor = E; }
1339
1340 /// Sets the location of '('.
1341 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1342
1343public:
1344 /// Build an AST node for a 'partial' clause.
1345 ///
1346 /// \param C Context of the AST.
1347 /// \param StartLoc Location of the 'partial' identifier.
1348 /// \param LParenLoc Location of '('.
1349 /// \param EndLoc Location of ')'.
1350 /// \param Factor Clause argument.
1351 static OMPPartialClause *Create(const ASTContext &C, SourceLocation StartLoc,
1352 SourceLocation LParenLoc,
1353 SourceLocation EndLoc, Expr *Factor);
1354
1355 /// Build an empty 'partial' AST node for deserialization.
1356 ///
1357 /// \param C Context of the AST.
1358 static OMPPartialClause *CreateEmpty(const ASTContext &C);
1359
1360 /// Returns the location of '('.
1361 SourceLocation getLParenLoc() const { return LParenLoc; }
1362
1363 /// Returns the argument of the clause or nullptr if not set.
1364 Expr *getFactor() const { return cast_or_null<Expr>(Factor); }
1365
1366 child_range children() { return child_range(&Factor, &Factor + 1); }
1368 return const_child_range(&Factor, &Factor + 1);
1369 }
1370
1377
1378 static bool classof(const OMPClause *T) {
1379 return T->getClauseKind() == llvm::omp::OMPC_partial;
1380 }
1381};
1382
1383/// This represents 'collapse' clause in the '#pragma omp ...'
1384/// directive.
1385///
1386/// \code
1387/// #pragma omp simd collapse(3)
1388/// \endcode
1389/// In this example directive '#pragma omp simd' has clause 'collapse'
1390/// with single expression '3'.
1391/// The parameter must be a constant positive integer expression, it specifies
1392/// the number of nested loops that should be collapsed into a single iteration
1393/// space.
1395 : public OMPOneStmtClause<llvm::omp::OMPC_collapse, OMPClause> {
1396 friend class OMPClauseReader;
1397
1398 /// Set the number of associated for-loops.
1399 void setNumForLoops(Expr *Num) { setStmt(Num); }
1400
1401public:
1402 /// Build 'collapse' clause.
1403 ///
1404 /// \param Num Expression associated with this clause.
1405 /// \param StartLoc Starting location of the clause.
1406 /// \param LParenLoc Location of '('.
1407 /// \param EndLoc Ending location of the clause.
1409 SourceLocation LParenLoc, SourceLocation EndLoc)
1410 : OMPOneStmtClause(Num, StartLoc, LParenLoc, EndLoc) {}
1411
1412 /// Build an empty clause.
1414
1415 /// Return the number of associated for-loops.
1416 Expr *getNumForLoops() const { return getStmtAs<Expr>(); }
1417};
1418
1419/// This represents 'default' clause in the '#pragma omp ...' directive.
1420///
1421/// \code
1422/// #pragma omp parallel default(shared)
1423/// \endcode
1424/// In this example directive '#pragma omp parallel' has simple 'default'
1425/// clause with kind 'shared'.
1427 friend class OMPClauseReader;
1428
1429 /// Location of '('.
1430 SourceLocation LParenLoc;
1431
1432 /// A kind of the 'default' clause.
1433 llvm::omp::DefaultKind Kind = llvm::omp::OMP_DEFAULT_unknown;
1434
1435 /// Start location of the kind in source code.
1436 SourceLocation KindKwLoc;
1437
1438 /// Variable-Category to indicate where Kind is applied
1439 OpenMPDefaultClauseVariableCategory VC = OMPC_DEFAULT_VC_all;
1440
1441 /// Start location of Variable-Category
1442 SourceLocation VCLoc;
1443
1444 /// Set kind of the clauses.
1445 ///
1446 /// \param K Argument of clause.
1447 void setDefaultKind(llvm::omp::DefaultKind K) { Kind = K; }
1448
1449 /// Set argument location.
1450 ///
1451 /// \param KLoc Argument location.
1452 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1453
1454 /// Set Variable Category used with the Kind Clause (Default Modifier)
1455 void setDefaultVariableCategory(OpenMPDefaultClauseVariableCategory VC) {
1456 this->VC = VC;
1457 }
1458
1459 void setDefaultVariableCategoryLocation(SourceLocation VCLoc) {
1460 this->VCLoc = VCLoc;
1461 }
1462
1463public:
1464 /// Build 'default' clause with argument \a A ('none' or 'shared').
1465 ///
1466 /// \param A Argument of the clause ('none' or 'shared').
1467 /// \param ALoc Starting location of the argument.
1468 /// \param StartLoc Starting location of the clause.
1469 /// \param LParenLoc Location of '('.
1470 /// \param EndLoc Ending location of the clause.
1471 OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc,
1473 SourceLocation StartLoc, SourceLocation LParenLoc,
1474 SourceLocation EndLoc)
1475 : OMPClause(llvm::omp::OMPC_default, StartLoc, EndLoc),
1476 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc), VC(VC), VCLoc(VCLoc) {}
1477
1478 /// Build an empty clause.
1480 : OMPClause(llvm::omp::OMPC_default, SourceLocation(), SourceLocation()) {
1481 }
1482
1483 /// Sets the location of '('.
1484 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1485
1486 /// Returns the location of '('.
1487 SourceLocation getLParenLoc() const { return LParenLoc; }
1488
1489 /// Returns kind of the clause.
1490 llvm::omp::DefaultKind getDefaultKind() const { return Kind; }
1491
1492 /// Returns location of clause kind.
1493 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
1494
1496
1497 SourceLocation getDefaultVCLoc() const { return VCLoc; }
1498
1502
1506
1513
1514 static bool classof(const OMPClause *T) {
1515 return T->getClauseKind() == llvm::omp::OMPC_default;
1516 }
1517};
1518
1519/// This represents 'threadset' clause in the '#pragma omp task ...' directive.
1520///
1521/// \code
1522/// #pragma omp task threadset(omp_pool)
1523/// \endcode
1524/// In this example directive '#pragma omp task' has simple 'threadset'
1525/// clause with kind 'omp_pool'.
1526class OMPThreadsetClause final : public OMPClause {
1527 friend class OMPClauseReader;
1528
1529 /// Location of '('.
1530 SourceLocation LParenLoc;
1531
1532 /// A kind of the 'threadset' clause.
1534
1535 /// Start location of the kind in source code.
1536 SourceLocation KindLoc;
1537
1538 /// Set kind of the clauses.
1539 ///
1540 /// \param K Argument of clause.
1541 void setThreadsetKind(OpenMPThreadsetKind K) { Kind = K; }
1542
1543 /// Set argument location.
1544 ///
1545 /// \param KLoc Argument location.
1546 void setThreadsetKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1547
1548public:
1549 /// Build 'threadset' clause with argument \a A ('omp_team' or 'omp_pool').
1550 ///
1551 /// \param A Argument of the clause ('omp_team' or 'omp_pool').
1552 /// \param ALoc Starting location of the argument.
1553 /// \param StartLoc Starting location of the clause.
1554 /// \param LParenLoc Location of '('.
1555 /// \param EndLoc Ending location of the clause.
1557 SourceLocation StartLoc, SourceLocation LParenLoc,
1558 SourceLocation EndLoc)
1559 : OMPClause(llvm::omp::OMPC_threadset, StartLoc, EndLoc),
1560 LParenLoc(LParenLoc), Kind(A), KindLoc(ALoc) {}
1561
1562 /// Build an empty clause.
1564 : OMPClause(llvm::omp::OMPC_threadset, SourceLocation(),
1565 SourceLocation()) {}
1566
1567 /// Sets the location of '('.
1568 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1569
1570 /// Returns the location of '('.
1571 SourceLocation getLParenLoc() const { return LParenLoc; }
1572
1573 /// Returns kind of the clause.
1574 OpenMPThreadsetKind getThreadsetKind() const { return Kind; }
1575
1576 /// Returns location of clause kind.
1577 SourceLocation getThreadsetKindLoc() const { return KindLoc; }
1578
1582
1586
1593
1594 static bool classof(const OMPClause *T) {
1595 return T->getClauseKind() == llvm::omp::OMPC_threadset;
1596 }
1597};
1598
1599/// This class represents the 'transparent' clause in the '#pragma omp task'
1600/// directive.
1601///
1602/// \code
1603/// #pragma omp task transparent(omp_not_impex)
1604/// \endcode
1605///
1606/// In this example, the directive '#pragma omp task' has a 'transparent'
1607/// clause with OpenMP keyword 'omp_not_impex`. Other valid keywords that may
1608/// appear in this clause are 'omp_import', 'omp_export' and 'omp_impex'.
1609///
1610class OMPTransparentClause final
1611 : public OMPOneStmtClause<llvm::omp::OMPC_transparent, OMPClause>,
1612 public OMPClauseWithPreInit {
1613 friend class OMPClauseReader;
1614
1615 /// Location of '('.
1616 SourceLocation LParenLoc;
1617
1618 /// Argument of the 'transparent' clause.
1619 Expr *ImpexType = nullptr;
1620
1621 /// Sets the location of '('.
1622 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1623
1624 void setImpexTypeKind(Expr *E) { ImpexType = E; }
1625
1626public:
1627 /// Build 'transparent' clause with argument \a A ('omp_not_impex',
1628 /// 'omp_import', 'omp_export' or 'omp_impex')
1629 ///
1630 /// \param A Argument of the clause ('omp_not_impex', 'omp_import',
1631 /// 'omp_export' or 'omp_impex')
1632 /// \param ALoc Starting location of the argument.
1633 /// \param StartLoc Starting location of the clause.
1634 /// \param LParenLoc Location of '('.
1635 /// \param EndLoc Ending location of the clause.
1636 OMPTransparentClause(Expr *ImpexTypeKind, Stmt *HelperValStmt,
1637 OpenMPDirectiveKind CaptureRegion,
1638 SourceLocation StartLoc, SourceLocation LParenLoc,
1639 SourceLocation EndLoc)
1640 : OMPOneStmtClause(ImpexTypeKind, StartLoc, LParenLoc, EndLoc),
1641 OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
1642 ImpexType(ImpexTypeKind) {
1643 setPreInitStmt(HelperValStmt, CaptureRegion);
1644 }
1645
1646 /// Build an empty clause.
1647 OMPTransparentClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {}
1648
1649 /// Returns the location of '('.
1650 SourceLocation getLParenLoc() const { return LParenLoc; }
1651
1652 /// Returns argument of the clause.
1653 Expr *getImpexType() const { return ImpexType; }
1654
1655 child_range children() {
1656 return child_range(reinterpret_cast<Stmt **>(&ImpexType),
1657 reinterpret_cast<Stmt **>(&ImpexType) + 1);
1658 }
1659
1660 const_child_range children() const {
1661 return const_cast<OMPTransparentClause *>(this)->children();
1662 }
1663
1664 child_range used_children() {
1665 return child_range(child_iterator(), child_iterator());
1666 }
1667 const_child_range used_children() const {
1668 return const_child_range(const_child_iterator(), const_child_iterator());
1669 }
1670
1671 static bool classof(const OMPClause *T) {
1672 return T->getClauseKind() == llvm::omp::OMPC_transparent;
1673 }
1674};
1675
1676/// This represents 'proc_bind' clause in the '#pragma omp ...'
1677/// directive.
1678///
1679/// \code
1680/// #pragma omp parallel proc_bind(master)
1681/// \endcode
1682/// In this example directive '#pragma omp parallel' has simple 'proc_bind'
1683/// clause with kind 'master'.
1684class OMPProcBindClause : public OMPClause {
1685 friend class OMPClauseReader;
1686
1687 /// Location of '('.
1688 SourceLocation LParenLoc;
1689
1690 /// A kind of the 'proc_bind' clause.
1691 llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown;
1692
1693 /// Start location of the kind in source code.
1694 SourceLocation KindKwLoc;
1695
1696 /// Set kind of the clause.
1697 ///
1698 /// \param K Kind of clause.
1699 void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; }
1700
1701 /// Set clause kind location.
1702 ///
1703 /// \param KLoc Kind location.
1704 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1705
1706public:
1707 /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
1708 /// 'spread').
1709 ///
1710 /// \param A Argument of the clause ('master', 'close' or 'spread').
1711 /// \param ALoc Starting location of the argument.
1712 /// \param StartLoc Starting location of the clause.
1713 /// \param LParenLoc Location of '('.
1714 /// \param EndLoc Ending location of the clause.
1715 OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc,
1716 SourceLocation StartLoc, SourceLocation LParenLoc,
1717 SourceLocation EndLoc)
1718 : OMPClause(llvm::omp::OMPC_proc_bind, StartLoc, EndLoc),
1719 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1720
1721 /// Build an empty clause.
1722 OMPProcBindClause()
1723 : OMPClause(llvm::omp::OMPC_proc_bind, SourceLocation(),
1724 SourceLocation()) {}
1725
1726 /// Sets the location of '('.
1727 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1728
1729 /// Returns the location of '('.
1730 SourceLocation getLParenLoc() const { return LParenLoc; }
1731
1732 /// Returns kind of the clause.
1733 llvm::omp::ProcBindKind getProcBindKind() const { return Kind; }
1734
1735 /// Returns location of clause kind.
1736 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
1737
1738 child_range children() {
1739 return child_range(child_iterator(), child_iterator());
1740 }
1741
1742 const_child_range children() const {
1743 return const_child_range(const_child_iterator(), const_child_iterator());
1744 }
1745
1746 child_range used_children() {
1747 return child_range(child_iterator(), child_iterator());
1748 }
1749 const_child_range used_children() const {
1750 return const_child_range(const_child_iterator(), const_child_iterator());
1751 }
1752
1753 static bool classof(const OMPClause *T) {
1754 return T->getClauseKind() == llvm::omp::OMPC_proc_bind;
1755 }
1756};
1757
1758/// This represents 'unified_address' clause in the '#pragma omp requires'
1759/// directive.
1760///
1761/// \code
1762/// #pragma omp requires unified_address
1763/// \endcode
1764/// In this example directive '#pragma omp requires' has 'unified_address'
1765/// clause.
1766class OMPUnifiedAddressClause final
1767 : public OMPNoChildClause<llvm::omp::OMPC_unified_address> {
1768public:
1769 friend class OMPClauseReader;
1770 /// Build 'unified_address' clause.
1771 ///
1772 /// \param StartLoc Starting location of the clause.
1773 /// \param EndLoc Ending location of the clause.
1774 OMPUnifiedAddressClause(SourceLocation StartLoc, SourceLocation EndLoc)
1775 : OMPNoChildClause(StartLoc, EndLoc) {}
1776
1777 /// Build an empty clause.
1778 OMPUnifiedAddressClause() : OMPNoChildClause() {}
1779};
1780
1781/// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
1782/// directive.
1783///
1784/// \code
1785/// #pragma omp requires unified_shared_memory
1786/// \endcode
1787/// In this example directive '#pragma omp requires' has 'unified_shared_memory'
1788/// clause.
1789class OMPUnifiedSharedMemoryClause final : public OMPClause {
1790public:
1791 friend class OMPClauseReader;
1792 /// Build 'unified_shared_memory' clause.
1793 ///
1794 /// \param StartLoc Starting location of the clause.
1795 /// \param EndLoc Ending location of the clause.
1796 OMPUnifiedSharedMemoryClause(SourceLocation StartLoc, SourceLocation EndLoc)
1797 : OMPClause(llvm::omp::OMPC_unified_shared_memory, StartLoc, EndLoc) {}
1798
1799 /// Build an empty clause.
1800 OMPUnifiedSharedMemoryClause()
1801 : OMPClause(llvm::omp::OMPC_unified_shared_memory, SourceLocation(),
1802 SourceLocation()) {}
1803
1804 child_range children() {
1805 return child_range(child_iterator(), child_iterator());
1806 }
1807
1808 const_child_range children() const {
1809 return const_child_range(const_child_iterator(), const_child_iterator());
1810 }
1811
1812 child_range used_children() {
1813 return child_range(child_iterator(), child_iterator());
1814 }
1815 const_child_range used_children() const {
1816 return const_child_range(const_child_iterator(), const_child_iterator());
1817 }
1818
1819 static bool classof(const OMPClause *T) {
1820 return T->getClauseKind() == llvm::omp::OMPC_unified_shared_memory;
1821 }
1822};
1823
1824/// This represents 'reverse_offload' clause in the '#pragma omp requires'
1825/// directive.
1826///
1827/// \code
1828/// #pragma omp requires reverse_offload
1829/// \endcode
1830/// In this example directive '#pragma omp requires' has 'reverse_offload'
1831/// clause.
1832class OMPReverseOffloadClause final : public OMPClause {
1833public:
1834 friend class OMPClauseReader;
1835 /// Build 'reverse_offload' clause.
1836 ///
1837 /// \param StartLoc Starting location of the clause.
1838 /// \param EndLoc Ending location of the clause.
1839 OMPReverseOffloadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1840 : OMPClause(llvm::omp::OMPC_reverse_offload, StartLoc, EndLoc) {}
1841
1842 /// Build an empty clause.
1843 OMPReverseOffloadClause()
1844 : OMPClause(llvm::omp::OMPC_reverse_offload, SourceLocation(),
1845 SourceLocation()) {}
1846
1847 child_range children() {
1848 return child_range(child_iterator(), child_iterator());
1849 }
1850
1851 const_child_range children() const {
1852 return const_child_range(const_child_iterator(), const_child_iterator());
1853 }
1854
1855 child_range used_children() {
1856 return child_range(child_iterator(), child_iterator());
1857 }
1858 const_child_range used_children() const {
1859 return const_child_range(const_child_iterator(), const_child_iterator());
1860 }
1861
1862 static bool classof(const OMPClause *T) {
1863 return T->getClauseKind() == llvm::omp::OMPC_reverse_offload;
1864 }
1865};
1866
1867/// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
1868/// directive.
1869///
1870/// \code
1871/// #pragma omp requires dynamic_allocators
1872/// \endcode
1873/// In this example directive '#pragma omp requires' has 'dynamic_allocators'
1874/// clause.
1875class OMPDynamicAllocatorsClause final : public OMPClause {
1876public:
1877 friend class OMPClauseReader;
1878 /// Build 'dynamic_allocators' clause.
1879 ///
1880 /// \param StartLoc Starting location of the clause.
1881 /// \param EndLoc Ending location of the clause.
1882 OMPDynamicAllocatorsClause(SourceLocation StartLoc, SourceLocation EndLoc)
1883 : OMPClause(llvm::omp::OMPC_dynamic_allocators, StartLoc, EndLoc) {}
1884
1885 /// Build an empty clause.
1886 OMPDynamicAllocatorsClause()
1887 : OMPClause(llvm::omp::OMPC_dynamic_allocators, SourceLocation(),
1888 SourceLocation()) {}
1889
1890 child_range children() {
1891 return child_range(child_iterator(), child_iterator());
1892 }
1893
1894 const_child_range children() const {
1895 return const_child_range(const_child_iterator(), const_child_iterator());
1896 }
1897
1898 child_range used_children() {
1899 return child_range(child_iterator(), child_iterator());
1900 }
1901 const_child_range used_children() const {
1902 return const_child_range(const_child_iterator(), const_child_iterator());
1903 }
1904
1905 static bool classof(const OMPClause *T) {
1906 return T->getClauseKind() == llvm::omp::OMPC_dynamic_allocators;
1907 }
1908};
1909
1910/// This represents 'atomic_default_mem_order' clause in the '#pragma omp
1911/// requires' directive.
1912///
1913/// \code
1914/// #pragma omp requires atomic_default_mem_order(seq_cst)
1915/// \endcode
1916/// In this example directive '#pragma omp requires' has simple
1917/// atomic_default_mem_order' clause with kind 'seq_cst'.
1918class OMPAtomicDefaultMemOrderClause final : public OMPClause {
1919 friend class OMPClauseReader;
1920
1921 /// Location of '('
1922 SourceLocation LParenLoc;
1923
1924 /// A kind of the 'atomic_default_mem_order' clause.
1927
1928 /// Start location of the kind in source code.
1929 SourceLocation KindKwLoc;
1930
1931 /// Set kind of the clause.
1932 ///
1933 /// \param K Kind of clause.
1934 void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
1935 Kind = K;
1936 }
1937
1938 /// Set clause kind location.
1939 ///
1940 /// \param KLoc Kind location.
1941 void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
1942 KindKwLoc = KLoc;
1943 }
1944
1945public:
1946 /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
1947 /// 'acq_rel' or 'relaxed').
1948 ///
1949 /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
1950 /// \param ALoc Starting location of the argument.
1951 /// \param StartLoc Starting location of the clause.
1952 /// \param LParenLoc Location of '('.
1953 /// \param EndLoc Ending location of the clause.
1954 OMPAtomicDefaultMemOrderClause(OpenMPAtomicDefaultMemOrderClauseKind A,
1955 SourceLocation ALoc, SourceLocation StartLoc,
1956 SourceLocation LParenLoc,
1957 SourceLocation EndLoc)
1958 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, StartLoc, EndLoc),
1959 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1960
1961 /// Build an empty clause.
1962 OMPAtomicDefaultMemOrderClause()
1963 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, SourceLocation(),
1964 SourceLocation()) {}
1965
1966 /// Sets the location of '('.
1967 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1968
1969 /// Returns the locaiton of '('.
1970 SourceLocation getLParenLoc() const { return LParenLoc; }
1971
1972 /// Returns kind of the clause.
1973 OpenMPAtomicDefaultMemOrderClauseKind getAtomicDefaultMemOrderKind() const {
1974 return Kind;
1975 }
1976
1977 /// Returns location of clause kind.
1978 SourceLocation getAtomicDefaultMemOrderKindKwLoc() const { return KindKwLoc; }
1979
1980 child_range children() {
1981 return child_range(child_iterator(), child_iterator());
1982 }
1983
1984 const_child_range children() const {
1985 return const_child_range(const_child_iterator(), const_child_iterator());
1986 }
1987
1988 child_range used_children() {
1989 return child_range(child_iterator(), child_iterator());
1990 }
1991 const_child_range used_children() const {
1992 return const_child_range(const_child_iterator(), const_child_iterator());
1993 }
1994
1995 static bool classof(const OMPClause *T) {
1996 return T->getClauseKind() == llvm::omp::OMPC_atomic_default_mem_order;
1997 }
1998};
1999
2000/// This represents 'self_maps' clause in the '#pragma omp requires'
2001/// directive.
2002///
2003/// \code
2004/// #pragma omp requires self_maps
2005/// \endcode
2006/// In this example directive '#pragma omp requires' has 'self_maps'
2007/// clause.
2008class OMPSelfMapsClause final : public OMPClause {
2009public:
2010 friend class OMPClauseReader;
2011 /// Build 'self_maps' clause.
2012 ///
2013 /// \param StartLoc Starting location of the clause.
2014 /// \param EndLoc Ending location of the clause.
2015 OMPSelfMapsClause(SourceLocation StartLoc, SourceLocation EndLoc)
2016 : OMPClause(llvm::omp::OMPC_self_maps, StartLoc, EndLoc) {}
2017
2018 /// Build an empty clause.
2019 OMPSelfMapsClause()
2020 : OMPClause(llvm::omp::OMPC_self_maps, SourceLocation(),
2021 SourceLocation()) {}
2022
2023 child_range children() {
2024 return child_range(child_iterator(), child_iterator());
2025 }
2026
2027 const_child_range children() const {
2028 return const_child_range(const_child_iterator(), const_child_iterator());
2029 }
2030
2031 child_range used_children() {
2032 return child_range(child_iterator(), child_iterator());
2033 }
2034 const_child_range used_children() const {
2035 return const_child_range(const_child_iterator(), const_child_iterator());
2036 }
2037
2038 static bool classof(const OMPClause *T) {
2039 return T->getClauseKind() == llvm::omp::OMPC_self_maps;
2040 }
2041};
2042
2043/// This represents 'at' clause in the '#pragma omp error' directive
2044///
2045/// \code
2046/// #pragma omp error at(compilation)
2047/// \endcode
2048/// In this example directive '#pragma omp error' has simple
2049/// 'at' clause with kind 'complilation'.
2050class OMPAtClause final : public OMPClause {
2051 friend class OMPClauseReader;
2052
2053 /// Location of '('
2054 SourceLocation LParenLoc;
2055
2056 /// A kind of the 'at' clause.
2058
2059 /// Start location of the kind in source code.
2060 SourceLocation KindKwLoc;
2061
2062 /// Set kind of the clause.
2063 ///
2064 /// \param K Kind of clause.
2065 void setAtKind(OpenMPAtClauseKind K) { Kind = K; }
2066
2067 /// Set clause kind location.
2068 ///
2069 /// \param KLoc Kind location.
2070 void setAtKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
2071
2072 /// Sets the location of '('.
2073 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2074
2075public:
2076 /// Build 'at' clause with argument \a A ('compilation' or 'execution').
2077 ///
2078 /// \param A Argument of the clause ('compilation' or 'execution').
2079 /// \param ALoc Starting location of the argument.
2080 /// \param StartLoc Starting location of the clause.
2081 /// \param LParenLoc Location of '('.
2082 /// \param EndLoc Ending location of the clause.
2083 OMPAtClause(OpenMPAtClauseKind A, SourceLocation ALoc,
2084 SourceLocation StartLoc, SourceLocation LParenLoc,
2085 SourceLocation EndLoc)
2086 : OMPClause(llvm::omp::OMPC_at, StartLoc, EndLoc), LParenLoc(LParenLoc),
2087 Kind(A), KindKwLoc(ALoc) {}
2088
2089 /// Build an empty clause.
2090 OMPAtClause()
2091 : OMPClause(llvm::omp::OMPC_at, SourceLocation(), SourceLocation()) {}
2092
2093 /// Returns the locaiton of '('.
2094 SourceLocation getLParenLoc() const { return LParenLoc; }
2095
2096 /// Returns kind of the clause.
2097 OpenMPAtClauseKind getAtKind() const { return Kind; }
2098
2099 /// Returns location of clause kind.
2100 SourceLocation getAtKindKwLoc() const { return KindKwLoc; }
2101
2102 child_range children() {
2103 return child_range(child_iterator(), child_iterator());
2104 }
2105
2106 const_child_range children() const {
2107 return const_child_range(const_child_iterator(), const_child_iterator());
2108 }
2109
2110 child_range used_children() {
2111 return child_range(child_iterator(), child_iterator());
2112 }
2113 const_child_range used_children() const {
2114 return const_child_range(const_child_iterator(), const_child_iterator());
2115 }
2116
2117 static bool classof(const OMPClause *T) {
2118 return T->getClauseKind() == llvm::omp::OMPC_at;
2119 }
2120};
2121
2122/// This represents the 'severity' clause in the '#pragma omp error' and the
2123/// '#pragma omp parallel' directives.
2124///
2125/// \code
2126/// #pragma omp error severity(fatal)
2127/// \endcode
2128/// In this example directive '#pragma omp error' has simple
2129/// 'severity' clause with kind 'fatal'.
2130class OMPSeverityClause final : public OMPClause {
2131 friend class OMPClauseReader;
2132
2133 /// Location of '('
2134 SourceLocation LParenLoc;
2135
2136 /// A kind of the 'severity' clause.
2138
2139 /// Start location of the kind in source code.
2140 SourceLocation KindKwLoc;
2141
2142 /// Set kind of the clause.
2143 ///
2144 /// \param K Kind of clause.
2145 void setSeverityKind(OpenMPSeverityClauseKind K) { Kind = K; }
2146
2147 /// Set clause kind location.
2148 ///
2149 /// \param KLoc Kind location.
2150 void setSeverityKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
2151
2152 /// Sets the location of '('.
2153 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2154
2155public:
2156 /// Build 'severity' clause with argument \a A ('fatal' or 'warning').
2157 ///
2158 /// \param A Argument of the clause ('fatal' or 'warning').
2159 /// \param ALoc Starting location of the argument.
2160 /// \param StartLoc Starting location of the clause.
2161 /// \param LParenLoc Location of '('.
2162 /// \param EndLoc Ending location of the clause.
2163 OMPSeverityClause(OpenMPSeverityClauseKind A, SourceLocation ALoc,
2164 SourceLocation StartLoc, SourceLocation LParenLoc,
2165 SourceLocation EndLoc)
2166 : OMPClause(llvm::omp::OMPC_severity, StartLoc, EndLoc),
2167 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
2168
2169 /// Build an empty clause.
2170 OMPSeverityClause()
2171 : OMPClause(llvm::omp::OMPC_severity, SourceLocation(),
2172 SourceLocation()) {}
2173
2174 /// Returns the locaiton of '('.
2175 SourceLocation getLParenLoc() const { return LParenLoc; }
2176
2177 /// Returns kind of the clause.
2178 OpenMPSeverityClauseKind getSeverityKind() const { return Kind; }
2179
2180 /// Returns location of clause kind.
2181 SourceLocation getSeverityKindKwLoc() const { return KindKwLoc; }
2182
2183 child_range children() {
2184 return child_range(child_iterator(), child_iterator());
2185 }
2186
2187 const_child_range children() const {
2188 return const_child_range(const_child_iterator(), const_child_iterator());
2189 }
2190
2191 child_range used_children() {
2192 return child_range(child_iterator(), child_iterator());
2193 }
2194 const_child_range used_children() const {
2195 return const_child_range(const_child_iterator(), const_child_iterator());
2196 }
2197
2198 static bool classof(const OMPClause *T) {
2199 return T->getClauseKind() == llvm::omp::OMPC_severity;
2200 }
2201};
2202
2203/// This represents the 'message' clause in the '#pragma omp error' and the
2204/// '#pragma omp parallel' directives.
2205///
2206/// \code
2207/// #pragma omp error message("GNU compiler required.")
2208/// \endcode
2209/// In this example directive '#pragma omp error' has simple
2210/// 'message' clause with user error message of "GNU compiler required.".
2211class OMPMessageClause final
2212 : public OMPOneStmtClause<llvm::omp::OMPC_message, OMPClause>,
2213 public OMPClauseWithPreInit {
2214 friend class OMPClauseReader;
2215
2216 /// Set message string of the clause.
2217 void setMessageString(Expr *MS) { setStmt(MS); }
2218
2219public:
2220 /// Build 'message' clause with message string argument
2221 ///
2222 /// \param MS Argument of the clause (message string).
2223 /// \param HelperMS Helper statement for the construct.
2224 /// \param CaptureRegion Innermost OpenMP region where expressions in this
2225 /// clause must be captured.
2226 /// \param StartLoc Starting location of the clause.
2227 /// \param LParenLoc Location of '('.
2228 /// \param EndLoc Ending location of the clause.
2229 OMPMessageClause(Expr *MS, Stmt *HelperMS, OpenMPDirectiveKind CaptureRegion,
2230 SourceLocation StartLoc, SourceLocation LParenLoc,
2231 SourceLocation EndLoc)
2232 : OMPOneStmtClause(MS, StartLoc, LParenLoc, EndLoc),
2233 OMPClauseWithPreInit(this) {
2234 setPreInitStmt(HelperMS, CaptureRegion);
2235 }
2236
2237 /// Build an empty clause.
2238 OMPMessageClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {}
2239
2240 /// Returns message string of the clause.
2241 Expr *getMessageString() const { return getStmtAs<Expr>(); }
2242
2243 /// Try to evaluate the message string at compile time.
2244 std::optional<std::string> tryEvaluateString(ASTContext &Ctx) const {
2245 if (Expr *MessageExpr = getMessageString())
2246 return MessageExpr->tryEvaluateString(Ctx);
2247 return std::nullopt;
2248 }
2249};
2250
2251/// This represents 'schedule' clause in the '#pragma omp ...' directive.
2252///
2253/// \code
2254/// #pragma omp for schedule(static, 3)
2255/// \endcode
2256/// In this example directive '#pragma omp for' has 'schedule' clause with
2257/// arguments 'static' and '3'.
2258class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
2259 friend class OMPClauseReader;
2260
2261 /// Location of '('.
2262 SourceLocation LParenLoc;
2263
2264 /// A kind of the 'schedule' clause.
2266
2267 /// Modifiers for 'schedule' clause.
2268 enum {FIRST, SECOND, NUM_MODIFIERS};
2269 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
2270
2271 /// Locations of modifiers.
2272 SourceLocation ModifiersLoc[NUM_MODIFIERS];
2273
2274 /// Start location of the schedule ind in source code.
2275 SourceLocation KindLoc;
2276
2277 /// Location of ',' (if any).
2278 SourceLocation CommaLoc;
2279
2280 /// Chunk size.
2281 Expr *ChunkSize = nullptr;
2282
2283 /// Set schedule kind.
2284 ///
2285 /// \param K Schedule kind.
2286 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
2287
2288 /// Set the first schedule modifier.
2289 ///
2290 /// \param M Schedule modifier.
2291 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
2292 Modifiers[FIRST] = M;
2293 }
2294
2295 /// Set the second schedule modifier.
2296 ///
2297 /// \param M Schedule modifier.
2298 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
2299 Modifiers[SECOND] = M;
2300 }
2301
2302 /// Set location of the first schedule modifier.
2303 void setFirstScheduleModifierLoc(SourceLocation Loc) {
2304 ModifiersLoc[FIRST] = Loc;
2305 }
2306
2307 /// Set location of the second schedule modifier.
2308 void setSecondScheduleModifierLoc(SourceLocation Loc) {
2309 ModifiersLoc[SECOND] = Loc;
2310 }
2311
2312 /// Set schedule modifier location.
2313 ///
2314 /// \param M Schedule modifier location.
2315 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
2316 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
2317 Modifiers[FIRST] = M;
2318 else {
2319 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
2320 Modifiers[SECOND] = M;
2321 }
2322 }
2323
2324 /// Sets the location of '('.
2325 ///
2326 /// \param Loc Location of '('.
2327 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2328
2329 /// Set schedule kind start location.
2330 ///
2331 /// \param KLoc Schedule kind location.
2332 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
2333
2334 /// Set location of ','.
2335 ///
2336 /// \param Loc Location of ','.
2337 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
2338
2339 /// Set chunk size.
2340 ///
2341 /// \param E Chunk size.
2342 void setChunkSize(Expr *E) { ChunkSize = E; }
2343
2344public:
2345 /// Build 'schedule' clause with schedule kind \a Kind and chunk size
2346 /// expression \a ChunkSize.
2347 ///
2348 /// \param StartLoc Starting location of the clause.
2349 /// \param LParenLoc Location of '('.
2350 /// \param KLoc Starting location of the argument.
2351 /// \param CommaLoc Location of ','.
2352 /// \param EndLoc Ending location of the clause.
2353 /// \param Kind Schedule kind.
2354 /// \param ChunkSize Chunk size.
2355 /// \param HelperChunkSize Helper chunk size for combined directives.
2356 /// \param M1 The first modifier applied to 'schedule' clause.
2357 /// \param M1Loc Location of the first modifier
2358 /// \param M2 The second modifier applied to 'schedule' clause.
2359 /// \param M2Loc Location of the second modifier
2360 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2361 SourceLocation KLoc, SourceLocation CommaLoc,
2362 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
2363 Expr *ChunkSize, Stmt *HelperChunkSize,
2364 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
2365 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
2366 : OMPClause(llvm::omp::OMPC_schedule, StartLoc, EndLoc),
2367 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
2368 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
2369 setPreInitStmt(HelperChunkSize);
2370 Modifiers[FIRST] = M1;
2371 Modifiers[SECOND] = M2;
2372 ModifiersLoc[FIRST] = M1Loc;
2373 ModifiersLoc[SECOND] = M2Loc;
2374 }
2375
2376 /// Build an empty clause.
2377 explicit OMPScheduleClause()
2378 : OMPClause(llvm::omp::OMPC_schedule, SourceLocation(), SourceLocation()),
2379 OMPClauseWithPreInit(this) {
2380 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
2381 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
2382 }
2383
2384 /// Get kind of the clause.
2385 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
2386
2387 /// Get the first modifier of the clause.
2388 OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
2389 return Modifiers[FIRST];
2390 }
2391
2392 /// Get the second modifier of the clause.
2393 OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
2394 return Modifiers[SECOND];
2395 }
2396
2397 /// Get location of '('.
2398 SourceLocation getLParenLoc() { return LParenLoc; }
2399
2400 /// Get kind location.
2401 SourceLocation getScheduleKindLoc() { return KindLoc; }
2402
2403 /// Get the first modifier location.
2404 SourceLocation getFirstScheduleModifierLoc() const {
2405 return ModifiersLoc[FIRST];
2406 }
2407
2408 /// Get the second modifier location.
2409 SourceLocation getSecondScheduleModifierLoc() const {
2410 return ModifiersLoc[SECOND];
2411 }
2412
2413 /// Get location of ','.
2414 SourceLocation getCommaLoc() { return CommaLoc; }
2415
2416 /// Get chunk size.
2417 Expr *getChunkSize() { return ChunkSize; }
2418
2419 /// Get chunk size.
2420 const Expr *getChunkSize() const { return ChunkSize; }
2421
2422 child_range children() {
2423 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
2424 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
2425 }
2426
2427 const_child_range children() const {
2428 return const_cast<OMPScheduleClause *>(this)->children();
2429 }
2430
2431 child_range used_children() {
2432 return child_range(child_iterator(), child_iterator());
2433 }
2434 const_child_range used_children() const {
2435 return const_child_range(const_child_iterator(), const_child_iterator());
2436 }
2437
2438 static bool classof(const OMPClause *T) {
2439 return T->getClauseKind() == llvm::omp::OMPC_schedule;
2440 }
2441};
2442
2443/// This represents 'ordered' clause in the '#pragma omp ...' directive.
2444///
2445/// \code
2446/// #pragma omp for ordered (2)
2447/// \endcode
2448/// In this example directive '#pragma omp for' has 'ordered' clause with
2449/// parameter 2.
2450class OMPOrderedClause final
2451 : public OMPClause,
2452 private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
2453 friend class OMPClauseReader;
2454 friend TrailingObjects;
2455
2456 /// Location of '('.
2457 SourceLocation LParenLoc;
2458
2459 /// Number of for-loops.
2460 Stmt *NumForLoops = nullptr;
2461
2462 /// Real number of loops.
2463 unsigned NumberOfLoops = 0;
2464
2465 /// Build 'ordered' clause.
2466 ///
2467 /// \param Num Expression, possibly associated with this clause.
2468 /// \param NumLoops Number of loops, associated with this clause.
2469 /// \param StartLoc Starting location of the clause.
2470 /// \param LParenLoc Location of '('.
2471 /// \param EndLoc Ending location of the clause.
2472 OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
2473 SourceLocation LParenLoc, SourceLocation EndLoc)
2474 : OMPClause(llvm::omp::OMPC_ordered, StartLoc, EndLoc),
2475 LParenLoc(LParenLoc), NumForLoops(Num), NumberOfLoops(NumLoops) {}
2476
2477 /// Build an empty clause.
2478 explicit OMPOrderedClause(unsigned NumLoops)
2479 : OMPClause(llvm::omp::OMPC_ordered, SourceLocation(), SourceLocation()),
2480 NumberOfLoops(NumLoops) {}
2481
2482 /// Set the number of associated for-loops.
2483 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
2484
2485public:
2486 /// Build 'ordered' clause.
2487 ///
2488 /// \param Num Expression, possibly associated with this clause.
2489 /// \param NumLoops Number of loops, associated with this clause.
2490 /// \param StartLoc Starting location of the clause.
2491 /// \param LParenLoc Location of '('.
2492 /// \param EndLoc Ending location of the clause.
2493 static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
2494 unsigned NumLoops, SourceLocation StartLoc,
2495 SourceLocation LParenLoc,
2496 SourceLocation EndLoc);
2497
2498 /// Build an empty clause.
2499 static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
2500
2501 /// Sets the location of '('.
2502 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2503
2504 /// Returns the location of '('.
2505 SourceLocation getLParenLoc() const { return LParenLoc; }
2506
2507 /// Return the number of associated for-loops.
2508 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
2509
2510 /// Set number of iterations for the specified loop.
2511 void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
2512 /// Get number of iterations for all the loops.
2513 ArrayRef<Expr *> getLoopNumIterations() const;
2514
2515 /// Set loop counter for the specified loop.
2516 void setLoopCounter(unsigned NumLoop, Expr *Counter);
2517 /// Get loops counter for the specified loop.
2518 Expr *getLoopCounter(unsigned NumLoop);
2519 const Expr *getLoopCounter(unsigned NumLoop) const;
2520
2521 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
2522
2523 const_child_range children() const {
2524 return const_child_range(&NumForLoops, &NumForLoops + 1);
2525 }
2526
2527 child_range used_children() {
2528 return child_range(child_iterator(), child_iterator());
2529 }
2530 const_child_range used_children() const {
2531 return const_child_range(const_child_iterator(), const_child_iterator());
2532 }
2533
2534 static bool classof(const OMPClause *T) {
2535 return T->getClauseKind() == llvm::omp::OMPC_ordered;
2536 }
2537};
2538
2539/// This represents 'nowait' clause in the '#pragma omp ...' directive.
2540///
2541/// \code
2542/// #pragma omp for nowait (cond)
2543/// \endcode
2544/// In this example directive '#pragma omp for' has simple 'nowait' clause with
2545/// condition 'cond'.
2546class OMPNowaitClause final : public OMPClause {
2547 friend class OMPClauseReader;
2548
2549 /// Location of '('.
2550 SourceLocation LParenLoc;
2551
2552 /// Condition of the 'nowait' clause.
2553 Stmt *Condition = nullptr;
2554
2555 /// Set condition.
2556 void setCondition(Expr *Cond) { Condition = Cond; }
2557
2558public:
2559 /// Build 'nowait' clause with condition \a Cond.
2560 ///
2561 /// \param Cond Condition of the clause.
2562 /// \param StartLoc Starting location of the clause.
2563 /// \param LParenLoc Location of '('.
2564 /// \param EndLoc Ending location of the clause.
2565 OMPNowaitClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
2566 SourceLocation EndLoc)
2567 : OMPClause(llvm::omp::OMPC_nowait, StartLoc, EndLoc),
2568 LParenLoc(LParenLoc), Condition(Cond) {}
2569
2570 /// Build an empty clause.
2571 OMPNowaitClause()
2572 : OMPClause(llvm::omp::OMPC_nowait, SourceLocation(), SourceLocation()) {}
2573
2574 /// Sets the location of '('.
2575 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2576
2577 /// Returns the location of '('.
2578 SourceLocation getLParenLoc() const { return LParenLoc; }
2579
2580 /// Returns condition.
2581 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
2582
2583 child_range children() {
2584 if (Condition)
2585 return child_range(&Condition, &Condition + 1);
2586 return child_range(child_iterator(), child_iterator());
2587 }
2588
2589 const_child_range children() const {
2590 if (Condition)
2591 return const_child_range(&Condition, &Condition + 1);
2592 return const_child_range(const_child_iterator(), const_child_iterator());
2593 }
2594
2595 child_range used_children();
2596 const_child_range used_children() const {
2597 return const_cast<OMPNowaitClause *>(this)->used_children();
2598 }
2599
2600 static bool classof(const OMPClause *T) {
2601 return T->getClauseKind() == llvm::omp::OMPC_nowait;
2602 }
2603};
2604
2605/// This represents 'untied' clause in the '#pragma omp ...' directive.
2606///
2607/// \code
2608/// #pragma omp task untied
2609/// \endcode
2610/// In this example directive '#pragma omp task' has 'untied' clause.
2611class OMPUntiedClause : public OMPClause {
2612public:
2613 /// Build 'untied' clause.
2614 ///
2615 /// \param StartLoc Starting location of the clause.
2616 /// \param EndLoc Ending location of the clause.
2617 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
2618 : OMPClause(llvm::omp::OMPC_untied, StartLoc, EndLoc) {}
2619
2620 /// Build an empty clause.
2621 OMPUntiedClause()
2622 : OMPClause(llvm::omp::OMPC_untied, SourceLocation(), SourceLocation()) {}
2623
2624 child_range children() {
2625 return child_range(child_iterator(), child_iterator());
2626 }
2627
2628 const_child_range children() const {
2629 return const_child_range(const_child_iterator(), const_child_iterator());
2630 }
2631
2632 child_range used_children() {
2633 return child_range(child_iterator(), child_iterator());
2634 }
2635 const_child_range used_children() const {
2636 return const_child_range(const_child_iterator(), const_child_iterator());
2637 }
2638
2639 static bool classof(const OMPClause *T) {
2640 return T->getClauseKind() == llvm::omp::OMPC_untied;
2641 }
2642};
2643
2644/// This represents 'mergeable' clause in the '#pragma omp ...'
2645/// directive.
2646///
2647/// \code
2648/// #pragma omp task mergeable
2649/// \endcode
2650/// In this example directive '#pragma omp task' has 'mergeable' clause.
2651class OMPMergeableClause : public OMPClause {
2652public:
2653 /// Build 'mergeable' clause.
2654 ///
2655 /// \param StartLoc Starting location of the clause.
2656 /// \param EndLoc Ending location of the clause.
2657 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
2658 : OMPClause(llvm::omp::OMPC_mergeable, StartLoc, EndLoc) {}
2659
2660 /// Build an empty clause.
2661 OMPMergeableClause()
2662 : OMPClause(llvm::omp::OMPC_mergeable, SourceLocation(),
2663 SourceLocation()) {}
2664
2665 child_range children() {
2666 return child_range(child_iterator(), child_iterator());
2667 }
2668
2669 const_child_range children() const {
2670 return const_child_range(const_child_iterator(), const_child_iterator());
2671 }
2672
2673 child_range used_children() {
2674 return child_range(child_iterator(), child_iterator());
2675 }
2676 const_child_range used_children() const {
2677 return const_child_range(const_child_iterator(), const_child_iterator());
2678 }
2679
2680 static bool classof(const OMPClause *T) {
2681 return T->getClauseKind() == llvm::omp::OMPC_mergeable;
2682 }
2683};
2684
2685/// This represents the 'absent' clause in the '#pragma omp assume'
2686/// directive.
2687///
2688/// \code
2689/// #pragma omp assume absent(<directive-name list>)
2690/// \endcode
2691/// In this example directive '#pragma omp assume' has an 'absent' clause.
2692class OMPAbsentClause final
2693 : public OMPDirectiveListClause<OMPAbsentClause>,
2694 private llvm::TrailingObjects<OMPAbsentClause, OpenMPDirectiveKind> {
2695 friend OMPDirectiveListClause;
2696 friend TrailingObjects;
2697
2698 /// Build 'absent' clause.
2699 ///
2700 /// \param StartLoc Starting location of the clause.
2701 /// \param LParenLoc Location of '('.
2702 /// \param EndLoc Ending location of the clause.
2703 /// \param NumKinds Number of directive kinds listed in the clause.
2704 OMPAbsentClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2705 SourceLocation EndLoc, unsigned NumKinds)
2706 : OMPDirectiveListClause<OMPAbsentClause>(
2707 llvm::omp::OMPC_absent, StartLoc, LParenLoc, EndLoc, NumKinds) {}
2708
2709 /// Build an empty clause.
2710 OMPAbsentClause(unsigned NumKinds)
2711 : OMPDirectiveListClause<OMPAbsentClause>(
2712 llvm::omp::OMPC_absent, SourceLocation(), SourceLocation(),
2713 SourceLocation(), NumKinds) {}
2714
2715public:
2716 static OMPAbsentClause *Create(const ASTContext &C,
2717 ArrayRef<OpenMPDirectiveKind> DKVec,
2718 SourceLocation Loc, SourceLocation LLoc,
2719 SourceLocation RLoc);
2720
2721 static OMPAbsentClause *CreateEmpty(const ASTContext &C, unsigned NumKinds);
2722
2723 static bool classof(const OMPClause *C) {
2724 return C->getClauseKind() == llvm::omp::OMPC_absent;
2725 }
2726};
2727
2728/// This represents the 'contains' clause in the '#pragma omp assume'
2729/// directive.
2730///
2731/// \code
2732/// #pragma omp assume contains(<directive-name list>)
2733/// \endcode
2734/// In this example directive '#pragma omp assume' has a 'contains' clause.
2735class OMPContainsClause final
2736 : public OMPDirectiveListClause<OMPContainsClause>,
2737 private llvm::TrailingObjects<OMPContainsClause, OpenMPDirectiveKind> {
2738 friend OMPDirectiveListClause;
2739 friend TrailingObjects;
2740
2741 /// Build 'contains' clause.
2742 ///
2743 /// \param StartLoc Starting location of the clause.
2744 /// \param LParenLoc Location of '('.
2745 /// \param EndLoc Ending location of the clause.
2746 /// \param NumKinds Number of directive kinds listed in the clause.
2747 OMPContainsClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2748 SourceLocation EndLoc, unsigned NumKinds)
2749 : OMPDirectiveListClause<OMPContainsClause>(
2750 llvm::omp::OMPC_contains, StartLoc, LParenLoc, EndLoc, NumKinds) {}
2751
2752 /// Build an empty clause.
2753 OMPContainsClause(unsigned NumKinds)
2754 : OMPDirectiveListClause<OMPContainsClause>(
2755 llvm::omp::OMPC_contains, SourceLocation(), SourceLocation(),
2756 SourceLocation(), NumKinds) {}
2757
2758public:
2759 static OMPContainsClause *Create(const ASTContext &C,
2760 ArrayRef<OpenMPDirectiveKind> DKVec,
2761 SourceLocation Loc, SourceLocation LLoc,
2762 SourceLocation RLoc);
2763
2764 static OMPContainsClause *CreateEmpty(const ASTContext &C, unsigned NumKinds);
2765
2766 static bool classof(const OMPClause *C) {
2767 return C->getClauseKind() == llvm::omp::OMPC_contains;
2768 }
2769};
2770
2771/// This represents the 'holds' clause in the '#pragma omp assume'
2772/// directive.
2773///
2774/// \code
2775/// #pragma omp assume holds(<expr>)
2776/// \endcode
2777/// In this example directive '#pragma omp assume' has a 'holds' clause.
2778class OMPHoldsClause final
2779 : public OMPOneStmtClause<llvm::omp::OMPC_holds, OMPClause> {
2780 friend class OMPClauseReader;
2781
2782public:
2783 /// Build 'holds' clause.
2784 ///
2785 /// \param StartLoc Starting location of the clause.
2786 /// \param EndLoc Ending location of the clause.
2787 OMPHoldsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
2788 SourceLocation EndLoc)
2789 : OMPOneStmtClause(E, StartLoc, LParenLoc, EndLoc) {}
2790
2791 /// Build an empty clause.
2792 OMPHoldsClause() : OMPOneStmtClause() {}
2793
2794 Expr *getExpr() const { return getStmtAs<Expr>(); }
2795 void setExpr(Expr *E) { setStmt(E); }
2796};
2797
2798/// This represents the 'no_openmp' clause in the '#pragma omp assume'
2799/// directive.
2800///
2801/// \code
2802/// #pragma omp assume no_openmp
2803/// \endcode
2804/// In this example directive '#pragma omp assume' has a 'no_openmp' clause.
2805class OMPNoOpenMPClause final
2806 : public OMPNoChildClause<llvm::omp::OMPC_no_openmp> {
2807public:
2808 /// Build 'no_openmp' clause.
2809 ///
2810 /// \param StartLoc Starting location of the clause.
2811 /// \param EndLoc Ending location of the clause.
2812 OMPNoOpenMPClause(SourceLocation StartLoc, SourceLocation EndLoc)
2813 : OMPNoChildClause(StartLoc, EndLoc) {}
2814
2815 /// Build an empty clause.
2816 OMPNoOpenMPClause() : OMPNoChildClause() {}
2817};
2818
2819/// This represents the 'no_openmp_routines' clause in the '#pragma omp assume'
2820/// directive.
2821///
2822/// \code
2823/// #pragma omp assume no_openmp_routines
2824/// \endcode
2825/// In this example directive '#pragma omp assume' has a 'no_openmp_routines'
2826/// clause.
2827class OMPNoOpenMPRoutinesClause final
2828 : public OMPNoChildClause<llvm::omp::OMPC_no_openmp_routines> {
2829public:
2830 /// Build 'no_openmp_routines' clause.
2831 ///
2832 /// \param StartLoc Starting location of the clause.
2833 /// \param EndLoc Ending location of the clause.
2834 OMPNoOpenMPRoutinesClause(SourceLocation StartLoc, SourceLocation EndLoc)
2835 : OMPNoChildClause(StartLoc, EndLoc) {}
2836
2837 /// Build an empty clause.
2838 OMPNoOpenMPRoutinesClause() : OMPNoChildClause() {}
2839};
2840
2841/// This represents the 'no_openmp_constructs' clause in the
2842//// '#pragma omp assume' directive.
2843///
2844/// \code
2845/// #pragma omp assume no_openmp_constructs
2846/// \endcode
2847/// In this example directive '#pragma omp assume' has a 'no_openmp_constructs'
2848/// clause.
2849class OMPNoOpenMPConstructsClause final
2850 : public OMPNoChildClause<llvm::omp::OMPC_no_openmp_constructs> {
2851public:
2852 /// Build 'no_openmp_constructs' clause.
2853 ///
2854 /// \param StartLoc Starting location of the clause.
2855 /// \param EndLoc Ending location of the clause.
2856 OMPNoOpenMPConstructsClause(SourceLocation StartLoc, SourceLocation EndLoc)
2857 : OMPNoChildClause(StartLoc, EndLoc) {}
2858
2859 /// Build an empty clause.
2860 OMPNoOpenMPConstructsClause() : OMPNoChildClause() {}
2861};
2862
2863/// This represents the 'no_parallelism' clause in the '#pragma omp assume'
2864/// directive.
2865///
2866/// \code
2867/// #pragma omp assume no_parallelism
2868/// \endcode
2869/// In this example directive '#pragma omp assume' has a 'no_parallelism'
2870/// clause.
2871class OMPNoParallelismClause final
2872 : public OMPNoChildClause<llvm::omp::OMPC_no_parallelism> {
2873public:
2874 /// Build 'no_parallelism' clause.
2875 ///
2876 /// \param StartLoc Starting location of the clause.
2877 /// \param EndLoc Ending location of the clause.
2878 OMPNoParallelismClause(SourceLocation StartLoc, SourceLocation EndLoc)
2879 : OMPNoChildClause(StartLoc, EndLoc) {}
2880
2881 /// Build an empty clause.
2882 OMPNoParallelismClause() : OMPNoChildClause() {}
2883};
2884
2885/// This represents 'read' clause in the '#pragma omp atomic' directive.
2886///
2887/// \code
2888/// #pragma omp atomic read
2889/// \endcode
2890/// In this example directive '#pragma omp atomic' has 'read' clause.
2891class OMPReadClause : public OMPClause {
2892public:
2893 /// Build 'read' clause.
2894 ///
2895 /// \param StartLoc Starting location of the clause.
2896 /// \param EndLoc Ending location of the clause.
2897 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
2898 : OMPClause(llvm::omp::OMPC_read, StartLoc, EndLoc) {}
2899
2900 /// Build an empty clause.
2901 OMPReadClause()
2902 : OMPClause(llvm::omp::OMPC_read, SourceLocation(), SourceLocation()) {}
2903
2904 child_range children() {
2905 return child_range(child_iterator(), child_iterator());
2906 }
2907
2908 const_child_range children() const {
2909 return const_child_range(const_child_iterator(), const_child_iterator());
2910 }
2911
2912 child_range used_children() {
2913 return child_range(child_iterator(), child_iterator());
2914 }
2915 const_child_range used_children() const {
2916 return const_child_range(const_child_iterator(), const_child_iterator());
2917 }
2918
2919 static bool classof(const OMPClause *T) {
2920 return T->getClauseKind() == llvm::omp::OMPC_read;
2921 }
2922};
2923
2924/// This represents 'write' clause in the '#pragma omp atomic' directive.
2925///
2926/// \code
2927/// #pragma omp atomic write
2928/// \endcode
2929/// In this example directive '#pragma omp atomic' has 'write' clause.
2930class OMPWriteClause : public OMPClause {
2931public:
2932 /// Build 'write' clause.
2933 ///
2934 /// \param StartLoc Starting location of the clause.
2935 /// \param EndLoc Ending location of the clause.
2936 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
2937 : OMPClause(llvm::omp::OMPC_write, StartLoc, EndLoc) {}
2938
2939 /// Build an empty clause.
2940 OMPWriteClause()
2941 : OMPClause(llvm::omp::OMPC_write, SourceLocation(), SourceLocation()) {}
2942
2943 child_range children() {
2944 return child_range(child_iterator(), child_iterator());
2945 }
2946
2947 const_child_range children() const {
2948 return const_child_range(const_child_iterator(), const_child_iterator());
2949 }
2950
2951 child_range used_children() {
2952 return child_range(child_iterator(), child_iterator());
2953 }
2954 const_child_range used_children() const {
2955 return const_child_range(const_child_iterator(), const_child_iterator());
2956 }
2957
2958 static bool classof(const OMPClause *T) {
2959 return T->getClauseKind() == llvm::omp::OMPC_write;
2960 }
2961};
2962
2963/// This represents 'update' clause in the '#pragma omp atomic'
2964/// directive.
2965///
2966/// \code
2967/// #pragma omp atomic update
2968/// \endcode
2969/// In this example directive '#pragma omp atomic' has 'update' clause.
2970/// Also, this class represents 'update' clause in '#pragma omp depobj'
2971/// directive.
2972///
2973/// \code
2974/// #pragma omp depobj(a) update(in)
2975/// \endcode
2976/// In this example directive '#pragma omp depobj' has 'update' clause with 'in'
2977/// dependence kind.
2978class OMPUpdateClause final
2979 : public OMPClause,
2980 private llvm::TrailingObjects<OMPUpdateClause, SourceLocation,
2981 OpenMPDependClauseKind> {
2982 friend class OMPClauseReader;
2983 friend TrailingObjects;
2984
2985 /// true if extended version of the clause for 'depobj' directive.
2986 bool IsExtended = false;
2987
2988 /// Define the sizes of each trailing object array except the last one. This
2989 /// is required for TrailingObjects to work properly.
2990 size_t numTrailingObjects(OverloadToken<SourceLocation>) const {
2991 // 2 locations: for '(' and argument location.
2992 return IsExtended ? 2 : 0;
2993 }
2994
2995 /// Sets the location of '(' in clause for 'depobj' directive.
2996 void setLParenLoc(SourceLocation Loc) {
2997 assert(IsExtended && "Expected extended clause.");
2998 *getTrailingObjects<SourceLocation>() = Loc;
2999 }
3000
3001 /// Sets the location of '(' in clause for 'depobj' directive.
3002 void setArgumentLoc(SourceLocation Loc) {
3003 assert(IsExtended && "Expected extended clause.");
3004 *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc;
3005 }
3006
3007 /// Sets the dependence kind for the clause for 'depobj' directive.
3008 void setDependencyKind(OpenMPDependClauseKind DK) {
3009 assert(IsExtended && "Expected extended clause.");
3010 *getTrailingObjects<OpenMPDependClauseKind>() = DK;
3011 }
3012
3013 /// Build 'update' clause.
3014 ///
3015 /// \param StartLoc Starting location of the clause.
3016 /// \param EndLoc Ending location of the clause.
3017 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc,
3018 bool IsExtended)
3019 : OMPClause(llvm::omp::OMPC_update, StartLoc, EndLoc),
3020 IsExtended(IsExtended) {}
3021
3022 /// Build an empty clause.
3023 OMPUpdateClause(bool IsExtended)
3024 : OMPClause(llvm::omp::OMPC_update, SourceLocation(), SourceLocation()),
3025 IsExtended(IsExtended) {}
3026
3027public:
3028 /// Creates clause for 'atomic' directive.
3029 ///
3030 /// \param C AST context.
3031 /// \param StartLoc Starting location of the clause.
3032 /// \param EndLoc Ending location of the clause.
3033 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
3034 SourceLocation EndLoc);
3035
3036 /// Creates clause for 'depobj' directive.
3037 ///
3038 /// \param C AST context.
3039 /// \param StartLoc Starting location of the clause.
3040 /// \param LParenLoc Location of '('.
3041 /// \param ArgumentLoc Location of the argument.
3042 /// \param DK Dependence kind.
3043 /// \param EndLoc Ending location of the clause.
3044 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
3045 SourceLocation LParenLoc,
3046 SourceLocation ArgumentLoc,
3047 OpenMPDependClauseKind DK,
3048 SourceLocation EndLoc);
3049
3050 /// Creates an empty clause with the place for \a N variables.
3051 ///
3052 /// \param C AST context.
3053 /// \param IsExtended true if extended clause for 'depobj' directive must be
3054 /// created.
3055 static OMPUpdateClause *CreateEmpty(const ASTContext &C, bool IsExtended);
3056
3057 /// Checks if the clause is the extended clauses for 'depobj' directive.
3058 bool isExtended() const { return IsExtended; }
3059
3060 child_range children() {
3061 return child_range(child_iterator(), child_iterator());
3062 }
3063
3064 const_child_range children() const {
3065 return const_child_range(const_child_iterator(), const_child_iterator());
3066 }
3067
3068 child_range used_children() {
3069 return child_range(child_iterator(), child_iterator());
3070 }
3071 const_child_range used_children() const {
3072 return const_child_range(const_child_iterator(), const_child_iterator());
3073 }
3074
3075 /// Gets the location of '(' in clause for 'depobj' directive.
3076 SourceLocation getLParenLoc() const {
3077 assert(IsExtended && "Expected extended clause.");
3078 return *getTrailingObjects<SourceLocation>();
3079 }
3080
3081 /// Gets the location of argument in clause for 'depobj' directive.
3082 SourceLocation getArgumentLoc() const {
3083 assert(IsExtended && "Expected extended clause.");
3084 return *std::next(getTrailingObjects<SourceLocation>(), 1);
3085 }
3086
3087 /// Gets the dependence kind in clause for 'depobj' directive.
3088 OpenMPDependClauseKind getDependencyKind() const {
3089 assert(IsExtended && "Expected extended clause.");
3090 return *getTrailingObjects<OpenMPDependClauseKind>();
3091 }
3092
3093 static bool classof(const OMPClause *T) {
3094 return T->getClauseKind() == llvm::omp::OMPC_update;
3095 }
3096};
3097
3098/// This represents 'capture' clause in the '#pragma omp atomic'
3099/// directive.
3100///
3101/// \code
3102/// #pragma omp atomic capture
3103/// \endcode
3104/// In this example directive '#pragma omp atomic' has 'capture' clause.
3105class OMPCaptureClause : public OMPClause {
3106public:
3107 /// Build 'capture' clause.
3108 ///
3109 /// \param StartLoc Starting location of the clause.
3110 /// \param EndLoc Ending location of the clause.
3111 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
3112 : OMPClause(llvm::omp::OMPC_capture, StartLoc, EndLoc) {}
3113
3114 /// Build an empty clause.
3115 OMPCaptureClause()
3116 : OMPClause(llvm::omp::OMPC_capture, SourceLocation(), SourceLocation()) {
3117 }
3118
3119 child_range children() {
3120 return child_range(child_iterator(), child_iterator());
3121 }
3122
3123 const_child_range children() const {
3124 return const_child_range(const_child_iterator(), const_child_iterator());
3125 }
3126
3127 child_range used_children() {
3128 return child_range(child_iterator(), child_iterator());
3129 }
3130 const_child_range used_children() const {
3131 return const_child_range(const_child_iterator(), const_child_iterator());
3132 }
3133
3134 static bool classof(const OMPClause *T) {
3135 return T->getClauseKind() == llvm::omp::OMPC_capture;
3136 }
3137};
3138
3139/// This represents 'compare' clause in the '#pragma omp atomic'
3140/// directive.
3141///
3142/// \code
3143/// #pragma omp atomic compare
3144/// \endcode
3145/// In this example directive '#pragma omp atomic' has 'compare' clause.
3146class OMPCompareClause final : public OMPClause {
3147public:
3148 /// Build 'compare' clause.
3149 ///
3150 /// \param StartLoc Starting location of the clause.
3151 /// \param EndLoc Ending location of the clause.
3152 OMPCompareClause(SourceLocation StartLoc, SourceLocation EndLoc)
3153 : OMPClause(llvm::omp::OMPC_compare, StartLoc, EndLoc) {}
3154
3155 /// Build an empty clause.
3156 OMPCompareClause()
3157 : OMPClause(llvm::omp::OMPC_compare, SourceLocation(), SourceLocation()) {
3158 }
3159
3160 child_range children() {
3161 return child_range(child_iterator(), child_iterator());
3162 }
3163
3164 const_child_range children() const {
3165 return const_child_range(const_child_iterator(), const_child_iterator());
3166 }
3167
3168 child_range used_children() {
3169 return child_range(child_iterator(), child_iterator());
3170 }
3171 const_child_range used_children() const {
3172 return const_child_range(const_child_iterator(), const_child_iterator());
3173 }
3174
3175 static bool classof(const OMPClause *T) {
3176 return T->getClauseKind() == llvm::omp::OMPC_compare;
3177 }
3178};
3179
3180/// This represents 'seq_cst' clause in the '#pragma omp atomic|flush'
3181/// directives.
3182///
3183/// \code
3184/// #pragma omp atomic seq_cst
3185/// \endcode
3186/// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
3187class OMPSeqCstClause : public OMPClause {
3188public:
3189 /// Build 'seq_cst' clause.
3190 ///
3191 /// \param StartLoc Starting location of the clause.
3192 /// \param EndLoc Ending location of the clause.
3193 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
3194 : OMPClause(llvm::omp::OMPC_seq_cst, StartLoc, EndLoc) {}
3195
3196 /// Build an empty clause.
3197 OMPSeqCstClause()
3198 : OMPClause(llvm::omp::OMPC_seq_cst, SourceLocation(), SourceLocation()) {
3199 }
3200
3201 child_range children() {
3202 return child_range(child_iterator(), child_iterator());
3203 }
3204
3205 const_child_range children() const {
3206 return const_child_range(const_child_iterator(), const_child_iterator());
3207 }
3208
3209 child_range used_children() {
3210 return child_range(child_iterator(), child_iterator());
3211 }
3212 const_child_range used_children() const {
3213 return const_child_range(const_child_iterator(), const_child_iterator());
3214 }
3215
3216 static bool classof(const OMPClause *T) {
3217 return T->getClauseKind() == llvm::omp::OMPC_seq_cst;
3218 }
3219};
3220
3221/// This represents 'acq_rel' clause in the '#pragma omp atomic|flush'
3222/// directives.
3223///
3224/// \code
3225/// #pragma omp flush acq_rel
3226/// \endcode
3227/// In this example directive '#pragma omp flush' has 'acq_rel' clause.
3228class OMPAcqRelClause final : public OMPClause {
3229public:
3230 /// Build 'ack_rel' clause.
3231 ///
3232 /// \param StartLoc Starting location of the clause.
3233 /// \param EndLoc Ending location of the clause.
3234 OMPAcqRelClause(SourceLocation StartLoc, SourceLocation EndLoc)
3235 : OMPClause(llvm::omp::OMPC_acq_rel, StartLoc, EndLoc) {}
3236
3237 /// Build an empty clause.
3238 OMPAcqRelClause()
3239 : OMPClause(llvm::omp::OMPC_acq_rel, SourceLocation(), SourceLocation()) {
3240 }
3241
3242 child_range children() {
3243 return child_range(child_iterator(), child_iterator());
3244 }
3245
3246 const_child_range children() const {
3247 return const_child_range(const_child_iterator(), const_child_iterator());
3248 }
3249
3250 child_range used_children() {
3251 return child_range(child_iterator(), child_iterator());
3252 }
3253 const_child_range used_children() const {
3254 return const_child_range(const_child_iterator(), const_child_iterator());
3255 }
3256
3257 static bool classof(const OMPClause *T) {
3258 return T->getClauseKind() == llvm::omp::OMPC_acq_rel;
3259 }
3260};
3261
3262/// This represents 'acquire' clause in the '#pragma omp atomic|flush'
3263/// directives.
3264///
3265/// \code
3266/// #pragma omp flush acquire
3267/// \endcode
3268/// In this example directive '#pragma omp flush' has 'acquire' clause.
3269class OMPAcquireClause final : public OMPClause {
3270public:
3271 /// Build 'acquire' clause.
3272 ///
3273 /// \param StartLoc Starting location of the clause.
3274 /// \param EndLoc Ending location of the clause.
3275 OMPAcquireClause(SourceLocation StartLoc, SourceLocation EndLoc)
3276 : OMPClause(llvm::omp::OMPC_acquire, StartLoc, EndLoc) {}
3277
3278 /// Build an empty clause.
3279 OMPAcquireClause()
3280 : OMPClause(llvm::omp::OMPC_acquire, SourceLocation(), SourceLocation()) {
3281 }
3282
3283 child_range children() {
3284 return child_range(child_iterator(), child_iterator());
3285 }
3286
3287 const_child_range children() const {
3288 return const_child_range(const_child_iterator(), const_child_iterator());
3289 }
3290
3291 child_range used_children() {
3292 return child_range(child_iterator(), child_iterator());
3293 }
3294 const_child_range used_children() const {
3295 return const_child_range(const_child_iterator(), const_child_iterator());
3296 }
3297
3298 static bool classof(const OMPClause *T) {
3299 return T->getClauseKind() == llvm::omp::OMPC_acquire;
3300 }
3301};
3302
3303/// This represents 'release' clause in the '#pragma omp atomic|flush'
3304/// directives.
3305///
3306/// \code
3307/// #pragma omp flush release
3308/// \endcode
3309/// In this example directive '#pragma omp flush' has 'release' clause.
3310class OMPReleaseClause final : public OMPClause {
3311public:
3312 /// Build 'release' clause.
3313 ///
3314 /// \param StartLoc Starting location of the clause.
3315 /// \param EndLoc Ending location of the clause.
3316 OMPReleaseClause(SourceLocation StartLoc, SourceLocation EndLoc)
3317 : OMPClause(llvm::omp::OMPC_release, StartLoc, EndLoc) {}
3318
3319 /// Build an empty clause.
3320 OMPReleaseClause()
3321 : OMPClause(llvm::omp::OMPC_release, SourceLocation(), SourceLocation()) {
3322 }
3323
3324 child_range children() {
3325 return child_range(child_iterator(), child_iterator());
3326 }
3327
3328 const_child_range children() const {
3329 return const_child_range(const_child_iterator(), const_child_iterator());
3330 }
3331
3332 child_range used_children() {
3333 return child_range(child_iterator(), child_iterator());
3334 }
3335 const_child_range used_children() const {
3336 return const_child_range(const_child_iterator(), const_child_iterator());
3337 }
3338
3339 static bool classof(const OMPClause *T) {
3340 return T->getClauseKind() == llvm::omp::OMPC_release;
3341 }
3342};
3343
3344/// This represents 'relaxed' clause in the '#pragma omp atomic'
3345/// directives.
3346///
3347/// \code
3348/// #pragma omp atomic relaxed
3349/// \endcode
3350/// In this example directive '#pragma omp atomic' has 'relaxed' clause.
3351class OMPRelaxedClause final : public OMPClause {
3352public:
3353 /// Build 'relaxed' clause.
3354 ///
3355 /// \param StartLoc Starting location of the clause.
3356 /// \param EndLoc Ending location of the clause.
3357 OMPRelaxedClause(SourceLocation StartLoc, SourceLocation EndLoc)
3358 : OMPClause(llvm::omp::OMPC_relaxed, StartLoc, EndLoc) {}
3359
3360 /// Build an empty clause.
3361 OMPRelaxedClause()
3362 : OMPClause(llvm::omp::OMPC_relaxed, SourceLocation(), SourceLocation()) {
3363 }
3364
3365 child_range children() {
3366 return child_range(child_iterator(), child_iterator());
3367 }
3368
3369 const_child_range children() const {
3370 return const_child_range(const_child_iterator(), const_child_iterator());
3371 }
3372
3373 child_range used_children() {
3374 return child_range(child_iterator(), child_iterator());
3375 }
3376 const_child_range used_children() const {
3377 return const_child_range(const_child_iterator(), const_child_iterator());
3378 }
3379
3380 static bool classof(const OMPClause *T) {
3381 return T->getClauseKind() == llvm::omp::OMPC_relaxed;
3382 }
3383};
3384
3385/// This represents 'weak' clause in the '#pragma omp atomic'
3386/// directives.
3387///
3388/// \code
3389/// #pragma omp atomic compare weak
3390/// \endcode
3391/// In this example directive '#pragma omp atomic' has 'weak' clause.
3392class OMPWeakClause final : public OMPClause {
3393public:
3394 /// Build 'weak' clause.
3395 ///
3396 /// \param StartLoc Starting location of the clause.
3397 /// \param EndLoc Ending location of the clause.
3398 OMPWeakClause(SourceLocation StartLoc, SourceLocation EndLoc)
3399 : OMPClause(llvm::omp::OMPC_weak, StartLoc, EndLoc) {}
3400
3401 /// Build an empty clause.
3402 OMPWeakClause()
3403 : OMPClause(llvm::omp::OMPC_weak, SourceLocation(), SourceLocation()) {}
3404
3405 child_range children() {
3406 return child_range(child_iterator(), child_iterator());
3407 }
3408
3409 const_child_range children() const {
3410 return const_child_range(const_child_iterator(), const_child_iterator());
3411 }
3412
3413 child_range used_children() {
3414 return child_range(child_iterator(), child_iterator());
3415 }
3416 const_child_range used_children() const {
3417 return const_child_range(const_child_iterator(), const_child_iterator());
3418 }
3419
3420 static bool classof(const OMPClause *T) {
3421 return T->getClauseKind() == llvm::omp::OMPC_weak;
3422 }
3423};
3424
3425/// This represents 'fail' clause in the '#pragma omp atomic'
3426/// directive.
3427///
3428/// \code
3429/// #pragma omp atomic compare fail
3430/// \endcode
3431/// In this example directive '#pragma omp atomic compare' has 'fail' clause.
3432class OMPFailClause final : public OMPClause {
3433
3434 // FailParameter is a memory-order-clause. Storing the ClauseKind is
3435 // sufficient for our purpose.
3436 OpenMPClauseKind FailParameter = llvm::omp::Clause::OMPC_unknown;
3437 SourceLocation FailParameterLoc;
3438 SourceLocation LParenLoc;
3439
3440 friend class OMPClauseReader;
3441
3442 /// Sets the location of '(' in fail clause.
3443 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3444
3445 /// Sets the location of memoryOrder clause argument in fail clause.
3446 void setFailParameterLoc(SourceLocation Loc) { FailParameterLoc = Loc; }
3447
3448 /// Sets the mem_order clause for 'atomic compare fail' directive.
3449 void setFailParameter(OpenMPClauseKind FailParameter) {
3450 this->FailParameter = FailParameter;
3451 assert(checkFailClauseParameter(FailParameter) &&
3452 "Invalid fail clause parameter");
3453 }
3454
3455public:
3456 /// Build 'fail' clause.
3457 ///
3458 /// \param StartLoc Starting location of the clause.
3459 /// \param EndLoc Ending location of the clause.
3460 OMPFailClause(SourceLocation StartLoc, SourceLocation EndLoc)
3461 : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc) {}
3462
3463 OMPFailClause(OpenMPClauseKind FailParameter, SourceLocation FailParameterLoc,
3464 SourceLocation StartLoc, SourceLocation LParenLoc,
3465 SourceLocation EndLoc)
3466 : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc),
3467 FailParameterLoc(FailParameterLoc), LParenLoc(LParenLoc) {
3468
3469 setFailParameter(FailParameter);
3470 }
3471
3472 /// Build an empty clause.
3473 OMPFailClause()
3474 : OMPClause(llvm::omp::OMPC_fail, SourceLocation(), SourceLocation()) {}
3475
3476 child_range children() {
3477 return child_range(child_iterator(), child_iterator());
3478 }
3479
3480 const_child_range children() const {
3481 return const_child_range(const_child_iterator(), const_child_iterator());
3482 }
3483
3484 child_range used_children() {
3485 return child_range(child_iterator(), child_iterator());
3486 }
3487 const_child_range used_children() const {
3488 return const_child_range(const_child_iterator(), const_child_iterator());
3489 }
3490
3491 static bool classof(const OMPClause *T) {
3492 return T->getClauseKind() == llvm::omp::OMPC_fail;
3493 }
3494
3495 /// Gets the location of '(' (for the parameter) in fail clause.
3496 SourceLocation getLParenLoc() const {
3497 return LParenLoc;
3498 }
3499
3500 /// Gets the location of Fail Parameter (type memory-order-clause) in
3501 /// fail clause.
3502 SourceLocation getFailParameterLoc() const { return FailParameterLoc; }
3503
3504 /// Gets the parameter (type memory-order-clause) in Fail clause.
3505 OpenMPClauseKind getFailParameter() const { return FailParameter; }
3506};
3507
3508/// This represents clause 'private' in the '#pragma omp ...' directives.
3509///
3510/// \code
3511/// #pragma omp parallel private(a,b)
3512/// \endcode
3513/// In this example directive '#pragma omp parallel' has clause 'private'
3514/// with the variables 'a' and 'b'.
3515class OMPPrivateClause final
3516 : public OMPVarListClause<OMPPrivateClause>,
3517 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
3518 friend class OMPClauseReader;
3519 friend OMPVarListClause;
3520 friend TrailingObjects;
3521
3522 /// Build clause with number of variables \a N.
3523 ///
3524 /// \param StartLoc Starting location of the clause.
3525 /// \param LParenLoc Location of '('.
3526 /// \param EndLoc Ending location of the clause.
3527 /// \param N Number of the variables in the clause.
3528 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3529 SourceLocation EndLoc, unsigned N)
3530 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc,
3531 LParenLoc, EndLoc, N) {}
3532
3533 /// Build an empty clause.
3534 ///
3535 /// \param N Number of variables.
3536 explicit OMPPrivateClause(unsigned N)
3537 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private,
3538 SourceLocation(), SourceLocation(),
3539 SourceLocation(), N) {}
3540
3541 /// Sets the list of references to private copies with initializers for
3542 /// new private variables.
3543 /// \param VL List of references.
3544 void setPrivateCopies(ArrayRef<Expr *> VL);
3545
3546 /// Gets the list of references to private copies with initializers for
3547 /// new private variables.
3548 MutableArrayRef<Expr *> getPrivateCopies() {
3549 return {varlist_end(), varlist_size()};
3550 }
3551 ArrayRef<const Expr *> getPrivateCopies() const {
3552 return {varlist_end(), varlist_size()};
3553 }
3554
3555public:
3556 /// Creates clause with a list of variables \a VL.
3557 ///
3558 /// \param C AST context.
3559 /// \param StartLoc Starting location of the clause.
3560 /// \param LParenLoc Location of '('.
3561 /// \param EndLoc Ending location of the clause.
3562 /// \param VL List of references to the variables.
3563 /// \param PrivateVL List of references to private copies with initializers.
3564 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
3565 SourceLocation LParenLoc,
3566 SourceLocation EndLoc, ArrayRef<Expr *> VL,
3567 ArrayRef<Expr *> PrivateVL);
3568
3569 /// Creates an empty clause with the place for \a N variables.
3570 ///
3571 /// \param C AST context.
3572 /// \param N The number of variables.
3573 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3574
3575 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
3576 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
3577 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
3578 using private_copies_const_range =
3579 llvm::iterator_range<private_copies_const_iterator>;
3580
3581 private_copies_range private_copies() { return getPrivateCopies(); }
3582
3583 private_copies_const_range private_copies() const {
3584 return getPrivateCopies();
3585 }
3586
3587 child_range children() {
3588 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3589 reinterpret_cast<Stmt **>(varlist_end()));
3590 }
3591
3592 const_child_range children() const {
3593 return const_cast<OMPPrivateClause *>(this)->children();
3594 }
3595
3596 child_range used_children() {
3597 return child_range(child_iterator(), child_iterator());
3598 }
3599 const_child_range used_children() const {
3600 return const_child_range(const_child_iterator(), const_child_iterator());
3601 }
3602
3603 static bool classof(const OMPClause *T) {
3604 return T->getClauseKind() == llvm::omp::OMPC_private;
3605 }
3606};
3607
3608/// This represents clause 'firstprivate' in the '#pragma omp ...'
3609/// directives.
3610///
3611/// \code
3612/// #pragma omp parallel firstprivate(a,b)
3613/// \endcode
3614/// In this example directive '#pragma omp parallel' has clause 'firstprivate'
3615/// with the variables 'a' and 'b'.
3616class OMPFirstprivateClause final
3617 : public OMPVarListClause<OMPFirstprivateClause>,
3618 public OMPClauseWithPreInit,
3619 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
3620 friend class OMPClauseReader;
3621 friend OMPVarListClause;
3622 friend TrailingObjects;
3623
3624 /// Build clause with number of variables \a N.
3625 ///
3626 /// \param StartLoc Starting location of the clause.
3627 /// \param LParenLoc Location of '('.
3628 /// \param EndLoc Ending location of the clause.
3629 /// \param N Number of the variables in the clause.
3630 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3631 SourceLocation EndLoc, unsigned N)
3632 : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate,
3633 StartLoc, LParenLoc, EndLoc, N),
3634 OMPClauseWithPreInit(this) {}
3635
3636 /// Build an empty clause.
3637 ///
3638 /// \param N Number of variables.
3639 explicit OMPFirstprivateClause(unsigned N)
3640 : OMPVarListClause<OMPFirstprivateClause>(
3641 llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(),
3642 SourceLocation(), N),
3643 OMPClauseWithPreInit(this) {}
3644
3645 /// Sets the list of references to private copies with initializers for
3646 /// new private variables.
3647 /// \param VL List of references.
3648 void setPrivateCopies(ArrayRef<Expr *> VL);
3649
3650 /// Gets the list of references to private copies with initializers for
3651 /// new private variables.
3652 MutableArrayRef<Expr *> getPrivateCopies() {
3653 return {varlist_end(), varlist_size()};
3654 }
3655 ArrayRef<const Expr *> getPrivateCopies() const {
3656 return {varlist_end(), varlist_size()};
3657 }
3658
3659 /// Sets the list of references to initializer variables for new
3660 /// private variables.
3661 /// \param VL List of references.
3662 void setInits(ArrayRef<Expr *> VL);
3663
3664 /// Gets the list of references to initializer variables for new
3665 /// private variables.
3666 MutableArrayRef<Expr *> getInits() {
3667 return {getPrivateCopies().end(), varlist_size()};
3668 }
3669 ArrayRef<const Expr *> getInits() const {
3670 return {getPrivateCopies().end(), varlist_size()};
3671 }
3672
3673public:
3674 /// Creates clause with a list of variables \a VL.
3675 ///
3676 /// \param C AST context.
3677 /// \param StartLoc Starting location of the clause.
3678 /// \param LParenLoc Location of '('.
3679 /// \param EndLoc Ending location of the clause.
3680 /// \param VL List of references to the original variables.
3681 /// \param PrivateVL List of references to private copies with initializers.
3682 /// \param InitVL List of references to auto generated variables used for
3683 /// initialization of a single array element. Used if firstprivate variable is
3684 /// of array type.
3685 /// \param PreInit Statement that must be executed before entering the OpenMP
3686 /// region with this clause.
3687 static OMPFirstprivateClause *
3688 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3689 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
3690 ArrayRef<Expr *> InitVL, Stmt *PreInit);
3691
3692 /// Creates an empty clause with the place for \a N variables.
3693 ///
3694 /// \param C AST context.
3695 /// \param N The number of variables.
3696 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3697
3698 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
3699 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
3700 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
3701 using private_copies_const_range =
3702 llvm::iterator_range<private_copies_const_iterator>;
3703
3704 private_copies_range private_copies() { return getPrivateCopies(); }
3705 private_copies_const_range private_copies() const {
3706 return getPrivateCopies();
3707 }
3708
3709 using inits_iterator = MutableArrayRef<Expr *>::iterator;
3710 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
3711 using inits_range = llvm::iterator_range<inits_iterator>;
3712 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
3713
3714 inits_range inits() { return getInits(); }
3715 inits_const_range inits() const { return getInits(); }
3716
3717 child_range children() {
3718 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3719 reinterpret_cast<Stmt **>(varlist_end()));
3720 }
3721
3722 const_child_range children() const {
3723 return const_cast<OMPFirstprivateClause *>(this)->children();
3724 }
3725
3726 child_range used_children() {
3727 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3728 reinterpret_cast<Stmt **>(varlist_end()));
3729 }
3730 const_child_range used_children() const {
3731 return const_cast<OMPFirstprivateClause *>(this)->used_children();
3732 }
3733
3734 static bool classof(const OMPClause *T) {
3735 return T->getClauseKind() == llvm::omp::OMPC_firstprivate;
3736 }
3737};
3738
3739/// This represents clause 'lastprivate' in the '#pragma omp ...'
3740/// directives.
3741///
3742/// \code
3743/// #pragma omp simd lastprivate(a,b)
3744/// \endcode
3745/// In this example directive '#pragma omp simd' has clause 'lastprivate'
3746/// with the variables 'a' and 'b'.
3747class OMPLastprivateClause final
3748 : public OMPVarListClause<OMPLastprivateClause>,
3750 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
3751 // There are 4 additional tail-allocated arrays at the end of the class:
3752 // 1. Contains list of pseudo variables with the default initialization for
3753 // each non-firstprivate variables. Used in codegen for initialization of
3754 // lastprivate copies.
3755 // 2. List of helper expressions for proper generation of assignment operation
3756 // required for lastprivate clause. This list represents private variables
3757 // (for arrays, single array element).
3758 // 3. List of helper expressions for proper generation of assignment operation
3759 // required for lastprivate clause. This list represents original variables
3760 // (for arrays, single array element).
3761 // 4. List of helper expressions that represents assignment operation:
3762 // \code
3763 // DstExprs = SrcExprs;
3764 // \endcode
3765 // Required for proper codegen of final assignment performed by the
3766 // lastprivate clause.
3767 friend class OMPClauseReader;
3768 friend OMPVarListClause;
3769 friend TrailingObjects;
3770
3771 /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
3773 /// Optional location of the lasptrivate kind, if specified by user.
3774 SourceLocation LPKindLoc;
3775 /// Optional colon location, if specified by user.
3776 SourceLocation ColonLoc;
3777
3778 /// Build clause with number of variables \a N.
3779 ///
3780 /// \param StartLoc Starting location of the clause.
3781 /// \param LParenLoc Location of '('.
3782 /// \param EndLoc Ending location of the clause.
3783 /// \param N Number of the variables in the clause.
3784 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3785 SourceLocation EndLoc, OpenMPLastprivateModifier LPKind,
3786 SourceLocation LPKindLoc, SourceLocation ColonLoc,
3787 unsigned N)
3788 : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate,
3789 StartLoc, LParenLoc, EndLoc, N),
3790 OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
3791 ColonLoc(ColonLoc) {}
3792
3793 /// Build an empty clause.
3794 ///
3795 /// \param N Number of variables.
3796 explicit OMPLastprivateClause(unsigned N)
3797 : OMPVarListClause<OMPLastprivateClause>(
3798 llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(),
3799 SourceLocation(), N),
3800 OMPClauseWithPostUpdate(this) {}
3801
3802 /// Get the list of helper expressions for initialization of private
3803 /// copies for lastprivate variables.
3804 MutableArrayRef<Expr *> getPrivateCopies() {
3805 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3806 }
3807 ArrayRef<const Expr *> getPrivateCopies() const {
3808 return {varlist_end(), varlist_size()};
3809 }
3810
3811 /// Set list of helper expressions, required for proper codegen of the
3812 /// clause. These expressions represent private variables (for arrays, single
3813 /// array element) in the final assignment statement performed by the
3814 /// lastprivate clause.
3815 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
3816
3817 /// Get the list of helper source expressions.
3818 MutableArrayRef<Expr *> getSourceExprs() {
3819 return {getPrivateCopies().end(), varlist_size()};
3820 }
3821 ArrayRef<const Expr *> getSourceExprs() const {
3822 return {getPrivateCopies().end(), varlist_size()};
3823 }
3824
3825 /// Set list of helper expressions, required for proper codegen of the
3826 /// clause. These expressions represent original variables (for arrays, single
3827 /// array element) in the final assignment statement performed by the
3828 /// lastprivate clause.
3829 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
3830
3831 /// Get the list of helper destination expressions.
3832 MutableArrayRef<Expr *> getDestinationExprs() {
3833 return {getSourceExprs().end(), varlist_size()};
3834 }
3835 ArrayRef<const Expr *> getDestinationExprs() const {
3836 return {getSourceExprs().end(), varlist_size()};
3837 }
3838
3839 /// Set list of helper assignment expressions, required for proper
3840 /// codegen of the clause. These expressions are assignment expressions that
3841 /// assign private copy of the variable to original variable.
3842 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
3843
3844 /// Get the list of helper assignment expressions.
3845 MutableArrayRef<Expr *> getAssignmentOps() {
3846 return {getDestinationExprs().end(), varlist_size()};
3847 }
3848 ArrayRef<const Expr *> getAssignmentOps() const {
3849 return {getDestinationExprs().end(), varlist_size()};
3850 }
3851
3852 /// Sets lastprivate kind.
3853 void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
3854 /// Sets location of the lastprivate kind.
3855 void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
3856 /// Sets colon symbol location.
3857 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3858
3859public:
3860 /// Creates clause with a list of variables \a VL.
3861 ///
3862 /// \param C AST context.
3863 /// \param StartLoc Starting location of the clause.
3864 /// \param LParenLoc Location of '('.
3865 /// \param EndLoc Ending location of the clause.
3866 /// \param VL List of references to the variables.
3867 /// \param SrcExprs List of helper expressions for proper generation of
3868 /// assignment operation required for lastprivate clause. This list represents
3869 /// private variables (for arrays, single array element).
3870 /// \param DstExprs List of helper expressions for proper generation of
3871 /// assignment operation required for lastprivate clause. This list represents
3872 /// original variables (for arrays, single array element).
3873 /// \param AssignmentOps List of helper expressions that represents assignment
3874 /// operation:
3875 /// \code
3876 /// DstExprs = SrcExprs;
3877 /// \endcode
3878 /// Required for proper codegen of final assignment performed by the
3879 /// lastprivate clause.
3880 /// \param LPKind Lastprivate kind, e.g. 'conditional'.
3881 /// \param LPKindLoc Location of the lastprivate kind.
3882 /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
3883 /// \param PreInit Statement that must be executed before entering the OpenMP
3884 /// region with this clause.
3885 /// \param PostUpdate Expression that must be executed after exit from the
3886 /// OpenMP region with this clause.
3887 static OMPLastprivateClause *
3888 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3889 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
3890 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
3891 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
3892 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
3893
3894 /// Creates an empty clause with the place for \a N variables.
3895 ///
3896 /// \param C AST context.
3897 /// \param N The number of variables.
3898 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3899
3900 /// Lastprivate kind.
3901 OpenMPLastprivateModifier getKind() const { return LPKind; }
3902 /// Returns the location of the lastprivate kind.
3903 SourceLocation getKindLoc() const { return LPKindLoc; }
3904 /// Returns the location of the ':' symbol, if any.
3905 SourceLocation getColonLoc() const { return ColonLoc; }
3906
3907 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3908 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3909 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3910 using helper_expr_const_range =
3911 llvm::iterator_range<helper_expr_const_iterator>;
3912
3913 /// Set list of helper expressions, required for generation of private
3914 /// copies of original lastprivate variables.
3915 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
3916
3917 helper_expr_const_range private_copies() const { return getPrivateCopies(); }
3918
3919 helper_expr_range private_copies() { return getPrivateCopies(); }
3920
3921 helper_expr_const_range source_exprs() const { return getSourceExprs(); }
3922
3923 helper_expr_range source_exprs() { return getSourceExprs(); }
3924
3925 helper_expr_const_range destination_exprs() const {
3926 return getDestinationExprs();
3927 }
3928
3929 helper_expr_range destination_exprs() { return getDestinationExprs(); }
3930
3931 helper_expr_const_range assignment_ops() const { return getAssignmentOps(); }
3932
3933 helper_expr_range assignment_ops() { return getAssignmentOps(); }
3934
3935 child_range children() {
3936 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3937 reinterpret_cast<Stmt **>(varlist_end()));
3938 }
3939
3940 const_child_range children() const {
3941 return const_cast<OMPLastprivateClause *>(this)->children();
3942 }
3943
3944 child_range used_children() {
3945 return child_range(child_iterator(), child_iterator());
3946 }
3947 const_child_range used_children() const {
3948 return const_child_range(const_child_iterator(), const_child_iterator());
3949 }
3950
3951 static bool classof(const OMPClause *T) {
3952 return T->getClauseKind() == llvm::omp::OMPC_lastprivate;
3953 }
3954};
3955
3956/// This represents clause 'shared' in the '#pragma omp ...' directives.
3957///
3958/// \code
3959/// #pragma omp parallel shared(a,b)
3960/// \endcode
3961/// In this example directive '#pragma omp parallel' has clause 'shared'
3962/// with the variables 'a' and 'b'.
3963class OMPSharedClause final
3964 : public OMPVarListClause<OMPSharedClause>,
3965 private llvm::TrailingObjects<OMPSharedClause, Expr *> {
3966 friend OMPVarListClause;
3967 friend TrailingObjects;
3968
3969 /// Build clause with number of variables \a N.
3970 ///
3971 /// \param StartLoc Starting location of the clause.
3972 /// \param LParenLoc Location of '('.
3973 /// \param EndLoc Ending location of the clause.
3974 /// \param N Number of the variables in the clause.
3975 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3976 SourceLocation EndLoc, unsigned N)
3977 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, StartLoc,
3978 LParenLoc, EndLoc, N) {}
3979
3980 /// Build an empty clause.
3981 ///
3982 /// \param N Number of variables.
3983 explicit OMPSharedClause(unsigned N)
3984 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared,
3985 SourceLocation(), SourceLocation(),
3986 SourceLocation(), N) {}
3987
3988public:
3989 /// Creates clause with a list of variables \a VL.
3990 ///
3991 /// \param C AST context.
3992 /// \param StartLoc Starting location of the clause.
3993 /// \param LParenLoc Location of '('.
3994 /// \param EndLoc Ending location of the clause.
3995 /// \param VL List of references to the variables.
3996 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
3997 SourceLocation LParenLoc,
3998 SourceLocation EndLoc, ArrayRef<Expr *> VL);
3999
4000 /// Creates an empty clause with \a N variables.
4001 ///
4002 /// \param C AST context.
4003 /// \param N The number of variables.
4004 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
4005
4006 child_range children() {
4007 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4008 reinterpret_cast<Stmt **>(varlist_end()));
4009 }
4010
4011 const_child_range children() const {
4012 return const_cast<OMPSharedClause *>(this)->children();
4013 }
4014
4015 child_range used_children() {
4016 return child_range(child_iterator(), child_iterator());
4017 }
4018 const_child_range used_children() const {
4019 return const_child_range(const_child_iterator(), const_child_iterator());
4020 }
4021
4022 static bool classof(const OMPClause *T) {
4023 return T->getClauseKind() == llvm::omp::OMPC_shared;
4024 }
4025};
4026
4027/// This represents clause 'reduction' in the '#pragma omp ...'
4028/// directives.
4029///
4030/// \code
4031/// #pragma omp parallel reduction(+:a,b)
4032/// \endcode
4033/// In this example directive '#pragma omp parallel' has clause 'reduction'
4034/// with operator '+' and the variables 'a' and 'b'.
4035class OMPReductionClause final
4036 : public OMPVarListClause<OMPReductionClause>,
4038 private llvm::TrailingObjects<OMPReductionClause, Expr *, bool> {
4039 friend class OMPClauseReader;
4040 friend OMPVarListClause;
4041 friend TrailingObjects;
4042
4043 /// Reduction modifier.
4045
4046 /// Original Sharing modifier.
4047 OpenMPOriginalSharingModifier OriginalSharingModifier =
4048 OMPC_ORIGINAL_SHARING_default;
4049
4050 /// Reduction modifier location.
4051 SourceLocation ModifierLoc;
4052
4053 /// Location of ':'.
4054 SourceLocation ColonLoc;
4055
4056 /// Nested name specifier for C++.
4057 NestedNameSpecifierLoc QualifierLoc;
4058
4059 /// Name of custom operator.
4060 DeclarationNameInfo NameInfo;
4061
4062 /// Build clause with number of variables \a N.
4063 ///
4064 /// \param StartLoc Starting location of the clause.
4065 /// \param LParenLoc Location of '('.
4066 /// \param ModifierLoc Modifier location.
4067 /// \param ColonLoc Location of ':'.
4068 /// \param EndLoc Ending location of the clause.
4069 /// \param N Number of the variables in the clause.
4070 /// \param QualifierLoc The nested-name qualifier with location information
4071 /// \param NameInfo The full name info for reduction identifier.
4072 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4073 SourceLocation ModifierLoc, SourceLocation ColonLoc,
4074 SourceLocation EndLoc,
4075 OpenMPReductionClauseModifier Modifier,
4076 OpenMPOriginalSharingModifier OriginalSharingModifier,
4077 unsigned N, NestedNameSpecifierLoc QualifierLoc,
4078 const DeclarationNameInfo &NameInfo)
4079 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
4080 StartLoc, LParenLoc, EndLoc, N),
4081 OMPClauseWithPostUpdate(this), Modifier(Modifier),
4082 OriginalSharingModifier(OriginalSharingModifier),
4083 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
4084 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
4085
4086 /// Build an empty clause.
4087 ///
4088 /// \param N Number of variables.
4089 explicit OMPReductionClause(unsigned N)
4090 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
4091 SourceLocation(), SourceLocation(),
4092 SourceLocation(), N),
4093 OMPClauseWithPostUpdate(this) {}
4094
4095 /// Sets reduction modifier.
4096 void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; }
4097
4098 /// Sets Original Sharing modifier.
4099 void setOriginalSharingModifier(OpenMPOriginalSharingModifier M) {
4100 OriginalSharingModifier = M;
4101 }
4102
4103 /// Sets location of the modifier.
4104 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
4105
4106 /// Sets location of ':' symbol in clause.
4107 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
4108
4109 /// Sets the name info for specified reduction identifier.
4110 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
4111
4112 /// Sets the nested name specifier.
4113 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
4114
4115 /// Set list of helper expressions, required for proper codegen of the
4116 /// clause. These expressions represent private copy of the reduction
4117 /// variable.
4118 void setPrivates(ArrayRef<Expr *> Privates);
4119
4120 /// Get the list of helper privates.
4121 MutableArrayRef<Expr *> getPrivates() {
4122 return {varlist_end(), varlist_size()};
4123 }
4124 ArrayRef<const Expr *> getPrivates() const {
4125 return {varlist_end(), varlist_size()};
4126 }
4127
4128 /// Set list of helper expressions, required for proper codegen of the
4129 /// clause. These expressions represent LHS expression in the final
4130 /// reduction expression performed by the reduction clause.
4131 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
4132
4133 /// Get the list of helper LHS expressions.
4134 MutableArrayRef<Expr *> getLHSExprs() {
4135 return {getPrivates().end(), varlist_size()};
4136 }
4137 ArrayRef<const Expr *> getLHSExprs() const {
4138 return {getPrivates().end(), varlist_size()};
4139 }
4140
4141 /// Set list of helper expressions, required for proper codegen of the
4142 /// clause. These expressions represent RHS expression in the final
4143 /// reduction expression performed by the reduction clause.
4144 /// Also, variables in these expressions are used for proper initialization of
4145 /// reduction copies.
4146 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
4147
4148 /// Set the list private reduction flags
4149 void setPrivateVariableReductionFlags(ArrayRef<bool> Flags) {
4150 assert(Flags.size() == varlist_size() &&
4151 "Number of private flags does not match vars");
4152 llvm::copy(Flags, getTrailingObjects<bool>());
4153 }
4154
4155 /// Get the list of help private variable reduction flags
4156 MutableArrayRef<bool> getPrivateVariableReductionFlags() {
4157 return getTrailingObjects<bool>(varlist_size());
4158 }
4159 ArrayRef<bool> getPrivateVariableReductionFlags() const {
4160 return getTrailingObjects<bool>(varlist_size());
4161 }
4162
4163 /// Returns the number of Expr* objects in trailing storage
4164 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4165 return varlist_size() * (Modifier == OMPC_REDUCTION_inscan ? 8 : 5);
4166 }
4167
4168 /// Returns the number of bool flags in trailing storage
4169 size_t numTrailingObjects(OverloadToken<bool>) const {
4170 return varlist_size();
4171 }
4172
4173 /// Get the list of helper destination expressions.
4174 MutableArrayRef<Expr *> getRHSExprs() {
4175 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
4176 }
4177 ArrayRef<const Expr *> getRHSExprs() const {
4178 return {getLHSExprs().end(), varlist_size()};
4179 }
4180
4181 /// Set list of helper reduction expressions, required for proper
4182 /// codegen of the clause. These expressions are binary expressions or
4183 /// operator/custom reduction call that calculates new value from source
4184 /// helper expressions to destination helper expressions.
4185 void setReductionOps(ArrayRef<Expr *> ReductionOps);
4186
4187 /// Get the list of helper reduction expressions.
4188 MutableArrayRef<Expr *> getReductionOps() {
4189 return {getRHSExprs().end(), varlist_size()};
4190 }
4191 ArrayRef<const Expr *> getReductionOps() const {
4192 return {getRHSExprs().end(), varlist_size()};
4193 }
4194
4195 /// Set list of helper copy operations for inscan reductions.
4196 /// The form is: Temps[i] = LHS[i];
4197 void setInscanCopyOps(ArrayRef<Expr *> Ops);
4198
4199 /// Get the list of helper inscan copy operations.
4200 MutableArrayRef<Expr *> getInscanCopyOps() {
4201 return {getReductionOps().end(), varlist_size()};
4202 }
4203 ArrayRef<const Expr *> getInscanCopyOps() const {
4204 return {getReductionOps().end(), varlist_size()};
4205 }
4206
4207 /// Set list of helper temp vars for inscan copy array operations.
4208 void setInscanCopyArrayTemps(ArrayRef<Expr *> CopyArrayTemps);
4209
4210 /// Get the list of helper inscan copy temps.
4211 MutableArrayRef<Expr *> getInscanCopyArrayTemps() {
4212 return {getInscanCopyOps().end(), varlist_size()};
4213 }
4214 ArrayRef<const Expr *> getInscanCopyArrayTemps() const {
4215 return {getInscanCopyOps().end(), varlist_size()};
4216 }
4217
4218 /// Set list of helper temp elements vars for inscan copy array operations.
4219 void setInscanCopyArrayElems(ArrayRef<Expr *> CopyArrayElems);
4220
4221 /// Get the list of helper inscan copy temps.
4222 MutableArrayRef<Expr *> getInscanCopyArrayElems() {
4223 return {getInscanCopyArrayTemps().end(), varlist_size()};
4224 }
4225 ArrayRef<const Expr *> getInscanCopyArrayElems() const {
4226 return {getInscanCopyArrayTemps().end(), varlist_size()};
4227 }
4228
4229public:
4230 /// Creates clause with a list of variables \a VL.
4231 ///
4232 /// \param StartLoc Starting location of the clause.
4233 /// \param LParenLoc Location of '('.
4234 /// \param ModifierLoc Modifier location.
4235 /// \param ColonLoc Location of ':'.
4236 /// \param EndLoc Ending location of the clause.
4237 /// \param VL The variables in the clause.
4238 /// \param QualifierLoc The nested-name qualifier with location information
4239 /// \param NameInfo The full name info for reduction identifier.
4240 /// \param Privates List of helper expressions for proper generation of
4241 /// private copies.
4242 /// \param LHSExprs List of helper expressions for proper generation of
4243 /// assignment operation required for copyprivate clause. This list represents
4244 /// LHSs of the reduction expressions.
4245 /// \param RHSExprs List of helper expressions for proper generation of
4246 /// assignment operation required for copyprivate clause. This list represents
4247 /// RHSs of the reduction expressions.
4248 /// Also, variables in these expressions are used for proper initialization of
4249 /// reduction copies.
4250 /// \param ReductionOps List of helper expressions that represents reduction
4251 /// expressions:
4252 /// \code
4253 /// LHSExprs binop RHSExprs;
4254 /// operator binop(LHSExpr, RHSExpr);
4255 /// <CutomReduction>(LHSExpr, RHSExpr);
4256 /// \endcode
4257 /// Required for proper codegen of final reduction operation performed by the
4258 /// reduction clause.
4259 /// \param CopyOps List of copy operations for inscan reductions:
4260 /// \code
4261 /// TempExprs = LHSExprs;
4262 /// \endcode
4263 /// \param CopyArrayTemps Temp arrays for prefix sums.
4264 /// \param CopyArrayElems Temp arrays for prefix sums.
4265 /// \param PreInit Statement that must be executed before entering the OpenMP
4266 /// region with this clause.
4267 /// \param PostUpdate Expression that must be executed after exit from the
4268 /// OpenMP region with this clause.
4269 /// \param IsPrivateVarReduction array for private variable reduction flags
4270 static OMPReductionClause *
4271 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4272 SourceLocation ModifierLoc, SourceLocation ColonLoc,
4273 SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier,
4274 ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc,
4275 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
4276 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
4277 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> CopyOps,
4278 ArrayRef<Expr *> CopyArrayTemps, ArrayRef<Expr *> CopyArrayElems,
4279 Stmt *PreInit, Expr *PostUpdate, ArrayRef<bool> IsPrivateVarReduction,
4280 OpenMPOriginalSharingModifier OriginalSharingModifier);
4281
4282 /// Creates an empty clause with the place for \a N variables.
4283 ///
4284 /// \param C AST context.
4285 /// \param N The number of variables.
4286 /// \param Modifier Reduction modifier.
4287 static OMPReductionClause *
4288 CreateEmpty(const ASTContext &C, unsigned N,
4289 OpenMPReductionClauseModifier Modifier);
4290
4291 /// Returns modifier.
4292 OpenMPReductionClauseModifier getModifier() const { return Modifier; }
4293
4294 /// Returns Original Sharing Modifier.
4295 OpenMPOriginalSharingModifier getOriginalSharingModifier() const {
4296 return OriginalSharingModifier;
4297 }
4298
4299 /// Returns modifier location.
4300 SourceLocation getModifierLoc() const { return ModifierLoc; }
4301
4302 /// Gets location of ':' symbol in clause.
4303 SourceLocation getColonLoc() const { return ColonLoc; }
4304
4305 /// Gets the name info for specified reduction identifier.
4306 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
4307
4308 /// Gets the nested name specifier.
4309 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
4310
4311 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
4312 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
4313 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4314 using helper_expr_const_range =
4315 llvm::iterator_range<helper_expr_const_iterator>;
4316 using helper_flag_iterator = MutableArrayRef<bool>::iterator;
4317 using helper_flag_const_iterator = ArrayRef<bool>::iterator;
4318 using helper_flag_range = llvm::iterator_range<helper_flag_iterator>;
4319 using helper_flag_const_range =
4320 llvm::iterator_range<helper_flag_const_iterator>;
4321
4322 helper_expr_const_range privates() const { return getPrivates(); }
4323
4324 helper_expr_range privates() { return getPrivates(); }
4325
4326 helper_expr_const_range lhs_exprs() const { return getLHSExprs(); }
4327
4328 helper_expr_range lhs_exprs() { return getLHSExprs(); }
4329
4330 helper_expr_const_range rhs_exprs() const { return getRHSExprs(); }
4331
4332 helper_expr_range rhs_exprs() { return getRHSExprs(); }
4333
4334 helper_flag_const_range private_var_reduction_flags() const {
4335 return getPrivateVariableReductionFlags();
4336 }
4337
4338 helper_flag_range private_var_reduction_flags() {
4339 return getPrivateVariableReductionFlags();
4340 }
4341
4342 helper_expr_const_range reduction_ops() const { return getReductionOps(); }
4343
4344 helper_expr_range reduction_ops() { return getReductionOps(); }
4345
4346 helper_expr_const_range copy_ops() const { return getInscanCopyOps(); }
4347
4348 helper_expr_range copy_ops() { return getInscanCopyOps(); }
4349
4350 helper_expr_const_range copy_array_temps() const {
4351 return getInscanCopyArrayTemps();
4352 }
4353
4354 helper_expr_range copy_array_temps() { return getInscanCopyArrayTemps(); }
4355
4356 helper_expr_const_range copy_array_elems() const {
4357 return getInscanCopyArrayElems();
4358 }
4359
4360 helper_expr_range copy_array_elems() { return getInscanCopyArrayElems(); }
4361
4362 child_range children() {
4363 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4364 reinterpret_cast<Stmt **>(varlist_end()));
4365 }
4366
4367 const_child_range children() const {
4368 return const_cast<OMPReductionClause *>(this)->children();
4369 }
4370
4371 child_range used_children() {
4372 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4373 reinterpret_cast<Stmt **>(varlist_end()));
4374 }
4375 const_child_range used_children() const {
4376 return const_cast<OMPReductionClause *>(this)->used_children();
4377 }
4378
4379 static bool classof(const OMPClause *T) {
4380 return T->getClauseKind() == llvm::omp::OMPC_reduction;
4381 }
4382};
4383
4384/// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
4385/// directives.
4386///
4387/// \code
4388/// #pragma omp taskgroup task_reduction(+:a,b)
4389/// \endcode
4390/// In this example directive '#pragma omp taskgroup' has clause
4391/// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
4392class OMPTaskReductionClause final
4393 : public OMPVarListClause<OMPTaskReductionClause>,
4395 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
4396 friend class OMPClauseReader;
4397 friend OMPVarListClause;
4398 friend TrailingObjects;
4399
4400 /// Location of ':'.
4401 SourceLocation ColonLoc;
4402
4403 /// Nested name specifier for C++.
4404 NestedNameSpecifierLoc QualifierLoc;
4405
4406 /// Name of custom operator.
4407 DeclarationNameInfo NameInfo;
4408
4409 /// Build clause with number of variables \a N.
4410 ///
4411 /// \param StartLoc Starting location of the clause.
4412 /// \param LParenLoc Location of '('.
4413 /// \param EndLoc Ending location of the clause.
4414 /// \param ColonLoc Location of ':'.
4415 /// \param N Number of the variables in the clause.
4416 /// \param QualifierLoc The nested-name qualifier with location information
4417 /// \param NameInfo The full name info for reduction identifier.
4418 OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4419 SourceLocation ColonLoc, SourceLocation EndLoc,
4420 unsigned N, NestedNameSpecifierLoc QualifierLoc,
4421 const DeclarationNameInfo &NameInfo)
4422 : OMPVarListClause<OMPTaskReductionClause>(
4423 llvm::omp::OMPC_task_reduction, StartLoc, LParenLoc, EndLoc, N),
4424 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
4425 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
4426
4427 /// Build an empty clause.
4428 ///
4429 /// \param N Number of variables.
4430 explicit OMPTaskReductionClause(unsigned N)
4431 : OMPVarListClause<OMPTaskReductionClause>(
4432 llvm::omp::OMPC_task_reduction, SourceLocation(), SourceLocation(),
4433 SourceLocation(), N),
4434 OMPClauseWithPostUpdate(this) {}
4435
4436 /// Sets location of ':' symbol in clause.
4437 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
4438
4439 /// Sets the name info for specified reduction identifier.
4440 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
4441
4442 /// Sets the nested name specifier.
4443 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
4444
4445 /// Set list of helper expressions, required for proper codegen of the clause.
4446 /// These expressions represent private copy of the reduction variable.
4447 void setPrivates(ArrayRef<Expr *> Privates);
4448
4449 /// Get the list of helper privates.
4450 MutableArrayRef<Expr *> getPrivates() {
4451 return {varlist_end(), varlist_size()};
4452 }
4453 ArrayRef<const Expr *> getPrivates() const {
4454 return {varlist_end(), varlist_size()};
4455 }
4456
4457 /// Set list of helper expressions, required for proper codegen of the clause.
4458 /// These expressions represent LHS expression in the final reduction
4459 /// expression performed by the reduction clause.
4460 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
4461
4462 /// Get the list of helper LHS expressions.
4463 MutableArrayRef<Expr *> getLHSExprs() {
4464 return {getPrivates().end(), varlist_size()};
4465 }
4466 ArrayRef<const Expr *> getLHSExprs() const {
4467 return {getPrivates().end(), varlist_size()};
4468 }
4469
4470 /// Set list of helper expressions, required for proper codegen of the clause.
4471 /// These expressions represent RHS expression in the final reduction
4472 /// expression performed by the reduction clause. Also, variables in these
4473 /// expressions are used for proper initialization of reduction copies.
4474 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
4475
4476 /// Get the list of helper destination expressions.
4477 MutableArrayRef<Expr *> getRHSExprs() {
4478 return {getLHSExprs().end(), varlist_size()};
4479 }
4480 ArrayRef<const Expr *> getRHSExprs() const {
4481 return {getLHSExprs().end(), varlist_size()};
4482 }
4483
4484 /// Set list of helper reduction expressions, required for proper
4485 /// codegen of the clause. These expressions are binary expressions or
4486 /// operator/custom reduction call that calculates new value from source
4487 /// helper expressions to destination helper expressions.
4488 void setReductionOps(ArrayRef<Expr *> ReductionOps);
4489
4490 /// Get the list of helper reduction expressions.
4491 MutableArrayRef<Expr *> getReductionOps() {
4492 return {getRHSExprs().end(), varlist_size()};
4493 }
4494 ArrayRef<const Expr *> getReductionOps() const {
4495 return {getRHSExprs().end(), varlist_size()};
4496 }
4497
4498public:
4499 /// Creates clause with a list of variables \a VL.
4500 ///
4501 /// \param StartLoc Starting location of the clause.
4502 /// \param LParenLoc Location of '('.
4503 /// \param ColonLoc Location of ':'.
4504 /// \param EndLoc Ending location of the clause.
4505 /// \param VL The variables in the clause.
4506 /// \param QualifierLoc The nested-name qualifier with location information
4507 /// \param NameInfo The full name info for reduction identifier.
4508 /// \param Privates List of helper expressions for proper generation of
4509 /// private copies.
4510 /// \param LHSExprs List of helper expressions for proper generation of
4511 /// assignment operation required for copyprivate clause. This list represents
4512 /// LHSs of the reduction expressions.
4513 /// \param RHSExprs List of helper expressions for proper generation of
4514 /// assignment operation required for copyprivate clause. This list represents
4515 /// RHSs of the reduction expressions.
4516 /// Also, variables in these expressions are used for proper initialization of
4517 /// reduction copies.
4518 /// \param ReductionOps List of helper expressions that represents reduction
4519 /// expressions:
4520 /// \code
4521 /// LHSExprs binop RHSExprs;
4522 /// operator binop(LHSExpr, RHSExpr);
4523 /// <CutomReduction>(LHSExpr, RHSExpr);
4524 /// \endcode
4525 /// Required for proper codegen of final reduction operation performed by the
4526 /// reduction clause.
4527 /// \param PreInit Statement that must be executed before entering the OpenMP
4528 /// region with this clause.
4529 /// \param PostUpdate Expression that must be executed after exit from the
4530 /// OpenMP region with this clause.
4531 static OMPTaskReductionClause *
4532 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4533 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
4534 NestedNameSpecifierLoc QualifierLoc,
4535 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
4536 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
4537 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
4538
4539 /// Creates an empty clause with the place for \a N variables.
4540 ///
4541 /// \param C AST context.
4542 /// \param N The number of variables.
4543 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
4544
4545 /// Gets location of ':' symbol in clause.
4546 SourceLocation getColonLoc() const { return ColonLoc; }
4547
4548 /// Gets the name info for specified reduction identifier.
4549 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
4550
4551 /// Gets the nested name specifier.
4552 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
4553
4554 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
4555 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
4556 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4557 using helper_expr_const_range =
4558 llvm::iterator_range<helper_expr_const_iterator>;
4559
4560 helper_expr_const_range privates() const { return getPrivates(); }
4561
4562 helper_expr_range privates() { return getPrivates(); }
4563
4564 helper_expr_const_range lhs_exprs() const { return getLHSExprs(); }
4565
4566 helper_expr_range lhs_exprs() { return getLHSExprs(); }
4567
4568 helper_expr_const_range rhs_exprs() const { return getRHSExprs(); }
4569
4570 helper_expr_range rhs_exprs() { return getRHSExprs(); }
4571
4572 helper_expr_const_range reduction_ops() const { return getReductionOps(); }
4573
4574 helper_expr_range reduction_ops() { return getReductionOps(); }
4575
4576 child_range children() {
4577 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4578 reinterpret_cast<Stmt **>(varlist_end()));
4579 }
4580
4581 const_child_range children() const {
4582 return const_cast<OMPTaskReductionClause *>(this)->children();
4583 }
4584
4585 child_range used_children() {
4586 return child_range(child_iterator(), child_iterator());
4587 }
4588 const_child_range used_children() const {
4589 return const_child_range(const_child_iterator(), const_child_iterator());
4590 }
4591
4592 static bool classof(const OMPClause *T) {
4593 return T->getClauseKind() == llvm::omp::OMPC_task_reduction;
4594 }
4595};
4596
4597/// This represents clause 'in_reduction' in the '#pragma omp task' directives.
4598///
4599/// \code
4600/// #pragma omp task in_reduction(+:a,b)
4601/// \endcode
4602/// In this example directive '#pragma omp task' has clause 'in_reduction' with
4603/// operator '+' and the variables 'a' and 'b'.
4604class OMPInReductionClause final
4605 : public OMPVarListClause<OMPInReductionClause>,
4607 private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
4608 friend class OMPClauseReader;
4609 friend OMPVarListClause;
4610 friend TrailingObjects;
4611
4612 /// Location of ':'.
4613 SourceLocation ColonLoc;
4614
4615 /// Nested name specifier for C++.
4616 NestedNameSpecifierLoc QualifierLoc;
4617
4618 /// Name of custom operator.
4619 DeclarationNameInfo NameInfo;
4620
4621 /// Build clause with number of variables \a N.
4622 ///
4623 /// \param StartLoc Starting location of the clause.
4624 /// \param LParenLoc Location of '('.
4625 /// \param EndLoc Ending location of the clause.
4626 /// \param ColonLoc Location of ':'.
4627 /// \param N Number of the variables in the clause.
4628 /// \param QualifierLoc The nested-name qualifier with location information
4629 /// \param NameInfo The full name info for reduction identifier.
4630 OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4631 SourceLocation ColonLoc, SourceLocation EndLoc,
4632 unsigned N, NestedNameSpecifierLoc QualifierLoc,
4633 const DeclarationNameInfo &NameInfo)
4634 : OMPVarListClause<OMPInReductionClause>(llvm::omp::OMPC_in_reduction,
4635 StartLoc, LParenLoc, EndLoc, N),
4636 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
4637 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
4638
4639 /// Build an empty clause.
4640 ///
4641 /// \param N Number of variables.
4642 explicit OMPInReductionClause(unsigned N)
4643 : OMPVarListClause<OMPInReductionClause>(
4644 llvm::omp::OMPC_in_reduction, SourceLocation(), SourceLocation(),
4645 SourceLocation(), N),
4646 OMPClauseWithPostUpdate(this) {}
4647
4648 /// Sets location of ':' symbol in clause.
4649 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
4650
4651 /// Sets the name info for specified reduction identifier.
4652 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
4653
4654 /// Sets the nested name specifier.
4655 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
4656
4657 /// Set list of helper expressions, required for proper codegen of the clause.
4658 /// These expressions represent private copy of the reduction variable.
4659 void setPrivates(ArrayRef<Expr *> Privates);
4660
4661 /// Get the list of helper privates.
4662 MutableArrayRef<Expr *> getPrivates() {
4663 return {varlist_end(), varlist_size()};
4664 }
4665 ArrayRef<const Expr *> getPrivates() const {
4666 return {varlist_end(), varlist_size()};
4667 }
4668
4669 /// Set list of helper expressions, required for proper codegen of the clause.
4670 /// These expressions represent LHS expression in the final reduction
4671 /// expression performed by the reduction clause.
4672 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
4673
4674 /// Get the list of helper LHS expressions.
4675 MutableArrayRef<Expr *> getLHSExprs() {
4676 return {getPrivates().end(), varlist_size()};
4677 }
4678 ArrayRef<const Expr *> getLHSExprs() const {
4679 return {getPrivates().end(), varlist_size()};
4680 }
4681
4682 /// Set list of helper expressions, required for proper codegen of the clause.
4683 /// These expressions represent RHS expression in the final reduction
4684 /// expression performed by the reduction clause. Also, variables in these
4685 /// expressions are used for proper initialization of reduction copies.
4686 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
4687
4688 /// Get the list of helper destination expressions.
4689 MutableArrayRef<Expr *> getRHSExprs() {
4690 return {getLHSExprs().end(), varlist_size()};
4691 }
4692 ArrayRef<const Expr *> getRHSExprs() const {
4693 return {getLHSExprs().end(), varlist_size()};
4694 }
4695
4696 /// Set list of helper reduction expressions, required for proper
4697 /// codegen of the clause. These expressions are binary expressions or
4698 /// operator/custom reduction call that calculates new value from source
4699 /// helper expressions to destination helper expressions.
4700 void setReductionOps(ArrayRef<Expr *> ReductionOps);
4701
4702 /// Get the list of helper reduction expressions.
4703 MutableArrayRef<Expr *> getReductionOps() {
4704 return {getRHSExprs().end(), varlist_size()};
4705 }
4706 ArrayRef<const Expr *> getReductionOps() const {
4707 return {getRHSExprs().end(), varlist_size()};
4708 }
4709
4710 /// Set list of helper reduction taskgroup descriptors.
4711 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
4712
4713 /// Get the list of helper reduction taskgroup descriptors.
4714 MutableArrayRef<Expr *> getTaskgroupDescriptors() {
4715 return {getReductionOps().end(), varlist_size()};
4716 }
4717 ArrayRef<const Expr *> getTaskgroupDescriptors() const {
4718 return {getReductionOps().end(), varlist_size()};
4719 }
4720
4721public:
4722 /// Creates clause with a list of variables \a VL.
4723 ///
4724 /// \param StartLoc Starting location of the clause.
4725 /// \param LParenLoc Location of '('.
4726 /// \param ColonLoc Location of ':'.
4727 /// \param EndLoc Ending location of the clause.
4728 /// \param VL The variables in the clause.
4729 /// \param QualifierLoc The nested-name qualifier with location information
4730 /// \param NameInfo The full name info for reduction identifier.
4731 /// \param Privates List of helper expressions for proper generation of
4732 /// private copies.
4733 /// \param LHSExprs List of helper expressions for proper generation of
4734 /// assignment operation required for copyprivate clause. This list represents
4735 /// LHSs of the reduction expressions.
4736 /// \param RHSExprs List of helper expressions for proper generation of
4737 /// assignment operation required for copyprivate clause. This list represents
4738 /// RHSs of the reduction expressions.
4739 /// Also, variables in these expressions are used for proper initialization of
4740 /// reduction copies.
4741 /// \param ReductionOps List of helper expressions that represents reduction
4742 /// expressions:
4743 /// \code
4744 /// LHSExprs binop RHSExprs;
4745 /// operator binop(LHSExpr, RHSExpr);
4746 /// <CutomReduction>(LHSExpr, RHSExpr);
4747 /// \endcode
4748 /// Required for proper codegen of final reduction operation performed by the
4749 /// reduction clause.
4750 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
4751 /// corresponding items in parent taskgroup task_reduction clause.
4752 /// \param PreInit Statement that must be executed before entering the OpenMP
4753 /// region with this clause.
4754 /// \param PostUpdate Expression that must be executed after exit from the
4755 /// OpenMP region with this clause.
4756 static OMPInReductionClause *
4757 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4758 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
4759 NestedNameSpecifierLoc QualifierLoc,
4760 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
4761 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
4762 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
4763 Stmt *PreInit, Expr *PostUpdate);
4764
4765 /// Creates an empty clause with the place for \a N variables.
4766 ///
4767 /// \param C AST context.
4768 /// \param N The number of variables.
4769 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
4770
4771 /// Gets location of ':' symbol in clause.
4772 SourceLocation getColonLoc() const { return ColonLoc; }
4773
4774 /// Gets the name info for specified reduction identifier.
4775 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
4776
4777 /// Gets the nested name specifier.
4778 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
4779
4780 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
4781 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
4782 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4783 using helper_expr_const_range =
4784 llvm::iterator_range<helper_expr_const_iterator>;
4785
4786 helper_expr_const_range privates() const { return getPrivates(); }
4787
4788 helper_expr_range privates() { return getPrivates(); }
4789
4790 helper_expr_const_range lhs_exprs() const { return getLHSExprs(); }
4791
4792 helper_expr_range lhs_exprs() { return getLHSExprs(); }
4793
4794 helper_expr_const_range rhs_exprs() const { return getRHSExprs(); }
4795
4796 helper_expr_range rhs_exprs() { return getRHSExprs(); }
4797
4798 helper_expr_const_range reduction_ops() const { return getReductionOps(); }
4799
4800 helper_expr_range reduction_ops() { return getReductionOps(); }
4801
4802 helper_expr_const_range taskgroup_descriptors() const {
4803 return getTaskgroupDescriptors();
4804 }
4805
4806 helper_expr_range taskgroup_descriptors() {
4807 return getTaskgroupDescriptors();
4808 }
4809
4810 child_range children() {
4811 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4812 reinterpret_cast<Stmt **>(varlist_end()));
4813 }
4814
4815 const_child_range children() const {
4816 return const_cast<OMPInReductionClause *>(this)->children();
4817 }
4818
4819 child_range used_children() {
4820 return child_range(child_iterator(), child_iterator());
4821 }
4822 const_child_range used_children() const {
4823 return const_child_range(const_child_iterator(), const_child_iterator());
4824 }
4825
4826 static bool classof(const OMPClause *T) {
4827 return T->getClauseKind() == llvm::omp::OMPC_in_reduction;
4828 }
4829};
4830
4831/// This represents clause 'linear' in the '#pragma omp ...'
4832/// directives.
4833///
4834/// \code
4835/// #pragma omp simd linear(a,b : 2)
4836/// \endcode
4837/// In this example directive '#pragma omp simd' has clause 'linear'
4838/// with variables 'a', 'b' and linear step '2'.
4839class OMPLinearClause final
4840 : public OMPVarListClause<OMPLinearClause>,
4842 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
4843 friend class OMPClauseReader;
4844 friend OMPVarListClause;
4845 friend TrailingObjects;
4846
4847 /// Modifier of 'linear' clause.
4848 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
4849
4850 /// Location of linear modifier if any.
4851 SourceLocation ModifierLoc;
4852
4853 /// Location of ':'.
4854 SourceLocation ColonLoc;
4855
4856 /// Location of 'step' modifier.
4857 SourceLocation StepModifierLoc;
4858
4859 /// Sets the linear step for clause.
4860 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
4861
4862 /// Sets the expression to calculate linear step for clause.
4863 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
4864
4865 /// Build 'linear' clause with given number of variables \a NumVars.
4866 ///
4867 /// \param StartLoc Starting location of the clause.
4868 /// \param LParenLoc Location of '('.
4869 /// \param ColonLoc Location of ':'.
4870 /// \param StepModifierLoc Location of 'step' modifier.
4871 /// \param EndLoc Ending location of the clause.
4872 /// \param NumVars Number of variables.
4873 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4874 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
4875 SourceLocation ColonLoc, SourceLocation StepModifierLoc,
4876 SourceLocation EndLoc, unsigned NumVars)
4877 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, StartLoc,
4878 LParenLoc, EndLoc, NumVars),
4879 OMPClauseWithPostUpdate(this), Modifier(Modifier),
4880 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
4881 StepModifierLoc(StepModifierLoc) {}
4882
4883 /// Build an empty clause.
4884 ///
4885 /// \param NumVars Number of variables.
4886 explicit OMPLinearClause(unsigned NumVars)
4887 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear,
4888 SourceLocation(), SourceLocation(),
4889 SourceLocation(), NumVars),
4890 OMPClauseWithPostUpdate(this) {}
4891
4892 /// Gets the list of initial values for linear variables.
4893 ///
4894 /// There are NumVars expressions with initial values allocated after the
4895 /// varlist, they are followed by NumVars update expressions (used to update
4896 /// the linear variable's value on current iteration) and they are followed by
4897 /// NumVars final expressions (used to calculate the linear variable's
4898 /// value after the loop body). After these lists, there are 2 helper
4899 /// expressions - linear step and a helper to calculate it before the
4900 /// loop body (used when the linear step is not constant):
4901 ///
4902 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
4903 /// Finals[]; Step; CalcStep; }
4905 return {varlist_end(), varlist_size()};
4906 }
4907 ArrayRef<const Expr *> getPrivates() const {
4908 return {varlist_end(), varlist_size()};
4909 }
4910
4912 return {getPrivates().end(), varlist_size()};
4913 }
4914 ArrayRef<const Expr *> getInits() const {
4915 return {getPrivates().end(), varlist_size()};
4916 }
4917
4918 /// Sets the list of update expressions for linear variables.
4920 return {getInits().end(), varlist_size()};
4921 }
4922 ArrayRef<const Expr *> getUpdates() const {
4923 return {getInits().end(), varlist_size()};
4924 }
4925
4926 /// Sets the list of final update expressions for linear variables.
4928 return {getUpdates().end(), varlist_size()};
4929 }
4930 ArrayRef<const Expr *> getFinals() const {
4931 return {getUpdates().end(), varlist_size()};
4932 }
4933
4934 /// Gets the list of used expressions for linear variables.
4936 return {getFinals().end() + 2, varlist_size() + 1};
4937 }
4938 ArrayRef<const Expr *> getUsedExprs() const {
4939 return {getFinals().end() + 2, varlist_size() + 1};
4940 }
4941
4942 /// Sets the list of the copies of original linear variables.
4943 /// \param PL List of expressions.
4944 void setPrivates(ArrayRef<Expr *> PL);
4945
4946 /// Sets the list of the initial values for linear variables.
4947 /// \param IL List of expressions.
4949
4950public:
4951 /// Creates clause with a list of variables \a VL and a linear step
4952 /// \a Step.
4953 ///
4954 /// \param C AST Context.
4955 /// \param StartLoc Starting location of the clause.
4956 /// \param LParenLoc Location of '('.
4957 /// \param Modifier Modifier of 'linear' clause.
4958 /// \param ModifierLoc Modifier location.
4959 /// \param ColonLoc Location of ':'.
4960 /// \param StepModifierLoc Location of 'step' modifier.
4961 /// \param EndLoc Ending location of the clause.
4962 /// \param VL List of references to the variables.
4963 /// \param PL List of private copies of original variables.
4964 /// \param IL List of initial values for the variables.
4965 /// \param Step Linear step.
4966 /// \param CalcStep Calculation of the linear step.
4967 /// \param PreInit Statement that must be executed before entering the OpenMP
4968 /// region with this clause.
4969 /// \param PostUpdate Expression that must be executed after exit from the
4970 /// OpenMP region with this clause.
4971 static OMPLinearClause *
4972 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4973 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
4974 SourceLocation ColonLoc, SourceLocation StepModifierLoc,
4976 ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit,
4977 Expr *PostUpdate);
4978
4979 /// Creates an empty clause with the place for \a NumVars variables.
4980 ///
4981 /// \param C AST context.
4982 /// \param NumVars Number of variables.
4983 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
4984
4985 /// Set modifier.
4986 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
4987
4988 /// Return modifier.
4989 OpenMPLinearClauseKind getModifier() const { return Modifier; }
4990
4991 /// Set modifier location.
4992 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
4993
4994 /// Return modifier location.
4995 SourceLocation getModifierLoc() const { return ModifierLoc; }
4996
4997 /// Sets the location of ':'.
4998 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4999
5000 /// Sets the location of 'step' modifier.
5001 void setStepModifierLoc(SourceLocation Loc) { StepModifierLoc = Loc; }
5002
5003 /// Returns the location of ':'.
5004 SourceLocation getColonLoc() const { return ColonLoc; }
5005
5006 /// Returns the location of 'step' modifier.
5007 SourceLocation getStepModifierLoc() const { return StepModifierLoc; }
5008
5009 /// Returns linear step.
5010 Expr *getStep() { return *(getFinals().end()); }
5011
5012 /// Returns linear step.
5013 const Expr *getStep() const { return *(getFinals().end()); }
5014
5015 /// Returns expression to calculate linear step.
5016 Expr *getCalcStep() { return *(getFinals().end() + 1); }
5017
5018 /// Returns expression to calculate linear step.
5019 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
5020
5021 /// Sets the list of update expressions for linear variables.
5022 /// \param UL List of expressions.
5023 void setUpdates(ArrayRef<Expr *> UL);
5024
5025 /// Sets the list of final update expressions for linear variables.
5026 /// \param FL List of expressions.
5027 void setFinals(ArrayRef<Expr *> FL);
5028
5029 /// Sets the list of used expressions for the linear clause.
5030 void setUsedExprs(ArrayRef<Expr *> UE);
5031
5034 using privates_range = llvm::iterator_range<privates_iterator>;
5035 using privates_const_range = llvm::iterator_range<privates_const_iterator>;
5036
5038
5039 privates_const_range privates() const { return getPrivates(); }
5040
5043 using inits_range = llvm::iterator_range<inits_iterator>;
5044 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
5045
5047
5048 inits_const_range inits() const { return getInits(); }
5049
5052 using updates_range = llvm::iterator_range<updates_iterator>;
5053 using updates_const_range = llvm::iterator_range<updates_const_iterator>;
5054
5056
5057 updates_const_range updates() const { return getUpdates(); }
5058
5061 using finals_range = llvm::iterator_range<finals_iterator>;
5062 using finals_const_range = llvm::iterator_range<finals_const_iterator>;
5063
5065
5066 finals_const_range finals() const { return getFinals(); }
5067
5071 llvm::iterator_range<used_expressions_iterator>;
5073 llvm::iterator_range<used_expressions_const_iterator>;
5074
5078
5079 used_expressions_const_range used_expressions() const {
5080 return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
5081 }
5082
5083 child_range children() {
5084 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5085 reinterpret_cast<Stmt **>(varlist_end()));
5086 }
5087
5088 const_child_range children() const {
5089 return const_cast<OMPLinearClause *>(this)->children();
5090 }
5091
5092 child_range used_children();
5093
5094 const_child_range used_children() const {
5095 return const_cast<OMPLinearClause *>(this)->used_children();
5096 }
5097
5098 static bool classof(const OMPClause *T) {
5099 return T->getClauseKind() == llvm::omp::OMPC_linear;
5100 }
5101};
5102
5103/// This represents clause 'aligned' in the '#pragma omp ...'
5104/// directives.
5105///
5106/// \code
5107/// #pragma omp simd aligned(a,b : 8)
5108/// \endcode
5109/// In this example directive '#pragma omp simd' has clause 'aligned'
5110/// with variables 'a', 'b' and alignment '8'.
5111class OMPAlignedClause final
5112 : public OMPVarListClause<OMPAlignedClause>,
5113 private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
5114 friend class OMPClauseReader;
5115 friend OMPVarListClause;
5116 friend TrailingObjects;
5117
5118 /// Location of ':'.
5119 SourceLocation ColonLoc;
5120
5121 /// Sets the alignment for clause.
5122 void setAlignment(Expr *A) { *varlist_end() = A; }
5123
5124 /// Build 'aligned' clause with given number of variables \a NumVars.
5125 ///
5126 /// \param StartLoc Starting location of the clause.
5127 /// \param LParenLoc Location of '('.
5128 /// \param ColonLoc Location of ':'.
5129 /// \param EndLoc Ending location of the clause.
5130 /// \param NumVars Number of variables.
5131 OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5132 SourceLocation ColonLoc, SourceLocation EndLoc,
5133 unsigned NumVars)
5134 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, StartLoc,
5135 LParenLoc, EndLoc, NumVars),
5136 ColonLoc(ColonLoc) {}
5137
5138 /// Build an empty clause.
5139 ///
5140 /// \param NumVars Number of variables.
5141 explicit OMPAlignedClause(unsigned NumVars)
5142 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned,
5143 SourceLocation(), SourceLocation(),
5144 SourceLocation(), NumVars) {}
5145
5146public:
5147 /// Creates clause with a list of variables \a VL and alignment \a A.
5148 ///
5149 /// \param C AST Context.
5150 /// \param StartLoc Starting location of the clause.
5151 /// \param LParenLoc Location of '('.
5152 /// \param ColonLoc Location of ':'.
5153 /// \param EndLoc Ending location of the clause.
5154 /// \param VL List of references to the variables.
5155 /// \param A Alignment.
5156 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
5157 SourceLocation LParenLoc,
5158 SourceLocation ColonLoc,
5159 SourceLocation EndLoc, ArrayRef<Expr *> VL,
5160 Expr *A);
5161
5162 /// Creates an empty clause with the place for \a NumVars variables.
5163 ///
5164 /// \param C AST context.
5165 /// \param NumVars Number of variables.
5166 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
5167
5168 /// Sets the location of ':'.
5169 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
5170
5171 /// Returns the location of ':'.
5172 SourceLocation getColonLoc() const { return ColonLoc; }
5173
5174 /// Returns alignment.
5175 Expr *getAlignment() { return *varlist_end(); }
5176
5177 /// Returns alignment.
5178 const Expr *getAlignment() const { return *varlist_end(); }
5179
5180 child_range children() {
5181 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5182 reinterpret_cast<Stmt **>(varlist_end()));
5183 }
5184
5185 const_child_range children() const {
5186 return const_cast<OMPAlignedClause *>(this)->children();
5187 }
5188
5189 child_range used_children() {
5190 return child_range(child_iterator(), child_iterator());
5191 }
5192 const_child_range used_children() const {
5193 return const_child_range(const_child_iterator(), const_child_iterator());
5194 }
5195
5196 static bool classof(const OMPClause *T) {
5197 return T->getClauseKind() == llvm::omp::OMPC_aligned;
5198 }
5199};
5200
5201/// This represents clause 'copyin' in the '#pragma omp ...' directives.
5202///
5203/// \code
5204/// #pragma omp parallel copyin(a,b)
5205/// \endcode
5206/// In this example directive '#pragma omp parallel' has clause 'copyin'
5207/// with the variables 'a' and 'b'.
5208class OMPCopyinClause final
5209 : public OMPVarListClause<OMPCopyinClause>,
5210 private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
5211 // Class has 3 additional tail allocated arrays:
5212 // 1. List of helper expressions for proper generation of assignment operation
5213 // required for copyin clause. This list represents sources.
5214 // 2. List of helper expressions for proper generation of assignment operation
5215 // required for copyin clause. This list represents destinations.
5216 // 3. List of helper expressions that represents assignment operation:
5217 // \code
5218 // DstExprs = SrcExprs;
5219 // \endcode
5220 // Required for proper codegen of propagation of master's thread values of
5221 // threadprivate variables to local instances of that variables in other
5222 // implicit threads.
5223
5224 friend class OMPClauseReader;
5225 friend OMPVarListClause;
5226 friend TrailingObjects;
5227
5228 /// Build clause with number of variables \a N.
5229 ///
5230 /// \param StartLoc Starting location of the clause.
5231 /// \param LParenLoc Location of '('.
5232 /// \param EndLoc Ending location of the clause.
5233 /// \param N Number of the variables in the clause.
5234 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5235 SourceLocation EndLoc, unsigned N)
5236 : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin, StartLoc,
5237 LParenLoc, EndLoc, N) {}
5238
5239 /// Build an empty clause.
5240 ///
5241 /// \param N Number of variables.
5242 explicit OMPCopyinClause(unsigned N)
5243 : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin,
5244 SourceLocation(), SourceLocation(),
5245 SourceLocation(), N) {}
5246
5247 /// Set list of helper expressions, required for proper codegen of the
5248 /// clause. These expressions represent source expression in the final
5249 /// assignment statement performed by the copyin clause.
5250 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
5251
5252 /// Get the list of helper source expressions.
5253 MutableArrayRef<Expr *> getSourceExprs() {
5254 return {varlist_end(), varlist_size()};
5255 }
5256 ArrayRef<const Expr *> getSourceExprs() const {
5257 return {varlist_end(), varlist_size()};
5258 }
5259
5260 /// Set list of helper expressions, required for proper codegen of the
5261 /// clause. These expressions represent destination expression in the final
5262 /// assignment statement performed by the copyin clause.
5263 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
5264
5265 /// Get the list of helper destination expressions.
5266 MutableArrayRef<Expr *> getDestinationExprs() {
5267 return {getSourceExprs().end(), varlist_size()};
5268 }
5269 ArrayRef<const Expr *> getDestinationExprs() const {
5270 return {getSourceExprs().end(), varlist_size()};
5271 }
5272
5273 /// Set list of helper assignment expressions, required for proper
5274 /// codegen of the clause. These expressions are assignment expressions that
5275 /// assign source helper expressions to destination helper expressions
5276 /// correspondingly.
5277 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
5278
5279 /// Get the list of helper assignment expressions.
5280 MutableArrayRef<Expr *> getAssignmentOps() {
5281 return {getDestinationExprs().end(), varlist_size()};
5282 }
5283 ArrayRef<const Expr *> getAssignmentOps() const {
5284 return {getDestinationExprs().end(), varlist_size()};
5285 }
5286
5287public:
5288 /// Creates clause with a list of variables \a VL.
5289 ///
5290 /// \param C AST context.
5291 /// \param StartLoc Starting location of the clause.
5292 /// \param LParenLoc Location of '('.
5293 /// \param EndLoc Ending location of the clause.
5294 /// \param VL List of references to the variables.
5295 /// \param SrcExprs List of helper expressions for proper generation of
5296 /// assignment operation required for copyin clause. This list represents
5297 /// sources.
5298 /// \param DstExprs List of helper expressions for proper generation of
5299 /// assignment operation required for copyin clause. This list represents
5300 /// destinations.
5301 /// \param AssignmentOps List of helper expressions that represents assignment
5302 /// operation:
5303 /// \code
5304 /// DstExprs = SrcExprs;
5305 /// \endcode
5306 /// Required for proper codegen of propagation of master's thread values of
5307 /// threadprivate variables to local instances of that variables in other
5308 /// implicit threads.
5309 static OMPCopyinClause *
5310 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
5311 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
5312 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
5313
5314 /// Creates an empty clause with \a N variables.
5315 ///
5316 /// \param C AST context.
5317 /// \param N The number of variables.
5318 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
5319
5320 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
5322 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
5324 llvm::iterator_range<helper_expr_const_iterator>;
5325
5326 helper_expr_const_range source_exprs() const { return getSourceExprs(); }
5327
5328 helper_expr_range source_exprs() { return getSourceExprs(); }
5329
5331 return getDestinationExprs();
5332 }
5333
5334 helper_expr_range destination_exprs() { return getDestinationExprs(); }
5335
5336 helper_expr_const_range assignment_ops() const { return getAssignmentOps(); }
5337
5338 helper_expr_range assignment_ops() { return getAssignmentOps(); }
5339
5340 child_range children() {
5341 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5342 reinterpret_cast<Stmt **>(varlist_end()));
5343 }
5344
5345 const_child_range children() const {
5346 return const_cast<OMPCopyinClause *>(this)->children();
5347 }
5348
5349 child_range used_children() {
5350 return child_range(child_iterator(), child_iterator());
5351 }
5352 const_child_range used_children() const {
5353 return const_child_range(const_child_iterator(), const_child_iterator());
5354 }
5355
5356 static bool classof(const OMPClause *T) {
5357 return T->getClauseKind() == llvm::omp::OMPC_copyin;
5358 }
5359};
5360
5361/// This represents clause 'copyprivate' in the '#pragma omp ...'
5362/// directives.
5363///
5364/// \code
5365/// #pragma omp single copyprivate(a,b)
5366/// \endcode
5367/// In this example directive '#pragma omp single' has clause 'copyprivate'
5368/// with the variables 'a' and 'b'.
5369class OMPCopyprivateClause final
5370 : public OMPVarListClause<OMPCopyprivateClause>,
5371 private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
5372 friend class OMPClauseReader;
5373 friend OMPVarListClause;
5374 friend TrailingObjects;
5375
5376 /// Build clause with number of variables \a N.
5377 ///
5378 /// \param StartLoc Starting location of the clause.
5379 /// \param LParenLoc Location of '('.
5380 /// \param EndLoc Ending location of the clause.
5381 /// \param N Number of the variables in the clause.
5382 OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5383 SourceLocation EndLoc, unsigned N)
5384 : OMPVarListClause<OMPCopyprivateClause>(llvm::omp::OMPC_copyprivate,
5385 StartLoc, LParenLoc, EndLoc, N) {
5386 }
5387
5388 /// Build an empty clause.
5389 ///
5390 /// \param N Number of variables.
5391 explicit OMPCopyprivateClause(unsigned N)
5392 : OMPVarListClause<OMPCopyprivateClause>(
5393 llvm::omp::OMPC_copyprivate, SourceLocation(), SourceLocation(),
5394 SourceLocation(), N) {}
5395
5396 /// Set list of helper expressions, required for proper codegen of the
5397 /// clause. These expressions represent source expression in the final
5398 /// assignment statement performed by the copyprivate clause.
5399 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
5400
5401 /// Get the list of helper source expressions.
5402 MutableArrayRef<Expr *> getSourceExprs() {
5403 return {varlist_end(), varlist_size()};
5404 }
5405 ArrayRef<const Expr *> getSourceExprs() const {
5406 return {varlist_end(), varlist_size()};
5407 }
5408
5409 /// Set list of helper expressions, required for proper codegen of the
5410 /// clause. These expressions represent destination expression in the final
5411 /// assignment statement performed by the copyprivate clause.
5412 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
5413
5414 /// Get the list of helper destination expressions.
5415 MutableArrayRef<Expr *> getDestinationExprs() {
5416 return {getSourceExprs().end(), varlist_size()};
5417 }
5418 ArrayRef<const Expr *> getDestinationExprs() const {
5419 return {getSourceExprs().end(), varlist_size()};
5420 }
5421
5422 /// Set list of helper assignment expressions, required for proper
5423 /// codegen of the clause. These expressions are assignment expressions that
5424 /// assign source helper expressions to destination helper expressions
5425 /// correspondingly.
5426 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
5427
5428 /// Get the list of helper assignment expressions.
5429 MutableArrayRef<Expr *> getAssignmentOps() {
5430 return {getDestinationExprs().end(), varlist_size()};
5431 }
5432 ArrayRef<const Expr *> getAssignmentOps() const {
5433 return {getDestinationExprs().end(), varlist_size()};
5434 }
5435
5436public:
5437 /// Creates clause with a list of variables \a VL.
5438 ///
5439 /// \param C AST context.
5440 /// \param StartLoc Starting location of the clause.
5441 /// \param LParenLoc Location of '('.
5442 /// \param EndLoc Ending location of the clause.
5443 /// \param VL List of references to the variables.
5444 /// \param SrcExprs List of helper expressions for proper generation of
5445 /// assignment operation required for copyprivate clause. This list represents
5446 /// sources.
5447 /// \param DstExprs List of helper expressions for proper generation of
5448 /// assignment operation required for copyprivate clause. This list represents
5449 /// destinations.
5450 /// \param AssignmentOps List of helper expressions that represents assignment
5451 /// operation:
5452 /// \code
5453 /// DstExprs = SrcExprs;
5454 /// \endcode
5455 /// Required for proper codegen of final assignment performed by the
5456 /// copyprivate clause.
5457 static OMPCopyprivateClause *
5458 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
5459 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
5460 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
5461
5462 /// Creates an empty clause with \a N variables.
5463 ///
5464 /// \param C AST context.
5465 /// \param N The number of variables.
5466 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
5467
5468 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
5470 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
5472 llvm::iterator_range<helper_expr_const_iterator>;
5473
5474 helper_expr_const_range source_exprs() const { return getSourceExprs(); }
5475
5476 helper_expr_range source_exprs() { return getSourceExprs(); }
5477
5479 return getDestinationExprs();
5480 }
5481
5482 helper_expr_range destination_exprs() { return getDestinationExprs(); }
5483
5484 helper_expr_const_range assignment_ops() const { return getAssignmentOps(); }
5485
5486 helper_expr_range assignment_ops() { return getAssignmentOps(); }
5487
5488 child_range children() {
5489 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5490 reinterpret_cast<Stmt **>(varlist_end()));
5491 }
5492
5493 const_child_range children() const {
5494 return const_cast<OMPCopyprivateClause *>(this)->children();
5495 }
5496
5497 child_range used_children() {
5498 return child_range(child_iterator(), child_iterator());
5499 }
5500 const_child_range used_children() const {
5501 return const_child_range(const_child_iterator(), const_child_iterator());
5502 }
5503
5504 static bool classof(const OMPClause *T) {
5505 return T->getClauseKind() == llvm::omp::OMPC_copyprivate;
5506 }
5507};
5508
5509/// This represents implicit clause 'flush' for the '#pragma omp flush'
5510/// directive.
5511/// This clause does not exist by itself, it can be only as a part of 'omp
5512/// flush' directive. This clause is introduced to keep the original structure
5513/// of \a OMPExecutableDirective class and its derivatives and to use the
5514/// existing infrastructure of clauses with the list of variables.
5515///
5516/// \code
5517/// #pragma omp flush(a,b)
5518/// \endcode
5519/// In this example directive '#pragma omp flush' has implicit clause 'flush'
5520/// with the variables 'a' and 'b'.
5521class OMPFlushClause final
5522 : public OMPVarListClause<OMPFlushClause>,
5523 private llvm::TrailingObjects<OMPFlushClause, Expr *> {
5524 friend OMPVarListClause;
5525 friend TrailingObjects;
5526
5527 /// Build clause with number of variables \a N.
5528 ///
5529 /// \param StartLoc Starting location of the clause.
5530 /// \param LParenLoc Location of '('.
5531 /// \param EndLoc Ending location of the clause.
5532 /// \param N Number of the variables in the clause.
5533 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5534 SourceLocation EndLoc, unsigned N)
5535 : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush, StartLoc,
5536 LParenLoc, EndLoc, N) {}
5537
5538 /// Build an empty clause.
5539 ///
5540 /// \param N Number of variables.
5541 explicit OMPFlushClause(unsigned N)
5542 : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush,
5543 SourceLocation(), SourceLocation(),
5544 SourceLocation(), N) {}
5545
5546public:
5547 /// Creates clause with a list of variables \a VL.
5548 ///
5549 /// \param C AST context.
5550 /// \param StartLoc Starting location of the clause.
5551 /// \param LParenLoc Location of '('.
5552 /// \param EndLoc Ending location of the clause.
5553 /// \param VL List of references to the variables.
5554 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
5555 SourceLocation LParenLoc, SourceLocation EndLoc,
5556 ArrayRef<Expr *> VL);
5557
5558 /// Creates an empty clause with \a N variables.
5559 ///
5560 /// \param C AST context.
5561 /// \param N The number of variables.
5562 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
5563
5564 child_range children() {
5565 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5566 reinterpret_cast<Stmt **>(varlist_end()));
5567 }
5568
5569 const_child_range children() const {
5570 return const_cast<OMPFlushClause *>(this)->children();
5571 }
5572
5573 child_range used_children() {
5574 return child_range(child_iterator(), child_iterator());
5575 }
5576 const_child_range used_children() const {
5577 return const_child_range(const_child_iterator(), const_child_iterator());
5578 }
5579
5580 static bool classof(const OMPClause *T) {
5581 return T->getClauseKind() == llvm::omp::OMPC_flush;
5582 }
5583};
5584
5585/// This represents implicit clause 'depobj' for the '#pragma omp depobj'
5586/// directive.
5587/// This clause does not exist by itself, it can be only as a part of 'omp
5588/// depobj' directive. This clause is introduced to keep the original structure
5589/// of \a OMPExecutableDirective class and its derivatives and to use the
5590/// existing infrastructure of clauses with the list of variables.
5591///
5592/// \code
5593/// #pragma omp depobj(a) destroy
5594/// \endcode
5595/// In this example directive '#pragma omp depobj' has implicit clause 'depobj'
5596/// with the depobj 'a'.
5597class OMPDepobjClause final : public OMPClause {
5598 friend class OMPClauseReader;
5599
5600 /// Location of '('.
5601 SourceLocation LParenLoc;
5602
5603 /// Chunk size.
5604 Expr *Depobj = nullptr;
5605
5606 /// Build clause with number of variables \a N.
5607 ///
5608 /// \param StartLoc Starting location of the clause.
5609 /// \param LParenLoc Location of '('.
5610 /// \param EndLoc Ending location of the clause.
5611 OMPDepobjClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5612 SourceLocation EndLoc)
5613 : OMPClause(llvm::omp::OMPC_depobj, StartLoc, EndLoc),
5614 LParenLoc(LParenLoc) {}
5615
5616 /// Build an empty clause.
5617 ///
5618 explicit OMPDepobjClause()
5619 : OMPClause(llvm::omp::OMPC_depobj, SourceLocation(), SourceLocation()) {}
5620
5621 void setDepobj(Expr *E) { Depobj = E; }
5622
5623 /// Sets the location of '('.
5624 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5625
5626public:
5627 /// Creates clause.
5628 ///
5629 /// \param C AST context.
5630 /// \param StartLoc Starting location of the clause.
5631 /// \param LParenLoc Location of '('.
5632 /// \param EndLoc Ending location of the clause.
5633 /// \param Depobj depobj expression associated with the 'depobj' directive.
5634 static OMPDepobjClause *Create(const ASTContext &C, SourceLocation StartLoc,
5635 SourceLocation LParenLoc,
5636 SourceLocation EndLoc, Expr *Depobj);
5637
5638 /// Creates an empty clause.
5639 ///
5640 /// \param C AST context.
5641 static OMPDepobjClause *CreateEmpty(const ASTContext &C);
5642
5643 /// Returns depobj expression associated with the clause.
5644 Expr *getDepobj() { return Depobj; }
5645 const Expr *getDepobj() const { return Depobj; }
5646
5647 /// Returns the location of '('.
5648 SourceLocation getLParenLoc() const { return LParenLoc; }
5649
5650 child_range children() {
5651 return child_range(reinterpret_cast<Stmt **>(&Depobj),
5652 reinterpret_cast<Stmt **>(&Depobj) + 1);
5653 }
5654
5655 const_child_range children() const {
5656 return const_cast<OMPDepobjClause *>(this)->children();
5657 }
5658
5659 child_range used_children() {
5660 return child_range(child_iterator(), child_iterator());
5661 }
5662 const_child_range used_children() const {
5663 return const_child_range(const_child_iterator(), const_child_iterator());
5664 }
5665
5666 static bool classof(const OMPClause *T) {
5667 return T->getClauseKind() == llvm::omp::OMPC_depobj;
5668 }
5669};
5670
5671/// This represents implicit clause 'depend' for the '#pragma omp task'
5672/// directive.
5673///
5674/// \code
5675/// #pragma omp task depend(in:a,b)
5676/// \endcode
5677/// In this example directive '#pragma omp task' with clause 'depend' with the
5678/// variables 'a' and 'b' with dependency 'in'.
5679class OMPDependClause final
5680 : public OMPVarListClause<OMPDependClause>,
5681 private llvm::TrailingObjects<OMPDependClause, Expr *> {
5682 friend class OMPClauseReader;
5683 friend OMPVarListClause;
5684 friend TrailingObjects;
5685
5686public:
5687 struct DependDataTy final {
5688 /// Dependency type (one of in, out, inout).
5689 OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
5690
5691 /// Dependency type location.
5692 SourceLocation DepLoc;
5693
5694 /// Colon location.
5695 SourceLocation ColonLoc;
5696
5697 /// Location of 'omp_all_memory'.
5698 SourceLocation OmpAllMemoryLoc;
5699 };
5700
5701private:
5702 /// Dependency type and source locations.
5703 DependDataTy Data;
5704
5705 /// Number of loops, associated with the depend clause.
5706 unsigned NumLoops = 0;
5707
5708 /// Build clause with number of variables \a N.
5709 ///
5710 /// \param StartLoc Starting location of the clause.
5711 /// \param LParenLoc Location of '('.
5712 /// \param EndLoc Ending location of the clause.
5713 /// \param N Number of the variables in the clause.
5714 /// \param NumLoops Number of loops that is associated with this depend
5715 /// clause.
5716 OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5717 SourceLocation EndLoc, unsigned N, unsigned NumLoops)
5718 : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend, StartLoc,
5719 LParenLoc, EndLoc, N),
5720 NumLoops(NumLoops) {}
5721
5722 /// Build an empty clause.
5723 ///
5724 /// \param N Number of variables.
5725 /// \param NumLoops Number of loops that is associated with this depend
5726 /// clause.
5727 explicit OMPDependClause(unsigned N, unsigned NumLoops)
5728 : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend,
5729 SourceLocation(), SourceLocation(),
5730 SourceLocation(), N),
5731 NumLoops(NumLoops) {}
5732
5733 /// Set dependency kind.
5734 void setDependencyKind(OpenMPDependClauseKind K) { Data.DepKind = K; }
5735
5736 /// Set dependency kind and its location.
5737 void setDependencyLoc(SourceLocation Loc) { Data.DepLoc = Loc; }
5738
5739 /// Set colon location.
5740 void setColonLoc(SourceLocation Loc) { Data.ColonLoc = Loc; }
5741
5742 /// Set the 'omp_all_memory' location.
5743 void setOmpAllMemoryLoc(SourceLocation Loc) { Data.OmpAllMemoryLoc = Loc; }
5744
5745 /// Sets optional dependency modifier.
5746 void setModifier(Expr *DepModifier);
5747
5748public:
5749 /// Creates clause with a list of variables \a VL.
5750 ///
5751 /// \param C AST context.
5752 /// \param StartLoc Starting location of the clause.
5753 /// \param LParenLoc Location of '('.
5754 /// \param EndLoc Ending location of the clause.
5755 /// \param Data Dependency type and source locations.
5756 /// \param VL List of references to the variables.
5757 /// \param NumLoops Number of loops that is associated with this depend
5758 /// clause.
5759 static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
5760 SourceLocation LParenLoc,
5761 SourceLocation EndLoc, DependDataTy Data,
5762 Expr *DepModifier, ArrayRef<Expr *> VL,
5763 unsigned NumLoops);
5764
5765 /// Creates an empty clause with \a N variables.
5766 ///
5767 /// \param C AST context.
5768 /// \param N The number of variables.
5769 /// \param NumLoops Number of loops that is associated with this depend
5770 /// clause.
5771 static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N,
5772 unsigned NumLoops);
5773
5774 /// Get dependency type.
5775 OpenMPDependClauseKind getDependencyKind() const { return Data.DepKind; }
5776
5777 /// Get dependency type location.
5778 SourceLocation getDependencyLoc() const { return Data.DepLoc; }
5779
5780 /// Get colon location.
5781 SourceLocation getColonLoc() const { return Data.ColonLoc; }
5782
5783 /// Get 'omp_all_memory' location.
5784 SourceLocation getOmpAllMemoryLoc() const { return Data.OmpAllMemoryLoc; }
5785
5786 /// Return optional depend modifier.
5787 Expr *getModifier();
5788 const Expr *getModifier() const {
5789 return const_cast<OMPDependClause *>(this)->getModifier();
5790 }
5791
5792 /// Get number of loops associated with the clause.
5793 unsigned getNumLoops() const { return NumLoops; }
5794
5795 /// Set the loop data for the depend clauses with 'sink|source' kind of
5796 /// dependency.
5797 void setLoopData(unsigned NumLoop, Expr *Cnt);
5798
5799 /// Get the loop data.
5800 Expr *getLoopData(unsigned NumLoop);
5801 const Expr *getLoopData(unsigned NumLoop) const;
5802
5803 child_range children() {
5804 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5805 reinterpret_cast<Stmt **>(varlist_end()));
5806 }
5807
5808 const_child_range children() const {
5809 return const_cast<OMPDependClause *>(this)->children();
5810 }
5811
5812 child_range used_children() {
5813 return child_range(child_iterator(), child_iterator());
5814 }
5815 const_child_range used_children() const {
5816 return const_child_range(const_child_iterator(), const_child_iterator());
5817 }
5818
5819 static bool classof(const OMPClause *T) {
5820 return T->getClauseKind() == llvm::omp::OMPC_depend;
5821 }
5822};
5823
5824/// This represents 'device' clause in the '#pragma omp ...'
5825/// directive.
5826///
5827/// \code
5828/// #pragma omp target device(a)
5829/// \endcode
5830/// In this example directive '#pragma omp target' has clause 'device'
5831/// with single expression 'a'.
5833 friend class OMPClauseReader;
5834
5835 /// Location of '('.
5836 SourceLocation LParenLoc;
5837
5838 /// Device clause modifier.
5839 OpenMPDeviceClauseModifier Modifier = OMPC_DEVICE_unknown;
5840
5841 /// Location of the modifier.
5842 SourceLocation ModifierLoc;
5843
5844 /// Device number.
5845 Stmt *Device = nullptr;
5846
5847 /// Set the device number.
5848 ///
5849 /// \param E Device number.
5850 void setDevice(Expr *E) { Device = E; }
5851
5852 /// Sets modifier.
5853 void setModifier(OpenMPDeviceClauseModifier M) { Modifier = M; }
5854
5855 /// Setst modifier location.
5856 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
5857
5858public:
5859 /// Build 'device' clause.
5860 ///
5861 /// \param Modifier Clause modifier.
5862 /// \param E Expression associated with this clause.
5863 /// \param CaptureRegion Innermost OpenMP region where expressions in this
5864 /// clause must be captured.
5865 /// \param StartLoc Starting location of the clause.
5866 /// \param ModifierLoc Modifier location.
5867 /// \param LParenLoc Location of '('.
5868 /// \param EndLoc Ending location of the clause.
5869 OMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *E, Stmt *HelperE,
5870 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
5871 SourceLocation LParenLoc, SourceLocation ModifierLoc,
5872 SourceLocation EndLoc)
5873 : OMPClause(llvm::omp::OMPC_device, StartLoc, EndLoc),
5874 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
5875 ModifierLoc(ModifierLoc), Device(E) {
5876 setPreInitStmt(HelperE, CaptureRegion);
5877 }
5878
5879 /// Build an empty clause.
5881 : OMPClause(llvm::omp::OMPC_device, SourceLocation(), SourceLocation()),
5882 OMPClauseWithPreInit(this) {}
5883
5884 /// Sets the location of '('.
5885 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5886
5887 /// Returns the location of '('.
5888 SourceLocation getLParenLoc() const { return LParenLoc; }
5889
5890 /// Return device number.
5891 Expr *getDevice() { return cast<Expr>(Device); }
5892
5893 /// Return device number.
5894 Expr *getDevice() const { return cast<Expr>(Device); }
5895
5896 /// Gets modifier.
5897 OpenMPDeviceClauseModifier getModifier() const { return Modifier; }
5898
5899 /// Gets modifier location.
5900 SourceLocation getModifierLoc() const { return ModifierLoc; }
5901
5902 child_range children() { return child_range(&Device, &Device + 1); }
5903
5904 const_child_range children() const {
5905 return const_child_range(&Device, &Device + 1);
5906 }
5907
5908 child_range used_children() {
5909 return child_range(child_iterator(), child_iterator());
5910 }
5911 const_child_range used_children() const {
5912 return const_child_range(const_child_iterator(), const_child_iterator());
5913 }
5914
5915 static bool classof(const OMPClause *T) {
5916 return T->getClauseKind() == llvm::omp::OMPC_device;
5917 }
5918};
5919
5920/// This represents 'threads' clause in the '#pragma omp ...' directive.
5921///
5922/// \code
5923/// #pragma omp ordered threads
5924/// \endcode
5925/// In this example directive '#pragma omp ordered' has simple 'threads' clause.
5927 : public OMPNoChildClause<llvm::omp::OMPC_threads> {
5928public:
5929 /// Build 'threads' clause.
5930 ///
5931 /// \param StartLoc Starting location of the clause.
5932 /// \param EndLoc Ending location of the clause.
5933 OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
5934 : OMPNoChildClause(StartLoc, EndLoc) {}
5935
5936 /// Build an empty clause.
5938};
5939
5940/// This represents 'simd' clause in the '#pragma omp ...' directive.
5941///
5942/// \code
5943/// #pragma omp ordered simd
5944/// \endcode
5945/// In this example directive '#pragma omp ordered' has simple 'simd' clause.
5946class OMPSIMDClause : public OMPClause {
5947public:
5948 /// Build 'simd' clause.
5949 ///
5950 /// \param StartLoc Starting location of the clause.
5951 /// \param EndLoc Ending location of the clause.
5952 OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
5953 : OMPClause(llvm::omp::OMPC_simd, StartLoc, EndLoc) {}
5954
5955 /// Build an empty clause.
5957 : OMPClause(llvm::omp::OMPC_simd, SourceLocation(), SourceLocation()) {}
5958
5959 child_range children() {
5960 return child_range(child_iterator(), child_iterator());
5961 }
5962
5963 const_child_range children() const {
5964 return const_child_range(const_child_iterator(), const_child_iterator());
5965 }
5966
5967 child_range used_children() {
5968 return child_range(child_iterator(), child_iterator());
5969 }
5970 const_child_range used_children() const {
5971 return const_child_range(const_child_iterator(), const_child_iterator());
5972 }
5973
5974 static bool classof(const OMPClause *T) {
5975 return T->getClauseKind() == llvm::omp::OMPC_simd;
5976 }
5977};
5978
5979/// Struct that defines common infrastructure to handle mappable
5980/// expressions used in OpenMP clauses.
5982public:
5983 /// Class that represents a component of a mappable expression. E.g.
5984 /// for an expression S.a, the first component is a declaration reference
5985 /// expression associated with 'S' and the second is a member expression
5986 /// associated with the field declaration 'a'. If the expression is an array
5987 /// subscript it may not have any associated declaration. In that case the
5988 /// associated declaration is set to nullptr.
5990 /// Pair of Expression and Non-contiguous pair associated with the
5991 /// component.
5992 llvm::PointerIntPair<Expr *, 1, bool> AssociatedExpressionNonContiguousPr;
5993
5994 /// Declaration associated with the declaration. If the component does
5995 /// not have a declaration (e.g. array subscripts or section), this is set
5996 /// to nullptr.
5997 ValueDecl *AssociatedDeclaration = nullptr;
5998
5999 public:
6000 explicit MappableComponent() = default;
6001 explicit MappableComponent(Expr *AssociatedExpression,
6002 ValueDecl *AssociatedDeclaration,
6003 bool IsNonContiguous)
6004 : AssociatedExpressionNonContiguousPr(AssociatedExpression,
6005 IsNonContiguous),
6006 AssociatedDeclaration(
6007 AssociatedDeclaration
6008 ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
6009 : nullptr) {}
6010
6012 return AssociatedExpressionNonContiguousPr.getPointer();
6013 }
6014
6015 bool isNonContiguous() const {
6016 return AssociatedExpressionNonContiguousPr.getInt();
6017 }
6018
6019 ValueDecl *getAssociatedDeclaration() const {
6020 return AssociatedDeclaration;
6021 }
6022
6023 bool operator==(const MappableComponent &Other) const {
6024 return AssociatedExpressionNonContiguousPr ==
6025 Other.AssociatedExpressionNonContiguousPr &&
6026 AssociatedDeclaration == Other.AssociatedDeclaration;
6027 }
6028 };
6029
6030 // List of components of an expression. This first one is the whole
6031 // expression and the last one is the base expression.
6034
6035 // List of all component lists associated to the same base declaration.
6036 // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
6037 // their component list but the same base declaration 'S'.
6040
6041 // Hash function to allow usage as DenseMap keys.
6042 friend llvm::hash_code hash_value(const MappableComponent &MC) {
6043 return llvm::hash_combine(MC.getAssociatedExpression(),
6045 MC.isNonContiguous());
6046 }
6047
6048public:
6049 /// Get the type of an element of a ComponentList Expr \p Exp.
6050 ///
6051 /// For something like the following:
6052 /// ```c
6053 /// int *p, **p;
6054 /// ```
6055 /// The types for the following Exprs would be:
6056 /// Expr | Type
6057 /// ---------|-----------
6058 /// p | int *
6059 /// *p | int
6060 /// p[0] | int
6061 /// p[0:1] | int
6062 /// pp | int **
6063 /// pp[0] | int *
6064 /// pp[0:1] | int *
6065 /// Note: this assumes that if \p Exp is an array-section, it is contiguous.
6066 static QualType getComponentExprElementType(const Expr *Exp);
6067
6068 /// Find the attach pointer expression from a list of mappable expression
6069 /// components.
6070 ///
6071 /// This function traverses the component list to find the first
6072 /// expression that has a pointer type, which represents the attach
6073 /// base pointer expr for the current component-list.
6074 ///
6075 /// For example, given the following:
6076 ///
6077 /// ```c
6078 /// struct S {
6079 /// int a;
6080 /// int b[10];
6081 /// int c[10][10];
6082 /// int *p;
6083 /// int **pp;
6084 /// }
6085 /// S s, *ps, **pps, *(pas[10]), ***ppps;
6086 /// int i;
6087 /// ```
6088 ///
6089 /// The base-pointers for the following map operands would be:
6090 /// map list-item | attach base-pointer | attach base-pointer
6091 /// | for directives except | target_update (if
6092 /// | target_update | different)
6093 /// ----------------|-----------------------|---------------------
6094 /// s | N/A |
6095 /// s.a | N/A |
6096 /// s.p | N/A |
6097 /// ps | N/A |
6098 /// ps->p | ps |
6099 /// ps[1] | ps |
6100 /// *(ps + 1) | ps |
6101 /// (ps + 1)[1] | ps |
6102 /// ps[1:10] | ps |
6103 /// ps->b[10] | ps |
6104 /// ps->p[10] | ps->p |
6105 /// ps->c[1][2] | ps |
6106 /// ps->c[1:2][2] | (error diagnostic) | N/A, TODO: ps
6107 /// ps->c[1:1][2] | ps | N/A, TODO: ps
6108 /// pps[1][2] | pps[1] |
6109 /// pps[1:1][2] | pps[1:1] | N/A, TODO: pps[1:1]
6110 /// pps[1:i][2] | pps[1:i] | N/A, TODO: pps[1:i]
6111 /// pps[1:2][2] | (error diagnostic) | N/A
6112 /// pps[1]->p | pps[1] |
6113 /// pps[1]->p[10] | pps[1] |
6114 /// pas[1] | N/A |
6115 /// pas[1][2] | pas[1] |
6116 /// ppps[1][2] | ppps[1] |
6117 /// ppps[1][2][3] | ppps[1][2] |
6118 /// ppps[1][2:1][3] | ppps[1][2:1] | N/A, TODO: ppps[1][2:1]
6119 /// ppps[1][2:2][3] | (error diagnostic) | N/A
6120 /// Returns a pair of the attach pointer expression and its depth in the
6121 /// component list.
6122 /// TODO: This may need to be updated to handle ref_ptr/ptee cases for byref
6123 /// map operands.
6124 /// TODO: Handle cases for target-update, where the list-item is a
6125 /// non-contiguous array-section that still has a base-pointer.
6126 static std::pair<const Expr *, std::optional<size_t>>
6127 findAttachPtrExpr(MappableExprComponentListRef Components,
6128 OpenMPDirectiveKind CurDirKind);
6129
6130protected:
6131 // Return the total number of elements in a list of component lists.
6132 static unsigned
6133 getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists);
6134
6135 // Return the total number of elements in a list of declarations. All
6136 // declarations are expected to be canonical.
6137 static unsigned
6138 getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations);
6139};
6140
6141/// This structure contains all sizes needed for by an
6142/// OMPMappableExprListClause.
6144 /// Number of expressions listed.
6145 unsigned NumVars;
6146 /// Number of unique base declarations.
6148 /// Number of component lists.
6150 /// Total number of expression components.
6157};
6158
6159/// This represents clauses with a list of expressions that are mappable.
6160/// Examples of these clauses are 'map' in
6161/// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from
6162/// in '#pragma omp target update...' directives.
6163template <class T>
6164class OMPMappableExprListClause : public OMPVarListClause<T>,
6166 friend class OMPClauseReader;
6167
6168 /// Number of unique declarations in this clause.
6169 unsigned NumUniqueDeclarations;
6170
6171 /// Number of component lists in this clause.
6172 unsigned NumComponentLists;
6173
6174 /// Total number of components in this clause.
6175 unsigned NumComponents;
6176
6177 /// Whether this clause is possible to have user-defined mappers associated.
6178 /// It should be true for map, to, and from clauses, and false for
6179 /// use_device_ptr and is_device_ptr.
6180 const bool SupportsMapper;
6181
6182 /// C++ nested name specifier for the associated user-defined mapper.
6183 NestedNameSpecifierLoc MapperQualifierLoc;
6184
6185 /// The associated user-defined mapper identifier information.
6186 DeclarationNameInfo MapperIdInfo;
6187
6188protected:
6189 /// Build a clause for \a NumUniqueDeclarations declarations, \a
6190 /// NumComponentLists total component lists, and \a NumComponents total
6191 /// components.
6192 ///
6193 /// \param K Kind of the clause.
6194 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6195 /// StartLoc: starting location of the clause (the clause keyword); 2)
6196 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6197 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6198 /// NumVars: number of expressions listed in this clause; 2)
6199 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6200 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6201 /// NumComponents: total number of expression components in the clause.
6202 /// \param SupportsMapper Indicates whether this clause is possible to have
6203 /// user-defined mappers associated.
6204 /// \param MapperQualifierLocPtr C++ nested name specifier for the associated
6205 /// user-defined mapper.
6206 /// \param MapperIdInfoPtr The identifier of associated user-defined mapper.
6208 OpenMPClauseKind K, const OMPVarListLocTy &Locs,
6209 const OMPMappableExprListSizeTy &Sizes, bool SupportsMapper = false,
6210 NestedNameSpecifierLoc *MapperQualifierLocPtr = nullptr,
6211 DeclarationNameInfo *MapperIdInfoPtr = nullptr)
6212 : OMPVarListClause<T>(K, Locs.StartLoc, Locs.LParenLoc, Locs.EndLoc,
6213 Sizes.NumVars),
6214 NumUniqueDeclarations(Sizes.NumUniqueDeclarations),
6215 NumComponentLists(Sizes.NumComponentLists),
6216 NumComponents(Sizes.NumComponents), SupportsMapper(SupportsMapper) {
6217 if (MapperQualifierLocPtr)
6218 MapperQualifierLoc = *MapperQualifierLocPtr;
6219 if (MapperIdInfoPtr)
6220 MapperIdInfo = *MapperIdInfoPtr;
6221 }
6222
6223 /// Get the unique declarations that are in the trailing objects of the
6224 /// class.
6225 MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
6226 return static_cast<T *>(this)
6227 ->template getTrailingObjectsNonStrict<ValueDecl *>(
6228 NumUniqueDeclarations);
6229 }
6230
6231 /// Get the unique declarations that are in the trailing objects of the
6232 /// class.
6234 return static_cast<const T *>(this)
6235 ->template getTrailingObjectsNonStrict<ValueDecl *>(
6236 NumUniqueDeclarations);
6237 }
6238
6239 /// Set the unique declarations that are in the trailing objects of the
6240 /// class.
6242 assert(UDs.size() == NumUniqueDeclarations &&
6243 "Unexpected amount of unique declarations.");
6244 llvm::copy(UDs, getUniqueDeclsRef().begin());
6245 }
6246
6247 /// Get the number of lists per declaration that are in the trailing
6248 /// objects of the class.
6249 MutableArrayRef<unsigned> getDeclNumListsRef() {
6250 return static_cast<T *>(this)
6251 ->template getTrailingObjectsNonStrict<unsigned>(NumUniqueDeclarations);
6252 }
6253
6254 /// Get the number of lists per declaration that are in the trailing
6255 /// objects of the class.
6257 return static_cast<const T *>(this)
6258 ->template getTrailingObjectsNonStrict<unsigned>(NumUniqueDeclarations);
6259 }
6260
6261 /// Set the number of lists per declaration that are in the trailing
6262 /// objects of the class.
6264 assert(DNLs.size() == NumUniqueDeclarations &&
6265 "Unexpected amount of list numbers.");
6266 llvm::copy(DNLs, getDeclNumListsRef().begin());
6267 }
6268
6269 /// Get the cumulative component lists sizes that are in the trailing
6270 /// objects of the class. They are appended after the number of lists.
6271 MutableArrayRef<unsigned> getComponentListSizesRef() {
6272 return MutableArrayRef<unsigned>(
6273 static_cast<T *>(this)
6274 ->template getTrailingObjectsNonStrict<unsigned>() +
6275 NumUniqueDeclarations,
6276 NumComponentLists);
6277 }
6278
6279 /// Get the cumulative component lists sizes that are in the trailing
6280 /// objects of the class. They are appended after the number of lists.
6282 return ArrayRef<unsigned>(
6283 static_cast<const T *>(this)
6284 ->template getTrailingObjectsNonStrict<unsigned>() +
6285 NumUniqueDeclarations,
6286 NumComponentLists);
6287 }
6288
6289 /// Set the cumulative component lists sizes that are in the trailing
6290 /// objects of the class.
6292 assert(CLSs.size() == NumComponentLists &&
6293 "Unexpected amount of component lists.");
6294 llvm::copy(CLSs, getComponentListSizesRef().begin());
6295 }
6296
6297 /// Get the components that are in the trailing objects of the class.
6298 MutableArrayRef<MappableComponent> getComponentsRef() {
6299 return static_cast<T *>(this)
6300 ->template getTrailingObjectsNonStrict<MappableComponent>(
6301 NumComponents);
6302 }
6303
6304 /// Get the components that are in the trailing objects of the class.
6306 return static_cast<const T *>(this)
6307 ->template getTrailingObjectsNonStrict<MappableComponent>(
6308 NumComponents);
6309 }
6310
6311 /// Set the components that are in the trailing objects of the class.
6312 /// This requires the list sizes so that it can also fill the original
6313 /// expressions, which are the first component of each list.
6315 ArrayRef<unsigned> CLSs) {
6316 assert(Components.size() == NumComponents &&
6317 "Unexpected amount of component lists.");
6318 assert(CLSs.size() == NumComponentLists &&
6319 "Unexpected amount of list sizes.");
6320 llvm::copy(Components, getComponentsRef().begin());
6321 }
6322
6323 /// Fill the clause information from the list of declarations and
6324 /// associated component lists.
6326 MappableExprComponentListsRef ComponentLists) {
6327 // Perform some checks to make sure the data sizes are consistent with the
6328 // information available when the clause was created.
6329 assert(getUniqueDeclarationsTotalNumber(Declarations) ==
6330 NumUniqueDeclarations &&
6331 "Unexpected number of mappable expression info entries!");
6332 assert(getComponentsTotalNumber(ComponentLists) == NumComponents &&
6333 "Unexpected total number of components!");
6334 assert(Declarations.size() == ComponentLists.size() &&
6335 "Declaration and component lists size is not consistent!");
6336 assert(Declarations.size() == NumComponentLists &&
6337 "Unexpected declaration and component lists size!");
6338
6339 // Organize the components by declaration and retrieve the original
6340 // expression. Original expressions are always the first component of the
6341 // mappable component list.
6342 llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>>
6343 ComponentListMap;
6344 {
6345 auto CI = ComponentLists.begin();
6346 for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE;
6347 ++DI, ++CI) {
6348 assert(!CI->empty() && "Invalid component list!");
6349 ComponentListMap[*DI].push_back(*CI);
6350 }
6351 }
6352
6353 // Iterators of the target storage.
6354 auto UniqueDeclarations = getUniqueDeclsRef();
6355 auto UDI = UniqueDeclarations.begin();
6356
6357 auto DeclNumLists = getDeclNumListsRef();
6358 auto DNLI = DeclNumLists.begin();
6359
6360 auto ComponentListSizes = getComponentListSizesRef();
6361 auto CLSI = ComponentListSizes.begin();
6362
6363 auto Components = getComponentsRef();
6364 auto CI = Components.begin();
6365
6366 // Variable to compute the accumulation of the number of components.
6367 unsigned PrevSize = 0u;
6368
6369 // Scan all the declarations and associated component lists.
6370 for (auto &M : ComponentListMap) {
6371 // The declaration.
6372 auto *D = M.first;
6373 // The component lists.
6374 auto CL = M.second;
6375
6376 // Initialize the entry.
6377 *UDI = D;
6378 ++UDI;
6379
6380 *DNLI = CL.size();
6381 ++DNLI;
6382
6383 // Obtain the cumulative sizes and concatenate all the components in the
6384 // reserved storage.
6385 for (auto C : CL) {
6386 // Accumulate with the previous size.
6387 PrevSize += C.size();
6388
6389 // Save the size.
6390 *CLSI = PrevSize;
6391 ++CLSI;
6392
6393 // Append components after the current components iterator.
6394 CI = llvm::copy(C, CI);
6395 }
6396 }
6397 }
6398
6399 /// Set the nested name specifier of associated user-defined mapper.
6400 void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL) {
6401 MapperQualifierLoc = NNSL;
6402 }
6403
6404 /// Set the name of associated user-defined mapper.
6405 void setMapperIdInfo(DeclarationNameInfo MapperId) {
6406 MapperIdInfo = MapperId;
6407 }
6408
6409 /// Get the user-defined mapper references that are in the trailing objects of
6410 /// the class.
6411 MutableArrayRef<Expr *> getUDMapperRefs() {
6412 assert(SupportsMapper &&
6413 "Must be a clause that is possible to have user-defined mappers");
6414 return MutableArrayRef<Expr *>(
6415 static_cast<T *>(this)->template getTrailingObjects<Expr *>() +
6416 OMPVarListClause<T>::varlist_size(),
6417 OMPVarListClause<T>::varlist_size());
6418 }
6419
6420 /// Get the user-defined mappers references that are in the trailing objects
6421 /// of the class.
6423 assert(SupportsMapper &&
6424 "Must be a clause that is possible to have user-defined mappers");
6425 return ArrayRef<Expr *>(
6426 static_cast<const T *>(this)->template getTrailingObjects<Expr *>() +
6427 OMPVarListClause<T>::varlist_size(),
6428 OMPVarListClause<T>::varlist_size());
6429 }
6430
6431 /// Set the user-defined mappers that are in the trailing objects of the
6432 /// class.
6434 assert(DMDs.size() == OMPVarListClause<T>::varlist_size() &&
6435 "Unexpected number of user-defined mappers.");
6436 assert(SupportsMapper &&
6437 "Must be a clause that is possible to have user-defined mappers");
6438 llvm::copy(DMDs, getUDMapperRefs().begin());
6439 }
6440
6441public:
6442 /// Return the number of unique base declarations in this clause.
6443 unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; }
6444
6445 /// Return the number of lists derived from the clause expressions.
6446 unsigned getTotalComponentListNum() const { return NumComponentLists; }
6447
6448 /// Return the total number of components in all lists derived from the
6449 /// clause.
6450 unsigned getTotalComponentsNum() const { return NumComponents; }
6451
6452 /// Gets the nested name specifier for associated user-defined mapper.
6453 NestedNameSpecifierLoc getMapperQualifierLoc() const {
6454 return MapperQualifierLoc;
6455 }
6456
6457 /// Gets the name info for associated user-defined mapper.
6458 const DeclarationNameInfo &getMapperIdInfo() const { return MapperIdInfo; }
6459
6460 /// Iterator that browse the components by lists. It also allows
6461 /// browsing components of a single declaration.
6463 : public llvm::iterator_adaptor_base<
6464 const_component_lists_iterator,
6465 MappableExprComponentListRef::const_iterator,
6466 std::forward_iterator_tag, MappableComponent, ptrdiff_t,
6467 MappableComponent, MappableComponent> {
6468 // The declaration the iterator currently refers to.
6470
6471 // The list number associated with the current declaration.
6472 ArrayRef<unsigned>::iterator NumListsCur;
6473
6474 // Whether this clause is possible to have user-defined mappers associated.
6475 const bool SupportsMapper;
6476
6477 // The user-defined mapper associated with the current declaration.
6479
6480 // Remaining lists for the current declaration.
6481 unsigned RemainingLists = 0;
6482
6483 // The cumulative size of the previous list, or zero if there is no previous
6484 // list.
6485 unsigned PrevListSize = 0;
6486
6487 // The cumulative sizes of the current list - it will delimit the remaining
6488 // range of interest.
6491
6492 // Iterator to the end of the components storage.
6493 MappableExprComponentListRef::const_iterator End;
6494
6495 public:
6496 /// Construct an iterator that scans all lists.
6498 ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum,
6499 ArrayRef<unsigned> CumulativeListSizes,
6500 MappableExprComponentListRef Components, bool SupportsMapper,
6501 ArrayRef<Expr *> Mappers)
6502 : const_component_lists_iterator::iterator_adaptor_base(
6503 Components.begin()),
6504 DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()),
6505 SupportsMapper(SupportsMapper),
6506 ListSizeCur(CumulativeListSizes.begin()),
6507 ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) {
6508 assert(UniqueDecls.size() == DeclsListNum.size() &&
6509 "Inconsistent number of declarations and list sizes!");
6510 if (!DeclsListNum.empty())
6511 RemainingLists = *NumListsCur;
6512 if (SupportsMapper)
6513 MapperCur = Mappers.begin();
6514 }
6515
6516 /// Construct an iterator that scan lists for a given declaration \a
6517 /// Declaration.
6519 const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls,
6520 ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes,
6521 MappableExprComponentListRef Components, bool SupportsMapper,
6522 ArrayRef<Expr *> Mappers)
6523 : const_component_lists_iterator(UniqueDecls, DeclsListNum,
6524 CumulativeListSizes, Components,
6525 SupportsMapper, Mappers) {
6526 // Look for the desired declaration. While we are looking for it, we
6527 // update the state so that we know the component where a given list
6528 // starts.
6529 for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) {
6530 if (*DeclCur == Declaration)
6531 break;
6532
6533 assert(*NumListsCur > 0 && "No lists associated with declaration??");
6534
6535 // Skip the lists associated with the current declaration, but save the
6536 // last list size that was skipped.
6537 std::advance(ListSizeCur, *NumListsCur - 1);
6538 PrevListSize = *ListSizeCur;
6539 ++ListSizeCur;
6540
6541 if (SupportsMapper)
6542 ++MapperCur;
6543 }
6544
6545 // If we didn't find any declaration, advance the iterator to after the
6546 // last component and set remaining lists to zero.
6547 if (ListSizeCur == CumulativeListSizes.end()) {
6548 this->I = End;
6549 RemainingLists = 0u;
6550 return;
6551 }
6552
6553 // Set the remaining lists with the total number of lists of the current
6554 // declaration.
6555 RemainingLists = *NumListsCur;
6556
6557 // Adjust the list size end iterator to the end of the relevant range.
6558 ListSizeEnd = ListSizeCur;
6559 std::advance(ListSizeEnd, RemainingLists);
6560
6561 // Given that the list sizes are cumulative, the index of the component
6562 // that start the list is the size of the previous list.
6563 std::advance(this->I, PrevListSize);
6564 }
6565
6566 // Return the array with the current list. The sizes are cumulative, so the
6567 // array size is the difference between the current size and previous one.
6568 std::tuple<const ValueDecl *, MappableExprComponentListRef,
6569 const ValueDecl *>
6570 operator*() const {
6571 assert(ListSizeCur != ListSizeEnd && "Invalid iterator!");
6572 const ValueDecl *Mapper = nullptr;
6573 if (SupportsMapper && *MapperCur)
6574 Mapper = cast<ValueDecl>(cast<DeclRefExpr>(*MapperCur)->getDecl());
6575 return std::make_tuple(
6576 *DeclCur,
6577 MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize),
6578 Mapper);
6579 }
6580 std::tuple<const ValueDecl *, MappableExprComponentListRef,
6581 const ValueDecl *>
6582 operator->() const {
6583 return **this;
6584 }
6585
6586 // Skip the components of the current list.
6588 assert(ListSizeCur != ListSizeEnd && RemainingLists &&
6589 "Invalid iterator!");
6590
6591 // If we don't have more lists just skip all the components. Otherwise,
6592 // advance the iterator by the number of components in the current list.
6593 if (std::next(ListSizeCur) == ListSizeEnd) {
6594 this->I = End;
6595 RemainingLists = 0;
6596 } else {
6597 std::advance(this->I, *ListSizeCur - PrevListSize);
6598 PrevListSize = *ListSizeCur;
6599
6600 // We are done with a declaration, move to the next one.
6601 if (!(--RemainingLists)) {
6602 ++DeclCur;
6603 ++NumListsCur;
6604 RemainingLists = *NumListsCur;
6605 assert(RemainingLists && "No lists in the following declaration??");
6606 }
6607 }
6608
6609 ++ListSizeCur;
6610 if (SupportsMapper)
6611 ++MapperCur;
6612 return *this;
6613 }
6614 };
6615
6617 llvm::iterator_range<const_component_lists_iterator>;
6618
6619 /// Iterators for all component lists.
6636
6637 /// Iterators for component lists associated with the provided
6638 /// declaration.
6639 const_component_lists_iterator
6640 decl_component_lists_begin(const ValueDecl *VD) const {
6643 getComponentListSizesRef(), getComponentsRef(), SupportsMapper,
6644 SupportsMapper ? getUDMapperRefs() : ArrayRef<Expr *>());
6645 }
6652
6653 /// Iterators to access all the declarations, number of lists, list sizes, and
6654 /// components.
6656 using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>;
6657
6659
6662 llvm::iterator_range<const_all_num_lists_iterator>;
6663
6667
6670 llvm::iterator_range<const_all_lists_sizes_iterator>;
6671
6675
6678 llvm::iterator_range<const_all_components_iterator>;
6679
6683
6684 using mapperlist_iterator = MutableArrayRef<Expr *>::iterator;
6686 using mapperlist_range = llvm::iterator_range<mapperlist_iterator>;
6688 llvm::iterator_range<mapperlist_const_iterator>;
6689
6693 return getUDMapperRefs().begin();
6694 }
6696 return getUDMapperRefs().end();
6697 }
6704};
6705
6706/// This represents clause 'map' in the '#pragma omp ...'
6707/// directives.
6708///
6709/// \code
6710/// #pragma omp target map(a,b)
6711/// \endcode
6712/// In this example directive '#pragma omp target' has clause 'map'
6713/// with the variables 'a' and 'b'.
6714class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
6715 private llvm::TrailingObjects<
6716 OMPMapClause, Expr *, ValueDecl *, unsigned,
6717 OMPClauseMappableExprCommon::MappableComponent> {
6718 friend class OMPClauseReader;
6719 friend OMPMappableExprListClause;
6720 friend OMPVarListClause;
6721 friend TrailingObjects;
6722
6723 /// Define the sizes of each trailing object array except the last one. This
6724 /// is required for TrailingObjects to work properly.
6725 size_t numTrailingObjects(OverloadToken<Expr *>) const {
6726 // There are varlist_size() of expressions, and varlist_size() of
6727 // user-defined mappers.
6728 return 2 * varlist_size() + 1;
6729 }
6730 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
6731 return getUniqueDeclarationsNum();
6732 }
6733 size_t numTrailingObjects(OverloadToken<unsigned>) const {
6734 return getUniqueDeclarationsNum() + getTotalComponentListNum();
6735 }
6736
6737private:
6738 /// Map-type-modifiers for the 'map' clause.
6739 OpenMPMapModifierKind MapTypeModifiers[NumberOfOMPMapClauseModifiers] = {
6744
6745 /// Location of map-type-modifiers for the 'map' clause.
6746 SourceLocation MapTypeModifiersLoc[NumberOfOMPMapClauseModifiers];
6747
6748 /// Map type for the 'map' clause.
6750
6751 /// Is this an implicit map type or not.
6752 bool MapTypeIsImplicit = false;
6753
6754 /// Location of the map type.
6755 SourceLocation MapLoc;
6756
6757 /// Colon location.
6758 SourceLocation ColonLoc;
6759
6760 /// Build a clause for \a NumVars listed expressions, \a
6761 /// NumUniqueDeclarations declarations, \a NumComponentLists total component
6762 /// lists, and \a NumComponents total expression components.
6763 ///
6764 /// \param MapModifiers Map-type-modifiers.
6765 /// \param MapModifiersLoc Locations of map-type-modifiers.
6766 /// \param MapperQualifierLoc C++ nested name specifier for the associated
6767 /// user-defined mapper.
6768 /// \param MapperIdInfo The identifier of associated user-defined mapper.
6769 /// \param MapType Map type.
6770 /// \param MapTypeIsImplicit Map type is inferred implicitly.
6771 /// \param MapLoc Location of the map type.
6772 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6773 /// StartLoc: starting location of the clause (the clause keyword); 2)
6774 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6775 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6776 /// NumVars: number of expressions listed in this clause; 2)
6777 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6778 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6779 /// NumComponents: total number of expression components in the clause.
6780 explicit OMPMapClause(ArrayRef<OpenMPMapModifierKind> MapModifiers,
6781 ArrayRef<SourceLocation> MapModifiersLoc,
6782 NestedNameSpecifierLoc MapperQualifierLoc,
6783 DeclarationNameInfo MapperIdInfo,
6784 OpenMPMapClauseKind MapType, bool MapTypeIsImplicit,
6785 SourceLocation MapLoc, const OMPVarListLocTy &Locs,
6786 const OMPMappableExprListSizeTy &Sizes)
6787 : OMPMappableExprListClause(llvm::omp::OMPC_map, Locs, Sizes,
6788 /*SupportsMapper=*/true, &MapperQualifierLoc,
6789 &MapperIdInfo),
6790 MapType(MapType), MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {
6791 assert(std::size(MapTypeModifiers) == MapModifiers.size() &&
6792 "Unexpected number of map type modifiers.");
6793 llvm::copy(MapModifiers, std::begin(MapTypeModifiers));
6794
6795 assert(std::size(MapTypeModifiersLoc) == MapModifiersLoc.size() &&
6796 "Unexpected number of map type modifier locations.");
6797 llvm::copy(MapModifiersLoc, std::begin(MapTypeModifiersLoc));
6798 }
6799
6800 /// Build an empty clause.
6801 ///
6802 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6803 /// NumVars: number of expressions listed in this clause; 2)
6804 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6805 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6806 /// NumComponents: total number of expression components in the clause.
6807 explicit OMPMapClause(const OMPMappableExprListSizeTy &Sizes)
6808 : OMPMappableExprListClause(llvm::omp::OMPC_map, OMPVarListLocTy(), Sizes,
6809 /*SupportsMapper=*/true) {}
6810
6811 /// Set map-type-modifier for the clause.
6812 ///
6813 /// \param I index for map-type-modifier.
6814 /// \param T map-type-modifier for the clause.
6815 void setMapTypeModifier(unsigned I, OpenMPMapModifierKind T) {
6816 assert(I < NumberOfOMPMapClauseModifiers &&
6817 "Unexpected index to store map type modifier, exceeds array size.");
6818 MapTypeModifiers[I] = T;
6819 }
6820
6821 /// Set location for the map-type-modifier.
6822 ///
6823 /// \param I index for map-type-modifier location.
6824 /// \param TLoc map-type-modifier location.
6825 void setMapTypeModifierLoc(unsigned I, SourceLocation TLoc) {
6826 assert(I < NumberOfOMPMapClauseModifiers &&
6827 "Index to store map type modifier location exceeds array size.");
6828 MapTypeModifiersLoc[I] = TLoc;
6829 }
6830
6831 /// Set type for the clause.
6832 ///
6833 /// \param T Type for the clause.
6834 void setMapType(OpenMPMapClauseKind T) { MapType = T; }
6835
6836 /// Set type location.
6837 ///
6838 /// \param TLoc Type location.
6839 void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
6840
6841 /// Set colon location.
6842 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
6843
6844 /// Set iterator modifier.
6845 void setIteratorModifier(Expr *IteratorModifier) {
6846 getTrailingObjects<Expr *>()[2 * varlist_size()] = IteratorModifier;
6847 }
6848
6849public:
6850 /// Creates clause with a list of variables \a VL.
6851 ///
6852 /// \param C AST context.
6853 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6854 /// StartLoc: starting location of the clause (the clause keyword); 2)
6855 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6856 /// \param Vars The original expression used in the clause.
6857 /// \param Declarations Declarations used in the clause.
6858 /// \param ComponentLists Component lists used in the clause.
6859 /// \param UDMapperRefs References to user-defined mappers associated with
6860 /// expressions used in the clause.
6861 /// \param IteratorModifier Iterator modifier.
6862 /// \param MapModifiers Map-type-modifiers.
6863 /// \param MapModifiersLoc Location of map-type-modifiers.
6864 /// \param UDMQualifierLoc C++ nested name specifier for the associated
6865 /// user-defined mapper.
6866 /// \param MapperId The identifier of associated user-defined mapper.
6867 /// \param Type Map type.
6868 /// \param TypeIsImplicit Map type is inferred implicitly.
6869 /// \param TypeLoc Location of the map type.
6870 static OMPMapClause *
6871 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
6872 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
6873 MappableExprComponentListsRef ComponentLists,
6874 ArrayRef<Expr *> UDMapperRefs, Expr *IteratorModifier,
6875 ArrayRef<OpenMPMapModifierKind> MapModifiers,
6876 ArrayRef<SourceLocation> MapModifiersLoc,
6877 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
6878 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc);
6879
6880 /// Creates an empty clause with the place for \a NumVars original
6881 /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists
6882 /// lists, and \a NumComponents expression components.
6883 ///
6884 /// \param C AST context.
6885 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6886 /// NumVars: number of expressions listed in this clause; 2)
6887 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6888 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6889 /// NumComponents: total number of expression components in the clause.
6890 static OMPMapClause *CreateEmpty(const ASTContext &C,
6891 const OMPMappableExprListSizeTy &Sizes);
6892
6893 /// Fetches Expr * of iterator modifier.
6895 return getTrailingObjects<Expr *>()[2 * varlist_size()];
6896 }
6897
6898 /// Fetches mapping kind for the clause.
6899 OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
6900
6901 /// Is this an implicit map type?
6902 /// We have to capture 'IsMapTypeImplicit' from the parser for more
6903 /// informative error messages. It helps distinguish map(r) from
6904 /// map(tofrom: r), which is important to print more helpful error
6905 /// messages for some target directives.
6906 bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; }
6907
6908 /// Fetches the map-type-modifier at 'Cnt' index of array of modifiers.
6909 ///
6910 /// \param Cnt index for map-type-modifier.
6911 OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY {
6912 assert(Cnt < NumberOfOMPMapClauseModifiers &&
6913 "Requested modifier exceeds the total number of modifiers.");
6914 return MapTypeModifiers[Cnt];
6915 }
6916
6917 /// Fetches the map-type-modifier location at 'Cnt' index of array of
6918 /// modifiers' locations.
6919 ///
6920 /// \param Cnt index for map-type-modifier location.
6921 SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY {
6922 assert(Cnt < NumberOfOMPMapClauseModifiers &&
6923 "Requested modifier location exceeds total number of modifiers.");
6924 return MapTypeModifiersLoc[Cnt];
6925 }
6926
6927 /// Fetches ArrayRef of map-type-modifiers.
6929 return MapTypeModifiers;
6930 }
6931
6932 /// Fetches ArrayRef of location of map-type-modifiers.
6934 return MapTypeModifiersLoc;
6935 }
6936
6937 /// Fetches location of clause mapping kind.
6938 SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
6939
6940 /// Get colon location.
6941 SourceLocation getColonLoc() const { return ColonLoc; }
6942
6943 child_range children() {
6944 return child_range(
6945 reinterpret_cast<Stmt **>(varlist_begin()),
6946 reinterpret_cast<Stmt **>(varlist_end()));
6947 }
6948
6949 const_child_range children() const {
6950 return const_cast<OMPMapClause *>(this)->children();
6951 }
6952
6953 child_range used_children() {
6954 if (MapType == OMPC_MAP_to || MapType == OMPC_MAP_tofrom)
6955 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6956 reinterpret_cast<Stmt **>(varlist_end()));
6957 return child_range(child_iterator(), child_iterator());
6958 }
6959 const_child_range used_children() const {
6960 return const_cast<OMPMapClause *>(this)->used_children();
6961 }
6962
6963
6964 static bool classof(const OMPClause *T) {
6965 return T->getClauseKind() == llvm::omp::OMPC_map;
6966 }
6967};
6968
6969/// This represents 'num_teams' clause in the '#pragma omp ...'
6970/// directive.
6971///
6972/// \code
6973/// #pragma omp teams num_teams(n)
6974/// \endcode
6975/// In this example directive '#pragma omp teams' has clause 'num_teams'
6976/// with single expression 'n'.
6977///
6978/// \code
6979/// #pragma omp teams num_teams(m:n)
6980/// \endcode
6981/// In this example directive '#pragma omp teams' has clause 'num_teams' with
6982/// single expression 'n' as upper-bound and modifier expression 'm' as
6983/// lower-bound.
6984///
6985/// When 'ompx_bare' clause exists on a 'target' directive, 'num_teams' clause
6986/// can accept up to three expressions.
6987///
6988/// \code
6989/// #pragma omp target teams ompx_bare num_teams(x, y, z)
6990/// \endcode
6991class OMPNumTeamsClause final
6992 : public OMPVarListClause<OMPNumTeamsClause>,
6993 public OMPClauseWithPreInit,
6994 private llvm::TrailingObjects<OMPNumTeamsClause, Expr *> {
6995 friend OMPVarListClause;
6996 friend TrailingObjects;
6997
6998 /// Modifier that was specified.
6999 OpenMPNumTeamsClauseModifier Modifier = OMPC_NUMTEAMS_unknown;
7000
7001 /// Location of the modifier.
7002 SourceLocation ModifierLoc;
7003
7004 OMPNumTeamsClause(const ASTContext &C, SourceLocation StartLoc,
7005 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
7006 : OMPVarListClause(llvm::omp::OMPC_num_teams, StartLoc, LParenLoc, EndLoc,
7007 N),
7008 OMPClauseWithPreInit(this) {}
7009
7010 /// Build an empty clause.
7011 OMPNumTeamsClause(unsigned N)
7012 : OMPVarListClause(llvm::omp::OMPC_num_teams, SourceLocation(),
7013 SourceLocation(), SourceLocation(), N),
7014 OMPClauseWithPreInit(this) {}
7015
7016public:
7017 /// Creates clause with a list of variables \a VL.
7018 ///
7019 /// \param C AST context.
7020 /// \param StartLoc Starting location of the clause.
7021 /// \param LParenLoc Location of '('.
7022 /// \param EndLoc Ending location of the clause.
7023 /// \param VL List of references to the variables.
7024 /// \param Modifier The modifier specified in the clause.
7025 /// \param ModifierExpr The expression of the modifier.
7026 /// \param ModifierLoc Location of the modifier.
7027 /// \param PreInit
7028 static OMPNumTeamsClause *
7029 Create(const ASTContext &C, OpenMPDirectiveKind CaptureRegion,
7030 SourceLocation StartLoc, SourceLocation LParenLoc,
7031 SourceLocation EndLoc, ArrayRef<Expr *> VL,
7032 OpenMPNumTeamsClauseModifier Modifier, Expr *ModifierExpr,
7033 SourceLocation ModifierLoc, Stmt *PreInit);
7034
7035 /// Creates an empty clause with \a N variables.
7036 ///
7037 /// \param C AST context.
7038 /// \param N The number of variables.
7039 static OMPNumTeamsClause *CreateEmpty(const ASTContext &C, unsigned N);
7040
7041 /// Return NumTeams expressions.
7042 ArrayRef<Expr *> getNumTeams() { return getVarRefs(); }
7043
7044 /// Return NumTeams expressions.
7046 return const_cast<OMPNumTeamsClause *>(this)->getNumTeams();
7047 }
7048
7049 /// Get the modifier.
7050 OpenMPNumTeamsClauseModifier getModifier() const { return Modifier; }
7051
7052 /// Set the modifier.
7053 void setModifier(OpenMPNumTeamsClauseModifier M) { Modifier = M; }
7054
7055 /// Get the expression of the modifier.
7056 const Expr *getModifierExpr() const { return *varlist_end(); }
7057
7058 /// Get the expression of the modifier.
7059 Expr *getModifierExpr() { return *varlist_end(); }
7060
7061 /// Set the expression of the modifier.
7062 void setModifierExpr(Expr *E) { *varlist_end() = E; }
7063
7064 /// Get the location of the modifier.
7065 SourceLocation getModifierLoc() const { return ModifierLoc; }
7066
7067 /// Set the location of the modifier.
7068 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
7069
7070 child_range children() {
7071 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
7072 reinterpret_cast<Stmt **>(varlist_end()) + 1);
7073 }
7074
7075 const_child_range children() const {
7076 return const_cast<OMPNumTeamsClause *>(this)->children();
7077 }
7078
7079 child_range used_children() {
7080 return child_range(child_iterator(), child_iterator());
7081 }
7082 const_child_range used_children() const {
7083 return const_child_range(const_child_iterator(), const_child_iterator());
7084 }
7085
7086 static bool classof(const OMPClause *T) {
7087 return T->getClauseKind() == llvm::omp::OMPC_num_teams;
7088 }
7089};
7090
7091/// This represents 'thread_limit' clause in the '#pragma omp ...'
7092/// directive.
7093///
7094/// \code
7095/// #pragma omp teams thread_limit(n)
7096/// \endcode
7097/// In this example directive '#pragma omp teams' has clause 'thread_limit'
7098/// with single expression 'n'.
7099///
7100/// When 'ompx_bare' clause exists on a 'target' directive, 'thread_limit'
7101/// clause can accept up to three expressions.
7102///
7103/// \code
7104/// #pragma omp target teams ompx_bare thread_limit(x, y, z)
7105/// \endcode
7106class OMPThreadLimitClause final
7107 : public OMPVarListClause<OMPThreadLimitClause>,
7108 public OMPClauseWithPreInit,
7109 private llvm::TrailingObjects<OMPThreadLimitClause, Expr *> {
7110 friend OMPVarListClause;
7111 friend TrailingObjects;
7112
7113 OMPThreadLimitClause(const ASTContext &C, SourceLocation StartLoc,
7114 SourceLocation LParenLoc, SourceLocation EndLoc,
7115 unsigned N)
7116 : OMPVarListClause(llvm::omp::OMPC_thread_limit, StartLoc, LParenLoc,
7117 EndLoc, N),
7118 OMPClauseWithPreInit(this) {}
7119
7120 /// Build an empty clause.
7121 OMPThreadLimitClause(unsigned N)
7122 : OMPVarListClause(llvm::omp::OMPC_thread_limit, SourceLocation(),
7123 SourceLocation(), SourceLocation(), N),
7124 OMPClauseWithPreInit(this) {}
7125
7126public:
7127 /// Creates clause with a list of variables \a VL.
7128 ///
7129 /// \param C AST context.
7130 /// \param StartLoc Starting location of the clause.
7131 /// \param LParenLoc Location of '('.
7132 /// \param EndLoc Ending location of the clause.
7133 /// \param VL List of references to the variables.
7134 /// \param PreInit
7135 static OMPThreadLimitClause *
7136 Create(const ASTContext &C, OpenMPDirectiveKind CaptureRegion,
7137 SourceLocation StartLoc, SourceLocation LParenLoc,
7138 SourceLocation EndLoc, ArrayRef<Expr *> VL, Stmt *PreInit);
7139
7140 /// Creates an empty clause with \a N variables.
7141 ///
7142 /// \param C AST context.
7143 /// \param N The number of variables.
7144 static OMPThreadLimitClause *CreateEmpty(const ASTContext &C, unsigned N);
7145
7146 /// Return ThreadLimit expressions.
7147 ArrayRef<Expr *> getThreadLimit() { return getVarRefs(); }
7148
7149 /// Return ThreadLimit expressions.
7151 return const_cast<OMPThreadLimitClause *>(this)->getThreadLimit();
7152 }
7153
7154 child_range children() {
7155 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
7156 reinterpret_cast<Stmt **>(varlist_end()));
7157 }
7158
7159 const_child_range children() const {
7160 return const_cast<OMPThreadLimitClause *>(this)->children();
7161 }
7162
7163 child_range used_children() {
7164 return child_range(child_iterator(), child_iterator());
7165 }
7166 const_child_range used_children() const {
7167 return const_child_range(const_child_iterator(), const_child_iterator());
7168 }
7169
7170 static bool classof(const OMPClause *T) {
7171 return T->getClauseKind() == llvm::omp::OMPC_thread_limit;
7172 }
7173};
7174
7175/// This represents 'priority' clause in the '#pragma omp ...'
7176/// directive.
7177///
7178/// \code
7179/// #pragma omp task priority(n)
7180/// \endcode
7181/// In this example directive '#pragma omp teams' has clause 'priority' with
7182/// single expression 'n'.
7184 friend class OMPClauseReader;
7185
7186 /// Location of '('.
7187 SourceLocation LParenLoc;
7188
7189 /// Priority number.
7190 Stmt *Priority = nullptr;
7191
7192 /// Set the Priority number.
7193 ///
7194 /// \param E Priority number.
7195 void setPriority(Expr *E) { Priority = E; }
7196
7197public:
7198 /// Build 'priority' clause.
7199 ///
7200 /// \param Priority Expression associated with this clause.
7201 /// \param HelperPriority Helper priority for the construct.
7202 /// \param CaptureRegion Innermost OpenMP region where expressions in this
7203 /// clause must be captured.
7204 /// \param StartLoc Starting location of the clause.
7205 /// \param LParenLoc Location of '('.
7206 /// \param EndLoc Ending location of the clause.
7207 OMPPriorityClause(Expr *Priority, Stmt *HelperPriority,
7208 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
7209 SourceLocation LParenLoc, SourceLocation EndLoc)
7210 : OMPClause(llvm::omp::OMPC_priority, StartLoc, EndLoc),
7211 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Priority(Priority) {
7212 setPreInitStmt(HelperPriority, CaptureRegion);
7213 }
7214
7215 /// Build an empty clause.
7217 : OMPClause(llvm::omp::OMPC_priority, SourceLocation(), SourceLocation()),
7218 OMPClauseWithPreInit(this) {}
7219
7220 /// Sets the location of '('.
7221 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7222
7223 /// Returns the location of '('.
7224 SourceLocation getLParenLoc() const { return LParenLoc; }
7225
7226 /// Return Priority number.
7227 Expr *getPriority() { return cast<Expr>(Priority); }
7228
7229 /// Return Priority number.
7230 Expr *getPriority() const { return cast<Expr>(Priority); }
7231
7232 child_range children() { return child_range(&Priority, &Priority + 1); }
7233
7234 const_child_range children() const {
7235 return const_child_range(&Priority, &Priority + 1);
7236 }
7237
7238 child_range used_children();
7239 const_child_range used_children() const {
7240 return const_cast<OMPPriorityClause *>(this)->used_children();
7241 }
7242
7243 static bool classof(const OMPClause *T) {
7244 return T->getClauseKind() == llvm::omp::OMPC_priority;
7245 }
7246};
7247
7248/// This represents 'grainsize' clause in the '#pragma omp ...'
7249/// directive.
7250///
7251/// \code
7252/// #pragma omp taskloop grainsize(4)
7253/// \endcode
7254/// In this example directive '#pragma omp taskloop' has clause 'grainsize'
7255/// with single expression '4'.
7257 friend class OMPClauseReader;
7258
7259 /// Location of '('.
7260 SourceLocation LParenLoc;
7261
7262 /// Modifiers for 'grainsize' clause.
7263 OpenMPGrainsizeClauseModifier Modifier = OMPC_GRAINSIZE_unknown;
7264
7265 /// Location of the modifier.
7266 SourceLocation ModifierLoc;
7267
7268 /// Safe iteration space distance.
7269 Stmt *Grainsize = nullptr;
7270
7271 /// Set safelen.
7272 void setGrainsize(Expr *Size) { Grainsize = Size; }
7273
7274 /// Sets modifier.
7275 void setModifier(OpenMPGrainsizeClauseModifier M) { Modifier = M; }
7276
7277 /// Sets modifier location.
7278 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
7279
7280public:
7281 /// Build 'grainsize' clause.
7282 ///
7283 /// \param Modifier Clause modifier.
7284 /// \param Size Expression associated with this clause.
7285 /// \param HelperSize Helper grainsize for the construct.
7286 /// \param CaptureRegion Innermost OpenMP region where expressions in this
7287 /// clause must be captured.
7288 /// \param StartLoc Starting location of the clause.
7289 /// \param ModifierLoc Modifier location.
7290 /// \param LParenLoc Location of '('.
7291 /// \param EndLoc Ending location of the clause.
7292 OMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size,
7293 Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion,
7294 SourceLocation StartLoc, SourceLocation LParenLoc,
7295 SourceLocation ModifierLoc, SourceLocation EndLoc)
7296 : OMPClause(llvm::omp::OMPC_grainsize, StartLoc, EndLoc),
7297 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
7298 ModifierLoc(ModifierLoc), Grainsize(Size) {
7299 setPreInitStmt(HelperSize, CaptureRegion);
7300 }
7301
7302 /// Build an empty clause.
7304 : OMPClause(llvm::omp::OMPC_grainsize, SourceLocation(),
7305 SourceLocation()),
7306 OMPClauseWithPreInit(this) {}
7307
7308 /// Sets the location of '('.
7309 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7310
7311 /// Returns the location of '('.
7312 SourceLocation getLParenLoc() const { return LParenLoc; }
7313
7314 /// Return safe iteration space distance.
7315 Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
7316
7317 /// Gets modifier.
7318 OpenMPGrainsizeClauseModifier getModifier() const { return Modifier; }
7319
7320 /// Gets modifier location.
7321 SourceLocation getModifierLoc() const { return ModifierLoc; }
7322
7323 child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
7324
7325 const_child_range children() const {
7326 return const_child_range(&Grainsize, &Grainsize + 1);
7327 }
7328
7329 child_range used_children();
7330 const_child_range used_children() const {
7331 return const_cast<OMPGrainsizeClause *>(this)->used_children();
7332 }
7333
7334 static bool classof(const OMPClause *T) {
7335 return T->getClauseKind() == llvm::omp::OMPC_grainsize;
7336 }
7337};
7338
7339/// This represents 'nogroup' clause in the '#pragma omp ...' directive.
7340///
7341/// \code
7342/// #pragma omp taskloop nogroup
7343/// \endcode
7344/// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
7346public:
7347 /// Build 'nogroup' clause.
7348 ///
7349 /// \param StartLoc Starting location of the clause.
7350 /// \param EndLoc Ending location of the clause.
7351 OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
7352 : OMPClause(llvm::omp::OMPC_nogroup, StartLoc, EndLoc) {}
7353
7354 /// Build an empty clause.
7356 : OMPClause(llvm::omp::OMPC_nogroup, SourceLocation(), SourceLocation()) {
7357 }
7358
7359 child_range children() {
7360 return child_range(child_iterator(), child_iterator());
7361 }
7362
7363 const_child_range children() const {
7364 return const_child_range(const_child_iterator(), const_child_iterator());
7365 }
7366
7367 child_range used_children() {
7368 return child_range(child_iterator(), child_iterator());
7369 }
7370 const_child_range used_children() const {
7371 return const_child_range(const_child_iterator(), const_child_iterator());
7372 }
7373
7374 static bool classof(const OMPClause *T) {
7375 return T->getClauseKind() == llvm::omp::OMPC_nogroup;
7376 }
7377};
7378
7379/// This represents 'num_tasks' clause in the '#pragma omp ...'
7380/// directive.
7381///
7382/// \code
7383/// #pragma omp taskloop num_tasks(4)
7384/// \endcode
7385/// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
7386/// with single expression '4'.
7388 friend class OMPClauseReader;
7389
7390 /// Location of '('.
7391 SourceLocation LParenLoc;
7392
7393 /// Modifiers for 'num_tasks' clause.
7394 OpenMPNumTasksClauseModifier Modifier = OMPC_NUMTASKS_unknown;
7395
7396 /// Location of the modifier.
7397 SourceLocation ModifierLoc;
7398
7399 /// Safe iteration space distance.
7400 Stmt *NumTasks = nullptr;
7401
7402 /// Set safelen.
7403 void setNumTasks(Expr *Size) { NumTasks = Size; }
7404
7405 /// Sets modifier.
7406 void setModifier(OpenMPNumTasksClauseModifier M) { Modifier = M; }
7407
7408 /// Sets modifier location.
7409 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
7410
7411public:
7412 /// Build 'num_tasks' clause.
7413 ///
7414 /// \param Modifier Clause modifier.
7415 /// \param Size Expression associated with this clause.
7416 /// \param HelperSize Helper grainsize for the construct.
7417 /// \param CaptureRegion Innermost OpenMP region where expressions in this
7418 /// clause must be captured.
7419 /// \param StartLoc Starting location of the clause.
7420 /// \param EndLoc Ending location of the clause.
7421 /// \param ModifierLoc Modifier location.
7422 /// \param LParenLoc Location of '('.
7423 OMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *Size,
7424 Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion,
7425 SourceLocation StartLoc, SourceLocation LParenLoc,
7426 SourceLocation ModifierLoc, SourceLocation EndLoc)
7427 : OMPClause(llvm::omp::OMPC_num_tasks, StartLoc, EndLoc),
7428 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
7429 ModifierLoc(ModifierLoc), NumTasks(Size) {
7430 setPreInitStmt(HelperSize, CaptureRegion);
7431 }
7432
7433 /// Build an empty clause.
7435 : OMPClause(llvm::omp::OMPC_num_tasks, SourceLocation(),
7436 SourceLocation()),
7437 OMPClauseWithPreInit(this) {}
7438
7439 /// Sets the location of '('.
7440 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7441
7442 /// Returns the location of '('.
7443 SourceLocation getLParenLoc() const { return LParenLoc; }
7444
7445 /// Return safe iteration space distance.
7446 Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
7447
7448 /// Gets modifier.
7449 OpenMPNumTasksClauseModifier getModifier() const { return Modifier; }
7450
7451 /// Gets modifier location.
7452 SourceLocation getModifierLoc() const { return ModifierLoc; }
7453
7454 child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
7455
7456 const_child_range children() const {
7457 return const_child_range(&NumTasks, &NumTasks + 1);
7458 }
7459
7460 child_range used_children();
7461 const_child_range used_children() const {
7462 return const_cast<OMPNumTasksClause *>(this)->used_children();
7463 }
7464
7465 static bool classof(const OMPClause *T) {
7466 return T->getClauseKind() == llvm::omp::OMPC_num_tasks;
7467 }
7468};
7469
7470/// This represents 'hint' clause in the '#pragma omp ...' directive.
7471///
7472/// \code
7473/// #pragma omp critical (name) hint(6)
7474/// \endcode
7475/// In this example directive '#pragma omp critical' has name 'name' and clause
7476/// 'hint' with argument '6'.
7477class OMPHintClause : public OMPClause {
7478 friend class OMPClauseReader;
7479
7480 /// Location of '('.
7481 SourceLocation LParenLoc;
7482
7483 /// Hint expression of the 'hint' clause.
7484 Stmt *Hint = nullptr;
7485
7486 /// Set hint expression.
7487 void setHint(Expr *H) { Hint = H; }
7488
7489public:
7490 /// Build 'hint' clause with expression \a Hint.
7491 ///
7492 /// \param Hint Hint expression.
7493 /// \param StartLoc Starting location of the clause.
7494 /// \param LParenLoc Location of '('.
7495 /// \param EndLoc Ending location of the clause.
7496 OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
7497 SourceLocation EndLoc)
7498 : OMPClause(llvm::omp::OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
7499 Hint(Hint) {}
7500
7501 /// Build an empty clause.
7503 : OMPClause(llvm::omp::OMPC_hint, SourceLocation(), SourceLocation()) {}
7504
7505 /// Sets the location of '('.
7506 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7507
7508 /// Returns the location of '('.
7509 SourceLocation getLParenLoc() const { return LParenLoc; }
7510
7511 /// Returns number of threads.
7512 Expr *getHint() const { return cast_or_null<Expr>(Hint); }
7513
7514 child_range children() { return child_range(&Hint, &Hint + 1); }
7515
7516 const_child_range children() const {
7517 return const_child_range(&Hint, &Hint + 1);
7518 }
7519
7520 child_range used_children() {
7521 return child_range(child_iterator(), child_iterator());
7522 }
7523 const_child_range used_children() const {
7524 return const_child_range(const_child_iterator(), const_child_iterator());
7525 }
7526
7527 static bool classof(const OMPClause *T) {
7528 return T->getClauseKind() == llvm::omp::OMPC_hint;
7529 }
7530};
7531
7532/// This represents 'dist_schedule' clause in the '#pragma omp ...'
7533/// directive.
7534///
7535/// \code
7536/// #pragma omp distribute dist_schedule(static, 3)
7537/// \endcode
7538/// In this example directive '#pragma omp distribute' has 'dist_schedule'
7539/// clause with arguments 'static' and '3'.
7541 friend class OMPClauseReader;
7542
7543 /// Location of '('.
7544 SourceLocation LParenLoc;
7545
7546 /// A kind of the 'schedule' clause.
7547 OpenMPDistScheduleClauseKind Kind = OMPC_DIST_SCHEDULE_unknown;
7548
7549 /// Start location of the schedule kind in source code.
7550 SourceLocation KindLoc;
7551
7552 /// Location of ',' (if any).
7553 SourceLocation CommaLoc;
7554
7555 /// Chunk size.
7556 Expr *ChunkSize = nullptr;
7557
7558 /// Set schedule kind.
7559 ///
7560 /// \param K Schedule kind.
7561 void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; }
7562
7563 /// Sets the location of '('.
7564 ///
7565 /// \param Loc Location of '('.
7566 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7567
7568 /// Set schedule kind start location.
7569 ///
7570 /// \param KLoc Schedule kind location.
7571 void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
7572
7573 /// Set location of ','.
7574 ///
7575 /// \param Loc Location of ','.
7576 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
7577
7578 /// Set chunk size.
7579 ///
7580 /// \param E Chunk size.
7581 void setChunkSize(Expr *E) { ChunkSize = E; }
7582
7583public:
7584 /// Build 'dist_schedule' clause with schedule kind \a Kind and chunk
7585 /// size expression \a ChunkSize.
7586 ///
7587 /// \param StartLoc Starting location of the clause.
7588 /// \param LParenLoc Location of '('.
7589 /// \param KLoc Starting location of the argument.
7590 /// \param CommaLoc Location of ','.
7591 /// \param EndLoc Ending location of the clause.
7592 /// \param Kind DistSchedule kind.
7593 /// \param ChunkSize Chunk size.
7594 /// \param HelperChunkSize Helper chunk size for combined directives.
7595 OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
7596 SourceLocation KLoc, SourceLocation CommaLoc,
7597 SourceLocation EndLoc,
7598 OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
7599 Stmt *HelperChunkSize)
7600 : OMPClause(llvm::omp::OMPC_dist_schedule, StartLoc, EndLoc),
7601 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
7602 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
7603 setPreInitStmt(HelperChunkSize);
7604 }
7605
7606 /// Build an empty clause.
7608 : OMPClause(llvm::omp::OMPC_dist_schedule, SourceLocation(),
7609 SourceLocation()),
7610 OMPClauseWithPreInit(this) {}
7611
7612 /// Get kind of the clause.
7613 OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; }
7614
7615 /// Get location of '('.
7616 SourceLocation getLParenLoc() { return LParenLoc; }
7617
7618 /// Get kind location.
7619 SourceLocation getDistScheduleKindLoc() { return KindLoc; }
7620
7621 /// Get location of ','.
7622 SourceLocation getCommaLoc() { return CommaLoc; }
7623
7624 /// Get chunk size.
7625 Expr *getChunkSize() { return ChunkSize; }
7626
7627 /// Get chunk size.
7628 const Expr *getChunkSize() const { return ChunkSize; }
7629
7630 child_range children() {
7631 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
7632 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
7633 }
7634
7635 const_child_range children() const {
7636 return const_cast<OMPDistScheduleClause *>(this)->children();
7637 }
7638
7639 child_range used_children() {
7640 return child_range(child_iterator(), child_iterator());
7641 }
7642 const_child_range used_children() const {
7643 return const_child_range(const_child_iterator(), const_child_iterator());
7644 }
7645
7646 static bool classof(const OMPClause *T) {
7647 return T->getClauseKind() == llvm::omp::OMPC_dist_schedule;
7648 }
7649};
7650
7651/// This represents 'defaultmap' clause in the '#pragma omp ...' directive.
7652///
7653/// \code
7654/// #pragma omp target defaultmap(tofrom: scalar)
7655/// \endcode
7656/// In this example directive '#pragma omp target' has 'defaultmap' clause of kind
7657/// 'scalar' with modifier 'tofrom'.
7659 friend class OMPClauseReader;
7660
7661 /// Location of '('.
7662 SourceLocation LParenLoc;
7663
7664 /// Modifiers for 'defaultmap' clause.
7665 OpenMPDefaultmapClauseModifier Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown;
7666
7667 /// Locations of modifiers.
7668 SourceLocation ModifierLoc;
7669
7670 /// A kind of the 'defaultmap' clause.
7671 OpenMPDefaultmapClauseKind Kind = OMPC_DEFAULTMAP_unknown;
7672
7673 /// Start location of the defaultmap kind in source code.
7674 SourceLocation KindLoc;
7675
7676 /// Set defaultmap kind.
7677 ///
7678 /// \param K Defaultmap kind.
7679 void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; }
7680
7681 /// Set the defaultmap modifier.
7682 ///
7683 /// \param M Defaultmap modifier.
7684 void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) {
7685 Modifier = M;
7686 }
7687
7688 /// Set location of the defaultmap modifier.
7689 void setDefaultmapModifierLoc(SourceLocation Loc) {
7690 ModifierLoc = Loc;
7691 }
7692
7693 /// Sets the location of '('.
7694 ///
7695 /// \param Loc Location of '('.
7696 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7697
7698 /// Set defaultmap kind start location.
7699 ///
7700 /// \param KLoc Defaultmap kind location.
7701 void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
7702
7703public:
7704 /// Build 'defaultmap' clause with defaultmap kind \a Kind
7705 ///
7706 /// \param StartLoc Starting location of the clause.
7707 /// \param LParenLoc Location of '('.
7708 /// \param KLoc Starting location of the argument.
7709 /// \param EndLoc Ending location of the clause.
7710 /// \param Kind Defaultmap kind.
7711 /// \param M The modifier applied to 'defaultmap' clause.
7712 /// \param MLoc Location of the modifier
7713 OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc,
7714 SourceLocation MLoc, SourceLocation KLoc,
7715 SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind,
7716 OpenMPDefaultmapClauseModifier M)
7717 : OMPClause(llvm::omp::OMPC_defaultmap, StartLoc, EndLoc),
7718 LParenLoc(LParenLoc), Modifier(M), ModifierLoc(MLoc), Kind(Kind),
7719 KindLoc(KLoc) {}
7720
7721 /// Build an empty clause.
7723 : OMPClause(llvm::omp::OMPC_defaultmap, SourceLocation(),
7724 SourceLocation()) {}
7725
7726 /// Get kind of the clause.
7727 OpenMPDefaultmapClauseKind getDefaultmapKind() const { return Kind; }
7728
7729 /// Get the modifier of the clause.
7730 OpenMPDefaultmapClauseModifier getDefaultmapModifier() const {
7731 return Modifier;
7732 }
7733
7734 /// Get location of '('.
7735 SourceLocation getLParenLoc() { return LParenLoc; }
7736
7737 /// Get kind location.
7738 SourceLocation getDefaultmapKindLoc() { return KindLoc; }
7739
7740 /// Get the modifier location.
7741 SourceLocation getDefaultmapModifierLoc() const {
7742 return ModifierLoc;
7743 }
7744
7745 child_range children() {
7746 return child_range(child_iterator(), child_iterator());
7747 }
7748
7749 const_child_range children() const {
7750 return const_child_range(const_child_iterator(), const_child_iterator());
7751 }
7752
7753 child_range used_children() {
7754 return child_range(child_iterator(), child_iterator());
7755 }
7756 const_child_range used_children() const {
7757 return const_child_range(const_child_iterator(), const_child_iterator());
7758 }
7759
7760 static bool classof(const OMPClause *T) {
7761 return T->getClauseKind() == llvm::omp::OMPC_defaultmap;
7762 }
7763};
7764
7765/// This represents clause 'to' in the '#pragma omp ...'
7766/// directives.
7767///
7768/// \code
7769/// #pragma omp target update to(a,b)
7770/// \endcode
7771/// In this example directive '#pragma omp target update' has clause 'to'
7772/// with the variables 'a' and 'b'.
7773class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
7774 private llvm::TrailingObjects<
7775 OMPToClause, Expr *, ValueDecl *, unsigned,
7776 OMPClauseMappableExprCommon::MappableComponent> {
7777 friend class OMPClauseReader;
7778 friend OMPMappableExprListClause;
7779 friend OMPVarListClause;
7780 friend TrailingObjects;
7781
7782 /// Motion-modifiers for the 'to' clause.
7783 OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
7784 OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown,
7785 OMPC_MOTION_MODIFIER_unknown};
7786
7787 /// Location of motion-modifiers for the 'to' clause.
7788 SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
7789
7790 /// Colon location.
7791 SourceLocation ColonLoc;
7792
7793 /// Build clause with number of variables \a NumVars.
7794 ///
7795 /// \param TheMotionModifiers Motion-modifiers.
7796 /// \param TheMotionModifiersLoc Locations of motion-modifiers.
7797 /// \param MapperQualifierLoc C++ nested name specifier for the associated
7798 /// user-defined mapper.
7799 /// \param MapperIdInfo The identifier of associated user-defined mapper.
7800 /// \param Locs Locations needed to build a mappable clause. It includes 1)
7801 /// StartLoc: starting location of the clause (the clause keyword); 2)
7802 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
7803 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
7804 /// NumVars: number of expressions listed in this clause; 2)
7805 /// NumUniqueDeclarations: number of unique base declarations in this clause;
7806 /// 3) NumComponentLists: number of component lists in this clause; and 4)
7807 /// NumComponents: total number of expression components in the clause.
7808 explicit OMPToClause(ArrayRef<OpenMPMotionModifierKind> TheMotionModifiers,
7809 ArrayRef<SourceLocation> TheMotionModifiersLoc,
7810 NestedNameSpecifierLoc MapperQualifierLoc,
7811 DeclarationNameInfo MapperIdInfo,
7812 const OMPVarListLocTy &Locs,
7813 const OMPMappableExprListSizeTy &Sizes)
7814 : OMPMappableExprListClause(llvm::omp::OMPC_to, Locs, Sizes,
7815 /*SupportsMapper=*/true, &MapperQualifierLoc,
7816 &MapperIdInfo) {
7817 assert(std::size(MotionModifiers) == TheMotionModifiers.size() &&
7818 "Unexpected number of motion modifiers.");
7819 llvm::copy(TheMotionModifiers, std::begin(MotionModifiers));
7820
7821 assert(std::size(MotionModifiersLoc) == TheMotionModifiersLoc.size() &&
7822 "Unexpected number of motion modifier locations.");
7823 llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc));
7824 }
7825
7826 /// Build an empty clause.
7827 ///
7828 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
7829 /// NumVars: number of expressions listed in this clause; 2)
7830 /// NumUniqueDeclarations: number of unique base declarations in this clause;
7831 /// 3) NumComponentLists: number of component lists in this clause; and 4)
7832 /// NumComponents: total number of expression components in the clause.
7833 explicit OMPToClause(const OMPMappableExprListSizeTy &Sizes)
7834 : OMPMappableExprListClause(llvm::omp::OMPC_to, OMPVarListLocTy(), Sizes,
7835 /*SupportsMapper=*/true) {}
7836
7837 /// Set motion-modifier for the clause.
7838 ///
7839 /// \param I index for motion-modifier.
7840 /// \param T motion-modifier for the clause.
7841 void setMotionModifier(unsigned I, OpenMPMotionModifierKind T) {
7842 assert(I < NumberOfOMPMotionModifiers &&
7843 "Unexpected index to store motion modifier, exceeds array size.");
7844 MotionModifiers[I] = T;
7845 }
7846
7847 /// Set location for the motion-modifier.
7848 ///
7849 /// \param I index for motion-modifier location.
7850 /// \param TLoc motion-modifier location.
7851 void setMotionModifierLoc(unsigned I, SourceLocation TLoc) {
7852 assert(I < NumberOfOMPMotionModifiers &&
7853 "Index to store motion modifier location exceeds array size.");
7854 MotionModifiersLoc[I] = TLoc;
7855 }
7856
7857 void setIteratorModifier(Expr *IteratorModifier) {
7858 getTrailingObjects<Expr *>()[2 * varlist_size()] = IteratorModifier;
7859 }
7860 /// Set colon location.
7861 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
7862
7863 /// Define the sizes of each trailing object array except the last one. This
7864 /// is required for TrailingObjects to work properly.
7865 size_t numTrailingObjects(OverloadToken<Expr *>) const {
7866 // There are varlist_size() of expressions, and varlist_size() of
7867 // user-defined mappers.
7868 return 2 * varlist_size() + 1;
7869 }
7870 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
7871 return getUniqueDeclarationsNum();
7872 }
7873 size_t numTrailingObjects(OverloadToken<unsigned>) const {
7874 return getUniqueDeclarationsNum() + getTotalComponentListNum();
7875 }
7876
7877public:
7878 /// Creates clause with a list of variables \a Vars.
7879 ///
7880 /// \param C AST context.
7881 /// \param Locs Locations needed to build a mappable clause. It includes 1)
7882 /// StartLoc: starting location of the clause (the clause keyword); 2)
7883 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
7884 /// \param Vars The original expression used in the clause.
7885 /// \param Declarations Declarations used in the clause.
7886 /// \param ComponentLists Component lists used in the clause.
7887 /// \param MotionModifiers Motion-modifiers.
7888 /// \param MotionModifiersLoc Location of motion-modifiers.
7889 /// \param UDMapperRefs References to user-defined mappers associated with
7890 /// expressions used in the clause.
7891 /// \param UDMQualifierLoc C++ nested name specifier for the associated
7892 /// user-defined mapper.
7893 /// \param MapperId The identifier of associated user-defined mapper.
7894 static OMPToClause *
7895 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
7896 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
7897 MappableExprComponentListsRef ComponentLists,
7898 ArrayRef<Expr *> UDMapperRefs, Expr *IteratorModifier,
7899 ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
7900 ArrayRef<SourceLocation> MotionModifiersLoc,
7901 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId);
7902
7903 /// Creates an empty clause with the place for \a NumVars variables.
7904 ///
7905 /// \param C AST context.
7906 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
7907 /// NumVars: number of expressions listed in this clause; 2)
7908 /// NumUniqueDeclarations: number of unique base declarations in this clause;
7909 /// 3) NumComponentLists: number of component lists in this clause; and 4)
7910 /// NumComponents: total number of expression components in the clause.
7911 static OMPToClause *CreateEmpty(const ASTContext &C,
7912 const OMPMappableExprListSizeTy &Sizes);
7913
7914 /// Fetches the motion-modifier at 'Cnt' index of array of modifiers.
7915 ///
7916 /// \param Cnt index for motion-modifier.
7917 OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY {
7918 assert(Cnt < NumberOfOMPMotionModifiers &&
7919 "Requested modifier exceeds the total number of modifiers.");
7920 return MotionModifiers[Cnt];
7921 }
7922 Expr *getIteratorModifier() const {
7923 return getTrailingObjects<Expr *>()[2 * varlist_size()];
7924 }
7925 /// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
7926 /// locations.
7927 ///
7928 /// \param Cnt index for motion-modifier location.
7929 SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY {
7930 assert(Cnt < NumberOfOMPMotionModifiers &&
7931 "Requested modifier location exceeds total number of modifiers.");
7932 return MotionModifiersLoc[Cnt];
7933 }
7934
7935 /// Fetches ArrayRef of motion-modifiers.
7937 return MotionModifiers;
7938 }
7939
7940 /// Fetches ArrayRef of location of motion-modifiers.
7942 return MotionModifiersLoc;
7943 }
7944
7945 /// Get colon location.
7946 SourceLocation getColonLoc() const { return ColonLoc; }
7947
7948 child_range children() {
7949 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
7950 reinterpret_cast<Stmt **>(varlist_end()));
7951 }
7952
7953 const_child_range children() const {
7954 return const_cast<OMPToClause *>(this)->children();
7955 }
7956
7957 child_range used_children() {
7958 return child_range(child_iterator(), child_iterator());
7959 }
7960 const_child_range used_children() const {
7961 return const_child_range(const_child_iterator(), const_child_iterator());
7962 }
7963
7964 static bool classof(const OMPClause *T) {
7965 return T->getClauseKind() == llvm::omp::OMPC_to;
7966 }
7967};
7968
7969/// This represents clause 'from' in the '#pragma omp ...'
7970/// directives.
7971///
7972/// \code
7973/// #pragma omp target update from(a,b)
7974/// \endcode
7975/// In this example directive '#pragma omp target update' has clause 'from'
7976/// with the variables 'a' and 'b'.
7977class OMPFromClause final
7978 : public OMPMappableExprListClause<OMPFromClause>,
7979 private llvm::TrailingObjects<
7980 OMPFromClause, Expr *, ValueDecl *, unsigned,
7981 OMPClauseMappableExprCommon::MappableComponent> {
7982 friend class OMPClauseReader;
7983 friend OMPMappableExprListClause;
7984 friend OMPVarListClause;
7985 friend TrailingObjects;
7986
7987 /// Motion-modifiers for the 'from' clause.
7988 OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
7989 OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown,
7990 OMPC_MOTION_MODIFIER_unknown};
7991
7992 /// Location of motion-modifiers for the 'from' clause.
7993 SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
7994
7995 /// Colon location.
7996 SourceLocation ColonLoc;
7997
7998 /// Build clause with number of variables \a NumVars.
7999 ///
8000 /// \param TheMotionModifiers Motion-modifiers.
8001 /// \param TheMotionModifiersLoc Locations of motion-modifiers.
8002 /// \param MapperQualifierLoc C++ nested name specifier for the associated
8003 /// user-defined mapper.
8004 /// \param MapperIdInfo The identifier of associated user-defined mapper.
8005 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8006 /// StartLoc: starting location of the clause (the clause keyword); 2)
8007 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8008 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8009 /// NumVars: number of expressions listed in this clause; 2)
8010 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8011 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8012 /// NumComponents: total number of expression components in the clause.
8013 explicit OMPFromClause(ArrayRef<OpenMPMotionModifierKind> TheMotionModifiers,
8014 ArrayRef<SourceLocation> TheMotionModifiersLoc,
8015 NestedNameSpecifierLoc MapperQualifierLoc,
8016 DeclarationNameInfo MapperIdInfo,
8017 const OMPVarListLocTy &Locs,
8018 const OMPMappableExprListSizeTy &Sizes)
8019 : OMPMappableExprListClause(llvm::omp::OMPC_from, Locs, Sizes,
8020 /*SupportsMapper=*/true, &MapperQualifierLoc,
8021 &MapperIdInfo) {
8022 assert(std::size(MotionModifiers) == TheMotionModifiers.size() &&
8023 "Unexpected number of motion modifiers.");
8024 llvm::copy(TheMotionModifiers, std::begin(MotionModifiers));
8025
8026 assert(std::size(MotionModifiersLoc) == TheMotionModifiersLoc.size() &&
8027 "Unexpected number of motion modifier locations.");
8028 llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc));
8029 }
8030
8031 /// Build an empty clause.
8032 ///
8033 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8034 /// NumVars: number of expressions listed in this clause; 2)
8035 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8036 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8037 /// NumComponents: total number of expression components in the clause.
8038 explicit OMPFromClause(const OMPMappableExprListSizeTy &Sizes)
8039 : OMPMappableExprListClause(llvm::omp::OMPC_from, OMPVarListLocTy(),
8040 Sizes, /*SupportsMapper=*/true) {}
8041
8042 /// Set motion-modifier for the clause.
8043 ///
8044 /// \param I index for motion-modifier.
8045 /// \param T motion-modifier for the clause.
8046 void setMotionModifier(unsigned I, OpenMPMotionModifierKind T) {
8047 assert(I < NumberOfOMPMotionModifiers &&
8048 "Unexpected index to store motion modifier, exceeds array size.");
8049 MotionModifiers[I] = T;
8050 }
8051 void setIteratorModifier(Expr *IteratorModifier) {
8052 getTrailingObjects<Expr *>()[2 * varlist_size()] = IteratorModifier;
8053 }
8054 /// Set location for the motion-modifier.
8055 ///
8056 /// \param I index for motion-modifier location.
8057 /// \param TLoc motion-modifier location.
8058 void setMotionModifierLoc(unsigned I, SourceLocation TLoc) {
8059 assert(I < NumberOfOMPMotionModifiers &&
8060 "Index to store motion modifier location exceeds array size.");
8061 MotionModifiersLoc[I] = TLoc;
8062 }
8063
8064 /// Set colon location.
8065 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
8066
8067 /// Define the sizes of each trailing object array except the last one. This
8068 /// is required for TrailingObjects to work properly.
8069 size_t numTrailingObjects(OverloadToken<Expr *>) const {
8070 // There are varlist_size() of expressions, and varlist_size() of
8071 // user-defined mappers.
8072 return 2 * varlist_size() + 1;
8073 }
8074 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
8075 return getUniqueDeclarationsNum();
8076 }
8077 size_t numTrailingObjects(OverloadToken<unsigned>) const {
8078 return getUniqueDeclarationsNum() + getTotalComponentListNum();
8079 }
8080
8081public:
8082 /// Creates clause with a list of variables \a Vars.
8083 ///
8084 /// \param C AST context.
8085 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8086 /// StartLoc: starting location of the clause (the clause keyword); 2)
8087 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8088 /// \param Vars The original expression used in the clause.
8089 /// \param Declarations Declarations used in the clause.
8090 /// \param ComponentLists Component lists used in the clause.
8091 /// \param MotionModifiers Motion-modifiers.
8092 /// \param MotionModifiersLoc Location of motion-modifiers.
8093 /// \param UDMapperRefs References to user-defined mappers associated with
8094 /// expressions used in the clause.
8095 /// \param UDMQualifierLoc C++ nested name specifier for the associated
8096 /// user-defined mapper.
8097 /// \param MapperId The identifier of associated user-defined mapper.
8098 static OMPFromClause *
8099 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
8100 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
8101 MappableExprComponentListsRef ComponentLists,
8102 ArrayRef<Expr *> UDMapperRefs, Expr *IteratorExpr,
8103 ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
8104 ArrayRef<SourceLocation> MotionModifiersLoc,
8105 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId);
8106
8107 /// Creates an empty clause with the place for \a NumVars variables.
8108 ///
8109 /// \param C AST context.
8110 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8111 /// NumVars: number of expressions listed in this clause; 2)
8112 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8113 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8114 /// NumComponents: total number of expression components in the clause.
8115 static OMPFromClause *CreateEmpty(const ASTContext &C,
8116 const OMPMappableExprListSizeTy &Sizes);
8117
8118 /// Fetches the motion-modifier at 'Cnt' index of array of modifiers.
8119 ///
8120 /// \param Cnt index for motion-modifier.
8121 OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY {
8122 assert(Cnt < NumberOfOMPMotionModifiers &&
8123 "Requested modifier exceeds the total number of modifiers.");
8124 return MotionModifiers[Cnt];
8125 }
8126 Expr *getIteratorModifier() const {
8127 return getTrailingObjects<Expr *>()[2 * varlist_size()];
8128 }
8129 /// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
8130 /// locations.
8131 ///
8132 /// \param Cnt index for motion-modifier location.
8133 SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY {
8134 assert(Cnt < NumberOfOMPMotionModifiers &&
8135 "Requested modifier location exceeds total number of modifiers.");
8136 return MotionModifiersLoc[Cnt];
8137 }
8138
8139 /// Fetches ArrayRef of motion-modifiers.
8141 return MotionModifiers;
8142 }
8143
8144 /// Fetches ArrayRef of location of motion-modifiers.
8146 return MotionModifiersLoc;
8147 }
8148
8149 /// Get colon location.
8150 SourceLocation getColonLoc() const { return ColonLoc; }
8151
8152 child_range children() {
8153 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8154 reinterpret_cast<Stmt **>(varlist_end()));
8155 }
8156
8157 const_child_range children() const {
8158 return const_cast<OMPFromClause *>(this)->children();
8159 }
8160
8161 child_range used_children() {
8162 return child_range(child_iterator(), child_iterator());
8163 }
8164 const_child_range used_children() const {
8165 return const_child_range(const_child_iterator(), const_child_iterator());
8166 }
8167
8168 static bool classof(const OMPClause *T) {
8169 return T->getClauseKind() == llvm::omp::OMPC_from;
8170 }
8171};
8172
8173/// This represents clause 'use_device_ptr' in the '#pragma omp ...'
8174/// directives.
8175///
8176/// \code
8177/// #pragma omp target data use_device_ptr(a,b)
8178/// \endcode
8179/// In this example directive '#pragma omp target data' has clause
8180/// 'use_device_ptr' with the variables 'a' and 'b'.
8181class OMPUseDevicePtrClause final
8182 : public OMPMappableExprListClause<OMPUseDevicePtrClause>,
8183 private llvm::TrailingObjects<
8184 OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned,
8185 OMPClauseMappableExprCommon::MappableComponent> {
8186 friend class OMPClauseReader;
8187 friend OMPMappableExprListClause;
8188 friend OMPVarListClause;
8189 friend TrailingObjects;
8190
8191 /// Fallback modifier for the clause.
8192 OpenMPUseDevicePtrFallbackModifier FallbackModifier =
8193 OMPC_USE_DEVICE_PTR_FALLBACK_unknown;
8194
8195 /// Location of the fallback modifier.
8196 SourceLocation FallbackModifierLoc;
8197
8198 /// Build clause with number of variables \a NumVars.
8199 ///
8200 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8201 /// StartLoc: starting location of the clause (the clause keyword); 2)
8202 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8203 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8204 /// NumVars: number of expressions listed in this clause; 2)
8205 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8206 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8207 /// NumComponents: total number of expression components in the clause.
8208 /// \param FallbackModifier The fallback modifier for the clause.
8209 /// \param FallbackModifierLoc Location of the fallback modifier.
8210 explicit OMPUseDevicePtrClause(
8211 const OMPVarListLocTy &Locs, const OMPMappableExprListSizeTy &Sizes,
8212 OpenMPUseDevicePtrFallbackModifier FallbackModifier,
8213 SourceLocation FallbackModifierLoc)
8214 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_ptr, Locs, Sizes),
8215 FallbackModifier(FallbackModifier),
8216 FallbackModifierLoc(FallbackModifierLoc) {}
8217
8218 /// Build an empty clause.
8219 ///
8220 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8221 /// NumVars: number of expressions listed in this clause; 2)
8222 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8223 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8224 /// NumComponents: total number of expression components in the clause.
8226 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_ptr,
8227 OMPVarListLocTy(), Sizes) {}
8228
8229 /// Define the sizes of each trailing object array except the last one. This
8230 /// is required for TrailingObjects to work properly.
8231 size_t numTrailingObjects(OverloadToken<Expr *>) const {
8232 return 3 * varlist_size();
8233 }
8234 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
8235 return getUniqueDeclarationsNum();
8236 }
8237 size_t numTrailingObjects(OverloadToken<unsigned>) const {
8238 return getUniqueDeclarationsNum() + getTotalComponentListNum();
8239 }
8240
8241 /// Sets the list of references to private copies with initializers for new
8242 /// private variables.
8243 /// \param VL List of references.
8244 void setPrivateCopies(ArrayRef<Expr *> VL);
8245
8246 /// Gets the list of references to private copies with initializers for new
8247 /// private variables.
8248 MutableArrayRef<Expr *> getPrivateCopies() {
8249 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
8250 }
8251 ArrayRef<const Expr *> getPrivateCopies() const {
8252 return {varlist_end(), varlist_size()};
8253 }
8254
8255 /// Sets the list of references to initializer variables for new private
8256 /// variables.
8257 /// \param VL List of references.
8258 void setInits(ArrayRef<Expr *> VL);
8259
8260 /// Gets the list of references to initializer variables for new private
8261 /// variables.
8262 MutableArrayRef<Expr *> getInits() {
8263 return {getPrivateCopies().end(), varlist_size()};
8264 }
8265 ArrayRef<const Expr *> getInits() const {
8266 return {getPrivateCopies().end(), varlist_size()};
8267 }
8268
8269 /// Set the fallback modifier for the clause.
8270 void setFallbackModifier(OpenMPUseDevicePtrFallbackModifier M) {
8271 FallbackModifier = M;
8272 }
8273
8274 /// Set the location of the fallback modifier.
8275 void setFallbackModifierLoc(SourceLocation Loc) { FallbackModifierLoc = Loc; }
8276
8277public:
8278 /// Creates clause with a list of variables \a Vars.
8279 ///
8280 /// \param C AST context.
8281 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8282 /// StartLoc: starting location of the clause (the clause keyword); 2)
8283 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8284 /// \param Vars The original expression used in the clause.
8285 /// \param PrivateVars Expressions referring to private copies.
8286 /// \param Inits Expressions referring to private copy initializers.
8287 /// \param Declarations Declarations used in the clause.
8288 /// \param ComponentLists Component lists used in the clause.
8289 /// \param FallbackModifier The fallback modifier for the clause.
8290 /// \param FallbackModifierLoc Location of the fallback modifier.
8291 static OMPUseDevicePtrClause *
8292 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
8293 ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
8294 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
8295 MappableExprComponentListsRef ComponentLists,
8296 OpenMPUseDevicePtrFallbackModifier FallbackModifier,
8297 SourceLocation FallbackModifierLoc);
8298
8299 /// Creates an empty clause with the place for \a NumVars variables.
8300 ///
8301 /// \param C AST context.
8302 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8303 /// NumVars: number of expressions listed in this clause; 2)
8304 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8305 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8306 /// NumComponents: total number of expression components in the clause.
8307 static OMPUseDevicePtrClause *
8308 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
8309
8310 /// Get the fallback modifier for the clause.
8311 OpenMPUseDevicePtrFallbackModifier getFallbackModifier() const {
8312 return FallbackModifier;
8313 }
8314
8315 /// Get the location of the fallback modifier.
8316 SourceLocation getFallbackModifierLoc() const { return FallbackModifierLoc; }
8317
8318 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
8320 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
8322 llvm::iterator_range<private_copies_const_iterator>;
8323
8324 private_copies_range private_copies() { return getPrivateCopies(); }
8325
8327 return getPrivateCopies();
8328 }
8329
8330 using inits_iterator = MutableArrayRef<Expr *>::iterator;
8332 using inits_range = llvm::iterator_range<inits_iterator>;
8333 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
8334
8335 inits_range inits() { return getInits(); }
8336
8337 inits_const_range inits() const { return getInits(); }
8338
8339 child_range children() {
8340 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8341 reinterpret_cast<Stmt **>(varlist_end()));
8342 }
8343
8344 const_child_range children() const {
8345 return const_cast<OMPUseDevicePtrClause *>(this)->children();
8346 }
8347
8348 child_range used_children() {
8349 return child_range(child_iterator(), child_iterator());
8350 }
8351 const_child_range used_children() const {
8352 return const_child_range(const_child_iterator(), const_child_iterator());
8353 }
8354
8355 static bool classof(const OMPClause *T) {
8356 return T->getClauseKind() == llvm::omp::OMPC_use_device_ptr;
8357 }
8358};
8359
8360/// This represents clause 'use_device_addr' in the '#pragma omp ...'
8361/// directives.
8362///
8363/// \code
8364/// #pragma omp target data use_device_addr(a,b)
8365/// \endcode
8366/// In this example directive '#pragma omp target data' has clause
8367/// 'use_device_addr' with the variables 'a' and 'b'.
8368class OMPUseDeviceAddrClause final
8369 : public OMPMappableExprListClause<OMPUseDeviceAddrClause>,
8370 private llvm::TrailingObjects<
8371 OMPUseDeviceAddrClause, Expr *, ValueDecl *, unsigned,
8372 OMPClauseMappableExprCommon::MappableComponent> {
8373 friend class OMPClauseReader;
8374 friend OMPMappableExprListClause;
8375 friend OMPVarListClause;
8376 friend TrailingObjects;
8377
8378 /// Build clause with number of variables \a NumVars.
8379 ///
8380 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8381 /// StartLoc: starting location of the clause (the clause keyword); 2)
8382 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8383 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8384 /// NumVars: number of expressions listed in this clause; 2)
8385 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8386 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8387 /// NumComponents: total number of expression components in the clause.
8388 explicit OMPUseDeviceAddrClause(const OMPVarListLocTy &Locs,
8389 const OMPMappableExprListSizeTy &Sizes)
8390 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_addr, Locs,
8391 Sizes) {}
8392
8393 /// Build an empty clause.
8394 ///
8395 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8396 /// NumVars: number of expressions listed in this clause; 2)
8397 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8398 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8399 /// NumComponents: total number of expression components in the clause.
8401 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_addr,
8402 OMPVarListLocTy(), Sizes) {}
8403
8404 /// Define the sizes of each trailing object array except the last one. This
8405 /// is required for TrailingObjects to work properly.
8406 size_t numTrailingObjects(OverloadToken<Expr *>) const {
8407 return varlist_size();
8408 }
8409 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
8410 return getUniqueDeclarationsNum();
8411 }
8412 size_t numTrailingObjects(OverloadToken<unsigned>) const {
8413 return getUniqueDeclarationsNum() + getTotalComponentListNum();
8414 }
8415
8416public:
8417 /// Creates clause with a list of variables \a Vars.
8418 ///
8419 /// \param C AST context.
8420 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8421 /// StartLoc: starting location of the clause (the clause keyword); 2)
8422 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8423 /// \param Vars The original expression used in the clause.
8424 /// \param Declarations Declarations used in the clause.
8425 /// \param ComponentLists Component lists used in the clause.
8426 static OMPUseDeviceAddrClause *
8427 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
8428 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
8429 MappableExprComponentListsRef ComponentLists);
8430
8431 /// Creates an empty clause with the place for \a NumVars variables.
8432 ///
8433 /// \param C AST context.
8434 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8435 /// NumVars: number of expressions listed in this clause; 2)
8436 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8437 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8438 /// NumComponents: total number of expression components in the clause.
8439 static OMPUseDeviceAddrClause *
8440 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
8441
8442 child_range children() {
8443 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8444 reinterpret_cast<Stmt **>(varlist_end()));
8445 }
8446
8447 const_child_range children() const {
8448 return const_cast<OMPUseDeviceAddrClause *>(this)->children();
8449 }
8450
8451 child_range used_children() {
8452 return child_range(child_iterator(), child_iterator());
8453 }
8454 const_child_range used_children() const {
8455 return const_child_range(const_child_iterator(), const_child_iterator());
8456 }
8457
8458 static bool classof(const OMPClause *T) {
8459 return T->getClauseKind() == llvm::omp::OMPC_use_device_addr;
8460 }
8461};
8462
8463/// This represents clause 'is_device_ptr' in the '#pragma omp ...'
8464/// directives.
8465///
8466/// \code
8467/// #pragma omp target is_device_ptr(a,b)
8468/// \endcode
8469/// In this example directive '#pragma omp target' has clause
8470/// 'is_device_ptr' with the variables 'a' and 'b'.
8471class OMPIsDevicePtrClause final
8472 : public OMPMappableExprListClause<OMPIsDevicePtrClause>,
8473 private llvm::TrailingObjects<
8474 OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned,
8475 OMPClauseMappableExprCommon::MappableComponent> {
8476 friend class OMPClauseReader;
8477 friend OMPMappableExprListClause;
8478 friend OMPVarListClause;
8479 friend TrailingObjects;
8480
8481 /// Build clause with number of variables \a NumVars.
8482 ///
8483 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8484 /// StartLoc: starting location of the clause (the clause keyword); 2)
8485 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8486 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8487 /// NumVars: number of expressions listed in this clause; 2)
8488 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8489 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8490 /// NumComponents: total number of expression components in the clause.
8491 explicit OMPIsDevicePtrClause(const OMPVarListLocTy &Locs,
8492 const OMPMappableExprListSizeTy &Sizes)
8493 : OMPMappableExprListClause(llvm::omp::OMPC_is_device_ptr, Locs, Sizes) {}
8494
8495 /// Build an empty clause.
8496 ///
8497 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8498 /// NumVars: number of expressions listed in this clause; 2)
8499 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8500 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8501 /// NumComponents: total number of expression components in the clause.
8502 explicit OMPIsDevicePtrClause(const OMPMappableExprListSizeTy &Sizes)
8503 : OMPMappableExprListClause(llvm::omp::OMPC_is_device_ptr,
8504 OMPVarListLocTy(), Sizes) {}
8505
8506 /// Define the sizes of each trailing object array except the last one. This
8507 /// is required for TrailingObjects to work properly.
8508 size_t numTrailingObjects(OverloadToken<Expr *>) const {
8509 return varlist_size();
8510 }
8511 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
8512 return getUniqueDeclarationsNum();
8513 }
8514 size_t numTrailingObjects(OverloadToken<unsigned>) const {
8515 return getUniqueDeclarationsNum() + getTotalComponentListNum();
8516 }
8517
8518public:
8519 /// Creates clause with a list of variables \a Vars.
8520 ///
8521 /// \param C AST context.
8522 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8523 /// StartLoc: starting location of the clause (the clause keyword); 2)
8524 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8525 /// \param Vars The original expression used in the clause.
8526 /// \param Declarations Declarations used in the clause.
8527 /// \param ComponentLists Component lists used in the clause.
8528 static OMPIsDevicePtrClause *
8529 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
8530 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
8531 MappableExprComponentListsRef ComponentLists);
8532
8533 /// Creates an empty clause with the place for \a NumVars variables.
8534 ///
8535 /// \param C AST context.
8536 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8537 /// NumVars: number of expressions listed in this clause; 2)
8538 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8539 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8540 /// NumComponents: total number of expression components in the clause.
8541 static OMPIsDevicePtrClause *
8542 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
8543
8544 child_range children() {
8545 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8546 reinterpret_cast<Stmt **>(varlist_end()));
8547 }
8548
8549 const_child_range children() const {
8550 return const_cast<OMPIsDevicePtrClause *>(this)->children();
8551 }
8552
8553 child_range used_children() {
8554 return child_range(child_iterator(), child_iterator());
8555 }
8556 const_child_range used_children() const {
8557 return const_child_range(const_child_iterator(), const_child_iterator());
8558 }
8559
8560 static bool classof(const OMPClause *T) {
8561 return T->getClauseKind() == llvm::omp::OMPC_is_device_ptr;
8562 }
8563};
8564
8565/// This represents clause 'has_device_ptr' in the '#pragma omp ...'
8566/// directives.
8567///
8568/// \code
8569/// #pragma omp target has_device_addr(a,b)
8570/// \endcode
8571/// In this example directive '#pragma omp target' has clause
8572/// 'has_device_ptr' with the variables 'a' and 'b'.
8573class OMPHasDeviceAddrClause final
8574 : public OMPMappableExprListClause<OMPHasDeviceAddrClause>,
8575 private llvm::TrailingObjects<
8576 OMPHasDeviceAddrClause, Expr *, ValueDecl *, unsigned,
8577 OMPClauseMappableExprCommon::MappableComponent> {
8578 friend class OMPClauseReader;
8579 friend OMPMappableExprListClause;
8580 friend OMPVarListClause;
8581 friend TrailingObjects;
8582
8583 /// Build clause with number of variables \a NumVars.
8584 ///
8585 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8586 /// StartLoc: starting location of the clause (the clause keyword); 2)
8587 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8588 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8589 /// NumVars: number of expressions listed in this clause; 2)
8590 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8591 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8592 /// NumComponents: total number of expression components in the clause.
8593 explicit OMPHasDeviceAddrClause(const OMPVarListLocTy &Locs,
8594 const OMPMappableExprListSizeTy &Sizes)
8595 : OMPMappableExprListClause(llvm::omp::OMPC_has_device_addr, Locs,
8596 Sizes) {}
8597
8598 /// Build an empty clause.
8599 ///
8600 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8601 /// NumVars: number of expressions listed in this clause; 2)
8602 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8603 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8604 /// NumComponents: total number of expression components in the clause.
8606 : OMPMappableExprListClause(llvm::omp::OMPC_has_device_addr,
8607 OMPVarListLocTy(), Sizes) {}
8608
8609 /// Define the sizes of each trailing object array except the last one. This
8610 /// is required for TrailingObjects to work properly.
8611 size_t numTrailingObjects(OverloadToken<Expr *>) const {
8612 return varlist_size();
8613 }
8614 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
8615 return getUniqueDeclarationsNum();
8616 }
8617 size_t numTrailingObjects(OverloadToken<unsigned>) const {
8618 return getUniqueDeclarationsNum() + getTotalComponentListNum();
8619 }
8620
8621public:
8622 /// Creates clause with a list of variables \a Vars.
8623 ///
8624 /// \param C AST context.
8625 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8626 /// StartLoc: starting location of the clause (the clause keyword); 2)
8627 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8628 /// \param Vars The original expression used in the clause.
8629 /// \param Declarations Declarations used in the clause.
8630 /// \param ComponentLists Component lists used in the clause.
8631 static OMPHasDeviceAddrClause *
8632 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
8633 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
8634 MappableExprComponentListsRef ComponentLists);
8635
8636 /// Creates an empty clause with the place for \a NumVars variables.
8637 ///
8638 /// \param C AST context.
8639 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8640 /// NumVars: number of expressions listed in this clause; 2)
8641 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8642 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8643 /// NumComponents: total number of expression components in the clause.
8644 static OMPHasDeviceAddrClause *
8645 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
8646
8647 child_range children() {
8648 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8649 reinterpret_cast<Stmt **>(varlist_end()));
8650 }
8651
8652 const_child_range children() const {
8653 return const_cast<OMPHasDeviceAddrClause *>(this)->children();
8654 }
8655
8656 child_range used_children() {
8657 return child_range(child_iterator(), child_iterator());
8658 }
8659 const_child_range used_children() const {
8660 return const_child_range(const_child_iterator(), const_child_iterator());
8661 }
8662
8663 static bool classof(const OMPClause *T) {
8664 return T->getClauseKind() == llvm::omp::OMPC_has_device_addr;
8665 }
8666};
8667
8668/// This represents clause 'nontemporal' in the '#pragma omp ...' directives.
8669///
8670/// \code
8671/// #pragma omp simd nontemporal(a)
8672/// \endcode
8673/// In this example directive '#pragma omp simd' has clause 'nontemporal' for
8674/// the variable 'a'.
8675class OMPNontemporalClause final
8676 : public OMPVarListClause<OMPNontemporalClause>,
8677 private llvm::TrailingObjects<OMPNontemporalClause, Expr *> {
8678 friend class OMPClauseReader;
8679 friend OMPVarListClause;
8680 friend TrailingObjects;
8681
8682 /// Build clause with number of variables \a N.
8683 ///
8684 /// \param StartLoc Starting location of the clause.
8685 /// \param LParenLoc Location of '('.
8686 /// \param EndLoc Ending location of the clause.
8687 /// \param N Number of the variables in the clause.
8688 OMPNontemporalClause(SourceLocation StartLoc, SourceLocation LParenLoc,
8689 SourceLocation EndLoc, unsigned N)
8690 : OMPVarListClause<OMPNontemporalClause>(llvm::omp::OMPC_nontemporal,
8691 StartLoc, LParenLoc, EndLoc, N) {
8692 }
8693
8694 /// Build an empty clause.
8695 ///
8696 /// \param N Number of variables.
8697 explicit OMPNontemporalClause(unsigned N)
8698 : OMPVarListClause<OMPNontemporalClause>(
8699 llvm::omp::OMPC_nontemporal, SourceLocation(), SourceLocation(),
8700 SourceLocation(), N) {}
8701
8702 /// Get the list of privatied copies if the member expression was captured by
8703 /// one of the privatization clauses.
8704 MutableArrayRef<Expr *> getPrivateRefs() {
8705 return {varlist_end(), varlist_size()};
8706 }
8707 ArrayRef<const Expr *> getPrivateRefs() const {
8708 return {varlist_end(), varlist_size()};
8709 }
8710
8711public:
8712 /// Creates clause with a list of variables \a VL.
8713 ///
8714 /// \param C AST context.
8715 /// \param StartLoc Starting location of the clause.
8716 /// \param LParenLoc Location of '('.
8717 /// \param EndLoc Ending location of the clause.
8718 /// \param VL List of references to the variables.
8719 static OMPNontemporalClause *
8720 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
8721 SourceLocation EndLoc, ArrayRef<Expr *> VL);
8722
8723 /// Creates an empty clause with the place for \a N variables.
8724 ///
8725 /// \param C AST context.
8726 /// \param N The number of variables.
8727 static OMPNontemporalClause *CreateEmpty(const ASTContext &C, unsigned N);
8728
8729 /// Sets the list of references to private copies created in private clauses.
8730 /// \param VL List of references.
8731 void setPrivateRefs(ArrayRef<Expr *> VL);
8732
8733 child_range children() {
8734 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8735 reinterpret_cast<Stmt **>(varlist_end()));
8736 }
8737
8738 const_child_range children() const {
8739 return const_cast<OMPNontemporalClause *>(this)->children();
8740 }
8741
8742 child_range private_refs() {
8743 return child_range(reinterpret_cast<Stmt **>(getPrivateRefs().begin()),
8744 reinterpret_cast<Stmt **>(getPrivateRefs().end()));
8745 }
8746
8747 const_child_range private_refs() const {
8748 return const_cast<OMPNontemporalClause *>(this)->private_refs();
8749 }
8750
8751 child_range used_children() {
8752 return child_range(child_iterator(), child_iterator());
8753 }
8754 const_child_range used_children() const {
8755 return const_child_range(const_child_iterator(), const_child_iterator());
8756 }
8757
8758 static bool classof(const OMPClause *T) {
8759 return T->getClauseKind() == llvm::omp::OMPC_nontemporal;
8760 }
8761};
8762
8763/// This represents 'order' clause in the '#pragma omp ...' directive.
8764///
8765/// \code
8766/// #pragma omp simd order(concurrent)
8767/// \endcode
8768/// In this example directive '#pragma omp parallel' has simple 'order'
8769/// clause with kind 'concurrent'.
8770class OMPOrderClause final : public OMPClause {
8771 friend class OMPClauseReader;
8772
8773 /// Location of '('.
8774 SourceLocation LParenLoc;
8775
8776 /// A kind of the 'order' clause.
8777 OpenMPOrderClauseKind Kind = OMPC_ORDER_unknown;
8778
8779 /// Start location of the kind in source code.
8780 SourceLocation KindKwLoc;
8781
8782 /// A modifier for order clause
8783 OpenMPOrderClauseModifier Modifier = OMPC_ORDER_MODIFIER_unknown;
8784
8785 /// Start location of the modifier in source code.
8786 SourceLocation ModifierKwLoc;
8787
8788 /// Set kind of the clause.
8789 ///
8790 /// \param K Argument of clause.
8791 void setKind(OpenMPOrderClauseKind K) { Kind = K; }
8792
8793 /// Set argument location.
8794 ///
8795 /// \param KLoc Argument location.
8796 void setKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
8797
8798 /// Set modifier of the clause.
8799 ///
8800 /// \param M Argument of clause.
8801 void setModifier(OpenMPOrderClauseModifier M) { Modifier = M; }
8802
8803 /// Set modifier location.
8804 ///
8805 /// \param MLoc Modifier keyword location.
8806 void setModifierKwLoc(SourceLocation MLoc) { ModifierKwLoc = MLoc; }
8807
8808public:
8809 /// Build 'order' clause with argument \p A ('concurrent').
8810 ///
8811 /// \param A Argument of the clause ('concurrent').
8812 /// \param ALoc Starting location of the argument.
8813 /// \param StartLoc Starting location of the clause.
8814 /// \param LParenLoc Location of '('.
8815 /// \param EndLoc Ending location of the clause.
8816 /// \param Modifier The modifier applied to 'order' clause.
8817 /// \param MLoc Location of the modifier
8818 OMPOrderClause(OpenMPOrderClauseKind A, SourceLocation ALoc,
8819 SourceLocation StartLoc, SourceLocation LParenLoc,
8820 SourceLocation EndLoc, OpenMPOrderClauseModifier Modifier,
8821 SourceLocation MLoc)
8822 : OMPClause(llvm::omp::OMPC_order, StartLoc, EndLoc),
8823 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc), Modifier(Modifier),
8824 ModifierKwLoc(MLoc) {}
8825
8826 /// Build an empty clause.
8828 : OMPClause(llvm::omp::OMPC_order, SourceLocation(), SourceLocation()) {}
8829
8830 /// Sets the location of '('.
8831 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
8832
8833 /// Returns the location of '('.
8834 SourceLocation getLParenLoc() const { return LParenLoc; }
8835
8836 /// Returns kind of the clause.
8837 OpenMPOrderClauseKind getKind() const { return Kind; }
8838
8839 /// Returns location of clause kind.
8840 SourceLocation getKindKwLoc() const { return KindKwLoc; }
8841
8842 /// Returns Modifier of the clause.
8843 OpenMPOrderClauseModifier getModifier() const { return Modifier; }
8844
8845 /// Returns location of clause modifier.
8846 SourceLocation getModifierKwLoc() const { return ModifierKwLoc; }
8847
8848 child_range children() {
8849 return child_range(child_iterator(), child_iterator());
8850 }
8851
8852 const_child_range children() const {
8853 return const_child_range(const_child_iterator(), const_child_iterator());
8854 }
8855
8856 child_range used_children() {
8857 return child_range(child_iterator(), child_iterator());
8858 }
8859 const_child_range used_children() const {
8860 return const_child_range(const_child_iterator(), const_child_iterator());
8861 }
8862
8863 static bool classof(const OMPClause *T) {
8864 return T->getClauseKind() == llvm::omp::OMPC_order;
8865 }
8866};
8867
8868/// This represents the 'init' clause in '#pragma omp ...' directives.
8869///
8870/// \code
8871/// #pragma omp interop init(target:obj)
8872/// \endcode
8873class OMPInitClause final
8874 : public OMPVarListClause<OMPInitClause>,
8875 private llvm::TrailingObjects<OMPInitClause, Expr *, unsigned> {
8876 friend class OMPClauseReader;
8877 friend OMPVarListClause;
8878 friend TrailingObjects;
8879
8880 /// Location of interop variable.
8881 SourceLocation VarLoc;
8882
8883 bool IsTarget = false;
8884 bool IsTargetSync = false;
8885 bool HasPreferAttrs = false;
8886
8887 /// Total number of attr() exprs across all pref-specs; equals the last entry
8888 /// of the trailing unsigned[] of cumulative end offsets (or 0 if no prefs).
8889 unsigned NumAttrs = 0;
8890
8891 /// Trailing-objects layout (single contiguous Expr* array):
8892 /// Expr*[ varlist_size() + NumAttrs ]:
8893 /// [0] = InteropVar
8894 /// [1 .. NumPrefs] = Fr expr per pref-spec (null if attr-only)
8895 /// [varlist_size() ..] = flat list of attr exprs, concatenated in
8896 /// pref-spec order
8897 /// unsigned[ NumPrefs ]:
8898 /// [i] = end offset of pref-spec i's attrs in the flat
8899 /// attr block (inclusive cumulative attr count);
8900 /// spec i's attrs are [ends[i-1], ends[i]), with
8901 /// an implicit 0 before ends[0]
8902 ///
8903 /// varlist_size() = 1 + NumPrefs, so OMPVarListClause iteration covers
8904 /// InteropVar + the Fr block.
8905
8906 size_t numTrailingObjects(OverloadToken<Expr *>) const {
8907 return varlist_size() + NumAttrs;
8908 }
8909 size_t numTrailingObjects(OverloadToken<unsigned>) const {
8910 return getNumPrefs();
8911 }
8912
8913 void setInteropVar(Expr *E) { varlist_begin()[0] = E; }
8914
8915 void setIsTarget(bool V) { IsTarget = V; }
8916
8917 void setIsTargetSync(bool V) { IsTargetSync = V; }
8918
8919 void setHasPreferAttrs(bool V) { HasPreferAttrs = V; }
8920
8921 void setAttrs(ArrayRef<unsigned> Counts, ArrayRef<Expr *> Attrs);
8922
8923 /// Number of pref-specs in prefer_type(...).
8924 unsigned getNumPrefs() const { return varlist_size() - 1; }
8925
8926 /// Per-pref-spec attr end offsets: entry i is the inclusive cumulative attr
8927 /// count through pref-spec i (one past its last attr in the flat attr block).
8928 ArrayRef<unsigned> getAttrEnds() const {
8929 return getTrailingObjects<unsigned>(getNumPrefs());
8930 }
8931
8932 /// Sets the location of the interop variable.
8933 void setVarLoc(SourceLocation Loc) { VarLoc = Loc; }
8934
8935 /// Build 'init' clause.
8936 ///
8937 /// \param IsTarget Uses the 'target' interop-type.
8938 /// \param IsTargetSync Uses the 'targetsync' interop-type.
8939 /// \param StartLoc Starting location of the clause.
8940 /// \param LParenLoc Location of '('.
8941 /// \param VarLoc Location of the interop variable.
8942 /// \param EndLoc Ending location of the clause.
8943 /// \param N Number of varlist entries (1 + NumPrefs).
8944 OMPInitClause(bool IsTarget, bool IsTargetSync, SourceLocation StartLoc,
8945 SourceLocation LParenLoc, SourceLocation VarLoc,
8946 SourceLocation EndLoc, unsigned N)
8947 : OMPVarListClause<OMPInitClause>(llvm::omp::OMPC_init, StartLoc,
8948 LParenLoc, EndLoc, N),
8949 VarLoc(VarLoc), IsTarget(IsTarget), IsTargetSync(IsTargetSync) {}
8950
8951 /// Build an empty clause.
8952 OMPInitClause(unsigned N)
8953 : OMPVarListClause<OMPInitClause>(llvm::omp::OMPC_init, SourceLocation(),
8954 SourceLocation(), SourceLocation(), N) {
8955 }
8956
8957public:
8958 struct PrefView {
8959 /// Foreign-runtime-id expression. Null for attr-only specs.
8960 Expr *Fr;
8961 /// attr() string-literal expressions. Empty for fr-only or OMP 5.1
8962 /// flat specs.
8964 };
8965
8966 /// Creates a fully specified clause.
8967 ///
8968 /// \param C AST context.
8969 /// \param InteropVar The interop variable.
8970 /// \param InteropInfo The interop-type and prefer_type list.
8971 /// \param StartLoc Starting location of the clause.
8972 /// \param LParenLoc Location of '('.
8973 /// \param VarLoc Location of the interop variable.
8974 /// \param EndLoc Ending location of the clause.
8975 static OMPInitClause *Create(const ASTContext &C, Expr *InteropVar,
8976 OMPInteropInfo &InteropInfo,
8977 SourceLocation StartLoc,
8978 SourceLocation LParenLoc, SourceLocation VarLoc,
8979 SourceLocation EndLoc);
8980
8981 /// Creates an empty clause sized for \a NumPrefs pref-specs and \a NumAttrs
8982 /// total attr() exprs across them.
8983 ///
8984 /// \param C AST context.
8985 /// \param NumPrefs Number of pref-specs (length of the Fr block).
8986 /// \param NumAttrs Total attr() exprs across all pref-specs.
8987 static OMPInitClause *CreateEmpty(const ASTContext &C, unsigned NumPrefs,
8988 unsigned NumAttrs);
8989
8990 /// Returns the location of the interop variable.
8991 SourceLocation getVarLoc() const { return VarLoc; }
8992
8993 /// Returns the interop variable.
8994 Expr *getInteropVar() { return varlist_begin()[0]; }
8995 const Expr *getInteropVar() const { return varlist_begin()[0]; }
8996
8997 /// Returns true is interop-type 'target' is used.
8998 bool getIsTarget() const { return IsTarget; }
8999
9000 /// Returns true is interop-type 'targetsync' is used.
9001 bool getIsTargetSync() const { return IsTargetSync; }
9002
9003 /// Returns true if OMP 6.0 {fr/attr} syntax is used.
9004 bool hasPreferAttrs() const { return HasPreferAttrs; }
9005
9006 /// All attr() exprs across every pref-spec, in pref-spec order (flat block).
9008 return ArrayRef<Expr *>(getTrailingObjects<Expr *>() + varlist_size(),
9009 NumAttrs);
9010 }
9011
9012 child_range children() {
9013 return child_range(
9014 reinterpret_cast<Stmt **>(varlist_begin()),
9015 reinterpret_cast<Stmt **>(varlist_begin() + varlist_size() + NumAttrs));
9016 }
9017
9018 const_child_range children() const {
9019 return const_cast<OMPInitClause *>(this)->children();
9020 }
9021
9022 child_range used_children() {
9023 return child_range(child_iterator(), child_iterator());
9024 }
9025 const_child_range used_children() const {
9026 return const_child_range(const_child_iterator(), const_child_iterator());
9027 }
9028
9029 /// Returns a range of PrefView objects, one per preference-specification,
9030 /// each carrying the fr() expression (or null) and the attr() exprs.
9031 auto prefs() const {
9032 unsigned N = getNumPrefs();
9033 Expr *const *E = getTrailingObjects<Expr *>();
9034 ArrayRef<unsigned> Ends = getAttrEnds();
9035 return llvm::map_range(llvm::seq<unsigned>(0, N), [=](unsigned I) {
9036 unsigned Start = (I == 0) ? 0 : Ends[I - 1];
9037 return PrefView{
9038 const_cast<Expr *>(E[1 + I]),
9039 ArrayRef<Expr *>(const_cast<Expr **>(E) + varlist_size() + Start,
9040 Ends[I] - Start)};
9041 });
9042 }
9043
9044 static bool classof(const OMPClause *T) {
9045 return T->getClauseKind() == llvm::omp::OMPC_init;
9046 }
9047};
9048
9049/// This represents the 'use' clause in '#pragma omp ...' directives.
9050///
9051/// \code
9052/// #pragma omp interop use(obj)
9053/// \endcode
9054class OMPUseClause final : public OMPClause {
9055 friend class OMPClauseReader;
9056
9057 /// Location of '('.
9058 SourceLocation LParenLoc;
9059
9060 /// Location of interop variable.
9061 SourceLocation VarLoc;
9062
9063 /// The interop variable.
9064 Stmt *InteropVar = nullptr;
9065
9066 /// Set the interop variable.
9067 void setInteropVar(Expr *E) { InteropVar = E; }
9068
9069 /// Sets the location of '('.
9070 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
9071
9072 /// Sets the location of the interop variable.
9073 void setVarLoc(SourceLocation Loc) { VarLoc = Loc; }
9074
9075public:
9076 /// Build 'use' clause with and interop variable expression \a InteropVar.
9077 ///
9078 /// \param InteropVar The interop variable.
9079 /// \param StartLoc Starting location of the clause.
9080 /// \param LParenLoc Location of '('.
9081 /// \param VarLoc Location of the interop variable.
9082 /// \param EndLoc Ending location of the clause.
9083 OMPUseClause(Expr *InteropVar, SourceLocation StartLoc,
9084 SourceLocation LParenLoc, SourceLocation VarLoc,
9085 SourceLocation EndLoc)
9086 : OMPClause(llvm::omp::OMPC_use, StartLoc, EndLoc), LParenLoc(LParenLoc),
9087 VarLoc(VarLoc), InteropVar(InteropVar) {}
9088
9089 /// Build an empty clause.
9091 : OMPClause(llvm::omp::OMPC_use, SourceLocation(), SourceLocation()) {}
9092
9093 /// Returns the location of '('.
9094 SourceLocation getLParenLoc() const { return LParenLoc; }
9095
9096 /// Returns the location of the interop variable.
9097 SourceLocation getVarLoc() const { return VarLoc; }
9098
9099 /// Returns the interop variable.
9100 Expr *getInteropVar() const { return cast<Expr>(InteropVar); }
9101
9102 child_range children() { return child_range(&InteropVar, &InteropVar + 1); }
9103
9104 const_child_range children() const {
9105 return const_child_range(&InteropVar, &InteropVar + 1);
9106 }
9107
9108 child_range used_children() {
9109 return child_range(child_iterator(), child_iterator());
9110 }
9111 const_child_range used_children() const {
9112 return const_child_range(const_child_iterator(), const_child_iterator());
9113 }
9114
9115 static bool classof(const OMPClause *T) {
9116 return T->getClauseKind() == llvm::omp::OMPC_use;
9117 }
9118};
9119
9120/// This represents 'destroy' clause in the '#pragma omp depobj'
9121/// directive or the '#pragma omp interop' directive..
9122///
9123/// \code
9124/// #pragma omp depobj(a) destroy
9125/// #pragma omp interop destroy(obj)
9126/// \endcode
9127/// In these examples directive '#pragma omp depobj' and '#pragma omp interop'
9128/// have a 'destroy' clause. The 'interop' directive includes an object.
9129class OMPDestroyClause final : public OMPClause {
9130 friend class OMPClauseReader;
9131
9132 /// Location of '('.
9133 SourceLocation LParenLoc;
9134
9135 /// Location of interop variable.
9136 SourceLocation VarLoc;
9137
9138 /// The interop variable.
9139 Stmt *InteropVar = nullptr;
9140
9141 /// Set the interop variable.
9142 void setInteropVar(Expr *E) { InteropVar = E; }
9143
9144 /// Sets the location of '('.
9145 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
9146
9147 /// Sets the location of the interop variable.
9148 void setVarLoc(SourceLocation Loc) { VarLoc = Loc; }
9149
9150public:
9151 /// Build 'destroy' clause with an interop variable expression \a InteropVar.
9152 ///
9153 /// \param InteropVar The interop variable.
9154 /// \param StartLoc Starting location of the clause.
9155 /// \param LParenLoc Location of '('.
9156 /// \param VarLoc Location of the interop variable.
9157 /// \param EndLoc Ending location of the clause.
9158 OMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc,
9159 SourceLocation LParenLoc, SourceLocation VarLoc,
9160 SourceLocation EndLoc)
9161 : OMPClause(llvm::omp::OMPC_destroy, StartLoc, EndLoc),
9162 LParenLoc(LParenLoc), VarLoc(VarLoc), InteropVar(InteropVar) {}
9163
9164 /// Build 'destroy' clause.
9165 ///
9166 /// \param StartLoc Starting location of the clause.
9167 /// \param EndLoc Ending location of the clause.
9168 OMPDestroyClause(SourceLocation StartLoc, SourceLocation EndLoc)
9169 : OMPClause(llvm::omp::OMPC_destroy, StartLoc, EndLoc) {}
9170
9171 /// Build an empty clause.
9173 : OMPClause(llvm::omp::OMPC_destroy, SourceLocation(), SourceLocation()) {
9174 }
9175
9176 /// Returns the location of '('.
9177 SourceLocation getLParenLoc() const { return LParenLoc; }
9178
9179 /// Returns the location of the interop variable.
9180 SourceLocation getVarLoc() const { return VarLoc; }
9181
9182 /// Returns the interop variable.
9183 Expr *getInteropVar() const { return cast_or_null<Expr>(InteropVar); }
9184
9185 child_range children() {
9186 if (InteropVar)
9187 return child_range(&InteropVar, &InteropVar + 1);
9188 return child_range(child_iterator(), child_iterator());
9189 }
9190
9191 const_child_range children() const {
9192 if (InteropVar)
9193 return const_child_range(&InteropVar, &InteropVar + 1);
9194 return const_child_range(const_child_iterator(), const_child_iterator());
9195 }
9196
9197 child_range used_children() {
9198 return child_range(child_iterator(), child_iterator());
9199 }
9200 const_child_range used_children() const {
9201 return const_child_range(const_child_iterator(), const_child_iterator());
9202 }
9203
9204 static bool classof(const OMPClause *T) {
9205 return T->getClauseKind() == llvm::omp::OMPC_destroy;
9206 }
9207};
9208
9209/// This represents 'novariants' clause in the '#pragma omp ...' directive.
9210///
9211/// \code
9212/// #pragma omp dispatch novariants(a > 5)
9213/// \endcode
9214/// In this example directive '#pragma omp dispatch' has simple 'novariants'
9215/// clause with condition 'a > 5'.
9217 : public OMPOneStmtClause<llvm::omp::OMPC_novariants, OMPClause>,
9218 public OMPClauseWithPreInit {
9219 friend class OMPClauseReader;
9220
9221 /// Set condition.
9222 void setCondition(Expr *Cond) { setStmt(Cond); }
9223
9224public:
9225 /// Build 'novariants' clause with condition \a Cond.
9226 ///
9227 /// \param Cond Condition of the clause.
9228 /// \param HelperCond Helper condition for the construct.
9229 /// \param CaptureRegion Innermost OpenMP region where expressions in this
9230 /// clause must be captured.
9231 /// \param StartLoc Starting location of the clause.
9232 /// \param LParenLoc Location of '('.
9233 /// \param EndLoc Ending location of the clause.
9234 OMPNovariantsClause(Expr *Cond, Stmt *HelperCond,
9235 OpenMPDirectiveKind CaptureRegion,
9236 SourceLocation StartLoc, SourceLocation LParenLoc,
9237 SourceLocation EndLoc)
9238 : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc),
9239 OMPClauseWithPreInit(this) {
9240 setPreInitStmt(HelperCond, CaptureRegion);
9241 }
9242
9243 /// Build an empty clause.
9245
9246 /// Returns condition.
9247 Expr *getCondition() const { return getStmtAs<Expr>(); }
9248
9249 child_range used_children();
9250 const_child_range used_children() const {
9251 return const_cast<OMPNovariantsClause *>(this)->used_children();
9252 }
9253};
9254
9255/// This represents 'nocontext' clause in the '#pragma omp ...' directive.
9256///
9257/// \code
9258/// #pragma omp dispatch nocontext(a > 5)
9259/// \endcode
9260/// In this example directive '#pragma omp dispatch' has simple 'nocontext'
9261/// clause with condition 'a > 5'.
9263 : public OMPOneStmtClause<llvm::omp::OMPC_nocontext, OMPClause>,
9264 public OMPClauseWithPreInit {
9265 friend class OMPClauseReader;
9266
9267 /// Set condition.
9268 void setCondition(Expr *Cond) { setStmt(Cond); }
9269
9270public:
9271 /// Build 'nocontext' clause with condition \a Cond.
9272 ///
9273 /// \param Cond Condition of the clause.
9274 /// \param HelperCond Helper condition for the construct.
9275 /// \param CaptureRegion Innermost OpenMP region where expressions in this
9276 /// clause must be captured.
9277 /// \param StartLoc Starting location of the clause.
9278 /// \param LParenLoc Location of '('.
9279 /// \param EndLoc Ending location of the clause.
9280 OMPNocontextClause(Expr *Cond, Stmt *HelperCond,
9281 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
9282 SourceLocation LParenLoc, SourceLocation EndLoc)
9283 : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc),
9284 OMPClauseWithPreInit(this) {
9285 setPreInitStmt(HelperCond, CaptureRegion);
9286 }
9287
9288 /// Build an empty clause.
9290
9291 /// Returns condition.
9292 Expr *getCondition() const { return getStmtAs<Expr>(); }
9293
9294 child_range used_children();
9295 const_child_range used_children() const {
9296 return const_cast<OMPNocontextClause *>(this)->used_children();
9297 }
9298};
9299
9300/// This represents 'detach' clause in the '#pragma omp task' directive.
9301///
9302/// \code
9303/// #pragma omp task detach(evt)
9304/// \endcode
9305/// In this example directive '#pragma omp detach' has simple 'detach' clause
9306/// with the variable 'evt'.
9308 : public OMPOneStmtClause<llvm::omp::OMPC_detach, OMPClause> {
9309 friend class OMPClauseReader;
9310
9311 /// Set condition.
9312 void setEventHandler(Expr *E) { setStmt(E); }
9313
9314public:
9315 /// Build 'detach' clause with event-handler \a Evt.
9316 ///
9317 /// \param Evt Event handler expression.
9318 /// \param StartLoc Starting location of the clause.
9319 /// \param LParenLoc Location of '('.
9320 /// \param EndLoc Ending location of the clause.
9321 OMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc,
9322 SourceLocation EndLoc)
9323 : OMPOneStmtClause(Evt, StartLoc, LParenLoc, EndLoc) {}
9324
9325 /// Build an empty clause.
9327
9328 /// Returns event-handler expression.
9329 Expr *getEventHandler() const { return getStmtAs<Expr>(); }
9330};
9331
9332/// This represents clause 'inclusive' in the '#pragma omp scan' directive.
9333///
9334/// \code
9335/// #pragma omp scan inclusive(a,b)
9336/// \endcode
9337/// In this example directive '#pragma omp scan' has clause 'inclusive'
9338/// with the variables 'a' and 'b'.
9339class OMPInclusiveClause final
9340 : public OMPVarListClause<OMPInclusiveClause>,
9341 private llvm::TrailingObjects<OMPInclusiveClause, Expr *> {
9342 friend class OMPClauseReader;
9343 friend OMPVarListClause;
9344 friend TrailingObjects;
9345
9346 /// Build clause with number of variables \a N.
9347 ///
9348 /// \param StartLoc Starting location of the clause.
9349 /// \param LParenLoc Location of '('.
9350 /// \param EndLoc Ending location of the clause.
9351 /// \param N Number of the variables in the clause.
9352 OMPInclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
9353 SourceLocation EndLoc, unsigned N)
9354 : OMPVarListClause<OMPInclusiveClause>(llvm::omp::OMPC_inclusive,
9355 StartLoc, LParenLoc, EndLoc, N) {}
9356
9357 /// Build an empty clause.
9358 ///
9359 /// \param N Number of variables.
9360 explicit OMPInclusiveClause(unsigned N)
9361 : OMPVarListClause<OMPInclusiveClause>(llvm::omp::OMPC_inclusive,
9362 SourceLocation(), SourceLocation(),
9363 SourceLocation(), N) {}
9364
9365public:
9366 /// Creates clause with a list of variables \a VL.
9367 ///
9368 /// \param C AST context.
9369 /// \param StartLoc Starting location of the clause.
9370 /// \param LParenLoc Location of '('.
9371 /// \param EndLoc Ending location of the clause.
9372 /// \param VL List of references to the original variables.
9373 static OMPInclusiveClause *Create(const ASTContext &C,
9374 SourceLocation StartLoc,
9375 SourceLocation LParenLoc,
9376 SourceLocation EndLoc, ArrayRef<Expr *> VL);
9377
9378 /// Creates an empty clause with the place for \a N variables.
9379 ///
9380 /// \param C AST context.
9381 /// \param N The number of variables.
9382 static OMPInclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
9383
9384 child_range children() {
9385 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
9386 reinterpret_cast<Stmt **>(varlist_end()));
9387 }
9388
9389 const_child_range children() const {
9390 return const_cast<OMPInclusiveClause *>(this)->children();
9391 }
9392
9393 child_range used_children() {
9394 return child_range(child_iterator(), child_iterator());
9395 }
9396 const_child_range used_children() const {
9397 return const_child_range(const_child_iterator(), const_child_iterator());
9398 }
9399
9400 static bool classof(const OMPClause *T) {
9401 return T->getClauseKind() == llvm::omp::OMPC_inclusive;
9402 }
9403};
9404
9405/// This represents clause 'exclusive' in the '#pragma omp scan' directive.
9406///
9407/// \code
9408/// #pragma omp scan exclusive(a,b)
9409/// \endcode
9410/// In this example directive '#pragma omp scan' has clause 'exclusive'
9411/// with the variables 'a' and 'b'.
9412class OMPExclusiveClause final
9413 : public OMPVarListClause<OMPExclusiveClause>,
9414 private llvm::TrailingObjects<OMPExclusiveClause, Expr *> {
9415 friend class OMPClauseReader;
9416 friend OMPVarListClause;
9417 friend TrailingObjects;
9418
9419 /// Build clause with number of variables \a N.
9420 ///
9421 /// \param StartLoc Starting location of the clause.
9422 /// \param LParenLoc Location of '('.
9423 /// \param EndLoc Ending location of the clause.
9424 /// \param N Number of the variables in the clause.
9425 OMPExclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
9426 SourceLocation EndLoc, unsigned N)
9427 : OMPVarListClause<OMPExclusiveClause>(llvm::omp::OMPC_exclusive,
9428 StartLoc, LParenLoc, EndLoc, N) {}
9429
9430 /// Build an empty clause.
9431 ///
9432 /// \param N Number of variables.
9433 explicit OMPExclusiveClause(unsigned N)
9434 : OMPVarListClause<OMPExclusiveClause>(llvm::omp::OMPC_exclusive,
9435 SourceLocation(), SourceLocation(),
9436 SourceLocation(), N) {}
9437
9438public:
9439 /// Creates clause with a list of variables \a VL.
9440 ///
9441 /// \param C AST context.
9442 /// \param StartLoc Starting location of the clause.
9443 /// \param LParenLoc Location of '('.
9444 /// \param EndLoc Ending location of the clause.
9445 /// \param VL List of references to the original variables.
9446 static OMPExclusiveClause *Create(const ASTContext &C,
9447 SourceLocation StartLoc,
9448 SourceLocation LParenLoc,
9449 SourceLocation EndLoc, ArrayRef<Expr *> VL);
9450
9451 /// Creates an empty clause with the place for \a N variables.
9452 ///
9453 /// \param C AST context.
9454 /// \param N The number of variables.
9455 static OMPExclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
9456
9457 child_range children() {
9458 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
9459 reinterpret_cast<Stmt **>(varlist_end()));
9460 }
9461
9462 const_child_range children() const {
9463 return const_cast<OMPExclusiveClause *>(this)->children();
9464 }
9465
9466 child_range used_children() {
9467 return child_range(child_iterator(), child_iterator());
9468 }
9469 const_child_range used_children() const {
9470 return const_child_range(const_child_iterator(), const_child_iterator());
9471 }
9472
9473 static bool classof(const OMPClause *T) {
9474 return T->getClauseKind() == llvm::omp::OMPC_exclusive;
9475 }
9476};
9477
9478/// This represents clause 'uses_allocators' in the '#pragma omp target'-based
9479/// directives.
9480///
9481/// \code
9482/// #pragma omp target uses_allocators(default_allocator, my_allocator(traits))
9483/// \endcode
9484/// In this example directive '#pragma omp target' has clause 'uses_allocators'
9485/// with the allocators 'default_allocator' and user-defined 'my_allocator'.
9486class OMPUsesAllocatorsClause final
9487 : public OMPClause,
9488 private llvm::TrailingObjects<OMPUsesAllocatorsClause, Expr *,
9489 SourceLocation> {
9490public:
9491 /// Data for list of allocators.
9492 struct Data {
9493 /// Allocator.
9494 Expr *Allocator = nullptr;
9495 /// Allocator traits.
9496 Expr *AllocatorTraits = nullptr;
9497 /// Locations of '(' and ')' symbols.
9498 SourceLocation LParenLoc, RParenLoc;
9499 };
9500
9501private:
9502 friend class OMPClauseReader;
9503 friend TrailingObjects;
9504
9505 enum class ExprOffsets {
9506 Allocator,
9507 AllocatorTraits,
9508 Total,
9509 };
9510
9511 enum class ParenLocsOffsets {
9512 LParen,
9513 RParen,
9514 Total,
9515 };
9516
9517 /// Location of '('.
9518 SourceLocation LParenLoc;
9519 /// Total number of allocators in the clause.
9520 unsigned NumOfAllocators = 0;
9521
9522 /// Build clause.
9523 ///
9524 /// \param StartLoc Starting location of the clause.
9525 /// \param LParenLoc Location of '('.
9526 /// \param EndLoc Ending location of the clause.
9527 /// \param N Number of allocators associated with the clause.
9528 OMPUsesAllocatorsClause(SourceLocation StartLoc, SourceLocation LParenLoc,
9529 SourceLocation EndLoc, unsigned N)
9530 : OMPClause(llvm::omp::OMPC_uses_allocators, StartLoc, EndLoc),
9531 LParenLoc(LParenLoc), NumOfAllocators(N) {}
9532
9533 /// Build an empty clause.
9534 /// \param N Number of allocators associated with the clause.
9535 ///
9536 explicit OMPUsesAllocatorsClause(unsigned N)
9537 : OMPClause(llvm::omp::OMPC_uses_allocators, SourceLocation(),
9538 SourceLocation()),
9539 NumOfAllocators(N) {}
9540
9541 unsigned numTrailingObjects(OverloadToken<Expr *>) const {
9542 return NumOfAllocators * static_cast<int>(ExprOffsets::Total);
9543 }
9544
9545 /// Sets the location of '('.
9546 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
9547
9548 /// Sets the allocators data for the clause.
9549 void setAllocatorsData(ArrayRef<OMPUsesAllocatorsClause::Data> Data);
9550
9551public:
9552 /// Creates clause with a list of allocators \p Data.
9553 ///
9554 /// \param C AST context.
9555 /// \param StartLoc Starting location of the clause.
9556 /// \param LParenLoc Location of '('.
9557 /// \param EndLoc Ending location of the clause.
9558 /// \param Data List of allocators.
9559 static OMPUsesAllocatorsClause *
9560 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
9561 SourceLocation EndLoc, ArrayRef<OMPUsesAllocatorsClause::Data> Data);
9562
9563 /// Creates an empty clause with the place for \p N allocators.
9564 ///
9565 /// \param C AST context.
9566 /// \param N The number of allocators.
9567 static OMPUsesAllocatorsClause *CreateEmpty(const ASTContext &C, unsigned N);
9568
9569 /// Returns the location of '('.
9570 SourceLocation getLParenLoc() const { return LParenLoc; }
9571
9572 /// Returns number of allocators associated with the clause.
9573 unsigned getNumberOfAllocators() const { return NumOfAllocators; }
9574
9575 /// Returns data for the specified allocator.
9576 OMPUsesAllocatorsClause::Data getAllocatorData(unsigned I) const;
9577
9578 // Iterators
9579 child_range children() {
9580 Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
9581 return child_range(Begin, Begin + NumOfAllocators *
9582 static_cast<int>(ExprOffsets::Total));
9583 }
9584 const_child_range children() const {
9585 Stmt *const *Begin =
9586 reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
9587 return const_child_range(
9588 Begin, Begin + NumOfAllocators * static_cast<int>(ExprOffsets::Total));
9589 }
9590
9591 child_range used_children() {
9592 return child_range(child_iterator(), child_iterator());
9593 }
9594 const_child_range used_children() const {
9595 return const_child_range(const_child_iterator(), const_child_iterator());
9596 }
9597
9598 static bool classof(const OMPClause *T) {
9599 return T->getClauseKind() == llvm::omp::OMPC_uses_allocators;
9600 }
9601};
9602
9603/// This represents clause 'affinity' in the '#pragma omp task'-based
9604/// directives.
9605///
9606/// \code
9607/// #pragma omp task affinity(iterator(i = 0:n) : ([3][n])a, b[:n], c[i])
9608/// \endcode
9609/// In this example directive '#pragma omp task' has clause 'affinity' with the
9610/// affinity modifer 'iterator(i = 0:n)' and locator items '([3][n])a', 'b[:n]'
9611/// and 'c[i]'.
9612class OMPAffinityClause final
9613 : public OMPVarListClause<OMPAffinityClause>,
9614 private llvm::TrailingObjects<OMPAffinityClause, Expr *> {
9615 friend class OMPClauseReader;
9616 friend OMPVarListClause;
9617 friend TrailingObjects;
9618
9619 /// Location of ':' symbol.
9620 SourceLocation ColonLoc;
9621
9622 /// Build clause.
9623 ///
9624 /// \param StartLoc Starting location of the clause.
9625 /// \param LParenLoc Location of '('.
9626 /// \param ColonLoc Location of ':'.
9627 /// \param EndLoc Ending location of the clause.
9628 /// \param N Number of locators associated with the clause.
9629 OMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc,
9630 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N)
9631 : OMPVarListClause<OMPAffinityClause>(llvm::omp::OMPC_affinity, StartLoc,
9632 LParenLoc, EndLoc, N) {}
9633
9634 /// Build an empty clause.
9635 /// \param N Number of locators associated with the clause.
9636 ///
9637 explicit OMPAffinityClause(unsigned N)
9638 : OMPVarListClause<OMPAffinityClause>(llvm::omp::OMPC_affinity,
9639 SourceLocation(), SourceLocation(),
9640 SourceLocation(), N) {}
9641
9642 /// Sets the affinity modifier for the clause, if any.
9643 void setModifier(Expr *E) { getTrailingObjects()[varlist_size()] = E; }
9644
9645 /// Sets the location of ':' symbol.
9646 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
9647
9648public:
9649 /// Creates clause with a modifier a list of locator items.
9650 ///
9651 /// \param C AST context.
9652 /// \param StartLoc Starting location of the clause.
9653 /// \param LParenLoc Location of '('.
9654 /// \param ColonLoc Location of ':'.
9655 /// \param EndLoc Ending location of the clause.
9656 /// \param Locators List of locator items.
9657 static OMPAffinityClause *Create(const ASTContext &C, SourceLocation StartLoc,
9658 SourceLocation LParenLoc,
9659 SourceLocation ColonLoc,
9660 SourceLocation EndLoc, Expr *Modifier,
9661 ArrayRef<Expr *> Locators);
9662
9663 /// Creates an empty clause with the place for \p N locator items.
9664 ///
9665 /// \param C AST context.
9666 /// \param N The number of locator items.
9667 static OMPAffinityClause *CreateEmpty(const ASTContext &C, unsigned N);
9668
9669 /// Gets affinity modifier.
9670 Expr *getModifier() { return getTrailingObjects()[varlist_size()]; }
9671 Expr *getModifier() const { return getTrailingObjects()[varlist_size()]; }
9672
9673 /// Gets the location of ':' symbol.
9674 SourceLocation getColonLoc() const { return ColonLoc; }
9675
9676 // Iterators
9677 child_range children() {
9678 int Offset = getModifier() ? 1 : 0;
9679 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
9680 reinterpret_cast<Stmt **>(varlist_end() + Offset));
9681 }
9682
9683 const_child_range children() const {
9684 return const_cast<OMPAffinityClause *>(this)->children();
9685 }
9686
9687 child_range used_children() {
9688 return child_range(child_iterator(), child_iterator());
9689 }
9690 const_child_range used_children() const {
9691 return const_child_range(const_child_iterator(), const_child_iterator());
9692 }
9693
9694 static bool classof(const OMPClause *T) {
9695 return T->getClauseKind() == llvm::omp::OMPC_affinity;
9696 }
9697};
9698
9699/// This represents 'filter' clause in the '#pragma omp ...' directive.
9700///
9701/// \code
9702/// #pragma omp masked filter(tid)
9703/// \endcode
9704/// In this example directive '#pragma omp masked' has 'filter' clause with
9705/// thread id.
9707 : public OMPOneStmtClause<llvm::omp::OMPC_filter, OMPClause>,
9708 public OMPClauseWithPreInit {
9709 friend class OMPClauseReader;
9710
9711 /// Sets the thread identifier.
9712 void setThreadID(Expr *TID) { setStmt(TID); }
9713
9714public:
9715 /// Build 'filter' clause with thread-id \a ThreadID.
9716 ///
9717 /// \param ThreadID Thread identifier.
9718 /// \param HelperE Helper expression associated with this clause.
9719 /// \param CaptureRegion Innermost OpenMP region where expressions in this
9720 /// clause must be captured.
9721 /// \param StartLoc Starting location of the clause.
9722 /// \param LParenLoc Location of '('.
9723 /// \param EndLoc Ending location of the clause.
9724 OMPFilterClause(Expr *ThreadID, Stmt *HelperE,
9725 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
9726 SourceLocation LParenLoc, SourceLocation EndLoc)
9727 : OMPOneStmtClause(ThreadID, StartLoc, LParenLoc, EndLoc),
9728 OMPClauseWithPreInit(this) {
9729 setPreInitStmt(HelperE, CaptureRegion);
9730 }
9731
9732 /// Build an empty clause.
9734
9735 /// Return thread identifier.
9736 Expr *getThreadID() const { return getStmtAs<Expr>(); }
9737
9738 /// Return thread identifier.
9739 Expr *getThreadID() { return getStmtAs<Expr>(); }
9740};
9741
9742/// This represents 'bind' clause in the '#pragma omp ...' directives.
9743///
9744/// \code
9745/// #pragma omp loop bind(parallel)
9746/// \endcode
9747class OMPBindClause final : public OMPNoChildClause<llvm::omp::OMPC_bind> {
9748 friend class OMPClauseReader;
9749
9750 /// Location of '('.
9751 SourceLocation LParenLoc;
9752
9753 /// The binding kind of 'bind' clause.
9754 OpenMPBindClauseKind Kind = OMPC_BIND_unknown;
9755
9756 /// Start location of the kind in source code.
9757 SourceLocation KindLoc;
9758
9759 /// Sets the location of '('.
9760 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
9761
9762 /// Set the binding kind.
9763 void setBindKind(OpenMPBindClauseKind K) { Kind = K; }
9764
9765 /// Set the binding kind location.
9766 void setBindKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
9767
9768 /// Build 'bind' clause with kind \a K ('teams', 'parallel', or 'thread').
9769 ///
9770 /// \param K Binding kind of the clause ('teams', 'parallel' or 'thread').
9771 /// \param KLoc Starting location of the binding kind.
9772 /// \param StartLoc Starting location of the clause.
9773 /// \param LParenLoc Location of '('.
9774 /// \param EndLoc Ending location of the clause.
9775 OMPBindClause(OpenMPBindClauseKind K, SourceLocation KLoc,
9776 SourceLocation StartLoc, SourceLocation LParenLoc,
9777 SourceLocation EndLoc)
9778 : OMPNoChildClause(StartLoc, EndLoc), LParenLoc(LParenLoc), Kind(K),
9779 KindLoc(KLoc) {}
9780
9781 /// Build an empty clause.
9782 OMPBindClause() : OMPNoChildClause() {}
9783
9784public:
9785 /// Build 'bind' clause with kind \a K ('teams', 'parallel', or 'thread').
9786 ///
9787 /// \param C AST context
9788 /// \param K Binding kind of the clause ('teams', 'parallel' or 'thread').
9789 /// \param KLoc Starting location of the binding kind.
9790 /// \param StartLoc Starting location of the clause.
9791 /// \param LParenLoc Location of '('.
9792 /// \param EndLoc Ending location of the clause.
9793 static OMPBindClause *Create(const ASTContext &C, OpenMPBindClauseKind K,
9794 SourceLocation KLoc, SourceLocation StartLoc,
9795 SourceLocation LParenLoc, SourceLocation EndLoc);
9796
9797 /// Build an empty 'bind' clause.
9798 ///
9799 /// \param C AST context
9800 static OMPBindClause *CreateEmpty(const ASTContext &C);
9801
9802 /// Returns the location of '('.
9803 SourceLocation getLParenLoc() const { return LParenLoc; }
9804
9805 /// Returns kind of the clause.
9806 OpenMPBindClauseKind getBindKind() const { return Kind; }
9807
9808 /// Returns location of clause kind.
9809 SourceLocation getBindKindLoc() const { return KindLoc; }
9810};
9811
9812/// This class implements a simple visitor for OMPClause
9813/// subclasses.
9814template<class ImplClass, template <typename> class Ptr, typename RetTy>
9816public:
9817#define PTR(CLASS) Ptr<CLASS>
9818#define DISPATCH(CLASS) \
9819 return static_cast<ImplClass*>(this)->Visit##CLASS(static_cast<PTR(CLASS)>(S))
9820
9821#define GEN_CLANG_CLAUSE_CLASS
9822#define CLAUSE_CLASS(Enum, Str, Class) \
9823 RetTy Visit##Class(PTR(Class) S) { \
9824 return static_cast<ImplClass *>(this)->VisitOMPClause(S); \
9825 }
9826#include "llvm/Frontend/OpenMP/OMP.inc"
9827
9828 RetTy Visit(PTR(OMPClause) S) {
9829 // Top switch clause: visit each OMPClause.
9830 switch (S->getClauseKind()) {
9831#define GEN_CLANG_CLAUSE_CLASS
9832#define CLAUSE_CLASS(Enum, Str, Class) \
9833 case llvm::omp::Clause::Enum: \
9834 DISPATCH(Class);
9835#define CLAUSE_NO_CLASS(Enum, Str) \
9836 case llvm::omp::Clause::Enum: \
9837 break;
9838#include "llvm/Frontend/OpenMP/OMP.inc"
9839 }
9840 }
9841 // Base case, ignore it. :)
9842 RetTy VisitOMPClause(PTR(OMPClause) Node) { return RetTy(); }
9843#undef PTR
9844#undef DISPATCH
9845};
9846
9847template <typename T> using const_ptr = std::add_pointer_t<std::add_const_t<T>>;
9848
9849template <class ImplClass, typename RetTy = void>
9851 : public OMPClauseVisitorBase<ImplClass, std::add_pointer_t, RetTy> {};
9852template<class ImplClass, typename RetTy = void>
9854 public OMPClauseVisitorBase <ImplClass, const_ptr, RetTy> {};
9855
9856class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> {
9857 raw_ostream &OS;
9858 const PrintingPolicy &Policy;
9859 unsigned Version;
9860
9861 /// Process clauses with list of variables.
9862 template <typename T> void VisitOMPClauseList(T *Node, char StartSym);
9863 /// Process motion clauses.
9864 template <typename T> void VisitOMPMotionClause(T *Node);
9865
9866public:
9867 OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy,
9868 unsigned OpenMPVersion)
9869 : OS(OS), Policy(Policy), Version(OpenMPVersion) {}
9870
9871#define GEN_CLANG_CLAUSE_CLASS
9872#define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *S);
9873#include "llvm/Frontend/OpenMP/OMP.inc"
9874};
9875
9877 llvm::omp::TraitProperty Kind = llvm::omp::TraitProperty::invalid;
9878
9879 /// The raw string as we parsed it. This is needed for the `isa` trait set
9880 /// (which accepts anything) and (later) extensions.
9881 StringRef RawString;
9882};
9883
9885 Expr *ScoreOrCondition = nullptr;
9886 llvm::omp::TraitSelector Kind = llvm::omp::TraitSelector::invalid;
9888};
9889
9891 llvm::omp::TraitSet Kind = llvm::omp::TraitSet::invalid;
9893};
9894
9895/// Helper data structure representing the traits in a match clause of an
9896/// `declare variant` or `metadirective`. The outer level is an ordered
9897/// collection of selector sets, each with an associated kind and an ordered
9898/// collection of selectors. A selector has a kind, an optional score/condition,
9899/// and an ordered collection of properties.
9900class OMPTraitInfo {
9901 /// Private constructor accesible only by ASTContext.
9902 OMPTraitInfo() {}
9903 friend class ASTContext;
9904
9905public:
9906 /// Reconstruct a (partial) OMPTraitInfo object from a mangled name.
9907 OMPTraitInfo(StringRef MangledName);
9908
9909 /// The outermost level of selector sets.
9911
9913 llvm::function_ref<bool(Expr *&, bool /* IsScore */)> Cond) {
9914 return llvm::any_of(Sets, [&](OMPTraitSet &Set) {
9915 return llvm::any_of(
9916 Set.Selectors, [&](OMPTraitSelector &Selector) {
9917 return Cond(Selector.ScoreOrCondition,
9918 /* IsScore */ Selector.Kind !=
9919 llvm::omp::TraitSelector::user_condition);
9920 });
9921 });
9922 }
9923
9924 /// Create a variant match info object from this trait info object. While the
9925 /// former is a flat representation the actual main difference is that the
9926 /// latter uses clang::Expr to store the score/condition while the former is
9927 /// independent of clang. Thus, expressions and conditions are evaluated in
9928 /// this method.
9929 void getAsVariantMatchInfo(ASTContext &ASTCtx,
9930 llvm::omp::VariantMatchInfo &VMI) const;
9931
9932 /// Return a string representation identifying this context selector.
9933 std::string getMangledName() const;
9934
9935 /// Check the extension trait \p TP is active.
9936 bool isExtensionActive(llvm::omp::TraitProperty TP) {
9937 for (const OMPTraitSet &Set : Sets) {
9938 if (Set.Kind != llvm::omp::TraitSet::implementation)
9939 continue;
9940 for (const OMPTraitSelector &Selector : Set.Selectors) {
9941 if (Selector.Kind != llvm::omp::TraitSelector::implementation_extension)
9942 continue;
9943 for (const OMPTraitProperty &Property : Selector.Properties) {
9944 if (Property.Kind == TP)
9945 return true;
9946 }
9947 }
9948 }
9949 return false;
9950 }
9951
9952 /// Print a human readable representation into \p OS.
9953 void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
9954};
9955llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo &TI);
9956llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo *TI);
9957
9958/// Clang specific specialization of the OMPContext to lookup target features.
9961 std::function<void(StringRef)> &&DiagUnknownTrait,
9962 const FunctionDecl *CurrentFunctionDecl,
9963 ArrayRef<llvm::omp::TraitProperty> ConstructTraits,
9964 int DeviceNum);
9965
9966 virtual ~TargetOMPContext() = default;
9967
9968 /// See llvm::omp::OMPContext::matchesISATrait
9969 bool matchesISATrait(StringRef RawString) const override;
9970
9971private:
9972 std::function<bool(StringRef)> FeatureValidityCheck;
9973 std::function<void(StringRef)> DiagUnknownTrait;
9974 llvm::StringMap<bool> FeatureMap;
9975};
9976
9977/// Contains data for OpenMP directives: clauses, children
9978/// expressions/statements (helpers for codegen) and associated statement, if
9979/// any.
9980class OMPChildren final
9981 : private llvm::TrailingObjects<OMPChildren, OMPClause *, Stmt *> {
9982 friend TrailingObjects;
9983 friend class OMPClauseReader;
9985 template <typename T> friend class OMPDeclarativeDirective;
9986
9987 /// Numbers of clauses.
9988 unsigned NumClauses = 0;
9989 /// Number of child expressions/stmts.
9990 unsigned NumChildren = 0;
9991 /// true if the directive has associated statement.
9992 bool HasAssociatedStmt = false;
9993
9994 /// Define the sizes of each trailing object array except the last one. This
9995 /// is required for TrailingObjects to work properly.
9996 size_t numTrailingObjects(OverloadToken<OMPClause *>) const {
9997 return NumClauses;
9998 }
9999
10000 OMPChildren() = delete;
10001
10002 OMPChildren(unsigned NumClauses, unsigned NumChildren, bool HasAssociatedStmt)
10003 : NumClauses(NumClauses), NumChildren(NumChildren),
10004 HasAssociatedStmt(HasAssociatedStmt) {}
10005
10006 static size_t size(unsigned NumClauses, bool HasAssociatedStmt,
10007 unsigned NumChildren);
10008
10009 static OMPChildren *Create(void *Mem, ArrayRef<OMPClause *> Clauses);
10010 static OMPChildren *Create(void *Mem, ArrayRef<OMPClause *> Clauses, Stmt *S,
10011 unsigned NumChildren = 0);
10012 static OMPChildren *CreateEmpty(void *Mem, unsigned NumClauses,
10013 bool HasAssociatedStmt = false,
10014 unsigned NumChildren = 0);
10015
10016public:
10017 unsigned getNumClauses() const { return NumClauses; }
10018 unsigned getNumChildren() const { return NumChildren; }
10019 bool hasAssociatedStmt() const { return HasAssociatedStmt; }
10020
10021 /// Set associated statement.
10022 void setAssociatedStmt(Stmt *S) {
10023 getTrailingObjects<Stmt *>()[NumChildren] = S;
10024 }
10025
10027
10028 /// Sets the list of variables for this clause.
10029 ///
10030 /// \param Clauses The list of clauses for the directive.
10031 ///
10032 void setClauses(ArrayRef<OMPClause *> Clauses);
10033
10034 /// Returns statement associated with the directive.
10035 const Stmt *getAssociatedStmt() const {
10036 return const_cast<OMPChildren *>(this)->getAssociatedStmt();
10037 }
10039 assert(HasAssociatedStmt &&
10040 "Expected directive with the associated statement.");
10041 return getTrailingObjects<Stmt *>()[NumChildren];
10042 }
10043
10044 /// Get the clauses storage.
10045 MutableArrayRef<OMPClause *> getClauses() {
10046 return getTrailingObjects<OMPClause *>(NumClauses);
10047 }
10049 return const_cast<OMPChildren *>(this)->getClauses();
10050 }
10051
10052 /// Returns the captured statement associated with the
10053 /// component region within the (combined) directive.
10054 ///
10055 /// \param RegionKind Component region kind.
10056 const CapturedStmt *
10057 getCapturedStmt(OpenMPDirectiveKind RegionKind,
10058 ArrayRef<OpenMPDirectiveKind> CaptureRegions) const {
10059 assert(llvm::is_contained(CaptureRegions, RegionKind) &&
10060 "RegionKind not found in OpenMP CaptureRegions.");
10061 auto *CS = cast<CapturedStmt>(getAssociatedStmt());
10062 for (auto ThisCaptureRegion : CaptureRegions) {
10063 if (ThisCaptureRegion == RegionKind)
10064 return CS;
10065 CS = cast<CapturedStmt>(CS->getCapturedStmt());
10066 }
10067 llvm_unreachable("Incorrect RegionKind specified for directive.");
10068 }
10069
10070 /// Get innermost captured statement for the construct.
10071 CapturedStmt *
10073 assert(hasAssociatedStmt() && "Must have associated captured statement.");
10074 assert(!CaptureRegions.empty() &&
10075 "At least one captured statement must be provided.");
10076 auto *CS = cast<CapturedStmt>(getAssociatedStmt());
10077 for (unsigned Level = CaptureRegions.size(); Level > 1; --Level)
10078 CS = cast<CapturedStmt>(CS->getCapturedStmt());
10079 return CS;
10080 }
10081
10082 const CapturedStmt *
10084 return const_cast<OMPChildren *>(this)->getInnermostCapturedStmt(
10085 CaptureRegions);
10086 }
10087
10088 MutableArrayRef<Stmt *> getChildren();
10090 return const_cast<OMPChildren *>(this)->getChildren();
10091 }
10092
10093 Stmt *getRawStmt() {
10094 assert(HasAssociatedStmt &&
10095 "Expected directive with the associated statement.");
10096 if (auto *CS = dyn_cast<CapturedStmt>(getAssociatedStmt())) {
10097 Stmt *S = nullptr;
10098 do {
10099 S = CS->getCapturedStmt();
10100 CS = dyn_cast<CapturedStmt>(S);
10101 } while (CS);
10102 return S;
10103 }
10104 return getAssociatedStmt();
10105 }
10106 const Stmt *getRawStmt() const {
10107 return const_cast<OMPChildren *>(this)->getRawStmt();
10108 }
10109
10110 Stmt::child_range getAssociatedStmtAsRange() {
10111 if (!HasAssociatedStmt)
10112 return Stmt::child_range(Stmt::child_iterator(), Stmt::child_iterator());
10113 return Stmt::child_range(&getTrailingObjects<Stmt *>()[NumChildren],
10114 &getTrailingObjects<Stmt *>()[NumChildren + 1]);
10115 }
10116};
10117
10118/// This represents 'ompx_dyn_cgroup_mem' clause in the '#pragma omp target ...'
10119/// directive.
10120///
10121/// \code
10122/// #pragma omp target [...] ompx_dyn_cgroup_mem(N)
10123/// \endcode
10125 : public OMPOneStmtClause<llvm::omp::OMPC_ompx_dyn_cgroup_mem, OMPClause>,
10126 public OMPClauseWithPreInit {
10127 friend class OMPClauseReader;
10128
10129 /// Set size.
10130 void setSize(Expr *E) { setStmt(E); }
10131
10132public:
10133 /// Build 'ompx_dyn_cgroup_mem' clause.
10134 ///
10135 /// \param Size Size expression.
10136 /// \param HelperSize Helper Size expression
10137 /// \param CaptureRegion Innermost OpenMP region where expressions in this
10138 /// \param StartLoc Starting location of the clause.
10139 /// \param LParenLoc Location of '('.
10140 /// \param EndLoc Ending location of the clause.
10141 OMPXDynCGroupMemClause(Expr *Size, Stmt *HelperSize,
10142 OpenMPDirectiveKind CaptureRegion,
10143 SourceLocation StartLoc, SourceLocation LParenLoc,
10144 SourceLocation EndLoc)
10145 : OMPOneStmtClause(Size, StartLoc, LParenLoc, EndLoc),
10146 OMPClauseWithPreInit(this) {
10147 setPreInitStmt(HelperSize, CaptureRegion);
10148 }
10149
10150 /// Build an empty clause.
10152
10153 /// Return the size expression.
10154 Expr *getSize() { return getStmtAs<Expr>(); }
10155
10156 /// Return the size expression.
10157 Expr *getSize() const { return getStmtAs<Expr>(); }
10158};
10159
10160/// This represents 'dyn_groupprivate' clause in '#pragma omp target ...'
10161/// and '#pragma omp teams ...' directives.
10162///
10163/// \code
10164/// #pragma omp target [...] dyn_groupprivate(a,b: N)
10165/// \endcode
10167 friend class OMPClauseReader;
10168
10169 /// Location of '('.
10170 SourceLocation LParenLoc;
10171
10172 /// Modifiers for 'dyn_groupprivate' clause.
10173 enum { SIMPLE, FALLBACK, NUM_MODIFIERS };
10174 unsigned Modifiers[NUM_MODIFIERS];
10175
10176 /// Locations of modifiers.
10177 SourceLocation ModifiersLoc[NUM_MODIFIERS];
10178
10179 /// The size of the dyn_groupprivate.
10180 Expr *Size = nullptr;
10181
10182 /// Set the first dyn_groupprivate modifier.
10183 ///
10184 /// \param M The modifier.
10185 void setDynGroupprivateModifier(OpenMPDynGroupprivateClauseModifier M) {
10186 Modifiers[SIMPLE] = M;
10187 }
10188
10189 /// Set the second dyn_groupprivate modifier.
10190 ///
10191 /// \param M The modifier.
10192 void setDynGroupprivateFallbackModifier(
10193 OpenMPDynGroupprivateClauseFallbackModifier M) {
10194 Modifiers[FALLBACK] = M;
10195 }
10196
10197 /// Set location of the first dyn_groupprivate modifier.
10198 void setDynGroupprivateModifierLoc(SourceLocation Loc) {
10199 ModifiersLoc[SIMPLE] = Loc;
10200 }
10201
10202 /// Set location of the second dyn_groupprivate modifier.
10203 void setDynGroupprivateFallbackModifierLoc(SourceLocation Loc) {
10204 ModifiersLoc[FALLBACK] = Loc;
10205 }
10206
10207 /// Sets the location of '('.
10208 ///
10209 /// \param Loc Location of '('.
10210 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
10211
10212 /// Set size.
10213 ///
10214 /// \param E Size.
10215 void setSize(Expr *E) { Size = E; }
10216
10217public:
10218 /// Build 'dyn_groupprivate' clause with a size expression \a Size.
10219 ///
10220 /// \param StartLoc Starting location of the clause.
10221 /// \param LParenLoc Location of '('.
10222 /// \param EndLoc Ending location of the clause.
10223 /// \param Size Size.
10224 /// \param M1 The first modifier applied to 'dyn_groupprivate' clause.
10225 /// \param M1Loc Location of the first modifier.
10226 /// \param M2 The second modifier applied to 'dyn_groupprivate' clause.
10227 /// \param M2Loc Location of the second modifier.
10228 OMPDynGroupprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
10229 SourceLocation EndLoc, Expr *Size, Stmt *HelperSize,
10230 OpenMPDirectiveKind CaptureRegion,
10231 OpenMPDynGroupprivateClauseModifier M1,
10232 SourceLocation M1Loc,
10233 OpenMPDynGroupprivateClauseFallbackModifier M2,
10234 SourceLocation M2Loc)
10235 : OMPClause(llvm::omp::OMPC_dyn_groupprivate, StartLoc, EndLoc),
10236 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Size(Size) {
10237 setPreInitStmt(HelperSize, CaptureRegion);
10238 Modifiers[SIMPLE] = M1;
10239 Modifiers[FALLBACK] = M2;
10240 ModifiersLoc[SIMPLE] = M1Loc;
10241 ModifiersLoc[FALLBACK] = M2Loc;
10242 }
10243
10244 /// Build an empty clause.
10246 : OMPClause(llvm::omp::OMPC_dyn_groupprivate, SourceLocation(),
10247 SourceLocation()),
10248 OMPClauseWithPreInit(this) {
10249 Modifiers[SIMPLE] = OMPC_DYN_GROUPPRIVATE_unknown;
10250 Modifiers[FALLBACK] = OMPC_DYN_GROUPPRIVATE_FALLBACK_unknown;
10251 }
10252
10253 /// Get the first modifier of the clause.
10254 OpenMPDynGroupprivateClauseModifier getDynGroupprivateModifier() const {
10255 return static_cast<OpenMPDynGroupprivateClauseModifier>(Modifiers[SIMPLE]);
10256 }
10257
10258 /// Get the second modifier of the clause.
10259 OpenMPDynGroupprivateClauseFallbackModifier
10261 return static_cast<OpenMPDynGroupprivateClauseFallbackModifier>(
10262 Modifiers[FALLBACK]);
10263 }
10264
10265 /// Get location of '('.
10266 SourceLocation getLParenLoc() { return LParenLoc; }
10267
10268 /// Get the first modifier location.
10269 SourceLocation getDynGroupprivateModifierLoc() const {
10270 return ModifiersLoc[SIMPLE];
10271 }
10272
10273 /// Get the second modifier location.
10275 return ModifiersLoc[FALLBACK];
10276 }
10277
10278 /// Get size.
10279 Expr *getSize() { return Size; }
10280
10281 /// Get size.
10282 const Expr *getSize() const { return Size; }
10283
10284 child_range children() {
10285 return child_range(reinterpret_cast<Stmt **>(&Size),
10286 reinterpret_cast<Stmt **>(&Size) + 1);
10287 }
10288
10289 const_child_range children() const {
10290 return const_cast<OMPDynGroupprivateClause *>(this)->children();
10291 }
10292
10293 child_range used_children() {
10294 return child_range(child_iterator(), child_iterator());
10295 }
10296 const_child_range used_children() const {
10297 return const_child_range(const_child_iterator(), const_child_iterator());
10298 }
10299
10300 static bool classof(const OMPClause *T) {
10301 return T->getClauseKind() == llvm::omp::OMPC_dyn_groupprivate;
10302 }
10303};
10304
10305/// This represents the 'doacross' clause for the '#pragma omp ordered'
10306/// directive.
10307///
10308/// \code
10309/// #pragma omp ordered doacross(sink: i-1, j-1)
10310/// \endcode
10311/// In this example directive '#pragma omp ordered' with clause 'doacross' with
10312/// a dependence-type 'sink' and loop-iteration vector expressions i-1 and j-1.
10313class OMPDoacrossClause final
10314 : public OMPVarListClause<OMPDoacrossClause>,
10315 private llvm::TrailingObjects<OMPDoacrossClause, Expr *> {
10316 friend class OMPClauseReader;
10317 friend OMPVarListClause;
10318 friend TrailingObjects;
10319
10320 /// Dependence type (sink or source).
10321 OpenMPDoacrossClauseModifier DepType = OMPC_DOACROSS_unknown;
10322
10323 /// Dependence type location.
10324 SourceLocation DepLoc;
10325
10326 /// Colon location.
10327 SourceLocation ColonLoc;
10328
10329 /// Number of loops, associated with the doacross clause.
10330 unsigned NumLoops = 0;
10331
10332 /// Build clause with number of expressions \a N.
10333 ///
10334 /// \param StartLoc Starting location of the clause.
10335 /// \param LParenLoc Location of '('.
10336 /// \param EndLoc Ending location of the clause.
10337 /// \param N Number of expressions in the clause.
10338 /// \param NumLoops Number of loops associated with the clause.
10339 OMPDoacrossClause(SourceLocation StartLoc, SourceLocation LParenLoc,
10340 SourceLocation EndLoc, unsigned N, unsigned NumLoops)
10341 : OMPVarListClause<OMPDoacrossClause>(llvm::omp::OMPC_doacross, StartLoc,
10342 LParenLoc, EndLoc, N),
10343 NumLoops(NumLoops) {}
10344
10345 /// Build an empty clause.
10346 ///
10347 /// \param N Number of expressions in the clause.
10348 /// \param NumLoops Number of loops associated with the clause.
10349 explicit OMPDoacrossClause(unsigned N, unsigned NumLoops)
10350 : OMPVarListClause<OMPDoacrossClause>(llvm::omp::OMPC_doacross,
10351 SourceLocation(), SourceLocation(),
10352 SourceLocation(), N),
10353 NumLoops(NumLoops) {}
10354
10355 /// Set dependence type.
10356 void setDependenceType(OpenMPDoacrossClauseModifier M) { DepType = M; }
10357
10358 /// Set dependence type location.
10359 void setDependenceLoc(SourceLocation Loc) { DepLoc = Loc; }
10360
10361 /// Set colon location.
10362 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
10363
10364public:
10365 /// Creates clause with a list of expressions \a VL.
10366 ///
10367 /// \param C AST context.
10368 /// \param StartLoc Starting location of the clause.
10369 /// \param LParenLoc Location of '('.
10370 /// \param EndLoc Ending location of the clause.
10371 /// \param DepType The dependence type.
10372 /// \param DepLoc Location of the dependence type.
10373 /// \param ColonLoc Location of ':'.
10374 /// \param VL List of references to the expressions.
10375 /// \param NumLoops Number of loops that associated with the clause.
10376 static OMPDoacrossClause *
10377 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
10378 SourceLocation EndLoc, OpenMPDoacrossClauseModifier DepType,
10379 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
10380 unsigned NumLoops);
10381
10382 /// Creates an empty clause with \a N expressions.
10383 ///
10384 /// \param C AST context.
10385 /// \param N The number of expressions.
10386 /// \param NumLoops Number of loops that is associated with this clause.
10387 static OMPDoacrossClause *CreateEmpty(const ASTContext &C, unsigned N,
10388 unsigned NumLoops);
10389
10390 /// Get dependence type.
10391 OpenMPDoacrossClauseModifier getDependenceType() const { return DepType; }
10392
10393 /// Get dependence type location.
10394 SourceLocation getDependenceLoc() const { return DepLoc; }
10395
10396 /// Get colon location.
10397 SourceLocation getColonLoc() const { return ColonLoc; }
10398
10399 /// Get number of loops associated with the clause.
10400 unsigned getNumLoops() const { return NumLoops; }
10401
10402 /// Set the loop data.
10403 void setLoopData(unsigned NumLoop, Expr *Cnt);
10404
10405 /// Get the loop data.
10406 Expr *getLoopData(unsigned NumLoop);
10407 const Expr *getLoopData(unsigned NumLoop) const;
10408
10409 child_range children() {
10410 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
10411 reinterpret_cast<Stmt **>(varlist_end()));
10412 }
10413
10414 const_child_range children() const {
10415 return const_cast<OMPDoacrossClause *>(this)->children();
10416 }
10417
10418 child_range used_children() {
10419 return child_range(child_iterator(), child_iterator());
10420 }
10421 const_child_range used_children() const {
10422 return const_child_range(const_child_iterator(), const_child_iterator());
10423 }
10424
10425 static bool classof(const OMPClause *T) {
10426 return T->getClauseKind() == llvm::omp::OMPC_doacross;
10427 }
10428};
10429
10430/// This represents 'ompx_attribute' clause in a directive that might generate
10431/// an outlined function. An example is given below.
10432///
10433/// \code
10434/// #pragma omp target [...] ompx_attribute(flatten)
10435/// \endcode
10437 : public OMPNoChildClause<llvm::omp::OMPC_ompx_attribute> {
10438 friend class OMPClauseReader;
10439
10440 /// Location of '('.
10441 SourceLocation LParenLoc;
10442
10443 /// The parsed attributes (clause arguments)
10445
10446public:
10447 /// Build 'ompx_attribute' clause.
10448 ///
10449 /// \param Attrs The parsed attributes (clause arguments)
10450 /// \param StartLoc Starting location of the clause.
10451 /// \param LParenLoc Location of '('.
10452 /// \param EndLoc Ending location of the clause.
10453 OMPXAttributeClause(ArrayRef<const Attr *> Attrs, SourceLocation StartLoc,
10454 SourceLocation LParenLoc, SourceLocation EndLoc)
10455 : OMPNoChildClause(StartLoc, EndLoc), LParenLoc(LParenLoc), Attrs(Attrs) {
10456 }
10457
10458 /// Build an empty clause.
10460
10461 /// Sets the location of '('.
10462 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
10463
10464 /// Returns the location of '('.
10465 SourceLocation getLParenLoc() const { return LParenLoc; }
10466
10467 /// Returned the attributes parsed from this clause.
10468 ArrayRef<const Attr *> getAttrs() const { return Attrs; }
10469
10470private:
10471 /// Replace the attributes with \p NewAttrs.
10472 void setAttrs(ArrayRef<Attr *> NewAttrs) {
10473 Attrs.clear();
10474 Attrs.append(NewAttrs.begin(), NewAttrs.end());
10475 }
10476};
10477
10478/// This represents 'ompx_bare' clause in the '#pragma omp target teams ...'
10479/// directive.
10480///
10481/// \code
10482/// #pragma omp target teams ompx_bare
10483/// \endcode
10484/// In this example directive '#pragma omp target teams' has a 'ompx_bare'
10485/// clause.
10486class OMPXBareClause : public OMPNoChildClause<llvm::omp::OMPC_ompx_bare> {
10487public:
10488 /// Build 'ompx_bare' clause.
10489 ///
10490 /// \param StartLoc Starting location of the clause.
10491 /// \param EndLoc Ending location of the clause.
10492 OMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
10493 : OMPNoChildClause(StartLoc, EndLoc) {}
10494
10495 /// Build an empty clause.
10496 OMPXBareClause() = default;
10497};
10498
10499} // namespace clang
10500
10501#endif // LLVM_CLANG_AST_OPENMPCLAUSE_H
#define V(N, I)
Forward declaration of all AST node types.
#define PTR(CLASS)
Definition AttrVisitor.h:27
static Decl::Kind getKind(const Decl *D)
SmallVector< AnnotatedLine *, 1 > Children
If this token starts a block, this contains all the unwrapped lines in it.
static const Decl * getCanonicalDecl(const Decl *D)
static void print(llvm::raw_ostream &OS, const T &V, const Context &Ctx, QualType Ty)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
std::add_pointer_t< std::add_const_t< T > > const_ptr
Defines some OpenMP-specific enums and functions.
Defines the clang::SourceLocation class and associated facilities.
Expr * getExpr()
Get 'expr' part of the associated expression/statement.
static OMPAtomicDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef< OMPClause * > Clauses, Stmt *AssociatedStmt, Expressions Exprs)
Creates directive with a list of Clauses and 'x', 'v' and 'expr' parts of the atomic construct (see S...
static bool classof(const Stmt *T)
static OMPAtomicDirective * CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell)
Creates an empty directive with the place for NumClauses clauses.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
This represents clause 'affinity' in the 'pragma omp task'-based directives.
friend class OMPClauseReader
Expr * getModifier()
Gets affinity modifier.
child_range used_children()
SourceLocation getColonLoc() const
Gets the location of ':' symbol.
const_child_range children() const
child_range children()
Expr * getModifier() const
static bool classof(const OMPClause *T)
const_child_range used_children() const
This represents clause 'aligned' in the 'pragma omp ...' directives.
friend class OMPClauseReader
void setColonLoc(SourceLocation Loc)
Sets the location of ':'.
SourceLocation getColonLoc() const
Returns the location of ':'.
const Expr * getAlignment() const
Returns alignment.
const_child_range children() const
child_range children()
static bool classof(const OMPClause *T)
Expr * getAlignment()
Returns alignment.
child_range used_children()
const_child_range used_children() const
friend class OMPClauseReader
SourceLocation getBindKindLoc() const
Returns location of clause kind.
SourceLocation getLParenLoc() const
Returns the location of '('.
OpenMPBindClauseKind getBindKind() const
Returns kind of the clause.
Contains data for OpenMP directives: clauses, children expressions/statements (helpers for codegen) a...
friend class OMPClauseReader
void setChildren(ArrayRef< Stmt * > Children)
Stmt::child_range getAssociatedStmtAsRange()
MutableArrayRef< OMPClause * > getClauses()
Get the clauses storage.
void setClauses(ArrayRef< OMPClause * > Clauses)
Sets the list of variables for this clause.
friend class OMPDeclarativeDirective
bool hasAssociatedStmt() const
const CapturedStmt * getInnermostCapturedStmt(ArrayRef< OpenMPDirectiveKind > CaptureRegions) const
Stmt * getRawStmt()
ArrayRef< Stmt * > getChildren() const
void setAssociatedStmt(Stmt *S)
Set associated statement.
const Stmt * getRawStmt() const
unsigned getNumChildren() const
CapturedStmt * getInnermostCapturedStmt(ArrayRef< OpenMPDirectiveKind > CaptureRegions)
Get innermost captured statement for the construct.
friend class OMPExecutableDirective
const Stmt * getAssociatedStmt() const
Returns statement associated with the directive.
ArrayRef< OMPClause * > getClauses() const
MutableArrayRef< Stmt * > getChildren()
const CapturedStmt * getCapturedStmt(OpenMPDirectiveKind RegionKind, ArrayRef< OpenMPDirectiveKind > CaptureRegions) const
Returns the captured statement associated with the component region within the (combined) directive.
Stmt * getAssociatedStmt()
unsigned getNumClauses() const
Class that represents a component of a mappable expression. E.g. for an expression S....
bool operator==(const MappableComponent &Other) const
MappableComponent(Expr *AssociatedExpression, ValueDecl *AssociatedDeclaration, bool IsNonContiguous)
Struct that defines common infrastructure to handle mappable expressions used in OpenMP clauses.
static unsigned getUniqueDeclarationsTotalNumber(ArrayRef< const ValueDecl * > Declarations)
static unsigned getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists)
friend llvm::hash_code hash_value(const MappableComponent &MC)
ArrayRef< MappableExprComponentList > MappableExprComponentListsRef
SmallVector< MappableComponent, 8 > MappableExprComponentList
ArrayRef< MappableComponent > MappableExprComponentListRef
SmallVector< MappableExprComponentList, 8 > MappableExprComponentLists
OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy, unsigned OpenMPVersion)
This class implements a simple visitor for OMPClause subclasses.
RetTy VisitOMPClause(PTR(OMPClause) Node)
RetTy Visit(PTR(OMPClause) S)
This represents clause 'copyin' in the 'pragma omp ...' directives.
friend class OMPClauseReader
llvm::iterator_range< helper_expr_iterator > helper_expr_range
helper_expr_const_range assignment_ops() const
ArrayRef< const Expr * >::iterator helper_expr_const_iterator
helper_expr_range assignment_ops()
child_range children()
helper_expr_range source_exprs()
helper_expr_const_range source_exprs() const
MutableArrayRef< Expr * >::iterator helper_expr_iterator
const_child_range children() const
static bool classof(const OMPClause *T)
helper_expr_range destination_exprs()
child_range used_children()
llvm::iterator_range< helper_expr_const_iterator > helper_expr_const_range
const_child_range used_children() const
helper_expr_const_range destination_exprs() const
This represents clause 'copyprivate' in the 'pragma omp ...' directives.
llvm::iterator_range< helper_expr_iterator > helper_expr_range
child_range children()
friend class OMPClauseReader
const_child_range used_children() const
helper_expr_range destination_exprs()
helper_expr_range source_exprs()
const_child_range children() const
llvm::iterator_range< helper_expr_const_iterator > helper_expr_const_range
child_range used_children()
static bool classof(const OMPClause *T)
helper_expr_const_range destination_exprs() const
ArrayRef< const Expr * >::iterator helper_expr_const_iterator
MutableArrayRef< Expr * >::iterator helper_expr_iterator
helper_expr_const_range source_exprs() const
helper_expr_range assignment_ops()
helper_expr_const_range assignment_ops() const
friend class OMPClauseReader
const_child_range children() const
OMPDefaultmapClause()
Build an empty clause.
child_range children()
OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KLoc, SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind, OpenMPDefaultmapClauseModifier M)
Build 'defaultmap' clause with defaultmap kind Kind.
static bool classof(const OMPClause *T)
child_range used_children()
SourceLocation getDefaultmapModifierLoc() const
Get the modifier location.
OpenMPDefaultmapClauseKind getDefaultmapKind() const
Get kind of the clause.
const_child_range used_children() const
SourceLocation getDefaultmapKindLoc()
Get kind location.
OpenMPDefaultmapClauseModifier getDefaultmapModifier() const
Get the modifier of the clause.
SourceLocation getLParenLoc()
Get location of '('.
This represents implicit clause 'depend' for the 'pragma omp task' directive.
const_child_range children() const
friend class OMPClauseReader
SourceLocation getDependencyLoc() const
Get dependency type location.
Expr * getModifier()
Return optional depend modifier.
unsigned getNumLoops() const
Get number of loops associated with the clause.
const Expr * getModifier() const
SourceLocation getColonLoc() const
Get colon location.
SourceLocation getOmpAllMemoryLoc() const
Get 'omp_all_memory' location.
const_child_range used_children() const
static bool classof(const OMPClause *T)
child_range children()
OpenMPDependClauseKind getDependencyKind() const
Get dependency type.
child_range used_children()
This represents implicit clause 'depobj' for the 'pragma omp depobj' directive. This clause does not ...
const Expr * getDepobj() const
friend class OMPClauseReader
SourceLocation getLParenLoc() const
Returns the location of '('.
const_child_range children() const
child_range children()
Expr * getDepobj()
Returns depobj expression associated with the clause.
static bool classof(const OMPClause *T)
const_child_range used_children() const
child_range used_children()
SourceLocation getLParenLoc() const
Returns the location of '('.
OMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build 'destroy' clause with an interop variable expression InteropVar.
friend class OMPClauseReader
const_child_range children() const
const_child_range used_children() const
static bool classof(const OMPClause *T)
SourceLocation getVarLoc() const
Returns the location of the interop variable.
Expr * getInteropVar() const
Returns the interop variable.
child_range used_children()
OMPDestroyClause()
Build an empty clause.
child_range children()
OMPDestroyClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build 'destroy' clause.
friend class OMPClauseReader
Expr * getEventHandler() const
Returns event-handler expression.
OMPDetachClause()
Build an empty clause.
OMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'detach' clause with event-handler Evt.
OpenMPDeviceClauseModifier getModifier() const
Gets modifier.
friend class OMPClauseReader
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
child_range used_children()
Expr * getDevice()
Return device number.
OMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build 'device' clause.
OMPDeviceClause()
Build an empty clause.
SourceLocation getModifierLoc() const
Gets modifier location.
Expr * getDevice() const
Return device number.
SourceLocation getLParenLoc() const
Returns the location of '('.
const_child_range used_children() const
const_child_range children() const
child_range children()
static bool classof(const OMPClause *T)
SourceLocation getDistScheduleKindLoc()
Get kind location.
friend class OMPClauseReader
OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KLoc, SourceLocation CommaLoc, SourceLocation EndLoc, OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, Stmt *HelperChunkSize)
Build 'dist_schedule' clause with schedule kind Kind and chunk size expression ChunkSize.
SourceLocation getLParenLoc()
Get location of '('.
child_range used_children()
const_child_range used_children() const
SourceLocation getCommaLoc()
Get location of ','.
static bool classof(const OMPClause *T)
const_child_range children() const
Expr * getChunkSize()
Get chunk size.
OpenMPDistScheduleClauseKind getDistScheduleKind() const
Get kind of the clause.
OMPDistScheduleClause()
Build an empty clause.
const Expr * getChunkSize() const
Get chunk size.
This represents the 'doacross' clause for the 'pragma omp ordered' directive.
const_child_range children() const
friend class OMPClauseReader
SourceLocation getDependenceLoc() const
Get dependence type location.
SourceLocation getColonLoc() const
Get colon location.
OpenMPDoacrossClauseModifier getDependenceType() const
Get dependence type.
static bool classof(const OMPClause *T)
const_child_range used_children() const
child_range children()
child_range used_children()
unsigned getNumLoops() const
Get number of loops associated with the clause.
OMPDynGroupprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, Expr *Size, Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion, OpenMPDynGroupprivateClauseModifier M1, SourceLocation M1Loc, OpenMPDynGroupprivateClauseFallbackModifier M2, SourceLocation M2Loc)
Build 'dyn_groupprivate' clause with a size expression Size.
static bool classof(const OMPClause *T)
const Expr * getSize() const
Get size.
Expr * getSize()
Get size.
SourceLocation getLParenLoc()
Get location of '('.
OpenMPDynGroupprivateClauseFallbackModifier getDynGroupprivateFallbackModifier() const
Get the second modifier of the clause.
OMPDynGroupprivateClause()
Build an empty clause.
SourceLocation getDynGroupprivateFallbackModifierLoc() const
Get the second modifier location.
SourceLocation getDynGroupprivateModifierLoc() const
Get the first modifier location.
OpenMPDynGroupprivateClauseModifier getDynGroupprivateModifier() const
Get the first modifier of the clause.
const_child_range children() const
const_child_range used_children() const
This represents clause 'exclusive' in the 'pragma omp scan' directive.
const_child_range children() const
friend class OMPClauseReader
child_range children()
static bool classof(const OMPClause *T)
child_range used_children()
const_child_range used_children() const
OMPFilterClause()
Build an empty clause.
friend class OMPClauseReader
Expr * getThreadID() const
Return thread identifier.
Expr * getThreadID()
Return thread identifier.
OMPFilterClause(Expr *ThreadID, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'filter' clause with thread-id ThreadID.
static bool classof(const OMPClause *T)
child_range used_children()
const_child_range used_children() const
child_range children()
const_child_range children() const
This represents clause 'from' in the 'pragma omp ...' directives.
const_child_range children() const
friend class OMPClauseReader
const_child_range used_children() const
child_range used_children()
ArrayRef< SourceLocation > getMotionModifiersLoc() const LLVM_READONLY
Fetches ArrayRef of location of motion-modifiers.
static bool classof(const OMPClause *T)
child_range children()
ArrayRef< OpenMPMotionModifierKind > getMotionModifiers() const LLVM_READONLY
Fetches ArrayRef of motion-modifiers.
SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY
Fetches the motion-modifier location at 'Cnt' index of array of modifiers' locations.
SourceLocation getColonLoc() const
Get colon location.
Expr * getIteratorModifier() const
OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY
Fetches the motion-modifier at 'Cnt' index of array of modifiers.
const_child_range children() const
OpenMPGrainsizeClauseModifier getModifier() const
Gets modifier.
friend class OMPClauseReader
OMPGrainsizeClause()
Build an empty clause.
SourceLocation getModifierLoc() const
Gets modifier location.
const_child_range used_children() const
Expr * getGrainsize() const
Return safe iteration space distance.
child_range used_children()
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
static bool classof(const OMPClause *T)
child_range children()
SourceLocation getLParenLoc() const
Returns the location of '('.
OMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size, Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build 'grainsize' clause.
This represents clause 'has_device_ptr' in the 'pragma omp ...' directives.
static bool classof(const OMPClause *T)
friend class OMPClauseReader
const_child_range used_children() const
const_child_range children() const
child_range used_children()
SourceLocation getLParenLoc() const
Returns the location of '('.
friend class OMPClauseReader
child_range used_children()
OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'hint' clause with expression Hint.
Expr * getHint() const
Returns number of threads.
const_child_range used_children() const
const_child_range children() const
static bool classof(const OMPClause *T)
child_range children()
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
OMPHintClause()
Build an empty clause.
This represents clause 'inclusive' in the 'pragma omp scan' directive.
const_child_range children() const
friend class OMPClauseReader
child_range children()
static bool classof(const OMPClause *T)
const_child_range used_children() const
child_range used_children()
bool getIsTarget() const
Returns true is interop-type 'target' is used.
friend class OMPClauseReader
ArrayRef< Expr * > attrs() const
All attr() exprs across every pref-spec, in pref-spec order (flat block).
const_child_range children() const
bool hasPreferAttrs() const
Returns true if OMP 6.0 {fr/attr} syntax is used.
child_range children()
child_range used_children()
Expr * getInteropVar()
Returns the interop variable.
const_child_range used_children() const
SourceLocation getVarLoc() const
Returns the location of the interop variable.
bool getIsTargetSync() const
Returns true is interop-type 'targetsync' is used.
const Expr * getInteropVar() const
static bool classof(const OMPClause *T)
auto prefs() const
Returns a range of PrefView objects, one per preference-specification, each carrying the fr() express...
This represents clause 'is_device_ptr' in the 'pragma omp ...' directives.
friend class OMPClauseReader
child_range children()
static bool classof(const OMPClause *T)
child_range used_children()
const_child_range children() const
const_child_range used_children() const
OpenMPMapClauseKind getMapType() const LLVM_READONLY
Fetches mapping kind for the clause.
child_range children()
friend class OMPClauseReader
const_child_range children() const
OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY
Fetches the map-type-modifier at 'Cnt' index of array of modifiers.
SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY
Fetches the map-type-modifier location at 'Cnt' index of array of modifiers' locations.
SourceLocation getMapLoc() const LLVM_READONLY
Fetches location of clause mapping kind.
child_range used_children()
ArrayRef< SourceLocation > getMapTypeModifiersLoc() const LLVM_READONLY
Fetches ArrayRef of location of map-type-modifiers.
static bool classof(const OMPClause *T)
SourceLocation getColonLoc() const
Get colon location.
ArrayRef< OpenMPMapModifierKind > getMapTypeModifiers() const LLVM_READONLY
Fetches ArrayRef of map-type-modifiers.
const_child_range used_children() const
bool isImplicitMapType() const LLVM_READONLY
Is this an implicit map type? We have to capture 'IsMapTypeImplicit' from the parser for more informa...
Expr * getIteratorModifier()
Fetches Expr * of iterator modifier.
Iterator that browse the components by lists. It also allows browsing components of a single declarat...
std::tuple< const ValueDecl *, MappableExprComponentListRef, const ValueDecl * > operator->() const
std::tuple< const ValueDecl *, MappableExprComponentListRef, const ValueDecl * > operator*() const
const_component_lists_iterator(const ValueDecl *Declaration, ArrayRef< ValueDecl * > UniqueDecls, ArrayRef< unsigned > DeclsListNum, ArrayRef< unsigned > CumulativeListSizes, MappableExprComponentListRef Components, bool SupportsMapper, ArrayRef< Expr * > Mappers)
Construct an iterator that scan lists for a given declaration Declaration.
const_component_lists_iterator(ArrayRef< ValueDecl * > UniqueDecls, ArrayRef< unsigned > DeclsListNum, ArrayRef< unsigned > CumulativeListSizes, MappableExprComponentListRef Components, bool SupportsMapper, ArrayRef< Expr * > Mappers)
Construct an iterator that scans all lists.
This represents clauses with a list of expressions that are mappable. Examples of these clauses are '...
MutableArrayRef< ValueDecl * > getUniqueDeclsRef()
Get the unique declarations that are in the trailing objects of the class.
const DeclarationNameInfo & getMapperIdInfo() const
Gets the name info for associated user-defined mapper.
const_all_lists_sizes_range all_lists_sizes() const
const_component_lists_range decl_component_lists(const ValueDecl *VD) const
llvm::iterator_range< const_all_components_iterator > const_all_components_range
unsigned getTotalComponentsNum() const
Return the total number of components in all lists derived from the clause.
void setComponents(ArrayRef< MappableComponent > Components, ArrayRef< unsigned > CLSs)
Set the components that are in the trailing objects of the class. This requires the list sizes so tha...
mapperlist_const_iterator mapperlist_end() const
const_component_lists_iterator component_lists_end() const
llvm::iterator_range< const_all_lists_sizes_iterator > const_all_lists_sizes_range
mapperlist_iterator mapperlist_begin()
ArrayRef< ValueDecl * > getUniqueDeclsRef() const
Get the unique declarations that are in the trailing objects of the class.
mapperlist_iterator mapperlist_end()
ArrayRef< ValueDecl * >::iterator const_all_decls_iterator
Iterators to access all the declarations, number of lists, list sizes, and components.
MutableArrayRef< Expr * >::iterator mapperlist_iterator
ArrayRef< unsigned > getComponentListSizesRef() const
Get the cumulative component lists sizes that are in the trailing objects of the class....
MutableArrayRef< unsigned > getDeclNumListsRef()
Get the number of lists per declaration that are in the trailing objects of the class.
ArrayRef< Expr * > getUDMapperRefs() const
Get the user-defined mappers references that are in the trailing objects of the class.
const_component_lists_range component_lists() const
void setDeclNumLists(ArrayRef< unsigned > DNLs)
Set the number of lists per declaration that are in the trailing objects of the class.
const_all_components_range all_components() const
ArrayRef< unsigned >::iterator const_all_num_lists_iterator
mapperlist_const_range mapperlists() const
OMPMappableExprListClause(OpenMPClauseKind K, const OMPVarListLocTy &Locs, const OMPMappableExprListSizeTy &Sizes, bool SupportsMapper=false, NestedNameSpecifierLoc *MapperQualifierLocPtr=nullptr, DeclarationNameInfo *MapperIdInfoPtr=nullptr)
Build a clause for NumUniqueDeclarations declarations, NumComponentLists total component lists,...
ArrayRef< const Expr * >::iterator mapperlist_const_iterator
mapperlist_const_iterator mapperlist_begin() const
void setMapperIdInfo(DeclarationNameInfo MapperId)
Set the name of associated user-defined mapper.
void setUDMapperRefs(ArrayRef< Expr * > DMDs)
Set the user-defined mappers that are in the trailing objects of the class.
void setComponentListSizes(ArrayRef< unsigned > CLSs)
Set the cumulative component lists sizes that are in the trailing objects of the class.
const_all_num_lists_range all_num_lists() const
ArrayRef< unsigned >::iterator const_all_lists_sizes_iterator
unsigned getTotalComponentListNum() const
Return the number of lists derived from the clause expressions.
void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL)
Set the nested name specifier of associated user-defined mapper.
MutableArrayRef< Expr * > getUDMapperRefs()
Get the user-defined mapper references that are in the trailing objects of the class.
unsigned getUniqueDeclarationsNum() const
Return the number of unique base declarations in this clause.
const_component_lists_iterator decl_component_lists_end() const
ArrayRef< unsigned > getDeclNumListsRef() const
Get the number of lists per declaration that are in the trailing objects of the class.
NestedNameSpecifierLoc getMapperQualifierLoc() const
Gets the nested name specifier for associated user-defined mapper.
llvm::iterator_range< const_all_num_lists_iterator > const_all_num_lists_range
mapperlist_range mapperlists()
MutableArrayRef< unsigned > getComponentListSizesRef()
Get the cumulative component lists sizes that are in the trailing objects of the class....
void setClauseInfo(ArrayRef< ValueDecl * > Declarations, MappableExprComponentListsRef ComponentLists)
Fill the clause information from the list of declarations and associated component lists.
MutableArrayRef< MappableComponent > getComponentsRef()
Get the components that are in the trailing objects of the class.
const_component_lists_iterator component_lists_begin() const
Iterators for all component lists.
llvm::iterator_range< const_component_lists_iterator > const_component_lists_range
llvm::iterator_range< mapperlist_const_iterator > mapperlist_const_range
const_component_lists_iterator decl_component_lists_begin(const ValueDecl *VD) const
Iterators for component lists associated with the provided declaration.
ArrayRef< MappableComponent > getComponentsRef() const
Get the components that are in the trailing objects of the class.
llvm::iterator_range< mapperlist_iterator > mapperlist_range
llvm::iterator_range< const_all_decls_iterator > const_all_decls_range
ArrayRef< MappableComponent >::iterator const_all_components_iterator
void setUniqueDecls(ArrayRef< ValueDecl * > UDs)
Set the unique declarations that are in the trailing objects of the class.
const_all_decls_range all_decls() const
friend class OMPClauseReader
OMPNocontextClause()
Build an empty clause.
const_child_range used_children() const
Expr * getCondition() const
Returns condition.
OMPNocontextClause(Expr *Cond, Stmt *HelperCond, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'nocontext' clause with condition Cond.
child_range used_children()
static bool classof(const OMPClause *T)
const_child_range children() const
child_range children()
const_child_range used_children() const
OMPNogroupClause()
Build an empty clause.
OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build 'nogroup' clause.
child_range used_children()
This represents clause 'nontemporal' in the 'pragma omp ...' directives.
friend class OMPClauseReader
child_range used_children()
static bool classof(const OMPClause *T)
const_child_range used_children() const
child_range children()
const_child_range children() const
const_child_range private_refs() const
child_range private_refs()
Expr * getCondition() const
Returns condition.
friend class OMPClauseReader
const_child_range used_children() const
child_range used_children()
OMPNovariantsClause()
Build an empty clause.
OMPNovariantsClause(Expr *Cond, Stmt *HelperCond, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'novariants' clause with condition Cond.
friend class OMPClauseReader
const_child_range children() const
SourceLocation getModifierLoc() const
Gets modifier location.
OMPNumTasksClause()
Build an empty clause.
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
SourceLocation getLParenLoc() const
Returns the location of '('.
const_child_range used_children() const
OpenMPNumTasksClauseModifier getModifier() const
Gets modifier.
OMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *Size, Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build 'num_tasks' clause.
child_range children()
static bool classof(const OMPClause *T)
child_range used_children()
Expr * getNumTasks() const
Return safe iteration space distance.
child_range used_children()
ArrayRef< Expr * > getNumTeams()
Return NumTeams expressions.
Expr * getModifierExpr()
Get the expression of the modifier.
static bool classof(const OMPClause *T)
const_child_range children() const
SourceLocation getModifierLoc() const
Get the location of the modifier.
OpenMPNumTeamsClauseModifier getModifier() const
Get the modifier.
void setModifierLoc(SourceLocation Loc)
Set the location of the modifier.
void setModifierExpr(Expr *E)
Set the expression of the modifier.
const Expr * getModifierExpr() const
Get the expression of the modifier.
ArrayRef< Expr * > getNumTeams() const
Return NumTeams expressions.
child_range children()
void setModifier(OpenMPNumTeamsClauseModifier M)
Set the modifier.
const_child_range used_children() const
friend class OMPClauseReader
SourceLocation getLParenLoc() const
Returns the location of '('.
SourceLocation getModifierKwLoc() const
Returns location of clause modifier.
OMPOrderClause(OpenMPOrderClauseKind A, SourceLocation ALoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, OpenMPOrderClauseModifier Modifier, SourceLocation MLoc)
Build 'order' clause with argument A ('concurrent').
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
SourceLocation getKindKwLoc() const
Returns location of clause kind.
const_child_range used_children() const
static bool classof(const OMPClause *T)
OMPOrderClause()
Build an empty clause.
const_child_range children() const
child_range used_children()
child_range children()
OpenMPOrderClauseKind getKind() const
Returns kind of the clause.
OpenMPOrderClauseModifier getModifier() const
Returns Modifier of the clause.
friend class OMPClauseReader
child_range children()
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
Expr * getPriority() const
Return Priority number.
child_range used_children()
SourceLocation getLParenLoc() const
Returns the location of '('.
const_child_range used_children() const
OMPPriorityClause(Expr *Priority, Stmt *HelperPriority, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'priority' clause.
OMPPriorityClause()
Build an empty clause.
static bool classof(const OMPClause *T)
const_child_range children() const
Expr * getPriority()
Return Priority number.
OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build 'simd' clause.
const_child_range used_children() const
const_child_range children() const
OMPSIMDClause()
Build an empty clause.
child_range used_children()
static bool classof(const OMPClause *T)
child_range children()
const_child_range children() const
child_range used_children()
const_child_range used_children() const
ArrayRef< Expr * > getThreadLimit() const
Return ThreadLimit expressions.
child_range children()
ArrayRef< Expr * > getThreadLimit()
Return ThreadLimit expressions.
static bool classof(const OMPClause *T)
OMPThreadsClause()
Build an empty clause.
OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build 'threads' clause.
This represents clause 'to' in the 'pragma omp ...' directives.
ArrayRef< SourceLocation > getMotionModifiersLoc() const LLVM_READONLY
Fetches ArrayRef of location of motion-modifiers.
friend class OMPClauseReader
Expr * getIteratorModifier() const
SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY
Fetches the motion-modifier location at 'Cnt' index of array of modifiers' locations.
ArrayRef< OpenMPMotionModifierKind > getMotionModifiers() const LLVM_READONLY
Fetches ArrayRef of motion-modifiers.
static bool classof(const OMPClause *T)
child_range used_children()
OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY
Fetches the motion-modifier at 'Cnt' index of array of modifiers.
const_child_range used_children() const
const_child_range children() const
child_range children()
SourceLocation getColonLoc() const
Get colon location.
bool isExtensionActive(llvm::omp::TraitProperty TP)
Check the extension trait TP is active.
friend class ASTContext
llvm::SmallVector< OMPTraitSet, 2 > Sets
The outermost level of selector sets.
bool anyScoreOrCondition(llvm::function_ref< bool(Expr *&, bool)> Cond)
friend class OMPClauseReader
static bool classof(const OMPClause *T)
child_range used_children()
SourceLocation getVarLoc() const
Returns the location of the interop variable.
Expr * getInteropVar() const
Returns the interop variable.
OMPUseClause()
Build an empty clause.
const_child_range children() const
const_child_range used_children() const
OMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build 'use' clause with and interop variable expression InteropVar.
child_range children()
SourceLocation getLParenLoc() const
Returns the location of '('.
This represents clause 'use_device_addr' in the 'pragma omp ...' directives.
friend class OMPClauseReader
const_child_range used_children() const
child_range used_children()
static bool classof(const OMPClause *T)
const_child_range children() const
This represents clause 'use_device_ptr' in the 'pragma omp ...' directives.
SourceLocation getFallbackModifierLoc() const
Get the location of the fallback modifier.
friend class OMPClauseReader
ArrayRef< const Expr * >::iterator inits_const_iterator
static bool classof(const OMPClause *T)
MutableArrayRef< Expr * >::iterator private_copies_iterator
llvm::iterator_range< private_copies_iterator > private_copies_range
llvm::iterator_range< inits_iterator > inits_range
const_child_range used_children() const
child_range used_children()
OpenMPUseDevicePtrFallbackModifier getFallbackModifier() const
Get the fallback modifier for the clause.
const_child_range children() const
private_copies_const_range private_copies() const
private_copies_range private_copies()
MutableArrayRef< Expr * >::iterator inits_iterator
ArrayRef< const Expr * >::iterator private_copies_const_iterator
llvm::iterator_range< inits_const_iterator > inits_const_range
inits_const_range inits() const
llvm::iterator_range< private_copies_const_iterator > private_copies_const_range
const_child_range used_children() const
child_range used_children()
const_child_range children() const
SourceLocation getLParenLoc() const
Returns the location of '('.
static bool classof(const OMPClause *T)
unsigned getNumberOfAllocators() const
Returns number of allocators associated with the clause.
ArrayRef< const Attr * > getAttrs() const
Returned the attributes parsed from this clause.
friend class OMPClauseReader
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
OMPXAttributeClause()
Build an empty clause.
SourceLocation getLParenLoc() const
Returns the location of '('.
OMPXAttributeClause(ArrayRef< const Attr * > Attrs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'ompx_attribute' clause.
OMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build 'ompx_bare' clause.
OMPXBareClause()=default
Build an empty clause.
Expr * getSize()
Return the size expression.
Expr * getSize() const
Return the size expression.
OMPXDynCGroupMemClause(Expr *Size, Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'ompx_dyn_cgroup_mem' clause.
OMPXDynCGroupMemClause()
Build an empty clause.
a trap message and trap category.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
This represents one expression.
Definition Expr.h:112
This represents the 'align' clause in the 'pragma omp allocate' directive.
friend class OMPClauseReader
Expr * getAlignment() const
Returns alignment.
This represents clause 'allocate' in the 'pragma omp ...' directives.
const_child_range children() const
SourceLocation getAllocatorModifierLoc() const
Return the location of the modifier.
const_child_range used_children() const
OpenMPAllocateClauseModifier getAllocatorModifier() const
Return 'allocate' modifier.
OpenMPAllocateClauseModifier getSecondAllocateModifier() const
Get the second modifier of the clause.
SourceLocation getColonLoc() const
Returns the location of the ':' delimiter.
Expr * getAlignment() const
Returns the alignment expression or nullptr, if no alignment specified.
OpenMPAllocateClauseModifier getFirstAllocateModifier() const
Get the first modifier of the clause.
Expr * getAllocator() const
Returns the allocator expression or nullptr, if no allocator is specified.
SourceLocation getSecondAllocateModifierLoc() const
Get location of second modifier of the clause.
child_range used_children()
SourceLocation getFirstAllocateModifierLoc() const
Get location of first modifier of the clause.
static OMPAllocateClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
static bool classof(const OMPClause *T)
OMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'allocator' clause with the given allocator.
OMPAllocatorClause()
Build an empty clause.
Expr * getAllocator() const
Returns allocator.
Class that handles post-update expression for some clauses, like 'lastprivate', 'reduction' etc.
void setPostUpdateExpr(Expr *S)
Set pre-initialization statement for the clause.
static OMPClauseWithPostUpdate * get(OMPClause *C)
Expr * getPostUpdateExpr()
Get post-update expression for the clause.
OMPClauseWithPostUpdate(const OMPClause *This)
const Expr * getPostUpdateExpr() const
Get post-update expression for the clause.
Class that handles pre-initialization statement for some clauses, like 'schedule',...
const Stmt * getPreInitStmt() const
Get pre-initialization statement for the clause.
OMPClauseWithPreInit(const OMPClause *This)
OpenMPDirectiveKind getCaptureRegion() const
Get capture region for the stmt in the clause.
Stmt * getPreInitStmt()
Get pre-initialization statement for the clause.
static OMPClauseWithPreInit * get(OMPClause *C)
void setPreInitStmt(Stmt *S, OpenMPDirectiveKind ThisRegion=llvm::omp::OMPD_unknown)
Set pre-initialization statement for the clause.
This is a basic class for representing single OpenMP clause.
const_child_range children() const
void setLocStart(SourceLocation Loc)
Sets the starting location of the clause.
static bool classof(const OMPClause *)
SourceLocation getBeginLoc() const
Returns the starting location of the clause.
llvm::iterator_range< const_child_iterator > const_child_range
ConstStmtIterator const_child_iterator
child_range used_children()
Get the iterator range for the expressions used in the clauses.
llvm::iterator_range< child_iterator > child_range
OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
void setLocEnd(SourceLocation Loc)
Sets the ending location of the clause.
bool isImplicit() const
StmtIterator child_iterator
SourceLocation getEndLoc() const
Returns the ending location of the clause.
child_range children()
OpenMPClauseKind getClauseKind() const
Returns kind of OpenMP clause (private, shared, reduction, etc.).
const_child_range used_children() const
OMPCollapseClause()
Build an empty clause.
Expr * getNumForLoops() const
Return the number of associated for-loops.
OMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'collapse' clause.
static bool classof(const OMPClause *T)
std::optional< unsigned > getOmpFillIndex() const
friend class OMPClauseReader
child_range used_children()
SourceLocation getOmpFillLoc() const
ArrayRef< Expr * > getCountsRefs() const
const_child_range used_children() const
const_child_range children() const
unsigned getNumCounts() const
Returns the number of list items.
static OMPCountsClause * CreateEmpty(const ASTContext &C, unsigned NumCounts)
Build an empty 'counts' AST node for deserialization.
SourceLocation getLParenLoc() const
Returns the location of '('.
MutableArrayRef< Expr * > getCountsRefs()
Returns the count expressions.
const_child_range used_children() const
OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc, OpenMPDefaultClauseVariableCategory VC, SourceLocation VCLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'default' clause with argument A ('none' or 'shared').
SourceLocation getLParenLoc() const
Returns the location of '('.
llvm::omp::DefaultKind getDefaultKind() const
Returns kind of the clause.
SourceLocation getDefaultKindKwLoc() const
Returns location of clause kind.
OpenMPDefaultClauseVariableCategory getDefaultVC() const
static bool classof(const OMPClause *T)
child_range used_children()
const_child_range children() const
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
OMPDefaultClause()
Build an empty clause.
SourceLocation getDefaultVCLoc() const
Class that represents a list of directive kinds (parallel, target, etc.) as used in absent,...
MutableArrayRef< OpenMPDirectiveKind > getDirectiveKinds()
void setDirectiveKinds(ArrayRef< OpenMPDirectiveKind > DK)
const_child_range children() const
unsigned NumKinds
Number of directive kinds listed in the clause.
void setLParenLoc(SourceLocation S)
const_child_range used_children() const
OMPDirectiveListClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, unsigned NumKinds)
Build a clause with NumKinds directive kinds.
child_range used_children()
friend class OMPClauseReader
Expr * getCondition() const
Returns condition.
OMPFinalClause(Expr *Cond, Stmt *HelperCond, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'final' clause with condition Cond.
OMPFinalClause()
Build an empty clause.
const_child_range used_children() const
Representation of the 'full' clause of the 'pragma omp unroll' directive.
friend class OMPClauseReader
static OMPFullClause * CreateEmpty(const ASTContext &C)
Build an empty 'full' AST node for deserialization.
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
friend class OMPClauseReader
const_child_range used_children() const
SourceLocation getLParenLoc() const
Returns the location of '('.
SourceLocation getColonLoc() const
Return the location of ':'.
static bool classof(const OMPClause *T)
child_range used_children()
Expr * getCondition() const
Returns condition.
OpenMPDirectiveKind getNameModifier() const
Return directive name modifier associated with the clause.
OMPIfClause()
Build an empty clause.
child_range children()
const_child_range children() const
OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build 'if' clause with condition Cond.
SourceLocation getNameModifierLoc() const
Return the location of directive name modifier.
Expr * getFirst() const
Get looprange 'first' expression.
static OMPLoopRangeClause * CreateEmpty(const ASTContext &C)
Build an empty 'looprange' clause node.
const_child_range used_children() const
void setFirstLoc(SourceLocation Loc)
void setCountLoc(SourceLocation Loc)
SourceLocation getFirstLoc() const
SourceLocation getLParenLoc() const
static bool classof(const OMPClause *T)
SourceLocation getCountLoc() const
const_child_range children() const
Expr * getCount() const
Get looprange 'count' expression.
void setLParenLoc(SourceLocation Loc)
OpenMPNumThreadsClauseModifier getModifier() const
Gets modifier.
SourceLocation getModifierLoc() const
Gets modifier location.
OMPNumThreadsClause()
Build an empty clause.
OMPNumThreadsClause(OpenMPNumThreadsClauseModifier Modifier, Expr *NumThreads, Stmt *HelperNumThreads, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build 'num_threads' clause with condition NumThreads.
Expr * getNumThreads() const
Returns number of threads.
const_child_range used_children() const
child_range used_children()
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
OMPOneStmtClause(Stmt *S, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static bool classof(const OMPClause *T)
ConstStmtIterator const_child_iterator
const_child_range children() const
StmtIterator child_iterator
llvm::iterator_range< child_iterator > child_range
SourceLocation getLParenLoc() const
Returns the location of '('.
llvm::iterator_range< const_child_iterator > const_child_range
T * getStmtAs() const
Return the associated statement, potentially casted to T.
child_range used_children()
static OMPPartialClause * CreateEmpty(const ASTContext &C)
Build an empty 'partial' AST node for deserialization.
const_child_range used_children() const
SourceLocation getLParenLoc() const
Returns the location of '('.
const_child_range children() const
static bool classof(const OMPClause *T)
Expr * getFactor() const
Returns the argument of the clause or nullptr if not set.
This class represents the 'permutation' clause in the 'pragma omp interchange' directive.
static bool classof(const OMPClause *T)
ArrayRef< Expr * > getArgsRefs() const
unsigned getNumLoops() const
Returns the number of list items.
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
SourceLocation getLParenLoc() const
Returns the location of '('.
MutableArrayRef< Expr * > getArgsRefs()
Returns the permutation index expressions.
static OMPPermutationClause * CreateEmpty(const ASTContext &C, unsigned NumLoops)
Build an empty 'permutation' AST node for deserialization.
const_child_range used_children() const
const_child_range children() const
friend class OMPClauseReader
OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'safelen' clause.
Expr * getSafelen() const
Return safe iteration space distance.
OMPSafelenClause()
Build an empty clause.
friend class OMPClauseReader
OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'simdlen' clause.
Expr * getSimdlen() const
Return safe iteration space distance.
OMPSimdlenClause()
Build an empty clause.
This represents the 'sizes' clause in the 'pragma omp tile' directive.
SourceLocation getLParenLoc() const
Returns the location of '('.
friend class OMPClauseReader
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
static bool classof(const OMPClause *T)
const_child_range used_children() const
void setSizesRefs(ArrayRef< Expr * > VL)
Sets the tile size expressions.
unsigned getNumSizes() const
Returns the number of list items.
child_range used_children()
MutableArrayRef< Expr * > getSizesRefs()
Returns the tile size expressions.
ArrayRef< Expr * > getSizesRefs() const
const_child_range children() const
static OMPSizesClause * CreateEmpty(const ASTContext &C, unsigned NumSizes)
Build an empty 'sizes' AST node for deserialization.
static bool classof(const OMPClause *T)
OpenMPThreadsetKind getThreadsetKind() const
Returns kind of the clause.
const_child_range children() const
OMPThreadsetClause(OpenMPThreadsetKind A, SourceLocation ALoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'threadset' clause with argument A ('omp_team' or 'omp_pool').
const_child_range used_children() const
SourceLocation getThreadsetKindLoc() const
Returns location of clause kind.
SourceLocation getLParenLoc() const
Returns the location of '('.
OMPThreadsetClause()
Build an empty clause.
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
This represents clauses with the list of variables like 'private', 'firstprivate',...
varlist_const_range varlist() const
friend class OMPClauseReader
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
ArrayRef< const Expr * > getVarRefs() const
Fetches list of all variables in the clause.
OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
Build a clause with N variables.
MutableArrayRef< Expr * > getVarRefs()
Fetches list of variables associated with this clause.
varlist_range varlist()
varlist_const_iterator varlist_end() const
varlist_iterator varlist_end()
llvm::iterator_range< varlist_const_iterator > varlist_const_range
MutableArrayRef< Expr * >::iterator varlist_iterator
varlist_iterator varlist_begin()
ArrayRef< const Expr * >::iterator varlist_const_iterator
SourceLocation getLParenLoc() const
Returns the location of '('.
unsigned varlist_size() const
varlist_const_iterator varlist_begin() const
llvm::iterator_range< varlist_iterator > varlist_range
void setVarRefs(ArrayRef< Expr * > VL)
Sets the list of variables for this clause.
Encodes a location in the source.
Stmt - This represents one statement.
Definition Stmt.h:86
Definition SPIR.cpp:35
The JSON file list parser is used to communicate input to InstallAPI.
OpenMPOriginalSharingModifier
OpenMP 6.0 original sharing modifiers.
ArrayRef< const Expr * >::iterator used_expressions_const_iterator
bool checkFailClauseParameter(OpenMPClauseKind FailClauseParameter)
Checks if the parameter to the fail clause in "#pragma atomic compare fail" is restricted only to mem...
MutableArrayRef< Expr * > getFinals()
Sets the list of final update expressions for linear variables.
llvm::iterator_range< inits_iterator > inits_range
privates_range privates()
OpenMPDefaultClauseVariableCategory
OpenMP variable-category for 'default' clause.
MutableArrayRef< Expr * >::iterator privates_iterator
llvm::iterator_range< finals_const_iterator > finals_const_range
MutableArrayRef< Expr * > getPrivates()
Finals[]; Step; CalcStep; }.
void setColonLoc(SourceLocation Loc)
Sets the location of ':'.
MutableArrayRef< Expr * >::iterator inits_iterator
OpenMPLinearClauseKind getModifier() const
Return modifier.
llvm::iterator_range< privates_const_iterator > privates_const_range
void setUsedExprs(ArrayRef< Expr * > UE)
Sets the list of used expressions for the linear clause.
OpenMPAtClauseKind
OpenMP attributes for 'at' clause.
@ OMPC_AT_unknown
OpenMPReductionClauseModifier
OpenMP modifiers for 'reduction' clause.
@ OMPC_REDUCTION_unknown
void setUpdates(ArrayRef< Expr * > UL)
Sets the list of update expressions for linear variables.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition OpenMPKinds.h:39
@ OMPC_SCHEDULE_MODIFIER_unknown
Definition OpenMPKinds.h:40
llvm::iterator_range< inits_const_iterator > inits_const_range
llvm::iterator_range< updates_iterator > updates_range
llvm::iterator_range< used_expressions_iterator > used_expressions_range
Expr * Cond
};
MutableArrayRef< Expr * >::iterator updates_iterator
SourceLocation getStepModifierLoc() const
Returns the location of 'step' modifier.
OpenMPLastprivateModifier
OpenMP 'lastprivate' clause modifier.
OpenMPDependClauseKind
OpenMP attributes for 'depend' clause.
Definition OpenMPKinds.h:55
Expr * getStep()
Returns linear step.
ArrayRef< const Expr * >::iterator updates_const_iterator
child_range used_children()
llvm::iterator_range< privates_iterator > privates_range
OpenMPSeverityClauseKind
OpenMP attributes for 'severity' clause.
@ OMPC_SEVERITY_unknown
void setPrivates(ArrayRef< Expr * > PL)
Sets the list of the copies of original linear variables.
MutableArrayRef< Expr * > getUsedExprs()
Gets the list of used expressions for linear variables.
MutableArrayRef< Expr * >::iterator used_expressions_iterator
void setInits(ArrayRef< Expr * > IL)
Sets the list of the initial values for linear variables.
OpenMPAllocateClauseModifier
OpenMP modifiers for 'allocate' clause.
@ OMPC_ALLOCATE_unknown
inits_range inits()
void setModifierLoc(SourceLocation Loc)
Set modifier location.
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
Definition OpenMPKinds.h:63
void setStepModifierLoc(SourceLocation Loc)
Sets the location of 'step' modifier.
SourceLocation getColonLoc() const
Returns the location of ':'.
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
Definition OpenMPKinds.h:25
MutableArrayRef< Expr * > getUpdates()
Sets the list of update expressions for linear variables.
updates_range updates()
void setFinals(ArrayRef< Expr * > FL)
Sets the list of final update expressions for linear variables.
void setModifier(OpenMPLinearClauseKind Kind)
Set modifier.
SourceLocation getModifierLoc() const
Return modifier location.
finals_range finals()
llvm::iterator_range< used_expressions_const_iterator > used_expressions_const_range
MutableArrayRef< Expr * > getInits()
OpenMPNumThreadsClauseModifier
@ OMPC_NUMTHREADS_unknown
ArrayRef< const Expr * >::iterator privates_const_iterator
OpenMPAtomicDefaultMemOrderClauseKind
OpenMP attributes for 'atomic_default_mem_order' clause.
@ OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown
child_range children()
ArrayRef< const Expr * >::iterator finals_const_iterator
MutableArrayRef< Expr * >::iterator finals_iterator
ArrayRef< const Expr * >::iterator inits_const_iterator
used_expressions_range used_expressions()
Expr * getCalcStep()
Returns expression to calculate linear step.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
OpenMPMapModifierKind
OpenMP modifier kind for 'map' clause.
Definition OpenMPKinds.h:79
@ OMPC_MAP_MODIFIER_unknown
Definition OpenMPKinds.h:80
llvm::omp::Clause OpenMPClauseKind
OpenMP clauses.
Definition OpenMPKinds.h:28
llvm::iterator_range< updates_const_iterator > updates_const_range
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition OpenMPKinds.h:31
@ OMPC_SCHEDULE_unknown
Definition OpenMPKinds.h:35
llvm::iterator_range< finals_iterator > finals_range
OpenMPThreadsetKind
OpenMP modifiers for 'threadset' clause.
@ OMPC_THREADSET_unknown
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition OpenMPKinds.h:71
@ OMPC_MAP_unknown
Definition OpenMPKinds.h:75
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
int const char * function
Definition c++config.h:31
#define true
Definition stdbool.h:25
OpenMPDependClauseKind DepKind
Dependency type (one of in, out, inout).
SourceLocation DepLoc
Dependency type location.
SourceLocation ColonLoc
Colon location.
SourceLocation OmpAllMemoryLoc
Location of 'omp_all_memory'.
ArrayRef< Expr * > Attrs
attr() string-literal expressions. Empty for fr-only or OMP 5.1 flat specs.
Expr * Fr
Foreign-runtime-id expression. Null for attr-only specs.
This structure contains all sizes needed for by an OMPMappableExprListClause.
OMPMappableExprListSizeTy(unsigned NumVars, unsigned NumUniqueDeclarations, unsigned NumComponentLists, unsigned NumComponents)
OMPMappableExprListSizeTy()=default
unsigned NumComponents
Total number of expression components.
unsigned NumUniqueDeclarations
Number of unique base declarations.
unsigned NumVars
Number of expressions listed.
unsigned NumComponentLists
Number of component lists.
llvm::omp::TraitProperty Kind
StringRef RawString
The raw string as we parsed it. This is needed for the isa trait set (which accepts anything) and (la...
llvm::omp::TraitSelector Kind
SmallVector< OMPTraitProperty, 1 > Properties
SmallVector< OMPTraitSelector, 2 > Selectors
llvm::omp::TraitSet Kind
Data for list of allocators.
Expr * AllocatorTraits
Allocator traits.
SourceLocation LParenLoc
Locations of '(' and ')' symbols.
TargetOMPContext(ASTContext &ASTCtx, std::function< void(StringRef)> &&DiagUnknownTrait, const FunctionDecl *CurrentFunctionDecl, ArrayRef< llvm::omp::TraitProperty > ConstructTraits, int DeviceNum)
bool matchesISATrait(StringRef RawString) const override
See llvm::omp::OMPContext::matchesISATrait.
virtual ~TargetOMPContext()=default
const_child_range used_children() const
static bool classof(const OMPClause *T)
OMPNoChildClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build 'ClauseKind' clause.
child_range used_children()
OMPNoChildClause()
Build an empty clause.
const_child_range children() const
SourceLocation StartLoc
Starting location of the clause (the clause keyword).
SourceLocation LParenLoc
Location of '('.
SourceLocation EndLoc
Ending location of the clause.
OMPVarListLocTy(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)