clang  9.0.0
OpenMPClause.cpp
Go to the documentation of this file.
1 //===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===//
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 // This file implements the subclesses of Stmt class declared in OpenMPClause.h
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/AST/OpenMPClause.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Decl.h"
16 #include "clang/AST/DeclOpenMP.h"
17 #include "clang/Basic/LLVM.h"
18 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/Support/Casting.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include <algorithm>
22 #include <cassert>
23 
24 using namespace clang;
25 
27  switch (getClauseKind()) {
28  default:
29  break;
30 #define OPENMP_CLAUSE(Name, Class) \
31  case OMPC_##Name: \
32  return static_cast<Class *>(this)->children();
33 #include "clang/Basic/OpenMPKinds.def"
34  }
35  llvm_unreachable("unknown OMPClause");
36 }
37 
39  switch (getClauseKind()) {
40 #define OPENMP_CLAUSE(Name, Class) \
41  case OMPC_##Name: \
42  return static_cast<Class *>(this)->used_children();
43 #include "clang/Basic/OpenMPKinds.def"
44  case OMPC_threadprivate:
45  case OMPC_uniform:
46  case OMPC_unknown:
47  break;
48  }
49  llvm_unreachable("unknown OMPClause");
50 }
51 
53  auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
54  return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
55 }
56 
58  switch (C->getClauseKind()) {
59  case OMPC_schedule:
60  return static_cast<const OMPScheduleClause *>(C);
61  case OMPC_dist_schedule:
62  return static_cast<const OMPDistScheduleClause *>(C);
63  case OMPC_firstprivate:
64  return static_cast<const OMPFirstprivateClause *>(C);
65  case OMPC_lastprivate:
66  return static_cast<const OMPLastprivateClause *>(C);
67  case OMPC_reduction:
68  return static_cast<const OMPReductionClause *>(C);
69  case OMPC_task_reduction:
70  return static_cast<const OMPTaskReductionClause *>(C);
71  case OMPC_in_reduction:
72  return static_cast<const OMPInReductionClause *>(C);
73  case OMPC_linear:
74  return static_cast<const OMPLinearClause *>(C);
75  case OMPC_if:
76  return static_cast<const OMPIfClause *>(C);
77  case OMPC_num_threads:
78  return static_cast<const OMPNumThreadsClause *>(C);
79  case OMPC_num_teams:
80  return static_cast<const OMPNumTeamsClause *>(C);
81  case OMPC_thread_limit:
82  return static_cast<const OMPThreadLimitClause *>(C);
83  case OMPC_device:
84  return static_cast<const OMPDeviceClause *>(C);
85  case OMPC_default:
86  case OMPC_proc_bind:
87  case OMPC_final:
88  case OMPC_safelen:
89  case OMPC_simdlen:
90  case OMPC_allocator:
91  case OMPC_allocate:
92  case OMPC_collapse:
93  case OMPC_private:
94  case OMPC_shared:
95  case OMPC_aligned:
96  case OMPC_copyin:
97  case OMPC_copyprivate:
98  case OMPC_ordered:
99  case OMPC_nowait:
100  case OMPC_untied:
101  case OMPC_mergeable:
102  case OMPC_threadprivate:
103  case OMPC_flush:
104  case OMPC_read:
105  case OMPC_write:
106  case OMPC_update:
107  case OMPC_capture:
108  case OMPC_seq_cst:
109  case OMPC_depend:
110  case OMPC_threads:
111  case OMPC_simd:
112  case OMPC_map:
113  case OMPC_priority:
114  case OMPC_grainsize:
115  case OMPC_nogroup:
116  case OMPC_num_tasks:
117  case OMPC_hint:
118  case OMPC_defaultmap:
119  case OMPC_unknown:
120  case OMPC_uniform:
121  case OMPC_to:
122  case OMPC_from:
123  case OMPC_use_device_ptr:
124  case OMPC_is_device_ptr:
125  case OMPC_unified_address:
126  case OMPC_unified_shared_memory:
127  case OMPC_reverse_offload:
128  case OMPC_dynamic_allocators:
129  case OMPC_atomic_default_mem_order:
130  break;
131  }
132 
133  return nullptr;
134 }
135 
137  auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
138  return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
139 }
140 
142  switch (C->getClauseKind()) {
143  case OMPC_lastprivate:
144  return static_cast<const OMPLastprivateClause *>(C);
145  case OMPC_reduction:
146  return static_cast<const OMPReductionClause *>(C);
147  case OMPC_task_reduction:
148  return static_cast<const OMPTaskReductionClause *>(C);
149  case OMPC_in_reduction:
150  return static_cast<const OMPInReductionClause *>(C);
151  case OMPC_linear:
152  return static_cast<const OMPLinearClause *>(C);
153  case OMPC_schedule:
154  case OMPC_dist_schedule:
155  case OMPC_firstprivate:
156  case OMPC_default:
157  case OMPC_proc_bind:
158  case OMPC_if:
159  case OMPC_final:
160  case OMPC_num_threads:
161  case OMPC_safelen:
162  case OMPC_simdlen:
163  case OMPC_allocator:
164  case OMPC_allocate:
165  case OMPC_collapse:
166  case OMPC_private:
167  case OMPC_shared:
168  case OMPC_aligned:
169  case OMPC_copyin:
170  case OMPC_copyprivate:
171  case OMPC_ordered:
172  case OMPC_nowait:
173  case OMPC_untied:
174  case OMPC_mergeable:
175  case OMPC_threadprivate:
176  case OMPC_flush:
177  case OMPC_read:
178  case OMPC_write:
179  case OMPC_update:
180  case OMPC_capture:
181  case OMPC_seq_cst:
182  case OMPC_depend:
183  case OMPC_device:
184  case OMPC_threads:
185  case OMPC_simd:
186  case OMPC_map:
187  case OMPC_num_teams:
188  case OMPC_thread_limit:
189  case OMPC_priority:
190  case OMPC_grainsize:
191  case OMPC_nogroup:
192  case OMPC_num_tasks:
193  case OMPC_hint:
194  case OMPC_defaultmap:
195  case OMPC_unknown:
196  case OMPC_uniform:
197  case OMPC_to:
198  case OMPC_from:
199  case OMPC_use_device_ptr:
200  case OMPC_is_device_ptr:
201  case OMPC_unified_address:
202  case OMPC_unified_shared_memory:
203  case OMPC_reverse_offload:
204  case OMPC_dynamic_allocators:
205  case OMPC_atomic_default_mem_order:
206  break;
207  }
208 
209  return nullptr;
210 }
211 
212 /// Gets the address of the original, non-captured, expression used in the
213 /// clause as the preinitializer.
215  if (!S)
216  return nullptr;
217  if (auto *DS = dyn_cast<DeclStmt>(S)) {
218  assert(DS->isSingleDecl() && "Only single expression must be captured.");
219  if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
220  return OED->getInitAddress();
221  }
222  return nullptr;
223 }
224 
226  if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
227  return child_range(C, C + 1);
228  return child_range(&Condition, &Condition + 1);
229 }
230 
232  unsigned NumLoops,
233  SourceLocation StartLoc,
234  SourceLocation LParenLoc,
235  SourceLocation EndLoc) {
236  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
237  auto *Clause =
238  new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
239  for (unsigned I = 0; I < NumLoops; ++I) {
240  Clause->setLoopNumIterations(I, nullptr);
241  Clause->setLoopCounter(I, nullptr);
242  }
243  return Clause;
244 }
245 
247  unsigned NumLoops) {
248  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
249  auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
250  for (unsigned I = 0; I < NumLoops; ++I) {
251  Clause->setLoopNumIterations(I, nullptr);
252  Clause->setLoopCounter(I, nullptr);
253  }
254  return Clause;
255 }
256 
258  Expr *NumIterations) {
259  assert(NumLoop < NumberOfLoops && "out of loops number.");
260  getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
261 }
262 
264  return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
265 }
266 
267 void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
268  assert(NumLoop < NumberOfLoops && "out of loops number.");
269  getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
270 }
271 
273  assert(NumLoop < NumberOfLoops && "out of loops number.");
274  return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
275 }
276 
277 const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
278  assert(NumLoop < NumberOfLoops && "out of loops number.");
279  return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
280 }
281 
282 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
283  assert(VL.size() == varlist_size() &&
284  "Number of private copies is not the same as the preallocated buffer");
285  std::copy(VL.begin(), VL.end(), varlist_end());
286 }
287 
290  SourceLocation LParenLoc, SourceLocation EndLoc,
291  ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
292  // Allocate space for private variables and initializer expressions.
293  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
294  OMPPrivateClause *Clause =
295  new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
296  Clause->setVarRefs(VL);
297  Clause->setPrivateCopies(PrivateVL);
298  return Clause;
299 }
300 
302  unsigned N) {
303  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
304  return new (Mem) OMPPrivateClause(N);
305 }
306 
307 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
308  assert(VL.size() == varlist_size() &&
309  "Number of private copies is not the same as the preallocated buffer");
310  std::copy(VL.begin(), VL.end(), varlist_end());
311 }
312 
313 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
314  assert(VL.size() == varlist_size() &&
315  "Number of inits is not the same as the preallocated buffer");
316  std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
317 }
318 
321  SourceLocation LParenLoc, SourceLocation EndLoc,
322  ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
323  ArrayRef<Expr *> InitVL, Stmt *PreInit) {
324  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
325  OMPFirstprivateClause *Clause =
326  new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
327  Clause->setVarRefs(VL);
328  Clause->setPrivateCopies(PrivateVL);
329  Clause->setInits(InitVL);
330  Clause->setPreInitStmt(PreInit);
331  return Clause;
332 }
333 
335  unsigned N) {
336  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
337  return new (Mem) OMPFirstprivateClause(N);
338 }
339 
341  assert(PrivateCopies.size() == varlist_size() &&
342  "Number of private copies is not the same as the preallocated buffer");
343  std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
344 }
345 
346 void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
347  assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
348  "not the same as the "
349  "preallocated buffer");
350  std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
351 }
352 
353 void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
354  assert(DstExprs.size() == varlist_size() && "Number of destination "
355  "expressions is not the same as "
356  "the preallocated buffer");
357  std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
358 }
359 
360 void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
361  assert(AssignmentOps.size() == varlist_size() &&
362  "Number of assignment expressions is not the same as the preallocated "
363  "buffer");
364  std::copy(AssignmentOps.begin(), AssignmentOps.end(),
365  getDestinationExprs().end());
366 }
367 
369  const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
370  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
371  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
372  Expr *PostUpdate) {
373  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
374  OMPLastprivateClause *Clause =
375  new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
376  Clause->setVarRefs(VL);
377  Clause->setSourceExprs(SrcExprs);
378  Clause->setDestinationExprs(DstExprs);
379  Clause->setAssignmentOps(AssignmentOps);
380  Clause->setPreInitStmt(PreInit);
381  Clause->setPostUpdateExpr(PostUpdate);
382  return Clause;
383 }
384 
386  unsigned N) {
387  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
388  return new (Mem) OMPLastprivateClause(N);
389 }
390 
392  SourceLocation StartLoc,
393  SourceLocation LParenLoc,
394  SourceLocation EndLoc,
395  ArrayRef<Expr *> VL) {
396  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
397  OMPSharedClause *Clause =
398  new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
399  Clause->setVarRefs(VL);
400  return Clause;
401 }
402 
404  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
405  return new (Mem) OMPSharedClause(N);
406 }
407 
409  assert(PL.size() == varlist_size() &&
410  "Number of privates is not the same as the preallocated buffer");
411  std::copy(PL.begin(), PL.end(), varlist_end());
412 }
413 
415  assert(IL.size() == varlist_size() &&
416  "Number of inits is not the same as the preallocated buffer");
417  std::copy(IL.begin(), IL.end(), getPrivates().end());
418 }
419 
421  assert(UL.size() == varlist_size() &&
422  "Number of updates is not the same as the preallocated buffer");
423  std::copy(UL.begin(), UL.end(), getInits().end());
424 }
425 
427  assert(FL.size() == varlist_size() &&
428  "Number of final updates is not the same as the preallocated buffer");
429  std::copy(FL.begin(), FL.end(), getUpdates().end());
430 }
431 
433  const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
437  Stmt *PreInit, Expr *PostUpdate) {
438  // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
439  // (Step and CalcStep).
440  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
441  OMPLinearClause *Clause = new (Mem) OMPLinearClause(
442  StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
443  Clause->setVarRefs(VL);
444  Clause->setPrivates(PL);
445  Clause->setInits(IL);
446  // Fill update and final expressions with zeroes, they are provided later,
447  // after the directive construction.
448  std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
449  nullptr);
450  std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
451  nullptr);
452  Clause->setStep(Step);
453  Clause->setCalcStep(CalcStep);
454  Clause->setPreInitStmt(PreInit);
455  Clause->setPostUpdateExpr(PostUpdate);
456  return Clause;
457 }
458 
460  unsigned NumVars) {
461  // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
462  // (Step and CalcStep).
463  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
464  return new (Mem) OMPLinearClause(NumVars);
465 }
466 
469  SourceLocation LParenLoc, SourceLocation ColonLoc,
470  SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
471  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
472  OMPAlignedClause *Clause = new (Mem)
473  OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
474  Clause->setVarRefs(VL);
475  Clause->setAlignment(A);
476  return Clause;
477 }
478 
480  unsigned NumVars) {
481  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
482  return new (Mem) OMPAlignedClause(NumVars);
483 }
484 
485 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
486  assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
487  "not the same as the "
488  "preallocated buffer");
489  std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
490 }
491 
492 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
493  assert(DstExprs.size() == varlist_size() && "Number of destination "
494  "expressions is not the same as "
495  "the preallocated buffer");
496  std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
497 }
498 
499 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
500  assert(AssignmentOps.size() == varlist_size() &&
501  "Number of assignment expressions is not the same as the preallocated "
502  "buffer");
503  std::copy(AssignmentOps.begin(), AssignmentOps.end(),
504  getDestinationExprs().end());
505 }
506 
508  const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
509  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
510  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
511  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
512  OMPCopyinClause *Clause =
513  new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
514  Clause->setVarRefs(VL);
515  Clause->setSourceExprs(SrcExprs);
516  Clause->setDestinationExprs(DstExprs);
517  Clause->setAssignmentOps(AssignmentOps);
518  return Clause;
519 }
520 
522  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
523  return new (Mem) OMPCopyinClause(N);
524 }
525 
526 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
527  assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
528  "not the same as the "
529  "preallocated buffer");
530  std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
531 }
532 
533 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
534  assert(DstExprs.size() == varlist_size() && "Number of destination "
535  "expressions is not the same as "
536  "the preallocated buffer");
537  std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
538 }
539 
540 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
541  assert(AssignmentOps.size() == varlist_size() &&
542  "Number of assignment expressions is not the same as the preallocated "
543  "buffer");
544  std::copy(AssignmentOps.begin(), AssignmentOps.end(),
545  getDestinationExprs().end());
546 }
547 
549  const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
550  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
551  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
552  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
553  OMPCopyprivateClause *Clause =
554  new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
555  Clause->setVarRefs(VL);
556  Clause->setSourceExprs(SrcExprs);
557  Clause->setDestinationExprs(DstExprs);
558  Clause->setAssignmentOps(AssignmentOps);
559  return Clause;
560 }
561 
563  unsigned N) {
564  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
565  return new (Mem) OMPCopyprivateClause(N);
566 }
567 
568 void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
569  assert(Privates.size() == varlist_size() &&
570  "Number of private copies is not the same as the preallocated buffer");
571  std::copy(Privates.begin(), Privates.end(), varlist_end());
572 }
573 
574 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
575  assert(
576  LHSExprs.size() == varlist_size() &&
577  "Number of LHS expressions is not the same as the preallocated buffer");
578  std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
579 }
580 
581 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
582  assert(
583  RHSExprs.size() == varlist_size() &&
584  "Number of RHS expressions is not the same as the preallocated buffer");
585  std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
586 }
587 
588 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
589  assert(ReductionOps.size() == varlist_size() && "Number of reduction "
590  "expressions is not the same "
591  "as the preallocated buffer");
592  std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
593 }
594 
596  const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
597  SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
598  NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
600  ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
601  Expr *PostUpdate) {
602  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
603  OMPReductionClause *Clause = new (Mem) OMPReductionClause(
604  StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
605  Clause->setVarRefs(VL);
606  Clause->setPrivates(Privates);
607  Clause->setLHSExprs(LHSExprs);
608  Clause->setRHSExprs(RHSExprs);
609  Clause->setReductionOps(ReductionOps);
610  Clause->setPreInitStmt(PreInit);
611  Clause->setPostUpdateExpr(PostUpdate);
612  return Clause;
613 }
614 
616  unsigned N) {
617  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
618  return new (Mem) OMPReductionClause(N);
619 }
620 
621 void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
622  assert(Privates.size() == varlist_size() &&
623  "Number of private copies is not the same as the preallocated buffer");
624  std::copy(Privates.begin(), Privates.end(), varlist_end());
625 }
626 
627 void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
628  assert(
629  LHSExprs.size() == varlist_size() &&
630  "Number of LHS expressions is not the same as the preallocated buffer");
631  std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
632 }
633 
634 void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
635  assert(
636  RHSExprs.size() == varlist_size() &&
637  "Number of RHS expressions is not the same as the preallocated buffer");
638  std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
639 }
640 
641 void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
642  assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
643  "expressions is not the same "
644  "as the preallocated buffer");
645  std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
646 }
647 
649  const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
650  SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
651  NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
652  ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
653  ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
654  Expr *PostUpdate) {
655  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
657  StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
658  Clause->setVarRefs(VL);
659  Clause->setPrivates(Privates);
660  Clause->setLHSExprs(LHSExprs);
661  Clause->setRHSExprs(RHSExprs);
662  Clause->setReductionOps(ReductionOps);
663  Clause->setPreInitStmt(PreInit);
664  Clause->setPostUpdateExpr(PostUpdate);
665  return Clause;
666 }
667 
669  unsigned N) {
670  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
671  return new (Mem) OMPTaskReductionClause(N);
672 }
673 
674 void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
675  assert(Privates.size() == varlist_size() &&
676  "Number of private copies is not the same as the preallocated buffer");
677  std::copy(Privates.begin(), Privates.end(), varlist_end());
678 }
679 
680 void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
681  assert(
682  LHSExprs.size() == varlist_size() &&
683  "Number of LHS expressions is not the same as the preallocated buffer");
684  std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
685 }
686 
687 void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
688  assert(
689  RHSExprs.size() == varlist_size() &&
690  "Number of RHS expressions is not the same as the preallocated buffer");
691  std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
692 }
693 
694 void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
695  assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
696  "expressions is not the same "
697  "as the preallocated buffer");
698  std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
699 }
700 
701 void OMPInReductionClause::setTaskgroupDescriptors(
702  ArrayRef<Expr *> TaskgroupDescriptors) {
703  assert(TaskgroupDescriptors.size() == varlist_size() &&
704  "Number of in reduction descriptors is not the same as the "
705  "preallocated buffer");
706  std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
707  getReductionOps().end());
708 }
709 
711  const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
712  SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
713  NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
714  ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
715  ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
716  ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
717  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
718  OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
719  StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
720  Clause->setVarRefs(VL);
721  Clause->setPrivates(Privates);
722  Clause->setLHSExprs(LHSExprs);
723  Clause->setRHSExprs(RHSExprs);
724  Clause->setReductionOps(ReductionOps);
725  Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
726  Clause->setPreInitStmt(PreInit);
727  Clause->setPostUpdateExpr(PostUpdate);
728  return Clause;
729 }
730 
732  unsigned N) {
733  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
734  return new (Mem) OMPInReductionClause(N);
735 }
736 
739  SourceLocation LParenLoc, Expr *Allocator,
740  SourceLocation ColonLoc, SourceLocation EndLoc,
741  ArrayRef<Expr *> VL) {
742  // Allocate space for private variables and initializer expressions.
743  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
744  auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
745  ColonLoc, EndLoc, VL.size());
746  Clause->setVarRefs(VL);
747  return Clause;
748 }
749 
751  unsigned N) {
752  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
753  return new (Mem) OMPAllocateClause(N);
754 }
755 
757  SourceLocation StartLoc,
758  SourceLocation LParenLoc,
759  SourceLocation EndLoc,
760  ArrayRef<Expr *> VL) {
761  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
762  OMPFlushClause *Clause =
763  new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
764  Clause->setVarRefs(VL);
765  return Clause;
766 }
767 
769  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
770  return new (Mem) OMPFlushClause(N);
771 }
772 
775  SourceLocation LParenLoc, SourceLocation EndLoc,
776  OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
777  SourceLocation ColonLoc, ArrayRef<Expr *> VL,
778  unsigned NumLoops) {
779  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
780  OMPDependClause *Clause = new (Mem)
781  OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
782  Clause->setVarRefs(VL);
783  Clause->setDependencyKind(DepKind);
784  Clause->setDependencyLoc(DepLoc);
785  Clause->setColonLoc(ColonLoc);
786  for (unsigned I = 0 ; I < NumLoops; ++I)
787  Clause->setLoopData(I, nullptr);
788  return Clause;
789 }
790 
792  unsigned NumLoops) {
793  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
794  return new (Mem) OMPDependClause(N, NumLoops);
795 }
796 
797 void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
798  assert((getDependencyKind() == OMPC_DEPEND_sink ||
799  getDependencyKind() == OMPC_DEPEND_source) &&
800  NumLoop < NumLoops &&
801  "Expected sink or source depend + loop index must be less number of "
802  "loops.");
803  auto It = std::next(getVarRefs().end(), NumLoop);
804  *It = Cnt;
805 }
806 
807 Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
808  assert((getDependencyKind() == OMPC_DEPEND_sink ||
809  getDependencyKind() == OMPC_DEPEND_source) &&
810  NumLoop < NumLoops &&
811  "Expected sink or source depend + loop index must be less number of "
812  "loops.");
813  auto It = std::next(getVarRefs().end(), NumLoop);
814  return *It;
815 }
816 
817 const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
818  assert((getDependencyKind() == OMPC_DEPEND_sink ||
819  getDependencyKind() == OMPC_DEPEND_source) &&
820  NumLoop < NumLoops &&
821  "Expected sink or source depend + loop index must be less number of "
822  "loops.");
823  auto It = std::next(getVarRefs().end(), NumLoop);
824  return *It;
825 }
826 
828  MappableExprComponentListsRef ComponentLists) {
829  unsigned TotalNum = 0u;
830  for (auto &C : ComponentLists)
831  TotalNum += C.size();
832  return TotalNum;
833 }
834 
836  ArrayRef<const ValueDecl *> Declarations) {
837  unsigned TotalNum = 0u;
838  llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
839  for (const ValueDecl *D : Declarations) {
840  const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
841  if (Cache.count(VD))
842  continue;
843  ++TotalNum;
844  Cache.insert(VD);
845  }
846  return TotalNum;
847 }
848 
850  const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
851  ArrayRef<ValueDecl *> Declarations,
852  MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
853  ArrayRef<OpenMPMapModifierKind> MapModifiers,
854  ArrayRef<SourceLocation> MapModifiersLoc,
855  NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
856  OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
858  Sizes.NumVars = Vars.size();
859  Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
860  Sizes.NumComponentLists = ComponentLists.size();
861  Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
862 
863  // We need to allocate:
864  // 2 x NumVars x Expr* - we have an original list expression and an associated
865  // user-defined mapper for each clause list entry.
866  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
867  // with each component list.
868  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
869  // number of lists for each unique declaration and the size of each component
870  // list.
871  // NumComponents x MappableComponent - the total of all the components in all
872  // the lists.
873  void *Mem = C.Allocate(
874  totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
876  2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
878  Sizes.NumComponents));
879  OMPMapClause *Clause = new (Mem)
880  OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
881  Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
882 
883  Clause->setVarRefs(Vars);
884  Clause->setUDMapperRefs(UDMapperRefs);
885  Clause->setClauseInfo(Declarations, ComponentLists);
886  Clause->setMapType(Type);
887  Clause->setMapLoc(TypeLoc);
888  return Clause;
889 }
890 
891 OMPMapClause *
893  const OMPMappableExprListSizeTy &Sizes) {
894  void *Mem = C.Allocate(
895  totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
897  2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
899  Sizes.NumComponents));
900  return new (Mem) OMPMapClause(Sizes);
901 }
902 
904  const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
905  ArrayRef<ValueDecl *> Declarations,
906  MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
907  NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
909  Sizes.NumVars = Vars.size();
910  Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
911  Sizes.NumComponentLists = ComponentLists.size();
912  Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
913 
914  // We need to allocate:
915  // 2 x NumVars x Expr* - we have an original list expression and an associated
916  // user-defined mapper for each clause list entry.
917  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
918  // with each component list.
919  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
920  // number of lists for each unique declaration and the size of each component
921  // list.
922  // NumComponents x MappableComponent - the total of all the components in all
923  // the lists.
924  void *Mem = C.Allocate(
925  totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
927  2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
929  Sizes.NumComponents));
930 
931  auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
932 
933  Clause->setVarRefs(Vars);
934  Clause->setUDMapperRefs(UDMapperRefs);
935  Clause->setClauseInfo(Declarations, ComponentLists);
936  return Clause;
937 }
938 
940  const OMPMappableExprListSizeTy &Sizes) {
941  void *Mem = C.Allocate(
942  totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
944  2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
946  Sizes.NumComponents));
947  return new (Mem) OMPToClause(Sizes);
948 }
949 
951  const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
952  ArrayRef<ValueDecl *> Declarations,
953  MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
954  NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
956  Sizes.NumVars = Vars.size();
957  Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
958  Sizes.NumComponentLists = ComponentLists.size();
959  Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
960 
961  // We need to allocate:
962  // 2 x NumVars x Expr* - we have an original list expression and an associated
963  // user-defined mapper for each clause list entry.
964  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
965  // with each component list.
966  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
967  // number of lists for each unique declaration and the size of each component
968  // list.
969  // NumComponents x MappableComponent - the total of all the components in all
970  // the lists.
971  void *Mem = C.Allocate(
972  totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
974  2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
976  Sizes.NumComponents));
977 
978  auto *Clause =
979  new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
980 
981  Clause->setVarRefs(Vars);
982  Clause->setUDMapperRefs(UDMapperRefs);
983  Clause->setClauseInfo(Declarations, ComponentLists);
984  return Clause;
985 }
986 
989  const OMPMappableExprListSizeTy &Sizes) {
990  void *Mem = C.Allocate(
991  totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
993  2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
995  Sizes.NumComponents));
996  return new (Mem) OMPFromClause(Sizes);
997 }
998 
999 void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1000  assert(VL.size() == varlist_size() &&
1001  "Number of private copies is not the same as the preallocated buffer");
1002  std::copy(VL.begin(), VL.end(), varlist_end());
1003 }
1004 
1005 void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1006  assert(VL.size() == varlist_size() &&
1007  "Number of inits is not the same as the preallocated buffer");
1008  std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1009 }
1010 
1012  const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1013  ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1014  ArrayRef<ValueDecl *> Declarations,
1015  MappableExprComponentListsRef ComponentLists) {
1017  Sizes.NumVars = Vars.size();
1018  Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1019  Sizes.NumComponentLists = ComponentLists.size();
1020  Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1021 
1022  // We need to allocate:
1023  // 3 x NumVars x Expr* - we have an original list expression for each clause
1024  // list entry and an equal number of private copies and inits.
1025  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1026  // with each component list.
1027  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1028  // number of lists for each unique declaration and the size of each component
1029  // list.
1030  // NumComponents x MappableComponent - the total of all the components in all
1031  // the lists.
1032  void *Mem = C.Allocate(
1033  totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1035  3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1037  Sizes.NumComponents));
1038 
1039  OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
1040 
1041  Clause->setVarRefs(Vars);
1042  Clause->setPrivateCopies(PrivateVars);
1043  Clause->setInits(Inits);
1044  Clause->setClauseInfo(Declarations, ComponentLists);
1045  return Clause;
1046 }
1047 
1050  const OMPMappableExprListSizeTy &Sizes) {
1051  void *Mem = C.Allocate(
1052  totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1054  3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1056  Sizes.NumComponents));
1057  return new (Mem) OMPUseDevicePtrClause(Sizes);
1058 }
1059 
1062  ArrayRef<Expr *> Vars,
1063  ArrayRef<ValueDecl *> Declarations,
1064  MappableExprComponentListsRef ComponentLists) {
1066  Sizes.NumVars = Vars.size();
1067  Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1068  Sizes.NumComponentLists = ComponentLists.size();
1069  Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1070 
1071  // We need to allocate:
1072  // NumVars x Expr* - we have an original list expression for each clause list
1073  // entry.
1074  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1075  // with each component list.
1076  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1077  // number of lists for each unique declaration and the size of each component
1078  // list.
1079  // NumComponents x MappableComponent - the total of all the components in all
1080  // the lists.
1081  void *Mem = C.Allocate(
1082  totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1084  Sizes.NumVars, Sizes.NumUniqueDeclarations,
1086  Sizes.NumComponents));
1087 
1088  OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
1089 
1090  Clause->setVarRefs(Vars);
1091  Clause->setClauseInfo(Declarations, ComponentLists);
1092  return Clause;
1093 }
1094 
1097  const OMPMappableExprListSizeTy &Sizes) {
1098  void *Mem = C.Allocate(
1099  totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1101  Sizes.NumVars, Sizes.NumUniqueDeclarations,
1103  Sizes.NumComponents));
1104  return new (Mem) OMPIsDevicePtrClause(Sizes);
1105 }
1106 
1107 //===----------------------------------------------------------------------===//
1108 // OpenMP clauses printing methods
1109 //===----------------------------------------------------------------------===//
1110 
1111 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1112  OS << "if(";
1113  if (Node->getNameModifier() != OMPD_unknown)
1114  OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1115  Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1116  OS << ")";
1117 }
1118 
1119 void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1120  OS << "final(";
1121  Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1122  OS << ")";
1123 }
1124 
1125 void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1126  OS << "num_threads(";
1127  Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1128  OS << ")";
1129 }
1130 
1131 void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1132  OS << "safelen(";
1133  Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1134  OS << ")";
1135 }
1136 
1137 void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1138  OS << "simdlen(";
1139  Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1140  OS << ")";
1141 }
1142 
1143 void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1144  OS << "allocator(";
1145  Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1146  OS << ")";
1147 }
1148 
1149 void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1150  OS << "collapse(";
1151  Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1152  OS << ")";
1153 }
1154 
1155 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1156  OS << "default("
1157  << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1158  << ")";
1159 }
1160 
1161 void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1162  OS << "proc_bind("
1163  << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1164  << ")";
1165 }
1166 
1167 void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1168  OS << "unified_address";
1169 }
1170 
1171 void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1173  OS << "unified_shared_memory";
1174 }
1175 
1176 void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1177  OS << "reverse_offload";
1178 }
1179 
1180 void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1182  OS << "dynamic_allocators";
1183 }
1184 
1185 void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1187  OS << "atomic_default_mem_order("
1188  << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1190  << ")";
1191 }
1192 
1193 void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1194  OS << "schedule(";
1196  OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1197  Node->getFirstScheduleModifier());
1199  OS << ", ";
1200  OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1201  Node->getSecondScheduleModifier());
1202  }
1203  OS << ": ";
1204  }
1205  OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1206  if (auto *E = Node->getChunkSize()) {
1207  OS << ", ";
1208  E->printPretty(OS, nullptr, Policy);
1209  }
1210  OS << ")";
1211 }
1212 
1213 void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1214  OS << "ordered";
1215  if (auto *Num = Node->getNumForLoops()) {
1216  OS << "(";
1217  Num->printPretty(OS, nullptr, Policy, 0);
1218  OS << ")";
1219  }
1220 }
1221 
1222 void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1223  OS << "nowait";
1224 }
1225 
1226 void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1227  OS << "untied";
1228 }
1229 
1230 void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1231  OS << "nogroup";
1232 }
1233 
1234 void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1235  OS << "mergeable";
1236 }
1237 
1238 void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1239 
1240 void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1241 
1242 void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1243  OS << "update";
1244 }
1245 
1246 void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1247  OS << "capture";
1248 }
1249 
1250 void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1251  OS << "seq_cst";
1252 }
1253 
1254 void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1255  OS << "threads";
1256 }
1257 
1258 void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1259 
1260 void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1261  OS << "device(";
1262  Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1263  OS << ")";
1264 }
1265 
1266 void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1267  OS << "num_teams(";
1268  Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1269  OS << ")";
1270 }
1271 
1272 void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1273  OS << "thread_limit(";
1274  Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1275  OS << ")";
1276 }
1277 
1278 void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1279  OS << "priority(";
1280  Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1281  OS << ")";
1282 }
1283 
1284 void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1285  OS << "grainsize(";
1286  Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1287  OS << ")";
1288 }
1289 
1290 void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1291  OS << "num_tasks(";
1292  Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1293  OS << ")";
1294 }
1295 
1296 void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1297  OS << "hint(";
1298  Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1299  OS << ")";
1300 }
1301 
1302 template<typename T>
1303 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1304  for (typename T::varlist_iterator I = Node->varlist_begin(),
1305  E = Node->varlist_end();
1306  I != E; ++I) {
1307  assert(*I && "Expected non-null Stmt");
1308  OS << (I == Node->varlist_begin() ? StartSym : ',');
1309  if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1310  if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1311  DRE->printPretty(OS, nullptr, Policy, 0);
1312  else
1313  DRE->getDecl()->printQualifiedName(OS);
1314  } else
1315  (*I)->printPretty(OS, nullptr, Policy, 0);
1316  }
1317 }
1318 
1319 void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1320  if (Node->varlist_empty())
1321  return;
1322  OS << "allocate";
1323  if (Expr *Allocator = Node->getAllocator()) {
1324  OS << "(";
1325  Allocator->printPretty(OS, nullptr, Policy, 0);
1326  OS << ":";
1327  VisitOMPClauseList(Node, ' ');
1328  } else {
1329  VisitOMPClauseList(Node, '(');
1330  }
1331  OS << ")";
1332 }
1333 
1334 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1335  if (!Node->varlist_empty()) {
1336  OS << "private";
1337  VisitOMPClauseList(Node, '(');
1338  OS << ")";
1339  }
1340 }
1341 
1342 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1343  if (!Node->varlist_empty()) {
1344  OS << "firstprivate";
1345  VisitOMPClauseList(Node, '(');
1346  OS << ")";
1347  }
1348 }
1349 
1350 void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1351  if (!Node->varlist_empty()) {
1352  OS << "lastprivate";
1353  VisitOMPClauseList(Node, '(');
1354  OS << ")";
1355  }
1356 }
1357 
1358 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1359  if (!Node->varlist_empty()) {
1360  OS << "shared";
1361  VisitOMPClauseList(Node, '(');
1362  OS << ")";
1363  }
1364 }
1365 
1366 void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1367  if (!Node->varlist_empty()) {
1368  OS << "reduction(";
1369  NestedNameSpecifier *QualifierLoc =
1373  if (QualifierLoc == nullptr && OOK != OO_None) {
1374  // Print reduction identifier in C format
1375  OS << getOperatorSpelling(OOK);
1376  } else {
1377  // Use C++ format
1378  if (QualifierLoc != nullptr)
1379  QualifierLoc->print(OS, Policy);
1380  OS << Node->getNameInfo();
1381  }
1382  OS << ":";
1383  VisitOMPClauseList(Node, ' ');
1384  OS << ")";
1385  }
1386 }
1387 
1388 void OMPClausePrinter::VisitOMPTaskReductionClause(
1389  OMPTaskReductionClause *Node) {
1390  if (!Node->varlist_empty()) {
1391  OS << "task_reduction(";
1392  NestedNameSpecifier *QualifierLoc =
1396  if (QualifierLoc == nullptr && OOK != OO_None) {
1397  // Print reduction identifier in C format
1398  OS << getOperatorSpelling(OOK);
1399  } else {
1400  // Use C++ format
1401  if (QualifierLoc != nullptr)
1402  QualifierLoc->print(OS, Policy);
1403  OS << Node->getNameInfo();
1404  }
1405  OS << ":";
1406  VisitOMPClauseList(Node, ' ');
1407  OS << ")";
1408  }
1409 }
1410 
1411 void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1412  if (!Node->varlist_empty()) {
1413  OS << "in_reduction(";
1414  NestedNameSpecifier *QualifierLoc =
1418  if (QualifierLoc == nullptr && OOK != OO_None) {
1419  // Print reduction identifier in C format
1420  OS << getOperatorSpelling(OOK);
1421  } else {
1422  // Use C++ format
1423  if (QualifierLoc != nullptr)
1424  QualifierLoc->print(OS, Policy);
1425  OS << Node->getNameInfo();
1426  }
1427  OS << ":";
1428  VisitOMPClauseList(Node, ' ');
1429  OS << ")";
1430  }
1431 }
1432 
1433 void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1434  if (!Node->varlist_empty()) {
1435  OS << "linear";
1436  if (Node->getModifierLoc().isValid()) {
1437  OS << '('
1438  << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1439  }
1440  VisitOMPClauseList(Node, '(');
1441  if (Node->getModifierLoc().isValid())
1442  OS << ')';
1443  if (Node->getStep() != nullptr) {
1444  OS << ": ";
1445  Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1446  }
1447  OS << ")";
1448  }
1449 }
1450 
1451 void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1452  if (!Node->varlist_empty()) {
1453  OS << "aligned";
1454  VisitOMPClauseList(Node, '(');
1455  if (Node->getAlignment() != nullptr) {
1456  OS << ": ";
1457  Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1458  }
1459  OS << ")";
1460  }
1461 }
1462 
1463 void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1464  if (!Node->varlist_empty()) {
1465  OS << "copyin";
1466  VisitOMPClauseList(Node, '(');
1467  OS << ")";
1468  }
1469 }
1470 
1471 void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1472  if (!Node->varlist_empty()) {
1473  OS << "copyprivate";
1474  VisitOMPClauseList(Node, '(');
1475  OS << ")";
1476  }
1477 }
1478 
1479 void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1480  if (!Node->varlist_empty()) {
1481  VisitOMPClauseList(Node, '(');
1482  OS << ")";
1483  }
1484 }
1485 
1486 void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1487  OS << "depend(";
1488  OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1489  Node->getDependencyKind());
1490  if (!Node->varlist_empty()) {
1491  OS << " :";
1492  VisitOMPClauseList(Node, ' ');
1493  }
1494  OS << ")";
1495 }
1496 
1497 void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1498  if (!Node->varlist_empty()) {
1499  OS << "map(";
1500  if (Node->getMapType() != OMPC_MAP_unknown) {
1501  for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1503  OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1504  Node->getMapTypeModifier(I));
1505  if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1506  OS << '(';
1507  NestedNameSpecifier *MapperNNS =
1509  if (MapperNNS)
1510  MapperNNS->print(OS, Policy);
1511  OS << Node->getMapperIdInfo() << ')';
1512  }
1513  OS << ',';
1514  }
1515  }
1516  OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1517  OS << ':';
1518  }
1519  VisitOMPClauseList(Node, ' ');
1520  OS << ")";
1521  }
1522 }
1523 
1524 void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1525  if (!Node->varlist_empty()) {
1526  OS << "to";
1527  DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1528  if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1529  OS << '(';
1530  OS << "mapper(";
1531  NestedNameSpecifier *MapperNNS =
1533  if (MapperNNS)
1534  MapperNNS->print(OS, Policy);
1535  OS << MapperId << "):";
1536  VisitOMPClauseList(Node, ' ');
1537  } else {
1538  VisitOMPClauseList(Node, '(');
1539  }
1540  OS << ")";
1541  }
1542 }
1543 
1544 void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1545  if (!Node->varlist_empty()) {
1546  OS << "from";
1547  DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1548  if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1549  OS << '(';
1550  OS << "mapper(";
1551  NestedNameSpecifier *MapperNNS =
1553  if (MapperNNS)
1554  MapperNNS->print(OS, Policy);
1555  OS << MapperId << "):";
1556  VisitOMPClauseList(Node, ' ');
1557  } else {
1558  VisitOMPClauseList(Node, '(');
1559  }
1560  OS << ")";
1561  }
1562 }
1563 
1564 void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1565  OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1566  OMPC_dist_schedule, Node->getDistScheduleKind());
1567  if (auto *E = Node->getChunkSize()) {
1568  OS << ", ";
1569  E->printPretty(OS, nullptr, Policy);
1570  }
1571  OS << ")";
1572 }
1573 
1574 void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1575  OS << "defaultmap(";
1576  OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1577  Node->getDefaultmapModifier());
1578  OS << ": ";
1579  OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1580  Node->getDefaultmapKind());
1581  OS << ")";
1582 }
1583 
1584 void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1585  if (!Node->varlist_empty()) {
1586  OS << "use_device_ptr";
1587  VisitOMPClauseList(Node, '(');
1588  OS << ")";
1589  }
1590 }
1591 
1592 void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1593  if (!Node->varlist_empty()) {
1594  OS << "is_device_ptr";
1595  VisitOMPClauseList(Node, '(');
1596  OS << ")";
1597  }
1598 }
1599 
static OMPTaskReductionClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, ArrayRef< Expr *> Privates, ArrayRef< Expr *> LHSExprs, ArrayRef< Expr *> RHSExprs, ArrayRef< Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL.
Defines the clang::ASTContext interface.
static OMPToClause * Create(const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef< Expr *> Vars, ArrayRef< ValueDecl *> Declarations, MappableExprComponentListsRef ComponentLists, ArrayRef< Expr *> UDMapperRefs, NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId)
Creates clause with a list of variables Vars.
This represents &#39;thread_limit&#39; clause in the &#39;#pragma omp ...&#39; directive.
static OMPCopyinClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with N variables.
This represents clause &#39;copyin&#39; in the &#39;#pragma omp ...&#39; directives.
bool varlist_empty() const
Definition: OpenMPClause.h:227
This represents &#39;atomic_default_mem_order&#39; clause in the &#39;#pragma omp requires&#39; directive.
static OMPCopyprivateClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> SrcExprs, ArrayRef< Expr *> DstExprs, ArrayRef< Expr *> AssignmentOps)
Creates clause with a list of variables VL.
TypePropertyCache< Private > Cache
Definition: Type.cpp:3553
static OMPClauseWithPreInit * get(OMPClause *C)
Stmt - This represents one statement.
Definition: Stmt.h:66
This represents clause &#39;in_reduction&#39; in the &#39;#pragma omp task&#39; directives.
Expr * getLoopData(unsigned NumLoop)
Get the loop data.
Class that handles pre-initialization statement for some clauses, like &#39;shedule&#39;, &#39;firstprivate&#39; etc...
Definition: OpenMPClause.h:107
Expr * getAllocator() const
Returns allocator.
Definition: OpenMPClause.h:298
static OMPFirstprivateClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
This represents &#39;grainsize&#39; clause in the &#39;#pragma omp ...&#39; directive.
static constexpr unsigned NumberOfModifiers
Number of allowed map-type-modifiers.
This represents &#39;if&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:422
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
This represents &#39;priority&#39; clause in the &#39;#pragma omp ...&#39; directive.
The base class of the type hierarchy.
Definition: Type.h:1433
const char * getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type)
Expr * getCondition() const
Returns condition.
Definition: OpenMPClause.h:557
This represents &#39;update&#39; clause in the &#39;#pragma omp atomic&#39; directive.
bool isEmpty() const
Evaluates true when this declaration name is empty.
Expr * getCondition() const
Returns condition.
Definition: OpenMPClause.h:490
Expr * getAlignment()
Returns alignment.
Expr * getNumForLoops() const
Return the number of associated for-loops.
OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY
Fetches the map-type-modifier at &#39;Cnt&#39; index of array of modifiers.
static OMPReductionClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
static OMPUseDevicePtrClause * CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes)
Creates an empty clause with the place for NumVars variables.
This represents &#39;read&#39; clause in the &#39;#pragma omp atomic&#39; directive.
static OMPUseDevicePtrClause * Create(const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef< Expr *> Vars, ArrayRef< Expr *> PrivateVars, ArrayRef< Expr *> Inits, ArrayRef< ValueDecl *> Declarations, MappableExprComponentListsRef ComponentLists)
Creates clause with a list of variables Vars.
This represents clause &#39;private&#39; in the &#39;#pragma omp ...&#39; directives.
This represents &#39;num_threads&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:585
This represents &#39;defaultmap&#39; clause in the &#39;#pragma omp ...&#39; directive.
void setUpdates(ArrayRef< Expr *> UL)
Sets the list of update expressions for linear variables.
This represents implicit clause &#39;flush&#39; for the &#39;#pragma omp flush&#39; directive.
const DeclarationNameInfo & getNameInfo() const
Gets the name info for specified reduction identifier.
This represents &#39;reverse_offload&#39; clause in the &#39;#pragma omp requires&#39; directive. ...
static OMPTaskReductionClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
Expr * getGrainsize() const
Return safe iteration space distance.
This represents &#39;nogroup&#39; clause in the &#39;#pragma omp ...&#39; directive.
This represents &#39;allocator&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:263
This represents &#39;safelen&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:661
static OMPOrderedClause * CreateEmpty(const ASTContext &C, unsigned NumLoops)
Build an empty clause.
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:56
static OMPReductionClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, ArrayRef< Expr *> Privates, ArrayRef< Expr *> LHSExprs, ArrayRef< Expr *> RHSExprs, ArrayRef< Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL.
CalcStep
Definition: OpenMPClause.h:151
Step
Definition: OpenMPClause.h:151
static OMPInReductionClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, ArrayRef< Expr *> Privates, ArrayRef< Expr *> LHSExprs, ArrayRef< Expr *> RHSExprs, ArrayRef< Expr *> ReductionOps, ArrayRef< Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL.
clang::OMPLinearClause OMPVarListClause, OMPClauseWithPostUpdate, llvm::TrailingObjects getPrivates()
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
A C++ nested-name-specifier augmented with source location information.
static OMPAllocateClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
This represents &#39;simd&#39; clause in the &#39;#pragma omp ...&#39; directive.
OpenMPLinearClauseKind
OpenMP attributes for &#39;linear&#39; clause.
Definition: OpenMPKinds.h:83
This represents clause &#39;lastprivate&#39; in the &#39;#pragma omp ...&#39; directives.
This represents clause &#39;allocate&#39; in the &#39;#pragma omp ...&#39; directives.
Definition: OpenMPClause.h:325
void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations)
Set number of iterations for the specified loop.
Expr * getChunkSize()
Get chunk size.
This represents clause &#39;map&#39; in the &#39;#pragma omp ...&#39; directives.
This represents clause &#39;to&#39; in the &#39;#pragma omp ...&#39; directives.
Expr * getSafelen() const
Return safe iteration space distance.
Definition: OpenMPClause.h:695
Expr * getNumTeams()
Return NumTeams number.
This represents clause &#39;copyprivate&#39; in the &#39;#pragma omp ...&#39; directives.
void setLoopCounter(unsigned NumLoop, Expr *Counter)
Set loop counter for the specified loop.
NestedNameSpecifierLoc getQualifierLoc() const
Gets the nested name specifier.
static OMPInReductionClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
static OMPLastprivateClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> SrcExprs, ArrayRef< Expr *> DstExprs, ArrayRef< Expr *> AssignmentOps, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL.
static unsigned getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists)
Class that handles post-update expression for some clauses, like &#39;lastprivate&#39;, &#39;reduction&#39; etc...
Definition: OpenMPClause.h:143
This represents &#39;default&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:853
This represents &#39;final&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:522
This represents &#39;mergeable&#39; clause in the &#39;#pragma omp ...&#39; directive.
OpenMPDependClauseKind getDependencyKind() const
Get dependency type.
This represents clause &#39;reduction&#39; in the &#39;#pragma omp ...&#39; directives.
void setPrivates(ArrayRef< Expr *> PL)
Sets the list of the copies of original linear variables.
unsigned NumVars
Number of expressions listed.
This represents clause &#39;is_device_ptr&#39; in the &#39;#pragma omp ...&#39; directives.
child_range used_children()
Get the iterator range for the expressions used in the clauses.
static OMPMapClause * Create(const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef< Expr *> Vars, ArrayRef< ValueDecl *> Declarations, MappableExprComponentListsRef ComponentLists, ArrayRef< Expr *> UDMapperRefs, ArrayRef< OpenMPMapModifierKind > MapModifiers, ArrayRef< SourceLocation > MapModifiersLoc, NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId, OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc)
Creates clause with a list of variables VL.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
void setFinals(ArrayRef< Expr *> FL)
Sets the list of final update expressions for linear variables.
static OMPCopyinClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> SrcExprs, ArrayRef< Expr *> DstExprs, ArrayRef< Expr *> AssignmentOps)
Creates clause with a list of variables VL.
static OMPDependClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, OpenMPDependClauseKind DepKind, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr *> VL, unsigned NumLoops)
Creates clause with a list of variables VL.
This represents clause &#39;from&#39; in the &#39;#pragma omp ...&#39; directives.
static OMPIsDevicePtrClause * Create(const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef< Expr *> Vars, ArrayRef< ValueDecl *> Declarations, MappableExprComponentListsRef ComponentLists)
Creates clause with a list of variables Vars.
child_range children()
This represents &#39;dynamic_allocators&#39; clause in the &#39;#pragma omp requires&#39; directive.
OpenMPDefaultClauseKind getDefaultKind() const
Returns kind of the clause.
Definition: OpenMPClause.h:900
OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, unsigned NumVars)
Build &#39;linear&#39; clause with given number of variables NumVars.
Definition: OpenMPClause.h:122
This represents &#39;threads&#39; clause in the &#39;#pragma omp ...&#39; directive.
NestedNameSpecifierLoc getMapperQualifierLoc() const
Gets the nested name specifier for associated user-defined mapper.
Expr * getSimdlen() const
Return safe iteration space distance.
Definition: OpenMPClause.h:760
This represents clause &#39;aligned&#39; in the &#39;#pragma omp ...&#39; directives.
OpenMPClauseKind getClauseKind() const
Returns kind of OpenMP clause (private, shared, reduction, etc.).
Definition: OpenMPClause.h:78
static OMPAlignedClause * CreateEmpty(const ASTContext &C, unsigned NumVars)
Creates an empty clause with the place for NumVars variables.
static OMPOrderedClause * Create(const ASTContext &C, Expr *Num, unsigned NumLoops, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build &#39;ordered&#39; clause.
This represents clause &#39;task_reduction&#39; in the &#39;#pragma omp taskgroup&#39; directives.
OpenMPProcBindClauseKind getProcBindKind() const
Returns kind of the clause.
Definition: OpenMPClause.h:981
This represents implicit clause &#39;depend&#39; for the &#39;#pragma omp task&#39; directive.
This represents &#39;proc_bind&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:933
This represents &#39;capture&#39; clause in the &#39;#pragma omp atomic&#39; directive.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
This represents one expression.
Definition: Expr.h:108
This represents &#39;simdlen&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:726
MutableArrayRef< Expr * > getUpdates()
Sets the list of update expressions for linear variables.
Expr * getNumTasks() const
Return safe iteration space distance.
unsigned NumComponentLists
Number of component lists.
Inits[]
Definition: OpenMPClause.h:150
static OMPDependClause * CreateEmpty(const ASTContext &C, unsigned N, unsigned NumLoops)
Creates an empty clause with N variables.
Expr * getAllocator() const
Returns the allocator expression or nullptr, if no allocator is specified.
Definition: OpenMPClause.h:382
static Stmt ** getAddrOfExprAsWritten(Stmt *S)
Gets the address of the original, non-captured, expression used in the clause as the preinitializer...
OpenMPDistScheduleClauseKind getDistScheduleKind() const
Get kind of the clause.
This represents &#39;ordered&#39; clause in the &#39;#pragma omp ...&#39; directive.
static OMPFlushClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with N variables.
static OMPLinearClause * CreateEmpty(const ASTContext &C, unsigned NumVars)
Creates an empty clause with the place for NumVars variables.
Expr * getDevice()
Return device number.
static OMPPrivateClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
This represents &#39;collapse&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:791
This represents clause &#39;firstprivate&#39; in the &#39;#pragma omp ...&#39; directives.
static OMPIsDevicePtrClause * CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes)
Creates an empty clause with the place for NumVars variables.
This file defines OpenMP AST classes for clauses.
ArrayRef< Expr * > getLoopNumIterations() const
Get number of iterations for all the loops.
This represents &#39;seq_cst&#39; clause in the &#39;#pragma omp atomic&#39; directive.
This represents &#39;untied&#39; clause in the &#39;#pragma omp ...&#39; directive.
This represents &#39;unified_address&#39; clause in the &#39;#pragma omp requires&#39; directive. ...
void setPostUpdateExpr(Expr *S)
Set pre-initialization statement for the clause.
Definition: OpenMPClause.h:155
This represents &#39;num_teams&#39; clause in the &#39;#pragma omp ...&#39; directive.
llvm::iterator_range< child_iterator > child_range
Definition: OpenMPClause.h:84
Encodes a location in the source.
This represents &#39;hint&#39; clause in the &#39;#pragma omp ...&#39; directive.
OpenMPDependClauseKind
OpenMP attributes for &#39;depend&#39; clause.
Definition: OpenMPKinds.h:75
MutableArrayRef< Expr * > getInits()
This structure contains all sizes needed for by an OMPMappableExprListClause.
DeclarationName getName() const
getName - Returns the embedded declaration name.
This represents &#39;schedule&#39; clause in the &#39;#pragma omp ...&#39; directive.
This represents clause &#39;shared&#39; in the &#39;#pragma omp ...&#39; directives.
Expr * getPriority()
Return Priority number.
OpenMPLinearClauseKind Modifier
Modifier of &#39;linear&#39; clause.
Definition: OpenMPClause.h:101
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
OpenMPMapClauseKind getMapType() const LLVM_READONLY
Fetches mapping kind for the clause.
This file defines OpenMP nodes for declarative directives.
static OMPSharedClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL)
Creates clause with a list of variables VL.
Expr * getLoopCounter(unsigned NumLoop)
Get loops counter for the specified loop.
void setPrivateCopies(ArrayRef< Expr *> PrivateCopies)
Set list of helper expressions, required for generation of private copies of original lastprivate var...
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:50
void setVarRefs(ArrayRef< Expr *> VL)
Sets the list of variables for this clause.
Definition: OpenMPClause.h:213
Expr * getNumForLoops() const
Return the number of associated for-loops.
Definition: OpenMPClause.h:826
static OMPAlignedClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, Expr *A)
Creates clause with a list of variables VL and alignment A.
static OMPPrivateClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PrivateVL)
Creates clause with a list of variables VL.
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:672
ast_type_traits::DynTypedNode Node
Dataflow Directional Tag Classes.
This represents &#39;device&#39; clause in the &#39;#pragma omp ...&#39; directive.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
OpenMPDefaultmapClauseKind getDefaultmapKind() const
Get kind of the clause.
SourceLocation ModifierLoc
Location of linear modifier if any.
Definition: OpenMPClause.h:104
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
This represents &#39;unified_shared_memory&#39; clause in the &#39;#pragma omp requires&#39; directive.
This represents clause &#39;linear&#39; in the &#39;#pragma omp ...&#39; directives.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
OpenMPDefaultmapClauseModifier getDefaultmapModifier() const
Get the modifier of the clause.
static OMPFirstprivateClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PrivateVL, ArrayRef< Expr *> InitVL, Stmt *PreInit)
Creates clause with a list of variables VL.
ArrayRef< MappableExprComponentList > MappableExprComponentListsRef
unsigned NumUniqueDeclarations
Number of unique base declarations.
static OMPSharedClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with N variables.
Class that represents a component of a mappable expression.
Not an overloaded operator.
Definition: OperatorKinds.h:22
static unsigned getUniqueDeclarationsTotalNumber(ArrayRef< const ValueDecl *> Declarations)
OpenMPDirectiveKind getNameModifier() const
Return directive name modifier associated with the clause.
Definition: OpenMPClause.h:493
static OMPCopyprivateClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with N variables.
child_range used_children()
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword...
void setUDMapperRefs(ArrayRef< Expr *> DMDs)
Set the user-defined mappers that are in the trailing objects of the class.
const DeclarationNameInfo & getNameInfo() const
Gets the name info for specified reduction identifier.
This represents &#39;write&#39; clause in the &#39;#pragma omp atomic&#39; directive.
const char * getOpenMPDirectiveName(OpenMPDirectiveKind Kind)
Definition: OpenMPKinds.cpp:30
void setLoopData(unsigned NumLoop, Expr *Cnt)
Set the loop data for the depend clauses with &#39;sink|source&#39; kind of dependency.
void setClauseInfo(ArrayRef< ValueDecl *> Declarations, MappableExprComponentListsRef ComponentLists)
Fill the clause information from the list of declarations and associated component lists...
const DeclarationNameInfo & getNameInfo() const
Gets the name info for specified reduction identifier.
OpenMPScheduleClauseModifier getSecondScheduleModifier() const
Get the second modifier of the clause.
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\, const ASTContext *Context=nullptr) const
This represents &#39;nowait&#39; clause in the &#39;#pragma omp ...&#39; directive.
OpenMPScheduleClauseModifier getFirstScheduleModifier() const
Get the first modifier of the clause.
This represents &#39;num_tasks&#39; clause in the &#39;#pragma omp ...&#39; directive.
OpenMPScheduleClauseKind getScheduleKind() const
Get kind of the clause.
static OMPMapClause * CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes)
Creates an empty clause with the place for NumVars original expressions, NumUniqueDeclarations declar...
Privates[]
Gets the list of initial values for linear variables.
Definition: OpenMPClause.h:150
OpenMPMapClauseKind
OpenMP mapping kind for &#39;map&#39; clause.
Definition: OpenMPKinds.h:91
Expr * getThreadLimit()
Return ThreadLimit number.
static OMPFromClause * CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes)
Creates an empty clause with the place for NumVars variables.
void setPreInitStmt(Stmt *S, OpenMPDirectiveKind ThisRegion=OMPD_unknown)
Set pre-initialization statement for the clause.
Definition: OpenMPClause.h:122
This represents &#39;dist_schedule&#39; clause in the &#39;#pragma omp ...&#39; directive.
Expr * getHint() const
Returns number of threads.
static OMPAllocateClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, Expr *Allocator, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL)
Creates clause with a list of variables VL.
NestedNameSpecifierLoc getQualifierLoc() const
Gets the nested name specifier.
void setInits(ArrayRef< Expr *> IL)
Sets the list of the initial values for linear variables.
NestedNameSpecifierLoc getQualifierLoc() const
Gets the nested name specifier.
Expr * getChunkSize()
Get chunk size.
static OMPFlushClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL)
Creates clause with a list of variables VL.
Expr * getNumThreads() const
Returns number of threads.
Definition: OpenMPClause.h:629
This structure contains most locations needed for by an OMPVarListClause.
Definition: OpenMPClause.h:169
static OMPClauseWithPostUpdate * get(OMPClause *C)
static OMPFromClause * Create(const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef< Expr *> Vars, ArrayRef< ValueDecl *> Declarations, MappableExprComponentListsRef ComponentLists, ArrayRef< Expr *> UDMapperRefs, NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId)
Creates clause with a list of variables Vars.
static OMPLastprivateClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
OpenMPAtomicDefaultMemOrderClauseKind getAtomicDefaultMemOrderKind() const
Returns kind of the clause.
const DeclarationNameInfo & getMapperIdInfo() const
Gets the name info for associated user-defined mapper.
SourceLocation ColonLoc
Location of &#39;:&#39;.
Definition: OpenMPClause.h:107
unsigned NumComponents
Total number of expression components.
static OMPToClause * CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes)
Creates an empty clause with the place for NumVars variables.
This represents clause &#39;use_device_ptr&#39; in the &#39;#pragma omp ...&#39; directives.
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.