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