clang 18.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.
1459 OpenMPAtClauseKind getAtKind() const { return Kind; }
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 clause 'private' in the '#pragma omp ...' directives.
2517///
2518/// \code
2519/// #pragma omp parallel private(a,b)
2520/// \endcode
2521/// In this example directive '#pragma omp parallel' has clause 'private'
2522/// with the variables 'a' and 'b'.
2524 : public OMPVarListClause<OMPPrivateClause>,
2525 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
2526 friend class OMPClauseReader;
2527 friend OMPVarListClause;
2528 friend TrailingObjects;
2529
2530 /// Build clause with number of variables \a N.
2531 ///
2532 /// \param StartLoc Starting location of the clause.
2533 /// \param LParenLoc Location of '('.
2534 /// \param EndLoc Ending location of the clause.
2535 /// \param N Number of the variables in the clause.
2537 SourceLocation EndLoc, unsigned N)
2538 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc,
2539 LParenLoc, EndLoc, N) {}
2540
2541 /// Build an empty clause.
2542 ///
2543 /// \param N Number of variables.
2544 explicit OMPPrivateClause(unsigned N)
2545 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private,
2547 SourceLocation(), N) {}
2548
2549 /// Sets the list of references to private copies with initializers for
2550 /// new private variables.
2551 /// \param VL List of references.
2552 void setPrivateCopies(ArrayRef<Expr *> VL);
2553
2554 /// Gets the list of references to private copies with initializers for
2555 /// new private variables.
2556 MutableArrayRef<Expr *> getPrivateCopies() {
2557 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2558 }
2559 ArrayRef<const Expr *> getPrivateCopies() const {
2561 }
2562
2563public:
2564 /// Creates clause with a list of variables \a VL.
2565 ///
2566 /// \param C AST context.
2567 /// \param StartLoc Starting location of the clause.
2568 /// \param LParenLoc Location of '('.
2569 /// \param EndLoc Ending location of the clause.
2570 /// \param VL List of references to the variables.
2571 /// \param PrivateVL List of references to private copies with initializers.
2572 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2573 SourceLocation LParenLoc,
2574 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2575 ArrayRef<Expr *> PrivateVL);
2576
2577 /// Creates an empty clause with the place for \a N variables.
2578 ///
2579 /// \param C AST context.
2580 /// \param N The number of variables.
2581 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2582
2585 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2587 llvm::iterator_range<private_copies_const_iterator>;
2588
2590 return private_copies_range(getPrivateCopies().begin(),
2591 getPrivateCopies().end());
2592 }
2593
2595 return private_copies_const_range(getPrivateCopies().begin(),
2596 getPrivateCopies().end());
2597 }
2598
2600 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2601 reinterpret_cast<Stmt **>(varlist_end()));
2602 }
2603
2605 auto Children = const_cast<OMPPrivateClause *>(this)->children();
2606 return const_child_range(Children.begin(), Children.end());
2607 }
2608
2611 }
2614 }
2615
2616 static bool classof(const OMPClause *T) {
2617 return T->getClauseKind() == llvm::omp::OMPC_private;
2618 }
2619};
2620
2621/// This represents clause 'firstprivate' in the '#pragma omp ...'
2622/// directives.
2623///
2624/// \code
2625/// #pragma omp parallel firstprivate(a,b)
2626/// \endcode
2627/// In this example directive '#pragma omp parallel' has clause 'firstprivate'
2628/// with the variables 'a' and 'b'.
2630 : public OMPVarListClause<OMPFirstprivateClause>,
2631 public OMPClauseWithPreInit,
2632 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
2633 friend class OMPClauseReader;
2634 friend OMPVarListClause;
2635 friend TrailingObjects;
2636
2637 /// Build clause with number of variables \a N.
2638 ///
2639 /// \param StartLoc Starting location of the clause.
2640 /// \param LParenLoc Location of '('.
2641 /// \param EndLoc Ending location of the clause.
2642 /// \param N Number of the variables in the clause.
2644 SourceLocation EndLoc, unsigned N)
2645 : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate,
2646 StartLoc, LParenLoc, EndLoc, N),
2647 OMPClauseWithPreInit(this) {}
2648
2649 /// Build an empty clause.
2650 ///
2651 /// \param N Number of variables.
2652 explicit OMPFirstprivateClause(unsigned N)
2654 llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(),
2655 SourceLocation(), N),
2656 OMPClauseWithPreInit(this) {}
2657
2658 /// Sets the list of references to private copies with initializers for
2659 /// new private variables.
2660 /// \param VL List of references.
2661 void setPrivateCopies(ArrayRef<Expr *> VL);
2662
2663 /// Gets the list of references to private copies with initializers for
2664 /// new private variables.
2665 MutableArrayRef<Expr *> getPrivateCopies() {
2666 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2667 }
2668 ArrayRef<const Expr *> getPrivateCopies() const {
2670 }
2671
2672 /// Sets the list of references to initializer variables for new
2673 /// private variables.
2674 /// \param VL List of references.
2675 void setInits(ArrayRef<Expr *> VL);
2676
2677 /// Gets the list of references to initializer variables for new
2678 /// private variables.
2679 MutableArrayRef<Expr *> getInits() {
2680 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2681 }
2682 ArrayRef<const Expr *> getInits() const {
2683 return llvm::ArrayRef(getPrivateCopies().end(), varlist_size());
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 original variables.
2694 /// \param PrivateVL List of references to private copies with initializers.
2695 /// \param InitVL List of references to auto generated variables used for
2696 /// initialization of a single array element. Used if firstprivate variable is
2697 /// of array type.
2698 /// \param PreInit Statement that must be executed before entering the OpenMP
2699 /// region with this clause.
2700 static OMPFirstprivateClause *
2701 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2702 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
2703 ArrayRef<Expr *> InitVL, Stmt *PreInit);
2704
2705 /// Creates an empty clause with the place for \a N variables.
2706 ///
2707 /// \param C AST context.
2708 /// \param N The number of variables.
2709 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2710
2713 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2715 llvm::iterator_range<private_copies_const_iterator>;
2716
2718 return private_copies_range(getPrivateCopies().begin(),
2719 getPrivateCopies().end());
2720 }
2722 return private_copies_const_range(getPrivateCopies().begin(),
2723 getPrivateCopies().end());
2724 }
2725
2728 using inits_range = llvm::iterator_range<inits_iterator>;
2729 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2730
2732 return inits_range(getInits().begin(), getInits().end());
2733 }
2735 return inits_const_range(getInits().begin(), getInits().end());
2736 }
2737
2739 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2740 reinterpret_cast<Stmt **>(varlist_end()));
2741 }
2742
2744 auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
2745 return const_child_range(Children.begin(), Children.end());
2746 }
2747
2749 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2750 reinterpret_cast<Stmt **>(varlist_end()));
2751 }
2753 auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
2754 return const_child_range(Children.begin(), Children.end());
2755 }
2756
2757 static bool classof(const OMPClause *T) {
2758 return T->getClauseKind() == llvm::omp::OMPC_firstprivate;
2759 }
2760};
2761
2762/// This represents clause 'lastprivate' in the '#pragma omp ...'
2763/// directives.
2764///
2765/// \code
2766/// #pragma omp simd lastprivate(a,b)
2767/// \endcode
2768/// In this example directive '#pragma omp simd' has clause 'lastprivate'
2769/// with the variables 'a' and 'b'.
2771 : public OMPVarListClause<OMPLastprivateClause>,
2773 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
2774 // There are 4 additional tail-allocated arrays at the end of the class:
2775 // 1. Contains list of pseudo variables with the default initialization for
2776 // each non-firstprivate variables. Used in codegen for initialization of
2777 // lastprivate copies.
2778 // 2. List of helper expressions for proper generation of assignment operation
2779 // required for lastprivate clause. This list represents private variables
2780 // (for arrays, single array element).
2781 // 3. List of helper expressions for proper generation of assignment operation
2782 // required for lastprivate clause. This list represents original variables
2783 // (for arrays, single array element).
2784 // 4. List of helper expressions that represents assignment operation:
2785 // \code
2786 // DstExprs = SrcExprs;
2787 // \endcode
2788 // Required for proper codegen of final assignment performed by the
2789 // lastprivate clause.
2790 friend class OMPClauseReader;
2791 friend OMPVarListClause;
2792 friend TrailingObjects;
2793
2794 /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
2796 /// Optional location of the lasptrivate kind, if specified by user.
2797 SourceLocation LPKindLoc;
2798 /// Optional colon location, if specified by user.
2799 SourceLocation ColonLoc;
2800
2801 /// Build clause with number of variables \a N.
2802 ///
2803 /// \param StartLoc Starting location of the clause.
2804 /// \param LParenLoc Location of '('.
2805 /// \param EndLoc Ending location of the clause.
2806 /// \param N Number of the variables in the clause.
2809 SourceLocation LPKindLoc, SourceLocation ColonLoc,
2810 unsigned N)
2811 : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate,
2812 StartLoc, LParenLoc, EndLoc, N),
2813 OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
2814 ColonLoc(ColonLoc) {}
2815
2816 /// Build an empty clause.
2817 ///
2818 /// \param N Number of variables.
2819 explicit OMPLastprivateClause(unsigned N)
2821 llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(),
2822 SourceLocation(), N),
2824
2825 /// Get the list of helper expressions for initialization of private
2826 /// copies for lastprivate variables.
2827 MutableArrayRef<Expr *> getPrivateCopies() {
2828 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2829 }
2830 ArrayRef<const Expr *> getPrivateCopies() const {
2832 }
2833
2834 /// Set list of helper expressions, required for proper codegen of the
2835 /// clause. These expressions represent private variables (for arrays, single
2836 /// array element) in the final assignment statement performed by the
2837 /// lastprivate clause.
2838 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2839
2840 /// Get the list of helper source expressions.
2841 MutableArrayRef<Expr *> getSourceExprs() {
2842 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2843 }
2844 ArrayRef<const Expr *> getSourceExprs() const {
2845 return llvm::ArrayRef(getPrivateCopies().end(), varlist_size());
2846 }
2847
2848 /// Set list of helper expressions, required for proper codegen of the
2849 /// clause. These expressions represent original variables (for arrays, single
2850 /// array element) in the final assignment statement performed by the
2851 /// lastprivate clause.
2852 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2853
2854 /// Get the list of helper destination expressions.
2855 MutableArrayRef<Expr *> getDestinationExprs() {
2856 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2857 }
2858 ArrayRef<const Expr *> getDestinationExprs() const {
2859 return llvm::ArrayRef(getSourceExprs().end(), varlist_size());
2860 }
2861
2862 /// Set list of helper assignment expressions, required for proper
2863 /// codegen of the clause. These expressions are assignment expressions that
2864 /// assign private copy of the variable to original variable.
2865 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2866
2867 /// Get the list of helper assignment expressions.
2868 MutableArrayRef<Expr *> getAssignmentOps() {
2869 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2870 }
2871 ArrayRef<const Expr *> getAssignmentOps() const {
2872 return llvm::ArrayRef(getDestinationExprs().end(), varlist_size());
2873 }
2874
2875 /// Sets lastprivate kind.
2876 void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
2877 /// Sets location of the lastprivate kind.
2878 void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
2879 /// Sets colon symbol location.
2880 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2881
2882public:
2883 /// Creates clause with a list of variables \a VL.
2884 ///
2885 /// \param C AST context.
2886 /// \param StartLoc Starting location of the clause.
2887 /// \param LParenLoc Location of '('.
2888 /// \param EndLoc Ending location of the clause.
2889 /// \param VL List of references to the variables.
2890 /// \param SrcExprs List of helper expressions for proper generation of
2891 /// assignment operation required for lastprivate clause. This list represents
2892 /// private variables (for arrays, single array element).
2893 /// \param DstExprs List of helper expressions for proper generation of
2894 /// assignment operation required for lastprivate clause. This list represents
2895 /// original variables (for arrays, single array element).
2896 /// \param AssignmentOps List of helper expressions that represents assignment
2897 /// operation:
2898 /// \code
2899 /// DstExprs = SrcExprs;
2900 /// \endcode
2901 /// Required for proper codegen of final assignment performed by the
2902 /// lastprivate clause.
2903 /// \param LPKind Lastprivate kind, e.g. 'conditional'.
2904 /// \param LPKindLoc Location of the lastprivate kind.
2905 /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
2906 /// \param PreInit Statement that must be executed before entering the OpenMP
2907 /// region with this clause.
2908 /// \param PostUpdate Expression that must be executed after exit from the
2909 /// OpenMP region with this clause.
2910 static OMPLastprivateClause *
2911 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2912 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2913 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
2914 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
2915 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
2916
2917 /// Creates an empty clause with the place for \a N variables.
2918 ///
2919 /// \param C AST context.
2920 /// \param N The number of variables.
2921 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2922
2923 /// Lastprivate kind.
2924 OpenMPLastprivateModifier getKind() const { return LPKind; }
2925 /// Returns the location of the lastprivate kind.
2926 SourceLocation getKindLoc() const { return LPKindLoc; }
2927 /// Returns the location of the ':' symbol, if any.
2928 SourceLocation getColonLoc() const { return ColonLoc; }
2929
2932 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2934 llvm::iterator_range<helper_expr_const_iterator>;
2935
2936 /// Set list of helper expressions, required for generation of private
2937 /// copies of original lastprivate variables.
2938 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
2939
2941 return helper_expr_const_range(getPrivateCopies().begin(),
2942 getPrivateCopies().end());
2943 }
2944
2946 return helper_expr_range(getPrivateCopies().begin(),
2947 getPrivateCopies().end());
2948 }
2949
2951 return helper_expr_const_range(getSourceExprs().begin(),
2952 getSourceExprs().end());
2953 }
2954
2956 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2957 }
2958
2960 return helper_expr_const_range(getDestinationExprs().begin(),
2961 getDestinationExprs().end());
2962 }
2963
2965 return helper_expr_range(getDestinationExprs().begin(),
2966 getDestinationExprs().end());
2967 }
2968
2970 return helper_expr_const_range(getAssignmentOps().begin(),
2971 getAssignmentOps().end());
2972 }
2973
2975 return helper_expr_range(getAssignmentOps().begin(),
2976 getAssignmentOps().end());
2977 }
2978
2980 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2981 reinterpret_cast<Stmt **>(varlist_end()));
2982 }
2983
2985 auto Children = const_cast<OMPLastprivateClause *>(this)->children();
2986 return const_child_range(Children.begin(), Children.end());
2987 }
2988
2991 }
2994 }
2995
2996 static bool classof(const OMPClause *T) {
2997 return T->getClauseKind() == llvm::omp::OMPC_lastprivate;
2998 }
2999};
3000
3001/// This represents clause 'shared' in the '#pragma omp ...' directives.
3002///
3003/// \code
3004/// #pragma omp parallel shared(a,b)
3005/// \endcode
3006/// In this example directive '#pragma omp parallel' has clause 'shared'
3007/// with the variables 'a' and 'b'.
3009 : public OMPVarListClause<OMPSharedClause>,
3010 private llvm::TrailingObjects<OMPSharedClause, Expr *> {
3011 friend OMPVarListClause;
3012 friend TrailingObjects;
3013
3014 /// Build clause with number of variables \a N.
3015 ///
3016 /// \param StartLoc Starting location of the clause.
3017 /// \param LParenLoc Location of '('.
3018 /// \param EndLoc Ending location of the clause.
3019 /// \param N Number of the variables in the clause.
3020 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3021 SourceLocation EndLoc, unsigned N)
3022 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, StartLoc,
3023 LParenLoc, EndLoc, N) {}
3024
3025 /// Build an empty clause.
3026 ///
3027 /// \param N Number of variables.
3028 explicit OMPSharedClause(unsigned N)
3029 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared,
3031 SourceLocation(), N) {}
3032
3033public:
3034 /// Creates clause with a list of variables \a VL.
3035 ///
3036 /// \param C AST context.
3037 /// \param StartLoc Starting location of the clause.
3038 /// \param LParenLoc Location of '('.
3039 /// \param EndLoc Ending location of the clause.
3040 /// \param VL List of references to the variables.
3041 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
3042 SourceLocation LParenLoc,
3043 SourceLocation EndLoc, ArrayRef<Expr *> VL);
3044
3045 /// Creates an empty clause with \a N variables.
3046 ///
3047 /// \param C AST context.
3048 /// \param N The number of variables.
3049 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
3050
3052 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3053 reinterpret_cast<Stmt **>(varlist_end()));
3054 }
3055
3057 auto Children = const_cast<OMPSharedClause *>(this)->children();
3058 return const_child_range(Children.begin(), Children.end());
3059 }
3060
3063 }
3066 }
3067
3068 static bool classof(const OMPClause *T) {
3069 return T->getClauseKind() == llvm::omp::OMPC_shared;
3070 }
3071};
3072
3073/// This represents clause 'reduction' in the '#pragma omp ...'
3074/// directives.
3075///
3076/// \code
3077/// #pragma omp parallel reduction(+:a,b)
3078/// \endcode
3079/// In this example directive '#pragma omp parallel' has clause 'reduction'
3080/// with operator '+' and the variables 'a' and 'b'.
3082 : public OMPVarListClause<OMPReductionClause>,
3084 private llvm::TrailingObjects<OMPReductionClause, Expr *> {
3085 friend class OMPClauseReader;
3086 friend OMPVarListClause;
3087 friend TrailingObjects;
3088
3089 /// Reduction modifier.
3091
3092 /// Reduction modifier location.
3093 SourceLocation ModifierLoc;
3094
3095 /// Location of ':'.
3096 SourceLocation ColonLoc;
3097
3098 /// Nested name specifier for C++.
3099 NestedNameSpecifierLoc QualifierLoc;
3100
3101 /// Name of custom operator.
3102 DeclarationNameInfo NameInfo;
3103
3104 /// Build clause with number of variables \a N.
3105 ///
3106 /// \param StartLoc Starting location of the clause.
3107 /// \param LParenLoc Location of '('.
3108 /// \param ModifierLoc Modifier location.
3109 /// \param ColonLoc Location of ':'.
3110 /// \param EndLoc Ending location of the clause.
3111 /// \param N Number of the variables in the clause.
3112 /// \param QualifierLoc The nested-name qualifier with location information
3113 /// \param NameInfo The full name info for reduction identifier.
3115 SourceLocation ModifierLoc, SourceLocation ColonLoc,
3116 SourceLocation EndLoc,
3117 OpenMPReductionClauseModifier Modifier, unsigned N,
3118 NestedNameSpecifierLoc QualifierLoc,
3119 const DeclarationNameInfo &NameInfo)
3120 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
3121 StartLoc, LParenLoc, EndLoc, N),
3122 OMPClauseWithPostUpdate(this), Modifier(Modifier),
3123 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
3124 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3125
3126 /// Build an empty clause.
3127 ///
3128 /// \param N Number of variables.
3129 explicit OMPReductionClause(unsigned N)
3130 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
3132 SourceLocation(), N),
3134
3135 /// Sets reduction modifier.
3136 void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; }
3137
3138 /// Sets location of the modifier.
3139 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
3140
3141 /// Sets location of ':' symbol in clause.
3142 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3143
3144 /// Sets the name info for specified reduction identifier.
3145 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3146
3147 /// Sets the nested name specifier.
3148 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3149
3150 /// Set list of helper expressions, required for proper codegen of the
3151 /// clause. These expressions represent private copy of the reduction
3152 /// variable.
3153 void setPrivates(ArrayRef<Expr *> Privates);
3154
3155 /// Get the list of helper privates.
3156 MutableArrayRef<Expr *> getPrivates() {
3157 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3158 }
3159 ArrayRef<const Expr *> getPrivates() const {
3161 }
3162
3163 /// Set list of helper expressions, required for proper codegen of the
3164 /// clause. These expressions represent LHS expression in the final
3165 /// reduction expression performed by the reduction clause.
3166 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3167
3168 /// Get the list of helper LHS expressions.
3169 MutableArrayRef<Expr *> getLHSExprs() {
3170 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3171 }
3172 ArrayRef<const Expr *> getLHSExprs() const {
3173 return llvm::ArrayRef(getPrivates().end(), varlist_size());
3174 }
3175
3176 /// Set list of helper expressions, required for proper codegen of the
3177 /// clause. These expressions represent RHS expression in the final
3178 /// reduction expression performed by the reduction clause.
3179 /// Also, variables in these expressions are used for proper initialization of
3180 /// reduction copies.
3181 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3182
3183 /// Get the list of helper destination expressions.
3184 MutableArrayRef<Expr *> getRHSExprs() {
3185 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3186 }
3187 ArrayRef<const Expr *> getRHSExprs() const {
3188 return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
3189 }
3190
3191 /// Set list of helper reduction expressions, required for proper
3192 /// codegen of the clause. These expressions are binary expressions or
3193 /// operator/custom reduction call that calculates new value from source
3194 /// helper expressions to destination helper expressions.
3195 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3196
3197 /// Get the list of helper reduction expressions.
3198 MutableArrayRef<Expr *> getReductionOps() {
3199 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3200 }
3201 ArrayRef<const Expr *> getReductionOps() const {
3202 return llvm::ArrayRef(getRHSExprs().end(), varlist_size());
3203 }
3204
3205 /// Set list of helper copy operations for inscan reductions.
3206 /// The form is: Temps[i] = LHS[i];
3207 void setInscanCopyOps(ArrayRef<Expr *> Ops);
3208
3209 /// Get the list of helper inscan copy operations.
3210 MutableArrayRef<Expr *> getInscanCopyOps() {
3211 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3212 }
3213 ArrayRef<const Expr *> getInscanCopyOps() const {
3214 return llvm::ArrayRef(getReductionOps().end(), varlist_size());
3215 }
3216
3217 /// Set list of helper temp vars for inscan copy array operations.
3218 void setInscanCopyArrayTemps(ArrayRef<Expr *> CopyArrayTemps);
3219
3220 /// Get the list of helper inscan copy temps.
3221 MutableArrayRef<Expr *> getInscanCopyArrayTemps() {
3222 return MutableArrayRef<Expr *>(getInscanCopyOps().end(), varlist_size());
3223 }
3224 ArrayRef<const Expr *> getInscanCopyArrayTemps() const {
3225 return llvm::ArrayRef(getInscanCopyOps().end(), varlist_size());
3226 }
3227
3228 /// Set list of helper temp elements vars for inscan copy array operations.
3229 void setInscanCopyArrayElems(ArrayRef<Expr *> CopyArrayElems);
3230
3231 /// Get the list of helper inscan copy temps.
3232 MutableArrayRef<Expr *> getInscanCopyArrayElems() {
3233 return MutableArrayRef<Expr *>(getInscanCopyArrayTemps().end(),
3234 varlist_size());
3235 }
3236 ArrayRef<const Expr *> getInscanCopyArrayElems() const {
3237 return llvm::ArrayRef(getInscanCopyArrayTemps().end(), varlist_size());
3238 }
3239
3240public:
3241 /// Creates clause with a list of variables \a VL.
3242 ///
3243 /// \param StartLoc Starting location of the clause.
3244 /// \param LParenLoc Location of '('.
3245 /// \param ModifierLoc Modifier location.
3246 /// \param ColonLoc Location of ':'.
3247 /// \param EndLoc Ending location of the clause.
3248 /// \param VL The variables in the clause.
3249 /// \param QualifierLoc The nested-name qualifier with location information
3250 /// \param NameInfo The full name info for reduction identifier.
3251 /// \param Privates List of helper expressions for proper generation of
3252 /// private copies.
3253 /// \param LHSExprs List of helper expressions for proper generation of
3254 /// assignment operation required for copyprivate clause. This list represents
3255 /// LHSs of the reduction expressions.
3256 /// \param RHSExprs List of helper expressions for proper generation of
3257 /// assignment operation required for copyprivate clause. This list represents
3258 /// RHSs of the reduction expressions.
3259 /// Also, variables in these expressions are used for proper initialization of
3260 /// reduction copies.
3261 /// \param ReductionOps List of helper expressions that represents reduction
3262 /// expressions:
3263 /// \code
3264 /// LHSExprs binop RHSExprs;
3265 /// operator binop(LHSExpr, RHSExpr);
3266 /// <CutomReduction>(LHSExpr, RHSExpr);
3267 /// \endcode
3268 /// Required for proper codegen of final reduction operation performed by the
3269 /// reduction clause.
3270 /// \param CopyOps List of copy operations for inscan reductions:
3271 /// \code
3272 /// TempExprs = LHSExprs;
3273 /// \endcode
3274 /// \param CopyArrayTemps Temp arrays for prefix sums.
3275 /// \param CopyArrayElems Temp arrays for prefix sums.
3276 /// \param PreInit Statement that must be executed before entering the OpenMP
3277 /// region with this clause.
3278 /// \param PostUpdate Expression that must be executed after exit from the
3279 /// OpenMP region with this clause.
3280 static OMPReductionClause *
3281 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3282 SourceLocation ModifierLoc, SourceLocation ColonLoc,
3283 SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier,
3284 ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc,
3285 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3286 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3287 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> CopyOps,
3288 ArrayRef<Expr *> CopyArrayTemps, ArrayRef<Expr *> CopyArrayElems,
3289 Stmt *PreInit, Expr *PostUpdate);
3290
3291 /// Creates an empty clause with the place for \a N variables.
3292 ///
3293 /// \param C AST context.
3294 /// \param N The number of variables.
3295 /// \param Modifier Reduction modifier.
3296 static OMPReductionClause *
3297 CreateEmpty(const ASTContext &C, unsigned N,
3299
3300 /// Returns modifier.
3301 OpenMPReductionClauseModifier getModifier() const { return Modifier; }
3302
3303 /// Returns modifier location.
3304 SourceLocation getModifierLoc() const { return ModifierLoc; }
3305
3306 /// Gets location of ':' symbol in clause.
3307 SourceLocation getColonLoc() const { return ColonLoc; }
3308
3309 /// Gets the name info for specified reduction identifier.
3310 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3311
3312 /// Gets the nested name specifier.
3313 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3314
3317 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3319 llvm::iterator_range<helper_expr_const_iterator>;
3320
3322 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3323 }
3324
3326 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3327 }
3328
3330 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3331 }
3332
3334 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3335 }
3336
3338 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3339 }
3340
3342 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3343 }
3344
3346 return helper_expr_const_range(getReductionOps().begin(),
3347 getReductionOps().end());
3348 }
3349
3351 return helper_expr_range(getReductionOps().begin(),
3352 getReductionOps().end());
3353 }
3354
3356 return helper_expr_const_range(getInscanCopyOps().begin(),
3357 getInscanCopyOps().end());
3358 }
3359
3361 return helper_expr_range(getInscanCopyOps().begin(),
3362 getInscanCopyOps().end());
3363 }
3364
3366 return helper_expr_const_range(getInscanCopyArrayTemps().begin(),
3367 getInscanCopyArrayTemps().end());
3368 }
3369
3371 return helper_expr_range(getInscanCopyArrayTemps().begin(),
3372 getInscanCopyArrayTemps().end());
3373 }
3374
3376 return helper_expr_const_range(getInscanCopyArrayElems().begin(),
3377 getInscanCopyArrayElems().end());
3378 }
3379
3381 return helper_expr_range(getInscanCopyArrayElems().begin(),
3382 getInscanCopyArrayElems().end());
3383 }
3384
3386 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3387 reinterpret_cast<Stmt **>(varlist_end()));
3388 }
3389
3391 auto Children = const_cast<OMPReductionClause *>(this)->children();
3392 return const_child_range(Children.begin(), Children.end());
3393 }
3394
3396 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3397 reinterpret_cast<Stmt **>(varlist_end()));
3398 }
3400 auto Children = const_cast<OMPReductionClause *>(this)->used_children();
3401 return const_child_range(Children.begin(), Children.end());
3402 }
3403
3404 static bool classof(const OMPClause *T) {
3405 return T->getClauseKind() == llvm::omp::OMPC_reduction;
3406 }
3407};
3408
3409/// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
3410/// directives.
3411///
3412/// \code
3413/// #pragma omp taskgroup task_reduction(+:a,b)
3414/// \endcode
3415/// In this example directive '#pragma omp taskgroup' has clause
3416/// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
3418 : public OMPVarListClause<OMPTaskReductionClause>,
3420 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
3421 friend class OMPClauseReader;
3422 friend OMPVarListClause;
3423 friend TrailingObjects;
3424
3425 /// Location of ':'.
3426 SourceLocation ColonLoc;
3427
3428 /// Nested name specifier for C++.
3429 NestedNameSpecifierLoc QualifierLoc;
3430
3431 /// Name of custom operator.
3432 DeclarationNameInfo NameInfo;
3433
3434 /// Build clause with number of variables \a N.
3435 ///
3436 /// \param StartLoc Starting location of the clause.
3437 /// \param LParenLoc Location of '('.
3438 /// \param EndLoc Ending location of the clause.
3439 /// \param ColonLoc Location of ':'.
3440 /// \param N Number of the variables in the clause.
3441 /// \param QualifierLoc The nested-name qualifier with location information
3442 /// \param NameInfo The full name info for reduction identifier.
3444 SourceLocation ColonLoc, SourceLocation EndLoc,
3445 unsigned N, NestedNameSpecifierLoc QualifierLoc,
3446 const DeclarationNameInfo &NameInfo)
3448 llvm::omp::OMPC_task_reduction, StartLoc, LParenLoc, EndLoc, N),
3449 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3450 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3451
3452 /// Build an empty clause.
3453 ///
3454 /// \param N Number of variables.
3455 explicit OMPTaskReductionClause(unsigned N)
3457 llvm::omp::OMPC_task_reduction, SourceLocation(), SourceLocation(),
3458 SourceLocation(), N),
3460
3461 /// Sets location of ':' symbol in clause.
3462 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3463
3464 /// Sets the name info for specified reduction identifier.
3465 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3466
3467 /// Sets the nested name specifier.
3468 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3469
3470 /// Set list of helper expressions, required for proper codegen of the clause.
3471 /// These expressions represent private copy of the reduction variable.
3472 void setPrivates(ArrayRef<Expr *> Privates);
3473
3474 /// Get the list of helper privates.
3475 MutableArrayRef<Expr *> getPrivates() {
3476 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3477 }
3478 ArrayRef<const Expr *> getPrivates() const {
3480 }
3481
3482 /// Set list of helper expressions, required for proper codegen of the clause.
3483 /// These expressions represent LHS expression in the final reduction
3484 /// expression performed by the reduction clause.
3485 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3486
3487 /// Get the list of helper LHS expressions.
3488 MutableArrayRef<Expr *> getLHSExprs() {
3489 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3490 }
3491 ArrayRef<const Expr *> getLHSExprs() const {
3492 return llvm::ArrayRef(getPrivates().end(), varlist_size());
3493 }
3494
3495 /// Set list of helper expressions, required for proper codegen of the clause.
3496 /// These expressions represent RHS expression in the final reduction
3497 /// expression performed by the reduction clause. Also, variables in these
3498 /// expressions are used for proper initialization of reduction copies.
3499 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3500
3501 /// Get the list of helper destination expressions.
3502 MutableArrayRef<Expr *> getRHSExprs() {
3503 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3504 }
3505 ArrayRef<const Expr *> getRHSExprs() const {
3506 return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
3507 }
3508
3509 /// Set list of helper reduction expressions, required for proper
3510 /// codegen of the clause. These expressions are binary expressions or
3511 /// operator/custom reduction call that calculates new value from source
3512 /// helper expressions to destination helper expressions.
3513 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3514
3515 /// Get the list of helper reduction expressions.
3516 MutableArrayRef<Expr *> getReductionOps() {
3517 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3518 }
3519 ArrayRef<const Expr *> getReductionOps() const {
3520 return llvm::ArrayRef(getRHSExprs().end(), varlist_size());
3521 }
3522
3523public:
3524 /// Creates clause with a list of variables \a VL.
3525 ///
3526 /// \param StartLoc Starting location of the clause.
3527 /// \param LParenLoc Location of '('.
3528 /// \param ColonLoc Location of ':'.
3529 /// \param EndLoc Ending location of the clause.
3530 /// \param VL The variables in the clause.
3531 /// \param QualifierLoc The nested-name qualifier with location information
3532 /// \param NameInfo The full name info for reduction identifier.
3533 /// \param Privates List of helper expressions for proper generation of
3534 /// private copies.
3535 /// \param LHSExprs List of helper expressions for proper generation of
3536 /// assignment operation required for copyprivate clause. This list represents
3537 /// LHSs of the reduction expressions.
3538 /// \param RHSExprs List of helper expressions for proper generation of
3539 /// assignment operation required for copyprivate clause. This list represents
3540 /// RHSs of the reduction expressions.
3541 /// Also, variables in these expressions are used for proper initialization of
3542 /// reduction copies.
3543 /// \param ReductionOps List of helper expressions that represents reduction
3544 /// expressions:
3545 /// \code
3546 /// LHSExprs binop RHSExprs;
3547 /// operator binop(LHSExpr, RHSExpr);
3548 /// <CutomReduction>(LHSExpr, RHSExpr);
3549 /// \endcode
3550 /// Required for proper codegen of final reduction operation performed by the
3551 /// reduction clause.
3552 /// \param PreInit Statement that must be executed before entering the OpenMP
3553 /// region with this clause.
3554 /// \param PostUpdate Expression that must be executed after exit from the
3555 /// OpenMP region with this clause.
3556 static OMPTaskReductionClause *
3557 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3558 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3559 NestedNameSpecifierLoc QualifierLoc,
3560 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3561 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3562 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
3563
3564 /// Creates an empty clause with the place for \a N variables.
3565 ///
3566 /// \param C AST context.
3567 /// \param N The number of variables.
3568 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3569
3570 /// Gets location of ':' symbol in clause.
3571 SourceLocation getColonLoc() const { return ColonLoc; }
3572
3573 /// Gets the name info for specified reduction identifier.
3574 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3575
3576 /// Gets the nested name specifier.
3577 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3578
3581 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3583 llvm::iterator_range<helper_expr_const_iterator>;
3584
3586 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3587 }
3588
3590 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3591 }
3592
3594 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3595 }
3596
3598 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3599 }
3600
3602 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3603 }
3604
3606 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3607 }
3608
3610 return helper_expr_const_range(getReductionOps().begin(),
3611 getReductionOps().end());
3612 }
3613
3615 return helper_expr_range(getReductionOps().begin(),
3616 getReductionOps().end());
3617 }
3618
3620 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3621 reinterpret_cast<Stmt **>(varlist_end()));
3622 }
3623
3625 auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
3626 return const_child_range(Children.begin(), Children.end());
3627 }
3628
3631 }
3634 }
3635
3636 static bool classof(const OMPClause *T) {
3637 return T->getClauseKind() == llvm::omp::OMPC_task_reduction;
3638 }
3639};
3640
3641/// This represents clause 'in_reduction' in the '#pragma omp task' directives.
3642///
3643/// \code
3644/// #pragma omp task in_reduction(+:a,b)
3645/// \endcode
3646/// In this example directive '#pragma omp task' has clause 'in_reduction' with
3647/// operator '+' and the variables 'a' and 'b'.
3649 : public OMPVarListClause<OMPInReductionClause>,
3651 private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
3652 friend class OMPClauseReader;
3653 friend OMPVarListClause;
3654 friend TrailingObjects;
3655
3656 /// Location of ':'.
3657 SourceLocation ColonLoc;
3658
3659 /// Nested name specifier for C++.
3660 NestedNameSpecifierLoc QualifierLoc;
3661
3662 /// Name of custom operator.
3663 DeclarationNameInfo NameInfo;
3664
3665 /// Build clause with number of variables \a N.
3666 ///
3667 /// \param StartLoc Starting location of the clause.
3668 /// \param LParenLoc Location of '('.
3669 /// \param EndLoc Ending location of the clause.
3670 /// \param ColonLoc Location of ':'.
3671 /// \param N Number of the variables in the clause.
3672 /// \param QualifierLoc The nested-name qualifier with location information
3673 /// \param NameInfo The full name info for reduction identifier.
3675 SourceLocation ColonLoc, SourceLocation EndLoc,
3676 unsigned N, NestedNameSpecifierLoc QualifierLoc,
3677 const DeclarationNameInfo &NameInfo)
3678 : OMPVarListClause<OMPInReductionClause>(llvm::omp::OMPC_in_reduction,
3679 StartLoc, LParenLoc, EndLoc, N),
3680 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3681 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3682
3683 /// Build an empty clause.
3684 ///
3685 /// \param N Number of variables.
3686 explicit OMPInReductionClause(unsigned N)
3688 llvm::omp::OMPC_in_reduction, SourceLocation(), SourceLocation(),
3689 SourceLocation(), N),
3691
3692 /// Sets location of ':' symbol in clause.
3693 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3694
3695 /// Sets the name info for specified reduction identifier.
3696 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3697
3698 /// Sets the nested name specifier.
3699 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3700
3701 /// Set list of helper expressions, required for proper codegen of the clause.
3702 /// These expressions represent private copy of the reduction variable.
3703 void setPrivates(ArrayRef<Expr *> Privates);
3704
3705 /// Get the list of helper privates.
3706 MutableArrayRef<Expr *> getPrivates() {
3707 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3708 }
3709 ArrayRef<const Expr *> getPrivates() const {
3711 }
3712
3713 /// Set list of helper expressions, required for proper codegen of the clause.
3714 /// These expressions represent LHS expression in the final reduction
3715 /// expression performed by the reduction clause.
3716 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3717
3718 /// Get the list of helper LHS expressions.
3719 MutableArrayRef<Expr *> getLHSExprs() {
3720 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3721 }
3722 ArrayRef<const Expr *> getLHSExprs() const {
3723 return llvm::ArrayRef(getPrivates().end(), varlist_size());
3724 }
3725
3726 /// Set list of helper expressions, required for proper codegen of the clause.
3727 /// These expressions represent RHS expression in the final reduction
3728 /// expression performed by the reduction clause. Also, variables in these
3729 /// expressions are used for proper initialization of reduction copies.
3730 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3731
3732 /// Get the list of helper destination expressions.
3733 MutableArrayRef<Expr *> getRHSExprs() {
3734 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3735 }
3736 ArrayRef<const Expr *> getRHSExprs() const {
3737 return llvm::ArrayRef(getLHSExprs().end(), varlist_size());
3738 }
3739
3740 /// Set list of helper reduction expressions, required for proper
3741 /// codegen of the clause. These expressions are binary expressions or
3742 /// operator/custom reduction call that calculates new value from source
3743 /// helper expressions to destination helper expressions.
3744 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3745
3746 /// Get the list of helper reduction expressions.
3747 MutableArrayRef<Expr *> getReductionOps() {
3748 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3749 }
3750 ArrayRef<const Expr *> getReductionOps() const {
3751 return llvm::ArrayRef(getRHSExprs().end(), varlist_size());
3752 }
3753
3754 /// Set list of helper reduction taskgroup descriptors.
3755 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
3756
3757 /// Get the list of helper reduction taskgroup descriptors.
3758 MutableArrayRef<Expr *> getTaskgroupDescriptors() {
3759 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3760 }
3761 ArrayRef<const Expr *> getTaskgroupDescriptors() const {
3762 return llvm::ArrayRef(getReductionOps().end(), varlist_size());
3763 }
3764
3765public:
3766 /// Creates clause with a list of variables \a VL.
3767 ///
3768 /// \param StartLoc Starting location of the clause.
3769 /// \param LParenLoc Location of '('.
3770 /// \param ColonLoc Location of ':'.
3771 /// \param EndLoc Ending location of the clause.
3772 /// \param VL The variables in the clause.
3773 /// \param QualifierLoc The nested-name qualifier with location information
3774 /// \param NameInfo The full name info for reduction identifier.
3775 /// \param Privates List of helper expressions for proper generation of
3776 /// private copies.
3777 /// \param LHSExprs List of helper expressions for proper generation of
3778 /// assignment operation required for copyprivate clause. This list represents
3779 /// LHSs of the reduction expressions.
3780 /// \param RHSExprs List of helper expressions for proper generation of
3781 /// assignment operation required for copyprivate clause. This list represents
3782 /// RHSs of the reduction expressions.
3783 /// Also, variables in these expressions are used for proper initialization of
3784 /// reduction copies.
3785 /// \param ReductionOps List of helper expressions that represents reduction
3786 /// expressions:
3787 /// \code
3788 /// LHSExprs binop RHSExprs;
3789 /// operator binop(LHSExpr, RHSExpr);
3790 /// <CutomReduction>(LHSExpr, RHSExpr);
3791 /// \endcode
3792 /// Required for proper codegen of final reduction operation performed by the
3793 /// reduction clause.
3794 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
3795 /// corresponding items in parent taskgroup task_reduction clause.
3796 /// \param PreInit Statement that must be executed before entering the OpenMP
3797 /// region with this clause.
3798 /// \param PostUpdate Expression that must be executed after exit from the
3799 /// OpenMP region with this clause.
3800 static OMPInReductionClause *
3801 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3802 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3803 NestedNameSpecifierLoc QualifierLoc,
3804 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3805 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3806 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
3807 Stmt *PreInit, Expr *PostUpdate);
3808
3809 /// Creates an empty clause with the place for \a N variables.
3810 ///
3811 /// \param C AST context.
3812 /// \param N The number of variables.
3813 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3814
3815 /// Gets location of ':' symbol in clause.
3816 SourceLocation getColonLoc() const { return ColonLoc; }
3817
3818 /// Gets the name info for specified reduction identifier.
3819 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3820
3821 /// Gets the nested name specifier.
3822 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3823
3826 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3828 llvm::iterator_range<helper_expr_const_iterator>;
3829
3831 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3832 }
3833
3835 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3836 }
3837
3839 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3840 }
3841
3843 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3844 }
3845
3847 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3848 }
3849
3851 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3852 }
3853
3855 return helper_expr_const_range(getReductionOps().begin(),
3856 getReductionOps().end());
3857 }
3858
3860 return helper_expr_range(getReductionOps().begin(),
3861 getReductionOps().end());
3862 }
3863
3865 return helper_expr_const_range(getTaskgroupDescriptors().begin(),
3866 getTaskgroupDescriptors().end());
3867 }
3868
3870 return helper_expr_range(getTaskgroupDescriptors().begin(),
3871 getTaskgroupDescriptors().end());
3872 }
3873
3875 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3876 reinterpret_cast<Stmt **>(varlist_end()));
3877 }
3878
3880 auto Children = const_cast<OMPInReductionClause *>(this)->children();
3881 return const_child_range(Children.begin(), Children.end());
3882 }
3883
3886 }
3889 }
3890
3891 static bool classof(const OMPClause *T) {
3892 return T->getClauseKind() == llvm::omp::OMPC_in_reduction;
3893 }
3894};
3895
3896/// This represents clause 'linear' in the '#pragma omp ...'
3897/// directives.
3898///
3899/// \code
3900/// #pragma omp simd linear(a,b : 2)
3901/// \endcode
3902/// In this example directive '#pragma omp simd' has clause 'linear'
3903/// with variables 'a', 'b' and linear step '2'.
3905 : public OMPVarListClause<OMPLinearClause>,
3907 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
3908 friend class OMPClauseReader;
3909 friend OMPVarListClause;
3910 friend TrailingObjects;
3911
3912 /// Modifier of 'linear' clause.
3913 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
3914
3915 /// Location of linear modifier if any.
3916 SourceLocation ModifierLoc;
3917
3918 /// Location of ':'.
3919 SourceLocation ColonLoc;
3920
3921 /// Sets the linear step for clause.
3922 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
3923
3924 /// Sets the expression to calculate linear step for clause.
3925 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
3926
3927 /// Build 'linear' clause with given number of variables \a NumVars.
3928 ///
3929 /// \param StartLoc Starting location of the clause.
3930 /// \param LParenLoc Location of '('.
3931 /// \param ColonLoc Location of ':'.
3932 /// \param EndLoc Ending location of the clause.
3933 /// \param NumVars Number of variables.
3934 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3935 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3936 SourceLocation ColonLoc, SourceLocation EndLoc,
3937 unsigned NumVars)
3938 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, StartLoc,
3939 LParenLoc, EndLoc, NumVars),
3940 OMPClauseWithPostUpdate(this), Modifier(Modifier),
3941 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
3942
3943 /// Build an empty clause.
3944 ///
3945 /// \param NumVars Number of variables.
3946 explicit OMPLinearClause(unsigned NumVars)
3947 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear,
3948 SourceLocation(), SourceLocation(),
3949 SourceLocation(), NumVars),
3951
3952 /// Gets the list of initial values for linear variables.
3953 ///
3954 /// There are NumVars expressions with initial values allocated after the
3955 /// varlist, they are followed by NumVars update expressions (used to update
3956 /// the linear variable's value on current iteration) and they are followed by
3957 /// NumVars final expressions (used to calculate the linear variable's
3958 /// value after the loop body). After these lists, there are 2 helper
3959 /// expressions - linear step and a helper to calculate it before the
3960 /// loop body (used when the linear step is not constant):
3961 ///
3962 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
3963 /// Finals[]; Step; CalcStep; }
3964 MutableArrayRef<Expr *> getPrivates() {
3965 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3966 }
3967 ArrayRef<const Expr *> getPrivates() const {
3969 }
3970
3971 MutableArrayRef<Expr *> getInits() {
3972 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3973 }
3974 ArrayRef<const Expr *> getInits() const {
3975 return llvm::ArrayRef(getPrivates().end(), varlist_size());
3976 }
3977
3978 /// Sets the list of update expressions for linear variables.
3979 MutableArrayRef<Expr *> getUpdates() {
3980 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
3981 }
3982 ArrayRef<const Expr *> getUpdates() const {
3983 return llvm::ArrayRef(getInits().end(), varlist_size());
3984 }
3985
3986 /// Sets the list of final update expressions for linear variables.
3987 MutableArrayRef<Expr *> getFinals() {
3988 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
3989 }
3990 ArrayRef<const Expr *> getFinals() const {
3991 return llvm::ArrayRef(getUpdates().end(), varlist_size());
3992 }
3993
3994 /// Gets the list of used expressions for linear variables.
3995 MutableArrayRef<Expr *> getUsedExprs() {
3996 return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
3997 }
3998 ArrayRef<const Expr *> getUsedExprs() const {
3999 return llvm::ArrayRef(getFinals().end() + 2, varlist_size() + 1);
4000 }
4001
4002 /// Sets the list of the copies of original linear variables.
4003 /// \param PL List of expressions.
4004 void setPrivates(ArrayRef<Expr *> PL);
4005
4006 /// Sets the list of the initial values for linear variables.
4007 /// \param IL List of expressions.
4008 void setInits(ArrayRef<Expr *> IL);
4009
4010public:
4011 /// Creates clause with a list of variables \a VL and a linear step
4012 /// \a Step.
4013 ///
4014 /// \param C AST Context.
4015 /// \param StartLoc Starting location of the clause.
4016 /// \param LParenLoc Location of '('.
4017 /// \param Modifier Modifier of 'linear' clause.
4018 /// \param ModifierLoc Modifier location.
4019 /// \param ColonLoc Location of ':'.
4020 /// \param EndLoc Ending location of the clause.
4021 /// \param VL List of references to the variables.
4022 /// \param PL List of private copies of original variables.
4023 /// \param IL List of initial values for the variables.
4024 /// \param Step Linear step.
4025 /// \param CalcStep Calculation of the linear step.
4026 /// \param PreInit Statement that must be executed before entering the OpenMP
4027 /// region with this clause.
4028 /// \param PostUpdate Expression that must be executed after exit from the
4029 /// OpenMP region with this clause.
4030 static OMPLinearClause *
4031 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4032 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
4033 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
4034 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
4035 Stmt *PreInit, Expr *PostUpdate);
4036
4037 /// Creates an empty clause with the place for \a NumVars variables.
4038 ///
4039 /// \param C AST context.
4040 /// \param NumVars Number of variables.
4041 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
4042
4043 /// Set modifier.
4044 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
4045
4046 /// Return modifier.
4047 OpenMPLinearClauseKind getModifier() const { return Modifier; }
4048
4049 /// Set modifier location.
4050 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
4051
4052 /// Return modifier location.
4053 SourceLocation getModifierLoc() const { return ModifierLoc; }
4054
4055 /// Sets the location of ':'.
4056 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4057
4058 /// Returns the location of ':'.
4059 SourceLocation getColonLoc() const { return ColonLoc; }
4060
4061 /// Returns linear step.
4062 Expr *getStep() { return *(getFinals().end()); }
4063
4064 /// Returns linear step.
4065 const Expr *getStep() const { return *(getFinals().end()); }
4066
4067 /// Returns expression to calculate linear step.
4068 Expr *getCalcStep() { return *(getFinals().end() + 1); }
4069
4070 /// Returns expression to calculate linear step.
4071 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
4072
4073 /// Sets the list of update expressions for linear variables.
4074 /// \param UL List of expressions.
4076
4077 /// Sets the list of final update expressions for linear variables.
4078 /// \param FL List of expressions.
4079 void setFinals(ArrayRef<Expr *> FL);
4080
4081 /// Sets the list of used expressions for the linear clause.
4083
4086 using privates_range = llvm::iterator_range<privates_iterator>;
4087 using privates_const_range = llvm::iterator_range<privates_const_iterator>;
4088
4090 return privates_range(getPrivates().begin(), getPrivates().end());
4091 }
4092
4094 return privates_const_range(getPrivates().begin(), getPrivates().end());
4095 }
4096
4099 using inits_range = llvm::iterator_range<inits_iterator>;
4100 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
4101
4103 return inits_range(getInits().begin(), getInits().end());
4104 }
4105
4107 return inits_const_range(getInits().begin(), getInits().end());
4108 }
4109
4112 using updates_range = llvm::iterator_range<updates_iterator>;
4113 using updates_const_range = llvm::iterator_range<updates_const_iterator>;
4114
4116 return updates_range(getUpdates().begin(), getUpdates().end());
4117 }
4118
4120 return updates_const_range(getUpdates().begin(), getUpdates().end());
4121 }
4122
4125 using finals_range = llvm::iterator_range<finals_iterator>;
4126 using finals_const_range = llvm::iterator_range<finals_const_iterator>;
4127
4129 return finals_range(getFinals().begin(), getFinals().end());
4130 }
4131
4133 return finals_const_range(getFinals().begin(), getFinals().end());
4134 }
4135
4139 llvm::iterator_range<used_expressions_iterator>;
4141 llvm::iterator_range<used_expressions_const_iterator>;
4142
4144 return finals_range(getUsedExprs().begin(), getUsedExprs().end());
4145 }
4146
4148 return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
4149 }
4150
4152 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4153 reinterpret_cast<Stmt **>(varlist_end()));
4154 }
4155
4157 auto Children = const_cast<OMPLinearClause *>(this)->children();
4158 return const_child_range(Children.begin(), Children.end());
4159 }
4160
4162
4164 auto Children = const_cast<OMPLinearClause *>(this)->used_children();
4165 return const_child_range(Children.begin(), Children.end());
4166 }
4167
4168 static bool classof(const OMPClause *T) {
4169 return T->getClauseKind() == llvm::omp::OMPC_linear;
4170 }
4171};
4172
4173/// This represents clause 'aligned' in the '#pragma omp ...'
4174/// directives.
4175///
4176/// \code
4177/// #pragma omp simd aligned(a,b : 8)
4178/// \endcode
4179/// In this example directive '#pragma omp simd' has clause 'aligned'
4180/// with variables 'a', 'b' and alignment '8'.
4182 : public OMPVarListClause<OMPAlignedClause>,
4183 private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
4184 friend class OMPClauseReader;
4185 friend OMPVarListClause;
4186 friend TrailingObjects;
4187
4188 /// Location of ':'.
4189 SourceLocation ColonLoc;
4190
4191 /// Sets the alignment for clause.
4192 void setAlignment(Expr *A) { *varlist_end() = A; }
4193
4194 /// Build 'aligned' clause with given number of variables \a NumVars.
4195 ///
4196 /// \param StartLoc Starting location of the clause.
4197 /// \param LParenLoc Location of '('.
4198 /// \param ColonLoc Location of ':'.
4199 /// \param EndLoc Ending location of the clause.
4200 /// \param NumVars Number of variables.
4202 SourceLocation ColonLoc, SourceLocation EndLoc,
4203 unsigned NumVars)
4204 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, StartLoc,
4205 LParenLoc, EndLoc, NumVars),
4206 ColonLoc(ColonLoc) {}
4207
4208 /// Build an empty clause.
4209 ///
4210 /// \param NumVars Number of variables.
4211 explicit OMPAlignedClause(unsigned NumVars)
4212 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned,
4213 SourceLocation(), SourceLocation(),
4214 SourceLocation(), NumVars) {}
4215
4216public:
4217 /// Creates clause with a list of variables \a VL and alignment \a A.
4218 ///
4219 /// \param C AST Context.
4220 /// \param StartLoc Starting location of the clause.
4221 /// \param LParenLoc Location of '('.
4222 /// \param ColonLoc Location of ':'.
4223 /// \param EndLoc Ending location of the clause.
4224 /// \param VL List of references to the variables.
4225 /// \param A Alignment.
4226 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
4227 SourceLocation LParenLoc,
4228 SourceLocation ColonLoc,
4229 SourceLocation EndLoc, ArrayRef<Expr *> VL,
4230 Expr *A);
4231
4232 /// Creates an empty clause with the place for \a NumVars variables.
4233 ///
4234 /// \param C AST context.
4235 /// \param NumVars Number of variables.
4236 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
4237
4238 /// Sets the location of ':'.
4239 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4240
4241 /// Returns the location of ':'.
4242 SourceLocation getColonLoc() const { return ColonLoc; }
4243
4244 /// Returns alignment.
4246
4247 /// Returns alignment.
4248 const Expr *getAlignment() const { return *varlist_end(); }
4249
4251 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4252 reinterpret_cast<Stmt **>(varlist_end()));
4253 }
4254
4256 auto Children = const_cast<OMPAlignedClause *>(this)->children();
4257 return const_child_range(Children.begin(), Children.end());
4258 }
4259
4262 }
4265 }
4266
4267 static bool classof(const OMPClause *T) {
4268 return T->getClauseKind() == llvm::omp::OMPC_aligned;
4269 }
4270};
4271
4272/// This represents clause 'copyin' in the '#pragma omp ...' directives.
4273///
4274/// \code
4275/// #pragma omp parallel copyin(a,b)
4276/// \endcode
4277/// In this example directive '#pragma omp parallel' has clause 'copyin'
4278/// with the variables 'a' and 'b'.
4280 : public OMPVarListClause<OMPCopyinClause>,
4281 private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
4282 // Class has 3 additional tail allocated arrays:
4283 // 1. List of helper expressions for proper generation of assignment operation
4284 // required for copyin clause. This list represents sources.
4285 // 2. List of helper expressions for proper generation of assignment operation
4286 // required for copyin clause. This list represents destinations.
4287 // 3. List of helper expressions that represents assignment operation:
4288 // \code
4289 // DstExprs = SrcExprs;
4290 // \endcode
4291 // Required for proper codegen of propagation of master's thread values of
4292 // threadprivate variables to local instances of that variables in other
4293 // implicit threads.
4294
4295 friend class OMPClauseReader;
4296 friend OMPVarListClause;
4297 friend TrailingObjects;
4298
4299 /// Build clause with number of variables \a N.
4300 ///
4301 /// \param StartLoc Starting location of the clause.
4302 /// \param LParenLoc Location of '('.
4303 /// \param EndLoc Ending location of the clause.
4304 /// \param N Number of the variables in the clause.
4305 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4306 SourceLocation EndLoc, unsigned N)
4307 : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin, StartLoc,
4308 LParenLoc, EndLoc, N) {}
4309
4310 /// Build an empty clause.
4311 ///
4312 /// \param N Number of variables.
4313 explicit OMPCopyinClause(unsigned N)
4314 : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin,
4316 SourceLocation(), N) {}
4317
4318 /// Set list of helper expressions, required for proper codegen of the
4319 /// clause. These expressions represent source expression in the final
4320 /// assignment statement performed by the copyin clause.
4321 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
4322
4323 /// Get the list of helper source expressions.
4324 MutableArrayRef<Expr *> getSourceExprs() {
4325 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4326 }
4327 ArrayRef<const Expr *> getSourceExprs() const {
4329 }
4330
4331 /// Set list of helper expressions, required for proper codegen of the
4332 /// clause. These expressions represent destination expression in the final
4333 /// assignment statement performed by the copyin clause.
4334 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
4335
4336 /// Get the list of helper destination expressions.
4337 MutableArrayRef<Expr *> getDestinationExprs() {
4338 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
4339 }
4340 ArrayRef<const Expr *> getDestinationExprs() const {
4341 return llvm::ArrayRef(getSourceExprs().end(), varlist_size());
4342 }
4343
4344 /// Set list of helper assignment expressions, required for proper
4345 /// codegen of the clause. These expressions are assignment expressions that
4346 /// assign source helper expressions to destination helper expressions
4347 /// correspondingly.
4348 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
4349
4350 /// Get the list of helper assignment expressions.
4351 MutableArrayRef<Expr *> getAssignmentOps() {
4352 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
4353 }
4354 ArrayRef<const Expr *> getAssignmentOps() const {
4355 return llvm::ArrayRef(getDestinationExprs().end(), varlist_size());
4356 }
4357
4358public:
4359 /// Creates clause with a list of variables \a VL.
4360 ///
4361 /// \param C AST context.
4362 /// \param StartLoc Starting location of the clause.
4363 /// \param LParenLoc Location of '('.
4364 /// \param EndLoc Ending location of the clause.
4365 /// \param VL List of references to the variables.
4366 /// \param SrcExprs List of helper expressions for proper generation of
4367 /// assignment operation required for copyin clause. This list represents
4368 /// sources.
4369 /// \param DstExprs List of helper expressions for proper generation of
4370 /// assignment operation required for copyin clause. This list represents
4371 /// destinations.
4372 /// \param AssignmentOps List of helper expressions that represents assignment
4373 /// operation:
4374 /// \code
4375 /// DstExprs = SrcExprs;
4376 /// \endcode
4377 /// Required for proper codegen of propagation of master's thread values of
4378 /// threadprivate variables to local instances of that variables in other
4379 /// implicit threads.
4380 static OMPCopyinClause *
4381 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4382 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4383 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
4384
4385 /// Creates an empty clause with \a N variables.
4386 ///
4387 /// \param C AST context.
4388 /// \param N The number of variables.
4389 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
4390
4393 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4395 llvm::iterator_range<helper_expr_const_iterator>;
4396
4398 return helper_expr_const_range(getSourceExprs().begin(),
4399 getSourceExprs().end());
4400 }
4401
4403 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
4404 }
4405
4407 return helper_expr_const_range(getDestinationExprs().begin(),
4408 getDestinationExprs().end());
4409 }
4410
4412 return helper_expr_range(getDestinationExprs().begin(),
4413 getDestinationExprs().end());
4414 }
4415
4417 return helper_expr_const_range(getAssignmentOps().begin(),
4418 getAssignmentOps().end());
4419 }
4420
4422 return helper_expr_range(getAssignmentOps().begin(),
4423 getAssignmentOps().end());
4424 }
4425
4427 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4428 reinterpret_cast<Stmt **>(varlist_end()));
4429 }
4430
4432 auto Children = const_cast<OMPCopyinClause *>(this)->children();
4433 return const_child_range(Children.begin(), Children.end());
4434 }
4435
4438 }
4441 }
4442
4443 static bool classof(const OMPClause *T) {
4444 return T->getClauseKind() == llvm::omp::OMPC_copyin;
4445 }
4446};
4447
4448/// This represents clause 'copyprivate' in the '#pragma omp ...'
4449/// directives.
4450///
4451/// \code
4452/// #pragma omp single copyprivate(a,b)
4453/// \endcode
4454/// In this example directive '#pragma omp single' has clause 'copyprivate'
4455/// with the variables 'a' and 'b'.
4457 : public OMPVarListClause<OMPCopyprivateClause>,
4458 private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
4459 friend class OMPClauseReader;
4460 friend OMPVarListClause;
4461 friend TrailingObjects;
4462
4463 /// Build clause with number of variables \a N.
4464 ///
4465 /// \param StartLoc Starting location of the clause.
4466 /// \param LParenLoc Location of '('.
4467 /// \param EndLoc Ending location of the clause.
4468 /// \param N Number of the variables in the clause.
4470 SourceLocation EndLoc, unsigned N)
4471 : OMPVarListClause<OMPCopyprivateClause>(llvm::omp::OMPC_copyprivate,
4472 StartLoc, LParenLoc, EndLoc, N) {
4473 }
4474
4475 /// Build an empty clause.
4476 ///
4477 /// \param N Number of variables.
4478 explicit OMPCopyprivateClause(unsigned N)
4480 llvm::omp::OMPC_copyprivate, SourceLocation(), SourceLocation(),
4481 SourceLocation(), N) {}
4482
4483 /// Set list of helper expressions, required for proper codegen of the
4484 /// clause. These expressions represent source expression in the final
4485 /// assignment statement performed by the copyprivate clause.
4486 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
4487
4488 /// Get the list of helper source expressions.
4489 MutableArrayRef<Expr *> getSourceExprs() {
4490 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4491 }
4492 ArrayRef<const Expr *> getSourceExprs() const {
4494 }
4495
4496 /// Set list of helper expressions, required for proper codegen of the
4497 /// clause. These expressions represent destination expression in the final
4498 /// assignment statement performed by the copyprivate clause.
4499 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
4500
4501 /// Get the list of helper destination expressions.
4502 MutableArrayRef<Expr *> getDestinationExprs() {
4503 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
4504 }
4505 ArrayRef<const Expr *> getDestinationExprs() const {
4506 return llvm::ArrayRef(getSourceExprs().end(), varlist_size());
4507 }
4508
4509 /// Set list of helper assignment expressions, required for proper
4510 /// codegen of the clause. These expressions are assignment expressions that
4511 /// assign source helper expressions to destination helper expressions
4512 /// correspondingly.
4513 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
4514
4515 /// Get the list of helper assignment expressions.
4516 MutableArrayRef<Expr *> getAssignmentOps() {
4517 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
4518 }
4519 ArrayRef<const Expr *> getAssignmentOps() const {
4520 return llvm::ArrayRef(getDestinationExprs().end(), varlist_size());
4521 }
4522
4523public:
4524 /// Creates clause with a list of variables \a VL.
4525 ///
4526 /// \param C AST context.
4527 /// \param StartLoc Starting location of the clause.
4528 /// \param LParenLoc Location of '('.
4529 /// \param EndLoc Ending location of the clause.
4530 /// \param VL List of references to the variables.
4531 /// \param SrcExprs List of helper expressions for proper generation of
4532 /// assignment operation required for copyprivate clause. This list represents
4533 /// sources.
4534 /// \param DstExprs List of helper expressions for proper generation of
4535 /// assignment operation required for copyprivate clause. This list represents
4536 /// destinations.
4537 /// \param AssignmentOps List of helper expressions that represents assignment
4538 /// operation:
4539 /// \code
4540 /// DstExprs = SrcExprs;
4541 /// \endcode
4542 /// Required for proper codegen of final assignment performed by the
4543 /// copyprivate clause.
4544 static OMPCopyprivateClause *
4545 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4546 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4547 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
4548
4549 /// Creates an empty clause with \a N variables.
4550 ///
4551 /// \param C AST context.
4552 /// \param N The number of variables.
4553 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
4554
4557 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4559 llvm::iterator_range<helper_expr_const_iterator>;
4560
4562 return helper_expr_const_range(getSourceExprs().begin(),
4563 getSourceExprs().end());
4564 }
4565
4567 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
4568 }
4569
4571 return helper_expr_const_range(getDestinationExprs().begin(),
4572 getDestinationExprs().end());
4573 }
4574
4576 return helper_expr_range(getDestinationExprs().begin(),
4577 getDestinationExprs().end());
4578 }
4579
4581 return helper_expr_const_range(getAssignmentOps().begin(),
4582 getAssignmentOps().end());
4583 }
4584
4586 return helper_expr_range(getAssignmentOps().begin(),
4587 getAssignmentOps().end());
4588 }
4589
4591 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4592 reinterpret_cast<Stmt **>(varlist_end()));
4593 }
4594
4596 auto Children = const_cast<OMPCopyprivateClause *>(this)->children();
4597 return const_child_range(Children.begin(), Children.end());
4598 }
4599
4602 }
4605 }
4606
4607 static bool classof(const OMPClause *T) {
4608 return T->getClauseKind() == llvm::omp::OMPC_copyprivate;
4609 }
4610};
4611
4612/// This represents implicit clause 'flush' for the '#pragma omp flush'
4613/// directive.
4614/// This clause does not exist by itself, it can be only as a part of 'omp
4615/// flush' directive. This clause is introduced to keep the original structure
4616/// of \a OMPExecutableDirective class and its derivatives and to use the
4617/// existing infrastructure of clauses with the list of variables.
4618///
4619/// \code
4620/// #pragma omp flush(a,b)
4621/// \endcode
4622/// In this example directive '#pragma omp flush' has implicit clause 'flush'
4623/// with the variables 'a' and 'b'.
4625 : public OMPVarListClause<OMPFlushClause>,
4626 private llvm::TrailingObjects<OMPFlushClause, Expr *> {
4627 friend OMPVarListClause;
4628 friend TrailingObjects;
4629
4630 /// Build clause with number of variables \a N.
4631 ///
4632 /// \param StartLoc Starting location of the clause.
4633 /// \param LParenLoc Location of '('.
4634 /// \param EndLoc Ending location of the clause.
4635 /// \param N Number of the variables in the clause.
4636 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4637 SourceLocation EndLoc, unsigned N)
4638 : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush, StartLoc,
4639 LParenLoc, EndLoc, N) {}
4640
4641 /// Build an empty clause.
4642 ///
4643 /// \param N Number of variables.
4644 explicit OMPFlushClause(unsigned N)
4645 : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush,
4647 SourceLocation(), N) {}
4648
4649public:
4650 /// Creates clause with a list of variables \a VL.
4651 ///
4652 /// \param C AST context.
4653 /// \param StartLoc Starting location of the clause.
4654 /// \param LParenLoc Location of '('.
4655 /// \param EndLoc Ending location of the clause.
4656 /// \param VL List of references to the variables.
4657 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
4658 SourceLocation LParenLoc, SourceLocation EndLoc,
4659 ArrayRef<Expr *> VL);
4660
4661 /// Creates an empty clause with \a N variables.
4662 ///
4663 /// \param C AST context.
4664 /// \param N The number of variables.
4665 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
4666
4668 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4669 reinterpret_cast<Stmt **>(varlist_end()));
4670 }
4671
4673 auto Children = const_cast<OMPFlushClause *>(this)->children();
4674 return const_child_range(Children.begin(), Children.end());
4675 }
4676
4679 }
4682 }
4683
4684 static bool classof(const OMPClause *T) {
4685 return T->getClauseKind() == llvm::omp::OMPC_flush;
4686 }
4687};
4688
4689/// This represents implicit clause 'depobj' for the '#pragma omp depobj'
4690/// directive.
4691/// This clause does not exist by itself, it can be only as a part of 'omp
4692/// depobj' directive. This clause is introduced to keep the original structure
4693/// of \a OMPExecutableDirective class and its derivatives and to use the
4694/// existing infrastructure of clauses with the list of variables.
4695///
4696/// \code
4697/// #pragma omp depobj(a) destroy
4698/// \endcode
4699/// In this example directive '#pragma omp depobj' has implicit clause 'depobj'
4700/// with the depobj 'a'.
4701class OMPDepobjClause final : public OMPClause {
4702 friend class OMPClauseReader;
4703
4704 /// Location of '('.
4705 SourceLocation LParenLoc;
4706
4707 /// Chunk size.
4708 Expr *Depobj = nullptr;
4709
4710 /// Build clause with number of variables \a N.
4711 ///
4712 /// \param StartLoc Starting location of the clause.
4713 /// \param LParenLoc Location of '('.
4714 /// \param EndLoc Ending location of the clause.
4715 OMPDepobjClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4716 SourceLocation EndLoc)
4717 : OMPClause(llvm::omp::OMPC_depobj, StartLoc, EndLoc),
4718 LParenLoc(LParenLoc) {}
4719
4720 /// Build an empty clause.
4721 ///
4722 explicit OMPDepobjClause()
4723 : OMPClause(llvm::omp::OMPC_depobj, SourceLocation(), SourceLocation()) {}
4724
4725 void setDepobj(Expr *E) { Depobj = E; }
4726
4727 /// Sets the location of '('.
4728 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4729
4730public:
4731 /// Creates clause.
4732 ///
4733 /// \param C AST context.
4734 /// \param StartLoc Starting location of the clause.
4735 /// \param LParenLoc Location of '('.
4736 /// \param EndLoc Ending location of the clause.
4737 /// \param Depobj depobj expression associated with the 'depobj' directive.
4738 static OMPDepobjClause *Create(const ASTContext &C, SourceLocation StartLoc,
4739 SourceLocation LParenLoc,
4740 SourceLocation EndLoc, Expr *Depobj);
4741
4742 /// Creates an empty clause.
4743 ///
4744 /// \param C AST context.
4745 static OMPDepobjClause *CreateEmpty(const ASTContext &C);
4746
4747 /// Returns depobj expression associated with the clause.
4748 Expr *getDepobj() { return Depobj; }
4749 const Expr *getDepobj() const { return Depobj; }
4750
4751 /// Returns the location of '('.
4752 SourceLocation getLParenLoc() const { return LParenLoc; }
4753