1 //===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// \brief 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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H
17 #define LLVM_CLANG_AST_OPENMPCLAUSE_H
19 #include "clang/AST/Expr.h"
20 #include "clang/AST/Stmt.h"
21 #include "clang/Basic/OpenMPKinds.h"
22 #include "clang/Basic/SourceLocation.h"
26 //===----------------------------------------------------------------------===//
27 // AST classes for clauses.
28 //===----------------------------------------------------------------------===//
30 /// \brief This is a basic class for representing single OpenMP clause.
33 /// \brief Starting location of the clause (the clause keyword).
34 SourceLocation StartLoc;
35 /// \brief Ending location of the clause.
36 SourceLocation EndLoc;
37 /// \brief Kind of the clause.
38 OpenMPClauseKind Kind;
41 OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
42 : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
45 /// \brief Returns the starting location of the clause.
46 SourceLocation getLocStart() const { return StartLoc; }
47 /// \brief Returns the ending location of the clause.
48 SourceLocation getLocEnd() const { return EndLoc; }
50 /// \brief Sets the starting location of the clause.
51 void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
52 /// \brief Sets the ending location of the clause.
53 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
55 /// \brief Returns kind of OpenMP clause (private, shared, reduction, etc.).
56 OpenMPClauseKind getClauseKind() const { return Kind; }
58 bool isImplicit() const { return StartLoc.isInvalid(); }
61 ConstStmtRange children() const {
62 return const_cast<OMPClause *>(this)->children();
64 static bool classof(const OMPClause *) { return true; }
67 /// \brief This represents clauses with the list of variables like 'private',
68 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
69 /// '#pragma omp ...' directives.
70 template <class T> class OMPVarListClause : public OMPClause {
71 friend class OMPClauseReader;
72 /// \brief Location of '('.
73 SourceLocation LParenLoc;
74 /// \brief Number of variables in the list.
78 /// \brief Fetches list of variables associated with this clause.
79 MutableArrayRef<Expr *> getVarRefs() {
80 return MutableArrayRef<Expr *>(
81 reinterpret_cast<Expr **>(
82 reinterpret_cast<char *>(this) +
83 llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())),
87 /// \brief Sets the list of variables for this clause.
88 void setVarRefs(ArrayRef<Expr *> VL) {
89 assert(VL.size() == NumVars &&
90 "Number of variables is not the same as the preallocated buffer");
93 reinterpret_cast<Expr **>(
94 reinterpret_cast<char *>(this) +
95 llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())));
98 /// \brief Build a clause with \a N variables
100 /// \param K Kind of the clause.
101 /// \param StartLoc Starting location of the clause (the clause keyword).
102 /// \param LParenLoc Location of '('.
103 /// \param EndLoc Ending location of the clause.
104 /// \param N Number of the variables in the clause.
106 OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
107 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
108 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
111 typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
112 typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
113 typedef llvm::iterator_range<varlist_iterator> varlist_range;
114 typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
116 unsigned varlist_size() const { return NumVars; }
117 bool varlist_empty() const { return NumVars == 0; }
119 varlist_range varlists() {
120 return varlist_range(varlist_begin(), varlist_end());
122 varlist_const_range varlists() const {
123 return varlist_const_range(varlist_begin(), varlist_end());
126 varlist_iterator varlist_begin() { return getVarRefs().begin(); }
127 varlist_iterator varlist_end() { return getVarRefs().end(); }
128 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
129 varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
131 /// \brief Sets the location of '('.
132 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
133 /// \brief Returns the location of '('.
134 SourceLocation getLParenLoc() const { return LParenLoc; }
136 /// \brief Fetches list of all variables in the clause.
137 ArrayRef<const Expr *> getVarRefs() const {
138 return llvm::makeArrayRef(
139 reinterpret_cast<const Expr *const *>(
140 reinterpret_cast<const char *>(this) +
141 llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<const Expr *>())),
146 /// \brief This represents 'if' clause in the '#pragma omp ...' directive.
149 /// #pragma omp parallel if(a > 5)
151 /// In this example directive '#pragma omp parallel' has simple 'if'
152 /// clause with condition 'a > 5'.
154 class OMPIfClause : public OMPClause {
155 friend class OMPClauseReader;
156 /// \brief Location of '('.
157 SourceLocation LParenLoc;
158 /// \brief Condition of the 'if' clause.
161 /// \brief Set condition.
163 void setCondition(Expr *Cond) { Condition = Cond; }
166 /// \brief Build 'if' clause with condition \a Cond.
168 /// \param StartLoc Starting location of the clause.
169 /// \param LParenLoc Location of '('.
170 /// \param Cond Condition of the clause.
171 /// \param EndLoc Ending location of the clause.
173 OMPIfClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
174 SourceLocation EndLoc)
175 : OMPClause(OMPC_if, StartLoc, EndLoc), LParenLoc(LParenLoc),
178 /// \brief Build an empty clause.
181 : OMPClause(OMPC_if, SourceLocation(), SourceLocation()),
182 LParenLoc(SourceLocation()), Condition(nullptr) {}
184 /// \brief Sets the location of '('.
185 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
186 /// \brief Returns the location of '('.
187 SourceLocation getLParenLoc() const { return LParenLoc; }
189 /// \brief Returns condition.
190 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
192 static bool classof(const OMPClause *T) {
193 return T->getClauseKind() == OMPC_if;
196 StmtRange children() { return StmtRange(&Condition, &Condition + 1); }
199 /// \brief This represents 'final' clause in the '#pragma omp ...' directive.
202 /// #pragma omp task final(a > 5)
204 /// In this example directive '#pragma omp task' has simple 'final'
205 /// clause with condition 'a > 5'.
207 class OMPFinalClause : public OMPClause {
208 friend class OMPClauseReader;
209 /// \brief Location of '('.
210 SourceLocation LParenLoc;
211 /// \brief Condition of the 'if' clause.
214 /// \brief Set condition.
216 void setCondition(Expr *Cond) { Condition = Cond; }
219 /// \brief Build 'final' clause with condition \a Cond.
221 /// \param StartLoc Starting location of the clause.
222 /// \param LParenLoc Location of '('.
223 /// \param Cond Condition of the clause.
224 /// \param EndLoc Ending location of the clause.
226 OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
227 SourceLocation EndLoc)
228 : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc),
231 /// \brief Build an empty clause.
234 : OMPClause(OMPC_final, SourceLocation(), SourceLocation()),
235 LParenLoc(SourceLocation()), Condition(nullptr) {}
237 /// \brief Sets the location of '('.
238 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
239 /// \brief Returns the location of '('.
240 SourceLocation getLParenLoc() const { return LParenLoc; }
242 /// \brief Returns condition.
243 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
245 static bool classof(const OMPClause *T) {
246 return T->getClauseKind() == OMPC_final;
249 StmtRange children() { return StmtRange(&Condition, &Condition + 1); }
252 /// \brief This represents 'num_threads' clause in the '#pragma omp ...'
256 /// #pragma omp parallel num_threads(6)
258 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
259 /// clause with number of threads '6'.
261 class OMPNumThreadsClause : public OMPClause {
262 friend class OMPClauseReader;
263 /// \brief Location of '('.
264 SourceLocation LParenLoc;
265 /// \brief Condition of the 'num_threads' clause.
268 /// \brief Set condition.
270 void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
273 /// \brief Build 'num_threads' clause with condition \a NumThreads.
275 /// \param NumThreads Number of threads for the construct.
276 /// \param StartLoc Starting location of the clause.
277 /// \param LParenLoc Location of '('.
278 /// \param EndLoc Ending location of the clause.
280 OMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc,
281 SourceLocation LParenLoc, SourceLocation EndLoc)
282 : OMPClause(OMPC_num_threads, StartLoc, EndLoc), LParenLoc(LParenLoc),
283 NumThreads(NumThreads) {}
285 /// \brief Build an empty clause.
287 OMPNumThreadsClause()
288 : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
289 LParenLoc(SourceLocation()), NumThreads(nullptr) {}
291 /// \brief Sets the location of '('.
292 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
293 /// \brief Returns the location of '('.
294 SourceLocation getLParenLoc() const { return LParenLoc; }
296 /// \brief Returns number of threads.
297 Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
299 static bool classof(const OMPClause *T) {
300 return T->getClauseKind() == OMPC_num_threads;
303 StmtRange children() { return StmtRange(&NumThreads, &NumThreads + 1); }
306 /// \brief This represents 'safelen' clause in the '#pragma omp ...'
310 /// #pragma omp simd safelen(4)
312 /// In this example directive '#pragma omp simd' has clause 'safelen'
313 /// with single expression '4'.
314 /// If the safelen clause is used then no two iterations executed
315 /// concurrently with SIMD instructions can have a greater distance
316 /// in the logical iteration space than its value. The parameter of
317 /// the safelen clause must be a constant positive integer expression.
319 class OMPSafelenClause : public OMPClause {
320 friend class OMPClauseReader;
321 /// \brief Location of '('.
322 SourceLocation LParenLoc;
323 /// \brief Safe iteration space distance.
326 /// \brief Set safelen.
327 void setSafelen(Expr *Len) { Safelen = Len; }
330 /// \brief Build 'safelen' clause.
332 /// \param Len Expression associated with this clause.
333 /// \param StartLoc Starting location of the clause.
334 /// \param EndLoc Ending location of the clause.
336 OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
337 SourceLocation EndLoc)
338 : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
341 /// \brief Build an empty clause.
343 explicit OMPSafelenClause()
344 : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()),
345 LParenLoc(SourceLocation()), Safelen(nullptr) {}
347 /// \brief Sets the location of '('.
348 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
349 /// \brief Returns the location of '('.
350 SourceLocation getLParenLoc() const { return LParenLoc; }
352 /// \brief Return safe iteration space distance.
353 Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
355 static bool classof(const OMPClause *T) {
356 return T->getClauseKind() == OMPC_safelen;
359 StmtRange children() { return StmtRange(&Safelen, &Safelen + 1); }
362 /// \brief This represents 'collapse' clause in the '#pragma omp ...'
366 /// #pragma omp simd collapse(3)
368 /// In this example directive '#pragma omp simd' has clause 'collapse'
369 /// with single expression '3'.
370 /// The parameter must be a constant positive integer expression, it specifies
371 /// the number of nested loops that should be collapsed into a single iteration
374 class OMPCollapseClause : public OMPClause {
375 friend class OMPClauseReader;
376 /// \brief Location of '('.
377 SourceLocation LParenLoc;
378 /// \brief Number of for-loops.
381 /// \brief Set the number of associated for-loops.
382 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
385 /// \brief Build 'collapse' clause.
387 /// \param Num Expression associated with this clause.
388 /// \param StartLoc Starting location of the clause.
389 /// \param LParenLoc Location of '('.
390 /// \param EndLoc Ending location of the clause.
392 OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
393 SourceLocation LParenLoc, SourceLocation EndLoc)
394 : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
397 /// \brief Build an empty clause.
399 explicit OMPCollapseClause()
400 : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()),
401 LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
403 /// \brief Sets the location of '('.
404 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
405 /// \brief Returns the location of '('.
406 SourceLocation getLParenLoc() const { return LParenLoc; }
408 /// \brief Return the number of associated for-loops.
409 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
411 static bool classof(const OMPClause *T) {
412 return T->getClauseKind() == OMPC_collapse;
415 StmtRange children() { return StmtRange(&NumForLoops, &NumForLoops + 1); }
418 /// \brief This represents 'default' clause in the '#pragma omp ...' directive.
421 /// #pragma omp parallel default(shared)
423 /// In this example directive '#pragma omp parallel' has simple 'default'
424 /// clause with kind 'shared'.
426 class OMPDefaultClause : public OMPClause {
427 friend class OMPClauseReader;
428 /// \brief Location of '('.
429 SourceLocation LParenLoc;
430 /// \brief A kind of the 'default' clause.
431 OpenMPDefaultClauseKind Kind;
432 /// \brief Start location of the kind in source code.
433 SourceLocation KindKwLoc;
435 /// \brief Set kind of the clauses.
437 /// \param K Argument of clause.
439 void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
441 /// \brief Set argument location.
443 /// \param KLoc Argument location.
445 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
448 /// \brief Build 'default' clause with argument \a A ('none' or 'shared').
450 /// \param A Argument of the clause ('none' or 'shared').
451 /// \param ALoc Starting location of the argument.
452 /// \param StartLoc Starting location of the clause.
453 /// \param LParenLoc Location of '('.
454 /// \param EndLoc Ending location of the clause.
456 OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
457 SourceLocation StartLoc, SourceLocation LParenLoc,
458 SourceLocation EndLoc)
459 : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
460 Kind(A), KindKwLoc(ALoc) {}
462 /// \brief Build an empty clause.
465 : OMPClause(OMPC_default, SourceLocation(), SourceLocation()),
466 LParenLoc(SourceLocation()), Kind(OMPC_DEFAULT_unknown),
467 KindKwLoc(SourceLocation()) {}
469 /// \brief Sets the location of '('.
470 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
471 /// \brief Returns the location of '('.
472 SourceLocation getLParenLoc() const { return LParenLoc; }
474 /// \brief Returns kind of the clause.
475 OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
477 /// \brief Returns location of clause kind.
478 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
480 static bool classof(const OMPClause *T) {
481 return T->getClauseKind() == OMPC_default;
484 StmtRange children() { return StmtRange(); }
487 /// \brief This represents 'proc_bind' clause in the '#pragma omp ...'
491 /// #pragma omp parallel proc_bind(master)
493 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
494 /// clause with kind 'master'.
496 class OMPProcBindClause : public OMPClause {
497 friend class OMPClauseReader;
498 /// \brief Location of '('.
499 SourceLocation LParenLoc;
500 /// \brief A kind of the 'proc_bind' clause.
501 OpenMPProcBindClauseKind Kind;
502 /// \brief Start location of the kind in source code.
503 SourceLocation KindKwLoc;
505 /// \brief Set kind of the clause.
507 /// \param K Kind of clause.
509 void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
511 /// \brief Set clause kind location.
513 /// \param KLoc Kind location.
515 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
518 /// \brief Build 'proc_bind' clause with argument \a A ('master', 'close' or
521 /// \param A Argument of the clause ('master', 'close' or 'spread').
522 /// \param ALoc Starting location of the argument.
523 /// \param StartLoc Starting location of the clause.
524 /// \param LParenLoc Location of '('.
525 /// \param EndLoc Ending location of the clause.
527 OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
528 SourceLocation StartLoc, SourceLocation LParenLoc,
529 SourceLocation EndLoc)
530 : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
531 Kind(A), KindKwLoc(ALoc) {}
533 /// \brief Build an empty clause.
536 : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()),
537 LParenLoc(SourceLocation()), Kind(OMPC_PROC_BIND_unknown),
538 KindKwLoc(SourceLocation()) {}
540 /// \brief Sets the location of '('.
541 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
542 /// \brief Returns the location of '('.
543 SourceLocation getLParenLoc() const { return LParenLoc; }
545 /// \brief Returns kind of the clause.
546 OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
548 /// \brief Returns location of clause kind.
549 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
551 static bool classof(const OMPClause *T) {
552 return T->getClauseKind() == OMPC_proc_bind;
555 StmtRange children() { return StmtRange(); }
558 /// \brief This represents 'schedule' clause in the '#pragma omp ...' directive.
561 /// #pragma omp for schedule(static, 3)
563 /// In this example directive '#pragma omp for' has 'schedule' clause with
564 /// arguments 'static' and '3'.
566 class OMPScheduleClause : public OMPClause {
567 friend class OMPClauseReader;
568 /// \brief Location of '('.
569 SourceLocation LParenLoc;
570 /// \brief A kind of the 'schedule' clause.
571 OpenMPScheduleClauseKind Kind;
572 /// \brief Start location of the schedule ind in source code.
573 SourceLocation KindLoc;
574 /// \brief Location of ',' (if any).
575 SourceLocation CommaLoc;
576 /// \brief Chunk size and a reference to pseudo variable for combined
578 enum { CHUNK_SIZE, HELPER_CHUNK_SIZE, NUM_EXPRS };
579 Stmt *ChunkSizes[NUM_EXPRS];
581 /// \brief Set schedule kind.
583 /// \param K Schedule kind.
585 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
586 /// \brief Sets the location of '('.
588 /// \param Loc Location of '('.
590 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
591 /// \brief Set schedule kind start location.
593 /// \param KLoc Schedule kind location.
595 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
596 /// \brief Set location of ','.
598 /// \param Loc Location of ','.
600 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
601 /// \brief Set chunk size.
603 /// \param E Chunk size.
605 void setChunkSize(Expr *E) { ChunkSizes[CHUNK_SIZE] = E; }
606 /// \brief Set helper chunk size.
608 /// \param E Helper chunk size.
610 void setHelperChunkSize(Expr *E) { ChunkSizes[HELPER_CHUNK_SIZE] = E; }
613 /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size
614 /// expression \a ChunkSize.
616 /// \param StartLoc Starting location of the clause.
617 /// \param LParenLoc Location of '('.
618 /// \param KLoc Starting location of the argument.
619 /// \param CommaLoc Location of ','.
620 /// \param EndLoc Ending location of the clause.
621 /// \param Kind Schedule kind.
622 /// \param ChunkSize Chunk size.
623 /// \param HelperChunkSize Helper chunk size for combined directives.
625 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
626 SourceLocation KLoc, SourceLocation CommaLoc,
627 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
628 Expr *ChunkSize, Expr *HelperChunkSize)
629 : OMPClause(OMPC_schedule, StartLoc, EndLoc), LParenLoc(LParenLoc),
630 Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc) {
631 ChunkSizes[CHUNK_SIZE] = ChunkSize;
632 ChunkSizes[HELPER_CHUNK_SIZE] = HelperChunkSize;
635 /// \brief Build an empty clause.
637 explicit OMPScheduleClause()
638 : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
639 Kind(OMPC_SCHEDULE_unknown) {
640 ChunkSizes[CHUNK_SIZE] = nullptr;
641 ChunkSizes[HELPER_CHUNK_SIZE] = nullptr;
644 /// \brief Get kind of the clause.
646 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
647 /// \brief Get location of '('.
649 SourceLocation getLParenLoc() { return LParenLoc; }
650 /// \brief Get kind location.
652 SourceLocation getScheduleKindLoc() { return KindLoc; }
653 /// \brief Get location of ','.
655 SourceLocation getCommaLoc() { return CommaLoc; }
656 /// \brief Get chunk size.
658 Expr *getChunkSize() { return dyn_cast_or_null<Expr>(ChunkSizes[CHUNK_SIZE]); }
659 /// \brief Get chunk size.
661 Expr *getChunkSize() const {
662 return dyn_cast_or_null<Expr>(ChunkSizes[CHUNK_SIZE]);
664 /// \brief Get helper chunk size.
666 Expr *getHelperChunkSize() {
667 return dyn_cast_or_null<Expr>(ChunkSizes[HELPER_CHUNK_SIZE]);
669 /// \brief Get helper chunk size.
671 Expr *getHelperChunkSize() const {
672 return dyn_cast_or_null<Expr>(ChunkSizes[HELPER_CHUNK_SIZE]);
675 static bool classof(const OMPClause *T) {
676 return T->getClauseKind() == OMPC_schedule;
679 StmtRange children() {
680 return StmtRange(&ChunkSizes[CHUNK_SIZE], &ChunkSizes[CHUNK_SIZE] + 1);
684 /// \brief This represents 'ordered' clause in the '#pragma omp ...' directive.
687 /// #pragma omp for ordered
689 /// In this example directive '#pragma omp for' has 'ordered' clause.
691 class OMPOrderedClause : public OMPClause {
693 /// \brief Build 'ordered' clause.
695 /// \param StartLoc Starting location of the clause.
696 /// \param EndLoc Ending location of the clause.
698 OMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc)
699 : OMPClause(OMPC_ordered, StartLoc, EndLoc) {}
701 /// \brief Build an empty clause.
704 : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {}
706 static bool classof(const OMPClause *T) {
707 return T->getClauseKind() == OMPC_ordered;
710 StmtRange children() { return StmtRange(); }
713 /// \brief This represents 'nowait' clause in the '#pragma omp ...' directive.
716 /// #pragma omp for nowait
718 /// In this example directive '#pragma omp for' has 'nowait' clause.
720 class OMPNowaitClause : public OMPClause {
722 /// \brief Build 'nowait' clause.
724 /// \param StartLoc Starting location of the clause.
725 /// \param EndLoc Ending location of the clause.
727 OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
728 : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
730 /// \brief Build an empty clause.
733 : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
735 static bool classof(const OMPClause *T) {
736 return T->getClauseKind() == OMPC_nowait;
739 StmtRange children() { return StmtRange(); }
742 /// \brief This represents 'untied' clause in the '#pragma omp ...' directive.
745 /// #pragma omp task untied
747 /// In this example directive '#pragma omp task' has 'untied' clause.
749 class OMPUntiedClause : public OMPClause {
751 /// \brief Build 'untied' clause.
753 /// \param StartLoc Starting location of the clause.
754 /// \param EndLoc Ending location of the clause.
756 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
757 : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
759 /// \brief Build an empty clause.
762 : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
764 static bool classof(const OMPClause *T) {
765 return T->getClauseKind() == OMPC_untied;
768 StmtRange children() { return StmtRange(); }
771 /// \brief This represents 'mergeable' clause in the '#pragma omp ...'
775 /// #pragma omp task mergeable
777 /// In this example directive '#pragma omp task' has 'mergeable' clause.
779 class OMPMergeableClause : public OMPClause {
781 /// \brief Build 'mergeable' clause.
783 /// \param StartLoc Starting location of the clause.
784 /// \param EndLoc Ending location of the clause.
786 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
787 : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
789 /// \brief Build an empty clause.
792 : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
794 static bool classof(const OMPClause *T) {
795 return T->getClauseKind() == OMPC_mergeable;
798 StmtRange children() { return StmtRange(); }
801 /// \brief This represents 'read' clause in the '#pragma omp atomic' directive.
804 /// #pragma omp atomic read
806 /// In this example directive '#pragma omp atomic' has 'read' clause.
808 class OMPReadClause : public OMPClause {
810 /// \brief Build 'read' clause.
812 /// \param StartLoc Starting location of the clause.
813 /// \param EndLoc Ending location of the clause.
815 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
816 : OMPClause(OMPC_read, StartLoc, EndLoc) {}
818 /// \brief Build an empty clause.
820 OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
822 static bool classof(const OMPClause *T) {
823 return T->getClauseKind() == OMPC_read;
826 StmtRange children() { return StmtRange(); }
829 /// \brief This represents 'write' clause in the '#pragma omp atomic' directive.
832 /// #pragma omp atomic write
834 /// In this example directive '#pragma omp atomic' has 'write' clause.
836 class OMPWriteClause : public OMPClause {
838 /// \brief Build 'write' clause.
840 /// \param StartLoc Starting location of the clause.
841 /// \param EndLoc Ending location of the clause.
843 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
844 : OMPClause(OMPC_write, StartLoc, EndLoc) {}
846 /// \brief Build an empty clause.
849 : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
851 static bool classof(const OMPClause *T) {
852 return T->getClauseKind() == OMPC_write;
855 StmtRange children() { return StmtRange(); }
858 /// \brief This represents 'update' clause in the '#pragma omp atomic'
862 /// #pragma omp atomic update
864 /// In this example directive '#pragma omp atomic' has 'update' clause.
866 class OMPUpdateClause : public OMPClause {
868 /// \brief Build 'update' clause.
870 /// \param StartLoc Starting location of the clause.
871 /// \param EndLoc Ending location of the clause.
873 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
874 : OMPClause(OMPC_update, StartLoc, EndLoc) {}
876 /// \brief Build an empty clause.
879 : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
881 static bool classof(const OMPClause *T) {
882 return T->getClauseKind() == OMPC_update;
885 StmtRange children() { return StmtRange(); }
888 /// \brief This represents 'capture' clause in the '#pragma omp atomic'
892 /// #pragma omp atomic capture
894 /// In this example directive '#pragma omp atomic' has 'capture' clause.
896 class OMPCaptureClause : public OMPClause {
898 /// \brief Build 'capture' clause.
900 /// \param StartLoc Starting location of the clause.
901 /// \param EndLoc Ending location of the clause.
903 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
904 : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
906 /// \brief Build an empty clause.
909 : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
911 static bool classof(const OMPClause *T) {
912 return T->getClauseKind() == OMPC_capture;
915 StmtRange children() { return StmtRange(); }
918 /// \brief This represents 'seq_cst' clause in the '#pragma omp atomic'
922 /// #pragma omp atomic seq_cst
924 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
926 class OMPSeqCstClause : public OMPClause {
928 /// \brief Build 'seq_cst' clause.
930 /// \param StartLoc Starting location of the clause.
931 /// \param EndLoc Ending location of the clause.
933 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
934 : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
936 /// \brief Build an empty clause.
939 : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
941 static bool classof(const OMPClause *T) {
942 return T->getClauseKind() == OMPC_seq_cst;
945 StmtRange children() { return StmtRange(); }
948 /// \brief This represents clause 'private' in the '#pragma omp ...' directives.
951 /// #pragma omp parallel private(a,b)
953 /// In this example directive '#pragma omp parallel' has clause 'private'
954 /// with the variables 'a' and 'b'.
956 class OMPPrivateClause : public OMPVarListClause<OMPPrivateClause> {
957 friend class OMPClauseReader;
958 /// \brief Build clause with number of variables \a N.
960 /// \param StartLoc Starting location of the clause.
961 /// \param LParenLoc Location of '('.
962 /// \param EndLoc Ending location of the clause.
963 /// \param N Number of the variables in the clause.
965 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
966 SourceLocation EndLoc, unsigned N)
967 : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
970 /// \brief Build an empty clause.
972 /// \param N Number of variables.
974 explicit OMPPrivateClause(unsigned N)
975 : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
976 SourceLocation(), SourceLocation(),
979 /// \brief Sets the list of references to private copies with initializers for
980 /// new private variables.
981 /// \param VL List of references.
982 void setPrivateCopies(ArrayRef<Expr *> VL);
984 /// \brief Gets the list of references to private copies with initializers for
985 /// new private variables.
986 MutableArrayRef<Expr *> getPrivateCopies() {
987 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
989 ArrayRef<const Expr *> getPrivateCopies() const {
990 return llvm::makeArrayRef(varlist_end(), varlist_size());
994 /// \brief Creates clause with a list of variables \a VL.
996 /// \param C AST context.
997 /// \param StartLoc Starting location of the clause.
998 /// \param LParenLoc Location of '('.
999 /// \param EndLoc Ending location of the clause.
1000 /// \param VL List of references to the variables.
1001 /// \param PrivateVL List of references to private copies with initializers.
1003 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1004 SourceLocation LParenLoc,
1005 SourceLocation EndLoc, ArrayRef<Expr *> VL,
1006 ArrayRef<Expr *> PrivateVL);
1007 /// \brief Creates an empty clause with the place for \a N variables.
1009 /// \param C AST context.
1010 /// \param N The number of variables.
1012 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1014 typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
1015 typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
1016 typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
1017 typedef llvm::iterator_range<private_copies_const_iterator>
1018 private_copies_const_range;
1020 private_copies_range private_copies() {
1021 return private_copies_range(getPrivateCopies().begin(),
1022 getPrivateCopies().end());
1024 private_copies_const_range private_copies() const {
1025 return private_copies_const_range(getPrivateCopies().begin(),
1026 getPrivateCopies().end());
1029 StmtRange children() {
1030 return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1031 reinterpret_cast<Stmt **>(varlist_end()));
1034 static bool classof(const OMPClause *T) {
1035 return T->getClauseKind() == OMPC_private;
1039 /// \brief This represents clause 'firstprivate' in the '#pragma omp ...'
1043 /// #pragma omp parallel firstprivate(a,b)
1045 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1046 /// with the variables 'a' and 'b'.
1048 class OMPFirstprivateClause : public OMPVarListClause<OMPFirstprivateClause> {
1049 friend class OMPClauseReader;
1051 /// \brief Build clause with number of variables \a N.
1053 /// \param StartLoc Starting location of the clause.
1054 /// \param LParenLoc Location of '('.
1055 /// \param EndLoc Ending location of the clause.
1056 /// \param N Number of the variables in the clause.
1058 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1059 SourceLocation EndLoc, unsigned N)
1060 : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
1061 LParenLoc, EndLoc, N) {}
1063 /// \brief Build an empty clause.
1065 /// \param N Number of variables.
1067 explicit OMPFirstprivateClause(unsigned N)
1068 : OMPVarListClause<OMPFirstprivateClause>(
1069 OMPC_firstprivate, SourceLocation(), SourceLocation(),
1070 SourceLocation(), N) {}
1071 /// \brief Sets the list of references to private copies with initializers for
1072 /// new private variables.
1073 /// \param VL List of references.
1074 void setPrivateCopies(ArrayRef<Expr *> VL);
1076 /// \brief Gets the list of references to private copies with initializers for
1077 /// new private variables.
1078 MutableArrayRef<Expr *> getPrivateCopies() {
1079 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1081 ArrayRef<const Expr *> getPrivateCopies() const {
1082 return llvm::makeArrayRef(varlist_end(), varlist_size());
1085 /// \brief Sets the list of references to initializer variables for new
1086 /// private variables.
1087 /// \param VL List of references.
1088 void setInits(ArrayRef<Expr *> VL);
1090 /// \brief Gets the list of references to initializer variables for new
1091 /// private variables.
1092 MutableArrayRef<Expr *> getInits() {
1093 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1095 ArrayRef<const Expr *> getInits() const {
1096 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1100 /// \brief Creates clause with a list of variables \a VL.
1102 /// \param C AST context.
1103 /// \param StartLoc Starting location of the clause.
1104 /// \param LParenLoc Location of '('.
1105 /// \param EndLoc Ending location of the clause.
1106 /// \param VL List of references to the original variables.
1107 /// \param PrivateVL List of references to private copies with initializers.
1108 /// \param InitVL List of references to auto generated variables used for
1109 /// initialization of a single array element. Used if firstprivate variable is
1112 static OMPFirstprivateClause *
1113 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1114 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1115 ArrayRef<Expr *> InitVL);
1116 /// \brief Creates an empty clause with the place for \a N variables.
1118 /// \param C AST context.
1119 /// \param N The number of variables.
1121 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1123 typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
1124 typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
1125 typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
1126 typedef llvm::iterator_range<private_copies_const_iterator>
1127 private_copies_const_range;
1129 private_copies_range private_copies() {
1130 return private_copies_range(getPrivateCopies().begin(),
1131 getPrivateCopies().end());
1133 private_copies_const_range private_copies() const {
1134 return private_copies_const_range(getPrivateCopies().begin(),
1135 getPrivateCopies().end());
1138 typedef MutableArrayRef<Expr *>::iterator inits_iterator;
1139 typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
1140 typedef llvm::iterator_range<inits_iterator> inits_range;
1141 typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
1143 inits_range inits() {
1144 return inits_range(getInits().begin(), getInits().end());
1146 inits_const_range inits() const {
1147 return inits_const_range(getInits().begin(), getInits().end());
1150 StmtRange children() {
1151 return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1152 reinterpret_cast<Stmt **>(varlist_end()));
1155 static bool classof(const OMPClause *T) {
1156 return T->getClauseKind() == OMPC_firstprivate;
1160 /// \brief This represents clause 'lastprivate' in the '#pragma omp ...'
1164 /// #pragma omp simd lastprivate(a,b)
1166 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
1167 /// with the variables 'a' and 'b'.
1168 class OMPLastprivateClause : public OMPVarListClause<OMPLastprivateClause> {
1169 // There are 4 additional tail-allocated arrays at the end of the class:
1170 // 1. Contains list of pseudo variables with the default initialization for
1171 // each non-firstprivate variables. Used in codegen for initialization of
1172 // lastprivate copies.
1173 // 2. List of helper expressions for proper generation of assignment operation
1174 // required for lastprivate clause. This list represents private variables
1175 // (for arrays, single array element).
1176 // 3. List of helper expressions for proper generation of assignment operation
1177 // required for lastprivate clause. This list represents original variables
1178 // (for arrays, single array element).
1179 // 4. List of helper expressions that represents assignment operation:
1181 // DstExprs = SrcExprs;
1183 // Required for proper codegen of final assignment performed by the
1184 // lastprivate clause.
1186 friend class OMPClauseReader;
1188 /// \brief Build clause with number of variables \a N.
1190 /// \param StartLoc Starting location of the clause.
1191 /// \param LParenLoc Location of '('.
1192 /// \param EndLoc Ending location of the clause.
1193 /// \param N Number of the variables in the clause.
1195 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1196 SourceLocation EndLoc, unsigned N)
1197 : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
1198 LParenLoc, EndLoc, N) {}
1200 /// \brief Build an empty clause.
1202 /// \param N Number of variables.
1204 explicit OMPLastprivateClause(unsigned N)
1205 : OMPVarListClause<OMPLastprivateClause>(
1206 OMPC_lastprivate, SourceLocation(), SourceLocation(),
1207 SourceLocation(), N) {}
1209 /// \brief Get the list of helper expressions for initialization of private
1210 /// copies for lastprivate variables.
1211 MutableArrayRef<Expr *> getPrivateCopies() {
1212 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1214 ArrayRef<const Expr *> getPrivateCopies() const {
1215 return llvm::makeArrayRef(varlist_end(), varlist_size());
1218 /// \brief Set list of helper expressions, required for proper codegen of the
1219 /// clause. These expressions represent private variables (for arrays, single
1220 /// array element) in the final assignment statement performed by the
1221 /// lastprivate clause.
1222 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
1224 /// \brief Get the list of helper source expressions.
1225 MutableArrayRef<Expr *> getSourceExprs() {
1226 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1228 ArrayRef<const Expr *> getSourceExprs() const {
1229 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1232 /// \brief Set list of helper expressions, required for proper codegen of the
1233 /// clause. These expressions represent original variables (for arrays, single
1234 /// array element) in the final assignment statement performed by the
1235 /// lastprivate clause.
1236 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
1238 /// \brief Get the list of helper destination expressions.
1239 MutableArrayRef<Expr *> getDestinationExprs() {
1240 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
1242 ArrayRef<const Expr *> getDestinationExprs() const {
1243 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
1246 /// \brief Set list of helper assignment expressions, required for proper
1247 /// codegen of the clause. These expressions are assignment expressions that
1248 /// assign private copy of the variable to original variable.
1249 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
1251 /// \brief Get the list of helper assignment expressions.
1252 MutableArrayRef<Expr *> getAssignmentOps() {
1253 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
1255 ArrayRef<const Expr *> getAssignmentOps() const {
1256 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
1260 /// \brief Creates clause with a list of variables \a VL.
1262 /// \param C AST context.
1263 /// \param StartLoc Starting location of the clause.
1264 /// \param LParenLoc Location of '('.
1265 /// \param EndLoc Ending location of the clause.
1266 /// \param VL List of references to the variables.
1267 /// \param SrcExprs List of helper expressions for proper generation of
1268 /// assignment operation required for lastprivate clause. This list represents
1269 /// private variables (for arrays, single array element).
1270 /// \param DstExprs List of helper expressions for proper generation of
1271 /// assignment operation required for lastprivate clause. This list represents
1272 /// original variables (for arrays, single array element).
1273 /// \param AssignmentOps List of helper expressions that represents assignment
1276 /// DstExprs = SrcExprs;
1278 /// Required for proper codegen of final assignment performed by the
1279 /// lastprivate clause.
1282 static OMPLastprivateClause *
1283 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1284 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1285 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
1286 /// \brief Creates an empty clause with the place for \a N variables.
1288 /// \param C AST context.
1289 /// \param N The number of variables.
1291 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1293 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1294 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1295 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1296 typedef llvm::iterator_range<helper_expr_const_iterator>
1297 helper_expr_const_range;
1299 /// \brief Set list of helper expressions, required for generation of private
1300 /// copies of original lastprivate variables.
1301 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
1303 helper_expr_const_range private_copies() const {
1304 return helper_expr_const_range(getPrivateCopies().begin(),
1305 getPrivateCopies().end());
1307 helper_expr_range private_copies() {
1308 return helper_expr_range(getPrivateCopies().begin(),
1309 getPrivateCopies().end());
1311 helper_expr_const_range source_exprs() const {
1312 return helper_expr_const_range(getSourceExprs().begin(),
1313 getSourceExprs().end());
1315 helper_expr_range source_exprs() {
1316 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
1318 helper_expr_const_range destination_exprs() const {
1319 return helper_expr_const_range(getDestinationExprs().begin(),
1320 getDestinationExprs().end());
1322 helper_expr_range destination_exprs() {
1323 return helper_expr_range(getDestinationExprs().begin(),
1324 getDestinationExprs().end());
1326 helper_expr_const_range assignment_ops() const {
1327 return helper_expr_const_range(getAssignmentOps().begin(),
1328 getAssignmentOps().end());
1330 helper_expr_range assignment_ops() {
1331 return helper_expr_range(getAssignmentOps().begin(),
1332 getAssignmentOps().end());
1335 StmtRange children() {
1336 return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1337 reinterpret_cast<Stmt **>(varlist_end()));
1340 static bool classof(const OMPClause *T) {
1341 return T->getClauseKind() == OMPC_lastprivate;
1345 /// \brief This represents clause 'shared' in the '#pragma omp ...' directives.
1348 /// #pragma omp parallel shared(a,b)
1350 /// In this example directive '#pragma omp parallel' has clause 'shared'
1351 /// with the variables 'a' and 'b'.
1353 class OMPSharedClause : public OMPVarListClause<OMPSharedClause> {
1354 /// \brief Build clause with number of variables \a N.
1356 /// \param StartLoc Starting location of the clause.
1357 /// \param LParenLoc Location of '('.
1358 /// \param EndLoc Ending location of the clause.
1359 /// \param N Number of the variables in the clause.
1361 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1362 SourceLocation EndLoc, unsigned N)
1363 : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
1366 /// \brief Build an empty clause.
1368 /// \param N Number of variables.
1370 explicit OMPSharedClause(unsigned N)
1371 : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
1372 SourceLocation(), SourceLocation(),
1376 /// \brief Creates clause with a list of variables \a VL.
1378 /// \param C AST context.
1379 /// \param StartLoc Starting location of the clause.
1380 /// \param LParenLoc Location of '('.
1381 /// \param EndLoc Ending location of the clause.
1382 /// \param VL List of references to the variables.
1384 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1385 SourceLocation LParenLoc,
1386 SourceLocation EndLoc, ArrayRef<Expr *> VL);
1387 /// \brief Creates an empty clause with \a N variables.
1389 /// \param C AST context.
1390 /// \param N The number of variables.
1392 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
1394 StmtRange children() {
1395 return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1396 reinterpret_cast<Stmt **>(varlist_end()));
1399 static bool classof(const OMPClause *T) {
1400 return T->getClauseKind() == OMPC_shared;
1404 /// \brief This represents clause 'reduction' in the '#pragma omp ...'
1408 /// #pragma omp parallel reduction(+:a,b)
1410 /// In this example directive '#pragma omp parallel' has clause 'reduction'
1411 /// with operator '+' and the variables 'a' and 'b'.
1413 class OMPReductionClause : public OMPVarListClause<OMPReductionClause> {
1414 friend class OMPClauseReader;
1415 /// \brief Location of ':'.
1416 SourceLocation ColonLoc;
1417 /// \brief Nested name specifier for C++.
1418 NestedNameSpecifierLoc QualifierLoc;
1419 /// \brief Name of custom operator.
1420 DeclarationNameInfo NameInfo;
1422 /// \brief Build clause with number of variables \a N.
1424 /// \param StartLoc Starting location of the clause.
1425 /// \param LParenLoc Location of '('.
1426 /// \param EndLoc Ending location of the clause.
1427 /// \param ColonLoc Location of ':'.
1428 /// \param N Number of the variables in the clause.
1429 /// \param QualifierLoc The nested-name qualifier with location information
1430 /// \param NameInfo The full name info for reduction identifier.
1432 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1433 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
1434 NestedNameSpecifierLoc QualifierLoc,
1435 const DeclarationNameInfo &NameInfo)
1436 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
1437 LParenLoc, EndLoc, N),
1438 ColonLoc(ColonLoc), QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1440 /// \brief Build an empty clause.
1442 /// \param N Number of variables.
1444 explicit OMPReductionClause(unsigned N)
1445 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
1446 SourceLocation(), SourceLocation(),
1448 ColonLoc(), QualifierLoc(), NameInfo() {}
1450 /// \brief Sets location of ':' symbol in clause.
1451 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1452 /// \brief Sets the name info for specified reduction identifier.
1453 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1454 /// \brief Sets the nested name specifier.
1455 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1457 /// \brief Set list of helper expressions, required for proper codegen of the
1458 /// clause. These expressions represent LHS expression in the final
1459 /// reduction expression performed by the reduction clause.
1460 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
1462 /// \brief Get the list of helper LHS expressions.
1463 MutableArrayRef<Expr *> getLHSExprs() {
1464 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1466 ArrayRef<const Expr *> getLHSExprs() const {
1467 return llvm::makeArrayRef(varlist_end(), varlist_size());
1470 /// \brief Set list of helper expressions, required for proper codegen of the
1471 /// clause. These expressions represent RHS expression in the final
1472 /// reduction expression performed by the reduction clause.
1473 /// Also, variables in these expressions are used for proper initialization of
1474 /// reduction copies.
1475 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
1477 /// \brief Get the list of helper destination expressions.
1478 MutableArrayRef<Expr *> getRHSExprs() {
1479 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
1481 ArrayRef<const Expr *> getRHSExprs() const {
1482 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
1485 /// \brief Set list of helper reduction expressions, required for proper
1486 /// codegen of the clause. These expressions are binary expressions or
1487 /// operator/custom reduction call that calculates new value from source
1488 /// helper expressions to destination helper expressions.
1489 void setReductionOps(ArrayRef<Expr *> ReductionOps);
1491 /// \brief Get the list of helper reduction expressions.
1492 MutableArrayRef<Expr *> getReductionOps() {
1493 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
1495 ArrayRef<const Expr *> getReductionOps() const {
1496 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
1500 /// \brief Creates clause with a list of variables \a VL.
1502 /// \param StartLoc Starting location of the clause.
1503 /// \param LParenLoc Location of '('.
1504 /// \param ColonLoc Location of ':'.
1505 /// \param EndLoc Ending location of the clause.
1506 /// \param VL The variables in the clause.
1507 /// \param QualifierLoc The nested-name qualifier with location information
1508 /// \param NameInfo The full name info for reduction identifier.
1509 /// \param LHSExprs List of helper expressions for proper generation of
1510 /// assignment operation required for copyprivate clause. This list represents
1511 /// LHSs of the reduction expressions.
1512 /// \param RHSExprs List of helper expressions for proper generation of
1513 /// assignment operation required for copyprivate clause. This list represents
1514 /// RHSs of the reduction expressions.
1515 /// Also, variables in these expressions are used for proper initialization of
1516 /// reduction copies.
1517 /// \param ReductionOps List of helper expressions that represents reduction
1520 /// LHSExprs binop RHSExprs;
1521 /// operator binop(LHSExpr, RHSExpr);
1522 /// <CutomReduction>(LHSExpr, RHSExpr);
1524 /// Required for proper codegen of final reduction operation performed by the
1525 /// reduction clause.
1527 static OMPReductionClause *
1528 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1529 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1530 NestedNameSpecifierLoc QualifierLoc,
1531 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> LHSExprs,
1532 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps);
1533 /// \brief Creates an empty clause with the place for \a N variables.
1535 /// \param C AST context.
1536 /// \param N The number of variables.
1538 static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
1540 /// \brief Gets location of ':' symbol in clause.
1541 SourceLocation getColonLoc() const { return ColonLoc; }
1542 /// \brief Gets the name info for specified reduction identifier.
1543 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1544 /// \brief Gets the nested name specifier.
1545 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1547 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1548 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1549 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1550 typedef llvm::iterator_range<helper_expr_const_iterator>
1551 helper_expr_const_range;
1553 helper_expr_const_range lhs_exprs() const {
1554 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
1556 helper_expr_range lhs_exprs() {
1557 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
1559 helper_expr_const_range rhs_exprs() const {
1560 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
1562 helper_expr_range rhs_exprs() {
1563 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
1565 helper_expr_const_range reduction_ops() const {
1566 return helper_expr_const_range(getReductionOps().begin(),
1567 getReductionOps().end());
1569 helper_expr_range reduction_ops() {
1570 return helper_expr_range(getReductionOps().begin(),
1571 getReductionOps().end());
1574 StmtRange children() {
1575 return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1576 reinterpret_cast<Stmt **>(varlist_end()));
1579 static bool classof(const OMPClause *T) {
1580 return T->getClauseKind() == OMPC_reduction;
1584 /// \brief This represents clause 'linear' in the '#pragma omp ...'
1588 /// #pragma omp simd linear(a,b : 2)
1590 /// In this example directive '#pragma omp simd' has clause 'linear'
1591 /// with variables 'a', 'b' and linear step '2'.
1593 class OMPLinearClause : public OMPVarListClause<OMPLinearClause> {
1594 friend class OMPClauseReader;
1595 /// \brief Location of ':'.
1596 SourceLocation ColonLoc;
1598 /// \brief Sets the linear step for clause.
1599 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
1601 /// \brief Sets the expression to calculate linear step for clause.
1602 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
1604 /// \brief Build 'linear' clause with given number of variables \a NumVars.
1606 /// \param StartLoc Starting location of the clause.
1607 /// \param LParenLoc Location of '('.
1608 /// \param ColonLoc Location of ':'.
1609 /// \param EndLoc Ending location of the clause.
1610 /// \param NumVars Number of variables.
1612 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1613 SourceLocation ColonLoc, SourceLocation EndLoc,
1615 : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
1617 ColonLoc(ColonLoc) {}
1619 /// \brief Build an empty clause.
1621 /// \param NumVars Number of variables.
1623 explicit OMPLinearClause(unsigned NumVars)
1624 : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
1625 SourceLocation(), SourceLocation(),
1627 ColonLoc(SourceLocation()) {}
1629 /// \brief Gets the list of initial values for linear variables.
1631 /// There are NumVars expressions with initial values allocated after the
1632 /// varlist, they are followed by NumVars update expressions (used to update
1633 /// the linear variable's value on current iteration) and they are followed by
1634 /// NumVars final expressions (used to calculate the linear variable's
1635 /// value after the loop body). After these lists, there are 2 helper
1636 /// expressions - linear step and a helper to calculate it before the
1637 /// loop body (used when the linear step is not constant):
1639 /// { Vars[] /* in OMPVarListClause */; Inits[]; Updates[]; Finals[];
1640 /// Step; CalcStep; }
1642 MutableArrayRef<Expr *> getInits() {
1643 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1645 ArrayRef<const Expr *> getInits() const {
1646 return llvm::makeArrayRef(varlist_end(), varlist_size());
1649 /// \brief Sets the list of update expressions for linear variables.
1650 MutableArrayRef<Expr *> getUpdates() {
1651 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
1653 ArrayRef<const Expr *> getUpdates() const {
1654 return llvm::makeArrayRef(getInits().end(), varlist_size());
1657 /// \brief Sets the list of final update expressions for linear variables.
1658 MutableArrayRef<Expr *> getFinals() {
1659 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
1661 ArrayRef<const Expr *> getFinals() const {
1662 return llvm::makeArrayRef(getUpdates().end(), varlist_size());
1665 /// \brief Sets the list of the initial values for linear variables.
1666 /// \param IL List of expressions.
1667 void setInits(ArrayRef<Expr *> IL);
1670 /// \brief Creates clause with a list of variables \a VL and a linear step
1673 /// \param C AST Context.
1674 /// \param StartLoc Starting location of the clause.
1675 /// \param LParenLoc Location of '('.
1676 /// \param ColonLoc Location of ':'.
1677 /// \param EndLoc Ending location of the clause.
1678 /// \param VL List of references to the variables.
1679 /// \param IL List of initial values for the variables.
1680 /// \param Step Linear step.
1681 /// \param CalcStep Calculation of the linear step.
1682 static OMPLinearClause *Create(const ASTContext &C, SourceLocation StartLoc,
1683 SourceLocation LParenLoc,
1684 SourceLocation ColonLoc, SourceLocation EndLoc,
1685 ArrayRef<Expr *> VL, ArrayRef<Expr *> IL,
1686 Expr *Step, Expr *CalcStep);
1688 /// \brief Creates an empty clause with the place for \a NumVars variables.
1690 /// \param C AST context.
1691 /// \param NumVars Number of variables.
1693 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
1695 /// \brief Sets the location of ':'.
1696 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
1697 /// \brief Returns the location of '('.
1698 SourceLocation getColonLoc() const { return ColonLoc; }
1700 /// \brief Returns linear step.
1701 Expr *getStep() { return *(getFinals().end()); }
1702 /// \brief Returns linear step.
1703 const Expr *getStep() const { return *(getFinals().end()); }
1704 /// \brief Returns expression to calculate linear step.
1705 Expr *getCalcStep() { return *(getFinals().end() + 1); }
1706 /// \brief Returns expression to calculate linear step.
1707 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
1709 /// \brief Sets the list of update expressions for linear variables.
1710 /// \param UL List of expressions.
1711 void setUpdates(ArrayRef<Expr *> UL);
1713 /// \brief Sets the list of final update expressions for linear variables.
1714 /// \param FL List of expressions.
1715 void setFinals(ArrayRef<Expr *> FL);
1717 typedef MutableArrayRef<Expr *>::iterator inits_iterator;
1718 typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
1719 typedef llvm::iterator_range<inits_iterator> inits_range;
1720 typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
1722 inits_range inits() {
1723 return inits_range(getInits().begin(), getInits().end());
1725 inits_const_range inits() const {
1726 return inits_const_range(getInits().begin(), getInits().end());
1729 typedef MutableArrayRef<Expr *>::iterator updates_iterator;
1730 typedef ArrayRef<const Expr *>::iterator updates_const_iterator;
1731 typedef llvm::iterator_range<updates_iterator> updates_range;
1732 typedef llvm::iterator_range<updates_const_iterator> updates_const_range;
1734 updates_range updates() {
1735 return updates_range(getUpdates().begin(), getUpdates().end());
1737 updates_const_range updates() const {
1738 return updates_const_range(getUpdates().begin(), getUpdates().end());
1741 typedef MutableArrayRef<Expr *>::iterator finals_iterator;
1742 typedef ArrayRef<const Expr *>::iterator finals_const_iterator;
1743 typedef llvm::iterator_range<finals_iterator> finals_range;
1744 typedef llvm::iterator_range<finals_const_iterator> finals_const_range;
1746 finals_range finals() {
1747 return finals_range(getFinals().begin(), getFinals().end());
1749 finals_const_range finals() const {
1750 return finals_const_range(getFinals().begin(), getFinals().end());
1753 StmtRange children() {
1754 return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1755 reinterpret_cast<Stmt **>(varlist_end()));
1758 static bool classof(const OMPClause *T) {
1759 return T->getClauseKind() == OMPC_linear;
1763 /// \brief This represents clause 'aligned' in the '#pragma omp ...'
1767 /// #pragma omp simd aligned(a,b : 8)
1769 /// In this example directive '#pragma omp simd' has clause 'aligned'
1770 /// with variables 'a', 'b' and alignment '8'.
1772 class OMPAlignedClause : public OMPVarListClause<OMPAlignedClause> {
1773 friend class OMPClauseReader;
1774 /// \brief Location of ':'.
1775 SourceLocation ColonLoc;
1777 /// \brief Sets the alignment for clause.
1778 void setAlignment(Expr *A) { *varlist_end() = A; }
1780 /// \brief Build 'aligned' clause with given number of variables \a NumVars.
1782 /// \param StartLoc Starting location of the clause.
1783 /// \param LParenLoc Location of '('.
1784 /// \param ColonLoc Location of ':'.
1785 /// \param EndLoc Ending location of the clause.
1786 /// \param NumVars Number of variables.
1788 OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1789 SourceLocation ColonLoc, SourceLocation EndLoc,
1791 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
1793 ColonLoc(ColonLoc) {}
1795 /// \brief Build an empty clause.
1797 /// \param NumVars Number of variables.
1799 explicit OMPAlignedClause(unsigned NumVars)
1800 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
1801 SourceLocation(), SourceLocation(),
1803 ColonLoc(SourceLocation()) {}
1806 /// \brief Creates clause with a list of variables \a VL and alignment \a A.
1808 /// \param C AST Context.
1809 /// \param StartLoc Starting location of the clause.
1810 /// \param LParenLoc Location of '('.
1811 /// \param ColonLoc Location of ':'.
1812 /// \param EndLoc Ending location of the clause.
1813 /// \param VL List of references to the variables.
1814 /// \param A Alignment.
1815 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1816 SourceLocation LParenLoc,
1817 SourceLocation ColonLoc,
1818 SourceLocation EndLoc, ArrayRef<Expr *> VL,
1821 /// \brief Creates an empty clause with the place for \a NumVars variables.
1823 /// \param C AST context.
1824 /// \param NumVars Number of variables.
1826 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
1828 /// \brief Sets the location of ':'.
1829 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
1830 /// \brief Returns the location of ':'.
1831 SourceLocation getColonLoc() const { return ColonLoc; }
1833 /// \brief Returns alignment.
1834 Expr *getAlignment() { return *varlist_end(); }
1835 /// \brief Returns alignment.
1836 const Expr *getAlignment() const { return *varlist_end(); }
1838 StmtRange children() {
1839 return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1840 reinterpret_cast<Stmt **>(varlist_end()));
1843 static bool classof(const OMPClause *T) {
1844 return T->getClauseKind() == OMPC_aligned;
1848 /// \brief This represents clause 'copyin' in the '#pragma omp ...' directives.
1851 /// #pragma omp parallel copyin(a,b)
1853 /// In this example directive '#pragma omp parallel' has clause 'copyin'
1854 /// with the variables 'a' and 'b'.
1856 class OMPCopyinClause : public OMPVarListClause<OMPCopyinClause> {
1857 // Class has 3 additional tail allocated arrays:
1858 // 1. List of helper expressions for proper generation of assignment operation
1859 // required for copyin clause. This list represents sources.
1860 // 2. List of helper expressions for proper generation of assignment operation
1861 // required for copyin clause. This list represents destinations.
1862 // 3. List of helper expressions that represents assignment operation:
1864 // DstExprs = SrcExprs;
1866 // Required for proper codegen of propagation of master's thread values of
1867 // threadprivate variables to local instances of that variables in other
1868 // implicit threads.
1870 friend class OMPClauseReader;
1871 /// \brief Build clause with number of variables \a N.
1873 /// \param StartLoc Starting location of the clause.
1874 /// \param LParenLoc Location of '('.
1875 /// \param EndLoc Ending location of the clause.
1876 /// \param N Number of the variables in the clause.
1878 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1879 SourceLocation EndLoc, unsigned N)
1880 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
1883 /// \brief Build an empty clause.
1885 /// \param N Number of variables.
1887 explicit OMPCopyinClause(unsigned N)
1888 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
1889 SourceLocation(), SourceLocation(),
1892 /// \brief Set list of helper expressions, required for proper codegen of the
1893 /// clause. These expressions represent source expression in the final
1894 /// assignment statement performed by the copyin clause.
1895 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
1897 /// \brief Get the list of helper source expressions.
1898 MutableArrayRef<Expr *> getSourceExprs() {
1899 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1901 ArrayRef<const Expr *> getSourceExprs() const {
1902 return llvm::makeArrayRef(varlist_end(), varlist_size());
1905 /// \brief Set list of helper expressions, required for proper codegen of the
1906 /// clause. These expressions represent destination expression in the final
1907 /// assignment statement performed by the copyin clause.
1908 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
1910 /// \brief Get the list of helper destination expressions.
1911 MutableArrayRef<Expr *> getDestinationExprs() {
1912 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
1914 ArrayRef<const Expr *> getDestinationExprs() const {
1915 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
1918 /// \brief Set list of helper assignment expressions, required for proper
1919 /// codegen of the clause. These expressions are assignment expressions that
1920 /// assign source helper expressions to destination helper expressions
1921 /// correspondingly.
1922 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
1924 /// \brief Get the list of helper assignment expressions.
1925 MutableArrayRef<Expr *> getAssignmentOps() {
1926 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
1928 ArrayRef<const Expr *> getAssignmentOps() const {
1929 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
1933 /// \brief Creates clause with a list of variables \a VL.
1935 /// \param C AST context.
1936 /// \param StartLoc Starting location of the clause.
1937 /// \param LParenLoc Location of '('.
1938 /// \param EndLoc Ending location of the clause.
1939 /// \param VL List of references to the variables.
1940 /// \param SrcExprs List of helper expressions for proper generation of
1941 /// assignment operation required for copyin clause. This list represents
1943 /// \param DstExprs List of helper expressions for proper generation of
1944 /// assignment operation required for copyin clause. This list represents
1946 /// \param AssignmentOps List of helper expressions that represents assignment
1949 /// DstExprs = SrcExprs;
1951 /// Required for proper codegen of propagation of master's thread values of
1952 /// threadprivate variables to local instances of that variables in other
1953 /// implicit threads.
1955 static OMPCopyinClause *
1956 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1957 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1958 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
1959 /// \brief Creates an empty clause with \a N variables.
1961 /// \param C AST context.
1962 /// \param N The number of variables.
1964 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
1966 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1967 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1968 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1969 typedef llvm::iterator_range<helper_expr_const_iterator>
1970 helper_expr_const_range;
1972 helper_expr_const_range source_exprs() const {
1973 return helper_expr_const_range(getSourceExprs().begin(),
1974 getSourceExprs().end());
1976 helper_expr_range source_exprs() {
1977 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
1979 helper_expr_const_range destination_exprs() const {
1980 return helper_expr_const_range(getDestinationExprs().begin(),
1981 getDestinationExprs().end());
1983 helper_expr_range destination_exprs() {
1984 return helper_expr_range(getDestinationExprs().begin(),
1985 getDestinationExprs().end());
1987 helper_expr_const_range assignment_ops() const {
1988 return helper_expr_const_range(getAssignmentOps().begin(),
1989 getAssignmentOps().end());
1991 helper_expr_range assignment_ops() {
1992 return helper_expr_range(getAssignmentOps().begin(),
1993 getAssignmentOps().end());
1996 StmtRange children() {
1997 return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1998 reinterpret_cast<Stmt **>(varlist_end()));
2001 static bool classof(const OMPClause *T) {
2002 return T->getClauseKind() == OMPC_copyin;
2006 /// \brief This represents clause 'copyprivate' in the '#pragma omp ...'
2010 /// #pragma omp single copyprivate(a,b)
2012 /// In this example directive '#pragma omp single' has clause 'copyprivate'
2013 /// with the variables 'a' and 'b'.
2015 class OMPCopyprivateClause : public OMPVarListClause<OMPCopyprivateClause> {
2016 friend class OMPClauseReader;
2017 /// \brief Build clause with number of variables \a N.
2019 /// \param StartLoc Starting location of the clause.
2020 /// \param LParenLoc Location of '('.
2021 /// \param EndLoc Ending location of the clause.
2022 /// \param N Number of the variables in the clause.
2024 OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2025 SourceLocation EndLoc, unsigned N)
2026 : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
2027 LParenLoc, EndLoc, N) {}
2029 /// \brief Build an empty clause.
2031 /// \param N Number of variables.
2033 explicit OMPCopyprivateClause(unsigned N)
2034 : OMPVarListClause<OMPCopyprivateClause>(
2035 OMPC_copyprivate, SourceLocation(), SourceLocation(),
2036 SourceLocation(), N) {}
2038 /// \brief Set list of helper expressions, required for proper codegen of the
2039 /// clause. These expressions represent source expression in the final
2040 /// assignment statement performed by the copyprivate clause.
2041 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2043 /// \brief Get the list of helper source expressions.
2044 MutableArrayRef<Expr *> getSourceExprs() {
2045 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2047 ArrayRef<const Expr *> getSourceExprs() const {
2048 return llvm::makeArrayRef(varlist_end(), varlist_size());
2051 /// \brief Set list of helper expressions, required for proper codegen of the
2052 /// clause. These expressions represent destination expression in the final
2053 /// assignment statement performed by the copyprivate clause.
2054 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2056 /// \brief Get the list of helper destination expressions.
2057 MutableArrayRef<Expr *> getDestinationExprs() {
2058 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2060 ArrayRef<const Expr *> getDestinationExprs() const {
2061 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2064 /// \brief Set list of helper assignment expressions, required for proper
2065 /// codegen of the clause. These expressions are assignment expressions that
2066 /// assign source helper expressions to destination helper expressions
2067 /// correspondingly.
2068 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2070 /// \brief Get the list of helper assignment expressions.
2071 MutableArrayRef<Expr *> getAssignmentOps() {
2072 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2074 ArrayRef<const Expr *> getAssignmentOps() const {
2075 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2079 /// \brief Creates clause with a list of variables \a VL.
2081 /// \param C AST context.
2082 /// \param StartLoc Starting location of the clause.
2083 /// \param LParenLoc Location of '('.
2084 /// \param EndLoc Ending location of the clause.
2085 /// \param VL List of references to the variables.
2086 /// \param SrcExprs List of helper expressions for proper generation of
2087 /// assignment operation required for copyprivate clause. This list represents
2089 /// \param DstExprs List of helper expressions for proper generation of
2090 /// assignment operation required for copyprivate clause. This list represents
2092 /// \param AssignmentOps List of helper expressions that represents assignment
2095 /// DstExprs = SrcExprs;
2097 /// Required for proper codegen of final assignment performed by the
2098 /// copyprivate clause.
2100 static OMPCopyprivateClause *
2101 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2102 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2103 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2104 /// \brief Creates an empty clause with \a N variables.
2106 /// \param C AST context.
2107 /// \param N The number of variables.
2109 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2111 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
2112 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
2113 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
2114 typedef llvm::iterator_range<helper_expr_const_iterator>
2115 helper_expr_const_range;
2117 helper_expr_const_range source_exprs() const {
2118 return helper_expr_const_range(getSourceExprs().begin(),
2119 getSourceExprs().end());
2121 helper_expr_range source_exprs() {
2122 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2124 helper_expr_const_range destination_exprs() const {
2125 return helper_expr_const_range(getDestinationExprs().begin(),
2126 getDestinationExprs().end());
2128 helper_expr_range destination_exprs() {
2129 return helper_expr_range(getDestinationExprs().begin(),
2130 getDestinationExprs().end());
2132 helper_expr_const_range assignment_ops() const {
2133 return helper_expr_const_range(getAssignmentOps().begin(),
2134 getAssignmentOps().end());
2136 helper_expr_range assignment_ops() {
2137 return helper_expr_range(getAssignmentOps().begin(),
2138 getAssignmentOps().end());
2141 StmtRange children() {
2142 return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
2143 reinterpret_cast<Stmt **>(varlist_end()));
2146 static bool classof(const OMPClause *T) {
2147 return T->getClauseKind() == OMPC_copyprivate;
2151 /// \brief This represents implicit clause 'flush' for the '#pragma omp flush'
2153 /// This clause does not exist by itself, it can be only as a part of 'omp
2154 /// flush' directive. This clause is introduced to keep the original structure
2155 /// of \a OMPExecutableDirective class and its derivatives and to use the
2156 /// existing infrastructure of clauses with the list of variables.
2159 /// #pragma omp flush(a,b)
2161 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
2162 /// with the variables 'a' and 'b'.
2164 class OMPFlushClause : public OMPVarListClause<OMPFlushClause> {
2165 /// \brief Build clause with number of variables \a N.
2167 /// \param StartLoc Starting location of the clause.
2168 /// \param LParenLoc Location of '('.
2169 /// \param EndLoc Ending location of the clause.
2170 /// \param N Number of the variables in the clause.
2172 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2173 SourceLocation EndLoc, unsigned N)
2174 : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
2177 /// \brief Build an empty clause.
2179 /// \param N Number of variables.
2181 explicit OMPFlushClause(unsigned N)
2182 : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
2183 SourceLocation(), SourceLocation(),
2187 /// \brief Creates clause with a list of variables \a VL.
2189 /// \param C AST context.
2190 /// \param StartLoc Starting location of the clause.
2191 /// \param LParenLoc Location of '('.
2192 /// \param EndLoc Ending location of the clause.
2193 /// \param VL List of references to the variables.
2195 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
2196 SourceLocation LParenLoc, SourceLocation EndLoc,
2197 ArrayRef<Expr *> VL);
2198 /// \brief Creates an empty clause with \a N variables.
2200 /// \param C AST context.
2201 /// \param N The number of variables.
2203 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
2205 StmtRange children() {
2206 return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
2207 reinterpret_cast<Stmt **>(varlist_end()));
2210 static bool classof(const OMPClause *T) {
2211 return T->getClauseKind() == OMPC_flush;
2215 } // end namespace clang