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