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