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