clang 19.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/// 'shedule', '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/// This represents 'allocator' clause in the '#pragma omp ...'
346/// directive.
347///
348/// \code
349/// #pragma omp allocate(a) allocator(omp_default_mem_alloc)
350/// \endcode
351/// In this example directive '#pragma omp allocate' has simple 'allocator'
352/// clause with the allocator 'omp_default_mem_alloc'.
354 : public OMPOneStmtClause<llvm::omp::OMPC_allocator, OMPClause> {
355 friend class OMPClauseReader;
356
357 /// Set allocator.
358 void setAllocator(Expr *A) { setStmt(A); }
359
360public:
361 /// Build 'allocator' clause with the given allocator.
362 ///
363 /// \param A Allocator.
364 /// \param StartLoc Starting location of the clause.
365 /// \param LParenLoc Location of '('.
366 /// \param EndLoc Ending location of the clause.
368 SourceLocation EndLoc)
369 : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {}
370
371 /// Build an empty clause.
373
374 /// Returns allocator.
375 Expr *getAllocator() const { return getStmtAs<Expr>(); }
376};
377
378/// This represents the 'align' clause in the '#pragma omp allocate'
379/// directive.
380///
381/// \code
382/// #pragma omp allocate(a) allocator(omp_default_mem_alloc) align(8)
383/// \endcode
384/// In this example directive '#pragma omp allocate' has simple 'allocator'
385/// clause with the allocator 'omp_default_mem_alloc' and align clause with
386/// value of 8.
387class OMPAlignClause final
388 : public OMPOneStmtClause<llvm::omp::OMPC_align, OMPClause> {
389 friend class OMPClauseReader;
390
391 /// Set alignment value.
392 void setAlignment(Expr *A) { setStmt(A); }
393
394 /// Build 'align' clause with the given alignment
395 ///
396 /// \param A Alignment value.
397 /// \param StartLoc Starting location of the clause.
398 /// \param LParenLoc Location of '('.
399 /// \param EndLoc Ending location of the clause.
400 OMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc,
401 SourceLocation EndLoc)
402 : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {}
403
404 /// Build an empty clause.
405 OMPAlignClause() : OMPOneStmtClause() {}
406
407public:
408 /// Build 'align' clause with the given alignment
409 ///
410 /// \param A Alignment value.
411 /// \param StartLoc Starting location of the clause.
412 /// \param LParenLoc Location of '('.
413 /// \param EndLoc Ending location of the clause.
414 static OMPAlignClause *Create(const ASTContext &C, Expr *A,
415 SourceLocation StartLoc,
416 SourceLocation LParenLoc,
417 SourceLocation EndLoc);
418
419 /// Returns alignment
420 Expr *getAlignment() const { return getStmtAs<Expr>(); }
421};
422
423/// This represents clause 'allocate' in the '#pragma omp ...' directives.
424///
425/// \code
426/// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
427/// \endcode
428/// In this example directive '#pragma omp parallel' has clause 'private'
429/// and clause 'allocate' for the variable 'a'.
431 : public OMPVarListClause<OMPAllocateClause>,
432 private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
433 friend class OMPClauseReader;
434 friend OMPVarListClause;
435 friend TrailingObjects;
436
437 /// Allocator specified in the clause, or 'nullptr' if the default one is
438 /// used.
439 Expr *Allocator = nullptr;
440 /// Position of the ':' delimiter in the clause;
441 SourceLocation ColonLoc;
442
443 /// Build clause with number of variables \a N.
444 ///
445 /// \param StartLoc Starting location of the clause.
446 /// \param LParenLoc Location of '('.
447 /// \param Allocator Allocator expression.
448 /// \param ColonLoc Location of ':' delimiter.
449 /// \param EndLoc Ending location of the clause.
450 /// \param N Number of the variables in the clause.
452 Expr *Allocator, SourceLocation ColonLoc,
453 SourceLocation EndLoc, unsigned N)
454 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate, StartLoc,
455 LParenLoc, EndLoc, N),
456 Allocator(Allocator), ColonLoc(ColonLoc) {}
457
458 /// Build an empty clause.
459 ///
460 /// \param N Number of variables.
461 explicit OMPAllocateClause(unsigned N)
462 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate,
464 SourceLocation(), N) {}
465
466 /// Sets location of ':' symbol in clause.
467 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
468
469 void setAllocator(Expr *A) { Allocator = A; }
470
471public:
472 /// Creates clause with a list of variables \a VL.
473 ///
474 /// \param C AST context.
475 /// \param StartLoc Starting location of the clause.
476 /// \param LParenLoc Location of '('.
477 /// \param Allocator Allocator expression.
478 /// \param ColonLoc Location of ':' delimiter.
479 /// \param EndLoc Ending location of the clause.
480 /// \param VL List of references to the variables.
481 static OMPAllocateClause *Create(const ASTContext &C, SourceLocation StartLoc,
482 SourceLocation LParenLoc, Expr *Allocator,
483 SourceLocation ColonLoc,
484 SourceLocation EndLoc, ArrayRef<Expr *> VL);
485
486 /// Returns the allocator expression or nullptr, if no allocator is specified.
487 Expr *getAllocator() const { return Allocator; }
488
489 /// Returns the location of the ':' delimiter.
490 SourceLocation getColonLoc() const { return ColonLoc; }
491
492 /// Creates an empty clause with the place for \a N variables.
493 ///
494 /// \param C AST context.
495 /// \param N The number of variables.
496 static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
497
499 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
500 reinterpret_cast<Stmt **>(varlist_end()));
501 }
502
504 auto Children = const_cast<OMPAllocateClause *>(this)->children();
505 return const_child_range(Children.begin(), Children.end());
506 }
507
510 }
513 }
514
515 static bool classof(const OMPClause *T) {
516 return T->getClauseKind() == llvm::omp::OMPC_allocate;
517 }
518};
519
520/// This represents 'if' clause in the '#pragma omp ...' directive.
521///
522/// \code
523/// #pragma omp parallel if(parallel:a > 5)
524/// \endcode
525/// In this example directive '#pragma omp parallel' has simple 'if' clause with
526/// condition 'a > 5' and directive name modifier 'parallel'.
528 friend class OMPClauseReader;
529
530 /// Location of '('.
531 SourceLocation LParenLoc;
532
533 /// Condition of the 'if' clause.
534 Stmt *Condition = nullptr;
535
536 /// Location of ':' (if any).
537 SourceLocation ColonLoc;
538
539 /// Directive name modifier for the clause.
540 OpenMPDirectiveKind NameModifier = llvm::omp::OMPD_unknown;
541
542 /// Name modifier location.
543 SourceLocation NameModifierLoc;
544
545 /// Set condition.
546 void setCondition(Expr *Cond) { Condition = Cond; }
547
548 /// Set directive name modifier for the clause.
549 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
550
551 /// Set location of directive name modifier for the clause.
552 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
553
554 /// Set location of ':'.
555 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
556
557public:
558 /// Build 'if' clause with condition \a Cond.
559 ///
560 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
561 /// \param Cond Condition of the clause.
562 /// \param HelperCond Helper condition for the clause.
563 /// \param CaptureRegion Innermost OpenMP region where expressions in this
564 /// clause must be captured.
565 /// \param StartLoc Starting location of the clause.
566 /// \param LParenLoc Location of '('.
567 /// \param NameModifierLoc Location of directive name modifier.
568 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
569 /// \param EndLoc Ending location of the clause.
570 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
571 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
572 SourceLocation LParenLoc, SourceLocation NameModifierLoc,
573 SourceLocation ColonLoc, SourceLocation EndLoc)
574 : OMPClause(llvm::omp::OMPC_if, StartLoc, EndLoc),
575 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond),
576 ColonLoc(ColonLoc), NameModifier(NameModifier),
577 NameModifierLoc(NameModifierLoc) {
578 setPreInitStmt(HelperCond, CaptureRegion);
579 }
580
581 /// Build an empty clause.
583 : OMPClause(llvm::omp::OMPC_if, SourceLocation(), SourceLocation()),
584 OMPClauseWithPreInit(this) {}
585
586 /// Sets the location of '('.
587 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
588
589 /// Returns the location of '('.
590 SourceLocation getLParenLoc() const { return LParenLoc; }
591
592 /// Return the location of ':'.
593 SourceLocation getColonLoc() const { return ColonLoc; }
594
595 /// Returns condition.
596 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
597
598 /// Return directive name modifier associated with the clause.
599 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
600
601 /// Return the location of directive name modifier.
602 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
603
605
608 }
609
612 auto Children = const_cast<OMPIfClause *>(this)->used_children();
613 return const_child_range(Children.begin(), Children.end());
614 }
615
616 static bool classof(const OMPClause *T) {
617 return T->getClauseKind() == llvm::omp::OMPC_if;
618 }
619};
620
621/// This represents 'final' clause in the '#pragma omp ...' directive.
622///
623/// \code
624/// #pragma omp task final(a > 5)
625/// \endcode
626/// In this example directive '#pragma omp task' has simple 'final'
627/// clause with condition 'a > 5'.
628class OMPFinalClause final
629 : public OMPOneStmtClause<llvm::omp::OMPC_final, OMPClause>,
630 public OMPClauseWithPreInit {
631 friend class OMPClauseReader;
632
633 /// Set condition.
634 void setCondition(Expr *Cond) { setStmt(Cond); }
635
636public:
637 /// Build 'final' clause with condition \a Cond.
638 ///
639 /// \param Cond Condition of the clause.
640 /// \param HelperCond Helper condition for the construct.
641 /// \param CaptureRegion Innermost OpenMP region where expressions in this
642 /// clause must be captured.
643 /// \param StartLoc Starting location of the clause.
644 /// \param LParenLoc Location of '('.
645 /// \param EndLoc Ending location of the clause.
646 OMPFinalClause(Expr *Cond, Stmt *HelperCond,
647 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
648 SourceLocation LParenLoc, SourceLocation EndLoc)
649 : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc),
651 setPreInitStmt(HelperCond, CaptureRegion);
652 }
653
654 /// Build an empty clause.
656
657 /// Returns condition.
658 Expr *getCondition() const { return getStmtAs<Expr>(); }
659
662 auto Children = const_cast<OMPFinalClause *>(this)->used_children();
663 return const_child_range(Children.begin(), Children.end());
664 }
665};
666/// This represents 'num_threads' clause in the '#pragma omp ...'
667/// directive.
668///
669/// \code
670/// #pragma omp parallel num_threads(6)
671/// \endcode
672/// In this example directive '#pragma omp parallel' has simple 'num_threads'
673/// clause with number of threads '6'.
675 : public OMPOneStmtClause<llvm::omp::OMPC_num_threads, OMPClause>,
676 public OMPClauseWithPreInit {
677 friend class OMPClauseReader;
678
679 /// Set condition.
680 void setNumThreads(Expr *NThreads) { setStmt(NThreads); }
681
682public:
683 /// Build 'num_threads' clause with condition \a NumThreads.
684 ///
685 /// \param NumThreads Number of threads for the construct.
686 /// \param HelperNumThreads Helper Number of threads for the construct.
687 /// \param CaptureRegion Innermost OpenMP region where expressions in this
688 /// clause must be captured.
689 /// \param StartLoc Starting location of the clause.
690 /// \param LParenLoc Location of '('.
691 /// \param EndLoc Ending location of the clause.
692 OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
693 OpenMPDirectiveKind CaptureRegion,
694 SourceLocation StartLoc, SourceLocation LParenLoc,
695 SourceLocation EndLoc)
696 : OMPOneStmtClause(NumThreads, StartLoc, LParenLoc, EndLoc),
698 setPreInitStmt(HelperNumThreads, CaptureRegion);
699 }
700
701 /// Build an empty clause.
703
704 /// Returns number of threads.
705 Expr *getNumThreads() const { return getStmtAs<Expr>(); }
706};
707
708/// This represents 'safelen' clause in the '#pragma omp ...'
709/// directive.
710///
711/// \code
712/// #pragma omp simd safelen(4)
713/// \endcode
714/// In this example directive '#pragma omp simd' has clause 'safelen'
715/// with single expression '4'.
716/// If the safelen clause is used then no two iterations executed
717/// concurrently with SIMD instructions can have a greater distance
718/// in the logical iteration space than its value. The parameter of
719/// the safelen clause must be a constant positive integer expression.
721 : public OMPOneStmtClause<llvm::omp::OMPC_safelen, OMPClause> {
722 friend class OMPClauseReader;
723
724 /// Set safelen.
725 void setSafelen(Expr *Len) { setStmt(Len); }
726
727public:
728 /// Build 'safelen' clause.
729 ///
730 /// \param Len Expression associated with this clause.
731 /// \param StartLoc Starting location of the clause.
732 /// \param EndLoc Ending location of the clause.
734 SourceLocation EndLoc)
735 : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {}
736
737 /// Build an empty clause.
739
740 /// Return safe iteration space distance.
741 Expr *getSafelen() const { return getStmtAs<Expr>(); }
742};
743
744/// This represents 'simdlen' clause in the '#pragma omp ...'
745/// directive.
746///
747/// \code
748/// #pragma omp simd simdlen(4)
749/// \endcode
750/// In this example directive '#pragma omp simd' has clause 'simdlen'
751/// with single expression '4'.
752/// If the 'simdlen' clause is used then it specifies the preferred number of
753/// iterations to be executed concurrently. The parameter of the 'simdlen'
754/// clause must be a constant positive integer expression.
756 : public OMPOneStmtClause<llvm::omp::OMPC_simdlen, OMPClause> {
757 friend class OMPClauseReader;
758
759 /// Set simdlen.
760 void setSimdlen(Expr *Len) { setStmt(Len); }
761
762public:
763 /// Build 'simdlen' clause.
764 ///
765 /// \param Len Expression associated with this clause.
766 /// \param StartLoc Starting location of the clause.
767 /// \param EndLoc Ending location of the clause.
769 SourceLocation EndLoc)
770 : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {}
771
772 /// Build an empty clause.
774
775 /// Return safe iteration space distance.
776 Expr *getSimdlen() const { return getStmtAs<Expr>(); }
777};
778
779/// This represents the 'sizes' clause in the '#pragma omp tile' directive.
780///
781/// \code
782/// #pragma omp tile sizes(5,5)
783/// for (int i = 0; i < 64; ++i)
784/// for (int j = 0; j < 64; ++j)
785/// \endcode
786class OMPSizesClause final
787 : public OMPClause,
788 private llvm::TrailingObjects<OMPSizesClause, Expr *> {
789 friend class OMPClauseReader;
790 friend class llvm::TrailingObjects<OMPSizesClause, Expr *>;
791
792 /// Location of '('.
793 SourceLocation LParenLoc;
794
795 /// Number of tile sizes in the clause.
796 unsigned NumSizes;
797
798 /// Build an empty clause.
799 explicit OMPSizesClause(int NumSizes)
800 : OMPClause(llvm::omp::OMPC_sizes, SourceLocation(), SourceLocation()),
801 NumSizes(NumSizes) {}
802
803public:
804 /// Build a 'sizes' AST node.
805 ///
806 /// \param C Context of the AST.
807 /// \param StartLoc Location of the 'sizes' identifier.
808 /// \param LParenLoc Location of '('.
809 /// \param EndLoc Location of ')'.
810 /// \param Sizes Content of the clause.
811 static OMPSizesClause *Create(const ASTContext &C, SourceLocation StartLoc,
812 SourceLocation LParenLoc, SourceLocation EndLoc,
813 ArrayRef<Expr *> Sizes);
814
815 /// Build an empty 'sizes' AST node for deserialization.
816 ///
817 /// \param C Context of the AST.
818 /// \param NumSizes Number of items in the clause.
819 static OMPSizesClause *CreateEmpty(const ASTContext &C, unsigned NumSizes);
820
821 /// Sets the location of '('.
822 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
823
824 /// Returns the location of '('.
825 SourceLocation getLParenLoc() const { return LParenLoc; }
826
827 /// Returns the number of list items.
828 unsigned getNumSizes() const { return NumSizes; }
829
830 /// Returns the tile size expressions.
832 return MutableArrayRef<Expr *>(static_cast<OMPSizesClause *>(this)
833 ->template getTrailingObjects<Expr *>(),
834 NumSizes);
835 }
837 return ArrayRef<Expr *>(static_cast<const OMPSizesClause *>(this)
838 ->template getTrailingObjects<Expr *>(),
839 NumSizes);
840 }
841
842 /// Sets the tile size expressions.
844 assert(VL.size() == NumSizes);
845 std::copy(VL.begin(), VL.end(),
846 static_cast<OMPSizesClause *>(this)
847 ->template getTrailingObjects<Expr *>());
848 }
849
852 return child_range(reinterpret_cast<Stmt **>(Sizes.begin()),
853 reinterpret_cast<Stmt **>(Sizes.end()));
854 }
857 return const_child_range(reinterpret_cast<Stmt *const *>(Sizes.begin()),
858 reinterpret_cast<Stmt *const *>(Sizes.end()));
859 }
860
863 }
866 }
867
868 static bool classof(const OMPClause *T) {
869 return T->getClauseKind() == llvm::omp::OMPC_sizes;
870 }
871};
872
873/// Representation of the 'full' clause of the '#pragma omp unroll' directive.
874///
875/// \code
876/// #pragma omp unroll full
877/// for (int i = 0; i < 64; ++i)
878/// \endcode
879class OMPFullClause final : public OMPNoChildClause<llvm::omp::OMPC_full> {
880 friend class OMPClauseReader;
881
882 /// Build an empty clause.
883 explicit OMPFullClause() : OMPNoChildClause() {}
884
885public:
886 /// Build an AST node for a 'full' clause.
887 ///
888 /// \param C Context of the AST.
889 /// \param StartLoc Starting location of the clause.
890 /// \param EndLoc Ending location of the clause.
891 static OMPFullClause *Create(const ASTContext &C, SourceLocation StartLoc,
892 SourceLocation EndLoc);
893
894 /// Build an empty 'full' AST node for deserialization.
895 ///
896 /// \param C Context of the AST.
897 static OMPFullClause *CreateEmpty(const ASTContext &C);
898};
899
900/// Representation of the 'partial' clause of the '#pragma omp unroll'
901/// directive.
902///
903/// \code
904/// #pragma omp unroll partial(4)
905/// for (int i = start; i < end; ++i)
906/// \endcode
907class OMPPartialClause final : public OMPClause {
908 friend class OMPClauseReader;
909
910 /// Location of '('.
911 SourceLocation LParenLoc;
912
913 /// Optional argument to the clause (unroll factor).
914 Stmt *Factor;
915
916 /// Build an empty clause.
917 explicit OMPPartialClause() : OMPClause(llvm::omp::OMPC_partial, {}, {}) {}
918
919 /// Set the unroll factor.
920 void setFactor(Expr *E) { Factor = E; }
921
922 /// Sets the location of '('.
923 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
924
925public:
926 /// Build an AST node for a 'partial' clause.
927 ///
928 /// \param C Context of the AST.
929 /// \param StartLoc Location of the 'partial' identifier.
930 /// \param LParenLoc Location of '('.
931 /// \param EndLoc Location of ')'.
932 /// \param Factor Clause argument.
933 static OMPPartialClause *Create(const ASTContext &C, SourceLocation StartLoc,
934 SourceLocation LParenLoc,
935 SourceLocation EndLoc, Expr *Factor);
936
937 /// Build an empty 'partial' AST node for deserialization.
938 ///
939 /// \param C Context of the AST.
940 static OMPPartialClause *CreateEmpty(const ASTContext &C);
941
942 /// Returns the location of '('.
943 SourceLocation getLParenLoc() const { return LParenLoc; }
944
945 /// Returns the argument of the clause or nullptr if not set.
946 Expr *getFactor() const { return cast_or_null<Expr>(Factor); }
947
948 child_range children() { return child_range(&Factor, &Factor + 1); }
950 return const_child_range(&Factor, &Factor + 1);
951 }
952
955 }
958 }
959
960 static bool classof(const OMPClause *T) {
961 return T->getClauseKind() == llvm::omp::OMPC_partial;
962 }
963};
964
965/// This represents 'collapse' clause in the '#pragma omp ...'
966/// directive.
967///
968/// \code
969/// #pragma omp simd collapse(3)
970/// \endcode
971/// In this example directive '#pragma omp simd' has clause 'collapse'
972/// with single expression '3'.
973/// The parameter must be a constant positive integer expression, it specifies
974/// the number of nested loops that should be collapsed into a single iteration
975/// space.
977 : public OMPOneStmtClause<llvm::omp::OMPC_collapse, OMPClause> {
978 friend class OMPClauseReader;
979
980 /// Set the number of associated for-loops.
981 void setNumForLoops(Expr *Num) { setStmt(Num); }
982
983public:
984 /// Build 'collapse' clause.
985 ///
986 /// \param Num Expression associated with this clause.
987 /// \param StartLoc Starting location of the clause.
988 /// \param LParenLoc Location of '('.
989 /// \param EndLoc Ending location of the clause.
991 SourceLocation LParenLoc, SourceLocation EndLoc)
992 : OMPOneStmtClause(Num, StartLoc, LParenLoc, EndLoc) {}
993
994 /// Build an empty clause.
996
997 /// Return the number of associated for-loops.
998 Expr *getNumForLoops() const { return getStmtAs<Expr>(); }
999};
1000
1001/// This represents 'default' clause in the '#pragma omp ...' directive.
1002///
1003/// \code
1004/// #pragma omp parallel default(shared)
1005/// \endcode
1006/// In this example directive '#pragma omp parallel' has simple 'default'
1007/// clause with kind 'shared'.
1009 friend class OMPClauseReader;
1010
1011 /// Location of '('.
1012 SourceLocation LParenLoc;
1013
1014 /// A kind of the 'default' clause.
1015 llvm::omp::DefaultKind Kind = llvm::omp::OMP_DEFAULT_unknown;
1016
1017 /// Start location of the kind in source code.
1018 SourceLocation KindKwLoc;
1019
1020 /// Set kind of the clauses.
1021 ///
1022 /// \param K Argument of clause.
1023 void setDefaultKind(llvm::omp::DefaultKind K) { Kind = K; }
1024
1025 /// Set argument location.
1026 ///
1027 /// \param KLoc Argument location.
1028 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1029
1030public:
1031 /// Build 'default' clause with argument \a A ('none' or 'shared').
1032 ///
1033 /// \param A Argument of the clause ('none' or 'shared').
1034 /// \param ALoc Starting location of the argument.
1035 /// \param StartLoc Starting location of the clause.
1036 /// \param LParenLoc Location of '('.
1037 /// \param EndLoc Ending location of the clause.
1038 OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc,
1039 SourceLocation StartLoc, SourceLocation LParenLoc,
1040 SourceLocation EndLoc)
1041 : OMPClause(llvm::omp::OMPC_default, StartLoc, EndLoc),
1042 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1043
1044 /// Build an empty clause.
1046 : OMPClause(llvm::omp::OMPC_default, SourceLocation(), SourceLocation()) {
1047 }
1048
1049 /// Sets the location of '('.
1050 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1051
1052 /// Returns the location of '('.
1053 SourceLocation getLParenLoc() const { return LParenLoc; }
1054
1055 /// Returns kind of the clause.
1056 llvm::omp::DefaultKind getDefaultKind() const { return Kind; }
1057
1058 /// Returns location of clause kind.
1059 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
1060
1063 }
1064
1067 }
1068
1071 }
1074 }
1075
1076 static bool classof(const OMPClause *T) {
1077 return T->getClauseKind() == llvm::omp::OMPC_default;
1078 }
1079};
1080
1081/// This represents 'proc_bind' clause in the '#pragma omp ...'
1082/// directive.
1083///
1084/// \code
1085/// #pragma omp parallel proc_bind(master)
1086/// \endcode
1087/// In this example directive '#pragma omp parallel' has simple 'proc_bind'
1088/// clause with kind 'master'.
1090 friend class OMPClauseReader;
1091
1092 /// Location of '('.
1093 SourceLocation LParenLoc;
1094
1095 /// A kind of the 'proc_bind' clause.
1096 llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown;
1097
1098 /// Start location of the kind in source code.
1099 SourceLocation KindKwLoc;
1100
1101 /// Set kind of the clause.
1102 ///
1103 /// \param K Kind of clause.
1104 void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; }
1105
1106 /// Set clause kind location.
1107 ///
1108 /// \param KLoc Kind location.
1109 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1110
1111public:
1112 /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
1113 /// 'spread').
1114 ///
1115 /// \param A Argument of the clause ('master', 'close' or 'spread').
1116 /// \param ALoc Starting location of the argument.
1117 /// \param StartLoc Starting location of the clause.
1118 /// \param LParenLoc Location of '('.
1119 /// \param EndLoc Ending location of the clause.
1120 OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc,
1121 SourceLocation StartLoc, SourceLocation LParenLoc,
1122 SourceLocation EndLoc)
1123 : OMPClause(llvm::omp::OMPC_proc_bind, StartLoc, EndLoc),
1124 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1125
1126 /// Build an empty clause.
1128 : OMPClause(llvm::omp::OMPC_proc_bind, SourceLocation(),
1129 SourceLocation()) {}
1130
1131 /// Sets the location of '('.
1132 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1133
1134 /// Returns the location of '('.
1135 SourceLocation getLParenLoc() const { return LParenLoc; }
1136
1137 /// Returns kind of the clause.
1138 llvm::omp::ProcBindKind getProcBindKind() const { return Kind; }
1139
1140 /// Returns location of clause kind.
1141 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
1142
1145 }
1146
1149 }
1150
1153 }
1156 }
1157
1158 static bool classof(const OMPClause *T) {
1159 return T->getClauseKind() == llvm::omp::OMPC_proc_bind;
1160 }
1161};
1162
1163/// This represents 'unified_address' clause in the '#pragma omp requires'
1164/// directive.
1165///
1166/// \code
1167/// #pragma omp requires unified_address
1168/// \endcode
1169/// In this example directive '#pragma omp requires' has 'unified_address'
1170/// clause.
1172 : public OMPNoChildClause<llvm::omp::OMPC_unified_address> {
1173public:
1174 friend class OMPClauseReader;
1175 /// Build 'unified_address' clause.
1176 ///
1177 /// \param StartLoc Starting location of the clause.
1178 /// \param EndLoc Ending location of the clause.
1180 : OMPNoChildClause(StartLoc, EndLoc) {}
1181
1182 /// Build an empty clause.
1184};
1185
1186/// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
1187/// directive.
1188///
1189/// \code
1190/// #pragma omp requires unified_shared_memory
1191/// \endcode
1192/// In this example directive '#pragma omp requires' has 'unified_shared_memory'
1193/// clause.
1195public:
1196 friend class OMPClauseReader;
1197 /// Build 'unified_shared_memory' clause.
1198 ///
1199 /// \param StartLoc Starting location of the clause.
1200 /// \param EndLoc Ending location of the clause.
1202 : OMPClause(llvm::omp::OMPC_unified_shared_memory, StartLoc, EndLoc) {}
1203
1204 /// Build an empty clause.
1206 : OMPClause(llvm::omp::OMPC_unified_shared_memory, SourceLocation(),
1207 SourceLocation()) {}
1208
1211 }
1212
1215 }
1216
1219 }
1222 }
1223
1224 static bool classof(const OMPClause *T) {
1225 return T->getClauseKind() == llvm::omp::OMPC_unified_shared_memory;
1226 }
1227};
1228
1229/// This represents 'reverse_offload' clause in the '#pragma omp requires'
1230/// directive.
1231///
1232/// \code
1233/// #pragma omp requires reverse_offload
1234/// \endcode
1235/// In this example directive '#pragma omp requires' has 'reverse_offload'
1236/// clause.
1238public:
1239 friend class OMPClauseReader;
1240 /// Build 'reverse_offload' clause.
1241 ///
1242 /// \param StartLoc Starting location of the clause.
1243 /// \param EndLoc Ending location of the clause.
1245 : OMPClause(llvm::omp::OMPC_reverse_offload, StartLoc, EndLoc) {}
1246
1247 /// Build an empty clause.
1249 : OMPClause(llvm::omp::OMPC_reverse_offload, SourceLocation(),
1250 SourceLocation()) {}
1251
1254 }
1255
1258 }
1259
1262 }
1265 }
1266
1267 static bool classof(const OMPClause *T) {
1268 return T->getClauseKind() == llvm::omp::OMPC_reverse_offload;
1269 }
1270};
1271
1272/// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
1273/// directive.
1274///
1275/// \code
1276/// #pragma omp requires dynamic_allocators
1277/// \endcode
1278/// In this example directive '#pragma omp requires' has 'dynamic_allocators'
1279/// clause.
1281public:
1282 friend class OMPClauseReader;
1283 /// Build 'dynamic_allocators' clause.
1284 ///
1285 /// \param StartLoc Starting location of the clause.
1286 /// \param EndLoc Ending location of the clause.
1288 : OMPClause(llvm::omp::OMPC_dynamic_allocators, StartLoc, EndLoc) {}
1289
1290 /// Build an empty clause.
1292 : OMPClause(llvm::omp::OMPC_dynamic_allocators, SourceLocation(),
1293 SourceLocation()) {}
1294
1297 }
1298
1301 }
1302
1305 }
1308 }
1309
1310 static bool classof(const OMPClause *T) {
1311 return T->getClauseKind() == llvm::omp::OMPC_dynamic_allocators;
1312 }
1313};
1314
1315/// This represents 'atomic_default_mem_order' clause in the '#pragma omp
1316/// requires' directive.
1317///
1318/// \code
1319/// #pragma omp requires atomic_default_mem_order(seq_cst)
1320/// \endcode
1321/// In this example directive '#pragma omp requires' has simple
1322/// atomic_default_mem_order' clause with kind 'seq_cst'.
1324 friend class OMPClauseReader;
1325
1326 /// Location of '('
1327 SourceLocation LParenLoc;
1328
1329 /// A kind of the 'atomic_default_mem_order' clause.
1332
1333 /// Start location of the kind in source code.
1334 SourceLocation KindKwLoc;
1335
1336 /// Set kind of the clause.
1337 ///
1338 /// \param K Kind of clause.
1339 void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
1340 Kind = K;
1341 }
1342
1343 /// Set clause kind location.
1344 ///
1345 /// \param KLoc Kind location.
1346 void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
1347 KindKwLoc = KLoc;
1348 }
1349
1350public:
1351 /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
1352 /// 'acq_rel' or 'relaxed').
1353 ///
1354 /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
1355 /// \param ALoc Starting location of the argument.
1356 /// \param StartLoc Starting location of the clause.
1357 /// \param LParenLoc Location of '('.
1358 /// \param EndLoc Ending location of the clause.
1360 SourceLocation ALoc, SourceLocation StartLoc,
1361 SourceLocation LParenLoc,
1362 SourceLocation EndLoc)
1363 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, StartLoc, EndLoc),
1364 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1365
1366 /// Build an empty clause.
1368 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, SourceLocation(),
1369 SourceLocation()) {}
1370
1371 /// Sets the location of '('.
1372 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1373
1374 /// Returns the locaiton of '('.
1375 SourceLocation getLParenLoc() const { return LParenLoc; }
1376
1377 /// Returns kind of the clause.
1379 return Kind;
1380 }
1381
1382 /// Returns location of clause kind.
1384
1387 }
1388
1391 }
1392
1395 }
1398 }
1399
1400 static bool classof(const OMPClause *T) {
1401 return T->getClauseKind() == llvm::omp::OMPC_atomic_default_mem_order;
1402 }
1403};
1404
1405/// This represents 'at' clause in the '#pragma omp error' directive
1406///
1407/// \code
1408/// #pragma omp error at(compilation)
1409/// \endcode
1410/// In this example directive '#pragma omp error' has simple
1411/// 'at' clause with kind 'complilation'.
1412class OMPAtClause final : public OMPClause {
1413 friend class OMPClauseReader;
1414
1415 /// Location of '('
1416 SourceLocation LParenLoc;
1417
1418 /// A kind of the 'at' clause.
1420
1421 /// Start location of the kind in source code.
1422 SourceLocation KindKwLoc;
1423
1424 /// Set kind of the clause.
1425 ///
1426 /// \param K Kind of clause.
1427 void setAtKind(OpenMPAtClauseKind K) { Kind = K; }
1428
1429 /// Set clause kind location.
1430 ///
1431 /// \param KLoc Kind location.
1432 void setAtKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1433
1434 /// Sets the location of '('.
1435 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1436
1437public:
1438 /// Build 'at' clause with argument \a A ('compilation' or 'execution').
1439 ///
1440 /// \param A Argument of the clause ('compilation' or 'execution').
1441 /// \param ALoc Starting location of the argument.
1442 /// \param StartLoc Starting location of the clause.
1443 /// \param LParenLoc Location of '('.
1444 /// \param EndLoc Ending location of the clause.
1446 SourceLocation StartLoc, SourceLocation LParenLoc,
1447 SourceLocation EndLoc)
1448 : OMPClause(llvm::omp::OMPC_at, StartLoc, EndLoc), LParenLoc(LParenLoc),
1449 Kind(A), KindKwLoc(ALoc) {}
1450
1451 /// Build an empty clause.
1453 : OMPClause(llvm::omp::OMPC_at, SourceLocation(), SourceLocation()) {}
1454
1455 /// Returns the locaiton of '('.
1456 SourceLocation getLParenLoc() const { return LParenLoc; }
1457
1458 /// Returns kind of the clause.
1460
1461 /// Returns location of clause kind.
1462 SourceLocation getAtKindKwLoc() const { return KindKwLoc; }
1463
1466 }
1467
1470 }
1471
1474 }
1477 }
1478
1479 static bool classof(const OMPClause *T) {
1480 return T->getClauseKind() == llvm::omp::OMPC_at;
1481 }
1482};
1483
1484/// This represents 'severity' clause in the '#pragma omp error' directive
1485///
1486/// \code
1487/// #pragma omp error severity(fatal)
1488/// \endcode
1489/// In this example directive '#pragma omp error' has simple
1490/// 'severity' clause with kind 'fatal'.
1491class OMPSeverityClause final : public OMPClause {
1492 friend class OMPClauseReader;
1493
1494 /// Location of '('
1495 SourceLocation LParenLoc;
1496
1497 /// A kind of the 'severity' clause.
1499
1500 /// Start location of the kind in source code.
1501 SourceLocation KindKwLoc;
1502
1503 /// Set kind of the clause.
1504 ///
1505 /// \param K Kind of clause.
1506 void setSeverityKind(OpenMPSeverityClauseKind K) { Kind = K; }
1507
1508 /// Set clause kind location.
1509 ///
1510 /// \param KLoc Kind location.
1511 void setSeverityKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1512
1513 /// Sets the location of '('.
1514 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1515
1516public:
1517 /// Build 'severity' clause with argument \a A ('fatal' or 'warning').
1518 ///
1519 /// \param A Argument of the clause ('fatal' or 'warning').
1520 /// \param ALoc Starting location of the argument.
1521 /// \param StartLoc Starting location of the clause.
1522 /// \param LParenLoc Location of '('.
1523 /// \param EndLoc Ending location of the clause.
1525 SourceLocation StartLoc, SourceLocation LParenLoc,
1526 SourceLocation EndLoc)
1527 : OMPClause(llvm::omp::OMPC_severity, StartLoc, EndLoc),
1528 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1529
1530 /// Build an empty clause.
1532 : OMPClause(llvm::omp::OMPC_severity, SourceLocation(),
1533 SourceLocation()) {}
1534
1535 /// Returns the locaiton of '('.
1536 SourceLocation getLParenLoc() const { return LParenLoc; }
1537
1538 /// Returns kind of the clause.
1540
1541 /// Returns location of clause kind.
1542 SourceLocation getSeverityKindKwLoc() const { return KindKwLoc; }
1543
1546 }
1547
1550 }
1551
1554 }
1557 }
1558
1559 static bool classof(const OMPClause *T) {
1560 return T->getClauseKind() == llvm::omp::OMPC_severity;
1561 }
1562};
1563
1564/// This represents 'message' clause in the '#pragma omp error' directive
1565///
1566/// \code
1567/// #pragma omp error message("GNU compiler required.")
1568/// \endcode
1569/// In this example directive '#pragma omp error' has simple
1570/// 'message' clause with user error message of "GNU compiler required.".
1571class OMPMessageClause final : public OMPClause {
1572 friend class OMPClauseReader;
1573
1574 /// Location of '('
1575 SourceLocation LParenLoc;
1576
1577 // Expression of the 'message' clause.
1578 Stmt *MessageString = nullptr;
1579
1580 /// Set message string of the clause.
1581 void setMessageString(Expr *MS) { MessageString = MS; }
1582
1583 /// Sets the location of '('.
1584 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1585
1586public:
1587 /// Build 'message' clause with message string argument
1588 ///
1589 /// \param MS Argument of the clause (message string).
1590 /// \param StartLoc Starting location of the clause.
1591 /// \param LParenLoc Location of '('.
1592 /// \param EndLoc Ending location of the clause.
1594 SourceLocation EndLoc)
1595 : OMPClause(llvm::omp::OMPC_message, StartLoc, EndLoc),
1596 LParenLoc(LParenLoc), MessageString(MS) {}
1597
1598 /// Build an empty clause.
1600 : OMPClause(llvm::omp::OMPC_message, SourceLocation(), SourceLocation()) {
1601 }
1602
1603 /// Returns the locaiton of '('.
1604 SourceLocation getLParenLoc() const { return LParenLoc; }
1605
1606 /// Returns message string of the clause.
1607 Expr *getMessageString() const { return cast_or_null<Expr>(MessageString); }
1608
1610 return child_range(&MessageString, &MessageString + 1);
1611 }
1612
1614 return const_child_range(&MessageString, &MessageString + 1);
1615 }
1616
1619 }
1620
1623 }
1624
1625 static bool classof(const OMPClause *T) {
1626 return T->getClauseKind() == llvm::omp::OMPC_message;
1627 }
1628};
1629
1630/// This represents 'schedule' clause in the '#pragma omp ...' directive.
1631///
1632/// \code
1633/// #pragma omp for schedule(static, 3)
1634/// \endcode
1635/// In this example directive '#pragma omp for' has 'schedule' clause with
1636/// arguments 'static' and '3'.
1638 friend class OMPClauseReader;
1639
1640 /// Location of '('.
1641 SourceLocation LParenLoc;
1642
1643 /// A kind of the 'schedule' clause.
1645
1646 /// Modifiers for 'schedule' clause.
1647 enum {FIRST, SECOND, NUM_MODIFIERS};
1648 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
1649
1650 /// Locations of modifiers.
1651 SourceLocation ModifiersLoc[NUM_MODIFIERS];
1652
1653 /// Start location of the schedule ind in source code.
1654 SourceLocation KindLoc;
1655
1656 /// Location of ',' (if any).
1657 SourceLocation CommaLoc;
1658
1659 /// Chunk size.
1660 Expr *ChunkSize = nullptr;
1661
1662 /// Set schedule kind.
1663 ///
1664 /// \param K Schedule kind.
1665 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
1666
1667 /// Set the first schedule modifier.
1668 ///
1669 /// \param M Schedule modifier.
1670 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
1671 Modifiers[FIRST] = M;
1672 }
1673
1674 /// Set the second schedule modifier.
1675 ///
1676 /// \param M Schedule modifier.
1677 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
1678 Modifiers[SECOND] = M;
1679 }
1680
1681 /// Set location of the first schedule modifier.
1682 void setFirstScheduleModifierLoc(SourceLocation Loc) {
1683 ModifiersLoc[FIRST] = Loc;
1684 }
1685
1686 /// Set location of the second schedule modifier.
1687 void setSecondScheduleModifierLoc(SourceLocation Loc) {
1688 ModifiersLoc[SECOND] = Loc;
1689 }
1690
1691 /// Set schedule modifier location.
1692 ///
1693 /// \param M Schedule modifier location.
1694 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
1695 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
1696 Modifiers[FIRST] = M;
1697 else {
1698 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
1699 Modifiers[SECOND] = M;
1700 }
1701 }
1702
1703 /// Sets the location of '('.
1704 ///
1705 /// \param Loc Location of '('.
1706 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1707
1708 /// Set schedule kind start location.
1709 ///
1710 /// \param KLoc Schedule kind location.
1711 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1712
1713 /// Set location of ','.
1714 ///
1715 /// \param Loc Location of ','.
1716 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
1717
1718 /// Set chunk size.
1719 ///
1720 /// \param E Chunk size.
1721 void setChunkSize(Expr *E) { ChunkSize = E; }
1722
1723public:
1724 /// Build 'schedule' clause with schedule kind \a Kind and chunk size
1725 /// expression \a ChunkSize.
1726 ///
1727 /// \param StartLoc Starting location of the clause.
1728 /// \param LParenLoc Location of '('.
1729 /// \param KLoc Starting location of the argument.
1730 /// \param CommaLoc Location of ','.
1731 /// \param EndLoc Ending location of the clause.
1732 /// \param Kind Schedule kind.
1733 /// \param ChunkSize Chunk size.
1734 /// \param HelperChunkSize Helper chunk size for combined directives.
1735 /// \param M1 The first modifier applied to 'schedule' clause.
1736 /// \param M1Loc Location of the first modifier
1737 /// \param M2 The second modifier applied to 'schedule' clause.
1738 /// \param M2Loc Location of the second modifier
1740 SourceLocation KLoc, SourceLocation CommaLoc,
1742 Expr *ChunkSize, Stmt *HelperChunkSize,
1745 : OMPClause(llvm::omp::OMPC_schedule, StartLoc, EndLoc),
1746 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
1747 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
1748 setPreInitStmt(HelperChunkSize);
1749 Modifiers[FIRST] = M1;
1750 Modifiers[SECOND] = M2;
1751 ModifiersLoc[FIRST] = M1Loc;
1752 ModifiersLoc[SECOND] = M2Loc;
1753 }
1754
1755 /// Build an empty clause.
1757 : OMPClause(llvm::omp::OMPC_schedule, SourceLocation(), SourceLocation()),
1758 OMPClauseWithPreInit(this) {
1759 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
1760 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
1761 }
1762
1763 /// Get kind of the clause.
1765
1766 /// Get the first modifier of the clause.
1768 return Modifiers[FIRST];
1769 }
1770
1771 /// Get the second modifier of the clause.
1773 return Modifiers[SECOND];
1774 }
1775
1776 /// Get location of '('.
1777 SourceLocation getLParenLoc() { return LParenLoc; }
1778
1779 /// Get kind location.
1781
1782 /// Get the first modifier location.
1784 return ModifiersLoc[FIRST];
1785 }
1786
1787 /// Get the second modifier location.
1789 return ModifiersLoc[SECOND];
1790 }
1791
1792 /// Get location of ','.
1793 SourceLocation getCommaLoc() { return CommaLoc; }
1794
1795 /// Get chunk size.
1796 Expr *getChunkSize() { return ChunkSize; }
1797
1798 /// Get chunk size.
1799 const Expr *getChunkSize() const { return ChunkSize; }
1800
1802 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
1803 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
1804 }
1805
1807 auto Children = const_cast<OMPScheduleClause *>(this)->children();
1808 return const_child_range(Children.begin(), Children.end());
1809 }
1810
1813 }
1816 }
1817
1818 static bool classof(const OMPClause *T) {
1819 return T->getClauseKind() == llvm::omp::OMPC_schedule;
1820 }
1821};
1822
1823/// This represents 'ordered' clause in the '#pragma omp ...' directive.
1824///
1825/// \code
1826/// #pragma omp for ordered (2)
1827/// \endcode
1828/// In this example directive '#pragma omp for' has 'ordered' clause with
1829/// parameter 2.
1831 : public OMPClause,
1832 private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
1833 friend class OMPClauseReader;
1834 friend TrailingObjects;
1835
1836 /// Location of '('.
1837 SourceLocation LParenLoc;
1838
1839 /// Number of for-loops.
1840 Stmt *NumForLoops = nullptr;
1841
1842 /// Real number of loops.
1843 unsigned NumberOfLoops = 0;
1844
1845 /// Build 'ordered' clause.
1846 ///
1847 /// \param Num Expression, possibly associated with this clause.
1848 /// \param NumLoops Number of loops, associated with this clause.
1849 /// \param StartLoc Starting location of the clause.
1850 /// \param LParenLoc Location of '('.
1851 /// \param EndLoc Ending location of the clause.
1852 OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
1853 SourceLocation LParenLoc, SourceLocation EndLoc)
1854 : OMPClause(llvm::omp::OMPC_ordered, StartLoc, EndLoc),
1855 LParenLoc(LParenLoc), NumForLoops(Num), NumberOfLoops(NumLoops) {}
1856
1857 /// Build an empty clause.
1858 explicit OMPOrderedClause(unsigned NumLoops)
1859 : OMPClause(llvm::omp::OMPC_ordered, SourceLocation(), SourceLocation()),
1860 NumberOfLoops(NumLoops) {}
1861
1862 /// Set the number of associated for-loops.
1863 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
1864
1865public:
1866 /// Build 'ordered' clause.
1867 ///
1868 /// \param Num Expression, possibly associated with this clause.
1869 /// \param NumLoops Number of loops, associated with this clause.
1870 /// \param StartLoc Starting location of the clause.
1871 /// \param LParenLoc Location of '('.
1872 /// \param EndLoc Ending location of the clause.
1873 static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
1874 unsigned NumLoops, SourceLocation StartLoc,
1875 SourceLocation LParenLoc,
1876 SourceLocation EndLoc);
1877
1878 /// Build an empty clause.
1879 static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
1880
1881 /// Sets the location of '('.
1882 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1883
1884 /// Returns the location of '('.
1885 SourceLocation getLParenLoc() const { return LParenLoc; }
1886
1887 /// Return the number of associated for-loops.
1888 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
1889
1890 /// Set number of iterations for the specified loop.
1891 void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
1892 /// Get number of iterations for all the loops.
1894
1895 /// Set loop counter for the specified loop.
1896 void setLoopCounter(unsigned NumLoop, Expr *Counter);
1897 /// Get loops counter for the specified loop.
1898 Expr *getLoopCounter(unsigned NumLoop);
1899 const Expr *getLoopCounter(unsigned NumLoop) const;
1900
1901 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1902
1904 return const_child_range(&NumForLoops, &NumForLoops + 1);
1905 }
1906
1909 }
1912 }
1913
1914 static bool classof(const OMPClause *T) {
1915 return T->getClauseKind() == llvm::omp::OMPC_ordered;
1916 }
1917};
1918
1919/// This represents 'nowait' clause in the '#pragma omp ...' directive.
1920///
1921/// \code
1922/// #pragma omp for nowait
1923/// \endcode
1924/// In this example directive '#pragma omp for' has 'nowait' clause.
1925class OMPNowaitClause final : public OMPNoChildClause<llvm::omp::OMPC_nowait> {
1926public:
1927 /// Build 'nowait' clause.
1928 ///
1929 /// \param StartLoc Starting location of the clause.
1930 /// \param EndLoc Ending location of the clause.
1932 SourceLocation EndLoc = SourceLocation())
1933 : OMPNoChildClause(StartLoc, EndLoc) {}
1934};
1935
1936/// This represents 'untied' clause in the '#pragma omp ...' directive.
1937///
1938/// \code
1939/// #pragma omp task untied
1940/// \endcode
1941/// In this example directive '#pragma omp task' has 'untied' clause.
1943public:
1944 /// Build 'untied' clause.
1945 ///
1946 /// \param StartLoc Starting location of the clause.
1947 /// \param EndLoc Ending location of the clause.
1949 : OMPClause(llvm::omp::OMPC_untied, StartLoc, EndLoc) {}
1950
1951 /// Build an empty clause.
1953 : OMPClause(llvm::omp::OMPC_untied, SourceLocation(), SourceLocation()) {}
1954
1957 }
1958
1961 }
1962
1965 }
1968 }
1969
1970 static bool classof(const OMPClause *T) {
1971 return T->getClauseKind() == llvm::omp::OMPC_untied;
1972 }
1973};
1974
1975/// This represents 'mergeable' clause in the '#pragma omp ...'
1976/// directive.
1977///
1978/// \code
1979/// #pragma omp task mergeable
1980/// \endcode
1981/// In this example directive '#pragma omp task' has 'mergeable' clause.
1983public:
1984 /// Build 'mergeable' clause.
1985 ///
1986 /// \param StartLoc Starting location of the clause.
1987 /// \param EndLoc Ending location of the clause.
1989 : OMPClause(llvm::omp::OMPC_mergeable, StartLoc, EndLoc) {}
1990
1991 /// Build an empty clause.
1993 : OMPClause(llvm::omp::OMPC_mergeable, SourceLocation(),
1994 SourceLocation()) {}
1995
1998 }
1999
2002 }
2003
2006 }
2009 }
2010
2011 static bool classof(const OMPClause *T) {
2012 return T->getClauseKind() == llvm::omp::OMPC_mergeable;
2013 }
2014};
2015
2016/// This represents 'read' clause in the '#pragma omp atomic' directive.
2017///
2018/// \code
2019/// #pragma omp atomic read
2020/// \endcode
2021/// In this example directive '#pragma omp atomic' has 'read' clause.
2022class OMPReadClause : public OMPClause {
2023public:
2024 /// Build 'read' clause.
2025 ///
2026 /// \param StartLoc Starting location of the clause.
2027 /// \param EndLoc Ending location of the clause.
2029 : OMPClause(llvm::omp::OMPC_read, StartLoc, EndLoc) {}
2030
2031 /// Build an empty clause.
2033 : OMPClause(llvm::omp::OMPC_read, SourceLocation(), SourceLocation()) {}
2034
2037 }
2038
2041 }
2042
2045 }
2048 }
2049
2050 static bool classof(const OMPClause *T) {
2051 return T->getClauseKind() == llvm::omp::OMPC_read;
2052 }
2053};
2054
2055/// This represents 'write' clause in the '#pragma omp atomic' directive.
2056///
2057/// \code
2058/// #pragma omp atomic write
2059/// \endcode
2060/// In this example directive '#pragma omp atomic' has 'write' clause.
2062public:
2063 /// Build 'write' clause.
2064 ///
2065 /// \param StartLoc Starting location of the clause.
2066 /// \param EndLoc Ending location of the clause.
2068 : OMPClause(llvm::omp::OMPC_write, StartLoc, EndLoc) {}
2069
2070 /// Build an empty clause.
2072 : OMPClause(llvm::omp::OMPC_write, SourceLocation(), SourceLocation()) {}
2073
2076 }
2077
2080 }
2081
2084 }
2087 }
2088
2089 static bool classof(const OMPClause *T) {
2090 return T->getClauseKind() == llvm::omp::OMPC_write;
2091 }
2092};
2093
2094/// This represents 'update' clause in the '#pragma omp atomic'
2095/// directive.
2096///
2097/// \code
2098/// #pragma omp atomic update
2099/// \endcode
2100/// In this example directive '#pragma omp atomic' has 'update' clause.
2101/// Also, this class represents 'update' clause in '#pragma omp depobj'
2102/// directive.
2103///
2104/// \code
2105/// #pragma omp depobj(a) update(in)
2106/// \endcode
2107/// In this example directive '#pragma omp depobj' has 'update' clause with 'in'
2108/// dependence kind.
2110 : public OMPClause,
2111 private llvm::TrailingObjects<OMPUpdateClause, SourceLocation,
2112 OpenMPDependClauseKind> {
2113 friend class OMPClauseReader;
2114 friend TrailingObjects;
2115
2116 /// true if extended version of the clause for 'depobj' directive.
2117 bool IsExtended = false;
2118
2119 /// Define the sizes of each trailing object array except the last one. This
2120 /// is required for TrailingObjects to work properly.
2121 size_t numTrailingObjects(OverloadToken<SourceLocation>) const {
2122 // 2 locations: for '(' and argument location.
2123 return IsExtended ? 2 : 0;
2124 }
2125
2126 /// Sets the location of '(' in clause for 'depobj' directive.
2127 void setLParenLoc(SourceLocation Loc) {
2128 assert(IsExtended && "Expected extended clause.");
2129 *getTrailingObjects<SourceLocation>() = Loc;
2130 }
2131
2132 /// Sets the location of '(' in clause for 'depobj' directive.
2133 void setArgumentLoc(SourceLocation Loc) {
2134 assert(IsExtended && "Expected extended clause.");
2135 *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc;
2136 }
2137
2138 /// Sets the dependence kind for the clause for 'depobj' directive.
2139 void setDependencyKind(OpenMPDependClauseKind DK) {
2140 assert(IsExtended && "Expected extended clause.");
2141 *getTrailingObjects<OpenMPDependClauseKind>() = DK;
2142 }
2143
2144 /// Build 'update' clause.
2145 ///
2146 /// \param StartLoc Starting location of the clause.
2147 /// \param EndLoc Ending location of the clause.
2148 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc,
2149 bool IsExtended)
2150 : OMPClause(llvm::omp::OMPC_update, StartLoc, EndLoc),
2151 IsExtended(IsExtended) {}
2152
2153 /// Build an empty clause.
2154 OMPUpdateClause(bool IsExtended)
2155 : OMPClause(llvm::omp::OMPC_update, SourceLocation(), SourceLocation()),
2156 IsExtended(IsExtended) {}
2157
2158public:
2159 /// Creates clause for 'atomic' directive.
2160 ///
2161 /// \param C AST context.
2162 /// \param StartLoc Starting location of the clause.
2163 /// \param EndLoc Ending location of the clause.
2164 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2165 SourceLocation EndLoc);
2166
2167 /// Creates clause for 'depobj' directive.
2168 ///
2169 /// \param C AST context.
2170 /// \param StartLoc Starting location of the clause.
2171 /// \param LParenLoc Location of '('.
2172 /// \param ArgumentLoc Location of the argument.
2173 /// \param DK Dependence kind.
2174 /// \param EndLoc Ending location of the clause.
2175 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2176 SourceLocation LParenLoc,
2177 SourceLocation ArgumentLoc,
2179 SourceLocation EndLoc);
2180
2181 /// Creates an empty clause with the place for \a N variables.
2182 ///
2183 /// \param C AST context.
2184 /// \param IsExtended true if extended clause for 'depobj' directive must be
2185 /// created.
2186 static OMPUpdateClause *CreateEmpty(const ASTContext &C, bool IsExtended);
2187
2188 /// Checks if the clause is the extended clauses for 'depobj' directive.
2189 bool isExtended() const { return IsExtended; }
2190
2193 }
2194
2197 }
2198
2201 }
2204 }
2205
2206 /// Gets the location of '(' in clause for 'depobj' directive.
2208 assert(IsExtended && "Expected extended clause.");
2209 return *getTrailingObjects<SourceLocation>();
2210 }
2211
2212 /// Gets the location of argument in clause for 'depobj' directive.
2214 assert(IsExtended && "Expected extended clause.");
2215 return *std::next(getTrailingObjects<SourceLocation>(), 1);
2216 }
2217
2218 /// Gets the dependence kind in clause for 'depobj' directive.
2220 assert(IsExtended && "Expected extended clause.");
2221 return *getTrailingObjects<OpenMPDependClauseKind>();
2222 }
2223
2224 static bool classof(const OMPClause *T) {
2225 return T->getClauseKind() == llvm::omp::OMPC_update;
2226 }
2227};
2228
2229/// This represents 'capture' clause in the '#pragma omp atomic'
2230/// directive.
2231///
2232/// \code
2233/// #pragma omp atomic capture
2234/// \endcode
2235/// In this example directive '#pragma omp atomic' has 'capture' clause.
2237public:
2238 /// Build 'capture' clause.
2239 ///
2240 /// \param StartLoc Starting location of the clause.
2241 /// \param EndLoc Ending location of the clause.
2243 : OMPClause(llvm::omp::OMPC_capture, StartLoc, EndLoc) {}
2244
2245 /// Build an empty clause.
2247 : OMPClause(llvm::omp::OMPC_capture, SourceLocation(), SourceLocation()) {
2248 }
2249
2252 }
2253
2256 }
2257
2260 }
2263 }
2264
2265 static bool classof(const OMPClause *T) {
2266 return T->getClauseKind() == llvm::omp::OMPC_capture;
2267 }
2268};
2269
2270/// This represents 'compare' clause in the '#pragma omp atomic'
2271/// directive.
2272///
2273/// \code
2274/// #pragma omp atomic compare
2275/// \endcode
2276/// In this example directive '#pragma omp atomic' has 'compare' clause.
2277class OMPCompareClause final : public OMPClause {
2278public:
2279 /// Build 'compare' clause.
2280 ///
2281 /// \param StartLoc Starting location of the clause.
2282 /// \param EndLoc Ending location of the clause.
2284 : OMPClause(llvm::omp::OMPC_compare, StartLoc, EndLoc) {}
2285
2286 /// Build an empty clause.
2288 : OMPClause(llvm::omp::OMPC_compare, SourceLocation(), SourceLocation()) {
2289 }
2290
2293 }
2294
2297 }
2298
2301 }
2304 }
2305
2306 static bool classof(const OMPClause *T) {
2307 return T->getClauseKind() == llvm::omp::OMPC_compare;
2308 }
2309};
2310
2311/// This represents 'seq_cst' clause in the '#pragma omp atomic'
2312/// directive.
2313///
2314/// \code
2315/// #pragma omp atomic seq_cst
2316/// \endcode
2317/// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
2319public:
2320 /// Build 'seq_cst' clause.
2321 ///
2322 /// \param StartLoc Starting location of the clause.
2323 /// \param EndLoc Ending location of the clause.
2325 : OMPClause(llvm::omp::OMPC_seq_cst, StartLoc, EndLoc) {}
2326
2327 /// Build an empty clause.
2329 : OMPClause(llvm::omp::OMPC_seq_cst, SourceLocation(), SourceLocation()) {
2330 }
2331
2334 }
2335
2338 }
2339
2342 }
2345 }
2346
2347 static bool classof(const OMPClause *T) {
2348 return T->getClauseKind() == llvm::omp::OMPC_seq_cst;
2349 }
2350};
2351
2352/// This represents 'acq_rel' clause in the '#pragma omp atomic|flush'
2353/// directives.
2354///
2355/// \code
2356/// #pragma omp flush acq_rel
2357/// \endcode
2358/// In this example directive '#pragma omp flush' has 'acq_rel' clause.
2359class OMPAcqRelClause final : public OMPClause {
2360public:
2361 /// Build 'ack_rel' clause.
2362 ///
2363 /// \param StartLoc Starting location of the clause.
2364 /// \param EndLoc Ending location of the clause.
2366 : OMPClause(llvm::omp::OMPC_acq_rel, StartLoc, EndLoc) {}
2367
2368 /// Build an empty clause.
2370 : OMPClause(llvm::omp::OMPC_acq_rel, SourceLocation(), SourceLocation()) {
2371 }
2372
2375 }
2376
2379 }
2380
2383 }
2386 }
2387
2388 static bool classof(const OMPClause *T) {
2389 return T->getClauseKind() == llvm::omp::OMPC_acq_rel;
2390 }
2391};
2392
2393/// This represents 'acquire' clause in the '#pragma omp atomic|flush'
2394/// directives.
2395///
2396/// \code
2397/// #pragma omp flush acquire
2398/// \endcode
2399/// In this example directive '#pragma omp flush' has 'acquire' clause.
2400class OMPAcquireClause final : public OMPClause {
2401public:
2402 /// Build 'acquire' clause.
2403 ///
2404 /// \param StartLoc Starting location of the clause.
2405 /// \param EndLoc Ending location of the clause.
2407 : OMPClause(llvm::omp::OMPC_acquire, StartLoc, EndLoc) {}
2408
2409 /// Build an empty clause.
2411 : OMPClause(llvm::omp::OMPC_acquire, SourceLocation(), SourceLocation()) {
2412 }
2413
2416 }
2417
2420 }
2421
2424 }
2427 }
2428
2429 static bool classof(const OMPClause *T) {
2430 return T->getClauseKind() == llvm::omp::OMPC_acquire;
2431 }
2432};
2433
2434/// This represents 'release' clause in the '#pragma omp atomic|flush'
2435/// directives.
2436///
2437/// \code
2438/// #pragma omp flush release
2439/// \endcode
2440/// In this example directive '#pragma omp flush' has 'release' clause.
2441class OMPReleaseClause final : public OMPClause {
2442public:
2443 /// Build 'release' clause.
2444 ///
2445 /// \param StartLoc Starting location of the clause.
2446 /// \param EndLoc Ending location of the clause.
2448 : OMPClause(llvm::omp::OMPC_release, StartLoc, EndLoc) {}
2449
2450 /// Build an empty clause.
2452 : OMPClause(llvm::omp::OMPC_release, SourceLocation(), SourceLocation()) {
2453 }
2454
2457 }
2458
2461 }
2462
2465 }
2468 }
2469
2470 static bool classof(const OMPClause *T) {
2471 return T->getClauseKind() == llvm::omp::OMPC_release;
2472 }
2473};
2474
2475/// This represents 'relaxed' clause in the '#pragma omp atomic'
2476/// directives.
2477///
2478/// \code
2479/// #pragma omp atomic relaxed
2480/// \endcode
2481/// In this example directive '#pragma omp atomic' has 'relaxed' clause.
2482class OMPRelaxedClause final : public OMPClause {
2483public:
2484 /// Build 'relaxed' clause.
2485 ///
2486 /// \param StartLoc Starting location of the clause.
2487 /// \param EndLoc Ending location of the clause.
2489 : OMPClause(llvm::omp::OMPC_relaxed, StartLoc, EndLoc) {}
2490
2491 /// Build an empty clause.
2493 : OMPClause(llvm::omp::OMPC_relaxed, SourceLocation(), SourceLocation()) {
2494 }
2495
2498 }
2499
2502 }
2503
2506 }
2509 }
2510
2511 static bool classof(const OMPClause *T) {
2512 return T->getClauseKind() == llvm::omp::OMPC_relaxed;
2513 }
2514};
2515
2516/// This represents 'weak' clause in the '#pragma omp atomic'
2517/// directives.
2518///
2519/// \code
2520/// #pragma omp atomic compare weak
2521/// \endcode
2522/// In this example directive '#pragma omp atomic' has 'weak' clause.
2523class OMPWeakClause final : public OMPClause {
2524public:
2525 /// Build 'weak' clause.
2526 ///
2527 /// \param StartLoc Starting location of the clause.
2528 /// \param EndLoc Ending location of the clause.
2530 : OMPClause(llvm::omp::OMPC_weak, StartLoc, EndLoc) {}
2531
2532 /// Build an empty clause.
2534 : OMPClause(llvm::omp::OMPC_weak, SourceLocation(), SourceLocation()) {}
2535
2538 }
2539
2542 }
2543
2546 }
2549 }
2550
2551 static bool classof(const OMPClause *T) {
2552 return T->getClauseKind() == llvm::omp::OMPC_weak;
2553 }
2554};
2555
2556/// This represents 'fail' clause in the '#pragma omp atomic'
2557/// directive.
2558///
2559/// \code
2560/// #pragma omp atomic compare fail
2561/// \endcode
2562/// In this example directive '#pragma omp atomic compare' has 'fail' clause.
2563class OMPFailClause final : public OMPClause {
2564
2565 // FailParameter is a memory-order-clause. Storing the ClauseKind is
2566 // sufficient for our purpose.
2567 OpenMPClauseKind FailParameter = llvm::omp::Clause::OMPC_unknown;
2568 SourceLocation FailParameterLoc;
2569 SourceLocation LParenLoc;
2570
2571 friend class OMPClauseReader;
2572
2573 /// Sets the location of '(' in fail clause.
2574 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2575
2576 /// Sets the location of memoryOrder clause argument in fail clause.
2577 void setFailParameterLoc(SourceLocation Loc) { FailParameterLoc = Loc; }
2578
2579 /// Sets the mem_order clause for 'atomic compare fail' directive.
2580 void setFailParameter(OpenMPClauseKind FailParameter) {
2581 this->FailParameter = FailParameter;
2582 assert(checkFailClauseParameter(FailParameter) &&
2583 "Invalid fail clause parameter");
2584 }
2585
2586public:
2587 /// Build 'fail' clause.
2588 ///
2589 /// \param StartLoc Starting location of the clause.
2590 /// \param EndLoc Ending location of the clause.
2592 : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc) {}
2593
2594 OMPFailClause(OpenMPClauseKind FailParameter, SourceLocation FailParameterLoc,
2595 SourceLocation StartLoc, SourceLocation LParenLoc,
2596 SourceLocation EndLoc)
2597 : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc),
2598 FailParameterLoc(FailParameterLoc), LParenLoc(LParenLoc) {
2599
2600 setFailParameter(FailParameter);
2601 }
2602
2603 /// Build an empty clause.
2605 : OMPClause(llvm::omp::OMPC_fail, SourceLocation(), SourceLocation()) {}
2606
2609 }
2610
2613 }
2614
2617 }
2620 }
2621
2622 static bool classof(const OMPClause *T) {
2623 return T->getClauseKind() == llvm::omp::OMPC_fail;
2624 }
2625
2626 /// Gets the location of '(' (for the parameter) in fail clause.
2628 return LParenLoc;
2629 }
2630
2631 /// Gets the location of Fail Parameter (type memory-order-clause) in
2632 /// fail clause.
2633 SourceLocation getFailParameterLoc() const { return FailParameterLoc; }
2634
2635 /// Gets the parameter (type memory-order-clause) in Fail clause.
2636 OpenMPClauseKind getFailParameter() const { return FailParameter; }
2637};
2638
2639/// This represents clause 'private' in the '#pragma omp ...' directives.
2640///
2641/// \code
2642/// #pragma omp parallel private(a,b)
2643/// \endcode
2644/// In this example directive '#pragma omp parallel' has clause 'private'
2645/// with the variables 'a' and 'b'.
2647 : public OMPVarListClause<OMPPrivateClause>,
2648 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
2649 friend class OMPClauseReader;
2650 friend OMPVarListClause;
2651 friend TrailingObjects;
2652
2653 /// Build clause with number of variables \a N.
2654 ///
2655 /// \param StartLoc Starting location of the clause.
2656 /// \param LParenLoc Location of '('.
2657 /// \param EndLoc Ending location of the clause.
2658 /// \param N Number of the variables in the clause.
2660 SourceLocation EndLoc, unsigned N)
2661 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc,
2662 LParenLoc, EndLoc, N) {}
2663
2664 /// Build an empty clause.
2665 ///
2666 /// \param N Number of variables.
2667 explicit OMPPrivateClause(unsigned N)
2668 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private,
2670 SourceLocation(), N) {}
2671
2672 /// Sets the list of references to private copies with initializers for
2673 /// new private variables.
2674 /// \param VL List of references.
2675 void setPrivateCopies(ArrayRef<Expr *> VL);
2676
2677 /// Gets the list of references to private copies with initializers for
2678 /// new private variables.
2679 MutableArrayRef<Expr *> getPrivateCopies() {
2680 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2681 }
2682 ArrayRef<const Expr *> getPrivateCopies() const {
2684 }
2685
2686public:
2687 /// Creates clause with a list of variables \a VL.
2688 ///
2689 /// \param C AST context.
2690 /// \param StartLoc Starting location of the clause.
2691 /// \param LParenLoc Location of '('.
2692 /// \param EndLoc Ending location of the clause.
2693 /// \param VL List of references to the variables.
2694 /// \param PrivateVL List of references to private copies with initializers.
2695 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2696 SourceLocation LParenLoc,
2697 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2698 ArrayRef<Expr *> PrivateVL);
2699
2700 /// Creates an empty clause with the place for \a N variables.
2701 ///
2702 /// \param C AST context.
2703 /// \param N The number of variables.
2704 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2705
2708 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2710 llvm::iterator_range<private_copies_const_iterator>;
2711
2713 return private_copies_range(getPrivateCopies().begin(),
2714 getPrivateCopies().end());
2715 }
2716
2718 return private_copies_const_range(getPrivateCopies().begin(),
2719 getPrivateCopies().end());
2720 }
2721
2723 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2724 reinterpret_cast<Stmt **>(varlist_end()));
2725 }
2726
2728 auto Children = const_cast<OMPPrivateClause *>(this)->children();
2729 return const_child_range(Children.begin(), Children.end());
2730 }
2731
2734 }
2737 }
2738
2739 static bool classof(const OMPClause *T) {
2740 return T->getClauseKind() == llvm::omp::OMPC_private;
2741 }
2742};
2743
2744/// This represents clause 'firstprivate' in the '#pragma omp ...'
2745/// directives.
2746///
2747/// \code
2748/// #pragma omp parallel firstprivate(a,b)
2749/// \endcode
2750/// In this example directive '#pragma omp parallel' has clause 'firstprivate'
2751/// with the variables 'a' and 'b'.
2753 : public OMPVarListClause<OMPFirstprivateClause>,
2754 public OMPClauseWithPreInit,
2755 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
2756 friend class OMPClauseReader;
2757 friend OMPVarListClause;
2758 friend TrailingObjects;
2759
2760 /// Build clause with number of variables \a N.
2761 ///
2762 /// \param StartLoc Starting location of the clause.
2763 /// \param LParenLoc Location of '('.
2764 /// \param EndLoc Ending location of the clause.
2765 /// \param N Number of the variables in the clause.
2767 SourceLocation EndLoc, unsigned N)
2768 : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate,
2769 StartLoc, LParenLoc, EndLoc, N),
2770 OMPClauseWithPreInit(this) {}
2771
2772 /// Build an empty clause.
2773 ///
2774 /// \param N Number of variables.
2775 explicit OMPFirstprivateClause(unsigned N)
2777 llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(),
2778 SourceLocation(), N),
2779 OMPClauseWithPreInit(this) {}
2780
2781 /// Sets the list of references to private copies with initializers for
2782 /// new private variables.
2783 /// \param VL List of references.
2784 void setPrivateCopies(ArrayRef<Expr *> VL);
2785
2786 /// Gets the list of references to private copies with initializers for
2787 /// new private variables.
2788 MutableArrayRef<Expr *> getPrivateCopies() {
2789 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2790 }
2791 ArrayRef<const Expr *> getPrivateCopies() const {
2793 }
2794
2795 /// Sets the list of references to initializer variables for new
2796 /// private variables.
2797 /// \param VL List of references.
2798 void setInits(ArrayRef<Expr *> VL);
2799
2800 /// Gets the list of references to initializer variables for new
2801 /// private variables.
2802 MutableArrayRef<Expr *> getInits() {
2803 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2804 }
2805 ArrayRef<const Expr *> getInits() const {
2806 return llvm::ArrayRef(getPrivateCopies().end(), varlist_size());
2807 }
2808
2809public:
2810 /// Creates clause with a list of variables \a VL.
2811 ///
2812 /// \param C AST context.
2813 /// \param StartLoc Starting location of the clause.
2814 /// \param LParenLoc Location of '('.
2815 /// \param EndLoc Ending location of the clause.
2816 /// \param VL List of references to the original variables.
2817 /// \param PrivateVL List of references to private copies with initializers.
2818 /// \param InitVL List of references to auto generated variables used for
2819 /// initialization of a single array element. Used if firstprivate variable is
2820 /// of array type.
2821 /// \param PreInit Statement that must be executed before entering the OpenMP
2822 /// region with this clause.
2823 static OMPFirstprivateClause *
2824 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2825 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
2826 ArrayRef<Expr *> InitVL, Stmt *PreInit);
2827
2828 /// Creates an empty clause with the place for \a N variables.
2829 ///
2830 /// \param C AST context.
2831 /// \param N The number of variables.
2832 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2833
2836 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2838 llvm::iterator_range<private_copies_const_iterator>;
2839
2841 return private_copies_range(getPrivateCopies().begin(),
2842 getPrivateCopies().end());
2843 }
2845 return private_copies_const_range(getPrivateCopies().begin(),
2846 getPrivateCopies().end());
2847 }
2848
2851 using inits_range = llvm::iterator_range<inits_iterator>;
2852 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2853
2855 return inits_range(getInits().begin(), getInits().end());
2856 }
2858 return inits_const_range(getInits().begin(), getInits().end());
2859 }
2860
2862 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2863 reinterpret_cast<Stmt **>(varlist_end()));
2864 }
2865
2867 auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
2868 return const_child_range(Children.begin(), Children.end());
2869 }
2870
2872 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2873 reinterpret_cast<Stmt **>(varlist_end()));
2874 }
2876 auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
2877 return const_child_range(Children.begin(), Children.end());
2878 }
2879
2880 static bool classof(const OMPClause *T) {
2881 return T->getClauseKind() == llvm::omp::OMPC_firstprivate;
2882 }
2883};
2884
2885/// This represents clause 'lastprivate' in the '#pragma omp ...'
2886/// directives.
2887///
2888/// \code
2889/// #pragma omp simd lastprivate(a,b)
2890/// \endcode
2891/// In this example directive '#pragma omp simd' has clause 'lastprivate'
2892/// with the variables 'a' and 'b'.
2894 : public OMPVarListClause<OMPLastprivateClause>,
2896 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
2897 // There are 4 additional tail-allocated arrays at the end of the class:
2898 // 1. Contains list of pseudo variables with the default initialization for
2899 // each non-firstprivate variables. Used in codegen for initialization of
2900 // lastprivate copies.
2901 // 2. List of helper expressions for proper generation of assignment operation
2902 // required for lastprivate clause. This list represents private variables
2903 // (for arrays, single array element).
2904 // 3. List of helper expressions for proper generation of assignment operation
2905 // required for lastprivate clause. This list represents original variables
2906 // (for arrays, single array element).
2907 // 4. List of helper expressions that represents assignment operation:
2908 // \code
2909 // DstExprs = SrcExprs;
2910 // \endcode
2911 // Required for proper codegen of final assignment performed by the
2912 // lastprivate clause.
2913 friend class OMPClauseReader;
2914 friend OMPVarListClause;
2915 friend TrailingObjects;
2916
2917 /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
2919 /// Optional location of the lasptrivate kind, if specified by user.
2920 SourceLocation LPKindLoc;
2921 /// Optional colon location, if specified by user.
2922 SourceLocation ColonLoc;
2923
2924 /// Build clause with number of variables \a N.
2925 ///
2926 /// \param StartLoc Starting location of the clause.
2927 /// \param LParenLoc Location of '('.
2928 /// \param EndLoc Ending location of the clause.
2929 /// \param N Number of the variables in the clause.
2932 SourceLocation LPKindLoc, SourceLocation ColonLoc,
2933 unsigned N)
2934 : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate,
2935 StartLoc, LParenLoc, EndLoc, N),
2936 OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
2937 ColonLoc(ColonLoc) {}
2938
2939 /// Build an empty clause.
2940 ///
2941 /// \param N Number of variables.
2942 explicit OMPLastprivateClause(unsigned N)
2944 llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(),
2945 SourceLocation(), N),
2947
2948 /// Get the list of helper expressions for initialization of private
2949 /// copies for lastprivate variables.
2950 MutableArrayRef<Expr *> getPrivateCopies() {
2951 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2952 }
2953 ArrayRef<const Expr *> getPrivateCopies() const {
2955 }
2956
2957 /// Set list of helper expressions, required for proper codegen of the
2958 /// clause. These expressions represent private variables (for arrays, single
2959 /// array element) in the final assignment statement performed by the
2960 /// lastprivate clause.
2961 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2962
2963 /// Get the list of helper source expressions.
2964 MutableArrayRef<Expr *> getSourceExprs() {
2965 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2966 }
2967 ArrayRef<const Expr *> getSourceExprs() const {
2968 return llvm::ArrayRef(getPrivateCopies().end(), varlist_size());
2969 }
2970
2971 /// Set list of helper expressions, required for proper codegen of the
2972 /// clause. These expressions represent original variables (for arrays, single
2973 /// array element) in the final assignment statement performed by the
2974 /// lastprivate clause.
2975 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2976
2977 /// Get the list of helper destination expressions.
2978 MutableArrayRef<Expr *> getDestinationExprs() {
2979 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2980 }
2981 ArrayRef<const Expr *> getDestinationExprs() const {
2982 return llvm::ArrayRef(getSourceExprs().end(), varlist_size());
2983 }
2984
2985 /// Set list of helper assignment expressions, required for proper
2986 /// codegen of the clause. These expressions are assignment expressions that
2987 /// assign private copy of the variable to original variable.
2988 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2989
2990 /// Get the list of helper assignment expressions.
2991 MutableArrayRef<Expr *> getAssignmentOps() {
2992 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2993 }
2994 ArrayRef<const Expr *> getAssignmentOps() const {
2995 return llvm::ArrayRef(getDestinationExprs().end(), varlist_size());
2996 }
2997
2998 /// Sets lastprivate kind.
2999 void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
3000 /// Sets location of the lastprivate kind.
3001 void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
3002 /// Sets colon symbol location.
3003 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3004
3005public:
3006 /// Creates clause with a list of variables \a VL.
3007 ///
3008 /// \param C AST context.
3009 /// \param StartLoc Starting location of the clause.
3010 /// \param LParenLoc Location of '('.
3011 /// \param EndLoc Ending location of the clause.
3012 /// \param VL List of references to the variables.
3013 /// \param SrcExprs List of helper expressions for proper generation of
3014 /// assignment operation required for lastprivate clause. This list represents
3015 /// private variables (for arrays, single array element).
3016 /// \param DstExprs List of helper expressions for proper generation of
3017 /// assignment operation required for lastprivate clause. This list represents
3018 /// original variables (for arrays, single array element).
3019 /// \param AssignmentOps List of helper expressions that represents assignment
3020 /// operation:
3021 /// \code
3022 /// DstExprs = SrcExprs;
3023 /// \endcode
3024 /// Required for proper codegen of final assignment performed by the
3025 /// lastprivate clause.
3026 /// \param LPKind Lastprivate kind, e.g. 'conditional'.
3027 /// \param LPKindLoc Location of the lastprivate kind.
3028 /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
3029 /// \param PreInit Statement that must be executed before entering the OpenMP
3030 /// region with this clause.
3031 /// \param PostUpdate Expression that must be executed after exit from the
3032 /// OpenMP region with this clause.
3033 static OMPLastprivateClause *
3034 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3035 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
3036 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
3037 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
3038 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
3039
3040 /// Creates an empty clause with the place for \a N variables.
3041 ///
3042 /// \param C AST context.
3043 /// \param N The number of variables.
3044 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3045
3046 /// Lastprivate kind.
3047 OpenMPLastprivateModifier getKind() const { return LPKind; }
3048 /// Returns the location of the lastprivate kind.
3049 SourceLocation getKindLoc() const { return LPKindLoc; }
3050 /// Returns the location of the ':' symbol, if any.
3051 SourceLocation getColonLoc() const { return ColonLoc; }
3052
3055 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3057 llvm::iterator_range<helper_expr_const_iterator>;
3058
3059 /// Set list of helper expressions, required for generation of private
3060 /// copies of original lastprivate variables.
3061 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
3062
3064 return helper_expr_const_range(getPrivateCopies().begin(),
3065 getPrivateCopies().end());
3066 }
3067
3069 return helper_expr_range(getPrivateCopies().begin(),
3070 getPrivateCopies().end());
3071 }
3072
3074 return helper_expr_const_range(getSourceExprs().begin(),
3075 getSourceExprs().end());
3076 }
3077
3079 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
3080 }
3081
3083 return helper_expr_const_range(getDestinationExprs().begin(),
3084 getDestinationExprs().end());
3085 }
3086
3088 return helper_expr_range(getDestinationExprs().begin(),
3089 getDestinationExprs().end());
3090 }
3091
3093 return helper_expr_const_range(getAssignmentOps().begin(),
3094 getAssignmentOps().end());
3095 }
3096
3098 return helper_expr_range(getAssignmentOps().begin(),
3099 getAssignmentOps().end());
3100 }
3101
3103 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3104 reinterpret_cast<Stmt **>(varlist_end()));
3105 }
3106
3108 auto Children = const_cast<OMPLastprivateClause *>(this)->children();
3109 return const_child_range(Children.begin(), Children.end());
3110 }
3111
3114 }
3117 }
3118
3119 static bool classof(const OMPClause *T) {
3120 return T->getClauseKind() == llvm::omp::OMPC_lastprivate;
3121 }
3122};
3123
3124/// This represents clause 'shared' in the '#pragma omp ...' directives.
3125///
3126/// \code
3127/// #pragma omp parallel shared(a,b)
3128/// \endcode
3129/// In this example directive '#pragma omp parallel' has clause 'shared'
3130/// with the variables 'a' and 'b'.
3132 : public OMPVarListClause<OMPSharedClause>,
3133 private llvm::TrailingObjects<OMPSharedClause, Expr *> {
3134 friend OMPVarListClause;
3135 friend TrailingObjects;
3136
3137 /// Build clause with number of variables \a N.
3138 ///
3139 /// \param StartLoc Starting location of the clause.
3140 /// \param LParenLoc Location of '('.
3141 /// \param EndLoc Ending location of the clause.
3142 /// \param N Number of the variables in the clause.
3143 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3144 SourceLocation EndLoc, unsigned N)
3145 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, StartLoc,
3146 LParenLoc, EndLoc, N) {}
3147
3148 /// Build an empty clause.
3149 ///
3150 /// \param N Number of variables.
3151 explicit OMPSharedClause(unsigned N)
3152 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared,
3154 SourceLocation(), N) {}
3155
3156public:
3157 /// Creates clause with a list of variables \a VL.
3158 ///
3159 /// \param C AST context.
3160 /// \param StartLoc Starting location of the clause.
3161 /// \param LParenLoc Location of '('.
3162 /// \param EndLoc Ending location of the clause.
3163 /// \param VL List of references to the variables.
3164 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
3165 SourceLocation LParenLoc,
3166 SourceLocation EndLoc, ArrayRef<Expr *> VL);
3167
3168 /// Creates an empty clause with \a N variables.
3169 ///
3170 /// \param C AST context.
3171 /// \param N The number of variables.
3172 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
3173
3175 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3176 reinterpret_cast<Stmt **>(varlist_end()));
3177 }
3178
3180 auto Children = const_cast<OMPSharedClause *>(this)->children();
3181 return const_child_range(Children.begin(), Children.end());
3182 }
3183
3186 }
3189 }
3190
3191 static bool classof(const OMPClause *T) {
3192 return T->getClauseKind() == llvm::omp::OMPC_shared;
3193 }
3194};
3195
3196/// This represents clause 'reduction' in the '#pragma omp ...'
3197/// directives.
3198///
3199/// \code
3200/// #pragma omp parallel reduction(+:a,b)
3201/// \endcode
3202/// In this example directive '#pragma omp parallel' has clause 'reduction'
3203/// with operator '+' and the variables 'a' and 'b'.
3205 : public OMPVarListClause<OMPReductionClause>,
3207 private llvm::TrailingObjects<OMPReductionClause, Expr *> {
3208 friend class OMPClauseReader;
3209 friend OMPVarListClause;
3210 friend TrailingObjects;
3211
3212 /// Reduction modifier.
3214
3215 /// Reduction modifier location.
3216 SourceLocation ModifierLoc;
3217
3218 /// Location of ':'.
3219 SourceLocation ColonLoc;
3220
3221 /// Nested name specifier for C++.
3222 NestedNameSpecifierLoc QualifierLoc;
3223
3224 /// Name of custom operator.
3225 DeclarationNameInfo NameInfo;
3226
3227 /// Build clause with number of variables \a N.
3228 ///
3229 /// \param StartLoc Starting location of the clause.
3230 /// \param LParenLoc Location of '('.
3231 /// \param ModifierLoc Modifier location.
3232 /// \param ColonLoc Location of ':'.
3233 /// \param EndLoc Ending location of the clause.
3234 /// \param N Number of the variables in the clause.
3235 /// \param QualifierLoc The nested-name qualifier with location information
3236 /// \param NameInfo The full name info for reduction identifier.
3238 SourceLocation ModifierLoc, SourceLocation ColonLoc,
3239 SourceLocation EndLoc,
3240 OpenMPReductionClauseModifier Modifier, unsigned N,
3241 NestedNameSpecifierLoc QualifierLoc,
3242 const DeclarationNameInfo &NameInfo)
3243 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
3244 StartLoc, LParenLoc, EndLoc, N),
3245 OMPClauseWithPostUpdate(this), Modifier(Modifier),
3246 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
3247 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3248
3249 /// Build an empty clause.
3250 ///
3251 /// \param N Number of variables.
3252 explicit OMPReductionClause(unsigned N)
3253 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
3255 SourceLocation(), N),
3257
3258 /// Sets reduction modifier.
3259 void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; }
3260
3261 /// Sets location of the modifier.
3262 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
3263
3264 /// Sets location of ':' symbol in clause.
3265 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3266
3267 /// Sets the name info for specified reduction identifier.
3268 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3269
3270 /// Sets the nested name specifier.
3271 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3272
3273 /// Set list of helper expressions, required for proper codegen of the
3274 /// clause. These expressions represent private copy of the reduction
3275 /// variable.
3276 void setPrivates(ArrayRef<Expr *> Privates);
3277
3278 /// Get the list of helper privates.
3279 MutableArrayRef<Expr *> getPrivates() {
3280 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3281 }
3282 ArrayRef<const Expr *> getPrivates() const {
3284 }
3285
3286 /// Set list of helper expressions, required for proper codegen of the
3287 /// clause. These expressions represent LHS expression in the final
3288 /// reduction expression performed by the reduction clause.
3289 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3290
3291 /// Get the list of helper LHS expressions.
3292 MutableArrayRef<Expr *> getLHSExprs() {
3293 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3294 }
3295 ArrayRef<const Expr *> getLHSExprs() const {
3296 return llvm::ArrayRef(getPrivates().end(), varlist_size());
3297 }
3298
3299 /// Set list of helper expressions, required for proper codegen of the
3300 /// clause. These expressions represent RHS expression in the final
3301 /// reduction expression performed by the reduction clause.
3302 /// Also, variables in these expressions are used for proper initialization of
3303 /// reduction copies.
3304 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3305
3306 /// Get the list of helper destination expressions.
3307 MutableArrayRef<Expr *> getRHSExprs() {
3308 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3309 }
3310 ArrayRef<const Expr *> getRHSExprs() const {
3311 return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
3312 }
3313
3314 /// Set list of helper reduction expressions, required for proper
3315 /// codegen of the clause. These expressions are binary expressions or
3316 /// operator/custom reduction call that calculates new value from source
3317 /// helper expressions to destination helper expressions.
3318 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3319
3320 /// Get the list of helper reduction expressions.
3321 MutableArrayRef<Expr *> getReductionOps() {
3322 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3323 }
3324 ArrayRef<const Expr *> getReductionOps() const {
3325 return llvm::ArrayRef(getRHSExprs().end(), varlist_size());
3326 }
3327
3328 /// Set list of helper copy operations for inscan reductions.
3329 /// The form is: Temps[i] = LHS[i];
3330 void setInscanCopyOps(ArrayRef<Expr *> Ops);
3331
3332 /// Get the list of helper inscan copy operations.
3333 MutableArrayRef<Expr *> getInscanCopyOps() {
3334 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3335 }
3336 ArrayRef<const Expr *> getInscanCopyOps() const {
3337 return llvm::ArrayRef(getReductionOps().end(), varlist_size());
3338 }
3339
3340 /// Set list of helper temp vars for inscan copy array operations.
3341 void setInscanCopyArrayTemps(ArrayRef<Expr *> CopyArrayTemps);
3342
3343 /// Get the list of helper inscan copy temps.
3344 MutableArrayRef<Expr *> getInscanCopyArrayTemps() {
3345 return MutableArrayRef<Expr *>(getInscanCopyOps().end(), varlist_size());
3346 }
3347 ArrayRef<const Expr *> getInscanCopyArrayTemps() const {
3348 return llvm::ArrayRef(getInscanCopyOps().end(), varlist_size());
3349 }
3350
3351 /// Set list of helper temp elements vars for inscan copy array operations.
3352 void setInscanCopyArrayElems(ArrayRef<Expr *> CopyArrayElems);
3353
3354 /// Get the list of helper inscan copy temps.
3355 MutableArrayRef<Expr *> getInscanCopyArrayElems() {
3356 return MutableArrayRef<Expr *>(getInscanCopyArrayTemps().end(),
3357 varlist_size());
3358 }
3359 ArrayRef<const Expr *> getInscanCopyArrayElems() const {
3360 return llvm::ArrayRef(getInscanCopyArrayTemps().end(), varlist_size());
3361 }
3362
3363public:
3364 /// Creates clause with a list of variables \a VL.
3365 ///
3366 /// \param StartLoc Starting location of the clause.
3367 /// \param LParenLoc Location of '('.
3368 /// \param ModifierLoc Modifier location.
3369 /// \param ColonLoc Location of ':'.
3370 /// \param EndLoc Ending location of the clause.
3371 /// \param VL The variables in the clause.
3372 /// \param QualifierLoc The nested-name qualifier with location information
3373 /// \param NameInfo The full name info for reduction identifier.
3374 /// \param Privates List of helper expressions for proper generation of
3375 /// private copies.
3376 /// \param LHSExprs List of helper expressions for proper generation of
3377 /// assignment operation required for copyprivate clause. This list represents
3378 /// LHSs of the reduction expressions.
3379 /// \param RHSExprs List of helper expressions for proper generation of
3380 /// assignment operation required for copyprivate clause. This list represents
3381 /// RHSs of the reduction expressions.
3382 /// Also, variables in these expressions are used for proper initialization of
3383 /// reduction copies.
3384 /// \param ReductionOps List of helper expressions that represents reduction
3385 /// expressions:
3386 /// \code
3387 /// LHSExprs binop RHSExprs;
3388 /// operator binop(LHSExpr, RHSExpr);
3389 /// <CutomReduction>(LHSExpr, RHSExpr);
3390 /// \endcode
3391 /// Required for proper codegen of final reduction operation performed by the
3392 /// reduction clause.
3393 /// \param CopyOps List of copy operations for inscan reductions:
3394 /// \code
3395 /// TempExprs = LHSExprs;
3396 /// \endcode
3397 /// \param CopyArrayTemps Temp arrays for prefix sums.
3398 /// \param CopyArrayElems Temp arrays for prefix sums.
3399 /// \param PreInit Statement that must be executed before entering the OpenMP
3400 /// region with this clause.
3401 /// \param PostUpdate Expression that must be executed after exit from the
3402 /// OpenMP region with this clause.
3403 static OMPReductionClause *
3404 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3405 SourceLocation ModifierLoc, SourceLocation ColonLoc,
3406 SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier,
3407 ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc,
3408 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3409 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3410 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> CopyOps,
3411 ArrayRef<Expr *> CopyArrayTemps, ArrayRef<Expr *> CopyArrayElems,
3412 Stmt *PreInit, Expr *PostUpdate);
3413
3414 /// Creates an empty clause with the place for \a N variables.
3415 ///
3416 /// \param C AST context.
3417 /// \param N The number of variables.
3418 /// \param Modifier Reduction modifier.
3419 static OMPReductionClause *
3420 CreateEmpty(const ASTContext &C, unsigned N,
3422
3423 /// Returns modifier.
3424 OpenMPReductionClauseModifier getModifier() const { return Modifier; }
3425
3426 /// Returns modifier location.
3427 SourceLocation getModifierLoc() const { return ModifierLoc; }
3428
3429 /// Gets location of ':' symbol in clause.
3430 SourceLocation getColonLoc() const { return ColonLoc; }
3431
3432 /// Gets the name info for specified reduction identifier.
3433 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3434
3435 /// Gets the nested name specifier.
3436 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3437
3440 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3442 llvm::iterator_range<helper_expr_const_iterator>;
3443
3445 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3446 }
3447
3449 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3450 }
3451
3453 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3454 }
3455
3457 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3458 }
3459
3461 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3462 }
3463
3465 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3466 }
3467
3469 return helper_expr_const_range(getReductionOps().begin(),
3470 getReductionOps().end());
3471 }
3472
3474 return helper_expr_range(getReductionOps().begin(),
3475 getReductionOps().end());
3476 }
3477
3479 return helper_expr_const_range(getInscanCopyOps().begin(),
3480 getInscanCopyOps().end());
3481 }
3482
3484 return helper_expr_range(getInscanCopyOps().begin(),
3485 getInscanCopyOps().end());
3486 }
3487
3489 return helper_expr_const_range(getInscanCopyArrayTemps().begin(),
3490 getInscanCopyArrayTemps().end());
3491 }
3492
3494 return helper_expr_range(getInscanCopyArrayTemps().begin(),
3495 getInscanCopyArrayTemps().end());
3496 }
3497
3499 return helper_expr_const_range(getInscanCopyArrayElems().begin(),
3500 getInscanCopyArrayElems().end());
3501 }
3502
3504 return helper_expr_range(getInscanCopyArrayElems().begin(),
3505 getInscanCopyArrayElems().end());
3506 }
3507
3509 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3510 reinterpret_cast<Stmt **>(varlist_end()));
3511 }
3512
3514 auto Children = const_cast<OMPReductionClause *>(this)->children();
3515 return const_child_range(Children.begin(), Children.end());
3516 }
3517
3519 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3520 reinterpret_cast<Stmt **>(varlist_end()));
3521 }
3523 auto Children = const_cast<OMPReductionClause *>(this)->used_children();
3524 return const_child_range(Children.begin(), Children.end());
3525 }
3526
3527 static bool classof(const OMPClause *T) {
3528 return T->getClauseKind() == llvm::omp::OMPC_reduction;
3529 }
3530};
3531
3532/// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
3533/// directives.
3534///
3535/// \code
3536/// #pragma omp taskgroup task_reduction(+:a,b)
3537/// \endcode
3538/// In this example directive '#pragma omp taskgroup' has clause
3539/// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
3541 : public OMPVarListClause<OMPTaskReductionClause>,
3543 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
3544 friend class OMPClauseReader;
3545 friend OMPVarListClause;
3546 friend TrailingObjects;
3547
3548 /// Location of ':'.
3549 SourceLocation ColonLoc;
3550
3551 /// Nested name specifier for C++.
3552 NestedNameSpecifierLoc QualifierLoc;
3553
3554 /// Name of custom operator.
3555 DeclarationNameInfo NameInfo;
3556
3557 /// Build clause with number of variables \a N.
3558 ///
3559 /// \param StartLoc Starting location of the clause.
3560 /// \param LParenLoc Location of '('.
3561 /// \param EndLoc Ending location of the clause.
3562 /// \param ColonLoc Location of ':'.
3563 /// \param N Number of the variables in the clause.
3564 /// \param QualifierLoc The nested-name qualifier with location information
3565 /// \param NameInfo The full name info for reduction identifier.
3567 SourceLocation ColonLoc, SourceLocation EndLoc,
3568 unsigned N, NestedNameSpecifierLoc QualifierLoc,
3569 const DeclarationNameInfo &NameInfo)
3571 llvm::omp::OMPC_task_reduction, StartLoc, LParenLoc, EndLoc, N),
3572 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3573 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3574
3575 /// Build an empty clause.
3576 ///
3577 /// \param N Number of variables.
3578 explicit OMPTaskReductionClause(unsigned N)
3580 llvm::omp::OMPC_task_reduction, SourceLocation(), SourceLocation(),
3581 SourceLocation(), N),
3583
3584 /// Sets location of ':' symbol in clause.
3585 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3586
3587 /// Sets the name info for specified reduction identifier.
3588 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3589
3590 /// Sets the nested name specifier.
3591 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3592
3593 /// Set list of helper expressions, required for proper codegen of the clause.
3594 /// These expressions represent private copy of the reduction variable.
3595 void setPrivates(ArrayRef<Expr *> Privates);
3596
3597 /// Get the list of helper privates.
3598 MutableArrayRef<Expr *> getPrivates() {
3599 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3600 }
3601 ArrayRef<const Expr *> getPrivates() const {
3603 }
3604
3605 /// Set list of helper expressions, required for proper codegen of the clause.
3606 /// These expressions represent LHS expression in the final reduction
3607 /// expression performed by the reduction clause.
3608 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3609
3610 /// Get the list of helper LHS expressions.
3611 MutableArrayRef<Expr *> getLHSExprs() {
3612 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3613 }
3614 ArrayRef<const Expr *> getLHSExprs() const {
3615 return llvm::ArrayRef(getPrivates().end(), varlist_size());
3616 }
3617
3618 /// Set list of helper expressions, required for proper codegen of the clause.
3619 /// These expressions represent RHS expression in the final reduction
3620 /// expression performed by the reduction clause. Also, variables in these
3621 /// expressions are used for proper initialization of reduction copies.
3622 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3623
3624 /// Get the list of helper destination expressions.
3625 MutableArrayRef<Expr *> getRHSExprs() {
3626 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3627 }
3628 ArrayRef<const Expr *> getRHSExprs() const {
3629 return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
3630 }
3631
3632 /// Set list of helper reduction expressions, required for proper
3633 /// codegen of the clause. These expressions are binary expressions or
3634 /// operator/custom reduction call that calculates new value from source
3635 /// helper expressions to destination helper expressions.
3636 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3637
3638 /// Get the list of helper reduction expressions.
3639 MutableArrayRef<Expr *> getReductionOps() {
3640 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3641 }
3642 ArrayRef<const Expr *> getReductionOps() const {
3643 return llvm::ArrayRef(getRHSExprs().end(), varlist_size());
3644 }
3645
3646public:
3647 /// Creates clause with a list of variables \a VL.
3648 ///
3649 /// \param StartLoc Starting location of the clause.
3650 /// \param LParenLoc Location of '('.
3651 /// \param ColonLoc Location of ':'.
3652 /// \param EndLoc Ending location of the clause.
3653 /// \param VL The variables in the clause.
3654 /// \param QualifierLoc The nested-name qualifier with location information
3655 /// \param NameInfo The full name info for reduction identifier.
3656 /// \param Privates List of helper expressions for proper generation of
3657 /// private copies.
3658 /// \param LHSExprs List of helper expressions for proper generation of
3659 /// assignment operation required for copyprivate clause. This list represents
3660 /// LHSs of the reduction expressions.
3661 /// \param RHSExprs List of helper expressions for proper generation of
3662 /// assignment operation required for copyprivate clause. This list represents
3663 /// RHSs of the reduction expressions.
3664 /// Also, variables in these expressions are used for proper initialization of
3665 /// reduction copies.
3666 /// \param ReductionOps List of helper expressions that represents reduction
3667 /// expressions:
3668 /// \code
3669 /// LHSExprs binop RHSExprs;
3670 /// operator binop(LHSExpr, RHSExpr);
3671 /// <CutomReduction>(LHSExpr, RHSExpr);
3672 /// \endcode
3673 /// Required for proper codegen of final reduction operation performed by the
3674 /// reduction clause.
3675 /// \param PreInit Statement that must be executed before entering the OpenMP
3676 /// region with this clause.
3677 /// \param PostUpdate Expression that must be executed after exit from the
3678 /// OpenMP region with this clause.
3679 static OMPTaskReductionClause *
3680 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3681 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3682 NestedNameSpecifierLoc QualifierLoc,
3683 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3684 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3685 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
3686
3687 /// Creates an empty clause with the place for \a N variables.
3688 ///
3689 /// \param C AST context.
3690 /// \param N The number of variables.
3691 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3692
3693 /// Gets location of ':' symbol in clause.
3694 SourceLocation getColonLoc() const { return ColonLoc; }
3695
3696 /// Gets the name info for specified reduction identifier.
3697 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3698
3699 /// Gets the nested name specifier.
3700 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3701
3704 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3706 llvm::iterator_range<helper_expr_const_iterator>;
3707
3709 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3710 }
3711
3713 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3714 }
3715
3717 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3718 }
3719
3721 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3722 }
3723
3725 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3726 }
3727
3729 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3730 }
3731
3733 return helper_expr_const_range(getReductionOps().begin(),
3734 getReductionOps().end());
3735 }
3736
3738 return helper_expr_range(getReductionOps().begin(),
3739 getReductionOps().end());
3740 }
3741
3743 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3744 reinterpret_cast<Stmt **>(varlist_end()));
3745 }
3746
3748 auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
3749 return const_child_range(Children.begin(), Children.end());
3750 }
3751
3754 }
3757 }
3758
3759 static bool classof(const OMPClause *T) {
3760 return T->getClauseKind() == llvm::omp::OMPC_task_reduction;
3761 }
3762};
3763
3764/// This represents clause 'in_reduction' in the '#pragma omp task' directives.
3765///
3766/// \code
3767/// #pragma omp task in_reduction(+:a,b)
3768/// \endcode
3769/// In this example directive '#pragma omp task' has clause 'in_reduction' with
3770/// operator '+' and the variables 'a' and 'b'.
3772 : public OMPVarListClause<OMPInReductionClause>,
3774 private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
3775 friend class OMPClauseReader;
3776 friend OMPVarListClause;
3777 friend TrailingObjects;
3778
3779 /// Location of ':'.
3780 SourceLocation ColonLoc;
3781
3782 /// Nested name specifier for C++.
3783 NestedNameSpecifierLoc QualifierLoc;
3784
3785 /// Name of custom operator.
3786 DeclarationNameInfo NameInfo;
3787
3788 /// Build clause with number of variables \a N.
3789 ///
3790 /// \param StartLoc Starting location of the clause.
3791 /// \param LParenLoc Location of '('.
3792 /// \param EndLoc Ending location of the clause.
3793 /// \param ColonLoc Location of ':'.
3794 /// \param N Number of the variables in the clause.
3795 /// \param QualifierLoc The nested-name qualifier with location information
3796 /// \param NameInfo The full name info for reduction identifier.
3798 SourceLocation ColonLoc, SourceLocation EndLoc,
3799 unsigned N, NestedNameSpecifierLoc QualifierLoc,
3800 const DeclarationNameInfo &NameInfo)
3801 : OMPVarListClause<OMPInReductionClause>(llvm::omp::OMPC_in_reduction,
3802 StartLoc, LParenLoc, EndLoc, N),
3803 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3804 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3805
3806 /// Build an empty clause.
3807 ///
3808 /// \param N Number of variables.
3809 explicit OMPInReductionClause(unsigned N)
3811 llvm::omp::OMPC_in_reduction, SourceLocation(), SourceLocation(),
3812 SourceLocation(), N),
3814
3815 /// Sets location of ':' symbol in clause.
3816 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3817
3818 /// Sets the name info for specified reduction identifier.
3819 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3820
3821 /// Sets the nested name specifier.
3822 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3823
3824 /// Set list of helper expressions, required for proper codegen of the clause.
3825 /// These expressions represent private copy of the reduction variable.
3826 void setPrivates(ArrayRef<Expr *> Privates);
3827
3828 /// Get the list of helper privates.
3829 MutableArrayRef<Expr *> getPrivates() {
3830 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3831 }
3832 ArrayRef<const Expr *> getPrivates() const {
3834 }
3835
3836 /// Set list of helper expressions, required for proper codegen of the clause.
3837 /// These expressions represent LHS expression in the final reduction
3838 /// expression performed by the reduction clause.
3839 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3840
3841 /// Get the list of helper LHS expressions.
3842 MutableArrayRef<Expr *> getLHSExprs() {
3843 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3844 }
3845 ArrayRef<const Expr *> getLHSExprs() const {
3846 return llvm::ArrayRef(getPrivates().end(), varlist_size());
3847 }
3848
3849 /// Set list of helper expressions, required for proper codegen of the clause.
3850 /// These expressions represent RHS expression in the final reduction
3851 /// expression performed by the reduction clause. Also, variables in these
3852 /// expressions are used for proper initialization of reduction copies.
3853 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3854
3855 /// Get the list of helper destination expressions.
3856 MutableArrayRef<Expr *> getRHSExprs() {
3857 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3858 }
3859 ArrayRef<const Expr *> getRHSExprs() const {
3860 return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
3861 }
3862
3863 /// Set list of helper reduction expressions, required for proper
3864 /// codegen of the clause. These expressions are binary expressions or
3865 /// operator/custom reduction call that calculates new value from source
3866 /// helper expressions to destination helper expressions.
3867 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3868
3869 /// Get the list of helper reduction expressions.
3870 MutableArrayRef<Expr *> getReductionOps() {
3871 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3872 }
3873 ArrayRef<const Expr *> getReductionOps() const {
3874 return llvm::ArrayRef(getRHSExprs().end(), varlist_size());
3875 }
3876
3877 /// Set list of helper reduction taskgroup descriptors.
3878 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
3879
3880 /// Get the list of helper reduction taskgroup descriptors.
3881 MutableArrayRef<Expr *> getTaskgroupDescriptors() {
3882 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3883 }
3884 ArrayRef<const Expr *> getTaskgroupDescriptors() const {
3885 return llvm::ArrayRef(getReductionOps().end(), varlist_size());
3886 }
3887
3888public:
3889 /// Creates clause with a list of variables \a VL.
3890 ///
3891 /// \param StartLoc Starting location of the clause.
3892 /// \param LParenLoc Location of '('.
3893 /// \param ColonLoc Location of ':'.
3894 /// \param EndLoc Ending location of the clause.
3895 /// \param VL The variables in the clause.
3896 /// \param QualifierLoc The nested-name qualifier with location information
3897 /// \param NameInfo The full name info for reduction identifier.
3898 /// \param Privates List of helper expressions for proper generation of
3899 /// private copies.
3900 /// \param LHSExprs List of helper expressions for proper generation of
3901 /// assignment operation required for copyprivate clause. This list represents
3902 /// LHSs of the reduction expressions.
3903 /// \param RHSExprs List of helper expressions for proper generation of
3904 /// assignment operation required for copyprivate clause. This list represents
3905 /// RHSs of the reduction expressions.
3906 /// Also, variables in these expressions are used for proper initialization of
3907 /// reduction copies.
3908 /// \param ReductionOps List of helper expressions that represents reduction
3909 /// expressions:
3910 /// \code
3911 /// LHSExprs binop RHSExprs;
3912 /// operator binop(LHSExpr, RHSExpr);
3913 /// <CutomReduction>(LHSExpr, RHSExpr);
3914 /// \endcode
3915 /// Required for proper codegen of final reduction operation performed by the
3916 /// reduction clause.
3917 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
3918 /// corresponding items in parent taskgroup task_reduction clause.
3919 /// \param PreInit Statement that must be executed before entering the OpenMP
3920 /// region with this clause.
3921 /// \param PostUpdate Expression that must be executed after exit from the
3922 /// OpenMP region with this clause.
3923 static OMPInReductionClause *
3924 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3925 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3926 NestedNameSpecifierLoc QualifierLoc,
3927 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3928 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3929 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
3930 Stmt *PreInit, Expr *PostUpdate);
3931
3932 /// Creates an empty clause with the place for \a N variables.
3933 ///
3934 /// \param C AST context.
3935 /// \param N The number of variables.
3936 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3937
3938 /// Gets location of ':' symbol in clause.
3939 SourceLocation getColonLoc() const { return ColonLoc; }
3940
3941 /// Gets the name info for specified reduction identifier.
3942 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3943
3944 /// Gets the nested name specifier.
3945 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3946
3949 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3951 llvm::iterator_range<helper_expr_const_iterator>;
3952
3954 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3955 }
3956
3958 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3959 }
3960
3962 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3963 }
3964
3966 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3967 }
3968
3970 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3971 }
3972
3974 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3975 }
3976
3978 return helper_expr_const_range(getReductionOps().begin(),
3979 getReductionOps().end());
3980 }
3981
3983 return helper_expr_range(getReductionOps().begin(),
3984 getReductionOps().end());
3985 }
3986
3988 return helper_expr_const_range(getTaskgroupDescriptors().begin(),
3989 getTaskgroupDescriptors().end());
3990 }
3991
3993 return helper_expr_range(getTaskgroupDescriptors().begin(),
3994 getTaskgroupDescriptors().end());
3995 }
3996
3998 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3999 reinterpret_cast<Stmt **>(varlist_end()));
4000 }
4001
4003 auto Children = const_cast<OMPInReductionClause *>(this)->children();
4004 return const_child_range(Children.begin(), Children.end());
4005 }
4006
4009 }
4012 }
4013
4014 static bool classof(const OMPClause *T) {
4015 return T->getClauseKind() == llvm::omp::OMPC_in_reduction;
4016 }
4017};
4018
4019/// This represents clause 'linear' in the '#pragma omp ...'
4020/// directives.
4021///
4022/// \code
4023/// #pragma omp simd linear(a,b : 2)
4024/// \endcode
4025/// In this example directive '#pragma omp simd' has clause 'linear'
4026/// with variables 'a', 'b' and linear step '2'.
4028 : public OMPVarListClause<OMPLinearClause>,
4030 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
4031 friend class OMPClauseReader;
4032 friend OMPVarListClause;
4033 friend TrailingObjects;
4034
4035 /// Modifier of 'linear' clause.
4036 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
4037
4038 /// Location of linear modifier if any.
4039 SourceLocation ModifierLoc;
4040
4041 /// Location of ':'.
4042 SourceLocation ColonLoc;
4043
4044 /// Location of 'step' modifier.
4045 SourceLocation StepModifierLoc;
4046
4047 /// Sets the linear step for clause.
4048 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
4049
4050 /// Sets the expression to calculate linear step for clause.
4051 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
4052
4053 /// Build 'linear' clause with given number of variables \a NumVars.
4054 ///
4055 /// \param StartLoc Starting location of the clause.
4056 /// \param LParenLoc Location of '('.
4057 /// \param ColonLoc Location of ':'.
4058 /// \param StepModifierLoc Location of 'step' modifier.
4059 /// \param EndLoc Ending location of the clause.
4060 /// \param NumVars Number of variables.
4061 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4062 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
4063 SourceLocation ColonLoc, SourceLocation StepModifierLoc,
4064 SourceLocation EndLoc, unsigned NumVars)
4065 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, StartLoc,
4066 LParenLoc, EndLoc, NumVars),
4067 OMPClauseWithPostUpdate(this), Modifier(Modifier),
4068 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
4069 StepModifierLoc(StepModifierLoc) {}
4070
4071 /// Build an empty clause.
4072 ///
4073 /// \param NumVars Number of variables.
4074 explicit OMPLinearClause(unsigned NumVars)
4075 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear,
4076 SourceLocation(), SourceLocation(),
4077 SourceLocation(), NumVars),
4079
4080 /// Gets the list of initial values for linear variables.
4081 ///
4082 /// There are NumVars expressions with initial values allocated after the
4083 /// varlist, they are followed by NumVars update expressions (used to update
4084 /// the linear variable's value on current iteration) and they are followed by
4085 /// NumVars final expressions (used to calculate the linear variable's
4086 /// value after the loop body). After these lists, there are 2 helper
4087 /// expressions - linear step and a helper to calculate it before the
4088 /// loop body (used when the linear step is not constant):
4089 ///
4090 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
4091 /// Finals[]; Step; CalcStep; }
4092 MutableArrayRef<Expr *> getPrivates() {
4093 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4094 }
4095 ArrayRef<const Expr *> getPrivates() const {
4097 }
4098
4099 MutableArrayRef<Expr *> getInits() {
4100 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
4101 }
4102 ArrayRef<const Expr *> getInits() const {
4103 return llvm::ArrayRef(getPrivates().end(), varlist_size());
4104 }
4105
4106 /// Sets the list of update expressions for linear variables.
4107 MutableArrayRef<Expr *> getUpdates() {
4108 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
4109 }
4110 ArrayRef<const Expr *> getUpdates() const {
4111 return llvm::ArrayRef(getInits().end(), varlist_size());
4112 }
4113
4114 /// Sets the list of final update expressions for linear variables.
4115 MutableArrayRef<Expr *> getFinals() {
4116 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
4117 }
4118 ArrayRef<const Expr *> getFinals() const {
4119 return llvm::ArrayRef(getUpdates().end(), varlist_size());
4120 }
4121
4122 /// Gets the list of used expressions for linear variables.
4123 MutableArrayRef<Expr *> getUsedExprs() {
4124 return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
4125 }
4126 ArrayRef<const Expr *> getUsedExprs() const {
4127 return llvm::ArrayRef(getFinals().end() + 2, varlist_size() + 1);
4128 }
4129
4130 /// Sets the list of the copies of original linear variables.
4131 /// \param PL List of expressions.
4132 void setPrivates(ArrayRef<Expr *> PL);
4133
4134 /// Sets the list of the initial values for linear variables.
4135 /// \param IL List of expressions.
4136 void setInits(ArrayRef<Expr *> IL);
4137
4138public:
4139 /// Creates clause with a list of variables \a VL and a linear step
4140 /// \a Step.
4141 ///
4142 /// \param C AST Context.
4143 /// \param StartLoc Starting location of the clause.
4144 /// \param LParenLoc Location of '('.
4145 /// \param Modifier Modifier of 'linear' clause.
4146 /// \param ModifierLoc Modifier location.
4147 /// \param ColonLoc Location of ':'.
4148 /// \param StepModifierLoc Location of 'step' modifier.
4149 /// \param EndLoc Ending location of the clause.
4150 /// \param VL List of references to the variables.
4151 /// \param PL List of private copies of original variables.
4152 /// \param IL List of initial values for the variables.
4153 /// \param Step Linear step.
4154 /// \param CalcStep Calculation of the linear step.
4155 /// \param PreInit Statement that must be executed before entering the OpenMP
4156 /// region with this clause.
4157 /// \param PostUpdate Expression that must be executed after exit from the
4158 /// OpenMP region with this clause.
4159 static OMPLinearClause *
4160 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4161 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
4162 SourceLocation ColonLoc, SourceLocation StepModifierLoc,
4163 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PL,
4164 ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit,
4165 Expr *PostUpdate);
4166
4167 /// Creates an empty clause with the place for \a NumVars variables.
4168 ///
4169 /// \param C AST context.
4170 /// \param NumVars Number of variables.
4171 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
4172
4173 /// Set modifier.
4175
4176 /// Return modifier.
4177 OpenMPLinearClauseKind getModifier() const { return Modifier; }
4178
4179 /// Set modifier location.
4180 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
4181
4182 /// Return modifier location.
4183 SourceLocation getModifierLoc() const { return ModifierLoc; }
4184
4185 /// Sets the location of ':'.
4186 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4187
4188 /// Sets the location of 'step' modifier.
4189 void setStepModifierLoc(SourceLocation Loc) { StepModifierLoc = Loc; }
4190
4191 /// Returns the location of ':'.
4192 SourceLocation getColonLoc() const { return ColonLoc; }
4193
4194 /// Returns the location of 'step' modifier.
4195 SourceLocation getStepModifierLoc() const { return StepModifierLoc; }
4196
4197 /// Returns linear step.
4198 Expr *getStep() { return *(getFinals().end()); }
4199
4200 /// Returns linear step.
4201 const Expr *getStep() const { return *(getFinals().end()); }
4202
4203 /// Returns expression to calculate linear step.
4204 Expr *getCalcStep() { return *(getFinals().end() + 1); }
4205
4206 /// Returns expression to calculate linear step.
4207 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
4208
4209 /// Sets the list of update expressions for linear variables.
4210 /// \param UL List of expressions.
4212
4213 /// Sets the list of final update expressions for linear variables.
4214 /// \param FL List of expressions.
4215 void setFinals(ArrayRef<Expr *> FL);
4216
4217 /// Sets the list of used expressions for the linear clause.
4219
4222 using privates_range = llvm::iterator_range<privates_iterator>;
4223 using privates_const_range = llvm::iterator_range<privates_const_iterator>;
4224
4226 return privates_range(getPrivates().begin(), getPrivates().end());
4227 }
4228
4230 return privates_const_range(getPrivates().begin(), getPrivates().end());
4231 }
4232
4235 using inits_range = llvm::iterator_range<inits_iterator>;
4236 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
4237
4239 return inits_range(getInits().begin(), getInits().end());
4240 }
4241
4243 return inits_const_range(getInits().begin(), getInits().end());
4244 }
4245
4248 using updates_range = llvm::iterator_range<updates_iterator>;
4249 using updates_const_range = llvm::iterator_range<updates_const_iterator>;
4250
4252 return updates_range(getUpdates().begin(), getUpdates().end());
4253 }
4254
4256 return updates_const_range(getUpdates().begin(), getUpdates().end());
4257 }
4258
4261 using finals_range = llvm::iterator_range<finals_iterator>;
4262 using finals_const_range = llvm::iterator_range<finals_const_iterator>;
4263
4265 return finals_range(getFinals().begin(), getFinals().end());
4266 }
4267
4269 return finals_const_range(getFinals().begin(), getFinals().end());
4270 }
4271
4275 llvm::iterator_range<used_expressions_iterator>;
4277 llvm::iterator_range<used_expressions_const_iterator>;
4278
4280 return finals_range(getUsedExprs().begin(), getUsedExprs().end());
4281 }
4282
4284 return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
4285 }
4286
4288 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4289 reinterpret_cast<Stmt **>(varlist_end()));
4290 }
4291
4293 auto Children = const_cast<OMPLinearClause *>(this)->children();
4294 return const_child_range(Children.begin(), Children.end());
4295 }
4296
4298
4300 auto Children = const_cast<OMPLinearClause *>(this)->used_children();
4301 return const_child_range(Children.begin(), Children.end());
4302 }
4303
4304 static bool classof(const OMPClause *T) {
4305 return T->getClauseKind() == llvm::omp::OMPC_linear;
4306 }
4307};
4308
4309/// This represents clause 'aligned' in the '#pragma omp ...'
4310/// directives.
4311///
4312/// \code
4313/// #pragma omp simd aligned(a,b : 8)
4314/// \endcode
4315/// In this example directive '#pragma omp simd' has clause 'aligned'
4316/// with variables 'a', 'b' and alignment '8'.
4318 : public OMPVarListClause<OMPAlignedClause>,
4319 private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
4320 friend class OMPClauseReader;
4321 friend OMPVarListClause;
4322 friend TrailingObjects;
4323
4324 /// Location of ':'.
4325 SourceLocation ColonLoc;
4326
4327 /// Sets the alignment for clause.
4328 void setAlignment(Expr *A) { *varlist_end() = A; }
4329
4330 /// Build 'aligned' clause with given number of variables \a NumVars.
4331 ///
4332 /// \param StartLoc Starting location of the clause.
4333 /// \param LParenLoc Location of '('.
4334 /// \param ColonLoc Location of ':'.
4335 /// \param EndLoc Ending location of the clause.
4336 /// \param NumVars Number of variables.
4338 SourceLocation ColonLoc, SourceLocation EndLoc,
4339 unsigned NumVars)
4340 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, StartLoc,
4341 LParenLoc, EndLoc, NumVars),
4342 ColonLoc(ColonLoc) {}
4343
4344 /// Build an empty clause.
4345 ///
4346 /// \param NumVars Number of variables.
4347 explicit OMPAlignedClause(unsigned NumVars)
4348 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned,
4349 SourceLocation(), SourceLocation(),
4350 SourceLocation(), NumVars) {}
4351
4352public:
4353 /// Creates clause with a list of variables \a VL and alignment \a A.
4354 ///
4355 /// \param C AST Context.
4356 /// \param StartLoc Starting location of the clause.
4357 /// \param LParenLoc Location of '('.
4358 /// \param ColonLoc Location of ':'.
4359 /// \param EndLoc Ending location of the clause.
4360 /// \param VL List of references to the variables.
4361 /// \param A Alignment.
4362 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
4363 SourceLocation LParenLoc,
4364 SourceLocation ColonLoc,
4365 SourceLocation EndLoc, ArrayRef<Expr *> VL,
4366 Expr *A);
4367
4368 /// Creates an empty clause with the place for \a NumVars variables.
4369 ///
4370 /// \param C AST context.
4371 /// \param NumVars Number of variables.
4372 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
4373
4374 /// Sets the location of ':'.
4375 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4376
4377 /// Returns the location of ':'.
4378 SourceLocation getColonLoc() const { return ColonLoc; }
4379
4380 /// Returns alignment.
4382
4383 /// Returns alignment.
4384 const Expr *getAlignment() const { return *varlist_end(); }
4385
4387 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4388 reinterpret_cast<Stmt **>(varlist_end()));
4389 }
4390
4392 auto Children = const_cast<OMPAlignedClause *>(this)->children();
4393 return const_child_range(Children.begin(), Children.end());
4394 }
4395
4398 }
4401 }
4402
4403 static bool classof(const OMPClause *T) {
4404 return T->getClauseKind() == llvm::omp::OMPC_aligned;
4405 }
4406};
4407
4408/// This represents clause 'copyin' in the '#pragma omp ...' directives.
4409///
4410/// \code
4411/// #pragma omp parallel copyin(a,b)
4412/// \endcode
4413/// In this example directive '#pragma omp parallel' has clause 'copyin'
4414/// with the variables 'a' and 'b'.
4416 : public OMPVarListClause<OMPCopyinClause>,
4417 private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
4418 // Class has 3 additional tail allocated arrays:
4419 // 1. List of helper expressions for proper generation of assignment operation
4420 // required for copyin clause. This list represents sources.
4421 // 2. List of helper expressions for proper generation of assignment operation
4422 // required for copyin clause. This list represents destinations.
4423 // 3. List of helper expressions that represents assignment operation:
4424 // \code
4425 // DstExprs = SrcExprs;
4426 // \endcode
4427 // Required for proper codegen of propagation of master's thread values of
4428 // threadprivate variables to local instances of that variables in other
4429 // implicit threads.
4430
4431 friend class OMPClauseReader;
4432 friend OMPVarListClause;
4433 friend TrailingObjects;
4434
4435 /// Build clause with number of variables \a N.
4436 ///
4437 /// \param StartLoc Starting location of the clause.
4438 /// \param LParenLoc Location of '('.
4439 /// \param EndLoc Ending location of the clause.
4440 /// \param N Number of the variables in the clause.
4441 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4442 SourceLocation EndLoc, unsigned N)
4443 : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin, StartLoc,
4444 LParenLoc, EndLoc, N) {}
4445
4446 /// Build an empty clause.
4447 ///
4448 /// \param N Number of variables.
4449 explicit OMPCopyinClause(unsigned N)
4450 : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin,
4452 SourceLocation(), N) {}
4453
4454 /// Set list of helper expressions, required for proper codegen of the
4455 /// clause. These expressions represent source expression in the final
4456 /// assignment statement performed by the copyin clause.
4457 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
4458
4459 /// Get the list of helper source expressions.
4460 MutableArrayRef<Expr *> getSourceExprs() {
4461 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4462 }
4463 ArrayRef<const Expr *> getSourceExprs() const {
4465 }
4466
4467 /// Set list of helper expressions, required for proper codegen of the
4468 /// clause. These expressions represent destination expression in the final
4469 /// assignment statement performed by the copyin clause.
4470 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
4471
4472 /// Get the list of helper destination expressions.
4473 MutableArrayRef<Expr *> getDestinationExprs() {
4474 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
4475 }
4476 ArrayRef<const Expr *> getDestinationExprs() const {
4477 return llvm::ArrayRef(getSourceExprs().end(), varlist_size());
4478 }
4479
4480 /// Set list of helper assignment expressions, required for proper
4481 /// codegen of the clause. These expressions are assignment expressions that
4482 /// assign source helper expressions to destination helper expressions
4483 /// correspondingly.
4484 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
4485
4486 /// Get the list of helper assignment expressions.
4487 MutableArrayRef<Expr *> getAssignmentOps() {
4488 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
4489 }
4490 ArrayRef<const Expr *> getAssignmentOps() const {
4491 return llvm::ArrayRef(getDestinationExprs().end(), varlist_size());
4492 }
4493
4494public:
4495 /// Creates clause with a list of variables \a VL.
4496 ///
4497 /// \param C AST context.
4498 /// \param StartLoc Starting location of the clause.
4499 /// \param LParenLoc Location of '('.
4500 /// \param EndLoc Ending location of the clause.
4501 /// \param VL List of references to the variables.
4502 /// \param SrcExprs List of helper expressions for proper generation of
4503 /// assignment operation required for copyin clause. This list represents
4504 /// sources.
4505 /// \param DstExprs List of helper expressions for proper generation of
4506 /// assignment operation required for copyin clause. This list represents
4507 /// destinations.
4508 /// \param AssignmentOps List of helper expressions that represents assignment
4509 /// operation:
4510 /// \code
4511 /// DstExprs = SrcExprs;
4512 /// \endcode
4513 /// Required for proper codegen of propagation of master's thread values of
4514 /// threadprivate variables to local instances of that variables in other
4515 /// implicit threads.
4516 static OMPCopyinClause *
4517 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4518 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4519 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
4520
4521 /// Creates an empty clause with \a N variables.
4522 ///
4523 /// \param C AST context.
4524 /// \param N The number of variables.
4525 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
4526
4529 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4531 llvm::iterator_range<helper_expr_const_iterator>;
4532
4534 return helper_expr_const_range(getSourceExprs().begin(),
4535 getSourceExprs().end());
4536 }
4537
4539 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
4540 }
4541
4543 return helper_expr_const_range(getDestinationExprs().begin(),
4544 getDestinationExprs().end());
4545 }
4546
4548 return helper_expr_range(getDestinationExprs().begin(),
4549 getDestinationExprs().end());
4550 }
4551
4553 return helper_expr_const_range(getAssignmentOps().begin(),
4554 getAssignmentOps().end());
4555 }
4556
4558 return helper_expr_range(getAssignmentOps().begin(),
4559 getAssignmentOps().end());
4560 }
4561
4563 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4564 reinterpret_cast<Stmt **>(varlist_end()));
4565 }
4566
4568 auto Children = const_cast<OMPCopyinClause *>(this)->children();
4569 return const_child_range(Children.begin(), Children.end());
4570 }
4571
4574 }
4577 }
4578
4579 static bool classof(const OMPClause *T) {
4580 return T->getClauseKind() == llvm::omp::OMPC_copyin;
4581 }
4582};
4583
4584/// This represents clause 'copyprivate' in the '#pragma omp ...'
4585/// directives.
4586///
4587/// \code
4588/// #pragma omp single copyprivate(a,b)
4589/// \endcode
4590/// In this example directive '#pragma omp single' has clause 'copyprivate'
4591/// with the variables 'a' and 'b'.
4593 : public OMPVarListClause<OMPCopyprivateClause>,
4594 private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
4595 friend class OMPClauseReader;
4596 friend OMPVarListClause;
4597 friend TrailingObjects;
4598
4599 /// Build clause with number of variables \a N.
4600 ///
4601 /// \param StartLoc Starting location of the clause.
4602 /// \param LParenLoc Location of '('.
4603 /// \param EndLoc Ending location of the clause.
4604 /// \param N Number of the variables in the clause.
4606 SourceLocation EndLoc, unsigned N)
4607 : OMPVarListClause<OMPCopyprivateClause>(llvm::omp::OMPC_copyprivate,
4608 StartLoc, LParenLoc, EndLoc, N) {
4609 }
4610
4611 /// Build an empty clause.
4612 ///
4613 /// \param N Number of variables.
4614 explicit OMPCopyprivateClause(unsigned N)
4616 llvm::omp::OMPC_copyprivate, SourceLocation(), SourceLocation(),
4617 SourceLocation(), N) {}
4618
4619 /// Set list of helper expressions, required for proper codegen of the
4620 /// clause. These expressions represent source expression in the final
4621 /// assignment statement performed by the copyprivate clause.
4622 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
4623
4624 /// Get the list of helper source expressions.
4625 MutableArrayRef<Expr *> getSourceExprs() {
4626 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4627 }
4628 ArrayRef<const Expr *> getSourceExprs() const {
4630 }
4631
4632 /// Set list of helper expressions, required for proper codegen of the
4633 /// clause. These expressions represent destination expression in the final
4634 /// assignment statement performed by the copyprivate clause.
4635 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
4636
4637 /// Get the list of helper destination expressions.
4638 MutableArrayRef<Expr *> getDestinationExprs() {
4639 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
4640 }
4641 ArrayRef<const Expr *> getDestinationExprs() const {
4642 return llvm::ArrayRef(getSourceExprs().end(), varlist_size());
4643 }
4644
4645 /// Set list of helper assignment expressions, required for proper
4646 /// codegen of the clause. These expressions are assignment expressions that
4647 /// assign source helper expressions to destination helper expressions
4648 /// correspondingly.
4649 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
4650
4651 /// Get the list of helper assignment expressions.
4652 MutableArrayRef<Expr *> getAssignmentOps() {
4653 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
4654 }
4655 ArrayRef<const Expr *> getAssignmentOps() const {
4656 return llvm::ArrayRef(getDestinationExprs().end(), varlist_size());
4657 }
4658
4659public:
4660 /// Creates clause with a list of variables \a VL.
4661 ///
4662 /// \param C AST context.
4663 /// \param StartLoc Starting location of the clause.
4664 /// \param LParenLoc Location of '('.
4665 /// \param EndLoc Ending location of the clause.
4666 /// \param VL List of references to the variables.
4667 /// \param SrcExprs List of helper expressions for proper generation of
4668 /// assignment operation required for copyprivate clause. This list represents
4669 /// sources.
4670 /// \param DstExprs List of helper expressions for proper generation of
4671 /// assignment operation required for copyprivate clause. This list represents
4672 /// destinations.
4673 /// \param AssignmentOps List of helper expressions that represents assignment
4674 /// operation:
4675 /// \code
4676 /// DstExprs = SrcExprs;
4677 /// \endcode
4678 /// Required for proper codegen of final assignment performed by the
4679 /// copyprivate clause.
4680 static OMPCopyprivateClause *
4681 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4682 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4683 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
4684
4685 /// Creates an empty clause with \a N variables.
4686 ///
4687 /// \param C AST context.
4688 /// \param N The number of variables.
4689 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
4690
4692 using