clang 20.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 auto Children = const_cast<OMPClause *>(this)->children();
95 return const_child_range(Children.begin(), Children.end());
96 }
97
98 /// Get the iterator range for the expressions used in the clauses. Used
99 /// expressions include only the children that must be evaluated at the
100 /// runtime before entering the construct.
103 auto Children = const_cast<OMPClause *>(this)->children();
104 return const_child_range(Children.begin(), Children.end());
105 }
106
107 static bool classof(const OMPClause *) { return true; }
108};
109
110template <OpenMPClauseKind ClauseKind>
112 /// Build '\p ClauseKind' clause.
113 ///
114 /// \param StartLoc Starting location of the clause.
115 /// \param EndLoc Ending location of the clause.
117 : OMPClause(ClauseKind, StartLoc, EndLoc) {}
118
119 /// Build an empty clause.
121 : OMPClause(ClauseKind, SourceLocation(), SourceLocation()) {}
122
125 }
126
129 }
130
133 }
136 }
137
138 static bool classof(const OMPClause *T) {
139 return T->getClauseKind() == ClauseKind;
140 }
141};
142
143template <OpenMPClauseKind ClauseKind, class Base>
144class OMPOneStmtClause : public Base {
145
146 /// Location of '('.
147 SourceLocation LParenLoc;
148
149 /// Sub-expression.
150 Stmt *S = nullptr;
151
152protected:
153 void setStmt(Stmt *S) { this->S = S; }
154
155public:
157 SourceLocation EndLoc)
158 : Base(ClauseKind, StartLoc, EndLoc), LParenLoc(LParenLoc), S(S) {}
159
161
162 /// Return the associated statement, potentially casted to \p T.
163 template <typename T> T *getStmtAs() const { return cast_or_null<T>(S); }
164
165 /// Sets the location of '('.
166 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
167
168 /// Returns the location of '('.
169 SourceLocation getLParenLoc() const { return LParenLoc; }
170
173 using child_range = llvm::iterator_range<child_iterator>;
174 using const_child_range = llvm::iterator_range<const_child_iterator>;
175
176 child_range children() { return child_range(&S, &S + 1); }
177
178 const_child_range children() const { return const_child_range(&S, &S + 1); }
179
180 // TODO: Consider making the getAddrOfExprAsWritten version the default.
183 }
186 }
187
188 static bool classof(const OMPClause *T) {
189 return T->getClauseKind() == ClauseKind;
190 }
191};
192
193/// Class that handles pre-initialization statement for some clauses, like
194/// 'schedule', 'firstprivate' etc.
196 friend class OMPClauseReader;
197
198 /// Pre-initialization statement for the clause.
199 Stmt *PreInit = nullptr;
200
201 /// Region that captures the associated stmt.
202 OpenMPDirectiveKind CaptureRegion = llvm::omp::OMPD_unknown;
203
204protected:
206 assert(get(This) && "get is not tuned for pre-init.");
207 }
208
209 /// Set pre-initialization statement for the clause.
210 void
212 OpenMPDirectiveKind ThisRegion = llvm::omp::OMPD_unknown) {
213 PreInit = S;
214 CaptureRegion = ThisRegion;
215 }
216
217public:
218 /// Get pre-initialization statement for the clause.
219 const Stmt *getPreInitStmt() const { return PreInit; }
220
221 /// Get pre-initialization statement for the clause.
222 Stmt *getPreInitStmt() { return PreInit; }
223
224 /// Get capture region for the stmt in the clause.
225 OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
226
228 static const OMPClauseWithPreInit *get(const OMPClause *C);
229};
230
231/// Class that handles post-update expression for some clauses, like
232/// 'lastprivate', 'reduction' etc.
234 friend class OMPClauseReader;
235
236 /// Post-update expression for the clause.
237 Expr *PostUpdate = nullptr;
238
239protected:
241 assert(get(This) && "get is not tuned for post-update.");
242 }
243
244 /// Set pre-initialization statement for the clause.
245 void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
246
247public:
248 /// Get post-update expression for the clause.
249 const Expr *getPostUpdateExpr() const { return PostUpdate; }
250
251 /// Get post-update expression for the clause.
252 Expr *getPostUpdateExpr() { return PostUpdate; }
253
255 static const OMPClauseWithPostUpdate *get(const OMPClause *C);
256};
257
258/// This structure contains most locations needed for by an OMPVarListClause.
260 /// Starting location of the clause (the clause keyword).
262 /// Location of '('.
264 /// Ending location of the clause.
266 OMPVarListLocTy() = default;
270};
271
272/// This represents clauses with the list of variables like 'private',
273/// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
274/// '#pragma omp ...' directives.
275template <class T> class OMPVarListClause : public OMPClause {
276 friend class OMPClauseReader;
277
278 /// Location of '('.
279 SourceLocation LParenLoc;
280
281 /// Number of variables in the list.
282 unsigned NumVars;
283
284protected:
285 /// Build a clause with \a N variables
286 ///
287 /// \param K Kind of the clause.
288 /// \param StartLoc Starting location of the clause (the clause keyword).
289 /// \param LParenLoc Location of '('.
290 /// \param EndLoc Ending location of the clause.
291 /// \param N Number of the variables in the clause.
293 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
294 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
295
296 /// Fetches list of variables associated with this clause.
299 static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
300 }
301
302 /// Sets the list of variables for this clause.
304 assert(VL.size() == NumVars &&
305 "Number of variables is not the same as the preallocated buffer");
306 std::copy(VL.begin(), VL.end(),
307 static_cast<T *>(this)->template getTrailingObjects<Expr *>());
308 }
309
310public:
313 using varlist_range = llvm::iterator_range<varlist_iterator>;
314 using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
315
316 unsigned varlist_size() const { return NumVars; }
317 bool varlist_empty() const { return NumVars == 0; }
318
321 }
324 }
325
328 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
330
331 /// Sets the location of '('.
332 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
333
334 /// Returns the location of '('.
335 SourceLocation getLParenLoc() const { return LParenLoc; }
336
337 /// Fetches list of all variables in the clause.
339 return llvm::ArrayRef(
340 static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
341 NumVars);
342 }
343};
344
345/// Class that represents a list of directive kinds (parallel, target, etc.)
346/// as used in \c absent, \c contains clauses.
347template <class T> class OMPDirectiveListClause : public OMPClause {
348 /// Location of '('.
349 SourceLocation LParenLoc;
350
351protected:
352 /// Number of directive kinds listed in the clause
353 unsigned NumKinds;
354
355public:
356 /// Build a clause with \a NumKinds directive kinds.
357 ///
358 /// \param K The clause kind.
359 /// \param StartLoc Starting location of the clause (the clause keyword).
360 /// \param LParenLoc Location of '('.
361 /// \param EndLoc Ending location of the clause.
362 /// \param NumKinds Number of directive kinds listed in the clause.
364 SourceLocation LParenLoc, SourceLocation EndLoc,
365 unsigned NumKinds)
366 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc),
368
371 }
372
375 }
376
379 }
382 }
383
386 static_cast<T *>(this)
387 ->template getTrailingObjects<OpenMPDirectiveKind>(),
388 NumKinds);
389 }
390
392 assert(
393 DK.size() == NumKinds &&
394 "Number of directive kinds is not the same as the preallocated buffer");
395 std::copy(DK.begin(), DK.end(),
396 static_cast<T *>(this)
397 ->template getTrailingObjects<OpenMPDirectiveKind>());
398 }
399
400 SourceLocation getLParenLoc() { return LParenLoc; }
401
402 void setLParenLoc(SourceLocation S) { LParenLoc = S; }
403};
404
405/// This represents 'allocator' clause in the '#pragma omp ...'
406/// directive.
407///
408/// \code
409/// #pragma omp allocate(a) allocator(omp_default_mem_alloc)
410/// \endcode
411/// In this example directive '#pragma omp allocate' has simple 'allocator'
412/// clause with the allocator 'omp_default_mem_alloc'.
414 : public OMPOneStmtClause<llvm::omp::OMPC_allocator, OMPClause> {
415 friend class OMPClauseReader;
416
417 /// Set allocator.
418 void setAllocator(Expr *A) { setStmt(A); }
419
420public:
421 /// Build 'allocator' clause with the given allocator.
422 ///
423 /// \param A Allocator.
424 /// \param StartLoc Starting location of the clause.
425 /// \param LParenLoc Location of '('.
426 /// \param EndLoc Ending location of the clause.
428 SourceLocation EndLoc)
429 : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {}
430
431 /// Build an empty clause.
433
434 /// Returns allocator.
435 Expr *getAllocator() const { return getStmtAs<Expr>(); }
436};
437
438/// This represents the 'align' clause in the '#pragma omp allocate'
439/// directive.
440///
441/// \code
442/// #pragma omp allocate(a) allocator(omp_default_mem_alloc) align(8)
443/// \endcode
444/// In this example directive '#pragma omp allocate' has simple 'allocator'
445/// clause with the allocator 'omp_default_mem_alloc' and align clause with
446/// value of 8.
447class OMPAlignClause final
448 : public OMPOneStmtClause<llvm::omp::OMPC_align, OMPClause> {
449 friend class OMPClauseReader;
450
451 /// Set alignment value.
452 void setAlignment(Expr *A) { setStmt(A); }
453
454 /// Build 'align' clause with the given alignment
455 ///
456 /// \param A Alignment value.
457 /// \param StartLoc Starting location of the clause.
458 /// \param LParenLoc Location of '('.
459 /// \param EndLoc Ending location of the clause.
460 OMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc,
461 SourceLocation EndLoc)
462 : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {}
463
464 /// Build an empty clause.
465 OMPAlignClause() : OMPOneStmtClause() {}
466
467public:
468 /// Build 'align' clause with the given alignment
469 ///
470 /// \param A Alignment value.
471 /// \param StartLoc Starting location of the clause.
472 /// \param LParenLoc Location of '('.
473 /// \param EndLoc Ending location of the clause.
474 static OMPAlignClause *Create(const ASTContext &C, Expr *A,
475 SourceLocation StartLoc,
476 SourceLocation LParenLoc,
477 SourceLocation EndLoc);
478
479 /// Returns alignment
480 Expr *getAlignment() const { return getStmtAs<Expr>(); }
481};
482
483/// This represents clause 'allocate' in the '#pragma omp ...' directives.
484///
485/// \code
486/// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
487/// \endcode
488/// In this example directive '#pragma omp parallel' has clause 'private'
489/// and clause 'allocate' for the variable 'a'.
491 : public OMPVarListClause<OMPAllocateClause>,
492 private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
493 friend class OMPClauseReader;
494 friend OMPVarListClause;
495 friend TrailingObjects;
496
497 /// Allocator specified in the clause, or 'nullptr' if the default one is
498 /// used.
499 Expr *Allocator = nullptr;
500 /// Position of the ':' delimiter in the clause;
501 SourceLocation ColonLoc;
502
503 /// Build clause with number of variables \a N.
504 ///
505 /// \param StartLoc Starting location of the clause.
506 /// \param LParenLoc Location of '('.
507 /// \param Allocator Allocator expression.
508 /// \param ColonLoc Location of ':' delimiter.
509 /// \param EndLoc Ending location of the clause.
510 /// \param N Number of the variables in the clause.
512 Expr *Allocator, SourceLocation ColonLoc,
513 SourceLocation EndLoc, unsigned N)
514 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate, StartLoc,
515 LParenLoc, EndLoc, N),
516 Allocator(Allocator), ColonLoc(ColonLoc) {}
517
518 /// Build an empty clause.
519 ///
520 /// \param N Number of variables.
521 explicit OMPAllocateClause(unsigned N)
522 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate,
524 SourceLocation(), N) {}
525
526 /// Sets location of ':' symbol in clause.
527 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
528
529 void setAllocator(Expr *A) { Allocator = A; }
530
531public:
532 /// Creates clause with a list of variables \a VL.
533 ///
534 /// \param C AST context.
535 /// \param StartLoc Starting location of the clause.
536 /// \param LParenLoc Location of '('.
537 /// \param Allocator Allocator expression.
538 /// \param ColonLoc Location of ':' delimiter.
539 /// \param EndLoc Ending location of the clause.
540 /// \param VL List of references to the variables.
541 static OMPAllocateClause *Create(const ASTContext &C, SourceLocation StartLoc,
542 SourceLocation LParenLoc, Expr *Allocator,
543 SourceLocation ColonLoc,
544 SourceLocation EndLoc, ArrayRef<Expr *> VL);
545
546 /// Returns the allocator expression or nullptr, if no allocator is specified.
547 Expr *getAllocator() const { return Allocator; }
548
549 /// Returns the location of the ':' delimiter.
550 SourceLocation getColonLoc() const { return ColonLoc; }
551
552 /// Creates an empty clause with the place for \a N variables.
553 ///
554 /// \param C AST context.
555 /// \param N The number of variables.
556 static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
557
559 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
560 reinterpret_cast<Stmt **>(varlist_end()));
561 }
562
564 auto Children = const_cast<OMPAllocateClause *>(this)->children();
565 return const_child_range(Children.begin(), Children.end());
566 }
567
570 }
573 }
574
575 static bool classof(const OMPClause *T) {
576 return T->getClauseKind() == llvm::omp::OMPC_allocate;
577 }
578};
579
580/// This represents 'if' clause in the '#pragma omp ...' directive.
581///
582/// \code
583/// #pragma omp parallel if(parallel:a > 5)
584/// \endcode
585/// In this example directive '#pragma omp parallel' has simple 'if' clause with
586/// condition 'a > 5' and directive name modifier 'parallel'.
588 friend class OMPClauseReader;
589
590 /// Location of '('.
591 SourceLocation LParenLoc;
592
593 /// Condition of the 'if' clause.
594 Stmt *Condition = nullptr;
595
596 /// Location of ':' (if any).
597 SourceLocation ColonLoc;
598
599 /// Directive name modifier for the clause.
600 OpenMPDirectiveKind NameModifier = llvm::omp::OMPD_unknown;
601
602 /// Name modifier location.
603 SourceLocation NameModifierLoc;
604
605 /// Set condition.
606 void setCondition(Expr *Cond) { Condition = Cond; }
607
608 /// Set directive name modifier for the clause.
609 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
610
611 /// Set location of directive name modifier for the clause.
612 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
613
614 /// Set location of ':'.
615 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
616
617public:
618 /// Build 'if' clause with condition \a Cond.
619 ///
620 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
621 /// \param Cond Condition of the clause.
622 /// \param HelperCond Helper condition for the clause.
623 /// \param CaptureRegion Innermost OpenMP region where expressions in this
624 /// clause must be captured.
625 /// \param StartLoc Starting location of the clause.
626 /// \param LParenLoc Location of '('.
627 /// \param NameModifierLoc Location of directive name modifier.
628 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
629 /// \param EndLoc Ending location of the clause.
630 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
631 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
632 SourceLocation LParenLoc, SourceLocation NameModifierLoc,
633 SourceLocation ColonLoc, SourceLocation EndLoc)
634 : OMPClause(llvm::omp::OMPC_if, StartLoc, EndLoc),
635 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond),
636 ColonLoc(ColonLoc), NameModifier(NameModifier),
637 NameModifierLoc(NameModifierLoc) {
638 setPreInitStmt(HelperCond, CaptureRegion);
639 }
640
641 /// Build an empty clause.
643 : OMPClause(llvm::omp::OMPC_if, SourceLocation(), SourceLocation()),
644 OMPClauseWithPreInit(this) {}
645
646 /// Sets the location of '('.
647 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
648
649 /// Returns the location of '('.
650 SourceLocation getLParenLoc() const { return LParenLoc; }
651
652 /// Return the location of ':'.
653 SourceLocation getColonLoc() const { return ColonLoc; }
654
655 /// Returns condition.
656 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
657
658 /// Return directive name modifier associated with the clause.
659 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
660
661 /// Return the location of directive name modifier.
662 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
663
665
668 }
669
672 auto Children = const_cast<OMPIfClause *>(this)->used_children();
673 return const_child_range(Children.begin(), Children.end());
674 }
675
676 static bool classof(const OMPClause *T) {
677 return T->getClauseKind() == llvm::omp::OMPC_if;
678 }
679};
680
681/// This represents 'final' clause in the '#pragma omp ...' directive.
682///
683/// \code
684/// #pragma omp task final(a > 5)
685/// \endcode
686/// In this example directive '#pragma omp task' has simple 'final'
687/// clause with condition 'a > 5'.
688class OMPFinalClause final
689 : public OMPOneStmtClause<llvm::omp::OMPC_final, OMPClause>,
690 public OMPClauseWithPreInit {
691 friend class OMPClauseReader;
692
693 /// Set condition.
694 void setCondition(Expr *Cond) { setStmt(Cond); }
695
696public:
697 /// Build 'final' clause with condition \a Cond.
698 ///
699 /// \param Cond Condition of the clause.
700 /// \param HelperCond Helper condition for the construct.
701 /// \param CaptureRegion Innermost OpenMP region where expressions in this
702 /// clause must be captured.
703 /// \param StartLoc Starting location of the clause.
704 /// \param LParenLoc Location of '('.
705 /// \param EndLoc Ending location of the clause.
706 OMPFinalClause(Expr *Cond, Stmt *HelperCond,
707 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
708 SourceLocation LParenLoc, SourceLocation EndLoc)
709 : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc),
711 setPreInitStmt(HelperCond, CaptureRegion);
712 }
713
714 /// Build an empty clause.
716
717 /// Returns condition.
718 Expr *getCondition() const { return getStmtAs<Expr>(); }
719
722 auto Children = const_cast<OMPFinalClause *>(this)->used_children();
723 return const_child_range(Children.begin(), Children.end());
724 }
725};
726/// This represents 'num_threads' clause in the '#pragma omp ...'
727/// directive.
728///
729/// \code
730/// #pragma omp parallel num_threads(6)
731/// \endcode
732/// In this example directive '#pragma omp parallel' has simple 'num_threads'
733/// clause with number of threads '6'.
735 : public OMPOneStmtClause<llvm::omp::OMPC_num_threads, OMPClause>,
736 public OMPClauseWithPreInit {
737 friend class OMPClauseReader;
738
739 /// Set condition.
740 void setNumThreads(Expr *NThreads) { setStmt(NThreads); }
741
742public:
743 /// Build 'num_threads' clause with condition \a NumThreads.
744 ///
745 /// \param NumThreads Number of threads for the construct.
746 /// \param HelperNumThreads Helper Number of threads for the construct.
747 /// \param CaptureRegion Innermost OpenMP region where expressions in this
748 /// clause must be captured.
749 /// \param StartLoc Starting location of the clause.
750 /// \param LParenLoc Location of '('.
751 /// \param EndLoc Ending location of the clause.
752 OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
753 OpenMPDirectiveKind CaptureRegion,
754 SourceLocation StartLoc, SourceLocation LParenLoc,
755 SourceLocation EndLoc)
756 : OMPOneStmtClause(NumThreads, StartLoc, LParenLoc, EndLoc),
758 setPreInitStmt(HelperNumThreads, CaptureRegion);
759 }
760
761 /// Build an empty clause.
763
764 /// Returns number of threads.
765 Expr *getNumThreads() const { return getStmtAs<Expr>(); }
766};
767
768/// This represents 'safelen' clause in the '#pragma omp ...'
769/// directive.
770///
771/// \code
772/// #pragma omp simd safelen(4)
773/// \endcode
774/// In this example directive '#pragma omp simd' has clause 'safelen'
775/// with single expression '4'.
776/// If the safelen clause is used then no two iterations executed
777/// concurrently with SIMD instructions can have a greater distance
778/// in the logical iteration space than its value. The parameter of
779/// the safelen clause must be a constant positive integer expression.
781 : public OMPOneStmtClause<llvm::omp::OMPC_safelen, OMPClause> {
782 friend class OMPClauseReader;
783
784 /// Set safelen.
785 void setSafelen(Expr *Len) { setStmt(Len); }
786
787public:
788 /// Build 'safelen' clause.
789 ///
790 /// \param Len Expression associated with this clause.
791 /// \param StartLoc Starting location of the clause.
792 /// \param EndLoc Ending location of the clause.
794 SourceLocation EndLoc)
795 : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {}
796
797 /// Build an empty clause.
799
800 /// Return safe iteration space distance.
801 Expr *getSafelen() const { return getStmtAs<Expr>(); }
802};
803
804/// This represents 'simdlen' clause in the '#pragma omp ...'
805/// directive.
806///
807/// \code
808/// #pragma omp simd simdlen(4)
809/// \endcode
810/// In this example directive '#pragma omp simd' has clause 'simdlen'
811/// with single expression '4'.
812/// If the 'simdlen' clause is used then it specifies the preferred number of
813/// iterations to be executed concurrently. The parameter of the 'simdlen'
814/// clause must be a constant positive integer expression.
816 : public OMPOneStmtClause<llvm::omp::OMPC_simdlen, OMPClause> {
817 friend class OMPClauseReader;
818
819 /// Set simdlen.
820 void setSimdlen(Expr *Len) { setStmt(Len); }
821
822public:
823 /// Build 'simdlen' clause.
824 ///
825 /// \param Len Expression associated with this clause.
826 /// \param StartLoc Starting location of the clause.
827 /// \param EndLoc Ending location of the clause.
829 SourceLocation EndLoc)
830 : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {}
831
832 /// Build an empty clause.
834
835 /// Return safe iteration space distance.
836 Expr *getSimdlen() const { return getStmtAs<Expr>(); }
837};
838
839/// This represents the 'sizes' clause in the '#pragma omp tile' directive.
840///
841/// \code
842/// #pragma omp tile sizes(5,5)
843/// for (int i = 0; i < 64; ++i)
844/// for (int j = 0; j < 64; ++j)
845/// \endcode
846class OMPSizesClause final
847 : public OMPClause,
848 private llvm::TrailingObjects<OMPSizesClause, Expr *> {
849 friend class OMPClauseReader;
850 friend class llvm::TrailingObjects<OMPSizesClause, Expr *>;
851
852 /// Location of '('.
853 SourceLocation LParenLoc;
854
855 /// Number of tile sizes in the clause.
856 unsigned NumSizes;
857
858 /// Build an empty clause.
859 explicit OMPSizesClause(int NumSizes)
860 : OMPClause(llvm::omp::OMPC_sizes, SourceLocation(), SourceLocation()),
861 NumSizes(NumSizes) {}
862
863public:
864 /// Build a 'sizes' AST node.
865 ///
866 /// \param C Context of the AST.
867 /// \param StartLoc Location of the 'sizes' identifier.
868 /// \param LParenLoc Location of '('.
869 /// \param EndLoc Location of ')'.
870 /// \param Sizes Content of the clause.
871 static OMPSizesClause *Create(const ASTContext &C, SourceLocation StartLoc,
872 SourceLocation LParenLoc, SourceLocation EndLoc,
873 ArrayRef<Expr *> Sizes);
874
875 /// Build an empty 'sizes' AST node for deserialization.
876 ///
877 /// \param C Context of the AST.
878 /// \param NumSizes Number of items in the clause.
879 static OMPSizesClause *CreateEmpty(const ASTContext &C, unsigned NumSizes);
880
881 /// Sets the location of '('.
882 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
883
884 /// Returns the location of '('.
885 SourceLocation getLParenLoc() const { return LParenLoc; }
886
887 /// Returns the number of list items.
888 unsigned getNumSizes() const { return NumSizes; }
889
890 /// Returns the tile size expressions.
892 return MutableArrayRef<Expr *>(static_cast<OMPSizesClause *>(this)
893 ->template getTrailingObjects<Expr *>(),
894 NumSizes);
895 }
897 return ArrayRef<Expr *>(static_cast<const OMPSizesClause *>(this)
898 ->template getTrailingObjects<Expr *>(),
899 NumSizes);
900 }
901
902 /// Sets the tile size expressions.
904 assert(VL.size() == NumSizes);
905 std::copy(VL.begin(), VL.end(),
906 static_cast<OMPSizesClause *>(this)
907 ->template getTrailingObjects<Expr *>());
908 }
909
912 return child_range(reinterpret_cast<Stmt **>(Sizes.begin()),
913 reinterpret_cast<Stmt **>(Sizes.end()));
914 }
917 return const_child_range(reinterpret_cast<Stmt *const *>(Sizes.begin()),
918 reinterpret_cast<Stmt *const *>(Sizes.end()));
919 }
920
923 }
926 }
927
928 static bool classof(const OMPClause *T) {
929 return T->getClauseKind() == llvm::omp::OMPC_sizes;
930 }
931};
932
933/// Representation of the 'full' clause of the '#pragma omp unroll' directive.
934///
935/// \code
936/// #pragma omp unroll full
937/// for (int i = 0; i < 64; ++i)
938/// \endcode
939class OMPFullClause final : public OMPNoChildClause<llvm::omp::OMPC_full> {
940 friend class OMPClauseReader;
941
942 /// Build an empty clause.
943 explicit OMPFullClause() : OMPNoChildClause() {}
944
945public:
946 /// Build an AST node for a 'full' clause.
947 ///
948 /// \param C Context of the AST.
949 /// \param StartLoc Starting location of the clause.
950 /// \param EndLoc Ending location of the clause.
951 static OMPFullClause *Create(const ASTContext &C, SourceLocation StartLoc,
952 SourceLocation EndLoc);
953
954 /// Build an empty 'full' AST node for deserialization.
955 ///
956 /// \param C Context of the AST.
957 static OMPFullClause *CreateEmpty(const ASTContext &C);
958};
959
960/// Representation of the 'partial' clause of the '#pragma omp unroll'
961/// directive.
962///
963/// \code
964/// #pragma omp unroll partial(4)
965/// for (int i = start; i < end; ++i)
966/// \endcode
967class OMPPartialClause final : public OMPClause {
968 friend class OMPClauseReader;
969
970 /// Location of '('.
971 SourceLocation LParenLoc;
972
973 /// Optional argument to the clause (unroll factor).
974 Stmt *Factor;
975
976 /// Build an empty clause.
977 explicit OMPPartialClause() : OMPClause(llvm::omp::OMPC_partial, {}, {}) {}
978
979 /// Set the unroll factor.
980 void setFactor(Expr *E) { Factor = E; }
981
982 /// Sets the location of '('.
983 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
984
985public:
986 /// Build an AST node for a 'partial' clause.
987 ///
988 /// \param C Context of the AST.
989 /// \param StartLoc Location of the 'partial' identifier.
990 /// \param LParenLoc Location of '('.
991 /// \param EndLoc Location of ')'.
992 /// \param Factor Clause argument.
993 static OMPPartialClause *Create(const ASTContext &C, SourceLocation StartLoc,
994 SourceLocation LParenLoc,
995 SourceLocation EndLoc, Expr *Factor);
996
997 /// Build an empty 'partial' AST node for deserialization.
998 ///
999 /// \param C Context of the AST.
1000 static OMPPartialClause *CreateEmpty(const ASTContext &C);
1001
1002 /// Returns the location of '('.
1003 SourceLocation getLParenLoc() const { return LParenLoc; }
1004
1005 /// Returns the argument of the clause or nullptr if not set.
1006 Expr *getFactor() const { return cast_or_null<Expr>(Factor); }
1007
1008 child_range children() { return child_range(&Factor, &Factor + 1); }
1010 return const_child_range(&Factor, &Factor + 1);
1011 }
1012
1015 }
1018 }
1019
1020 static bool classof(const OMPClause *T) {
1021 return T->getClauseKind() == llvm::omp::OMPC_partial;
1022 }
1023};
1024
1025/// This represents 'collapse' clause in the '#pragma omp ...'
1026/// directive.
1027///
1028/// \code
1029/// #pragma omp simd collapse(3)
1030/// \endcode
1031/// In this example directive '#pragma omp simd' has clause 'collapse'
1032/// with single expression '3'.
1033/// The parameter must be a constant positive integer expression, it specifies
1034/// the number of nested loops that should be collapsed into a single iteration
1035/// space.
1037 : public OMPOneStmtClause<llvm::omp::OMPC_collapse, OMPClause> {
1038 friend class OMPClauseReader;
1039
1040 /// Set the number of associated for-loops.
1041 void setNumForLoops(Expr *Num) { setStmt(Num); }
1042
1043public:
1044 /// Build 'collapse' clause.
1045 ///
1046 /// \param Num Expression associated with this clause.
1047 /// \param StartLoc Starting location of the clause.
1048 /// \param LParenLoc Location of '('.
1049 /// \param EndLoc Ending location of the clause.
1051 SourceLocation LParenLoc, SourceLocation EndLoc)
1052 : OMPOneStmtClause(Num, StartLoc, LParenLoc, EndLoc) {}
1053
1054 /// Build an empty clause.
1056
1057 /// Return the number of associated for-loops.
1058 Expr *getNumForLoops() const { return getStmtAs<Expr>(); }
1059};
1060
1061/// This represents 'default' clause in the '#pragma omp ...' directive.
1062///
1063/// \code
1064/// #pragma omp parallel default(shared)
1065/// \endcode
1066/// In this example directive '#pragma omp parallel' has simple 'default'
1067/// clause with kind 'shared'.
1069 friend class OMPClauseReader;
1070
1071 /// Location of '('.
1072 SourceLocation LParenLoc;
1073
1074 /// A kind of the 'default' clause.
1075 llvm::omp::DefaultKind Kind = llvm::omp::OMP_DEFAULT_unknown;
1076
1077 /// Start location of the kind in source code.
1078 SourceLocation KindKwLoc;
1079
1080 /// Set kind of the clauses.
1081 ///
1082 /// \param K Argument of clause.
1083 void setDefaultKind(llvm::omp::DefaultKind K) { Kind = K; }
1084
1085 /// Set argument location.
1086 ///
1087 /// \param KLoc Argument location.
1088 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1089
1090public:
1091 /// Build 'default' clause with argument \a A ('none' or 'shared').
1092 ///
1093 /// \param A Argument of the clause ('none' or 'shared').
1094 /// \param ALoc Starting location of the argument.
1095 /// \param StartLoc Starting location of the clause.
1096 /// \param LParenLoc Location of '('.
1097 /// \param EndLoc Ending location of the clause.
1098 OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc,
1099 SourceLocation StartLoc, SourceLocation LParenLoc,
1100 SourceLocation EndLoc)
1101 : OMPClause(llvm::omp::OMPC_default, StartLoc, EndLoc),
1102 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1103
1104 /// Build an empty clause.
1106 : OMPClause(llvm::omp::OMPC_default, SourceLocation(), SourceLocation()) {
1107 }
1108
1109 /// Sets the location of '('.
1110 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1111
1112 /// Returns the location of '('.
1113 SourceLocation getLParenLoc() const { return LParenLoc; }
1114
1115 /// Returns kind of the clause.
1116 llvm::omp::DefaultKind getDefaultKind() const { return Kind; }
1117
1118 /// Returns location of clause kind.
1119 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
1120
1123 }
1124
1127 }
1128
1131 }
1134 }
1135
1136 static bool classof(const OMPClause *T) {
1137 return T->getClauseKind() == llvm::omp::OMPC_default;
1138 }
1139};
1140
1141/// This represents 'proc_bind' clause in the '#pragma omp ...'
1142/// directive.
1143///
1144/// \code
1145/// #pragma omp parallel proc_bind(master)
1146/// \endcode
1147/// In this example directive '#pragma omp parallel' has simple 'proc_bind'
1148/// clause with kind 'master'.
1150 friend class OMPClauseReader;
1151
1152 /// Location of '('.
1153 SourceLocation LParenLoc;
1154
1155 /// A kind of the 'proc_bind' clause.
1156 llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown;
1157
1158 /// Start location of the kind in source code.
1159 SourceLocation KindKwLoc;
1160
1161 /// Set kind of the clause.
1162 ///
1163 /// \param K Kind of clause.
1164 void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; }
1165
1166 /// Set clause kind location.
1167 ///
1168 /// \param KLoc Kind location.
1169 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1170
1171public:
1172 /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
1173 /// 'spread').
1174 ///
1175 /// \param A Argument of the clause ('master', 'close' or 'spread').
1176 /// \param ALoc Starting location of the argument.
1177 /// \param StartLoc Starting location of the clause.
1178 /// \param LParenLoc Location of '('.
1179 /// \param EndLoc Ending location of the clause.
1180 OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc,
1181 SourceLocation StartLoc, SourceLocation LParenLoc,
1182 SourceLocation EndLoc)
1183 : OMPClause(llvm::omp::OMPC_proc_bind, StartLoc, EndLoc),
1184 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1185
1186 /// Build an empty clause.
1188 : OMPClause(llvm::omp::OMPC_proc_bind, SourceLocation(),
1189 SourceLocation()) {}
1190
1191 /// Sets the location of '('.
1192 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1193
1194 /// Returns the location of '('.
1195 SourceLocation getLParenLoc() const { return LParenLoc; }
1196
1197 /// Returns kind of the clause.
1198 llvm::omp::ProcBindKind getProcBindKind() const { return Kind; }
1199
1200 /// Returns location of clause kind.
1201 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
1202
1205 }
1206
1209 }
1210
1213 }
1216 }
1217
1218 static bool classof(const OMPClause *T) {
1219 return T->getClauseKind() == llvm::omp::OMPC_proc_bind;
1220 }
1221};
1222
1223/// This represents 'unified_address' clause in the '#pragma omp requires'
1224/// directive.
1225///
1226/// \code
1227/// #pragma omp requires unified_address
1228/// \endcode
1229/// In this example directive '#pragma omp requires' has 'unified_address'
1230/// clause.
1232 : public OMPNoChildClause<llvm::omp::OMPC_unified_address> {
1233public:
1234 friend class OMPClauseReader;
1235 /// Build 'unified_address' clause.
1236 ///
1237 /// \param StartLoc Starting location of the clause.
1238 /// \param EndLoc Ending location of the clause.
1240 : OMPNoChildClause(StartLoc, EndLoc) {}
1241
1242 /// Build an empty clause.
1244};
1245
1246/// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
1247/// directive.
1248///
1249/// \code
1250/// #pragma omp requires unified_shared_memory
1251/// \endcode
1252/// In this example directive '#pragma omp requires' has 'unified_shared_memory'
1253/// clause.
1255public:
1256 friend class OMPClauseReader;
1257 /// Build 'unified_shared_memory' clause.
1258 ///
1259 /// \param StartLoc Starting location of the clause.
1260 /// \param EndLoc Ending location of the clause.
1262 : OMPClause(llvm::omp::OMPC_unified_shared_memory, StartLoc, EndLoc) {}
1263
1264 /// Build an empty clause.
1266 : OMPClause(llvm::omp::OMPC_unified_shared_memory, SourceLocation(),
1267 SourceLocation()) {}
1268
1271 }
1272
1275 }
1276
1279 }
1282 }
1283
1284 static bool classof(const OMPClause *T) {
1285 return T->getClauseKind() == llvm::omp::OMPC_unified_shared_memory;
1286 }
1287};
1288
1289/// This represents 'reverse_offload' clause in the '#pragma omp requires'
1290/// directive.
1291///
1292/// \code
1293/// #pragma omp requires reverse_offload
1294/// \endcode
1295/// In this example directive '#pragma omp requires' has 'reverse_offload'
1296/// clause.
1298public:
1299 friend class OMPClauseReader;
1300 /// Build 'reverse_offload' clause.
1301 ///
1302 /// \param StartLoc Starting location of the clause.
1303 /// \param EndLoc Ending location of the clause.
1305 : OMPClause(llvm::omp::OMPC_reverse_offload, StartLoc, EndLoc) {}
1306
1307 /// Build an empty clause.
1309 : OMPClause(llvm::omp::OMPC_reverse_offload, SourceLocation(),
1310 SourceLocation()) {}
1311
1314 }
1315
1318 }
1319
1322 }
1325 }
1326
1327 static bool classof(const OMPClause *T) {
1328 return T->getClauseKind() == llvm::omp::OMPC_reverse_offload;
1329 }
1330};
1331
1332/// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
1333/// directive.
1334///
1335/// \code
1336/// #pragma omp requires dynamic_allocators
1337/// \endcode
1338/// In this example directive '#pragma omp requires' has 'dynamic_allocators'
1339/// clause.
1341public:
1342 friend class OMPClauseReader;
1343 /// Build 'dynamic_allocators' clause.
1344 ///
1345 /// \param StartLoc Starting location of the clause.
1346 /// \param EndLoc Ending location of the clause.
1348 : OMPClause(llvm::omp::OMPC_dynamic_allocators, StartLoc, EndLoc) {}
1349
1350 /// Build an empty clause.
1352 : OMPClause(llvm::omp::OMPC_dynamic_allocators, SourceLocation(),
1353 SourceLocation()) {}
1354
1357 }
1358
1361 }
1362
1365 }
1368 }
1369
1370 static bool classof(const OMPClause *T) {
1371 return T->getClauseKind() == llvm::omp::OMPC_dynamic_allocators;
1372 }
1373};
1374
1375/// This represents 'atomic_default_mem_order' clause in the '#pragma omp
1376/// requires' directive.
1377///
1378/// \code
1379/// #pragma omp requires atomic_default_mem_order(seq_cst)
1380/// \endcode
1381/// In this example directive '#pragma omp requires' has simple
1382/// atomic_default_mem_order' clause with kind 'seq_cst'.
1384 friend class OMPClauseReader;
1385
1386 /// Location of '('
1387 SourceLocation LParenLoc;
1388
1389 /// A kind of the 'atomic_default_mem_order' clause.
1392
1393 /// Start location of the kind in source code.
1394 SourceLocation KindKwLoc;
1395
1396 /// Set kind of the clause.
1397 ///
1398 /// \param K Kind of clause.
1399 void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
1400 Kind = K;
1401 }
1402
1403 /// Set clause kind location.
1404 ///
1405 /// \param KLoc Kind location.
1406 void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
1407 KindKwLoc = KLoc;
1408 }
1409
1410public:
1411 /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
1412 /// 'acq_rel' or 'relaxed').
1413 ///
1414 /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
1415 /// \param ALoc Starting location of the argument.
1416 /// \param StartLoc Starting location of the clause.
1417 /// \param LParenLoc Location of '('.
1418 /// \param EndLoc Ending location of the clause.
1420 SourceLocation ALoc, SourceLocation StartLoc,
1421 SourceLocation LParenLoc,
1422 SourceLocation EndLoc)
1423 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, StartLoc, EndLoc),
1424 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1425
1426 /// Build an empty clause.
1428 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, SourceLocation(),
1429 SourceLocation()) {}
1430
1431 /// Sets the location of '('.
1432 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1433
1434 /// Returns the locaiton of '('.
1435 SourceLocation getLParenLoc() const { return LParenLoc; }
1436
1437 /// Returns kind of the clause.
1439 return Kind;
1440 }
1441
1442 /// Returns location of clause kind.
1444
1447 }
1448
1451 }
1452
1455 }
1458 }
1459
1460 static bool classof(const OMPClause *T) {
1461 return T->getClauseKind() == llvm::omp::OMPC_atomic_default_mem_order;
1462 }
1463};
1464
1465/// This represents 'at' clause in the '#pragma omp error' directive
1466///
1467/// \code
1468/// #pragma omp error at(compilation)
1469/// \endcode
1470/// In this example directive '#pragma omp error' has simple
1471/// 'at' clause with kind 'complilation'.
1472class OMPAtClause final : public OMPClause {
1473 friend class OMPClauseReader;
1474
1475 /// Location of '('
1476 SourceLocation LParenLoc;
1477
1478 /// A kind of the 'at' clause.
1480
1481 /// Start location of the kind in source code.
1482 SourceLocation KindKwLoc;
1483
1484 /// Set kind of the clause.
1485 ///
1486 /// \param K Kind of clause.
1487 void setAtKind(OpenMPAtClauseKind K) { Kind = K; }
1488
1489 /// Set clause kind location.
1490 ///
1491 /// \param KLoc Kind location.
1492 void setAtKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1493
1494 /// Sets the location of '('.
1495 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1496
1497public:
1498 /// Build 'at' clause with argument \a A ('compilation' or 'execution').
1499 ///
1500 /// \param A Argument of the clause ('compilation' or 'execution').
1501 /// \param ALoc Starting location of the argument.
1502 /// \param StartLoc Starting location of the clause.
1503 /// \param LParenLoc Location of '('.
1504 /// \param EndLoc Ending location of the clause.
1506 SourceLocation StartLoc, SourceLocation LParenLoc,
1507 SourceLocation EndLoc)
1508 : OMPClause(llvm::omp::OMPC_at, StartLoc, EndLoc), LParenLoc(LParenLoc),
1509 Kind(A), KindKwLoc(ALoc) {}
1510
1511 /// Build an empty clause.
1513 : OMPClause(llvm::omp::OMPC_at, SourceLocation(), SourceLocation()) {}
1514
1515 /// Returns the locaiton of '('.
1516 SourceLocation getLParenLoc() const { return LParenLoc; }
1517
1518 /// Returns kind of the clause.
1520
1521 /// Returns location of clause kind.
1522 SourceLocation getAtKindKwLoc() const { return KindKwLoc; }
1523
1526 }
1527
1530 }
1531
1534 }
1537 }
1538
1539 static bool classof(const OMPClause *T) {
1540 return T->getClauseKind() == llvm::omp::OMPC_at;
1541 }
1542};
1543
1544/// This represents 'severity' clause in the '#pragma omp error' directive
1545///
1546/// \code
1547/// #pragma omp error severity(fatal)
1548/// \endcode
1549/// In this example directive '#pragma omp error' has simple
1550/// 'severity' clause with kind 'fatal'.
1551class OMPSeverityClause final : public OMPClause {
1552 friend class OMPClauseReader;
1553
1554 /// Location of '('
1555 SourceLocation LParenLoc;
1556
1557 /// A kind of the 'severity' clause.
1559
1560 /// Start location of the kind in source code.
1561 SourceLocation KindKwLoc;
1562
1563 /// Set kind of the clause.
1564 ///
1565 /// \param K Kind of clause.
1566 void setSeverityKind(OpenMPSeverityClauseKind K) { Kind = K; }
1567
1568 /// Set clause kind location.
1569 ///
1570 /// \param KLoc Kind location.
1571 void setSeverityKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1572
1573 /// Sets the location of '('.
1574 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1575
1576public:
1577 /// Build 'severity' clause with argument \a A ('fatal' or 'warning').
1578 ///
1579 /// \param A Argument of the clause ('fatal' or 'warning').
1580 /// \param ALoc Starting location of the argument.
1581 /// \param StartLoc Starting location of the clause.
1582 /// \param LParenLoc Location of '('.
1583 /// \param EndLoc Ending location of the clause.
1585 SourceLocation StartLoc, SourceLocation LParenLoc,
1586 SourceLocation EndLoc)
1587 : OMPClause(llvm::omp::OMPC_severity, StartLoc, EndLoc),
1588 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1589
1590 /// Build an empty clause.
1592 : OMPClause(llvm::omp::OMPC_severity, SourceLocation(),
1593 SourceLocation()) {}
1594
1595 /// Returns the locaiton of '('.
1596 SourceLocation getLParenLoc() const { return LParenLoc; }
1597
1598 /// Returns kind of the clause.
1600
1601 /// Returns location of clause kind.
1602 SourceLocation getSeverityKindKwLoc() const { return KindKwLoc; }
1603
1606 }
1607
1610 }
1611
1614 }
1617 }
1618
1619 static bool classof(const OMPClause *T) {
1620 return T->getClauseKind() == llvm::omp::OMPC_severity;
1621 }
1622};
1623
1624/// This represents 'message' clause in the '#pragma omp error' directive
1625///
1626/// \code
1627/// #pragma omp error message("GNU compiler required.")
1628/// \endcode
1629/// In this example directive '#pragma omp error' has simple
1630/// 'message' clause with user error message of "GNU compiler required.".
1631class OMPMessageClause final : public OMPClause {
1632 friend class OMPClauseReader;
1633
1634 /// Location of '('
1635 SourceLocation LParenLoc;
1636
1637 // Expression of the 'message' clause.
1638 Stmt *MessageString = nullptr;
1639
1640 /// Set message string of the clause.
1641 void setMessageString(Expr *MS) { MessageString = MS; }
1642
1643 /// Sets the location of '('.
1644 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1645
1646public:
1647 /// Build 'message' clause with message string argument
1648 ///
1649 /// \param MS Argument of the clause (message string).
1650 /// \param StartLoc Starting location of the clause.
1651 /// \param LParenLoc Location of '('.
1652 /// \param EndLoc Ending location of the clause.
1654 SourceLocation EndLoc)
1655 : OMPClause(llvm::omp::OMPC_message, StartLoc, EndLoc),
1656 LParenLoc(LParenLoc), MessageString(MS) {}
1657
1658 /// Build an empty clause.
1660 : OMPClause(llvm::omp::OMPC_message, SourceLocation(), SourceLocation()) {
1661 }
1662
1663 /// Returns the locaiton of '('.
1664 SourceLocation getLParenLoc() const { return LParenLoc; }
1665
1666 /// Returns message string of the clause.
1667 Expr *getMessageString() const { return cast_or_null<Expr>(MessageString); }
1668
1670 return child_range(&MessageString, &MessageString + 1);
1671 }
1672
1674 return const_child_range(&MessageString, &MessageString + 1);
1675 }
1676
1679 }
1680
1683 }
1684
1685 static bool classof(const OMPClause *T) {
1686 return T->getClauseKind() == llvm::omp::OMPC_message;
1687 }
1688};
1689
1690/// This represents 'schedule' clause in the '#pragma omp ...' directive.
1691///
1692/// \code
1693/// #pragma omp for schedule(static, 3)
1694/// \endcode
1695/// In this example directive '#pragma omp for' has 'schedule' clause with
1696/// arguments 'static' and '3'.
1698 friend class OMPClauseReader;
1699
1700 /// Location of '('.
1701 SourceLocation LParenLoc;
1702
1703 /// A kind of the 'schedule' clause.
1705
1706 /// Modifiers for 'schedule' clause.
1707 enum {FIRST, SECOND, NUM_MODIFIERS};
1708 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
1709
1710 /// Locations of modifiers.
1711 SourceLocation ModifiersLoc[NUM_MODIFIERS];
1712
1713 /// Start location of the schedule ind in source code.
1714 SourceLocation KindLoc;
1715
1716 /// Location of ',' (if any).
1717 SourceLocation CommaLoc;
1718
1719 /// Chunk size.
1720 Expr *ChunkSize = nullptr;
1721
1722 /// Set schedule kind.
1723 ///
1724 /// \param K Schedule kind.
1725 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
1726
1727 /// Set the first schedule modifier.
1728 ///
1729 /// \param M Schedule modifier.
1730 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
1731 Modifiers[FIRST] = M;
1732 }
1733
1734 /// Set the second schedule modifier.
1735 ///
1736 /// \param M Schedule modifier.
1737 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
1738 Modifiers[SECOND] = M;
1739 }
1740
1741 /// Set location of the first schedule modifier.
1742 void setFirstScheduleModifierLoc(SourceLocation Loc) {
1743 ModifiersLoc[FIRST] = Loc;
1744 }
1745
1746 /// Set location of the second schedule modifier.
1747 void setSecondScheduleModifierLoc(SourceLocation Loc) {
1748 ModifiersLoc[SECOND] = Loc;
1749 }
1750
1751 /// Set schedule modifier location.
1752 ///
1753 /// \param M Schedule modifier location.
1754 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
1755 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
1756 Modifiers[FIRST] = M;
1757 else {
1758 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
1759 Modifiers[SECOND] = M;
1760 }
1761 }
1762
1763 /// Sets the location of '('.
1764 ///
1765 /// \param Loc Location of '('.
1766 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1767
1768 /// Set schedule kind start location.
1769 ///
1770 /// \param KLoc Schedule kind location.
1771 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1772
1773 /// Set location of ','.
1774 ///
1775 /// \param Loc Location of ','.
1776 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
1777
1778 /// Set chunk size.
1779 ///
1780 /// \param E Chunk size.
1781 void setChunkSize(Expr *E) { ChunkSize = E; }
1782
1783public:
1784 /// Build 'schedule' clause with schedule kind \a Kind and chunk size
1785 /// expression \a ChunkSize.
1786 ///
1787 /// \param StartLoc Starting location of the clause.
1788 /// \param LParenLoc Location of '('.
1789 /// \param KLoc Starting location of the argument.
1790 /// \param CommaLoc Location of ','.
1791 /// \param EndLoc Ending location of the clause.
1792 /// \param Kind Schedule kind.
1793 /// \param ChunkSize Chunk size.
1794 /// \param HelperChunkSize Helper chunk size for combined directives.
1795 /// \param M1 The first modifier applied to 'schedule' clause.
1796 /// \param M1Loc Location of the first modifier
1797 /// \param M2 The second modifier applied to 'schedule' clause.
1798 /// \param M2Loc Location of the second modifier
1800 SourceLocation KLoc, SourceLocation CommaLoc,
1802 Expr *ChunkSize, Stmt *HelperChunkSize,
1805 : OMPClause(llvm::omp::OMPC_schedule, StartLoc, EndLoc),
1806 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
1807 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
1808 setPreInitStmt(HelperChunkSize);
1809 Modifiers[FIRST] = M1;
1810 Modifiers[SECOND] = M2;
1811 ModifiersLoc[FIRST] = M1Loc;
1812 ModifiersLoc[SECOND] = M2Loc;
1813 }
1814
1815 /// Build an empty clause.
1817 : OMPClause(llvm::omp::OMPC_schedule, SourceLocation(), SourceLocation()),
1818 OMPClauseWithPreInit(this) {
1819 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
1820 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
1821 }
1822
1823 /// Get kind of the clause.
1825
1826 /// Get the first modifier of the clause.
1828 return Modifiers[FIRST];
1829 }
1830
1831 /// Get the second modifier of the clause.
1833 return Modifiers[SECOND];
1834 }
1835
1836 /// Get location of '('.
1837 SourceLocation getLParenLoc() { return LParenLoc; }
1838
1839 /// Get kind location.
1841
1842 /// Get the first modifier location.
1844 return ModifiersLoc[FIRST];
1845 }
1846
1847 /// Get the second modifier location.
1849 return ModifiersLoc[SECOND];
1850 }
1851
1852 /// Get location of ','.
1853 SourceLocation getCommaLoc() { return CommaLoc; }
1854
1855 /// Get chunk size.
1856 Expr *getChunkSize() { return ChunkSize; }
1857
1858 /// Get chunk size.
1859 const Expr *getChunkSize() const { return ChunkSize; }
1860
1862 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
1863 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
1864 }
1865
1867 auto Children = const_cast<OMPScheduleClause *>(this)->children();
1868 return const_child_range(Children.begin(), Children.end());
1869 }
1870
1873 }
1876 }
1877
1878 static bool classof(const OMPClause *T) {
1879 return T->getClauseKind() == llvm::omp::OMPC_schedule;
1880 }
1881};
1882
1883/// This represents 'ordered' clause in the '#pragma omp ...' directive.
1884///
1885/// \code
1886/// #pragma omp for ordered (2)
1887/// \endcode
1888/// In this example directive '#pragma omp for' has 'ordered' clause with
1889/// parameter 2.
1891 : public OMPClause,
1892 private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
1893 friend class OMPClauseReader;
1894 friend TrailingObjects;
1895
1896 /// Location of '('.
1897 SourceLocation LParenLoc;
1898
1899 /// Number of for-loops.
1900 Stmt *NumForLoops = nullptr;
1901
1902 /// Real number of loops.
1903 unsigned NumberOfLoops = 0;
1904
1905 /// Build 'ordered' clause.
1906 ///
1907 /// \param Num Expression, possibly associated with this clause.
1908 /// \param NumLoops Number of loops, associated with this clause.
1909 /// \param StartLoc Starting location of the clause.
1910 /// \param LParenLoc Location of '('.
1911 /// \param EndLoc Ending location of the clause.
1912 OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
1913 SourceLocation LParenLoc, SourceLocation EndLoc)
1914 : OMPClause(llvm::omp::OMPC_ordered, StartLoc, EndLoc),
1915 LParenLoc(LParenLoc), NumForLoops(Num), NumberOfLoops(NumLoops) {}
1916
1917 /// Build an empty clause.
1918 explicit OMPOrderedClause(unsigned NumLoops)
1919 : OMPClause(llvm::omp::OMPC_ordered, SourceLocation(), SourceLocation()),
1920 NumberOfLoops(NumLoops) {}
1921
1922 /// Set the number of associated for-loops.
1923 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
1924
1925public:
1926 /// Build 'ordered' clause.
1927 ///
1928 /// \param Num Expression, possibly associated with this clause.
1929 /// \param NumLoops Number of loops, associated with this clause.
1930 /// \param StartLoc Starting location of the clause.
1931 /// \param LParenLoc Location of '('.
1932 /// \param EndLoc Ending location of the clause.
1933 static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
1934 unsigned NumLoops, SourceLocation StartLoc,
1935 SourceLocation LParenLoc,
1936 SourceLocation EndLoc);
1937
1938 /// Build an empty clause.
1939 static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
1940
1941 /// Sets the location of '('.
1942 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1943
1944 /// Returns the location of '('.
1945 SourceLocation getLParenLoc() const { return LParenLoc; }
1946
1947 /// Return the number of associated for-loops.
1948 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
1949
1950 /// Set number of iterations for the specified loop.
1951 void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
1952 /// Get number of iterations for all the loops.
1954
1955 /// Set loop counter for the specified loop.
1956 void setLoopCounter(unsigned NumLoop, Expr *Counter);
1957 /// Get loops counter for the specified loop.
1958 Expr *getLoopCounter(unsigned NumLoop);
1959 const Expr *getLoopCounter(unsigned NumLoop) const;
1960
1961 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1962
1964 return const_child_range(&NumForLoops, &NumForLoops + 1);
1965 }
1966
1969 }
1972 }
1973
1974 static bool classof(const OMPClause *T) {
1975 return T->getClauseKind() == llvm::omp::OMPC_ordered;
1976 }
1977};
1978
1979/// This represents 'nowait' clause in the '#pragma omp ...' directive.
1980///
1981/// \code
1982/// #pragma omp for nowait
1983/// \endcode
1984/// In this example directive '#pragma omp for' has 'nowait' clause.
1985class OMPNowaitClause final : public OMPNoChildClause<llvm::omp::OMPC_nowait> {
1986public:
1987 /// Build 'nowait' clause.
1988 ///
1989 /// \param StartLoc Starting location of the clause.
1990 /// \param EndLoc Ending location of the clause.
1992 SourceLocation EndLoc = SourceLocation())
1993 : OMPNoChildClause(StartLoc, EndLoc) {}
1994};
1995
1996/// This represents 'untied' clause in the '#pragma omp ...' directive.
1997///
1998/// \code
1999/// #pragma omp task untied
2000/// \endcode
2001/// In this example directive '#pragma omp task' has 'untied' clause.
2003public:
2004 /// Build 'untied' clause.
2005 ///
2006 /// \param StartLoc Starting location of the clause.
2007 /// \param EndLoc Ending location of the clause.
2009 : OMPClause(llvm::omp::OMPC_untied, StartLoc, EndLoc) {}
2010
2011 /// Build an empty clause.
2013 : OMPClause(llvm::omp::OMPC_untied, SourceLocation(), SourceLocation()) {}
2014
2017 }
2018
2021 }
2022
2025 }
2028 }
2029
2030 static bool classof(const OMPClause *T) {
2031 return T->getClauseKind() == llvm::omp::OMPC_untied;
2032 }
2033};
2034
2035/// This represents 'mergeable' clause in the '#pragma omp ...'
2036/// directive.
2037///
2038/// \code
2039/// #pragma omp task mergeable
2040/// \endcode
2041/// In this example directive '#pragma omp task' has 'mergeable' clause.
2043public:
2044 /// Build 'mergeable' clause.
2045 ///
2046 /// \param StartLoc Starting location of the clause.
2047 /// \param EndLoc Ending location of the clause.
2049 : OMPClause(llvm::omp::OMPC_mergeable, StartLoc, EndLoc) {}
2050
2051 /// Build an empty clause.
2053 : OMPClause(llvm::omp::OMPC_mergeable, SourceLocation(),
2054 SourceLocation()) {}
2055
2058 }
2059
2062 }
2063
2066 }
2069 }
2070
2071 static bool classof(const OMPClause *T) {
2072 return T->getClauseKind() == llvm::omp::OMPC_mergeable;
2073 }
2074};
2075
2076/// This represents the 'absent' clause in the '#pragma omp assume'
2077/// directive.
2078///
2079/// \code
2080/// #pragma omp assume absent(<directive-name list>)
2081/// \endcode
2082/// In this example directive '#pragma omp assume' has an 'absent' clause.
2084 : public OMPDirectiveListClause<OMPAbsentClause>,
2085 private llvm::TrailingObjects<OMPAbsentClause, OpenMPDirectiveKind> {
2087 friend TrailingObjects;
2088
2089 /// Build 'absent' clause.
2090 ///
2091 /// \param StartLoc Starting location of the clause.
2092 /// \param LParenLoc Location of '('.
2093 /// \param EndLoc Ending location of the clause.
2094 /// \param NumKinds Number of directive kinds listed in the clause.
2095 OMPAbsentClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2096 SourceLocation EndLoc, unsigned NumKinds)
2098 llvm::omp::OMPC_absent, StartLoc, LParenLoc, EndLoc, NumKinds) {}
2099
2100 /// Build an empty clause.
2101 OMPAbsentClause(unsigned NumKinds)
2103 llvm::omp::OMPC_absent, SourceLocation(), SourceLocation(),
2105
2106public:
2107 static OMPAbsentClause *Create(const ASTContext &C,
2110 SourceLocation RLoc);
2111
2112 static OMPAbsentClause *CreateEmpty(const ASTContext &C, unsigned NumKinds);
2113
2114 static bool classof(const OMPClause *C) {
2115 return C->getClauseKind() == llvm::omp::OMPC_absent;
2116 }
2117};
2118
2119/// This represents the 'contains' clause in the '#pragma omp assume'
2120/// directive.
2121///
2122/// \code
2123/// #pragma omp assume contains(<directive-name list>)
2124/// \endcode
2125/// In this example directive '#pragma omp assume' has a 'contains' clause.
2127 : public OMPDirectiveListClause<OMPContainsClause>,
2128 private llvm::TrailingObjects<OMPContainsClause, OpenMPDirectiveKind> {
2130 friend TrailingObjects;
2131
2132 /// Build 'contains' clause.
2133 ///
2134 /// \param StartLoc Starting location of the clause.
2135 /// \param LParenLoc Location of '('.
2136 /// \param EndLoc Ending location of the clause.
2137 /// \param NumKinds Number of directive kinds listed in the clause.
2139 SourceLocation EndLoc, unsigned NumKinds)
2141 llvm::omp::OMPC_contains, StartLoc, LParenLoc, EndLoc, NumKinds) {}
2142
2143 /// Build an empty clause.
2144 OMPContainsClause(unsigned NumKinds)
2146 llvm::omp::OMPC_contains, SourceLocation(), SourceLocation(),
2148
2149public:
2150 static OMPContainsClause *Create(const ASTContext &C,
2153 SourceLocation RLoc);
2154
2155 static OMPContainsClause *CreateEmpty(const ASTContext &C, unsigned NumKinds);
2156
2157 static bool classof(const OMPClause *C) {
2158 return C->getClauseKind() == llvm::omp::OMPC_contains;
2159 }
2160};
2161
2162/// This represents the 'holds' clause in the '#pragma omp assume'
2163/// directive.
2164///
2165/// \code
2166/// #pragma omp assume holds(<expr>)
2167/// \endcode
2168/// In this example directive '#pragma omp assume' has a 'holds' clause.
2170 : public OMPOneStmtClause<llvm::omp::OMPC_holds, OMPClause> {
2171 friend class OMPClauseReader;
2172
2173public:
2174 /// Build 'holds' clause.
2175 ///
2176 /// \param StartLoc Starting location of the clause.
2177 /// \param EndLoc Ending location of the clause.
2179 SourceLocation EndLoc)
2180 : OMPOneStmtClause(E, StartLoc, LParenLoc, EndLoc) {}
2181
2182 /// Build an empty clause.
2184
2185 Expr *getExpr() const { return getStmtAs<Expr>(); }
2186 void setExpr(Expr *E) { setStmt(E); }
2187};
2188
2189/// This represents the 'no_openmp' clause in the '#pragma omp assume'
2190/// directive.
2191///
2192/// \code
2193/// #pragma omp assume no_openmp
2194/// \endcode
2195/// In this example directive '#pragma omp assume' has a 'no_openmp' clause.
2197 : public OMPNoChildClause<llvm::omp::OMPC_no_openmp> {
2198public:
2199 /// Build 'no_openmp' clause.
2200 ///
2201 /// \param StartLoc Starting location of the clause.
2202 /// \param EndLoc Ending location of the clause.
2204 : OMPNoChildClause(StartLoc, EndLoc) {}
2205
2206 /// Build an empty clause.
2208};
2209
2210/// This represents the 'no_openmp_routines' clause in the '#pragma omp assume'
2211/// directive.
2212///
2213/// \code
2214/// #pragma omp assume no_openmp_routines
2215/// \endcode
2216/// In this example directive '#pragma omp assume' has a 'no_openmp_routines'
2217/// clause.
2219 : public OMPNoChildClause<llvm::omp::OMPC_no_openmp_routines> {
2220public:
2221 /// Build 'no_openmp_routines' clause.
2222 ///
2223 /// \param StartLoc Starting location of the clause.
2224 /// \param EndLoc Ending location of the clause.
2226 : OMPNoChildClause(StartLoc, EndLoc) {}
2227
2228 /// Build an empty clause.
2230};
2231
2232/// This represents the 'no_parallelism' clause in the '#pragma omp assume'
2233/// directive.
2234///
2235/// \code
2236/// #pragma omp assume no_parallelism
2237/// \endcode
2238/// In this example directive '#pragma omp assume' has a 'no_parallelism'
2239/// clause.
2241 : public OMPNoChildClause<llvm::omp::OMPC_no_parallelism> {
2242public:
2243 /// Build 'no_parallelism' clause.
2244 ///
2245 /// \param StartLoc Starting location of the clause.
2246 /// \param EndLoc Ending location of the clause.
2248 : OMPNoChildClause(StartLoc, EndLoc) {}
2249
2250 /// Build an empty clause.
2252};
2253
2254/// This represents 'read' clause in the '#pragma omp atomic' directive.
2255///
2256/// \code
2257/// #pragma omp atomic read
2258/// \endcode
2259/// In this example directive '#pragma omp atomic' has 'read' clause.
2260class OMPReadClause : public OMPClause {
2261public:
2262 /// Build 'read' clause.
2263 ///
2264 /// \param StartLoc Starting location of the clause.
2265 /// \param EndLoc Ending location of the clause.
2267 : OMPClause(llvm::omp::OMPC_read, StartLoc, EndLoc) {}
2268
2269 /// Build an empty clause.
2271 : OMPClause(llvm::omp::OMPC_read, SourceLocation(), SourceLocation()) {}
2272
2275 }
2276
2279 }
2280
2283 }
2286 }
2287
2288 static bool classof(const OMPClause *T) {
2289 return T->getClauseKind() == llvm::omp::OMPC_read;
2290 }
2291};
2292
2293/// This represents 'write' clause in the '#pragma omp atomic' directive.
2294///
2295/// \code
2296/// #pragma omp atomic write
2297/// \endcode
2298/// In this example directive '#pragma omp atomic' has 'write' clause.
2300public:
2301 /// Build 'write' clause.
2302 ///
2303 /// \param StartLoc Starting location of the clause.
2304 /// \param EndLoc Ending location of the clause.
2306 : OMPClause(llvm::omp::OMPC_write, StartLoc, EndLoc) {}
2307
2308 /// Build an empty clause.
2310 : OMPClause(llvm::omp::OMPC_write, SourceLocation(), SourceLocation()) {}
2311
2314 }
2315
2318 }
2319
2322 }
2325 }
2326
2327 static bool classof(const OMPClause *T) {
2328 return T->getClauseKind() == llvm::omp::OMPC_write;
2329 }
2330};
2331
2332/// This represents 'update' clause in the '#pragma omp atomic'
2333/// directive.
2334///
2335/// \code
2336/// #pragma omp atomic update
2337/// \endcode
2338/// In this example directive '#pragma omp atomic' has 'update' clause.
2339/// Also, this class represents 'update' clause in '#pragma omp depobj'
2340/// directive.
2341///
2342/// \code
2343/// #pragma omp depobj(a) update(in)
2344/// \endcode
2345/// In this example directive '#pragma omp depobj' has 'update' clause with 'in'
2346/// dependence kind.
2348 : public OMPClause,
2349 private llvm::TrailingObjects<OMPUpdateClause, SourceLocation,
2350 OpenMPDependClauseKind> {
2351 friend class OMPClauseReader;
2352 friend TrailingObjects;
2353
2354 /// true if extended version of the clause for 'depobj' directive.
2355 bool IsExtended = false;
2356
2357 /// Define the sizes of each trailing object array except the last one. This
2358 /// is required for TrailingObjects to work properly.
2359 size_t numTrailingObjects(OverloadToken<SourceLocation>) const {
2360 // 2 locations: for '(' and argument location.
2361 return IsExtended ? 2 : 0;
2362 }
2363
2364 /// Sets the location of '(' in clause for 'depobj' directive.
2365 void setLParenLoc(SourceLocation Loc) {
2366 assert(IsExtended && "Expected extended clause.");
2367 *getTrailingObjects<SourceLocation>() = Loc;
2368 }
2369
2370 /// Sets the location of '(' in clause for 'depobj' directive.
2371 void setArgumentLoc(SourceLocation Loc) {
2372 assert(IsExtended && "Expected extended clause.");
2373 *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc;
2374 }
2375
2376 /// Sets the dependence kind for the clause for 'depobj' directive.
2377 void setDependencyKind(OpenMPDependClauseKind DK) {
2378 assert(IsExtended && "Expected extended clause.");
2379 *getTrailingObjects<OpenMPDependClauseKind>() = DK;
2380 }
2381
2382 /// Build 'update' clause.
2383 ///
2384 /// \param StartLoc Starting location of the clause.
2385 /// \param EndLoc Ending location of the clause.
2386 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc,
2387 bool IsExtended)
2388 : OMPClause(llvm::omp::OMPC_update, StartLoc, EndLoc),
2389 IsExtended(IsExtended) {}
2390
2391 /// Build an empty clause.
2392 OMPUpdateClause(bool IsExtended)
2393 : OMPClause(llvm::omp::OMPC_update, SourceLocation(), SourceLocation()),
2394 IsExtended(IsExtended) {}
2395
2396public:
2397 /// Creates clause for 'atomic' directive.
2398 ///
2399 /// \param C AST context.
2400 /// \param StartLoc Starting location of the clause.
2401 /// \param EndLoc Ending location of the clause.
2402 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2403 SourceLocation EndLoc);
2404
2405 /// Creates clause for 'depobj' directive.
2406 ///
2407 /// \param C AST context.
2408 /// \param StartLoc Starting location of the clause.
2409 /// \param LParenLoc Location of '('.
2410 /// \param ArgumentLoc Location of the argument.
2411 /// \param DK Dependence kind.
2412 /// \param EndLoc Ending location of the clause.
2413 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2414 SourceLocation LParenLoc,
2415 SourceLocation ArgumentLoc,
2417 SourceLocation EndLoc);
2418
2419 /// Creates an empty clause with the place for \a N variables.
2420 ///
2421 /// \param C AST context.
2422 /// \param IsExtended true if extended clause for 'depobj' directive must be
2423 /// created.
2424 static OMPUpdateClause *CreateEmpty(const ASTContext &C, bool IsExtended);
2425
2426 /// Checks if the clause is the extended clauses for 'depobj' directive.
2427 bool isExtended() const { return IsExtended; }
2428
2431 }
2432
2435 }
2436
2439 }
2442 }
2443
2444 /// Gets the location of '(' in clause for 'depobj' directive.
2446 assert(IsExtended && "Expected extended clause.");
2447 return *getTrailingObjects<SourceLocation>();
2448 }
2449
2450 /// Gets the location of argument in clause for 'depobj' directive.
2452 assert(IsExtended && "Expected extended clause.");
2453 return *std::next(getTrailingObjects<SourceLocation>(), 1);
2454 }
2455
2456 /// Gets the dependence kind in clause for 'depobj' directive.
2458 assert(IsExtended && "Expected extended clause.");
2459 return *getTrailingObjects<OpenMPDependClauseKind>();
2460 }
2461
2462 static bool classof(const OMPClause *T) {
2463 return T->getClauseKind() == llvm::omp::OMPC_update;
2464 }
2465};
2466
2467/// This represents 'capture' clause in the '#pragma omp atomic'
2468/// directive.
2469///
2470/// \code
2471/// #pragma omp atomic capture
2472/// \endcode
2473/// In this example directive '#pragma omp atomic' has 'capture' clause.
2475public:
2476 /// Build 'capture' clause.
2477 ///
2478 /// \param StartLoc Starting location of the clause.
2479 /// \param EndLoc Ending location of the clause.
2481 : OMPClause(llvm::omp::OMPC_capture, StartLoc, EndLoc) {}
2482
2483 /// Build an empty clause.
2485 : OMPClause(llvm::omp::OMPC_capture, SourceLocation(), SourceLocation()) {
2486 }
2487
2490 }
2491
2494 }
2495
2498 }
2501 }
2502
2503 static bool classof(const OMPClause *T) {
2504 return T->getClauseKind() == llvm::omp::OMPC_capture;
2505 }
2506};
2507
2508/// This represents 'compare' clause in the '#pragma omp atomic'
2509/// directive.
2510///
2511/// \code
2512/// #pragma omp atomic compare
2513/// \endcode
2514/// In this example directive '#pragma omp atomic' has 'compare' clause.
2515class OMPCompareClause final : public OMPClause {
2516public:
2517 /// Build 'compare' clause.
2518 ///
2519 /// \param StartLoc Starting location of the clause.
2520 /// \param EndLoc Ending location of the clause.
2522 : OMPClause(llvm::omp::OMPC_compare, StartLoc, EndLoc) {}
2523
2524 /// Build an empty clause.
2526 : OMPClause(llvm::omp::OMPC_compare, SourceLocation(), SourceLocation()) {
2527 }
2528
2531 }
2532
2535 }
2536
2539 }
2542 }
2543
2544 static bool classof(const OMPClause *T) {
2545 return T->getClauseKind() == llvm::omp::OMPC_compare;
2546 }
2547};
2548
2549/// This represents 'seq_cst' clause in the '#pragma omp atomic'
2550/// directive.
2551///
2552/// \code
2553/// #pragma omp atomic seq_cst
2554/// \endcode
2555/// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
2557public:
2558 /// Build 'seq_cst' clause.
2559 ///
2560 /// \param StartLoc Starting location of the clause.
2561 /// \param EndLoc Ending location of the clause.
2563 : OMPClause(llvm::omp::OMPC_seq_cst, StartLoc, EndLoc) {}
2564
2565 /// Build an empty clause.
2567 : OMPClause(llvm::omp::OMPC_seq_cst, SourceLocation(), SourceLocation()) {
2568 }
2569
2572 }
2573
2576 }
2577
2580 }
2583 }
2584
2585 static bool classof(const OMPClause *T) {
2586 return T->getClauseKind() == llvm::omp::OMPC_seq_cst;
2587 }
2588};
2589
2590/// This represents 'acq_rel' clause in the '#pragma omp atomic|flush'
2591/// directives.
2592///
2593/// \code
2594/// #pragma omp flush acq_rel
2595/// \endcode
2596/// In this example directive '#pragma omp flush' has 'acq_rel' clause.
2597class OMPAcqRelClause final : public OMPClause {
2598public:
2599 /// Build 'ack_rel' clause.
2600 ///
2601 /// \param StartLoc Starting location of the clause.
2602 /// \param EndLoc Ending location of the clause.
2604 : OMPClause(llvm::omp::OMPC_acq_rel, StartLoc, EndLoc) {}
2605
2606 /// Build an empty clause.
2608 : OMPClause(llvm::omp::OMPC_acq_rel, SourceLocation(), SourceLocation()) {
2609 }
2610
2613 }
2614
2617 }
2618
2621 }
2624 }
2625
2626 static bool classof(const OMPClause *T) {
2627 return T->getClauseKind() == llvm::omp::OMPC_acq_rel;
2628 }
2629};
2630
2631/// This represents 'acquire' clause in the '#pragma omp atomic|flush'
2632/// directives.
2633///
2634/// \code
2635/// #pragma omp flush acquire
2636/// \endcode
2637/// In this example directive '#pragma omp flush' has 'acquire' clause.
2638class OMPAcquireClause final : public OMPClause {
2639public:
2640 /// Build 'acquire' clause.
2641 ///
2642 /// \param StartLoc Starting location of the clause.
2643 /// \param EndLoc Ending location of the clause.
2645 : OMPClause(llvm::omp::OMPC_acquire, StartLoc, EndLoc) {}
2646
2647 /// Build an empty clause.
2649 : OMPClause(llvm::omp::OMPC_acquire, SourceLocation(), SourceLocation()) {
2650 }
2651
2654 }
2655
2658 }
2659
2662 }
2665 }
2666
2667 static bool classof(const OMPClause *T) {
2668 return T->getClauseKind() == llvm::omp::OMPC_acquire;
2669 }
2670};
2671
2672/// This represents 'release' clause in the '#pragma omp atomic|flush'
2673/// directives.
2674///
2675/// \code
2676/// #pragma omp flush release
2677/// \endcode
2678/// In this example directive '#pragma omp flush' has 'release' clause.
2679class OMPReleaseClause final : public OMPClause {
2680public:
2681 /// Build 'release' clause.
2682 ///
2683 /// \param StartLoc Starting location of the clause.
2684 /// \param EndLoc Ending location of the clause.
2686 : OMPClause(llvm::omp::OMPC_release, StartLoc, EndLoc) {}
2687
2688 /// Build an empty clause.
2690 : OMPClause(llvm::omp::OMPC_release, SourceLocation(), SourceLocation()) {
2691 }
2692
2695 }
2696
2699 }
2700
2703 }
2706 }
2707
2708 static bool classof(const OMPClause *T) {
2709 return T->getClauseKind() == llvm::omp::OMPC_release;
2710 }
2711};
2712
2713/// This represents 'relaxed' clause in the '#pragma omp atomic'
2714/// directives.
2715///
2716/// \code
2717/// #pragma omp atomic relaxed
2718/// \endcode
2719/// In this example directive '#pragma omp atomic' has 'relaxed' clause.
2720class OMPRelaxedClause final : public OMPClause {
2721public:
2722 /// Build 'relaxed' clause.
2723 ///
2724 /// \param StartLoc Starting location of the clause.
2725 /// \param EndLoc Ending location of the clause.
2727 : OMPClause(llvm::omp::OMPC_relaxed, StartLoc, EndLoc) {}
2728
2729 /// Build an empty clause.
2731 : OMPClause(llvm::omp::OMPC_relaxed, SourceLocation(), SourceLocation()) {
2732 }
2733
2736 }
2737
2740 }
2741
2744 }
2747 }
2748
2749 static bool classof(const OMPClause *T) {
2750 return T->getClauseKind() == llvm::omp::OMPC_relaxed;
2751 }
2752};
2753
2754/// This represents 'weak' clause in the '#pragma omp atomic'
2755/// directives.
2756///
2757/// \code
2758/// #pragma omp atomic compare weak
2759/// \endcode
2760/// In this example directive '#pragma omp atomic' has 'weak' clause.
2761class OMPWeakClause final : public OMPClause {
2762public:
2763 /// Build 'weak' clause.
2764 ///
2765 /// \param StartLoc Starting location of the clause.
2766 /// \param EndLoc Ending location of the clause.
2768 : OMPClause(llvm::omp::OMPC_weak, StartLoc, EndLoc) {}
2769
2770 /// Build an empty clause.
2772 : OMPClause(llvm::omp::OMPC_weak, SourceLocation(), SourceLocation()) {}
2773
2776 }
2777
2780 }
2781
2784 }
2787 }
2788
2789 static bool classof(const OMPClause *T) {
2790 return T->getClauseKind() == llvm::omp::OMPC_weak;
2791 }
2792};
2793
2794/// This represents 'fail' clause in the '#pragma omp atomic'
2795/// directive.
2796///
2797/// \code
2798/// #pragma omp atomic compare fail
2799/// \endcode
2800/// In this example directive '#pragma omp atomic compare' has 'fail' clause.
2801class OMPFailClause final : public OMPClause {
2802
2803 // FailParameter is a memory-order-clause. Storing the ClauseKind is
2804 // sufficient for our purpose.
2805 OpenMPClauseKind FailParameter = llvm::omp::Clause::OMPC_unknown;
2806 SourceLocation FailParameterLoc;
2807 SourceLocation LParenLoc;
2808
2809 friend class OMPClauseReader;
2810
2811 /// Sets the location of '(' in fail clause.
2812 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2813
2814 /// Sets the location of memoryOrder clause argument in fail clause.
2815 void setFailParameterLoc(SourceLocation Loc) { FailParameterLoc = Loc; }
2816
2817 /// Sets the mem_order clause for 'atomic compare fail' directive.
2818 void setFailParameter(OpenMPClauseKind FailParameter) {
2819 this->FailParameter = FailParameter;
2820 assert(checkFailClauseParameter(FailParameter) &&
2821 "Invalid fail clause parameter");
2822 }
2823
2824public:
2825 /// Build 'fail' clause.
2826 ///
2827 /// \param StartLoc Starting location of the clause.
2828 /// \param EndLoc Ending location of the clause.
2830 : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc) {}
2831
2832 OMPFailClause(OpenMPClauseKind FailParameter, SourceLocation FailParameterLoc,
2833 SourceLocation StartLoc, SourceLocation LParenLoc,
2834 SourceLocation EndLoc)
2835 : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc),
2836 FailParameterLoc(FailParameterLoc), LParenLoc(LParenLoc) {
2837
2838 setFailParameter(FailParameter);
2839 }
2840
2841 /// Build an empty clause.
2843 : OMPClause(llvm::omp::OMPC_fail, SourceLocation(), SourceLocation()) {}
2844
2847 }
2848
2851 }
2852
2855 }
2858 }
2859
2860 static bool classof(const OMPClause *T) {
2861 return T->getClauseKind() == llvm::omp::OMPC_fail;
2862 }
2863
2864 /// Gets the location of '(' (for the parameter) in fail clause.
2866 return LParenLoc;
2867 }
2868
2869 /// Gets the location of Fail Parameter (type memory-order-clause) in
2870 /// fail clause.
2871 SourceLocation getFailParameterLoc() const { return FailParameterLoc; }
2872
2873 /// Gets the parameter (type memory-order-clause) in Fail clause.
2874 OpenMPClauseKind getFailParameter() const { return FailParameter; }
2875};
2876
2877/// This represents clause 'private' in the '#pragma omp ...' directives.
2878///
2879/// \code
2880/// #pragma omp parallel private(a,b)
2881/// \endcode
2882/// In this example directive '#pragma omp parallel' has clause 'private'
2883/// with the variables 'a' and 'b'.
2885 : public OMPVarListClause<OMPPrivateClause>,
2886 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
2887 friend class OMPClauseReader;
2888 friend OMPVarListClause;
2889 friend TrailingObjects;
2890
2891 /// Build clause with number of variables \a N.
2892 ///
2893 /// \param StartLoc Starting location of the clause.
2894 /// \param LParenLoc Location of '('.
2895 /// \param EndLoc Ending location of the clause.
2896 /// \param N Number of the variables in the clause.
2898 SourceLocation EndLoc, unsigned N)
2899 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc,
2900 LParenLoc, EndLoc, N) {}
2901
2902 /// Build an empty clause.
2903 ///
2904 /// \param N Number of variables.
2905 explicit OMPPrivateClause(unsigned N)
2906 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private,
2908 SourceLocation(), N) {}
2909
2910 /// Sets the list of references to private copies with initializers for
2911 /// new private variables.
2912 /// \param VL List of references.
2913 void setPrivateCopies(ArrayRef<Expr *> VL);
2914
2915 /// Gets the list of references to private copies with initializers for
2916 /// new private variables.
2917 MutableArrayRef<Expr *> getPrivateCopies() {
2918 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2919 }
2920 ArrayRef<const Expr *> getPrivateCopies() const {
2922 }
2923
2924public:
2925 /// Creates clause with a list of variables \a VL.
2926 ///
2927 /// \param C AST context.
2928 /// \param StartLoc Starting location of the clause.
2929 /// \param LParenLoc Location of '('.
2930 /// \param EndLoc Ending location of the clause.
2931 /// \param VL List of references to the variables.
2932 /// \param PrivateVL List of references to private copies with initializers.
2933 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2934 SourceLocation LParenLoc,
2935 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2936 ArrayRef<Expr *> PrivateVL);
2937
2938 /// Creates an empty clause with the place for \a N variables.
2939 ///
2940 /// \param C AST context.
2941 /// \param N The number of variables.
2942 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2943
2946 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2948 llvm::iterator_range<private_copies_const_iterator>;
2949
2951 return private_copies_range(getPrivateCopies().begin(),
2952 getPrivateCopies().end());
2953 }
2954
2956 return private_copies_const_range(getPrivateCopies().begin(),
2957 getPrivateCopies().end());
2958 }
2959
2961 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2962 reinterpret_cast<Stmt **>(varlist_end()));
2963 }
2964
2966 auto Children = const_cast<OMPPrivateClause *>(this)->children();
2967 return const_child_range(Children.begin(), Children.end());
2968 }
2969
2972 }
2975 }
2976
2977 static bool classof(const OMPClause *T) {
2978 return T->getClauseKind() == llvm::omp::OMPC_private;
2979 }
2980};
2981
2982/// This represents clause 'firstprivate' in the '#pragma omp ...'
2983/// directives.
2984///
2985/// \code
2986/// #pragma omp parallel firstprivate(a,b)
2987/// \endcode
2988/// In this example directive '#pragma omp parallel' has clause 'firstprivate'
2989/// with the variables 'a' and 'b'.
2991 : public OMPVarListClause<OMPFirstprivateClause>,
2992 public OMPClauseWithPreInit,
2993 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
2994 friend class OMPClauseReader;
2995 friend OMPVarListClause;
2996 friend TrailingObjects;
2997
2998 /// Build clause with number of variables \a N.
2999 ///
3000 /// \param StartLoc Starting location of the clause.
3001 /// \param LParenLoc Location of '('.
3002 /// \param EndLoc Ending location of the clause.
3003 /// \param N Number of the variables in the clause.
3005 SourceLocation EndLoc, unsigned N)
3006 : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate,
3007 StartLoc, LParenLoc, EndLoc, N),
3008 OMPClauseWithPreInit(this) {}
3009
3010 /// Build an empty clause.
3011 ///
3012 /// \param N Number of variables.
3013 explicit OMPFirstprivateClause(unsigned N)
3015 llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(),
3016 SourceLocation(), N),
3017 OMPClauseWithPreInit(this) {}
3018
3019 /// Sets the list of references to private copies with initializers for
3020 /// new private variables.
3021 /// \param VL List of references.
3022 void setPrivateCopies(ArrayRef<Expr *> VL);
3023
3024 /// Gets the list of references to private copies with initializers for
3025 /// new private variables.
3026 MutableArrayRef<Expr *> getPrivateCopies() {
3027 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3028 }
3029 ArrayRef<const Expr *> getPrivateCopies() const {
3031 }
3032
3033 /// Sets the list of references to initializer variables for new
3034 /// private variables.
3035 /// \param VL List of references.
3036 void setInits(ArrayRef<Expr *> VL);
3037
3038 /// Gets the list of references to initializer variables for new
3039 /// private variables.
3040 MutableArrayRef<Expr *> getInits() {
3041 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
3042 }
3043 ArrayRef<const Expr *> getInits() const {
3044 return llvm::ArrayRef(getPrivateCopies().end(), varlist_size());
3045 }
3046
3047public:
3048 /// Creates clause with a list of variables \a VL.
3049 ///
3050 /// \param C AST context.
3051 /// \param StartLoc Starting location of the clause.
3052 /// \param LParenLoc Location of '('.
3053 /// \param EndLoc Ending location of the clause.
3054 /// \param VL List of references to the original variables.
3055 /// \param PrivateVL List of references to private copies with initializers.
3056 /// \param InitVL List of references to auto generated variables used for
3057 /// initialization of a single array element. Used if firstprivate variable is
3058 /// of array type.
3059 /// \param PreInit Statement that must be executed before entering the OpenMP
3060 /// region with this clause.
3061 static OMPFirstprivateClause *
3062 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3063 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
3064 ArrayRef<Expr *> InitVL, Stmt *PreInit);
3065
3066 /// Creates an empty clause with the place for \a N variables.
3067 ///
3068 /// \param C AST context.
3069 /// \param N The number of variables.
3070 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3071
3074 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
3076 llvm::iterator_range<private_copies_const_iterator>;
3077
3079 return private_copies_range(getPrivateCopies().begin(),
3080 getPrivateCopies().end());
3081 }
3083 return private_copies_const_range(getPrivateCopies().begin(),
3084 getPrivateCopies().end());
3085 }
3086
3089 using inits_range = llvm::iterator_range<inits_iterator>;
3090 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
3091
3093 return inits_range(getInits().begin(), getInits().end());
3094 }
3096 return inits_const_range(getInits().begin(), getInits().end());
3097 }
3098
3100 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3101 reinterpret_cast<Stmt **>(varlist_end()));
3102 }
3103
3105 auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
3106 return const_child_range(Children.begin(), Children.end());
3107 }
3108
3110 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3111 reinterpret_cast<Stmt **>(varlist_end()));
3112 }
3114 auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
3115 return const_child_range(Children.begin(), Children.end());
3116 }
3117
3118 static bool classof(const OMPClause *T) {
3119 return T->getClauseKind() == llvm::omp::OMPC_firstprivate;
3120 }
3121};
3122
3123/// This represents clause 'lastprivate' in the '#pragma omp ...'
3124/// directives.
3125///
3126/// \code
3127/// #pragma omp simd lastprivate(a,b)
3128/// \endcode
3129/// In this example directive '#pragma omp simd' has clause 'lastprivate'
3130/// with the variables 'a' and 'b'.
3132 : public OMPVarListClause<OMPLastprivateClause>,
3134 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
3135 // There are 4 additional tail-allocated arrays at the end of the class:
3136 // 1. Contains list of pseudo variables with the default initialization for
3137 // each non-firstprivate variables. Used in codegen for initialization of
3138 // lastprivate copies.
3139 // 2. List of helper expressions for proper generation of assignment operation
3140 // required for lastprivate clause. This list represents private variables
3141 // (for arrays, single array element).
3142 // 3. List of helper expressions for proper generation of assignment operation
3143 // required for lastprivate clause. This list represents original variables
3144 // (for arrays, single array element).
3145 // 4. List of helper expressions that represents assignment operation:
3146 // \code
3147 // DstExprs = SrcExprs;
3148 // \endcode
3149 // Required for proper codegen of final assignment performed by the
3150 // lastprivate clause.
3151 friend class OMPClauseReader;
3152 friend OMPVarListClause;
3153 friend TrailingObjects;
3154
3155 /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
3157 /// Optional location of the lasptrivate kind, if specified by user.
3158 SourceLocation LPKindLoc;
3159 /// Optional colon location, if specified by user.
3160 SourceLocation ColonLoc;
3161
3162 /// Build clause with number of variables \a N.
3163 ///
3164 /// \param StartLoc Starting location of the clause.
3165 /// \param LParenLoc Location of '('.
3166 /// \param EndLoc Ending location of the clause.
3167 /// \param N Number of the variables in the clause.
3170 SourceLocation LPKindLoc, SourceLocation ColonLoc,
3171 unsigned N)
3172 : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate,
3173 StartLoc, LParenLoc, EndLoc, N),
3174 OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
3175 ColonLoc(ColonLoc) {}
3176
3177 /// Build an empty clause.
3178 ///
3179 /// \param N Number of variables.
3180 explicit OMPLastprivateClause(unsigned N)
3182 llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(),
3183 SourceLocation(), N),
3185
3186 /// Get the list of helper expressions for initialization of private
3187 /// copies for lastprivate variables.
3188 MutableArrayRef<Expr *> getPrivateCopies() {
3189 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3190 }
3191 ArrayRef<const Expr *> getPrivateCopies() const {
3193 }
3194
3195 /// Set list of helper expressions, required for proper codegen of the
3196 /// clause. These expressions represent private variables (for arrays, single
3197 /// array element) in the final assignment statement performed by the
3198 /// lastprivate clause.
3199 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
3200
3201 /// Get the list of helper source expressions.
3202 MutableArrayRef<Expr *> getSourceExprs() {
3203 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
3204 }
3205 ArrayRef<const Expr *> getSourceExprs() const {
3206 return llvm::ArrayRef(getPrivateCopies().end(), varlist_size());
3207 }
3208
3209 /// Set list of helper expressions, required for proper codegen of the
3210 /// clause. These expressions represent original variables (for arrays, single
3211 /// array element) in the final assignment statement performed by the
3212 /// lastprivate clause.
3213 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
3214
3215 /// Get the list of helper destination expressions.
3216 MutableArrayRef<Expr *> getDestinationExprs() {
3217 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
3218 }
3219 ArrayRef<const Expr *> getDestinationExprs() const {
3220 return llvm::ArrayRef(getSourceExprs().end(), varlist_size());
3221 }
3222
3223 /// Set list of helper assignment expressions, required for proper
3224 /// codegen of the clause. These expressions are assignment expressions that
3225 /// assign private copy of the variable to original variable.
3226 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
3227
3228 /// Get the list of helper assignment expressions.
3229 MutableArrayRef<Expr *> getAssignmentOps() {
3230 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
3231 }
3232 ArrayRef<const Expr *> getAssignmentOps() const {
3233 return llvm::ArrayRef(getDestinationExprs().end(), varlist_size());
3234 }
3235
3236 /// Sets lastprivate kind.
3237 void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
3238 /// Sets location of the lastprivate kind.
3239 void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
3240 /// Sets colon symbol location.
3241 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3242
3243public:
3244 /// Creates clause with a list of variables \a VL.
3245 ///
3246 /// \param C AST context.
3247 /// \param StartLoc Starting location of the clause.
3248 /// \param LParenLoc Location of '('.
3249 /// \param EndLoc Ending location of the clause.
3250 /// \param VL List of references to the variables.
3251 /// \param SrcExprs List of helper expressions for proper generation of
3252 /// assignment operation required for lastprivate clause. This list represents
3253 /// private variables (for arrays, single array element).
3254 /// \param DstExprs List of helper expressions for proper generation of
3255 /// assignment operation required for lastprivate clause. This list represents
3256 /// original variables (for arrays, single array element).
3257 /// \param AssignmentOps List of helper expressions that represents assignment
3258 /// operation:
3259 /// \code
3260 /// DstExprs = SrcExprs;
3261 /// \endcode
3262 /// Required for proper codegen of final assignment performed by the
3263 /// lastprivate clause.
3264 /// \param LPKind Lastprivate kind, e.g. 'conditional'.
3265 /// \param LPKindLoc Location of the lastprivate kind.
3266 /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
3267 /// \param PreInit Statement that must be executed before entering the OpenMP
3268 /// region with this clause.
3269 /// \param PostUpdate Expression that must be executed after exit from the
3270 /// OpenMP region with this clause.
3271 static OMPLastprivateClause *
3272 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3273 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
3274 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
3275 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
3276 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
3277
3278 /// Creates an empty clause with the place for \a N variables.
3279 ///
3280 /// \param C AST context.
3281 /// \param N The number of variables.
3282 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3283
3284 /// Lastprivate kind.
3285 OpenMPLastprivateModifier getKind() const { return LPKind; }
3286 /// Returns the location of the lastprivate kind.
3287 SourceLocation getKindLoc() const { return LPKindLoc; }
3288 /// Returns the location of the ':' symbol, if any.
3289 SourceLocation getColonLoc() const { return ColonLoc; }
3290
3293 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3295 llvm::iterator_range<helper_expr_const_iterator>;
3296
3297 /// Set list of helper expressions, required for generation of private
3298 /// copies of original lastprivate variables.
3299 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
3300
3302 return helper_expr_const_range(getPrivateCopies().begin(),
3303 getPrivateCopies().end());
3304 }
3305
3307 return helper_expr_range(getPrivateCopies().begin(),
3308 getPrivateCopies().end());
3309 }
3310
3312 return helper_expr_const_range(getSourceExprs().begin(),
3313 getSourceExprs().end());
3314 }
3315
3317 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
3318 }
3319
3321 return helper_expr_const_range(getDestinationExprs().begin(),
3322 getDestinationExprs().end());
3323 }
3324
3326 return helper_expr_range(getDestinationExprs().begin(),
3327 getDestinationExprs().end());
3328 }
3329
3331 return helper_expr_const_range(getAssignmentOps().begin(),
3332 getAssignmentOps().end());
3333 }
3334
3336 return helper_expr_range(getAssignmentOps().begin(),
3337 getAssignmentOps().end());
3338 }
3339
3341 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3342 reinterpret_cast<Stmt **>(varlist_end()));
3343 }
3344
3346 auto Children = const_cast<OMPLastprivateClause *>(this)->children();
3347 return const_child_range(Children.begin(), Children.end());
3348 }
3349
3352 }
3355 }
3356
3357 static bool classof(const OMPClause *T) {
3358 return T->getClauseKind() == llvm::omp::OMPC_lastprivate;
3359 }
3360};
3361
3362/// This represents clause 'shared' in the '#pragma omp ...' directives.
3363///
3364/// \code
3365/// #pragma omp parallel shared(a,b)
3366/// \endcode
3367/// In this example directive '#pragma omp parallel' has clause 'shared'
3368/// with the variables 'a' and 'b'.
3370 : public OMPVarListClause<OMPSharedClause>,
3371 private llvm::TrailingObjects<OMPSharedClause, Expr *> {
3372 friend OMPVarListClause;
3373 friend TrailingObjects;
3374
3375 /// Build clause with number of variables \a N.
3376 ///
3377 /// \param StartLoc Starting location of the clause.
3378 /// \param LParenLoc Location of '('.
3379 /// \param EndLoc Ending location of the clause.
3380 /// \param N Number of the variables in the clause.
3381 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3382 SourceLocation EndLoc, unsigned N)
3383 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, StartLoc,
3384 LParenLoc, EndLoc, N) {}
3385
3386 /// Build an empty clause.
3387 ///
3388 /// \param N Number of variables.
3389 explicit OMPSharedClause(unsigned N)
3390 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared,
3392 SourceLocation(), N) {}
3393
3394public:
3395 /// Creates clause with a list of variables \a VL.
3396 ///
3397 /// \param C AST context.
3398 /// \param StartLoc Starting location of the clause.
3399 /// \param LParenLoc Location of '('.
3400 /// \param EndLoc Ending location of the clause.
3401 /// \param VL List of references to the variables.
3402 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
3403 SourceLocation LParenLoc,
3404 SourceLocation EndLoc, ArrayRef<Expr *> VL);
3405
3406 /// Creates an empty clause with \a N variables.
3407 ///
3408 /// \param C AST context.
3409 /// \param N The number of variables.
3410 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
3411
3413 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3414 reinterpret_cast<Stmt **>(varlist_end()));
3415 }
3416
3418 auto Children = const_cast<OMPSharedClause *>(this)->children();
3419 return const_child_range(Children.begin(), Children.end());
3420 }
3421
3424 }
3427 }
3428
3429 static bool classof(const OMPClause *T) {
3430 return T->getClauseKind() == llvm::omp::OMPC_shared;
3431 }
3432};
3433
3434/// This represents clause 'reduction' in the '#pragma omp ...'
3435/// directives.
3436///
3437/// \code
3438/// #pragma omp parallel reduction(+:a,b)
3439/// \endcode
3440/// In this example directive '#pragma omp parallel' has clause 'reduction'
3441/// with operator '+' and the variables 'a' and 'b'.
3443 : public OMPVarListClause<OMPReductionClause>,
3445 private llvm::TrailingObjects<OMPReductionClause, Expr *> {
3446 friend class OMPClauseReader;
3447 friend OMPVarListClause;
3448 friend TrailingObjects;
3449
3450 /// Reduction modifier.
3452
3453 /// Reduction modifier location.
3454 SourceLocation ModifierLoc;
3455
3456 /// Location of ':'.
3457 SourceLocation ColonLoc;
3458
3459 /// Nested name specifier for C++.
3460 NestedNameSpecifierLoc QualifierLoc;
3461
3462 /// Name of custom operator.
3463 DeclarationNameInfo NameInfo;
3464
3465 /// Build clause with number of variables \a N.
3466 ///
3467 /// \param StartLoc Starting location of the clause.
3468 /// \param LParenLoc Location of '('.
3469 /// \param ModifierLoc Modifier location.
3470 /// \param ColonLoc Location of ':'.
3471 /// \param EndLoc Ending location of the clause.
3472 /// \param N Number of the variables in the clause.
3473 /// \param QualifierLoc The nested-name qualifier with location information
3474 /// \param NameInfo The full name info for reduction identifier.
3476 SourceLocation ModifierLoc, SourceLocation ColonLoc,
3477 SourceLocation EndLoc,
3478 OpenMPReductionClauseModifier Modifier, unsigned N,
3479 NestedNameSpecifierLoc QualifierLoc,
3480 const DeclarationNameInfo &NameInfo)
3481 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
3482 StartLoc, LParenLoc, EndLoc, N),
3483 OMPClauseWithPostUpdate(this), Modifier(Modifier),
3484 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
3485 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3486
3487 /// Build an empty clause.
3488 ///
3489 /// \param N Number of variables.
3490 explicit OMPReductionClause(unsigned N)
3491 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
3493 SourceLocation(), N),
3495
3496 /// Sets reduction modifier.
3497 void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; }
3498
3499 /// Sets location of the modifier.
3500 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
3501
3502 /// Sets location of ':' symbol in clause.
3503 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3504
3505 /// Sets the name info for specified reduction identifier.
3506 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3507
3508 /// Sets the nested name specifier.
3509 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3510
3511 /// Set list of helper expressions, required for proper codegen of the
3512 /// clause. These expressions represent private copy of the reduction
3513 /// variable.
3514 void setPrivates(ArrayRef<Expr *> Privates);
3515
3516 /// Get the list of helper privates.
3517 MutableArrayRef<Expr *> getPrivates() {
3518 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3519 }
3520 ArrayRef<const Expr *> getPrivates() const {
3522 }
3523
3524 /// Set list of helper expressions, required for proper codegen of the
3525 /// clause. These expressions represent LHS expression in the final
3526 /// reduction expression performed by the reduction clause.
3527 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3528
3529 /// Get the list of helper LHS expressions.
3530 MutableArrayRef<Expr *> getLHSExprs() {
3531 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3532 }
3533 ArrayRef<const Expr *> getLHSExprs() const {
3534 return llvm::ArrayRef(getPrivates().end(), varlist_size());
3535 }
3536
3537 /// Set list of helper expressions, required for proper codegen of the
3538 /// clause. These expressions represent RHS expression in the final
3539 /// reduction expression performed by the reduction clause.
3540 /// Also, variables in these expressions are used for proper initialization of
3541 /// reduction copies.
3542 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3543
3544 /// Get the list of helper destination expressions.
3545 MutableArrayRef<Expr *> getRHSExprs() {
3546 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3547 }
3548 ArrayRef<const Expr *> getRHSExprs() const {
3549 return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
3550 }
3551
3552 /// Set list of helper reduction expressions, required for proper
3553 /// codegen of the clause. These expressions are binary expressions or
3554 /// operator/custom reduction call that calculates new value from source
3555 /// helper expressions to destination helper expressions.
3556 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3557
3558 /// Get the list of helper reduction expressions.
3559 MutableArrayRef<Expr *> getReductionOps() {
3560 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3561 }
3562 ArrayRef<const Expr *> getReductionOps() const {
3563 return llvm::ArrayRef(getRHSExprs().end(), varlist_size());
3564 }
3565
3566 /// Set list of helper copy operations for inscan reductions.
3567 /// The form is: Temps[i] = LHS[i];
3568 void setInscanCopyOps(ArrayRef<Expr *> Ops);
3569
3570 /// Get the list of helper inscan copy operations.
3571 MutableArrayRef<Expr *> getInscanCopyOps() {
3572 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3573 }
3574 ArrayRef<const Expr *> getInscanCopyOps() const {
3575 return llvm::ArrayRef(getReductionOps().end(), varlist_size());
3576 }
3577
3578 /// Set list of helper temp vars for inscan copy array operations.
3579 void setInscanCopyArrayTemps(ArrayRef<Expr *> CopyArrayTemps);
3580
3581 /// Get the list of helper inscan copy temps.
3582 MutableArrayRef<Expr *> getInscanCopyArrayTemps() {
3583 return MutableArrayRef<Expr *>(getInscanCopyOps().end(), varlist_size());
3584 }
3585 ArrayRef<const Expr *> getInscanCopyArrayTemps() const {
3586 return llvm::ArrayRef(getInscanCopyOps().end(), varlist_size());
3587 }
3588
3589 /// Set list of helper temp elements vars for inscan copy array operations.
3590 void setInscanCopyArrayElems(ArrayRef<Expr *> CopyArrayElems);
3591
3592 /// Get the list of helper inscan copy temps.
3593 MutableArrayRef<Expr *> getInscanCopyArrayElems() {
3594 return MutableArrayRef<Expr *>(getInscanCopyArrayTemps().end(),
3595 varlist_size());
3596 }
3597 ArrayRef<const Expr *> getInscanCopyArrayElems() const {
3598 return llvm::ArrayRef(getInscanCopyArrayTemps().end(), varlist_size());
3599 }
3600
3601public:
3602 /// Creates clause with a list of variables \a VL.
3603 ///
3604 /// \param StartLoc Starting location of the clause.
3605 /// \param LParenLoc Location of '('.
3606 /// \param ModifierLoc Modifier location.
3607 /// \param ColonLoc Location of ':'.
3608 /// \param EndLoc Ending location of the clause.
3609 /// \param VL The variables in the clause.
3610 /// \param QualifierLoc The nested-name qualifier with location information
3611 /// \param NameInfo The full name info for reduction identifier.
3612 /// \param Privates List of helper expressions for proper generation of
3613 /// private copies.
3614 /// \param LHSExprs List of helper expressions for proper generation of
3615 /// assignment operation required for copyprivate clause. This list represents
3616 /// LHSs of the reduction expressions.
3617 /// \param RHSExprs List of helper expressions for proper generation of
3618 /// assignment operation required for copyprivate clause. This list represents
3619 /// RHSs of the reduction expressions.
3620 /// Also, variables in these expressions are used for proper initialization of
3621 /// reduction copies.
3622 /// \param ReductionOps List of helper expressions that represents reduction
3623 /// expressions:
3624 /// \code
3625 /// LHSExprs binop RHSExprs;
3626 /// operator binop(LHSExpr, RHSExpr);
3627 /// <CutomReduction>(LHSExpr, RHSExpr);
3628 /// \endcode
3629 /// Required for proper codegen of final reduction operation performed by the
3630 /// reduction clause.
3631 /// \param CopyOps List of copy operations for inscan reductions:
3632 /// \code
3633 /// TempExprs = LHSExprs;
3634 /// \endcode
3635 /// \param CopyArrayTemps Temp arrays for prefix sums.
3636 /// \param CopyArrayElems Temp arrays for prefix sums.
3637 /// \param PreInit Statement that must be executed before entering the OpenMP
3638 /// region with this clause.
3639 /// \param PostUpdate Expression that must be executed after exit from the
3640 /// OpenMP region with this clause.
3641 static OMPReductionClause *
3642 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3643 SourceLocation ModifierLoc, SourceLocation ColonLoc,
3644 SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier,
3645 ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc,
3646 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3647 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3648 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> CopyOps,
3649 ArrayRef<Expr *> CopyArrayTemps, ArrayRef<Expr *> CopyArrayElems,
3650 Stmt *PreInit, Expr *PostUpdate);
3651
3652 /// Creates an empty clause with the place for \a N variables.
3653 ///
3654 /// \param C AST context.
3655 /// \param N The number of variables.
3656 /// \param Modifier Reduction modifier.
3657 static OMPReductionClause *
3658 CreateEmpty(const ASTContext &C, unsigned N,
3660
3661 /// Returns modifier.
3662 OpenMPReductionClauseModifier getModifier() const { return Modifier; }
3663
3664 /// Returns modifier location.
3665 SourceLocation getModifierLoc() const { return ModifierLoc; }
3666
3667 /// Gets location of ':' symbol in clause.
3668 SourceLocation getColonLoc() const { return ColonLoc; }
3669
3670 /// Gets the name info for specified reduction identifier.
3671 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3672
3673 /// Gets the nested name specifier.
3674 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3675
3678 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3680 llvm::iterator_range<helper_expr_const_iterator>;
3681
3683 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3684 }
3685
3687 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3688 }
3689
3691 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3692 }
3693
3695 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3696 }
3697
3699 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3700 }
3701
3703 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3704 }
3705
3707 return helper_expr_const_range(getReductionOps().begin(),
3708 getReductionOps().end());
3709 }
3710
3712 return helper_expr_range(getReductionOps().begin(),
3713 getReductionOps().end());
3714 }
3715
3717 return helper_expr_const_range(getInscanCopyOps().begin(),
3718 getInscanCopyOps().end());
3719 }
3720
3722 return helper_expr_range(getInscanCopyOps().begin(),
3723 getInscanCopyOps().end());
3724 }
3725
3727 return helper_expr_const_range(getInscanCopyArrayTemps().begin(),
3728 getInscanCopyArrayTemps().end());
3729 }
3730
3732 return helper_expr_range(getInscanCopyArrayTemps().begin(),
3733 getInscanCopyArrayTemps().end());
3734 }
3735
3737 return helper_expr_const_range(getInscanCopyArrayElems().begin(),
3738 getInscanCopyArrayElems().end());
3739 }
3740
3742 return helper_expr_range(getInscanCopyArrayElems().begin(),
3743 getInscanCopyArrayElems().end());
3744 }
3745
3747 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3748 reinterpret_cast<Stmt **>(varlist_end()));
3749 }
3750
3752 auto Children = const_cast<OMPReductionClause *>(this)->children();
3753 return const_child_range(Children.begin(), Children.end());
3754 }
3755
3757 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3758 reinterpret_cast<Stmt **>(varlist_end()));
3759 }
3761 auto Children = const_cast<OMPReductionClause *>(this)->used_children();
3762 return const_child_range(Children.begin(), Children.end());
3763 }
3764
3765 static bool classof(const OMPClause *T) {
3766 return T->getClauseKind() == llvm::omp::OMPC_reduction;
3767 }
3768};
3769
3770/// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
3771/// directives.
3772///
3773/// \code
3774/// #pragma omp taskgroup task_reduction(+:a,b)
3775/// \endcode
3776/// In this example directive '#pragma omp taskgroup' has clause
3777/// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
3779 : public OMPVarListClause<OMPTaskReductionClause>,
3781 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
3782 friend class OMPClauseReader;
3783 friend OMPVarListClause;
3784 friend TrailingObjects;
3785
3786 /// Location of ':'.
3787 SourceLocation ColonLoc;
3788
3789 /// Nested name specifier for C++.
3790 NestedNameSpecifierLoc QualifierLoc;
3791
3792 /// Name of custom operator.
3793 DeclarationNameInfo NameInfo;
3794
3795 /// Build clause with number of variables \a N.
3796 ///
3797 /// \param StartLoc Starting location of the clause.
3798 /// \param LParenLoc Location of '('.
3799 /// \param EndLoc Ending location of the clause.
3800 /// \param ColonLoc Location of ':'.
3801 /// \param N Number of the variables in the clause.
3802 /// \param QualifierLoc The nested-name qualifier with location information
3803 /// \param NameInfo The full name info for reduction identifier.
3805 SourceLocation ColonLoc, SourceLocation EndLoc,
3806 unsigned N, NestedNameSpecifierLoc QualifierLoc,
3807 const DeclarationNameInfo &NameInfo)
3809 llvm::omp::OMPC_task_reduction, StartLoc, LParenLoc, EndLoc, N),
3810 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3811 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3812
3813 /// Build an empty clause.
3814 ///
3815 /// \param N Number of variables.
3816 explicit OMPTaskReductionClause(unsigned N)
3818 llvm::omp::OMPC_task_reduction, SourceLocation(), SourceLocation(),
3819 SourceLocation(), N),
3821
3822 /// Sets location of ':' symbol in clause.
3823 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3824
3825 /// Sets the name info for specified reduction identifier.
3826 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3827
3828 /// Sets the nested name specifier.
3829 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3830
3831 /// Set list of helper expressions, required for proper codegen of the clause.
3832 /// These expressions represent private copy of the reduction variable.
3833 void setPrivates(ArrayRef<Expr *> Privates);
3834
3835 /// Get the list of helper privates.
3836 MutableArrayRef<Expr *> getPrivates() {
3837 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3838 }
3839 ArrayRef<const Expr *> getPrivates() const {
3841 }
3842
3843 /// Set list of helper expressions, required for proper codegen of the clause.
3844 /// These expressions represent LHS expression in the final reduction
3845 /// expression performed by the reduction clause.
3846 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3847
3848 /// Get the list of helper LHS expressions.
3849 MutableArrayRef<Expr *> getLHSExprs() {
3850 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3851 }
3852 ArrayRef<const Expr *> getLHSExprs() const {
3853 return llvm::ArrayRef(getPrivates().end(), varlist_size());
3854 }
3855
3856 /// Set list of helper expressions, required for proper codegen of the clause.
3857 /// These expressions represent RHS expression in the final reduction
3858 /// expression performed by the reduction clause. Also, variables in these
3859 /// expressions are used for proper initialization of reduction copies.
3860 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3861
3862 /// Get the list of helper destination expressions.
3863 MutableArrayRef<Expr *> getRHSExprs() {
3864 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3865 }
3866 ArrayRef<const Expr *> getRHSExprs() const {
3867 return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
3868 }
3869
3870 /// Set list of helper reduction expressions, required for proper
3871 /// codegen of the clause. These expressions are binary expressions or
3872 /// operator/custom reduction call that calculates new value from source
3873 /// helper expressions to destination helper expressions.
3874 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3875
3876 /// Get the list of helper reduction expressions.
3877 MutableArrayRef<Expr *> getReductionOps() {
3878 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3879 }
3880 ArrayRef<const Expr *> getReductionOps() const {
3881 return llvm::ArrayRef(getRHSExprs().end(), varlist_size());
3882 }
3883
3884public:
3885 /// Creates clause with a list of variables \a VL.
3886 ///
3887 /// \param StartLoc Starting location of the clause.
3888 /// \param LParenLoc Location of '('.
3889 /// \param ColonLoc Location of ':'.
3890 /// \param EndLoc Ending location of the clause.
3891 /// \param VL The variables in the clause.
3892 /// \param QualifierLoc The nested-name qualifier with location information
3893 /// \param NameInfo The full name info for reduction identifier.
3894 /// \param Privates List of helper expressions for proper generation of
3895 /// private copies.
3896 /// \param LHSExprs List of helper expressions for proper generation of
3897 /// assignment operation required for copyprivate clause. This list represents
3898 /// LHSs of the reduction expressions.
3899 /// \param RHSExprs List of helper expressions for proper generation of
3900 /// assignment operation required for copyprivate clause. This list represents
3901 /// RHSs of the reduction expressions.
3902 /// Also, variables in these expressions are used for proper initialization of
3903 /// reduction copies.
3904 /// \param ReductionOps List of helper expressions that represents reduction
3905 /// expressions:
3906 /// \code
3907 /// LHSExprs binop RHSExprs;
3908 /// operator binop(LHSExpr, RHSExpr);
3909 /// <CutomReduction>(LHSExpr, RHSExpr);
3910 /// \endcode
3911 /// Required for proper codegen of final reduction operation performed by the
3912 /// reduction clause.
3913 /// \param PreInit Statement that must be executed before entering the OpenMP
3914 /// region with this clause.
3915 /// \param PostUpdate Expression that must be executed after exit from the
3916 /// OpenMP region with this clause.
3917 static OMPTaskReductionClause *
3918 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3919 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3920 NestedNameSpecifierLoc QualifierLoc,
3921 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3922 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3923 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
3924
3925 /// Creates an empty clause with the place for \a N variables.
3926 ///
3927 /// \param C AST context.
3928 /// \param N The number of variables.
3929 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3930
3931 /// Gets location of ':' symbol in clause.
3932 SourceLocation getColonLoc() const { return ColonLoc; }
3933
3934 /// Gets the name info for specified reduction identifier.
3935 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3936
3937 /// Gets the nested name specifier.
3938 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3939
3942 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3944 llvm::iterator_range<helper_expr_const_iterator>;
3945
3947 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3948 }
3949
3951 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3952 }
3953
3955 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3956 }
3957
3959 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3960 }
3961
3963 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3964 }
3965
3967 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3968 }
3969
3971 return helper_expr_const_range(getReductionOps().begin(),
3972 getReductionOps().end());
3973 }
3974
3976 return helper_expr_range(getReductionOps().begin(),
3977 getReductionOps().end());
3978 }
3979
3981 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3982 reinterpret_cast<Stmt **>(varlist_end()));
3983 }
3984
3986 auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
3987 return const_child_range(Children.begin(), Children.end());
3988 }
3989
3992 }
3995 }
3996
3997 static bool classof(const OMPClause *T) {
3998 return T->getClauseKind() == llvm::omp::OMPC_task_reduction;
3999 }
4000};
4001
4002/// This represents clause 'in_reduction' in the '#pragma omp task' directives.
4003///
4004/// \code
4005/// #pragma omp task in_reduction(+:a,b)
4006/// \endcode
4007/// In this example directive '#pragma omp task' has clause 'in_reduction' with
4008/// operator '+' and the variables 'a' and 'b'.
4010 : public OMPVarListClause<OMPInReductionClause>,
4012 private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
4013 friend class OMPClauseReader;
4014 friend OMPVarListClause;
4015 friend TrailingObjects;
4016
4017 /// Location of ':'.
4018 SourceLocation ColonLoc;
4019
4020 /// Nested name specifier for C++.
4021 NestedNameSpecifierLoc QualifierLoc;
4022
4023 /// Name of custom operator.
4024 DeclarationNameInfo NameInfo;
4025
4026 /// Build clause with number of variables \a N.
4027 ///
4028 /// \param StartLoc Starting location of the clause.
4029 /// \param LParenLoc Location of '('.
4030 /// \param EndLoc Ending location of the clause.
4031 /// \param ColonLoc Location of ':'.
4032 /// \param N Number of the variables in the clause.
4033 /// \param QualifierLoc The nested-name qualifier with location information
4034 /// \param NameInfo The full name info for reduction identifier.
4036 SourceLocation ColonLoc, SourceLocation EndLoc,
4037 unsigned N, NestedNameSpecifierLoc QualifierLoc,
4038 const DeclarationNameInfo &NameInfo)
4039 : OMPVarListClause<OMPInReductionClause>(llvm::omp::OMPC_in_reduction,
4040 StartLoc, LParenLoc, EndLoc, N),
4041 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
4042 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
4043
4044 /// Build an empty clause.
4045 ///
4046 /// \param N Number of variables.
4047 explicit OMPInReductionClause(unsigned N)
4049 llvm::omp::OMPC_in_reduction, SourceLocation(), SourceLocation(),
4050 SourceLocation(), N),
4052
4053 /// Sets location of ':' symbol in clause.
4054 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
4055
4056 /// Sets the name info for specified reduction identifier.
4057 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
4058
4059 /// Sets the nested name specifier.
4060 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
4061
4062 /// Set list of helper expressions, required for proper codegen of the clause.
4063 /// These expressions represent private copy of the reduction variable.
4064 void setPrivates(ArrayRef<Expr *> Privates);
4065
4066 /// Get the list of helper privates.
4067 MutableArrayRef<Expr *> getPrivates() {
4068 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4069 }
4070 ArrayRef<const Expr *> getPrivates() const {
4072 }
4073
4074 /// Set list of helper expressions, required for proper codegen of the clause.
4075 /// These expressions represent LHS expression in the final reduction
4076 /// expression performed by the reduction clause.
4077 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
4078
4079 /// Get the list of helper LHS expressions.
4080 MutableArrayRef<Expr *> getLHSExprs() {
4081 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
4082 }
4083 ArrayRef<const Expr *> getLHSExprs() const {
4084 return llvm::ArrayRef(getPrivates().end(), varlist_size());
4085 }
4086
4087 /// Set list of helper expressions, required for proper codegen of the clause.
4088 /// These expressions represent RHS expression in the final reduction
4089 /// expression performed by the reduction clause. Also, variables in these
4090 /// expressions are used for proper initialization of reduction copies.
4091 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
4092
4093 /// Get the list of helper destination expressions.
4094 MutableArrayRef<Expr *> getRHSExprs() {
4095 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
4096 }
4097 ArrayRef<const Expr *> getRHSExprs() const {
4098 return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
4099 }
4100
4101 /// Set list of helper reduction expressions, required for proper
4102 /// codegen of the clause. These expressions are binary expressions or
4103 /// operator/custom reduction call that calculates new value from source
4104 /// helper expressions to destination helper expressions.
4105 void setReductionOps(ArrayRef<Expr *> ReductionOps);
4106
4107 /// Get the list of helper reduction expressions.
4108 MutableArrayRef<Expr *> getReductionOps() {
4109 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
4110 }
4111 ArrayRef<const Expr *> getReductionOps() const {
4112 return llvm::ArrayRef(getRHSExprs().end(), varlist_size());
4113 }
4114
4115 /// Set list of helper reduction taskgroup descriptors.
4116 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
4117
4118 /// Get the list of helper reduction taskgroup descriptors.
4119 MutableArrayRef<Expr *> getTaskgroupDescriptors() {
4120 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
4121 }
4122 ArrayRef<const Expr *> getTaskgroupDescriptors() const {
4123 return llvm::ArrayRef(getReductionOps().end(), varlist_size());
4124 }
4125
4126public:
4127 /// Creates clause with a list of variables \a VL.
4128 ///
4129 /// \param StartLoc Starting location of the clause.
4130 /// \param LParenLoc Location of '('.
4131 /// \param ColonLoc Location of ':'.
4132 /// \param EndLoc Ending location of the clause.
4133 /// \param VL The variables in the clause.
4134 /// \param QualifierLoc The nested-name qualifier with location information
4135 /// \param NameInfo The full name info for reduction identifier.
4136 /// \param Privates List of helper expressions for proper generation of
4137 /// private copies.
4138 /// \param LHSExprs List of helper expressions for proper generation of
4139 /// assignment operation required for copyprivate clause. This list represents
4140 /// LHSs of the reduction expressions.
4141 /// \param RHSExprs List of helper expressions for proper generation of
4142 /// assignment operation required for copyprivate clause. This list represents
4143 /// RHSs of the reduction expressions.
4144 /// Also, variables in these expressions are used for proper initialization of
4145 /// reduction copies.
4146 /// \param ReductionOps List of helper expressions that represents reduction
4147 /// expressions:
4148 /// \code
4149 /// LHSExprs binop RHSExprs;
4150 /// operator binop(LHSExpr, RHSExpr);
4151 /// <CutomReduction>(LHSExpr, RHSExpr);
4152 /// \endcode
4153 /// Required for proper codegen of final reduction operation performed by the
4154 /// reduction clause.
4155 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
4156 /// corresponding items in parent taskgroup task_reduction clause.
4157 /// \param PreInit Statement that must be executed before entering the OpenMP
4158 /// region with this clause.
4159 /// \param PostUpdate Expression that must be executed after exit from the
4160 /// OpenMP region with this clause.
4161 static OMPInReductionClause *
4162 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4163 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
4164 NestedNameSpecifierLoc QualifierLoc,
4165 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
4166 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
4167 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
4168 Stmt *PreInit, Expr *PostUpdate);
4169
4170 /// Creates an empty clause with the place for \a N variables.
4171 ///
4172 /// \param C AST context.
4173 /// \param N The number of variables.
4174 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
4175
4176 /// Gets location of ':' symbol in clause.
4177 SourceLocation getColonLoc() const { return ColonLoc; }
4178
4179 /// Gets the name info for specified reduction identifier.
4180 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
4181
4182 /// Gets the nested name specifier.
4183 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
4184
4187 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4189 llvm::iterator_range<helper_expr_const_iterator>;
4190
4192 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
4193 }
4194
4196 return helper_expr_range(getPrivates().begin(), getPrivates().end());
4197 }
4198
4200 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
4201 }
4202
4204 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
4205 }
4206
4208 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
4209 }
4210
4212 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
4213 }
4214
4216 return helper_expr_const_range(getReductionOps().begin(),
4217 getReductionOps().end());
4218 }
4219
4221 return helper_expr_range(getReductionOps().begin(),
4222 getReductionOps().end());
4223 }
4224
4226 return helper_expr_const_range(getTaskgroupDescriptors().begin(),
4227 getTaskgroupDescriptors().end());
4228 }
4229
4231 return helper_expr_range(getTaskgroupDescriptors().begin(),
4232 getTaskgroupDescriptors().end());
4233 }
4234
4236 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4237 reinterpret_cast<Stmt **>(varlist_end()));
4238 }
4239
4241 auto Children = const_cast<OMPInReductionClause *>(this)->children();
4242 return const_child_range(Children.begin(), Children.end());
4243 }
4244
4247 }
4250 }
4251
4252 static bool classof(const OMPClause *T) {
4253 return T->getClauseKind() == llvm::omp::OMPC_in_reduction;
4254 }
4255};
4256
4257/// This represents clause 'linear' in the '#pragma omp ...'
4258/// directives.
4259///
4260/// \code
4261/// #pragma omp simd linear(a,b : 2)
4262/// \endcode
4263/// In this example directive '#pragma omp simd' has clause 'linear'
4264/// with variables 'a', 'b' and linear step '2'.
4266 : public OMPVarListClause<OMPLinearClause>,
4268 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
4269 friend class OMPClauseReader;
4270 friend OMPVarListClause;
4271 friend TrailingObjects;
4272
4273 /// Modifier of 'linear' clause.
4274 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
4275
4276 /// Location of linear modifier if any.
4277 SourceLocation ModifierLoc;
4278
4279 /// Location of ':'.
4280 SourceLocation ColonLoc;
4281
4282 /// Location of 'step' modifier.
4283 SourceLocation StepModifierLoc;
4284
4285 /// Sets the linear step for clause.
4286 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
4287
4288 /// Sets the expression to calculate linear step for clause.
4289 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
4290
4291 /// Build 'linear' clause with given number of variables \a NumVars.
4292 ///
4293 /// \param StartLoc Starting location of the clause.
4294 /// \param LParenLoc Location of '('.
4295 /// \param ColonLoc Location of ':'.
4296 /// \param StepModifierLoc Location of 'step' modifier.
4297 /// \param EndLoc Ending location of the clause.
4298 /// \param NumVars Number of variables.
4299 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4300 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
4301 SourceLocation ColonLoc, SourceLocation StepModifierLoc,
4302 SourceLocation EndLoc, unsigned NumVars)
4303 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, StartLoc,
4304 LParenLoc, EndLoc, NumVars),
4305 OMPClauseWithPostUpdate(this), Modifier(Modifier),
4306 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
4307 StepModifierLoc(StepModifierLoc) {}
4308
4309 /// Build an empty clause.
4310 ///
4311 /// \param NumVars Number of variables.
4312 explicit OMPLinearClause(unsigned NumVars)
4313 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear,
4314 SourceLocation(), SourceLocation(),
4315 SourceLocation(), NumVars),
4317
4318 /// Gets the list of initial values for linear variables.
4319 ///
4320 /// There are NumVars expressions with initial values allocated after the
4321 /// varlist, they are followed by NumVars update expressions (used to update
4322 /// the linear variable's value on current iteration) and they are followed by
4323 /// NumVars final expressions (used to calculate the linear variable's
4324 /// value after the loop body). After these lists, there are 2 helper
4325 /// expressions - linear step and a helper to calculate it before the
4326 /// loop body (used when the linear step is not constant):
4327 ///
4328 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
4329 /// Finals[]; Step; CalcStep; }
4330 MutableArrayRef<Expr *> getPrivates() {
4331 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4332 }
4333 ArrayRef<const Expr *> getPrivates() const {
4335 }
4336
4337 MutableArrayRef<Expr *> getInits() {
4338 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
4339 }
4340 ArrayRef<const Expr *> getInits() const {
4341 return llvm::ArrayRef(getPrivates().end(), varlist_size());
4342 }
4343
4344 /// Sets the list of update expressions for linear variables.
4345 MutableArrayRef<Expr *> getUpdates() {
4346 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
4347 }
4348 ArrayRef<const Expr *> getUpdates() const {
4349 return llvm::ArrayRef(getInits().end(), varlist_size());
4350 }
4351
4352 /// Sets the list of final update expressions for linear variables.
4353 MutableArrayRef<Expr *> getFinals() {
4354 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
4355 }
4356 ArrayRef<const Expr *> getFinals() const {
4357 return llvm::ArrayRef(getUpdates().end(), varlist_size());
4358 }
4359
4360 /// Gets the list of used expressions for linear variables.
4361 MutableArrayRef<Expr *> getUsedExprs() {
4362 return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
4363 }
4364 ArrayRef<const Expr *> getUsedExprs() const {
4365 return llvm::ArrayRef(getFinals().end() + 2, varlist_size() + 1);
4366 }
4367
4368 /// Sets the list of the copies of original linear variables.
4369 /// \param PL List of expressions.
4370 void setPrivates(ArrayRef<Expr *> PL);
4371
4372 /// Sets the list of the initial values for linear variables.
4373 /// \param IL List of expressions.
4374 void setInits(ArrayRef<Expr *> IL);
4375
4376public:
4377 /// Creates clause with a list of variables \a VL and a linear step
4378 /// \a Step.
4379 ///
4380 /// \param C AST Context.
4381 /// \param StartLoc Starting location of the clause.
4382 /// \param LParenLoc Location of '('.
4383 /// \param Modifier Modifier of 'linear' clause.
4384 /// \param ModifierLoc Modifier location.
4385 /// \param ColonLoc Location of ':'.
4386 /// \param StepModifierLoc Location of 'step' modifier.
4387 /// \param EndLoc Ending location of the clause.
4388 /// \param VL List of references to the variables.
4389 /// \param PL List of private copies of original variables.
4390 /// \param IL List of initial values for the variables.
4391 /// \param Step Linear step.
4392 /// \param CalcStep Calculation of the linear step.
4393 /// \param PreInit Statement that must be executed before entering the OpenMP
4394 /// region with this clause.
4395 /// \param PostUpdate Expression that must be executed after exit from the
4396 /// OpenMP region with this clause.
4397 static OMPLinearClause *
4398 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4399 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
4400 SourceLocation ColonLoc, SourceLocation StepModifierLoc,
4401 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PL,
4402 ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit,
4403 Expr *PostUpdate);
4404
4405 /// Creates an empty clause with the place for \a NumVars variables.
4406 ///
4407 /// \param C AST context.
4408 /// \param NumVars Number of variables.
4409 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
4410
4411 /// Set modifier.
4413
4414 /// Return modifier.
4415 OpenMPLinearClauseKind getModifier() const { return Modifier; }
4416
4417 /// Set modifier location.
4418 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
4419
4420 /// Return modifier location.
4421 SourceLocation getModifierLoc() const { return ModifierLoc; }
4422
4423 /// Sets the location of ':'.
4424 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4425
4426 /// Sets the location of 'step' modifier.
4427 void setStepModifierLoc(SourceLocation Loc) { StepModifierLoc = Loc; }
4428
4429 /// Returns the location of ':'.
4430 SourceLocation getColonLoc() const { return ColonLoc; }
4431
4432 /// Returns the location of 'step' modifier.
4433 SourceLocation getStepModifierLoc() const { return StepModifierLoc; }
4434
4435 /// Returns linear step.
4436 Expr *getStep() { return *(getFinals().end()); }
4437
4438 /// Returns linear step.
4439 const Expr *getStep() const { return *(getFinals().end()); }
4440
4441 /// Returns expression to calculate linear step.
4442 Expr *getCalcStep() { return *(getFinals().end() + 1); }
4443
4444 /// Returns expression to calculate linear step.
4445 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
4446
4447 /// Sets the list of update expressions for linear variables.
4448 /// \param UL List of expressions.
4450
4451 /// Sets the list of final update expressions for linear variables.
4452 /// \param FL List of expressions.
4453 void setFinals(ArrayRef<Expr *> FL);
4454
4455 /// Sets the list of used expressions for the linear clause.
4457
4460 using privates_range = llvm::iterator_range<privates_iterator>;
4461 using privates_const_range = llvm::iterator_range<privates_const_iterator>;
4462
4464 return privates_range(getPrivates().begin(), getPrivates().end());
4465 }
4466
4468 return privates_const_range(getPrivates().begin(), getPrivates().end());
4469 }
4470
4473 using inits_range = llvm::iterator_range<inits_iterator>;
4474 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
4475
4477 return inits_range(getInits().begin(), getInits().end());
4478 }
4479
4481 return inits_const_range(getInits().begin(), getInits().end());
4482 }
4483
4486 using updates_range = llvm::iterator_range<updates_iterator>;
4487 using updates_const_range = llvm::iterator_range<updates_const_iterator>;
4488
4490 return updates_range(getUpdates().begin(), getUpdates().end());
4491 }
4492
4494 return updates_const_range(getUpdates().begin(), getUpdates().end());
4495 }
4496
4499 using finals_range = llvm::iterator_range<finals_iterator>;
4500 using finals_const_range = llvm::iterator_range<finals_const_iterator>;
4501
4503 return finals_range(getFinals().begin(), getFinals().end());
4504 }
4505
4507 return finals_const_range(getFinals().begin(), getFinals().end());
4508 }
4509
4513 llvm::iterator_range<used_expressions_iterator>;
4515 llvm::iterator_range<used_expressions_const_iterator>;
4516
4518 return finals_range(getUsedExprs().begin(), getUsedExprs().end());
4519 }
4520
4522 return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
4523 }
4524
4526 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4527 reinterpret_cast<Stmt **>(varlist_end()));
4528 }
4529
4531 auto Children = const_cast<OMPLinearClause *>(this)->children();
4532 return const_child_range(Children.begin(), Children.end());
4533 }
4534
4536
4538 auto Children = const_cast<OMPLinearClause *>(this)->used_children();
4539 return const_child_range(Children.begin(), Children.end());
4540 }
4541
4542 static bool classof(const OMPClause *T) {
4543 return T->getClauseKind() == llvm::omp::OMPC_linear;
4544 }
4545};
4546
4547/// This represents clause 'aligned' in the '#pragma omp ...'
4548/// directives.
4549///
4550/// \code
4551/// #pragma omp simd aligned(a,b : 8)
4552/// \endcode
4553/// In this example directive '#pragma omp simd' has clause 'aligned'
4554/// with variables 'a', 'b' and alignment '8'.
4556 : public OMPVarListClause<OMPAlignedClause>,
4557 private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
4558 friend class OMPClauseReader;
4559 friend OMPVarListClause;
4560 friend TrailingObjects;
4561
4562 /// Location of ':'.
4563 SourceLocation ColonLoc;
4564
4565 /// Sets the alignment for clause.
4566 void setAlignment(Expr *A) { *varlist_end() = A; }
4567
4568 /// Build 'aligned' clause with given number of variables \a NumVars.
4569 ///
4570 /// \param StartLoc Starting location of the clause.
4571 /// \param LParenLoc Location of '('.
4572 /// \param ColonLoc Location of ':'.
4573 /// \param EndLoc Ending location of the clause.
4574 /// \param NumVars Number of variables.
4576 SourceLocation ColonLoc, SourceLocation EndLoc,
4577 unsigned NumVars)
4578 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, StartLoc,
4579 LParenLoc, EndLoc, NumVars),
4580 ColonLoc(ColonLoc) {}
4581
4582 /// Build an empty clause.
4583 ///
4584 /// \param NumVars Number of variables.
4585 explicit OMPAlignedClause(unsigned NumVars)
4586 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned,
4587 SourceLocation(), SourceLocation(),
4588 SourceLocation(), NumVars) {}
4589
4590public:
4591 /// Creates clause with a list of variables \a VL and alignment \a A.
4592 ///
4593 /// \param C AST Context.
4594 /// \param StartLoc Starting location of the clause.
4595 /// \param LParenLoc Location of '('.
4596 /// \param ColonLoc Location of ':'.
4597 /// \param EndLoc Ending location of the clause.
4598 /// \param VL List of references to the variables.
4599 /// \param A Alignment.
4600 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
4601 SourceLocation LParenLoc,
4602 SourceLocation ColonLoc,
4603 SourceLocation EndLoc, ArrayRef<Expr *> VL,
4604 Expr *A);
4605
4606 /// Creates an empty clause with the place for \a NumVars variables.
4607 ///
4608 /// \param C AST context.
4609 /// \param NumVars Number of variables.
4610 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
4611
4612 /// Sets the location of ':'.
4613 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4614
4615 /// Returns the location of ':'.
4616 SourceLocation getColonLoc() const { return ColonLoc; }
4617
4618 /// Returns alignment.
4620
4621 /// Returns alignment.
4622 const Expr *getAlignment() const { return *varlist_end(); }
4623
4625 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4626 reinterpret_cast<Stmt **>(varlist_end()));
4627 }
4628
4630 auto Children = const_cast<OMPAlignedClause *>(this)->children();
4631 return const_child_range(Children.begin(), Children.end());
4632 }
4633
4636 }
4639 }
4640
4641 static bool classof(const OMPClause *T) {
4642 return T->getClauseKind() == llvm::omp::OMPC_aligned;
4643 }
4644};
4645
4646/// This represents clause 'copyin' in the '#pragma omp ...' directives.
4647///
4648/// \code
4649/// #pragma omp parallel copyin(a,b)
4650/// \endcode
4651/// In this example directive '#pragma omp parallel' has clause 'copyin'
4652/// with the variables 'a' and 'b'.
4654 : public OMPVarListClause<OMPCopyinClause>,
4655 private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
4656 // Class has 3 additional tail allocated arrays:
4657 // 1. List of helper expressions for proper generation of assignment operation
4658 // required for copyin clause. This list represents sources.
4659 // 2. List of helper expressions for proper generation of assignment operation
4660 // required for copyin clause. This list represents destinations.
4661 // 3. List of helper expressions that represents assignment operation:
4662 // \code
4663 // DstExprs = SrcExprs;
4664 // \endcode
4665 // Required for proper codegen of propagation of master's thread values of
4666 // threadprivate variables to local instances of that variables in other
4667 // implicit threads.
4668
4669 friend class OMPClauseReader;