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