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