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