1 //===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===// 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 OpenMPClause.h 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "clang/AST/OpenMPClause.h" 15 #include "clang/AST/ASTContext.h" 16 #include "clang/AST/Decl.h" 17 #include "clang/Basic/LLVM.h" 18 #include "llvm/ADT/SmallPtrSet.h" 19 #include "llvm/Support/Casting.h" 20 #include "llvm/Support/ErrorHandling.h" 21 #include <algorithm> 22 #include <cassert> 23 24 using namespace clang; 25 26 OMPClause::child_range OMPClause::children() { 27 switch (getClauseKind()) { 28 default: 29 break; 30 #define OPENMP_CLAUSE(Name, Class) \ 31 case OMPC_##Name: \ 32 return static_cast<Class *>(this)->children(); 33 #include "clang/Basic/OpenMPKinds.def" 34 } 35 llvm_unreachable("unknown OMPClause"); 36 } 37 38 OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) { 39 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C)); 40 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr; 41 } 42 43 const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) { 44 switch (C->getClauseKind()) { 45 case OMPC_schedule: 46 return static_cast<const OMPScheduleClause *>(C); 47 case OMPC_dist_schedule: 48 return static_cast<const OMPDistScheduleClause *>(C); 49 case OMPC_firstprivate: 50 return static_cast<const OMPFirstprivateClause *>(C); 51 case OMPC_lastprivate: 52 return static_cast<const OMPLastprivateClause *>(C); 53 case OMPC_reduction: 54 return static_cast<const OMPReductionClause *>(C); 55 case OMPC_task_reduction: 56 return static_cast<const OMPTaskReductionClause *>(C); 57 case OMPC_in_reduction: 58 return static_cast<const OMPInReductionClause *>(C); 59 case OMPC_linear: 60 return static_cast<const OMPLinearClause *>(C); 61 case OMPC_if: 62 return static_cast<const OMPIfClause *>(C); 63 case OMPC_num_threads: 64 return static_cast<const OMPNumThreadsClause *>(C); 65 case OMPC_num_teams: 66 return static_cast<const OMPNumTeamsClause *>(C); 67 case OMPC_thread_limit: 68 return static_cast<const OMPThreadLimitClause *>(C); 69 case OMPC_device: 70 return static_cast<const OMPDeviceClause *>(C); 71 case OMPC_default: 72 case OMPC_proc_bind: 73 case OMPC_final: 74 case OMPC_safelen: 75 case OMPC_simdlen: 76 case OMPC_collapse: 77 case OMPC_private: 78 case OMPC_shared: 79 case OMPC_aligned: 80 case OMPC_copyin: 81 case OMPC_copyprivate: 82 case OMPC_ordered: 83 case OMPC_nowait: 84 case OMPC_untied: 85 case OMPC_mergeable: 86 case OMPC_threadprivate: 87 case OMPC_flush: 88 case OMPC_read: 89 case OMPC_write: 90 case OMPC_update: 91 case OMPC_capture: 92 case OMPC_seq_cst: 93 case OMPC_depend: 94 case OMPC_threads: 95 case OMPC_simd: 96 case OMPC_map: 97 case OMPC_priority: 98 case OMPC_grainsize: 99 case OMPC_nogroup: 100 case OMPC_num_tasks: 101 case OMPC_hint: 102 case OMPC_defaultmap: 103 case OMPC_unknown: 104 case OMPC_uniform: 105 case OMPC_to: 106 case OMPC_from: 107 case OMPC_use_device_ptr: 108 case OMPC_is_device_ptr: 109 break; 110 } 111 112 return nullptr; 113 } 114 115 OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) { 116 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C)); 117 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr; 118 } 119 120 const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) { 121 switch (C->getClauseKind()) { 122 case OMPC_lastprivate: 123 return static_cast<const OMPLastprivateClause *>(C); 124 case OMPC_reduction: 125 return static_cast<const OMPReductionClause *>(C); 126 case OMPC_task_reduction: 127 return static_cast<const OMPTaskReductionClause *>(C); 128 case OMPC_in_reduction: 129 return static_cast<const OMPInReductionClause *>(C); 130 case OMPC_linear: 131 return static_cast<const OMPLinearClause *>(C); 132 case OMPC_schedule: 133 case OMPC_dist_schedule: 134 case OMPC_firstprivate: 135 case OMPC_default: 136 case OMPC_proc_bind: 137 case OMPC_if: 138 case OMPC_final: 139 case OMPC_num_threads: 140 case OMPC_safelen: 141 case OMPC_simdlen: 142 case OMPC_collapse: 143 case OMPC_private: 144 case OMPC_shared: 145 case OMPC_aligned: 146 case OMPC_copyin: 147 case OMPC_copyprivate: 148 case OMPC_ordered: 149 case OMPC_nowait: 150 case OMPC_untied: 151 case OMPC_mergeable: 152 case OMPC_threadprivate: 153 case OMPC_flush: 154 case OMPC_read: 155 case OMPC_write: 156 case OMPC_update: 157 case OMPC_capture: 158 case OMPC_seq_cst: 159 case OMPC_depend: 160 case OMPC_device: 161 case OMPC_threads: 162 case OMPC_simd: 163 case OMPC_map: 164 case OMPC_num_teams: 165 case OMPC_thread_limit: 166 case OMPC_priority: 167 case OMPC_grainsize: 168 case OMPC_nogroup: 169 case OMPC_num_tasks: 170 case OMPC_hint: 171 case OMPC_defaultmap: 172 case OMPC_unknown: 173 case OMPC_uniform: 174 case OMPC_to: 175 case OMPC_from: 176 case OMPC_use_device_ptr: 177 case OMPC_is_device_ptr: 178 break; 179 } 180 181 return nullptr; 182 } 183 184 OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num, 185 unsigned NumLoops, 186 SourceLocation StartLoc, 187 SourceLocation LParenLoc, 188 SourceLocation EndLoc) { 189 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops)); 190 auto *Clause = 191 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc); 192 for (unsigned I = 0; I < NumLoops; ++I) { 193 Clause->setLoopNumIterations(I, nullptr); 194 Clause->setLoopCounter(I, nullptr); 195 } 196 return Clause; 197 } 198 199 OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C, 200 unsigned NumLoops) { 201 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops)); 202 auto *Clause = new (Mem) OMPOrderedClause(NumLoops); 203 for (unsigned I = 0; I < NumLoops; ++I) { 204 Clause->setLoopNumIterations(I, nullptr); 205 Clause->setLoopCounter(I, nullptr); 206 } 207 return Clause; 208 } 209 210 void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop, 211 Expr *NumIterations) { 212 assert(NumLoop < NumberOfLoops && "out of loops number."); 213 getTrailingObjects<Expr *>()[NumLoop] = NumIterations; 214 } 215 216 ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const { 217 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops); 218 } 219 220 void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) { 221 assert(NumLoop < NumberOfLoops && "out of loops number."); 222 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter; 223 } 224 225 Expr *OMPOrderedClause::getLoopCunter(unsigned NumLoop) { 226 assert(NumLoop < NumberOfLoops && "out of loops number."); 227 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop]; 228 } 229 230 const Expr *OMPOrderedClause::getLoopCunter(unsigned NumLoop) const { 231 assert(NumLoop < NumberOfLoops && "out of loops number."); 232 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop]; 233 } 234 235 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { 236 assert(VL.size() == varlist_size() && 237 "Number of private copies is not the same as the preallocated buffer"); 238 std::copy(VL.begin(), VL.end(), varlist_end()); 239 } 240 241 OMPPrivateClause * 242 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, 243 SourceLocation LParenLoc, SourceLocation EndLoc, 244 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) { 245 // Allocate space for private variables and initializer expressions. 246 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size())); 247 OMPPrivateClause *Clause = 248 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 249 Clause->setVarRefs(VL); 250 Clause->setPrivateCopies(PrivateVL); 251 return Clause; 252 } 253 254 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, 255 unsigned N) { 256 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N)); 257 return new (Mem) OMPPrivateClause(N); 258 } 259 260 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { 261 assert(VL.size() == varlist_size() && 262 "Number of private copies is not the same as the preallocated buffer"); 263 std::copy(VL.begin(), VL.end(), varlist_end()); 264 } 265 266 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) { 267 assert(VL.size() == varlist_size() && 268 "Number of inits is not the same as the preallocated buffer"); 269 std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); 270 } 271 272 OMPFirstprivateClause * 273 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, 274 SourceLocation LParenLoc, SourceLocation EndLoc, 275 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, 276 ArrayRef<Expr *> InitVL, Stmt *PreInit) { 277 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size())); 278 OMPFirstprivateClause *Clause = 279 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 280 Clause->setVarRefs(VL); 281 Clause->setPrivateCopies(PrivateVL); 282 Clause->setInits(InitVL); 283 Clause->setPreInitStmt(PreInit); 284 return Clause; 285 } 286 287 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, 288 unsigned N) { 289 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N)); 290 return new (Mem) OMPFirstprivateClause(N); 291 } 292 293 void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) { 294 assert(PrivateCopies.size() == varlist_size() && 295 "Number of private copies is not the same as the preallocated buffer"); 296 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end()); 297 } 298 299 void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { 300 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " 301 "not the same as the " 302 "preallocated buffer"); 303 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end()); 304 } 305 306 void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { 307 assert(DstExprs.size() == varlist_size() && "Number of destination " 308 "expressions is not the same as " 309 "the preallocated buffer"); 310 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); 311 } 312 313 void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { 314 assert(AssignmentOps.size() == varlist_size() && 315 "Number of assignment expressions is not the same as the preallocated " 316 "buffer"); 317 std::copy(AssignmentOps.begin(), AssignmentOps.end(), 318 getDestinationExprs().end()); 319 } 320 321 OMPLastprivateClause *OMPLastprivateClause::Create( 322 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 323 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 324 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit, 325 Expr *PostUpdate) { 326 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); 327 OMPLastprivateClause *Clause = 328 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 329 Clause->setVarRefs(VL); 330 Clause->setSourceExprs(SrcExprs); 331 Clause->setDestinationExprs(DstExprs); 332 Clause->setAssignmentOps(AssignmentOps); 333 Clause->setPreInitStmt(PreInit); 334 Clause->setPostUpdateExpr(PostUpdate); 335 return Clause; 336 } 337 338 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, 339 unsigned N) { 340 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); 341 return new (Mem) OMPLastprivateClause(N); 342 } 343 344 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, 345 SourceLocation StartLoc, 346 SourceLocation LParenLoc, 347 SourceLocation EndLoc, 348 ArrayRef<Expr *> VL) { 349 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); 350 OMPSharedClause *Clause = 351 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size()); 352 Clause->setVarRefs(VL); 353 return Clause; 354 } 355 356 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) { 357 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); 358 return new (Mem) OMPSharedClause(N); 359 } 360 361 void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) { 362 assert(PL.size() == varlist_size() && 363 "Number of privates is not the same as the preallocated buffer"); 364 std::copy(PL.begin(), PL.end(), varlist_end()); 365 } 366 367 void OMPLinearClause::setInits(ArrayRef<Expr *> IL) { 368 assert(IL.size() == varlist_size() && 369 "Number of inits is not the same as the preallocated buffer"); 370 std::copy(IL.begin(), IL.end(), getPrivates().end()); 371 } 372 373 void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) { 374 assert(UL.size() == varlist_size() && 375 "Number of updates is not the same as the preallocated buffer"); 376 std::copy(UL.begin(), UL.end(), getInits().end()); 377 } 378 379 void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) { 380 assert(FL.size() == varlist_size() && 381 "Number of final updates is not the same as the preallocated buffer"); 382 std::copy(FL.begin(), FL.end(), getUpdates().end()); 383 } 384 385 OMPLinearClause *OMPLinearClause::Create( 386 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 387 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, 388 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, 389 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, 390 Stmt *PreInit, Expr *PostUpdate) { 391 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions 392 // (Step and CalcStep). 393 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2)); 394 OMPLinearClause *Clause = new (Mem) OMPLinearClause( 395 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size()); 396 Clause->setVarRefs(VL); 397 Clause->setPrivates(PL); 398 Clause->setInits(IL); 399 // Fill update and final expressions with zeroes, they are provided later, 400 // after the directive construction. 401 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(), 402 nullptr); 403 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(), 404 nullptr); 405 Clause->setStep(Step); 406 Clause->setCalcStep(CalcStep); 407 Clause->setPreInitStmt(PreInit); 408 Clause->setPostUpdateExpr(PostUpdate); 409 return Clause; 410 } 411 412 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, 413 unsigned NumVars) { 414 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions 415 // (Step and CalcStep). 416 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2)); 417 return new (Mem) OMPLinearClause(NumVars); 418 } 419 420 OMPAlignedClause * 421 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, 422 SourceLocation LParenLoc, SourceLocation ColonLoc, 423 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { 424 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); 425 OMPAlignedClause *Clause = new (Mem) 426 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); 427 Clause->setVarRefs(VL); 428 Clause->setAlignment(A); 429 return Clause; 430 } 431 432 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, 433 unsigned NumVars) { 434 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1)); 435 return new (Mem) OMPAlignedClause(NumVars); 436 } 437 438 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { 439 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " 440 "not the same as the " 441 "preallocated buffer"); 442 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); 443 } 444 445 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { 446 assert(DstExprs.size() == varlist_size() && "Number of destination " 447 "expressions is not the same as " 448 "the preallocated buffer"); 449 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); 450 } 451 452 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { 453 assert(AssignmentOps.size() == varlist_size() && 454 "Number of assignment expressions is not the same as the preallocated " 455 "buffer"); 456 std::copy(AssignmentOps.begin(), AssignmentOps.end(), 457 getDestinationExprs().end()); 458 } 459 460 OMPCopyinClause *OMPCopyinClause::Create( 461 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 462 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 463 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { 464 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); 465 OMPCopyinClause *Clause = 466 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size()); 467 Clause->setVarRefs(VL); 468 Clause->setSourceExprs(SrcExprs); 469 Clause->setDestinationExprs(DstExprs); 470 Clause->setAssignmentOps(AssignmentOps); 471 return Clause; 472 } 473 474 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) { 475 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); 476 return new (Mem) OMPCopyinClause(N); 477 } 478 479 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { 480 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " 481 "not the same as the " 482 "preallocated buffer"); 483 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); 484 } 485 486 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { 487 assert(DstExprs.size() == varlist_size() && "Number of destination " 488 "expressions is not the same as " 489 "the preallocated buffer"); 490 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); 491 } 492 493 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { 494 assert(AssignmentOps.size() == varlist_size() && 495 "Number of assignment expressions is not the same as the preallocated " 496 "buffer"); 497 std::copy(AssignmentOps.begin(), AssignmentOps.end(), 498 getDestinationExprs().end()); 499 } 500 501 OMPCopyprivateClause *OMPCopyprivateClause::Create( 502 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 503 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 504 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { 505 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); 506 OMPCopyprivateClause *Clause = 507 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 508 Clause->setVarRefs(VL); 509 Clause->setSourceExprs(SrcExprs); 510 Clause->setDestinationExprs(DstExprs); 511 Clause->setAssignmentOps(AssignmentOps); 512 return Clause; 513 } 514 515 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, 516 unsigned N) { 517 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); 518 return new (Mem) OMPCopyprivateClause(N); 519 } 520 521 void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) { 522 assert(Privates.size() == varlist_size() && 523 "Number of private copies is not the same as the preallocated buffer"); 524 std::copy(Privates.begin(), Privates.end(), varlist_end()); 525 } 526 527 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { 528 assert( 529 LHSExprs.size() == varlist_size() && 530 "Number of LHS expressions is not the same as the preallocated buffer"); 531 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); 532 } 533 534 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { 535 assert( 536 RHSExprs.size() == varlist_size() && 537 "Number of RHS expressions is not the same as the preallocated buffer"); 538 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); 539 } 540 541 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { 542 assert(ReductionOps.size() == varlist_size() && "Number of reduction " 543 "expressions is not the same " 544 "as the preallocated buffer"); 545 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); 546 } 547 548 OMPReductionClause *OMPReductionClause::Create( 549 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 550 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, 551 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, 552 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, 553 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit, 554 Expr *PostUpdate) { 555 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); 556 OMPReductionClause *Clause = new (Mem) OMPReductionClause( 557 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); 558 Clause->setVarRefs(VL); 559 Clause->setPrivates(Privates); 560 Clause->setLHSExprs(LHSExprs); 561 Clause->setRHSExprs(RHSExprs); 562 Clause->setReductionOps(ReductionOps); 563 Clause->setPreInitStmt(PreInit); 564 Clause->setPostUpdateExpr(PostUpdate); 565 return Clause; 566 } 567 568 OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C, 569 unsigned N) { 570 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); 571 return new (Mem) OMPReductionClause(N); 572 } 573 574 void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) { 575 assert(Privates.size() == varlist_size() && 576 "Number of private copies is not the same as the preallocated buffer"); 577 std::copy(Privates.begin(), Privates.end(), varlist_end()); 578 } 579 580 void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { 581 assert( 582 LHSExprs.size() == varlist_size() && 583 "Number of LHS expressions is not the same as the preallocated buffer"); 584 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); 585 } 586 587 void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { 588 assert( 589 RHSExprs.size() == varlist_size() && 590 "Number of RHS expressions is not the same as the preallocated buffer"); 591 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); 592 } 593 594 void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { 595 assert(ReductionOps.size() == varlist_size() && "Number of task reduction " 596 "expressions is not the same " 597 "as the preallocated buffer"); 598 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); 599 } 600 601 OMPTaskReductionClause *OMPTaskReductionClause::Create( 602 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 603 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, 604 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, 605 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, 606 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit, 607 Expr *PostUpdate) { 608 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); 609 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause( 610 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); 611 Clause->setVarRefs(VL); 612 Clause->setPrivates(Privates); 613 Clause->setLHSExprs(LHSExprs); 614 Clause->setRHSExprs(RHSExprs); 615 Clause->setReductionOps(ReductionOps); 616 Clause->setPreInitStmt(PreInit); 617 Clause->setPostUpdateExpr(PostUpdate); 618 return Clause; 619 } 620 621 OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C, 622 unsigned N) { 623 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); 624 return new (Mem) OMPTaskReductionClause(N); 625 } 626 627 void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) { 628 assert(Privates.size() == varlist_size() && 629 "Number of private copies is not the same as the preallocated buffer"); 630 std::copy(Privates.begin(), Privates.end(), varlist_end()); 631 } 632 633 void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { 634 assert( 635 LHSExprs.size() == varlist_size() && 636 "Number of LHS expressions is not the same as the preallocated buffer"); 637 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); 638 } 639 640 void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { 641 assert( 642 RHSExprs.size() == varlist_size() && 643 "Number of RHS expressions is not the same as the preallocated buffer"); 644 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); 645 } 646 647 void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { 648 assert(ReductionOps.size() == varlist_size() && "Number of in reduction " 649 "expressions is not the same " 650 "as the preallocated buffer"); 651 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); 652 } 653 654 void OMPInReductionClause::setTaskgroupDescriptors( 655 ArrayRef<Expr *> TaskgroupDescriptors) { 656 assert(TaskgroupDescriptors.size() == varlist_size() && 657 "Number of in reduction descriptors is not the same as the " 658 "preallocated buffer"); 659 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(), 660 getReductionOps().end()); 661 } 662 663 OMPInReductionClause *OMPInReductionClause::Create( 664 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 665 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, 666 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, 667 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, 668 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, 669 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) { 670 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size())); 671 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause( 672 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); 673 Clause->setVarRefs(VL); 674 Clause->setPrivates(Privates); 675 Clause->setLHSExprs(LHSExprs); 676 Clause->setRHSExprs(RHSExprs); 677 Clause->setReductionOps(ReductionOps); 678 Clause->setTaskgroupDescriptors(TaskgroupDescriptors); 679 Clause->setPreInitStmt(PreInit); 680 Clause->setPostUpdateExpr(PostUpdate); 681 return Clause; 682 } 683 684 OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C, 685 unsigned N) { 686 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N)); 687 return new (Mem) OMPInReductionClause(N); 688 } 689 690 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, 691 SourceLocation StartLoc, 692 SourceLocation LParenLoc, 693 SourceLocation EndLoc, 694 ArrayRef<Expr *> VL) { 695 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); 696 OMPFlushClause *Clause = 697 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); 698 Clause->setVarRefs(VL); 699 return Clause; 700 } 701 702 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { 703 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); 704 return new (Mem) OMPFlushClause(N); 705 } 706 707 OMPDependClause * 708 OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc, 709 SourceLocation LParenLoc, SourceLocation EndLoc, 710 OpenMPDependClauseKind DepKind, SourceLocation DepLoc, 711 SourceLocation ColonLoc, ArrayRef<Expr *> VL, 712 unsigned NumLoops) { 713 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops)); 714 OMPDependClause *Clause = new (Mem) 715 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops); 716 Clause->setVarRefs(VL); 717 Clause->setDependencyKind(DepKind); 718 Clause->setDependencyLoc(DepLoc); 719 Clause->setColonLoc(ColonLoc); 720 for (unsigned I = 0 ; I < NumLoops; ++I) 721 Clause->setLoopData(I, nullptr); 722 return Clause; 723 } 724 725 OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N, 726 unsigned NumLoops) { 727 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops)); 728 return new (Mem) OMPDependClause(N, NumLoops); 729 } 730 731 void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) { 732 assert((getDependencyKind() == OMPC_DEPEND_sink || 733 getDependencyKind() == OMPC_DEPEND_source) && 734 NumLoop < NumLoops && 735 "Expected sink or source depend + loop index must be less number of " 736 "loops."); 737 auto It = std::next(getVarRefs().end(), NumLoop); 738 *It = Cnt; 739 } 740 741 Expr *OMPDependClause::getLoopData(unsigned NumLoop) { 742 assert((getDependencyKind() == OMPC_DEPEND_sink || 743 getDependencyKind() == OMPC_DEPEND_source) && 744 NumLoop < NumLoops && 745 "Expected sink or source depend + loop index must be less number of " 746 "loops."); 747 auto It = std::next(getVarRefs().end(), NumLoop); 748 return *It; 749 } 750 751 const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const { 752 assert((getDependencyKind() == OMPC_DEPEND_sink || 753 getDependencyKind() == OMPC_DEPEND_source) && 754 NumLoop < NumLoops && 755 "Expected sink or source depend + loop index must be less number of " 756 "loops."); 757 auto It = std::next(getVarRefs().end(), NumLoop); 758 return *It; 759 } 760 761 unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber( 762 MappableExprComponentListsRef ComponentLists) { 763 unsigned TotalNum = 0u; 764 for (auto &C : ComponentLists) 765 TotalNum += C.size(); 766 return TotalNum; 767 } 768 769 unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber( 770 ArrayRef<const ValueDecl *> Declarations) { 771 unsigned TotalNum = 0u; 772 llvm::SmallPtrSet<const ValueDecl *, 8> Cache; 773 for (const ValueDecl *D : Declarations) { 774 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr; 775 if (Cache.count(VD)) 776 continue; 777 ++TotalNum; 778 Cache.insert(VD); 779 } 780 return TotalNum; 781 } 782 783 OMPMapClause * 784 OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc, 785 SourceLocation LParenLoc, SourceLocation EndLoc, 786 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, 787 MappableExprComponentListsRef ComponentLists, 788 OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type, 789 bool TypeIsImplicit, SourceLocation TypeLoc) { 790 unsigned NumVars = Vars.size(); 791 unsigned NumUniqueDeclarations = 792 getUniqueDeclarationsTotalNumber(Declarations); 793 unsigned NumComponentLists = ComponentLists.size(); 794 unsigned NumComponents = getComponentsTotalNumber(ComponentLists); 795 796 // We need to allocate: 797 // NumVars x Expr* - we have an original list expression for each clause list 798 // entry. 799 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 800 // with each component list. 801 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 802 // number of lists for each unique declaration and the size of each component 803 // list. 804 // NumComponents x MappableComponent - the total of all the components in all 805 // the lists. 806 void *Mem = C.Allocate( 807 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 808 OMPClauseMappableExprCommon::MappableComponent>( 809 NumVars, NumUniqueDeclarations, 810 NumUniqueDeclarations + NumComponentLists, NumComponents)); 811 OMPMapClause *Clause = new (Mem) OMPMapClause( 812 TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc, 813 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents); 814 815 Clause->setVarRefs(Vars); 816 Clause->setClauseInfo(Declarations, ComponentLists); 817 Clause->setMapTypeModifier(TypeModifier); 818 Clause->setMapType(Type); 819 Clause->setMapLoc(TypeLoc); 820 return Clause; 821 } 822 823 OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars, 824 unsigned NumUniqueDeclarations, 825 unsigned NumComponentLists, 826 unsigned NumComponents) { 827 void *Mem = C.Allocate( 828 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 829 OMPClauseMappableExprCommon::MappableComponent>( 830 NumVars, NumUniqueDeclarations, 831 NumUniqueDeclarations + NumComponentLists, NumComponents)); 832 return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations, 833 NumComponentLists, NumComponents); 834 } 835 836 OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc, 837 SourceLocation LParenLoc, 838 SourceLocation EndLoc, ArrayRef<Expr *> Vars, 839 ArrayRef<ValueDecl *> Declarations, 840 MappableExprComponentListsRef ComponentLists) { 841 unsigned NumVars = Vars.size(); 842 unsigned NumUniqueDeclarations = 843 getUniqueDeclarationsTotalNumber(Declarations); 844 unsigned NumComponentLists = ComponentLists.size(); 845 unsigned NumComponents = getComponentsTotalNumber(ComponentLists); 846 847 // We need to allocate: 848 // NumVars x Expr* - we have an original list expression for each clause list 849 // entry. 850 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 851 // with each component list. 852 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 853 // number of lists for each unique declaration and the size of each component 854 // list. 855 // NumComponents x MappableComponent - the total of all the components in all 856 // the lists. 857 void *Mem = C.Allocate( 858 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 859 OMPClauseMappableExprCommon::MappableComponent>( 860 NumVars, NumUniqueDeclarations, 861 NumUniqueDeclarations + NumComponentLists, NumComponents)); 862 863 OMPToClause *Clause = new (Mem) 864 OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations, 865 NumComponentLists, NumComponents); 866 867 Clause->setVarRefs(Vars); 868 Clause->setClauseInfo(Declarations, ComponentLists); 869 return Clause; 870 } 871 872 OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars, 873 unsigned NumUniqueDeclarations, 874 unsigned NumComponentLists, 875 unsigned NumComponents) { 876 void *Mem = C.Allocate( 877 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 878 OMPClauseMappableExprCommon::MappableComponent>( 879 NumVars, NumUniqueDeclarations, 880 NumUniqueDeclarations + NumComponentLists, NumComponents)); 881 return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations, 882 NumComponentLists, NumComponents); 883 } 884 885 OMPFromClause * 886 OMPFromClause::Create(const ASTContext &C, SourceLocation StartLoc, 887 SourceLocation LParenLoc, SourceLocation EndLoc, 888 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, 889 MappableExprComponentListsRef ComponentLists) { 890 unsigned NumVars = Vars.size(); 891 unsigned NumUniqueDeclarations = 892 getUniqueDeclarationsTotalNumber(Declarations); 893 unsigned NumComponentLists = ComponentLists.size(); 894 unsigned NumComponents = getComponentsTotalNumber(ComponentLists); 895 896 // We need to allocate: 897 // NumVars x Expr* - we have an original list expression for each clause list 898 // entry. 899 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 900 // with each component list. 901 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 902 // number of lists for each unique declaration and the size of each component 903 // list. 904 // NumComponents x MappableComponent - the total of all the components in all 905 // the lists. 906 void *Mem = C.Allocate( 907 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 908 OMPClauseMappableExprCommon::MappableComponent>( 909 NumVars, NumUniqueDeclarations, 910 NumUniqueDeclarations + NumComponentLists, NumComponents)); 911 912 OMPFromClause *Clause = new (Mem) 913 OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations, 914 NumComponentLists, NumComponents); 915 916 Clause->setVarRefs(Vars); 917 Clause->setClauseInfo(Declarations, ComponentLists); 918 return Clause; 919 } 920 921 OMPFromClause *OMPFromClause::CreateEmpty(const ASTContext &C, unsigned NumVars, 922 unsigned NumUniqueDeclarations, 923 unsigned NumComponentLists, 924 unsigned NumComponents) { 925 void *Mem = C.Allocate( 926 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 927 OMPClauseMappableExprCommon::MappableComponent>( 928 NumVars, NumUniqueDeclarations, 929 NumUniqueDeclarations + NumComponentLists, NumComponents)); 930 return new (Mem) OMPFromClause(NumVars, NumUniqueDeclarations, 931 NumComponentLists, NumComponents); 932 } 933 934 void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) { 935 assert(VL.size() == varlist_size() && 936 "Number of private copies is not the same as the preallocated buffer"); 937 std::copy(VL.begin(), VL.end(), varlist_end()); 938 } 939 940 void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) { 941 assert(VL.size() == varlist_size() && 942 "Number of inits is not the same as the preallocated buffer"); 943 std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); 944 } 945 946 OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create( 947 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 948 SourceLocation EndLoc, ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars, 949 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations, 950 MappableExprComponentListsRef ComponentLists) { 951 unsigned NumVars = Vars.size(); 952 unsigned NumUniqueDeclarations = 953 getUniqueDeclarationsTotalNumber(Declarations); 954 unsigned NumComponentLists = ComponentLists.size(); 955 unsigned NumComponents = getComponentsTotalNumber(ComponentLists); 956 957 // We need to allocate: 958 // 3 x NumVars x Expr* - we have an original list expression for each clause 959 // list entry and an equal number of private copies and inits. 960 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 961 // with each component list. 962 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 963 // number of lists for each unique declaration and the size of each component 964 // list. 965 // NumComponents x MappableComponent - the total of all the components in all 966 // the lists. 967 void *Mem = C.Allocate( 968 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 969 OMPClauseMappableExprCommon::MappableComponent>( 970 3 * NumVars, NumUniqueDeclarations, 971 NumUniqueDeclarations + NumComponentLists, NumComponents)); 972 973 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause( 974 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations, 975 NumComponentLists, NumComponents); 976 977 Clause->setVarRefs(Vars); 978 Clause->setPrivateCopies(PrivateVars); 979 Clause->setInits(Inits); 980 Clause->setClauseInfo(Declarations, ComponentLists); 981 return Clause; 982 } 983 984 OMPUseDevicePtrClause *OMPUseDevicePtrClause::CreateEmpty( 985 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations, 986 unsigned NumComponentLists, unsigned NumComponents) { 987 void *Mem = C.Allocate( 988 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 989 OMPClauseMappableExprCommon::MappableComponent>( 990 3 * NumVars, NumUniqueDeclarations, 991 NumUniqueDeclarations + NumComponentLists, NumComponents)); 992 return new (Mem) OMPUseDevicePtrClause(NumVars, NumUniqueDeclarations, 993 NumComponentLists, NumComponents); 994 } 995 996 OMPIsDevicePtrClause * 997 OMPIsDevicePtrClause::Create(const ASTContext &C, SourceLocation StartLoc, 998 SourceLocation LParenLoc, SourceLocation EndLoc, 999 ArrayRef<Expr *> Vars, 1000 ArrayRef<ValueDecl *> Declarations, 1001 MappableExprComponentListsRef ComponentLists) { 1002 unsigned NumVars = Vars.size(); 1003 unsigned NumUniqueDeclarations = 1004 getUniqueDeclarationsTotalNumber(Declarations); 1005 unsigned NumComponentLists = ComponentLists.size(); 1006 unsigned NumComponents = getComponentsTotalNumber(ComponentLists); 1007 1008 // We need to allocate: 1009 // NumVars x Expr* - we have an original list expression for each clause list 1010 // entry. 1011 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 1012 // with each component list. 1013 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 1014 // number of lists for each unique declaration and the size of each component 1015 // list. 1016 // NumComponents x MappableComponent - the total of all the components in all 1017 // the lists. 1018 void *Mem = C.Allocate( 1019 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1020 OMPClauseMappableExprCommon::MappableComponent>( 1021 NumVars, NumUniqueDeclarations, 1022 NumUniqueDeclarations + NumComponentLists, NumComponents)); 1023 1024 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause( 1025 StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations, 1026 NumComponentLists, NumComponents); 1027 1028 Clause->setVarRefs(Vars); 1029 Clause->setClauseInfo(Declarations, ComponentLists); 1030 return Clause; 1031 } 1032 1033 OMPIsDevicePtrClause *OMPIsDevicePtrClause::CreateEmpty( 1034 const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations, 1035 unsigned NumComponentLists, unsigned NumComponents) { 1036 void *Mem = C.Allocate( 1037 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1038 OMPClauseMappableExprCommon::MappableComponent>( 1039 NumVars, NumUniqueDeclarations, 1040 NumUniqueDeclarations + NumComponentLists, NumComponents)); 1041 return new (Mem) OMPIsDevicePtrClause(NumVars, NumUniqueDeclarations, 1042 NumComponentLists, NumComponents); 1043 } 1044