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