1 //===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===// 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 /// \file 10 /// This file defines OpenMP AST classes for clauses. 11 /// There are clauses for executable directives, clauses for declarative 12 /// directives and clauses which can be used in both kinds of directives. 13 // 14 //===----------------------------------------------------------------------===// 15 16 #ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H 17 #define LLVM_CLANG_AST_OPENMPCLAUSE_H 18 19 #include "clang/AST/ASTFwd.h" 20 #include "clang/AST/Decl.h" 21 #include "clang/AST/DeclarationName.h" 22 #include "clang/AST/Expr.h" 23 #include "clang/AST/NestedNameSpecifier.h" 24 #include "clang/AST/Stmt.h" 25 #include "clang/AST/StmtIterator.h" 26 #include "clang/Basic/LLVM.h" 27 #include "clang/Basic/OpenMPKinds.h" 28 #include "clang/Basic/SourceLocation.h" 29 #include "llvm/ADT/ArrayRef.h" 30 #include "llvm/ADT/MapVector.h" 31 #include "llvm/ADT/PointerIntPair.h" 32 #include "llvm/ADT/SmallVector.h" 33 #include "llvm/ADT/iterator.h" 34 #include "llvm/ADT/iterator_range.h" 35 #include "llvm/Frontend/OpenMP/OMPAssume.h" 36 #include "llvm/Frontend/OpenMP/OMPConstants.h" 37 #include "llvm/Frontend/OpenMP/OMPContext.h" 38 #include "llvm/Support/Casting.h" 39 #include "llvm/Support/Compiler.h" 40 #include "llvm/Support/TrailingObjects.h" 41 #include <cassert> 42 #include <cstddef> 43 #include <iterator> 44 #include <utility> 45 46 namespace clang { 47 48 class ASTContext; 49 50 //===----------------------------------------------------------------------===// 51 // AST classes for clauses. 52 //===----------------------------------------------------------------------===// 53 54 /// This is a basic class for representing single OpenMP clause. 55 class OMPClause { 56 /// Starting location of the clause (the clause keyword). 57 SourceLocation StartLoc; 58 59 /// Ending location of the clause. 60 SourceLocation EndLoc; 61 62 /// Kind of the clause. 63 OpenMPClauseKind Kind; 64 65 protected: 66 OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc) 67 : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {} 68 69 public: 70 /// Returns the starting location of the clause. 71 SourceLocation getBeginLoc() const { return StartLoc; } 72 73 /// Returns the ending location of the clause. 74 SourceLocation getEndLoc() const { return EndLoc; } 75 76 /// Sets the starting location of the clause. 77 void setLocStart(SourceLocation Loc) { StartLoc = Loc; } 78 79 /// Sets the ending location of the clause. 80 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; } 81 82 /// Returns kind of OpenMP clause (private, shared, reduction, etc.). 83 OpenMPClauseKind getClauseKind() const { return Kind; } 84 85 bool isImplicit() const { return StartLoc.isInvalid(); } 86 87 using child_iterator = StmtIterator; 88 using const_child_iterator = ConstStmtIterator; 89 using child_range = llvm::iterator_range<child_iterator>; 90 using const_child_range = llvm::iterator_range<const_child_iterator>; 91 92 child_range children(); 93 const_child_range children() const { 94 auto Children = const_cast<OMPClause *>(this)->children(); 95 return const_child_range(Children.begin(), Children.end()); 96 } 97 98 /// Get the iterator range for the expressions used in the clauses. Used 99 /// expressions include only the children that must be evaluated at the 100 /// runtime before entering the construct. 101 child_range used_children(); 102 const_child_range used_children() const { 103 auto Children = const_cast<OMPClause *>(this)->children(); 104 return const_child_range(Children.begin(), Children.end()); 105 } 106 107 static bool classof(const OMPClause *) { return true; } 108 }; 109 110 template <OpenMPClauseKind ClauseKind> 111 struct OMPNoChildClause : public OMPClause { 112 /// Build '\p ClauseKind' clause. 113 /// 114 /// \param StartLoc Starting location of the clause. 115 /// \param EndLoc Ending location of the clause. 116 OMPNoChildClause(SourceLocation StartLoc, SourceLocation EndLoc) 117 : OMPClause(ClauseKind, StartLoc, EndLoc) {} 118 119 /// Build an empty clause. 120 OMPNoChildClause() 121 : OMPClause(ClauseKind, SourceLocation(), SourceLocation()) {} 122 123 child_range children() { 124 return child_range(child_iterator(), child_iterator()); 125 } 126 127 const_child_range children() const { 128 return const_child_range(const_child_iterator(), const_child_iterator()); 129 } 130 131 child_range used_children() { 132 return child_range(child_iterator(), child_iterator()); 133 } 134 const_child_range used_children() const { 135 return const_child_range(const_child_iterator(), const_child_iterator()); 136 } 137 138 static bool classof(const OMPClause *T) { 139 return T->getClauseKind() == ClauseKind; 140 } 141 }; 142 143 template <OpenMPClauseKind ClauseKind, class Base> 144 class OMPOneStmtClause : public Base { 145 146 /// Location of '('. 147 SourceLocation LParenLoc; 148 149 /// Sub-expression. 150 Stmt *S = nullptr; 151 152 protected: 153 void setStmt(Stmt *S) { this->S = S; } 154 155 public: 156 OMPOneStmtClause(Stmt *S, SourceLocation StartLoc, SourceLocation LParenLoc, 157 SourceLocation EndLoc) 158 : Base(ClauseKind, StartLoc, EndLoc), LParenLoc(LParenLoc), S(S) {} 159 160 OMPOneStmtClause() : Base(ClauseKind, SourceLocation(), SourceLocation()) {} 161 162 /// Return the associated statement, potentially casted to \p T. 163 template <typename T> T *getStmtAs() const { return cast_or_null<T>(S); } 164 165 /// Sets the location of '('. 166 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 167 168 /// Returns the location of '('. 169 SourceLocation getLParenLoc() const { return LParenLoc; } 170 171 using child_iterator = StmtIterator; 172 using const_child_iterator = ConstStmtIterator; 173 using child_range = llvm::iterator_range<child_iterator>; 174 using const_child_range = llvm::iterator_range<const_child_iterator>; 175 176 child_range children() { return child_range(&S, &S + 1); } 177 178 const_child_range children() const { return const_child_range(&S, &S + 1); } 179 180 // TODO: Consider making the getAddrOfExprAsWritten version the default. 181 child_range used_children() { 182 return child_range(child_iterator(), child_iterator()); 183 } 184 const_child_range used_children() const { 185 return const_child_range(const_child_iterator(), const_child_iterator()); 186 } 187 188 static bool classof(const OMPClause *T) { 189 return T->getClauseKind() == ClauseKind; 190 } 191 }; 192 193 /// Class that handles pre-initialization statement for some clauses, like 194 /// 'schedule', 'firstprivate' etc. 195 class OMPClauseWithPreInit { 196 friend class OMPClauseReader; 197 198 /// Pre-initialization statement for the clause. 199 Stmt *PreInit = nullptr; 200 201 /// Region that captures the associated stmt. 202 OpenMPDirectiveKind CaptureRegion = llvm::omp::OMPD_unknown; 203 204 protected: 205 OMPClauseWithPreInit(const OMPClause *This) { 206 assert(get(This) && "get is not tuned for pre-init."); 207 } 208 209 /// Set pre-initialization statement for the clause. 210 void 211 setPreInitStmt(Stmt *S, 212 OpenMPDirectiveKind ThisRegion = llvm::omp::OMPD_unknown) { 213 PreInit = S; 214 CaptureRegion = ThisRegion; 215 } 216 217 public: 218 /// Get pre-initialization statement for the clause. 219 const Stmt *getPreInitStmt() const { return PreInit; } 220 221 /// Get pre-initialization statement for the clause. 222 Stmt *getPreInitStmt() { return PreInit; } 223 224 /// Get capture region for the stmt in the clause. 225 OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; } 226 227 static OMPClauseWithPreInit *get(OMPClause *C); 228 static const OMPClauseWithPreInit *get(const OMPClause *C); 229 }; 230 231 /// Class that handles post-update expression for some clauses, like 232 /// 'lastprivate', 'reduction' etc. 233 class OMPClauseWithPostUpdate : public OMPClauseWithPreInit { 234 friend class OMPClauseReader; 235 236 /// Post-update expression for the clause. 237 Expr *PostUpdate = nullptr; 238 239 protected: 240 OMPClauseWithPostUpdate(const OMPClause *This) : OMPClauseWithPreInit(This) { 241 assert(get(This) && "get is not tuned for post-update."); 242 } 243 244 /// Set pre-initialization statement for the clause. 245 void setPostUpdateExpr(Expr *S) { PostUpdate = S; } 246 247 public: 248 /// Get post-update expression for the clause. 249 const Expr *getPostUpdateExpr() const { return PostUpdate; } 250 251 /// Get post-update expression for the clause. 252 Expr *getPostUpdateExpr() { return PostUpdate; } 253 254 static OMPClauseWithPostUpdate *get(OMPClause *C); 255 static const OMPClauseWithPostUpdate *get(const OMPClause *C); 256 }; 257 258 /// This structure contains most locations needed for by an OMPVarListClause. 259 struct OMPVarListLocTy { 260 /// Starting location of the clause (the clause keyword). 261 SourceLocation StartLoc; 262 /// Location of '('. 263 SourceLocation LParenLoc; 264 /// Ending location of the clause. 265 SourceLocation EndLoc; 266 OMPVarListLocTy() = default; 267 OMPVarListLocTy(SourceLocation StartLoc, SourceLocation LParenLoc, 268 SourceLocation EndLoc) 269 : StartLoc(StartLoc), LParenLoc(LParenLoc), EndLoc(EndLoc) {} 270 }; 271 272 /// This represents clauses with the list of variables like 'private', 273 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the 274 /// '#pragma omp ...' directives. 275 template <class T> class OMPVarListClause : public OMPClause { 276 friend class OMPClauseReader; 277 278 /// Location of '('. 279 SourceLocation LParenLoc; 280 281 /// Number of variables in the list. 282 unsigned NumVars; 283 284 protected: 285 /// Build a clause with \a N variables 286 /// 287 /// \param K Kind of the clause. 288 /// \param StartLoc Starting location of the clause (the clause keyword). 289 /// \param LParenLoc Location of '('. 290 /// \param EndLoc Ending location of the clause. 291 /// \param N Number of the variables in the clause. 292 OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc, 293 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N) 294 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {} 295 296 /// Fetches list of variables associated with this clause. 297 MutableArrayRef<Expr *> getVarRefs() { 298 return MutableArrayRef<Expr *>( 299 static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars); 300 } 301 302 /// Sets the list of variables for this clause. 303 void setVarRefs(ArrayRef<Expr *> VL) { 304 assert(VL.size() == NumVars && 305 "Number of variables is not the same as the preallocated buffer"); 306 std::copy(VL.begin(), VL.end(), 307 static_cast<T *>(this)->template getTrailingObjects<Expr *>()); 308 } 309 310 public: 311 using varlist_iterator = MutableArrayRef<Expr *>::iterator; 312 using varlist_const_iterator = ArrayRef<const Expr *>::iterator; 313 using varlist_range = llvm::iterator_range<varlist_iterator>; 314 using varlist_const_range = llvm::iterator_range<varlist_const_iterator>; 315 316 unsigned varlist_size() const { return NumVars; } 317 bool varlist_empty() const { return NumVars == 0; } 318 319 varlist_range varlist() { 320 return varlist_range(varlist_begin(), varlist_end()); 321 } 322 varlist_const_range varlist() const { 323 return varlist_const_range(varlist_begin(), varlist_end()); 324 } 325 326 varlist_iterator varlist_begin() { return getVarRefs().begin(); } 327 varlist_iterator varlist_end() { return getVarRefs().end(); } 328 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); } 329 varlist_const_iterator varlist_end() const { return getVarRefs().end(); } 330 331 /// Sets the location of '('. 332 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 333 334 /// Returns the location of '('. 335 SourceLocation getLParenLoc() const { return LParenLoc; } 336 337 /// Fetches list of all variables in the clause. 338 ArrayRef<const Expr *> getVarRefs() const { 339 return llvm::ArrayRef( 340 static_cast<const T *>(this)->template getTrailingObjects<Expr *>(), 341 NumVars); 342 } 343 }; 344 345 /// Class that represents a list of directive kinds (parallel, target, etc.) 346 /// as used in \c absent, \c contains clauses. 347 template <class T> class OMPDirectiveListClause : public OMPClause { 348 /// Location of '('. 349 SourceLocation LParenLoc; 350 351 protected: 352 /// Number of directive kinds listed in the clause 353 unsigned NumKinds; 354 355 public: 356 /// Build a clause with \a NumKinds directive kinds. 357 /// 358 /// \param K The clause kind. 359 /// \param StartLoc Starting location of the clause (the clause keyword). 360 /// \param LParenLoc Location of '('. 361 /// \param EndLoc Ending location of the clause. 362 /// \param NumKinds Number of directive kinds listed in the clause. 363 OMPDirectiveListClause(OpenMPClauseKind K, SourceLocation StartLoc, 364 SourceLocation LParenLoc, SourceLocation EndLoc, 365 unsigned NumKinds) 366 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), 367 NumKinds(NumKinds) {} 368 369 child_range children() { 370 return child_range(child_iterator(), child_iterator()); 371 } 372 373 const_child_range children() const { 374 return const_child_range(const_child_iterator(), const_child_iterator()); 375 } 376 377 child_range used_children() { 378 return child_range(child_iterator(), child_iterator()); 379 } 380 const_child_range used_children() const { 381 return const_child_range(const_child_iterator(), const_child_iterator()); 382 } 383 384 MutableArrayRef<OpenMPDirectiveKind> getDirectiveKinds() { 385 return MutableArrayRef<OpenMPDirectiveKind>( 386 static_cast<T *>(this) 387 ->template getTrailingObjects<OpenMPDirectiveKind>(), 388 NumKinds); 389 } 390 391 void setDirectiveKinds(ArrayRef<OpenMPDirectiveKind> DK) { 392 assert( 393 DK.size() == NumKinds && 394 "Number of directive kinds is not the same as the preallocated buffer"); 395 std::copy(DK.begin(), DK.end(), 396 static_cast<T *>(this) 397 ->template getTrailingObjects<OpenMPDirectiveKind>()); 398 } 399 400 SourceLocation getLParenLoc() { return LParenLoc; } 401 402 void setLParenLoc(SourceLocation S) { LParenLoc = S; } 403 }; 404 405 /// This represents 'allocator' clause in the '#pragma omp ...' 406 /// directive. 407 /// 408 /// \code 409 /// #pragma omp allocate(a) allocator(omp_default_mem_alloc) 410 /// \endcode 411 /// In this example directive '#pragma omp allocate' has simple 'allocator' 412 /// clause with the allocator 'omp_default_mem_alloc'. 413 class OMPAllocatorClause final 414 : public OMPOneStmtClause<llvm::omp::OMPC_allocator, OMPClause> { 415 friend class OMPClauseReader; 416 417 /// Set allocator. 418 void setAllocator(Expr *A) { setStmt(A); } 419 420 public: 421 /// Build 'allocator' clause with the given allocator. 422 /// 423 /// \param A Allocator. 424 /// \param StartLoc Starting location of the clause. 425 /// \param LParenLoc Location of '('. 426 /// \param EndLoc Ending location of the clause. 427 OMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, 428 SourceLocation EndLoc) 429 : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {} 430 431 /// Build an empty clause. 432 OMPAllocatorClause() : OMPOneStmtClause() {} 433 434 /// Returns allocator. 435 Expr *getAllocator() const { return getStmtAs<Expr>(); } 436 }; 437 438 /// This represents the 'align' clause in the '#pragma omp allocate' 439 /// directive. 440 /// 441 /// \code 442 /// #pragma omp allocate(a) allocator(omp_default_mem_alloc) align(8) 443 /// \endcode 444 /// In this example directive '#pragma omp allocate' has simple 'allocator' 445 /// clause with the allocator 'omp_default_mem_alloc' and align clause with 446 /// value of 8. 447 class OMPAlignClause final 448 : public OMPOneStmtClause<llvm::omp::OMPC_align, OMPClause> { 449 friend class OMPClauseReader; 450 451 /// Set alignment value. 452 void setAlignment(Expr *A) { setStmt(A); } 453 454 /// Build 'align' clause with the given alignment 455 /// 456 /// \param A Alignment value. 457 /// \param StartLoc Starting location of the clause. 458 /// \param LParenLoc Location of '('. 459 /// \param EndLoc Ending location of the clause. 460 OMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, 461 SourceLocation EndLoc) 462 : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {} 463 464 /// Build an empty clause. 465 OMPAlignClause() : OMPOneStmtClause() {} 466 467 public: 468 /// Build 'align' clause with the given alignment 469 /// 470 /// \param A Alignment value. 471 /// \param StartLoc Starting location of the clause. 472 /// \param LParenLoc Location of '('. 473 /// \param EndLoc Ending location of the clause. 474 static OMPAlignClause *Create(const ASTContext &C, Expr *A, 475 SourceLocation StartLoc, 476 SourceLocation LParenLoc, 477 SourceLocation EndLoc); 478 479 /// Returns alignment 480 Expr *getAlignment() const { return getStmtAs<Expr>(); } 481 }; 482 483 /// This represents clause 'allocate' in the '#pragma omp ...' directives. 484 /// 485 /// \code 486 /// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a) 487 /// \endcode 488 /// In this example directive '#pragma omp parallel' has clause 'private' 489 /// and clause 'allocate' for the variable 'a', which specifies an explicit 490 /// memory allocator. 491 class OMPAllocateClause final 492 : public OMPVarListClause<OMPAllocateClause>, 493 private llvm::TrailingObjects<OMPAllocateClause, Expr *> { 494 friend class OMPClauseReader; 495 friend OMPVarListClause; 496 friend TrailingObjects; 497 498 /// Allocator specified in the clause, or 'nullptr' if the default one is 499 /// used. 500 Expr *Allocator = nullptr; 501 /// Alignment specified in the clause, or 'nullptr' if the default one is 502 /// used. 503 Expr *Alignment = nullptr; 504 /// Position of the ':' delimiter in the clause; 505 SourceLocation ColonLoc; 506 /// Modifier of 'allocate' clause. 507 OpenMPAllocateClauseModifier AllocatorModifier = OMPC_ALLOCATE_unknown; 508 /// Location of allocator modifier if any. 509 SourceLocation AllocatorModifierLoc; 510 511 // ---------------------------------------------------------------------------- 512 513 /// Modifiers for 'allocate' clause. 514 enum { FIRST, SECOND, NUM_MODIFIERS }; 515 OpenMPAllocateClauseModifier Modifiers[NUM_MODIFIERS]; 516 517 /// Locations of modifiers. 518 SourceLocation ModifiersLoc[NUM_MODIFIERS]; 519 520 /// Set the first allocate modifier. 521 /// 522 /// \param M Allocate modifier. 523 void setFirstAllocateModifier(OpenMPAllocateClauseModifier M) { 524 Modifiers[FIRST] = M; 525 } 526 527 /// Set the second allocate modifier. 528 /// 529 /// \param M Allocate modifier. 530 void setSecondAllocateModifier(OpenMPAllocateClauseModifier M) { 531 Modifiers[SECOND] = M; 532 } 533 534 /// Set location of the first allocate modifier. 535 void setFirstAllocateModifierLoc(SourceLocation Loc) { 536 ModifiersLoc[FIRST] = Loc; 537 } 538 539 /// Set location of the second allocate modifier. 540 void setSecondAllocateModifierLoc(SourceLocation Loc) { 541 ModifiersLoc[SECOND] = Loc; 542 } 543 544 // ---------------------------------------------------------------------------- 545 546 /// Build clause with number of variables \a N. 547 /// 548 /// \param StartLoc Starting location of the clause. 549 /// \param LParenLoc Location of '('. 550 /// \param Allocator Allocator expression. 551 /// \param ColonLoc Location of ':' delimiter. 552 /// \param EndLoc Ending location of the clause. 553 /// \param N Number of the variables in the clause. 554 OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc, 555 Expr *Allocator, Expr *Alignment, SourceLocation ColonLoc, 556 OpenMPAllocateClauseModifier Modifier1, 557 SourceLocation Modifier1Loc, 558 OpenMPAllocateClauseModifier Modifier2, 559 SourceLocation Modifier2Loc, SourceLocation EndLoc, 560 unsigned N) 561 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate, StartLoc, 562 LParenLoc, EndLoc, N), 563 Allocator(Allocator), Alignment(Alignment), ColonLoc(ColonLoc) { 564 Modifiers[FIRST] = Modifier1; 565 Modifiers[SECOND] = Modifier2; 566 ModifiersLoc[FIRST] = Modifier1Loc; 567 ModifiersLoc[SECOND] = Modifier2Loc; 568 } 569 570 /// Build an empty clause. 571 /// 572 /// \param N Number of variables. 573 explicit OMPAllocateClause(unsigned N) 574 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate, 575 SourceLocation(), SourceLocation(), 576 SourceLocation(), N) { 577 Modifiers[FIRST] = OMPC_ALLOCATE_unknown; 578 Modifiers[SECOND] = OMPC_ALLOCATE_unknown; 579 } 580 581 /// Sets location of ':' symbol in clause. 582 void setColonLoc(SourceLocation CL) { ColonLoc = CL; } 583 584 void setAllocator(Expr *A) { Allocator = A; } 585 void setAllocatorModifier(OpenMPAllocateClauseModifier AM) { 586 AllocatorModifier = AM; 587 } 588 void setAlignment(Expr *A) { Alignment = A; } 589 590 public: 591 /// Creates clause with a list of variables \a VL. 592 /// 593 /// \param C AST context. 594 /// \param StartLoc Starting location of the clause. 595 /// \param LParenLoc Location of '('. 596 /// \param Allocator Allocator expression. 597 /// \param ColonLoc Location of ':' delimiter. 598 /// \param AllocatorModifier Allocator modifier. 599 /// \param SourceLocation Allocator modifier location. 600 /// \param EndLoc Ending location of the clause. 601 /// \param VL List of references to the variables. 602 static OMPAllocateClause * 603 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 604 Expr *Allocator, Expr *Alignment, SourceLocation ColonLoc, 605 OpenMPAllocateClauseModifier Modifier1, SourceLocation Modifier1Loc, 606 OpenMPAllocateClauseModifier Modifier2, SourceLocation Modifier2Loc, 607 SourceLocation EndLoc, ArrayRef<Expr *> VL); 608 609 /// Returns the allocator expression or nullptr, if no allocator is specified. 610 Expr *getAllocator() const { return Allocator; } 611 612 /// Returns the alignment expression or nullptr, if no alignment specified. 613 Expr *getAlignment() const { return Alignment; } 614 615 /// Return 'allocate' modifier. 616 OpenMPAllocateClauseModifier getAllocatorModifier() const { 617 return AllocatorModifier; 618 } 619 620 /// Get the first modifier of the clause. 621 OpenMPAllocateClauseModifier getFirstAllocateModifier() const { 622 return Modifiers[FIRST]; 623 } 624 625 /// Get location of first modifier of the clause. 626 SourceLocation getFirstAllocateModifierLoc() const { 627 return ModifiersLoc[FIRST]; 628 } 629 630 /// Get the second modifier of the clause. 631 OpenMPAllocateClauseModifier getSecondAllocateModifier() const { 632 return Modifiers[SECOND]; 633 } 634 635 /// Get location of second modifier of the clause. 636 SourceLocation getSecondAllocateModifierLoc() const { 637 return ModifiersLoc[SECOND]; 638 } 639 640 /// Returns the location of the ':' delimiter. 641 SourceLocation getColonLoc() const { return ColonLoc; } 642 /// Return the location of the modifier. 643 SourceLocation getAllocatorModifierLoc() const { 644 return AllocatorModifierLoc; 645 } 646 647 /// Creates an empty clause with the place for \a N variables. 648 /// 649 /// \param C AST context. 650 /// \param N The number of variables. 651 static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N); 652 653 child_range children() { 654 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 655 reinterpret_cast<Stmt **>(varlist_end())); 656 } 657 658 const_child_range children() const { 659 auto Children = const_cast<OMPAllocateClause *>(this)->children(); 660 return const_child_range(Children.begin(), Children.end()); 661 } 662 663 child_range used_children() { 664 return child_range(child_iterator(), child_iterator()); 665 } 666 const_child_range used_children() const { 667 return const_child_range(const_child_iterator(), const_child_iterator()); 668 } 669 670 static bool classof(const OMPClause *T) { 671 return T->getClauseKind() == llvm::omp::OMPC_allocate; 672 } 673 }; 674 675 /// This represents 'if' clause in the '#pragma omp ...' directive. 676 /// 677 /// \code 678 /// #pragma omp parallel if(parallel:a > 5) 679 /// \endcode 680 /// In this example directive '#pragma omp parallel' has simple 'if' clause with 681 /// condition 'a > 5' and directive name modifier 'parallel'. 682 class OMPIfClause : public OMPClause, public OMPClauseWithPreInit { 683 friend class OMPClauseReader; 684 685 /// Location of '('. 686 SourceLocation LParenLoc; 687 688 /// Condition of the 'if' clause. 689 Stmt *Condition = nullptr; 690 691 /// Location of ':' (if any). 692 SourceLocation ColonLoc; 693 694 /// Directive name modifier for the clause. 695 OpenMPDirectiveKind NameModifier = llvm::omp::OMPD_unknown; 696 697 /// Name modifier location. 698 SourceLocation NameModifierLoc; 699 700 /// Set condition. 701 void setCondition(Expr *Cond) { Condition = Cond; } 702 703 /// Set directive name modifier for the clause. 704 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; } 705 706 /// Set location of directive name modifier for the clause. 707 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; } 708 709 /// Set location of ':'. 710 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 711 712 public: 713 /// Build 'if' clause with condition \a Cond. 714 /// 715 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause. 716 /// \param Cond Condition of the clause. 717 /// \param HelperCond Helper condition for the clause. 718 /// \param CaptureRegion Innermost OpenMP region where expressions in this 719 /// clause must be captured. 720 /// \param StartLoc Starting location of the clause. 721 /// \param LParenLoc Location of '('. 722 /// \param NameModifierLoc Location of directive name modifier. 723 /// \param ColonLoc [OpenMP 4.1] Location of ':'. 724 /// \param EndLoc Ending location of the clause. 725 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond, 726 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, 727 SourceLocation LParenLoc, SourceLocation NameModifierLoc, 728 SourceLocation ColonLoc, SourceLocation EndLoc) 729 : OMPClause(llvm::omp::OMPC_if, StartLoc, EndLoc), 730 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond), 731 ColonLoc(ColonLoc), NameModifier(NameModifier), 732 NameModifierLoc(NameModifierLoc) { 733 setPreInitStmt(HelperCond, CaptureRegion); 734 } 735 736 /// Build an empty clause. 737 OMPIfClause() 738 : OMPClause(llvm::omp::OMPC_if, SourceLocation(), SourceLocation()), 739 OMPClauseWithPreInit(this) {} 740 741 /// Sets the location of '('. 742 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 743 744 /// Returns the location of '('. 745 SourceLocation getLParenLoc() const { return LParenLoc; } 746 747 /// Return the location of ':'. 748 SourceLocation getColonLoc() const { return ColonLoc; } 749 750 /// Returns condition. 751 Expr *getCondition() const { return cast_or_null<Expr>(Condition); } 752 753 /// Return directive name modifier associated with the clause. 754 OpenMPDirectiveKind getNameModifier() const { return NameModifier; } 755 756 /// Return the location of directive name modifier. 757 SourceLocation getNameModifierLoc() const { return NameModifierLoc; } 758 759 child_range children() { return child_range(&Condition, &Condition + 1); } 760 761 const_child_range children() const { 762 return const_child_range(&Condition, &Condition + 1); 763 } 764 765 child_range used_children(); 766 const_child_range used_children() const { 767 auto Children = const_cast<OMPIfClause *>(this)->used_children(); 768 return const_child_range(Children.begin(), Children.end()); 769 } 770 771 static bool classof(const OMPClause *T) { 772 return T->getClauseKind() == llvm::omp::OMPC_if; 773 } 774 }; 775 776 /// This represents 'final' clause in the '#pragma omp ...' directive. 777 /// 778 /// \code 779 /// #pragma omp task final(a > 5) 780 /// \endcode 781 /// In this example directive '#pragma omp task' has simple 'final' 782 /// clause with condition 'a > 5'. 783 class OMPFinalClause final 784 : public OMPOneStmtClause<llvm::omp::OMPC_final, OMPClause>, 785 public OMPClauseWithPreInit { 786 friend class OMPClauseReader; 787 788 /// Set condition. 789 void setCondition(Expr *Cond) { setStmt(Cond); } 790 791 public: 792 /// Build 'final' clause with condition \a Cond. 793 /// 794 /// \param Cond Condition of the clause. 795 /// \param HelperCond Helper condition for the construct. 796 /// \param CaptureRegion Innermost OpenMP region where expressions in this 797 /// clause must be captured. 798 /// \param StartLoc Starting location of the clause. 799 /// \param LParenLoc Location of '('. 800 /// \param EndLoc Ending location of the clause. 801 OMPFinalClause(Expr *Cond, Stmt *HelperCond, 802 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, 803 SourceLocation LParenLoc, SourceLocation EndLoc) 804 : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc), 805 OMPClauseWithPreInit(this) { 806 setPreInitStmt(HelperCond, CaptureRegion); 807 } 808 809 /// Build an empty clause. 810 OMPFinalClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {} 811 812 /// Returns condition. 813 Expr *getCondition() const { return getStmtAs<Expr>(); } 814 815 child_range used_children(); 816 const_child_range used_children() const { 817 auto Children = const_cast<OMPFinalClause *>(this)->used_children(); 818 return const_child_range(Children.begin(), Children.end()); 819 } 820 }; 821 /// This represents 'num_threads' clause in the '#pragma omp ...' 822 /// directive. 823 /// 824 /// \code 825 /// #pragma omp parallel num_threads(6) 826 /// \endcode 827 /// In this example directive '#pragma omp parallel' has simple 'num_threads' 828 /// clause with number of threads '6'. 829 class OMPNumThreadsClause final 830 : public OMPOneStmtClause<llvm::omp::OMPC_num_threads, OMPClause>, 831 public OMPClauseWithPreInit { 832 friend class OMPClauseReader; 833 834 /// Set condition. 835 void setNumThreads(Expr *NThreads) { setStmt(NThreads); } 836 837 public: 838 /// Build 'num_threads' clause with condition \a NumThreads. 839 /// 840 /// \param NumThreads Number of threads for the construct. 841 /// \param HelperNumThreads Helper Number of threads for the construct. 842 /// \param CaptureRegion Innermost OpenMP region where expressions in this 843 /// clause must be captured. 844 /// \param StartLoc Starting location of the clause. 845 /// \param LParenLoc Location of '('. 846 /// \param EndLoc Ending location of the clause. 847 OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads, 848 OpenMPDirectiveKind CaptureRegion, 849 SourceLocation StartLoc, SourceLocation LParenLoc, 850 SourceLocation EndLoc) 851 : OMPOneStmtClause(NumThreads, StartLoc, LParenLoc, EndLoc), 852 OMPClauseWithPreInit(this) { 853 setPreInitStmt(HelperNumThreads, CaptureRegion); 854 } 855 856 /// Build an empty clause. 857 OMPNumThreadsClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {} 858 859 /// Returns number of threads. 860 Expr *getNumThreads() const { return getStmtAs<Expr>(); } 861 }; 862 863 /// This represents 'safelen' clause in the '#pragma omp ...' 864 /// directive. 865 /// 866 /// \code 867 /// #pragma omp simd safelen(4) 868 /// \endcode 869 /// In this example directive '#pragma omp simd' has clause 'safelen' 870 /// with single expression '4'. 871 /// If the safelen clause is used then no two iterations executed 872 /// concurrently with SIMD instructions can have a greater distance 873 /// in the logical iteration space than its value. The parameter of 874 /// the safelen clause must be a constant positive integer expression. 875 class OMPSafelenClause final 876 : public OMPOneStmtClause<llvm::omp::OMPC_safelen, OMPClause> { 877 friend class OMPClauseReader; 878 879 /// Set safelen. 880 void setSafelen(Expr *Len) { setStmt(Len); } 881 882 public: 883 /// Build 'safelen' clause. 884 /// 885 /// \param Len Expression associated with this clause. 886 /// \param StartLoc Starting location of the clause. 887 /// \param EndLoc Ending location of the clause. 888 OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, 889 SourceLocation EndLoc) 890 : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {} 891 892 /// Build an empty clause. 893 explicit OMPSafelenClause() : OMPOneStmtClause() {} 894 895 /// Return safe iteration space distance. 896 Expr *getSafelen() const { return getStmtAs<Expr>(); } 897 }; 898 899 /// This represents 'simdlen' clause in the '#pragma omp ...' 900 /// directive. 901 /// 902 /// \code 903 /// #pragma omp simd simdlen(4) 904 /// \endcode 905 /// In this example directive '#pragma omp simd' has clause 'simdlen' 906 /// with single expression '4'. 907 /// If the 'simdlen' clause is used then it specifies the preferred number of 908 /// iterations to be executed concurrently. The parameter of the 'simdlen' 909 /// clause must be a constant positive integer expression. 910 class OMPSimdlenClause final 911 : public OMPOneStmtClause<llvm::omp::OMPC_simdlen, OMPClause> { 912 friend class OMPClauseReader; 913 914 /// Set simdlen. 915 void setSimdlen(Expr *Len) { setStmt(Len); } 916 917 public: 918 /// Build 'simdlen' clause. 919 /// 920 /// \param Len Expression associated with this clause. 921 /// \param StartLoc Starting location of the clause. 922 /// \param EndLoc Ending location of the clause. 923 OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, 924 SourceLocation EndLoc) 925 : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {} 926 927 /// Build an empty clause. 928 explicit OMPSimdlenClause() : OMPOneStmtClause() {} 929 930 /// Return safe iteration space distance. 931 Expr *getSimdlen() const { return getStmtAs<Expr>(); } 932 }; 933 934 /// This represents the 'sizes' clause in the '#pragma omp tile' directive. 935 /// 936 /// \code 937 /// #pragma omp tile sizes(5,5) 938 /// for (int i = 0; i < 64; ++i) 939 /// for (int j = 0; j < 64; ++j) 940 /// \endcode 941 class OMPSizesClause final 942 : public OMPClause, 943 private llvm::TrailingObjects<OMPSizesClause, Expr *> { 944 friend class OMPClauseReader; 945 friend class llvm::TrailingObjects<OMPSizesClause, Expr *>; 946 947 /// Location of '('. 948 SourceLocation LParenLoc; 949 950 /// Number of tile sizes in the clause. 951 unsigned NumSizes; 952 953 /// Build an empty clause. 954 explicit OMPSizesClause(int NumSizes) 955 : OMPClause(llvm::omp::OMPC_sizes, SourceLocation(), SourceLocation()), 956 NumSizes(NumSizes) {} 957 958 public: 959 /// Build a 'sizes' AST node. 960 /// 961 /// \param C Context of the AST. 962 /// \param StartLoc Location of the 'sizes' identifier. 963 /// \param LParenLoc Location of '('. 964 /// \param EndLoc Location of ')'. 965 /// \param Sizes Content of the clause. 966 static OMPSizesClause *Create(const ASTContext &C, SourceLocation StartLoc, 967 SourceLocation LParenLoc, SourceLocation EndLoc, 968 ArrayRef<Expr *> Sizes); 969 970 /// Build an empty 'sizes' AST node for deserialization. 971 /// 972 /// \param C Context of the AST. 973 /// \param NumSizes Number of items in the clause. 974 static OMPSizesClause *CreateEmpty(const ASTContext &C, unsigned NumSizes); 975 976 /// Sets the location of '('. 977 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 978 979 /// Returns the location of '('. 980 SourceLocation getLParenLoc() const { return LParenLoc; } 981 982 /// Returns the number of list items. 983 unsigned getNumSizes() const { return NumSizes; } 984 985 /// Returns the tile size expressions. 986 MutableArrayRef<Expr *> getSizesRefs() { 987 return MutableArrayRef<Expr *>(static_cast<OMPSizesClause *>(this) 988 ->template getTrailingObjects<Expr *>(), 989 NumSizes); 990 } 991 ArrayRef<Expr *> getSizesRefs() const { 992 return ArrayRef<Expr *>(static_cast<const OMPSizesClause *>(this) 993 ->template getTrailingObjects<Expr *>(), 994 NumSizes); 995 } 996 997 /// Sets the tile size expressions. 998 void setSizesRefs(ArrayRef<Expr *> VL) { 999 assert(VL.size() == NumSizes); 1000 std::copy(VL.begin(), VL.end(), 1001 static_cast<OMPSizesClause *>(this) 1002 ->template getTrailingObjects<Expr *>()); 1003 } 1004 1005 child_range children() { 1006 MutableArrayRef<Expr *> Sizes = getSizesRefs(); 1007 return child_range(reinterpret_cast<Stmt **>(Sizes.begin()), 1008 reinterpret_cast<Stmt **>(Sizes.end())); 1009 } 1010 const_child_range children() const { 1011 ArrayRef<Expr *> Sizes = getSizesRefs(); 1012 return const_child_range(reinterpret_cast<Stmt *const *>(Sizes.begin()), 1013 reinterpret_cast<Stmt *const *>(Sizes.end())); 1014 } 1015 1016 child_range used_children() { 1017 return child_range(child_iterator(), child_iterator()); 1018 } 1019 const_child_range used_children() const { 1020 return const_child_range(const_child_iterator(), const_child_iterator()); 1021 } 1022 1023 static bool classof(const OMPClause *T) { 1024 return T->getClauseKind() == llvm::omp::OMPC_sizes; 1025 } 1026 }; 1027 1028 /// This class represents the 'permutation' clause in the 1029 /// '#pragma omp interchange' directive. 1030 /// 1031 /// \code{.c} 1032 /// #pragma omp interchange permutation(2,1) 1033 /// for (int i = 0; i < 64; ++i) 1034 /// for (int j = 0; j < 64; ++j) 1035 /// \endcode 1036 class OMPPermutationClause final 1037 : public OMPClause, 1038 private llvm::TrailingObjects<OMPSizesClause, Expr *> { 1039 friend class OMPClauseReader; 1040 friend class llvm::TrailingObjects<OMPSizesClause, Expr *>; 1041 1042 /// Location of '('. 1043 SourceLocation LParenLoc; 1044 1045 /// Number of arguments in the clause, and hence also the number of loops to 1046 /// be permuted. 1047 unsigned NumLoops; 1048 1049 /// Sets the permutation index expressions. 1050 void setArgRefs(ArrayRef<Expr *> VL) { 1051 assert(VL.size() == NumLoops && "Expecting one expression per loop"); 1052 llvm::copy(VL, static_cast<OMPPermutationClause *>(this) 1053 ->template getTrailingObjects<Expr *>()); 1054 } 1055 1056 /// Build an empty clause. 1057 explicit OMPPermutationClause(int NumLoops) 1058 : OMPClause(llvm::omp::OMPC_permutation, SourceLocation(), 1059 SourceLocation()), 1060 NumLoops(NumLoops) {} 1061 1062 public: 1063 /// Build a 'permutation' clause AST node. 1064 /// 1065 /// \param C Context of the AST. 1066 /// \param StartLoc Location of the 'permutation' identifier. 1067 /// \param LParenLoc Location of '('. 1068 /// \param EndLoc Location of ')'. 1069 /// \param Args Content of the clause. 1070 static OMPPermutationClause * 1071 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 1072 SourceLocation EndLoc, ArrayRef<Expr *> Args); 1073 1074 /// Build an empty 'permutation' AST node for deserialization. 1075 /// 1076 /// \param C Context of the AST. 1077 /// \param NumLoops Number of arguments in the clause. 1078 static OMPPermutationClause *CreateEmpty(const ASTContext &C, 1079 unsigned NumLoops); 1080 1081 /// Sets the location of '('. 1082 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 1083 1084 /// Returns the location of '('. 1085 SourceLocation getLParenLoc() const { return LParenLoc; } 1086 1087 /// Returns the number of list items. 1088 unsigned getNumLoops() const { return NumLoops; } 1089 1090 /// Returns the permutation index expressions. 1091 ///@{ 1092 MutableArrayRef<Expr *> getArgsRefs() { 1093 return MutableArrayRef<Expr *>(static_cast<OMPPermutationClause *>(this) 1094 ->template getTrailingObjects<Expr *>(), 1095 NumLoops); 1096 } 1097 ArrayRef<Expr *> getArgsRefs() const { 1098 return ArrayRef<Expr *>(static_cast<const OMPPermutationClause *>(this) 1099 ->template getTrailingObjects<Expr *>(), 1100 NumLoops); 1101 } 1102 ///@} 1103 1104 child_range children() { 1105 MutableArrayRef<Expr *> Args = getArgsRefs(); 1106 return child_range(reinterpret_cast<Stmt **>(Args.begin()), 1107 reinterpret_cast<Stmt **>(Args.end())); 1108 } 1109 const_child_range children() const { 1110 ArrayRef<Expr *> Args = getArgsRefs(); 1111 return const_child_range(reinterpret_cast<Stmt *const *>(Args.begin()), 1112 reinterpret_cast<Stmt *const *>(Args.end())); 1113 } 1114 1115 child_range used_children() { 1116 return child_range(child_iterator(), child_iterator()); 1117 } 1118 const_child_range used_children() const { 1119 return const_child_range(const_child_iterator(), const_child_iterator()); 1120 } 1121 1122 static bool classof(const OMPClause *T) { 1123 return T->getClauseKind() == llvm::omp::OMPC_permutation; 1124 } 1125 }; 1126 1127 /// Representation of the 'full' clause of the '#pragma omp unroll' directive. 1128 /// 1129 /// \code 1130 /// #pragma omp unroll full 1131 /// for (int i = 0; i < 64; ++i) 1132 /// \endcode 1133 class OMPFullClause final : public OMPNoChildClause<llvm::omp::OMPC_full> { 1134 friend class OMPClauseReader; 1135 1136 /// Build an empty clause. 1137 explicit OMPFullClause() : OMPNoChildClause() {} 1138 1139 public: 1140 /// Build an AST node for a 'full' clause. 1141 /// 1142 /// \param C Context of the AST. 1143 /// \param StartLoc Starting location of the clause. 1144 /// \param EndLoc Ending location of the clause. 1145 static OMPFullClause *Create(const ASTContext &C, SourceLocation StartLoc, 1146 SourceLocation EndLoc); 1147 1148 /// Build an empty 'full' AST node for deserialization. 1149 /// 1150 /// \param C Context of the AST. 1151 static OMPFullClause *CreateEmpty(const ASTContext &C); 1152 }; 1153 1154 /// Representation of the 'partial' clause of the '#pragma omp unroll' 1155 /// directive. 1156 /// 1157 /// \code 1158 /// #pragma omp unroll partial(4) 1159 /// for (int i = start; i < end; ++i) 1160 /// \endcode 1161 class OMPPartialClause final : public OMPClause { 1162 friend class OMPClauseReader; 1163 1164 /// Location of '('. 1165 SourceLocation LParenLoc; 1166 1167 /// Optional argument to the clause (unroll factor). 1168 Stmt *Factor; 1169 1170 /// Build an empty clause. 1171 explicit OMPPartialClause() : OMPClause(llvm::omp::OMPC_partial, {}, {}) {} 1172 1173 /// Set the unroll factor. 1174 void setFactor(Expr *E) { Factor = E; } 1175 1176 /// Sets the location of '('. 1177 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 1178 1179 public: 1180 /// Build an AST node for a 'partial' clause. 1181 /// 1182 /// \param C Context of the AST. 1183 /// \param StartLoc Location of the 'partial' identifier. 1184 /// \param LParenLoc Location of '('. 1185 /// \param EndLoc Location of ')'. 1186 /// \param Factor Clause argument. 1187 static OMPPartialClause *Create(const ASTContext &C, SourceLocation StartLoc, 1188 SourceLocation LParenLoc, 1189 SourceLocation EndLoc, Expr *Factor); 1190 1191 /// Build an empty 'partial' AST node for deserialization. 1192 /// 1193 /// \param C Context of the AST. 1194 static OMPPartialClause *CreateEmpty(const ASTContext &C); 1195 1196 /// Returns the location of '('. 1197 SourceLocation getLParenLoc() const { return LParenLoc; } 1198 1199 /// Returns the argument of the clause or nullptr if not set. 1200 Expr *getFactor() const { return cast_or_null<Expr>(Factor); } 1201 1202 child_range children() { return child_range(&Factor, &Factor + 1); } 1203 const_child_range children() const { 1204 return const_child_range(&Factor, &Factor + 1); 1205 } 1206 1207 child_range used_children() { 1208 return child_range(child_iterator(), child_iterator()); 1209 } 1210 const_child_range used_children() const { 1211 return const_child_range(const_child_iterator(), const_child_iterator()); 1212 } 1213 1214 static bool classof(const OMPClause *T) { 1215 return T->getClauseKind() == llvm::omp::OMPC_partial; 1216 } 1217 }; 1218 1219 /// This represents 'collapse' clause in the '#pragma omp ...' 1220 /// directive. 1221 /// 1222 /// \code 1223 /// #pragma omp simd collapse(3) 1224 /// \endcode 1225 /// In this example directive '#pragma omp simd' has clause 'collapse' 1226 /// with single expression '3'. 1227 /// The parameter must be a constant positive integer expression, it specifies 1228 /// the number of nested loops that should be collapsed into a single iteration 1229 /// space. 1230 class OMPCollapseClause final 1231 : public OMPOneStmtClause<llvm::omp::OMPC_collapse, OMPClause> { 1232 friend class OMPClauseReader; 1233 1234 /// Set the number of associated for-loops. 1235 void setNumForLoops(Expr *Num) { setStmt(Num); } 1236 1237 public: 1238 /// Build 'collapse' clause. 1239 /// 1240 /// \param Num Expression associated with this clause. 1241 /// \param StartLoc Starting location of the clause. 1242 /// \param LParenLoc Location of '('. 1243 /// \param EndLoc Ending location of the clause. 1244 OMPCollapseClause(Expr *Num, SourceLocation StartLoc, 1245 SourceLocation LParenLoc, SourceLocation EndLoc) 1246 : OMPOneStmtClause(Num, StartLoc, LParenLoc, EndLoc) {} 1247 1248 /// Build an empty clause. 1249 explicit OMPCollapseClause() : OMPOneStmtClause() {} 1250 1251 /// Return the number of associated for-loops. 1252 Expr *getNumForLoops() const { return getStmtAs<Expr>(); } 1253 }; 1254 1255 /// This represents 'default' clause in the '#pragma omp ...' directive. 1256 /// 1257 /// \code 1258 /// #pragma omp parallel default(shared) 1259 /// \endcode 1260 /// In this example directive '#pragma omp parallel' has simple 'default' 1261 /// clause with kind 'shared'. 1262 class OMPDefaultClause : public OMPClause { 1263 friend class OMPClauseReader; 1264 1265 /// Location of '('. 1266 SourceLocation LParenLoc; 1267 1268 /// A kind of the 'default' clause. 1269 llvm::omp::DefaultKind Kind = llvm::omp::OMP_DEFAULT_unknown; 1270 1271 /// Start location of the kind in source code. 1272 SourceLocation KindKwLoc; 1273 1274 /// Set kind of the clauses. 1275 /// 1276 /// \param K Argument of clause. 1277 void setDefaultKind(llvm::omp::DefaultKind K) { Kind = K; } 1278 1279 /// Set argument location. 1280 /// 1281 /// \param KLoc Argument location. 1282 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; } 1283 1284 public: 1285 /// Build 'default' clause with argument \a A ('none' or 'shared'). 1286 /// 1287 /// \param A Argument of the clause ('none' or 'shared'). 1288 /// \param ALoc Starting location of the argument. 1289 /// \param StartLoc Starting location of the clause. 1290 /// \param LParenLoc Location of '('. 1291 /// \param EndLoc Ending location of the clause. 1292 OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc, 1293 SourceLocation StartLoc, SourceLocation LParenLoc, 1294 SourceLocation EndLoc) 1295 : OMPClause(llvm::omp::OMPC_default, StartLoc, EndLoc), 1296 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {} 1297 1298 /// Build an empty clause. 1299 OMPDefaultClause() 1300 : OMPClause(llvm::omp::OMPC_default, SourceLocation(), SourceLocation()) { 1301 } 1302 1303 /// Sets the location of '('. 1304 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 1305 1306 /// Returns the location of '('. 1307 SourceLocation getLParenLoc() const { return LParenLoc; } 1308 1309 /// Returns kind of the clause. 1310 llvm::omp::DefaultKind getDefaultKind() const { return Kind; } 1311 1312 /// Returns location of clause kind. 1313 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; } 1314 1315 child_range children() { 1316 return child_range(child_iterator(), child_iterator()); 1317 } 1318 1319 const_child_range children() const { 1320 return const_child_range(const_child_iterator(), const_child_iterator()); 1321 } 1322 1323 child_range used_children() { 1324 return child_range(child_iterator(), child_iterator()); 1325 } 1326 const_child_range used_children() const { 1327 return const_child_range(const_child_iterator(), const_child_iterator()); 1328 } 1329 1330 static bool classof(const OMPClause *T) { 1331 return T->getClauseKind() == llvm::omp::OMPC_default; 1332 } 1333 }; 1334 1335 /// This represents 'proc_bind' clause in the '#pragma omp ...' 1336 /// directive. 1337 /// 1338 /// \code 1339 /// #pragma omp parallel proc_bind(master) 1340 /// \endcode 1341 /// In this example directive '#pragma omp parallel' has simple 'proc_bind' 1342 /// clause with kind 'master'. 1343 class OMPProcBindClause : public OMPClause { 1344 friend class OMPClauseReader; 1345 1346 /// Location of '('. 1347 SourceLocation LParenLoc; 1348 1349 /// A kind of the 'proc_bind' clause. 1350 llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown; 1351 1352 /// Start location of the kind in source code. 1353 SourceLocation KindKwLoc; 1354 1355 /// Set kind of the clause. 1356 /// 1357 /// \param K Kind of clause. 1358 void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; } 1359 1360 /// Set clause kind location. 1361 /// 1362 /// \param KLoc Kind location. 1363 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; } 1364 1365 public: 1366 /// Build 'proc_bind' clause with argument \a A ('master', 'close' or 1367 /// 'spread'). 1368 /// 1369 /// \param A Argument of the clause ('master', 'close' or 'spread'). 1370 /// \param ALoc Starting location of the argument. 1371 /// \param StartLoc Starting location of the clause. 1372 /// \param LParenLoc Location of '('. 1373 /// \param EndLoc Ending location of the clause. 1374 OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc, 1375 SourceLocation StartLoc, SourceLocation LParenLoc, 1376 SourceLocation EndLoc) 1377 : OMPClause(llvm::omp::OMPC_proc_bind, StartLoc, EndLoc), 1378 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {} 1379 1380 /// Build an empty clause. 1381 OMPProcBindClause() 1382 : OMPClause(llvm::omp::OMPC_proc_bind, SourceLocation(), 1383 SourceLocation()) {} 1384 1385 /// Sets the location of '('. 1386 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 1387 1388 /// Returns the location of '('. 1389 SourceLocation getLParenLoc() const { return LParenLoc; } 1390 1391 /// Returns kind of the clause. 1392 llvm::omp::ProcBindKind getProcBindKind() const { return Kind; } 1393 1394 /// Returns location of clause kind. 1395 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; } 1396 1397 child_range children() { 1398 return child_range(child_iterator(), child_iterator()); 1399 } 1400 1401 const_child_range children() const { 1402 return const_child_range(const_child_iterator(), const_child_iterator()); 1403 } 1404 1405 child_range used_children() { 1406 return child_range(child_iterator(), child_iterator()); 1407 } 1408 const_child_range used_children() const { 1409 return const_child_range(const_child_iterator(), const_child_iterator()); 1410 } 1411 1412 static bool classof(const OMPClause *T) { 1413 return T->getClauseKind() == llvm::omp::OMPC_proc_bind; 1414 } 1415 }; 1416 1417 /// This represents 'unified_address' clause in the '#pragma omp requires' 1418 /// directive. 1419 /// 1420 /// \code 1421 /// #pragma omp requires unified_address 1422 /// \endcode 1423 /// In this example directive '#pragma omp requires' has 'unified_address' 1424 /// clause. 1425 class OMPUnifiedAddressClause final 1426 : public OMPNoChildClause<llvm::omp::OMPC_unified_address> { 1427 public: 1428 friend class OMPClauseReader; 1429 /// Build 'unified_address' clause. 1430 /// 1431 /// \param StartLoc Starting location of the clause. 1432 /// \param EndLoc Ending location of the clause. 1433 OMPUnifiedAddressClause(SourceLocation StartLoc, SourceLocation EndLoc) 1434 : OMPNoChildClause(StartLoc, EndLoc) {} 1435 1436 /// Build an empty clause. 1437 OMPUnifiedAddressClause() : OMPNoChildClause() {} 1438 }; 1439 1440 /// This represents 'unified_shared_memory' clause in the '#pragma omp requires' 1441 /// directive. 1442 /// 1443 /// \code 1444 /// #pragma omp requires unified_shared_memory 1445 /// \endcode 1446 /// In this example directive '#pragma omp requires' has 'unified_shared_memory' 1447 /// clause. 1448 class OMPUnifiedSharedMemoryClause final : public OMPClause { 1449 public: 1450 friend class OMPClauseReader; 1451 /// Build 'unified_shared_memory' clause. 1452 /// 1453 /// \param StartLoc Starting location of the clause. 1454 /// \param EndLoc Ending location of the clause. 1455 OMPUnifiedSharedMemoryClause(SourceLocation StartLoc, SourceLocation EndLoc) 1456 : OMPClause(llvm::omp::OMPC_unified_shared_memory, StartLoc, EndLoc) {} 1457 1458 /// Build an empty clause. 1459 OMPUnifiedSharedMemoryClause() 1460 : OMPClause(llvm::omp::OMPC_unified_shared_memory, SourceLocation(), 1461 SourceLocation()) {} 1462 1463 child_range children() { 1464 return child_range(child_iterator(), child_iterator()); 1465 } 1466 1467 const_child_range children() const { 1468 return const_child_range(const_child_iterator(), const_child_iterator()); 1469 } 1470 1471 child_range used_children() { 1472 return child_range(child_iterator(), child_iterator()); 1473 } 1474 const_child_range used_children() const { 1475 return const_child_range(const_child_iterator(), const_child_iterator()); 1476 } 1477 1478 static bool classof(const OMPClause *T) { 1479 return T->getClauseKind() == llvm::omp::OMPC_unified_shared_memory; 1480 } 1481 }; 1482 1483 /// This represents 'reverse_offload' clause in the '#pragma omp requires' 1484 /// directive. 1485 /// 1486 /// \code 1487 /// #pragma omp requires reverse_offload 1488 /// \endcode 1489 /// In this example directive '#pragma omp requires' has 'reverse_offload' 1490 /// clause. 1491 class OMPReverseOffloadClause final : public OMPClause { 1492 public: 1493 friend class OMPClauseReader; 1494 /// Build 'reverse_offload' clause. 1495 /// 1496 /// \param StartLoc Starting location of the clause. 1497 /// \param EndLoc Ending location of the clause. 1498 OMPReverseOffloadClause(SourceLocation StartLoc, SourceLocation EndLoc) 1499 : OMPClause(llvm::omp::OMPC_reverse_offload, StartLoc, EndLoc) {} 1500 1501 /// Build an empty clause. 1502 OMPReverseOffloadClause() 1503 : OMPClause(llvm::omp::OMPC_reverse_offload, SourceLocation(), 1504 SourceLocation()) {} 1505 1506 child_range children() { 1507 return child_range(child_iterator(), child_iterator()); 1508 } 1509 1510 const_child_range children() const { 1511 return const_child_range(const_child_iterator(), const_child_iterator()); 1512 } 1513 1514 child_range used_children() { 1515 return child_range(child_iterator(), child_iterator()); 1516 } 1517 const_child_range used_children() const { 1518 return const_child_range(const_child_iterator(), const_child_iterator()); 1519 } 1520 1521 static bool classof(const OMPClause *T) { 1522 return T->getClauseKind() == llvm::omp::OMPC_reverse_offload; 1523 } 1524 }; 1525 1526 /// This represents 'dynamic_allocators' clause in the '#pragma omp requires' 1527 /// directive. 1528 /// 1529 /// \code 1530 /// #pragma omp requires dynamic_allocators 1531 /// \endcode 1532 /// In this example directive '#pragma omp requires' has 'dynamic_allocators' 1533 /// clause. 1534 class OMPDynamicAllocatorsClause final : public OMPClause { 1535 public: 1536 friend class OMPClauseReader; 1537 /// Build 'dynamic_allocators' clause. 1538 /// 1539 /// \param StartLoc Starting location of the clause. 1540 /// \param EndLoc Ending location of the clause. 1541 OMPDynamicAllocatorsClause(SourceLocation StartLoc, SourceLocation EndLoc) 1542 : OMPClause(llvm::omp::OMPC_dynamic_allocators, StartLoc, EndLoc) {} 1543 1544 /// Build an empty clause. 1545 OMPDynamicAllocatorsClause() 1546 : OMPClause(llvm::omp::OMPC_dynamic_allocators, SourceLocation(), 1547 SourceLocation()) {} 1548 1549 child_range children() { 1550 return child_range(child_iterator(), child_iterator()); 1551 } 1552 1553 const_child_range children() const { 1554 return const_child_range(const_child_iterator(), const_child_iterator()); 1555 } 1556 1557 child_range used_children() { 1558 return child_range(child_iterator(), child_iterator()); 1559 } 1560 const_child_range used_children() const { 1561 return const_child_range(const_child_iterator(), const_child_iterator()); 1562 } 1563 1564 static bool classof(const OMPClause *T) { 1565 return T->getClauseKind() == llvm::omp::OMPC_dynamic_allocators; 1566 } 1567 }; 1568 1569 /// This represents 'atomic_default_mem_order' clause in the '#pragma omp 1570 /// requires' directive. 1571 /// 1572 /// \code 1573 /// #pragma omp requires atomic_default_mem_order(seq_cst) 1574 /// \endcode 1575 /// In this example directive '#pragma omp requires' has simple 1576 /// atomic_default_mem_order' clause with kind 'seq_cst'. 1577 class OMPAtomicDefaultMemOrderClause final : public OMPClause { 1578 friend class OMPClauseReader; 1579 1580 /// Location of '(' 1581 SourceLocation LParenLoc; 1582 1583 /// A kind of the 'atomic_default_mem_order' clause. 1584 OpenMPAtomicDefaultMemOrderClauseKind Kind = 1585 OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown; 1586 1587 /// Start location of the kind in source code. 1588 SourceLocation KindKwLoc; 1589 1590 /// Set kind of the clause. 1591 /// 1592 /// \param K Kind of clause. 1593 void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) { 1594 Kind = K; 1595 } 1596 1597 /// Set clause kind location. 1598 /// 1599 /// \param KLoc Kind location. 1600 void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) { 1601 KindKwLoc = KLoc; 1602 } 1603 1604 public: 1605 /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst', 1606 /// 'acq_rel' or 'relaxed'). 1607 /// 1608 /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed'). 1609 /// \param ALoc Starting location of the argument. 1610 /// \param StartLoc Starting location of the clause. 1611 /// \param LParenLoc Location of '('. 1612 /// \param EndLoc Ending location of the clause. 1613 OMPAtomicDefaultMemOrderClause(OpenMPAtomicDefaultMemOrderClauseKind A, 1614 SourceLocation ALoc, SourceLocation StartLoc, 1615 SourceLocation LParenLoc, 1616 SourceLocation EndLoc) 1617 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, StartLoc, EndLoc), 1618 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {} 1619 1620 /// Build an empty clause. 1621 OMPAtomicDefaultMemOrderClause() 1622 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, SourceLocation(), 1623 SourceLocation()) {} 1624 1625 /// Sets the location of '('. 1626 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 1627 1628 /// Returns the locaiton of '('. 1629 SourceLocation getLParenLoc() const { return LParenLoc; } 1630 1631 /// Returns kind of the clause. 1632 OpenMPAtomicDefaultMemOrderClauseKind getAtomicDefaultMemOrderKind() const { 1633 return Kind; 1634 } 1635 1636 /// Returns location of clause kind. 1637 SourceLocation getAtomicDefaultMemOrderKindKwLoc() const { return KindKwLoc; } 1638 1639 child_range children() { 1640 return child_range(child_iterator(), child_iterator()); 1641 } 1642 1643 const_child_range children() const { 1644 return const_child_range(const_child_iterator(), const_child_iterator()); 1645 } 1646 1647 child_range used_children() { 1648 return child_range(child_iterator(), child_iterator()); 1649 } 1650 const_child_range used_children() const { 1651 return const_child_range(const_child_iterator(), const_child_iterator()); 1652 } 1653 1654 static bool classof(const OMPClause *T) { 1655 return T->getClauseKind() == llvm::omp::OMPC_atomic_default_mem_order; 1656 } 1657 }; 1658 1659 /// This represents 'at' clause in the '#pragma omp error' directive 1660 /// 1661 /// \code 1662 /// #pragma omp error at(compilation) 1663 /// \endcode 1664 /// In this example directive '#pragma omp error' has simple 1665 /// 'at' clause with kind 'complilation'. 1666 class OMPAtClause final : public OMPClause { 1667 friend class OMPClauseReader; 1668 1669 /// Location of '(' 1670 SourceLocation LParenLoc; 1671 1672 /// A kind of the 'at' clause. 1673 OpenMPAtClauseKind Kind = OMPC_AT_unknown; 1674 1675 /// Start location of the kind in source code. 1676 SourceLocation KindKwLoc; 1677 1678 /// Set kind of the clause. 1679 /// 1680 /// \param K Kind of clause. 1681 void setAtKind(OpenMPAtClauseKind K) { Kind = K; } 1682 1683 /// Set clause kind location. 1684 /// 1685 /// \param KLoc Kind location. 1686 void setAtKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; } 1687 1688 /// Sets the location of '('. 1689 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 1690 1691 public: 1692 /// Build 'at' clause with argument \a A ('compilation' or 'execution'). 1693 /// 1694 /// \param A Argument of the clause ('compilation' or 'execution'). 1695 /// \param ALoc Starting location of the argument. 1696 /// \param StartLoc Starting location of the clause. 1697 /// \param LParenLoc Location of '('. 1698 /// \param EndLoc Ending location of the clause. 1699 OMPAtClause(OpenMPAtClauseKind A, SourceLocation ALoc, 1700 SourceLocation StartLoc, SourceLocation LParenLoc, 1701 SourceLocation EndLoc) 1702 : OMPClause(llvm::omp::OMPC_at, StartLoc, EndLoc), LParenLoc(LParenLoc), 1703 Kind(A), KindKwLoc(ALoc) {} 1704 1705 /// Build an empty clause. 1706 OMPAtClause() 1707 : OMPClause(llvm::omp::OMPC_at, SourceLocation(), SourceLocation()) {} 1708 1709 /// Returns the locaiton of '('. 1710 SourceLocation getLParenLoc() const { return LParenLoc; } 1711 1712 /// Returns kind of the clause. 1713 OpenMPAtClauseKind getAtKind() const { return Kind; } 1714 1715 /// Returns location of clause kind. 1716 SourceLocation getAtKindKwLoc() const { return KindKwLoc; } 1717 1718 child_range children() { 1719 return child_range(child_iterator(), child_iterator()); 1720 } 1721 1722 const_child_range children() const { 1723 return const_child_range(const_child_iterator(), const_child_iterator()); 1724 } 1725 1726 child_range used_children() { 1727 return child_range(child_iterator(), child_iterator()); 1728 } 1729 const_child_range used_children() const { 1730 return const_child_range(const_child_iterator(), const_child_iterator()); 1731 } 1732 1733 static bool classof(const OMPClause *T) { 1734 return T->getClauseKind() == llvm::omp::OMPC_at; 1735 } 1736 }; 1737 1738 /// This represents 'severity' clause in the '#pragma omp error' directive 1739 /// 1740 /// \code 1741 /// #pragma omp error severity(fatal) 1742 /// \endcode 1743 /// In this example directive '#pragma omp error' has simple 1744 /// 'severity' clause with kind 'fatal'. 1745 class OMPSeverityClause final : public OMPClause { 1746 friend class OMPClauseReader; 1747 1748 /// Location of '(' 1749 SourceLocation LParenLoc; 1750 1751 /// A kind of the 'severity' clause. 1752 OpenMPSeverityClauseKind Kind = OMPC_SEVERITY_unknown; 1753 1754 /// Start location of the kind in source code. 1755 SourceLocation KindKwLoc; 1756 1757 /// Set kind of the clause. 1758 /// 1759 /// \param K Kind of clause. 1760 void setSeverityKind(OpenMPSeverityClauseKind K) { Kind = K; } 1761 1762 /// Set clause kind location. 1763 /// 1764 /// \param KLoc Kind location. 1765 void setSeverityKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; } 1766 1767 /// Sets the location of '('. 1768 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 1769 1770 public: 1771 /// Build 'severity' clause with argument \a A ('fatal' or 'warning'). 1772 /// 1773 /// \param A Argument of the clause ('fatal' or 'warning'). 1774 /// \param ALoc Starting location of the argument. 1775 /// \param StartLoc Starting location of the clause. 1776 /// \param LParenLoc Location of '('. 1777 /// \param EndLoc Ending location of the clause. 1778 OMPSeverityClause(OpenMPSeverityClauseKind A, SourceLocation ALoc, 1779 SourceLocation StartLoc, SourceLocation LParenLoc, 1780 SourceLocation EndLoc) 1781 : OMPClause(llvm::omp::OMPC_severity, StartLoc, EndLoc), 1782 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {} 1783 1784 /// Build an empty clause. 1785 OMPSeverityClause() 1786 : OMPClause(llvm::omp::OMPC_severity, SourceLocation(), 1787 SourceLocation()) {} 1788 1789 /// Returns the locaiton of '('. 1790 SourceLocation getLParenLoc() const { return LParenLoc; } 1791 1792 /// Returns kind of the clause. 1793 OpenMPSeverityClauseKind getSeverityKind() const { return Kind; } 1794 1795 /// Returns location of clause kind. 1796 SourceLocation getSeverityKindKwLoc() const { return KindKwLoc; } 1797 1798 child_range children() { 1799 return child_range(child_iterator(), child_iterator()); 1800 } 1801 1802 const_child_range children() const { 1803 return const_child_range(const_child_iterator(), const_child_iterator()); 1804 } 1805 1806 child_range used_children() { 1807 return child_range(child_iterator(), child_iterator()); 1808 } 1809 const_child_range used_children() const { 1810 return const_child_range(const_child_iterator(), const_child_iterator()); 1811 } 1812 1813 static bool classof(const OMPClause *T) { 1814 return T->getClauseKind() == llvm::omp::OMPC_severity; 1815 } 1816 }; 1817 1818 /// This represents 'message' clause in the '#pragma omp error' directive 1819 /// 1820 /// \code 1821 /// #pragma omp error message("GNU compiler required.") 1822 /// \endcode 1823 /// In this example directive '#pragma omp error' has simple 1824 /// 'message' clause with user error message of "GNU compiler required.". 1825 class OMPMessageClause final : public OMPClause { 1826 friend class OMPClauseReader; 1827 1828 /// Location of '(' 1829 SourceLocation LParenLoc; 1830 1831 // Expression of the 'message' clause. 1832 Stmt *MessageString = nullptr; 1833 1834 /// Set message string of the clause. 1835 void setMessageString(Expr *MS) { MessageString = MS; } 1836 1837 /// Sets the location of '('. 1838 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 1839 1840 public: 1841 /// Build 'message' clause with message string argument 1842 /// 1843 /// \param MS Argument of the clause (message string). 1844 /// \param StartLoc Starting location of the clause. 1845 /// \param LParenLoc Location of '('. 1846 /// \param EndLoc Ending location of the clause. 1847 OMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, 1848 SourceLocation EndLoc) 1849 : OMPClause(llvm::omp::OMPC_message, StartLoc, EndLoc), 1850 LParenLoc(LParenLoc), MessageString(MS) {} 1851 1852 /// Build an empty clause. 1853 OMPMessageClause() 1854 : OMPClause(llvm::omp::OMPC_message, SourceLocation(), SourceLocation()) { 1855 } 1856 1857 /// Returns the locaiton of '('. 1858 SourceLocation getLParenLoc() const { return LParenLoc; } 1859 1860 /// Returns message string of the clause. 1861 Expr *getMessageString() const { return cast_or_null<Expr>(MessageString); } 1862 1863 child_range children() { 1864 return child_range(&MessageString, &MessageString + 1); 1865 } 1866 1867 const_child_range children() const { 1868 return const_child_range(&MessageString, &MessageString + 1); 1869 } 1870 1871 child_range used_children() { 1872 return child_range(child_iterator(), child_iterator()); 1873 } 1874 1875 const_child_range used_children() const { 1876 return const_child_range(const_child_iterator(), const_child_iterator()); 1877 } 1878 1879 static bool classof(const OMPClause *T) { 1880 return T->getClauseKind() == llvm::omp::OMPC_message; 1881 } 1882 }; 1883 1884 /// This represents 'schedule' clause in the '#pragma omp ...' directive. 1885 /// 1886 /// \code 1887 /// #pragma omp for schedule(static, 3) 1888 /// \endcode 1889 /// In this example directive '#pragma omp for' has 'schedule' clause with 1890 /// arguments 'static' and '3'. 1891 class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit { 1892 friend class OMPClauseReader; 1893 1894 /// Location of '('. 1895 SourceLocation LParenLoc; 1896 1897 /// A kind of the 'schedule' clause. 1898 OpenMPScheduleClauseKind Kind = OMPC_SCHEDULE_unknown; 1899 1900 /// Modifiers for 'schedule' clause. 1901 enum {FIRST, SECOND, NUM_MODIFIERS}; 1902 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS]; 1903 1904 /// Locations of modifiers. 1905 SourceLocation ModifiersLoc[NUM_MODIFIERS]; 1906 1907 /// Start location of the schedule ind in source code. 1908 SourceLocation KindLoc; 1909 1910 /// Location of ',' (if any). 1911 SourceLocation CommaLoc; 1912 1913 /// Chunk size. 1914 Expr *ChunkSize = nullptr; 1915 1916 /// Set schedule kind. 1917 /// 1918 /// \param K Schedule kind. 1919 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; } 1920 1921 /// Set the first schedule modifier. 1922 /// 1923 /// \param M Schedule modifier. 1924 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) { 1925 Modifiers[FIRST] = M; 1926 } 1927 1928 /// Set the second schedule modifier. 1929 /// 1930 /// \param M Schedule modifier. 1931 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) { 1932 Modifiers[SECOND] = M; 1933 } 1934 1935 /// Set location of the first schedule modifier. 1936 void setFirstScheduleModifierLoc(SourceLocation Loc) { 1937 ModifiersLoc[FIRST] = Loc; 1938 } 1939 1940 /// Set location of the second schedule modifier. 1941 void setSecondScheduleModifierLoc(SourceLocation Loc) { 1942 ModifiersLoc[SECOND] = Loc; 1943 } 1944 1945 /// Set schedule modifier location. 1946 /// 1947 /// \param M Schedule modifier location. 1948 void setScheduleModifer(OpenMPScheduleClauseModifier M) { 1949 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown) 1950 Modifiers[FIRST] = M; 1951 else { 1952 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown); 1953 Modifiers[SECOND] = M; 1954 } 1955 } 1956 1957 /// Sets the location of '('. 1958 /// 1959 /// \param Loc Location of '('. 1960 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 1961 1962 /// Set schedule kind start location. 1963 /// 1964 /// \param KLoc Schedule kind location. 1965 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; } 1966 1967 /// Set location of ','. 1968 /// 1969 /// \param Loc Location of ','. 1970 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; } 1971 1972 /// Set chunk size. 1973 /// 1974 /// \param E Chunk size. 1975 void setChunkSize(Expr *E) { ChunkSize = E; } 1976 1977 public: 1978 /// Build 'schedule' clause with schedule kind \a Kind and chunk size 1979 /// expression \a ChunkSize. 1980 /// 1981 /// \param StartLoc Starting location of the clause. 1982 /// \param LParenLoc Location of '('. 1983 /// \param KLoc Starting location of the argument. 1984 /// \param CommaLoc Location of ','. 1985 /// \param EndLoc Ending location of the clause. 1986 /// \param Kind Schedule kind. 1987 /// \param ChunkSize Chunk size. 1988 /// \param HelperChunkSize Helper chunk size for combined directives. 1989 /// \param M1 The first modifier applied to 'schedule' clause. 1990 /// \param M1Loc Location of the first modifier 1991 /// \param M2 The second modifier applied to 'schedule' clause. 1992 /// \param M2Loc Location of the second modifier 1993 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc, 1994 SourceLocation KLoc, SourceLocation CommaLoc, 1995 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind, 1996 Expr *ChunkSize, Stmt *HelperChunkSize, 1997 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc, 1998 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc) 1999 : OMPClause(llvm::omp::OMPC_schedule, StartLoc, EndLoc), 2000 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind), 2001 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) { 2002 setPreInitStmt(HelperChunkSize); 2003 Modifiers[FIRST] = M1; 2004 Modifiers[SECOND] = M2; 2005 ModifiersLoc[FIRST] = M1Loc; 2006 ModifiersLoc[SECOND] = M2Loc; 2007 } 2008 2009 /// Build an empty clause. 2010 explicit OMPScheduleClause() 2011 : OMPClause(llvm::omp::OMPC_schedule, SourceLocation(), SourceLocation()), 2012 OMPClauseWithPreInit(this) { 2013 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown; 2014 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown; 2015 } 2016 2017 /// Get kind of the clause. 2018 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; } 2019 2020 /// Get the first modifier of the clause. 2021 OpenMPScheduleClauseModifier getFirstScheduleModifier() const { 2022 return Modifiers[FIRST]; 2023 } 2024 2025 /// Get the second modifier of the clause. 2026 OpenMPScheduleClauseModifier getSecondScheduleModifier() const { 2027 return Modifiers[SECOND]; 2028 } 2029 2030 /// Get location of '('. 2031 SourceLocation getLParenLoc() { return LParenLoc; } 2032 2033 /// Get kind location. 2034 SourceLocation getScheduleKindLoc() { return KindLoc; } 2035 2036 /// Get the first modifier location. 2037 SourceLocation getFirstScheduleModifierLoc() const { 2038 return ModifiersLoc[FIRST]; 2039 } 2040 2041 /// Get the second modifier location. 2042 SourceLocation getSecondScheduleModifierLoc() const { 2043 return ModifiersLoc[SECOND]; 2044 } 2045 2046 /// Get location of ','. 2047 SourceLocation getCommaLoc() { return CommaLoc; } 2048 2049 /// Get chunk size. 2050 Expr *getChunkSize() { return ChunkSize; } 2051 2052 /// Get chunk size. 2053 const Expr *getChunkSize() const { return ChunkSize; } 2054 2055 child_range children() { 2056 return child_range(reinterpret_cast<Stmt **>(&ChunkSize), 2057 reinterpret_cast<Stmt **>(&ChunkSize) + 1); 2058 } 2059 2060 const_child_range children() const { 2061 auto Children = const_cast<OMPScheduleClause *>(this)->children(); 2062 return const_child_range(Children.begin(), Children.end()); 2063 } 2064 2065 child_range used_children() { 2066 return child_range(child_iterator(), child_iterator()); 2067 } 2068 const_child_range used_children() const { 2069 return const_child_range(const_child_iterator(), const_child_iterator()); 2070 } 2071 2072 static bool classof(const OMPClause *T) { 2073 return T->getClauseKind() == llvm::omp::OMPC_schedule; 2074 } 2075 }; 2076 2077 /// This represents 'ordered' clause in the '#pragma omp ...' directive. 2078 /// 2079 /// \code 2080 /// #pragma omp for ordered (2) 2081 /// \endcode 2082 /// In this example directive '#pragma omp for' has 'ordered' clause with 2083 /// parameter 2. 2084 class OMPOrderedClause final 2085 : public OMPClause, 2086 private llvm::TrailingObjects<OMPOrderedClause, Expr *> { 2087 friend class OMPClauseReader; 2088 friend TrailingObjects; 2089 2090 /// Location of '('. 2091 SourceLocation LParenLoc; 2092 2093 /// Number of for-loops. 2094 Stmt *NumForLoops = nullptr; 2095 2096 /// Real number of loops. 2097 unsigned NumberOfLoops = 0; 2098 2099 /// Build 'ordered' clause. 2100 /// 2101 /// \param Num Expression, possibly associated with this clause. 2102 /// \param NumLoops Number of loops, associated with this clause. 2103 /// \param StartLoc Starting location of the clause. 2104 /// \param LParenLoc Location of '('. 2105 /// \param EndLoc Ending location of the clause. 2106 OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc, 2107 SourceLocation LParenLoc, SourceLocation EndLoc) 2108 : OMPClause(llvm::omp::OMPC_ordered, StartLoc, EndLoc), 2109 LParenLoc(LParenLoc), NumForLoops(Num), NumberOfLoops(NumLoops) {} 2110 2111 /// Build an empty clause. 2112 explicit OMPOrderedClause(unsigned NumLoops) 2113 : OMPClause(llvm::omp::OMPC_ordered, SourceLocation(), SourceLocation()), 2114 NumberOfLoops(NumLoops) {} 2115 2116 /// Set the number of associated for-loops. 2117 void setNumForLoops(Expr *Num) { NumForLoops = Num; } 2118 2119 public: 2120 /// Build 'ordered' clause. 2121 /// 2122 /// \param Num Expression, possibly associated with this clause. 2123 /// \param NumLoops Number of loops, associated with this clause. 2124 /// \param StartLoc Starting location of the clause. 2125 /// \param LParenLoc Location of '('. 2126 /// \param EndLoc Ending location of the clause. 2127 static OMPOrderedClause *Create(const ASTContext &C, Expr *Num, 2128 unsigned NumLoops, SourceLocation StartLoc, 2129 SourceLocation LParenLoc, 2130 SourceLocation EndLoc); 2131 2132 /// Build an empty clause. 2133 static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops); 2134 2135 /// Sets the location of '('. 2136 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 2137 2138 /// Returns the location of '('. 2139 SourceLocation getLParenLoc() const { return LParenLoc; } 2140 2141 /// Return the number of associated for-loops. 2142 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); } 2143 2144 /// Set number of iterations for the specified loop. 2145 void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations); 2146 /// Get number of iterations for all the loops. 2147 ArrayRef<Expr *> getLoopNumIterations() const; 2148 2149 /// Set loop counter for the specified loop. 2150 void setLoopCounter(unsigned NumLoop, Expr *Counter); 2151 /// Get loops counter for the specified loop. 2152 Expr *getLoopCounter(unsigned NumLoop); 2153 const Expr *getLoopCounter(unsigned NumLoop) const; 2154 2155 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); } 2156 2157 const_child_range children() const { 2158 return const_child_range(&NumForLoops, &NumForLoops + 1); 2159 } 2160 2161 child_range used_children() { 2162 return child_range(child_iterator(), child_iterator()); 2163 } 2164 const_child_range used_children() const { 2165 return const_child_range(const_child_iterator(), const_child_iterator()); 2166 } 2167 2168 static bool classof(const OMPClause *T) { 2169 return T->getClauseKind() == llvm::omp::OMPC_ordered; 2170 } 2171 }; 2172 2173 /// This represents 'nowait' clause in the '#pragma omp ...' directive. 2174 /// 2175 /// \code 2176 /// #pragma omp for nowait 2177 /// \endcode 2178 /// In this example directive '#pragma omp for' has 'nowait' clause. 2179 class OMPNowaitClause final : public OMPNoChildClause<llvm::omp::OMPC_nowait> { 2180 public: 2181 /// Build 'nowait' clause. 2182 /// 2183 /// \param StartLoc Starting location of the clause. 2184 /// \param EndLoc Ending location of the clause. 2185 OMPNowaitClause(SourceLocation StartLoc = SourceLocation(), 2186 SourceLocation EndLoc = SourceLocation()) 2187 : OMPNoChildClause(StartLoc, EndLoc) {} 2188 }; 2189 2190 /// This represents 'untied' clause in the '#pragma omp ...' directive. 2191 /// 2192 /// \code 2193 /// #pragma omp task untied 2194 /// \endcode 2195 /// In this example directive '#pragma omp task' has 'untied' clause. 2196 class OMPUntiedClause : public OMPClause { 2197 public: 2198 /// Build 'untied' clause. 2199 /// 2200 /// \param StartLoc Starting location of the clause. 2201 /// \param EndLoc Ending location of the clause. 2202 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc) 2203 : OMPClause(llvm::omp::OMPC_untied, StartLoc, EndLoc) {} 2204 2205 /// Build an empty clause. 2206 OMPUntiedClause() 2207 : OMPClause(llvm::omp::OMPC_untied, SourceLocation(), SourceLocation()) {} 2208 2209 child_range children() { 2210 return child_range(child_iterator(), child_iterator()); 2211 } 2212 2213 const_child_range children() const { 2214 return const_child_range(const_child_iterator(), const_child_iterator()); 2215 } 2216 2217 child_range used_children() { 2218 return child_range(child_iterator(), child_iterator()); 2219 } 2220 const_child_range used_children() const { 2221 return const_child_range(const_child_iterator(), const_child_iterator()); 2222 } 2223 2224 static bool classof(const OMPClause *T) { 2225 return T->getClauseKind() == llvm::omp::OMPC_untied; 2226 } 2227 }; 2228 2229 /// This represents 'mergeable' clause in the '#pragma omp ...' 2230 /// directive. 2231 /// 2232 /// \code 2233 /// #pragma omp task mergeable 2234 /// \endcode 2235 /// In this example directive '#pragma omp task' has 'mergeable' clause. 2236 class OMPMergeableClause : public OMPClause { 2237 public: 2238 /// Build 'mergeable' clause. 2239 /// 2240 /// \param StartLoc Starting location of the clause. 2241 /// \param EndLoc Ending location of the clause. 2242 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc) 2243 : OMPClause(llvm::omp::OMPC_mergeable, StartLoc, EndLoc) {} 2244 2245 /// Build an empty clause. 2246 OMPMergeableClause() 2247 : OMPClause(llvm::omp::OMPC_mergeable, SourceLocation(), 2248 SourceLocation()) {} 2249 2250 child_range children() { 2251 return child_range(child_iterator(), child_iterator()); 2252 } 2253 2254 const_child_range children() const { 2255 return const_child_range(const_child_iterator(), const_child_iterator()); 2256 } 2257 2258 child_range used_children() { 2259 return child_range(child_iterator(), child_iterator()); 2260 } 2261 const_child_range used_children() const { 2262 return const_child_range(const_child_iterator(), const_child_iterator()); 2263 } 2264 2265 static bool classof(const OMPClause *T) { 2266 return T->getClauseKind() == llvm::omp::OMPC_mergeable; 2267 } 2268 }; 2269 2270 /// This represents the 'absent' clause in the '#pragma omp assume' 2271 /// directive. 2272 /// 2273 /// \code 2274 /// #pragma omp assume absent(<directive-name list>) 2275 /// \endcode 2276 /// In this example directive '#pragma omp assume' has an 'absent' clause. 2277 class OMPAbsentClause final 2278 : public OMPDirectiveListClause<OMPAbsentClause>, 2279 private llvm::TrailingObjects<OMPAbsentClause, OpenMPDirectiveKind> { 2280 friend OMPDirectiveListClause; 2281 friend TrailingObjects; 2282 2283 /// Build 'absent' clause. 2284 /// 2285 /// \param StartLoc Starting location of the clause. 2286 /// \param LParenLoc Location of '('. 2287 /// \param EndLoc Ending location of the clause. 2288 /// \param NumKinds Number of directive kinds listed in the clause. 2289 OMPAbsentClause(SourceLocation StartLoc, SourceLocation LParenLoc, 2290 SourceLocation EndLoc, unsigned NumKinds) 2291 : OMPDirectiveListClause<OMPAbsentClause>( 2292 llvm::omp::OMPC_absent, StartLoc, LParenLoc, EndLoc, NumKinds) {} 2293 2294 /// Build an empty clause. 2295 OMPAbsentClause(unsigned NumKinds) 2296 : OMPDirectiveListClause<OMPAbsentClause>( 2297 llvm::omp::OMPC_absent, SourceLocation(), SourceLocation(), 2298 SourceLocation(), NumKinds) {} 2299 2300 public: 2301 static OMPAbsentClause *Create(const ASTContext &C, 2302 ArrayRef<OpenMPDirectiveKind> DKVec, 2303 SourceLocation Loc, SourceLocation LLoc, 2304 SourceLocation RLoc); 2305 2306 static OMPAbsentClause *CreateEmpty(const ASTContext &C, unsigned NumKinds); 2307 2308 static bool classof(const OMPClause *C) { 2309 return C->getClauseKind() == llvm::omp::OMPC_absent; 2310 } 2311 }; 2312 2313 /// This represents the 'contains' clause in the '#pragma omp assume' 2314 /// directive. 2315 /// 2316 /// \code 2317 /// #pragma omp assume contains(<directive-name list>) 2318 /// \endcode 2319 /// In this example directive '#pragma omp assume' has a 'contains' clause. 2320 class OMPContainsClause final 2321 : public OMPDirectiveListClause<OMPContainsClause>, 2322 private llvm::TrailingObjects<OMPContainsClause, OpenMPDirectiveKind> { 2323 friend OMPDirectiveListClause; 2324 friend TrailingObjects; 2325 2326 /// Build 'contains' clause. 2327 /// 2328 /// \param StartLoc Starting location of the clause. 2329 /// \param LParenLoc Location of '('. 2330 /// \param EndLoc Ending location of the clause. 2331 /// \param NumKinds Number of directive kinds listed in the clause. 2332 OMPContainsClause(SourceLocation StartLoc, SourceLocation LParenLoc, 2333 SourceLocation EndLoc, unsigned NumKinds) 2334 : OMPDirectiveListClause<OMPContainsClause>( 2335 llvm::omp::OMPC_contains, StartLoc, LParenLoc, EndLoc, NumKinds) {} 2336 2337 /// Build an empty clause. 2338 OMPContainsClause(unsigned NumKinds) 2339 : OMPDirectiveListClause<OMPContainsClause>( 2340 llvm::omp::OMPC_contains, SourceLocation(), SourceLocation(), 2341 SourceLocation(), NumKinds) {} 2342 2343 public: 2344 static OMPContainsClause *Create(const ASTContext &C, 2345 ArrayRef<OpenMPDirectiveKind> DKVec, 2346 SourceLocation Loc, SourceLocation LLoc, 2347 SourceLocation RLoc); 2348 2349 static OMPContainsClause *CreateEmpty(const ASTContext &C, unsigned NumKinds); 2350 2351 static bool classof(const OMPClause *C) { 2352 return C->getClauseKind() == llvm::omp::OMPC_contains; 2353 } 2354 }; 2355 2356 /// This represents the 'holds' clause in the '#pragma omp assume' 2357 /// directive. 2358 /// 2359 /// \code 2360 /// #pragma omp assume holds(<expr>) 2361 /// \endcode 2362 /// In this example directive '#pragma omp assume' has a 'holds' clause. 2363 class OMPHoldsClause final 2364 : public OMPOneStmtClause<llvm::omp::OMPC_holds, OMPClause> { 2365 friend class OMPClauseReader; 2366 2367 public: 2368 /// Build 'holds' clause. 2369 /// 2370 /// \param StartLoc Starting location of the clause. 2371 /// \param EndLoc Ending location of the clause. 2372 OMPHoldsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc, 2373 SourceLocation EndLoc) 2374 : OMPOneStmtClause(E, StartLoc, LParenLoc, EndLoc) {} 2375 2376 /// Build an empty clause. 2377 OMPHoldsClause() : OMPOneStmtClause() {} 2378 2379 Expr *getExpr() const { return getStmtAs<Expr>(); } 2380 void setExpr(Expr *E) { setStmt(E); } 2381 }; 2382 2383 /// This represents the 'no_openmp' clause in the '#pragma omp assume' 2384 /// directive. 2385 /// 2386 /// \code 2387 /// #pragma omp assume no_openmp 2388 /// \endcode 2389 /// In this example directive '#pragma omp assume' has a 'no_openmp' clause. 2390 class OMPNoOpenMPClause final 2391 : public OMPNoChildClause<llvm::omp::OMPC_no_openmp> { 2392 public: 2393 /// Build 'no_openmp' clause. 2394 /// 2395 /// \param StartLoc Starting location of the clause. 2396 /// \param EndLoc Ending location of the clause. 2397 OMPNoOpenMPClause(SourceLocation StartLoc, SourceLocation EndLoc) 2398 : OMPNoChildClause(StartLoc, EndLoc) {} 2399 2400 /// Build an empty clause. 2401 OMPNoOpenMPClause() : OMPNoChildClause() {} 2402 }; 2403 2404 /// This represents the 'no_openmp_routines' clause in the '#pragma omp assume' 2405 /// directive. 2406 /// 2407 /// \code 2408 /// #pragma omp assume no_openmp_routines 2409 /// \endcode 2410 /// In this example directive '#pragma omp assume' has a 'no_openmp_routines' 2411 /// clause. 2412 class OMPNoOpenMPRoutinesClause final 2413 : public OMPNoChildClause<llvm::omp::OMPC_no_openmp_routines> { 2414 public: 2415 /// Build 'no_openmp_routines' clause. 2416 /// 2417 /// \param StartLoc Starting location of the clause. 2418 /// \param EndLoc Ending location of the clause. 2419 OMPNoOpenMPRoutinesClause(SourceLocation StartLoc, SourceLocation EndLoc) 2420 : OMPNoChildClause(StartLoc, EndLoc) {} 2421 2422 /// Build an empty clause. 2423 OMPNoOpenMPRoutinesClause() : OMPNoChildClause() {} 2424 }; 2425 2426 /// This represents the 'no_parallelism' clause in the '#pragma omp assume' 2427 /// directive. 2428 /// 2429 /// \code 2430 /// #pragma omp assume no_parallelism 2431 /// \endcode 2432 /// In this example directive '#pragma omp assume' has a 'no_parallelism' 2433 /// clause. 2434 class OMPNoParallelismClause final 2435 : public OMPNoChildClause<llvm::omp::OMPC_no_parallelism> { 2436 public: 2437 /// Build 'no_parallelism' clause. 2438 /// 2439 /// \param StartLoc Starting location of the clause. 2440 /// \param EndLoc Ending location of the clause. 2441 OMPNoParallelismClause(SourceLocation StartLoc, SourceLocation EndLoc) 2442 : OMPNoChildClause(StartLoc, EndLoc) {} 2443 2444 /// Build an empty clause. 2445 OMPNoParallelismClause() : OMPNoChildClause() {} 2446 }; 2447 2448 /// This represents 'read' clause in the '#pragma omp atomic' directive. 2449 /// 2450 /// \code 2451 /// #pragma omp atomic read 2452 /// \endcode 2453 /// In this example directive '#pragma omp atomic' has 'read' clause. 2454 class OMPReadClause : public OMPClause { 2455 public: 2456 /// Build 'read' clause. 2457 /// 2458 /// \param StartLoc Starting location of the clause. 2459 /// \param EndLoc Ending location of the clause. 2460 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc) 2461 : OMPClause(llvm::omp::OMPC_read, StartLoc, EndLoc) {} 2462 2463 /// Build an empty clause. 2464 OMPReadClause() 2465 : OMPClause(llvm::omp::OMPC_read, SourceLocation(), SourceLocation()) {} 2466 2467 child_range children() { 2468 return child_range(child_iterator(), child_iterator()); 2469 } 2470 2471 const_child_range children() const { 2472 return const_child_range(const_child_iterator(), const_child_iterator()); 2473 } 2474 2475 child_range used_children() { 2476 return child_range(child_iterator(), child_iterator()); 2477 } 2478 const_child_range used_children() const { 2479 return const_child_range(const_child_iterator(), const_child_iterator()); 2480 } 2481 2482 static bool classof(const OMPClause *T) { 2483 return T->getClauseKind() == llvm::omp::OMPC_read; 2484 } 2485 }; 2486 2487 /// This represents 'write' clause in the '#pragma omp atomic' directive. 2488 /// 2489 /// \code 2490 /// #pragma omp atomic write 2491 /// \endcode 2492 /// In this example directive '#pragma omp atomic' has 'write' clause. 2493 class OMPWriteClause : public OMPClause { 2494 public: 2495 /// Build 'write' clause. 2496 /// 2497 /// \param StartLoc Starting location of the clause. 2498 /// \param EndLoc Ending location of the clause. 2499 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc) 2500 : OMPClause(llvm::omp::OMPC_write, StartLoc, EndLoc) {} 2501 2502 /// Build an empty clause. 2503 OMPWriteClause() 2504 : OMPClause(llvm::omp::OMPC_write, SourceLocation(), SourceLocation()) {} 2505 2506 child_range children() { 2507 return child_range(child_iterator(), child_iterator()); 2508 } 2509 2510 const_child_range children() const { 2511 return const_child_range(const_child_iterator(), const_child_iterator()); 2512 } 2513 2514 child_range used_children() { 2515 return child_range(child_iterator(), child_iterator()); 2516 } 2517 const_child_range used_children() const { 2518 return const_child_range(const_child_iterator(), const_child_iterator()); 2519 } 2520 2521 static bool classof(const OMPClause *T) { 2522 return T->getClauseKind() == llvm::omp::OMPC_write; 2523 } 2524 }; 2525 2526 /// This represents 'update' clause in the '#pragma omp atomic' 2527 /// directive. 2528 /// 2529 /// \code 2530 /// #pragma omp atomic update 2531 /// \endcode 2532 /// In this example directive '#pragma omp atomic' has 'update' clause. 2533 /// Also, this class represents 'update' clause in '#pragma omp depobj' 2534 /// directive. 2535 /// 2536 /// \code 2537 /// #pragma omp depobj(a) update(in) 2538 /// \endcode 2539 /// In this example directive '#pragma omp depobj' has 'update' clause with 'in' 2540 /// dependence kind. 2541 class OMPUpdateClause final 2542 : public OMPClause, 2543 private llvm::TrailingObjects<OMPUpdateClause, SourceLocation, 2544 OpenMPDependClauseKind> { 2545 friend class OMPClauseReader; 2546 friend TrailingObjects; 2547 2548 /// true if extended version of the clause for 'depobj' directive. 2549 bool IsExtended = false; 2550 2551 /// Define the sizes of each trailing object array except the last one. This 2552 /// is required for TrailingObjects to work properly. 2553 size_t numTrailingObjects(OverloadToken<SourceLocation>) const { 2554 // 2 locations: for '(' and argument location. 2555 return IsExtended ? 2 : 0; 2556 } 2557 2558 /// Sets the location of '(' in clause for 'depobj' directive. 2559 void setLParenLoc(SourceLocation Loc) { 2560 assert(IsExtended && "Expected extended clause."); 2561 *getTrailingObjects<SourceLocation>() = Loc; 2562 } 2563 2564 /// Sets the location of '(' in clause for 'depobj' directive. 2565 void setArgumentLoc(SourceLocation Loc) { 2566 assert(IsExtended && "Expected extended clause."); 2567 *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc; 2568 } 2569 2570 /// Sets the dependence kind for the clause for 'depobj' directive. 2571 void setDependencyKind(OpenMPDependClauseKind DK) { 2572 assert(IsExtended && "Expected extended clause."); 2573 *getTrailingObjects<OpenMPDependClauseKind>() = DK; 2574 } 2575 2576 /// Build 'update' clause. 2577 /// 2578 /// \param StartLoc Starting location of the clause. 2579 /// \param EndLoc Ending location of the clause. 2580 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc, 2581 bool IsExtended) 2582 : OMPClause(llvm::omp::OMPC_update, StartLoc, EndLoc), 2583 IsExtended(IsExtended) {} 2584 2585 /// Build an empty clause. 2586 OMPUpdateClause(bool IsExtended) 2587 : OMPClause(llvm::omp::OMPC_update, SourceLocation(), SourceLocation()), 2588 IsExtended(IsExtended) {} 2589 2590 public: 2591 /// Creates clause for 'atomic' directive. 2592 /// 2593 /// \param C AST context. 2594 /// \param StartLoc Starting location of the clause. 2595 /// \param EndLoc Ending location of the clause. 2596 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc, 2597 SourceLocation EndLoc); 2598 2599 /// Creates clause for 'depobj' directive. 2600 /// 2601 /// \param C AST context. 2602 /// \param StartLoc Starting location of the clause. 2603 /// \param LParenLoc Location of '('. 2604 /// \param ArgumentLoc Location of the argument. 2605 /// \param DK Dependence kind. 2606 /// \param EndLoc Ending location of the clause. 2607 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc, 2608 SourceLocation LParenLoc, 2609 SourceLocation ArgumentLoc, 2610 OpenMPDependClauseKind DK, 2611 SourceLocation EndLoc); 2612 2613 /// Creates an empty clause with the place for \a N variables. 2614 /// 2615 /// \param C AST context. 2616 /// \param IsExtended true if extended clause for 'depobj' directive must be 2617 /// created. 2618 static OMPUpdateClause *CreateEmpty(const ASTContext &C, bool IsExtended); 2619 2620 /// Checks if the clause is the extended clauses for 'depobj' directive. 2621 bool isExtended() const { return IsExtended; } 2622 2623 child_range children() { 2624 return child_range(child_iterator(), child_iterator()); 2625 } 2626 2627 const_child_range children() const { 2628 return const_child_range(const_child_iterator(), const_child_iterator()); 2629 } 2630 2631 child_range used_children() { 2632 return child_range(child_iterator(), child_iterator()); 2633 } 2634 const_child_range used_children() const { 2635 return const_child_range(const_child_iterator(), const_child_iterator()); 2636 } 2637 2638 /// Gets the location of '(' in clause for 'depobj' directive. 2639 SourceLocation getLParenLoc() const { 2640 assert(IsExtended && "Expected extended clause."); 2641 return *getTrailingObjects<SourceLocation>(); 2642 } 2643 2644 /// Gets the location of argument in clause for 'depobj' directive. 2645 SourceLocation getArgumentLoc() const { 2646 assert(IsExtended && "Expected extended clause."); 2647 return *std::next(getTrailingObjects<SourceLocation>(), 1); 2648 } 2649 2650 /// Gets the dependence kind in clause for 'depobj' directive. 2651 OpenMPDependClauseKind getDependencyKind() const { 2652 assert(IsExtended && "Expected extended clause."); 2653 return *getTrailingObjects<OpenMPDependClauseKind>(); 2654 } 2655 2656 static bool classof(const OMPClause *T) { 2657 return T->getClauseKind() == llvm::omp::OMPC_update; 2658 } 2659 }; 2660 2661 /// This represents 'capture' clause in the '#pragma omp atomic' 2662 /// directive. 2663 /// 2664 /// \code 2665 /// #pragma omp atomic capture 2666 /// \endcode 2667 /// In this example directive '#pragma omp atomic' has 'capture' clause. 2668 class OMPCaptureClause : public OMPClause { 2669 public: 2670 /// Build 'capture' clause. 2671 /// 2672 /// \param StartLoc Starting location of the clause. 2673 /// \param EndLoc Ending location of the clause. 2674 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc) 2675 : OMPClause(llvm::omp::OMPC_capture, StartLoc, EndLoc) {} 2676 2677 /// Build an empty clause. 2678 OMPCaptureClause() 2679 : OMPClause(llvm::omp::OMPC_capture, SourceLocation(), SourceLocation()) { 2680 } 2681 2682 child_range children() { 2683 return child_range(child_iterator(), child_iterator()); 2684 } 2685 2686 const_child_range children() const { 2687 return const_child_range(const_child_iterator(), const_child_iterator()); 2688 } 2689 2690 child_range used_children() { 2691 return child_range(child_iterator(), child_iterator()); 2692 } 2693 const_child_range used_children() const { 2694 return const_child_range(const_child_iterator(), const_child_iterator()); 2695 } 2696 2697 static bool classof(const OMPClause *T) { 2698 return T->getClauseKind() == llvm::omp::OMPC_capture; 2699 } 2700 }; 2701 2702 /// This represents 'compare' clause in the '#pragma omp atomic' 2703 /// directive. 2704 /// 2705 /// \code 2706 /// #pragma omp atomic compare 2707 /// \endcode 2708 /// In this example directive '#pragma omp atomic' has 'compare' clause. 2709 class OMPCompareClause final : public OMPClause { 2710 public: 2711 /// Build 'compare' clause. 2712 /// 2713 /// \param StartLoc Starting location of the clause. 2714 /// \param EndLoc Ending location of the clause. 2715 OMPCompareClause(SourceLocation StartLoc, SourceLocation EndLoc) 2716 : OMPClause(llvm::omp::OMPC_compare, StartLoc, EndLoc) {} 2717 2718 /// Build an empty clause. 2719 OMPCompareClause() 2720 : OMPClause(llvm::omp::OMPC_compare, SourceLocation(), SourceLocation()) { 2721 } 2722 2723 child_range children() { 2724 return child_range(child_iterator(), child_iterator()); 2725 } 2726 2727 const_child_range children() const { 2728 return const_child_range(const_child_iterator(), const_child_iterator()); 2729 } 2730 2731 child_range used_children() { 2732 return child_range(child_iterator(), child_iterator()); 2733 } 2734 const_child_range used_children() const { 2735 return const_child_range(const_child_iterator(), const_child_iterator()); 2736 } 2737 2738 static bool classof(const OMPClause *T) { 2739 return T->getClauseKind() == llvm::omp::OMPC_compare; 2740 } 2741 }; 2742 2743 /// This represents 'seq_cst' clause in the '#pragma omp atomic|flush' 2744 /// directives. 2745 /// 2746 /// \code 2747 /// #pragma omp atomic seq_cst 2748 /// \endcode 2749 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause. 2750 class OMPSeqCstClause : public OMPClause { 2751 public: 2752 /// Build 'seq_cst' clause. 2753 /// 2754 /// \param StartLoc Starting location of the clause. 2755 /// \param EndLoc Ending location of the clause. 2756 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc) 2757 : OMPClause(llvm::omp::OMPC_seq_cst, StartLoc, EndLoc) {} 2758 2759 /// Build an empty clause. 2760 OMPSeqCstClause() 2761 : OMPClause(llvm::omp::OMPC_seq_cst, SourceLocation(), SourceLocation()) { 2762 } 2763 2764 child_range children() { 2765 return child_range(child_iterator(), child_iterator()); 2766 } 2767 2768 const_child_range children() const { 2769 return const_child_range(const_child_iterator(), const_child_iterator()); 2770 } 2771 2772 child_range used_children() { 2773 return child_range(child_iterator(), child_iterator()); 2774 } 2775 const_child_range used_children() const { 2776 return const_child_range(const_child_iterator(), const_child_iterator()); 2777 } 2778 2779 static bool classof(const OMPClause *T) { 2780 return T->getClauseKind() == llvm::omp::OMPC_seq_cst; 2781 } 2782 }; 2783 2784 /// This represents 'acq_rel' clause in the '#pragma omp atomic|flush' 2785 /// directives. 2786 /// 2787 /// \code 2788 /// #pragma omp flush acq_rel 2789 /// \endcode 2790 /// In this example directive '#pragma omp flush' has 'acq_rel' clause. 2791 class OMPAcqRelClause final : public OMPClause { 2792 public: 2793 /// Build 'ack_rel' clause. 2794 /// 2795 /// \param StartLoc Starting location of the clause. 2796 /// \param EndLoc Ending location of the clause. 2797 OMPAcqRelClause(SourceLocation StartLoc, SourceLocation EndLoc) 2798 : OMPClause(llvm::omp::OMPC_acq_rel, StartLoc, EndLoc) {} 2799 2800 /// Build an empty clause. 2801 OMPAcqRelClause() 2802 : OMPClause(llvm::omp::OMPC_acq_rel, SourceLocation(), SourceLocation()) { 2803 } 2804 2805 child_range children() { 2806 return child_range(child_iterator(), child_iterator()); 2807 } 2808 2809 const_child_range children() const { 2810 return const_child_range(const_child_iterator(), const_child_iterator()); 2811 } 2812 2813 child_range used_children() { 2814 return child_range(child_iterator(), child_iterator()); 2815 } 2816 const_child_range used_children() const { 2817 return const_child_range(const_child_iterator(), const_child_iterator()); 2818 } 2819 2820 static bool classof(const OMPClause *T) { 2821 return T->getClauseKind() == llvm::omp::OMPC_acq_rel; 2822 } 2823 }; 2824 2825 /// This represents 'acquire' clause in the '#pragma omp atomic|flush' 2826 /// directives. 2827 /// 2828 /// \code 2829 /// #pragma omp flush acquire 2830 /// \endcode 2831 /// In this example directive '#pragma omp flush' has 'acquire' clause. 2832 class OMPAcquireClause final : public OMPClause { 2833 public: 2834 /// Build 'acquire' clause. 2835 /// 2836 /// \param StartLoc Starting location of the clause. 2837 /// \param EndLoc Ending location of the clause. 2838 OMPAcquireClause(SourceLocation StartLoc, SourceLocation EndLoc) 2839 : OMPClause(llvm::omp::OMPC_acquire, StartLoc, EndLoc) {} 2840 2841 /// Build an empty clause. 2842 OMPAcquireClause() 2843 : OMPClause(llvm::omp::OMPC_acquire, SourceLocation(), SourceLocation()) { 2844 } 2845 2846 child_range children() { 2847 return child_range(child_iterator(), child_iterator()); 2848 } 2849 2850 const_child_range children() const { 2851 return const_child_range(const_child_iterator(), const_child_iterator()); 2852 } 2853 2854 child_range used_children() { 2855 return child_range(child_iterator(), child_iterator()); 2856 } 2857 const_child_range used_children() const { 2858 return const_child_range(const_child_iterator(), const_child_iterator()); 2859 } 2860 2861 static bool classof(const OMPClause *T) { 2862 return T->getClauseKind() == llvm::omp::OMPC_acquire; 2863 } 2864 }; 2865 2866 /// This represents 'release' clause in the '#pragma omp atomic|flush' 2867 /// directives. 2868 /// 2869 /// \code 2870 /// #pragma omp flush release 2871 /// \endcode 2872 /// In this example directive '#pragma omp flush' has 'release' clause. 2873 class OMPReleaseClause final : public OMPClause { 2874 public: 2875 /// Build 'release' clause. 2876 /// 2877 /// \param StartLoc Starting location of the clause. 2878 /// \param EndLoc Ending location of the clause. 2879 OMPReleaseClause(SourceLocation StartLoc, SourceLocation EndLoc) 2880 : OMPClause(llvm::omp::OMPC_release, StartLoc, EndLoc) {} 2881 2882 /// Build an empty clause. 2883 OMPReleaseClause() 2884 : OMPClause(llvm::omp::OMPC_release, SourceLocation(), SourceLocation()) { 2885 } 2886 2887 child_range children() { 2888 return child_range(child_iterator(), child_iterator()); 2889 } 2890 2891 const_child_range children() const { 2892 return const_child_range(const_child_iterator(), const_child_iterator()); 2893 } 2894 2895 child_range used_children() { 2896 return child_range(child_iterator(), child_iterator()); 2897 } 2898 const_child_range used_children() const { 2899 return const_child_range(const_child_iterator(), const_child_iterator()); 2900 } 2901 2902 static bool classof(const OMPClause *T) { 2903 return T->getClauseKind() == llvm::omp::OMPC_release; 2904 } 2905 }; 2906 2907 /// This represents 'relaxed' clause in the '#pragma omp atomic' 2908 /// directives. 2909 /// 2910 /// \code 2911 /// #pragma omp atomic relaxed 2912 /// \endcode 2913 /// In this example directive '#pragma omp atomic' has 'relaxed' clause. 2914 class OMPRelaxedClause final : public OMPClause { 2915 public: 2916 /// Build 'relaxed' clause. 2917 /// 2918 /// \param StartLoc Starting location of the clause. 2919 /// \param EndLoc Ending location of the clause. 2920 OMPRelaxedClause(SourceLocation StartLoc, SourceLocation EndLoc) 2921 : OMPClause(llvm::omp::OMPC_relaxed, StartLoc, EndLoc) {} 2922 2923 /// Build an empty clause. 2924 OMPRelaxedClause() 2925 : OMPClause(llvm::omp::OMPC_relaxed, SourceLocation(), SourceLocation()) { 2926 } 2927 2928 child_range children() { 2929 return child_range(child_iterator(), child_iterator()); 2930 } 2931 2932 const_child_range children() const { 2933 return const_child_range(const_child_iterator(), const_child_iterator()); 2934 } 2935 2936 child_range used_children() { 2937 return child_range(child_iterator(), child_iterator()); 2938 } 2939 const_child_range used_children() const { 2940 return const_child_range(const_child_iterator(), const_child_iterator()); 2941 } 2942 2943 static bool classof(const OMPClause *T) { 2944 return T->getClauseKind() == llvm::omp::OMPC_relaxed; 2945 } 2946 }; 2947 2948 /// This represents 'weak' clause in the '#pragma omp atomic' 2949 /// directives. 2950 /// 2951 /// \code 2952 /// #pragma omp atomic compare weak 2953 /// \endcode 2954 /// In this example directive '#pragma omp atomic' has 'weak' clause. 2955 class OMPWeakClause final : public OMPClause { 2956 public: 2957 /// Build 'weak' clause. 2958 /// 2959 /// \param StartLoc Starting location of the clause. 2960 /// \param EndLoc Ending location of the clause. 2961 OMPWeakClause(SourceLocation StartLoc, SourceLocation EndLoc) 2962 : OMPClause(llvm::omp::OMPC_weak, StartLoc, EndLoc) {} 2963 2964 /// Build an empty clause. 2965 OMPWeakClause() 2966 : OMPClause(llvm::omp::OMPC_weak, SourceLocation(), SourceLocation()) {} 2967 2968 child_range children() { 2969 return child_range(child_iterator(), child_iterator()); 2970 } 2971 2972 const_child_range children() const { 2973 return const_child_range(const_child_iterator(), const_child_iterator()); 2974 } 2975 2976 child_range used_children() { 2977 return child_range(child_iterator(), child_iterator()); 2978 } 2979 const_child_range used_children() const { 2980 return const_child_range(const_child_iterator(), const_child_iterator()); 2981 } 2982 2983 static bool classof(const OMPClause *T) { 2984 return T->getClauseKind() == llvm::omp::OMPC_weak; 2985 } 2986 }; 2987 2988 /// This represents 'fail' clause in the '#pragma omp atomic' 2989 /// directive. 2990 /// 2991 /// \code 2992 /// #pragma omp atomic compare fail 2993 /// \endcode 2994 /// In this example directive '#pragma omp atomic compare' has 'fail' clause. 2995 class OMPFailClause final : public OMPClause { 2996 2997 // FailParameter is a memory-order-clause. Storing the ClauseKind is 2998 // sufficient for our purpose. 2999 OpenMPClauseKind FailParameter = llvm::omp::Clause::OMPC_unknown; 3000 SourceLocation FailParameterLoc; 3001 SourceLocation LParenLoc; 3002 3003 friend class OMPClauseReader; 3004 3005 /// Sets the location of '(' in fail clause. 3006 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 3007 3008 /// Sets the location of memoryOrder clause argument in fail clause. 3009 void setFailParameterLoc(SourceLocation Loc) { FailParameterLoc = Loc; } 3010 3011 /// Sets the mem_order clause for 'atomic compare fail' directive. 3012 void setFailParameter(OpenMPClauseKind FailParameter) { 3013 this->FailParameter = FailParameter; 3014 assert(checkFailClauseParameter(FailParameter) && 3015 "Invalid fail clause parameter"); 3016 } 3017 3018 public: 3019 /// Build 'fail' clause. 3020 /// 3021 /// \param StartLoc Starting location of the clause. 3022 /// \param EndLoc Ending location of the clause. 3023 OMPFailClause(SourceLocation StartLoc, SourceLocation EndLoc) 3024 : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc) {} 3025 3026 OMPFailClause(OpenMPClauseKind FailParameter, SourceLocation FailParameterLoc, 3027 SourceLocation StartLoc, SourceLocation LParenLoc, 3028 SourceLocation EndLoc) 3029 : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc), 3030 FailParameterLoc(FailParameterLoc), LParenLoc(LParenLoc) { 3031 3032 setFailParameter(FailParameter); 3033 } 3034 3035 /// Build an empty clause. 3036 OMPFailClause() 3037 : OMPClause(llvm::omp::OMPC_fail, SourceLocation(), SourceLocation()) {} 3038 3039 child_range children() { 3040 return child_range(child_iterator(), child_iterator()); 3041 } 3042 3043 const_child_range children() const { 3044 return const_child_range(const_child_iterator(), const_child_iterator()); 3045 } 3046 3047 child_range used_children() { 3048 return child_range(child_iterator(), child_iterator()); 3049 } 3050 const_child_range used_children() const { 3051 return const_child_range(const_child_iterator(), const_child_iterator()); 3052 } 3053 3054 static bool classof(const OMPClause *T) { 3055 return T->getClauseKind() == llvm::omp::OMPC_fail; 3056 } 3057 3058 /// Gets the location of '(' (for the parameter) in fail clause. 3059 SourceLocation getLParenLoc() const { 3060 return LParenLoc; 3061 } 3062 3063 /// Gets the location of Fail Parameter (type memory-order-clause) in 3064 /// fail clause. 3065 SourceLocation getFailParameterLoc() const { return FailParameterLoc; } 3066 3067 /// Gets the parameter (type memory-order-clause) in Fail clause. 3068 OpenMPClauseKind getFailParameter() const { return FailParameter; } 3069 }; 3070 3071 /// This represents clause 'private' in the '#pragma omp ...' directives. 3072 /// 3073 /// \code 3074 /// #pragma omp parallel private(a,b) 3075 /// \endcode 3076 /// In this example directive '#pragma omp parallel' has clause 'private' 3077 /// with the variables 'a' and 'b'. 3078 class OMPPrivateClause final 3079 : public OMPVarListClause<OMPPrivateClause>, 3080 private llvm::TrailingObjects<OMPPrivateClause, Expr *> { 3081 friend class OMPClauseReader; 3082 friend OMPVarListClause; 3083 friend TrailingObjects; 3084 3085 /// Build clause with number of variables \a N. 3086 /// 3087 /// \param StartLoc Starting location of the clause. 3088 /// \param LParenLoc Location of '('. 3089 /// \param EndLoc Ending location of the clause. 3090 /// \param N Number of the variables in the clause. 3091 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc, 3092 SourceLocation EndLoc, unsigned N) 3093 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc, 3094 LParenLoc, EndLoc, N) {} 3095 3096 /// Build an empty clause. 3097 /// 3098 /// \param N Number of variables. 3099 explicit OMPPrivateClause(unsigned N) 3100 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, 3101 SourceLocation(), SourceLocation(), 3102 SourceLocation(), N) {} 3103 3104 /// Sets the list of references to private copies with initializers for 3105 /// new private variables. 3106 /// \param VL List of references. 3107 void setPrivateCopies(ArrayRef<Expr *> VL); 3108 3109 /// Gets the list of references to private copies with initializers for 3110 /// new private variables. 3111 MutableArrayRef<Expr *> getPrivateCopies() { 3112 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 3113 } 3114 ArrayRef<const Expr *> getPrivateCopies() const { 3115 return llvm::ArrayRef(varlist_end(), varlist_size()); 3116 } 3117 3118 public: 3119 /// Creates clause with a list of variables \a VL. 3120 /// 3121 /// \param C AST context. 3122 /// \param StartLoc Starting location of the clause. 3123 /// \param LParenLoc Location of '('. 3124 /// \param EndLoc Ending location of the clause. 3125 /// \param VL List of references to the variables. 3126 /// \param PrivateVL List of references to private copies with initializers. 3127 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc, 3128 SourceLocation LParenLoc, 3129 SourceLocation EndLoc, ArrayRef<Expr *> VL, 3130 ArrayRef<Expr *> PrivateVL); 3131 3132 /// Creates an empty clause with the place for \a N variables. 3133 /// 3134 /// \param C AST context. 3135 /// \param N The number of variables. 3136 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N); 3137 3138 using private_copies_iterator = MutableArrayRef<Expr *>::iterator; 3139 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator; 3140 using private_copies_range = llvm::iterator_range<private_copies_iterator>; 3141 using private_copies_const_range = 3142 llvm::iterator_range<private_copies_const_iterator>; 3143 3144 private_copies_range private_copies() { 3145 return private_copies_range(getPrivateCopies().begin(), 3146 getPrivateCopies().end()); 3147 } 3148 3149 private_copies_const_range private_copies() const { 3150 return private_copies_const_range(getPrivateCopies().begin(), 3151 getPrivateCopies().end()); 3152 } 3153 3154 child_range children() { 3155 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 3156 reinterpret_cast<Stmt **>(varlist_end())); 3157 } 3158 3159 const_child_range children() const { 3160 auto Children = const_cast<OMPPrivateClause *>(this)->children(); 3161 return const_child_range(Children.begin(), Children.end()); 3162 } 3163 3164 child_range used_children() { 3165 return child_range(child_iterator(), child_iterator()); 3166 } 3167 const_child_range used_children() const { 3168 return const_child_range(const_child_iterator(), const_child_iterator()); 3169 } 3170 3171 static bool classof(const OMPClause *T) { 3172 return T->getClauseKind() == llvm::omp::OMPC_private; 3173 } 3174 }; 3175 3176 /// This represents clause 'firstprivate' in the '#pragma omp ...' 3177 /// directives. 3178 /// 3179 /// \code 3180 /// #pragma omp parallel firstprivate(a,b) 3181 /// \endcode 3182 /// In this example directive '#pragma omp parallel' has clause 'firstprivate' 3183 /// with the variables 'a' and 'b'. 3184 class OMPFirstprivateClause final 3185 : public OMPVarListClause<OMPFirstprivateClause>, 3186 public OMPClauseWithPreInit, 3187 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> { 3188 friend class OMPClauseReader; 3189 friend OMPVarListClause; 3190 friend TrailingObjects; 3191 3192 /// Build clause with number of variables \a N. 3193 /// 3194 /// \param StartLoc Starting location of the clause. 3195 /// \param LParenLoc Location of '('. 3196 /// \param EndLoc Ending location of the clause. 3197 /// \param N Number of the variables in the clause. 3198 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc, 3199 SourceLocation EndLoc, unsigned N) 3200 : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate, 3201 StartLoc, LParenLoc, EndLoc, N), 3202 OMPClauseWithPreInit(this) {} 3203 3204 /// Build an empty clause. 3205 /// 3206 /// \param N Number of variables. 3207 explicit OMPFirstprivateClause(unsigned N) 3208 : OMPVarListClause<OMPFirstprivateClause>( 3209 llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(), 3210 SourceLocation(), N), 3211 OMPClauseWithPreInit(this) {} 3212 3213 /// Sets the list of references to private copies with initializers for 3214 /// new private variables. 3215 /// \param VL List of references. 3216 void setPrivateCopies(ArrayRef<Expr *> VL); 3217 3218 /// Gets the list of references to private copies with initializers for 3219 /// new private variables. 3220 MutableArrayRef<Expr *> getPrivateCopies() { 3221 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 3222 } 3223 ArrayRef<const Expr *> getPrivateCopies() const { 3224 return llvm::ArrayRef(varlist_end(), varlist_size()); 3225 } 3226 3227 /// Sets the list of references to initializer variables for new 3228 /// private variables. 3229 /// \param VL List of references. 3230 void setInits(ArrayRef<Expr *> VL); 3231 3232 /// Gets the list of references to initializer variables for new 3233 /// private variables. 3234 MutableArrayRef<Expr *> getInits() { 3235 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size()); 3236 } 3237 ArrayRef<const Expr *> getInits() const { 3238 return llvm::ArrayRef(getPrivateCopies().end(), varlist_size()); 3239 } 3240 3241 public: 3242 /// Creates clause with a list of variables \a VL. 3243 /// 3244 /// \param C AST context. 3245 /// \param StartLoc Starting location of the clause. 3246 /// \param LParenLoc Location of '('. 3247 /// \param EndLoc Ending location of the clause. 3248 /// \param VL List of references to the original variables. 3249 /// \param PrivateVL List of references to private copies with initializers. 3250 /// \param InitVL List of references to auto generated variables used for 3251 /// initialization of a single array element. Used if firstprivate variable is 3252 /// of array type. 3253 /// \param PreInit Statement that must be executed before entering the OpenMP 3254 /// region with this clause. 3255 static OMPFirstprivateClause * 3256 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 3257 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, 3258 ArrayRef<Expr *> InitVL, Stmt *PreInit); 3259 3260 /// Creates an empty clause with the place for \a N variables. 3261 /// 3262 /// \param C AST context. 3263 /// \param N The number of variables. 3264 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N); 3265 3266 using private_copies_iterator = MutableArrayRef<Expr *>::iterator; 3267 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator; 3268 using private_copies_range = llvm::iterator_range<private_copies_iterator>; 3269 using private_copies_const_range = 3270 llvm::iterator_range<private_copies_const_iterator>; 3271 3272 private_copies_range private_copies() { 3273 return private_copies_range(getPrivateCopies().begin(), 3274 getPrivateCopies().end()); 3275 } 3276 private_copies_const_range private_copies() const { 3277 return private_copies_const_range(getPrivateCopies().begin(), 3278 getPrivateCopies().end()); 3279 } 3280 3281 using inits_iterator = MutableArrayRef<Expr *>::iterator; 3282 using inits_const_iterator = ArrayRef<const Expr *>::iterator; 3283 using inits_range = llvm::iterator_range<inits_iterator>; 3284 using inits_const_range = llvm::iterator_range<inits_const_iterator>; 3285 3286 inits_range inits() { 3287 return inits_range(getInits().begin(), getInits().end()); 3288 } 3289 inits_const_range inits() const { 3290 return inits_const_range(getInits().begin(), getInits().end()); 3291 } 3292 3293 child_range children() { 3294 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 3295 reinterpret_cast<Stmt **>(varlist_end())); 3296 } 3297 3298 const_child_range children() const { 3299 auto Children = const_cast<OMPFirstprivateClause *>(this)->children(); 3300 return const_child_range(Children.begin(), Children.end()); 3301 } 3302 3303 child_range used_children() { 3304 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 3305 reinterpret_cast<Stmt **>(varlist_end())); 3306 } 3307 const_child_range used_children() const { 3308 auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children(); 3309 return const_child_range(Children.begin(), Children.end()); 3310 } 3311 3312 static bool classof(const OMPClause *T) { 3313 return T->getClauseKind() == llvm::omp::OMPC_firstprivate; 3314 } 3315 }; 3316 3317 /// This represents clause 'lastprivate' in the '#pragma omp ...' 3318 /// directives. 3319 /// 3320 /// \code 3321 /// #pragma omp simd lastprivate(a,b) 3322 /// \endcode 3323 /// In this example directive '#pragma omp simd' has clause 'lastprivate' 3324 /// with the variables 'a' and 'b'. 3325 class OMPLastprivateClause final 3326 : public OMPVarListClause<OMPLastprivateClause>, 3327 public OMPClauseWithPostUpdate, 3328 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> { 3329 // There are 4 additional tail-allocated arrays at the end of the class: 3330 // 1. Contains list of pseudo variables with the default initialization for 3331 // each non-firstprivate variables. Used in codegen for initialization of 3332 // lastprivate copies. 3333 // 2. List of helper expressions for proper generation of assignment operation 3334 // required for lastprivate clause. This list represents private variables 3335 // (for arrays, single array element). 3336 // 3. List of helper expressions for proper generation of assignment operation 3337 // required for lastprivate clause. This list represents original variables 3338 // (for arrays, single array element). 3339 // 4. List of helper expressions that represents assignment operation: 3340 // \code 3341 // DstExprs = SrcExprs; 3342 // \endcode 3343 // Required for proper codegen of final assignment performed by the 3344 // lastprivate clause. 3345 friend class OMPClauseReader; 3346 friend OMPVarListClause; 3347 friend TrailingObjects; 3348 3349 /// Optional lastprivate kind, e.g. 'conditional', if specified by user. 3350 OpenMPLastprivateModifier LPKind; 3351 /// Optional location of the lasptrivate kind, if specified by user. 3352 SourceLocation LPKindLoc; 3353 /// Optional colon location, if specified by user. 3354 SourceLocation ColonLoc; 3355 3356 /// Build clause with number of variables \a N. 3357 /// 3358 /// \param StartLoc Starting location of the clause. 3359 /// \param LParenLoc Location of '('. 3360 /// \param EndLoc Ending location of the clause. 3361 /// \param N Number of the variables in the clause. 3362 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc, 3363 SourceLocation EndLoc, OpenMPLastprivateModifier LPKind, 3364 SourceLocation LPKindLoc, SourceLocation ColonLoc, 3365 unsigned N) 3366 : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate, 3367 StartLoc, LParenLoc, EndLoc, N), 3368 OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc), 3369 ColonLoc(ColonLoc) {} 3370 3371 /// Build an empty clause. 3372 /// 3373 /// \param N Number of variables. 3374 explicit OMPLastprivateClause(unsigned N) 3375 : OMPVarListClause<OMPLastprivateClause>( 3376 llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(), 3377 SourceLocation(), N), 3378 OMPClauseWithPostUpdate(this) {} 3379 3380 /// Get the list of helper expressions for initialization of private 3381 /// copies for lastprivate variables. 3382 MutableArrayRef<Expr *> getPrivateCopies() { 3383 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 3384 } 3385 ArrayRef<const Expr *> getPrivateCopies() const { 3386 return llvm::ArrayRef(varlist_end(), varlist_size()); 3387 } 3388 3389 /// Set list of helper expressions, required for proper codegen of the 3390 /// clause. These expressions represent private variables (for arrays, single 3391 /// array element) in the final assignment statement performed by the 3392 /// lastprivate clause. 3393 void setSourceExprs(ArrayRef<Expr *> SrcExprs); 3394 3395 /// Get the list of helper source expressions. 3396 MutableArrayRef<Expr *> getSourceExprs() { 3397 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size()); 3398 } 3399 ArrayRef<const Expr *> getSourceExprs() const { 3400 return llvm::ArrayRef(getPrivateCopies().end(), varlist_size()); 3401 } 3402 3403 /// Set list of helper expressions, required for proper codegen of the 3404 /// clause. These expressions represent original variables (for arrays, single 3405 /// array element) in the final assignment statement performed by the 3406 /// lastprivate clause. 3407 void setDestinationExprs(ArrayRef<Expr *> DstExprs); 3408 3409 /// Get the list of helper destination expressions. 3410 MutableArrayRef<Expr *> getDestinationExprs() { 3411 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size()); 3412 } 3413 ArrayRef<const Expr *> getDestinationExprs() const { 3414 return llvm::ArrayRef(getSourceExprs().end(), varlist_size()); 3415 } 3416 3417 /// Set list of helper assignment expressions, required for proper 3418 /// codegen of the clause. These expressions are assignment expressions that 3419 /// assign private copy of the variable to original variable. 3420 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps); 3421 3422 /// Get the list of helper assignment expressions. 3423 MutableArrayRef<Expr *> getAssignmentOps() { 3424 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size()); 3425 } 3426 ArrayRef<const Expr *> getAssignmentOps() const { 3427 return llvm::ArrayRef(getDestinationExprs().end(), varlist_size()); 3428 } 3429 3430 /// Sets lastprivate kind. 3431 void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; } 3432 /// Sets location of the lastprivate kind. 3433 void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; } 3434 /// Sets colon symbol location. 3435 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 3436 3437 public: 3438 /// Creates clause with a list of variables \a VL. 3439 /// 3440 /// \param C AST context. 3441 /// \param StartLoc Starting location of the clause. 3442 /// \param LParenLoc Location of '('. 3443 /// \param EndLoc Ending location of the clause. 3444 /// \param VL List of references to the variables. 3445 /// \param SrcExprs List of helper expressions for proper generation of 3446 /// assignment operation required for lastprivate clause. This list represents 3447 /// private variables (for arrays, single array element). 3448 /// \param DstExprs List of helper expressions for proper generation of 3449 /// assignment operation required for lastprivate clause. This list represents 3450 /// original variables (for arrays, single array element). 3451 /// \param AssignmentOps List of helper expressions that represents assignment 3452 /// operation: 3453 /// \code 3454 /// DstExprs = SrcExprs; 3455 /// \endcode 3456 /// Required for proper codegen of final assignment performed by the 3457 /// lastprivate clause. 3458 /// \param LPKind Lastprivate kind, e.g. 'conditional'. 3459 /// \param LPKindLoc Location of the lastprivate kind. 3460 /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used. 3461 /// \param PreInit Statement that must be executed before entering the OpenMP 3462 /// region with this clause. 3463 /// \param PostUpdate Expression that must be executed after exit from the 3464 /// OpenMP region with this clause. 3465 static OMPLastprivateClause * 3466 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 3467 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 3468 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, 3469 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, 3470 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate); 3471 3472 /// Creates an empty clause with the place for \a N variables. 3473 /// 3474 /// \param C AST context. 3475 /// \param N The number of variables. 3476 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N); 3477 3478 /// Lastprivate kind. 3479 OpenMPLastprivateModifier getKind() const { return LPKind; } 3480 /// Returns the location of the lastprivate kind. 3481 SourceLocation getKindLoc() const { return LPKindLoc; } 3482 /// Returns the location of the ':' symbol, if any. 3483 SourceLocation getColonLoc() const { return ColonLoc; } 3484 3485 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator; 3486 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator; 3487 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>; 3488 using helper_expr_const_range = 3489 llvm::iterator_range<helper_expr_const_iterator>; 3490 3491 /// Set list of helper expressions, required for generation of private 3492 /// copies of original lastprivate variables. 3493 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies); 3494 3495 helper_expr_const_range private_copies() const { 3496 return helper_expr_const_range(getPrivateCopies().begin(), 3497 getPrivateCopies().end()); 3498 } 3499 3500 helper_expr_range private_copies() { 3501 return helper_expr_range(getPrivateCopies().begin(), 3502 getPrivateCopies().end()); 3503 } 3504 3505 helper_expr_const_range source_exprs() const { 3506 return helper_expr_const_range(getSourceExprs().begin(), 3507 getSourceExprs().end()); 3508 } 3509 3510 helper_expr_range source_exprs() { 3511 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end()); 3512 } 3513 3514 helper_expr_const_range destination_exprs() const { 3515 return helper_expr_const_range(getDestinationExprs().begin(), 3516 getDestinationExprs().end()); 3517 } 3518 3519 helper_expr_range destination_exprs() { 3520 return helper_expr_range(getDestinationExprs().begin(), 3521 getDestinationExprs().end()); 3522 } 3523 3524 helper_expr_const_range assignment_ops() const { 3525 return helper_expr_const_range(getAssignmentOps().begin(), 3526 getAssignmentOps().end()); 3527 } 3528 3529 helper_expr_range assignment_ops() { 3530 return helper_expr_range(getAssignmentOps().begin(), 3531 getAssignmentOps().end()); 3532 } 3533 3534 child_range children() { 3535 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 3536 reinterpret_cast<Stmt **>(varlist_end())); 3537 } 3538 3539 const_child_range children() const { 3540 auto Children = const_cast<OMPLastprivateClause *>(this)->children(); 3541 return const_child_range(Children.begin(), Children.end()); 3542 } 3543 3544 child_range used_children() { 3545 return child_range(child_iterator(), child_iterator()); 3546 } 3547 const_child_range used_children() const { 3548 return const_child_range(const_child_iterator(), const_child_iterator()); 3549 } 3550 3551 static bool classof(const OMPClause *T) { 3552 return T->getClauseKind() == llvm::omp::OMPC_lastprivate; 3553 } 3554 }; 3555 3556 /// This represents clause 'shared' in the '#pragma omp ...' directives. 3557 /// 3558 /// \code 3559 /// #pragma omp parallel shared(a,b) 3560 /// \endcode 3561 /// In this example directive '#pragma omp parallel' has clause 'shared' 3562 /// with the variables 'a' and 'b'. 3563 class OMPSharedClause final 3564 : public OMPVarListClause<OMPSharedClause>, 3565 private llvm::TrailingObjects<OMPSharedClause, Expr *> { 3566 friend OMPVarListClause; 3567 friend TrailingObjects; 3568 3569 /// Build clause with number of variables \a N. 3570 /// 3571 /// \param StartLoc Starting location of the clause. 3572 /// \param LParenLoc Location of '('. 3573 /// \param EndLoc Ending location of the clause. 3574 /// \param N Number of the variables in the clause. 3575 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc, 3576 SourceLocation EndLoc, unsigned N) 3577 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, StartLoc, 3578 LParenLoc, EndLoc, N) {} 3579 3580 /// Build an empty clause. 3581 /// 3582 /// \param N Number of variables. 3583 explicit OMPSharedClause(unsigned N) 3584 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, 3585 SourceLocation(), SourceLocation(), 3586 SourceLocation(), N) {} 3587 3588 public: 3589 /// Creates clause with a list of variables \a VL. 3590 /// 3591 /// \param C AST context. 3592 /// \param StartLoc Starting location of the clause. 3593 /// \param LParenLoc Location of '('. 3594 /// \param EndLoc Ending location of the clause. 3595 /// \param VL List of references to the variables. 3596 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc, 3597 SourceLocation LParenLoc, 3598 SourceLocation EndLoc, ArrayRef<Expr *> VL); 3599 3600 /// Creates an empty clause with \a N variables. 3601 /// 3602 /// \param C AST context. 3603 /// \param N The number of variables. 3604 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N); 3605 3606 child_range children() { 3607 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 3608 reinterpret_cast<Stmt **>(varlist_end())); 3609 } 3610 3611 const_child_range children() const { 3612 auto Children = const_cast<OMPSharedClause *>(this)->children(); 3613 return const_child_range(Children.begin(), Children.end()); 3614 } 3615 3616 child_range used_children() { 3617 return child_range(child_iterator(), child_iterator()); 3618 } 3619 const_child_range used_children() const { 3620 return const_child_range(const_child_iterator(), const_child_iterator()); 3621 } 3622 3623 static bool classof(const OMPClause *T) { 3624 return T->getClauseKind() == llvm::omp::OMPC_shared; 3625 } 3626 }; 3627 3628 /// This represents clause 'reduction' in the '#pragma omp ...' 3629 /// directives. 3630 /// 3631 /// \code 3632 /// #pragma omp parallel reduction(+:a,b) 3633 /// \endcode 3634 /// In this example directive '#pragma omp parallel' has clause 'reduction' 3635 /// with operator '+' and the variables 'a' and 'b'. 3636 class OMPReductionClause final 3637 : public OMPVarListClause<OMPReductionClause>, 3638 public OMPClauseWithPostUpdate, 3639 private llvm::TrailingObjects<OMPReductionClause, Expr *> { 3640 friend class OMPClauseReader; 3641 friend OMPVarListClause; 3642 friend TrailingObjects; 3643 3644 /// Reduction modifier. 3645 OpenMPReductionClauseModifier Modifier = OMPC_REDUCTION_unknown; 3646 3647 /// Reduction modifier location. 3648 SourceLocation ModifierLoc; 3649 3650 /// Location of ':'. 3651 SourceLocation ColonLoc; 3652 3653 /// Nested name specifier for C++. 3654 NestedNameSpecifierLoc QualifierLoc; 3655 3656 /// Name of custom operator. 3657 DeclarationNameInfo NameInfo; 3658 3659 /// Build clause with number of variables \a N. 3660 /// 3661 /// \param StartLoc Starting location of the clause. 3662 /// \param LParenLoc Location of '('. 3663 /// \param ModifierLoc Modifier location. 3664 /// \param ColonLoc Location of ':'. 3665 /// \param EndLoc Ending location of the clause. 3666 /// \param N Number of the variables in the clause. 3667 /// \param QualifierLoc The nested-name qualifier with location information 3668 /// \param NameInfo The full name info for reduction identifier. 3669 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc, 3670 SourceLocation ModifierLoc, SourceLocation ColonLoc, 3671 SourceLocation EndLoc, 3672 OpenMPReductionClauseModifier Modifier, unsigned N, 3673 NestedNameSpecifierLoc QualifierLoc, 3674 const DeclarationNameInfo &NameInfo) 3675 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction, 3676 StartLoc, LParenLoc, EndLoc, N), 3677 OMPClauseWithPostUpdate(this), Modifier(Modifier), 3678 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc), 3679 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {} 3680 3681 /// Build an empty clause. 3682 /// 3683 /// \param N Number of variables. 3684 explicit OMPReductionClause(unsigned N) 3685 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction, 3686 SourceLocation(), SourceLocation(), 3687 SourceLocation(), N), 3688 OMPClauseWithPostUpdate(this) {} 3689 3690 /// Sets reduction modifier. 3691 void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; } 3692 3693 /// Sets location of the modifier. 3694 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; } 3695 3696 /// Sets location of ':' symbol in clause. 3697 void setColonLoc(SourceLocation CL) { ColonLoc = CL; } 3698 3699 /// Sets the name info for specified reduction identifier. 3700 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; } 3701 3702 /// Sets the nested name specifier. 3703 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; } 3704 3705 /// Set list of helper expressions, required for proper codegen of the 3706 /// clause. These expressions represent private copy of the reduction 3707 /// variable. 3708 void setPrivates(ArrayRef<Expr *> Privates); 3709 3710 /// Get the list of helper privates. 3711 MutableArrayRef<Expr *> getPrivates() { 3712 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 3713 } 3714 ArrayRef<const Expr *> getPrivates() const { 3715 return llvm::ArrayRef(varlist_end(), varlist_size()); 3716 } 3717 3718 /// Set list of helper expressions, required for proper codegen of the 3719 /// clause. These expressions represent LHS expression in the final 3720 /// reduction expression performed by the reduction clause. 3721 void setLHSExprs(ArrayRef<Expr *> LHSExprs); 3722 3723 /// Get the list of helper LHS expressions. 3724 MutableArrayRef<Expr *> getLHSExprs() { 3725 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size()); 3726 } 3727 ArrayRef<const Expr *> getLHSExprs() const { 3728 return llvm::ArrayRef(getPrivates().end(), varlist_size()); 3729 } 3730 3731 /// Set list of helper expressions, required for proper codegen of the 3732 /// clause. These expressions represent RHS expression in the final 3733 /// reduction expression performed by the reduction clause. 3734 /// Also, variables in these expressions are used for proper initialization of 3735 /// reduction copies. 3736 void setRHSExprs(ArrayRef<Expr *> RHSExprs); 3737 3738 /// Get the list of helper destination expressions. 3739 MutableArrayRef<Expr *> getRHSExprs() { 3740 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size()); 3741 } 3742 ArrayRef<const Expr *> getRHSExprs() const { 3743 return llvm::ArrayRef(getLHSExprs().end(), varlist_size()); 3744 } 3745 3746 /// Set list of helper reduction expressions, required for proper 3747 /// codegen of the clause. These expressions are binary expressions or 3748 /// operator/custom reduction call that calculates new value from source 3749 /// helper expressions to destination helper expressions. 3750 void setReductionOps(ArrayRef<Expr *> ReductionOps); 3751 3752 /// Get the list of helper reduction expressions. 3753 MutableArrayRef<Expr *> getReductionOps() { 3754 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size()); 3755 } 3756 ArrayRef<const Expr *> getReductionOps() const { 3757 return llvm::ArrayRef(getRHSExprs().end(), varlist_size()); 3758 } 3759 3760 /// Set list of helper copy operations for inscan reductions. 3761 /// The form is: Temps[i] = LHS[i]; 3762 void setInscanCopyOps(ArrayRef<Expr *> Ops); 3763 3764 /// Get the list of helper inscan copy operations. 3765 MutableArrayRef<Expr *> getInscanCopyOps() { 3766 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size()); 3767 } 3768 ArrayRef<const Expr *> getInscanCopyOps() const { 3769 return llvm::ArrayRef(getReductionOps().end(), varlist_size()); 3770 } 3771 3772 /// Set list of helper temp vars for inscan copy array operations. 3773 void setInscanCopyArrayTemps(ArrayRef<Expr *> CopyArrayTemps); 3774 3775 /// Get the list of helper inscan copy temps. 3776 MutableArrayRef<Expr *> getInscanCopyArrayTemps() { 3777 return MutableArrayRef<Expr *>(getInscanCopyOps().end(), varlist_size()); 3778 } 3779 ArrayRef<const Expr *> getInscanCopyArrayTemps() const { 3780 return llvm::ArrayRef(getInscanCopyOps().end(), varlist_size()); 3781 } 3782 3783 /// Set list of helper temp elements vars for inscan copy array operations. 3784 void setInscanCopyArrayElems(ArrayRef<Expr *> CopyArrayElems); 3785 3786 /// Get the list of helper inscan copy temps. 3787 MutableArrayRef<Expr *> getInscanCopyArrayElems() { 3788 return MutableArrayRef<Expr *>(getInscanCopyArrayTemps().end(), 3789 varlist_size()); 3790 } 3791 ArrayRef<const Expr *> getInscanCopyArrayElems() const { 3792 return llvm::ArrayRef(getInscanCopyArrayTemps().end(), varlist_size()); 3793 } 3794 3795 public: 3796 /// Creates clause with a list of variables \a VL. 3797 /// 3798 /// \param StartLoc Starting location of the clause. 3799 /// \param LParenLoc Location of '('. 3800 /// \param ModifierLoc Modifier location. 3801 /// \param ColonLoc Location of ':'. 3802 /// \param EndLoc Ending location of the clause. 3803 /// \param VL The variables in the clause. 3804 /// \param QualifierLoc The nested-name qualifier with location information 3805 /// \param NameInfo The full name info for reduction identifier. 3806 /// \param Privates List of helper expressions for proper generation of 3807 /// private copies. 3808 /// \param LHSExprs List of helper expressions for proper generation of 3809 /// assignment operation required for copyprivate clause. This list represents 3810 /// LHSs of the reduction expressions. 3811 /// \param RHSExprs List of helper expressions for proper generation of 3812 /// assignment operation required for copyprivate clause. This list represents 3813 /// RHSs of the reduction expressions. 3814 /// Also, variables in these expressions are used for proper initialization of 3815 /// reduction copies. 3816 /// \param ReductionOps List of helper expressions that represents reduction 3817 /// expressions: 3818 /// \code 3819 /// LHSExprs binop RHSExprs; 3820 /// operator binop(LHSExpr, RHSExpr); 3821 /// <CutomReduction>(LHSExpr, RHSExpr); 3822 /// \endcode 3823 /// Required for proper codegen of final reduction operation performed by the 3824 /// reduction clause. 3825 /// \param CopyOps List of copy operations for inscan reductions: 3826 /// \code 3827 /// TempExprs = LHSExprs; 3828 /// \endcode 3829 /// \param CopyArrayTemps Temp arrays for prefix sums. 3830 /// \param CopyArrayElems Temp arrays for prefix sums. 3831 /// \param PreInit Statement that must be executed before entering the OpenMP 3832 /// region with this clause. 3833 /// \param PostUpdate Expression that must be executed after exit from the 3834 /// OpenMP region with this clause. 3835 static OMPReductionClause * 3836 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 3837 SourceLocation ModifierLoc, SourceLocation ColonLoc, 3838 SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier, 3839 ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc, 3840 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates, 3841 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs, 3842 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> CopyOps, 3843 ArrayRef<Expr *> CopyArrayTemps, ArrayRef<Expr *> CopyArrayElems, 3844 Stmt *PreInit, Expr *PostUpdate); 3845 3846 /// Creates an empty clause with the place for \a N variables. 3847 /// 3848 /// \param C AST context. 3849 /// \param N The number of variables. 3850 /// \param Modifier Reduction modifier. 3851 static OMPReductionClause * 3852 CreateEmpty(const ASTContext &C, unsigned N, 3853 OpenMPReductionClauseModifier Modifier); 3854 3855 /// Returns modifier. 3856 OpenMPReductionClauseModifier getModifier() const { return Modifier; } 3857 3858 /// Returns modifier location. 3859 SourceLocation getModifierLoc() const { return ModifierLoc; } 3860 3861 /// Gets location of ':' symbol in clause. 3862 SourceLocation getColonLoc() const { return ColonLoc; } 3863 3864 /// Gets the name info for specified reduction identifier. 3865 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 3866 3867 /// Gets the nested name specifier. 3868 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 3869 3870 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator; 3871 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator; 3872 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>; 3873 using helper_expr_const_range = 3874 llvm::iterator_range<helper_expr_const_iterator>; 3875 3876 helper_expr_const_range privates() const { 3877 return helper_expr_const_range(getPrivates().begin(), getPrivates().end()); 3878 } 3879 3880 helper_expr_range privates() { 3881 return helper_expr_range(getPrivates().begin(), getPrivates().end()); 3882 } 3883 3884 helper_expr_const_range lhs_exprs() const { 3885 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end()); 3886 } 3887 3888 helper_expr_range lhs_exprs() { 3889 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end()); 3890 } 3891 3892 helper_expr_const_range rhs_exprs() const { 3893 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end()); 3894 } 3895 3896 helper_expr_range rhs_exprs() { 3897 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end()); 3898 } 3899 3900 helper_expr_const_range reduction_ops() const { 3901 return helper_expr_const_range(getReductionOps().begin(), 3902 getReductionOps().end()); 3903 } 3904 3905 helper_expr_range reduction_ops() { 3906 return helper_expr_range(getReductionOps().begin(), 3907 getReductionOps().end()); 3908 } 3909 3910 helper_expr_const_range copy_ops() const { 3911 return helper_expr_const_range(getInscanCopyOps().begin(), 3912 getInscanCopyOps().end()); 3913 } 3914 3915 helper_expr_range copy_ops() { 3916 return helper_expr_range(getInscanCopyOps().begin(), 3917 getInscanCopyOps().end()); 3918 } 3919 3920 helper_expr_const_range copy_array_temps() const { 3921 return helper_expr_const_range(getInscanCopyArrayTemps().begin(), 3922 getInscanCopyArrayTemps().end()); 3923 } 3924 3925 helper_expr_range copy_array_temps() { 3926 return helper_expr_range(getInscanCopyArrayTemps().begin(), 3927 getInscanCopyArrayTemps().end()); 3928 } 3929 3930 helper_expr_const_range copy_array_elems() const { 3931 return helper_expr_const_range(getInscanCopyArrayElems().begin(), 3932 getInscanCopyArrayElems().end()); 3933 } 3934 3935 helper_expr_range copy_array_elems() { 3936 return helper_expr_range(getInscanCopyArrayElems().begin(), 3937 getInscanCopyArrayElems().end()); 3938 } 3939 3940 child_range children() { 3941 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 3942 reinterpret_cast<Stmt **>(varlist_end())); 3943 } 3944 3945 const_child_range children() const { 3946 auto Children = const_cast<OMPReductionClause *>(this)->children(); 3947 return const_child_range(Children.begin(), Children.end()); 3948 } 3949 3950 child_range used_children() { 3951 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 3952 reinterpret_cast<Stmt **>(varlist_end())); 3953 } 3954 const_child_range used_children() const { 3955 auto Children = const_cast<OMPReductionClause *>(this)->used_children(); 3956 return const_child_range(Children.begin(), Children.end()); 3957 } 3958 3959 static bool classof(const OMPClause *T) { 3960 return T->getClauseKind() == llvm::omp::OMPC_reduction; 3961 } 3962 }; 3963 3964 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup' 3965 /// directives. 3966 /// 3967 /// \code 3968 /// #pragma omp taskgroup task_reduction(+:a,b) 3969 /// \endcode 3970 /// In this example directive '#pragma omp taskgroup' has clause 3971 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'. 3972 class OMPTaskReductionClause final 3973 : public OMPVarListClause<OMPTaskReductionClause>, 3974 public OMPClauseWithPostUpdate, 3975 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> { 3976 friend class OMPClauseReader; 3977 friend OMPVarListClause; 3978 friend TrailingObjects; 3979 3980 /// Location of ':'. 3981 SourceLocation ColonLoc; 3982 3983 /// Nested name specifier for C++. 3984 NestedNameSpecifierLoc QualifierLoc; 3985 3986 /// Name of custom operator. 3987 DeclarationNameInfo NameInfo; 3988 3989 /// Build clause with number of variables \a N. 3990 /// 3991 /// \param StartLoc Starting location of the clause. 3992 /// \param LParenLoc Location of '('. 3993 /// \param EndLoc Ending location of the clause. 3994 /// \param ColonLoc Location of ':'. 3995 /// \param N Number of the variables in the clause. 3996 /// \param QualifierLoc The nested-name qualifier with location information 3997 /// \param NameInfo The full name info for reduction identifier. 3998 OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc, 3999 SourceLocation ColonLoc, SourceLocation EndLoc, 4000 unsigned N, NestedNameSpecifierLoc QualifierLoc, 4001 const DeclarationNameInfo &NameInfo) 4002 : OMPVarListClause<OMPTaskReductionClause>( 4003 llvm::omp::OMPC_task_reduction, StartLoc, LParenLoc, EndLoc, N), 4004 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc), 4005 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {} 4006 4007 /// Build an empty clause. 4008 /// 4009 /// \param N Number of variables. 4010 explicit OMPTaskReductionClause(unsigned N) 4011 : OMPVarListClause<OMPTaskReductionClause>( 4012 llvm::omp::OMPC_task_reduction, SourceLocation(), SourceLocation(), 4013 SourceLocation(), N), 4014 OMPClauseWithPostUpdate(this) {} 4015 4016 /// Sets location of ':' symbol in clause. 4017 void setColonLoc(SourceLocation CL) { ColonLoc = CL; } 4018 4019 /// Sets the name info for specified reduction identifier. 4020 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; } 4021 4022 /// Sets the nested name specifier. 4023 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; } 4024 4025 /// Set list of helper expressions, required for proper codegen of the clause. 4026 /// These expressions represent private copy of the reduction variable. 4027 void setPrivates(ArrayRef<Expr *> Privates); 4028 4029 /// Get the list of helper privates. 4030 MutableArrayRef<Expr *> getPrivates() { 4031 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 4032 } 4033 ArrayRef<const Expr *> getPrivates() const { 4034 return llvm::ArrayRef(varlist_end(), varlist_size()); 4035 } 4036 4037 /// Set list of helper expressions, required for proper codegen of the clause. 4038 /// These expressions represent LHS expression in the final reduction 4039 /// expression performed by the reduction clause. 4040 void setLHSExprs(ArrayRef<Expr *> LHSExprs); 4041 4042 /// Get the list of helper LHS expressions. 4043 MutableArrayRef<Expr *> getLHSExprs() { 4044 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size()); 4045 } 4046 ArrayRef<const Expr *> getLHSExprs() const { 4047 return llvm::ArrayRef(getPrivates().end(), varlist_size()); 4048 } 4049 4050 /// Set list of helper expressions, required for proper codegen of the clause. 4051 /// These expressions represent RHS expression in the final reduction 4052 /// expression performed by the reduction clause. Also, variables in these 4053 /// expressions are used for proper initialization of reduction copies. 4054 void setRHSExprs(ArrayRef<Expr *> RHSExprs); 4055 4056 /// Get the list of helper destination expressions. 4057 MutableArrayRef<Expr *> getRHSExprs() { 4058 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size()); 4059 } 4060 ArrayRef<const Expr *> getRHSExprs() const { 4061 return llvm::ArrayRef(getLHSExprs().end(), varlist_size()); 4062 } 4063 4064 /// Set list of helper reduction expressions, required for proper 4065 /// codegen of the clause. These expressions are binary expressions or 4066 /// operator/custom reduction call that calculates new value from source 4067 /// helper expressions to destination helper expressions. 4068 void setReductionOps(ArrayRef<Expr *> ReductionOps); 4069 4070 /// Get the list of helper reduction expressions. 4071 MutableArrayRef<Expr *> getReductionOps() { 4072 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size()); 4073 } 4074 ArrayRef<const Expr *> getReductionOps() const { 4075 return llvm::ArrayRef(getRHSExprs().end(), varlist_size()); 4076 } 4077 4078 public: 4079 /// Creates clause with a list of variables \a VL. 4080 /// 4081 /// \param StartLoc Starting location of the clause. 4082 /// \param LParenLoc Location of '('. 4083 /// \param ColonLoc Location of ':'. 4084 /// \param EndLoc Ending location of the clause. 4085 /// \param VL The variables in the clause. 4086 /// \param QualifierLoc The nested-name qualifier with location information 4087 /// \param NameInfo The full name info for reduction identifier. 4088 /// \param Privates List of helper expressions for proper generation of 4089 /// private copies. 4090 /// \param LHSExprs List of helper expressions for proper generation of 4091 /// assignment operation required for copyprivate clause. This list represents 4092 /// LHSs of the reduction expressions. 4093 /// \param RHSExprs List of helper expressions for proper generation of 4094 /// assignment operation required for copyprivate clause. This list represents 4095 /// RHSs of the reduction expressions. 4096 /// Also, variables in these expressions are used for proper initialization of 4097 /// reduction copies. 4098 /// \param ReductionOps List of helper expressions that represents reduction 4099 /// expressions: 4100 /// \code 4101 /// LHSExprs binop RHSExprs; 4102 /// operator binop(LHSExpr, RHSExpr); 4103 /// <CutomReduction>(LHSExpr, RHSExpr); 4104 /// \endcode 4105 /// Required for proper codegen of final reduction operation performed by the 4106 /// reduction clause. 4107 /// \param PreInit Statement that must be executed before entering the OpenMP 4108 /// region with this clause. 4109 /// \param PostUpdate Expression that must be executed after exit from the 4110 /// OpenMP region with this clause. 4111 static OMPTaskReductionClause * 4112 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 4113 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, 4114 NestedNameSpecifierLoc QualifierLoc, 4115 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates, 4116 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs, 4117 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate); 4118 4119 /// Creates an empty clause with the place for \a N variables. 4120 /// 4121 /// \param C AST context. 4122 /// \param N The number of variables. 4123 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N); 4124 4125 /// Gets location of ':' symbol in clause. 4126 SourceLocation getColonLoc() const { return ColonLoc; } 4127 4128 /// Gets the name info for specified reduction identifier. 4129 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 4130 4131 /// Gets the nested name specifier. 4132 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 4133 4134 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator; 4135 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator; 4136 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>; 4137 using helper_expr_const_range = 4138 llvm::iterator_range<helper_expr_const_iterator>; 4139 4140 helper_expr_const_range privates() const { 4141 return helper_expr_const_range(getPrivates().begin(), getPrivates().end()); 4142 } 4143 4144 helper_expr_range privates() { 4145 return helper_expr_range(getPrivates().begin(), getPrivates().end()); 4146 } 4147 4148 helper_expr_const_range lhs_exprs() const { 4149 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end()); 4150 } 4151 4152 helper_expr_range lhs_exprs() { 4153 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end()); 4154 } 4155 4156 helper_expr_const_range rhs_exprs() const { 4157 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end()); 4158 } 4159 4160 helper_expr_range rhs_exprs() { 4161 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end()); 4162 } 4163 4164 helper_expr_const_range reduction_ops() const { 4165 return helper_expr_const_range(getReductionOps().begin(), 4166 getReductionOps().end()); 4167 } 4168 4169 helper_expr_range reduction_ops() { 4170 return helper_expr_range(getReductionOps().begin(), 4171 getReductionOps().end()); 4172 } 4173 4174 child_range children() { 4175 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 4176 reinterpret_cast<Stmt **>(varlist_end())); 4177 } 4178 4179 const_child_range children() const { 4180 auto Children = const_cast<OMPTaskReductionClause *>(this)->children(); 4181 return const_child_range(Children.begin(), Children.end()); 4182 } 4183 4184 child_range used_children() { 4185 return child_range(child_iterator(), child_iterator()); 4186 } 4187 const_child_range used_children() const { 4188 return const_child_range(const_child_iterator(), const_child_iterator()); 4189 } 4190 4191 static bool classof(const OMPClause *T) { 4192 return T->getClauseKind() == llvm::omp::OMPC_task_reduction; 4193 } 4194 }; 4195 4196 /// This represents clause 'in_reduction' in the '#pragma omp task' directives. 4197 /// 4198 /// \code 4199 /// #pragma omp task in_reduction(+:a,b) 4200 /// \endcode 4201 /// In this example directive '#pragma omp task' has clause 'in_reduction' with 4202 /// operator '+' and the variables 'a' and 'b'. 4203 class OMPInReductionClause final 4204 : public OMPVarListClause<OMPInReductionClause>, 4205 public OMPClauseWithPostUpdate, 4206 private llvm::TrailingObjects<OMPInReductionClause, Expr *> { 4207 friend class OMPClauseReader; 4208 friend OMPVarListClause; 4209 friend TrailingObjects; 4210 4211 /// Location of ':'. 4212 SourceLocation ColonLoc; 4213 4214 /// Nested name specifier for C++. 4215 NestedNameSpecifierLoc QualifierLoc; 4216 4217 /// Name of custom operator. 4218 DeclarationNameInfo NameInfo; 4219 4220 /// Build clause with number of variables \a N. 4221 /// 4222 /// \param StartLoc Starting location of the clause. 4223 /// \param LParenLoc Location of '('. 4224 /// \param EndLoc Ending location of the clause. 4225 /// \param ColonLoc Location of ':'. 4226 /// \param N Number of the variables in the clause. 4227 /// \param QualifierLoc The nested-name qualifier with location information 4228 /// \param NameInfo The full name info for reduction identifier. 4229 OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc, 4230 SourceLocation ColonLoc, SourceLocation EndLoc, 4231 unsigned N, NestedNameSpecifierLoc QualifierLoc, 4232 const DeclarationNameInfo &NameInfo) 4233 : OMPVarListClause<OMPInReductionClause>(llvm::omp::OMPC_in_reduction, 4234 StartLoc, LParenLoc, EndLoc, N), 4235 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc), 4236 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {} 4237 4238 /// Build an empty clause. 4239 /// 4240 /// \param N Number of variables. 4241 explicit OMPInReductionClause(unsigned N) 4242 : OMPVarListClause<OMPInReductionClause>( 4243 llvm::omp::OMPC_in_reduction, SourceLocation(), SourceLocation(), 4244 SourceLocation(), N), 4245 OMPClauseWithPostUpdate(this) {} 4246 4247 /// Sets location of ':' symbol in clause. 4248 void setColonLoc(SourceLocation CL) { ColonLoc = CL; } 4249 4250 /// Sets the name info for specified reduction identifier. 4251 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; } 4252 4253 /// Sets the nested name specifier. 4254 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; } 4255 4256 /// Set list of helper expressions, required for proper codegen of the clause. 4257 /// These expressions represent private copy of the reduction variable. 4258 void setPrivates(ArrayRef<Expr *> Privates); 4259 4260 /// Get the list of helper privates. 4261 MutableArrayRef<Expr *> getPrivates() { 4262 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 4263 } 4264 ArrayRef<const Expr *> getPrivates() const { 4265 return llvm::ArrayRef(varlist_end(), varlist_size()); 4266 } 4267 4268 /// Set list of helper expressions, required for proper codegen of the clause. 4269 /// These expressions represent LHS expression in the final reduction 4270 /// expression performed by the reduction clause. 4271 void setLHSExprs(ArrayRef<Expr *> LHSExprs); 4272 4273 /// Get the list of helper LHS expressions. 4274 MutableArrayRef<Expr *> getLHSExprs() { 4275 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size()); 4276 } 4277 ArrayRef<const Expr *> getLHSExprs() const { 4278 return llvm::ArrayRef(getPrivates().end(), varlist_size()); 4279 } 4280 4281 /// Set list of helper expressions, required for proper codegen of the clause. 4282 /// These expressions represent RHS expression in the final reduction 4283 /// expression performed by the reduction clause. Also, variables in these 4284 /// expressions are used for proper initialization of reduction copies. 4285 void setRHSExprs(ArrayRef<Expr *> RHSExprs); 4286 4287 /// Get the list of helper destination expressions. 4288 MutableArrayRef<Expr *> getRHSExprs() { 4289 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size()); 4290 } 4291 ArrayRef<const Expr *> getRHSExprs() const { 4292 return llvm::ArrayRef(getLHSExprs().end(), varlist_size()); 4293 } 4294 4295 /// Set list of helper reduction expressions, required for proper 4296 /// codegen of the clause. These expressions are binary expressions or 4297 /// operator/custom reduction call that calculates new value from source 4298 /// helper expressions to destination helper expressions. 4299 void setReductionOps(ArrayRef<Expr *> ReductionOps); 4300 4301 /// Get the list of helper reduction expressions. 4302 MutableArrayRef<Expr *> getReductionOps() { 4303 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size()); 4304 } 4305 ArrayRef<const Expr *> getReductionOps() const { 4306 return llvm::ArrayRef(getRHSExprs().end(), varlist_size()); 4307 } 4308 4309 /// Set list of helper reduction taskgroup descriptors. 4310 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps); 4311 4312 /// Get the list of helper reduction taskgroup descriptors. 4313 MutableArrayRef<Expr *> getTaskgroupDescriptors() { 4314 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size()); 4315 } 4316 ArrayRef<const Expr *> getTaskgroupDescriptors() const { 4317 return llvm::ArrayRef(getReductionOps().end(), varlist_size()); 4318 } 4319 4320 public: 4321 /// Creates clause with a list of variables \a VL. 4322 /// 4323 /// \param StartLoc Starting location of the clause. 4324 /// \param LParenLoc Location of '('. 4325 /// \param ColonLoc Location of ':'. 4326 /// \param EndLoc Ending location of the clause. 4327 /// \param VL The variables in the clause. 4328 /// \param QualifierLoc The nested-name qualifier with location information 4329 /// \param NameInfo The full name info for reduction identifier. 4330 /// \param Privates List of helper expressions for proper generation of 4331 /// private copies. 4332 /// \param LHSExprs List of helper expressions for proper generation of 4333 /// assignment operation required for copyprivate clause. This list represents 4334 /// LHSs of the reduction expressions. 4335 /// \param RHSExprs List of helper expressions for proper generation of 4336 /// assignment operation required for copyprivate clause. This list represents 4337 /// RHSs of the reduction expressions. 4338 /// Also, variables in these expressions are used for proper initialization of 4339 /// reduction copies. 4340 /// \param ReductionOps List of helper expressions that represents reduction 4341 /// expressions: 4342 /// \code 4343 /// LHSExprs binop RHSExprs; 4344 /// operator binop(LHSExpr, RHSExpr); 4345 /// <CutomReduction>(LHSExpr, RHSExpr); 4346 /// \endcode 4347 /// Required for proper codegen of final reduction operation performed by the 4348 /// reduction clause. 4349 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for 4350 /// corresponding items in parent taskgroup task_reduction clause. 4351 /// \param PreInit Statement that must be executed before entering the OpenMP 4352 /// region with this clause. 4353 /// \param PostUpdate Expression that must be executed after exit from the 4354 /// OpenMP region with this clause. 4355 static OMPInReductionClause * 4356 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 4357 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, 4358 NestedNameSpecifierLoc QualifierLoc, 4359 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates, 4360 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs, 4361 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors, 4362 Stmt *PreInit, Expr *PostUpdate); 4363 4364 /// Creates an empty clause with the place for \a N variables. 4365 /// 4366 /// \param C AST context. 4367 /// \param N The number of variables. 4368 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N); 4369 4370 /// Gets location of ':' symbol in clause. 4371 SourceLocation getColonLoc() const { return ColonLoc; } 4372 4373 /// Gets the name info for specified reduction identifier. 4374 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 4375 4376 /// Gets the nested name specifier. 4377 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 4378 4379 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator; 4380 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator; 4381 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>; 4382 using helper_expr_const_range = 4383 llvm::iterator_range<helper_expr_const_iterator>; 4384 4385 helper_expr_const_range privates() const { 4386 return helper_expr_const_range(getPrivates().begin(), getPrivates().end()); 4387 } 4388 4389 helper_expr_range privates() { 4390 return helper_expr_range(getPrivates().begin(), getPrivates().end()); 4391 } 4392 4393 helper_expr_const_range lhs_exprs() const { 4394 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end()); 4395 } 4396 4397 helper_expr_range lhs_exprs() { 4398 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end()); 4399 } 4400 4401 helper_expr_const_range rhs_exprs() const { 4402 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end()); 4403 } 4404 4405 helper_expr_range rhs_exprs() { 4406 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end()); 4407 } 4408 4409 helper_expr_const_range reduction_ops() const { 4410 return helper_expr_const_range(getReductionOps().begin(), 4411 getReductionOps().end()); 4412 } 4413 4414 helper_expr_range reduction_ops() { 4415 return helper_expr_range(getReductionOps().begin(), 4416 getReductionOps().end()); 4417 } 4418 4419 helper_expr_const_range taskgroup_descriptors() const { 4420 return helper_expr_const_range(getTaskgroupDescriptors().begin(), 4421 getTaskgroupDescriptors().end()); 4422 } 4423 4424 helper_expr_range taskgroup_descriptors() { 4425 return helper_expr_range(getTaskgroupDescriptors().begin(), 4426 getTaskgroupDescriptors().end()); 4427 } 4428 4429 child_range children() { 4430 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 4431 reinterpret_cast<Stmt **>(varlist_end())); 4432 } 4433 4434 const_child_range children() const { 4435 auto Children = const_cast<OMPInReductionClause *>(this)->children(); 4436 return const_child_range(Children.begin(), Children.end()); 4437 } 4438 4439 child_range used_children() { 4440 return child_range(child_iterator(), child_iterator()); 4441 } 4442 const_child_range used_children() const { 4443 return const_child_range(const_child_iterator(), const_child_iterator()); 4444 } 4445 4446 static bool classof(const OMPClause *T) { 4447 return T->getClauseKind() == llvm::omp::OMPC_in_reduction; 4448 } 4449 }; 4450 4451 /// This represents clause 'linear' in the '#pragma omp ...' 4452 /// directives. 4453 /// 4454 /// \code 4455 /// #pragma omp simd linear(a,b : 2) 4456 /// \endcode 4457 /// In this example directive '#pragma omp simd' has clause 'linear' 4458 /// with variables 'a', 'b' and linear step '2'. 4459 class OMPLinearClause final 4460 : public OMPVarListClause<OMPLinearClause>, 4461 public OMPClauseWithPostUpdate, 4462 private llvm::TrailingObjects<OMPLinearClause, Expr *> { 4463 friend class OMPClauseReader; 4464 friend OMPVarListClause; 4465 friend TrailingObjects; 4466 4467 /// Modifier of 'linear' clause. 4468 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val; 4469 4470 /// Location of linear modifier if any. 4471 SourceLocation ModifierLoc; 4472 4473 /// Location of ':'. 4474 SourceLocation ColonLoc; 4475 4476 /// Location of 'step' modifier. 4477 SourceLocation StepModifierLoc; 4478 4479 /// Sets the linear step for clause. 4480 void setStep(Expr *Step) { *(getFinals().end()) = Step; } 4481 4482 /// Sets the expression to calculate linear step for clause. 4483 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; } 4484 4485 /// Build 'linear' clause with given number of variables \a NumVars. 4486 /// 4487 /// \param StartLoc Starting location of the clause. 4488 /// \param LParenLoc Location of '('. 4489 /// \param ColonLoc Location of ':'. 4490 /// \param StepModifierLoc Location of 'step' modifier. 4491 /// \param EndLoc Ending location of the clause. 4492 /// \param NumVars Number of variables. 4493 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc, 4494 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, 4495 SourceLocation ColonLoc, SourceLocation StepModifierLoc, 4496 SourceLocation EndLoc, unsigned NumVars) 4497 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, StartLoc, 4498 LParenLoc, EndLoc, NumVars), 4499 OMPClauseWithPostUpdate(this), Modifier(Modifier), 4500 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc), 4501 StepModifierLoc(StepModifierLoc) {} 4502 4503 /// Build an empty clause. 4504 /// 4505 /// \param NumVars Number of variables. 4506 explicit OMPLinearClause(unsigned NumVars) 4507 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, 4508 SourceLocation(), SourceLocation(), 4509 SourceLocation(), NumVars), 4510 OMPClauseWithPostUpdate(this) {} 4511 4512 /// Gets the list of initial values for linear variables. 4513 /// 4514 /// There are NumVars expressions with initial values allocated after the 4515 /// varlist, they are followed by NumVars update expressions (used to update 4516 /// the linear variable's value on current iteration) and they are followed by 4517 /// NumVars final expressions (used to calculate the linear variable's 4518 /// value after the loop body). After these lists, there are 2 helper 4519 /// expressions - linear step and a helper to calculate it before the 4520 /// loop body (used when the linear step is not constant): 4521 /// 4522 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[]; 4523 /// Finals[]; Step; CalcStep; } 4524 MutableArrayRef<Expr *> getPrivates() { 4525 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 4526 } 4527 ArrayRef<const Expr *> getPrivates() const { 4528 return llvm::ArrayRef(varlist_end(), varlist_size()); 4529 } 4530 4531 MutableArrayRef<Expr *> getInits() { 4532 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size()); 4533 } 4534 ArrayRef<const Expr *> getInits() const { 4535 return llvm::ArrayRef(getPrivates().end(), varlist_size()); 4536 } 4537 4538 /// Sets the list of update expressions for linear variables. 4539 MutableArrayRef<Expr *> getUpdates() { 4540 return MutableArrayRef<Expr *>(getInits().end(), varlist_size()); 4541 } 4542 ArrayRef<const Expr *> getUpdates() const { 4543 return llvm::ArrayRef(getInits().end(), varlist_size()); 4544 } 4545 4546 /// Sets the list of final update expressions for linear variables. 4547 MutableArrayRef<Expr *> getFinals() { 4548 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size()); 4549 } 4550 ArrayRef<const Expr *> getFinals() const { 4551 return llvm::ArrayRef(getUpdates().end(), varlist_size()); 4552 } 4553 4554 /// Gets the list of used expressions for linear variables. 4555 MutableArrayRef<Expr *> getUsedExprs() { 4556 return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1); 4557 } 4558 ArrayRef<const Expr *> getUsedExprs() const { 4559 return llvm::ArrayRef(getFinals().end() + 2, varlist_size() + 1); 4560 } 4561 4562 /// Sets the list of the copies of original linear variables. 4563 /// \param PL List of expressions. 4564 void setPrivates(ArrayRef<Expr *> PL); 4565 4566 /// Sets the list of the initial values for linear variables. 4567 /// \param IL List of expressions. 4568 void setInits(ArrayRef<Expr *> IL); 4569 4570 public: 4571 /// Creates clause with a list of variables \a VL and a linear step 4572 /// \a Step. 4573 /// 4574 /// \param C AST Context. 4575 /// \param StartLoc Starting location of the clause. 4576 /// \param LParenLoc Location of '('. 4577 /// \param Modifier Modifier of 'linear' clause. 4578 /// \param ModifierLoc Modifier location. 4579 /// \param ColonLoc Location of ':'. 4580 /// \param StepModifierLoc Location of 'step' modifier. 4581 /// \param EndLoc Ending location of the clause. 4582 /// \param VL List of references to the variables. 4583 /// \param PL List of private copies of original variables. 4584 /// \param IL List of initial values for the variables. 4585 /// \param Step Linear step. 4586 /// \param CalcStep Calculation of the linear step. 4587 /// \param PreInit Statement that must be executed before entering the OpenMP 4588 /// region with this clause. 4589 /// \param PostUpdate Expression that must be executed after exit from the 4590 /// OpenMP region with this clause. 4591 static OMPLinearClause * 4592 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 4593 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, 4594 SourceLocation ColonLoc, SourceLocation StepModifierLoc, 4595 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PL, 4596 ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, 4597 Expr *PostUpdate); 4598 4599 /// Creates an empty clause with the place for \a NumVars variables. 4600 /// 4601 /// \param C AST context. 4602 /// \param NumVars Number of variables. 4603 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars); 4604 4605 /// Set modifier. 4606 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; } 4607 4608 /// Return modifier. 4609 OpenMPLinearClauseKind getModifier() const { return Modifier; } 4610 4611 /// Set modifier location. 4612 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; } 4613 4614 /// Return modifier location. 4615 SourceLocation getModifierLoc() const { return ModifierLoc; } 4616 4617 /// Sets the location of ':'. 4618 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 4619 4620 /// Sets the location of 'step' modifier. 4621 void setStepModifierLoc(SourceLocation Loc) { StepModifierLoc = Loc; } 4622 4623 /// Returns the location of ':'. 4624 SourceLocation getColonLoc() const { return ColonLoc; } 4625 4626 /// Returns the location of 'step' modifier. 4627 SourceLocation getStepModifierLoc() const { return StepModifierLoc; } 4628 4629 /// Returns linear step. 4630 Expr *getStep() { return *(getFinals().end()); } 4631 4632 /// Returns linear step. 4633 const Expr *getStep() const { return *(getFinals().end()); } 4634 4635 /// Returns expression to calculate linear step. 4636 Expr *getCalcStep() { return *(getFinals().end() + 1); } 4637 4638 /// Returns expression to calculate linear step. 4639 const Expr *getCalcStep() const { return *(getFinals().end() + 1); } 4640 4641 /// Sets the list of update expressions for linear variables. 4642 /// \param UL List of expressions. 4643 void setUpdates(ArrayRef<Expr *> UL); 4644 4645 /// Sets the list of final update expressions for linear variables. 4646 /// \param FL List of expressions. 4647 void setFinals(ArrayRef<Expr *> FL); 4648 4649 /// Sets the list of used expressions for the linear clause. 4650 void setUsedExprs(ArrayRef<Expr *> UE); 4651 4652 using privates_iterator = MutableArrayRef<Expr *>::iterator; 4653 using privates_const_iterator = ArrayRef<const Expr *>::iterator; 4654 using privates_range = llvm::iterator_range<privates_iterator>; 4655 using privates_const_range = llvm::iterator_range<privates_const_iterator>; 4656 4657 privates_range privates() { 4658 return privates_range(getPrivates().begin(), getPrivates().end()); 4659 } 4660 4661 privates_const_range privates() const { 4662 return privates_const_range(getPrivates().begin(), getPrivates().end()); 4663 } 4664 4665 using inits_iterator = MutableArrayRef<Expr *>::iterator; 4666 using inits_const_iterator = ArrayRef<const Expr *>::iterator; 4667 using inits_range = llvm::iterator_range<inits_iterator>; 4668 using inits_const_range = llvm::iterator_range<inits_const_iterator>; 4669 4670 inits_range inits() { 4671 return inits_range(getInits().begin(), getInits().end()); 4672 } 4673 4674 inits_const_range inits() const { 4675 return inits_const_range(getInits().begin(), getInits().end()); 4676 } 4677 4678 using updates_iterator = MutableArrayRef<Expr *>::iterator; 4679 using updates_const_iterator = ArrayRef<const Expr *>::iterator; 4680 using updates_range = llvm::iterator_range<updates_iterator>; 4681 using updates_const_range = llvm::iterator_range<updates_const_iterator>; 4682 4683 updates_range updates() { 4684 return updates_range(getUpdates().begin(), getUpdates().end()); 4685 } 4686 4687 updates_const_range updates() const { 4688 return updates_const_range(getUpdates().begin(), getUpdates().end()); 4689 } 4690 4691 using finals_iterator = MutableArrayRef<Expr *>::iterator; 4692 using finals_const_iterator = ArrayRef<const Expr *>::iterator; 4693 using finals_range = llvm::iterator_range<finals_iterator>; 4694 using finals_const_range = llvm::iterator_range<finals_const_iterator>; 4695 4696 finals_range finals() { 4697 return finals_range(getFinals().begin(), getFinals().end()); 4698 } 4699 4700 finals_const_range finals() const { 4701 return finals_const_range(getFinals().begin(), getFinals().end()); 4702 } 4703 4704 using used_expressions_iterator = MutableArrayRef<Expr *>::iterator; 4705 using used_expressions_const_iterator = ArrayRef<const Expr *>::iterator; 4706 using used_expressions_range = 4707 llvm::iterator_range<used_expressions_iterator>; 4708 using used_expressions_const_range = 4709 llvm::iterator_range<used_expressions_const_iterator>; 4710 4711 used_expressions_range used_expressions() { 4712 return finals_range(getUsedExprs().begin(), getUsedExprs().end()); 4713 } 4714 4715 used_expressions_const_range used_expressions() const { 4716 return finals_const_range(getUsedExprs().begin(), getUsedExprs().end()); 4717 } 4718 4719 child_range children() { 4720 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 4721 reinterpret_cast<Stmt **>(varlist_end())); 4722 } 4723 4724 const_child_range children() const { 4725 auto Children = const_cast<OMPLinearClause *>(this)->children(); 4726 return const_child_range(Children.begin(), Children.end()); 4727 } 4728 4729 child_range used_children(); 4730 4731 const_child_range used_children() const { 4732 auto Children = const_cast<OMPLinearClause *>(this)->used_children(); 4733 return const_child_range(Children.begin(), Children.end()); 4734 } 4735 4736 static bool classof(const OMPClause *T) { 4737 return T->getClauseKind() == llvm::omp::OMPC_linear; 4738 } 4739 }; 4740 4741 /// This represents clause 'aligned' in the '#pragma omp ...' 4742 /// directives. 4743 /// 4744 /// \code 4745 /// #pragma omp simd aligned(a,b : 8) 4746 /// \endcode 4747 /// In this example directive '#pragma omp simd' has clause 'aligned' 4748 /// with variables 'a', 'b' and alignment '8'. 4749 class OMPAlignedClause final 4750 : public OMPVarListClause<OMPAlignedClause>, 4751 private llvm::TrailingObjects<OMPAlignedClause, Expr *> { 4752 friend class OMPClauseReader; 4753 friend OMPVarListClause; 4754 friend TrailingObjects; 4755 4756 /// Location of ':'. 4757 SourceLocation ColonLoc; 4758 4759 /// Sets the alignment for clause. 4760 void setAlignment(Expr *A) { *varlist_end() = A; } 4761 4762 /// Build 'aligned' clause with given number of variables \a NumVars. 4763 /// 4764 /// \param StartLoc Starting location of the clause. 4765 /// \param LParenLoc Location of '('. 4766 /// \param ColonLoc Location of ':'. 4767 /// \param EndLoc Ending location of the clause. 4768 /// \param NumVars Number of variables. 4769 OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc, 4770 SourceLocation ColonLoc, SourceLocation EndLoc, 4771 unsigned NumVars) 4772 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, StartLoc, 4773 LParenLoc, EndLoc, NumVars), 4774 ColonLoc(ColonLoc) {} 4775 4776 /// Build an empty clause. 4777 /// 4778 /// \param NumVars Number of variables. 4779 explicit OMPAlignedClause(unsigned NumVars) 4780 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, 4781 SourceLocation(), SourceLocation(), 4782 SourceLocation(), NumVars) {} 4783 4784 public: 4785 /// Creates clause with a list of variables \a VL and alignment \a A. 4786 /// 4787 /// \param C AST Context. 4788 /// \param StartLoc Starting location of the clause. 4789 /// \param LParenLoc Location of '('. 4790 /// \param ColonLoc Location of ':'. 4791 /// \param EndLoc Ending location of the clause. 4792 /// \param VL List of references to the variables. 4793 /// \param A Alignment. 4794 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc, 4795 SourceLocation LParenLoc, 4796 SourceLocation ColonLoc, 4797 SourceLocation EndLoc, ArrayRef<Expr *> VL, 4798 Expr *A); 4799 4800 /// Creates an empty clause with the place for \a NumVars variables. 4801 /// 4802 /// \param C AST context. 4803 /// \param NumVars Number of variables. 4804 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars); 4805 4806 /// Sets the location of ':'. 4807 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 4808 4809 /// Returns the location of ':'. 4810 SourceLocation getColonLoc() const { return ColonLoc; } 4811 4812 /// Returns alignment. 4813 Expr *getAlignment() { return *varlist_end(); } 4814 4815 /// Returns alignment. 4816 const Expr *getAlignment() const { return *varlist_end(); } 4817 4818 child_range children() { 4819 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 4820 reinterpret_cast<Stmt **>(varlist_end())); 4821 } 4822 4823 const_child_range children() const { 4824 auto Children = const_cast<OMPAlignedClause *>(this)->children(); 4825 return const_child_range(Children.begin(), Children.end()); 4826 } 4827 4828 child_range used_children() { 4829 return child_range(child_iterator(), child_iterator()); 4830 } 4831 const_child_range used_children() const { 4832 return const_child_range(const_child_iterator(), const_child_iterator()); 4833 } 4834 4835 static bool classof(const OMPClause *T) { 4836 return T->getClauseKind() == llvm::omp::OMPC_aligned; 4837 } 4838 }; 4839 4840 /// This represents clause 'copyin' in the '#pragma omp ...' directives. 4841 /// 4842 /// \code 4843 /// #pragma omp parallel copyin(a,b) 4844 /// \endcode 4845 /// In this example directive '#pragma omp parallel' has clause 'copyin' 4846 /// with the variables 'a' and 'b'. 4847 class OMPCopyinClause final 4848 : public OMPVarListClause<OMPCopyinClause>, 4849 private llvm::TrailingObjects<OMPCopyinClause, Expr *> { 4850 // Class has 3 additional tail allocated arrays: 4851 // 1. List of helper expressions for proper generation of assignment operation 4852 // required for copyin clause. This list represents sources. 4853 // 2. List of helper expressions for proper generation of assignment operation 4854 // required for copyin clause. This list represents destinations. 4855 // 3. List of helper expressions that represents assignment operation: 4856 // \code 4857 // DstExprs = SrcExprs; 4858 // \endcode 4859 // Required for proper codegen of propagation of master's thread values of 4860 // threadprivate variables to local instances of that variables in other 4861 // implicit threads. 4862 4863 friend class OMPClauseReader; 4864 friend OMPVarListClause; 4865 friend TrailingObjects; 4866 4867 /// Build clause with number of variables \a N. 4868 /// 4869 /// \param StartLoc Starting location of the clause. 4870 /// \param LParenLoc Location of '('. 4871 /// \param EndLoc Ending location of the clause. 4872 /// \param N Number of the variables in the clause. 4873 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc, 4874 SourceLocation EndLoc, unsigned N) 4875 : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin, StartLoc, 4876 LParenLoc, EndLoc, N) {} 4877 4878 /// Build an empty clause. 4879 /// 4880 /// \param N Number of variables. 4881 explicit OMPCopyinClause(unsigned N) 4882 : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin, 4883 SourceLocation(), SourceLocation(), 4884 SourceLocation(), N) {} 4885 4886 /// Set list of helper expressions, required for proper codegen of the 4887 /// clause. These expressions represent source expression in the final 4888 /// assignment statement performed by the copyin clause. 4889 void setSourceExprs(ArrayRef<Expr *> SrcExprs); 4890 4891 /// Get the list of helper source expressions. 4892 MutableArrayRef<Expr *> getSourceExprs() { 4893 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 4894 } 4895 ArrayRef<const Expr *> getSourceExprs() const { 4896 return llvm::ArrayRef(varlist_end(), varlist_size()); 4897 } 4898 4899 /// Set list of helper expressions, required for proper codegen of the 4900 /// clause. These expressions represent destination expression in the final 4901 /// assignment statement performed by the copyin clause. 4902 void setDestinationExprs(ArrayRef<Expr *> DstExprs); 4903 4904 /// Get the list of helper destination expressions. 4905 MutableArrayRef<Expr *> getDestinationExprs() { 4906 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size()); 4907 } 4908 ArrayRef<const Expr *> getDestinationExprs() const { 4909 return llvm::ArrayRef(getSourceExprs().end(), varlist_size()); 4910 } 4911 4912 /// Set list of helper assignment expressions, required for proper 4913 /// codegen of the clause. These expressions are assignment expressions that 4914 /// assign source helper expressions to destination helper expressions 4915 /// correspondingly. 4916 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps); 4917 4918 /// Get the list of helper assignment expressions. 4919 MutableArrayRef<Expr *> getAssignmentOps() { 4920 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size()); 4921 } 4922 ArrayRef<const Expr *> getAssignmentOps() const { 4923 return llvm::ArrayRef(getDestinationExprs().end(), varlist_size()); 4924 } 4925 4926 public: 4927 /// Creates clause with a list of variables \a VL. 4928 /// 4929 /// \param C AST context. 4930 /// \param StartLoc Starting location of the clause. 4931 /// \param LParenLoc Location of '('. 4932 /// \param EndLoc Ending location of the clause. 4933 /// \param VL List of references to the variables. 4934 /// \param SrcExprs List of helper expressions for proper generation of 4935 /// assignment operation required for copyin clause. This list represents 4936 /// sources. 4937 /// \param DstExprs List of helper expressions for proper generation of 4938 /// assignment operation required for copyin clause. This list represents 4939 /// destinations. 4940 /// \param AssignmentOps List of helper expressions that represents assignment 4941 /// operation: 4942 /// \code 4943 /// DstExprs = SrcExprs; 4944 /// \endcode 4945 /// Required for proper codegen of propagation of master's thread values of 4946 /// threadprivate variables to local instances of that variables in other 4947 /// implicit threads. 4948 static OMPCopyinClause * 4949 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 4950 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 4951 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps); 4952 4953 /// Creates an empty clause with \a N variables. 4954 /// 4955 /// \param C AST context. 4956 /// \param N The number of variables. 4957 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N); 4958 4959 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator; 4960 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator; 4961 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>; 4962 using helper_expr_const_range = 4963 llvm::iterator_range<helper_expr_const_iterator>; 4964 4965 helper_expr_const_range source_exprs() const { 4966 return helper_expr_const_range(getSourceExprs().begin(), 4967 getSourceExprs().end()); 4968 } 4969 4970 helper_expr_range source_exprs() { 4971 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end()); 4972 } 4973 4974 helper_expr_const_range destination_exprs() const { 4975 return helper_expr_const_range(getDestinationExprs().begin(), 4976 getDestinationExprs().end()); 4977 } 4978 4979 helper_expr_range destination_exprs() { 4980 return helper_expr_range(getDestinationExprs().begin(), 4981 getDestinationExprs().end()); 4982 } 4983 4984 helper_expr_const_range assignment_ops() const { 4985 return helper_expr_const_range(getAssignmentOps().begin(), 4986 getAssignmentOps().end()); 4987 } 4988 4989 helper_expr_range assignment_ops() { 4990 return helper_expr_range(getAssignmentOps().begin(), 4991 getAssignmentOps().end()); 4992 } 4993 4994 child_range children() { 4995 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 4996 reinterpret_cast<Stmt **>(varlist_end())); 4997 } 4998 4999 const_child_range children() const { 5000 auto Children = const_cast<OMPCopyinClause *>(this)->children(); 5001 return const_child_range(Children.begin(), Children.end()); 5002 } 5003 5004 child_range used_children() { 5005 return child_range(child_iterator(), child_iterator()); 5006 } 5007 const_child_range used_children() const { 5008 return const_child_range(const_child_iterator(), const_child_iterator()); 5009 } 5010 5011 static bool classof(const OMPClause *T) { 5012 return T->getClauseKind() == llvm::omp::OMPC_copyin; 5013 } 5014 }; 5015 5016 /// This represents clause 'copyprivate' in the '#pragma omp ...' 5017 /// directives. 5018 /// 5019 /// \code 5020 /// #pragma omp single copyprivate(a,b) 5021 /// \endcode 5022 /// In this example directive '#pragma omp single' has clause 'copyprivate' 5023 /// with the variables 'a' and 'b'. 5024 class OMPCopyprivateClause final 5025 : public OMPVarListClause<OMPCopyprivateClause>, 5026 private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> { 5027 friend class OMPClauseReader; 5028 friend OMPVarListClause; 5029 friend TrailingObjects; 5030 5031 /// Build clause with number of variables \a N. 5032 /// 5033 /// \param StartLoc Starting location of the clause. 5034 /// \param LParenLoc Location of '('. 5035 /// \param EndLoc Ending location of the clause. 5036 /// \param N Number of the variables in the clause. 5037 OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc, 5038 SourceLocation EndLoc, unsigned N) 5039 : OMPVarListClause<OMPCopyprivateClause>(llvm::omp::OMPC_copyprivate, 5040 StartLoc, LParenLoc, EndLoc, N) { 5041 } 5042 5043 /// Build an empty clause. 5044 /// 5045 /// \param N Number of variables. 5046 explicit OMPCopyprivateClause(unsigned N) 5047 : OMPVarListClause<OMPCopyprivateClause>( 5048 llvm::omp::OMPC_copyprivate, SourceLocation(), SourceLocation(), 5049 SourceLocation(), N) {} 5050 5051 /// Set list of helper expressions, required for proper codegen of the 5052 /// clause. These expressions represent source expression in the final 5053 /// assignment statement performed by the copyprivate clause. 5054 void setSourceExprs(ArrayRef<Expr *> SrcExprs); 5055 5056 /// Get the list of helper source expressions. 5057 MutableArrayRef<Expr *> getSourceExprs() { 5058 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 5059 } 5060 ArrayRef<const Expr *> getSourceExprs() const { 5061 return llvm::ArrayRef(varlist_end(), varlist_size()); 5062 } 5063 5064 /// Set list of helper expressions, required for proper codegen of the 5065 /// clause. These expressions represent destination expression in the final 5066 /// assignment statement performed by the copyprivate clause. 5067 void setDestinationExprs(ArrayRef<Expr *> DstExprs); 5068 5069 /// Get the list of helper destination expressions. 5070 MutableArrayRef<Expr *> getDestinationExprs() { 5071 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size()); 5072 } 5073 ArrayRef<const Expr *> getDestinationExprs() const { 5074 return llvm::ArrayRef(getSourceExprs().end(), varlist_size()); 5075 } 5076 5077 /// Set list of helper assignment expressions, required for proper 5078 /// codegen of the clause. These expressions are assignment expressions that 5079 /// assign source helper expressions to destination helper expressions 5080 /// correspondingly. 5081 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps); 5082 5083 /// Get the list of helper assignment expressions. 5084 MutableArrayRef<Expr *> getAssignmentOps() { 5085 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size()); 5086 } 5087 ArrayRef<const Expr *> getAssignmentOps() const { 5088 return llvm::ArrayRef(getDestinationExprs().end(), varlist_size()); 5089 } 5090 5091 public: 5092 /// Creates clause with a list of variables \a VL. 5093 /// 5094 /// \param C AST context. 5095 /// \param StartLoc Starting location of the clause. 5096 /// \param LParenLoc Location of '('. 5097 /// \param EndLoc Ending location of the clause. 5098 /// \param VL List of references to the variables. 5099 /// \param SrcExprs List of helper expressions for proper generation of 5100 /// assignment operation required for copyprivate clause. This list represents 5101 /// sources. 5102 /// \param DstExprs List of helper expressions for proper generation of 5103 /// assignment operation required for copyprivate clause. This list represents 5104 /// destinations. 5105 /// \param AssignmentOps List of helper expressions that represents assignment 5106 /// operation: 5107 /// \code 5108 /// DstExprs = SrcExprs; 5109 /// \endcode 5110 /// Required for proper codegen of final assignment performed by the 5111 /// copyprivate clause. 5112 static OMPCopyprivateClause * 5113 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 5114 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 5115 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps); 5116 5117 /// Creates an empty clause with \a N variables. 5118 /// 5119 /// \param C AST context. 5120 /// \param N The number of variables. 5121 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N); 5122 5123 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator; 5124 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator; 5125 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>; 5126 using helper_expr_const_range = 5127 llvm::iterator_range<helper_expr_const_iterator>; 5128 5129 helper_expr_const_range source_exprs() const { 5130 return helper_expr_const_range(getSourceExprs().begin(), 5131 getSourceExprs().end()); 5132 } 5133 5134 helper_expr_range source_exprs() { 5135 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end()); 5136 } 5137 5138 helper_expr_const_range destination_exprs() const { 5139 return helper_expr_const_range(getDestinationExprs().begin(), 5140 getDestinationExprs().end()); 5141 } 5142 5143 helper_expr_range destination_exprs() { 5144 return helper_expr_range(getDestinationExprs().begin(), 5145 getDestinationExprs().end()); 5146 } 5147 5148 helper_expr_const_range assignment_ops() const { 5149 return helper_expr_const_range(getAssignmentOps().begin(), 5150 getAssignmentOps().end()); 5151 } 5152 5153 helper_expr_range assignment_ops() { 5154 return helper_expr_range(getAssignmentOps().begin(), 5155 getAssignmentOps().end()); 5156 } 5157 5158 child_range children() { 5159 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 5160 reinterpret_cast<Stmt **>(varlist_end())); 5161 } 5162 5163 const_child_range children() const { 5164 auto Children = const_cast<OMPCopyprivateClause *>(this)->children(); 5165 return const_child_range(Children.begin(), Children.end()); 5166 } 5167 5168 child_range used_children() { 5169 return child_range(child_iterator(), child_iterator()); 5170 } 5171 const_child_range used_children() const { 5172 return const_child_range(const_child_iterator(), const_child_iterator()); 5173 } 5174 5175 static bool classof(const OMPClause *T) { 5176 return T->getClauseKind() == llvm::omp::OMPC_copyprivate; 5177 } 5178 }; 5179 5180 /// This represents implicit clause 'flush' for the '#pragma omp flush' 5181 /// directive. 5182 /// This clause does not exist by itself, it can be only as a part of 'omp 5183 /// flush' directive. This clause is introduced to keep the original structure 5184 /// of \a OMPExecutableDirective class and its derivatives and to use the 5185 /// existing infrastructure of clauses with the list of variables. 5186 /// 5187 /// \code 5188 /// #pragma omp flush(a,b) 5189 /// \endcode 5190 /// In this example directive '#pragma omp flush' has implicit clause 'flush' 5191 /// with the variables 'a' and 'b'. 5192 class OMPFlushClause final 5193 : public OMPVarListClause<OMPFlushClause>, 5194 private llvm::TrailingObjects<OMPFlushClause, Expr *> { 5195 friend OMPVarListClause; 5196 friend TrailingObjects; 5197 5198 /// Build clause with number of variables \a N. 5199 /// 5200 /// \param StartLoc Starting location of the clause. 5201 /// \param LParenLoc Location of '('. 5202 /// \param EndLoc Ending location of the clause. 5203 /// \param N Number of the variables in the clause. 5204 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc, 5205 SourceLocation EndLoc, unsigned N) 5206 : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush, StartLoc, 5207 LParenLoc, EndLoc, N) {} 5208 5209 /// Build an empty clause. 5210 /// 5211 /// \param N Number of variables. 5212 explicit OMPFlushClause(unsigned N) 5213 : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush, 5214 SourceLocation(), SourceLocation(), 5215 SourceLocation(), N) {} 5216 5217 public: 5218 /// Creates clause with a list of variables \a VL. 5219 /// 5220 /// \param C AST context. 5221 /// \param StartLoc Starting location of the clause. 5222 /// \param LParenLoc Location of '('. 5223 /// \param EndLoc Ending location of the clause. 5224 /// \param VL List of references to the variables. 5225 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc, 5226 SourceLocation LParenLoc, SourceLocation EndLoc, 5227 ArrayRef<Expr *> VL); 5228 5229 /// Creates an empty clause with \a N variables. 5230 /// 5231 /// \param C AST context. 5232 /// \param N The number of variables. 5233 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N); 5234 5235 child_range children() { 5236 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 5237 reinterpret_cast<Stmt **>(varlist_end())); 5238 } 5239 5240 const_child_range children() const { 5241 auto Children = const_cast<OMPFlushClause *>(this)->children(); 5242 return const_child_range(Children.begin(), Children.end()); 5243 } 5244 5245 child_range used_children() { 5246 return child_range(child_iterator(), child_iterator()); 5247 } 5248 const_child_range used_children() const { 5249 return const_child_range(const_child_iterator(), const_child_iterator()); 5250 } 5251 5252 static bool classof(const OMPClause *T) { 5253 return T->getClauseKind() == llvm::omp::OMPC_flush; 5254 } 5255 }; 5256 5257 /// This represents implicit clause 'depobj' for the '#pragma omp depobj' 5258 /// directive. 5259 /// This clause does not exist by itself, it can be only as a part of 'omp 5260 /// depobj' directive. This clause is introduced to keep the original structure 5261 /// of \a OMPExecutableDirective class and its derivatives and to use the 5262 /// existing infrastructure of clauses with the list of variables. 5263 /// 5264 /// \code 5265 /// #pragma omp depobj(a) destroy 5266 /// \endcode 5267 /// In this example directive '#pragma omp depobj' has implicit clause 'depobj' 5268 /// with the depobj 'a'. 5269 class OMPDepobjClause final : public OMPClause { 5270 friend class OMPClauseReader; 5271 5272 /// Location of '('. 5273 SourceLocation LParenLoc; 5274 5275 /// Chunk size. 5276 Expr *Depobj = nullptr; 5277 5278 /// Build clause with number of variables \a N. 5279 /// 5280 /// \param StartLoc Starting location of the clause. 5281 /// \param LParenLoc Location of '('. 5282 /// \param EndLoc Ending location of the clause. 5283 OMPDepobjClause(SourceLocation StartLoc, SourceLocation LParenLoc, 5284 SourceLocation EndLoc) 5285 : OMPClause(llvm::omp::OMPC_depobj, StartLoc, EndLoc), 5286 LParenLoc(LParenLoc) {} 5287 5288 /// Build an empty clause. 5289 /// 5290 explicit OMPDepobjClause() 5291 : OMPClause(llvm::omp::OMPC_depobj, SourceLocation(), SourceLocation()) {} 5292 5293 void setDepobj(Expr *E) { Depobj = E; } 5294 5295 /// Sets the location of '('. 5296 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 5297 5298 public: 5299 /// Creates clause. 5300 /// 5301 /// \param C AST context. 5302 /// \param StartLoc Starting location of the clause. 5303 /// \param LParenLoc Location of '('. 5304 /// \param EndLoc Ending location of the clause. 5305 /// \param Depobj depobj expression associated with the 'depobj' directive. 5306 static OMPDepobjClause *Create(const ASTContext &C, SourceLocation StartLoc, 5307 SourceLocation LParenLoc, 5308 SourceLocation EndLoc, Expr *Depobj); 5309 5310 /// Creates an empty clause. 5311 /// 5312 /// \param C AST context. 5313 static OMPDepobjClause *CreateEmpty(const ASTContext &C); 5314 5315 /// Returns depobj expression associated with the clause. 5316 Expr *getDepobj() { return Depobj; } 5317 const Expr *getDepobj() const { return Depobj; } 5318 5319 /// Returns the location of '('. 5320 SourceLocation getLParenLoc() const { return LParenLoc; } 5321 5322 child_range children() { 5323 return child_range(reinterpret_cast<Stmt **>(&Depobj), 5324 reinterpret_cast<Stmt **>(&Depobj) + 1); 5325 } 5326 5327 const_child_range children() const { 5328 auto Children = const_cast<OMPDepobjClause *>(this)->children(); 5329 return const_child_range(Children.begin(), Children.end()); 5330 } 5331 5332 child_range used_children() { 5333 return child_range(child_iterator(), child_iterator()); 5334 } 5335 const_child_range used_children() const { 5336 return const_child_range(const_child_iterator(), const_child_iterator()); 5337 } 5338 5339 static bool classof(const OMPClause *T) { 5340 return T->getClauseKind() == llvm::omp::OMPC_depobj; 5341 } 5342 }; 5343 5344 /// This represents implicit clause 'depend' for the '#pragma omp task' 5345 /// directive. 5346 /// 5347 /// \code 5348 /// #pragma omp task depend(in:a,b) 5349 /// \endcode 5350 /// In this example directive '#pragma omp task' with clause 'depend' with the 5351 /// variables 'a' and 'b' with dependency 'in'. 5352 class OMPDependClause final 5353 : public OMPVarListClause<OMPDependClause>, 5354 private llvm::TrailingObjects<OMPDependClause, Expr *> { 5355 friend class OMPClauseReader; 5356 friend OMPVarListClause; 5357 friend TrailingObjects; 5358 5359 public: 5360 struct DependDataTy final { 5361 /// Dependency type (one of in, out, inout). 5362 OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown; 5363 5364 /// Dependency type location. 5365 SourceLocation DepLoc; 5366 5367 /// Colon location. 5368 SourceLocation ColonLoc; 5369 5370 /// Location of 'omp_all_memory'. 5371 SourceLocation OmpAllMemoryLoc; 5372 }; 5373 5374 private: 5375 /// Dependency type and source locations. 5376 DependDataTy Data; 5377 5378 /// Number of loops, associated with the depend clause. 5379 unsigned NumLoops = 0; 5380 5381 /// Build clause with number of variables \a N. 5382 /// 5383 /// \param StartLoc Starting location of the clause. 5384 /// \param LParenLoc Location of '('. 5385 /// \param EndLoc Ending location of the clause. 5386 /// \param N Number of the variables in the clause. 5387 /// \param NumLoops Number of loops that is associated with this depend 5388 /// clause. 5389 OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc, 5390 SourceLocation EndLoc, unsigned N, unsigned NumLoops) 5391 : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend, StartLoc, 5392 LParenLoc, EndLoc, N), 5393 NumLoops(NumLoops) {} 5394 5395 /// Build an empty clause. 5396 /// 5397 /// \param N Number of variables. 5398 /// \param NumLoops Number of loops that is associated with this depend 5399 /// clause. 5400 explicit OMPDependClause(unsigned N, unsigned NumLoops) 5401 : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend, 5402 SourceLocation(), SourceLocation(), 5403 SourceLocation(), N), 5404 NumLoops(NumLoops) {} 5405 5406 /// Set dependency kind. 5407 void setDependencyKind(OpenMPDependClauseKind K) { Data.DepKind = K; } 5408 5409 /// Set dependency kind and its location. 5410 void setDependencyLoc(SourceLocation Loc) { Data.DepLoc = Loc; } 5411 5412 /// Set colon location. 5413 void setColonLoc(SourceLocation Loc) { Data.ColonLoc = Loc; } 5414 5415 /// Set the 'omp_all_memory' location. 5416 void setOmpAllMemoryLoc(SourceLocation Loc) { Data.OmpAllMemoryLoc = Loc; } 5417 5418 /// Sets optional dependency modifier. 5419 void setModifier(Expr *DepModifier); 5420 5421 public: 5422 /// Creates clause with a list of variables \a VL. 5423 /// 5424 /// \param C AST context. 5425 /// \param StartLoc Starting location of the clause. 5426 /// \param LParenLoc Location of '('. 5427 /// \param EndLoc Ending location of the clause. 5428 /// \param Data Dependency type and source locations. 5429 /// \param VL List of references to the variables. 5430 /// \param NumLoops Number of loops that is associated with this depend 5431 /// clause. 5432 static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc, 5433 SourceLocation LParenLoc, 5434 SourceLocation EndLoc, DependDataTy Data, 5435 Expr *DepModifier, ArrayRef<Expr *> VL, 5436 unsigned NumLoops); 5437 5438 /// Creates an empty clause with \a N variables. 5439 /// 5440 /// \param C AST context. 5441 /// \param N The number of variables. 5442 /// \param NumLoops Number of loops that is associated with this depend 5443 /// clause. 5444 static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N, 5445 unsigned NumLoops); 5446 5447 /// Get dependency type. 5448 OpenMPDependClauseKind getDependencyKind() const { return Data.DepKind; } 5449 5450 /// Get dependency type location. 5451 SourceLocation getDependencyLoc() const { return Data.DepLoc; } 5452 5453 /// Get colon location. 5454 SourceLocation getColonLoc() const { return Data.ColonLoc; } 5455 5456 /// Get 'omp_all_memory' location. 5457 SourceLocation getOmpAllMemoryLoc() const { return Data.OmpAllMemoryLoc; } 5458 5459 /// Return optional depend modifier. 5460 Expr *getModifier(); 5461 const Expr *getModifier() const { 5462 return const_cast<OMPDependClause *>(this)->getModifier(); 5463 } 5464 5465 /// Get number of loops associated with the clause. 5466 unsigned getNumLoops() const { return NumLoops; } 5467 5468 /// Set the loop data for the depend clauses with 'sink|source' kind of 5469 /// dependency. 5470 void setLoopData(unsigned NumLoop, Expr *Cnt); 5471 5472 /// Get the loop data. 5473 Expr *getLoopData(unsigned NumLoop); 5474 const Expr *getLoopData(unsigned NumLoop) const; 5475 5476 child_range children() { 5477 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 5478 reinterpret_cast<Stmt **>(varlist_end())); 5479 } 5480 5481 const_child_range children() const { 5482 auto Children = const_cast<OMPDependClause *>(this)->children(); 5483 return const_child_range(Children.begin(), Children.end()); 5484 } 5485 5486 child_range used_children() { 5487 return child_range(child_iterator(), child_iterator()); 5488 } 5489 const_child_range used_children() const { 5490 return const_child_range(const_child_iterator(), const_child_iterator()); 5491 } 5492 5493 static bool classof(const OMPClause *T) { 5494 return T->getClauseKind() == llvm::omp::OMPC_depend; 5495 } 5496 }; 5497 5498 /// This represents 'device' clause in the '#pragma omp ...' 5499 /// directive. 5500 /// 5501 /// \code 5502 /// #pragma omp target device(a) 5503 /// \endcode 5504 /// In this example directive '#pragma omp target' has clause 'device' 5505 /// with single expression 'a'. 5506 class OMPDeviceClause : public OMPClause, public OMPClauseWithPreInit { 5507 friend class OMPClauseReader; 5508 5509 /// Location of '('. 5510 SourceLocation LParenLoc; 5511 5512 /// Device clause modifier. 5513 OpenMPDeviceClauseModifier Modifier = OMPC_DEVICE_unknown; 5514 5515 /// Location of the modifier. 5516 SourceLocation ModifierLoc; 5517 5518 /// Device number. 5519 Stmt *Device = nullptr; 5520 5521 /// Set the device number. 5522 /// 5523 /// \param E Device number. 5524 void setDevice(Expr *E) { Device = E; } 5525 5526 /// Sets modifier. 5527 void setModifier(OpenMPDeviceClauseModifier M) { Modifier = M; } 5528 5529 /// Setst modifier location. 5530 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; } 5531 5532 public: 5533 /// Build 'device' clause. 5534 /// 5535 /// \param Modifier Clause modifier. 5536 /// \param E Expression associated with this clause. 5537 /// \param CaptureRegion Innermost OpenMP region where expressions in this 5538 /// clause must be captured. 5539 /// \param StartLoc Starting location of the clause. 5540 /// \param ModifierLoc Modifier location. 5541 /// \param LParenLoc Location of '('. 5542 /// \param EndLoc Ending location of the clause. 5543 OMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *E, Stmt *HelperE, 5544 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, 5545 SourceLocation LParenLoc, SourceLocation ModifierLoc, 5546 SourceLocation EndLoc) 5547 : OMPClause(llvm::omp::OMPC_device, StartLoc, EndLoc), 5548 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier), 5549 ModifierLoc(ModifierLoc), Device(E) { 5550 setPreInitStmt(HelperE, CaptureRegion); 5551 } 5552 5553 /// Build an empty clause. 5554 OMPDeviceClause() 5555 : OMPClause(llvm::omp::OMPC_device, SourceLocation(), SourceLocation()), 5556 OMPClauseWithPreInit(this) {} 5557 5558 /// Sets the location of '('. 5559 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 5560 5561 /// Returns the location of '('. 5562 SourceLocation getLParenLoc() const { return LParenLoc; } 5563 5564 /// Return device number. 5565 Expr *getDevice() { return cast<Expr>(Device); } 5566 5567 /// Return device number. 5568 Expr *getDevice() const { return cast<Expr>(Device); } 5569 5570 /// Gets modifier. 5571 OpenMPDeviceClauseModifier getModifier() const { return Modifier; } 5572 5573 /// Gets modifier location. 5574 SourceLocation getModifierLoc() const { return ModifierLoc; } 5575 5576 child_range children() { return child_range(&Device, &Device + 1); } 5577 5578 const_child_range children() const { 5579 return const_child_range(&Device, &Device + 1); 5580 } 5581 5582 child_range used_children() { 5583 return child_range(child_iterator(), child_iterator()); 5584 } 5585 const_child_range used_children() const { 5586 return const_child_range(const_child_iterator(), const_child_iterator()); 5587 } 5588 5589 static bool classof(const OMPClause *T) { 5590 return T->getClauseKind() == llvm::omp::OMPC_device; 5591 } 5592 }; 5593 5594 /// This represents 'threads' clause in the '#pragma omp ...' directive. 5595 /// 5596 /// \code 5597 /// #pragma omp ordered threads 5598 /// \endcode 5599 /// In this example directive '#pragma omp ordered' has simple 'threads' clause. 5600 class OMPThreadsClause final 5601 : public OMPNoChildClause<llvm::omp::OMPC_threads> { 5602 public: 5603 /// Build 'threads' clause. 5604 /// 5605 /// \param StartLoc Starting location of the clause. 5606 /// \param EndLoc Ending location of the clause. 5607 OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc) 5608 : OMPNoChildClause(StartLoc, EndLoc) {} 5609 5610 /// Build an empty clause. 5611 OMPThreadsClause() : OMPNoChildClause() {} 5612 }; 5613 5614 /// This represents 'simd' clause in the '#pragma omp ...' directive. 5615 /// 5616 /// \code 5617 /// #pragma omp ordered simd 5618 /// \endcode 5619 /// In this example directive '#pragma omp ordered' has simple 'simd' clause. 5620 class OMPSIMDClause : public OMPClause { 5621 public: 5622 /// Build 'simd' clause. 5623 /// 5624 /// \param StartLoc Starting location of the clause. 5625 /// \param EndLoc Ending location of the clause. 5626 OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc) 5627 : OMPClause(llvm::omp::OMPC_simd, StartLoc, EndLoc) {} 5628 5629 /// Build an empty clause. 5630 OMPSIMDClause() 5631 : OMPClause(llvm::omp::OMPC_simd, SourceLocation(), SourceLocation()) {} 5632 5633 child_range children() { 5634 return child_range(child_iterator(), child_iterator()); 5635 } 5636 5637 const_child_range children() const { 5638 return const_child_range(const_child_iterator(), const_child_iterator()); 5639 } 5640 5641 child_range used_children() { 5642 return child_range(child_iterator(), child_iterator()); 5643 } 5644 const_child_range used_children() const { 5645 return const_child_range(const_child_iterator(), const_child_iterator()); 5646 } 5647 5648 static bool classof(const OMPClause *T) { 5649 return T->getClauseKind() == llvm::omp::OMPC_simd; 5650 } 5651 }; 5652 5653 /// Struct that defines common infrastructure to handle mappable 5654 /// expressions used in OpenMP clauses. 5655 class OMPClauseMappableExprCommon { 5656 public: 5657 /// Class that represents a component of a mappable expression. E.g. 5658 /// for an expression S.a, the first component is a declaration reference 5659 /// expression associated with 'S' and the second is a member expression 5660 /// associated with the field declaration 'a'. If the expression is an array 5661 /// subscript it may not have any associated declaration. In that case the 5662 /// associated declaration is set to nullptr. 5663 class MappableComponent { 5664 /// Pair of Expression and Non-contiguous pair associated with the 5665 /// component. 5666 llvm::PointerIntPair<Expr *, 1, bool> AssociatedExpressionNonContiguousPr; 5667 5668 /// Declaration associated with the declaration. If the component does 5669 /// not have a declaration (e.g. array subscripts or section), this is set 5670 /// to nullptr. 5671 ValueDecl *AssociatedDeclaration = nullptr; 5672 5673 public: 5674 explicit MappableComponent() = default; 5675 explicit MappableComponent(Expr *AssociatedExpression, 5676 ValueDecl *AssociatedDeclaration, 5677 bool IsNonContiguous) 5678 : AssociatedExpressionNonContiguousPr(AssociatedExpression, 5679 IsNonContiguous), 5680 AssociatedDeclaration( 5681 AssociatedDeclaration 5682 ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl()) 5683 : nullptr) {} 5684 5685 Expr *getAssociatedExpression() const { 5686 return AssociatedExpressionNonContiguousPr.getPointer(); 5687 } 5688 5689 bool isNonContiguous() const { 5690 return AssociatedExpressionNonContiguousPr.getInt(); 5691 } 5692 5693 ValueDecl *getAssociatedDeclaration() const { 5694 return AssociatedDeclaration; 5695 } 5696 }; 5697 5698 // List of components of an expression. This first one is the whole 5699 // expression and the last one is the base expression. 5700 using MappableExprComponentList = SmallVector<MappableComponent, 8>; 5701 using MappableExprComponentListRef = ArrayRef<MappableComponent>; 5702 5703 // List of all component lists associated to the same base declaration. 5704 // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have 5705 // their component list but the same base declaration 'S'. 5706 using MappableExprComponentLists = SmallVector<MappableExprComponentList, 8>; 5707 using MappableExprComponentListsRef = ArrayRef<MappableExprComponentList>; 5708 5709 protected: 5710 // Return the total number of elements in a list of component lists. 5711 static unsigned 5712 getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists); 5713 5714 // Return the total number of elements in a list of declarations. All 5715 // declarations are expected to be canonical. 5716 static unsigned 5717 getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations); 5718 }; 5719 5720 /// This structure contains all sizes needed for by an 5721 /// OMPMappableExprListClause. 5722 struct OMPMappableExprListSizeTy { 5723 /// Number of expressions listed. 5724 unsigned NumVars; 5725 /// Number of unique base declarations. 5726 unsigned NumUniqueDeclarations; 5727 /// Number of component lists. 5728 unsigned NumComponentLists; 5729 /// Total number of expression components. 5730 unsigned NumComponents; 5731 OMPMappableExprListSizeTy() = default; 5732 OMPMappableExprListSizeTy(unsigned NumVars, unsigned NumUniqueDeclarations, 5733 unsigned NumComponentLists, unsigned NumComponents) 5734 : NumVars(NumVars), NumUniqueDeclarations(NumUniqueDeclarations), 5735 NumComponentLists(NumComponentLists), NumComponents(NumComponents) {} 5736 }; 5737 5738 /// This represents clauses with a list of expressions that are mappable. 5739 /// Examples of these clauses are 'map' in 5740 /// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from 5741 /// in '#pragma omp target update...' directives. 5742 template <class T> 5743 class OMPMappableExprListClause : public OMPVarListClause<T>, 5744 public OMPClauseMappableExprCommon { 5745 friend class OMPClauseReader; 5746 5747 /// Number of unique declarations in this clause. 5748 unsigned NumUniqueDeclarations; 5749 5750 /// Number of component lists in this clause. 5751 unsigned NumComponentLists; 5752 5753 /// Total number of components in this clause. 5754 unsigned NumComponents; 5755 5756 /// Whether this clause is possible to have user-defined mappers associated. 5757 /// It should be true for map, to, and from clauses, and false for 5758 /// use_device_ptr and is_device_ptr. 5759 const bool SupportsMapper; 5760 5761 /// C++ nested name specifier for the associated user-defined mapper. 5762 NestedNameSpecifierLoc MapperQualifierLoc; 5763 5764 /// The associated user-defined mapper identifier information. 5765 DeclarationNameInfo MapperIdInfo; 5766 5767 protected: 5768 /// Build a clause for \a NumUniqueDeclarations declarations, \a 5769 /// NumComponentLists total component lists, and \a NumComponents total 5770 /// components. 5771 /// 5772 /// \param K Kind of the clause. 5773 /// \param Locs Locations needed to build a mappable clause. It includes 1) 5774 /// StartLoc: starting location of the clause (the clause keyword); 2) 5775 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 5776 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 5777 /// NumVars: number of expressions listed in this clause; 2) 5778 /// NumUniqueDeclarations: number of unique base declarations in this clause; 5779 /// 3) NumComponentLists: number of component lists in this clause; and 4) 5780 /// NumComponents: total number of expression components in the clause. 5781 /// \param SupportsMapper Indicates whether this clause is possible to have 5782 /// user-defined mappers associated. 5783 /// \param MapperQualifierLocPtr C++ nested name specifier for the associated 5784 /// user-defined mapper. 5785 /// \param MapperIdInfoPtr The identifier of associated user-defined mapper. 5786 OMPMappableExprListClause( 5787 OpenMPClauseKind K, const OMPVarListLocTy &Locs, 5788 const OMPMappableExprListSizeTy &Sizes, bool SupportsMapper = false, 5789 NestedNameSpecifierLoc *MapperQualifierLocPtr = nullptr, 5790 DeclarationNameInfo *MapperIdInfoPtr = nullptr) 5791 : OMPVarListClause<T>(K, Locs.StartLoc, Locs.LParenLoc, Locs.EndLoc, 5792 Sizes.NumVars), 5793 NumUniqueDeclarations(Sizes.NumUniqueDeclarations), 5794 NumComponentLists(Sizes.NumComponentLists), 5795 NumComponents(Sizes.NumComponents), SupportsMapper(SupportsMapper) { 5796 if (MapperQualifierLocPtr) 5797 MapperQualifierLoc = *MapperQualifierLocPtr; 5798 if (MapperIdInfoPtr) 5799 MapperIdInfo = *MapperIdInfoPtr; 5800 } 5801 5802 /// Get the unique declarations that are in the trailing objects of the 5803 /// class. 5804 MutableArrayRef<ValueDecl *> getUniqueDeclsRef() { 5805 return MutableArrayRef<ValueDecl *>( 5806 static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(), 5807 NumUniqueDeclarations); 5808 } 5809 5810 /// Get the unique declarations that are in the trailing objects of the 5811 /// class. 5812 ArrayRef<ValueDecl *> getUniqueDeclsRef() const { 5813 return ArrayRef<ValueDecl *>( 5814 static_cast<const T *>(this) 5815 ->template getTrailingObjects<ValueDecl *>(), 5816 NumUniqueDeclarations); 5817 } 5818 5819 /// Set the unique declarations that are in the trailing objects of the 5820 /// class. 5821 void setUniqueDecls(ArrayRef<ValueDecl *> UDs) { 5822 assert(UDs.size() == NumUniqueDeclarations && 5823 "Unexpected amount of unique declarations."); 5824 std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin()); 5825 } 5826 5827 /// Get the number of lists per declaration that are in the trailing 5828 /// objects of the class. 5829 MutableArrayRef<unsigned> getDeclNumListsRef() { 5830 return MutableArrayRef<unsigned>( 5831 static_cast<T *>(this)->template getTrailingObjects<unsigned>(), 5832 NumUniqueDeclarations); 5833 } 5834 5835 /// Get the number of lists per declaration that are in the trailing 5836 /// objects of the class. 5837 ArrayRef<unsigned> getDeclNumListsRef() const { 5838 return ArrayRef<unsigned>( 5839 static_cast<const T *>(this)->template getTrailingObjects<unsigned>(), 5840 NumUniqueDeclarations); 5841 } 5842 5843 /// Set the number of lists per declaration that are in the trailing 5844 /// objects of the class. 5845 void setDeclNumLists(ArrayRef<unsigned> DNLs) { 5846 assert(DNLs.size() == NumUniqueDeclarations && 5847 "Unexpected amount of list numbers."); 5848 std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin()); 5849 } 5850 5851 /// Get the cumulative component lists sizes that are in the trailing 5852 /// objects of the class. They are appended after the number of lists. 5853 MutableArrayRef<unsigned> getComponentListSizesRef() { 5854 return MutableArrayRef<unsigned>( 5855 static_cast<T *>(this)->template getTrailingObjects<unsigned>() + 5856 NumUniqueDeclarations, 5857 NumComponentLists); 5858 } 5859 5860 /// Get the cumulative component lists sizes that are in the trailing 5861 /// objects of the class. They are appended after the number of lists. 5862 ArrayRef<unsigned> getComponentListSizesRef() const { 5863 return ArrayRef<unsigned>( 5864 static_cast<const T *>(this)->template getTrailingObjects<unsigned>() + 5865 NumUniqueDeclarations, 5866 NumComponentLists); 5867 } 5868 5869 /// Set the cumulative component lists sizes that are in the trailing 5870 /// objects of the class. 5871 void setComponentListSizes(ArrayRef<unsigned> CLSs) { 5872 assert(CLSs.size() == NumComponentLists && 5873 "Unexpected amount of component lists."); 5874 std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin()); 5875 } 5876 5877 /// Get the components that are in the trailing objects of the class. 5878 MutableArrayRef<MappableComponent> getComponentsRef() { 5879 return MutableArrayRef<MappableComponent>( 5880 static_cast<T *>(this) 5881 ->template getTrailingObjects<MappableComponent>(), 5882 NumComponents); 5883 } 5884 5885 /// Get the components that are in the trailing objects of the class. 5886 ArrayRef<MappableComponent> getComponentsRef() const { 5887 return ArrayRef<MappableComponent>( 5888 static_cast<const T *>(this) 5889 ->template getTrailingObjects<MappableComponent>(), 5890 NumComponents); 5891 } 5892 5893 /// Set the components that are in the trailing objects of the class. 5894 /// This requires the list sizes so that it can also fill the original 5895 /// expressions, which are the first component of each list. 5896 void setComponents(ArrayRef<MappableComponent> Components, 5897 ArrayRef<unsigned> CLSs) { 5898 assert(Components.size() == NumComponents && 5899 "Unexpected amount of component lists."); 5900 assert(CLSs.size() == NumComponentLists && 5901 "Unexpected amount of list sizes."); 5902 std::copy(Components.begin(), Components.end(), getComponentsRef().begin()); 5903 } 5904 5905 /// Fill the clause information from the list of declarations and 5906 /// associated component lists. 5907 void setClauseInfo(ArrayRef<ValueDecl *> Declarations, 5908 MappableExprComponentListsRef ComponentLists) { 5909 // Perform some checks to make sure the data sizes are consistent with the 5910 // information available when the clause was created. 5911 assert(getUniqueDeclarationsTotalNumber(Declarations) == 5912 NumUniqueDeclarations && 5913 "Unexpected number of mappable expression info entries!"); 5914 assert(getComponentsTotalNumber(ComponentLists) == NumComponents && 5915 "Unexpected total number of components!"); 5916 assert(Declarations.size() == ComponentLists.size() && 5917 "Declaration and component lists size is not consistent!"); 5918 assert(Declarations.size() == NumComponentLists && 5919 "Unexpected declaration and component lists size!"); 5920 5921 // Organize the components by declaration and retrieve the original 5922 // expression. Original expressions are always the first component of the 5923 // mappable component list. 5924 llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>> 5925 ComponentListMap; 5926 { 5927 auto CI = ComponentLists.begin(); 5928 for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE; 5929 ++DI, ++CI) { 5930 assert(!CI->empty() && "Invalid component list!"); 5931 ComponentListMap[*DI].push_back(*CI); 5932 } 5933 } 5934 5935 // Iterators of the target storage. 5936 auto UniqueDeclarations = getUniqueDeclsRef(); 5937 auto UDI = UniqueDeclarations.begin(); 5938 5939 auto DeclNumLists = getDeclNumListsRef(); 5940 auto DNLI = DeclNumLists.begin(); 5941 5942 auto ComponentListSizes = getComponentListSizesRef(); 5943 auto CLSI = ComponentListSizes.begin(); 5944 5945 auto Components = getComponentsRef(); 5946 auto CI = Components.begin(); 5947 5948 // Variable to compute the accumulation of the number of components. 5949 unsigned PrevSize = 0u; 5950 5951 // Scan all the declarations and associated component lists. 5952 for (auto &M : ComponentListMap) { 5953 // The declaration. 5954 auto *D = M.first; 5955 // The component lists. 5956 auto CL = M.second; 5957 5958 // Initialize the entry. 5959 *UDI = D; 5960 ++UDI; 5961 5962 *DNLI = CL.size(); 5963 ++DNLI; 5964 5965 // Obtain the cumulative sizes and concatenate all the components in the 5966 // reserved storage. 5967 for (auto C : CL) { 5968 // Accumulate with the previous size. 5969 PrevSize += C.size(); 5970 5971 // Save the size. 5972 *CLSI = PrevSize; 5973 ++CLSI; 5974 5975 // Append components after the current components iterator. 5976 CI = std::copy(C.begin(), C.end(), CI); 5977 } 5978 } 5979 } 5980 5981 /// Set the nested name specifier of associated user-defined mapper. 5982 void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL) { 5983 MapperQualifierLoc = NNSL; 5984 } 5985 5986 /// Set the name of associated user-defined mapper. 5987 void setMapperIdInfo(DeclarationNameInfo MapperId) { 5988 MapperIdInfo = MapperId; 5989 } 5990 5991 /// Get the user-defined mapper references that are in the trailing objects of 5992 /// the class. 5993 MutableArrayRef<Expr *> getUDMapperRefs() { 5994 assert(SupportsMapper && 5995 "Must be a clause that is possible to have user-defined mappers"); 5996 return llvm::MutableArrayRef<Expr *>( 5997 static_cast<T *>(this)->template getTrailingObjects<Expr *>() + 5998 OMPVarListClause<T>::varlist_size(), 5999 OMPVarListClause<T>::varlist_size()); 6000 } 6001 6002 /// Get the user-defined mappers references that are in the trailing objects 6003 /// of the class. 6004 ArrayRef<Expr *> getUDMapperRefs() const { 6005 assert(SupportsMapper && 6006 "Must be a clause that is possible to have user-defined mappers"); 6007 return llvm::ArrayRef<Expr *>( 6008 static_cast<const T *>(this)->template getTrailingObjects<Expr *>() + 6009 OMPVarListClause<T>::varlist_size(), 6010 OMPVarListClause<T>::varlist_size()); 6011 } 6012 6013 /// Set the user-defined mappers that are in the trailing objects of the 6014 /// class. 6015 void setUDMapperRefs(ArrayRef<Expr *> DMDs) { 6016 assert(DMDs.size() == OMPVarListClause<T>::varlist_size() && 6017 "Unexpected number of user-defined mappers."); 6018 assert(SupportsMapper && 6019 "Must be a clause that is possible to have user-defined mappers"); 6020 std::copy(DMDs.begin(), DMDs.end(), getUDMapperRefs().begin()); 6021 } 6022 6023 public: 6024 /// Return the number of unique base declarations in this clause. 6025 unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; } 6026 6027 /// Return the number of lists derived from the clause expressions. 6028 unsigned getTotalComponentListNum() const { return NumComponentLists; } 6029 6030 /// Return the total number of components in all lists derived from the 6031 /// clause. 6032 unsigned getTotalComponentsNum() const { return NumComponents; } 6033 6034 /// Gets the nested name specifier for associated user-defined mapper. 6035 NestedNameSpecifierLoc getMapperQualifierLoc() const { 6036 return MapperQualifierLoc; 6037 } 6038 6039 /// Gets the name info for associated user-defined mapper. 6040 const DeclarationNameInfo &getMapperIdInfo() const { return MapperIdInfo; } 6041 6042 /// Iterator that browse the components by lists. It also allows 6043 /// browsing components of a single declaration. 6044 class const_component_lists_iterator 6045 : public llvm::iterator_adaptor_base< 6046 const_component_lists_iterator, 6047 MappableExprComponentListRef::const_iterator, 6048 std::forward_iterator_tag, MappableComponent, ptrdiff_t, 6049 MappableComponent, MappableComponent> { 6050 // The declaration the iterator currently refers to. 6051 ArrayRef<ValueDecl *>::iterator DeclCur; 6052 6053 // The list number associated with the current declaration. 6054 ArrayRef<unsigned>::iterator NumListsCur; 6055 6056 // Whether this clause is possible to have user-defined mappers associated. 6057 const bool SupportsMapper; 6058 6059 // The user-defined mapper associated with the current declaration. 6060 ArrayRef<Expr *>::iterator MapperCur; 6061 6062 // Remaining lists for the current declaration. 6063 unsigned RemainingLists = 0; 6064 6065 // The cumulative size of the previous list, or zero if there is no previous 6066 // list. 6067 unsigned PrevListSize = 0; 6068 6069 // The cumulative sizes of the current list - it will delimit the remaining 6070 // range of interest. 6071 ArrayRef<unsigned>::const_iterator ListSizeCur; 6072 ArrayRef<unsigned>::const_iterator ListSizeEnd; 6073 6074 // Iterator to the end of the components storage. 6075 MappableExprComponentListRef::const_iterator End; 6076 6077 public: 6078 /// Construct an iterator that scans all lists. 6079 explicit const_component_lists_iterator( 6080 ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum, 6081 ArrayRef<unsigned> CumulativeListSizes, 6082 MappableExprComponentListRef Components, bool SupportsMapper, 6083 ArrayRef<Expr *> Mappers) 6084 : const_component_lists_iterator::iterator_adaptor_base( 6085 Components.begin()), 6086 DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()), 6087 SupportsMapper(SupportsMapper), 6088 ListSizeCur(CumulativeListSizes.begin()), 6089 ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) { 6090 assert(UniqueDecls.size() == DeclsListNum.size() && 6091 "Inconsistent number of declarations and list sizes!"); 6092 if (!DeclsListNum.empty()) 6093 RemainingLists = *NumListsCur; 6094 if (SupportsMapper) 6095 MapperCur = Mappers.begin(); 6096 } 6097 6098 /// Construct an iterator that scan lists for a given declaration \a 6099 /// Declaration. 6100 explicit const_component_lists_iterator( 6101 const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls, 6102 ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes, 6103 MappableExprComponentListRef Components, bool SupportsMapper, 6104 ArrayRef<Expr *> Mappers) 6105 : const_component_lists_iterator(UniqueDecls, DeclsListNum, 6106 CumulativeListSizes, Components, 6107 SupportsMapper, Mappers) { 6108 // Look for the desired declaration. While we are looking for it, we 6109 // update the state so that we know the component where a given list 6110 // starts. 6111 for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) { 6112 if (*DeclCur == Declaration) 6113 break; 6114 6115 assert(*NumListsCur > 0 && "No lists associated with declaration??"); 6116 6117 // Skip the lists associated with the current declaration, but save the 6118 // last list size that was skipped. 6119 std::advance(ListSizeCur, *NumListsCur - 1); 6120 PrevListSize = *ListSizeCur; 6121 ++ListSizeCur; 6122 6123 if (SupportsMapper) 6124 ++MapperCur; 6125 } 6126 6127 // If we didn't find any declaration, advance the iterator to after the 6128 // last component and set remaining lists to zero. 6129 if (ListSizeCur == CumulativeListSizes.end()) { 6130 this->I = End; 6131 RemainingLists = 0u; 6132 return; 6133 } 6134 6135 // Set the remaining lists with the total number of lists of the current 6136 // declaration. 6137 RemainingLists = *NumListsCur; 6138 6139 // Adjust the list size end iterator to the end of the relevant range. 6140 ListSizeEnd = ListSizeCur; 6141 std::advance(ListSizeEnd, RemainingLists); 6142 6143 // Given that the list sizes are cumulative, the index of the component 6144 // that start the list is the size of the previous list. 6145 std::advance(this->I, PrevListSize); 6146 } 6147 6148 // Return the array with the current list. The sizes are cumulative, so the 6149 // array size is the difference between the current size and previous one. 6150 std::tuple<const ValueDecl *, MappableExprComponentListRef, 6151 const ValueDecl *> 6152 operator*() const { 6153 assert(ListSizeCur != ListSizeEnd && "Invalid iterator!"); 6154 const ValueDecl *Mapper = nullptr; 6155 if (SupportsMapper && *MapperCur) 6156 Mapper = cast<ValueDecl>(cast<DeclRefExpr>(*MapperCur)->getDecl()); 6157 return std::make_tuple( 6158 *DeclCur, 6159 MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize), 6160 Mapper); 6161 } 6162 std::tuple<const ValueDecl *, MappableExprComponentListRef, 6163 const ValueDecl *> 6164 operator->() const { 6165 return **this; 6166 } 6167 6168 // Skip the components of the current list. 6169 const_component_lists_iterator &operator++() { 6170 assert(ListSizeCur != ListSizeEnd && RemainingLists && 6171 "Invalid iterator!"); 6172 6173 // If we don't have more lists just skip all the components. Otherwise, 6174 // advance the iterator by the number of components in the current list. 6175 if (std::next(ListSizeCur) == ListSizeEnd) { 6176 this->I = End; 6177 RemainingLists = 0; 6178 } else { 6179 std::advance(this->I, *ListSizeCur - PrevListSize); 6180 PrevListSize = *ListSizeCur; 6181 6182 // We are done with a declaration, move to the next one. 6183 if (!(--RemainingLists)) { 6184 ++DeclCur; 6185 ++NumListsCur; 6186 RemainingLists = *NumListsCur; 6187 assert(RemainingLists && "No lists in the following declaration??"); 6188 } 6189 } 6190 6191 ++ListSizeCur; 6192 if (SupportsMapper) 6193 ++MapperCur; 6194 return *this; 6195 } 6196 }; 6197 6198 using const_component_lists_range = 6199 llvm::iterator_range<const_component_lists_iterator>; 6200 6201 /// Iterators for all component lists. 6202 const_component_lists_iterator component_lists_begin() const { 6203 return const_component_lists_iterator( 6204 getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(), 6205 getComponentsRef(), SupportsMapper, 6206 SupportsMapper ? getUDMapperRefs() : ArrayRef<Expr *>()); 6207 } 6208 const_component_lists_iterator component_lists_end() const { 6209 return const_component_lists_iterator( 6210 ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(), 6211 MappableExprComponentListRef(getComponentsRef().end(), 6212 getComponentsRef().end()), 6213 SupportsMapper, {}); 6214 } 6215 const_component_lists_range component_lists() const { 6216 return {component_lists_begin(), component_lists_end()}; 6217 } 6218 6219 /// Iterators for component lists associated with the provided 6220 /// declaration. 6221 const_component_lists_iterator 6222 decl_component_lists_begin(const ValueDecl *VD) const { 6223 return const_component_lists_iterator( 6224 VD, getUniqueDeclsRef(), getDeclNumListsRef(), 6225 getComponentListSizesRef(), getComponentsRef(), SupportsMapper, 6226 SupportsMapper ? getUDMapperRefs() : ArrayRef<Expr *>()); 6227 } 6228 const_component_lists_iterator decl_component_lists_end() const { 6229 return component_lists_end(); 6230 } 6231 const_component_lists_range decl_component_lists(const ValueDecl *VD) const { 6232 return {decl_component_lists_begin(VD), decl_component_lists_end()}; 6233 } 6234 6235 /// Iterators to access all the declarations, number of lists, list sizes, and 6236 /// components. 6237 using const_all_decls_iterator = ArrayRef<ValueDecl *>::iterator; 6238 using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>; 6239 6240 const_all_decls_range all_decls() const { 6241 auto A = getUniqueDeclsRef(); 6242 return const_all_decls_range(A.begin(), A.end()); 6243 } 6244 6245 using const_all_num_lists_iterator = ArrayRef<unsigned>::iterator; 6246 using const_all_num_lists_range = 6247 llvm::iterator_range<const_all_num_lists_iterator>; 6248 6249 const_all_num_lists_range all_num_lists() const { 6250 auto A = getDeclNumListsRef(); 6251 return const_all_num_lists_range(A.begin(), A.end()); 6252 } 6253 6254 using const_all_lists_sizes_iterator = ArrayRef<unsigned>::iterator; 6255 using const_all_lists_sizes_range = 6256 llvm::iterator_range<const_all_lists_sizes_iterator>; 6257 6258 const_all_lists_sizes_range all_lists_sizes() const { 6259 auto A = getComponentListSizesRef(); 6260 return const_all_lists_sizes_range(A.begin(), A.end()); 6261 } 6262 6263 using const_all_components_iterator = ArrayRef<MappableComponent>::iterator; 6264 using const_all_components_range = 6265 llvm::iterator_range<const_all_components_iterator>; 6266 6267 const_all_components_range all_components() const { 6268 auto A = getComponentsRef(); 6269 return const_all_components_range(A.begin(), A.end()); 6270 } 6271 6272 using mapperlist_iterator = MutableArrayRef<Expr *>::iterator; 6273 using mapperlist_const_iterator = ArrayRef<const Expr *>::iterator; 6274 using mapperlist_range = llvm::iterator_range<mapperlist_iterator>; 6275 using mapperlist_const_range = 6276 llvm::iterator_range<mapperlist_const_iterator>; 6277 6278 mapperlist_iterator mapperlist_begin() { return getUDMapperRefs().begin(); } 6279 mapperlist_iterator mapperlist_end() { return getUDMapperRefs().end(); } 6280 mapperlist_const_iterator mapperlist_begin() const { 6281 return getUDMapperRefs().begin(); 6282 } 6283 mapperlist_const_iterator mapperlist_end() const { 6284 return getUDMapperRefs().end(); 6285 } 6286 mapperlist_range mapperlists() { 6287 return mapperlist_range(mapperlist_begin(), mapperlist_end()); 6288 } 6289 mapperlist_const_range mapperlists() const { 6290 return mapperlist_const_range(mapperlist_begin(), mapperlist_end()); 6291 } 6292 }; 6293 6294 /// This represents clause 'map' in the '#pragma omp ...' 6295 /// directives. 6296 /// 6297 /// \code 6298 /// #pragma omp target map(a,b) 6299 /// \endcode 6300 /// In this example directive '#pragma omp target' has clause 'map' 6301 /// with the variables 'a' and 'b'. 6302 class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>, 6303 private llvm::TrailingObjects< 6304 OMPMapClause, Expr *, ValueDecl *, unsigned, 6305 OMPClauseMappableExprCommon::MappableComponent> { 6306 friend class OMPClauseReader; 6307 friend OMPMappableExprListClause; 6308 friend OMPVarListClause; 6309 friend TrailingObjects; 6310 6311 /// Define the sizes of each trailing object array except the last one. This 6312 /// is required for TrailingObjects to work properly. 6313 size_t numTrailingObjects(OverloadToken<Expr *>) const { 6314 // There are varlist_size() of expressions, and varlist_size() of 6315 // user-defined mappers. 6316 return 2 * varlist_size() + 1; 6317 } 6318 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { 6319 return getUniqueDeclarationsNum(); 6320 } 6321 size_t numTrailingObjects(OverloadToken<unsigned>) const { 6322 return getUniqueDeclarationsNum() + getTotalComponentListNum(); 6323 } 6324 6325 private: 6326 /// Map-type-modifiers for the 'map' clause. 6327 OpenMPMapModifierKind MapTypeModifiers[NumberOfOMPMapClauseModifiers] = { 6328 OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown, 6329 OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown, 6330 OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown}; 6331 6332 /// Location of map-type-modifiers for the 'map' clause. 6333 SourceLocation MapTypeModifiersLoc[NumberOfOMPMapClauseModifiers]; 6334 6335 /// Map type for the 'map' clause. 6336 OpenMPMapClauseKind MapType = OMPC_MAP_unknown; 6337 6338 /// Is this an implicit map type or not. 6339 bool MapTypeIsImplicit = false; 6340 6341 /// Location of the map type. 6342 SourceLocation MapLoc; 6343 6344 /// Colon location. 6345 SourceLocation ColonLoc; 6346 6347 /// Build a clause for \a NumVars listed expressions, \a 6348 /// NumUniqueDeclarations declarations, \a NumComponentLists total component 6349 /// lists, and \a NumComponents total expression components. 6350 /// 6351 /// \param MapModifiers Map-type-modifiers. 6352 /// \param MapModifiersLoc Locations of map-type-modifiers. 6353 /// \param MapperQualifierLoc C++ nested name specifier for the associated 6354 /// user-defined mapper. 6355 /// \param MapperIdInfo The identifier of associated user-defined mapper. 6356 /// \param MapType Map type. 6357 /// \param MapTypeIsImplicit Map type is inferred implicitly. 6358 /// \param MapLoc Location of the map type. 6359 /// \param Locs Locations needed to build a mappable clause. It includes 1) 6360 /// StartLoc: starting location of the clause (the clause keyword); 2) 6361 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 6362 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 6363 /// NumVars: number of expressions listed in this clause; 2) 6364 /// NumUniqueDeclarations: number of unique base declarations in this clause; 6365 /// 3) NumComponentLists: number of component lists in this clause; and 4) 6366 /// NumComponents: total number of expression components in the clause. 6367 explicit OMPMapClause(ArrayRef<OpenMPMapModifierKind> MapModifiers, 6368 ArrayRef<SourceLocation> MapModifiersLoc, 6369 NestedNameSpecifierLoc MapperQualifierLoc, 6370 DeclarationNameInfo MapperIdInfo, 6371 OpenMPMapClauseKind MapType, bool MapTypeIsImplicit, 6372 SourceLocation MapLoc, const OMPVarListLocTy &Locs, 6373 const OMPMappableExprListSizeTy &Sizes) 6374 : OMPMappableExprListClause(llvm::omp::OMPC_map, Locs, Sizes, 6375 /*SupportsMapper=*/true, &MapperQualifierLoc, 6376 &MapperIdInfo), 6377 MapType(MapType), MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) { 6378 assert(std::size(MapTypeModifiers) == MapModifiers.size() && 6379 "Unexpected number of map type modifiers."); 6380 llvm::copy(MapModifiers, std::begin(MapTypeModifiers)); 6381 6382 assert(std::size(MapTypeModifiersLoc) == MapModifiersLoc.size() && 6383 "Unexpected number of map type modifier locations."); 6384 llvm::copy(MapModifiersLoc, std::begin(MapTypeModifiersLoc)); 6385 } 6386 6387 /// Build an empty clause. 6388 /// 6389 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 6390 /// NumVars: number of expressions listed in this clause; 2) 6391 /// NumUniqueDeclarations: number of unique base declarations in this clause; 6392 /// 3) NumComponentLists: number of component lists in this clause; and 4) 6393 /// NumComponents: total number of expression components in the clause. 6394 explicit OMPMapClause(const OMPMappableExprListSizeTy &Sizes) 6395 : OMPMappableExprListClause(llvm::omp::OMPC_map, OMPVarListLocTy(), Sizes, 6396 /*SupportsMapper=*/true) {} 6397 6398 /// Set map-type-modifier for the clause. 6399 /// 6400 /// \param I index for map-type-modifier. 6401 /// \param T map-type-modifier for the clause. 6402 void setMapTypeModifier(unsigned I, OpenMPMapModifierKind T) { 6403 assert(I < NumberOfOMPMapClauseModifiers && 6404 "Unexpected index to store map type modifier, exceeds array size."); 6405 MapTypeModifiers[I] = T; 6406 } 6407 6408 /// Set location for the map-type-modifier. 6409 /// 6410 /// \param I index for map-type-modifier location. 6411 /// \param TLoc map-type-modifier location. 6412 void setMapTypeModifierLoc(unsigned I, SourceLocation TLoc) { 6413 assert(I < NumberOfOMPMapClauseModifiers && 6414 "Index to store map type modifier location exceeds array size."); 6415 MapTypeModifiersLoc[I] = TLoc; 6416 } 6417 6418 /// Set type for the clause. 6419 /// 6420 /// \param T Type for the clause. 6421 void setMapType(OpenMPMapClauseKind T) { MapType = T; } 6422 6423 /// Set type location. 6424 /// 6425 /// \param TLoc Type location. 6426 void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; } 6427 6428 /// Set colon location. 6429 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 6430 6431 /// Set iterator modifier. 6432 void setIteratorModifier(Expr *IteratorModifier) { 6433 getTrailingObjects<Expr *>()[2 * varlist_size()] = IteratorModifier; 6434 } 6435 6436 public: 6437 /// Creates clause with a list of variables \a VL. 6438 /// 6439 /// \param C AST context. 6440 /// \param Locs Locations needed to build a mappable clause. It includes 1) 6441 /// StartLoc: starting location of the clause (the clause keyword); 2) 6442 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 6443 /// \param Vars The original expression used in the clause. 6444 /// \param Declarations Declarations used in the clause. 6445 /// \param ComponentLists Component lists used in the clause. 6446 /// \param UDMapperRefs References to user-defined mappers associated with 6447 /// expressions used in the clause. 6448 /// \param IteratorModifier Iterator modifier. 6449 /// \param MapModifiers Map-type-modifiers. 6450 /// \param MapModifiersLoc Location of map-type-modifiers. 6451 /// \param UDMQualifierLoc C++ nested name specifier for the associated 6452 /// user-defined mapper. 6453 /// \param MapperId The identifier of associated user-defined mapper. 6454 /// \param Type Map type. 6455 /// \param TypeIsImplicit Map type is inferred implicitly. 6456 /// \param TypeLoc Location of the map type. 6457 static OMPMapClause * 6458 Create(const ASTContext &C, const OMPVarListLocTy &Locs, 6459 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, 6460 MappableExprComponentListsRef ComponentLists, 6461 ArrayRef<Expr *> UDMapperRefs, Expr *IteratorModifier, 6462 ArrayRef<OpenMPMapModifierKind> MapModifiers, 6463 ArrayRef<SourceLocation> MapModifiersLoc, 6464 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId, 6465 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc); 6466 6467 /// Creates an empty clause with the place for \a NumVars original 6468 /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists 6469 /// lists, and \a NumComponents expression components. 6470 /// 6471 /// \param C AST context. 6472 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 6473 /// NumVars: number of expressions listed in this clause; 2) 6474 /// NumUniqueDeclarations: number of unique base declarations in this clause; 6475 /// 3) NumComponentLists: number of component lists in this clause; and 4) 6476 /// NumComponents: total number of expression components in the clause. 6477 static OMPMapClause *CreateEmpty(const ASTContext &C, 6478 const OMPMappableExprListSizeTy &Sizes); 6479 6480 /// Fetches Expr * of iterator modifier. 6481 Expr *getIteratorModifier() { 6482 return getTrailingObjects<Expr *>()[2 * varlist_size()]; 6483 } 6484 6485 /// Fetches mapping kind for the clause. 6486 OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; } 6487 6488 /// Is this an implicit map type? 6489 /// We have to capture 'IsMapTypeImplicit' from the parser for more 6490 /// informative error messages. It helps distinguish map(r) from 6491 /// map(tofrom: r), which is important to print more helpful error 6492 /// messages for some target directives. 6493 bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; } 6494 6495 /// Fetches the map-type-modifier at 'Cnt' index of array of modifiers. 6496 /// 6497 /// \param Cnt index for map-type-modifier. 6498 OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY { 6499 assert(Cnt < NumberOfOMPMapClauseModifiers && 6500 "Requested modifier exceeds the total number of modifiers."); 6501 return MapTypeModifiers[Cnt]; 6502 } 6503 6504 /// Fetches the map-type-modifier location at 'Cnt' index of array of 6505 /// modifiers' locations. 6506 /// 6507 /// \param Cnt index for map-type-modifier location. 6508 SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY { 6509 assert(Cnt < NumberOfOMPMapClauseModifiers && 6510 "Requested modifier location exceeds total number of modifiers."); 6511 return MapTypeModifiersLoc[Cnt]; 6512 } 6513 6514 /// Fetches ArrayRef of map-type-modifiers. 6515 ArrayRef<OpenMPMapModifierKind> getMapTypeModifiers() const LLVM_READONLY { 6516 return llvm::ArrayRef(MapTypeModifiers); 6517 } 6518 6519 /// Fetches ArrayRef of location of map-type-modifiers. 6520 ArrayRef<SourceLocation> getMapTypeModifiersLoc() const LLVM_READONLY { 6521 return llvm::ArrayRef(MapTypeModifiersLoc); 6522 } 6523 6524 /// Fetches location of clause mapping kind. 6525 SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; } 6526 6527 /// Get colon location. 6528 SourceLocation getColonLoc() const { return ColonLoc; } 6529 6530 child_range children() { 6531 return child_range( 6532 reinterpret_cast<Stmt **>(varlist_begin()), 6533 reinterpret_cast<Stmt **>(varlist_end())); 6534 } 6535 6536 const_child_range children() const { 6537 auto Children = const_cast<OMPMapClause *>(this)->children(); 6538 return const_child_range(Children.begin(), Children.end()); 6539 } 6540 6541 child_range used_children() { 6542 if (MapType == OMPC_MAP_to || MapType == OMPC_MAP_tofrom) 6543 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 6544 reinterpret_cast<Stmt **>(varlist_end())); 6545 return child_range(child_iterator(), child_iterator()); 6546 } 6547 const_child_range used_children() const { 6548 auto Children = const_cast<OMPMapClause *>(this)->used_children(); 6549 return const_child_range(Children.begin(), Children.end()); 6550 } 6551 6552 6553 static bool classof(const OMPClause *T) { 6554 return T->getClauseKind() == llvm::omp::OMPC_map; 6555 } 6556 }; 6557 6558 /// This represents 'num_teams' clause in the '#pragma omp ...' 6559 /// directive. 6560 /// 6561 /// \code 6562 /// #pragma omp teams num_teams(n) 6563 /// \endcode 6564 /// In this example directive '#pragma omp teams' has clause 'num_teams' 6565 /// with single expression 'n'. 6566 /// 6567 /// When 'ompx_bare' clause exists on a 'target' directive, 'num_teams' clause 6568 /// can accept up to three expressions. 6569 /// 6570 /// \code 6571 /// #pragma omp target teams ompx_bare num_teams(x, y, z) 6572 /// \endcode 6573 class OMPNumTeamsClause final 6574 : public OMPVarListClause<OMPNumTeamsClause>, 6575 public OMPClauseWithPreInit, 6576 private llvm::TrailingObjects<OMPNumTeamsClause, Expr *> { 6577 friend OMPVarListClause; 6578 friend TrailingObjects; 6579 6580 /// Location of '('. 6581 SourceLocation LParenLoc; 6582 6583 OMPNumTeamsClause(const ASTContext &C, SourceLocation StartLoc, 6584 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N) 6585 : OMPVarListClause(llvm::omp::OMPC_num_teams, StartLoc, LParenLoc, EndLoc, 6586 N), 6587 OMPClauseWithPreInit(this) {} 6588 6589 /// Build an empty clause. 6590 OMPNumTeamsClause(unsigned N) 6591 : OMPVarListClause(llvm::omp::OMPC_num_teams, SourceLocation(), 6592 SourceLocation(), SourceLocation(), N), 6593 OMPClauseWithPreInit(this) {} 6594 6595 public: 6596 /// Creates clause with a list of variables \a VL. 6597 /// 6598 /// \param C AST context. 6599 /// \param StartLoc Starting location of the clause. 6600 /// \param LParenLoc Location of '('. 6601 /// \param EndLoc Ending location of the clause. 6602 /// \param VL List of references to the variables. 6603 /// \param PreInit 6604 static OMPNumTeamsClause * 6605 Create(const ASTContext &C, OpenMPDirectiveKind CaptureRegion, 6606 SourceLocation StartLoc, SourceLocation LParenLoc, 6607 SourceLocation EndLoc, ArrayRef<Expr *> VL, Stmt *PreInit); 6608 6609 /// Creates an empty clause with \a N variables. 6610 /// 6611 /// \param C AST context. 6612 /// \param N The number of variables. 6613 static OMPNumTeamsClause *CreateEmpty(const ASTContext &C, unsigned N); 6614 6615 /// Sets the location of '('. 6616 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 6617 6618 /// Returns the location of '('. 6619 SourceLocation getLParenLoc() const { return LParenLoc; } 6620 6621 /// Return NumTeams expressions. 6622 ArrayRef<Expr *> getNumTeams() { return getVarRefs(); } 6623 6624 /// Return NumTeams expressions. 6625 ArrayRef<Expr *> getNumTeams() const { 6626 return const_cast<OMPNumTeamsClause *>(this)->getNumTeams(); 6627 } 6628 6629 child_range children() { 6630 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 6631 reinterpret_cast<Stmt **>(varlist_end())); 6632 } 6633 6634 const_child_range children() const { 6635 auto Children = const_cast<OMPNumTeamsClause *>(this)->children(); 6636 return const_child_range(Children.begin(), Children.end()); 6637 } 6638 6639 child_range used_children() { 6640 return child_range(child_iterator(), child_iterator()); 6641 } 6642 const_child_range used_children() const { 6643 return const_child_range(const_child_iterator(), const_child_iterator()); 6644 } 6645 6646 static bool classof(const OMPClause *T) { 6647 return T->getClauseKind() == llvm::omp::OMPC_num_teams; 6648 } 6649 }; 6650 6651 /// This represents 'thread_limit' clause in the '#pragma omp ...' 6652 /// directive. 6653 /// 6654 /// \code 6655 /// #pragma omp teams thread_limit(n) 6656 /// \endcode 6657 /// In this example directive '#pragma omp teams' has clause 'thread_limit' 6658 /// with single expression 'n'. 6659 /// 6660 /// When 'ompx_bare' clause exists on a 'target' directive, 'thread_limit' 6661 /// clause can accept up to three expressions. 6662 /// 6663 /// \code 6664 /// #pragma omp target teams ompx_bare thread_limit(x, y, z) 6665 /// \endcode 6666 class OMPThreadLimitClause final 6667 : public OMPVarListClause<OMPThreadLimitClause>, 6668 public OMPClauseWithPreInit, 6669 private llvm::TrailingObjects<OMPThreadLimitClause, Expr *> { 6670 friend OMPVarListClause; 6671 friend TrailingObjects; 6672 6673 /// Location of '('. 6674 SourceLocation LParenLoc; 6675 6676 OMPThreadLimitClause(const ASTContext &C, SourceLocation StartLoc, 6677 SourceLocation LParenLoc, SourceLocation EndLoc, 6678 unsigned N) 6679 : OMPVarListClause(llvm::omp::OMPC_thread_limit, StartLoc, LParenLoc, 6680 EndLoc, N), 6681 OMPClauseWithPreInit(this) {} 6682 6683 /// Build an empty clause. 6684 OMPThreadLimitClause(unsigned N) 6685 : OMPVarListClause(llvm::omp::OMPC_thread_limit, SourceLocation(), 6686 SourceLocation(), SourceLocation(), N), 6687 OMPClauseWithPreInit(this) {} 6688 6689 public: 6690 /// Creates clause with a list of variables \a VL. 6691 /// 6692 /// \param C AST context. 6693 /// \param StartLoc Starting location of the clause. 6694 /// \param LParenLoc Location of '('. 6695 /// \param EndLoc Ending location of the clause. 6696 /// \param VL List of references to the variables. 6697 /// \param PreInit 6698 static OMPThreadLimitClause * 6699 Create(const ASTContext &C, OpenMPDirectiveKind CaptureRegion, 6700 SourceLocation StartLoc, SourceLocation LParenLoc, 6701 SourceLocation EndLoc, ArrayRef<Expr *> VL, Stmt *PreInit); 6702 6703 /// Creates an empty clause with \a N variables. 6704 /// 6705 /// \param C AST context. 6706 /// \param N The number of variables. 6707 static OMPThreadLimitClause *CreateEmpty(const ASTContext &C, unsigned N); 6708 6709 /// Sets the location of '('. 6710 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 6711 6712 /// Returns the location of '('. 6713 SourceLocation getLParenLoc() const { return LParenLoc; } 6714 6715 /// Return ThreadLimit expressions. 6716 ArrayRef<Expr *> getThreadLimit() { return getVarRefs(); } 6717 6718 /// Return ThreadLimit expressions. 6719 ArrayRef<Expr *> getThreadLimit() const { 6720 return const_cast<OMPThreadLimitClause *>(this)->getThreadLimit(); 6721 } 6722 6723 child_range children() { 6724 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 6725 reinterpret_cast<Stmt **>(varlist_end())); 6726 } 6727 6728 const_child_range children() const { 6729 auto Children = const_cast<OMPThreadLimitClause *>(this)->children(); 6730 return const_child_range(Children.begin(), Children.end()); 6731 } 6732 6733 child_range used_children() { 6734 return child_range(child_iterator(), child_iterator()); 6735 } 6736 const_child_range used_children() const { 6737 return const_child_range(const_child_iterator(), const_child_iterator()); 6738 } 6739 6740 static bool classof(const OMPClause *T) { 6741 return T->getClauseKind() == llvm::omp::OMPC_thread_limit; 6742 } 6743 }; 6744 6745 /// This represents 'priority' clause in the '#pragma omp ...' 6746 /// directive. 6747 /// 6748 /// \code 6749 /// #pragma omp task priority(n) 6750 /// \endcode 6751 /// In this example directive '#pragma omp teams' has clause 'priority' with 6752 /// single expression 'n'. 6753 class OMPPriorityClause : public OMPClause, public OMPClauseWithPreInit { 6754 friend class OMPClauseReader; 6755 6756 /// Location of '('. 6757 SourceLocation LParenLoc; 6758 6759 /// Priority number. 6760 Stmt *Priority = nullptr; 6761 6762 /// Set the Priority number. 6763 /// 6764 /// \param E Priority number. 6765 void setPriority(Expr *E) { Priority = E; } 6766 6767 public: 6768 /// Build 'priority' clause. 6769 /// 6770 /// \param Priority Expression associated with this clause. 6771 /// \param HelperPriority Helper priority for the construct. 6772 /// \param CaptureRegion Innermost OpenMP region where expressions in this 6773 /// clause must be captured. 6774 /// \param StartLoc Starting location of the clause. 6775 /// \param LParenLoc Location of '('. 6776 /// \param EndLoc Ending location of the clause. 6777 OMPPriorityClause(Expr *Priority, Stmt *HelperPriority, 6778 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, 6779 SourceLocation LParenLoc, SourceLocation EndLoc) 6780 : OMPClause(llvm::omp::OMPC_priority, StartLoc, EndLoc), 6781 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Priority(Priority) { 6782 setPreInitStmt(HelperPriority, CaptureRegion); 6783 } 6784 6785 /// Build an empty clause. 6786 OMPPriorityClause() 6787 : OMPClause(llvm::omp::OMPC_priority, SourceLocation(), SourceLocation()), 6788 OMPClauseWithPreInit(this) {} 6789 6790 /// Sets the location of '('. 6791 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 6792 6793 /// Returns the location of '('. 6794 SourceLocation getLParenLoc() const { return LParenLoc; } 6795 6796 /// Return Priority number. 6797 Expr *getPriority() { return cast<Expr>(Priority); } 6798 6799 /// Return Priority number. 6800 Expr *getPriority() const { return cast<Expr>(Priority); } 6801 6802 child_range children() { return child_range(&Priority, &Priority + 1); } 6803 6804 const_child_range children() const { 6805 return const_child_range(&Priority, &Priority + 1); 6806 } 6807 6808 child_range used_children(); 6809 const_child_range used_children() const { 6810 auto Children = const_cast<OMPPriorityClause *>(this)->used_children(); 6811 return const_child_range(Children.begin(), Children.end()); 6812 } 6813 6814 static bool classof(const OMPClause *T) { 6815 return T->getClauseKind() == llvm::omp::OMPC_priority; 6816 } 6817 }; 6818 6819 /// This represents 'grainsize' clause in the '#pragma omp ...' 6820 /// directive. 6821 /// 6822 /// \code 6823 /// #pragma omp taskloop grainsize(4) 6824 /// \endcode 6825 /// In this example directive '#pragma omp taskloop' has clause 'grainsize' 6826 /// with single expression '4'. 6827 class OMPGrainsizeClause : public OMPClause, public OMPClauseWithPreInit { 6828 friend class OMPClauseReader; 6829 6830 /// Location of '('. 6831 SourceLocation LParenLoc; 6832 6833 /// Modifiers for 'grainsize' clause. 6834 OpenMPGrainsizeClauseModifier Modifier = OMPC_GRAINSIZE_unknown; 6835 6836 /// Location of the modifier. 6837 SourceLocation ModifierLoc; 6838 6839 /// Safe iteration space distance. 6840 Stmt *Grainsize = nullptr; 6841 6842 /// Set safelen. 6843 void setGrainsize(Expr *Size) { Grainsize = Size; } 6844 6845 /// Sets modifier. 6846 void setModifier(OpenMPGrainsizeClauseModifier M) { Modifier = M; } 6847 6848 /// Sets modifier location. 6849 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; } 6850 6851 public: 6852 /// Build 'grainsize' clause. 6853 /// 6854 /// \param Modifier Clause modifier. 6855 /// \param Size Expression associated with this clause. 6856 /// \param HelperSize Helper grainsize for the construct. 6857 /// \param CaptureRegion Innermost OpenMP region where expressions in this 6858 /// clause must be captured. 6859 /// \param StartLoc Starting location of the clause. 6860 /// \param ModifierLoc Modifier location. 6861 /// \param LParenLoc Location of '('. 6862 /// \param EndLoc Ending location of the clause. 6863 OMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size, 6864 Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion, 6865 SourceLocation StartLoc, SourceLocation LParenLoc, 6866 SourceLocation ModifierLoc, SourceLocation EndLoc) 6867 : OMPClause(llvm::omp::OMPC_grainsize, StartLoc, EndLoc), 6868 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier), 6869 ModifierLoc(ModifierLoc), Grainsize(Size) { 6870 setPreInitStmt(HelperSize, CaptureRegion); 6871 } 6872 6873 /// Build an empty clause. 6874 explicit OMPGrainsizeClause() 6875 : OMPClause(llvm::omp::OMPC_grainsize, SourceLocation(), 6876 SourceLocation()), 6877 OMPClauseWithPreInit(this) {} 6878 6879 /// Sets the location of '('. 6880 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 6881 6882 /// Returns the location of '('. 6883 SourceLocation getLParenLoc() const { return LParenLoc; } 6884 6885 /// Return safe iteration space distance. 6886 Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); } 6887 6888 /// Gets modifier. 6889 OpenMPGrainsizeClauseModifier getModifier() const { return Modifier; } 6890 6891 /// Gets modifier location. 6892 SourceLocation getModifierLoc() const { return ModifierLoc; } 6893 6894 child_range children() { return child_range(&Grainsize, &Grainsize + 1); } 6895 6896 const_child_range children() const { 6897 return const_child_range(&Grainsize, &Grainsize + 1); 6898 } 6899 6900 child_range used_children(); 6901 const_child_range used_children() const { 6902 auto Children = const_cast<OMPGrainsizeClause *>(this)->used_children(); 6903 return const_child_range(Children.begin(), Children.end()); 6904 } 6905 6906 static bool classof(const OMPClause *T) { 6907 return T->getClauseKind() == llvm::omp::OMPC_grainsize; 6908 } 6909 }; 6910 6911 /// This represents 'nogroup' clause in the '#pragma omp ...' directive. 6912 /// 6913 /// \code 6914 /// #pragma omp taskloop nogroup 6915 /// \endcode 6916 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause. 6917 class OMPNogroupClause : public OMPClause { 6918 public: 6919 /// Build 'nogroup' clause. 6920 /// 6921 /// \param StartLoc Starting location of the clause. 6922 /// \param EndLoc Ending location of the clause. 6923 OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc) 6924 : OMPClause(llvm::omp::OMPC_nogroup, StartLoc, EndLoc) {} 6925 6926 /// Build an empty clause. 6927 OMPNogroupClause() 6928 : OMPClause(llvm::omp::OMPC_nogroup, SourceLocation(), SourceLocation()) { 6929 } 6930 6931 child_range children() { 6932 return child_range(child_iterator(), child_iterator()); 6933 } 6934 6935 const_child_range children() const { 6936 return const_child_range(const_child_iterator(), const_child_iterator()); 6937 } 6938 6939 child_range used_children() { 6940 return child_range(child_iterator(), child_iterator()); 6941 } 6942 const_child_range used_children() const { 6943 return const_child_range(const_child_iterator(), const_child_iterator()); 6944 } 6945 6946 static bool classof(const OMPClause *T) { 6947 return T->getClauseKind() == llvm::omp::OMPC_nogroup; 6948 } 6949 }; 6950 6951 /// This represents 'num_tasks' clause in the '#pragma omp ...' 6952 /// directive. 6953 /// 6954 /// \code 6955 /// #pragma omp taskloop num_tasks(4) 6956 /// \endcode 6957 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks' 6958 /// with single expression '4'. 6959 class OMPNumTasksClause : public OMPClause, public OMPClauseWithPreInit { 6960 friend class OMPClauseReader; 6961 6962 /// Location of '('. 6963 SourceLocation LParenLoc; 6964 6965 /// Modifiers for 'num_tasks' clause. 6966 OpenMPNumTasksClauseModifier Modifier = OMPC_NUMTASKS_unknown; 6967 6968 /// Location of the modifier. 6969 SourceLocation ModifierLoc; 6970 6971 /// Safe iteration space distance. 6972 Stmt *NumTasks = nullptr; 6973 6974 /// Set safelen. 6975 void setNumTasks(Expr *Size) { NumTasks = Size; } 6976 6977 /// Sets modifier. 6978 void setModifier(OpenMPNumTasksClauseModifier M) { Modifier = M; } 6979 6980 /// Sets modifier location. 6981 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; } 6982 6983 public: 6984 /// Build 'num_tasks' clause. 6985 /// 6986 /// \param Modifier Clause modifier. 6987 /// \param Size Expression associated with this clause. 6988 /// \param HelperSize Helper grainsize for the construct. 6989 /// \param CaptureRegion Innermost OpenMP region where expressions in this 6990 /// clause must be captured. 6991 /// \param StartLoc Starting location of the clause. 6992 /// \param EndLoc Ending location of the clause. 6993 /// \param ModifierLoc Modifier location. 6994 /// \param LParenLoc Location of '('. 6995 OMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *Size, 6996 Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion, 6997 SourceLocation StartLoc, SourceLocation LParenLoc, 6998 SourceLocation ModifierLoc, SourceLocation EndLoc) 6999 : OMPClause(llvm::omp::OMPC_num_tasks, StartLoc, EndLoc), 7000 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier), 7001 ModifierLoc(ModifierLoc), NumTasks(Size) { 7002 setPreInitStmt(HelperSize, CaptureRegion); 7003 } 7004 7005 /// Build an empty clause. 7006 explicit OMPNumTasksClause() 7007 : OMPClause(llvm::omp::OMPC_num_tasks, SourceLocation(), 7008 SourceLocation()), 7009 OMPClauseWithPreInit(this) {} 7010 7011 /// Sets the location of '('. 7012 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 7013 7014 /// Returns the location of '('. 7015 SourceLocation getLParenLoc() const { return LParenLoc; } 7016 7017 /// Return safe iteration space distance. 7018 Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); } 7019 7020 /// Gets modifier. 7021 OpenMPNumTasksClauseModifier getModifier() const { return Modifier; } 7022 7023 /// Gets modifier location. 7024 SourceLocation getModifierLoc() const { return ModifierLoc; } 7025 7026 child_range children() { return child_range(&NumTasks, &NumTasks + 1); } 7027 7028 const_child_range children() const { 7029 return const_child_range(&NumTasks, &NumTasks + 1); 7030 } 7031 7032 child_range used_children(); 7033 const_child_range used_children() const { 7034 auto Children = const_cast<OMPNumTasksClause *>(this)->used_children(); 7035 return const_child_range(Children.begin(), Children.end()); 7036 } 7037 7038 static bool classof(const OMPClause *T) { 7039 return T->getClauseKind() == llvm::omp::OMPC_num_tasks; 7040 } 7041 }; 7042 7043 /// This represents 'hint' clause in the '#pragma omp ...' directive. 7044 /// 7045 /// \code 7046 /// #pragma omp critical (name) hint(6) 7047 /// \endcode 7048 /// In this example directive '#pragma omp critical' has name 'name' and clause 7049 /// 'hint' with argument '6'. 7050 class OMPHintClause : public OMPClause { 7051 friend class OMPClauseReader; 7052 7053 /// Location of '('. 7054 SourceLocation LParenLoc; 7055 7056 /// Hint expression of the 'hint' clause. 7057 Stmt *Hint = nullptr; 7058 7059 /// Set hint expression. 7060 void setHint(Expr *H) { Hint = H; } 7061 7062 public: 7063 /// Build 'hint' clause with expression \a Hint. 7064 /// 7065 /// \param Hint Hint expression. 7066 /// \param StartLoc Starting location of the clause. 7067 /// \param LParenLoc Location of '('. 7068 /// \param EndLoc Ending location of the clause. 7069 OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, 7070 SourceLocation EndLoc) 7071 : OMPClause(llvm::omp::OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc), 7072 Hint(Hint) {} 7073 7074 /// Build an empty clause. 7075 OMPHintClause() 7076 : OMPClause(llvm::omp::OMPC_hint, SourceLocation(), SourceLocation()) {} 7077 7078 /// Sets the location of '('. 7079 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 7080 7081 /// Returns the location of '('. 7082 SourceLocation getLParenLoc() const { return LParenLoc; } 7083 7084 /// Returns number of threads. 7085 Expr *getHint() const { return cast_or_null<Expr>(Hint); } 7086 7087 child_range children() { return child_range(&Hint, &Hint + 1); } 7088 7089 const_child_range children() const { 7090 return const_child_range(&Hint, &Hint + 1); 7091 } 7092 7093 child_range used_children() { 7094 return child_range(child_iterator(), child_iterator()); 7095 } 7096 const_child_range used_children() const { 7097 return const_child_range(const_child_iterator(), const_child_iterator()); 7098 } 7099 7100 static bool classof(const OMPClause *T) { 7101 return T->getClauseKind() == llvm::omp::OMPC_hint; 7102 } 7103 }; 7104 7105 /// This represents 'dist_schedule' clause in the '#pragma omp ...' 7106 /// directive. 7107 /// 7108 /// \code 7109 /// #pragma omp distribute dist_schedule(static, 3) 7110 /// \endcode 7111 /// In this example directive '#pragma omp distribute' has 'dist_schedule' 7112 /// clause with arguments 'static' and '3'. 7113 class OMPDistScheduleClause : public OMPClause, public OMPClauseWithPreInit { 7114 friend class OMPClauseReader; 7115 7116 /// Location of '('. 7117 SourceLocation LParenLoc; 7118 7119 /// A kind of the 'schedule' clause. 7120 OpenMPDistScheduleClauseKind Kind = OMPC_DIST_SCHEDULE_unknown; 7121 7122 /// Start location of the schedule kind in source code. 7123 SourceLocation KindLoc; 7124 7125 /// Location of ',' (if any). 7126 SourceLocation CommaLoc; 7127 7128 /// Chunk size. 7129 Expr *ChunkSize = nullptr; 7130 7131 /// Set schedule kind. 7132 /// 7133 /// \param K Schedule kind. 7134 void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; } 7135 7136 /// Sets the location of '('. 7137 /// 7138 /// \param Loc Location of '('. 7139 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 7140 7141 /// Set schedule kind start location. 7142 /// 7143 /// \param KLoc Schedule kind location. 7144 void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; } 7145 7146 /// Set location of ','. 7147 /// 7148 /// \param Loc Location of ','. 7149 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; } 7150 7151 /// Set chunk size. 7152 /// 7153 /// \param E Chunk size. 7154 void setChunkSize(Expr *E) { ChunkSize = E; } 7155 7156 public: 7157 /// Build 'dist_schedule' clause with schedule kind \a Kind and chunk 7158 /// size expression \a ChunkSize. 7159 /// 7160 /// \param StartLoc Starting location of the clause. 7161 /// \param LParenLoc Location of '('. 7162 /// \param KLoc Starting location of the argument. 7163 /// \param CommaLoc Location of ','. 7164 /// \param EndLoc Ending location of the clause. 7165 /// \param Kind DistSchedule kind. 7166 /// \param ChunkSize Chunk size. 7167 /// \param HelperChunkSize Helper chunk size for combined directives. 7168 OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc, 7169 SourceLocation KLoc, SourceLocation CommaLoc, 7170 SourceLocation EndLoc, 7171 OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, 7172 Stmt *HelperChunkSize) 7173 : OMPClause(llvm::omp::OMPC_dist_schedule, StartLoc, EndLoc), 7174 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind), 7175 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) { 7176 setPreInitStmt(HelperChunkSize); 7177 } 7178 7179 /// Build an empty clause. 7180 explicit OMPDistScheduleClause() 7181 : OMPClause(llvm::omp::OMPC_dist_schedule, SourceLocation(), 7182 SourceLocation()), 7183 OMPClauseWithPreInit(this) {} 7184 7185 /// Get kind of the clause. 7186 OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; } 7187 7188 /// Get location of '('. 7189 SourceLocation getLParenLoc() { return LParenLoc; } 7190 7191 /// Get kind location. 7192 SourceLocation getDistScheduleKindLoc() { return KindLoc; } 7193 7194 /// Get location of ','. 7195 SourceLocation getCommaLoc() { return CommaLoc; } 7196 7197 /// Get chunk size. 7198 Expr *getChunkSize() { return ChunkSize; } 7199 7200 /// Get chunk size. 7201 const Expr *getChunkSize() const { return ChunkSize; } 7202 7203 child_range children() { 7204 return child_range(reinterpret_cast<Stmt **>(&ChunkSize), 7205 reinterpret_cast<Stmt **>(&ChunkSize) + 1); 7206 } 7207 7208 const_child_range children() const { 7209 auto Children = const_cast<OMPDistScheduleClause *>(this)->children(); 7210 return const_child_range(Children.begin(), Children.end()); 7211 } 7212 7213 child_range used_children() { 7214 return child_range(child_iterator(), child_iterator()); 7215 } 7216 const_child_range used_children() const { 7217 return const_child_range(const_child_iterator(), const_child_iterator()); 7218 } 7219 7220 static bool classof(const OMPClause *T) { 7221 return T->getClauseKind() == llvm::omp::OMPC_dist_schedule; 7222 } 7223 }; 7224 7225 /// This represents 'defaultmap' clause in the '#pragma omp ...' directive. 7226 /// 7227 /// \code 7228 /// #pragma omp target defaultmap(tofrom: scalar) 7229 /// \endcode 7230 /// In this example directive '#pragma omp target' has 'defaultmap' clause of kind 7231 /// 'scalar' with modifier 'tofrom'. 7232 class OMPDefaultmapClause : public OMPClause { 7233 friend class OMPClauseReader; 7234 7235 /// Location of '('. 7236 SourceLocation LParenLoc; 7237 7238 /// Modifiers for 'defaultmap' clause. 7239 OpenMPDefaultmapClauseModifier Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown; 7240 7241 /// Locations of modifiers. 7242 SourceLocation ModifierLoc; 7243 7244 /// A kind of the 'defaultmap' clause. 7245 OpenMPDefaultmapClauseKind Kind = OMPC_DEFAULTMAP_unknown; 7246 7247 /// Start location of the defaultmap kind in source code. 7248 SourceLocation KindLoc; 7249 7250 /// Set defaultmap kind. 7251 /// 7252 /// \param K Defaultmap kind. 7253 void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; } 7254 7255 /// Set the defaultmap modifier. 7256 /// 7257 /// \param M Defaultmap modifier. 7258 void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) { 7259 Modifier = M; 7260 } 7261 7262 /// Set location of the defaultmap modifier. 7263 void setDefaultmapModifierLoc(SourceLocation Loc) { 7264 ModifierLoc = Loc; 7265 } 7266 7267 /// Sets the location of '('. 7268 /// 7269 /// \param Loc Location of '('. 7270 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 7271 7272 /// Set defaultmap kind start location. 7273 /// 7274 /// \param KLoc Defaultmap kind location. 7275 void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; } 7276 7277 public: 7278 /// Build 'defaultmap' clause with defaultmap kind \a Kind 7279 /// 7280 /// \param StartLoc Starting location of the clause. 7281 /// \param LParenLoc Location of '('. 7282 /// \param KLoc Starting location of the argument. 7283 /// \param EndLoc Ending location of the clause. 7284 /// \param Kind Defaultmap kind. 7285 /// \param M The modifier applied to 'defaultmap' clause. 7286 /// \param MLoc Location of the modifier 7287 OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc, 7288 SourceLocation MLoc, SourceLocation KLoc, 7289 SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind, 7290 OpenMPDefaultmapClauseModifier M) 7291 : OMPClause(llvm::omp::OMPC_defaultmap, StartLoc, EndLoc), 7292 LParenLoc(LParenLoc), Modifier(M), ModifierLoc(MLoc), Kind(Kind), 7293 KindLoc(KLoc) {} 7294 7295 /// Build an empty clause. 7296 explicit OMPDefaultmapClause() 7297 : OMPClause(llvm::omp::OMPC_defaultmap, SourceLocation(), 7298 SourceLocation()) {} 7299 7300 /// Get kind of the clause. 7301 OpenMPDefaultmapClauseKind getDefaultmapKind() const { return Kind; } 7302 7303 /// Get the modifier of the clause. 7304 OpenMPDefaultmapClauseModifier getDefaultmapModifier() const { 7305 return Modifier; 7306 } 7307 7308 /// Get location of '('. 7309 SourceLocation getLParenLoc() { return LParenLoc; } 7310 7311 /// Get kind location. 7312 SourceLocation getDefaultmapKindLoc() { return KindLoc; } 7313 7314 /// Get the modifier location. 7315 SourceLocation getDefaultmapModifierLoc() const { 7316 return ModifierLoc; 7317 } 7318 7319 child_range children() { 7320 return child_range(child_iterator(), child_iterator()); 7321 } 7322 7323 const_child_range children() const { 7324 return const_child_range(const_child_iterator(), const_child_iterator()); 7325 } 7326 7327 child_range used_children() { 7328 return child_range(child_iterator(), child_iterator()); 7329 } 7330 const_child_range used_children() const { 7331 return const_child_range(const_child_iterator(), const_child_iterator()); 7332 } 7333 7334 static bool classof(const OMPClause *T) { 7335 return T->getClauseKind() == llvm::omp::OMPC_defaultmap; 7336 } 7337 }; 7338 7339 /// This represents clause 'to' in the '#pragma omp ...' 7340 /// directives. 7341 /// 7342 /// \code 7343 /// #pragma omp target update to(a,b) 7344 /// \endcode 7345 /// In this example directive '#pragma omp target update' has clause 'to' 7346 /// with the variables 'a' and 'b'. 7347 class OMPToClause final : public OMPMappableExprListClause<OMPToClause>, 7348 private llvm::TrailingObjects< 7349 OMPToClause, Expr *, ValueDecl *, unsigned, 7350 OMPClauseMappableExprCommon::MappableComponent> { 7351 friend class OMPClauseReader; 7352 friend OMPMappableExprListClause; 7353 friend OMPVarListClause; 7354 friend TrailingObjects; 7355 7356 /// Motion-modifiers for the 'to' clause. 7357 OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = { 7358 OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown}; 7359 7360 /// Location of motion-modifiers for the 'to' clause. 7361 SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers]; 7362 7363 /// Colon location. 7364 SourceLocation ColonLoc; 7365 7366 /// Build clause with number of variables \a NumVars. 7367 /// 7368 /// \param TheMotionModifiers Motion-modifiers. 7369 /// \param TheMotionModifiersLoc Locations of motion-modifiers. 7370 /// \param MapperQualifierLoc C++ nested name specifier for the associated 7371 /// user-defined mapper. 7372 /// \param MapperIdInfo The identifier of associated user-defined mapper. 7373 /// \param Locs Locations needed to build a mappable clause. It includes 1) 7374 /// StartLoc: starting location of the clause (the clause keyword); 2) 7375 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 7376 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 7377 /// NumVars: number of expressions listed in this clause; 2) 7378 /// NumUniqueDeclarations: number of unique base declarations in this clause; 7379 /// 3) NumComponentLists: number of component lists in this clause; and 4) 7380 /// NumComponents: total number of expression components in the clause. 7381 explicit OMPToClause(ArrayRef<OpenMPMotionModifierKind> TheMotionModifiers, 7382 ArrayRef<SourceLocation> TheMotionModifiersLoc, 7383 NestedNameSpecifierLoc MapperQualifierLoc, 7384 DeclarationNameInfo MapperIdInfo, 7385 const OMPVarListLocTy &Locs, 7386 const OMPMappableExprListSizeTy &Sizes) 7387 : OMPMappableExprListClause(llvm::omp::OMPC_to, Locs, Sizes, 7388 /*SupportsMapper=*/true, &MapperQualifierLoc, 7389 &MapperIdInfo) { 7390 assert(std::size(MotionModifiers) == TheMotionModifiers.size() && 7391 "Unexpected number of motion modifiers."); 7392 llvm::copy(TheMotionModifiers, std::begin(MotionModifiers)); 7393 7394 assert(std::size(MotionModifiersLoc) == TheMotionModifiersLoc.size() && 7395 "Unexpected number of motion modifier locations."); 7396 llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc)); 7397 } 7398 7399 /// Build an empty clause. 7400 /// 7401 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 7402 /// NumVars: number of expressions listed in this clause; 2) 7403 /// NumUniqueDeclarations: number of unique base declarations in this clause; 7404 /// 3) NumComponentLists: number of component lists in this clause; and 4) 7405 /// NumComponents: total number of expression components in the clause. 7406 explicit OMPToClause(const OMPMappableExprListSizeTy &Sizes) 7407 : OMPMappableExprListClause(llvm::omp::OMPC_to, OMPVarListLocTy(), Sizes, 7408 /*SupportsMapper=*/true) {} 7409 7410 /// Set motion-modifier for the clause. 7411 /// 7412 /// \param I index for motion-modifier. 7413 /// \param T motion-modifier for the clause. 7414 void setMotionModifier(unsigned I, OpenMPMotionModifierKind T) { 7415 assert(I < NumberOfOMPMotionModifiers && 7416 "Unexpected index to store motion modifier, exceeds array size."); 7417 MotionModifiers[I] = T; 7418 } 7419 7420 /// Set location for the motion-modifier. 7421 /// 7422 /// \param I index for motion-modifier location. 7423 /// \param TLoc motion-modifier location. 7424 void setMotionModifierLoc(unsigned I, SourceLocation TLoc) { 7425 assert(I < NumberOfOMPMotionModifiers && 7426 "Index to store motion modifier location exceeds array size."); 7427 MotionModifiersLoc[I] = TLoc; 7428 } 7429 7430 /// Set colon location. 7431 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 7432 7433 /// Define the sizes of each trailing object array except the last one. This 7434 /// is required for TrailingObjects to work properly. 7435 size_t numTrailingObjects(OverloadToken<Expr *>) const { 7436 // There are varlist_size() of expressions, and varlist_size() of 7437 // user-defined mappers. 7438 return 2 * varlist_size(); 7439 } 7440 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { 7441 return getUniqueDeclarationsNum(); 7442 } 7443 size_t numTrailingObjects(OverloadToken<unsigned>) const { 7444 return getUniqueDeclarationsNum() + getTotalComponentListNum(); 7445 } 7446 7447 public: 7448 /// Creates clause with a list of variables \a Vars. 7449 /// 7450 /// \param C AST context. 7451 /// \param Locs Locations needed to build a mappable clause. It includes 1) 7452 /// StartLoc: starting location of the clause (the clause keyword); 2) 7453 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 7454 /// \param Vars The original expression used in the clause. 7455 /// \param Declarations Declarations used in the clause. 7456 /// \param ComponentLists Component lists used in the clause. 7457 /// \param MotionModifiers Motion-modifiers. 7458 /// \param MotionModifiersLoc Location of motion-modifiers. 7459 /// \param UDMapperRefs References to user-defined mappers associated with 7460 /// expressions used in the clause. 7461 /// \param UDMQualifierLoc C++ nested name specifier for the associated 7462 /// user-defined mapper. 7463 /// \param MapperId The identifier of associated user-defined mapper. 7464 static OMPToClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs, 7465 ArrayRef<Expr *> Vars, 7466 ArrayRef<ValueDecl *> Declarations, 7467 MappableExprComponentListsRef ComponentLists, 7468 ArrayRef<Expr *> UDMapperRefs, 7469 ArrayRef<OpenMPMotionModifierKind> MotionModifiers, 7470 ArrayRef<SourceLocation> MotionModifiersLoc, 7471 NestedNameSpecifierLoc UDMQualifierLoc, 7472 DeclarationNameInfo MapperId); 7473 7474 /// Creates an empty clause with the place for \a NumVars variables. 7475 /// 7476 /// \param C AST context. 7477 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 7478 /// NumVars: number of expressions listed in this clause; 2) 7479 /// NumUniqueDeclarations: number of unique base declarations in this clause; 7480 /// 3) NumComponentLists: number of component lists in this clause; and 4) 7481 /// NumComponents: total number of expression components in the clause. 7482 static OMPToClause *CreateEmpty(const ASTContext &C, 7483 const OMPMappableExprListSizeTy &Sizes); 7484 7485 /// Fetches the motion-modifier at 'Cnt' index of array of modifiers. 7486 /// 7487 /// \param Cnt index for motion-modifier. 7488 OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY { 7489 assert(Cnt < NumberOfOMPMotionModifiers && 7490 "Requested modifier exceeds the total number of modifiers."); 7491 return MotionModifiers[Cnt]; 7492 } 7493 7494 /// Fetches the motion-modifier location at 'Cnt' index of array of modifiers' 7495 /// locations. 7496 /// 7497 /// \param Cnt index for motion-modifier location. 7498 SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY { 7499 assert(Cnt < NumberOfOMPMotionModifiers && 7500 "Requested modifier location exceeds total number of modifiers."); 7501 return MotionModifiersLoc[Cnt]; 7502 } 7503 7504 /// Fetches ArrayRef of motion-modifiers. 7505 ArrayRef<OpenMPMotionModifierKind> getMotionModifiers() const LLVM_READONLY { 7506 return llvm::ArrayRef(MotionModifiers); 7507 } 7508 7509 /// Fetches ArrayRef of location of motion-modifiers. 7510 ArrayRef<SourceLocation> getMotionModifiersLoc() const LLVM_READONLY { 7511 return llvm::ArrayRef(MotionModifiersLoc); 7512 } 7513 7514 /// Get colon location. 7515 SourceLocation getColonLoc() const { return ColonLoc; } 7516 7517 child_range children() { 7518 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 7519 reinterpret_cast<Stmt **>(varlist_end())); 7520 } 7521 7522 const_child_range children() const { 7523 auto Children = const_cast<OMPToClause *>(this)->children(); 7524 return const_child_range(Children.begin(), Children.end()); 7525 } 7526 7527 child_range used_children() { 7528 return child_range(child_iterator(), child_iterator()); 7529 } 7530 const_child_range used_children() const { 7531 return const_child_range(const_child_iterator(), const_child_iterator()); 7532 } 7533 7534 static bool classof(const OMPClause *T) { 7535 return T->getClauseKind() == llvm::omp::OMPC_to; 7536 } 7537 }; 7538 7539 /// This represents clause 'from' in the '#pragma omp ...' 7540 /// directives. 7541 /// 7542 /// \code 7543 /// #pragma omp target update from(a,b) 7544 /// \endcode 7545 /// In this example directive '#pragma omp target update' has clause 'from' 7546 /// with the variables 'a' and 'b'. 7547 class OMPFromClause final 7548 : public OMPMappableExprListClause<OMPFromClause>, 7549 private llvm::TrailingObjects< 7550 OMPFromClause, Expr *, ValueDecl *, unsigned, 7551 OMPClauseMappableExprCommon::MappableComponent> { 7552 friend class OMPClauseReader; 7553 friend OMPMappableExprListClause; 7554 friend OMPVarListClause; 7555 friend TrailingObjects; 7556 7557 /// Motion-modifiers for the 'from' clause. 7558 OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = { 7559 OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown}; 7560 7561 /// Location of motion-modifiers for the 'from' clause. 7562 SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers]; 7563 7564 /// Colon location. 7565 SourceLocation ColonLoc; 7566 7567 /// Build clause with number of variables \a NumVars. 7568 /// 7569 /// \param TheMotionModifiers Motion-modifiers. 7570 /// \param TheMotionModifiersLoc Locations of motion-modifiers. 7571 /// \param MapperQualifierLoc C++ nested name specifier for the associated 7572 /// user-defined mapper. 7573 /// \param MapperIdInfo The identifier of associated user-defined mapper. 7574 /// \param Locs Locations needed to build a mappable clause. It includes 1) 7575 /// StartLoc: starting location of the clause (the clause keyword); 2) 7576 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 7577 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 7578 /// NumVars: number of expressions listed in this clause; 2) 7579 /// NumUniqueDeclarations: number of unique base declarations in this clause; 7580 /// 3) NumComponentLists: number of component lists in this clause; and 4) 7581 /// NumComponents: total number of expression components in the clause. 7582 explicit OMPFromClause(ArrayRef<OpenMPMotionModifierKind> TheMotionModifiers, 7583 ArrayRef<SourceLocation> TheMotionModifiersLoc, 7584 NestedNameSpecifierLoc MapperQualifierLoc, 7585 DeclarationNameInfo MapperIdInfo, 7586 const OMPVarListLocTy &Locs, 7587 const OMPMappableExprListSizeTy &Sizes) 7588 : OMPMappableExprListClause(llvm::omp::OMPC_from, Locs, Sizes, 7589 /*SupportsMapper=*/true, &MapperQualifierLoc, 7590 &MapperIdInfo) { 7591 assert(std::size(MotionModifiers) == TheMotionModifiers.size() && 7592 "Unexpected number of motion modifiers."); 7593 llvm::copy(TheMotionModifiers, std::begin(MotionModifiers)); 7594 7595 assert(std::size(MotionModifiersLoc) == TheMotionModifiersLoc.size() && 7596 "Unexpected number of motion modifier locations."); 7597 llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc)); 7598 } 7599 7600 /// Build an empty clause. 7601 /// 7602 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 7603 /// NumVars: number of expressions listed in this clause; 2) 7604 /// NumUniqueDeclarations: number of unique base declarations in this clause; 7605 /// 3) NumComponentLists: number of component lists in this clause; and 4) 7606 /// NumComponents: total number of expression components in the clause. 7607 explicit OMPFromClause(const OMPMappableExprListSizeTy &Sizes) 7608 : OMPMappableExprListClause(llvm::omp::OMPC_from, OMPVarListLocTy(), 7609 Sizes, /*SupportsMapper=*/true) {} 7610 7611 /// Set motion-modifier for the clause. 7612 /// 7613 /// \param I index for motion-modifier. 7614 /// \param T motion-modifier for the clause. 7615 void setMotionModifier(unsigned I, OpenMPMotionModifierKind T) { 7616 assert(I < NumberOfOMPMotionModifiers && 7617 "Unexpected index to store motion modifier, exceeds array size."); 7618 MotionModifiers[I] = T; 7619 } 7620 7621 /// Set location for the motion-modifier. 7622 /// 7623 /// \param I index for motion-modifier location. 7624 /// \param TLoc motion-modifier location. 7625 void setMotionModifierLoc(unsigned I, SourceLocation TLoc) { 7626 assert(I < NumberOfOMPMotionModifiers && 7627 "Index to store motion modifier location exceeds array size."); 7628 MotionModifiersLoc[I] = TLoc; 7629 } 7630 7631 /// Set colon location. 7632 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 7633 7634 /// Define the sizes of each trailing object array except the last one. This 7635 /// is required for TrailingObjects to work properly. 7636 size_t numTrailingObjects(OverloadToken<Expr *>) const { 7637 // There are varlist_size() of expressions, and varlist_size() of 7638 // user-defined mappers. 7639 return 2 * varlist_size(); 7640 } 7641 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { 7642 return getUniqueDeclarationsNum(); 7643 } 7644 size_t numTrailingObjects(OverloadToken<unsigned>) const { 7645 return getUniqueDeclarationsNum() + getTotalComponentListNum(); 7646 } 7647 7648 public: 7649 /// Creates clause with a list of variables \a Vars. 7650 /// 7651 /// \param C AST context. 7652 /// \param Locs Locations needed to build a mappable clause. It includes 1) 7653 /// StartLoc: starting location of the clause (the clause keyword); 2) 7654 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 7655 /// \param Vars The original expression used in the clause. 7656 /// \param Declarations Declarations used in the clause. 7657 /// \param ComponentLists Component lists used in the clause. 7658 /// \param MotionModifiers Motion-modifiers. 7659 /// \param MotionModifiersLoc Location of motion-modifiers. 7660 /// \param UDMapperRefs References to user-defined mappers associated with 7661 /// expressions used in the clause. 7662 /// \param UDMQualifierLoc C++ nested name specifier for the associated 7663 /// user-defined mapper. 7664 /// \param MapperId The identifier of associated user-defined mapper. 7665 static OMPFromClause * 7666 Create(const ASTContext &C, const OMPVarListLocTy &Locs, 7667 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, 7668 MappableExprComponentListsRef ComponentLists, 7669 ArrayRef<Expr *> UDMapperRefs, 7670 ArrayRef<OpenMPMotionModifierKind> MotionModifiers, 7671 ArrayRef<SourceLocation> MotionModifiersLoc, 7672 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId); 7673 7674 /// Creates an empty clause with the place for \a NumVars variables. 7675 /// 7676 /// \param C AST context. 7677 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 7678 /// NumVars: number of expressions listed in this clause; 2) 7679 /// NumUniqueDeclarations: number of unique base declarations in this clause; 7680 /// 3) NumComponentLists: number of component lists in this clause; and 4) 7681 /// NumComponents: total number of expression components in the clause. 7682 static OMPFromClause *CreateEmpty(const ASTContext &C, 7683 const OMPMappableExprListSizeTy &Sizes); 7684 7685 /// Fetches the motion-modifier at 'Cnt' index of array of modifiers. 7686 /// 7687 /// \param Cnt index for motion-modifier. 7688 OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY { 7689 assert(Cnt < NumberOfOMPMotionModifiers && 7690 "Requested modifier exceeds the total number of modifiers."); 7691 return MotionModifiers[Cnt]; 7692 } 7693 7694 /// Fetches the motion-modifier location at 'Cnt' index of array of modifiers' 7695 /// locations. 7696 /// 7697 /// \param Cnt index for motion-modifier location. 7698 SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY { 7699 assert(Cnt < NumberOfOMPMotionModifiers && 7700 "Requested modifier location exceeds total number of modifiers."); 7701 return MotionModifiersLoc[Cnt]; 7702 } 7703 7704 /// Fetches ArrayRef of motion-modifiers. 7705 ArrayRef<OpenMPMotionModifierKind> getMotionModifiers() const LLVM_READONLY { 7706 return llvm::ArrayRef(MotionModifiers); 7707 } 7708 7709 /// Fetches ArrayRef of location of motion-modifiers. 7710 ArrayRef<SourceLocation> getMotionModifiersLoc() const LLVM_READONLY { 7711 return llvm::ArrayRef(MotionModifiersLoc); 7712 } 7713 7714 /// Get colon location. 7715 SourceLocation getColonLoc() const { return ColonLoc; } 7716 7717 child_range children() { 7718 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 7719 reinterpret_cast<Stmt **>(varlist_end())); 7720 } 7721 7722 const_child_range children() const { 7723 auto Children = const_cast<OMPFromClause *>(this)->children(); 7724 return const_child_range(Children.begin(), Children.end()); 7725 } 7726 7727 child_range used_children() { 7728 return child_range(child_iterator(), child_iterator()); 7729 } 7730 const_child_range used_children() const { 7731 return const_child_range(const_child_iterator(), const_child_iterator()); 7732 } 7733 7734 static bool classof(const OMPClause *T) { 7735 return T->getClauseKind() == llvm::omp::OMPC_from; 7736 } 7737 }; 7738 7739 /// This represents clause 'use_device_ptr' in the '#pragma omp ...' 7740 /// directives. 7741 /// 7742 /// \code 7743 /// #pragma omp target data use_device_ptr(a,b) 7744 /// \endcode 7745 /// In this example directive '#pragma omp target data' has clause 7746 /// 'use_device_ptr' with the variables 'a' and 'b'. 7747 class OMPUseDevicePtrClause final 7748 : public OMPMappableExprListClause<OMPUseDevicePtrClause>, 7749 private llvm::TrailingObjects< 7750 OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned, 7751 OMPClauseMappableExprCommon::MappableComponent> { 7752 friend class OMPClauseReader; 7753 friend OMPMappableExprListClause; 7754 friend OMPVarListClause; 7755 friend TrailingObjects; 7756 7757 /// Build clause with number of variables \a NumVars. 7758 /// 7759 /// \param Locs Locations needed to build a mappable clause. It includes 1) 7760 /// StartLoc: starting location of the clause (the clause keyword); 2) 7761 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 7762 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 7763 /// NumVars: number of expressions listed in this clause; 2) 7764 /// NumUniqueDeclarations: number of unique base declarations in this clause; 7765 /// 3) NumComponentLists: number of component lists in this clause; and 4) 7766 /// NumComponents: total number of expression components in the clause. 7767 explicit OMPUseDevicePtrClause(const OMPVarListLocTy &Locs, 7768 const OMPMappableExprListSizeTy &Sizes) 7769 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_ptr, Locs, Sizes) { 7770 } 7771 7772 /// Build an empty clause. 7773 /// 7774 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 7775 /// NumVars: number of expressions listed in this clause; 2) 7776 /// NumUniqueDeclarations: number of unique base declarations in this clause; 7777 /// 3) NumComponentLists: number of component lists in this clause; and 4) 7778 /// NumComponents: total number of expression components in the clause. 7779 explicit OMPUseDevicePtrClause(const OMPMappableExprListSizeTy &Sizes) 7780 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_ptr, 7781 OMPVarListLocTy(), Sizes) {} 7782 7783 /// Define the sizes of each trailing object array except the last one. This 7784 /// is required for TrailingObjects to work properly. 7785 size_t numTrailingObjects(OverloadToken<Expr *>) const { 7786 return 3 * varlist_size(); 7787 } 7788 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { 7789 return getUniqueDeclarationsNum(); 7790 } 7791 size_t numTrailingObjects(OverloadToken<unsigned>) const { 7792 return getUniqueDeclarationsNum() + getTotalComponentListNum(); 7793 } 7794 7795 /// Sets the list of references to private copies with initializers for new 7796 /// private variables. 7797 /// \param VL List of references. 7798 void setPrivateCopies(ArrayRef<Expr *> VL); 7799 7800 /// Gets the list of references to private copies with initializers for new 7801 /// private variables. 7802 MutableArrayRef<Expr *> getPrivateCopies() { 7803 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 7804 } 7805 ArrayRef<const Expr *> getPrivateCopies() const { 7806 return llvm::ArrayRef(varlist_end(), varlist_size()); 7807 } 7808 7809 /// Sets the list of references to initializer variables for new private 7810 /// variables. 7811 /// \param VL List of references. 7812 void setInits(ArrayRef<Expr *> VL); 7813 7814 /// Gets the list of references to initializer variables for new private 7815 /// variables. 7816 MutableArrayRef<Expr *> getInits() { 7817 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size()); 7818 } 7819 ArrayRef<const Expr *> getInits() const { 7820 return llvm::ArrayRef(getPrivateCopies().end(), varlist_size()); 7821 } 7822 7823 public: 7824 /// Creates clause with a list of variables \a Vars. 7825 /// 7826 /// \param C AST context. 7827 /// \param Locs Locations needed to build a mappable clause. It includes 1) 7828 /// StartLoc: starting location of the clause (the clause keyword); 2) 7829 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 7830 /// \param Vars The original expression used in the clause. 7831 /// \param PrivateVars Expressions referring to private copies. 7832 /// \param Inits Expressions referring to private copy initializers. 7833 /// \param Declarations Declarations used in the clause. 7834 /// \param ComponentLists Component lists used in the clause. 7835 static OMPUseDevicePtrClause * 7836 Create(const ASTContext &C, const OMPVarListLocTy &Locs, 7837 ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars, 7838 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations, 7839 MappableExprComponentListsRef ComponentLists); 7840 7841 /// Creates an empty clause with the place for \a NumVars variables. 7842 /// 7843 /// \param C AST context. 7844 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 7845 /// NumVars: number of expressions listed in this clause; 2) 7846 /// NumUniqueDeclarations: number of unique base declarations in this clause; 7847 /// 3) NumComponentLists: number of component lists in this clause; and 4) 7848 /// NumComponents: total number of expression components in the clause. 7849 static OMPUseDevicePtrClause * 7850 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes); 7851 7852 using private_copies_iterator = MutableArrayRef<Expr *>::iterator; 7853 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator; 7854 using private_copies_range = llvm::iterator_range<private_copies_iterator>; 7855 using private_copies_const_range = 7856 llvm::iterator_range<private_copies_const_iterator>; 7857 7858 private_copies_range private_copies() { 7859 return private_copies_range(getPrivateCopies().begin(), 7860 getPrivateCopies().end()); 7861 } 7862 7863 private_copies_const_range private_copies() const { 7864 return private_copies_const_range(getPrivateCopies().begin(), 7865 getPrivateCopies().end()); 7866 } 7867 7868 using inits_iterator = MutableArrayRef<Expr *>::iterator; 7869 using inits_const_iterator = ArrayRef<const Expr *>::iterator; 7870 using inits_range = llvm::iterator_range<inits_iterator>; 7871 using inits_const_range = llvm::iterator_range<inits_const_iterator>; 7872 7873 inits_range inits() { 7874 return inits_range(getInits().begin(), getInits().end()); 7875 } 7876 7877 inits_const_range inits() const { 7878 return inits_const_range(getInits().begin(), getInits().end()); 7879 } 7880 7881 child_range children() { 7882 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 7883 reinterpret_cast<Stmt **>(varlist_end())); 7884 } 7885 7886 const_child_range children() const { 7887 auto Children = const_cast<OMPUseDevicePtrClause *>(this)->children(); 7888 return const_child_range(Children.begin(), Children.end()); 7889 } 7890 7891 child_range used_children() { 7892 return child_range(child_iterator(), child_iterator()); 7893 } 7894 const_child_range used_children() const { 7895 return const_child_range(const_child_iterator(), const_child_iterator()); 7896 } 7897 7898 static bool classof(const OMPClause *T) { 7899 return T->getClauseKind() == llvm::omp::OMPC_use_device_ptr; 7900 } 7901 }; 7902 7903 /// This represents clause 'use_device_addr' in the '#pragma omp ...' 7904 /// directives. 7905 /// 7906 /// \code 7907 /// #pragma omp target data use_device_addr(a,b) 7908 /// \endcode 7909 /// In this example directive '#pragma omp target data' has clause 7910 /// 'use_device_addr' with the variables 'a' and 'b'. 7911 class OMPUseDeviceAddrClause final 7912 : public OMPMappableExprListClause<OMPUseDeviceAddrClause>, 7913 private llvm::TrailingObjects< 7914 OMPUseDeviceAddrClause, Expr *, ValueDecl *, unsigned, 7915 OMPClauseMappableExprCommon::MappableComponent> { 7916 friend class OMPClauseReader; 7917 friend OMPMappableExprListClause; 7918 friend OMPVarListClause; 7919 friend TrailingObjects; 7920 7921 /// Build clause with number of variables \a NumVars. 7922 /// 7923 /// \param Locs Locations needed to build a mappable clause. It includes 1) 7924 /// StartLoc: starting location of the clause (the clause keyword); 2) 7925 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 7926 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 7927 /// NumVars: number of expressions listed in this clause; 2) 7928 /// NumUniqueDeclarations: number of unique base declarations in this clause; 7929 /// 3) NumComponentLists: number of component lists in this clause; and 4) 7930 /// NumComponents: total number of expression components in the clause. 7931 explicit OMPUseDeviceAddrClause(const OMPVarListLocTy &Locs, 7932 const OMPMappableExprListSizeTy &Sizes) 7933 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_addr, Locs, 7934 Sizes) {} 7935 7936 /// Build an empty clause. 7937 /// 7938 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 7939 /// NumVars: number of expressions listed in this clause; 2) 7940 /// NumUniqueDeclarations: number of unique base declarations in this clause; 7941 /// 3) NumComponentLists: number of component lists in this clause; and 4) 7942 /// NumComponents: total number of expression components in the clause. 7943 explicit OMPUseDeviceAddrClause(const OMPMappableExprListSizeTy &Sizes) 7944 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_addr, 7945 OMPVarListLocTy(), Sizes) {} 7946 7947 /// Define the sizes of each trailing object array except the last one. This 7948 /// is required for TrailingObjects to work properly. 7949 size_t numTrailingObjects(OverloadToken<Expr *>) const { 7950 return varlist_size(); 7951 } 7952 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { 7953 return getUniqueDeclarationsNum(); 7954 } 7955 size_t numTrailingObjects(OverloadToken<unsigned>) const { 7956 return getUniqueDeclarationsNum() + getTotalComponentListNum(); 7957 } 7958 7959 public: 7960 /// Creates clause with a list of variables \a Vars. 7961 /// 7962 /// \param C AST context. 7963 /// \param Locs Locations needed to build a mappable clause. It includes 1) 7964 /// StartLoc: starting location of the clause (the clause keyword); 2) 7965 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 7966 /// \param Vars The original expression used in the clause. 7967 /// \param Declarations Declarations used in the clause. 7968 /// \param ComponentLists Component lists used in the clause. 7969 static OMPUseDeviceAddrClause * 7970 Create(const ASTContext &C, const OMPVarListLocTy &Locs, 7971 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, 7972 MappableExprComponentListsRef ComponentLists); 7973 7974 /// Creates an empty clause with the place for \a NumVars variables. 7975 /// 7976 /// \param C AST context. 7977 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 7978 /// NumVars: number of expressions listed in this clause; 2) 7979 /// NumUniqueDeclarations: number of unique base declarations in this clause; 7980 /// 3) NumComponentLists: number of component lists in this clause; and 4) 7981 /// NumComponents: total number of expression components in the clause. 7982 static OMPUseDeviceAddrClause * 7983 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes); 7984 7985 child_range children() { 7986 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 7987 reinterpret_cast<Stmt **>(varlist_end())); 7988 } 7989 7990 const_child_range children() const { 7991 auto Children = const_cast<OMPUseDeviceAddrClause *>(this)->children(); 7992 return const_child_range(Children.begin(), Children.end()); 7993 } 7994 7995 child_range used_children() { 7996 return child_range(child_iterator(), child_iterator()); 7997 } 7998 const_child_range used_children() const { 7999 return const_child_range(const_child_iterator(), const_child_iterator()); 8000 } 8001 8002 static bool classof(const OMPClause *T) { 8003 return T->getClauseKind() == llvm::omp::OMPC_use_device_addr; 8004 } 8005 }; 8006 8007 /// This represents clause 'is_device_ptr' in the '#pragma omp ...' 8008 /// directives. 8009 /// 8010 /// \code 8011 /// #pragma omp target is_device_ptr(a,b) 8012 /// \endcode 8013 /// In this example directive '#pragma omp target' has clause 8014 /// 'is_device_ptr' with the variables 'a' and 'b'. 8015 class OMPIsDevicePtrClause final 8016 : public OMPMappableExprListClause<OMPIsDevicePtrClause>, 8017 private llvm::TrailingObjects< 8018 OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned, 8019 OMPClauseMappableExprCommon::MappableComponent> { 8020 friend class OMPClauseReader; 8021 friend OMPMappableExprListClause; 8022 friend OMPVarListClause; 8023 friend TrailingObjects; 8024 8025 /// Build clause with number of variables \a NumVars. 8026 /// 8027 /// \param Locs Locations needed to build a mappable clause. It includes 1) 8028 /// StartLoc: starting location of the clause (the clause keyword); 2) 8029 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 8030 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 8031 /// NumVars: number of expressions listed in this clause; 2) 8032 /// NumUniqueDeclarations: number of unique base declarations in this clause; 8033 /// 3) NumComponentLists: number of component lists in this clause; and 4) 8034 /// NumComponents: total number of expression components in the clause. 8035 explicit OMPIsDevicePtrClause(const OMPVarListLocTy &Locs, 8036 const OMPMappableExprListSizeTy &Sizes) 8037 : OMPMappableExprListClause(llvm::omp::OMPC_is_device_ptr, Locs, Sizes) {} 8038 8039 /// Build an empty clause. 8040 /// 8041 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 8042 /// NumVars: number of expressions listed in this clause; 2) 8043 /// NumUniqueDeclarations: number of unique base declarations in this clause; 8044 /// 3) NumComponentLists: number of component lists in this clause; and 4) 8045 /// NumComponents: total number of expression components in the clause. 8046 explicit OMPIsDevicePtrClause(const OMPMappableExprListSizeTy &Sizes) 8047 : OMPMappableExprListClause(llvm::omp::OMPC_is_device_ptr, 8048 OMPVarListLocTy(), Sizes) {} 8049 8050 /// Define the sizes of each trailing object array except the last one. This 8051 /// is required for TrailingObjects to work properly. 8052 size_t numTrailingObjects(OverloadToken<Expr *>) const { 8053 return varlist_size(); 8054 } 8055 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { 8056 return getUniqueDeclarationsNum(); 8057 } 8058 size_t numTrailingObjects(OverloadToken<unsigned>) const { 8059 return getUniqueDeclarationsNum() + getTotalComponentListNum(); 8060 } 8061 8062 public: 8063 /// Creates clause with a list of variables \a Vars. 8064 /// 8065 /// \param C AST context. 8066 /// \param Locs Locations needed to build a mappable clause. It includes 1) 8067 /// StartLoc: starting location of the clause (the clause keyword); 2) 8068 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 8069 /// \param Vars The original expression used in the clause. 8070 /// \param Declarations Declarations used in the clause. 8071 /// \param ComponentLists Component lists used in the clause. 8072 static OMPIsDevicePtrClause * 8073 Create(const ASTContext &C, const OMPVarListLocTy &Locs, 8074 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, 8075 MappableExprComponentListsRef ComponentLists); 8076 8077 /// Creates an empty clause with the place for \a NumVars variables. 8078 /// 8079 /// \param C AST context. 8080 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 8081 /// NumVars: number of expressions listed in this clause; 2) 8082 /// NumUniqueDeclarations: number of unique base declarations in this clause; 8083 /// 3) NumComponentLists: number of component lists in this clause; and 4) 8084 /// NumComponents: total number of expression components in the clause. 8085 static OMPIsDevicePtrClause * 8086 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes); 8087 8088 child_range children() { 8089 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 8090 reinterpret_cast<Stmt **>(varlist_end())); 8091 } 8092 8093 const_child_range children() const { 8094 auto Children = const_cast<OMPIsDevicePtrClause *>(this)->children(); 8095 return const_child_range(Children.begin(), Children.end()); 8096 } 8097 8098 child_range used_children() { 8099 return child_range(child_iterator(), child_iterator()); 8100 } 8101 const_child_range used_children() const { 8102 return const_child_range(const_child_iterator(), const_child_iterator()); 8103 } 8104 8105 static bool classof(const OMPClause *T) { 8106 return T->getClauseKind() == llvm::omp::OMPC_is_device_ptr; 8107 } 8108 }; 8109 8110 /// This represents clause 'has_device_ptr' in the '#pragma omp ...' 8111 /// directives. 8112 /// 8113 /// \code 8114 /// #pragma omp target has_device_addr(a,b) 8115 /// \endcode 8116 /// In this example directive '#pragma omp target' has clause 8117 /// 'has_device_ptr' with the variables 'a' and 'b'. 8118 class OMPHasDeviceAddrClause final 8119 : public OMPMappableExprListClause<OMPHasDeviceAddrClause>, 8120 private llvm::TrailingObjects< 8121 OMPHasDeviceAddrClause, Expr *, ValueDecl *, unsigned, 8122 OMPClauseMappableExprCommon::MappableComponent> { 8123 friend class OMPClauseReader; 8124 friend OMPMappableExprListClause; 8125 friend OMPVarListClause; 8126 friend TrailingObjects; 8127 8128 /// Build clause with number of variables \a NumVars. 8129 /// 8130 /// \param Locs Locations needed to build a mappable clause. It includes 1) 8131 /// StartLoc: starting location of the clause (the clause keyword); 2) 8132 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 8133 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 8134 /// NumVars: number of expressions listed in this clause; 2) 8135 /// NumUniqueDeclarations: number of unique base declarations in this clause; 8136 /// 3) NumComponentLists: number of component lists in this clause; and 4) 8137 /// NumComponents: total number of expression components in the clause. 8138 explicit OMPHasDeviceAddrClause(const OMPVarListLocTy &Locs, 8139 const OMPMappableExprListSizeTy &Sizes) 8140 : OMPMappableExprListClause(llvm::omp::OMPC_has_device_addr, Locs, 8141 Sizes) {} 8142 8143 /// Build an empty clause. 8144 /// 8145 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 8146 /// NumVars: number of expressions listed in this clause; 2) 8147 /// NumUniqueDeclarations: number of unique base declarations in this clause; 8148 /// 3) NumComponentLists: number of component lists in this clause; and 4) 8149 /// NumComponents: total number of expression components in the clause. 8150 explicit OMPHasDeviceAddrClause(const OMPMappableExprListSizeTy &Sizes) 8151 : OMPMappableExprListClause(llvm::omp::OMPC_has_device_addr, 8152 OMPVarListLocTy(), Sizes) {} 8153 8154 /// Define the sizes of each trailing object array except the last one. This 8155 /// is required for TrailingObjects to work properly. 8156 size_t numTrailingObjects(OverloadToken<Expr *>) const { 8157 return varlist_size(); 8158 } 8159 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { 8160 return getUniqueDeclarationsNum(); 8161 } 8162 size_t numTrailingObjects(OverloadToken<unsigned>) const { 8163 return getUniqueDeclarationsNum() + getTotalComponentListNum(); 8164 } 8165 8166 public: 8167 /// Creates clause with a list of variables \a Vars. 8168 /// 8169 /// \param C AST context. 8170 /// \param Locs Locations needed to build a mappable clause. It includes 1) 8171 /// StartLoc: starting location of the clause (the clause keyword); 2) 8172 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause. 8173 /// \param Vars The original expression used in the clause. 8174 /// \param Declarations Declarations used in the clause. 8175 /// \param ComponentLists Component lists used in the clause. 8176 static OMPHasDeviceAddrClause * 8177 Create(const ASTContext &C, const OMPVarListLocTy &Locs, 8178 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, 8179 MappableExprComponentListsRef ComponentLists); 8180 8181 /// Creates an empty clause with the place for \a NumVars variables. 8182 /// 8183 /// \param C AST context. 8184 /// \param Sizes All required sizes to build a mappable clause. It includes 1) 8185 /// NumVars: number of expressions listed in this clause; 2) 8186 /// NumUniqueDeclarations: number of unique base declarations in this clause; 8187 /// 3) NumComponentLists: number of component lists in this clause; and 4) 8188 /// NumComponents: total number of expression components in the clause. 8189 static OMPHasDeviceAddrClause * 8190 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes); 8191 8192 child_range children() { 8193 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 8194 reinterpret_cast<Stmt **>(varlist_end())); 8195 } 8196 8197 const_child_range children() const { 8198 auto Children = const_cast<OMPHasDeviceAddrClause *>(this)->children(); 8199 return const_child_range(Children.begin(), Children.end()); 8200 } 8201 8202 child_range used_children() { 8203 return child_range(child_iterator(), child_iterator()); 8204 } 8205 const_child_range used_children() const { 8206 return const_child_range(const_child_iterator(), const_child_iterator()); 8207 } 8208 8209 static bool classof(const OMPClause *T) { 8210 return T->getClauseKind() == llvm::omp::OMPC_has_device_addr; 8211 } 8212 }; 8213 8214 /// This represents clause 'nontemporal' in the '#pragma omp ...' directives. 8215 /// 8216 /// \code 8217 /// #pragma omp simd nontemporal(a) 8218 /// \endcode 8219 /// In this example directive '#pragma omp simd' has clause 'nontemporal' for 8220 /// the variable 'a'. 8221 class OMPNontemporalClause final 8222 : public OMPVarListClause<OMPNontemporalClause>, 8223 private llvm::TrailingObjects<OMPNontemporalClause, Expr *> { 8224 friend class OMPClauseReader; 8225 friend OMPVarListClause; 8226 friend TrailingObjects; 8227 8228 /// Build clause with number of variables \a N. 8229 /// 8230 /// \param StartLoc Starting location of the clause. 8231 /// \param LParenLoc Location of '('. 8232 /// \param EndLoc Ending location of the clause. 8233 /// \param N Number of the variables in the clause. 8234 OMPNontemporalClause(SourceLocation StartLoc, SourceLocation LParenLoc, 8235 SourceLocation EndLoc, unsigned N) 8236 : OMPVarListClause<OMPNontemporalClause>(llvm::omp::OMPC_nontemporal, 8237 StartLoc, LParenLoc, EndLoc, N) { 8238 } 8239 8240 /// Build an empty clause. 8241 /// 8242 /// \param N Number of variables. 8243 explicit OMPNontemporalClause(unsigned N) 8244 : OMPVarListClause<OMPNontemporalClause>( 8245 llvm::omp::OMPC_nontemporal, SourceLocation(), SourceLocation(), 8246 SourceLocation(), N) {} 8247 8248 /// Get the list of privatied copies if the member expression was captured by 8249 /// one of the privatization clauses. 8250 MutableArrayRef<Expr *> getPrivateRefs() { 8251 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 8252 } 8253 ArrayRef<const Expr *> getPrivateRefs() const { 8254 return llvm::ArrayRef(varlist_end(), varlist_size()); 8255 } 8256 8257 public: 8258 /// Creates clause with a list of variables \a VL. 8259 /// 8260 /// \param C AST context. 8261 /// \param StartLoc Starting location of the clause. 8262 /// \param LParenLoc Location of '('. 8263 /// \param EndLoc Ending location of the clause. 8264 /// \param VL List of references to the variables. 8265 static OMPNontemporalClause * 8266 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 8267 SourceLocation EndLoc, ArrayRef<Expr *> VL); 8268 8269 /// Creates an empty clause with the place for \a N variables. 8270 /// 8271 /// \param C AST context. 8272 /// \param N The number of variables. 8273 static OMPNontemporalClause *CreateEmpty(const ASTContext &C, unsigned N); 8274 8275 /// Sets the list of references to private copies created in private clauses. 8276 /// \param VL List of references. 8277 void setPrivateRefs(ArrayRef<Expr *> VL); 8278 8279 child_range children() { 8280 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 8281 reinterpret_cast<Stmt **>(varlist_end())); 8282 } 8283 8284 const_child_range children() const { 8285 auto Children = const_cast<OMPNontemporalClause *>(this)->children(); 8286 return const_child_range(Children.begin(), Children.end()); 8287 } 8288 8289 child_range private_refs() { 8290 return child_range(reinterpret_cast<Stmt **>(getPrivateRefs().begin()), 8291 reinterpret_cast<Stmt **>(getPrivateRefs().end())); 8292 } 8293 8294 const_child_range private_refs() const { 8295 auto Children = const_cast<OMPNontemporalClause *>(this)->private_refs(); 8296 return const_child_range(Children.begin(), Children.end()); 8297 } 8298 8299 child_range used_children() { 8300 return child_range(child_iterator(), child_iterator()); 8301 } 8302 const_child_range used_children() const { 8303 return const_child_range(const_child_iterator(), const_child_iterator()); 8304 } 8305 8306 static bool classof(const OMPClause *T) { 8307 return T->getClauseKind() == llvm::omp::OMPC_nontemporal; 8308 } 8309 }; 8310 8311 /// This represents 'order' clause in the '#pragma omp ...' directive. 8312 /// 8313 /// \code 8314 /// #pragma omp simd order(concurrent) 8315 /// \endcode 8316 /// In this example directive '#pragma omp parallel' has simple 'order' 8317 /// clause with kind 'concurrent'. 8318 class OMPOrderClause final : public OMPClause { 8319 friend class OMPClauseReader; 8320 8321 /// Location of '('. 8322 SourceLocation LParenLoc; 8323 8324 /// A kind of the 'order' clause. 8325 OpenMPOrderClauseKind Kind = OMPC_ORDER_unknown; 8326 8327 /// Start location of the kind in source code. 8328 SourceLocation KindKwLoc; 8329 8330 /// A modifier for order clause 8331 OpenMPOrderClauseModifier Modifier = OMPC_ORDER_MODIFIER_unknown; 8332 8333 /// Start location of the modifier in source code. 8334 SourceLocation ModifierKwLoc; 8335 8336 /// Set kind of the clause. 8337 /// 8338 /// \param K Argument of clause. 8339 void setKind(OpenMPOrderClauseKind K) { Kind = K; } 8340 8341 /// Set argument location. 8342 /// 8343 /// \param KLoc Argument location. 8344 void setKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; } 8345 8346 /// Set modifier of the clause. 8347 /// 8348 /// \param M Argument of clause. 8349 void setModifier(OpenMPOrderClauseModifier M) { Modifier = M; } 8350 8351 /// Set modifier location. 8352 /// 8353 /// \param MLoc Modifier keyword location. 8354 void setModifierKwLoc(SourceLocation MLoc) { ModifierKwLoc = MLoc; } 8355 8356 public: 8357 /// Build 'order' clause with argument \p A ('concurrent'). 8358 /// 8359 /// \param A Argument of the clause ('concurrent'). 8360 /// \param ALoc Starting location of the argument. 8361 /// \param StartLoc Starting location of the clause. 8362 /// \param LParenLoc Location of '('. 8363 /// \param EndLoc Ending location of the clause. 8364 /// \param Modifier The modifier applied to 'order' clause. 8365 /// \param MLoc Location of the modifier 8366 OMPOrderClause(OpenMPOrderClauseKind A, SourceLocation ALoc, 8367 SourceLocation StartLoc, SourceLocation LParenLoc, 8368 SourceLocation EndLoc, OpenMPOrderClauseModifier Modifier, 8369 SourceLocation MLoc) 8370 : OMPClause(llvm::omp::OMPC_order, StartLoc, EndLoc), 8371 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc), Modifier(Modifier), 8372 ModifierKwLoc(MLoc) {} 8373 8374 /// Build an empty clause. 8375 OMPOrderClause() 8376 : OMPClause(llvm::omp::OMPC_order, SourceLocation(), SourceLocation()) {} 8377 8378 /// Sets the location of '('. 8379 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 8380 8381 /// Returns the location of '('. 8382 SourceLocation getLParenLoc() const { return LParenLoc; } 8383 8384 /// Returns kind of the clause. 8385 OpenMPOrderClauseKind getKind() const { return Kind; } 8386 8387 /// Returns location of clause kind. 8388 SourceLocation getKindKwLoc() const { return KindKwLoc; } 8389 8390 /// Returns Modifier of the clause. 8391 OpenMPOrderClauseModifier getModifier() const { return Modifier; } 8392 8393 /// Returns location of clause modifier. 8394 SourceLocation getModifierKwLoc() const { return ModifierKwLoc; } 8395 8396 child_range children() { 8397 return child_range(child_iterator(), child_iterator()); 8398 } 8399 8400 const_child_range children() const { 8401 return const_child_range(const_child_iterator(), const_child_iterator()); 8402 } 8403 8404 child_range used_children() { 8405 return child_range(child_iterator(), child_iterator()); 8406 } 8407 const_child_range used_children() const { 8408 return const_child_range(const_child_iterator(), const_child_iterator()); 8409 } 8410 8411 static bool classof(const OMPClause *T) { 8412 return T->getClauseKind() == llvm::omp::OMPC_order; 8413 } 8414 }; 8415 8416 /// This represents the 'init' clause in '#pragma omp ...' directives. 8417 /// 8418 /// \code 8419 /// #pragma omp interop init(target:obj) 8420 /// \endcode 8421 class OMPInitClause final 8422 : public OMPVarListClause<OMPInitClause>, 8423 private llvm::TrailingObjects<OMPInitClause, Expr *> { 8424 friend class OMPClauseReader; 8425 friend OMPVarListClause; 8426 friend TrailingObjects; 8427 8428 /// Location of interop variable. 8429 SourceLocation VarLoc; 8430 8431 bool IsTarget = false; 8432 bool IsTargetSync = false; 8433 8434 void setInteropVar(Expr *E) { varlist_begin()[0] = E; } 8435 8436 void setIsTarget(bool V) { IsTarget = V; } 8437 8438 void setIsTargetSync(bool V) { IsTargetSync = V; } 8439 8440 /// Sets the location of the interop variable. 8441 void setVarLoc(SourceLocation Loc) { VarLoc = Loc; } 8442 8443 /// Build 'init' clause. 8444 /// 8445 /// \param IsTarget Uses the 'target' interop-type. 8446 /// \param IsTargetSync Uses the 'targetsync' interop-type. 8447 /// \param StartLoc Starting location of the clause. 8448 /// \param LParenLoc Location of '('. 8449 /// \param VarLoc Location of the interop variable. 8450 /// \param EndLoc Ending location of the clause. 8451 /// \param N Number of expressions. 8452 OMPInitClause(bool IsTarget, bool IsTargetSync, SourceLocation StartLoc, 8453 SourceLocation LParenLoc, SourceLocation VarLoc, 8454 SourceLocation EndLoc, unsigned N) 8455 : OMPVarListClause<OMPInitClause>(llvm::omp::OMPC_init, StartLoc, 8456 LParenLoc, EndLoc, N), 8457 VarLoc(VarLoc), IsTarget(IsTarget), IsTargetSync(IsTargetSync) {} 8458 8459 /// Build an empty clause. 8460 OMPInitClause(unsigned N) 8461 : OMPVarListClause<OMPInitClause>(llvm::omp::OMPC_init, SourceLocation(), 8462 SourceLocation(), SourceLocation(), N) { 8463 } 8464 8465 public: 8466 /// Creates a fully specified clause. 8467 /// 8468 /// \param C AST context. 8469 /// \param InteropVar The interop variable. 8470 /// \param InteropInfo The interop-type and prefer_type list. 8471 /// \param StartLoc Starting location of the clause. 8472 /// \param LParenLoc Location of '('. 8473 /// \param VarLoc Location of the interop variable. 8474 /// \param EndLoc Ending location of the clause. 8475 static OMPInitClause *Create(const ASTContext &C, Expr *InteropVar, 8476 OMPInteropInfo &InteropInfo, 8477 SourceLocation StartLoc, 8478 SourceLocation LParenLoc, SourceLocation VarLoc, 8479 SourceLocation EndLoc); 8480 8481 /// Creates an empty clause with \a N expressions. 8482 /// 8483 /// \param C AST context. 8484 /// \param N Number of expression items. 8485 static OMPInitClause *CreateEmpty(const ASTContext &C, unsigned N); 8486 8487 /// Returns the location of the interop variable. 8488 SourceLocation getVarLoc() const { return VarLoc; } 8489 8490 /// Returns the interop variable. 8491 Expr *getInteropVar() { return varlist_begin()[0]; } 8492 const Expr *getInteropVar() const { return varlist_begin()[0]; } 8493 8494 /// Returns true is interop-type 'target' is used. 8495 bool getIsTarget() const { return IsTarget; } 8496 8497 /// Returns true is interop-type 'targetsync' is used. 8498 bool getIsTargetSync() const { return IsTargetSync; } 8499 8500 child_range children() { 8501 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 8502 reinterpret_cast<Stmt **>(varlist_end())); 8503 } 8504 8505 const_child_range children() const { 8506 auto Children = const_cast<OMPInitClause *>(this)->children(); 8507 return const_child_range(Children.begin(), Children.end()); 8508 } 8509 8510 child_range used_children() { 8511 return child_range(child_iterator(), child_iterator()); 8512 } 8513 const_child_range used_children() const { 8514 return const_child_range(const_child_iterator(), const_child_iterator()); 8515 } 8516 8517 using prefs_iterator = MutableArrayRef<Expr *>::iterator; 8518 using const_prefs_iterator = ArrayRef<const Expr *>::iterator; 8519 using prefs_range = llvm::iterator_range<prefs_iterator>; 8520 using const_prefs_range = llvm::iterator_range<const_prefs_iterator>; 8521 8522 prefs_range prefs() { 8523 return prefs_range(reinterpret_cast<Expr **>(std::next(varlist_begin())), 8524 reinterpret_cast<Expr **>(varlist_end())); 8525 } 8526 8527 const_prefs_range prefs() const { 8528 auto Prefs = const_cast<OMPInitClause *>(this)->prefs(); 8529 return const_prefs_range(Prefs.begin(), Prefs.end()); 8530 } 8531 8532 static bool classof(const OMPClause *T) { 8533 return T->getClauseKind() == llvm::omp::OMPC_init; 8534 } 8535 }; 8536 8537 /// This represents the 'use' clause in '#pragma omp ...' directives. 8538 /// 8539 /// \code 8540 /// #pragma omp interop use(obj) 8541 /// \endcode 8542 class OMPUseClause final : public OMPClause { 8543 friend class OMPClauseReader; 8544 8545 /// Location of '('. 8546 SourceLocation LParenLoc; 8547 8548 /// Location of interop variable. 8549 SourceLocation VarLoc; 8550 8551 /// The interop variable. 8552 Stmt *InteropVar = nullptr; 8553 8554 /// Set the interop variable. 8555 void setInteropVar(Expr *E) { InteropVar = E; } 8556 8557 /// Sets the location of '('. 8558 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 8559 8560 /// Sets the location of the interop variable. 8561 void setVarLoc(SourceLocation Loc) { VarLoc = Loc; } 8562 8563 public: 8564 /// Build 'use' clause with and interop variable expression \a InteropVar. 8565 /// 8566 /// \param InteropVar The interop variable. 8567 /// \param StartLoc Starting location of the clause. 8568 /// \param LParenLoc Location of '('. 8569 /// \param VarLoc Location of the interop variable. 8570 /// \param EndLoc Ending location of the clause. 8571 OMPUseClause(Expr *InteropVar, SourceLocation StartLoc, 8572 SourceLocation LParenLoc, SourceLocation VarLoc, 8573 SourceLocation EndLoc) 8574 : OMPClause(llvm::omp::OMPC_use, StartLoc, EndLoc), LParenLoc(LParenLoc), 8575 VarLoc(VarLoc), InteropVar(InteropVar) {} 8576 8577 /// Build an empty clause. 8578 OMPUseClause() 8579 : OMPClause(llvm::omp::OMPC_use, SourceLocation(), SourceLocation()) {} 8580 8581 /// Returns the location of '('. 8582 SourceLocation getLParenLoc() const { return LParenLoc; } 8583 8584 /// Returns the location of the interop variable. 8585 SourceLocation getVarLoc() const { return VarLoc; } 8586 8587 /// Returns the interop variable. 8588 Expr *getInteropVar() const { return cast<Expr>(InteropVar); } 8589 8590 child_range children() { return child_range(&InteropVar, &InteropVar + 1); } 8591 8592 const_child_range children() const { 8593 return const_child_range(&InteropVar, &InteropVar + 1); 8594 } 8595 8596 child_range used_children() { 8597 return child_range(child_iterator(), child_iterator()); 8598 } 8599 const_child_range used_children() const { 8600 return const_child_range(const_child_iterator(), const_child_iterator()); 8601 } 8602 8603 static bool classof(const OMPClause *T) { 8604 return T->getClauseKind() == llvm::omp::OMPC_use; 8605 } 8606 }; 8607 8608 /// This represents 'destroy' clause in the '#pragma omp depobj' 8609 /// directive or the '#pragma omp interop' directive.. 8610 /// 8611 /// \code 8612 /// #pragma omp depobj(a) destroy 8613 /// #pragma omp interop destroy(obj) 8614 /// \endcode 8615 /// In these examples directive '#pragma omp depobj' and '#pragma omp interop' 8616 /// have a 'destroy' clause. The 'interop' directive includes an object. 8617 class OMPDestroyClause final : public OMPClause { 8618 friend class OMPClauseReader; 8619 8620 /// Location of '('. 8621 SourceLocation LParenLoc; 8622 8623 /// Location of interop variable. 8624 SourceLocation VarLoc; 8625 8626 /// The interop variable. 8627 Stmt *InteropVar = nullptr; 8628 8629 /// Set the interop variable. 8630 void setInteropVar(Expr *E) { InteropVar = E; } 8631 8632 /// Sets the location of '('. 8633 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 8634 8635 /// Sets the location of the interop variable. 8636 void setVarLoc(SourceLocation Loc) { VarLoc = Loc; } 8637 8638 public: 8639 /// Build 'destroy' clause with an interop variable expression \a InteropVar. 8640 /// 8641 /// \param InteropVar The interop variable. 8642 /// \param StartLoc Starting location of the clause. 8643 /// \param LParenLoc Location of '('. 8644 /// \param VarLoc Location of the interop variable. 8645 /// \param EndLoc Ending location of the clause. 8646 OMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, 8647 SourceLocation LParenLoc, SourceLocation VarLoc, 8648 SourceLocation EndLoc) 8649 : OMPClause(llvm::omp::OMPC_destroy, StartLoc, EndLoc), 8650 LParenLoc(LParenLoc), VarLoc(VarLoc), InteropVar(InteropVar) {} 8651 8652 /// Build 'destroy' clause. 8653 /// 8654 /// \param StartLoc Starting location of the clause. 8655 /// \param EndLoc Ending location of the clause. 8656 OMPDestroyClause(SourceLocation StartLoc, SourceLocation EndLoc) 8657 : OMPClause(llvm::omp::OMPC_destroy, StartLoc, EndLoc) {} 8658 8659 /// Build an empty clause. 8660 OMPDestroyClause() 8661 : OMPClause(llvm::omp::OMPC_destroy, SourceLocation(), SourceLocation()) { 8662 } 8663 8664 /// Returns the location of '('. 8665 SourceLocation getLParenLoc() const { return LParenLoc; } 8666 8667 /// Returns the location of the interop variable. 8668 SourceLocation getVarLoc() const { return VarLoc; } 8669 8670 /// Returns the interop variable. 8671 Expr *getInteropVar() const { return cast_or_null<Expr>(InteropVar); } 8672 8673 child_range children() { 8674 if (InteropVar) 8675 return child_range(&InteropVar, &InteropVar + 1); 8676 return child_range(child_iterator(), child_iterator()); 8677 } 8678 8679 const_child_range children() const { 8680 if (InteropVar) 8681 return const_child_range(&InteropVar, &InteropVar + 1); 8682 return const_child_range(const_child_iterator(), const_child_iterator()); 8683 } 8684 8685 child_range used_children() { 8686 return child_range(child_iterator(), child_iterator()); 8687 } 8688 const_child_range used_children() const { 8689 return const_child_range(const_child_iterator(), const_child_iterator()); 8690 } 8691 8692 static bool classof(const OMPClause *T) { 8693 return T->getClauseKind() == llvm::omp::OMPC_destroy; 8694 } 8695 }; 8696 8697 /// This represents 'novariants' clause in the '#pragma omp ...' directive. 8698 /// 8699 /// \code 8700 /// #pragma omp dispatch novariants(a > 5) 8701 /// \endcode 8702 /// In this example directive '#pragma omp dispatch' has simple 'novariants' 8703 /// clause with condition 'a > 5'. 8704 class OMPNovariantsClause final 8705 : public OMPOneStmtClause<llvm::omp::OMPC_novariants, OMPClause>, 8706 public OMPClauseWithPreInit { 8707 friend class OMPClauseReader; 8708 8709 /// Set condition. 8710 void setCondition(Expr *Cond) { setStmt(Cond); } 8711 8712 public: 8713 /// Build 'novariants' clause with condition \a Cond. 8714 /// 8715 /// \param Cond Condition of the clause. 8716 /// \param HelperCond Helper condition for the construct. 8717 /// \param CaptureRegion Innermost OpenMP region where expressions in this 8718 /// clause must be captured. 8719 /// \param StartLoc Starting location of the clause. 8720 /// \param LParenLoc Location of '('. 8721 /// \param EndLoc Ending location of the clause. 8722 OMPNovariantsClause(Expr *Cond, Stmt *HelperCond, 8723 OpenMPDirectiveKind CaptureRegion, 8724 SourceLocation StartLoc, SourceLocation LParenLoc, 8725 SourceLocation EndLoc) 8726 : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc), 8727 OMPClauseWithPreInit(this) { 8728 setPreInitStmt(HelperCond, CaptureRegion); 8729 } 8730 8731 /// Build an empty clause. 8732 OMPNovariantsClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {} 8733 8734 /// Returns condition. 8735 Expr *getCondition() const { return getStmtAs<Expr>(); } 8736 8737 child_range used_children(); 8738 const_child_range used_children() const { 8739 auto Children = const_cast<OMPNovariantsClause *>(this)->used_children(); 8740 return const_child_range(Children.begin(), Children.end()); 8741 } 8742 }; 8743 8744 /// This represents 'nocontext' clause in the '#pragma omp ...' directive. 8745 /// 8746 /// \code 8747 /// #pragma omp dispatch nocontext(a > 5) 8748 /// \endcode 8749 /// In this example directive '#pragma omp dispatch' has simple 'nocontext' 8750 /// clause with condition 'a > 5'. 8751 class OMPNocontextClause final 8752 : public OMPOneStmtClause<llvm::omp::OMPC_nocontext, OMPClause>, 8753 public OMPClauseWithPreInit { 8754 friend class OMPClauseReader; 8755 8756 /// Set condition. 8757 void setCondition(Expr *Cond) { setStmt(Cond); } 8758 8759 public: 8760 /// Build 'nocontext' clause with condition \a Cond. 8761 /// 8762 /// \param Cond Condition of the clause. 8763 /// \param HelperCond Helper condition for the construct. 8764 /// \param CaptureRegion Innermost OpenMP region where expressions in this 8765 /// clause must be captured. 8766 /// \param StartLoc Starting location of the clause. 8767 /// \param LParenLoc Location of '('. 8768 /// \param EndLoc Ending location of the clause. 8769 OMPNocontextClause(Expr *Cond, Stmt *HelperCond, 8770 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, 8771 SourceLocation LParenLoc, SourceLocation EndLoc) 8772 : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc), 8773 OMPClauseWithPreInit(this) { 8774 setPreInitStmt(HelperCond, CaptureRegion); 8775 } 8776 8777 /// Build an empty clause. 8778 OMPNocontextClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {} 8779 8780 /// Returns condition. 8781 Expr *getCondition() const { return getStmtAs<Expr>(); } 8782 8783 child_range used_children(); 8784 const_child_range used_children() const { 8785 auto Children = const_cast<OMPNocontextClause *>(this)->used_children(); 8786 return const_child_range(Children.begin(), Children.end()); 8787 } 8788 }; 8789 8790 /// This represents 'detach' clause in the '#pragma omp task' directive. 8791 /// 8792 /// \code 8793 /// #pragma omp task detach(evt) 8794 /// \endcode 8795 /// In this example directive '#pragma omp detach' has simple 'detach' clause 8796 /// with the variable 'evt'. 8797 class OMPDetachClause final 8798 : public OMPOneStmtClause<llvm::omp::OMPC_detach, OMPClause> { 8799 friend class OMPClauseReader; 8800 8801 /// Set condition. 8802 void setEventHandler(Expr *E) { setStmt(E); } 8803 8804 public: 8805 /// Build 'detach' clause with event-handler \a Evt. 8806 /// 8807 /// \param Evt Event handler expression. 8808 /// \param StartLoc Starting location of the clause. 8809 /// \param LParenLoc Location of '('. 8810 /// \param EndLoc Ending location of the clause. 8811 OMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, 8812 SourceLocation EndLoc) 8813 : OMPOneStmtClause(Evt, StartLoc, LParenLoc, EndLoc) {} 8814 8815 /// Build an empty clause. 8816 OMPDetachClause() : OMPOneStmtClause() {} 8817 8818 /// Returns event-handler expression. 8819 Expr *getEventHandler() const { return getStmtAs<Expr>(); } 8820 }; 8821 8822 /// This represents clause 'inclusive' in the '#pragma omp scan' directive. 8823 /// 8824 /// \code 8825 /// #pragma omp scan inclusive(a,b) 8826 /// \endcode 8827 /// In this example directive '#pragma omp scan' has clause 'inclusive' 8828 /// with the variables 'a' and 'b'. 8829 class OMPInclusiveClause final 8830 : public OMPVarListClause<OMPInclusiveClause>, 8831 private llvm::TrailingObjects<OMPInclusiveClause, Expr *> { 8832 friend class OMPClauseReader; 8833 friend OMPVarListClause; 8834 friend TrailingObjects; 8835 8836 /// Build clause with number of variables \a N. 8837 /// 8838 /// \param StartLoc Starting location of the clause. 8839 /// \param LParenLoc Location of '('. 8840 /// \param EndLoc Ending location of the clause. 8841 /// \param N Number of the variables in the clause. 8842 OMPInclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc, 8843 SourceLocation EndLoc, unsigned N) 8844 : OMPVarListClause<OMPInclusiveClause>(llvm::omp::OMPC_inclusive, 8845 StartLoc, LParenLoc, EndLoc, N) {} 8846 8847 /// Build an empty clause. 8848 /// 8849 /// \param N Number of variables. 8850 explicit OMPInclusiveClause(unsigned N) 8851 : OMPVarListClause<OMPInclusiveClause>(llvm::omp::OMPC_inclusive, 8852 SourceLocation(), SourceLocation(), 8853 SourceLocation(), N) {} 8854 8855 public: 8856 /// Creates clause with a list of variables \a VL. 8857 /// 8858 /// \param C AST context. 8859 /// \param StartLoc Starting location of the clause. 8860 /// \param LParenLoc Location of '('. 8861 /// \param EndLoc Ending location of the clause. 8862 /// \param VL List of references to the original variables. 8863 static OMPInclusiveClause *Create(const ASTContext &C, 8864 SourceLocation StartLoc, 8865 SourceLocation LParenLoc, 8866 SourceLocation EndLoc, ArrayRef<Expr *> VL); 8867 8868 /// Creates an empty clause with the place for \a N variables. 8869 /// 8870 /// \param C AST context. 8871 /// \param N The number of variables. 8872 static OMPInclusiveClause *CreateEmpty(const ASTContext &C, unsigned N); 8873 8874 child_range children() { 8875 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 8876 reinterpret_cast<Stmt **>(varlist_end())); 8877 } 8878 8879 const_child_range children() const { 8880 auto Children = const_cast<OMPInclusiveClause *>(this)->children(); 8881 return const_child_range(Children.begin(), Children.end()); 8882 } 8883 8884 child_range used_children() { 8885 return child_range(child_iterator(), child_iterator()); 8886 } 8887 const_child_range used_children() const { 8888 return const_child_range(const_child_iterator(), const_child_iterator()); 8889 } 8890 8891 static bool classof(const OMPClause *T) { 8892 return T->getClauseKind() == llvm::omp::OMPC_inclusive; 8893 } 8894 }; 8895 8896 /// This represents clause 'exclusive' in the '#pragma omp scan' directive. 8897 /// 8898 /// \code 8899 /// #pragma omp scan exclusive(a,b) 8900 /// \endcode 8901 /// In this example directive '#pragma omp scan' has clause 'exclusive' 8902 /// with the variables 'a' and 'b'. 8903 class OMPExclusiveClause final 8904 : public OMPVarListClause<OMPExclusiveClause>, 8905 private llvm::TrailingObjects<OMPExclusiveClause, Expr *> { 8906 friend class OMPClauseReader; 8907 friend OMPVarListClause; 8908 friend TrailingObjects; 8909 8910 /// Build clause with number of variables \a N. 8911 /// 8912 /// \param StartLoc Starting location of the clause. 8913 /// \param LParenLoc Location of '('. 8914 /// \param EndLoc Ending location of the clause. 8915 /// \param N Number of the variables in the clause. 8916 OMPExclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc, 8917 SourceLocation EndLoc, unsigned N) 8918 : OMPVarListClause<OMPExclusiveClause>(llvm::omp::OMPC_exclusive, 8919 StartLoc, LParenLoc, EndLoc, N) {} 8920 8921 /// Build an empty clause. 8922 /// 8923 /// \param N Number of variables. 8924 explicit OMPExclusiveClause(unsigned N) 8925 : OMPVarListClause<OMPExclusiveClause>(llvm::omp::OMPC_exclusive, 8926 SourceLocation(), SourceLocation(), 8927 SourceLocation(), N) {} 8928 8929 public: 8930 /// Creates clause with a list of variables \a VL. 8931 /// 8932 /// \param C AST context. 8933 /// \param StartLoc Starting location of the clause. 8934 /// \param LParenLoc Location of '('. 8935 /// \param EndLoc Ending location of the clause. 8936 /// \param VL List of references to the original variables. 8937 static OMPExclusiveClause *Create(const ASTContext &C, 8938 SourceLocation StartLoc, 8939 SourceLocation LParenLoc, 8940 SourceLocation EndLoc, ArrayRef<Expr *> VL); 8941 8942 /// Creates an empty clause with the place for \a N variables. 8943 /// 8944 /// \param C AST context. 8945 /// \param N The number of variables. 8946 static OMPExclusiveClause *CreateEmpty(const ASTContext &C, unsigned N); 8947 8948 child_range children() { 8949 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 8950 reinterpret_cast<Stmt **>(varlist_end())); 8951 } 8952 8953 const_child_range children() const { 8954 auto Children = const_cast<OMPExclusiveClause *>(this)->children(); 8955 return const_child_range(Children.begin(), Children.end()); 8956 } 8957 8958 child_range used_children() { 8959 return child_range(child_iterator(), child_iterator()); 8960 } 8961 const_child_range used_children() const { 8962 return const_child_range(const_child_iterator(), const_child_iterator()); 8963 } 8964 8965 static bool classof(const OMPClause *T) { 8966 return T->getClauseKind() == llvm::omp::OMPC_exclusive; 8967 } 8968 }; 8969 8970 /// This represents clause 'uses_allocators' in the '#pragma omp target'-based 8971 /// directives. 8972 /// 8973 /// \code 8974 /// #pragma omp target uses_allocators(default_allocator, my_allocator(traits)) 8975 /// \endcode 8976 /// In this example directive '#pragma omp target' has clause 'uses_allocators' 8977 /// with the allocators 'default_allocator' and user-defined 'my_allocator'. 8978 class OMPUsesAllocatorsClause final 8979 : public OMPClause, 8980 private llvm::TrailingObjects<OMPUsesAllocatorsClause, Expr *, 8981 SourceLocation> { 8982 public: 8983 /// Data for list of allocators. 8984 struct Data { 8985 /// Allocator. 8986 Expr *Allocator = nullptr; 8987 /// Allocator traits. 8988 Expr *AllocatorTraits = nullptr; 8989 /// Locations of '(' and ')' symbols. 8990 SourceLocation LParenLoc, RParenLoc; 8991 }; 8992 8993 private: 8994 friend class OMPClauseReader; 8995 friend TrailingObjects; 8996 8997 enum class ExprOffsets { 8998 Allocator, 8999 AllocatorTraits, 9000 Total, 9001 }; 9002 9003 enum class ParenLocsOffsets { 9004 LParen, 9005 RParen, 9006 Total, 9007 }; 9008 9009 /// Location of '('. 9010 SourceLocation LParenLoc; 9011 /// Total number of allocators in the clause. 9012 unsigned NumOfAllocators = 0; 9013 9014 /// Build clause. 9015 /// 9016 /// \param StartLoc Starting location of the clause. 9017 /// \param LParenLoc Location of '('. 9018 /// \param EndLoc Ending location of the clause. 9019 /// \param N Number of allocators associated with the clause. 9020 OMPUsesAllocatorsClause(SourceLocation StartLoc, SourceLocation LParenLoc, 9021 SourceLocation EndLoc, unsigned N) 9022 : OMPClause(llvm::omp::OMPC_uses_allocators, StartLoc, EndLoc), 9023 LParenLoc(LParenLoc), NumOfAllocators(N) {} 9024 9025 /// Build an empty clause. 9026 /// \param N Number of allocators associated with the clause. 9027 /// 9028 explicit OMPUsesAllocatorsClause(unsigned N) 9029 : OMPClause(llvm::omp::OMPC_uses_allocators, SourceLocation(), 9030 SourceLocation()), 9031 NumOfAllocators(N) {} 9032 9033 unsigned numTrailingObjects(OverloadToken<Expr *>) const { 9034 return NumOfAllocators * static_cast<int>(ExprOffsets::Total); 9035 } 9036 9037 /// Sets the location of '('. 9038 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 9039 9040 /// Sets the allocators data for the clause. 9041 void setAllocatorsData(ArrayRef<OMPUsesAllocatorsClause::Data> Data); 9042 9043 public: 9044 /// Creates clause with a list of allocators \p Data. 9045 /// 9046 /// \param C AST context. 9047 /// \param StartLoc Starting location of the clause. 9048 /// \param LParenLoc Location of '('. 9049 /// \param EndLoc Ending location of the clause. 9050 /// \param Data List of allocators. 9051 static OMPUsesAllocatorsClause * 9052 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 9053 SourceLocation EndLoc, ArrayRef<OMPUsesAllocatorsClause::Data> Data); 9054 9055 /// Creates an empty clause with the place for \p N allocators. 9056 /// 9057 /// \param C AST context. 9058 /// \param N The number of allocators. 9059 static OMPUsesAllocatorsClause *CreateEmpty(const ASTContext &C, unsigned N); 9060 9061 /// Returns the location of '('. 9062 SourceLocation getLParenLoc() const { return LParenLoc; } 9063 9064 /// Returns number of allocators associated with the clause. 9065 unsigned getNumberOfAllocators() const { return NumOfAllocators; } 9066 9067 /// Returns data for the specified allocator. 9068 OMPUsesAllocatorsClause::Data getAllocatorData(unsigned I) const; 9069 9070 // Iterators 9071 child_range children() { 9072 Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>()); 9073 return child_range(Begin, Begin + NumOfAllocators * 9074 static_cast<int>(ExprOffsets::Total)); 9075 } 9076 const_child_range children() const { 9077 Stmt *const *Begin = 9078 reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>()); 9079 return const_child_range( 9080 Begin, Begin + NumOfAllocators * static_cast<int>(ExprOffsets::Total)); 9081 } 9082 9083 child_range used_children() { 9084 return child_range(child_iterator(), child_iterator()); 9085 } 9086 const_child_range used_children() const { 9087 return const_child_range(const_child_iterator(), const_child_iterator()); 9088 } 9089 9090 static bool classof(const OMPClause *T) { 9091 return T->getClauseKind() == llvm::omp::OMPC_uses_allocators; 9092 } 9093 }; 9094 9095 /// This represents clause 'affinity' in the '#pragma omp task'-based 9096 /// directives. 9097 /// 9098 /// \code 9099 /// #pragma omp task affinity(iterator(i = 0:n) : ([3][n])a, b[:n], c[i]) 9100 /// \endcode 9101 /// In this example directive '#pragma omp task' has clause 'affinity' with the 9102 /// affinity modifer 'iterator(i = 0:n)' and locator items '([3][n])a', 'b[:n]' 9103 /// and 'c[i]'. 9104 class OMPAffinityClause final 9105 : public OMPVarListClause<OMPAffinityClause>, 9106 private llvm::TrailingObjects<OMPAffinityClause, Expr *> { 9107 friend class OMPClauseReader; 9108 friend OMPVarListClause; 9109 friend TrailingObjects; 9110 9111 /// Location of ':' symbol. 9112 SourceLocation ColonLoc; 9113 9114 /// Build clause. 9115 /// 9116 /// \param StartLoc Starting location of the clause. 9117 /// \param LParenLoc Location of '('. 9118 /// \param ColonLoc Location of ':'. 9119 /// \param EndLoc Ending location of the clause. 9120 /// \param N Number of locators associated with the clause. 9121 OMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, 9122 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N) 9123 : OMPVarListClause<OMPAffinityClause>(llvm::omp::OMPC_affinity, StartLoc, 9124 LParenLoc, EndLoc, N) {} 9125 9126 /// Build an empty clause. 9127 /// \param N Number of locators associated with the clause. 9128 /// 9129 explicit OMPAffinityClause(unsigned N) 9130 : OMPVarListClause<OMPAffinityClause>(llvm::omp::OMPC_affinity, 9131 SourceLocation(), SourceLocation(), 9132 SourceLocation(), N) {} 9133 9134 /// Sets the affinity modifier for the clause, if any. 9135 void setModifier(Expr *E) { 9136 getTrailingObjects<Expr *>()[varlist_size()] = E; 9137 } 9138 9139 /// Sets the location of ':' symbol. 9140 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 9141 9142 public: 9143 /// Creates clause with a modifier a list of locator items. 9144 /// 9145 /// \param C AST context. 9146 /// \param StartLoc Starting location of the clause. 9147 /// \param LParenLoc Location of '('. 9148 /// \param ColonLoc Location of ':'. 9149 /// \param EndLoc Ending location of the clause. 9150 /// \param Locators List of locator items. 9151 static OMPAffinityClause *Create(const ASTContext &C, SourceLocation StartLoc, 9152 SourceLocation LParenLoc, 9153 SourceLocation ColonLoc, 9154 SourceLocation EndLoc, Expr *Modifier, 9155 ArrayRef<Expr *> Locators); 9156 9157 /// Creates an empty clause with the place for \p N locator items. 9158 /// 9159 /// \param C AST context. 9160 /// \param N The number of locator items. 9161 static OMPAffinityClause *CreateEmpty(const ASTContext &C, unsigned N); 9162 9163 /// Gets affinity modifier. 9164 Expr *getModifier() { return getTrailingObjects<Expr *>()[varlist_size()]; } 9165 Expr *getModifier() const { 9166 return getTrailingObjects<Expr *>()[varlist_size()]; 9167 } 9168 9169 /// Gets the location of ':' symbol. 9170 SourceLocation getColonLoc() const { return ColonLoc; } 9171 9172 // Iterators 9173 child_range children() { 9174 int Offset = getModifier() ? 1 : 0; 9175 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 9176 reinterpret_cast<Stmt **>(varlist_end() + Offset)); 9177 } 9178 9179 const_child_range children() const { 9180 auto Children = const_cast<OMPAffinityClause *>(this)->children(); 9181 return const_child_range(Children.begin(), Children.end()); 9182 } 9183 9184 child_range used_children() { 9185 return child_range(child_iterator(), child_iterator()); 9186 } 9187 const_child_range used_children() const { 9188 return const_child_range(const_child_iterator(), const_child_iterator()); 9189 } 9190 9191 static bool classof(const OMPClause *T) { 9192 return T->getClauseKind() == llvm::omp::OMPC_affinity; 9193 } 9194 }; 9195 9196 /// This represents 'filter' clause in the '#pragma omp ...' directive. 9197 /// 9198 /// \code 9199 /// #pragma omp masked filter(tid) 9200 /// \endcode 9201 /// In this example directive '#pragma omp masked' has 'filter' clause with 9202 /// thread id. 9203 class OMPFilterClause final 9204 : public OMPOneStmtClause<llvm::omp::OMPC_filter, OMPClause>, 9205 public OMPClauseWithPreInit { 9206 friend class OMPClauseReader; 9207 9208 /// Sets the thread identifier. 9209 void setThreadID(Expr *TID) { setStmt(TID); } 9210 9211 public: 9212 /// Build 'filter' clause with thread-id \a ThreadID. 9213 /// 9214 /// \param ThreadID Thread identifier. 9215 /// \param HelperE Helper expression associated with this clause. 9216 /// \param CaptureRegion Innermost OpenMP region where expressions in this 9217 /// clause must be captured. 9218 /// \param StartLoc Starting location of the clause. 9219 /// \param LParenLoc Location of '('. 9220 /// \param EndLoc Ending location of the clause. 9221 OMPFilterClause(Expr *ThreadID, Stmt *HelperE, 9222 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, 9223 SourceLocation LParenLoc, SourceLocation EndLoc) 9224 : OMPOneStmtClause(ThreadID, StartLoc, LParenLoc, EndLoc), 9225 OMPClauseWithPreInit(this) { 9226 setPreInitStmt(HelperE, CaptureRegion); 9227 } 9228 9229 /// Build an empty clause. 9230 OMPFilterClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {} 9231 9232 /// Return thread identifier. 9233 Expr *getThreadID() const { return getStmtAs<Expr>(); } 9234 9235 /// Return thread identifier. 9236 Expr *getThreadID() { return getStmtAs<Expr>(); } 9237 }; 9238 9239 /// This represents 'bind' clause in the '#pragma omp ...' directives. 9240 /// 9241 /// \code 9242 /// #pragma omp loop bind(parallel) 9243 /// \endcode 9244 class OMPBindClause final : public OMPNoChildClause<llvm::omp::OMPC_bind> { 9245 friend class OMPClauseReader; 9246 9247 /// Location of '('. 9248 SourceLocation LParenLoc; 9249 9250 /// The binding kind of 'bind' clause. 9251 OpenMPBindClauseKind Kind = OMPC_BIND_unknown; 9252 9253 /// Start location of the kind in source code. 9254 SourceLocation KindLoc; 9255 9256 /// Sets the location of '('. 9257 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 9258 9259 /// Set the binding kind. 9260 void setBindKind(OpenMPBindClauseKind K) { Kind = K; } 9261 9262 /// Set the binding kind location. 9263 void setBindKindLoc(SourceLocation KLoc) { KindLoc = KLoc; } 9264 9265 /// Build 'bind' clause with kind \a K ('teams', 'parallel', or 'thread'). 9266 /// 9267 /// \param K Binding kind of the clause ('teams', 'parallel' or 'thread'). 9268 /// \param KLoc Starting location of the binding kind. 9269 /// \param StartLoc Starting location of the clause. 9270 /// \param LParenLoc Location of '('. 9271 /// \param EndLoc Ending location of the clause. 9272 OMPBindClause(OpenMPBindClauseKind K, SourceLocation KLoc, 9273 SourceLocation StartLoc, SourceLocation LParenLoc, 9274 SourceLocation EndLoc) 9275 : OMPNoChildClause(StartLoc, EndLoc), LParenLoc(LParenLoc), Kind(K), 9276 KindLoc(KLoc) {} 9277 9278 /// Build an empty clause. 9279 OMPBindClause() : OMPNoChildClause() {} 9280 9281 public: 9282 /// Build 'bind' clause with kind \a K ('teams', 'parallel', or 'thread'). 9283 /// 9284 /// \param C AST context 9285 /// \param K Binding kind of the clause ('teams', 'parallel' or 'thread'). 9286 /// \param KLoc Starting location of the binding kind. 9287 /// \param StartLoc Starting location of the clause. 9288 /// \param LParenLoc Location of '('. 9289 /// \param EndLoc Ending location of the clause. 9290 static OMPBindClause *Create(const ASTContext &C, OpenMPBindClauseKind K, 9291 SourceLocation KLoc, SourceLocation StartLoc, 9292 SourceLocation LParenLoc, SourceLocation EndLoc); 9293 9294 /// Build an empty 'bind' clause. 9295 /// 9296 /// \param C AST context 9297 static OMPBindClause *CreateEmpty(const ASTContext &C); 9298 9299 /// Returns the location of '('. 9300 SourceLocation getLParenLoc() const { return LParenLoc; } 9301 9302 /// Returns kind of the clause. 9303 OpenMPBindClauseKind getBindKind() const { return Kind; } 9304 9305 /// Returns location of clause kind. 9306 SourceLocation getBindKindLoc() const { return KindLoc; } 9307 }; 9308 9309 /// This class implements a simple visitor for OMPClause 9310 /// subclasses. 9311 template<class ImplClass, template <typename> class Ptr, typename RetTy> 9312 class OMPClauseVisitorBase { 9313 public: 9314 #define PTR(CLASS) Ptr<CLASS> 9315 #define DISPATCH(CLASS) \ 9316 return static_cast<ImplClass*>(this)->Visit##CLASS(static_cast<PTR(CLASS)>(S)) 9317 9318 #define GEN_CLANG_CLAUSE_CLASS 9319 #define CLAUSE_CLASS(Enum, Str, Class) \ 9320 RetTy Visit##Class(PTR(Class) S) { DISPATCH(Class); } 9321 #include "llvm/Frontend/OpenMP/OMP.inc" 9322 9323 RetTy Visit(PTR(OMPClause) S) { 9324 // Top switch clause: visit each OMPClause. 9325 switch (S->getClauseKind()) { 9326 #define GEN_CLANG_CLAUSE_CLASS 9327 #define CLAUSE_CLASS(Enum, Str, Class) \ 9328 case llvm::omp::Clause::Enum: \ 9329 return Visit##Class(static_cast<PTR(Class)>(S)); 9330 #define CLAUSE_NO_CLASS(Enum, Str) \ 9331 case llvm::omp::Clause::Enum: \ 9332 break; 9333 #include "llvm/Frontend/OpenMP/OMP.inc" 9334 } 9335 } 9336 // Base case, ignore it. :) 9337 RetTy VisitOMPClause(PTR(OMPClause) Node) { return RetTy(); } 9338 #undef PTR 9339 #undef DISPATCH 9340 }; 9341 9342 template <typename T> using const_ptr = std::add_pointer_t<std::add_const_t<T>>; 9343 9344 template <class ImplClass, typename RetTy = void> 9345 class OMPClauseVisitor 9346 : public OMPClauseVisitorBase<ImplClass, std::add_pointer_t, RetTy> {}; 9347 template<class ImplClass, typename RetTy = void> 9348 class ConstOMPClauseVisitor : 9349 public OMPClauseVisitorBase <ImplClass, const_ptr, RetTy> {}; 9350 9351 class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> { 9352 raw_ostream &OS; 9353 const PrintingPolicy &Policy; 9354 9355 /// Process clauses with list of variables. 9356 template <typename T> void VisitOMPClauseList(T *Node, char StartSym); 9357 /// Process motion clauses. 9358 template <typename T> void VisitOMPMotionClause(T *Node); 9359 9360 public: 9361 OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy) 9362 : OS(OS), Policy(Policy) {} 9363 9364 #define GEN_CLANG_CLAUSE_CLASS 9365 #define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *S); 9366 #include "llvm/Frontend/OpenMP/OMP.inc" 9367 }; 9368 9369 struct OMPTraitProperty { 9370 llvm::omp::TraitProperty Kind = llvm::omp::TraitProperty::invalid; 9371 9372 /// The raw string as we parsed it. This is needed for the `isa` trait set 9373 /// (which accepts anything) and (later) extensions. 9374 StringRef RawString; 9375 }; 9376 struct OMPTraitSelector { 9377 Expr *ScoreOrCondition = nullptr; 9378 llvm::omp::TraitSelector Kind = llvm::omp::TraitSelector::invalid; 9379 llvm::SmallVector<OMPTraitProperty, 1> Properties; 9380 }; 9381 struct OMPTraitSet { 9382 llvm::omp::TraitSet Kind = llvm::omp::TraitSet::invalid; 9383 llvm::SmallVector<OMPTraitSelector, 2> Selectors; 9384 }; 9385 9386 /// Helper data structure representing the traits in a match clause of an 9387 /// `declare variant` or `metadirective`. The outer level is an ordered 9388 /// collection of selector sets, each with an associated kind and an ordered 9389 /// collection of selectors. A selector has a kind, an optional score/condition, 9390 /// and an ordered collection of properties. 9391 class OMPTraitInfo { 9392 /// Private constructor accesible only by ASTContext. 9393 OMPTraitInfo() {} 9394 friend class ASTContext; 9395 9396 public: 9397 /// Reconstruct a (partial) OMPTraitInfo object from a mangled name. 9398 OMPTraitInfo(StringRef MangledName); 9399 9400 /// The outermost level of selector sets. 9401 llvm::SmallVector<OMPTraitSet, 2> Sets; 9402 9403 bool anyScoreOrCondition( 9404 llvm::function_ref<bool(Expr *&, bool /* IsScore */)> Cond) { 9405 return llvm::any_of(Sets, [&](OMPTraitSet &Set) { 9406 return llvm::any_of( 9407 Set.Selectors, [&](OMPTraitSelector &Selector) { 9408 return Cond(Selector.ScoreOrCondition, 9409 /* IsScore */ Selector.Kind != 9410 llvm::omp::TraitSelector::user_condition); 9411 }); 9412 }); 9413 } 9414 9415 /// Create a variant match info object from this trait info object. While the 9416 /// former is a flat representation the actual main difference is that the 9417 /// latter uses clang::Expr to store the score/condition while the former is 9418 /// independent of clang. Thus, expressions and conditions are evaluated in 9419 /// this method. 9420 void getAsVariantMatchInfo(ASTContext &ASTCtx, 9421 llvm::omp::VariantMatchInfo &VMI) const; 9422 9423 /// Return a string representation identifying this context selector. 9424 std::string getMangledName() const; 9425 9426 /// Check the extension trait \p TP is active. 9427 bool isExtensionActive(llvm::omp::TraitProperty TP) { 9428 for (const OMPTraitSet &Set : Sets) { 9429 if (Set.Kind != llvm::omp::TraitSet::implementation) 9430 continue; 9431 for (const OMPTraitSelector &Selector : Set.Selectors) { 9432 if (Selector.Kind != llvm::omp::TraitSelector::implementation_extension) 9433 continue; 9434 for (const OMPTraitProperty &Property : Selector.Properties) { 9435 if (Property.Kind == TP) 9436 return true; 9437 } 9438 } 9439 } 9440 return false; 9441 } 9442 9443 /// Print a human readable representation into \p OS. 9444 void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const; 9445 }; 9446 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo &TI); 9447 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo *TI); 9448 9449 /// Clang specific specialization of the OMPContext to lookup target features. 9450 struct TargetOMPContext final : public llvm::omp::OMPContext { 9451 TargetOMPContext(ASTContext &ASTCtx, 9452 std::function<void(StringRef)> &&DiagUnknownTrait, 9453 const FunctionDecl *CurrentFunctionDecl, 9454 ArrayRef<llvm::omp::TraitProperty> ConstructTraits); 9455 9456 virtual ~TargetOMPContext() = default; 9457 9458 /// See llvm::omp::OMPContext::matchesISATrait 9459 bool matchesISATrait(StringRef RawString) const override; 9460 9461 private: 9462 std::function<bool(StringRef)> FeatureValidityCheck; 9463 std::function<void(StringRef)> DiagUnknownTrait; 9464 llvm::StringMap<bool> FeatureMap; 9465 }; 9466 9467 /// Contains data for OpenMP directives: clauses, children 9468 /// expressions/statements (helpers for codegen) and associated statement, if 9469 /// any. 9470 class OMPChildren final 9471 : private llvm::TrailingObjects<OMPChildren, OMPClause *, Stmt *> { 9472 friend TrailingObjects; 9473 friend class OMPClauseReader; 9474 friend class OMPExecutableDirective; 9475 template <typename T> friend class OMPDeclarativeDirective; 9476 9477 /// Numbers of clauses. 9478 unsigned NumClauses = 0; 9479 /// Number of child expressions/stmts. 9480 unsigned NumChildren = 0; 9481 /// true if the directive has associated statement. 9482 bool HasAssociatedStmt = false; 9483 9484 /// Define the sizes of each trailing object array except the last one. This 9485 /// is required for TrailingObjects to work properly. 9486 size_t numTrailingObjects(OverloadToken<OMPClause *>) const { 9487 return NumClauses; 9488 } 9489 9490 OMPChildren() = delete; 9491 9492 OMPChildren(unsigned NumClauses, unsigned NumChildren, bool HasAssociatedStmt) 9493 : NumClauses(NumClauses), NumChildren(NumChildren), 9494 HasAssociatedStmt(HasAssociatedStmt) {} 9495 9496 static size_t size(unsigned NumClauses, bool HasAssociatedStmt, 9497 unsigned NumChildren); 9498 9499 static OMPChildren *Create(void *Mem, ArrayRef<OMPClause *> Clauses); 9500 static OMPChildren *Create(void *Mem, ArrayRef<OMPClause *> Clauses, Stmt *S, 9501 unsigned NumChildren = 0); 9502 static OMPChildren *CreateEmpty(void *Mem, unsigned NumClauses, 9503 bool HasAssociatedStmt = false, 9504 unsigned NumChildren = 0); 9505 9506 public: 9507 unsigned getNumClauses() const { return NumClauses; } 9508 unsigned getNumChildren() const { return NumChildren; } 9509 bool hasAssociatedStmt() const { return HasAssociatedStmt; } 9510 9511 /// Set associated statement. 9512 void setAssociatedStmt(Stmt *S) { 9513 getTrailingObjects<Stmt *>()[NumChildren] = S; 9514 } 9515 9516 void setChildren(ArrayRef<Stmt *> Children); 9517 9518 /// Sets the list of variables for this clause. 9519 /// 9520 /// \param Clauses The list of clauses for the directive. 9521 /// 9522 void setClauses(ArrayRef<OMPClause *> Clauses); 9523 9524 /// Returns statement associated with the directive. 9525 const Stmt *getAssociatedStmt() const { 9526 return const_cast<OMPChildren *>(this)->getAssociatedStmt(); 9527 } 9528 Stmt *getAssociatedStmt() { 9529 assert(HasAssociatedStmt && 9530 "Expected directive with the associated statement."); 9531 return getTrailingObjects<Stmt *>()[NumChildren]; 9532 } 9533 9534 /// Get the clauses storage. 9535 MutableArrayRef<OMPClause *> getClauses() { 9536 return llvm::MutableArrayRef(getTrailingObjects<OMPClause *>(), 9537 NumClauses); 9538 } 9539 ArrayRef<OMPClause *> getClauses() const { 9540 return const_cast<OMPChildren *>(this)->getClauses(); 9541 } 9542 9543 /// Returns the captured statement associated with the 9544 /// component region within the (combined) directive. 9545 /// 9546 /// \param RegionKind Component region kind. 9547 const CapturedStmt * 9548 getCapturedStmt(OpenMPDirectiveKind RegionKind, 9549 ArrayRef<OpenMPDirectiveKind> CaptureRegions) const { 9550 assert(llvm::is_contained(CaptureRegions, RegionKind) && 9551 "RegionKind not found in OpenMP CaptureRegions."); 9552 auto *CS = cast<CapturedStmt>(getAssociatedStmt()); 9553 for (auto ThisCaptureRegion : CaptureRegions) { 9554 if (ThisCaptureRegion == RegionKind) 9555 return CS; 9556 CS = cast<CapturedStmt>(CS->getCapturedStmt()); 9557 } 9558 llvm_unreachable("Incorrect RegionKind specified for directive."); 9559 } 9560 9561 /// Get innermost captured statement for the construct. 9562 CapturedStmt * 9563 getInnermostCapturedStmt(ArrayRef<OpenMPDirectiveKind> CaptureRegions) { 9564 assert(hasAssociatedStmt() && "Must have associated captured statement."); 9565 assert(!CaptureRegions.empty() && 9566 "At least one captured statement must be provided."); 9567 auto *CS = cast<CapturedStmt>(getAssociatedStmt()); 9568 for (unsigned Level = CaptureRegions.size(); Level > 1; --Level) 9569 CS = cast<CapturedStmt>(CS->getCapturedStmt()); 9570 return CS; 9571 } 9572 9573 const CapturedStmt * 9574 getInnermostCapturedStmt(ArrayRef<OpenMPDirectiveKind> CaptureRegions) const { 9575 return const_cast<OMPChildren *>(this)->getInnermostCapturedStmt( 9576 CaptureRegions); 9577 } 9578 9579 MutableArrayRef<Stmt *> getChildren(); 9580 ArrayRef<Stmt *> getChildren() const { 9581 return const_cast<OMPChildren *>(this)->getChildren(); 9582 } 9583 9584 Stmt *getRawStmt() { 9585 assert(HasAssociatedStmt && 9586 "Expected directive with the associated statement."); 9587 if (auto *CS = dyn_cast<CapturedStmt>(getAssociatedStmt())) { 9588 Stmt *S = nullptr; 9589 do { 9590 S = CS->getCapturedStmt(); 9591 CS = dyn_cast<CapturedStmt>(S); 9592 } while (CS); 9593 return S; 9594 } 9595 return getAssociatedStmt(); 9596 } 9597 const Stmt *getRawStmt() const { 9598 return const_cast<OMPChildren *>(this)->getRawStmt(); 9599 } 9600 9601 Stmt::child_range getAssociatedStmtAsRange() { 9602 if (!HasAssociatedStmt) 9603 return Stmt::child_range(Stmt::child_iterator(), Stmt::child_iterator()); 9604 return Stmt::child_range(&getTrailingObjects<Stmt *>()[NumChildren], 9605 &getTrailingObjects<Stmt *>()[NumChildren + 1]); 9606 } 9607 }; 9608 9609 /// This represents 'ompx_dyn_cgroup_mem' clause in the '#pragma omp target ...' 9610 /// directive. 9611 /// 9612 /// \code 9613 /// #pragma omp target [...] ompx_dyn_cgroup_mem(N) 9614 /// \endcode 9615 class OMPXDynCGroupMemClause 9616 : public OMPOneStmtClause<llvm::omp::OMPC_ompx_dyn_cgroup_mem, OMPClause>, 9617 public OMPClauseWithPreInit { 9618 friend class OMPClauseReader; 9619 9620 /// Set size. 9621 void setSize(Expr *E) { setStmt(E); } 9622 9623 public: 9624 /// Build 'ompx_dyn_cgroup_mem' clause. 9625 /// 9626 /// \param Size Size expression. 9627 /// \param HelperSize Helper Size expression 9628 /// \param CaptureRegion Innermost OpenMP region where expressions in this 9629 /// \param StartLoc Starting location of the clause. 9630 /// \param LParenLoc Location of '('. 9631 /// \param EndLoc Ending location of the clause. 9632 OMPXDynCGroupMemClause(Expr *Size, Stmt *HelperSize, 9633 OpenMPDirectiveKind CaptureRegion, 9634 SourceLocation StartLoc, SourceLocation LParenLoc, 9635 SourceLocation EndLoc) 9636 : OMPOneStmtClause(Size, StartLoc, LParenLoc, EndLoc), 9637 OMPClauseWithPreInit(this) { 9638 setPreInitStmt(HelperSize, CaptureRegion); 9639 } 9640 9641 /// Build an empty clause. 9642 OMPXDynCGroupMemClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {} 9643 9644 /// Return the size expression. 9645 Expr *getSize() { return getStmtAs<Expr>(); } 9646 9647 /// Return the size expression. 9648 Expr *getSize() const { return getStmtAs<Expr>(); } 9649 }; 9650 9651 /// This represents the 'doacross' clause for the '#pragma omp ordered' 9652 /// directive. 9653 /// 9654 /// \code 9655 /// #pragma omp ordered doacross(sink: i-1, j-1) 9656 /// \endcode 9657 /// In this example directive '#pragma omp ordered' with clause 'doacross' with 9658 /// a dependence-type 'sink' and loop-iteration vector expressions i-1 and j-1. 9659 class OMPDoacrossClause final 9660 : public OMPVarListClause<OMPDoacrossClause>, 9661 private llvm::TrailingObjects<OMPDoacrossClause, Expr *> { 9662 friend class OMPClauseReader; 9663 friend OMPVarListClause; 9664 friend TrailingObjects; 9665 9666 /// Dependence type (sink or source). 9667 OpenMPDoacrossClauseModifier DepType = OMPC_DOACROSS_unknown; 9668 9669 /// Dependence type location. 9670 SourceLocation DepLoc; 9671 9672 /// Colon location. 9673 SourceLocation ColonLoc; 9674 9675 /// Number of loops, associated with the doacross clause. 9676 unsigned NumLoops = 0; 9677 9678 /// Build clause with number of expressions \a N. 9679 /// 9680 /// \param StartLoc Starting location of the clause. 9681 /// \param LParenLoc Location of '('. 9682 /// \param EndLoc Ending location of the clause. 9683 /// \param N Number of expressions in the clause. 9684 /// \param NumLoops Number of loops associated with the clause. 9685 OMPDoacrossClause(SourceLocation StartLoc, SourceLocation LParenLoc, 9686 SourceLocation EndLoc, unsigned N, unsigned NumLoops) 9687 : OMPVarListClause<OMPDoacrossClause>(llvm::omp::OMPC_doacross, StartLoc, 9688 LParenLoc, EndLoc, N), 9689 NumLoops(NumLoops) {} 9690 9691 /// Build an empty clause. 9692 /// 9693 /// \param N Number of expressions in the clause. 9694 /// \param NumLoops Number of loops associated with the clause. 9695 explicit OMPDoacrossClause(unsigned N, unsigned NumLoops) 9696 : OMPVarListClause<OMPDoacrossClause>(llvm::omp::OMPC_doacross, 9697 SourceLocation(), SourceLocation(), 9698 SourceLocation(), N), 9699 NumLoops(NumLoops) {} 9700 9701 /// Set dependence type. 9702 void setDependenceType(OpenMPDoacrossClauseModifier M) { DepType = M; } 9703 9704 /// Set dependence type location. 9705 void setDependenceLoc(SourceLocation Loc) { DepLoc = Loc; } 9706 9707 /// Set colon location. 9708 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 9709 9710 public: 9711 /// Creates clause with a list of expressions \a VL. 9712 /// 9713 /// \param C AST context. 9714 /// \param StartLoc Starting location of the clause. 9715 /// \param LParenLoc Location of '('. 9716 /// \param EndLoc Ending location of the clause. 9717 /// \param DepType The dependence type. 9718 /// \param DepLoc Location of the dependence type. 9719 /// \param ColonLoc Location of ':'. 9720 /// \param VL List of references to the expressions. 9721 /// \param NumLoops Number of loops that associated with the clause. 9722 static OMPDoacrossClause * 9723 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 9724 SourceLocation EndLoc, OpenMPDoacrossClauseModifier DepType, 9725 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, 9726 unsigned NumLoops); 9727 9728 /// Creates an empty clause with \a N expressions. 9729 /// 9730 /// \param C AST context. 9731 /// \param N The number of expressions. 9732 /// \param NumLoops Number of loops that is associated with this clause. 9733 static OMPDoacrossClause *CreateEmpty(const ASTContext &C, unsigned N, 9734 unsigned NumLoops); 9735 9736 /// Get dependence type. 9737 OpenMPDoacrossClauseModifier getDependenceType() const { return DepType; } 9738 9739 /// Get dependence type location. 9740 SourceLocation getDependenceLoc() const { return DepLoc; } 9741 9742 /// Get colon location. 9743 SourceLocation getColonLoc() const { return ColonLoc; } 9744 9745 /// Get number of loops associated with the clause. 9746 unsigned getNumLoops() const { return NumLoops; } 9747 9748 /// Set the loop data. 9749 void setLoopData(unsigned NumLoop, Expr *Cnt); 9750 9751 /// Get the loop data. 9752 Expr *getLoopData(unsigned NumLoop); 9753 const Expr *getLoopData(unsigned NumLoop) const; 9754 9755 child_range children() { 9756 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 9757 reinterpret_cast<Stmt **>(varlist_end())); 9758 } 9759 9760 const_child_range children() const { 9761 auto Children = const_cast<OMPDoacrossClause *>(this)->children(); 9762 return const_child_range(Children.begin(), Children.end()); 9763 } 9764 9765 child_range used_children() { 9766 return child_range(child_iterator(), child_iterator()); 9767 } 9768 const_child_range used_children() const { 9769 return const_child_range(const_child_iterator(), const_child_iterator()); 9770 } 9771 9772 static bool classof(const OMPClause *T) { 9773 return T->getClauseKind() == llvm::omp::OMPC_doacross; 9774 } 9775 }; 9776 9777 /// This represents 'ompx_attribute' clause in a directive that might generate 9778 /// an outlined function. An example is given below. 9779 /// 9780 /// \code 9781 /// #pragma omp target [...] ompx_attribute(flatten) 9782 /// \endcode 9783 class OMPXAttributeClause 9784 : public OMPNoChildClause<llvm::omp::OMPC_ompx_attribute> { 9785 friend class OMPClauseReader; 9786 9787 /// Location of '('. 9788 SourceLocation LParenLoc; 9789 9790 /// The parsed attributes (clause arguments) 9791 SmallVector<const Attr *> Attrs; 9792 9793 public: 9794 /// Build 'ompx_attribute' clause. 9795 /// 9796 /// \param Attrs The parsed attributes (clause arguments) 9797 /// \param StartLoc Starting location of the clause. 9798 /// \param LParenLoc Location of '('. 9799 /// \param EndLoc Ending location of the clause. 9800 OMPXAttributeClause(ArrayRef<const Attr *> Attrs, SourceLocation StartLoc, 9801 SourceLocation LParenLoc, SourceLocation EndLoc) 9802 : OMPNoChildClause(StartLoc, EndLoc), LParenLoc(LParenLoc), Attrs(Attrs) { 9803 } 9804 9805 /// Build an empty clause. 9806 OMPXAttributeClause() : OMPNoChildClause() {} 9807 9808 /// Sets the location of '('. 9809 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 9810 9811 /// Returns the location of '('. 9812 SourceLocation getLParenLoc() const { return LParenLoc; } 9813 9814 /// Returned the attributes parsed from this clause. 9815 ArrayRef<const Attr *> getAttrs() const { return Attrs; } 9816 9817 private: 9818 /// Replace the attributes with \p NewAttrs. 9819 void setAttrs(ArrayRef<Attr *> NewAttrs) { 9820 Attrs.clear(); 9821 Attrs.append(NewAttrs.begin(), NewAttrs.end()); 9822 } 9823 }; 9824 9825 /// This represents 'ompx_bare' clause in the '#pragma omp target teams ...' 9826 /// directive. 9827 /// 9828 /// \code 9829 /// #pragma omp target teams ompx_bare 9830 /// \endcode 9831 /// In this example directive '#pragma omp target teams' has a 'ompx_bare' 9832 /// clause. 9833 class OMPXBareClause : public OMPNoChildClause<llvm::omp::OMPC_ompx_bare> { 9834 public: 9835 /// Build 'ompx_bare' clause. 9836 /// 9837 /// \param StartLoc Starting location of the clause. 9838 /// \param EndLoc Ending location of the clause. 9839 OMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc) 9840 : OMPNoChildClause(StartLoc, EndLoc) {} 9841 9842 /// Build an empty clause. 9843 OMPXBareClause() = default; 9844 }; 9845 9846 } // namespace clang 9847 9848 #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H 9849