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_unknown:
47     break;
48   }
49   llvm_unreachable("unknown OMPClause");
50 }
51 
52 OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
53   auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
54   return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
55 }
56 
57 const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
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 
136 OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
137   auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
138   return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
139 }
140 
141 const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
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.
214 static Stmt **getAddrOfExprAsWritten(Stmt *S) {
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 
225 OMPClause::child_range OMPIfClause::used_children() {
226   if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
227     return child_range(C, C + 1);
228   return child_range(&Condition, &Condition + 1);
229 }
230 
231 OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
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 
246 OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
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 
257 void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
258                                             Expr *NumIterations) {
259   assert(NumLoop < NumberOfLoops && "out of loops number.");
260   getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
261 }
262 
263 ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
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 
272 Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
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 
288 OMPPrivateClause *
289 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
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 
301 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
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 
319 OMPFirstprivateClause *
320 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
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 
334 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
335                                                           unsigned N) {
336   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
337   return new (Mem) OMPFirstprivateClause(N);
338 }
339 
340 void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
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 
368 OMPLastprivateClause *OMPLastprivateClause::Create(
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 
385 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
386                                                         unsigned N) {
387   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
388   return new (Mem) OMPLastprivateClause(N);
389 }
390 
391 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
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 
403 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
404   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
405   return new (Mem) OMPSharedClause(N);
406 }
407 
408 void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
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 
414 void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
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 
420 void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
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 
426 void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
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 
432 void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
433   assert(
434       UE.size() == varlist_size() + 1 &&
435       "Number of used expressions is not the same as the preallocated buffer");
436   std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
437 }
438 
439 OMPLinearClause *OMPLinearClause::Create(
440     const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
441     OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
442     SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
443     ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
444     Stmt *PreInit, Expr *PostUpdate) {
445   // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
446   // (Step and CalcStep), list of used expression + step.
447   void *Mem =
448       C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
449   OMPLinearClause *Clause = new (Mem) OMPLinearClause(
450       StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
451   Clause->setVarRefs(VL);
452   Clause->setPrivates(PL);
453   Clause->setInits(IL);
454   // Fill update and final expressions with zeroes, they are provided later,
455   // after the directive construction.
456   std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
457             nullptr);
458   std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
459             nullptr);
460   std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
461             nullptr);
462   Clause->setStep(Step);
463   Clause->setCalcStep(CalcStep);
464   Clause->setPreInitStmt(PreInit);
465   Clause->setPostUpdateExpr(PostUpdate);
466   return Clause;
467 }
468 
469 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
470                                               unsigned NumVars) {
471   // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
472   // (Step and CalcStep), list of used expression + step.
473   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars  +1));
474   return new (Mem) OMPLinearClause(NumVars);
475 }
476 
477 OMPClause::child_range OMPLinearClause::used_children() {
478   // Range includes only non-nullptr elements.
479   return child_range(
480       reinterpret_cast<Stmt **>(getUsedExprs().begin()),
481       reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
482 }
483 
484 OMPAlignedClause *
485 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
486                          SourceLocation LParenLoc, SourceLocation ColonLoc,
487                          SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
488   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
489   OMPAlignedClause *Clause = new (Mem)
490       OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
491   Clause->setVarRefs(VL);
492   Clause->setAlignment(A);
493   return Clause;
494 }
495 
496 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
497                                                 unsigned NumVars) {
498   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
499   return new (Mem) OMPAlignedClause(NumVars);
500 }
501 
502 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
503   assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
504                                               "not the same as the "
505                                               "preallocated buffer");
506   std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
507 }
508 
509 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
510   assert(DstExprs.size() == varlist_size() && "Number of destination "
511                                               "expressions is not the same as "
512                                               "the preallocated buffer");
513   std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
514 }
515 
516 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
517   assert(AssignmentOps.size() == varlist_size() &&
518          "Number of assignment expressions is not the same as the preallocated "
519          "buffer");
520   std::copy(AssignmentOps.begin(), AssignmentOps.end(),
521             getDestinationExprs().end());
522 }
523 
524 OMPCopyinClause *OMPCopyinClause::Create(
525     const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
526     SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
527     ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
528   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
529   OMPCopyinClause *Clause =
530       new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
531   Clause->setVarRefs(VL);
532   Clause->setSourceExprs(SrcExprs);
533   Clause->setDestinationExprs(DstExprs);
534   Clause->setAssignmentOps(AssignmentOps);
535   return Clause;
536 }
537 
538 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
539   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
540   return new (Mem) OMPCopyinClause(N);
541 }
542 
543 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
544   assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
545                                               "not the same as the "
546                                               "preallocated buffer");
547   std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
548 }
549 
550 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
551   assert(DstExprs.size() == varlist_size() && "Number of destination "
552                                               "expressions is not the same as "
553                                               "the preallocated buffer");
554   std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
555 }
556 
557 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
558   assert(AssignmentOps.size() == varlist_size() &&
559          "Number of assignment expressions is not the same as the preallocated "
560          "buffer");
561   std::copy(AssignmentOps.begin(), AssignmentOps.end(),
562             getDestinationExprs().end());
563 }
564 
565 OMPCopyprivateClause *OMPCopyprivateClause::Create(
566     const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
567     SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
568     ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
569   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
570   OMPCopyprivateClause *Clause =
571       new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
572   Clause->setVarRefs(VL);
573   Clause->setSourceExprs(SrcExprs);
574   Clause->setDestinationExprs(DstExprs);
575   Clause->setAssignmentOps(AssignmentOps);
576   return Clause;
577 }
578 
579 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
580                                                         unsigned N) {
581   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
582   return new (Mem) OMPCopyprivateClause(N);
583 }
584 
585 void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
586   assert(Privates.size() == varlist_size() &&
587          "Number of private copies is not the same as the preallocated buffer");
588   std::copy(Privates.begin(), Privates.end(), varlist_end());
589 }
590 
591 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
592   assert(
593       LHSExprs.size() == varlist_size() &&
594       "Number of LHS expressions is not the same as the preallocated buffer");
595   std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
596 }
597 
598 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
599   assert(
600       RHSExprs.size() == varlist_size() &&
601       "Number of RHS expressions is not the same as the preallocated buffer");
602   std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
603 }
604 
605 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
606   assert(ReductionOps.size() == varlist_size() && "Number of reduction "
607                                                   "expressions is not the same "
608                                                   "as the preallocated buffer");
609   std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
610 }
611 
612 OMPReductionClause *OMPReductionClause::Create(
613     const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
614     SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
615     NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
616     ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
617     ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
618     Expr *PostUpdate) {
619   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
620   OMPReductionClause *Clause = new (Mem) OMPReductionClause(
621       StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
622   Clause->setVarRefs(VL);
623   Clause->setPrivates(Privates);
624   Clause->setLHSExprs(LHSExprs);
625   Clause->setRHSExprs(RHSExprs);
626   Clause->setReductionOps(ReductionOps);
627   Clause->setPreInitStmt(PreInit);
628   Clause->setPostUpdateExpr(PostUpdate);
629   return Clause;
630 }
631 
632 OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
633                                                     unsigned N) {
634   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
635   return new (Mem) OMPReductionClause(N);
636 }
637 
638 void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
639   assert(Privates.size() == varlist_size() &&
640          "Number of private copies is not the same as the preallocated buffer");
641   std::copy(Privates.begin(), Privates.end(), varlist_end());
642 }
643 
644 void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
645   assert(
646       LHSExprs.size() == varlist_size() &&
647       "Number of LHS expressions is not the same as the preallocated buffer");
648   std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
649 }
650 
651 void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
652   assert(
653       RHSExprs.size() == varlist_size() &&
654       "Number of RHS expressions is not the same as the preallocated buffer");
655   std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
656 }
657 
658 void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
659   assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
660                                                   "expressions is not the same "
661                                                   "as the preallocated buffer");
662   std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
663 }
664 
665 OMPTaskReductionClause *OMPTaskReductionClause::Create(
666     const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
667     SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
668     NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
669     ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
670     ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
671     Expr *PostUpdate) {
672   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
673   OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
674       StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
675   Clause->setVarRefs(VL);
676   Clause->setPrivates(Privates);
677   Clause->setLHSExprs(LHSExprs);
678   Clause->setRHSExprs(RHSExprs);
679   Clause->setReductionOps(ReductionOps);
680   Clause->setPreInitStmt(PreInit);
681   Clause->setPostUpdateExpr(PostUpdate);
682   return Clause;
683 }
684 
685 OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
686                                                             unsigned N) {
687   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
688   return new (Mem) OMPTaskReductionClause(N);
689 }
690 
691 void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
692   assert(Privates.size() == varlist_size() &&
693          "Number of private copies is not the same as the preallocated buffer");
694   std::copy(Privates.begin(), Privates.end(), varlist_end());
695 }
696 
697 void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
698   assert(
699       LHSExprs.size() == varlist_size() &&
700       "Number of LHS expressions is not the same as the preallocated buffer");
701   std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
702 }
703 
704 void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
705   assert(
706       RHSExprs.size() == varlist_size() &&
707       "Number of RHS expressions is not the same as the preallocated buffer");
708   std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
709 }
710 
711 void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
712   assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
713                                                   "expressions is not the same "
714                                                   "as the preallocated buffer");
715   std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
716 }
717 
718 void OMPInReductionClause::setTaskgroupDescriptors(
719     ArrayRef<Expr *> TaskgroupDescriptors) {
720   assert(TaskgroupDescriptors.size() == varlist_size() &&
721          "Number of in reduction descriptors is not the same as the "
722          "preallocated buffer");
723   std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
724             getReductionOps().end());
725 }
726 
727 OMPInReductionClause *OMPInReductionClause::Create(
728     const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
729     SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
730     NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
731     ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
732     ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
733     ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
734   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
735   OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
736       StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
737   Clause->setVarRefs(VL);
738   Clause->setPrivates(Privates);
739   Clause->setLHSExprs(LHSExprs);
740   Clause->setRHSExprs(RHSExprs);
741   Clause->setReductionOps(ReductionOps);
742   Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
743   Clause->setPreInitStmt(PreInit);
744   Clause->setPostUpdateExpr(PostUpdate);
745   return Clause;
746 }
747 
748 OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
749                                                         unsigned N) {
750   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
751   return new (Mem) OMPInReductionClause(N);
752 }
753 
754 OMPAllocateClause *
755 OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
756                           SourceLocation LParenLoc, Expr *Allocator,
757                           SourceLocation ColonLoc, SourceLocation EndLoc,
758                           ArrayRef<Expr *> VL) {
759   // Allocate space for private variables and initializer expressions.
760   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
761   auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
762                                              ColonLoc, EndLoc, VL.size());
763   Clause->setVarRefs(VL);
764   return Clause;
765 }
766 
767 OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
768                                                   unsigned N) {
769   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
770   return new (Mem) OMPAllocateClause(N);
771 }
772 
773 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
774                                        SourceLocation StartLoc,
775                                        SourceLocation LParenLoc,
776                                        SourceLocation EndLoc,
777                                        ArrayRef<Expr *> VL) {
778   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
779   OMPFlushClause *Clause =
780       new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
781   Clause->setVarRefs(VL);
782   return Clause;
783 }
784 
785 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
786   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
787   return new (Mem) OMPFlushClause(N);
788 }
789 
790 OMPDependClause *
791 OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
792                         SourceLocation LParenLoc, SourceLocation EndLoc,
793                         OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
794                         SourceLocation ColonLoc, ArrayRef<Expr *> VL,
795                         unsigned NumLoops) {
796   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
797   OMPDependClause *Clause = new (Mem)
798       OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
799   Clause->setVarRefs(VL);
800   Clause->setDependencyKind(DepKind);
801   Clause->setDependencyLoc(DepLoc);
802   Clause->setColonLoc(ColonLoc);
803   for (unsigned I = 0 ; I < NumLoops; ++I)
804     Clause->setLoopData(I, nullptr);
805   return Clause;
806 }
807 
808 OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
809                                               unsigned NumLoops) {
810   void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
811   return new (Mem) OMPDependClause(N, NumLoops);
812 }
813 
814 void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
815   assert((getDependencyKind() == OMPC_DEPEND_sink ||
816           getDependencyKind() == OMPC_DEPEND_source) &&
817          NumLoop < NumLoops &&
818          "Expected sink or source depend + loop index must be less number of "
819          "loops.");
820   auto It = std::next(getVarRefs().end(), NumLoop);
821   *It = Cnt;
822 }
823 
824 Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
825   assert((getDependencyKind() == OMPC_DEPEND_sink ||
826           getDependencyKind() == OMPC_DEPEND_source) &&
827          NumLoop < NumLoops &&
828          "Expected sink or source depend + loop index must be less number of "
829          "loops.");
830   auto It = std::next(getVarRefs().end(), NumLoop);
831   return *It;
832 }
833 
834 const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
835   assert((getDependencyKind() == OMPC_DEPEND_sink ||
836           getDependencyKind() == OMPC_DEPEND_source) &&
837          NumLoop < NumLoops &&
838          "Expected sink or source depend + loop index must be less number of "
839          "loops.");
840   auto It = std::next(getVarRefs().end(), NumLoop);
841   return *It;
842 }
843 
844 unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
845     MappableExprComponentListsRef ComponentLists) {
846   unsigned TotalNum = 0u;
847   for (auto &C : ComponentLists)
848     TotalNum += C.size();
849   return TotalNum;
850 }
851 
852 unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
853     ArrayRef<const ValueDecl *> Declarations) {
854   unsigned TotalNum = 0u;
855   llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
856   for (const ValueDecl *D : Declarations) {
857     const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
858     if (Cache.count(VD))
859       continue;
860     ++TotalNum;
861     Cache.insert(VD);
862   }
863   return TotalNum;
864 }
865 
866 OMPMapClause *OMPMapClause::Create(
867     const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
868     ArrayRef<ValueDecl *> Declarations,
869     MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
870     ArrayRef<OpenMPMapModifierKind> MapModifiers,
871     ArrayRef<SourceLocation> MapModifiersLoc,
872     NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
873     OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
874   OMPMappableExprListSizeTy Sizes;
875   Sizes.NumVars = Vars.size();
876   Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
877   Sizes.NumComponentLists = ComponentLists.size();
878   Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
879 
880   // We need to allocate:
881   // 2 x NumVars x Expr* - we have an original list expression and an associated
882   // user-defined mapper for each clause list entry.
883   // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
884   // with each component list.
885   // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
886   // number of lists for each unique declaration and the size of each component
887   // list.
888   // NumComponents x MappableComponent - the total of all the components in all
889   // the lists.
890   void *Mem = C.Allocate(
891       totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
892                        OMPClauseMappableExprCommon::MappableComponent>(
893           2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
894           Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
895           Sizes.NumComponents));
896   OMPMapClause *Clause = new (Mem)
897       OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
898                    Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
899 
900   Clause->setVarRefs(Vars);
901   Clause->setUDMapperRefs(UDMapperRefs);
902   Clause->setClauseInfo(Declarations, ComponentLists);
903   Clause->setMapType(Type);
904   Clause->setMapLoc(TypeLoc);
905   return Clause;
906 }
907 
908 OMPMapClause *
909 OMPMapClause::CreateEmpty(const ASTContext &C,
910                           const OMPMappableExprListSizeTy &Sizes) {
911   void *Mem = C.Allocate(
912       totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
913                        OMPClauseMappableExprCommon::MappableComponent>(
914           2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
915           Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
916           Sizes.NumComponents));
917   return new (Mem) OMPMapClause(Sizes);
918 }
919 
920 OMPToClause *OMPToClause::Create(
921     const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
922     ArrayRef<ValueDecl *> Declarations,
923     MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
924     NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
925   OMPMappableExprListSizeTy Sizes;
926   Sizes.NumVars = Vars.size();
927   Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
928   Sizes.NumComponentLists = ComponentLists.size();
929   Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
930 
931   // We need to allocate:
932   // 2 x NumVars x Expr* - we have an original list expression and an associated
933   // user-defined mapper for each clause list entry.
934   // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
935   // with each component list.
936   // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
937   // number of lists for each unique declaration and the size of each component
938   // list.
939   // NumComponents x MappableComponent - the total of all the components in all
940   // the lists.
941   void *Mem = C.Allocate(
942       totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
943                        OMPClauseMappableExprCommon::MappableComponent>(
944           2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
945           Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
946           Sizes.NumComponents));
947 
948   auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
949 
950   Clause->setVarRefs(Vars);
951   Clause->setUDMapperRefs(UDMapperRefs);
952   Clause->setClauseInfo(Declarations, ComponentLists);
953   return Clause;
954 }
955 
956 OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
957                                       const OMPMappableExprListSizeTy &Sizes) {
958   void *Mem = C.Allocate(
959       totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
960                        OMPClauseMappableExprCommon::MappableComponent>(
961           2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
962           Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
963           Sizes.NumComponents));
964   return new (Mem) OMPToClause(Sizes);
965 }
966 
967 OMPFromClause *OMPFromClause::Create(
968     const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
969     ArrayRef<ValueDecl *> Declarations,
970     MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
971     NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
972   OMPMappableExprListSizeTy Sizes;
973   Sizes.NumVars = Vars.size();
974   Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
975   Sizes.NumComponentLists = ComponentLists.size();
976   Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
977 
978   // We need to allocate:
979   // 2 x NumVars x Expr* - we have an original list expression and an associated
980   // user-defined mapper for each clause list entry.
981   // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
982   // with each component list.
983   // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
984   // number of lists for each unique declaration and the size of each component
985   // list.
986   // NumComponents x MappableComponent - the total of all the components in all
987   // the lists.
988   void *Mem = C.Allocate(
989       totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
990                        OMPClauseMappableExprCommon::MappableComponent>(
991           2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
992           Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
993           Sizes.NumComponents));
994 
995   auto *Clause =
996       new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
997 
998   Clause->setVarRefs(Vars);
999   Clause->setUDMapperRefs(UDMapperRefs);
1000   Clause->setClauseInfo(Declarations, ComponentLists);
1001   return Clause;
1002 }
1003 
1004 OMPFromClause *
1005 OMPFromClause::CreateEmpty(const ASTContext &C,
1006                            const OMPMappableExprListSizeTy &Sizes) {
1007   void *Mem = C.Allocate(
1008       totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1009                        OMPClauseMappableExprCommon::MappableComponent>(
1010           2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1011           Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1012           Sizes.NumComponents));
1013   return new (Mem) OMPFromClause(Sizes);
1014 }
1015 
1016 void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1017   assert(VL.size() == varlist_size() &&
1018          "Number of private copies is not the same as the preallocated buffer");
1019   std::copy(VL.begin(), VL.end(), varlist_end());
1020 }
1021 
1022 void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1023   assert(VL.size() == varlist_size() &&
1024          "Number of inits is not the same as the preallocated buffer");
1025   std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1026 }
1027 
1028 OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
1029     const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1030     ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1031     ArrayRef<ValueDecl *> Declarations,
1032     MappableExprComponentListsRef ComponentLists) {
1033   OMPMappableExprListSizeTy Sizes;
1034   Sizes.NumVars = Vars.size();
1035   Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1036   Sizes.NumComponentLists = ComponentLists.size();
1037   Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1038 
1039   // We need to allocate:
1040   // 3 x NumVars x Expr* - we have an original list expression for each clause
1041   // list entry and an equal number of private copies and inits.
1042   // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1043   // with each component list.
1044   // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1045   // number of lists for each unique declaration and the size of each component
1046   // list.
1047   // NumComponents x MappableComponent - the total of all the components in all
1048   // the lists.
1049   void *Mem = C.Allocate(
1050       totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1051                        OMPClauseMappableExprCommon::MappableComponent>(
1052           3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1053           Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1054           Sizes.NumComponents));
1055 
1056   OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
1057 
1058   Clause->setVarRefs(Vars);
1059   Clause->setPrivateCopies(PrivateVars);
1060   Clause->setInits(Inits);
1061   Clause->setClauseInfo(Declarations, ComponentLists);
1062   return Clause;
1063 }
1064 
1065 OMPUseDevicePtrClause *
1066 OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1067                                    const OMPMappableExprListSizeTy &Sizes) {
1068   void *Mem = C.Allocate(
1069       totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1070                        OMPClauseMappableExprCommon::MappableComponent>(
1071           3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1072           Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1073           Sizes.NumComponents));
1074   return new (Mem) OMPUseDevicePtrClause(Sizes);
1075 }
1076 
1077 OMPIsDevicePtrClause *
1078 OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
1079                              ArrayRef<Expr *> Vars,
1080                              ArrayRef<ValueDecl *> Declarations,
1081                              MappableExprComponentListsRef ComponentLists) {
1082   OMPMappableExprListSizeTy Sizes;
1083   Sizes.NumVars = Vars.size();
1084   Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1085   Sizes.NumComponentLists = ComponentLists.size();
1086   Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1087 
1088   // We need to allocate:
1089   // NumVars x Expr* - we have an original list expression for each clause list
1090   // entry.
1091   // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1092   // with each component list.
1093   // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1094   // number of lists for each unique declaration and the size of each component
1095   // list.
1096   // NumComponents x MappableComponent - the total of all the components in all
1097   // the lists.
1098   void *Mem = C.Allocate(
1099       totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1100                        OMPClauseMappableExprCommon::MappableComponent>(
1101           Sizes.NumVars, Sizes.NumUniqueDeclarations,
1102           Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1103           Sizes.NumComponents));
1104 
1105   OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
1106 
1107   Clause->setVarRefs(Vars);
1108   Clause->setClauseInfo(Declarations, ComponentLists);
1109   return Clause;
1110 }
1111 
1112 OMPIsDevicePtrClause *
1113 OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1114                                   const OMPMappableExprListSizeTy &Sizes) {
1115   void *Mem = C.Allocate(
1116       totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1117                        OMPClauseMappableExprCommon::MappableComponent>(
1118           Sizes.NumVars, Sizes.NumUniqueDeclarations,
1119           Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1120           Sizes.NumComponents));
1121   return new (Mem) OMPIsDevicePtrClause(Sizes);
1122 }
1123 
1124 //===----------------------------------------------------------------------===//
1125 //  OpenMP clauses printing methods
1126 //===----------------------------------------------------------------------===//
1127 
1128 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1129   OS << "if(";
1130   if (Node->getNameModifier() != OMPD_unknown)
1131     OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1132   Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1133   OS << ")";
1134 }
1135 
1136 void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1137   OS << "final(";
1138   Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1139   OS << ")";
1140 }
1141 
1142 void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1143   OS << "num_threads(";
1144   Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1145   OS << ")";
1146 }
1147 
1148 void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1149   OS << "safelen(";
1150   Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1151   OS << ")";
1152 }
1153 
1154 void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1155   OS << "simdlen(";
1156   Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1157   OS << ")";
1158 }
1159 
1160 void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1161   OS << "allocator(";
1162   Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1163   OS << ")";
1164 }
1165 
1166 void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1167   OS << "collapse(";
1168   Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1169   OS << ")";
1170 }
1171 
1172 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1173   OS << "default("
1174      << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
1175      << ")";
1176 }
1177 
1178 void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1179   OS << "proc_bind("
1180      << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
1181      << ")";
1182 }
1183 
1184 void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1185   OS << "unified_address";
1186 }
1187 
1188 void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1189     OMPUnifiedSharedMemoryClause *) {
1190   OS << "unified_shared_memory";
1191 }
1192 
1193 void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1194   OS << "reverse_offload";
1195 }
1196 
1197 void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1198     OMPDynamicAllocatorsClause *) {
1199   OS << "dynamic_allocators";
1200 }
1201 
1202 void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1203     OMPAtomicDefaultMemOrderClause *Node) {
1204   OS << "atomic_default_mem_order("
1205      << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1206                                       Node->getAtomicDefaultMemOrderKind())
1207      << ")";
1208 }
1209 
1210 void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1211   OS << "schedule(";
1212   if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1213     OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1214                                         Node->getFirstScheduleModifier());
1215     if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1216       OS << ", ";
1217       OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1218                                           Node->getSecondScheduleModifier());
1219     }
1220     OS << ": ";
1221   }
1222   OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1223   if (auto *E = Node->getChunkSize()) {
1224     OS << ", ";
1225     E->printPretty(OS, nullptr, Policy);
1226   }
1227   OS << ")";
1228 }
1229 
1230 void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1231   OS << "ordered";
1232   if (auto *Num = Node->getNumForLoops()) {
1233     OS << "(";
1234     Num->printPretty(OS, nullptr, Policy, 0);
1235     OS << ")";
1236   }
1237 }
1238 
1239 void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1240   OS << "nowait";
1241 }
1242 
1243 void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1244   OS << "untied";
1245 }
1246 
1247 void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1248   OS << "nogroup";
1249 }
1250 
1251 void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1252   OS << "mergeable";
1253 }
1254 
1255 void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1256 
1257 void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1258 
1259 void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1260   OS << "update";
1261 }
1262 
1263 void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1264   OS << "capture";
1265 }
1266 
1267 void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1268   OS << "seq_cst";
1269 }
1270 
1271 void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1272   OS << "threads";
1273 }
1274 
1275 void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1276 
1277 void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1278   OS << "device(";
1279   Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1280   OS << ")";
1281 }
1282 
1283 void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1284   OS << "num_teams(";
1285   Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1286   OS << ")";
1287 }
1288 
1289 void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1290   OS << "thread_limit(";
1291   Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1292   OS << ")";
1293 }
1294 
1295 void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1296   OS << "priority(";
1297   Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1298   OS << ")";
1299 }
1300 
1301 void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1302   OS << "grainsize(";
1303   Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1304   OS << ")";
1305 }
1306 
1307 void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1308   OS << "num_tasks(";
1309   Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1310   OS << ")";
1311 }
1312 
1313 void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1314   OS << "hint(";
1315   Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1316   OS << ")";
1317 }
1318 
1319 template<typename T>
1320 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1321   for (typename T::varlist_iterator I = Node->varlist_begin(),
1322                                     E = Node->varlist_end();
1323        I != E; ++I) {
1324     assert(*I && "Expected non-null Stmt");
1325     OS << (I == Node->varlist_begin() ? StartSym : ',');
1326     if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1327       if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1328         DRE->printPretty(OS, nullptr, Policy, 0);
1329       else
1330         DRE->getDecl()->printQualifiedName(OS);
1331     } else
1332       (*I)->printPretty(OS, nullptr, Policy, 0);
1333   }
1334 }
1335 
1336 void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1337   if (Node->varlist_empty())
1338     return;
1339   OS << "allocate";
1340   if (Expr *Allocator = Node->getAllocator()) {
1341     OS << "(";
1342     Allocator->printPretty(OS, nullptr, Policy, 0);
1343     OS << ":";
1344     VisitOMPClauseList(Node, ' ');
1345   } else {
1346     VisitOMPClauseList(Node, '(');
1347   }
1348   OS << ")";
1349 }
1350 
1351 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1352   if (!Node->varlist_empty()) {
1353     OS << "private";
1354     VisitOMPClauseList(Node, '(');
1355     OS << ")";
1356   }
1357 }
1358 
1359 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1360   if (!Node->varlist_empty()) {
1361     OS << "firstprivate";
1362     VisitOMPClauseList(Node, '(');
1363     OS << ")";
1364   }
1365 }
1366 
1367 void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1368   if (!Node->varlist_empty()) {
1369     OS << "lastprivate";
1370     VisitOMPClauseList(Node, '(');
1371     OS << ")";
1372   }
1373 }
1374 
1375 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1376   if (!Node->varlist_empty()) {
1377     OS << "shared";
1378     VisitOMPClauseList(Node, '(');
1379     OS << ")";
1380   }
1381 }
1382 
1383 void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1384   if (!Node->varlist_empty()) {
1385     OS << "reduction(";
1386     NestedNameSpecifier *QualifierLoc =
1387         Node->getQualifierLoc().getNestedNameSpecifier();
1388     OverloadedOperatorKind OOK =
1389         Node->getNameInfo().getName().getCXXOverloadedOperator();
1390     if (QualifierLoc == nullptr && OOK != OO_None) {
1391       // Print reduction identifier in C format
1392       OS << getOperatorSpelling(OOK);
1393     } else {
1394       // Use C++ format
1395       if (QualifierLoc != nullptr)
1396         QualifierLoc->print(OS, Policy);
1397       OS << Node->getNameInfo();
1398     }
1399     OS << ":";
1400     VisitOMPClauseList(Node, ' ');
1401     OS << ")";
1402   }
1403 }
1404 
1405 void OMPClausePrinter::VisitOMPTaskReductionClause(
1406     OMPTaskReductionClause *Node) {
1407   if (!Node->varlist_empty()) {
1408     OS << "task_reduction(";
1409     NestedNameSpecifier *QualifierLoc =
1410         Node->getQualifierLoc().getNestedNameSpecifier();
1411     OverloadedOperatorKind OOK =
1412         Node->getNameInfo().getName().getCXXOverloadedOperator();
1413     if (QualifierLoc == nullptr && OOK != OO_None) {
1414       // Print reduction identifier in C format
1415       OS << getOperatorSpelling(OOK);
1416     } else {
1417       // Use C++ format
1418       if (QualifierLoc != nullptr)
1419         QualifierLoc->print(OS, Policy);
1420       OS << Node->getNameInfo();
1421     }
1422     OS << ":";
1423     VisitOMPClauseList(Node, ' ');
1424     OS << ")";
1425   }
1426 }
1427 
1428 void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1429   if (!Node->varlist_empty()) {
1430     OS << "in_reduction(";
1431     NestedNameSpecifier *QualifierLoc =
1432         Node->getQualifierLoc().getNestedNameSpecifier();
1433     OverloadedOperatorKind OOK =
1434         Node->getNameInfo().getName().getCXXOverloadedOperator();
1435     if (QualifierLoc == nullptr && OOK != OO_None) {
1436       // Print reduction identifier in C format
1437       OS << getOperatorSpelling(OOK);
1438     } else {
1439       // Use C++ format
1440       if (QualifierLoc != nullptr)
1441         QualifierLoc->print(OS, Policy);
1442       OS << Node->getNameInfo();
1443     }
1444     OS << ":";
1445     VisitOMPClauseList(Node, ' ');
1446     OS << ")";
1447   }
1448 }
1449 
1450 void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1451   if (!Node->varlist_empty()) {
1452     OS << "linear";
1453     if (Node->getModifierLoc().isValid()) {
1454       OS << '('
1455          << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1456     }
1457     VisitOMPClauseList(Node, '(');
1458     if (Node->getModifierLoc().isValid())
1459       OS << ')';
1460     if (Node->getStep() != nullptr) {
1461       OS << ": ";
1462       Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1463     }
1464     OS << ")";
1465   }
1466 }
1467 
1468 void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1469   if (!Node->varlist_empty()) {
1470     OS << "aligned";
1471     VisitOMPClauseList(Node, '(');
1472     if (Node->getAlignment() != nullptr) {
1473       OS << ": ";
1474       Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1475     }
1476     OS << ")";
1477   }
1478 }
1479 
1480 void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1481   if (!Node->varlist_empty()) {
1482     OS << "copyin";
1483     VisitOMPClauseList(Node, '(');
1484     OS << ")";
1485   }
1486 }
1487 
1488 void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1489   if (!Node->varlist_empty()) {
1490     OS << "copyprivate";
1491     VisitOMPClauseList(Node, '(');
1492     OS << ")";
1493   }
1494 }
1495 
1496 void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1497   if (!Node->varlist_empty()) {
1498     VisitOMPClauseList(Node, '(');
1499     OS << ")";
1500   }
1501 }
1502 
1503 void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1504   OS << "depend(";
1505   OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1506                                       Node->getDependencyKind());
1507   if (!Node->varlist_empty()) {
1508     OS << " :";
1509     VisitOMPClauseList(Node, ' ');
1510   }
1511   OS << ")";
1512 }
1513 
1514 void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1515   if (!Node->varlist_empty()) {
1516     OS << "map(";
1517     if (Node->getMapType() != OMPC_MAP_unknown) {
1518       for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) {
1519         if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1520           OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1521                                               Node->getMapTypeModifier(I));
1522           if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1523             OS << '(';
1524             NestedNameSpecifier *MapperNNS =
1525                 Node->getMapperQualifierLoc().getNestedNameSpecifier();
1526             if (MapperNNS)
1527               MapperNNS->print(OS, Policy);
1528             OS << Node->getMapperIdInfo() << ')';
1529           }
1530           OS << ',';
1531         }
1532       }
1533       OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1534       OS << ':';
1535     }
1536     VisitOMPClauseList(Node, ' ');
1537     OS << ")";
1538   }
1539 }
1540 
1541 void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1542   if (!Node->varlist_empty()) {
1543     OS << "to";
1544     DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1545     if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1546       OS << '(';
1547       OS << "mapper(";
1548       NestedNameSpecifier *MapperNNS =
1549           Node->getMapperQualifierLoc().getNestedNameSpecifier();
1550       if (MapperNNS)
1551         MapperNNS->print(OS, Policy);
1552       OS << MapperId << "):";
1553       VisitOMPClauseList(Node, ' ');
1554     } else {
1555       VisitOMPClauseList(Node, '(');
1556     }
1557     OS << ")";
1558   }
1559 }
1560 
1561 void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1562   if (!Node->varlist_empty()) {
1563     OS << "from";
1564     DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1565     if (MapperId.getName() && !MapperId.getName().isEmpty()) {
1566       OS << '(';
1567       OS << "mapper(";
1568       NestedNameSpecifier *MapperNNS =
1569           Node->getMapperQualifierLoc().getNestedNameSpecifier();
1570       if (MapperNNS)
1571         MapperNNS->print(OS, Policy);
1572       OS << MapperId << "):";
1573       VisitOMPClauseList(Node, ' ');
1574     } else {
1575       VisitOMPClauseList(Node, '(');
1576     }
1577     OS << ")";
1578   }
1579 }
1580 
1581 void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1582   OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1583                            OMPC_dist_schedule, Node->getDistScheduleKind());
1584   if (auto *E = Node->getChunkSize()) {
1585     OS << ", ";
1586     E->printPretty(OS, nullptr, Policy);
1587   }
1588   OS << ")";
1589 }
1590 
1591 void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1592   OS << "defaultmap(";
1593   OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1594                                       Node->getDefaultmapModifier());
1595   OS << ": ";
1596   OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1597     Node->getDefaultmapKind());
1598   OS << ")";
1599 }
1600 
1601 void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1602   if (!Node->varlist_empty()) {
1603     OS << "use_device_ptr";
1604     VisitOMPClauseList(Node, '(');
1605     OS << ")";
1606   }
1607 }
1608 
1609 void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1610   if (!Node->varlist_empty()) {
1611     OS << "is_device_ptr";
1612     VisitOMPClauseList(Node, '(');
1613     OS << ")";
1614   }
1615 }
1616 
1617