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