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);
52 return static_cast<const OMPIfClause *>(C);
53 case OMPC_num_threads:
54 return static_cast<const OMPNumThreadsClause *>(C);
56 return static_cast<const OMPNumTeamsClause *>(C);
57 case OMPC_thread_limit:
58 return static_cast<const OMPThreadLimitClause *>(C);
69 case OMPC_copyprivate:
74 case OMPC_threadprivate:
96 case OMPC_use_device_ptr:
97 case OMPC_is_device_ptr:
104 OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
105 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
106 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr;
109 const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
110 switch (C->getClauseKind()) {
111 case OMPC_lastprivate:
112 return static_cast<const OMPLastprivateClause *>(C);
114 return static_cast<const OMPReductionClause *>(C);
116 return static_cast<const OMPLinearClause *>(C);
118 case OMPC_dist_schedule:
119 case OMPC_firstprivate:
124 case OMPC_num_threads:
132 case OMPC_copyprivate:
137 case OMPC_threadprivate:
150 case OMPC_thread_limit:
156 case OMPC_defaultmap:
161 case OMPC_use_device_ptr:
162 case OMPC_is_device_ptr:
169 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
170 assert(VL.size() == varlist_size() &&
171 "Number of private copies is not the same as the preallocated buffer");
172 std::copy(VL.begin(), VL.end(), varlist_end());
176 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
177 SourceLocation LParenLoc, SourceLocation EndLoc,
178 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
179 // Allocate space for private variables and initializer expressions.
180 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
181 OMPPrivateClause *Clause =
182 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
183 Clause->setVarRefs(VL);
184 Clause->setPrivateCopies(PrivateVL);
188 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
190 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
191 return new (Mem) OMPPrivateClause(N);
194 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
195 assert(VL.size() == varlist_size() &&
196 "Number of private copies is not the same as the preallocated buffer");
197 std::copy(VL.begin(), VL.end(), varlist_end());
200 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
201 assert(VL.size() == varlist_size() &&
202 "Number of inits is not the same as the preallocated buffer");
203 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
206 OMPFirstprivateClause *
207 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
208 SourceLocation LParenLoc, SourceLocation EndLoc,
209 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
210 ArrayRef<Expr *> InitVL, Stmt *PreInit) {
211 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
212 OMPFirstprivateClause *Clause =
213 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
214 Clause->setVarRefs(VL);
215 Clause->setPrivateCopies(PrivateVL);
216 Clause->setInits(InitVL);
217 Clause->setPreInitStmt(PreInit);
221 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
223 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
224 return new (Mem) OMPFirstprivateClause(N);
227 void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
228 assert(PrivateCopies.size() == varlist_size() &&
229 "Number of private copies is not the same as the preallocated buffer");
230 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
233 void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
234 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
235 "not the same as the "
236 "preallocated buffer");
237 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
240 void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
241 assert(DstExprs.size() == varlist_size() && "Number of destination "
242 "expressions is not the same as "
243 "the preallocated buffer");
244 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
247 void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
248 assert(AssignmentOps.size() == varlist_size() &&
249 "Number of assignment expressions is not the same as the preallocated "
251 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
252 getDestinationExprs().end());
255 OMPLastprivateClause *OMPLastprivateClause::Create(
256 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
257 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
258 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
260 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
261 OMPLastprivateClause *Clause =
262 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
263 Clause->setVarRefs(VL);
264 Clause->setSourceExprs(SrcExprs);
265 Clause->setDestinationExprs(DstExprs);
266 Clause->setAssignmentOps(AssignmentOps);
267 Clause->setPreInitStmt(PreInit);
268 Clause->setPostUpdateExpr(PostUpdate);
272 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
274 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
275 return new (Mem) OMPLastprivateClause(N);
278 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
279 SourceLocation StartLoc,
280 SourceLocation LParenLoc,
281 SourceLocation EndLoc,
282 ArrayRef<Expr *> VL) {
283 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
284 OMPSharedClause *Clause =
285 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
286 Clause->setVarRefs(VL);
290 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
291 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
292 return new (Mem) OMPSharedClause(N);
295 void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
296 assert(PL.size() == varlist_size() &&
297 "Number of privates is not the same as the preallocated buffer");
298 std::copy(PL.begin(), PL.end(), varlist_end());
301 void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
302 assert(IL.size() == varlist_size() &&
303 "Number of inits is not the same as the preallocated buffer");
304 std::copy(IL.begin(), IL.end(), getPrivates().end());
307 void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
308 assert(UL.size() == varlist_size() &&
309 "Number of updates is not the same as the preallocated buffer");
310 std::copy(UL.begin(), UL.end(), getInits().end());
313 void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
314 assert(FL.size() == varlist_size() &&
315 "Number of final updates is not the same as the preallocated buffer");
316 std::copy(FL.begin(), FL.end(), getUpdates().end());
319 OMPLinearClause *OMPLinearClause::Create(
320 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
321 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
322 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
323 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
324 Stmt *PreInit, Expr *PostUpdate) {
325 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
326 // (Step and CalcStep).
327 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
328 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
329 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
330 Clause->setVarRefs(VL);
331 Clause->setPrivates(PL);
332 Clause->setInits(IL);
333 // Fill update and final expressions with zeroes, they are provided later,
334 // after the directive construction.
335 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
337 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
339 Clause->setStep(Step);
340 Clause->setCalcStep(CalcStep);
341 Clause->setPreInitStmt(PreInit);
342 Clause->setPostUpdateExpr(PostUpdate);
346 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
348 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
349 // (Step and CalcStep).
350 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
351 return new (Mem) OMPLinearClause(NumVars);
355 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
356 SourceLocation LParenLoc, SourceLocation ColonLoc,
357 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
358 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
359 OMPAlignedClause *Clause = new (Mem)
360 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
361 Clause->setVarRefs(VL);
362 Clause->setAlignment(A);
366 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
368 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
369 return new (Mem) OMPAlignedClause(NumVars);
372 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
373 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
374 "not the same as the "
375 "preallocated buffer");
376 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
379 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
380 assert(DstExprs.size() == varlist_size() && "Number of destination "
381 "expressions is not the same as "
382 "the preallocated buffer");
383 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
386 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
387 assert(AssignmentOps.size() == varlist_size() &&
388 "Number of assignment expressions is not the same as the preallocated "
390 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
391 getDestinationExprs().end());
394 OMPCopyinClause *OMPCopyinClause::Create(
395 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
396 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
397 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
398 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
399 OMPCopyinClause *Clause =
400 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
401 Clause->setVarRefs(VL);
402 Clause->setSourceExprs(SrcExprs);
403 Clause->setDestinationExprs(DstExprs);
404 Clause->setAssignmentOps(AssignmentOps);
408 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
409 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
410 return new (Mem) OMPCopyinClause(N);
413 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
414 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
415 "not the same as the "
416 "preallocated buffer");
417 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
420 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
421 assert(DstExprs.size() == varlist_size() && "Number of destination "
422 "expressions is not the same as "
423 "the preallocated buffer");
424 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
427 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
428 assert(AssignmentOps.size() == varlist_size() &&
429 "Number of assignment expressions is not the same as the preallocated "
431 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
432 getDestinationExprs().end());
435 OMPCopyprivateClause *OMPCopyprivateClause::Create(
436 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
437 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
438 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
439 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
440 OMPCopyprivateClause *Clause =
441 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
442 Clause->setVarRefs(VL);
443 Clause->setSourceExprs(SrcExprs);
444 Clause->setDestinationExprs(DstExprs);
445 Clause->setAssignmentOps(AssignmentOps);
449 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
451 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
452 return new (Mem) OMPCopyprivateClause(N);
455 void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
456 assert(Privates.size() == varlist_size() &&
457 "Number of private copies is not the same as the preallocated buffer");
458 std::copy(Privates.begin(), Privates.end(), varlist_end());
461 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
463 LHSExprs.size() == varlist_size() &&
464 "Number of LHS expressions is not the same as the preallocated buffer");
465 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
468 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
470 RHSExprs.size() == varlist_size() &&
471 "Number of RHS expressions is not the same as the preallocated buffer");
472 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
475 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
476 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
477 "expressions is not the same "
478 "as the preallocated buffer");
479 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
482 OMPReductionClause *OMPReductionClause::Create(
483 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
484 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
485 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
486 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
487 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
489 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
490 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
491 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
492 Clause->setVarRefs(VL);
493 Clause->setPrivates(Privates);
494 Clause->setLHSExprs(LHSExprs);
495 Clause->setRHSExprs(RHSExprs);
496 Clause->setReductionOps(ReductionOps);
497 Clause->setPreInitStmt(PreInit);
498 Clause->setPostUpdateExpr(PostUpdate);
502 OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
504 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
505 return new (Mem) OMPReductionClause(N);
508 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
509 SourceLocation StartLoc,
510 SourceLocation LParenLoc,
511 SourceLocation EndLoc,
512 ArrayRef<Expr *> VL) {
513 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
514 OMPFlushClause *Clause =
515 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
516 Clause->setVarRefs(VL);
520 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
521 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
522 return new (Mem) OMPFlushClause(N);
525 OMPDependClause *OMPDependClause::Create(
526 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
527 SourceLocation EndLoc, OpenMPDependClauseKind DepKind,
528 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL) {
529 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
530 OMPDependClause *Clause =
531 new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size());
532 Clause->setVarRefs(VL);
533 Clause->setDependencyKind(DepKind);
534 Clause->setDependencyLoc(DepLoc);
535 Clause->setColonLoc(ColonLoc);
536 Clause->setCounterValue(nullptr);
540 OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) {
541 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
542 return new (Mem) OMPDependClause(N);
545 void OMPDependClause::setCounterValue(Expr *V) {
546 assert(getDependencyKind() == OMPC_DEPEND_sink ||
547 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
548 *getVarRefs().end() = V;
551 const Expr *OMPDependClause::getCounterValue() const {
552 auto *V = *getVarRefs().end();
553 assert(getDependencyKind() == OMPC_DEPEND_sink ||
554 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
558 Expr *OMPDependClause::getCounterValue() {
559 auto *V = *getVarRefs().end();
560 assert(getDependencyKind() == OMPC_DEPEND_sink ||
561 getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
565 unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
566 MappableExprComponentListsRef ComponentLists) {
567 unsigned TotalNum = 0u;
568 for (auto &C : ComponentLists)
569 TotalNum += C.size();
573 unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
574 ArrayRef<ValueDecl *> Declarations) {
575 unsigned TotalNum = 0u;
576 llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
577 for (auto *D : Declarations) {
578 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
588 OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc,
589 SourceLocation LParenLoc, SourceLocation EndLoc,
590 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
591 MappableExprComponentListsRef ComponentLists,
592 OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type,
593 bool TypeIsImplicit, SourceLocation TypeLoc) {
595 unsigned NumVars = Vars.size();
596 unsigned NumUniqueDeclarations =
597 getUniqueDeclarationsTotalNumber(Declarations);
598 unsigned NumComponentLists = ComponentLists.size();
599 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
601 // We need to allocate:
602 // NumVars x Expr* - we have an original list expression for each clause list
604 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
605 // with each component list.
606 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
607 // number of lists for each unique declaration and the size of each component
609 // NumComponents x MappableComponent - the total of all the components in all
611 void *Mem = C.Allocate(
612 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
613 OMPClauseMappableExprCommon::MappableComponent>(
614 NumVars, NumUniqueDeclarations,
615 NumUniqueDeclarations + NumComponentLists, NumComponents));
616 OMPMapClause *Clause = new (Mem) OMPMapClause(
617 TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc,
618 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents);
620 Clause->setVarRefs(Vars);
621 Clause->setClauseInfo(Declarations, ComponentLists);
622 Clause->setMapTypeModifier(TypeModifier);
623 Clause->setMapType(Type);
624 Clause->setMapLoc(TypeLoc);
628 OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
629 unsigned NumUniqueDeclarations,
630 unsigned NumComponentLists,
631 unsigned NumComponents) {
632 void *Mem = C.Allocate(
633 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
634 OMPClauseMappableExprCommon::MappableComponent>(
635 NumVars, NumUniqueDeclarations,
636 NumUniqueDeclarations + NumComponentLists, NumComponents));
637 return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations,
638 NumComponentLists, NumComponents);
641 OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc,
642 SourceLocation LParenLoc,
643 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
644 ArrayRef<ValueDecl *> Declarations,
645 MappableExprComponentListsRef ComponentLists) {
646 unsigned NumVars = Vars.size();
647 unsigned NumUniqueDeclarations =
648 getUniqueDeclarationsTotalNumber(Declarations);
649 unsigned NumComponentLists = ComponentLists.size();
650 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
652 // We need to allocate:
653 // NumVars x Expr* - we have an original list expression for each clause list
655 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
656 // with each component list.
657 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
658 // number of lists for each unique declaration and the size of each component
660 // NumComponents x MappableComponent - the total of all the components in all
662 void *Mem = C.Allocate(
663 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
664 OMPClauseMappableExprCommon::MappableComponent>(
665 NumVars, NumUniqueDeclarations,
666 NumUniqueDeclarations + NumComponentLists, NumComponents));
668 OMPToClause *Clause = new (Mem)
669 OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
670 NumComponentLists, NumComponents);
672 Clause->setVarRefs(Vars);
673 Clause->setClauseInfo(Declarations, ComponentLists);
677 OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
678 unsigned NumUniqueDeclarations,
679 unsigned NumComponentLists,
680 unsigned NumComponents) {
681 void *Mem = C.Allocate(
682 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
683 OMPClauseMappableExprCommon::MappableComponent>(
684 NumVars, NumUniqueDeclarations,
685 NumUniqueDeclarations + NumComponentLists, NumComponents));
686 return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations,
687 NumComponentLists, NumComponents);
691 OMPFromClause::Create(const ASTContext &C, SourceLocation StartLoc,
692 SourceLocation LParenLoc, SourceLocation EndLoc,
693 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
694 MappableExprComponentListsRef ComponentLists) {
695 unsigned NumVars = Vars.size();
696 unsigned NumUniqueDeclarations =
697 getUniqueDeclarationsTotalNumber(Declarations);
698 unsigned NumComponentLists = ComponentLists.size();
699 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
701 // We need to allocate:
702 // NumVars x Expr* - we have an original list expression for each clause list
704 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
705 // with each component list.
706 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
707 // number of lists for each unique declaration and the size of each component
709 // NumComponents x MappableComponent - the total of all the components in all
711 void *Mem = C.Allocate(
712 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
713 OMPClauseMappableExprCommon::MappableComponent>(
714 NumVars, NumUniqueDeclarations,
715 NumUniqueDeclarations + NumComponentLists, NumComponents));
717 OMPFromClause *Clause = new (Mem)
718 OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
719 NumComponentLists, NumComponents);
721 Clause->setVarRefs(Vars);
722 Clause->setClauseInfo(Declarations, ComponentLists);
726 OMPFromClause *OMPFromClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
727 unsigned NumUniqueDeclarations,
728 unsigned NumComponentLists,
729 unsigned NumComponents) {
730 void *Mem = C.Allocate(
731 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
732 OMPClauseMappableExprCommon::MappableComponent>(
733 NumVars, NumUniqueDeclarations,
734 NumUniqueDeclarations + NumComponentLists, NumComponents));
735 return new (Mem) OMPFromClause(NumVars, NumUniqueDeclarations,
736 NumComponentLists, NumComponents);
739 void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
740 assert(VL.size() == varlist_size() &&
741 "Number of private copies is not the same as the preallocated buffer");
742 std::copy(VL.begin(), VL.end(), varlist_end());
745 void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
746 assert(VL.size() == varlist_size() &&
747 "Number of inits is not the same as the preallocated buffer");
748 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
751 OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
752 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
753 SourceLocation EndLoc, ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
754 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
755 MappableExprComponentListsRef ComponentLists) {
756 unsigned NumVars = Vars.size();
757 unsigned NumUniqueDeclarations =
758 getUniqueDeclarationsTotalNumber(Declarations);
759 unsigned NumComponentLists = ComponentLists.size();
760 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
762 // We need to allocate:
763 // 3 x NumVars x Expr* - we have an original list expression for each clause
764 // list entry and an equal number of private copies and inits.
765 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
766 // with each component list.
767 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
768 // number of lists for each unique declaration and the size of each component
770 // NumComponents x MappableComponent - the total of all the components in all
772 void *Mem = C.Allocate(
773 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
774 OMPClauseMappableExprCommon::MappableComponent>(
775 3 * NumVars, NumUniqueDeclarations,
776 NumUniqueDeclarations + NumComponentLists, NumComponents));
778 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(
779 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
780 NumComponentLists, NumComponents);
782 Clause->setVarRefs(Vars);
783 Clause->setPrivateCopies(PrivateVars);
784 Clause->setInits(Inits);
785 Clause->setClauseInfo(Declarations, ComponentLists);
789 OMPUseDevicePtrClause *OMPUseDevicePtrClause::CreateEmpty(
790 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
791 unsigned NumComponentLists, unsigned NumComponents) {
792 void *Mem = C.Allocate(
793 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
794 OMPClauseMappableExprCommon::MappableComponent>(
795 3 * NumVars, NumUniqueDeclarations,
796 NumUniqueDeclarations + NumComponentLists, NumComponents));
797 return new (Mem) OMPUseDevicePtrClause(NumVars, NumUniqueDeclarations,
798 NumComponentLists, NumComponents);
801 OMPIsDevicePtrClause *
802 OMPIsDevicePtrClause::Create(const ASTContext &C, SourceLocation StartLoc,
803 SourceLocation LParenLoc, SourceLocation EndLoc,
804 ArrayRef<Expr *> Vars,
805 ArrayRef<ValueDecl *> Declarations,
806 MappableExprComponentListsRef ComponentLists) {
807 unsigned NumVars = Vars.size();
808 unsigned NumUniqueDeclarations =
809 getUniqueDeclarationsTotalNumber(Declarations);
810 unsigned NumComponentLists = ComponentLists.size();
811 unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
813 // We need to allocate:
814 // NumVars x Expr* - we have an original list expression for each clause list
816 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
817 // with each component list.
818 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
819 // number of lists for each unique declaration and the size of each component
821 // NumComponents x MappableComponent - the total of all the components in all
823 void *Mem = C.Allocate(
824 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
825 OMPClauseMappableExprCommon::MappableComponent>(
826 NumVars, NumUniqueDeclarations,
827 NumUniqueDeclarations + NumComponentLists, NumComponents));
829 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(
830 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
831 NumComponentLists, NumComponents);
833 Clause->setVarRefs(Vars);
834 Clause->setClauseInfo(Declarations, ComponentLists);
838 OMPIsDevicePtrClause *OMPIsDevicePtrClause::CreateEmpty(
839 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
840 unsigned NumComponentLists, unsigned NumComponents) {
841 void *Mem = C.Allocate(
842 totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
843 OMPClauseMappableExprCommon::MappableComponent>(
844 NumVars, NumUniqueDeclarations,
845 NumUniqueDeclarations + NumComponentLists, NumComponents));
846 return new (Mem) OMPIsDevicePtrClause(NumVars, NumUniqueDeclarations,
847 NumComponentLists, NumComponents);