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