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