1 //===--- StmtOpenMP.cpp - Classes for OpenMP directives -------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the subclesses of Stmt class declared in StmtOpenMP.h
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/StmtOpenMP.h"
15 
16 #include "clang/AST/ASTContext.h"
17 
18 using namespace clang;
19 
20 void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) {
21   assert(Clauses.size() == getNumClauses() &&
22          "Number of clauses is not the same as the preallocated buffer");
23   std::copy(Clauses.begin(), Clauses.end(), getClauses().begin());
24 }
25 
26 void OMPLoopDirective::setCounters(ArrayRef<Expr *> A) {
27   assert(A.size() == getCollapsedNumber() &&
28          "Number of loop counters is not the same as the collapsed number");
29   std::copy(A.begin(), A.end(), getCounters().begin());
30 }
31 
32 void OMPLoopDirective::setPrivateCounters(ArrayRef<Expr *> A) {
33   assert(A.size() == getCollapsedNumber() && "Number of loop private counters "
34                                              "is not the same as the collapsed "
35                                              "number");
36   std::copy(A.begin(), A.end(), getPrivateCounters().begin());
37 }
38 
39 void OMPLoopDirective::setInits(ArrayRef<Expr *> A) {
40   assert(A.size() == getCollapsedNumber() &&
41          "Number of counter inits is not the same as the collapsed number");
42   std::copy(A.begin(), A.end(), getInits().begin());
43 }
44 
45 void OMPLoopDirective::setUpdates(ArrayRef<Expr *> A) {
46   assert(A.size() == getCollapsedNumber() &&
47          "Number of counter updates is not the same as the collapsed number");
48   std::copy(A.begin(), A.end(), getUpdates().begin());
49 }
50 
51 void OMPLoopDirective::setFinals(ArrayRef<Expr *> A) {
52   assert(A.size() == getCollapsedNumber() &&
53          "Number of counter finals is not the same as the collapsed number");
54   std::copy(A.begin(), A.end(), getFinals().begin());
55 }
56 
57 OMPParallelDirective *OMPParallelDirective::Create(
58     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
59     ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, bool HasCancel) {
60   unsigned Size =
61       llvm::alignTo(sizeof(OMPParallelDirective), llvm::alignOf<OMPClause *>());
62   void *Mem =
63       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
64   OMPParallelDirective *Dir =
65       new (Mem) OMPParallelDirective(StartLoc, EndLoc, Clauses.size());
66   Dir->setClauses(Clauses);
67   Dir->setAssociatedStmt(AssociatedStmt);
68   Dir->setHasCancel(HasCancel);
69   return Dir;
70 }
71 
72 OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C,
73                                                         unsigned NumClauses,
74                                                         EmptyShell) {
75   unsigned Size =
76       llvm::alignTo(sizeof(OMPParallelDirective), llvm::alignOf<OMPClause *>());
77   void *Mem =
78       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
79   return new (Mem) OMPParallelDirective(NumClauses);
80 }
81 
82 OMPSimdDirective *
83 OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc,
84                          SourceLocation EndLoc, unsigned CollapsedNum,
85                          ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
86                          const HelperExprs &Exprs) {
87   unsigned Size =
88       llvm::alignTo(sizeof(OMPSimdDirective), llvm::alignOf<OMPClause *>());
89   void *Mem =
90       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
91                  sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd));
92   OMPSimdDirective *Dir = new (Mem)
93       OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
94   Dir->setClauses(Clauses);
95   Dir->setAssociatedStmt(AssociatedStmt);
96   Dir->setIterationVariable(Exprs.IterationVarRef);
97   Dir->setLastIteration(Exprs.LastIteration);
98   Dir->setCalcLastIteration(Exprs.CalcLastIteration);
99   Dir->setPreCond(Exprs.PreCond);
100   Dir->setCond(Exprs.Cond);
101   Dir->setInit(Exprs.Init);
102   Dir->setInc(Exprs.Inc);
103   Dir->setCounters(Exprs.Counters);
104   Dir->setPrivateCounters(Exprs.PrivateCounters);
105   Dir->setInits(Exprs.Inits);
106   Dir->setUpdates(Exprs.Updates);
107   Dir->setFinals(Exprs.Finals);
108   Dir->setPreInits(Exprs.PreInits);
109   return Dir;
110 }
111 
112 OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C,
113                                                 unsigned NumClauses,
114                                                 unsigned CollapsedNum,
115                                                 EmptyShell) {
116   unsigned Size =
117       llvm::alignTo(sizeof(OMPSimdDirective), llvm::alignOf<OMPClause *>());
118   void *Mem =
119       C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
120                  sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd));
121   return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses);
122 }
123 
124 OMPForDirective *
125 OMPForDirective::Create(const ASTContext &C, SourceLocation StartLoc,
126                         SourceLocation EndLoc, unsigned CollapsedNum,
127                         ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
128                         const HelperExprs &Exprs, bool HasCancel) {
129   unsigned Size =
130       llvm::alignTo(sizeof(OMPForDirective), llvm::alignOf<OMPClause *>());
131   void *Mem =
132       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
133                  sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for));
134   OMPForDirective *Dir =
135       new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
136   Dir->setClauses(Clauses);
137   Dir->setAssociatedStmt(AssociatedStmt);
138   Dir->setIterationVariable(Exprs.IterationVarRef);
139   Dir->setLastIteration(Exprs.LastIteration);
140   Dir->setCalcLastIteration(Exprs.CalcLastIteration);
141   Dir->setPreCond(Exprs.PreCond);
142   Dir->setCond(Exprs.Cond);
143   Dir->setInit(Exprs.Init);
144   Dir->setInc(Exprs.Inc);
145   Dir->setIsLastIterVariable(Exprs.IL);
146   Dir->setLowerBoundVariable(Exprs.LB);
147   Dir->setUpperBoundVariable(Exprs.UB);
148   Dir->setStrideVariable(Exprs.ST);
149   Dir->setEnsureUpperBound(Exprs.EUB);
150   Dir->setNextLowerBound(Exprs.NLB);
151   Dir->setNextUpperBound(Exprs.NUB);
152   Dir->setCounters(Exprs.Counters);
153   Dir->setPrivateCounters(Exprs.PrivateCounters);
154   Dir->setInits(Exprs.Inits);
155   Dir->setUpdates(Exprs.Updates);
156   Dir->setFinals(Exprs.Finals);
157   Dir->setPreInits(Exprs.PreInits);
158   Dir->setHasCancel(HasCancel);
159   return Dir;
160 }
161 
162 OMPForDirective *OMPForDirective::CreateEmpty(const ASTContext &C,
163                                               unsigned NumClauses,
164                                               unsigned CollapsedNum,
165                                               EmptyShell) {
166   unsigned Size =
167       llvm::alignTo(sizeof(OMPForDirective), llvm::alignOf<OMPClause *>());
168   void *Mem =
169       C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
170                  sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for));
171   return new (Mem) OMPForDirective(CollapsedNum, NumClauses);
172 }
173 
174 OMPForSimdDirective *
175 OMPForSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc,
176                             SourceLocation EndLoc, unsigned CollapsedNum,
177                             ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
178                             const HelperExprs &Exprs) {
179   unsigned Size =
180       llvm::alignTo(sizeof(OMPForSimdDirective), llvm::alignOf<OMPClause *>());
181   void *Mem =
182       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
183                  sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd));
184   OMPForSimdDirective *Dir = new (Mem)
185       OMPForSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
186   Dir->setClauses(Clauses);
187   Dir->setAssociatedStmt(AssociatedStmt);
188   Dir->setIterationVariable(Exprs.IterationVarRef);
189   Dir->setLastIteration(Exprs.LastIteration);
190   Dir->setCalcLastIteration(Exprs.CalcLastIteration);
191   Dir->setPreCond(Exprs.PreCond);
192   Dir->setCond(Exprs.Cond);
193   Dir->setInit(Exprs.Init);
194   Dir->setInc(Exprs.Inc);
195   Dir->setIsLastIterVariable(Exprs.IL);
196   Dir->setLowerBoundVariable(Exprs.LB);
197   Dir->setUpperBoundVariable(Exprs.UB);
198   Dir->setStrideVariable(Exprs.ST);
199   Dir->setEnsureUpperBound(Exprs.EUB);
200   Dir->setNextLowerBound(Exprs.NLB);
201   Dir->setNextUpperBound(Exprs.NUB);
202   Dir->setCounters(Exprs.Counters);
203   Dir->setPrivateCounters(Exprs.PrivateCounters);
204   Dir->setInits(Exprs.Inits);
205   Dir->setUpdates(Exprs.Updates);
206   Dir->setFinals(Exprs.Finals);
207   Dir->setPreInits(Exprs.PreInits);
208   return Dir;
209 }
210 
211 OMPForSimdDirective *OMPForSimdDirective::CreateEmpty(const ASTContext &C,
212                                                       unsigned NumClauses,
213                                                       unsigned CollapsedNum,
214                                                       EmptyShell) {
215   unsigned Size =
216       llvm::alignTo(sizeof(OMPForSimdDirective), llvm::alignOf<OMPClause *>());
217   void *Mem =
218       C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
219                  sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd));
220   return new (Mem) OMPForSimdDirective(CollapsedNum, NumClauses);
221 }
222 
223 OMPSectionsDirective *OMPSectionsDirective::Create(
224     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
225     ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, bool HasCancel) {
226   unsigned Size =
227       llvm::alignTo(sizeof(OMPSectionsDirective), llvm::alignOf<OMPClause *>());
228   void *Mem =
229       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
230   OMPSectionsDirective *Dir =
231       new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size());
232   Dir->setClauses(Clauses);
233   Dir->setAssociatedStmt(AssociatedStmt);
234   Dir->setHasCancel(HasCancel);
235   return Dir;
236 }
237 
238 OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C,
239                                                         unsigned NumClauses,
240                                                         EmptyShell) {
241   unsigned Size =
242       llvm::alignTo(sizeof(OMPSectionsDirective), llvm::alignOf<OMPClause *>());
243   void *Mem =
244       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
245   return new (Mem) OMPSectionsDirective(NumClauses);
246 }
247 
248 OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C,
249                                                  SourceLocation StartLoc,
250                                                  SourceLocation EndLoc,
251                                                  Stmt *AssociatedStmt,
252                                                  bool HasCancel) {
253   unsigned Size =
254       llvm::alignTo(sizeof(OMPSectionDirective), llvm::alignOf<Stmt *>());
255   void *Mem = C.Allocate(Size + sizeof(Stmt *));
256   OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc);
257   Dir->setAssociatedStmt(AssociatedStmt);
258   Dir->setHasCancel(HasCancel);
259   return Dir;
260 }
261 
262 OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C,
263                                                       EmptyShell) {
264   unsigned Size =
265       llvm::alignTo(sizeof(OMPSectionDirective), llvm::alignOf<Stmt *>());
266   void *Mem = C.Allocate(Size + sizeof(Stmt *));
267   return new (Mem) OMPSectionDirective();
268 }
269 
270 OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C,
271                                                SourceLocation StartLoc,
272                                                SourceLocation EndLoc,
273                                                ArrayRef<OMPClause *> Clauses,
274                                                Stmt *AssociatedStmt) {
275   unsigned Size =
276       llvm::alignTo(sizeof(OMPSingleDirective), llvm::alignOf<OMPClause *>());
277   void *Mem =
278       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
279   OMPSingleDirective *Dir =
280       new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size());
281   Dir->setClauses(Clauses);
282   Dir->setAssociatedStmt(AssociatedStmt);
283   return Dir;
284 }
285 
286 OMPSingleDirective *OMPSingleDirective::CreateEmpty(const ASTContext &C,
287                                                     unsigned NumClauses,
288                                                     EmptyShell) {
289   unsigned Size =
290       llvm::alignTo(sizeof(OMPSingleDirective), llvm::alignOf<OMPClause *>());
291   void *Mem =
292       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
293   return new (Mem) OMPSingleDirective(NumClauses);
294 }
295 
296 OMPMasterDirective *OMPMasterDirective::Create(const ASTContext &C,
297                                                SourceLocation StartLoc,
298                                                SourceLocation EndLoc,
299                                                Stmt *AssociatedStmt) {
300   unsigned Size =
301       llvm::alignTo(sizeof(OMPMasterDirective), llvm::alignOf<Stmt *>());
302   void *Mem = C.Allocate(Size + sizeof(Stmt *));
303   OMPMasterDirective *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc);
304   Dir->setAssociatedStmt(AssociatedStmt);
305   return Dir;
306 }
307 
308 OMPMasterDirective *OMPMasterDirective::CreateEmpty(const ASTContext &C,
309                                                     EmptyShell) {
310   unsigned Size =
311       llvm::alignTo(sizeof(OMPMasterDirective), llvm::alignOf<Stmt *>());
312   void *Mem = C.Allocate(Size + sizeof(Stmt *));
313   return new (Mem) OMPMasterDirective();
314 }
315 
316 OMPCriticalDirective *OMPCriticalDirective::Create(
317     const ASTContext &C, const DeclarationNameInfo &Name,
318     SourceLocation StartLoc, SourceLocation EndLoc,
319     ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
320   unsigned Size =
321       llvm::alignTo(sizeof(OMPCriticalDirective), llvm::alignOf<OMPClause *>());
322   void *Mem =
323       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
324   OMPCriticalDirective *Dir =
325       new (Mem) OMPCriticalDirective(Name, StartLoc, EndLoc, Clauses.size());
326   Dir->setClauses(Clauses);
327   Dir->setAssociatedStmt(AssociatedStmt);
328   return Dir;
329 }
330 
331 OMPCriticalDirective *OMPCriticalDirective::CreateEmpty(const ASTContext &C,
332                                                         unsigned NumClauses,
333                                                         EmptyShell) {
334   unsigned Size =
335       llvm::alignTo(sizeof(OMPCriticalDirective), llvm::alignOf<OMPClause *>());
336   void *Mem =
337       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
338   return new (Mem) OMPCriticalDirective(NumClauses);
339 }
340 
341 OMPParallelForDirective *OMPParallelForDirective::Create(
342     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
343     unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
344     const HelperExprs &Exprs, bool HasCancel) {
345   unsigned Size = llvm::alignTo(sizeof(OMPParallelForDirective),
346                                 llvm::alignOf<OMPClause *>());
347   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
348                          sizeof(Stmt *) *
349                              numLoopChildren(CollapsedNum, OMPD_parallel_for));
350   OMPParallelForDirective *Dir = new (Mem)
351       OMPParallelForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
352   Dir->setClauses(Clauses);
353   Dir->setAssociatedStmt(AssociatedStmt);
354   Dir->setIterationVariable(Exprs.IterationVarRef);
355   Dir->setLastIteration(Exprs.LastIteration);
356   Dir->setCalcLastIteration(Exprs.CalcLastIteration);
357   Dir->setPreCond(Exprs.PreCond);
358   Dir->setCond(Exprs.Cond);
359   Dir->setInit(Exprs.Init);
360   Dir->setInc(Exprs.Inc);
361   Dir->setIsLastIterVariable(Exprs.IL);
362   Dir->setLowerBoundVariable(Exprs.LB);
363   Dir->setUpperBoundVariable(Exprs.UB);
364   Dir->setStrideVariable(Exprs.ST);
365   Dir->setEnsureUpperBound(Exprs.EUB);
366   Dir->setNextLowerBound(Exprs.NLB);
367   Dir->setNextUpperBound(Exprs.NUB);
368   Dir->setCounters(Exprs.Counters);
369   Dir->setPrivateCounters(Exprs.PrivateCounters);
370   Dir->setInits(Exprs.Inits);
371   Dir->setUpdates(Exprs.Updates);
372   Dir->setFinals(Exprs.Finals);
373   Dir->setPreInits(Exprs.PreInits);
374   Dir->setHasCancel(HasCancel);
375   return Dir;
376 }
377 
378 OMPParallelForDirective *
379 OMPParallelForDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses,
380                                      unsigned CollapsedNum, EmptyShell) {
381   unsigned Size = llvm::alignTo(sizeof(OMPParallelForDirective),
382                                 llvm::alignOf<OMPClause *>());
383   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
384                          sizeof(Stmt *) *
385                              numLoopChildren(CollapsedNum, OMPD_parallel_for));
386   return new (Mem) OMPParallelForDirective(CollapsedNum, NumClauses);
387 }
388 
389 OMPParallelForSimdDirective *OMPParallelForSimdDirective::Create(
390     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
391     unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
392     const HelperExprs &Exprs) {
393   unsigned Size = llvm::alignTo(sizeof(OMPParallelForSimdDirective),
394                                 llvm::alignOf<OMPClause *>());
395   void *Mem = C.Allocate(
396       Size + sizeof(OMPClause *) * Clauses.size() +
397       sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd));
398   OMPParallelForSimdDirective *Dir = new (Mem) OMPParallelForSimdDirective(
399       StartLoc, EndLoc, CollapsedNum, Clauses.size());
400   Dir->setClauses(Clauses);
401   Dir->setAssociatedStmt(AssociatedStmt);
402   Dir->setIterationVariable(Exprs.IterationVarRef);
403   Dir->setLastIteration(Exprs.LastIteration);
404   Dir->setCalcLastIteration(Exprs.CalcLastIteration);
405   Dir->setPreCond(Exprs.PreCond);
406   Dir->setCond(Exprs.Cond);
407   Dir->setInit(Exprs.Init);
408   Dir->setInc(Exprs.Inc);
409   Dir->setIsLastIterVariable(Exprs.IL);
410   Dir->setLowerBoundVariable(Exprs.LB);
411   Dir->setUpperBoundVariable(Exprs.UB);
412   Dir->setStrideVariable(Exprs.ST);
413   Dir->setEnsureUpperBound(Exprs.EUB);
414   Dir->setNextLowerBound(Exprs.NLB);
415   Dir->setNextUpperBound(Exprs.NUB);
416   Dir->setCounters(Exprs.Counters);
417   Dir->setPrivateCounters(Exprs.PrivateCounters);
418   Dir->setInits(Exprs.Inits);
419   Dir->setUpdates(Exprs.Updates);
420   Dir->setFinals(Exprs.Finals);
421   Dir->setPreInits(Exprs.PreInits);
422   return Dir;
423 }
424 
425 OMPParallelForSimdDirective *
426 OMPParallelForSimdDirective::CreateEmpty(const ASTContext &C,
427                                          unsigned NumClauses,
428                                          unsigned CollapsedNum, EmptyShell) {
429   unsigned Size = llvm::alignTo(sizeof(OMPParallelForSimdDirective),
430                                 llvm::alignOf<OMPClause *>());
431   void *Mem = C.Allocate(
432       Size + sizeof(OMPClause *) * NumClauses +
433       sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd));
434   return new (Mem) OMPParallelForSimdDirective(CollapsedNum, NumClauses);
435 }
436 
437 OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create(
438     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
439     ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, bool HasCancel) {
440   unsigned Size = llvm::alignTo(sizeof(OMPParallelSectionsDirective),
441                                 llvm::alignOf<OMPClause *>());
442   void *Mem =
443       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
444   OMPParallelSectionsDirective *Dir =
445       new (Mem) OMPParallelSectionsDirective(StartLoc, EndLoc, Clauses.size());
446   Dir->setClauses(Clauses);
447   Dir->setAssociatedStmt(AssociatedStmt);
448   Dir->setHasCancel(HasCancel);
449   return Dir;
450 }
451 
452 OMPParallelSectionsDirective *
453 OMPParallelSectionsDirective::CreateEmpty(const ASTContext &C,
454                                           unsigned NumClauses, EmptyShell) {
455   unsigned Size = llvm::alignTo(sizeof(OMPParallelSectionsDirective),
456                                 llvm::alignOf<OMPClause *>());
457   void *Mem =
458       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
459   return new (Mem) OMPParallelSectionsDirective(NumClauses);
460 }
461 
462 OMPTaskDirective *
463 OMPTaskDirective::Create(const ASTContext &C, SourceLocation StartLoc,
464                          SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses,
465                          Stmt *AssociatedStmt, bool HasCancel) {
466   unsigned Size =
467       llvm::alignTo(sizeof(OMPTaskDirective), llvm::alignOf<OMPClause *>());
468   void *Mem =
469       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
470   OMPTaskDirective *Dir =
471       new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size());
472   Dir->setClauses(Clauses);
473   Dir->setAssociatedStmt(AssociatedStmt);
474   Dir->setHasCancel(HasCancel);
475   return Dir;
476 }
477 
478 OMPTaskDirective *OMPTaskDirective::CreateEmpty(const ASTContext &C,
479                                                 unsigned NumClauses,
480                                                 EmptyShell) {
481   unsigned Size =
482       llvm::alignTo(sizeof(OMPTaskDirective), llvm::alignOf<OMPClause *>());
483   void *Mem =
484       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
485   return new (Mem) OMPTaskDirective(NumClauses);
486 }
487 
488 OMPTaskyieldDirective *OMPTaskyieldDirective::Create(const ASTContext &C,
489                                                      SourceLocation StartLoc,
490                                                      SourceLocation EndLoc) {
491   void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective));
492   OMPTaskyieldDirective *Dir =
493       new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc);
494   return Dir;
495 }
496 
497 OMPTaskyieldDirective *OMPTaskyieldDirective::CreateEmpty(const ASTContext &C,
498                                                           EmptyShell) {
499   void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective));
500   return new (Mem) OMPTaskyieldDirective();
501 }
502 
503 OMPBarrierDirective *OMPBarrierDirective::Create(const ASTContext &C,
504                                                  SourceLocation StartLoc,
505                                                  SourceLocation EndLoc) {
506   void *Mem = C.Allocate(sizeof(OMPBarrierDirective));
507   OMPBarrierDirective *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc);
508   return Dir;
509 }
510 
511 OMPBarrierDirective *OMPBarrierDirective::CreateEmpty(const ASTContext &C,
512                                                       EmptyShell) {
513   void *Mem = C.Allocate(sizeof(OMPBarrierDirective));
514   return new (Mem) OMPBarrierDirective();
515 }
516 
517 OMPTaskwaitDirective *OMPTaskwaitDirective::Create(const ASTContext &C,
518                                                    SourceLocation StartLoc,
519                                                    SourceLocation EndLoc) {
520   void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective));
521   OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc);
522   return Dir;
523 }
524 
525 OMPTaskwaitDirective *OMPTaskwaitDirective::CreateEmpty(const ASTContext &C,
526                                                         EmptyShell) {
527   void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective));
528   return new (Mem) OMPTaskwaitDirective();
529 }
530 
531 OMPTaskgroupDirective *OMPTaskgroupDirective::Create(const ASTContext &C,
532                                                      SourceLocation StartLoc,
533                                                      SourceLocation EndLoc,
534                                                      Stmt *AssociatedStmt) {
535   unsigned Size =
536       llvm::alignTo(sizeof(OMPTaskgroupDirective), llvm::alignOf<Stmt *>());
537   void *Mem = C.Allocate(Size + sizeof(Stmt *));
538   OMPTaskgroupDirective *Dir =
539       new (Mem) OMPTaskgroupDirective(StartLoc, EndLoc);
540   Dir->setAssociatedStmt(AssociatedStmt);
541   return Dir;
542 }
543 
544 OMPTaskgroupDirective *OMPTaskgroupDirective::CreateEmpty(const ASTContext &C,
545                                                           EmptyShell) {
546   unsigned Size =
547       llvm::alignTo(sizeof(OMPTaskgroupDirective), llvm::alignOf<Stmt *>());
548   void *Mem = C.Allocate(Size + sizeof(Stmt *));
549   return new (Mem) OMPTaskgroupDirective();
550 }
551 
552 OMPCancellationPointDirective *OMPCancellationPointDirective::Create(
553     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
554     OpenMPDirectiveKind CancelRegion) {
555   unsigned Size = llvm::alignTo(sizeof(OMPCancellationPointDirective),
556                                 llvm::alignOf<Stmt *>());
557   void *Mem = C.Allocate(Size);
558   OMPCancellationPointDirective *Dir =
559       new (Mem) OMPCancellationPointDirective(StartLoc, EndLoc);
560   Dir->setCancelRegion(CancelRegion);
561   return Dir;
562 }
563 
564 OMPCancellationPointDirective *
565 OMPCancellationPointDirective::CreateEmpty(const ASTContext &C, EmptyShell) {
566   unsigned Size = llvm::alignTo(sizeof(OMPCancellationPointDirective),
567                                 llvm::alignOf<Stmt *>());
568   void *Mem = C.Allocate(Size);
569   return new (Mem) OMPCancellationPointDirective();
570 }
571 
572 OMPCancelDirective *
573 OMPCancelDirective::Create(const ASTContext &C, SourceLocation StartLoc,
574                            SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses,
575                            OpenMPDirectiveKind CancelRegion) {
576   unsigned Size = llvm::alignTo(sizeof(OMPCancelDirective) +
577                                     sizeof(OMPClause *) * Clauses.size(),
578                                 llvm::alignOf<Stmt *>());
579   void *Mem = C.Allocate(Size);
580   OMPCancelDirective *Dir =
581       new (Mem) OMPCancelDirective(StartLoc, EndLoc, Clauses.size());
582   Dir->setClauses(Clauses);
583   Dir->setCancelRegion(CancelRegion);
584   return Dir;
585 }
586 
587 OMPCancelDirective *OMPCancelDirective::CreateEmpty(const ASTContext &C,
588                                                     unsigned NumClauses,
589                                                     EmptyShell) {
590   unsigned Size = llvm::alignTo(sizeof(OMPCancelDirective) +
591                                     sizeof(OMPClause *) * NumClauses,
592                                 llvm::alignOf<Stmt *>());
593   void *Mem = C.Allocate(Size);
594   return new (Mem) OMPCancelDirective(NumClauses);
595 }
596 
597 OMPFlushDirective *OMPFlushDirective::Create(const ASTContext &C,
598                                              SourceLocation StartLoc,
599                                              SourceLocation EndLoc,
600                                              ArrayRef<OMPClause *> Clauses) {
601   unsigned Size =
602       llvm::alignTo(sizeof(OMPFlushDirective), llvm::alignOf<OMPClause *>());
603   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size());
604   OMPFlushDirective *Dir =
605       new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size());
606   Dir->setClauses(Clauses);
607   return Dir;
608 }
609 
610 OMPFlushDirective *OMPFlushDirective::CreateEmpty(const ASTContext &C,
611                                                   unsigned NumClauses,
612                                                   EmptyShell) {
613   unsigned Size =
614       llvm::alignTo(sizeof(OMPFlushDirective), llvm::alignOf<OMPClause *>());
615   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses);
616   return new (Mem) OMPFlushDirective(NumClauses);
617 }
618 
619 OMPOrderedDirective *OMPOrderedDirective::Create(const ASTContext &C,
620                                                  SourceLocation StartLoc,
621                                                  SourceLocation EndLoc,
622                                                  ArrayRef<OMPClause *> Clauses,
623                                                  Stmt *AssociatedStmt) {
624   unsigned Size =
625       llvm::alignTo(sizeof(OMPOrderedDirective), llvm::alignOf<OMPClause *>());
626   void *Mem =
627       C.Allocate(Size + sizeof(Stmt *) + sizeof(OMPClause *) * Clauses.size());
628   OMPOrderedDirective *Dir =
629       new (Mem) OMPOrderedDirective(StartLoc, EndLoc, Clauses.size());
630   Dir->setClauses(Clauses);
631   Dir->setAssociatedStmt(AssociatedStmt);
632   return Dir;
633 }
634 
635 OMPOrderedDirective *OMPOrderedDirective::CreateEmpty(const ASTContext &C,
636                                                       unsigned NumClauses,
637                                                       EmptyShell) {
638   unsigned Size =
639       llvm::alignTo(sizeof(OMPOrderedDirective), llvm::alignOf<OMPClause *>());
640   void *Mem =
641       C.Allocate(Size + sizeof(Stmt *) + sizeof(OMPClause *) * NumClauses);
642   return new (Mem) OMPOrderedDirective(NumClauses);
643 }
644 
645 OMPAtomicDirective *OMPAtomicDirective::Create(
646     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
647     ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *X, Expr *V,
648     Expr *E, Expr *UE, bool IsXLHSInRHSPart, bool IsPostfixUpdate) {
649   unsigned Size =
650       llvm::alignTo(sizeof(OMPAtomicDirective), llvm::alignOf<OMPClause *>());
651   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
652                          5 * sizeof(Stmt *));
653   OMPAtomicDirective *Dir =
654       new (Mem) OMPAtomicDirective(StartLoc, EndLoc, Clauses.size());
655   Dir->setClauses(Clauses);
656   Dir->setAssociatedStmt(AssociatedStmt);
657   Dir->setX(X);
658   Dir->setV(V);
659   Dir->setExpr(E);
660   Dir->setUpdateExpr(UE);
661   Dir->IsXLHSInRHSPart = IsXLHSInRHSPart;
662   Dir->IsPostfixUpdate = IsPostfixUpdate;
663   return Dir;
664 }
665 
666 OMPAtomicDirective *OMPAtomicDirective::CreateEmpty(const ASTContext &C,
667                                                     unsigned NumClauses,
668                                                     EmptyShell) {
669   unsigned Size =
670       llvm::alignTo(sizeof(OMPAtomicDirective), llvm::alignOf<OMPClause *>());
671   void *Mem =
672       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 5 * sizeof(Stmt *));
673   return new (Mem) OMPAtomicDirective(NumClauses);
674 }
675 
676 OMPTargetDirective *OMPTargetDirective::Create(const ASTContext &C,
677                                                SourceLocation StartLoc,
678                                                SourceLocation EndLoc,
679                                                ArrayRef<OMPClause *> Clauses,
680                                                Stmt *AssociatedStmt) {
681   unsigned Size =
682       llvm::alignTo(sizeof(OMPTargetDirective), llvm::alignOf<OMPClause *>());
683   void *Mem =
684       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
685   OMPTargetDirective *Dir =
686       new (Mem) OMPTargetDirective(StartLoc, EndLoc, Clauses.size());
687   Dir->setClauses(Clauses);
688   Dir->setAssociatedStmt(AssociatedStmt);
689   return Dir;
690 }
691 
692 OMPTargetDirective *OMPTargetDirective::CreateEmpty(const ASTContext &C,
693                                                     unsigned NumClauses,
694                                                     EmptyShell) {
695   unsigned Size =
696       llvm::alignTo(sizeof(OMPTargetDirective), llvm::alignOf<OMPClause *>());
697   void *Mem =
698       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
699   return new (Mem) OMPTargetDirective(NumClauses);
700 }
701 
702 OMPTargetParallelDirective *OMPTargetParallelDirective::Create(
703     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
704     ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
705   unsigned Size = llvm::alignTo(sizeof(OMPTargetParallelDirective),
706                                 llvm::alignOf<OMPClause *>());
707   void *Mem =
708       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
709   OMPTargetParallelDirective *Dir =
710       new (Mem) OMPTargetParallelDirective(StartLoc, EndLoc, Clauses.size());
711   Dir->setClauses(Clauses);
712   Dir->setAssociatedStmt(AssociatedStmt);
713   return Dir;
714 }
715 
716 OMPTargetParallelDirective *
717 OMPTargetParallelDirective::CreateEmpty(const ASTContext &C,
718                                         unsigned NumClauses, EmptyShell) {
719   unsigned Size = llvm::alignTo(sizeof(OMPTargetParallelDirective),
720                                 llvm::alignOf<OMPClause *>());
721   void *Mem =
722       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
723   return new (Mem) OMPTargetParallelDirective(NumClauses);
724 }
725 
726 OMPTargetParallelForDirective *OMPTargetParallelForDirective::Create(
727     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
728     unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
729     const HelperExprs &Exprs, bool HasCancel) {
730   unsigned Size = llvm::alignTo(sizeof(OMPTargetParallelForDirective),
731                                 llvm::alignOf<OMPClause *>());
732   void *Mem = C.Allocate(
733       Size + sizeof(OMPClause *) * Clauses.size() +
734       sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_target_parallel_for));
735   OMPTargetParallelForDirective *Dir = new (Mem) OMPTargetParallelForDirective(
736       StartLoc, EndLoc, CollapsedNum, Clauses.size());
737   Dir->setClauses(Clauses);
738   Dir->setAssociatedStmt(AssociatedStmt);
739   Dir->setIterationVariable(Exprs.IterationVarRef);
740   Dir->setLastIteration(Exprs.LastIteration);
741   Dir->setCalcLastIteration(Exprs.CalcLastIteration);
742   Dir->setPreCond(Exprs.PreCond);
743   Dir->setCond(Exprs.Cond);
744   Dir->setInit(Exprs.Init);
745   Dir->setInc(Exprs.Inc);
746   Dir->setIsLastIterVariable(Exprs.IL);
747   Dir->setLowerBoundVariable(Exprs.LB);
748   Dir->setUpperBoundVariable(Exprs.UB);
749   Dir->setStrideVariable(Exprs.ST);
750   Dir->setEnsureUpperBound(Exprs.EUB);
751   Dir->setNextLowerBound(Exprs.NLB);
752   Dir->setNextUpperBound(Exprs.NUB);
753   Dir->setCounters(Exprs.Counters);
754   Dir->setPrivateCounters(Exprs.PrivateCounters);
755   Dir->setInits(Exprs.Inits);
756   Dir->setUpdates(Exprs.Updates);
757   Dir->setFinals(Exprs.Finals);
758   Dir->setPreInits(Exprs.PreInits);
759   Dir->setHasCancel(HasCancel);
760   return Dir;
761 }
762 
763 OMPTargetParallelForDirective *
764 OMPTargetParallelForDirective::CreateEmpty(const ASTContext &C,
765                                            unsigned NumClauses,
766                                            unsigned CollapsedNum, EmptyShell) {
767   unsigned Size = llvm::alignTo(sizeof(OMPTargetParallelForDirective),
768                                 llvm::alignOf<OMPClause *>());
769   void *Mem = C.Allocate(
770       Size + sizeof(OMPClause *) * NumClauses +
771       sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_target_parallel_for));
772   return new (Mem) OMPTargetParallelForDirective(CollapsedNum, NumClauses);
773 }
774 
775 OMPTargetDataDirective *OMPTargetDataDirective::Create(
776     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
777     ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
778   void *Mem = C.Allocate(llvm::alignTo(sizeof(OMPTargetDataDirective),
779                                        llvm::alignOf<OMPClause *>()) +
780                          sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
781   OMPTargetDataDirective *Dir =
782       new (Mem) OMPTargetDataDirective(StartLoc, EndLoc, Clauses.size());
783   Dir->setClauses(Clauses);
784   Dir->setAssociatedStmt(AssociatedStmt);
785   return Dir;
786 }
787 
788 OMPTargetDataDirective *OMPTargetDataDirective::CreateEmpty(const ASTContext &C,
789                                                             unsigned N,
790                                                             EmptyShell) {
791   void *Mem = C.Allocate(llvm::alignTo(sizeof(OMPTargetDataDirective),
792                                        llvm::alignOf<OMPClause *>()) +
793                          sizeof(OMPClause *) * N + sizeof(Stmt *));
794   return new (Mem) OMPTargetDataDirective(N);
795 }
796 
797 OMPTargetEnterDataDirective *OMPTargetEnterDataDirective::Create(
798     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
799     ArrayRef<OMPClause *> Clauses) {
800   void *Mem = C.Allocate(llvm::alignTo(sizeof(OMPTargetEnterDataDirective),
801                                        llvm::alignOf<OMPClause *>()) +
802                          sizeof(OMPClause *) * Clauses.size());
803   OMPTargetEnterDataDirective *Dir =
804       new (Mem) OMPTargetEnterDataDirective(StartLoc, EndLoc, Clauses.size());
805   Dir->setClauses(Clauses);
806   return Dir;
807 }
808 
809 OMPTargetEnterDataDirective *
810 OMPTargetEnterDataDirective::CreateEmpty(const ASTContext &C, unsigned N,
811                                          EmptyShell) {
812   void *Mem = C.Allocate(llvm::alignTo(sizeof(OMPTargetEnterDataDirective),
813                                        llvm::alignOf<OMPClause *>()) +
814                          sizeof(OMPClause *) * N);
815   return new (Mem) OMPTargetEnterDataDirective(N);
816 }
817 
818 OMPTargetExitDataDirective *
819 OMPTargetExitDataDirective::Create(const ASTContext &C, SourceLocation StartLoc,
820                                    SourceLocation EndLoc,
821                                    ArrayRef<OMPClause *> Clauses) {
822   void *Mem = C.Allocate(llvm::alignTo(sizeof(OMPTargetExitDataDirective),
823                                        llvm::alignOf<OMPClause *>()) +
824                          sizeof(OMPClause *) * Clauses.size());
825   OMPTargetExitDataDirective *Dir =
826       new (Mem) OMPTargetExitDataDirective(StartLoc, EndLoc, Clauses.size());
827   Dir->setClauses(Clauses);
828   return Dir;
829 }
830 
831 OMPTargetExitDataDirective *
832 OMPTargetExitDataDirective::CreateEmpty(const ASTContext &C, unsigned N,
833                                         EmptyShell) {
834   void *Mem = C.Allocate(llvm::alignTo(sizeof(OMPTargetExitDataDirective),
835                                        llvm::alignOf<OMPClause *>()) +
836                          sizeof(OMPClause *) * N);
837   return new (Mem) OMPTargetExitDataDirective(N);
838 }
839 
840 OMPTeamsDirective *OMPTeamsDirective::Create(const ASTContext &C,
841                                              SourceLocation StartLoc,
842                                              SourceLocation EndLoc,
843                                              ArrayRef<OMPClause *> Clauses,
844                                              Stmt *AssociatedStmt) {
845   unsigned Size =
846       llvm::alignTo(sizeof(OMPTeamsDirective), llvm::alignOf<OMPClause *>());
847   void *Mem =
848       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
849   OMPTeamsDirective *Dir =
850       new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size());
851   Dir->setClauses(Clauses);
852   Dir->setAssociatedStmt(AssociatedStmt);
853   return Dir;
854 }
855 
856 OMPTeamsDirective *OMPTeamsDirective::CreateEmpty(const ASTContext &C,
857                                                   unsigned NumClauses,
858                                                   EmptyShell) {
859   unsigned Size =
860       llvm::alignTo(sizeof(OMPTeamsDirective), llvm::alignOf<OMPClause *>());
861   void *Mem =
862       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
863   return new (Mem) OMPTeamsDirective(NumClauses);
864 }
865 
866 OMPTaskLoopDirective *OMPTaskLoopDirective::Create(
867     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
868     unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
869     const HelperExprs &Exprs) {
870   unsigned Size =
871       llvm::alignTo(sizeof(OMPTaskLoopDirective), llvm::alignOf<OMPClause *>());
872   void *Mem =
873       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
874                  sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_taskloop));
875   OMPTaskLoopDirective *Dir = new (Mem)
876       OMPTaskLoopDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
877   Dir->setClauses(Clauses);
878   Dir->setAssociatedStmt(AssociatedStmt);
879   Dir->setIterationVariable(Exprs.IterationVarRef);
880   Dir->setLastIteration(Exprs.LastIteration);
881   Dir->setCalcLastIteration(Exprs.CalcLastIteration);
882   Dir->setPreCond(Exprs.PreCond);
883   Dir->setCond(Exprs.Cond);
884   Dir->setInit(Exprs.Init);
885   Dir->setInc(Exprs.Inc);
886   Dir->setIsLastIterVariable(Exprs.IL);
887   Dir->setLowerBoundVariable(Exprs.LB);
888   Dir->setUpperBoundVariable(Exprs.UB);
889   Dir->setStrideVariable(Exprs.ST);
890   Dir->setEnsureUpperBound(Exprs.EUB);
891   Dir->setNextLowerBound(Exprs.NLB);
892   Dir->setNextUpperBound(Exprs.NUB);
893   Dir->setCounters(Exprs.Counters);
894   Dir->setPrivateCounters(Exprs.PrivateCounters);
895   Dir->setInits(Exprs.Inits);
896   Dir->setUpdates(Exprs.Updates);
897   Dir->setFinals(Exprs.Finals);
898   Dir->setPreInits(Exprs.PreInits);
899   return Dir;
900 }
901 
902 OMPTaskLoopDirective *OMPTaskLoopDirective::CreateEmpty(const ASTContext &C,
903                                                         unsigned NumClauses,
904                                                         unsigned CollapsedNum,
905                                                         EmptyShell) {
906   unsigned Size =
907       llvm::alignTo(sizeof(OMPTaskLoopDirective), llvm::alignOf<OMPClause *>());
908   void *Mem =
909       C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
910                  sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_taskloop));
911   return new (Mem) OMPTaskLoopDirective(CollapsedNum, NumClauses);
912 }
913 
914 OMPTaskLoopSimdDirective *OMPTaskLoopSimdDirective::Create(
915     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
916     unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
917     const HelperExprs &Exprs) {
918   unsigned Size = llvm::alignTo(sizeof(OMPTaskLoopSimdDirective),
919                                 llvm::alignOf<OMPClause *>());
920   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
921                          sizeof(Stmt *) *
922                              numLoopChildren(CollapsedNum, OMPD_taskloop_simd));
923   OMPTaskLoopSimdDirective *Dir = new (Mem)
924       OMPTaskLoopSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
925   Dir->setClauses(Clauses);
926   Dir->setAssociatedStmt(AssociatedStmt);
927   Dir->setIterationVariable(Exprs.IterationVarRef);
928   Dir->setLastIteration(Exprs.LastIteration);
929   Dir->setCalcLastIteration(Exprs.CalcLastIteration);
930   Dir->setPreCond(Exprs.PreCond);
931   Dir->setCond(Exprs.Cond);
932   Dir->setInit(Exprs.Init);
933   Dir->setInc(Exprs.Inc);
934   Dir->setIsLastIterVariable(Exprs.IL);
935   Dir->setLowerBoundVariable(Exprs.LB);
936   Dir->setUpperBoundVariable(Exprs.UB);
937   Dir->setStrideVariable(Exprs.ST);
938   Dir->setEnsureUpperBound(Exprs.EUB);
939   Dir->setNextLowerBound(Exprs.NLB);
940   Dir->setNextUpperBound(Exprs.NUB);
941   Dir->setCounters(Exprs.Counters);
942   Dir->setPrivateCounters(Exprs.PrivateCounters);
943   Dir->setInits(Exprs.Inits);
944   Dir->setUpdates(Exprs.Updates);
945   Dir->setFinals(Exprs.Finals);
946   Dir->setPreInits(Exprs.PreInits);
947   return Dir;
948 }
949 
950 OMPTaskLoopSimdDirective *
951 OMPTaskLoopSimdDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses,
952                                       unsigned CollapsedNum, EmptyShell) {
953   unsigned Size = llvm::alignTo(sizeof(OMPTaskLoopSimdDirective),
954                                 llvm::alignOf<OMPClause *>());
955   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
956                          sizeof(Stmt *) *
957                              numLoopChildren(CollapsedNum, OMPD_taskloop_simd));
958   return new (Mem) OMPTaskLoopSimdDirective(CollapsedNum, NumClauses);
959 }
960 
961 OMPDistributeDirective *OMPDistributeDirective::Create(
962     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
963     unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
964     const HelperExprs &Exprs) {
965   unsigned Size = llvm::alignTo(sizeof(OMPDistributeDirective),
966                                 llvm::alignOf<OMPClause *>());
967   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
968                          sizeof(Stmt *) *
969                              numLoopChildren(CollapsedNum, OMPD_distribute));
970   OMPDistributeDirective *Dir = new (Mem)
971       OMPDistributeDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
972   Dir->setClauses(Clauses);
973   Dir->setAssociatedStmt(AssociatedStmt);
974   Dir->setIterationVariable(Exprs.IterationVarRef);
975   Dir->setLastIteration(Exprs.LastIteration);
976   Dir->setCalcLastIteration(Exprs.CalcLastIteration);
977   Dir->setPreCond(Exprs.PreCond);
978   Dir->setCond(Exprs.Cond);
979   Dir->setInit(Exprs.Init);
980   Dir->setInc(Exprs.Inc);
981   Dir->setIsLastIterVariable(Exprs.IL);
982   Dir->setLowerBoundVariable(Exprs.LB);
983   Dir->setUpperBoundVariable(Exprs.UB);
984   Dir->setStrideVariable(Exprs.ST);
985   Dir->setEnsureUpperBound(Exprs.EUB);
986   Dir->setNextLowerBound(Exprs.NLB);
987   Dir->setNextUpperBound(Exprs.NUB);
988   Dir->setCounters(Exprs.Counters);
989   Dir->setPrivateCounters(Exprs.PrivateCounters);
990   Dir->setInits(Exprs.Inits);
991   Dir->setUpdates(Exprs.Updates);
992   Dir->setFinals(Exprs.Finals);
993   Dir->setPreInits(Exprs.PreInits);
994   return Dir;
995 }
996 
997 OMPDistributeDirective *
998 OMPDistributeDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses,
999                                     unsigned CollapsedNum, EmptyShell) {
1000   unsigned Size = llvm::alignTo(sizeof(OMPDistributeDirective),
1001                                 llvm::alignOf<OMPClause *>());
1002   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1003                          sizeof(Stmt *) *
1004                              numLoopChildren(CollapsedNum, OMPD_distribute));
1005   return new (Mem) OMPDistributeDirective(CollapsedNum, NumClauses);
1006 }
1007