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