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"
21#include "clang/AST/DeclarationName.h"
22#include "clang/AST/Expr.h"
23#include "clang/AST/NestedNameSpecifier.h"
24#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtIterator.h"
26#include "clang/Basic/LLVM.h"
27#include "clang/Basic/OpenMPKinds.h"
28#include "clang/Basic/SourceLocation.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/OMPConstants.h"
36#include "llvm/Frontend/OpenMP/OMPContext.h"
37#include "llvm/Support/Casting.h"
38#include "llvm/Support/Compiler.h"
39#include "llvm/Support/TrailingObjects.h"
40#include <cassert>
41#include <cstddef>
42#include <iterator>
43#include <utility>
44
45namespace clang {
46
47class ASTContext;
48
49//===----------------------------------------------------------------------===//
50// AST classes for clauses.
51//===----------------------------------------------------------------------===//
52
53/// This is a basic class for representing single OpenMP clause.
54class OMPClause {
55 /// Starting location of the clause (the clause keyword).
56 SourceLocation StartLoc;
57
58 /// Ending location of the clause.
59 SourceLocation EndLoc;
60
61 /// Kind of the clause.
62 OpenMPClauseKind Kind;
63
64protected:
65 OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
66 : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
67
68public:
69 /// Returns the starting location of the clause.
70 SourceLocation getBeginLoc() const { return StartLoc; }
71
72 /// Returns the ending location of the clause.
73 SourceLocation getEndLoc() const { return EndLoc; }
74
75 /// Sets the starting location of the clause.
76 void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
77
78 /// Sets the ending location of the clause.
79 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
80
81 /// Returns kind of OpenMP clause (private, shared, reduction, etc.).
82 OpenMPClauseKind getClauseKind() const { return Kind; }
83
84 bool isImplicit() const { return StartLoc.isInvalid(); }
85
86 using child_iterator = StmtIterator;
87 using const_child_iterator = ConstStmtIterator;
88 using child_range = llvm::iterator_range<child_iterator>;
89 using const_child_range = llvm::iterator_range<const_child_iterator>;
90
91 child_range children();
92 const_child_range children() const {
93 auto Children = const_cast<OMPClause *>(this)->children();
94 return const_child_range(Children.begin(), Children.end());
95 }
96
97 /// Get the iterator range for the expressions used in the clauses. Used
98 /// expressions include only the children that must be evaluated at the
99 /// runtime before entering the construct.
100 child_range used_children();
101 const_child_range used_children() const {
102 auto Children = const_cast<OMPClause *>(this)->children();
103 return const_child_range(Children.begin(), Children.end());
104 }
105
106 static bool classof(const OMPClause *) { return true; }
107};
108
109/// Class that handles pre-initialization statement for some clauses, like
110/// 'shedule', 'firstprivate' etc.
111class OMPClauseWithPreInit {
112 friend class OMPClauseReader;
113
114 /// Pre-initialization statement for the clause.
115 Stmt *PreInit = nullptr;
116
117 /// Region that captures the associated stmt.
118 OpenMPDirectiveKind CaptureRegion = llvm::omp::OMPD_unknown;
119
120protected:
121 OMPClauseWithPreInit(const OMPClause *This) {
122 assert(get(This) && "get is not tuned for pre-init.");
123 }
124
125 /// Set pre-initialization statement for the clause.
126 void
127 setPreInitStmt(Stmt *S,
128 OpenMPDirectiveKind ThisRegion = llvm::omp::OMPD_unknown) {
129 PreInit = S;
130 CaptureRegion = ThisRegion;
131 }
132
133public:
134 /// Get pre-initialization statement for the clause.
135 const Stmt *getPreInitStmt() const { return PreInit; }
136
137 /// Get pre-initialization statement for the clause.
138 Stmt *getPreInitStmt() { return PreInit; }
139
140 /// Get capture region for the stmt in the clause.
141 OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
142
143 static OMPClauseWithPreInit *get(OMPClause *C);
144 static const OMPClauseWithPreInit *get(const OMPClause *C);
145};
146
147/// Class that handles post-update expression for some clauses, like
148/// 'lastprivate', 'reduction' etc.
149class OMPClauseWithPostUpdate : public OMPClauseWithPreInit {
150 friend class OMPClauseReader;
151
152 /// Post-update expression for the clause.
153 Expr *PostUpdate = nullptr;
154
155protected:
156 OMPClauseWithPostUpdate(const OMPClause *This) : OMPClauseWithPreInit(This) {
157 assert(get(This) && "get is not tuned for post-update.");
158 }
159
160 /// Set pre-initialization statement for the clause.
161 void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
162
163public:
164 /// Get post-update expression for the clause.
165 const Expr *getPostUpdateExpr() const { return PostUpdate; }
166
167 /// Get post-update expression for the clause.
168 Expr *getPostUpdateExpr() { return PostUpdate; }
169
170 static OMPClauseWithPostUpdate *get(OMPClause *C);
171 static const OMPClauseWithPostUpdate *get(const OMPClause *C);
172};
173
174/// This structure contains most locations needed for by an OMPVarListClause.
175struct OMPVarListLocTy {
176 /// Starting location of the clause (the clause keyword).
177 SourceLocation StartLoc;
178 /// Location of '('.
179 SourceLocation LParenLoc;
180 /// Ending location of the clause.
181 SourceLocation EndLoc;
182 OMPVarListLocTy() = default;
183 OMPVarListLocTy(SourceLocation StartLoc, SourceLocation LParenLoc,
184 SourceLocation EndLoc)
185 : StartLoc(StartLoc), LParenLoc(LParenLoc), EndLoc(EndLoc) {}
186};
187
188/// This represents clauses with the list of variables like 'private',
189/// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
190/// '#pragma omp ...' directives.
191template <class T> class OMPVarListClause : public OMPClause {
192 friend class OMPClauseReader;
193
194 /// Location of '('.
195 SourceLocation LParenLoc;
196
197 /// Number of variables in the list.
198 unsigned NumVars;
199
200protected:
201 /// Build a clause with \a N variables
202 ///
203 /// \param K Kind of the clause.
204 /// \param StartLoc Starting location of the clause (the clause keyword).
205 /// \param LParenLoc Location of '('.
206 /// \param EndLoc Ending location of the clause.
207 /// \param N Number of the variables in the clause.
208 OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
209 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
210 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
211
212 /// Fetches list of variables associated with this clause.
213 MutableArrayRef<Expr *> getVarRefs() {
214 return MutableArrayRef<Expr *>(
215 static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
216 }
217
218 /// Sets the list of variables for this clause.
219 void setVarRefs(ArrayRef<Expr *> VL) {
220 assert(VL.size() == NumVars &&
221 "Number of variables is not the same as the preallocated buffer");
222 std::copy(VL.begin(), VL.end(),
223 static_cast<T *>(this)->template getTrailingObjects<Expr *>());
224 }
225
226public:
227 using varlist_iterator = MutableArrayRef<Expr *>::iterator;
228 using varlist_const_iterator = ArrayRef<const Expr *>::iterator;
229 using varlist_range = llvm::iterator_range<varlist_iterator>;
230 using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
231
232 unsigned varlist_size() const { return NumVars; }
233 bool varlist_empty() const { return NumVars == 0; }
234
235 varlist_range varlists() {
236 return varlist_range(varlist_begin(), varlist_end());
237 }
238 varlist_const_range varlists() const {
239 return varlist_const_range(varlist_begin(), varlist_end());
240 }
241
242 varlist_iterator varlist_begin() { return getVarRefs().begin(); }
243 varlist_iterator varlist_end() { return getVarRefs().end(); }
244 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
245 varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
246
247 /// Sets the location of '('.
248 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
249
250 /// Returns the location of '('.
251 SourceLocation getLParenLoc() const { return LParenLoc; }
252
253 /// Fetches list of all variables in the clause.
254 ArrayRef<const Expr *> getVarRefs() const {
255 return llvm::makeArrayRef(
256 static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
257 NumVars);
258 }
259};
260
261/// This represents 'allocator' clause in the '#pragma omp ...'
262/// directive.
263///
264/// \code
265/// #pragma omp allocate(a) allocator(omp_default_mem_alloc)
266/// \endcode
267/// In this example directive '#pragma omp allocate' has simple 'allocator'
268/// clause with the allocator 'omp_default_mem_alloc'.
269class OMPAllocatorClause : public OMPClause {
270 friend class OMPClauseReader;
271
272 /// Location of '('.
273 SourceLocation LParenLoc;
274
275 /// Expression with the allocator.
276 Stmt *Allocator = nullptr;
277
278 /// Set allocator.
279 void setAllocator(Expr *A) { Allocator = A; }
280
281public:
282 /// Build 'allocator' clause with the given allocator.
283 ///
284 /// \param A Allocator.
285 /// \param StartLoc Starting location of the clause.
286 /// \param LParenLoc Location of '('.
287 /// \param EndLoc Ending location of the clause.
288 OMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc,
289 SourceLocation EndLoc)
290 : OMPClause(llvm::omp::OMPC_allocator, StartLoc, EndLoc),
291 LParenLoc(LParenLoc), Allocator(A) {}
292
293 /// Build an empty clause.
294 OMPAllocatorClause()
295 : OMPClause(llvm::omp::OMPC_allocator, SourceLocation(),
296 SourceLocation()) {}
297
298 /// Sets the location of '('.
299 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
300
301 /// Returns the location of '('.
302 SourceLocation getLParenLoc() const { return LParenLoc; }
303
304 /// Returns allocator.
305 Expr *getAllocator() const { return cast_or_null<Expr>(Allocator); }
306
307 child_range children() { return child_range(&Allocator, &Allocator + 1); }
308
309 const_child_range children() const {
310 return const_child_range(&Allocator, &Allocator + 1);
311 }
312
313 child_range used_children() {
314 return child_range(child_iterator(), child_iterator());
315 }
316 const_child_range used_children() const {
317 return const_child_range(const_child_iterator(), const_child_iterator());
318 }
319
320 static bool classof(const OMPClause *T) {
321 return T->getClauseKind() == llvm::omp::OMPC_allocator;
322 }
323};
324
325/// This represents clause 'allocate' in the '#pragma omp ...' directives.
326///
327/// \code
328/// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
329/// \endcode
330/// In this example directive '#pragma omp parallel' has clause 'private'
331/// and clause 'allocate' for the variable 'a'.
332class OMPAllocateClause final
333 : public OMPVarListClause<OMPAllocateClause>,
334 private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
335 friend class OMPClauseReader;
336 friend OMPVarListClause;
337 friend TrailingObjects;
338
339 /// Allocator specified in the clause, or 'nullptr' if the default one is
340 /// used.
341 Expr *Allocator = nullptr;
342 /// Position of the ':' delimiter in the clause;
343 SourceLocation ColonLoc;
344
345 /// Build clause with number of variables \a N.
346 ///
347 /// \param StartLoc Starting location of the clause.
348 /// \param LParenLoc Location of '('.
349 /// \param Allocator Allocator expression.
350 /// \param ColonLoc Location of ':' delimiter.
351 /// \param EndLoc Ending location of the clause.
352 /// \param N Number of the variables in the clause.
353 OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
354 Expr *Allocator, SourceLocation ColonLoc,
355 SourceLocation EndLoc, unsigned N)
356 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate, StartLoc,
357 LParenLoc, EndLoc, N),
358 Allocator(Allocator), ColonLoc(ColonLoc) {}
359
360 /// Build an empty clause.
361 ///
362 /// \param N Number of variables.
363 explicit OMPAllocateClause(unsigned N)
364 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate,
365 SourceLocation(), SourceLocation(),
366 SourceLocation(), N) {}
367
368 /// Sets location of ':' symbol in clause.
369 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
370
371 void setAllocator(Expr *A) { Allocator = A; }
372
373public:
374 /// Creates clause with a list of variables \a VL.
375 ///
376 /// \param C AST context.
377 /// \param StartLoc Starting location of the clause.
378 /// \param LParenLoc Location of '('.
379 /// \param Allocator Allocator expression.
380 /// \param ColonLoc Location of ':' delimiter.
381 /// \param EndLoc Ending location of the clause.
382 /// \param VL List of references to the variables.
383 static OMPAllocateClause *Create(const ASTContext &C, SourceLocation StartLoc,
384 SourceLocation LParenLoc, Expr *Allocator,
385 SourceLocation ColonLoc,
386 SourceLocation EndLoc, ArrayRef<Expr *> VL);
387
388 /// Returns the allocator expression or nullptr, if no allocator is specified.
389 Expr *getAllocator() const { return Allocator; }
390
391 /// Returns the location of the ':' delimiter.
392 SourceLocation getColonLoc() const { return ColonLoc; }
393
394 /// Creates an empty clause with the place for \a N variables.
395 ///
396 /// \param C AST context.
397 /// \param N The number of variables.
398 static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
399
400 child_range children() {
401 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
402 reinterpret_cast<Stmt **>(varlist_end()));
403 }
404
405 const_child_range children() const {
406 auto Children = const_cast<OMPAllocateClause *>(this)->children();
407 return const_child_range(Children.begin(), Children.end());
408 }
409
410 child_range used_children() {
411 return child_range(child_iterator(), child_iterator());
412 }
413 const_child_range used_children() const {
414 return const_child_range(const_child_iterator(), const_child_iterator());
415 }
416
417 static bool classof(const OMPClause *T) {
418 return T->getClauseKind() == llvm::omp::OMPC_allocate;
419 }
420};
421
422/// This represents 'if' clause in the '#pragma omp ...' directive.
423///
424/// \code
425/// #pragma omp parallel if(parallel:a > 5)
426/// \endcode
427/// In this example directive '#pragma omp parallel' has simple 'if' clause with
428/// condition 'a > 5' and directive name modifier 'parallel'.
429class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
430 friend class OMPClauseReader;
431
432 /// Location of '('.
433 SourceLocation LParenLoc;
434
435 /// Condition of the 'if' clause.
436 Stmt *Condition = nullptr;
437
438 /// Location of ':' (if any).
439 SourceLocation ColonLoc;
440
441 /// Directive name modifier for the clause.
442 OpenMPDirectiveKind NameModifier = llvm::omp::OMPD_unknown;
443
444 /// Name modifier location.
445 SourceLocation NameModifierLoc;
446
447 /// Set condition.
448 void setCondition(Expr *Cond) { Condition = Cond; }
449
450 /// Set directive name modifier for the clause.
451 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
452
453 /// Set location of directive name modifier for the clause.
454 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
455
456 /// Set location of ':'.
457 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
458
459public:
460 /// Build 'if' clause with condition \a Cond.
461 ///
462 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
463 /// \param Cond Condition of the clause.
464 /// \param HelperCond Helper condition for the clause.
465 /// \param CaptureRegion Innermost OpenMP region where expressions in this
466 /// clause must be captured.
467 /// \param StartLoc Starting location of the clause.
468 /// \param LParenLoc Location of '('.
469 /// \param NameModifierLoc Location of directive name modifier.
470 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
471 /// \param EndLoc Ending location of the clause.
472 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
473 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
474 SourceLocation LParenLoc, SourceLocation NameModifierLoc,
475 SourceLocation ColonLoc, SourceLocation EndLoc)
476 : OMPClause(llvm::omp::OMPC_if, StartLoc, EndLoc),
477 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond),
478 ColonLoc(ColonLoc), NameModifier(NameModifier),
479 NameModifierLoc(NameModifierLoc) {
480 setPreInitStmt(HelperCond, CaptureRegion);
481 }
482
483 /// Build an empty clause.
484 OMPIfClause()
485 : OMPClause(llvm::omp::OMPC_if, SourceLocation(), SourceLocation()),
486 OMPClauseWithPreInit(this) {}
487
488 /// Sets the location of '('.
489 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
490
491 /// Returns the location of '('.
492 SourceLocation getLParenLoc() const { return LParenLoc; }
493
494 /// Return the location of ':'.
495 SourceLocation getColonLoc() const { return ColonLoc; }
496
497 /// Returns condition.
498 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
499
500 /// Return directive name modifier associated with the clause.
501 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
502
503 /// Return the location of directive name modifier.
504 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
505
506 child_range children() { return child_range(&Condition, &Condition + 1); }
507
508 const_child_range children() const {
509 return const_child_range(&Condition, &Condition + 1);
510 }
511
512 child_range used_children();
513 const_child_range used_children() const {
514 auto Children = const_cast<OMPIfClause *>(this)->used_children();
515 return const_child_range(Children.begin(), Children.end());
516 }
517
518 static bool classof(const OMPClause *T) {
519 return T->getClauseKind() == llvm::omp::OMPC_if;
520 }
521};
522
523/// This represents 'final' clause in the '#pragma omp ...' directive.
524///
525/// \code
526/// #pragma omp task final(a > 5)
527/// \endcode
528/// In this example directive '#pragma omp task' has simple 'final'
529/// clause with condition 'a > 5'.
530class OMPFinalClause : public OMPClause, public OMPClauseWithPreInit {
531 friend class OMPClauseReader;
532
533 /// Location of '('.
534 SourceLocation LParenLoc;
535
536 /// Condition of the 'if' clause.
537 Stmt *Condition = nullptr;
538
539 /// Set condition.
540 void setCondition(Expr *Cond) { Condition = Cond; }
541
542public:
543 /// Build 'final' clause with condition \a Cond.
544 ///
545 /// \param Cond Condition of the clause.
546 /// \param HelperCond Helper condition for the construct.
547 /// \param CaptureRegion Innermost OpenMP region where expressions in this
548 /// clause must be captured.
549 /// \param StartLoc Starting location of the clause.
550 /// \param LParenLoc Location of '('.
551 /// \param EndLoc Ending location of the clause.
552 OMPFinalClause(Expr *Cond, Stmt *HelperCond,
553 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
554 SourceLocation LParenLoc, SourceLocation EndLoc)
555 : OMPClause(llvm::omp::OMPC_final, StartLoc, EndLoc),
556 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond) {
557 setPreInitStmt(HelperCond, CaptureRegion);
558 }
559
560 /// Build an empty clause.
561 OMPFinalClause()
562 : OMPClause(llvm::omp::OMPC_final, SourceLocation(), SourceLocation()),
563 OMPClauseWithPreInit(this) {}
564
565 /// Sets the location of '('.
566 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
567
568 /// Returns the location of '('.
569 SourceLocation getLParenLoc() const { return LParenLoc; }
570
571 /// Returns condition.
572 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
573
574 child_range children() { return child_range(&Condition, &Condition + 1); }
575
576 const_child_range children() const {
577 return const_child_range(&Condition, &Condition + 1);
578 }
579
580 child_range used_children();
581 const_child_range used_children() const {
582 auto Children = const_cast<OMPFinalClause *>(this)->used_children();
583 return const_child_range(Children.begin(), Children.end());
584 }
585
586 static bool classof(const OMPClause *T) {
587 return T->getClauseKind() == llvm::omp::OMPC_final;
588 }
589};
590
591/// This represents 'num_threads' clause in the '#pragma omp ...'
592/// directive.
593///
594/// \code
595/// #pragma omp parallel num_threads(6)
596/// \endcode
597/// In this example directive '#pragma omp parallel' has simple 'num_threads'
598/// clause with number of threads '6'.
599class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit {
600 friend class OMPClauseReader;
601
602 /// Location of '('.
603 SourceLocation LParenLoc;
604
605 /// Condition of the 'num_threads' clause.
606 Stmt *NumThreads = nullptr;
607
608 /// Set condition.
609 void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
610
611public:
612 /// Build 'num_threads' clause with condition \a NumThreads.
613 ///
614 /// \param NumThreads Number of threads for the construct.
615 /// \param HelperNumThreads Helper Number of threads for the construct.
616 /// \param CaptureRegion Innermost OpenMP region where expressions in this
617 /// clause must be captured.
618 /// \param StartLoc Starting location of the clause.
619 /// \param LParenLoc Location of '('.
620 /// \param EndLoc Ending location of the clause.
621 OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
622 OpenMPDirectiveKind CaptureRegion,
623 SourceLocation StartLoc, SourceLocation LParenLoc,
624 SourceLocation EndLoc)
625 : OMPClause(llvm::omp::OMPC_num_threads, StartLoc, EndLoc),
626 OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
627 NumThreads(NumThreads) {
628 setPreInitStmt(HelperNumThreads, CaptureRegion);
629 }
630
631 /// Build an empty clause.
632 OMPNumThreadsClause()
633 : OMPClause(llvm::omp::OMPC_num_threads, SourceLocation(),
634 SourceLocation()),
635 OMPClauseWithPreInit(this) {}
636
637 /// Sets the location of '('.
638 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
639
640 /// Returns the location of '('.
641 SourceLocation getLParenLoc() const { return LParenLoc; }
642
643 /// Returns number of threads.
644 Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
645
646 child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
647
648 const_child_range children() const {
649 return const_child_range(&NumThreads, &NumThreads + 1);
650 }
651
652 child_range used_children() {
653 return child_range(child_iterator(), child_iterator());
654 }
655 const_child_range used_children() const {
656 return const_child_range(const_child_iterator(), const_child_iterator());
657 }
658
659 static bool classof(const OMPClause *T) {
660 return T->getClauseKind() == llvm::omp::OMPC_num_threads;
661 }
662};
663
664/// This represents 'safelen' clause in the '#pragma omp ...'
665/// directive.
666///
667/// \code
668/// #pragma omp simd safelen(4)
669/// \endcode
670/// In this example directive '#pragma omp simd' has clause 'safelen'
671/// with single expression '4'.
672/// If the safelen clause is used then no two iterations executed
673/// concurrently with SIMD instructions can have a greater distance
674/// in the logical iteration space than its value. The parameter of
675/// the safelen clause must be a constant positive integer expression.
676class OMPSafelenClause : public OMPClause {
677 friend class OMPClauseReader;
678
679 /// Location of '('.
680 SourceLocation LParenLoc;
681
682 /// Safe iteration space distance.
683 Stmt *Safelen = nullptr;
684
685 /// Set safelen.
686 void setSafelen(Expr *Len) { Safelen = Len; }
687
688public:
689 /// Build 'safelen' clause.
690 ///
691 /// \param Len Expression associated with this clause.
692 /// \param StartLoc Starting location of the clause.
693 /// \param EndLoc Ending location of the clause.
694 OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
695 SourceLocation EndLoc)
696 : OMPClause(llvm::omp::OMPC_safelen, StartLoc, EndLoc),
697 LParenLoc(LParenLoc), Safelen(Len) {}
698
699 /// Build an empty clause.
700 explicit OMPSafelenClause()
701 : OMPClause(llvm::omp::OMPC_safelen, SourceLocation(), SourceLocation()) {
702 }
703
704 /// Sets the location of '('.
705 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
706
707 /// Returns the location of '('.
708 SourceLocation getLParenLoc() const { return LParenLoc; }
709
710 /// Return safe iteration space distance.
711 Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
712
713 child_range children() { return child_range(&Safelen, &Safelen + 1); }
714
715 const_child_range children() const {
716 return const_child_range(&Safelen, &Safelen + 1);
717 }
718
719 child_range used_children() {
720 return child_range(child_iterator(), child_iterator());
721 }
722 const_child_range used_children() const {
723 return const_child_range(const_child_iterator(), const_child_iterator());
724 }
725
726 static bool classof(const OMPClause *T) {
727 return T->getClauseKind() == llvm::omp::OMPC_safelen;
728 }
729};
730
731/// This represents 'simdlen' clause in the '#pragma omp ...'
732/// directive.
733///
734/// \code
735/// #pragma omp simd simdlen(4)
736/// \endcode
737/// In this example directive '#pragma omp simd' has clause 'simdlen'
738/// with single expression '4'.
739/// If the 'simdlen' clause is used then it specifies the preferred number of
740/// iterations to be executed concurrently. The parameter of the 'simdlen'
741/// clause must be a constant positive integer expression.
742class OMPSimdlenClause : public OMPClause {
743 friend class OMPClauseReader;
744
745 /// Location of '('.
746 SourceLocation LParenLoc;
747
748 /// Safe iteration space distance.
749 Stmt *Simdlen = nullptr;
750
751 /// Set simdlen.
752 void setSimdlen(Expr *Len) { Simdlen = Len; }
753
754public:
755 /// Build 'simdlen' clause.
756 ///
757 /// \param Len Expression associated with this clause.
758 /// \param StartLoc Starting location of the clause.
759 /// \param EndLoc Ending location of the clause.
760 OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
761 SourceLocation EndLoc)
762 : OMPClause(llvm::omp::OMPC_simdlen, StartLoc, EndLoc),
763 LParenLoc(LParenLoc), Simdlen(Len) {}
764
765 /// Build an empty clause.
766 explicit OMPSimdlenClause()
767 : OMPClause(llvm::omp::OMPC_simdlen, SourceLocation(), SourceLocation()) {
768 }
769
770 /// Sets the location of '('.
771 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
772
773 /// Returns the location of '('.
774 SourceLocation getLParenLoc() const { return LParenLoc; }
775
776 /// Return safe iteration space distance.
777 Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
778
779 child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
780
781 const_child_range children() const {
782 return const_child_range(&Simdlen, &Simdlen + 1);
783 }
784
785 child_range used_children() {
786 return child_range(child_iterator(), child_iterator());
787 }
788 const_child_range used_children() const {
789 return const_child_range(const_child_iterator(), const_child_iterator());
790 }
791
792 static bool classof(const OMPClause *T) {
793 return T->getClauseKind() == llvm::omp::OMPC_simdlen;
794 }
795};
796
797/// This represents the 'sizes' clause in the '#pragma omp tile' directive.
798///
799/// \code
800/// #pragma omp tile sizes(5,5)
801/// for (int i = 0; i < 64; ++i)
802/// for (int j = 0; j < 64; ++j)
803/// \endcode
804class OMPSizesClause final
805 : public OMPClause,
806 private llvm::TrailingObjects<OMPSizesClause, Expr *> {
807 friend class OMPClauseReader;
808 friend class llvm::TrailingObjects<OMPSizesClause, Expr *>;
809
810 /// Location of '('.
811 SourceLocation LParenLoc;
812
813 /// Number of tile sizes in the clause.
814 unsigned NumSizes;
815
816 /// Build an empty clause.
817 explicit OMPSizesClause(int NumSizes)
818 : OMPClause(llvm::omp::OMPC_sizes, SourceLocation(), SourceLocation()),
819 NumSizes(NumSizes) {}
820
821public:
822 /// Build a 'sizes' AST node.
823 ///
824 /// \param C Context of the AST.
825 /// \param StartLoc Location of the 'sizes' identifier.
826 /// \param LParenLoc Location of '('.
827 /// \param EndLoc Location of ')'.
828 /// \param Sizes Content of the clause.
829 static OMPSizesClause *Create(const ASTContext &C, SourceLocation StartLoc,
830 SourceLocation LParenLoc, SourceLocation EndLoc,
831 ArrayRef<Expr *> Sizes);
832
833 /// Build an empty 'sizes' AST node for deserialization.
834 ///
835 /// \param C Context of the AST.
836 /// \param NumSizes Number of items in the clause.
837 static OMPSizesClause *CreateEmpty(const ASTContext &C, unsigned NumSizes);
838
839 /// Sets the location of '('.
840 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
841
842 /// Returns the location of '('.
843 SourceLocation getLParenLoc() const { return LParenLoc; }
844
845 /// Returns the number of list items.
846 unsigned getNumSizes() const { return NumSizes; }
847
848 /// Returns the tile size expressions.
849 MutableArrayRef<Expr *> getSizesRefs() {
850 return MutableArrayRef<Expr *>(static_cast<OMPSizesClause *>(this)
851 ->template getTrailingObjects<Expr *>(),
852 NumSizes);
853 }
854 ArrayRef<Expr *> getSizesRefs() const {
855 return ArrayRef<Expr *>(static_cast<const OMPSizesClause *>(this)
856 ->template getTrailingObjects<Expr *>(),
857 NumSizes);
858 }
859
860 /// Sets the tile size expressions.
861 void setSizesRefs(ArrayRef<Expr *> VL) {
862 assert(VL.size() == NumSizes);
863 std::copy(VL.begin(), VL.end(),
864 static_cast<OMPSizesClause *>(this)
865 ->template getTrailingObjects<Expr *>());
866 }
867
868 child_range children() {
869 MutableArrayRef<Expr *> Sizes = getSizesRefs();
870 return child_range(reinterpret_cast<Stmt **>(Sizes.begin()),
871 reinterpret_cast<Stmt **>(Sizes.end()));
872 }
873 const_child_range children() const {
874 ArrayRef<Expr *> Sizes = getSizesRefs();
875 return const_child_range(reinterpret_cast<Stmt *const *>(Sizes.begin()),
876 reinterpret_cast<Stmt *const *>(Sizes.end()));
877 }
878
879 child_range used_children() {
880 return child_range(child_iterator(), child_iterator());
881 }
882 const_child_range used_children() const {
883 return const_child_range(const_child_iterator(), const_child_iterator());
884 }
885
886 static bool classof(const OMPClause *T) {
887 return T->getClauseKind() == llvm::omp::OMPC_sizes;
888 }
889};
890
891/// This represents 'collapse' clause in the '#pragma omp ...'
892/// directive.
893///
894/// \code
895/// #pragma omp simd collapse(3)
896/// \endcode
897/// In this example directive '#pragma omp simd' has clause 'collapse'
898/// with single expression '3'.
899/// The parameter must be a constant positive integer expression, it specifies
900/// the number of nested loops that should be collapsed into a single iteration
901/// space.
902class OMPCollapseClause : public OMPClause {
903 friend class OMPClauseReader;
904
905 /// Location of '('.
906 SourceLocation LParenLoc;
907
908 /// Number of for-loops.
909 Stmt *NumForLoops = nullptr;
910
911 /// Set the number of associated for-loops.
912 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
913
914public:
915 /// Build 'collapse' clause.
916 ///
917 /// \param Num Expression associated with this clause.
918 /// \param StartLoc Starting location of the clause.
919 /// \param LParenLoc Location of '('.
920 /// \param EndLoc Ending location of the clause.
921 OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
922 SourceLocation LParenLoc, SourceLocation EndLoc)
923 : OMPClause(llvm::omp::OMPC_collapse, StartLoc, EndLoc),
924 LParenLoc(LParenLoc), NumForLoops(Num) {}
925
926 /// Build an empty clause.
927 explicit OMPCollapseClause()
928 : OMPClause(llvm::omp::OMPC_collapse, SourceLocation(),
929 SourceLocation()) {}
930
931 /// Sets the location of '('.
932 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
933
934 /// Returns the location of '('.
935 SourceLocation getLParenLoc() const { return LParenLoc; }
936
937 /// Return the number of associated for-loops.
938 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
939
940 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
941
942 const_child_range children() const {
943 return const_child_range(&NumForLoops, &NumForLoops + 1);
944 }
945
946 child_range used_children() {
947 return child_range(child_iterator(), child_iterator());
948 }
949 const_child_range used_children() const {
950 return const_child_range(const_child_iterator(), const_child_iterator());
951 }
952
953 static bool classof(const OMPClause *T) {
954 return T->getClauseKind() == llvm::omp::OMPC_collapse;
955 }
956};
957
958/// This represents 'default' clause in the '#pragma omp ...' directive.
959///
960/// \code
961/// #pragma omp parallel default(shared)
962/// \endcode
963/// In this example directive '#pragma omp parallel' has simple 'default'
964/// clause with kind 'shared'.
965class OMPDefaultClause : public OMPClause {
966 friend class OMPClauseReader;
967
968 /// Location of '('.
969 SourceLocation LParenLoc;
970
971 /// A kind of the 'default' clause.
972 llvm::omp::DefaultKind Kind = llvm::omp::OMP_DEFAULT_unknown;
973
974 /// Start location of the kind in source code.
975 SourceLocation KindKwLoc;
976
977 /// Set kind of the clauses.
978 ///
979 /// \param K Argument of clause.
980 void setDefaultKind(llvm::omp::DefaultKind K) { Kind = K; }
981
982 /// Set argument location.
983 ///
984 /// \param KLoc Argument location.
985 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
986
987public:
988 /// Build 'default' clause with argument \a A ('none' or 'shared').
989 ///
990 /// \param A Argument of the clause ('none' or 'shared').
991 /// \param ALoc Starting location of the argument.
992 /// \param StartLoc Starting location of the clause.
993 /// \param LParenLoc Location of '('.
994 /// \param EndLoc Ending location of the clause.
995 OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc,
996 SourceLocation StartLoc, SourceLocation LParenLoc,
997 SourceLocation EndLoc)
998 : OMPClause(llvm::omp::OMPC_default, StartLoc, EndLoc),
999 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1000
1001 /// Build an empty clause.
1002 OMPDefaultClause()
1003 : OMPClause(llvm::omp::OMPC_default, SourceLocation(), SourceLocation()) {
1004 }
1005
1006 /// Sets the location of '('.
1007 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1008
1009 /// Returns the location of '('.
1010 SourceLocation getLParenLoc() const { return LParenLoc; }
1011
1012 /// Returns kind of the clause.
1013 llvm::omp::DefaultKind getDefaultKind() const { return Kind; }
1014
1015 /// Returns location of clause kind.
1016 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
1017
1018 child_range children() {
1019 return child_range(child_iterator(), child_iterator());
1020 }
1021
1022 const_child_range children() const {
1023 return const_child_range(const_child_iterator(), const_child_iterator());
1024 }
1025
1026 child_range used_children() {
1027 return child_range(child_iterator(), child_iterator());
1028 }
1029 const_child_range used_children() const {
1030 return const_child_range(const_child_iterator(), const_child_iterator());
1031 }
1032
1033 static bool classof(const OMPClause *T) {
1034 return T->getClauseKind() == llvm::omp::OMPC_default;
1035 }
1036};
1037
1038/// This represents 'proc_bind' clause in the '#pragma omp ...'
1039/// directive.
1040///
1041/// \code
1042/// #pragma omp parallel proc_bind(master)
1043/// \endcode
1044/// In this example directive '#pragma omp parallel' has simple 'proc_bind'
1045/// clause with kind 'master'.
1046class OMPProcBindClause : public OMPClause {
1047 friend class OMPClauseReader;
1048
1049 /// Location of '('.
1050 SourceLocation LParenLoc;
1051
1052 /// A kind of the 'proc_bind' clause.
1053 llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown;
1054
1055 /// Start location of the kind in source code.
1056 SourceLocation KindKwLoc;
1057
1058 /// Set kind of the clause.
1059 ///
1060 /// \param K Kind of clause.
1061 void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; }
1062
1063 /// Set clause kind location.
1064 ///
1065 /// \param KLoc Kind location.
1066 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1067
1068public:
1069 /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
1070 /// 'spread').
1071 ///
1072 /// \param A Argument of the clause ('master', 'close' or 'spread').
1073 /// \param ALoc Starting location of the argument.
1074 /// \param StartLoc Starting location of the clause.
1075 /// \param LParenLoc Location of '('.
1076 /// \param EndLoc Ending location of the clause.
1077 OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc,
1078 SourceLocation StartLoc, SourceLocation LParenLoc,
1079 SourceLocation EndLoc)
1080 : OMPClause(llvm::omp::OMPC_proc_bind, StartLoc, EndLoc),
1081 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1082
1083 /// Build an empty clause.
1084 OMPProcBindClause()
1085 : OMPClause(llvm::omp::OMPC_proc_bind, SourceLocation(),
1086 SourceLocation()) {}
1087
1088 /// Sets the location of '('.
1089 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1090
1091 /// Returns the location of '('.
1092 SourceLocation getLParenLoc() const { return LParenLoc; }
1093
1094 /// Returns kind of the clause.
1095 llvm::omp::ProcBindKind getProcBindKind() const { return Kind; }
1096
1097 /// Returns location of clause kind.
1098 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
1099
1100 child_range children() {
1101 return child_range(child_iterator(), child_iterator());
1102 }
1103
1104 const_child_range children() const {
1105 return const_child_range(const_child_iterator(), const_child_iterator());
1106 }
1107
1108 child_range used_children() {
1109 return child_range(child_iterator(), child_iterator());
1110 }
1111 const_child_range used_children() const {
1112 return const_child_range(const_child_iterator(), const_child_iterator());
1113 }
1114
1115 static bool classof(const OMPClause *T) {
1116 return T->getClauseKind() == llvm::omp::OMPC_proc_bind;
1117 }
1118};
1119
1120/// This represents 'unified_address' clause in the '#pragma omp requires'
1121/// directive.
1122///
1123/// \code
1124/// #pragma omp requires unified_address
1125/// \endcode
1126/// In this example directive '#pragma omp requires' has 'unified_address'
1127/// clause.
1128class OMPUnifiedAddressClause final : public OMPClause {
1129public:
1130 friend class OMPClauseReader;
1131 /// Build 'unified_address' clause.
1132 ///
1133 /// \param StartLoc Starting location of the clause.
1134 /// \param EndLoc Ending location of the clause.
1135 OMPUnifiedAddressClause(SourceLocation StartLoc, SourceLocation EndLoc)
1136 : OMPClause(llvm::omp::OMPC_unified_address, StartLoc, EndLoc) {}
1137
1138 /// Build an empty clause.
1139 OMPUnifiedAddressClause()
1140 : OMPClause(llvm::omp::OMPC_unified_address, SourceLocation(),
1141 SourceLocation()) {}
1142
1143 child_range children() {
1144 return child_range(child_iterator(), child_iterator());
1145 }
1146
1147 const_child_range children() const {
1148 return const_child_range(const_child_iterator(), const_child_iterator());
1149 }
1150
1151 child_range used_children() {
1152 return child_range(child_iterator(), child_iterator());
1153 }
1154 const_child_range used_children() const {
1155 return const_child_range(const_child_iterator(), const_child_iterator());
1156 }
1157
1158 static bool classof(const OMPClause *T) {
1159 return T->getClauseKind() == llvm::omp::OMPC_unified_address;
1160 }
1161};
1162
1163/// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
1164/// directive.
1165///
1166/// \code
1167/// #pragma omp requires unified_shared_memory
1168/// \endcode
1169/// In this example directive '#pragma omp requires' has 'unified_shared_memory'
1170/// clause.
1171class OMPUnifiedSharedMemoryClause final : public OMPClause {
1172public:
1173 friend class OMPClauseReader;
1174 /// Build 'unified_shared_memory' clause.
1175 ///
1176 /// \param StartLoc Starting location of the clause.
1177 /// \param EndLoc Ending location of the clause.
1178 OMPUnifiedSharedMemoryClause(SourceLocation StartLoc, SourceLocation EndLoc)
1179 : OMPClause(llvm::omp::OMPC_unified_shared_memory, StartLoc, EndLoc) {}
1180
1181 /// Build an empty clause.
1182 OMPUnifiedSharedMemoryClause()
1183 : OMPClause(llvm::omp::OMPC_unified_shared_memory, SourceLocation(),
1184 SourceLocation()) {}
1185
1186 child_range children() {
1187 return child_range(child_iterator(), child_iterator());
1188 }
1189
1190 const_child_range children() const {
1191 return const_child_range(const_child_iterator(), const_child_iterator());
1192 }
1193
1194 child_range used_children() {
1195 return child_range(child_iterator(), child_iterator());
1196 }
1197 const_child_range used_children() const {
1198 return const_child_range(const_child_iterator(), const_child_iterator());
1199 }
1200
1201 static bool classof(const OMPClause *T) {
1202 return T->getClauseKind() == llvm::omp::OMPC_unified_shared_memory;
1203 }
1204};
1205
1206/// This represents 'reverse_offload' clause in the '#pragma omp requires'
1207/// directive.
1208///
1209/// \code
1210/// #pragma omp requires reverse_offload
1211/// \endcode
1212/// In this example directive '#pragma omp requires' has 'reverse_offload'
1213/// clause.
1214class OMPReverseOffloadClause final : public OMPClause {
1215public:
1216 friend class OMPClauseReader;
1217 /// Build 'reverse_offload' clause.
1218 ///
1219 /// \param StartLoc Starting location of the clause.
1220 /// \param EndLoc Ending location of the clause.
1221 OMPReverseOffloadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1222 : OMPClause(llvm::omp::OMPC_reverse_offload, StartLoc, EndLoc) {}
1223
1224 /// Build an empty clause.
1225 OMPReverseOffloadClause()
1226 : OMPClause(llvm::omp::OMPC_reverse_offload, SourceLocation(),
1227 SourceLocation()) {}
1228
1229 child_range children() {
1230 return child_range(child_iterator(), child_iterator());
1231 }
1232
1233 const_child_range children() const {
1234 return const_child_range(const_child_iterator(), const_child_iterator());
1235 }
1236
1237 child_range used_children() {
1238 return child_range(child_iterator(), child_iterator());
1239 }
1240 const_child_range used_children() const {
1241 return const_child_range(const_child_iterator(), const_child_iterator());
1242 }
1243
1244 static bool classof(const OMPClause *T) {
1245 return T->getClauseKind() == llvm::omp::OMPC_reverse_offload;
1246 }
1247};
1248
1249/// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
1250/// directive.
1251///
1252/// \code
1253/// #pragma omp requires dynamic_allocators
1254/// \endcode
1255/// In this example directive '#pragma omp requires' has 'dynamic_allocators'
1256/// clause.
1257class OMPDynamicAllocatorsClause final : public OMPClause {
1258public:
1259 friend class OMPClauseReader;
1260 /// Build 'dynamic_allocators' clause.
1261 ///
1262 /// \param StartLoc Starting location of the clause.
1263 /// \param EndLoc Ending location of the clause.
1264 OMPDynamicAllocatorsClause(SourceLocation StartLoc, SourceLocation EndLoc)
1265 : OMPClause(llvm::omp::OMPC_dynamic_allocators, StartLoc, EndLoc) {}
1266
1267 /// Build an empty clause.
1268 OMPDynamicAllocatorsClause()
1269 : OMPClause(llvm::omp::OMPC_dynamic_allocators, SourceLocation(),
1270 SourceLocation()) {}
1271
1272 child_range children() {
1273 return child_range(child_iterator(), child_iterator());
1274 }
1275
1276 const_child_range children() const {
1277 return const_child_range(const_child_iterator(), const_child_iterator());
1278 }
1279
1280 child_range used_children() {
1281 return child_range(child_iterator(), child_iterator());
1282 }
1283 const_child_range used_children() const {
1284 return const_child_range(const_child_iterator(), const_child_iterator());
1285 }
1286
1287 static bool classof(const OMPClause *T) {
1288 return T->getClauseKind() == llvm::omp::OMPC_dynamic_allocators;
1289 }
1290};
1291
1292/// This represents 'atomic_default_mem_order' clause in the '#pragma omp
1293/// requires' directive.
1294///
1295/// \code
1296/// #pragma omp requires atomic_default_mem_order(seq_cst)
1297/// \endcode
1298/// In this example directive '#pragma omp requires' has simple
1299/// atomic_default_mem_order' clause with kind 'seq_cst'.
1300class OMPAtomicDefaultMemOrderClause final : public OMPClause {
1301 friend class OMPClauseReader;
1302
1303 /// Location of '('
1304 SourceLocation LParenLoc;
1305
1306 /// A kind of the 'atomic_default_mem_order' clause.
1307 OpenMPAtomicDefaultMemOrderClauseKind Kind =
1308 OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown;
1309
1310 /// Start location of the kind in source code.
1311 SourceLocation KindKwLoc;
1312
1313 /// Set kind of the clause.
1314 ///
1315 /// \param K Kind of clause.
1316 void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
1317 Kind = K;
1318 }
1319
1320 /// Set clause kind location.
1321 ///
1322 /// \param KLoc Kind location.
1323 void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
1324 KindKwLoc = KLoc;
1325 }
1326
1327public:
1328 /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
1329 /// 'acq_rel' or 'relaxed').
1330 ///
1331 /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
1332 /// \param ALoc Starting location of the argument.
1333 /// \param StartLoc Starting location of the clause.
1334 /// \param LParenLoc Location of '('.
1335 /// \param EndLoc Ending location of the clause.
1336 OMPAtomicDefaultMemOrderClause(OpenMPAtomicDefaultMemOrderClauseKind A,
1337 SourceLocation ALoc, SourceLocation StartLoc,
1338 SourceLocation LParenLoc,
1339 SourceLocation EndLoc)
1340 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, StartLoc, EndLoc),
1341 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1342
1343 /// Build an empty clause.
1344 OMPAtomicDefaultMemOrderClause()
1345 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, SourceLocation(),
1346 SourceLocation()) {}
1347
1348 /// Sets the location of '('.
1349 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1350
1351 /// Returns the locaiton of '('.
1352 SourceLocation getLParenLoc() const { return LParenLoc; }
1353
1354 /// Returns kind of the clause.
1355 OpenMPAtomicDefaultMemOrderClauseKind getAtomicDefaultMemOrderKind() const {
1356 return Kind;
1357 }
1358
1359 /// Returns location of clause kind.
1360 SourceLocation getAtomicDefaultMemOrderKindKwLoc() const { return KindKwLoc; }
1361
1362 child_range children() {
1363 return child_range(child_iterator(), child_iterator());
1364 }
1365
1366 const_child_range children() const {
1367 return const_child_range(const_child_iterator(), const_child_iterator());
1368 }
1369
1370 child_range used_children() {
1371 return child_range(child_iterator(), child_iterator());
1372 }
1373 const_child_range used_children() const {
1374 return const_child_range(const_child_iterator(), const_child_iterator());
1375 }
1376
1377 static bool classof(const OMPClause *T) {
1378 return T->getClauseKind() == llvm::omp::OMPC_atomic_default_mem_order;
1379 }
1380};
1381
1382/// This represents 'schedule' clause in the '#pragma omp ...' directive.
1383///
1384/// \code
1385/// #pragma omp for schedule(static, 3)
1386/// \endcode
1387/// In this example directive '#pragma omp for' has 'schedule' clause with
1388/// arguments 'static' and '3'.
1389class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
1390 friend class OMPClauseReader;
1391
1392 /// Location of '('.
1393 SourceLocation LParenLoc;
1394
1395 /// A kind of the 'schedule' clause.
1396 OpenMPScheduleClauseKind Kind = OMPC_SCHEDULE_unknown;
1397
1398 /// Modifiers for 'schedule' clause.
1399 enum {FIRST, SECOND, NUM_MODIFIERS};
1400 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
1401
1402 /// Locations of modifiers.
1403 SourceLocation ModifiersLoc[NUM_MODIFIERS];
1404
1405 /// Start location of the schedule ind in source code.
1406 SourceLocation KindLoc;
1407
1408 /// Location of ',' (if any).
1409 SourceLocation CommaLoc;
1410
1411 /// Chunk size.
1412 Expr *ChunkSize = nullptr;
1413
1414 /// Set schedule kind.
1415 ///
1416 /// \param K Schedule kind.
1417 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
1418
1419 /// Set the first schedule modifier.
1420 ///
1421 /// \param M Schedule modifier.
1422 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
1423 Modifiers[FIRST] = M;
1424 }
1425
1426 /// Set the second schedule modifier.
1427 ///
1428 /// \param M Schedule modifier.
1429 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
1430 Modifiers[SECOND] = M;
1431 }
1432
1433 /// Set location of the first schedule modifier.
1434 void setFirstScheduleModifierLoc(SourceLocation Loc) {
1435 ModifiersLoc[FIRST] = Loc;
1436 }
1437
1438 /// Set location of the second schedule modifier.
1439 void setSecondScheduleModifierLoc(SourceLocation Loc) {
1440 ModifiersLoc[SECOND] = Loc;
1441 }
1442
1443 /// Set schedule modifier location.
1444 ///
1445 /// \param M Schedule modifier location.
1446 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
1447 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
1448 Modifiers[FIRST] = M;
1449 else {
1450 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
1451 Modifiers[SECOND] = M;
1452 }
1453 }
1454
1455 /// Sets the location of '('.
1456 ///
1457 /// \param Loc Location of '('.
1458 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1459
1460 /// Set schedule kind start location.
1461 ///
1462 /// \param KLoc Schedule kind location.
1463 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1464
1465 /// Set location of ','.
1466 ///
1467 /// \param Loc Location of ','.
1468 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
1469
1470 /// Set chunk size.
1471 ///
1472 /// \param E Chunk size.
1473 void setChunkSize(Expr *E) { ChunkSize = E; }
1474
1475public:
1476 /// Build 'schedule' clause with schedule kind \a Kind and chunk size
1477 /// expression \a ChunkSize.
1478 ///
1479 /// \param StartLoc Starting location of the clause.
1480 /// \param LParenLoc Location of '('.
1481 /// \param KLoc Starting location of the argument.
1482 /// \param CommaLoc Location of ','.
1483 /// \param EndLoc Ending location of the clause.
1484 /// \param Kind Schedule kind.
1485 /// \param ChunkSize Chunk size.
1486 /// \param HelperChunkSize Helper chunk size for combined directives.
1487 /// \param M1 The first modifier applied to 'schedule' clause.
1488 /// \param M1Loc Location of the first modifier
1489 /// \param M2 The second modifier applied to 'schedule' clause.
1490 /// \param M2Loc Location of the second modifier
1491 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1492 SourceLocation KLoc, SourceLocation CommaLoc,
1493 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
1494 Expr *ChunkSize, Stmt *HelperChunkSize,
1495 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
1496 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
1497 : OMPClause(llvm::omp::OMPC_schedule, StartLoc, EndLoc),
1498 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
1499 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
1500 setPreInitStmt(HelperChunkSize);
1501 Modifiers[FIRST] = M1;
1502 Modifiers[SECOND] = M2;
1503 ModifiersLoc[FIRST] = M1Loc;
1504 ModifiersLoc[SECOND] = M2Loc;
1505 }
1506
1507 /// Build an empty clause.
1508 explicit OMPScheduleClause()
1509 : OMPClause(llvm::omp::OMPC_schedule, SourceLocation(), SourceLocation()),
1510 OMPClauseWithPreInit(this) {
1511 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
1512 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
1513 }
1514
1515 /// Get kind of the clause.
1516 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
1517
1518 /// Get the first modifier of the clause.
1519 OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
1520 return Modifiers[FIRST];
1521 }
1522
1523 /// Get the second modifier of the clause.
1524 OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
1525 return Modifiers[SECOND];
1526 }
1527
1528 /// Get location of '('.
1529 SourceLocation getLParenLoc() { return LParenLoc; }
1530
1531 /// Get kind location.
1532 SourceLocation getScheduleKindLoc() { return KindLoc; }
1533
1534 /// Get the first modifier location.
1535 SourceLocation getFirstScheduleModifierLoc() const {
1536 return ModifiersLoc[FIRST];
1537 }
1538
1539 /// Get the second modifier location.
1540 SourceLocation getSecondScheduleModifierLoc() const {
1541 return ModifiersLoc[SECOND];
1542 }
1543
1544 /// Get location of ','.
1545 SourceLocation getCommaLoc() { return CommaLoc; }
1546
1547 /// Get chunk size.
1548 Expr *getChunkSize() { return ChunkSize; }
1549
1550 /// Get chunk size.
1551 const Expr *getChunkSize() const { return ChunkSize; }
1552
1553 child_range children() {
1554 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
1555 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
1556 }
1557
1558 const_child_range children() const {
1559 auto Children = const_cast<OMPScheduleClause *>(this)->children();
1560 return const_child_range(Children.begin(), Children.end());
1561 }
1562
1563 child_range used_children() {
1564 return child_range(child_iterator(), child_iterator());
1565 }
1566 const_child_range used_children() const {
1567 return const_child_range(const_child_iterator(), const_child_iterator());
1568 }
1569
1570 static bool classof(const OMPClause *T) {
1571 return T->getClauseKind() == llvm::omp::OMPC_schedule;
1572 }
1573};
1574
1575/// This represents 'ordered' clause in the '#pragma omp ...' directive.
1576///
1577/// \code
1578/// #pragma omp for ordered (2)
1579/// \endcode
1580/// In this example directive '#pragma omp for' has 'ordered' clause with
1581/// parameter 2.
1582class OMPOrderedClause final
1583 : public OMPClause,
1584 private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
1585 friend class OMPClauseReader;
1586 friend TrailingObjects;
1587
1588 /// Location of '('.
1589 SourceLocation LParenLoc;
1590
1591 /// Number of for-loops.
1592 Stmt *NumForLoops = nullptr;
1593
1594 /// Real number of loops.
1595 unsigned NumberOfLoops = 0;
1596
1597 /// Build 'ordered' clause.
1598 ///
1599 /// \param Num Expression, possibly associated with this clause.
1600 /// \param NumLoops Number of loops, associated with this clause.
1601 /// \param StartLoc Starting location of the clause.
1602 /// \param LParenLoc Location of '('.
1603 /// \param EndLoc Ending location of the clause.
1604 OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
1605 SourceLocation LParenLoc, SourceLocation EndLoc)
1606 : OMPClause(llvm::omp::OMPC_ordered, StartLoc, EndLoc),
1607 LParenLoc(LParenLoc), NumForLoops(Num), NumberOfLoops(NumLoops) {}
1608
1609 /// Build an empty clause.
1610 explicit OMPOrderedClause(unsigned NumLoops)
1611 : OMPClause(llvm::omp::OMPC_ordered, SourceLocation(), SourceLocation()),
1612 NumberOfLoops(NumLoops) {}
1613
1614 /// Set the number of associated for-loops.
1615 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
1616
1617public:
1618 /// Build 'ordered' clause.
1619 ///
1620 /// \param Num Expression, possibly associated with this clause.
1621 /// \param NumLoops Number of loops, associated with this clause.
1622 /// \param StartLoc Starting location of the clause.
1623 /// \param LParenLoc Location of '('.
1624 /// \param EndLoc Ending location of the clause.
1625 static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
1626 unsigned NumLoops, SourceLocation StartLoc,
1627 SourceLocation LParenLoc,
1628 SourceLocation EndLoc);
1629
1630 /// Build an empty clause.
1631 static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
1632
1633 /// Sets the location of '('.
1634 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1635
1636 /// Returns the location of '('.
1637 SourceLocation getLParenLoc() const { return LParenLoc; }
1638
1639 /// Return the number of associated for-loops.
1640 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
1641
1642 /// Set number of iterations for the specified loop.
1643 void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
1644 /// Get number of iterations for all the loops.
1645 ArrayRef<Expr *> getLoopNumIterations() const;
1646
1647 /// Set loop counter for the specified loop.
1648 void setLoopCounter(unsigned NumLoop, Expr *Counter);
1649 /// Get loops counter for the specified loop.
1650 Expr *getLoopCounter(unsigned NumLoop);
1651 const Expr *getLoopCounter(unsigned NumLoop) const;
1652
1653 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1654
1655 const_child_range children() const {
1656 return const_child_range(&NumForLoops, &NumForLoops + 1);
1657 }
1658
1659 child_range used_children() {
1660 return child_range(child_iterator(), child_iterator());
1661 }
1662 const_child_range used_children() const {
1663 return const_child_range(const_child_iterator(), const_child_iterator());
1664 }
1665
1666 static bool classof(const OMPClause *T) {
1667 return T->getClauseKind() == llvm::omp::OMPC_ordered;
1668 }
1669};
1670
1671/// This represents 'nowait' clause in the '#pragma omp ...' directive.
1672///
1673/// \code
1674/// #pragma omp for nowait
1675/// \endcode
1676/// In this example directive '#pragma omp for' has 'nowait' clause.
1677class OMPNowaitClause : public OMPClause {
1678public:
1679 /// Build 'nowait' clause.
1680 ///
1681 /// \param StartLoc Starting location of the clause.
1682 /// \param EndLoc Ending location of the clause.
1683 OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
1684 : OMPClause(llvm::omp::OMPC_nowait, StartLoc, EndLoc) {}
1685
1686 /// Build an empty clause.
1687 OMPNowaitClause()
1688 : OMPClause(llvm::omp::OMPC_nowait, SourceLocation(), SourceLocation()) {}
1689
1690 child_range children() {
1691 return child_range(child_iterator(), child_iterator());
1692 }
1693
1694 const_child_range children() const {
1695 return const_child_range(const_child_iterator(), const_child_iterator());
1696 }
1697
1698 child_range used_children() {
1699 return child_range(child_iterator(), child_iterator());
1700 }
1701 const_child_range used_children() const {
1702 return const_child_range(const_child_iterator(), const_child_iterator());
1703 }
1704
1705 static bool classof(const OMPClause *T) {
1706 return T->getClauseKind() == llvm::omp::OMPC_nowait;
1707 }
1708};
1709
1710/// This represents 'untied' clause in the '#pragma omp ...' directive.
1711///
1712/// \code
1713/// #pragma omp task untied
1714/// \endcode
1715/// In this example directive '#pragma omp task' has 'untied' clause.
1716class OMPUntiedClause : public OMPClause {
1717public:
1718 /// Build 'untied' clause.
1719 ///
1720 /// \param StartLoc Starting location of the clause.
1721 /// \param EndLoc Ending location of the clause.
1722 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
1723 : OMPClause(llvm::omp::OMPC_untied, StartLoc, EndLoc) {}
1724
1725 /// Build an empty clause.
1726 OMPUntiedClause()
1727 : OMPClause(llvm::omp::OMPC_untied, SourceLocation(), SourceLocation()) {}
1728
1729 child_range children() {
1730 return child_range(child_iterator(), child_iterator());
1731 }
1732
1733 const_child_range children() const {
1734 return const_child_range(const_child_iterator(), const_child_iterator());
1735 }
1736
1737 child_range used_children() {
1738 return child_range(child_iterator(), child_iterator());
1739 }
1740 const_child_range used_children() const {
1741 return const_child_range(const_child_iterator(), const_child_iterator());
1742 }
1743
1744 static bool classof(const OMPClause *T) {
1745 return T->getClauseKind() == llvm::omp::OMPC_untied;
1746 }
1747};
1748
1749/// This represents 'mergeable' clause in the '#pragma omp ...'
1750/// directive.
1751///
1752/// \code
1753/// #pragma omp task mergeable
1754/// \endcode
1755/// In this example directive '#pragma omp task' has 'mergeable' clause.
1756class OMPMergeableClause : public OMPClause {
1757public:
1758 /// Build 'mergeable' clause.
1759 ///
1760 /// \param StartLoc Starting location of the clause.
1761 /// \param EndLoc Ending location of the clause.
1762 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
1763 : OMPClause(llvm::omp::OMPC_mergeable, StartLoc, EndLoc) {}
1764
1765 /// Build an empty clause.
1766 OMPMergeableClause()
1767 : OMPClause(llvm::omp::OMPC_mergeable, SourceLocation(),
1768 SourceLocation()) {}
1769
1770 child_range children() {
1771 return child_range(child_iterator(), child_iterator());
1772 }
1773
1774 const_child_range children() const {
1775 return const_child_range(const_child_iterator(), const_child_iterator());
1776 }
1777
1778 child_range used_children() {
1779 return child_range(child_iterator(), child_iterator());
1780 }
1781 const_child_range used_children() const {
1782 return const_child_range(const_child_iterator(), const_child_iterator());
1783 }
1784
1785 static bool classof(const OMPClause *T) {
1786 return T->getClauseKind() == llvm::omp::OMPC_mergeable;
1787 }
1788};
1789
1790/// This represents 'read' clause in the '#pragma omp atomic' directive.
1791///
1792/// \code
1793/// #pragma omp atomic read
1794/// \endcode
1795/// In this example directive '#pragma omp atomic' has 'read' clause.
1796class OMPReadClause : public OMPClause {
1797public:
1798 /// Build 'read' clause.
1799 ///
1800 /// \param StartLoc Starting location of the clause.
1801 /// \param EndLoc Ending location of the clause.
1802 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1803 : OMPClause(llvm::omp::OMPC_read, StartLoc, EndLoc) {}
1804
1805 /// Build an empty clause.
1806 OMPReadClause()
1807 : OMPClause(llvm::omp::OMPC_read, SourceLocation(), SourceLocation()) {}
1808
1809 child_range children() {
1810 return child_range(child_iterator(), child_iterator());
1811 }
1812
1813 const_child_range children() const {
1814 return const_child_range(const_child_iterator(), const_child_iterator());
1815 }
1816
1817 child_range used_children() {
1818 return child_range(child_iterator(), child_iterator());
1819 }
1820 const_child_range used_children() const {
1821 return const_child_range(const_child_iterator(), const_child_iterator());
1822 }
1823
1824 static bool classof(const OMPClause *T) {
1825 return T->getClauseKind() == llvm::omp::OMPC_read;
1826 }
1827};
1828
1829/// This represents 'write' clause in the '#pragma omp atomic' directive.
1830///
1831/// \code
1832/// #pragma omp atomic write
1833/// \endcode
1834/// In this example directive '#pragma omp atomic' has 'write' clause.
1835class OMPWriteClause : public OMPClause {
1836public:
1837 /// Build 'write' clause.
1838 ///
1839 /// \param StartLoc Starting location of the clause.
1840 /// \param EndLoc Ending location of the clause.
1841 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
1842 : OMPClause(llvm::omp::OMPC_write, StartLoc, EndLoc) {}
1843
1844 /// Build an empty clause.
1845 OMPWriteClause()
1846 : OMPClause(llvm::omp::OMPC_write, SourceLocation(), SourceLocation()) {}
1847
1848 child_range children() {
1849 return child_range(child_iterator(), child_iterator());
1850 }
1851
1852 const_child_range children() const {
1853 return const_child_range(const_child_iterator(), const_child_iterator());
1854 }
1855
1856 child_range used_children() {
1857 return child_range(child_iterator(), child_iterator());
1858 }
1859 const_child_range used_children() const {
1860 return const_child_range(const_child_iterator(), const_child_iterator());
1861 }
1862
1863 static bool classof(const OMPClause *T) {
1864 return T->getClauseKind() == llvm::omp::OMPC_write;
1865 }
1866};
1867
1868/// This represents 'update' clause in the '#pragma omp atomic'
1869/// directive.
1870///
1871/// \code
1872/// #pragma omp atomic update
1873/// \endcode
1874/// In this example directive '#pragma omp atomic' has 'update' clause.
1875/// Also, this class represents 'update' clause in '#pragma omp depobj'
1876/// directive.
1877///
1878/// \code
1879/// #pragma omp depobj(a) update(in)
1880/// \endcode
1881/// In this example directive '#pragma omp depobj' has 'update' clause with 'in'
1882/// dependence kind.
1883class OMPUpdateClause final
1884 : public OMPClause,
1885 private llvm::TrailingObjects<OMPUpdateClause, SourceLocation,
1886 OpenMPDependClauseKind> {
1887 friend class OMPClauseReader;
1888 friend TrailingObjects;
1889
1890 /// true if extended version of the clause for 'depobj' directive.
1891 bool IsExtended = false;
1892
1893 /// Define the sizes of each trailing object array except the last one. This
1894 /// is required for TrailingObjects to work properly.
1895 size_t numTrailingObjects(OverloadToken<SourceLocation>) const {
1896 // 2 locations: for '(' and argument location.
1897 return IsExtended ? 2 : 0;
1898 }
1899
1900 /// Sets the the location of '(' in clause for 'depobj' directive.
1901 void setLParenLoc(SourceLocation Loc) {
1902 assert(IsExtended && "Expected extended clause.");
1903 *getTrailingObjects<SourceLocation>() = Loc;
1904 }
1905
1906 /// Sets the the location of '(' in clause for 'depobj' directive.
1907 void setArgumentLoc(SourceLocation Loc) {
1908 assert(IsExtended && "Expected extended clause.");
1909 *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc;
1910 }
1911
1912 /// Sets the dependence kind for the clause for 'depobj' directive.
1913 void setDependencyKind(OpenMPDependClauseKind DK) {
1914 assert(IsExtended && "Expected extended clause.");
1915 *getTrailingObjects<OpenMPDependClauseKind>() = DK;
1916 }
1917
1918 /// Build 'update' clause.
1919 ///
1920 /// \param StartLoc Starting location of the clause.
1921 /// \param EndLoc Ending location of the clause.
1922 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc,
1923 bool IsExtended)
1924 : OMPClause(llvm::omp::OMPC_update, StartLoc, EndLoc),
1925 IsExtended(IsExtended) {}
1926
1927 /// Build an empty clause.
1928 OMPUpdateClause(bool IsExtended)
1929 : OMPClause(llvm::omp::OMPC_update, SourceLocation(), SourceLocation()),
1930 IsExtended(IsExtended) {}
1931
1932public:
1933 /// Creates clause for 'atomic' directive.
1934 ///
1935 /// \param C AST context.
1936 /// \param StartLoc Starting location of the clause.
1937 /// \param EndLoc Ending location of the clause.
1938 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1939 SourceLocation EndLoc);
1940
1941 /// Creates clause for 'depobj' directive.
1942 ///
1943 /// \param C AST context.
1944 /// \param StartLoc Starting location of the clause.
1945 /// \param LParenLoc Location of '('.
1946 /// \param ArgumentLoc Location of the argument.
1947 /// \param DK Dependence kind.
1948 /// \param EndLoc Ending location of the clause.
1949 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1950 SourceLocation LParenLoc,
1951 SourceLocation ArgumentLoc,
1952 OpenMPDependClauseKind DK,
1953 SourceLocation EndLoc);
1954
1955 /// Creates an empty clause with the place for \a N variables.
1956 ///
1957 /// \param C AST context.
1958 /// \param IsExtended true if extended clause for 'depobj' directive must be
1959 /// created.
1960 static OMPUpdateClause *CreateEmpty(const ASTContext &C, bool IsExtended);
1961
1962 /// Checks if the clause is the extended clauses for 'depobj' directive.
1963 bool isExtended() const { return IsExtended; }
1964
1965 child_range children() {
1966 return child_range(child_iterator(), child_iterator());
1967 }
1968
1969 const_child_range children() const {
1970 return const_child_range(const_child_iterator(), const_child_iterator());
1971 }
1972
1973 child_range used_children() {
1974 return child_range(child_iterator(), child_iterator());
1975 }
1976 const_child_range used_children() const {
1977 return const_child_range(const_child_iterator(), const_child_iterator());
1978 }
1979
1980 /// Gets the the location of '(' in clause for 'depobj' directive.
1981 SourceLocation getLParenLoc() const {
1982 assert(IsExtended && "Expected extended clause.");
1983 return *getTrailingObjects<SourceLocation>();
1984 }
1985
1986 /// Gets the the location of argument in clause for 'depobj' directive.
1987 SourceLocation getArgumentLoc() const {
1988 assert(IsExtended && "Expected extended clause.");
1989 return *std::next(getTrailingObjects<SourceLocation>(), 1);
1990 }
1991
1992 /// Gets the dependence kind in clause for 'depobj' directive.
1993 OpenMPDependClauseKind getDependencyKind() const {
1994 assert(IsExtended && "Expected extended clause.");
1995 return *getTrailingObjects<OpenMPDependClauseKind>();
1996 }
1997
1998 static bool classof(const OMPClause *T) {
1999 return T->getClauseKind() == llvm::omp::OMPC_update;
2000 }
2001};
2002
2003/// This represents 'capture' clause in the '#pragma omp atomic'
2004/// directive.
2005///
2006/// \code
2007/// #pragma omp atomic capture
2008/// \endcode
2009/// In this example directive '#pragma omp atomic' has 'capture' clause.
2010class OMPCaptureClause : public OMPClause {
2011public:
2012 /// Build 'capture' clause.
2013 ///
2014 /// \param StartLoc Starting location of the clause.
2015 /// \param EndLoc Ending location of the clause.
2016 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
2017 : OMPClause(llvm::omp::OMPC_capture, StartLoc, EndLoc) {}
2018
2019 /// Build an empty clause.
2020 OMPCaptureClause()
2021 : OMPClause(llvm::omp::OMPC_capture, SourceLocation(), SourceLocation()) {
2022 }
2023
2024 child_range children() {
2025 return child_range(child_iterator(), child_iterator());
2026 }
2027
2028 const_child_range children() const {
2029 return const_child_range(const_child_iterator(), const_child_iterator());
2030 }
2031
2032 child_range used_children() {
2033 return child_range(child_iterator(), child_iterator());
2034 }
2035 const_child_range used_children() const {
2036 return const_child_range(const_child_iterator(), const_child_iterator());
2037 }
2038
2039 static bool classof(const OMPClause *T) {
2040 return T->getClauseKind() == llvm::omp::OMPC_capture;
2041 }
2042};
2043
2044/// This represents 'seq_cst' clause in the '#pragma omp atomic'
2045/// directive.
2046///
2047/// \code
2048/// #pragma omp atomic seq_cst
2049/// \endcode
2050/// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
2051class OMPSeqCstClause : public OMPClause {
2052public:
2053 /// Build 'seq_cst' clause.
2054 ///
2055 /// \param StartLoc Starting location of the clause.
2056 /// \param EndLoc Ending location of the clause.
2057 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
2058 : OMPClause(llvm::omp::OMPC_seq_cst, StartLoc, EndLoc) {}
2059
2060 /// Build an empty clause.
2061 OMPSeqCstClause()
2062 : OMPClause(llvm::omp::OMPC_seq_cst, SourceLocation(), SourceLocation()) {
2063 }
2064
2065 child_range children() {
2066 return child_range(child_iterator(), child_iterator());
2067 }
2068
2069 const_child_range children() const {
2070 return const_child_range(const_child_iterator(), const_child_iterator());
2071 }
2072
2073 child_range used_children() {
2074 return child_range(child_iterator(), child_iterator());
2075 }
2076 const_child_range used_children() const {
2077 return const_child_range(const_child_iterator(), const_child_iterator());
2078 }
2079
2080 static bool classof(const OMPClause *T) {
2081 return T->getClauseKind() == llvm::omp::OMPC_seq_cst;
2082 }
2083};
2084
2085/// This represents 'acq_rel' clause in the '#pragma omp atomic|flush'
2086/// directives.
2087///
2088/// \code
2089/// #pragma omp flush acq_rel
2090/// \endcode
2091/// In this example directive '#pragma omp flush' has 'acq_rel' clause.
2092class OMPAcqRelClause final : public OMPClause {
2093public:
2094 /// Build 'ack_rel' clause.
2095 ///
2096 /// \param StartLoc Starting location of the clause.
2097 /// \param EndLoc Ending location of the clause.
2098 OMPAcqRelClause(SourceLocation StartLoc, SourceLocation EndLoc)
2099 : OMPClause(llvm::omp::OMPC_acq_rel, StartLoc, EndLoc) {}
2100
2101 /// Build an empty clause.
2102 OMPAcqRelClause()
2103 : OMPClause(llvm::omp::OMPC_acq_rel, SourceLocation(), SourceLocation()) {
2104 }
2105
2106 child_range children() {
2107 return child_range(child_iterator(), child_iterator());
2108 }
2109
2110 const_child_range children() const {
2111 return const_child_range(const_child_iterator(), const_child_iterator());
2112 }
2113
2114 child_range used_children() {
2115 return child_range(child_iterator(), child_iterator());
2116 }
2117 const_child_range used_children() const {
2118 return const_child_range(const_child_iterator(), const_child_iterator());
2119 }
2120
2121 static bool classof(const OMPClause *T) {
2122 return T->getClauseKind() == llvm::omp::OMPC_acq_rel;
2123 }
2124};
2125
2126/// This represents 'acquire' clause in the '#pragma omp atomic|flush'
2127/// directives.
2128///
2129/// \code
2130/// #pragma omp flush acquire
2131/// \endcode
2132/// In this example directive '#pragma omp flush' has 'acquire' clause.
2133class OMPAcquireClause final : public OMPClause {
2134public:
2135 /// Build 'acquire' clause.
2136 ///
2137 /// \param StartLoc Starting location of the clause.
2138 /// \param EndLoc Ending location of the clause.
2139 OMPAcquireClause(SourceLocation StartLoc, SourceLocation EndLoc)
2140 : OMPClause(llvm::omp::OMPC_acquire, StartLoc, EndLoc) {}
2141
2142 /// Build an empty clause.
2143 OMPAcquireClause()
2144 : OMPClause(llvm::omp::OMPC_acquire, SourceLocation(), SourceLocation()) {
2145 }
2146
2147 child_range children() {
2148 return child_range(child_iterator(), child_iterator());
2149 }
2150
2151 const_child_range children() const {
2152 return const_child_range(const_child_iterator(), const_child_iterator());
2153 }
2154
2155 child_range used_children() {
2156 return child_range(child_iterator(), child_iterator());
2157 }
2158 const_child_range used_children() const {
2159 return const_child_range(const_child_iterator(), const_child_iterator());
2160 }
2161
2162 static bool classof(const OMPClause *T) {
2163 return T->getClauseKind() == llvm::omp::OMPC_acquire;
2164 }
2165};
2166
2167/// This represents 'release' clause in the '#pragma omp atomic|flush'
2168/// directives.
2169///
2170/// \code
2171/// #pragma omp flush release
2172/// \endcode
2173/// In this example directive '#pragma omp flush' has 'release' clause.
2174class OMPReleaseClause final : public OMPClause {
2175public:
2176 /// Build 'release' clause.
2177 ///
2178 /// \param StartLoc Starting location of the clause.
2179 /// \param EndLoc Ending location of the clause.
2180 OMPReleaseClause(SourceLocation StartLoc, SourceLocation EndLoc)
2181 : OMPClause(llvm::omp::OMPC_release, StartLoc, EndLoc) {}
2182
2183 /// Build an empty clause.
2184 OMPReleaseClause()
2185 : OMPClause(llvm::omp::OMPC_release, SourceLocation(), SourceLocation()) {
2186 }
2187
2188 child_range children() {
2189 return child_range(child_iterator(), child_iterator());
2190 }
2191
2192 const_child_range children() const {
2193 return const_child_range(const_child_iterator(), const_child_iterator());
2194 }
2195
2196 child_range used_children() {
2197 return child_range(child_iterator(), child_iterator());
2198 }
2199 const_child_range used_children() const {
2200 return const_child_range(const_child_iterator(), const_child_iterator());
2201 }
2202
2203 static bool classof(const OMPClause *T) {
2204 return T->getClauseKind() == llvm::omp::OMPC_release;
2205 }
2206};
2207
2208/// This represents 'relaxed' clause in the '#pragma omp atomic'
2209/// directives.
2210///
2211/// \code
2212/// #pragma omp atomic relaxed
2213/// \endcode
2214/// In this example directive '#pragma omp atomic' has 'relaxed' clause.
2215class OMPRelaxedClause final : public OMPClause {
2216public:
2217 /// Build 'relaxed' clause.
2218 ///
2219 /// \param StartLoc Starting location of the clause.
2220 /// \param EndLoc Ending location of the clause.
2221 OMPRelaxedClause(SourceLocation StartLoc, SourceLocation EndLoc)
2222 : OMPClause(llvm::omp::OMPC_relaxed, StartLoc, EndLoc) {}
2223
2224 /// Build an empty clause.
2225 OMPRelaxedClause()
2226 : OMPClause(llvm::omp::OMPC_relaxed, SourceLocation(), SourceLocation()) {
2227 }
2228
2229 child_range children() {
2230 return child_range(child_iterator(), child_iterator());
2231 }
2232
2233 const_child_range children() const {
2234 return const_child_range(const_child_iterator(), const_child_iterator());
2235 }
2236
2237 child_range used_children() {
2238 return child_range(child_iterator(), child_iterator());
2239 }
2240 const_child_range used_children() const {
2241 return const_child_range(const_child_iterator(), const_child_iterator());
2242 }
2243
2244 static bool classof(const OMPClause *T) {
2245 return T->getClauseKind() == llvm::omp::OMPC_relaxed;
2246 }
2247};
2248
2249/// This represents clause 'private' in the '#pragma omp ...' directives.
2250///
2251/// \code
2252/// #pragma omp parallel private(a,b)
2253/// \endcode
2254/// In this example directive '#pragma omp parallel' has clause 'private'
2255/// with the variables 'a' and 'b'.
2256class OMPPrivateClause final
2257 : public OMPVarListClause<OMPPrivateClause>,
2258 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
2259 friend class OMPClauseReader;
2260 friend OMPVarListClause;
2261 friend TrailingObjects;
2262
2263 /// Build clause with number of variables \a N.
2264 ///
2265 /// \param StartLoc Starting location of the clause.
2266 /// \param LParenLoc Location of '('.
2267 /// \param EndLoc Ending location of the clause.
2268 /// \param N Number of the variables in the clause.
2269 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2270 SourceLocation EndLoc, unsigned N)
2271 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc,
2272 LParenLoc, EndLoc, N) {}
2273
2274 /// Build an empty clause.
2275 ///
2276 /// \param N Number of variables.
2277 explicit OMPPrivateClause(unsigned N)
2278 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private,
2279 SourceLocation(), SourceLocation(),
2280 SourceLocation(), N) {}
2281
2282 /// Sets the list of references to private copies with initializers for
2283 /// new private variables.
2284 /// \param VL List of references.
2285 void setPrivateCopies(ArrayRef<Expr *> VL);
2286
2287 /// Gets the list of references to private copies with initializers for
2288 /// new private variables.
2289 MutableArrayRef<Expr *> getPrivateCopies() {
2290 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2291 }
2292 ArrayRef<const Expr *> getPrivateCopies() const {
2293 return llvm::makeArrayRef(varlist_end(), varlist_size());
2294 }
2295
2296public:
2297 /// Creates clause with a list of variables \a VL.
2298 ///
2299 /// \param C AST context.
2300 /// \param StartLoc Starting location of the clause.
2301 /// \param LParenLoc Location of '('.
2302 /// \param EndLoc Ending location of the clause.
2303 /// \param VL List of references to the variables.
2304 /// \param PrivateVL List of references to private copies with initializers.
2305 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2306 SourceLocation LParenLoc,
2307 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2308 ArrayRef<Expr *> PrivateVL);
2309
2310 /// Creates an empty clause with the place for \a N variables.
2311 ///
2312 /// \param C AST context.
2313 /// \param N The number of variables.
2314 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2315
2316 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
2317 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
2318 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2319 using private_copies_const_range =
2320 llvm::iterator_range<private_copies_const_iterator>;
2321
2322 private_copies_range private_copies() {
2323 return private_copies_range(getPrivateCopies().begin(),
2324 getPrivateCopies().end());
2325 }
2326
2327 private_copies_const_range private_copies() const {
2328 return private_copies_const_range(getPrivateCopies().begin(),
2329 getPrivateCopies().end());
2330 }
2331
2332 child_range children() {
2333 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2334 reinterpret_cast<Stmt **>(varlist_end()));
2335 }
2336
2337 const_child_range children() const {
2338 auto Children = const_cast<OMPPrivateClause *>(this)->children();
2339 return const_child_range(Children.begin(), Children.end());
2340 }
2341
2342 child_range used_children() {
2343 return child_range(child_iterator(), child_iterator());
2344 }
2345 const_child_range used_children() const {
2346 return const_child_range(const_child_iterator(), const_child_iterator());
2347 }
2348
2349 static bool classof(const OMPClause *T) {
2350 return T->getClauseKind() == llvm::omp::OMPC_private;
2351 }
2352};
2353
2354/// This represents clause 'firstprivate' in the '#pragma omp ...'
2355/// directives.
2356///
2357/// \code
2358/// #pragma omp parallel firstprivate(a,b)
2359/// \endcode
2360/// In this example directive '#pragma omp parallel' has clause 'firstprivate'
2361/// with the variables 'a' and 'b'.
2362class OMPFirstprivateClause final
2363 : public OMPVarListClause<OMPFirstprivateClause>,
2364 public OMPClauseWithPreInit,
2365 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
2366 friend class OMPClauseReader;
2367 friend OMPVarListClause;
2368 friend TrailingObjects;
2369
2370 /// Build clause with number of variables \a N.
2371 ///
2372 /// \param StartLoc Starting location of the clause.
2373 /// \param LParenLoc Location of '('.
2374 /// \param EndLoc Ending location of the clause.
2375 /// \param N Number of the variables in the clause.
2376 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2377 SourceLocation EndLoc, unsigned N)
2378 : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate,
2379 StartLoc, LParenLoc, EndLoc, N),
2380 OMPClauseWithPreInit(this) {}
2381
2382 /// Build an empty clause.
2383 ///
2384 /// \param N Number of variables.
2385 explicit OMPFirstprivateClause(unsigned N)
2386 : OMPVarListClause<OMPFirstprivateClause>(
2387 llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(),
2388 SourceLocation(), N),
2389 OMPClauseWithPreInit(this) {}
2390
2391 /// Sets the list of references to private copies with initializers for
2392 /// new private variables.
2393 /// \param VL List of references.
2394 void setPrivateCopies(ArrayRef<Expr *> VL);
2395
2396 /// Gets the list of references to private copies with initializers for
2397 /// new private variables.
2398 MutableArrayRef<Expr *> getPrivateCopies() {
2399 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2400 }
2401 ArrayRef<const Expr *> getPrivateCopies() const {
2402 return llvm::makeArrayRef(varlist_end(), varlist_size());
2403 }
2404
2405 /// Sets the list of references to initializer variables for new
2406 /// private variables.
2407 /// \param VL List of references.
2408 void setInits(ArrayRef<Expr *> VL);
2409
2410 /// Gets the list of references to initializer variables for new
2411 /// private variables.
2412 MutableArrayRef<Expr *> getInits() {
2413 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2414 }
2415 ArrayRef<const Expr *> getInits() const {
2416 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2417 }
2418
2419public:
2420 /// Creates clause with a list of variables \a VL.
2421 ///
2422 /// \param C AST context.
2423 /// \param StartLoc Starting location of the clause.
2424 /// \param LParenLoc Location of '('.
2425 /// \param EndLoc Ending location of the clause.
2426 /// \param VL List of references to the original variables.
2427 /// \param PrivateVL List of references to private copies with initializers.
2428 /// \param InitVL List of references to auto generated variables used for
2429 /// initialization of a single array element. Used if firstprivate variable is
2430 /// of array type.
2431 /// \param PreInit Statement that must be executed before entering the OpenMP
2432 /// region with this clause.
2433 static OMPFirstprivateClause *
2434 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2435 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
2436 ArrayRef<Expr *> InitVL, Stmt *PreInit);
2437
2438 /// Creates an empty clause with the place for \a N variables.
2439 ///
2440 /// \param C AST context.
2441 /// \param N The number of variables.
2442 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2443
2444 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
2445 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
2446 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2447 using private_copies_const_range =
2448 llvm::iterator_range<private_copies_const_iterator>;
2449
2450 private_copies_range private_copies() {
2451 return private_copies_range(getPrivateCopies().begin(),
2452 getPrivateCopies().end());
2453 }
2454 private_copies_const_range private_copies() const {
2455 return private_copies_const_range(getPrivateCopies().begin(),
2456 getPrivateCopies().end());
2457 }
2458
2459 using inits_iterator = MutableArrayRef<Expr *>::iterator;
2460 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
2461 using inits_range = llvm::iterator_range<inits_iterator>;
2462 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2463
2464 inits_range inits() {
2465 return inits_range(getInits().begin(), getInits().end());
2466 }
2467 inits_const_range inits() const {
2468 return inits_const_range(getInits().begin(), getInits().end());
2469 }
2470
2471 child_range children() {
2472 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2473 reinterpret_cast<Stmt **>(varlist_end()));
2474 }
2475
2476 const_child_range children() const {
2477 auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
2478 return const_child_range(Children.begin(), Children.end());
2479 }
2480
2481 child_range used_children() {
2482 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2483 reinterpret_cast<Stmt **>(varlist_end()));
2484 }
2485 const_child_range used_children() const {
2486 auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
2487 return const_child_range(Children.begin(), Children.end());
2488 }
2489
2490 static bool classof(const OMPClause *T) {
2491 return T->getClauseKind() == llvm::omp::OMPC_firstprivate;
2492 }
2493};
2494
2495/// This represents clause 'lastprivate' in the '#pragma omp ...'
2496/// directives.
2497///
2498/// \code
2499/// #pragma omp simd lastprivate(a,b)
2500/// \endcode
2501/// In this example directive '#pragma omp simd' has clause 'lastprivate'
2502/// with the variables 'a' and 'b'.
2503class OMPLastprivateClause final
2504 : public OMPVarListClause<OMPLastprivateClause>,
2505 public OMPClauseWithPostUpdate,
2506 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
2507 // There are 4 additional tail-allocated arrays at the end of the class:
2508 // 1. Contains list of pseudo variables with the default initialization for
2509 // each non-firstprivate variables. Used in codegen for initialization of
2510 // lastprivate copies.
2511 // 2. List of helper expressions for proper generation of assignment operation
2512 // required for lastprivate clause. This list represents private variables
2513 // (for arrays, single array element).
2514 // 3. List of helper expressions for proper generation of assignment operation
2515 // required for lastprivate clause. This list represents original variables
2516 // (for arrays, single array element).
2517 // 4. List of helper expressions that represents assignment operation:
2518 // \code
2519 // DstExprs = SrcExprs;
2520 // \endcode
2521 // Required for proper codegen of final assignment performed by the
2522 // lastprivate clause.
2523 friend class OMPClauseReader;
2524 friend OMPVarListClause;
2525 friend TrailingObjects;
2526
2527 /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
2528 OpenMPLastprivateModifier LPKind;
2529 /// Optional location of the lasptrivate kind, if specified by user.
2530 SourceLocation LPKindLoc;
2531 /// Optional colon location, if specified by user.
2532 SourceLocation ColonLoc;
2533
2534 /// Build clause with number of variables \a N.
2535 ///
2536 /// \param StartLoc Starting location of the clause.
2537 /// \param LParenLoc Location of '('.
2538 /// \param EndLoc Ending location of the clause.
2539 /// \param N Number of the variables in the clause.
2540 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2541 SourceLocation EndLoc, OpenMPLastprivateModifier LPKind,
2542 SourceLocation LPKindLoc, SourceLocation ColonLoc,
2543 unsigned N)
2544 : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate,
2545 StartLoc, LParenLoc, EndLoc, N),
2546 OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
2547 ColonLoc(ColonLoc) {}
2548
2549 /// Build an empty clause.
2550 ///
2551 /// \param N Number of variables.
2552 explicit OMPLastprivateClause(unsigned N)
2553 : OMPVarListClause<OMPLastprivateClause>(
2554 llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(),
2555 SourceLocation(), N),
2556 OMPClauseWithPostUpdate(this) {}
2557
2558 /// Get the list of helper expressions for initialization of private
2559 /// copies for lastprivate variables.
2560 MutableArrayRef<Expr *> getPrivateCopies() {
2561 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2562 }
2563 ArrayRef<const Expr *> getPrivateCopies() const {
2564 return llvm::makeArrayRef(varlist_end(), varlist_size());
2565 }
2566
2567 /// Set list of helper expressions, required for proper codegen of the
2568 /// clause. These expressions represent private variables (for arrays, single
2569 /// array element) in the final assignment statement performed by the
2570 /// lastprivate clause.
2571 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2572
2573 /// Get the list of helper source expressions.
2574 MutableArrayRef<Expr *> getSourceExprs() {
2575 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2576 }
2577 ArrayRef<const Expr *> getSourceExprs() const {
2578 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2579 }
2580
2581 /// Set list of helper expressions, required for proper codegen of the
2582 /// clause. These expressions represent original variables (for arrays, single
2583 /// array element) in the final assignment statement performed by the
2584 /// lastprivate clause.
2585 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2586
2587 /// Get the list of helper destination expressions.
2588 MutableArrayRef<Expr *> getDestinationExprs() {
2589 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2590 }
2591 ArrayRef<const Expr *> getDestinationExprs() const {
2592 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2593 }
2594
2595 /// Set list of helper assignment expressions, required for proper
2596 /// codegen of the clause. These expressions are assignment expressions that
2597 /// assign private copy of the variable to original variable.
2598 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2599
2600 /// Get the list of helper assignment expressions.
2601 MutableArrayRef<Expr *> getAssignmentOps() {
2602 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2603 }
2604 ArrayRef<const Expr *> getAssignmentOps() const {
2605 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2606 }
2607
2608 /// Sets lastprivate kind.
2609 void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
2610 /// Sets location of the lastprivate kind.
2611 void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
2612 /// Sets colon symbol location.
2613 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2614
2615public:
2616 /// Creates clause with a list of variables \a VL.
2617 ///
2618 /// \param C AST context.
2619 /// \param StartLoc Starting location of the clause.
2620 /// \param LParenLoc Location of '('.
2621 /// \param EndLoc Ending location of the clause.
2622 /// \param VL List of references to the variables.
2623 /// \param SrcExprs List of helper expressions for proper generation of
2624 /// assignment operation required for lastprivate clause. This list represents
2625 /// private variables (for arrays, single array element).
2626 /// \param DstExprs List of helper expressions for proper generation of
2627 /// assignment operation required for lastprivate clause. This list represents
2628 /// original variables (for arrays, single array element).
2629 /// \param AssignmentOps List of helper expressions that represents assignment
2630 /// operation:
2631 /// \code
2632 /// DstExprs = SrcExprs;
2633 /// \endcode
2634 /// Required for proper codegen of final assignment performed by the
2635 /// lastprivate clause.
2636 /// \param LPKind Lastprivate kind, e.g. 'conditional'.
2637 /// \param LPKindLoc Location of the lastprivate kind.
2638 /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
2639 /// \param PreInit Statement that must be executed before entering the OpenMP
2640 /// region with this clause.
2641 /// \param PostUpdate Expression that must be executed after exit from the
2642 /// OpenMP region with this clause.
2643 static OMPLastprivateClause *
2644 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2645 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2646 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
2647 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
2648 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
2649
2650 /// Creates an empty clause with the place for \a N variables.
2651 ///
2652 /// \param C AST context.
2653 /// \param N The number of variables.
2654 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2655
2656 /// Lastprivate kind.
2657 OpenMPLastprivateModifier getKind() const { return LPKind; }
2658 /// Returns the location of the lastprivate kind.
2659 SourceLocation getKindLoc() const { return LPKindLoc; }
2660 /// Returns the location of the ':' symbol, if any.
2661 SourceLocation getColonLoc() const { return ColonLoc; }
2662
2663 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2664 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2665 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2666 using helper_expr_const_range =
2667 llvm::iterator_range<helper_expr_const_iterator>;
2668
2669 /// Set list of helper expressions, required for generation of private
2670 /// copies of original lastprivate variables.
2671 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
2672
2673 helper_expr_const_range private_copies() const {
2674 return helper_expr_const_range(getPrivateCopies().begin(),
2675 getPrivateCopies().end());
2676 }
2677
2678 helper_expr_range private_copies() {
2679 return helper_expr_range(getPrivateCopies().begin(),
2680 getPrivateCopies().end());
2681 }
2682
2683 helper_expr_const_range source_exprs() const {
2684 return helper_expr_const_range(getSourceExprs().begin(),
2685 getSourceExprs().end());
2686 }
2687
2688 helper_expr_range source_exprs() {
2689 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2690 }
2691
2692 helper_expr_const_range destination_exprs() const {
2693 return helper_expr_const_range(getDestinationExprs().begin(),
2694 getDestinationExprs().end());
2695 }
2696
2697 helper_expr_range destination_exprs() {
2698 return helper_expr_range(getDestinationExprs().begin(),
2699 getDestinationExprs().end());
2700 }
2701
2702 helper_expr_const_range assignment_ops() const {
2703 return helper_expr_const_range(getAssignmentOps().begin(),
2704 getAssignmentOps().end());
2705 }
2706
2707 helper_expr_range assignment_ops() {
2708 return helper_expr_range(getAssignmentOps().begin(),
2709 getAssignmentOps().end());
2710 }
2711
2712 child_range children() {
2713 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2714 reinterpret_cast<Stmt **>(varlist_end()));
2715 }
2716
2717 const_child_range children() const {
2718 auto Children = const_cast<OMPLastprivateClause *>(this)->children();
2719 return const_child_range(Children.begin(), Children.end());
2720 }
2721
2722 child_range used_children() {
2723 return child_range(child_iterator(), child_iterator());
2724 }
2725 const_child_range used_children() const {
2726 return const_child_range(const_child_iterator