1 //===--- OpenMPClause.cpp - Classes for OpenMP clauses --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the subclesses of Stmt class declared in OpenMPClause.h
12 //===----------------------------------------------------------------------===//
14 #include "clang/AST/OpenMPClause.h"
16 #include "clang/AST/ASTContext.h"
18 using namespace clang;
20 OMPClause::child_range OMPClause::children() {
21 switch (getClauseKind()) {
24 #define OPENMP_CLAUSE(Name, Class) \
26 return static_cast<Class *>(this)->children();
27 #include "clang/Basic/OpenMPKinds.def"
29 llvm_unreachable("unknown OMPClause");
32 OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
33 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
34 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr;
37 const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
38 switch (C->getClauseKind()) {
40 return static_cast<const OMPScheduleClause *>(C);
41 case OMPC_dist_schedule:
42 return static_cast<const OMPDistScheduleClause *>(C);
43 case OMPC_firstprivate:
44 return static_cast<const OMPFirstprivateClause *>(C);
45 case OMPC_lastprivate:
46 return static_cast<const OMPLastprivateClause *>(C);
48 return static_cast<const OMPReductionClause *>(C);
50 return static_cast<const OMPLinearClause *>(C);
55 case OMPC_num_threads:
63 case OMPC_copyprivate:
68 case OMPC_threadprivate:
81 case OMPC_thread_limit:
92 case OMPC_use_device_ptr:
93 case OMPC_is_device_ptr:
100 OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
101 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
102 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
105 const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
106 switch (C->getClauseKind()) {
107 case OMPC_lastprivate:
108 return static_cast<const OMPLastprivateClause *>(C);
110 return static_cast<const OMPReductionClause *>(C);
112 return static_cast<const OMPLinearClause *>(C);
114 case OMPC_dist_schedule:
115 case OMPC_firstprivate:
120 case OMPC_num_threads:
128 case OMPC_copyprivate:
133 case OMPC_threadprivate:
146 case OMPC_thread_limit:
152 case OMPC_defaultmap:
157 case OMPC_use_device_ptr:
158 case OMPC_is_device_ptr:
165 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
166 assert(VL.size() == varlist_size() &&
167 "Number of private copies is not the same as the preallocated buffer");
168 std::copy(VL.begin(), VL.end(), varlist_end());
172 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
173 SourceLocation LParenLoc, SourceLocation EndLoc,
174 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
175 // Allocate space for private variables and initializer expressions.
176 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
177 OMPPrivateClause *Clause =
178 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
179 Clause->setVarRefs(VL);
180 Clause->setPrivateCopies(PrivateVL);
184 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
186 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
187 return new (Mem) OMPPrivateClause(N);
190 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
191 assert(VL.size() == varlist_size() &&
192 "Number of private copies is not the same as the preallocated buffer");
193 std::copy(VL.begin(), VL.end(), varlist_end());
196 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
197 assert(VL.size() == varlist_size() &&
198 "Number of inits is not the same as the preallocated buffer");
199 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
202 OMPFirstprivateClause *
203 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
204 SourceLocation LParenLoc, SourceLocation EndLoc,
205 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
206 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
207 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
208 OMPFirstprivateClause *Clause =
209 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
210 Clause->setVarRefs(VL);
211 Clause->setPrivateCopies(PrivateVL);
212 Clause->setInits(InitVL);
213 Clause->setPreInitStmt(PreInit);
217 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
219 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
220 return new (Mem) OMPFirstprivateClause(N);
223 void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
224 assert(PrivateCopies.size() == varlist_size() &&
225 "Number of private copies is not the same as the preallocated buffer");
226 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
229 void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
230 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
231 "not the same as the "
232 "preallocated buffer");
233 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
236 void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
237 assert(DstExprs.size() == varlist_size() && "Number of destination "
238 "expressions is not the same as "
239 "the preallocated buffer");
240 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
243 void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
244 assert(AssignmentOps.size() == varlist_size() &&
245 "Number of assignment expressions is not the same as the preallocated "
247 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
248 getDestinationExprs().end());
251 OMPLastprivateClause *OMPLastprivateClause::Create(
252 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
253 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
254 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
256 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
257 OMPLastprivateClause *Clause =
258 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
259 Clause->setVarRefs(VL);
260 Clause->setSourceExprs(SrcExprs);
261 Clause->setDestinationExprs(DstExprs);
262 Clause->setAssignmentOps(AssignmentOps);
263 Clause->setPreInitStmt(PreInit);
264 Clause->setPostUpdateExpr(PostUpdate);
268 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
270 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
271 return new (Mem) OMPLastprivateClause(N);
274 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
275 SourceLocation StartLoc,
276 SourceLocation LParenLoc,
277 SourceLocation EndLoc,
278 ArrayRef<Expr *> VL) {
279 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
280 OMPSharedClause *Clause =
281 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
282 Clause->setVarRefs(VL);
286 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
287 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
288 return new (Mem) OMPSharedClause(N);
291 void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
292 assert(PL.size() == varlist_size() &&
293 "Number of privates is not the same as the preallocated buffer");
294 std::copy(PL.begin(), PL.end(), varlist_end());
297 void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
298 assert(IL.size() == varlist_size() &&
299 "Number of inits is not the same as the preallocated buffer");
300 std::copy(IL.begin(), IL.end(), getPrivates().end());
303 void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
304 assert(UL.size() == varlist_size() &&
305 "Number of updates is not the same as the preallocated buffer");
306 std::copy(UL.begin(), UL.end(), getInits().end());
309 void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
310 assert(FL.size() == varlist_size() &&
311 "Number of final updates is not the same as the preallocated buffer");
312 std::copy(FL.begin(), FL.end(), getUpdates().end());
315 OMPLinearClause *OMPLinearClause::Create(
316 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
317 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
318 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
319 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
320 Stmt *PreInit, Expr *PostUpdate) {
321 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
322 // (Step and CalcStep).
323 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
324 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
325 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
326 Clause->setVarRefs(VL);
327 Clause->setPrivates(PL);
328 Clause->setInits(IL);
329 // Fill update and final expressions with zeroes, they are provided later,
330 // after the directive construction.
331 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
333 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
335 Clause->setStep(Step);
336 Clause->setCalcStep(CalcStep);
337 Clause->setPreInitStmt(PreInit);
338 Clause->setPostUpdateExpr(PostUpdate);
342 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
344 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
345 // (Step and CalcStep).
346 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
347 return new (Mem) OMPLinearClause(NumVars);
351 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
352 SourceLocation LParenLoc, SourceLocation ColonLoc,
353 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
354 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
355 OMPAlignedClause *Clause = new (Mem)
356 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
357 Clause->setVarRefs(VL);
358 Clause->setAlignment(A);
362 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
364 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
365 return new (Mem) OMPAlignedClause(NumVars);
368 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
369 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
370 "not the same as the "
371 "preallocated buffer");
372 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
375 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
376 assert(DstExprs.size() == varlist_size() && "Number of destination "
377 "expressions is not the same as "
378 "the preallocated buffer");
379 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
382 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
383 assert(AssignmentOps.size() == varlist_size() &&
384 "Number of assignment expressions is not the same as the preallocated "
386 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
387 getDestinationExprs().end());
390 OMPCopyinClause *OMPCopyinClause::Create(
391 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
392 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
393 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
394 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
395 OMPCopyinClause *Clause =
396 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
397 Clause->setVarRefs(VL);
398 Clause->setSourceExprs(SrcExprs);
399 Clause->setDestinationExprs(DstExprs);
400 Clause->setAssignmentOps(AssignmentOps);
404 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
405 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
406 return new (Mem) OMPCopyinClause(N);
409 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
410 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
411 "not the same as the "
412 "preallocated buffer");
413 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
416 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
417 assert(DstExprs.size() == varlist_size() && "Number of destination "
418 "expressions is not the same as "
419 "the preallocated buffer");
420 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
423 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
424 assert(AssignmentOps.size() == varlist_size() &&
425 "Number of assignment expressions is not the same as the preallocated "
427 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
428 getDestinationExprs().end());
431 OMPCopyprivateClause *OMPCopyprivateClause::Create(
432 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
433 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
434 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
435 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
436 OMPCopyprivateClause *Clause =
437 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
438 Clause->setVarRefs(VL);
439 Clause->setSourceExprs(SrcExprs);
440 Clause->setDestinationExprs(DstExprs);
441 Clause->setAssignmentOps(AssignmentOps);
445 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
447 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
448 return new (Mem) OMPCopyprivateClause(N);
451 void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
452 assert(Privates.size() == varlist_size() &&
453 "Number of private copies is not the same as the preallocated buffer");
454 std::copy(Privates.begin(), Privates.end(), varlist_end());
457 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
459 LHSExprs.size() == varlist_size() &&
460 "Number of LHS expressions is not the same as the preallocated buffer");
461 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
464 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
466 RHSExprs.size() == varlist_size() &&
467 "Number of RHS expressions is not the same as the preallocated buffer");
468 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
471 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
472 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
473 "expressions is not the same "
474 "as the preallocated buffer");
475 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
478 OMPReductionClause *OMPReductionClause::Create(
479 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
480 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
481 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
482 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
483 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
485 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
486 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
487 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
488 Clause->setVarRefs(VL);
489 Clause->setPrivates(Privates);
490 Clause->setLHSExprs(LHSExprs);
491 Clause->setRHSExprs(RHSExprs);
492 Clause->setReductionOps(ReductionOps);
493 Clause->setPreInitStmt(PreInit);
494 Clause->setPostUpdateExpr(PostUpdate);
498 OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
500 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
501 return new (Mem) OMPReductionClause(N);
504 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
505 SourceLocation StartLoc,
506 SourceLocation LParenLoc,
507 SourceLocation EndLoc,
508 ArrayRef<Expr *> VL) {
509 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
510 OMPFlushClause *Clause =
511 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
512 Clause->setVarRefs(VL);
516 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
517 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
518 return new (Mem) OMPFlushClause(N);
521 OMPDependClause *OMPDependClause::Create(
522 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
523 SourceLocation EndLoc, OpenMPDependClauseKind DepKind,
524 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL) {
525 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
526 OMPDependClause *Clause =
527 new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size());
528 Clause->setVarRefs(VL);
529 Clause->setDependencyKind(DepKind);
530 Clause->setDependencyLoc(DepLoc);
531 Clause->setColonLoc(ColonLoc);
532 Clause->setCounterValue(nullptr);
536 OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) {
537 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
538 return new (Mem) OMPDependClause(N);
541 void OMPDependClause::setCounterValue(Expr *V) {
542 assert(getDependencyKind() == OMPC_DEPEND_sink ||
543 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
544 *getVarRefs().end() = V;
547 const Expr *OMPDependClause::getCounterValue() const {
548 auto *V = *getVarRefs().end();
549 assert(getDependencyKind() == OMPC_DEPEND_sink ||
550 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
554 Expr *OMPDependClause::getCounterValue() {
555 auto *V = *getVarRefs().end();
556 assert(getDependencyKind() == OMPC_DEPEND_sink ||
557 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
561 unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
562 MappableExprComponentListsRef ComponentLists) {
563 unsigned TotalNum = 0u;
564 for (auto &C : ComponentLists)
565 TotalNum += C.size();
569 unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
570 ArrayRef<ValueDecl *> Declarations) {
571 unsigned TotalNum = 0u;
572 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
573 for (auto *D : Declarations) {
574 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
584 OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc,
585 SourceLocation LParenLoc, SourceLocation EndLoc,
586 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
587 MappableExprComponentListsRef ComponentLists,
588 OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type,
589 bool TypeIsImplicit, SourceLocation TypeLoc) {
591 unsigned NumVars = Vars.size();
592 unsigned NumUniqueDeclarations =
593 getUniqueDeclarationsTotalNumber(Declarations);
594 unsigned NumComponentLists = ComponentLists.size();
595 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
597 // We need to allocate:
598 // NumVars x Expr* - we have an original list expression for each clause list
600 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
601 // with each component list.
602 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
603 // number of lists for each unique declaration and the size of each component
605 // NumComponents x MappableComponent - the total of all the components in all
607 void *Mem = C.Allocate(
608 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
609 OMPClauseMappableExprCommon::MappableComponent>(
610 NumVars, NumUniqueDeclarations,
611 NumUniqueDeclarations + NumComponentLists, NumComponents));
612 OMPMapClause *Clause = new (Mem) OMPMapClause(
613 TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc,
614 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents);
616 Clause->setVarRefs(Vars);
617 Clause->setClauseInfo(Declarations, ComponentLists);
618 Clause->setMapTypeModifier(TypeModifier);
619 Clause->setMapType(Type);
620 Clause->setMapLoc(TypeLoc);
624 OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
625 unsigned NumUniqueDeclarations,
626 unsigned NumComponentLists,
627 unsigned NumComponents) {
628 void *Mem = C.Allocate(
629 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
630 OMPClauseMappableExprCommon::MappableComponent>(
631 NumVars, NumUniqueDeclarations,
632 NumUniqueDeclarations + NumComponentLists, NumComponents));
633 return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations,
634 NumComponentLists, NumComponents);
637 OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc,
638 SourceLocation LParenLoc,
639 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
640 ArrayRef<ValueDecl *> Declarations,
641 MappableExprComponentListsRef ComponentLists) {
642 unsigned NumVars = Vars.size();
643 unsigned NumUniqueDeclarations =
644 getUniqueDeclarationsTotalNumber(Declarations);
645 unsigned NumComponentLists = ComponentLists.size();
646 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
648 // We need to allocate:
649 // NumVars x Expr* - we have an original list expression for each clause list
651 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
652 // with each component list.
653 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
654 // number of lists for each unique declaration and the size of each component
656 // NumComponents x MappableComponent - the total of all the components in all
658 void *Mem = C.Allocate(
659 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
660 OMPClauseMappableExprCommon::MappableComponent>(
661 NumVars, NumUniqueDeclarations,
662 NumUniqueDeclarations + NumComponentLists, NumComponents));
664 OMPToClause *Clause = new (Mem)
665 OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
666 NumComponentLists, NumComponents);
668 Clause->setVarRefs(Vars);
669 Clause->setClauseInfo(Declarations, ComponentLists);
673 OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
674 unsigned NumUniqueDeclarations,
675 unsigned NumComponentLists,
676 unsigned NumComponents) {
677 void *Mem = C.Allocate(
678 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
679 OMPClauseMappableExprCommon::MappableComponent>(
680 NumVars, NumUniqueDeclarations,
681 NumUniqueDeclarations + NumComponentLists, NumComponents));
682 return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations,
683 NumComponentLists, NumComponents);
687 OMPFromClause::Create(const ASTContext &C, SourceLocation StartLoc,
688 SourceLocation LParenLoc, SourceLocation EndLoc,
689 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
690 MappableExprComponentListsRef ComponentLists) {
691 unsigned NumVars = Vars.size();
692 unsigned NumUniqueDeclarations =
693 getUniqueDeclarationsTotalNumber(Declarations);
694 unsigned NumComponentLists = ComponentLists.size();
695 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
697 // We need to allocate:
698 // NumVars x Expr* - we have an original list expression for each clause list
700 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
701 // with each component list.
702 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
703 // number of lists for each unique declaration and the size of each component
705 // NumComponents x MappableComponent - the total of all the components in all
707 void *Mem = C.Allocate(
708 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
709 OMPClauseMappableExprCommon::MappableComponent>(
710 NumVars, NumUniqueDeclarations,
711 NumUniqueDeclarations + NumComponentLists, NumComponents));
713 OMPFromClause *Clause = new (Mem)
714 OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
715 NumComponentLists, NumComponents);
717 Clause->setVarRefs(Vars);
718 Clause->setClauseInfo(Declarations, ComponentLists);
722 OMPFromClause *OMPFromClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
723 unsigned NumUniqueDeclarations,
724 unsigned NumComponentLists,
725 unsigned NumComponents) {
726 void *Mem = C.Allocate(
727 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
728 OMPClauseMappableExprCommon::MappableComponent>(
729 NumVars, NumUniqueDeclarations,
730 NumUniqueDeclarations + NumComponentLists, NumComponents));
731 return new (Mem) OMPFromClause(NumVars, NumUniqueDeclarations,
732 NumComponentLists, NumComponents);
735 void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
736 assert(VL.size() == varlist_size() &&
737 "Number of private copies is not the same as the preallocated buffer");
738 std::copy(VL.begin(), VL.end(), varlist_end());
741 void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
742 assert(VL.size() == varlist_size() &&
743 "Number of inits is not the same as the preallocated buffer");
744 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
747 OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
748 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
749 SourceLocation EndLoc, ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
750 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
751 MappableExprComponentListsRef ComponentLists) {
752 unsigned NumVars = Vars.size();
753 unsigned NumUniqueDeclarations =
754 getUniqueDeclarationsTotalNumber(Declarations);
755 unsigned NumComponentLists = ComponentLists.size();
756 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
758 // We need to allocate:
759 // 3 x NumVars x Expr* - we have an original list expression for each clause
760 // list entry and an equal number of private copies and inits.
761 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
762 // with each component list.
763 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
764 // number of lists for each unique declaration and the size of each component
766 // NumComponents x MappableComponent - the total of all the components in all
768 void *Mem = C.Allocate(
769 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
770 OMPClauseMappableExprCommon::MappableComponent>(
771 3 * NumVars, NumUniqueDeclarations,
772 NumUniqueDeclarations + NumComponentLists, NumComponents));
774 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(
775 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
776 NumComponentLists, NumComponents);
778 Clause->setVarRefs(Vars);
779 Clause->setPrivateCopies(PrivateVars);
780 Clause->setInits(Inits);
781 Clause->setClauseInfo(Declarations, ComponentLists);
785 OMPUseDevicePtrClause *OMPUseDevicePtrClause::CreateEmpty(
786 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
787 unsigned NumComponentLists, unsigned NumComponents) {
788 void *Mem = C.Allocate(
789 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
790 OMPClauseMappableExprCommon::MappableComponent>(
791 3 * NumVars, NumUniqueDeclarations,
792 NumUniqueDeclarations + NumComponentLists, NumComponents));
793 return new (Mem) OMPUseDevicePtrClause(NumVars, NumUniqueDeclarations,
794 NumComponentLists, NumComponents);
797 OMPIsDevicePtrClause *
798 OMPIsDevicePtrClause::Create(const ASTContext &C, SourceLocation StartLoc,
799 SourceLocation LParenLoc, SourceLocation EndLoc,
800 ArrayRef<Expr *> Vars,
801 ArrayRef<ValueDecl *> Declarations,
802 MappableExprComponentListsRef ComponentLists) {
803 unsigned NumVars = Vars.size();
804 unsigned NumUniqueDeclarations =
805 getUniqueDeclarationsTotalNumber(Declarations);
806 unsigned NumComponentLists = ComponentLists.size();
807 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
809 // We need to allocate:
810 // NumVars x Expr* - we have an original list expression for each clause list
812 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
813 // with each component list.
814 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
815 // number of lists for each unique declaration and the size of each component
817 // NumComponents x MappableComponent - the total of all the components in all
819 void *Mem = C.Allocate(
820 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
821 OMPClauseMappableExprCommon::MappableComponent>(
822 NumVars, NumUniqueDeclarations,
823 NumUniqueDeclarations + NumComponentLists, NumComponents));
825 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(
826 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
827 NumComponentLists, NumComponents);
829 Clause->setVarRefs(Vars);
830 Clause->setClauseInfo(Declarations, ComponentLists);
834 OMPIsDevicePtrClause *OMPIsDevicePtrClause::CreateEmpty(
835 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
836 unsigned NumComponentLists, unsigned NumComponents) {
837 void *Mem = C.Allocate(
838 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
839 OMPClauseMappableExprCommon::MappableComponent>(
840 NumVars, NumUniqueDeclarations,
841 NumUniqueDeclarations + NumComponentLists, NumComponents));
842 return new (Mem) OMPIsDevicePtrClause(NumVars, NumUniqueDeclarations,
843 NumComponentLists, NumComponents);