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/Attr.h" 16 #include "clang/AST/Decl.h" 17 #include "clang/AST/DeclOpenMP.h" 18 #include "clang/Basic/LLVM.h" 19 #include "clang/Basic/OpenMPKinds.h" 20 #include "clang/Basic/TargetInfo.h" 21 #include "llvm/ADT/SmallPtrSet.h" 22 #include "llvm/Support/Casting.h" 23 #include "llvm/Support/ErrorHandling.h" 24 #include <algorithm> 25 #include <cassert> 26 27 using namespace clang; 28 using namespace llvm; 29 using namespace omp; 30 31 OMPClause::child_range OMPClause::children() { 32 switch (getClauseKind()) { 33 default: 34 break; 35 #define OMP_CLAUSE_CLASS(Enum, Str, Class) \ 36 case Enum: \ 37 return static_cast<Class *>(this)->children(); 38 #include "llvm/Frontend/OpenMP/OMPKinds.def" 39 } 40 llvm_unreachable("unknown OMPClause"); 41 } 42 43 OMPClause::child_range OMPClause::used_children() { 44 switch (getClauseKind()) { 45 #define OMP_CLAUSE_CLASS(Enum, Str, Class) \ 46 case Enum: \ 47 return static_cast<Class *>(this)->used_children(); 48 #include "llvm/Frontend/OpenMP/OMPKinds.def" 49 case OMPC_threadprivate: 50 case OMPC_uniform: 51 case OMPC_device_type: 52 case OMPC_match: 53 case OMPC_unknown: 54 break; 55 default: 56 break; 57 } 58 llvm_unreachable("unknown OMPClause"); 59 } 60 61 OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) { 62 auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C)); 63 return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr; 64 } 65 66 const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) { 67 switch (C->getClauseKind()) { 68 case OMPC_schedule: 69 return static_cast<const OMPScheduleClause *>(C); 70 case OMPC_dist_schedule: 71 return static_cast<const OMPDistScheduleClause *>(C); 72 case OMPC_firstprivate: 73 return static_cast<const OMPFirstprivateClause *>(C); 74 case OMPC_lastprivate: 75 return static_cast<const OMPLastprivateClause *>(C); 76 case OMPC_reduction: 77 return static_cast<const OMPReductionClause *>(C); 78 case OMPC_task_reduction: 79 return static_cast<const OMPTaskReductionClause *>(C); 80 case OMPC_in_reduction: 81 return static_cast<const OMPInReductionClause *>(C); 82 case OMPC_linear: 83 return static_cast<const OMPLinearClause *>(C); 84 case OMPC_if: 85 return static_cast<const OMPIfClause *>(C); 86 case OMPC_num_threads: 87 return static_cast<const OMPNumThreadsClause *>(C); 88 case OMPC_num_teams: 89 return static_cast<const OMPNumTeamsClause *>(C); 90 case OMPC_thread_limit: 91 return static_cast<const OMPThreadLimitClause *>(C); 92 case OMPC_device: 93 return static_cast<const OMPDeviceClause *>(C); 94 case OMPC_grainsize: 95 return static_cast<const OMPGrainsizeClause *>(C); 96 case OMPC_num_tasks: 97 return static_cast<const OMPNumTasksClause *>(C); 98 case OMPC_final: 99 return static_cast<const OMPFinalClause *>(C); 100 case OMPC_priority: 101 return static_cast<const OMPPriorityClause *>(C); 102 case OMPC_default: 103 case OMPC_proc_bind: 104 case OMPC_safelen: 105 case OMPC_simdlen: 106 case OMPC_allocator: 107 case OMPC_allocate: 108 case OMPC_collapse: 109 case OMPC_private: 110 case OMPC_shared: 111 case OMPC_aligned: 112 case OMPC_copyin: 113 case OMPC_copyprivate: 114 case OMPC_ordered: 115 case OMPC_nowait: 116 case OMPC_untied: 117 case OMPC_mergeable: 118 case OMPC_threadprivate: 119 case OMPC_flush: 120 case OMPC_depobj: 121 case OMPC_read: 122 case OMPC_write: 123 case OMPC_update: 124 case OMPC_capture: 125 case OMPC_seq_cst: 126 case OMPC_acq_rel: 127 case OMPC_acquire: 128 case OMPC_release: 129 case OMPC_relaxed: 130 case OMPC_depend: 131 case OMPC_threads: 132 case OMPC_simd: 133 case OMPC_map: 134 case OMPC_nogroup: 135 case OMPC_hint: 136 case OMPC_defaultmap: 137 case OMPC_unknown: 138 case OMPC_uniform: 139 case OMPC_to: 140 case OMPC_from: 141 case OMPC_use_device_ptr: 142 case OMPC_use_device_addr: 143 case OMPC_is_device_ptr: 144 case OMPC_unified_address: 145 case OMPC_unified_shared_memory: 146 case OMPC_reverse_offload: 147 case OMPC_dynamic_allocators: 148 case OMPC_atomic_default_mem_order: 149 case OMPC_device_type: 150 case OMPC_match: 151 case OMPC_nontemporal: 152 case OMPC_order: 153 case OMPC_destroy: 154 case OMPC_detach: 155 case OMPC_inclusive: 156 case OMPC_exclusive: 157 case OMPC_uses_allocators: 158 case OMPC_affinity: 159 break; 160 default: 161 break; 162 } 163 164 return nullptr; 165 } 166 167 OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) { 168 auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C)); 169 return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr; 170 } 171 172 const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) { 173 switch (C->getClauseKind()) { 174 case OMPC_lastprivate: 175 return static_cast<const OMPLastprivateClause *>(C); 176 case OMPC_reduction: 177 return static_cast<const OMPReductionClause *>(C); 178 case OMPC_task_reduction: 179 return static_cast<const OMPTaskReductionClause *>(C); 180 case OMPC_in_reduction: 181 return static_cast<const OMPInReductionClause *>(C); 182 case OMPC_linear: 183 return static_cast<const OMPLinearClause *>(C); 184 case OMPC_schedule: 185 case OMPC_dist_schedule: 186 case OMPC_firstprivate: 187 case OMPC_default: 188 case OMPC_proc_bind: 189 case OMPC_if: 190 case OMPC_final: 191 case OMPC_num_threads: 192 case OMPC_safelen: 193 case OMPC_simdlen: 194 case OMPC_allocator: 195 case OMPC_allocate: 196 case OMPC_collapse: 197 case OMPC_private: 198 case OMPC_shared: 199 case OMPC_aligned: 200 case OMPC_copyin: 201 case OMPC_copyprivate: 202 case OMPC_ordered: 203 case OMPC_nowait: 204 case OMPC_untied: 205 case OMPC_mergeable: 206 case OMPC_threadprivate: 207 case OMPC_flush: 208 case OMPC_depobj: 209 case OMPC_read: 210 case OMPC_write: 211 case OMPC_update: 212 case OMPC_capture: 213 case OMPC_seq_cst: 214 case OMPC_acq_rel: 215 case OMPC_acquire: 216 case OMPC_release: 217 case OMPC_relaxed: 218 case OMPC_depend: 219 case OMPC_device: 220 case OMPC_threads: 221 case OMPC_simd: 222 case OMPC_map: 223 case OMPC_num_teams: 224 case OMPC_thread_limit: 225 case OMPC_priority: 226 case OMPC_grainsize: 227 case OMPC_nogroup: 228 case OMPC_num_tasks: 229 case OMPC_hint: 230 case OMPC_defaultmap: 231 case OMPC_unknown: 232 case OMPC_uniform: 233 case OMPC_to: 234 case OMPC_from: 235 case OMPC_use_device_ptr: 236 case OMPC_use_device_addr: 237 case OMPC_is_device_ptr: 238 case OMPC_unified_address: 239 case OMPC_unified_shared_memory: 240 case OMPC_reverse_offload: 241 case OMPC_dynamic_allocators: 242 case OMPC_atomic_default_mem_order: 243 case OMPC_device_type: 244 case OMPC_match: 245 case OMPC_nontemporal: 246 case OMPC_order: 247 case OMPC_destroy: 248 case OMPC_detach: 249 case OMPC_inclusive: 250 case OMPC_exclusive: 251 case OMPC_uses_allocators: 252 case OMPC_affinity: 253 break; 254 default: 255 break; 256 } 257 258 return nullptr; 259 } 260 261 /// Gets the address of the original, non-captured, expression used in the 262 /// clause as the preinitializer. 263 static Stmt **getAddrOfExprAsWritten(Stmt *S) { 264 if (!S) 265 return nullptr; 266 if (auto *DS = dyn_cast<DeclStmt>(S)) { 267 assert(DS->isSingleDecl() && "Only single expression must be captured."); 268 if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl())) 269 return OED->getInitAddress(); 270 } 271 return nullptr; 272 } 273 274 OMPClause::child_range OMPIfClause::used_children() { 275 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) 276 return child_range(C, C + 1); 277 return child_range(&Condition, &Condition + 1); 278 } 279 280 OMPClause::child_range OMPGrainsizeClause::used_children() { 281 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) 282 return child_range(C, C + 1); 283 return child_range(&Grainsize, &Grainsize + 1); 284 } 285 286 OMPClause::child_range OMPNumTasksClause::used_children() { 287 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) 288 return child_range(C, C + 1); 289 return child_range(&NumTasks, &NumTasks + 1); 290 } 291 292 OMPClause::child_range OMPFinalClause::used_children() { 293 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) 294 return child_range(C, C + 1); 295 return child_range(&Condition, &Condition + 1); 296 } 297 298 OMPClause::child_range OMPPriorityClause::used_children() { 299 if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) 300 return child_range(C, C + 1); 301 return child_range(&Priority, &Priority + 1); 302 } 303 304 OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num, 305 unsigned NumLoops, 306 SourceLocation StartLoc, 307 SourceLocation LParenLoc, 308 SourceLocation EndLoc) { 309 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops)); 310 auto *Clause = 311 new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc); 312 for (unsigned I = 0; I < NumLoops; ++I) { 313 Clause->setLoopNumIterations(I, nullptr); 314 Clause->setLoopCounter(I, nullptr); 315 } 316 return Clause; 317 } 318 319 OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C, 320 unsigned NumLoops) { 321 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops)); 322 auto *Clause = new (Mem) OMPOrderedClause(NumLoops); 323 for (unsigned I = 0; I < NumLoops; ++I) { 324 Clause->setLoopNumIterations(I, nullptr); 325 Clause->setLoopCounter(I, nullptr); 326 } 327 return Clause; 328 } 329 330 void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop, 331 Expr *NumIterations) { 332 assert(NumLoop < NumberOfLoops && "out of loops number."); 333 getTrailingObjects<Expr *>()[NumLoop] = NumIterations; 334 } 335 336 ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const { 337 return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops); 338 } 339 340 void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) { 341 assert(NumLoop < NumberOfLoops && "out of loops number."); 342 getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter; 343 } 344 345 Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) { 346 assert(NumLoop < NumberOfLoops && "out of loops number."); 347 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop]; 348 } 349 350 const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const { 351 assert(NumLoop < NumberOfLoops && "out of loops number."); 352 return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop]; 353 } 354 355 OMPUpdateClause *OMPUpdateClause::Create(const ASTContext &C, 356 SourceLocation StartLoc, 357 SourceLocation EndLoc) { 358 return new (C) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/false); 359 } 360 361 OMPUpdateClause * 362 OMPUpdateClause::Create(const ASTContext &C, SourceLocation StartLoc, 363 SourceLocation LParenLoc, SourceLocation ArgumentLoc, 364 OpenMPDependClauseKind DK, SourceLocation EndLoc) { 365 void *Mem = 366 C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1), 367 alignof(OMPUpdateClause)); 368 auto *Clause = 369 new (Mem) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/true); 370 Clause->setLParenLoc(LParenLoc); 371 Clause->setArgumentLoc(ArgumentLoc); 372 Clause->setDependencyKind(DK); 373 return Clause; 374 } 375 376 OMPUpdateClause *OMPUpdateClause::CreateEmpty(const ASTContext &C, 377 bool IsExtended) { 378 if (!IsExtended) 379 return new (C) OMPUpdateClause(/*IsExtended=*/false); 380 void *Mem = 381 C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1), 382 alignof(OMPUpdateClause)); 383 auto *Clause = new (Mem) OMPUpdateClause(/*IsExtended=*/true); 384 Clause->IsExtended = true; 385 return Clause; 386 } 387 388 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { 389 assert(VL.size() == varlist_size() && 390 "Number of private copies is not the same as the preallocated buffer"); 391 std::copy(VL.begin(), VL.end(), varlist_end()); 392 } 393 394 OMPPrivateClause * 395 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, 396 SourceLocation LParenLoc, SourceLocation EndLoc, 397 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) { 398 // Allocate space for private variables and initializer expressions. 399 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size())); 400 OMPPrivateClause *Clause = 401 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 402 Clause->setVarRefs(VL); 403 Clause->setPrivateCopies(PrivateVL); 404 return Clause; 405 } 406 407 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, 408 unsigned N) { 409 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N)); 410 return new (Mem) OMPPrivateClause(N); 411 } 412 413 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { 414 assert(VL.size() == varlist_size() && 415 "Number of private copies is not the same as the preallocated buffer"); 416 std::copy(VL.begin(), VL.end(), varlist_end()); 417 } 418 419 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) { 420 assert(VL.size() == varlist_size() && 421 "Number of inits is not the same as the preallocated buffer"); 422 std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); 423 } 424 425 OMPFirstprivateClause * 426 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, 427 SourceLocation LParenLoc, SourceLocation EndLoc, 428 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, 429 ArrayRef<Expr *> InitVL, Stmt *PreInit) { 430 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size())); 431 OMPFirstprivateClause *Clause = 432 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 433 Clause->setVarRefs(VL); 434 Clause->setPrivateCopies(PrivateVL); 435 Clause->setInits(InitVL); 436 Clause->setPreInitStmt(PreInit); 437 return Clause; 438 } 439 440 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, 441 unsigned N) { 442 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N)); 443 return new (Mem) OMPFirstprivateClause(N); 444 } 445 446 void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) { 447 assert(PrivateCopies.size() == varlist_size() && 448 "Number of private copies is not the same as the preallocated buffer"); 449 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end()); 450 } 451 452 void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { 453 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " 454 "not the same as the " 455 "preallocated buffer"); 456 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end()); 457 } 458 459 void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { 460 assert(DstExprs.size() == varlist_size() && "Number of destination " 461 "expressions is not the same as " 462 "the preallocated buffer"); 463 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); 464 } 465 466 void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { 467 assert(AssignmentOps.size() == varlist_size() && 468 "Number of assignment expressions is not the same as the preallocated " 469 "buffer"); 470 std::copy(AssignmentOps.begin(), AssignmentOps.end(), 471 getDestinationExprs().end()); 472 } 473 474 OMPLastprivateClause *OMPLastprivateClause::Create( 475 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 476 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 477 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, 478 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, 479 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) { 480 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); 481 OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause( 482 StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size()); 483 Clause->setVarRefs(VL); 484 Clause->setSourceExprs(SrcExprs); 485 Clause->setDestinationExprs(DstExprs); 486 Clause->setAssignmentOps(AssignmentOps); 487 Clause->setPreInitStmt(PreInit); 488 Clause->setPostUpdateExpr(PostUpdate); 489 return Clause; 490 } 491 492 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, 493 unsigned N) { 494 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); 495 return new (Mem) OMPLastprivateClause(N); 496 } 497 498 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, 499 SourceLocation StartLoc, 500 SourceLocation LParenLoc, 501 SourceLocation EndLoc, 502 ArrayRef<Expr *> VL) { 503 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); 504 OMPSharedClause *Clause = 505 new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size()); 506 Clause->setVarRefs(VL); 507 return Clause; 508 } 509 510 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) { 511 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); 512 return new (Mem) OMPSharedClause(N); 513 } 514 515 void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) { 516 assert(PL.size() == varlist_size() && 517 "Number of privates is not the same as the preallocated buffer"); 518 std::copy(PL.begin(), PL.end(), varlist_end()); 519 } 520 521 void OMPLinearClause::setInits(ArrayRef<Expr *> IL) { 522 assert(IL.size() == varlist_size() && 523 "Number of inits is not the same as the preallocated buffer"); 524 std::copy(IL.begin(), IL.end(), getPrivates().end()); 525 } 526 527 void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) { 528 assert(UL.size() == varlist_size() && 529 "Number of updates is not the same as the preallocated buffer"); 530 std::copy(UL.begin(), UL.end(), getInits().end()); 531 } 532 533 void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) { 534 assert(FL.size() == varlist_size() && 535 "Number of final updates is not the same as the preallocated buffer"); 536 std::copy(FL.begin(), FL.end(), getUpdates().end()); 537 } 538 539 void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) { 540 assert( 541 UE.size() == varlist_size() + 1 && 542 "Number of used expressions is not the same as the preallocated buffer"); 543 std::copy(UE.begin(), UE.end(), getFinals().end() + 2); 544 } 545 546 OMPLinearClause *OMPLinearClause::Create( 547 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 548 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, 549 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, 550 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, 551 Stmt *PreInit, Expr *PostUpdate) { 552 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions 553 // (Step and CalcStep), list of used expression + step. 554 void *Mem = 555 C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1)); 556 OMPLinearClause *Clause = new (Mem) OMPLinearClause( 557 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size()); 558 Clause->setVarRefs(VL); 559 Clause->setPrivates(PL); 560 Clause->setInits(IL); 561 // Fill update and final expressions with zeroes, they are provided later, 562 // after the directive construction. 563 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(), 564 nullptr); 565 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(), 566 nullptr); 567 std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(), 568 nullptr); 569 Clause->setStep(Step); 570 Clause->setCalcStep(CalcStep); 571 Clause->setPreInitStmt(PreInit); 572 Clause->setPostUpdateExpr(PostUpdate); 573 return Clause; 574 } 575 576 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, 577 unsigned NumVars) { 578 // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions 579 // (Step and CalcStep), list of used expression + step. 580 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1)); 581 return new (Mem) OMPLinearClause(NumVars); 582 } 583 584 OMPClause::child_range OMPLinearClause::used_children() { 585 // Range includes only non-nullptr elements. 586 return child_range( 587 reinterpret_cast<Stmt **>(getUsedExprs().begin()), 588 reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr))); 589 } 590 591 OMPAlignedClause * 592 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, 593 SourceLocation LParenLoc, SourceLocation ColonLoc, 594 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { 595 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); 596 OMPAlignedClause *Clause = new (Mem) 597 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); 598 Clause->setVarRefs(VL); 599 Clause->setAlignment(A); 600 return Clause; 601 } 602 603 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, 604 unsigned NumVars) { 605 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1)); 606 return new (Mem) OMPAlignedClause(NumVars); 607 } 608 609 void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { 610 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " 611 "not the same as the " 612 "preallocated buffer"); 613 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); 614 } 615 616 void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { 617 assert(DstExprs.size() == varlist_size() && "Number of destination " 618 "expressions is not the same as " 619 "the preallocated buffer"); 620 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); 621 } 622 623 void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { 624 assert(AssignmentOps.size() == varlist_size() && 625 "Number of assignment expressions is not the same as the preallocated " 626 "buffer"); 627 std::copy(AssignmentOps.begin(), AssignmentOps.end(), 628 getDestinationExprs().end()); 629 } 630 631 OMPCopyinClause *OMPCopyinClause::Create( 632 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 633 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 634 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { 635 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); 636 OMPCopyinClause *Clause = 637 new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size()); 638 Clause->setVarRefs(VL); 639 Clause->setSourceExprs(SrcExprs); 640 Clause->setDestinationExprs(DstExprs); 641 Clause->setAssignmentOps(AssignmentOps); 642 return Clause; 643 } 644 645 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) { 646 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); 647 return new (Mem) OMPCopyinClause(N); 648 } 649 650 void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { 651 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " 652 "not the same as the " 653 "preallocated buffer"); 654 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); 655 } 656 657 void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { 658 assert(DstExprs.size() == varlist_size() && "Number of destination " 659 "expressions is not the same as " 660 "the preallocated buffer"); 661 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); 662 } 663 664 void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { 665 assert(AssignmentOps.size() == varlist_size() && 666 "Number of assignment expressions is not the same as the preallocated " 667 "buffer"); 668 std::copy(AssignmentOps.begin(), AssignmentOps.end(), 669 getDestinationExprs().end()); 670 } 671 672 OMPCopyprivateClause *OMPCopyprivateClause::Create( 673 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 674 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 675 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { 676 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); 677 OMPCopyprivateClause *Clause = 678 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 679 Clause->setVarRefs(VL); 680 Clause->setSourceExprs(SrcExprs); 681 Clause->setDestinationExprs(DstExprs); 682 Clause->setAssignmentOps(AssignmentOps); 683 return Clause; 684 } 685 686 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, 687 unsigned N) { 688 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); 689 return new (Mem) OMPCopyprivateClause(N); 690 } 691 692 void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) { 693 assert(Privates.size() == varlist_size() && 694 "Number of private copies is not the same as the preallocated buffer"); 695 std::copy(Privates.begin(), Privates.end(), varlist_end()); 696 } 697 698 void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { 699 assert( 700 LHSExprs.size() == varlist_size() && 701 "Number of LHS expressions is not the same as the preallocated buffer"); 702 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); 703 } 704 705 void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { 706 assert( 707 RHSExprs.size() == varlist_size() && 708 "Number of RHS expressions is not the same as the preallocated buffer"); 709 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); 710 } 711 712 void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { 713 assert(ReductionOps.size() == varlist_size() && "Number of reduction " 714 "expressions is not the same " 715 "as the preallocated buffer"); 716 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); 717 } 718 719 void OMPReductionClause::setInscanCopyOps(ArrayRef<Expr *> Ops) { 720 assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction."); 721 assert(Ops.size() == varlist_size() && "Number of copy " 722 "expressions is not the same " 723 "as the preallocated buffer"); 724 llvm::copy(Ops, getReductionOps().end()); 725 } 726 727 void OMPReductionClause::setInscanCopyArrayTemps( 728 ArrayRef<Expr *> CopyArrayTemps) { 729 assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction."); 730 assert(CopyArrayTemps.size() == varlist_size() && 731 "Number of copy temp expressions is not the same as the preallocated " 732 "buffer"); 733 llvm::copy(CopyArrayTemps, getInscanCopyOps().end()); 734 } 735 736 void OMPReductionClause::setInscanCopyArrayElems( 737 ArrayRef<Expr *> CopyArrayElems) { 738 assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction."); 739 assert(CopyArrayElems.size() == varlist_size() && 740 "Number of copy temp expressions is not the same as the preallocated " 741 "buffer"); 742 llvm::copy(CopyArrayElems, getInscanCopyArrayTemps().end()); 743 } 744 745 OMPReductionClause *OMPReductionClause::Create( 746 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 747 SourceLocation ModifierLoc, SourceLocation EndLoc, SourceLocation ColonLoc, 748 OpenMPReductionClauseModifier Modifier, ArrayRef<Expr *> VL, 749 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, 750 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, 751 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, 752 ArrayRef<Expr *> CopyOps, ArrayRef<Expr *> CopyArrayTemps, 753 ArrayRef<Expr *> CopyArrayElems, Stmt *PreInit, Expr *PostUpdate) { 754 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>( 755 (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * VL.size())); 756 auto *Clause = new (Mem) 757 OMPReductionClause(StartLoc, LParenLoc, ModifierLoc, EndLoc, ColonLoc, 758 Modifier, VL.size(), QualifierLoc, NameInfo); 759 Clause->setVarRefs(VL); 760 Clause->setPrivates(Privates); 761 Clause->setLHSExprs(LHSExprs); 762 Clause->setRHSExprs(RHSExprs); 763 Clause->setReductionOps(ReductionOps); 764 Clause->setPreInitStmt(PreInit); 765 Clause->setPostUpdateExpr(PostUpdate); 766 if (Modifier == OMPC_REDUCTION_inscan) { 767 Clause->setInscanCopyOps(CopyOps); 768 Clause->setInscanCopyArrayTemps(CopyArrayTemps); 769 Clause->setInscanCopyArrayElems(CopyArrayElems); 770 } else { 771 assert(CopyOps.empty() && 772 "copy operations are expected in inscan reductions only."); 773 assert(CopyArrayTemps.empty() && 774 "copy array temps are expected in inscan reductions only."); 775 assert(CopyArrayElems.empty() && 776 "copy array temps are expected in inscan reductions only."); 777 } 778 return Clause; 779 } 780 781 OMPReductionClause * 782 OMPReductionClause::CreateEmpty(const ASTContext &C, unsigned N, 783 OpenMPReductionClauseModifier Modifier) { 784 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>( 785 (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * N)); 786 auto *Clause = new (Mem) OMPReductionClause(N); 787 Clause->setModifier(Modifier); 788 return Clause; 789 } 790 791 void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) { 792 assert(Privates.size() == varlist_size() && 793 "Number of private copies is not the same as the preallocated buffer"); 794 std::copy(Privates.begin(), Privates.end(), varlist_end()); 795 } 796 797 void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { 798 assert( 799 LHSExprs.size() == varlist_size() && 800 "Number of LHS expressions is not the same as the preallocated buffer"); 801 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); 802 } 803 804 void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { 805 assert( 806 RHSExprs.size() == varlist_size() && 807 "Number of RHS expressions is not the same as the preallocated buffer"); 808 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); 809 } 810 811 void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { 812 assert(ReductionOps.size() == varlist_size() && "Number of task reduction " 813 "expressions is not the same " 814 "as the preallocated buffer"); 815 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); 816 } 817 818 OMPTaskReductionClause *OMPTaskReductionClause::Create( 819 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 820 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, 821 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, 822 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, 823 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit, 824 Expr *PostUpdate) { 825 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); 826 OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause( 827 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); 828 Clause->setVarRefs(VL); 829 Clause->setPrivates(Privates); 830 Clause->setLHSExprs(LHSExprs); 831 Clause->setRHSExprs(RHSExprs); 832 Clause->setReductionOps(ReductionOps); 833 Clause->setPreInitStmt(PreInit); 834 Clause->setPostUpdateExpr(PostUpdate); 835 return Clause; 836 } 837 838 OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C, 839 unsigned N) { 840 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); 841 return new (Mem) OMPTaskReductionClause(N); 842 } 843 844 void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) { 845 assert(Privates.size() == varlist_size() && 846 "Number of private copies is not the same as the preallocated buffer"); 847 std::copy(Privates.begin(), Privates.end(), varlist_end()); 848 } 849 850 void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { 851 assert( 852 LHSExprs.size() == varlist_size() && 853 "Number of LHS expressions is not the same as the preallocated buffer"); 854 std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); 855 } 856 857 void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { 858 assert( 859 RHSExprs.size() == varlist_size() && 860 "Number of RHS expressions is not the same as the preallocated buffer"); 861 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); 862 } 863 864 void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { 865 assert(ReductionOps.size() == varlist_size() && "Number of in reduction " 866 "expressions is not the same " 867 "as the preallocated buffer"); 868 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); 869 } 870 871 void OMPInReductionClause::setTaskgroupDescriptors( 872 ArrayRef<Expr *> TaskgroupDescriptors) { 873 assert(TaskgroupDescriptors.size() == varlist_size() && 874 "Number of in reduction descriptors is not the same as the " 875 "preallocated buffer"); 876 std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(), 877 getReductionOps().end()); 878 } 879 880 OMPInReductionClause *OMPInReductionClause::Create( 881 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 882 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, 883 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, 884 ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, 885 ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, 886 ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) { 887 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size())); 888 OMPInReductionClause *Clause = new (Mem) OMPInReductionClause( 889 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); 890 Clause->setVarRefs(VL); 891 Clause->setPrivates(Privates); 892 Clause->setLHSExprs(LHSExprs); 893 Clause->setRHSExprs(RHSExprs); 894 Clause->setReductionOps(ReductionOps); 895 Clause->setTaskgroupDescriptors(TaskgroupDescriptors); 896 Clause->setPreInitStmt(PreInit); 897 Clause->setPostUpdateExpr(PostUpdate); 898 return Clause; 899 } 900 901 OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C, 902 unsigned N) { 903 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N)); 904 return new (Mem) OMPInReductionClause(N); 905 } 906 907 OMPAllocateClause * 908 OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc, 909 SourceLocation LParenLoc, Expr *Allocator, 910 SourceLocation ColonLoc, SourceLocation EndLoc, 911 ArrayRef<Expr *> VL) { 912 // Allocate space for private variables and initializer expressions. 913 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); 914 auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator, 915 ColonLoc, EndLoc, VL.size()); 916 Clause->setVarRefs(VL); 917 return Clause; 918 } 919 920 OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C, 921 unsigned N) { 922 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); 923 return new (Mem) OMPAllocateClause(N); 924 } 925 926 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, 927 SourceLocation StartLoc, 928 SourceLocation LParenLoc, 929 SourceLocation EndLoc, 930 ArrayRef<Expr *> VL) { 931 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); 932 OMPFlushClause *Clause = 933 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); 934 Clause->setVarRefs(VL); 935 return Clause; 936 } 937 938 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { 939 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); 940 return new (Mem) OMPFlushClause(N); 941 } 942 943 OMPDepobjClause *OMPDepobjClause::Create(const ASTContext &C, 944 SourceLocation StartLoc, 945 SourceLocation LParenLoc, 946 SourceLocation RParenLoc, 947 Expr *Depobj) { 948 auto *Clause = new (C) OMPDepobjClause(StartLoc, LParenLoc, RParenLoc); 949 Clause->setDepobj(Depobj); 950 return Clause; 951 } 952 953 OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) { 954 return new (C) OMPDepobjClause(); 955 } 956 957 OMPDependClause * 958 OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc, 959 SourceLocation LParenLoc, SourceLocation EndLoc, 960 Expr *DepModifier, OpenMPDependClauseKind DepKind, 961 SourceLocation DepLoc, SourceLocation ColonLoc, 962 ArrayRef<Expr *> VL, unsigned NumLoops) { 963 void *Mem = C.Allocate( 964 totalSizeToAlloc<Expr *>(VL.size() + /*depend-modifier*/ 1 + NumLoops), 965 alignof(OMPDependClause)); 966 OMPDependClause *Clause = new (Mem) 967 OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops); 968 Clause->setVarRefs(VL); 969 Clause->setDependencyKind(DepKind); 970 Clause->setDependencyLoc(DepLoc); 971 Clause->setColonLoc(ColonLoc); 972 Clause->setModifier(DepModifier); 973 for (unsigned I = 0 ; I < NumLoops; ++I) 974 Clause->setLoopData(I, nullptr); 975 return Clause; 976 } 977 978 OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N, 979 unsigned NumLoops) { 980 void *Mem = 981 C.Allocate(totalSizeToAlloc<Expr *>(N + /*depend-modifier*/ 1 + NumLoops), 982 alignof(OMPDependClause)); 983 return new (Mem) OMPDependClause(N, NumLoops); 984 } 985 986 void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) { 987 assert((getDependencyKind() == OMPC_DEPEND_sink || 988 getDependencyKind() == OMPC_DEPEND_source) && 989 NumLoop < NumLoops && 990 "Expected sink or source depend + loop index must be less number of " 991 "loops."); 992 auto *It = std::next(getVarRefs().end(), NumLoop + 1); 993 *It = Cnt; 994 } 995 996 Expr *OMPDependClause::getLoopData(unsigned NumLoop) { 997 assert((getDependencyKind() == OMPC_DEPEND_sink || 998 getDependencyKind() == OMPC_DEPEND_source) && 999 NumLoop < NumLoops && 1000 "Expected sink or source depend + loop index must be less number of " 1001 "loops."); 1002 auto *It = std::next(getVarRefs().end(), NumLoop + 1); 1003 return *It; 1004 } 1005 1006 const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const { 1007 assert((getDependencyKind() == OMPC_DEPEND_sink || 1008 getDependencyKind() == OMPC_DEPEND_source) && 1009 NumLoop < NumLoops && 1010 "Expected sink or source depend + loop index must be less number of " 1011 "loops."); 1012 const auto *It = std::next(getVarRefs().end(), NumLoop + 1); 1013 return *It; 1014 } 1015 1016 void OMPDependClause::setModifier(Expr *DepModifier) { 1017 *getVarRefs().end() = DepModifier; 1018 } 1019 Expr *OMPDependClause::getModifier() { return *getVarRefs().end(); } 1020 1021 unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber( 1022 MappableExprComponentListsRef ComponentLists) { 1023 unsigned TotalNum = 0u; 1024 for (auto &C : ComponentLists) 1025 TotalNum += C.size(); 1026 return TotalNum; 1027 } 1028 1029 unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber( 1030 ArrayRef<const ValueDecl *> Declarations) { 1031 unsigned TotalNum = 0u; 1032 llvm::SmallPtrSet<const ValueDecl *, 8> Cache; 1033 for (const ValueDecl *D : Declarations) { 1034 const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr; 1035 if (Cache.count(VD)) 1036 continue; 1037 ++TotalNum; 1038 Cache.insert(VD); 1039 } 1040 return TotalNum; 1041 } 1042 1043 OMPMapClause *OMPMapClause::Create( 1044 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, 1045 ArrayRef<ValueDecl *> Declarations, 1046 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, 1047 ArrayRef<OpenMPMapModifierKind> MapModifiers, 1048 ArrayRef<SourceLocation> MapModifiersLoc, 1049 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId, 1050 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) { 1051 OMPMappableExprListSizeTy Sizes; 1052 Sizes.NumVars = Vars.size(); 1053 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); 1054 Sizes.NumComponentLists = ComponentLists.size(); 1055 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); 1056 1057 // We need to allocate: 1058 // 2 x NumVars x Expr* - we have an original list expression and an associated 1059 // user-defined mapper for each clause list entry. 1060 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 1061 // with each component list. 1062 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 1063 // number of lists for each unique declaration and the size of each component 1064 // list. 1065 // NumComponents x MappableComponent - the total of all the components in all 1066 // the lists. 1067 void *Mem = C.Allocate( 1068 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1069 OMPClauseMappableExprCommon::MappableComponent>( 1070 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 1071 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1072 Sizes.NumComponents)); 1073 OMPMapClause *Clause = new (Mem) 1074 OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId, 1075 Type, TypeIsImplicit, TypeLoc, Locs, Sizes); 1076 1077 Clause->setVarRefs(Vars); 1078 Clause->setUDMapperRefs(UDMapperRefs); 1079 Clause->setClauseInfo(Declarations, ComponentLists); 1080 Clause->setMapType(Type); 1081 Clause->setMapLoc(TypeLoc); 1082 return Clause; 1083 } 1084 1085 OMPMapClause * 1086 OMPMapClause::CreateEmpty(const ASTContext &C, 1087 const OMPMappableExprListSizeTy &Sizes) { 1088 void *Mem = C.Allocate( 1089 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1090 OMPClauseMappableExprCommon::MappableComponent>( 1091 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 1092 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1093 Sizes.NumComponents)); 1094 return new (Mem) OMPMapClause(Sizes); 1095 } 1096 1097 OMPToClause *OMPToClause::Create( 1098 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, 1099 ArrayRef<ValueDecl *> Declarations, 1100 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, 1101 ArrayRef<OpenMPMotionModifierKind> MotionModifiers, 1102 ArrayRef<SourceLocation> MotionModifiersLoc, 1103 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) { 1104 OMPMappableExprListSizeTy Sizes; 1105 Sizes.NumVars = Vars.size(); 1106 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); 1107 Sizes.NumComponentLists = ComponentLists.size(); 1108 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); 1109 1110 // We need to allocate: 1111 // 2 x NumVars x Expr* - we have an original list expression and an associated 1112 // user-defined mapper for each clause list entry. 1113 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 1114 // with each component list. 1115 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 1116 // number of lists for each unique declaration and the size of each component 1117 // list. 1118 // NumComponents x MappableComponent - the total of all the components in all 1119 // the lists. 1120 void *Mem = C.Allocate( 1121 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1122 OMPClauseMappableExprCommon::MappableComponent>( 1123 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 1124 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1125 Sizes.NumComponents)); 1126 1127 auto *Clause = new (Mem) OMPToClause(MotionModifiers, MotionModifiersLoc, 1128 UDMQualifierLoc, MapperId, Locs, Sizes); 1129 1130 Clause->setVarRefs(Vars); 1131 Clause->setUDMapperRefs(UDMapperRefs); 1132 Clause->setClauseInfo(Declarations, ComponentLists); 1133 return Clause; 1134 } 1135 1136 OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, 1137 const OMPMappableExprListSizeTy &Sizes) { 1138 void *Mem = C.Allocate( 1139 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1140 OMPClauseMappableExprCommon::MappableComponent>( 1141 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 1142 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1143 Sizes.NumComponents)); 1144 return new (Mem) OMPToClause(Sizes); 1145 } 1146 1147 OMPFromClause *OMPFromClause::Create( 1148 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, 1149 ArrayRef<ValueDecl *> Declarations, 1150 MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, 1151 ArrayRef<OpenMPMotionModifierKind> MotionModifiers, 1152 ArrayRef<SourceLocation> MotionModifiersLoc, 1153 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) { 1154 OMPMappableExprListSizeTy Sizes; 1155 Sizes.NumVars = Vars.size(); 1156 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); 1157 Sizes.NumComponentLists = ComponentLists.size(); 1158 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); 1159 1160 // We need to allocate: 1161 // 2 x NumVars x Expr* - we have an original list expression and an associated 1162 // user-defined mapper for each clause list entry. 1163 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 1164 // with each component list. 1165 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 1166 // number of lists for each unique declaration and the size of each component 1167 // list. 1168 // NumComponents x MappableComponent - the total of all the components in all 1169 // the lists. 1170 void *Mem = C.Allocate( 1171 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1172 OMPClauseMappableExprCommon::MappableComponent>( 1173 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 1174 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1175 Sizes.NumComponents)); 1176 1177 auto *Clause = 1178 new (Mem) OMPFromClause(MotionModifiers, MotionModifiersLoc, 1179 UDMQualifierLoc, MapperId, Locs, Sizes); 1180 1181 Clause->setVarRefs(Vars); 1182 Clause->setUDMapperRefs(UDMapperRefs); 1183 Clause->setClauseInfo(Declarations, ComponentLists); 1184 return Clause; 1185 } 1186 1187 OMPFromClause * 1188 OMPFromClause::CreateEmpty(const ASTContext &C, 1189 const OMPMappableExprListSizeTy &Sizes) { 1190 void *Mem = C.Allocate( 1191 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1192 OMPClauseMappableExprCommon::MappableComponent>( 1193 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 1194 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1195 Sizes.NumComponents)); 1196 return new (Mem) OMPFromClause(Sizes); 1197 } 1198 1199 void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) { 1200 assert(VL.size() == varlist_size() && 1201 "Number of private copies is not the same as the preallocated buffer"); 1202 std::copy(VL.begin(), VL.end(), varlist_end()); 1203 } 1204 1205 void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) { 1206 assert(VL.size() == varlist_size() && 1207 "Number of inits is not the same as the preallocated buffer"); 1208 std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); 1209 } 1210 1211 OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create( 1212 const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, 1213 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits, 1214 ArrayRef<ValueDecl *> Declarations, 1215 MappableExprComponentListsRef ComponentLists) { 1216 OMPMappableExprListSizeTy Sizes; 1217 Sizes.NumVars = Vars.size(); 1218 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); 1219 Sizes.NumComponentLists = ComponentLists.size(); 1220 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); 1221 1222 // We need to allocate: 1223 // NumVars x Expr* - we have an original list expression for each clause 1224 // list entry. 1225 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 1226 // with each component list. 1227 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 1228 // number of lists for each unique declaration and the size of each component 1229 // list. 1230 // NumComponents x MappableComponent - the total of all the components in all 1231 // the lists. 1232 void *Mem = C.Allocate( 1233 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1234 OMPClauseMappableExprCommon::MappableComponent>( 1235 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 1236 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1237 Sizes.NumComponents)); 1238 1239 OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes); 1240 1241 Clause->setVarRefs(Vars); 1242 Clause->setPrivateCopies(PrivateVars); 1243 Clause->setInits(Inits); 1244 Clause->setClauseInfo(Declarations, ComponentLists); 1245 return Clause; 1246 } 1247 1248 OMPUseDevicePtrClause * 1249 OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C, 1250 const OMPMappableExprListSizeTy &Sizes) { 1251 void *Mem = C.Allocate( 1252 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1253 OMPClauseMappableExprCommon::MappableComponent>( 1254 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations, 1255 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1256 Sizes.NumComponents)); 1257 return new (Mem) OMPUseDevicePtrClause(Sizes); 1258 } 1259 1260 OMPUseDeviceAddrClause * 1261 OMPUseDeviceAddrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs, 1262 ArrayRef<Expr *> Vars, 1263 ArrayRef<ValueDecl *> Declarations, 1264 MappableExprComponentListsRef ComponentLists) { 1265 OMPMappableExprListSizeTy Sizes; 1266 Sizes.NumVars = Vars.size(); 1267 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); 1268 Sizes.NumComponentLists = ComponentLists.size(); 1269 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); 1270 1271 // We need to allocate: 1272 // 3 x NumVars x Expr* - we have an original list expression for each clause 1273 // list entry and an equal number of private copies and inits. 1274 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 1275 // with each component list. 1276 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 1277 // number of lists for each unique declaration and the size of each component 1278 // list. 1279 // NumComponents x MappableComponent - the total of all the components in all 1280 // the lists. 1281 void *Mem = C.Allocate( 1282 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1283 OMPClauseMappableExprCommon::MappableComponent>( 1284 Sizes.NumVars, Sizes.NumUniqueDeclarations, 1285 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1286 Sizes.NumComponents)); 1287 1288 auto *Clause = new (Mem) OMPUseDeviceAddrClause(Locs, Sizes); 1289 1290 Clause->setVarRefs(Vars); 1291 Clause->setClauseInfo(Declarations, ComponentLists); 1292 return Clause; 1293 } 1294 1295 OMPUseDeviceAddrClause * 1296 OMPUseDeviceAddrClause::CreateEmpty(const ASTContext &C, 1297 const OMPMappableExprListSizeTy &Sizes) { 1298 void *Mem = C.Allocate( 1299 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1300 OMPClauseMappableExprCommon::MappableComponent>( 1301 Sizes.NumVars, Sizes.NumUniqueDeclarations, 1302 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1303 Sizes.NumComponents)); 1304 return new (Mem) OMPUseDeviceAddrClause(Sizes); 1305 } 1306 1307 OMPIsDevicePtrClause * 1308 OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs, 1309 ArrayRef<Expr *> Vars, 1310 ArrayRef<ValueDecl *> Declarations, 1311 MappableExprComponentListsRef ComponentLists) { 1312 OMPMappableExprListSizeTy Sizes; 1313 Sizes.NumVars = Vars.size(); 1314 Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); 1315 Sizes.NumComponentLists = ComponentLists.size(); 1316 Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); 1317 1318 // We need to allocate: 1319 // NumVars x Expr* - we have an original list expression for each clause list 1320 // entry. 1321 // NumUniqueDeclarations x ValueDecl* - unique base declarations associated 1322 // with each component list. 1323 // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the 1324 // number of lists for each unique declaration and the size of each component 1325 // list. 1326 // NumComponents x MappableComponent - the total of all the components in all 1327 // the lists. 1328 void *Mem = C.Allocate( 1329 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1330 OMPClauseMappableExprCommon::MappableComponent>( 1331 Sizes.NumVars, Sizes.NumUniqueDeclarations, 1332 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1333 Sizes.NumComponents)); 1334 1335 OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes); 1336 1337 Clause->setVarRefs(Vars); 1338 Clause->setClauseInfo(Declarations, ComponentLists); 1339 return Clause; 1340 } 1341 1342 OMPIsDevicePtrClause * 1343 OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C, 1344 const OMPMappableExprListSizeTy &Sizes) { 1345 void *Mem = C.Allocate( 1346 totalSizeToAlloc<Expr *, ValueDecl *, unsigned, 1347 OMPClauseMappableExprCommon::MappableComponent>( 1348 Sizes.NumVars, Sizes.NumUniqueDeclarations, 1349 Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, 1350 Sizes.NumComponents)); 1351 return new (Mem) OMPIsDevicePtrClause(Sizes); 1352 } 1353 1354 OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C, 1355 SourceLocation StartLoc, 1356 SourceLocation LParenLoc, 1357 SourceLocation EndLoc, 1358 ArrayRef<Expr *> VL) { 1359 // Allocate space for nontemporal variables + private references. 1360 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size())); 1361 auto *Clause = 1362 new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size()); 1363 Clause->setVarRefs(VL); 1364 return Clause; 1365 } 1366 1367 OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C, 1368 unsigned N) { 1369 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N)); 1370 return new (Mem) OMPNontemporalClause(N); 1371 } 1372 1373 void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) { 1374 assert(VL.size() == varlist_size() && "Number of private references is not " 1375 "the same as the preallocated buffer"); 1376 std::copy(VL.begin(), VL.end(), varlist_end()); 1377 } 1378 1379 OMPInclusiveClause *OMPInclusiveClause::Create(const ASTContext &C, 1380 SourceLocation StartLoc, 1381 SourceLocation LParenLoc, 1382 SourceLocation EndLoc, 1383 ArrayRef<Expr *> VL) { 1384 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); 1385 auto *Clause = 1386 new (Mem) OMPInclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size()); 1387 Clause->setVarRefs(VL); 1388 return Clause; 1389 } 1390 1391 OMPInclusiveClause *OMPInclusiveClause::CreateEmpty(const ASTContext &C, 1392 unsigned N) { 1393 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); 1394 return new (Mem) OMPInclusiveClause(N); 1395 } 1396 1397 OMPExclusiveClause *OMPExclusiveClause::Create(const ASTContext &C, 1398 SourceLocation StartLoc, 1399 SourceLocation LParenLoc, 1400 SourceLocation EndLoc, 1401 ArrayRef<Expr *> VL) { 1402 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); 1403 auto *Clause = 1404 new (Mem) OMPExclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size()); 1405 Clause->setVarRefs(VL); 1406 return Clause; 1407 } 1408 1409 OMPExclusiveClause *OMPExclusiveClause::CreateEmpty(const ASTContext &C, 1410 unsigned N) { 1411 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); 1412 return new (Mem) OMPExclusiveClause(N); 1413 } 1414 1415 void OMPUsesAllocatorsClause::setAllocatorsData( 1416 ArrayRef<OMPUsesAllocatorsClause::Data> Data) { 1417 assert(Data.size() == NumOfAllocators && 1418 "Size of allocators data is not the same as the preallocated buffer."); 1419 for (unsigned I = 0, E = Data.size(); I < E; ++I) { 1420 const OMPUsesAllocatorsClause::Data &D = Data[I]; 1421 getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) + 1422 static_cast<int>(ExprOffsets::Allocator)] = 1423 D.Allocator; 1424 getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) + 1425 static_cast<int>( 1426 ExprOffsets::AllocatorTraits)] = 1427 D.AllocatorTraits; 1428 getTrailingObjects< 1429 SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) + 1430 static_cast<int>(ParenLocsOffsets::LParen)] = 1431 D.LParenLoc; 1432 getTrailingObjects< 1433 SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) + 1434 static_cast<int>(ParenLocsOffsets::RParen)] = 1435 D.RParenLoc; 1436 } 1437 } 1438 1439 OMPUsesAllocatorsClause::Data 1440 OMPUsesAllocatorsClause::getAllocatorData(unsigned I) const { 1441 OMPUsesAllocatorsClause::Data Data; 1442 Data.Allocator = 1443 getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) + 1444 static_cast<int>(ExprOffsets::Allocator)]; 1445 Data.AllocatorTraits = 1446 getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) + 1447 static_cast<int>( 1448 ExprOffsets::AllocatorTraits)]; 1449 Data.LParenLoc = getTrailingObjects< 1450 SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) + 1451 static_cast<int>(ParenLocsOffsets::LParen)]; 1452 Data.RParenLoc = getTrailingObjects< 1453 SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) + 1454 static_cast<int>(ParenLocsOffsets::RParen)]; 1455 return Data; 1456 } 1457 1458 OMPUsesAllocatorsClause * 1459 OMPUsesAllocatorsClause::Create(const ASTContext &C, SourceLocation StartLoc, 1460 SourceLocation LParenLoc, SourceLocation EndLoc, 1461 ArrayRef<OMPUsesAllocatorsClause::Data> Data) { 1462 void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>( 1463 static_cast<int>(ExprOffsets::Total) * Data.size(), 1464 static_cast<int>(ParenLocsOffsets::Total) * Data.size())); 1465 auto *Clause = new (Mem) 1466 OMPUsesAllocatorsClause(StartLoc, LParenLoc, EndLoc, Data.size()); 1467 Clause->setAllocatorsData(Data); 1468 return Clause; 1469 } 1470 1471 OMPUsesAllocatorsClause * 1472 OMPUsesAllocatorsClause::CreateEmpty(const ASTContext &C, unsigned N) { 1473 void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>( 1474 static_cast<int>(ExprOffsets::Total) * N, 1475 static_cast<int>(ParenLocsOffsets::Total) * N)); 1476 return new (Mem) OMPUsesAllocatorsClause(N); 1477 } 1478 1479 OMPAffinityClause * 1480 OMPAffinityClause::Create(const ASTContext &C, SourceLocation StartLoc, 1481 SourceLocation LParenLoc, SourceLocation ColonLoc, 1482 SourceLocation EndLoc, Expr *Modifier, 1483 ArrayRef<Expr *> Locators) { 1484 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Locators.size() + 1)); 1485 auto *Clause = new (Mem) 1486 OMPAffinityClause(StartLoc, LParenLoc, ColonLoc, EndLoc, Locators.size()); 1487 Clause->setModifier(Modifier); 1488 Clause->setVarRefs(Locators); 1489 return Clause; 1490 } 1491 1492 OMPAffinityClause *OMPAffinityClause::CreateEmpty(const ASTContext &C, 1493 unsigned N) { 1494 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1)); 1495 return new (Mem) OMPAffinityClause(N); 1496 } 1497 1498 //===----------------------------------------------------------------------===// 1499 // OpenMP clauses printing methods 1500 //===----------------------------------------------------------------------===// 1501 1502 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) { 1503 OS << "if("; 1504 if (Node->getNameModifier() != OMPD_unknown) 1505 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": "; 1506 Node->getCondition()->printPretty(OS, nullptr, Policy, 0); 1507 OS << ")"; 1508 } 1509 1510 void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) { 1511 OS << "final("; 1512 Node->getCondition()->printPretty(OS, nullptr, Policy, 0); 1513 OS << ")"; 1514 } 1515 1516 void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) { 1517 OS << "num_threads("; 1518 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0); 1519 OS << ")"; 1520 } 1521 1522 void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) { 1523 OS << "safelen("; 1524 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0); 1525 OS << ")"; 1526 } 1527 1528 void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) { 1529 OS << "simdlen("; 1530 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0); 1531 OS << ")"; 1532 } 1533 1534 void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) { 1535 OS << "allocator("; 1536 Node->getAllocator()->printPretty(OS, nullptr, Policy, 0); 1537 OS << ")"; 1538 } 1539 1540 void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) { 1541 OS << "collapse("; 1542 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0); 1543 OS << ")"; 1544 } 1545 1546 void OMPClausePrinter::VisitOMPDetachClause(OMPDetachClause *Node) { 1547 OS << "detach("; 1548 Node->getEventHandler()->printPretty(OS, nullptr, Policy, 0); 1549 OS << ")"; 1550 } 1551 1552 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) { 1553 OS << "default(" 1554 << getOpenMPSimpleClauseTypeName(OMPC_default, 1555 unsigned(Node->getDefaultKind())) 1556 << ")"; 1557 } 1558 1559 void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) { 1560 OS << "proc_bind(" 1561 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, 1562 unsigned(Node->getProcBindKind())) 1563 << ")"; 1564 } 1565 1566 void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) { 1567 OS << "unified_address"; 1568 } 1569 1570 void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause( 1571 OMPUnifiedSharedMemoryClause *) { 1572 OS << "unified_shared_memory"; 1573 } 1574 1575 void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) { 1576 OS << "reverse_offload"; 1577 } 1578 1579 void OMPClausePrinter::VisitOMPDynamicAllocatorsClause( 1580 OMPDynamicAllocatorsClause *) { 1581 OS << "dynamic_allocators"; 1582 } 1583 1584 void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause( 1585 OMPAtomicDefaultMemOrderClause *Node) { 1586 OS << "atomic_default_mem_order(" 1587 << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order, 1588 Node->getAtomicDefaultMemOrderKind()) 1589 << ")"; 1590 } 1591 1592 void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) { 1593 OS << "schedule("; 1594 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) { 1595 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, 1596 Node->getFirstScheduleModifier()); 1597 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) { 1598 OS << ", "; 1599 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, 1600 Node->getSecondScheduleModifier()); 1601 } 1602 OS << ": "; 1603 } 1604 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind()); 1605 if (auto *E = Node->getChunkSize()) { 1606 OS << ", "; 1607 E->printPretty(OS, nullptr, Policy); 1608 } 1609 OS << ")"; 1610 } 1611 1612 void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) { 1613 OS << "ordered"; 1614 if (auto *Num = Node->getNumForLoops()) { 1615 OS << "("; 1616 Num->printPretty(OS, nullptr, Policy, 0); 1617 OS << ")"; 1618 } 1619 } 1620 1621 void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) { 1622 OS << "nowait"; 1623 } 1624 1625 void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) { 1626 OS << "untied"; 1627 } 1628 1629 void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) { 1630 OS << "nogroup"; 1631 } 1632 1633 void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) { 1634 OS << "mergeable"; 1635 } 1636 1637 void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; } 1638 1639 void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; } 1640 1641 void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *Node) { 1642 OS << "update"; 1643 if (Node->isExtended()) { 1644 OS << "("; 1645 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), 1646 Node->getDependencyKind()); 1647 OS << ")"; 1648 } 1649 } 1650 1651 void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) { 1652 OS << "capture"; 1653 } 1654 1655 void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) { 1656 OS << "seq_cst"; 1657 } 1658 1659 void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause *) { 1660 OS << "acq_rel"; 1661 } 1662 1663 void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause *) { 1664 OS << "acquire"; 1665 } 1666 1667 void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause *) { 1668 OS << "release"; 1669 } 1670 1671 void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause *) { 1672 OS << "relaxed"; 1673 } 1674 1675 void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) { 1676 OS << "threads"; 1677 } 1678 1679 void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; } 1680 1681 void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) { 1682 OS << "device("; 1683 OpenMPDeviceClauseModifier Modifier = Node->getModifier(); 1684 if (Modifier != OMPC_DEVICE_unknown) { 1685 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier) 1686 << ": "; 1687 } 1688 Node->getDevice()->printPretty(OS, nullptr, Policy, 0); 1689 OS << ")"; 1690 } 1691 1692 void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) { 1693 OS << "num_teams("; 1694 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0); 1695 OS << ")"; 1696 } 1697 1698 void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) { 1699 OS << "thread_limit("; 1700 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0); 1701 OS << ")"; 1702 } 1703 1704 void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) { 1705 OS << "priority("; 1706 Node->getPriority()->printPretty(OS, nullptr, Policy, 0); 1707 OS << ")"; 1708 } 1709 1710 void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) { 1711 OS << "grainsize("; 1712 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0); 1713 OS << ")"; 1714 } 1715 1716 void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) { 1717 OS << "num_tasks("; 1718 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0); 1719 OS << ")"; 1720 } 1721 1722 void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) { 1723 OS << "hint("; 1724 Node->getHint()->printPretty(OS, nullptr, Policy, 0); 1725 OS << ")"; 1726 } 1727 1728 void OMPClausePrinter::VisitOMPDestroyClause(OMPDestroyClause *) { 1729 OS << "destroy"; 1730 } 1731 1732 template<typename T> 1733 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) { 1734 for (typename T::varlist_iterator I = Node->varlist_begin(), 1735 E = Node->varlist_end(); 1736 I != E; ++I) { 1737 assert(*I && "Expected non-null Stmt"); 1738 OS << (I == Node->varlist_begin() ? StartSym : ','); 1739 if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) { 1740 if (isa<OMPCapturedExprDecl>(DRE->getDecl())) 1741 DRE->printPretty(OS, nullptr, Policy, 0); 1742 else 1743 DRE->getDecl()->printQualifiedName(OS); 1744 } else 1745 (*I)->printPretty(OS, nullptr, Policy, 0); 1746 } 1747 } 1748 1749 void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) { 1750 if (Node->varlist_empty()) 1751 return; 1752 OS << "allocate"; 1753 if (Expr *Allocator = Node->getAllocator()) { 1754 OS << "("; 1755 Allocator->printPretty(OS, nullptr, Policy, 0); 1756 OS << ":"; 1757 VisitOMPClauseList(Node, ' '); 1758 } else { 1759 VisitOMPClauseList(Node, '('); 1760 } 1761 OS << ")"; 1762 } 1763 1764 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) { 1765 if (!Node->varlist_empty()) { 1766 OS << "private"; 1767 VisitOMPClauseList(Node, '('); 1768 OS << ")"; 1769 } 1770 } 1771 1772 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) { 1773 if (!Node->varlist_empty()) { 1774 OS << "firstprivate"; 1775 VisitOMPClauseList(Node, '('); 1776 OS << ")"; 1777 } 1778 } 1779 1780 void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) { 1781 if (!Node->varlist_empty()) { 1782 OS << "lastprivate"; 1783 OpenMPLastprivateModifier LPKind = Node->getKind(); 1784 if (LPKind != OMPC_LASTPRIVATE_unknown) { 1785 OS << "(" 1786 << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind()) 1787 << ":"; 1788 } 1789 VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' '); 1790 OS << ")"; 1791 } 1792 } 1793 1794 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) { 1795 if (!Node->varlist_empty()) { 1796 OS << "shared"; 1797 VisitOMPClauseList(Node, '('); 1798 OS << ")"; 1799 } 1800 } 1801 1802 void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) { 1803 if (!Node->varlist_empty()) { 1804 OS << "reduction("; 1805 if (Node->getModifierLoc().isValid()) 1806 OS << getOpenMPSimpleClauseTypeName(OMPC_reduction, Node->getModifier()) 1807 << ", "; 1808 NestedNameSpecifier *QualifierLoc = 1809 Node->getQualifierLoc().getNestedNameSpecifier(); 1810 OverloadedOperatorKind OOK = 1811 Node->getNameInfo().getName().getCXXOverloadedOperator(); 1812 if (QualifierLoc == nullptr && OOK != OO_None) { 1813 // Print reduction identifier in C format 1814 OS << getOperatorSpelling(OOK); 1815 } else { 1816 // Use C++ format 1817 if (QualifierLoc != nullptr) 1818 QualifierLoc->print(OS, Policy); 1819 OS << Node->getNameInfo(); 1820 } 1821 OS << ":"; 1822 VisitOMPClauseList(Node, ' '); 1823 OS << ")"; 1824 } 1825 } 1826 1827 void OMPClausePrinter::VisitOMPTaskReductionClause( 1828 OMPTaskReductionClause *Node) { 1829 if (!Node->varlist_empty()) { 1830 OS << "task_reduction("; 1831 NestedNameSpecifier *QualifierLoc = 1832 Node->getQualifierLoc().getNestedNameSpecifier(); 1833 OverloadedOperatorKind OOK = 1834 Node->getNameInfo().getName().getCXXOverloadedOperator(); 1835 if (QualifierLoc == nullptr && OOK != OO_None) { 1836 // Print reduction identifier in C format 1837 OS << getOperatorSpelling(OOK); 1838 } else { 1839 // Use C++ format 1840 if (QualifierLoc != nullptr) 1841 QualifierLoc->print(OS, Policy); 1842 OS << Node->getNameInfo(); 1843 } 1844 OS << ":"; 1845 VisitOMPClauseList(Node, ' '); 1846 OS << ")"; 1847 } 1848 } 1849 1850 void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) { 1851 if (!Node->varlist_empty()) { 1852 OS << "in_reduction("; 1853 NestedNameSpecifier *QualifierLoc = 1854 Node->getQualifierLoc().getNestedNameSpecifier(); 1855 OverloadedOperatorKind OOK = 1856 Node->getNameInfo().getName().getCXXOverloadedOperator(); 1857 if (QualifierLoc == nullptr && OOK != OO_None) { 1858 // Print reduction identifier in C format 1859 OS << getOperatorSpelling(OOK); 1860 } else { 1861 // Use C++ format 1862 if (QualifierLoc != nullptr) 1863 QualifierLoc->print(OS, Policy); 1864 OS << Node->getNameInfo(); 1865 } 1866 OS << ":"; 1867 VisitOMPClauseList(Node, ' '); 1868 OS << ")"; 1869 } 1870 } 1871 1872 void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) { 1873 if (!Node->varlist_empty()) { 1874 OS << "linear"; 1875 if (Node->getModifierLoc().isValid()) { 1876 OS << '(' 1877 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier()); 1878 } 1879 VisitOMPClauseList(Node, '('); 1880 if (Node->getModifierLoc().isValid()) 1881 OS << ')'; 1882 if (Node->getStep() != nullptr) { 1883 OS << ": "; 1884 Node->getStep()->printPretty(OS, nullptr, Policy, 0); 1885 } 1886 OS << ")"; 1887 } 1888 } 1889 1890 void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) { 1891 if (!Node->varlist_empty()) { 1892 OS << "aligned"; 1893 VisitOMPClauseList(Node, '('); 1894 if (Node->getAlignment() != nullptr) { 1895 OS << ": "; 1896 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0); 1897 } 1898 OS << ")"; 1899 } 1900 } 1901 1902 void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) { 1903 if (!Node->varlist_empty()) { 1904 OS << "copyin"; 1905 VisitOMPClauseList(Node, '('); 1906 OS << ")"; 1907 } 1908 } 1909 1910 void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) { 1911 if (!Node->varlist_empty()) { 1912 OS << "copyprivate"; 1913 VisitOMPClauseList(Node, '('); 1914 OS << ")"; 1915 } 1916 } 1917 1918 void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) { 1919 if (!Node->varlist_empty()) { 1920 VisitOMPClauseList(Node, '('); 1921 OS << ")"; 1922 } 1923 } 1924 1925 void OMPClausePrinter::VisitOMPDepobjClause(OMPDepobjClause *Node) { 1926 OS << "("; 1927 Node->getDepobj()->printPretty(OS, nullptr, Policy, 0); 1928 OS << ")"; 1929 } 1930 1931 void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) { 1932 OS << "depend("; 1933 if (Expr *DepModifier = Node->getModifier()) { 1934 DepModifier->printPretty(OS, nullptr, Policy); 1935 OS << ", "; 1936 } 1937 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), 1938 Node->getDependencyKind()); 1939 if (!Node->varlist_empty()) { 1940 OS << " :"; 1941 VisitOMPClauseList(Node, ' '); 1942 } 1943 OS << ")"; 1944 } 1945 1946 template <typename T> 1947 static void PrintMapper(raw_ostream &OS, T *Node, 1948 const PrintingPolicy &Policy) { 1949 OS << '('; 1950 NestedNameSpecifier *MapperNNS = 1951 Node->getMapperQualifierLoc().getNestedNameSpecifier(); 1952 if (MapperNNS) 1953 MapperNNS->print(OS, Policy); 1954 OS << Node->getMapperIdInfo() << ')'; 1955 } 1956 1957 void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) { 1958 if (!Node->varlist_empty()) { 1959 OS << "map("; 1960 if (Node->getMapType() != OMPC_MAP_unknown) { 1961 for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) { 1962 if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) { 1963 OS << getOpenMPSimpleClauseTypeName(OMPC_map, 1964 Node->getMapTypeModifier(I)); 1965 if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) 1966 PrintMapper(OS, Node, Policy); 1967 OS << ','; 1968 } 1969 } 1970 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType()); 1971 OS << ':'; 1972 } 1973 VisitOMPClauseList(Node, ' '); 1974 OS << ")"; 1975 } 1976 } 1977 1978 template <typename T> void OMPClausePrinter::VisitOMPMotionClause(T *Node) { 1979 if (Node->varlist_empty()) 1980 return; 1981 OS << getOpenMPClauseName(Node->getClauseKind()); 1982 unsigned ModifierCount = 0; 1983 for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) { 1984 if (Node->getMotionModifier(I) != OMPC_MOTION_MODIFIER_unknown) 1985 ++ModifierCount; 1986 } 1987 if (ModifierCount) { 1988 OS << '('; 1989 for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) { 1990 if (Node->getMotionModifier(I) != OMPC_MOTION_MODIFIER_unknown) { 1991 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), 1992 Node->getMotionModifier(I)); 1993 if (Node->getMotionModifier(I) == OMPC_MOTION_MODIFIER_mapper) 1994 PrintMapper(OS, Node, Policy); 1995 if (I < ModifierCount - 1) 1996 OS << ", "; 1997 } 1998 } 1999 OS << ':'; 2000 VisitOMPClauseList(Node, ' '); 2001 } else { 2002 VisitOMPClauseList(Node, '('); 2003 } 2004 OS << ")"; 2005 } 2006 2007 void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) { 2008 VisitOMPMotionClause(Node); 2009 } 2010 2011 void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) { 2012 VisitOMPMotionClause(Node); 2013 } 2014 2015 void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) { 2016 OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName( 2017 OMPC_dist_schedule, Node->getDistScheduleKind()); 2018 if (auto *E = Node->getChunkSize()) { 2019 OS << ", "; 2020 E->printPretty(OS, nullptr, Policy); 2021 } 2022 OS << ")"; 2023 } 2024 2025 void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) { 2026 OS << "defaultmap("; 2027 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap, 2028 Node->getDefaultmapModifier()); 2029 if (Node->getDefaultmapKind() != OMPC_DEFAULTMAP_unknown) { 2030 OS << ": "; 2031 OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap, 2032 Node->getDefaultmapKind()); 2033 } 2034 OS << ")"; 2035 } 2036 2037 void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) { 2038 if (!Node->varlist_empty()) { 2039 OS << "use_device_ptr"; 2040 VisitOMPClauseList(Node, '('); 2041 OS << ")"; 2042 } 2043 } 2044 2045 void OMPClausePrinter::VisitOMPUseDeviceAddrClause( 2046 OMPUseDeviceAddrClause *Node) { 2047 if (!Node->varlist_empty()) { 2048 OS << "use_device_addr"; 2049 VisitOMPClauseList(Node, '('); 2050 OS << ")"; 2051 } 2052 } 2053 2054 void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) { 2055 if (!Node->varlist_empty()) { 2056 OS << "is_device_ptr"; 2057 VisitOMPClauseList(Node, '('); 2058 OS << ")"; 2059 } 2060 } 2061 2062 void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) { 2063 if (!Node->varlist_empty()) { 2064 OS << "nontemporal"; 2065 VisitOMPClauseList(Node, '('); 2066 OS << ")"; 2067 } 2068 } 2069 2070 void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) { 2071 OS << "order(" << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind()) 2072 << ")"; 2073 } 2074 2075 void OMPClausePrinter::VisitOMPInclusiveClause(OMPInclusiveClause *Node) { 2076 if (!Node->varlist_empty()) { 2077 OS << "inclusive"; 2078 VisitOMPClauseList(Node, '('); 2079 OS << ")"; 2080 } 2081 } 2082 2083 void OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause *Node) { 2084 if (!Node->varlist_empty()) { 2085 OS << "exclusive"; 2086 VisitOMPClauseList(Node, '('); 2087 OS << ")"; 2088 } 2089 } 2090 2091 void OMPClausePrinter::VisitOMPUsesAllocatorsClause( 2092 OMPUsesAllocatorsClause *Node) { 2093 if (Node->getNumberOfAllocators() == 0) 2094 return; 2095 OS << "uses_allocators("; 2096 for (unsigned I = 0, E = Node->getNumberOfAllocators(); I < E; ++I) { 2097 OMPUsesAllocatorsClause::Data Data = Node->getAllocatorData(I); 2098 Data.Allocator->printPretty(OS, nullptr, Policy); 2099 if (Data.AllocatorTraits) { 2100 OS << "("; 2101 Data.AllocatorTraits->printPretty(OS, nullptr, Policy); 2102 OS << ")"; 2103 } 2104 if (I < E - 1) 2105 OS << ","; 2106 } 2107 OS << ")"; 2108 } 2109 2110 void OMPClausePrinter::VisitOMPAffinityClause(OMPAffinityClause *Node) { 2111 if (Node->varlist_empty()) 2112 return; 2113 OS << "affinity"; 2114 char StartSym = '('; 2115 if (Expr *Modifier = Node->getModifier()) { 2116 OS << "("; 2117 Modifier->printPretty(OS, nullptr, Policy); 2118 OS << " :"; 2119 StartSym = ' '; 2120 } 2121 VisitOMPClauseList(Node, StartSym); 2122 OS << ")"; 2123 } 2124 2125 void OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx, 2126 VariantMatchInfo &VMI) const { 2127 for (const OMPTraitSet &Set : Sets) { 2128 for (const OMPTraitSelector &Selector : Set.Selectors) { 2129 2130 // User conditions are special as we evaluate the condition here. 2131 if (Selector.Kind == TraitSelector::user_condition) { 2132 assert(Selector.ScoreOrCondition && 2133 "Ill-formed user condition, expected condition expression!"); 2134 assert(Selector.Properties.size() == 1 && 2135 Selector.Properties.front().Kind == 2136 TraitProperty::user_condition_unknown && 2137 "Ill-formed user condition, expected unknown trait property!"); 2138 2139 if (Optional<APSInt> CondVal = 2140 Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx)) 2141 VMI.addTrait(CondVal->isNullValue() 2142 ? TraitProperty::user_condition_false 2143 : TraitProperty::user_condition_true, 2144 "<condition>"); 2145 else 2146 VMI.addTrait(TraitProperty::user_condition_false, "<condition>"); 2147 continue; 2148 } 2149 2150 Optional<llvm::APSInt> Score; 2151 llvm::APInt *ScorePtr = nullptr; 2152 if (Selector.ScoreOrCondition) { 2153 if ((Score = Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx))) 2154 ScorePtr = &*Score; 2155 else 2156 VMI.addTrait(TraitProperty::user_condition_false, 2157 "<non-constant-score>"); 2158 } 2159 2160 for (const OMPTraitProperty &Property : Selector.Properties) 2161 VMI.addTrait(Set.Kind, Property.Kind, Property.RawString, ScorePtr); 2162 2163 if (Set.Kind != TraitSet::construct) 2164 continue; 2165 2166 // TODO: This might not hold once we implement SIMD properly. 2167 assert(Selector.Properties.size() == 1 && 2168 Selector.Properties.front().Kind == 2169 getOpenMPContextTraitPropertyForSelector( 2170 Selector.Kind) && 2171 "Ill-formed construct selector!"); 2172 2173 VMI.ConstructTraits.push_back(Selector.Properties.front().Kind); 2174 } 2175 } 2176 } 2177 2178 void OMPTraitInfo::print(llvm::raw_ostream &OS, 2179 const PrintingPolicy &Policy) const { 2180 bool FirstSet = true; 2181 for (const OMPTraitSet &Set : Sets) { 2182 if (!FirstSet) 2183 OS << ", "; 2184 FirstSet = false; 2185 OS << getOpenMPContextTraitSetName(Set.Kind) << "={"; 2186 2187 bool FirstSelector = true; 2188 for (const OMPTraitSelector &Selector : Set.Selectors) { 2189 if (!FirstSelector) 2190 OS << ", "; 2191 FirstSelector = false; 2192 OS << getOpenMPContextTraitSelectorName(Selector.Kind); 2193 2194 bool AllowsTraitScore = false; 2195 bool RequiresProperty = false; 2196 isValidTraitSelectorForTraitSet( 2197 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty); 2198 2199 if (!RequiresProperty) 2200 continue; 2201 2202 OS << "("; 2203 if (Selector.Kind == TraitSelector::user_condition) { 2204 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy); 2205 } else { 2206 2207 if (Selector.ScoreOrCondition) { 2208 OS << "score("; 2209 Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy); 2210 OS << "): "; 2211 } 2212 2213 bool FirstProperty = true; 2214 for (const OMPTraitProperty &Property : Selector.Properties) { 2215 if (!FirstProperty) 2216 OS << ", "; 2217 FirstProperty = false; 2218 OS << getOpenMPContextTraitPropertyName(Property.Kind, 2219 Property.RawString); 2220 } 2221 } 2222 OS << ")"; 2223 } 2224 OS << "}"; 2225 } 2226 } 2227 2228 std::string OMPTraitInfo::getMangledName() const { 2229 std::string MangledName; 2230 llvm::raw_string_ostream OS(MangledName); 2231 for (const OMPTraitSet &Set : Sets) { 2232 OS << '$' << 'S' << unsigned(Set.Kind); 2233 for (const OMPTraitSelector &Selector : Set.Selectors) { 2234 2235 bool AllowsTraitScore = false; 2236 bool RequiresProperty = false; 2237 isValidTraitSelectorForTraitSet( 2238 Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty); 2239 OS << '$' << 's' << unsigned(Selector.Kind); 2240 2241 if (!RequiresProperty || 2242 Selector.Kind == TraitSelector::user_condition) 2243 continue; 2244 2245 for (const OMPTraitProperty &Property : Selector.Properties) 2246 OS << '$' << 'P' 2247 << getOpenMPContextTraitPropertyName(Property.Kind, 2248 Property.RawString); 2249 } 2250 } 2251 return OS.str(); 2252 } 2253 2254 OMPTraitInfo::OMPTraitInfo(StringRef MangledName) { 2255 unsigned long U; 2256 do { 2257 if (!MangledName.consume_front("$S")) 2258 break; 2259 if (MangledName.consumeInteger(10, U)) 2260 break; 2261 Sets.push_back(OMPTraitSet()); 2262 OMPTraitSet &Set = Sets.back(); 2263 Set.Kind = TraitSet(U); 2264 do { 2265 if (!MangledName.consume_front("$s")) 2266 break; 2267 if (MangledName.consumeInteger(10, U)) 2268 break; 2269 Set.Selectors.push_back(OMPTraitSelector()); 2270 OMPTraitSelector &Selector = Set.Selectors.back(); 2271 Selector.Kind = TraitSelector(U); 2272 do { 2273 if (!MangledName.consume_front("$P")) 2274 break; 2275 Selector.Properties.push_back(OMPTraitProperty()); 2276 OMPTraitProperty &Property = Selector.Properties.back(); 2277 std::pair<StringRef, StringRef> PropRestPair = MangledName.split('$'); 2278 Property.RawString = PropRestPair.first; 2279 Property.Kind = getOpenMPContextTraitPropertyKind( 2280 Set.Kind, Selector.Kind, PropRestPair.first); 2281 MangledName = PropRestPair.second; 2282 } while (true); 2283 } while (true); 2284 } while (true); 2285 } 2286 2287 llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS, 2288 const OMPTraitInfo &TI) { 2289 LangOptions LO; 2290 PrintingPolicy Policy(LO); 2291 TI.print(OS, Policy); 2292 return OS; 2293 } 2294 llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS, 2295 const OMPTraitInfo *TI) { 2296 return TI ? OS << *TI : OS; 2297 } 2298 2299 TargetOMPContext::TargetOMPContext( 2300 ASTContext &ASTCtx, std::function<void(StringRef)> &&DiagUnknownTrait, 2301 const FunctionDecl *CurrentFunctionDecl) 2302 : OMPContext(ASTCtx.getLangOpts().OpenMPIsDevice, 2303 ASTCtx.getTargetInfo().getTriple()), 2304 FeatureValidityCheck([&](StringRef FeatureName) { 2305 return ASTCtx.getTargetInfo().isValidFeatureName(FeatureName); 2306 }), 2307 DiagUnknownTrait(std::move(DiagUnknownTrait)) { 2308 ASTCtx.getFunctionFeatureMap(FeatureMap, CurrentFunctionDecl); 2309 } 2310 2311 bool TargetOMPContext::matchesISATrait(StringRef RawString) const { 2312 auto It = FeatureMap.find(RawString); 2313 if (It != FeatureMap.end()) 2314 return It->second; 2315 if (!FeatureValidityCheck(RawString)) 2316 DiagUnknownTrait(RawString); 2317 return false; 2318 } 2319