1 //===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements the subclesses of Stmt class declared in OpenMPClause.h 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "clang/AST/OpenMPClause.h" 14 #include "clang/AST/ASTContext.h" 15 #include "clang/AST/Decl.h" 16 #include "clang/AST/DeclOpenMP.h" 17 #include "clang/Basic/LLVM.h" 18 #include "llvm/ADT/SmallPtrSet.h" 19 #include "llvm/Support/Casting.h" 20 #include "llvm/Support/ErrorHandling.h" 21 #include <algorithm> 22 #include <cassert> 23 24 using namespace clang; 25 26 OMPClause::child_range OMPClause::children() { 27 switch (getClauseKind()) { 28 default: 29 break; 30 #define OPENMP_CLAUSE(Name, Class) \ 31 case OMPC_##Name: \ 32 return static_cast<Class *>(this)->children(); 33 #include "clang/Basic/OpenMPKinds.def" 34 } 35 llvm_unreachable("unknown OMPClause"); 36 } 37 38 OMPClause::child_range OMPClause::used_children() { 39 switch (getClauseKind()) { 40 #define OPENMP_CLAUSE(Name, Class) \ 41 case OMPC_##Name: \ 42 return static_cast<Class *>(this)->used_children(); 43 #include "clang/Basic/OpenMPKinds.def" 44 case OMPC_threadprivate: 45 case OMPC_uniform: 46 case OMPC_device_type: 47 case OMPC_match: 48 case OMPC_unknown: 49 break; 50 } 51 llvm_unreachable("unknown OMPClause"); 52 } 53 54 OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) { 55 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C)); 56 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr; 57 } 58 59 const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) { 60 switch (C->getClauseKind()) { 61 case OMPC_schedule: 62 return static_cast<const OMPScheduleClause *>(C); 63 case OMPC_dist_schedule: 64 return static_cast<const OMPDistScheduleClause *>(C); 65 case OMPC_firstprivate: 66 return static_cast<const OMPFirstprivateClause *>(C); 67 case OMPC_lastprivate: 68 return static_cast<const OMPLastprivateClause *>(C); 69 case OMPC_reduction: 70 return static_cast<const OMPReductionClause *>(C); 71 case OMPC_task_reduction: 72 return static_cast<const OMPTaskReductionClause *>(C); 73 case OMPC_in_reduction: 74 return static_cast<const OMPInReductionClause *>(C); 75 case OMPC_linear: 76 return static_cast<const OMPLinearClause *>(C); 77 case OMPC_if: 78 return static_cast<const OMPIfClause *>(C); 79 case OMPC_num_threads: 80 return static_cast<const OMPNumThreadsClause *>(C); 81 case OMPC_num_teams: 82 return static_cast<const OMPNumTeamsClause *>(C); 83 case OMPC_thread_limit: 84 return static_cast<const OMPThreadLimitClause *>(C); 85 case OMPC_device: 86 return static_cast<const OMPDeviceClause *>(C); 87 case OMPC_default: 88 case OMPC_proc_bind: 89 case OMPC_final: 90 case OMPC_safelen: 91 case OMPC_simdlen: 92 case OMPC_allocator: 93 case OMPC_allocate: 94 case OMPC_collapse: 95 case OMPC_private: 96 case OMPC_shared: 97 case OMPC_aligned: 98 case OMPC_copyin: 99 case OMPC_copyprivate: 100 case OMPC_ordered: 101 case OMPC_nowait: 102 case OMPC_untied: 103 case OMPC_mergeable: 104 case OMPC_threadprivate: 105 case OMPC_flush: 106 case OMPC_read: 107 case OMPC_write: 108 case OMPC_update: 109 case OMPC_capture: 110 case OMPC_seq_cst: 111 case OMPC_depend: 112 case OMPC_threads: 113 case OMPC_simd: 114 case OMPC_map: 115 case OMPC_priority: 116 case OMPC_grainsize: 117 case OMPC_nogroup: 118 case OMPC_num_tasks: 119 case OMPC_hint: 120 case OMPC_defaultmap: 121 case OMPC_unknown: 122 case OMPC_uniform: 123 case OMPC_to: 124 case OMPC_from: 125 case OMPC_use_device_ptr: 126 case OMPC_is_device_ptr: 127 case OMPC_unified_address: 128 case OMPC_unified_shared_memory: 129 case OMPC_reverse_offload: 130 case OMPC_dynamic_allocators: 131 case OMPC_atomic_default_mem_order: 132 case OMPC_device_type: 133 case OMPC_match: 134 break; 135 } 136 137 return nullptr; 138 } 139 140 OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) { 141 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C)); 142 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr; 143 } 144 145 const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) { 146 switch (C->getClauseKind()) { 147 case OMPC_lastprivate: 148 return static_cast<const OMPLastprivateClause *>(C); 149 case OMPC_reduction: 150 return static_cast<const OMPReductionClause *>(C); 151 case OMPC_task_reduction: 152 return static_cast<const OMPTaskReductionClause *>(C); 153 case OMPC_in_reduction: 154 return static_cast<const OMPInReductionClause *>(C); 155 case OMPC_linear: 156 return static_cast<const OMPLinearClause *>(C); 157 case OMPC_schedule: 158 case OMPC_dist_schedule: 159 case OMPC_firstprivate: 160 case OMPC_default: 161 case OMPC_proc_bind: 162 case OMPC_if: 163 case OMPC_final: 164 case OMPC_num_threads: 165 case OMPC_safelen: 166 case OMPC_simdlen: 167 case OMPC_allocator: 168 case OMPC_allocate: 169 case OMPC_collapse: 170 case OMPC_private: 171 case OMPC_shared: 172 case OMPC_aligned: 173 case OMPC_copyin: 174 case OMPC_copyprivate: 175 case OMPC_ordered: 176 case OMPC_nowait: 177 case OMPC_untied: 178 case OMPC_mergeable: 179 case OMPC_threadprivate: 180 case OMPC_flush: 181 case OMPC_read: 182 case OMPC_write: 183 case OMPC_update: 184 case OMPC_capture: 185 case OMPC_seq_cst: 186 case OMPC_depend: 187 case OMPC_device: 188 case OMPC_threads: 189 case OMPC_simd: 190 case OMPC_map: 191 case OMPC_num_teams: 192 case OMPC_thread_limit: 193 case OMPC_priority: 194 case OMPC_grainsize: 195 case OMPC_nogroup: 196 case OMPC_num_tasks: 197 case OMPC_hint: 198 case OMPC_defaultmap: 199 case OMPC_unknown: 200 case OMPC_uniform: 201 case OMPC_to: 202 case OMPC_from: 203 case OMPC_use_device_ptr: 204 case OMPC_is_device_ptr: 205 case OMPC_unified_address: 206 case OMPC_unified_shared_memory: 207 case OMPC_reverse_offload: 208 case OMPC_dynamic_allocators: 209 case OMPC_atomic_default_mem_order: 210 case OMPC_device_type: 211 case OMPC_match: 212 break; 213 } 214 215 return nullptr; 216 } 217 218 /// Gets the address of the original, non-captured, expression used in the 219 /// clause as the preinitializer. 220 static Stmt **getAddrOfExprAsWritten(Stmt *S) { 221 if (!S) 222 return nullptr; 223 if (auto *DS = dyn_cast<DeclStmt>(S)) { 224 assert(DS->isSingleDecl() && "Only single expression must be captured."); 225 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl())) 226 return OED->getInitAddress(); 227 } 228 return nullptr; 229 } 230 231 OMPClause::child_range OMPIfClause::used_children() { 232 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) 233 return child_range(C, C + 1); 234 return child_range(&Condition, &Condition + 1); 235 } 236 237 OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num, 238 unsigned NumLoops, 239 SourceLocation StartLoc, 240 SourceLocation LParenLoc, 241 SourceLocation EndLoc) { 242 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops)); 243 auto *Clause = 244 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc); 245 for (unsigned I = 0; I < NumLoops; ++I) { 246 Clause->setLoopNumIterations(I, nullptr); 247 Clause->setLoopCounter(I, nullptr); 248 } 249 return Clause; 250 } 251 252 OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C, 253 unsigned NumLoops) { 254 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops)); 255 auto *Clause = new (Mem) OMPOrderedClause(NumLoops); 256 for (unsigned I = 0; I < NumLoops; ++I) { 257 Clause->setLoopNumIterations(I, nullptr); 258 Clause->setLoopCounter(I, nullptr); 259 } 260 return Clause; 261 } 262 263 void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop, 264 Expr *NumIterations) { 265 assert(NumLoop < NumberOfLoops && "out of loops number."); 266 getTrailingObjects<Expr *>()[NumLoop] = NumIterations; 267 } 268 269 ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const { 270 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops); 271 } 272 273 void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) { 274 assert(NumLoop < NumberOfLoops && "out of loops number."); 275 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter; 276 } 277 278 Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) { 279 assert(NumLoop < NumberOfLoops && "out of loops number."); 280 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop]; 281 } 282 283 const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const { 284 assert(NumLoop < NumberOfLoops && "out of loops number."); 285 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop]; 286 } 287 288 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { 289 assert(VL.size() == varlist_size() && 290 "Number of private copies is not the same as the preallocated buffer"); 291 std::copy(VL.begin(), VL.end(), varlist_end()); 292 } 293 294 OMPPrivateClause * 295 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, 296 SourceLocation LParenLoc, SourceLocation EndLoc, 297 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) { 298 // Allocate space for private variables and initializer expressions. 299 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size())); 300 OMPPrivateClause *Clause = 301 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 302 Clause->setVarRefs(VL); 303 Clause->setPrivateCopies(PrivateVL); 304 return Clause; 305 } 306 307 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, 308 unsigned N) { 309 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N)); 310 return new (Mem) OMPPrivateClause(N); 311 } 312 313 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { 314 assert(VL.size() == varlist_size() && 315 "Number of private copies is not the same as the preallocated buffer"); 316 std::copy(VL.begin(), VL.end(), varlist_end()); 317 } 318 319 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) { 320 assert(VL.size() == varlist_size() && 321 "Number of inits is not the same as the preallocated buffer"); 322 std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); 323 } 324 325 OMPFirstprivateClause * 326 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, 327 SourceLocation LParenLoc, SourceLocation EndLoc, 328 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, 329 ArrayRef<Expr *> InitVL, Stmt *PreInit) { 330 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size())); 331 OMPFirstprivateClause *Clause = 332 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 333 Clause->setVarRefs(VL); 334 Clause->setPrivateCopies(PrivateVL); 335 Clause->setInits(InitVL); 336 Clause->setPreInitStmt(PreInit); 337 return Clause; 338 } 339 340 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, 341 unsigned N) { 342 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N)); 343 return new (Mem) OMPFirstprivateClause(N); 344 } 345 346 void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) { 347 assert(PrivateCopies.size() == varlist_size() && 348 "Number of private copies is not the same as the preallocated buffer"); 349 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end()); 350 } 351 352 void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { 353 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " 354 "not the same as the " 355 "preallocated buffer"); 356 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end()); 357 } 358 359 void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { 360 assert(DstExprs.size() == varlist_size() && "Number of destination " 361 "expressions is not the same as " 362 "the preallocated buffer"); 363 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); 364 } 365 366 void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { 367 assert(AssignmentOps.size() == varlist_size() && 368 "Number of assignment expressions is not the same as the preallocated " 369 "buffer"); 370 std::copy(AssignmentOps.begin(), AssignmentOps.end(), 371 getDestinationExprs().end()); 372 } 373 374 OMPLastprivateClause *OMPLastprivateClause::Create( 375 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 376 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 377 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit, 378 Expr *PostUpdate) { 379 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); 380 OMPLastprivateClause *Clause = 381 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 382 Clause->setVarRefs(VL); 383 Clause->setSourceExprs(SrcExprs); 384 Clause->setDestinationExprs(DstExprs); 385 Clause->setAssignmentOps(AssignmentOps); 386 Clause->setPreInitStmt(PreInit); 387 Clause->setPostUpdateExpr(PostUpdate); 388 return Clause; 389 } 390 391 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, 392 unsigned N) { 393 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); 394 return new (Mem) OMPLastprivateClause(N); 395 } 396 397 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, 398 SourceLocation StartLoc, 399 SourceLocation LParenLoc, 400 SourceLocation EndLoc, 401 ArrayRef<Expr *> VL) { 402 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); 403 OMPSharedClause *Clause = 404 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size()); 405 Clause->setVarRefs(VL); 406 return Clause; 407 } 408 409 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) { 410 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); 411 return new (Mem) OMPSharedClause(N); 412 } 413 414 void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) { 415 assert(PL.size() == varlist_size() && 416 "Number of privates is not the same as the preallocated buffer"); 417 std::copy(PL.begin(), PL.end(), varlist_end()); 418 } 419 420 void OMPLinearClause::setInits(ArrayRef<Expr *> IL) { 421 assert(IL.size() == varlist_size() && 422 "Number of inits is not the same as the preallocated buffer"); 423 std::copy(IL.begin(), IL.end(), getPrivates().end()); 424 } 425 426 void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) { 427 assert(UL.size() == varlist_size() && 428 "Number of updates is not the same as the preallocated buffer"); 429 std::copy(UL.begin(), UL.end(), getInits().end()); 430 } 431 432 void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) { 433 assert(FL.size() == varlist_size() && 434 "Number of final updates is not the same as the preallocated buffer"); 435 std::copy(FL.begin(), FL.end(), getUpdates().end()); 436 } 437 438 void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) { 439 assert( 440 UE.size() == varlist_size() + 1 && 441 "Number of used expressions is not the same as the preallocated buffer"); 442 std::copy(UE.begin(), UE.end(), getFinals().end() + 2); 443 } 444 445 OMPLinearClause *OMPLinearClause::Create( 446 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 447 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, 448 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, 449 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, 450 Stmt *PreInit, Expr *PostUpdate) { 451 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions 452 // (Step and CalcStep), list of used expression + step. 453 void *Mem = 454 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1)); 455 OMPLinearClause *Clause = new (Mem) OMPLinearClause( 456 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size()); 457 Clause->setVarRefs(VL); 458 Clause->setPrivates(PL); 459 Clause->setInits(IL); 460 // Fill update and final expressions with zeroes, they are provided later, 461 // after the directive construction. 462 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(), 463 nullptr); 464 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(), 465 nullptr); 466 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(), 467 nullptr); 468 Clause->setStep(Step); 469 Clause->setCalcStep(CalcStep); 470 Clause->setPreInitStmt(PreInit); 471 Clause->setPostUpdateExpr(PostUpdate); 472 return Clause; 473 } 474 475 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, 476 unsigned NumVars) { 477 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions 478 // (Step and CalcStep), list of used expression + step. 479 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1)); 480 return new (Mem) OMPLinearClause(NumVars); 481 } 482 483 OMPClause::child_range OMPLinearClause::used_children() { 484 // Range includes only non-nullptr elements. 485 return child_range( 486 reinterpret_cast<Stmt **>(getUsedExprs().begin()), 487 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr))); 488 } 489 490 OMPAlignedClause * 491 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, 492 SourceLocation LParenLoc, SourceLocation ColonLoc, 493 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { 494 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); 495 OMPAlignedClause *Clause = new (Mem) 496 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); 497 Clause->setVarRefs(VL); 498 Clause->setAlignment(A); 499 return Clause; 500 } 501 502 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, 503 unsigned NumVars) { 504 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1)); 505 return new (Mem) OMPAlignedClause(NumVars); 506 } 507 508 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { 509 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " 510 "not the same as the " 511 "preallocated buffer"); 512 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); 513 } 514 515 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { 516 assert(DstExprs.size() == varlist_size() && "Number of destination " 517 "expressions is not the same as " 518 "the preallocated buffer"); 519 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); 520 } 521 522 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { 523 assert(AssignmentOps.size() == varlist_size() && 524 "Number of assignment expressions is not the same as the preallocated " 525 "buffer"); 526 std::copy(AssignmentOps.begin(), AssignmentOps.end(), 527 getDestinationExprs().end()); 528 } 529 530 OMPCopyinClause *OMPCopyinClause::Create( 531 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 532 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 533 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { 534 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); 535 OMPCopyinClause *Clause = 536 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size()); 537 Clause->setVarRefs(VL); 538 Clause->setSourceExprs(SrcExprs); 539 Clause->setDestinationExprs(DstExprs); 540 Clause->setAssignmentOps(AssignmentOps); 541 return Clause; 542 } 543 544 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) { 545 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); 546 return new (Mem) OMPCopyinClause(N); 547 } 548 549 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { 550 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " 551 "not the same as the " 552 "preallocated buffer"); 553 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); 554 } 555 556 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { 557 assert(DstExprs.size() == varlist_size() && "Number of destination " 558 "expressions is not the same as " 559 "the preallocated buffer"); 560 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); 561 } 562 563 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { 564 assert(AssignmentOps.size() == varlist_size() && 565 "Number of assignment expressions is not the same as the preallocated " 566 "buffer"); 567 std::copy(AssignmentOps.begin(), AssignmentOps.end(), 568 getDestinationExprs().end()); 569 } 570 571 OMPCopyprivateClause *OMPCopyprivateClause::Create( 572 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 573 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 574 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { 575 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); 576 OMPCopyprivateClause *Clause = 577 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 578 Clause->setVarRefs(VL); 579 Clause->setSourceExprs(SrcExprs); 580 Clause->setDestinationExprs(DstExprs); 581 Clause->setAssignmentOps(AssignmentOps); 582 return Clause; 583 } 584 585 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, 586 unsigned N) { 587 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); 588 return new (Mem) OMPCopyprivateClause(N); 589 } 590 591 void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) { 592 assert(Privates.size() == varlist_size() && 593 "Number of private copies is not the same as the preallocated buffer"); 594 std::copy(Privates.begin(), Privates.end(), varlist_end()); 595 } 596 597 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { 598 assert( 599 LHSExprs.size() == varlist_size() && 600 "Number of LHS expressions is not the same as the preallocated buffer"); 601 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); 602 } 603 604 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { 605 assert( 606 RHSExprs.size() == varlist_size() && 607 "Number of RHS expressions is not the same as the preallocated buffer"); 608 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); 609 } 610 611 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { 612 assert(ReductionOps.size() == varlist_size() && "Number of reduction " 613 "expressions is not the same " 614 "as the preallocated buffer"); 615 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); 616 } 617 618 OMPReductionClause *OMPReductionClause::Create( 619 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 620 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, 621 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, 622 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, 623 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit, 624 Expr *PostUpdate) { 625 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); 626 OMPReductionClause *Clause = new (Mem) OMPReductionClause( 627 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); 628 Clause->setVarRefs(VL); 629 Clause->setPrivates(Privates); 630 Clause->setLHSExprs(LHSExprs); 631 Clause->setRHSExprs(RHSExprs); 632 Clause->setReductionOps(ReductionOps); 633 Clause->setPreInitStmt(PreInit); 634 Clause->setPostUpdateExpr(PostUpdate); 635 return Clause; 636 } 637 638 OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C, 639 unsigned N) { 640 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); 641 return new (Mem) OMPReductionClause(N); 642 } 643 644 void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) { 645 assert(Privates.size() == varlist_size() && 646 "Number of private copies is not the same as the preallocated buffer"); 647 std::copy(Privates.begin(), Privates.end(), varlist_end()); 648 } 649 650 void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { 651 assert( 652 LHSExprs.size() == varlist_size() && 653 "Number of LHS expressions is not the same as the preallocated buffer"); 654 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); 655 } 656 657 void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { 658 assert( 659 RHSExprs.size() == varlist_size() && 660 "Number of RHS expressions is not the same as the preallocated buffer"); 661 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); 662 } 663 664 void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { 665 assert(ReductionOps.size() == varlist_size() && "Number of task reduction " 666 "expressions is not the same " 667 "as the preallocated buffer"); 668 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); 669 } 670 671 OMPTaskReductionClause *OMPTaskReductionClause::Create( 672 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 673 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, 674 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, 675 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, 676 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit, 677 Expr *PostUpdate) { 678 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); 679 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause( 680 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); 681 Clause->setVarRefs(VL); 682 Clause->setPrivates(Privates); 683 Clause->setLHSExprs(LHSExprs); 684 Clause->setRHSExprs(RHSExprs); 685 Clause->setReductionOps(ReductionOps); 686 Clause->setPreInitStmt(PreInit); 687 Clause->setPostUpdateExpr(PostUpdate); 688 return Clause; 689 } 690 691 OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C, 692 unsigned N) { 693 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); 694 return new (Mem) OMPTaskReductionClause(N); 695 } 696 697 void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) { 698 assert(Privates.size() == varlist_size() && 699 "Number of private copies is not the same as the preallocated buffer"); 700 std::copy(Privates.begin(), Privates.end(), varlist_end()); 701 } 702 703 void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { 704 assert( 705 LHSExprs.size() == varlist_size() && 706 "Number of LHS expressions is not the same as the preallocated buffer"); 707 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); 708 } 709 710 void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { 711 assert( 712 RHSExprs.size() == varlist_size() && 713 "Number of RHS expressions is not the same as the preallocated buffer"); 714 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); 715 } 716 717 void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { 718 assert(ReductionOps.size() == varlist_size() && "Number of in reduction " 719 "expressions is not the same " 720 "as the preallocated buffer"); 721 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); 722 } 723 724 void OMPInReductionClause::setTaskgroupDescriptors( 725 ArrayRef<Expr *> TaskgroupDescriptors) { 726 assert(TaskgroupDescriptors.size() == varlist_size() && 727 "Number of in reduction descriptors is not the same as the " 728 "preallocated buffer"); 729 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(), 730 getReductionOps().end()); 731 } 732 733 OMPInReductionClause *OMPInReductionClause::Create( 734 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 735 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, 736 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, 737 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, 738 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, 739 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) { 740 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size())); 741 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause( 742 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); 743 Clause->setVarRefs(VL); 744 Clause->setPrivates(Privates); 745 Clause->setLHSExprs(LHSExprs); 746 Clause->setRHSExprs(RHSExprs); 747 Clause->setReductionOps(ReductionOps); 748 Clause->setTaskgroupDescriptors(TaskgroupDescriptors); 749 Clause->setPreInitStmt(PreInit); 750 Clause->setPostUpdateExpr(PostUpdate); 751 return Clause; 752 } 753 754 OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C, 755 unsigned N) { 756 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N)); 757 return new (Mem) OMPInReductionClause(N); 758 } 759 760 OMPAllocateClause * 761 OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc, 762 SourceLocation LParenLoc, Expr *Allocator, 763 SourceLocation ColonLoc, SourceLocation EndLoc, 764 ArrayRef<Expr *> VL) { 765 // Allocate space for private variables and initializer expressions. 766 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); 767 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator, 768 ColonLoc, EndLoc, VL.size()); 769 Clause->setVarRefs(VL); 770 return Clause; 771 } 772 773 OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C, 774 unsigned N) { 775 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); 776 return new (Mem) OMPAllocateClause(N); 777 } 778 779 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, 780 SourceLocation StartLoc, 781 SourceLocation LParenLoc, 782 SourceLocation EndLoc, 783 ArrayRef<Expr *> VL) { 784 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); 785 OMPFlushClause *Clause = 786 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); 787 Clause->setVarRefs(VL); 788 return Clause; 789 } 790 791 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { 792 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); 793 return new (Mem) OMPFlushClause(N); 794 } 795 796 OMPDependClause * 797 OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc, 798 SourceLocation LParenLoc, SourceLocation EndLoc, 799 OpenMPDependClauseKind DepKind, SourceLocation DepLoc, 800 SourceLocation ColonLoc, ArrayRef<Expr *> VL, 801 unsigned NumLoops) { 802 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops)); 803 OMPDependClause *Clause = new (Mem) 804 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops); 805 Clause->setVarRefs(VL); 806 Clause->setDependencyKind(DepKind); 807 Clause->setDependencyLoc(DepLoc); 808 Clause->setColonLoc(ColonLoc); 809 for (unsigned I = 0 ; I < NumLoops; ++I) 810 Clause->setLoopData(I, nullptr); 811 return Clause; 812 } 813 814 OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N, 815 unsigned NumLoops) { 816 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops)); 817 return new (Mem) OMPDependClause(N, NumLoops); 818 } 819 820 void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) { 821 assert((getDependencyKind() == OMPC_DEPEND_sink || 822 getDependencyKind() == OMPC_DEPEND_source) && 823 NumLoop < NumLoops && 824 "Expected sink or source depend + loop index must be less number of " 825 "loops."); 826 auto It = std::next(getVarRefs().end(), NumLoop); 827 *It = Cnt; 828 } 829 830 Expr *OMPDependClause::getLoopData(unsigned NumLoop) { 831 assert((getDependencyKind() == OMPC_DEPEND_sink || 832 getDependencyKind() == OMPC_DEPEND_source) && 833 NumLoop < NumLoops && 834 "Expected sink or source depend + loop index must be less number of " 835 "loops."); 836 auto It = std::next(getVarRefs().end(), NumLoop); 837 return *It; 838 } 839 840 const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const { 841 assert((getDependencyKind() == OMPC_DEPEND_sink || 842 getDependencyKind() == OMPC_DEPEND_source) && 843 NumLoop < NumLoops && 844 "Expected sink or source depend + loop index must be less number of " 845 "loops."); 846 auto It = std::next(getVarRefs().end(), NumLoop); 847 return *It; 848 } 849 850 unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber( 851 MappableExprComponentListsRef ComponentLists) { 852 unsigned TotalNum = 0u; 853 for (auto &C : ComponentLists) 854 TotalNum += C.size(); 855 return TotalNum; 856 } 857 858 unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber( 859 ArrayRef<const ValueDecl *> Declarations) { 860 unsigned TotalNum = 0u; 861 llvm::SmallPtrSet<const ValueDecl *, 8> Cache; 862 for (const ValueDecl *D : Declarations) { 863 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr; 864 if (Cache.count(VD)) 865 continue; 866 ++TotalNum; 867 Cache.insert(VD); 868 } 869 return TotalNum; 870 } 871 872 OMPMapClause *OMPMapClause::Create( 873 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, 874 ArrayRef<ValueDecl *> Declarations, 875 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, 876 ArrayRef<OpenMPMapModifierKind> MapModifiers, 877 ArrayRef<SourceLocation> MapModifiersLoc, 878 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId, 879 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) { 880 OMPMappableExprListSizeTy Sizes; 881 Sizes.NumVars = Vars.size(); 882 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); 883 Sizes.NumComponentLists = ComponentLists.size(); 884 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); 885 886 // We need to allocate: 887 // 2 x NumVars x Expr* - we have an original list expression and an associated 888 // user-defined mapper for each clause list entry. 889 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 890 // with each component list. 891 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 892 // number of lists for each unique declaration and the size of each component 893 // list. 894 // NumComponents x MappableComponent - the total of all the components in all 895 // the lists. 896 void *Mem = C.Allocate( 897 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 898 OMPClauseMappableExprCommon::MappableComponent>( 899 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 900 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 901 Sizes.NumComponents)); 902 OMPMapClause *Clause = new (Mem) 903 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId, 904 Type, TypeIsImplicit, TypeLoc, Locs, Sizes); 905 906 Clause->setVarRefs(Vars); 907 Clause->setUDMapperRefs(UDMapperRefs); 908 Clause->setClauseInfo(Declarations, ComponentLists); 909 Clause->setMapType(Type); 910 Clause->setMapLoc(TypeLoc); 911 return Clause; 912 } 913 914 OMPMapClause * 915 OMPMapClause::CreateEmpty(const ASTContext &C, 916 const OMPMappableExprListSizeTy &Sizes) { 917 void *Mem = C.Allocate( 918 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 919 OMPClauseMappableExprCommon::MappableComponent>( 920 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 921 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 922 Sizes.NumComponents)); 923 return new (Mem) OMPMapClause(Sizes); 924 } 925 926 OMPToClause *OMPToClause::Create( 927 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, 928 ArrayRef<ValueDecl *> Declarations, 929 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, 930 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) { 931 OMPMappableExprListSizeTy Sizes; 932 Sizes.NumVars = Vars.size(); 933 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); 934 Sizes.NumComponentLists = ComponentLists.size(); 935 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); 936 937 // We need to allocate: 938 // 2 x NumVars x Expr* - we have an original list expression and an associated 939 // user-defined mapper for each clause list entry. 940 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 941 // with each component list. 942 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 943 // number of lists for each unique declaration and the size of each component 944 // list. 945 // NumComponents x MappableComponent - the total of all the components in all 946 // the lists. 947 void *Mem = C.Allocate( 948 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 949 OMPClauseMappableExprCommon::MappableComponent>( 950 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 951 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 952 Sizes.NumComponents)); 953 954 auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes); 955 956 Clause->setVarRefs(Vars); 957 Clause->setUDMapperRefs(UDMapperRefs); 958 Clause->setClauseInfo(Declarations, ComponentLists); 959 return Clause; 960 } 961 962 OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, 963 const OMPMappableExprListSizeTy &Sizes) { 964 void *Mem = C.Allocate( 965 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 966 OMPClauseMappableExprCommon::MappableComponent>( 967 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 968 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 969 Sizes.NumComponents)); 970 return new (Mem) OMPToClause(Sizes); 971 } 972 973 OMPFromClause *OMPFromClause::Create( 974 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, 975 ArrayRef<ValueDecl *> Declarations, 976 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, 977 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) { 978 OMPMappableExprListSizeTy Sizes; 979 Sizes.NumVars = Vars.size(); 980 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); 981 Sizes.NumComponentLists = ComponentLists.size(); 982 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); 983 984 // We need to allocate: 985 // 2 x NumVars x Expr* - we have an original list expression and an associated 986 // user-defined mapper for each clause list entry. 987 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 988 // with each component list. 989 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 990 // number of lists for each unique declaration and the size of each component 991 // list. 992 // NumComponents x MappableComponent - the total of all the components in all 993 // the lists. 994 void *Mem = C.Allocate( 995 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 996 OMPClauseMappableExprCommon::MappableComponent>( 997 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 998 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 999 Sizes.NumComponents)); 1000 1001 auto *Clause = 1002 new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes); 1003 1004 Clause->setVarRefs(Vars); 1005 Clause->setUDMapperRefs(UDMapperRefs); 1006 Clause->setClauseInfo(Declarations, ComponentLists); 1007 return Clause; 1008 } 1009 1010 OMPFromClause * 1011 OMPFromClause::CreateEmpty(const ASTContext &C, 1012 const OMPMappableExprListSizeTy &Sizes) { 1013 void *Mem = C.Allocate( 1014 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1015 OMPClauseMappableExprCommon::MappableComponent>( 1016 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 1017 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1018 Sizes.NumComponents)); 1019 return new (Mem) OMPFromClause(Sizes); 1020 } 1021 1022 void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) { 1023 assert(VL.size() == varlist_size() && 1024 "Number of private copies is not the same as the preallocated buffer"); 1025 std::copy(VL.begin(), VL.end(), varlist_end()); 1026 } 1027 1028 void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) { 1029 assert(VL.size() == varlist_size() && 1030 "Number of inits is not the same as the preallocated buffer"); 1031 std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); 1032 } 1033 1034 OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create( 1035 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, 1036 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits, 1037 ArrayRef<ValueDecl *> Declarations, 1038 MappableExprComponentListsRef ComponentLists) { 1039 OMPMappableExprListSizeTy Sizes; 1040 Sizes.NumVars = Vars.size(); 1041 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); 1042 Sizes.NumComponentLists = ComponentLists.size(); 1043 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); 1044 1045 // We need to allocate: 1046 // 3 x NumVars x Expr* - we have an original list expression for each clause 1047 // list entry and an equal number of private copies and inits. 1048 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 1049 // with each component list. 1050 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 1051 // number of lists for each unique declaration and the size of each component 1052 // list. 1053 // NumComponents x MappableComponent - the total of all the components in all 1054 // the lists. 1055 void *Mem = C.Allocate( 1056 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1057 OMPClauseMappableExprCommon::MappableComponent>( 1058 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 1059 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1060 Sizes.NumComponents)); 1061 1062 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes); 1063 1064 Clause->setVarRefs(Vars); 1065 Clause->setPrivateCopies(PrivateVars); 1066 Clause->setInits(Inits); 1067 Clause->setClauseInfo(Declarations, ComponentLists); 1068 return Clause; 1069 } 1070 1071 OMPUseDevicePtrClause * 1072 OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C, 1073 const OMPMappableExprListSizeTy &Sizes) { 1074 void *Mem = C.Allocate( 1075 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1076 OMPClauseMappableExprCommon::MappableComponent>( 1077 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 1078 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1079 Sizes.NumComponents)); 1080 return new (Mem) OMPUseDevicePtrClause(Sizes); 1081 } 1082 1083 OMPIsDevicePtrClause * 1084 OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs, 1085 ArrayRef<Expr *> Vars, 1086 ArrayRef<ValueDecl *> Declarations, 1087 MappableExprComponentListsRef ComponentLists) { 1088 OMPMappableExprListSizeTy Sizes; 1089 Sizes.NumVars = Vars.size(); 1090 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); 1091 Sizes.NumComponentLists = ComponentLists.size(); 1092 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); 1093 1094 // We need to allocate: 1095 // NumVars x Expr* - we have an original list expression for each clause list 1096 // entry. 1097 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 1098 // with each component list. 1099 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 1100 // number of lists for each unique declaration and the size of each component 1101 // list. 1102 // NumComponents x MappableComponent - the total of all the components in all 1103 // the lists. 1104 void *Mem = C.Allocate( 1105 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1106 OMPClauseMappableExprCommon::MappableComponent>( 1107 Sizes.NumVars, Sizes.NumUniqueDeclarations, 1108 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1109 Sizes.NumComponents)); 1110 1111 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes); 1112 1113 Clause->setVarRefs(Vars); 1114 Clause->setClauseInfo(Declarations, ComponentLists); 1115 return Clause; 1116 } 1117 1118 OMPIsDevicePtrClause * 1119 OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C, 1120 const OMPMappableExprListSizeTy &Sizes) { 1121 void *Mem = C.Allocate( 1122 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1123 OMPClauseMappableExprCommon::MappableComponent>( 1124 Sizes.NumVars, Sizes.NumUniqueDeclarations, 1125 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1126 Sizes.NumComponents)); 1127 return new (Mem) OMPIsDevicePtrClause(Sizes); 1128 } 1129 1130 //===----------------------------------------------------------------------===// 1131 // OpenMP clauses printing methods 1132 //===----------------------------------------------------------------------===// 1133 1134 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) { 1135 OS << "if("; 1136 if (Node->getNameModifier() != OMPD_unknown) 1137 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": "; 1138 Node->getCondition()->printPretty(OS, nullptr, Policy, 0); 1139 OS << ")"; 1140 } 1141 1142 void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) { 1143 OS << "final("; 1144 Node->getCondition()->printPretty(OS, nullptr, Policy, 0); 1145 OS << ")"; 1146 } 1147 1148 void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) { 1149 OS << "num_threads("; 1150 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0); 1151 OS << ")"; 1152 } 1153 1154 void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) { 1155 OS << "safelen("; 1156 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0); 1157 OS << ")"; 1158 } 1159 1160 void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) { 1161 OS << "simdlen("; 1162 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0); 1163 OS << ")"; 1164 } 1165 1166 void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) { 1167 OS << "allocator("; 1168 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0); 1169 OS << ")"; 1170 } 1171 1172 void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) { 1173 OS << "collapse("; 1174 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0); 1175 OS << ")"; 1176 } 1177 1178 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) { 1179 OS << "default(" 1180 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind()) 1181 << ")"; 1182 } 1183 1184 void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) { 1185 OS << "proc_bind(" 1186 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind()) 1187 << ")"; 1188 } 1189 1190 void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) { 1191 OS << "unified_address"; 1192 } 1193 1194 void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause( 1195 OMPUnifiedSharedMemoryClause *) { 1196 OS << "unified_shared_memory"; 1197 } 1198 1199 void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) { 1200 OS << "reverse_offload"; 1201 } 1202 1203 void OMPClausePrinter::VisitOMPDynamicAllocatorsClause( 1204 OMPDynamicAllocatorsClause *) { 1205 OS << "dynamic_allocators"; 1206 } 1207 1208 void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause( 1209 OMPAtomicDefaultMemOrderClause *Node) { 1210 OS << "atomic_default_mem_order(" 1211 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order, 1212 Node->getAtomicDefaultMemOrderKind()) 1213 << ")"; 1214 } 1215 1216 void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) { 1217 OS << "schedule("; 1218 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) { 1219 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, 1220 Node->getFirstScheduleModifier()); 1221 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) { 1222 OS << ", "; 1223 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, 1224 Node->getSecondScheduleModifier()); 1225 } 1226 OS << ": "; 1227 } 1228 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind()); 1229 if (auto *E = Node->getChunkSize()) { 1230 OS << ", "; 1231 E->printPretty(OS, nullptr, Policy); 1232 } 1233 OS << ")"; 1234 } 1235 1236 void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) { 1237 OS << "ordered"; 1238 if (auto *Num = Node->getNumForLoops()) { 1239 OS << "("; 1240 Num->printPretty(OS, nullptr, Policy, 0); 1241 OS << ")"; 1242 } 1243 } 1244 1245 void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) { 1246 OS << "nowait"; 1247 } 1248 1249 void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) { 1250 OS << "untied"; 1251 } 1252 1253 void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) { 1254 OS << "nogroup"; 1255 } 1256 1257 void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) { 1258 OS << "mergeable"; 1259 } 1260 1261 void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; } 1262 1263 void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; } 1264 1265 void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) { 1266 OS << "update"; 1267 } 1268 1269 void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) { 1270 OS << "capture"; 1271 } 1272 1273 void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) { 1274 OS << "seq_cst"; 1275 } 1276 1277 void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) { 1278 OS << "threads"; 1279 } 1280 1281 void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; } 1282 1283 void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) { 1284 OS << "device("; 1285 Node->getDevice()->printPretty(OS, nullptr, Policy, 0); 1286 OS << ")"; 1287 } 1288 1289 void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) { 1290 OS << "num_teams("; 1291 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0); 1292 OS << ")"; 1293 } 1294 1295 void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) { 1296 OS << "thread_limit("; 1297 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0); 1298 OS << ")"; 1299 } 1300 1301 void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) { 1302 OS << "priority("; 1303 Node->getPriority()->printPretty(OS, nullptr, Policy, 0); 1304 OS << ")"; 1305 } 1306 1307 void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) { 1308 OS << "grainsize("; 1309 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0); 1310 OS << ")"; 1311 } 1312 1313 void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) { 1314 OS << "num_tasks("; 1315 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0); 1316 OS << ")"; 1317 } 1318 1319 void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) { 1320 OS << "hint("; 1321 Node->getHint()->printPretty(OS, nullptr, Policy, 0); 1322 OS << ")"; 1323 } 1324 1325 template<typename T> 1326 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) { 1327 for (typename T::varlist_iterator I = Node->varlist_begin(), 1328 E = Node->varlist_end(); 1329 I != E; ++I) { 1330 assert(*I && "Expected non-null Stmt"); 1331 OS << (I == Node->varlist_begin() ? StartSym : ','); 1332 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) { 1333 if (isa<OMPCapturedExprDecl>(DRE->getDecl())) 1334 DRE->printPretty(OS, nullptr, Policy, 0); 1335 else 1336 DRE->getDecl()->printQualifiedName(OS); 1337 } else 1338 (*I)->printPretty(OS, nullptr, Policy, 0); 1339 } 1340 } 1341 1342 void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) { 1343 if (Node->varlist_empty()) 1344 return; 1345 OS << "allocate"; 1346 if (Expr *Allocator = Node->getAllocator()) { 1347 OS << "("; 1348 Allocator->printPretty(OS, nullptr, Policy, 0); 1349 OS << ":"; 1350 VisitOMPClauseList(Node, ' '); 1351 } else { 1352 VisitOMPClauseList(Node, '('); 1353 } 1354 OS << ")"; 1355 } 1356 1357 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) { 1358 if (!Node->varlist_empty()) { 1359 OS << "private"; 1360 VisitOMPClauseList(Node, '('); 1361 OS << ")"; 1362 } 1363 } 1364 1365 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) { 1366 if (!Node->varlist_empty()) { 1367 OS << "firstprivate"; 1368 VisitOMPClauseList(Node, '('); 1369 OS << ")"; 1370 } 1371 } 1372 1373 void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) { 1374 if (!Node->varlist_empty()) { 1375 OS << "lastprivate"; 1376 VisitOMPClauseList(Node, '('); 1377 OS << ")"; 1378 } 1379 } 1380 1381 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) { 1382 if (!Node->varlist_empty()) { 1383 OS << "shared"; 1384 VisitOMPClauseList(Node, '('); 1385 OS << ")"; 1386 } 1387 } 1388 1389 void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) { 1390 if (!Node->varlist_empty()) { 1391 OS << "reduction("; 1392 NestedNameSpecifier *QualifierLoc = 1393 Node->getQualifierLoc().getNestedNameSpecifier(); 1394 OverloadedOperatorKind OOK = 1395 Node->getNameInfo().getName().getCXXOverloadedOperator(); 1396 if (QualifierLoc == nullptr && OOK != OO_None) { 1397 // Print reduction identifier in C format 1398 OS << getOperatorSpelling(OOK); 1399 } else { 1400 // Use C++ format 1401 if (QualifierLoc != nullptr) 1402 QualifierLoc->print(OS, Policy); 1403 OS << Node->getNameInfo(); 1404 } 1405 OS << ":"; 1406 VisitOMPClauseList(Node, ' '); 1407 OS << ")"; 1408 } 1409 } 1410 1411 void OMPClausePrinter::VisitOMPTaskReductionClause( 1412 OMPTaskReductionClause *Node) { 1413 if (!Node->varlist_empty()) { 1414 OS << "task_reduction("; 1415 NestedNameSpecifier *QualifierLoc = 1416 Node->getQualifierLoc().getNestedNameSpecifier(); 1417 OverloadedOperatorKind OOK = 1418 Node->getNameInfo().getName().getCXXOverloadedOperator(); 1419 if (QualifierLoc == nullptr && OOK != OO_None) { 1420 // Print reduction identifier in C format 1421 OS << getOperatorSpelling(OOK); 1422 } else { 1423 // Use C++ format 1424 if (QualifierLoc != nullptr) 1425 QualifierLoc->print(OS, Policy); 1426 OS << Node->getNameInfo(); 1427 } 1428 OS << ":"; 1429 VisitOMPClauseList(Node, ' '); 1430 OS << ")"; 1431 } 1432 } 1433 1434 void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) { 1435 if (!Node->varlist_empty()) { 1436 OS << "in_reduction("; 1437 NestedNameSpecifier *QualifierLoc = 1438 Node->getQualifierLoc().getNestedNameSpecifier(); 1439 OverloadedOperatorKind OOK = 1440 Node->getNameInfo().getName().getCXXOverloadedOperator(); 1441 if (QualifierLoc == nullptr && OOK != OO_None) { 1442 // Print reduction identifier in C format 1443 OS << getOperatorSpelling(OOK); 1444 } else { 1445 // Use C++ format 1446 if (QualifierLoc != nullptr) 1447 QualifierLoc->print(OS, Policy); 1448 OS << Node->getNameInfo(); 1449 } 1450 OS << ":"; 1451 VisitOMPClauseList(Node, ' '); 1452 OS << ")"; 1453 } 1454 } 1455 1456 void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) { 1457 if (!Node->varlist_empty()) { 1458 OS << "linear"; 1459 if (Node->getModifierLoc().isValid()) { 1460 OS << '(' 1461 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier()); 1462 } 1463 VisitOMPClauseList(Node, '('); 1464 if (Node->getModifierLoc().isValid()) 1465 OS << ')'; 1466 if (Node->getStep() != nullptr) { 1467 OS << ": "; 1468 Node->getStep()->printPretty(OS, nullptr, Policy, 0); 1469 } 1470 OS << ")"; 1471 } 1472 } 1473 1474 void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) { 1475 if (!Node->varlist_empty()) { 1476 OS << "aligned"; 1477 VisitOMPClauseList(Node, '('); 1478 if (Node->getAlignment() != nullptr) { 1479 OS << ": "; 1480 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0); 1481 } 1482 OS << ")"; 1483 } 1484 } 1485 1486 void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) { 1487 if (!Node->varlist_empty()) { 1488 OS << "copyin"; 1489 VisitOMPClauseList(Node, '('); 1490 OS << ")"; 1491 } 1492 } 1493 1494 void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) { 1495 if (!Node->varlist_empty()) { 1496 OS << "copyprivate"; 1497 VisitOMPClauseList(Node, '('); 1498 OS << ")"; 1499 } 1500 } 1501 1502 void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) { 1503 if (!Node->varlist_empty()) { 1504 VisitOMPClauseList(Node, '('); 1505 OS << ")"; 1506 } 1507 } 1508 1509 void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) { 1510 OS << "depend("; 1511 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), 1512 Node->getDependencyKind()); 1513 if (!Node->varlist_empty()) { 1514 OS << " :"; 1515 VisitOMPClauseList(Node, ' '); 1516 } 1517 OS << ")"; 1518 } 1519 1520 void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) { 1521 if (!Node->varlist_empty()) { 1522 OS << "map("; 1523 if (Node->getMapType() != OMPC_MAP_unknown) { 1524 for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) { 1525 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) { 1526 OS << getOpenMPSimpleClauseTypeName(OMPC_map, 1527 Node->getMapTypeModifier(I)); 1528 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) { 1529 OS << '('; 1530 NestedNameSpecifier *MapperNNS = 1531 Node->getMapperQualifierLoc().getNestedNameSpecifier(); 1532 if (MapperNNS) 1533 MapperNNS->print(OS, Policy); 1534 OS << Node->getMapperIdInfo() << ')'; 1535 } 1536 OS << ','; 1537 } 1538 } 1539 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType()); 1540 OS << ':'; 1541 } 1542 VisitOMPClauseList(Node, ' '); 1543 OS << ")"; 1544 } 1545 } 1546 1547 void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) { 1548 if (!Node->varlist_empty()) { 1549 OS << "to"; 1550 DeclarationNameInfo MapperId = Node->getMapperIdInfo(); 1551 if (MapperId.getName() && !MapperId.getName().isEmpty()) { 1552 OS << '('; 1553 OS << "mapper("; 1554 NestedNameSpecifier *MapperNNS = 1555 Node->getMapperQualifierLoc().getNestedNameSpecifier(); 1556 if (MapperNNS) 1557 MapperNNS->print(OS, Policy); 1558 OS << MapperId << "):"; 1559 VisitOMPClauseList(Node, ' '); 1560 } else { 1561 VisitOMPClauseList(Node, '('); 1562 } 1563 OS << ")"; 1564 } 1565 } 1566 1567 void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) { 1568 if (!Node->varlist_empty()) { 1569 OS << "from"; 1570 DeclarationNameInfo MapperId = Node->getMapperIdInfo(); 1571 if (MapperId.getName() && !MapperId.getName().isEmpty()) { 1572 OS << '('; 1573 OS << "mapper("; 1574 NestedNameSpecifier *MapperNNS = 1575 Node->getMapperQualifierLoc().getNestedNameSpecifier(); 1576 if (MapperNNS) 1577 MapperNNS->print(OS, Policy); 1578 OS << MapperId << "):"; 1579 VisitOMPClauseList(Node, ' '); 1580 } else { 1581 VisitOMPClauseList(Node, '('); 1582 } 1583 OS << ")"; 1584 } 1585 } 1586 1587 void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) { 1588 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName( 1589 OMPC_dist_schedule, Node->getDistScheduleKind()); 1590 if (auto *E = Node->getChunkSize()) { 1591 OS << ", "; 1592 E->printPretty(OS, nullptr, Policy); 1593 } 1594 OS << ")"; 1595 } 1596 1597 void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) { 1598 OS << "defaultmap("; 1599 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap, 1600 Node->getDefaultmapModifier()); 1601 OS << ": "; 1602 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap, 1603 Node->getDefaultmapKind()); 1604 OS << ")"; 1605 } 1606 1607 void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) { 1608 if (!Node->varlist_empty()) { 1609 OS << "use_device_ptr"; 1610 VisitOMPClauseList(Node, '('); 1611 OS << ")"; 1612 } 1613 } 1614 1615 void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) { 1616 if (!Node->varlist_empty()) { 1617 OS << "is_device_ptr"; 1618 VisitOMPClauseList(Node, '('); 1619 OS << ")"; 1620 } 1621 } 1622 1623