OpenMPClause.h revision 327952
1//===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10/// \file 11/// \brief This file defines OpenMP AST classes for clauses. 12/// There are clauses for executable directives, clauses for declarative 13/// directives and clauses which can be used in both kinds of directives. 14// 15//===----------------------------------------------------------------------===// 16 17#ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H 18#define LLVM_CLANG_AST_OPENMPCLAUSE_H 19 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/SmallVector.h" 32#include "llvm/ADT/iterator.h" 33#include "llvm/ADT/iterator_range.h" 34#include "llvm/Support/Casting.h" 35#include "llvm/Support/Compiler.h" 36#include "llvm/Support/TrailingObjects.h" 37#include <cassert> 38#include <cstddef> 39#include <iterator> 40#include <utility> 41 42namespace clang { 43 44class ASTContext; 45 46//===----------------------------------------------------------------------===// 47// AST classes for clauses. 48//===----------------------------------------------------------------------===// 49 50/// \brief This is a basic class for representing single OpenMP clause. 51class OMPClause { 52 /// \brief Starting location of the clause (the clause keyword). 53 SourceLocation StartLoc; 54 55 /// \brief Ending location of the clause. 56 SourceLocation EndLoc; 57 58 /// \brief Kind of the clause. 59 OpenMPClauseKind Kind; 60 61protected: 62 OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc) 63 : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {} 64 65public: 66 /// \brief Returns the starting location of the clause. 67 SourceLocation getLocStart() const { return StartLoc; } 68 69 /// \brief Returns the ending location of the clause. 70 SourceLocation getLocEnd() const { return EndLoc; } 71 72 /// \brief Sets the starting location of the clause. 73 void setLocStart(SourceLocation Loc) { StartLoc = Loc; } 74 75 /// \brief Sets the ending location of the clause. 76 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; } 77 78 /// \brief Returns kind of OpenMP clause (private, shared, reduction, etc.). 79 OpenMPClauseKind getClauseKind() const { return Kind; } 80 81 bool isImplicit() const { return StartLoc.isInvalid(); } 82 83 using child_iterator = StmtIterator; 84 using const_child_iterator = ConstStmtIterator; 85 using child_range = llvm::iterator_range<child_iterator>; 86 using const_child_range = llvm::iterator_range<const_child_iterator>; 87 88 child_range children(); 89 const_child_range children() const { 90 auto Children = const_cast<OMPClause *>(this)->children(); 91 return const_child_range(Children.begin(), Children.end()); 92 } 93 94 static bool classof(const OMPClause *) { return true; } 95}; 96 97/// Class that handles pre-initialization statement for some clauses, like 98/// 'shedule', 'firstprivate' etc. 99class OMPClauseWithPreInit { 100 friend class OMPClauseReader; 101 102 /// Pre-initialization statement for the clause. 103 Stmt *PreInit = nullptr; 104 105 /// Region that captures the associated stmt. 106 OpenMPDirectiveKind CaptureRegion = OMPD_unknown; 107 108protected: 109 OMPClauseWithPreInit(const OMPClause *This) { 110 assert(get(This) && "get is not tuned for pre-init."); 111 } 112 113 /// Set pre-initialization statement for the clause. 114 void setPreInitStmt(Stmt *S, OpenMPDirectiveKind ThisRegion = OMPD_unknown) { 115 PreInit = S; 116 CaptureRegion = ThisRegion; 117 } 118 119public: 120 /// Get pre-initialization statement for the clause. 121 const Stmt *getPreInitStmt() const { return PreInit; } 122 123 /// Get pre-initialization statement for the clause. 124 Stmt *getPreInitStmt() { return PreInit; } 125 126 /// Get capture region for the stmt in the clause. 127 OpenMPDirectiveKind getCaptureRegion() { return CaptureRegion; } 128 129 static OMPClauseWithPreInit *get(OMPClause *C); 130 static const OMPClauseWithPreInit *get(const OMPClause *C); 131}; 132 133/// Class that handles post-update expression for some clauses, like 134/// 'lastprivate', 'reduction' etc. 135class OMPClauseWithPostUpdate : public OMPClauseWithPreInit { 136 friend class OMPClauseReader; 137 138 /// Post-update expression for the clause. 139 Expr *PostUpdate = nullptr; 140 141protected: 142 OMPClauseWithPostUpdate(const OMPClause *This) : OMPClauseWithPreInit(This) { 143 assert(get(This) && "get is not tuned for post-update."); 144 } 145 146 /// Set pre-initialization statement for the clause. 147 void setPostUpdateExpr(Expr *S) { PostUpdate = S; } 148 149public: 150 /// Get post-update expression for the clause. 151 const Expr *getPostUpdateExpr() const { return PostUpdate; } 152 153 /// Get post-update expression for the clause. 154 Expr *getPostUpdateExpr() { return PostUpdate; } 155 156 static OMPClauseWithPostUpdate *get(OMPClause *C); 157 static const OMPClauseWithPostUpdate *get(const OMPClause *C); 158}; 159 160/// \brief This represents clauses with the list of variables like 'private', 161/// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the 162/// '#pragma omp ...' directives. 163template <class T> class OMPVarListClause : public OMPClause { 164 friend class OMPClauseReader; 165 166 /// \brief Location of '('. 167 SourceLocation LParenLoc; 168 169 /// \brief Number of variables in the list. 170 unsigned NumVars; 171 172protected: 173 /// \brief Build a clause with \a N variables 174 /// 175 /// \param K Kind of the clause. 176 /// \param StartLoc Starting location of the clause (the clause keyword). 177 /// \param LParenLoc Location of '('. 178 /// \param EndLoc Ending location of the clause. 179 /// \param N Number of the variables in the clause. 180 OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc, 181 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N) 182 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {} 183 184 /// \brief Fetches list of variables associated with this clause. 185 MutableArrayRef<Expr *> getVarRefs() { 186 return MutableArrayRef<Expr *>( 187 static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars); 188 } 189 190 /// \brief Sets the list of variables for this clause. 191 void setVarRefs(ArrayRef<Expr *> VL) { 192 assert(VL.size() == NumVars && 193 "Number of variables is not the same as the preallocated buffer"); 194 std::copy(VL.begin(), VL.end(), 195 static_cast<T *>(this)->template getTrailingObjects<Expr *>()); 196 } 197 198public: 199 using varlist_iterator = MutableArrayRef<Expr *>::iterator; 200 using varlist_const_iterator = ArrayRef<const Expr *>::iterator; 201 using varlist_range = llvm::iterator_range<varlist_iterator>; 202 using varlist_const_range = llvm::iterator_range<varlist_const_iterator>; 203 204 unsigned varlist_size() const { return NumVars; } 205 bool varlist_empty() const { return NumVars == 0; } 206 207 varlist_range varlists() { 208 return varlist_range(varlist_begin(), varlist_end()); 209 } 210 varlist_const_range varlists() const { 211 return varlist_const_range(varlist_begin(), varlist_end()); 212 } 213 214 varlist_iterator varlist_begin() { return getVarRefs().begin(); } 215 varlist_iterator varlist_end() { return getVarRefs().end(); } 216 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); } 217 varlist_const_iterator varlist_end() const { return getVarRefs().end(); } 218 219 /// \brief Sets the location of '('. 220 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 221 222 /// \brief Returns the location of '('. 223 SourceLocation getLParenLoc() const { return LParenLoc; } 224 225 /// \brief Fetches list of all variables in the clause. 226 ArrayRef<const Expr *> getVarRefs() const { 227 return llvm::makeArrayRef( 228 static_cast<const T *>(this)->template getTrailingObjects<Expr *>(), 229 NumVars); 230 } 231}; 232 233/// \brief This represents 'if' clause in the '#pragma omp ...' directive. 234/// 235/// \code 236/// #pragma omp parallel if(parallel:a > 5) 237/// \endcode 238/// In this example directive '#pragma omp parallel' has simple 'if' clause with 239/// condition 'a > 5' and directive name modifier 'parallel'. 240class OMPIfClause : public OMPClause, public OMPClauseWithPreInit { 241 friend class OMPClauseReader; 242 243 /// \brief Location of '('. 244 SourceLocation LParenLoc; 245 246 /// \brief Condition of the 'if' clause. 247 Stmt *Condition = nullptr; 248 249 /// \brief Location of ':' (if any). 250 SourceLocation ColonLoc; 251 252 /// \brief Directive name modifier for the clause. 253 OpenMPDirectiveKind NameModifier = OMPD_unknown; 254 255 /// \brief Name modifier location. 256 SourceLocation NameModifierLoc; 257 258 /// \brief Set condition. 259 void setCondition(Expr *Cond) { Condition = Cond; } 260 261 /// \brief Set directive name modifier for the clause. 262 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; } 263 264 /// \brief Set location of directive name modifier for the clause. 265 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; } 266 267 /// \brief Set location of ':'. 268 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 269 270public: 271 /// \brief Build 'if' clause with condition \a Cond. 272 /// 273 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause. 274 /// \param Cond Condition of the clause. 275 /// \param HelperCond Helper condition for the clause. 276 /// \param CaptureRegion Innermost OpenMP region where expressions in this 277 /// clause must be captured. 278 /// \param StartLoc Starting location of the clause. 279 /// \param LParenLoc Location of '('. 280 /// \param NameModifierLoc Location of directive name modifier. 281 /// \param ColonLoc [OpenMP 4.1] Location of ':'. 282 /// \param EndLoc Ending location of the clause. 283 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond, 284 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, 285 SourceLocation LParenLoc, SourceLocation NameModifierLoc, 286 SourceLocation ColonLoc, SourceLocation EndLoc) 287 : OMPClause(OMPC_if, StartLoc, EndLoc), OMPClauseWithPreInit(this), 288 LParenLoc(LParenLoc), Condition(Cond), ColonLoc(ColonLoc), 289 NameModifier(NameModifier), NameModifierLoc(NameModifierLoc) { 290 setPreInitStmt(HelperCond, CaptureRegion); 291 } 292 293 /// \brief Build an empty clause. 294 OMPIfClause() 295 : OMPClause(OMPC_if, SourceLocation(), SourceLocation()), 296 OMPClauseWithPreInit(this) {} 297 298 /// \brief Sets the location of '('. 299 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 300 301 /// \brief Returns the location of '('. 302 SourceLocation getLParenLoc() const { return LParenLoc; } 303 304 /// \brief Return the location of ':'. 305 SourceLocation getColonLoc() const { return ColonLoc; } 306 307 /// \brief Returns condition. 308 Expr *getCondition() const { return cast_or_null<Expr>(Condition); } 309 310 /// \brief Return directive name modifier associated with the clause. 311 OpenMPDirectiveKind getNameModifier() const { return NameModifier; } 312 313 /// \brief Return the location of directive name modifier. 314 SourceLocation getNameModifierLoc() const { return NameModifierLoc; } 315 316 child_range children() { return child_range(&Condition, &Condition + 1); } 317 318 static bool classof(const OMPClause *T) { 319 return T->getClauseKind() == OMPC_if; 320 } 321}; 322 323/// \brief This represents 'final' clause in the '#pragma omp ...' directive. 324/// 325/// \code 326/// #pragma omp task final(a > 5) 327/// \endcode 328/// In this example directive '#pragma omp task' has simple 'final' 329/// clause with condition 'a > 5'. 330class OMPFinalClause : public OMPClause { 331 friend class OMPClauseReader; 332 333 /// \brief Location of '('. 334 SourceLocation LParenLoc; 335 336 /// \brief Condition of the 'if' clause. 337 Stmt *Condition = nullptr; 338 339 /// \brief Set condition. 340 void setCondition(Expr *Cond) { Condition = Cond; } 341 342public: 343 /// \brief Build 'final' clause with condition \a Cond. 344 /// 345 /// \param StartLoc Starting location of the clause. 346 /// \param LParenLoc Location of '('. 347 /// \param Cond Condition of the clause. 348 /// \param EndLoc Ending location of the clause. 349 OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc, 350 SourceLocation EndLoc) 351 : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc), 352 Condition(Cond) {} 353 354 /// \brief Build an empty clause. 355 OMPFinalClause() 356 : OMPClause(OMPC_final, SourceLocation(), SourceLocation()) {} 357 358 /// \brief Sets the location of '('. 359 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 360 361 /// \brief Returns the location of '('. 362 SourceLocation getLParenLoc() const { return LParenLoc; } 363 364 /// \brief Returns condition. 365 Expr *getCondition() const { return cast_or_null<Expr>(Condition); } 366 367 child_range children() { return child_range(&Condition, &Condition + 1); } 368 369 static bool classof(const OMPClause *T) { 370 return T->getClauseKind() == OMPC_final; 371 } 372}; 373 374/// \brief This represents 'num_threads' clause in the '#pragma omp ...' 375/// directive. 376/// 377/// \code 378/// #pragma omp parallel num_threads(6) 379/// \endcode 380/// In this example directive '#pragma omp parallel' has simple 'num_threads' 381/// clause with number of threads '6'. 382class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit { 383 friend class OMPClauseReader; 384 385 /// \brief Location of '('. 386 SourceLocation LParenLoc; 387 388 /// \brief Condition of the 'num_threads' clause. 389 Stmt *NumThreads = nullptr; 390 391 /// \brief Set condition. 392 void setNumThreads(Expr *NThreads) { NumThreads = NThreads; } 393 394public: 395 /// \brief Build 'num_threads' clause with condition \a NumThreads. 396 /// 397 /// \param NumThreads Number of threads for the construct. 398 /// \param HelperNumThreads Helper Number of threads for the construct. 399 /// \param CaptureRegion Innermost OpenMP region where expressions in this 400 /// clause must be captured. 401 /// \param StartLoc Starting location of the clause. 402 /// \param LParenLoc Location of '('. 403 /// \param EndLoc Ending location of the clause. 404 OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads, 405 OpenMPDirectiveKind CaptureRegion, 406 SourceLocation StartLoc, SourceLocation LParenLoc, 407 SourceLocation EndLoc) 408 : OMPClause(OMPC_num_threads, StartLoc, EndLoc), 409 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), 410 NumThreads(NumThreads) { 411 setPreInitStmt(HelperNumThreads, CaptureRegion); 412 } 413 414 /// \brief Build an empty clause. 415 OMPNumThreadsClause() 416 : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()), 417 OMPClauseWithPreInit(this) {} 418 419 /// \brief Sets the location of '('. 420 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 421 422 /// \brief Returns the location of '('. 423 SourceLocation getLParenLoc() const { return LParenLoc; } 424 425 /// \brief Returns number of threads. 426 Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); } 427 428 child_range children() { return child_range(&NumThreads, &NumThreads + 1); } 429 430 static bool classof(const OMPClause *T) { 431 return T->getClauseKind() == OMPC_num_threads; 432 } 433}; 434 435/// \brief This represents 'safelen' clause in the '#pragma omp ...' 436/// directive. 437/// 438/// \code 439/// #pragma omp simd safelen(4) 440/// \endcode 441/// In this example directive '#pragma omp simd' has clause 'safelen' 442/// with single expression '4'. 443/// If the safelen clause is used then no two iterations executed 444/// concurrently with SIMD instructions can have a greater distance 445/// in the logical iteration space than its value. The parameter of 446/// the safelen clause must be a constant positive integer expression. 447class OMPSafelenClause : public OMPClause { 448 friend class OMPClauseReader; 449 450 /// \brief Location of '('. 451 SourceLocation LParenLoc; 452 453 /// \brief Safe iteration space distance. 454 Stmt *Safelen = nullptr; 455 456 /// \brief Set safelen. 457 void setSafelen(Expr *Len) { Safelen = Len; } 458 459public: 460 /// \brief Build 'safelen' clause. 461 /// 462 /// \param Len Expression associated with this clause. 463 /// \param StartLoc Starting location of the clause. 464 /// \param EndLoc Ending location of the clause. 465 OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, 466 SourceLocation EndLoc) 467 : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc), 468 Safelen(Len) {} 469 470 /// \brief Build an empty clause. 471 explicit OMPSafelenClause() 472 : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()) {} 473 474 /// \brief Sets the location of '('. 475 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 476 477 /// \brief Returns the location of '('. 478 SourceLocation getLParenLoc() const { return LParenLoc; } 479 480 /// \brief Return safe iteration space distance. 481 Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); } 482 483 child_range children() { return child_range(&Safelen, &Safelen + 1); } 484 485 static bool classof(const OMPClause *T) { 486 return T->getClauseKind() == OMPC_safelen; 487 } 488}; 489 490/// \brief This represents 'simdlen' clause in the '#pragma omp ...' 491/// directive. 492/// 493/// \code 494/// #pragma omp simd simdlen(4) 495/// \endcode 496/// In this example directive '#pragma omp simd' has clause 'simdlen' 497/// with single expression '4'. 498/// If the 'simdlen' clause is used then it specifies the preferred number of 499/// iterations to be executed concurrently. The parameter of the 'simdlen' 500/// clause must be a constant positive integer expression. 501class OMPSimdlenClause : public OMPClause { 502 friend class OMPClauseReader; 503 504 /// \brief Location of '('. 505 SourceLocation LParenLoc; 506 507 /// \brief Safe iteration space distance. 508 Stmt *Simdlen = nullptr; 509 510 /// \brief Set simdlen. 511 void setSimdlen(Expr *Len) { Simdlen = Len; } 512 513public: 514 /// \brief Build 'simdlen' clause. 515 /// 516 /// \param Len Expression associated with this clause. 517 /// \param StartLoc Starting location of the clause. 518 /// \param EndLoc Ending location of the clause. 519 OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, 520 SourceLocation EndLoc) 521 : OMPClause(OMPC_simdlen, StartLoc, EndLoc), LParenLoc(LParenLoc), 522 Simdlen(Len) {} 523 524 /// \brief Build an empty clause. 525 explicit OMPSimdlenClause() 526 : OMPClause(OMPC_simdlen, SourceLocation(), SourceLocation()) {} 527 528 /// \brief Sets the location of '('. 529 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 530 531 /// \brief Returns the location of '('. 532 SourceLocation getLParenLoc() const { return LParenLoc; } 533 534 /// \brief Return safe iteration space distance. 535 Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); } 536 537 child_range children() { return child_range(&Simdlen, &Simdlen + 1); } 538 539 static bool classof(const OMPClause *T) { 540 return T->getClauseKind() == OMPC_simdlen; 541 } 542}; 543 544/// \brief This represents 'collapse' clause in the '#pragma omp ...' 545/// directive. 546/// 547/// \code 548/// #pragma omp simd collapse(3) 549/// \endcode 550/// In this example directive '#pragma omp simd' has clause 'collapse' 551/// with single expression '3'. 552/// The parameter must be a constant positive integer expression, it specifies 553/// the number of nested loops that should be collapsed into a single iteration 554/// space. 555class OMPCollapseClause : public OMPClause { 556 friend class OMPClauseReader; 557 558 /// \brief Location of '('. 559 SourceLocation LParenLoc; 560 561 /// \brief Number of for-loops. 562 Stmt *NumForLoops = nullptr; 563 564 /// \brief Set the number of associated for-loops. 565 void setNumForLoops(Expr *Num) { NumForLoops = Num; } 566 567public: 568 /// \brief Build 'collapse' clause. 569 /// 570 /// \param Num Expression associated with this clause. 571 /// \param StartLoc Starting location of the clause. 572 /// \param LParenLoc Location of '('. 573 /// \param EndLoc Ending location of the clause. 574 OMPCollapseClause(Expr *Num, SourceLocation StartLoc, 575 SourceLocation LParenLoc, SourceLocation EndLoc) 576 : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc), 577 NumForLoops(Num) {} 578 579 /// \brief Build an empty clause. 580 explicit OMPCollapseClause() 581 : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()) {} 582 583 /// \brief Sets the location of '('. 584 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 585 586 /// \brief Returns the location of '('. 587 SourceLocation getLParenLoc() const { return LParenLoc; } 588 589 /// \brief Return the number of associated for-loops. 590 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); } 591 592 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); } 593 594 static bool classof(const OMPClause *T) { 595 return T->getClauseKind() == OMPC_collapse; 596 } 597}; 598 599/// \brief This represents 'default' clause in the '#pragma omp ...' directive. 600/// 601/// \code 602/// #pragma omp parallel default(shared) 603/// \endcode 604/// In this example directive '#pragma omp parallel' has simple 'default' 605/// clause with kind 'shared'. 606class OMPDefaultClause : public OMPClause { 607 friend class OMPClauseReader; 608 609 /// \brief Location of '('. 610 SourceLocation LParenLoc; 611 612 /// \brief A kind of the 'default' clause. 613 OpenMPDefaultClauseKind Kind = OMPC_DEFAULT_unknown; 614 615 /// \brief Start location of the kind in source code. 616 SourceLocation KindKwLoc; 617 618 /// \brief Set kind of the clauses. 619 /// 620 /// \param K Argument of clause. 621 void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; } 622 623 /// \brief Set argument location. 624 /// 625 /// \param KLoc Argument location. 626 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; } 627 628public: 629 /// \brief Build 'default' clause with argument \a A ('none' or 'shared'). 630 /// 631 /// \param A Argument of the clause ('none' or 'shared'). 632 /// \param ALoc Starting location of the argument. 633 /// \param StartLoc Starting location of the clause. 634 /// \param LParenLoc Location of '('. 635 /// \param EndLoc Ending location of the clause. 636 OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc, 637 SourceLocation StartLoc, SourceLocation LParenLoc, 638 SourceLocation EndLoc) 639 : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc), 640 Kind(A), KindKwLoc(ALoc) {} 641 642 /// \brief Build an empty clause. 643 OMPDefaultClause() 644 : OMPClause(OMPC_default, SourceLocation(), SourceLocation()) {} 645 646 /// \brief Sets the location of '('. 647 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 648 649 /// \brief Returns the location of '('. 650 SourceLocation getLParenLoc() const { return LParenLoc; } 651 652 /// \brief Returns kind of the clause. 653 OpenMPDefaultClauseKind getDefaultKind() const { return Kind; } 654 655 /// \brief Returns location of clause kind. 656 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; } 657 658 child_range children() { 659 return child_range(child_iterator(), child_iterator()); 660 } 661 662 static bool classof(const OMPClause *T) { 663 return T->getClauseKind() == OMPC_default; 664 } 665}; 666 667/// \brief This represents 'proc_bind' clause in the '#pragma omp ...' 668/// directive. 669/// 670/// \code 671/// #pragma omp parallel proc_bind(master) 672/// \endcode 673/// In this example directive '#pragma omp parallel' has simple 'proc_bind' 674/// clause with kind 'master'. 675class OMPProcBindClause : public OMPClause { 676 friend class OMPClauseReader; 677 678 /// \brief Location of '('. 679 SourceLocation LParenLoc; 680 681 /// \brief A kind of the 'proc_bind' clause. 682 OpenMPProcBindClauseKind Kind = OMPC_PROC_BIND_unknown; 683 684 /// \brief Start location of the kind in source code. 685 SourceLocation KindKwLoc; 686 687 /// \brief Set kind of the clause. 688 /// 689 /// \param K Kind of clause. 690 void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; } 691 692 /// \brief Set clause kind location. 693 /// 694 /// \param KLoc Kind location. 695 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; } 696 697public: 698 /// \brief Build 'proc_bind' clause with argument \a A ('master', 'close' or 699 /// 'spread'). 700 /// 701 /// \param A Argument of the clause ('master', 'close' or 'spread'). 702 /// \param ALoc Starting location of the argument. 703 /// \param StartLoc Starting location of the clause. 704 /// \param LParenLoc Location of '('. 705 /// \param EndLoc Ending location of the clause. 706 OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc, 707 SourceLocation StartLoc, SourceLocation LParenLoc, 708 SourceLocation EndLoc) 709 : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc), 710 Kind(A), KindKwLoc(ALoc) {} 711 712 /// \brief Build an empty clause. 713 OMPProcBindClause() 714 : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()) {} 715 716 /// \brief Sets the location of '('. 717 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 718 719 /// \brief Returns the location of '('. 720 SourceLocation getLParenLoc() const { return LParenLoc; } 721 722 /// \brief Returns kind of the clause. 723 OpenMPProcBindClauseKind getProcBindKind() const { return Kind; } 724 725 /// \brief Returns location of clause kind. 726 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; } 727 728 child_range children() { 729 return child_range(child_iterator(), child_iterator()); 730 } 731 732 static bool classof(const OMPClause *T) { 733 return T->getClauseKind() == OMPC_proc_bind; 734 } 735}; 736 737/// \brief This represents 'schedule' clause in the '#pragma omp ...' directive. 738/// 739/// \code 740/// #pragma omp for schedule(static, 3) 741/// \endcode 742/// In this example directive '#pragma omp for' has 'schedule' clause with 743/// arguments 'static' and '3'. 744class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit { 745 friend class OMPClauseReader; 746 747 /// \brief Location of '('. 748 SourceLocation LParenLoc; 749 750 /// \brief A kind of the 'schedule' clause. 751 OpenMPScheduleClauseKind Kind = OMPC_SCHEDULE_unknown; 752 753 /// \brief Modifiers for 'schedule' clause. 754 enum {FIRST, SECOND, NUM_MODIFIERS}; 755 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS]; 756 757 /// \brief Locations of modifiers. 758 SourceLocation ModifiersLoc[NUM_MODIFIERS]; 759 760 /// \brief Start location of the schedule ind in source code. 761 SourceLocation KindLoc; 762 763 /// \brief Location of ',' (if any). 764 SourceLocation CommaLoc; 765 766 /// \brief Chunk size. 767 Expr *ChunkSize = nullptr; 768 769 /// \brief Set schedule kind. 770 /// 771 /// \param K Schedule kind. 772 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; } 773 774 /// \brief Set the first schedule modifier. 775 /// 776 /// \param M Schedule modifier. 777 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) { 778 Modifiers[FIRST] = M; 779 } 780 781 /// \brief Set the second schedule modifier. 782 /// 783 /// \param M Schedule modifier. 784 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) { 785 Modifiers[SECOND] = M; 786 } 787 788 /// \brief Set location of the first schedule modifier. 789 void setFirstScheduleModifierLoc(SourceLocation Loc) { 790 ModifiersLoc[FIRST] = Loc; 791 } 792 793 /// \brief Set location of the second schedule modifier. 794 void setSecondScheduleModifierLoc(SourceLocation Loc) { 795 ModifiersLoc[SECOND] = Loc; 796 } 797 798 /// \brief Set schedule modifier location. 799 /// 800 /// \param M Schedule modifier location. 801 void setScheduleModifer(OpenMPScheduleClauseModifier M) { 802 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown) 803 Modifiers[FIRST] = M; 804 else { 805 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown); 806 Modifiers[SECOND] = M; 807 } 808 } 809 810 /// \brief Sets the location of '('. 811 /// 812 /// \param Loc Location of '('. 813 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 814 815 /// \brief Set schedule kind start location. 816 /// 817 /// \param KLoc Schedule kind location. 818 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; } 819 820 /// \brief Set location of ','. 821 /// 822 /// \param Loc Location of ','. 823 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; } 824 825 /// \brief Set chunk size. 826 /// 827 /// \param E Chunk size. 828 void setChunkSize(Expr *E) { ChunkSize = E; } 829 830public: 831 /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size 832 /// expression \a ChunkSize. 833 /// 834 /// \param StartLoc Starting location of the clause. 835 /// \param LParenLoc Location of '('. 836 /// \param KLoc Starting location of the argument. 837 /// \param CommaLoc Location of ','. 838 /// \param EndLoc Ending location of the clause. 839 /// \param Kind Schedule kind. 840 /// \param ChunkSize Chunk size. 841 /// \param HelperChunkSize Helper chunk size for combined directives. 842 /// \param M1 The first modifier applied to 'schedule' clause. 843 /// \param M1Loc Location of the first modifier 844 /// \param M2 The second modifier applied to 'schedule' clause. 845 /// \param M2Loc Location of the second modifier 846 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc, 847 SourceLocation KLoc, SourceLocation CommaLoc, 848 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind, 849 Expr *ChunkSize, Stmt *HelperChunkSize, 850 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc, 851 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc) 852 : OMPClause(OMPC_schedule, StartLoc, EndLoc), OMPClauseWithPreInit(this), 853 LParenLoc(LParenLoc), Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc), 854 ChunkSize(ChunkSize) { 855 setPreInitStmt(HelperChunkSize); 856 Modifiers[FIRST] = M1; 857 Modifiers[SECOND] = M2; 858 ModifiersLoc[FIRST] = M1Loc; 859 ModifiersLoc[SECOND] = M2Loc; 860 } 861 862 /// \brief Build an empty clause. 863 explicit OMPScheduleClause() 864 : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()), 865 OMPClauseWithPreInit(this) { 866 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown; 867 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown; 868 } 869 870 /// \brief Get kind of the clause. 871 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; } 872 873 /// \brief Get the first modifier of the clause. 874 OpenMPScheduleClauseModifier getFirstScheduleModifier() const { 875 return Modifiers[FIRST]; 876 } 877 878 /// \brief Get the second modifier of the clause. 879 OpenMPScheduleClauseModifier getSecondScheduleModifier() const { 880 return Modifiers[SECOND]; 881 } 882 883 /// \brief Get location of '('. 884 SourceLocation getLParenLoc() { return LParenLoc; } 885 886 /// \brief Get kind location. 887 SourceLocation getScheduleKindLoc() { return KindLoc; } 888 889 /// \brief Get the first modifier location. 890 SourceLocation getFirstScheduleModifierLoc() const { 891 return ModifiersLoc[FIRST]; 892 } 893 894 /// \brief Get the second modifier location. 895 SourceLocation getSecondScheduleModifierLoc() const { 896 return ModifiersLoc[SECOND]; 897 } 898 899 /// \brief Get location of ','. 900 SourceLocation getCommaLoc() { return CommaLoc; } 901 902 /// \brief Get chunk size. 903 Expr *getChunkSize() { return ChunkSize; } 904 905 /// \brief Get chunk size. 906 const Expr *getChunkSize() const { return ChunkSize; } 907 908 child_range children() { 909 return child_range(reinterpret_cast<Stmt **>(&ChunkSize), 910 reinterpret_cast<Stmt **>(&ChunkSize) + 1); 911 } 912 913 static bool classof(const OMPClause *T) { 914 return T->getClauseKind() == OMPC_schedule; 915 } 916}; 917 918/// \brief This represents 'ordered' clause in the '#pragma omp ...' directive. 919/// 920/// \code 921/// #pragma omp for ordered (2) 922/// \endcode 923/// In this example directive '#pragma omp for' has 'ordered' clause with 924/// parameter 2. 925class OMPOrderedClause : public OMPClause { 926 friend class OMPClauseReader; 927 928 /// \brief Location of '('. 929 SourceLocation LParenLoc; 930 931 /// \brief Number of for-loops. 932 Stmt *NumForLoops = nullptr; 933 934 /// \brief Set the number of associated for-loops. 935 void setNumForLoops(Expr *Num) { NumForLoops = Num; } 936 937public: 938 /// \brief Build 'ordered' clause. 939 /// 940 /// \param Num Expression, possibly associated with this clause. 941 /// \param StartLoc Starting location of the clause. 942 /// \param LParenLoc Location of '('. 943 /// \param EndLoc Ending location of the clause. 944 OMPOrderedClause(Expr *Num, SourceLocation StartLoc, 945 SourceLocation LParenLoc, SourceLocation EndLoc) 946 : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc), 947 NumForLoops(Num) {} 948 949 /// \brief Build an empty clause. 950 explicit OMPOrderedClause() 951 : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {} 952 953 /// \brief Sets the location of '('. 954 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 955 956 /// \brief Returns the location of '('. 957 SourceLocation getLParenLoc() const { return LParenLoc; } 958 959 /// \brief Return the number of associated for-loops. 960 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); } 961 962 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); } 963 964 static bool classof(const OMPClause *T) { 965 return T->getClauseKind() == OMPC_ordered; 966 } 967}; 968 969/// \brief This represents 'nowait' clause in the '#pragma omp ...' directive. 970/// 971/// \code 972/// #pragma omp for nowait 973/// \endcode 974/// In this example directive '#pragma omp for' has 'nowait' clause. 975class OMPNowaitClause : public OMPClause { 976public: 977 /// \brief Build 'nowait' clause. 978 /// 979 /// \param StartLoc Starting location of the clause. 980 /// \param EndLoc Ending location of the clause. 981 OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc) 982 : OMPClause(OMPC_nowait, StartLoc, EndLoc) {} 983 984 /// \brief Build an empty clause. 985 OMPNowaitClause() 986 : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {} 987 988 child_range children() { 989 return child_range(child_iterator(), child_iterator()); 990 } 991 992 static bool classof(const OMPClause *T) { 993 return T->getClauseKind() == OMPC_nowait; 994 } 995}; 996 997/// \brief This represents 'untied' clause in the '#pragma omp ...' directive. 998/// 999/// \code 1000/// #pragma omp task untied 1001/// \endcode 1002/// In this example directive '#pragma omp task' has 'untied' clause. 1003class OMPUntiedClause : public OMPClause { 1004public: 1005 /// \brief Build 'untied' clause. 1006 /// 1007 /// \param StartLoc Starting location of the clause. 1008 /// \param EndLoc Ending location of the clause. 1009 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc) 1010 : OMPClause(OMPC_untied, StartLoc, EndLoc) {} 1011 1012 /// \brief Build an empty clause. 1013 OMPUntiedClause() 1014 : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {} 1015 1016 child_range children() { 1017 return child_range(child_iterator(), child_iterator()); 1018 } 1019 1020 static bool classof(const OMPClause *T) { 1021 return T->getClauseKind() == OMPC_untied; 1022 } 1023}; 1024 1025/// \brief This represents 'mergeable' clause in the '#pragma omp ...' 1026/// directive. 1027/// 1028/// \code 1029/// #pragma omp task mergeable 1030/// \endcode 1031/// In this example directive '#pragma omp task' has 'mergeable' clause. 1032class OMPMergeableClause : public OMPClause { 1033public: 1034 /// \brief Build 'mergeable' clause. 1035 /// 1036 /// \param StartLoc Starting location of the clause. 1037 /// \param EndLoc Ending location of the clause. 1038 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc) 1039 : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {} 1040 1041 /// \brief Build an empty clause. 1042 OMPMergeableClause() 1043 : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {} 1044 1045 child_range children() { 1046 return child_range(child_iterator(), child_iterator()); 1047 } 1048 1049 static bool classof(const OMPClause *T) { 1050 return T->getClauseKind() == OMPC_mergeable; 1051 } 1052}; 1053 1054/// \brief This represents 'read' clause in the '#pragma omp atomic' directive. 1055/// 1056/// \code 1057/// #pragma omp atomic read 1058/// \endcode 1059/// In this example directive '#pragma omp atomic' has 'read' clause. 1060class OMPReadClause : public OMPClause { 1061public: 1062 /// \brief Build 'read' clause. 1063 /// 1064 /// \param StartLoc Starting location of the clause. 1065 /// \param EndLoc Ending location of the clause. 1066 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc) 1067 : OMPClause(OMPC_read, StartLoc, EndLoc) {} 1068 1069 /// \brief Build an empty clause. 1070 OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {} 1071 1072 child_range children() { 1073 return child_range(child_iterator(), child_iterator()); 1074 } 1075 1076 static bool classof(const OMPClause *T) { 1077 return T->getClauseKind() == OMPC_read; 1078 } 1079}; 1080 1081/// \brief This represents 'write' clause in the '#pragma omp atomic' directive. 1082/// 1083/// \code 1084/// #pragma omp atomic write 1085/// \endcode 1086/// In this example directive '#pragma omp atomic' has 'write' clause. 1087class OMPWriteClause : public OMPClause { 1088public: 1089 /// \brief Build 'write' clause. 1090 /// 1091 /// \param StartLoc Starting location of the clause. 1092 /// \param EndLoc Ending location of the clause. 1093 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc) 1094 : OMPClause(OMPC_write, StartLoc, EndLoc) {} 1095 1096 /// \brief Build an empty clause. 1097 OMPWriteClause() 1098 : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {} 1099 1100 child_range children() { 1101 return child_range(child_iterator(), child_iterator()); 1102 } 1103 1104 static bool classof(const OMPClause *T) { 1105 return T->getClauseKind() == OMPC_write; 1106 } 1107}; 1108 1109/// \brief This represents 'update' clause in the '#pragma omp atomic' 1110/// directive. 1111/// 1112/// \code 1113/// #pragma omp atomic update 1114/// \endcode 1115/// In this example directive '#pragma omp atomic' has 'update' clause. 1116class OMPUpdateClause : public OMPClause { 1117public: 1118 /// \brief Build 'update' clause. 1119 /// 1120 /// \param StartLoc Starting location of the clause. 1121 /// \param EndLoc Ending location of the clause. 1122 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc) 1123 : OMPClause(OMPC_update, StartLoc, EndLoc) {} 1124 1125 /// \brief Build an empty clause. 1126 OMPUpdateClause() 1127 : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {} 1128 1129 child_range children() { 1130 return child_range(child_iterator(), child_iterator()); 1131 } 1132 1133 static bool classof(const OMPClause *T) { 1134 return T->getClauseKind() == OMPC_update; 1135 } 1136}; 1137 1138/// \brief This represents 'capture' clause in the '#pragma omp atomic' 1139/// directive. 1140/// 1141/// \code 1142/// #pragma omp atomic capture 1143/// \endcode 1144/// In this example directive '#pragma omp atomic' has 'capture' clause. 1145class OMPCaptureClause : public OMPClause { 1146public: 1147 /// \brief Build 'capture' clause. 1148 /// 1149 /// \param StartLoc Starting location of the clause. 1150 /// \param EndLoc Ending location of the clause. 1151 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc) 1152 : OMPClause(OMPC_capture, StartLoc, EndLoc) {} 1153 1154 /// \brief Build an empty clause. 1155 OMPCaptureClause() 1156 : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {} 1157 1158 child_range children() { 1159 return child_range(child_iterator(), child_iterator()); 1160 } 1161 1162 static bool classof(const OMPClause *T) { 1163 return T->getClauseKind() == OMPC_capture; 1164 } 1165}; 1166 1167/// \brief This represents 'seq_cst' clause in the '#pragma omp atomic' 1168/// directive. 1169/// 1170/// \code 1171/// #pragma omp atomic seq_cst 1172/// \endcode 1173/// In this example directive '#pragma omp atomic' has 'seq_cst' clause. 1174class OMPSeqCstClause : public OMPClause { 1175public: 1176 /// \brief Build 'seq_cst' clause. 1177 /// 1178 /// \param StartLoc Starting location of the clause. 1179 /// \param EndLoc Ending location of the clause. 1180 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc) 1181 : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {} 1182 1183 /// \brief Build an empty clause. 1184 OMPSeqCstClause() 1185 : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {} 1186 1187 child_range children() { 1188 return child_range(child_iterator(), child_iterator()); 1189 } 1190 1191 static bool classof(const OMPClause *T) { 1192 return T->getClauseKind() == OMPC_seq_cst; 1193 } 1194}; 1195 1196/// \brief This represents clause 'private' in the '#pragma omp ...' directives. 1197/// 1198/// \code 1199/// #pragma omp parallel private(a,b) 1200/// \endcode 1201/// In this example directive '#pragma omp parallel' has clause 'private' 1202/// with the variables 'a' and 'b'. 1203class OMPPrivateClause final 1204 : public OMPVarListClause<OMPPrivateClause>, 1205 private llvm::TrailingObjects<OMPPrivateClause, Expr *> { 1206 friend class OMPClauseReader; 1207 friend OMPVarListClause; 1208 friend TrailingObjects; 1209 1210 /// \brief Build clause with number of variables \a N. 1211 /// 1212 /// \param StartLoc Starting location of the clause. 1213 /// \param LParenLoc Location of '('. 1214 /// \param EndLoc Ending location of the clause. 1215 /// \param N Number of the variables in the clause. 1216 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc, 1217 SourceLocation EndLoc, unsigned N) 1218 : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc, 1219 EndLoc, N) {} 1220 1221 /// \brief Build an empty clause. 1222 /// 1223 /// \param N Number of variables. 1224 explicit OMPPrivateClause(unsigned N) 1225 : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(), 1226 SourceLocation(), SourceLocation(), 1227 N) {} 1228 1229 /// \brief Sets the list of references to private copies with initializers for 1230 /// new private variables. 1231 /// \param VL List of references. 1232 void setPrivateCopies(ArrayRef<Expr *> VL); 1233 1234 /// \brief Gets the list of references to private copies with initializers for 1235 /// new private variables. 1236 MutableArrayRef<Expr *> getPrivateCopies() { 1237 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 1238 } 1239 ArrayRef<const Expr *> getPrivateCopies() const { 1240 return llvm::makeArrayRef(varlist_end(), varlist_size()); 1241 } 1242 1243public: 1244 /// \brief Creates clause with a list of variables \a VL. 1245 /// 1246 /// \param C AST context. 1247 /// \param StartLoc Starting location of the clause. 1248 /// \param LParenLoc Location of '('. 1249 /// \param EndLoc Ending location of the clause. 1250 /// \param VL List of references to the variables. 1251 /// \param PrivateVL List of references to private copies with initializers. 1252 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc, 1253 SourceLocation LParenLoc, 1254 SourceLocation EndLoc, ArrayRef<Expr *> VL, 1255 ArrayRef<Expr *> PrivateVL); 1256 1257 /// \brief Creates an empty clause with the place for \a N variables. 1258 /// 1259 /// \param C AST context. 1260 /// \param N The number of variables. 1261 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N); 1262 1263 using private_copies_iterator = MutableArrayRef<Expr *>::iterator; 1264 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator; 1265 using private_copies_range = llvm::iterator_range<private_copies_iterator>; 1266 using private_copies_const_range = 1267 llvm::iterator_range<private_copies_const_iterator>; 1268 1269 private_copies_range private_copies() { 1270 return private_copies_range(getPrivateCopies().begin(), 1271 getPrivateCopies().end()); 1272 } 1273 1274 private_copies_const_range private_copies() const { 1275 return private_copies_const_range(getPrivateCopies().begin(), 1276 getPrivateCopies().end()); 1277 } 1278 1279 child_range children() { 1280 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 1281 reinterpret_cast<Stmt **>(varlist_end())); 1282 } 1283 1284 static bool classof(const OMPClause *T) { 1285 return T->getClauseKind() == OMPC_private; 1286 } 1287}; 1288 1289/// \brief This represents clause 'firstprivate' in the '#pragma omp ...' 1290/// directives. 1291/// 1292/// \code 1293/// #pragma omp parallel firstprivate(a,b) 1294/// \endcode 1295/// In this example directive '#pragma omp parallel' has clause 'firstprivate' 1296/// with the variables 'a' and 'b'. 1297class OMPFirstprivateClause final 1298 : public OMPVarListClause<OMPFirstprivateClause>, 1299 public OMPClauseWithPreInit, 1300 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> { 1301 friend class OMPClauseReader; 1302 friend OMPVarListClause; 1303 friend TrailingObjects; 1304 1305 /// \brief Build clause with number of variables \a N. 1306 /// 1307 /// \param StartLoc Starting location of the clause. 1308 /// \param LParenLoc Location of '('. 1309 /// \param EndLoc Ending location of the clause. 1310 /// \param N Number of the variables in the clause. 1311 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc, 1312 SourceLocation EndLoc, unsigned N) 1313 : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc, 1314 LParenLoc, EndLoc, N), 1315 OMPClauseWithPreInit(this) {} 1316 1317 /// \brief Build an empty clause. 1318 /// 1319 /// \param N Number of variables. 1320 explicit OMPFirstprivateClause(unsigned N) 1321 : OMPVarListClause<OMPFirstprivateClause>( 1322 OMPC_firstprivate, SourceLocation(), SourceLocation(), 1323 SourceLocation(), N), 1324 OMPClauseWithPreInit(this) {} 1325 1326 /// \brief Sets the list of references to private copies with initializers for 1327 /// new private variables. 1328 /// \param VL List of references. 1329 void setPrivateCopies(ArrayRef<Expr *> VL); 1330 1331 /// \brief Gets the list of references to private copies with initializers for 1332 /// new private variables. 1333 MutableArrayRef<Expr *> getPrivateCopies() { 1334 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 1335 } 1336 ArrayRef<const Expr *> getPrivateCopies() const { 1337 return llvm::makeArrayRef(varlist_end(), varlist_size()); 1338 } 1339 1340 /// \brief Sets the list of references to initializer variables for new 1341 /// private variables. 1342 /// \param VL List of references. 1343 void setInits(ArrayRef<Expr *> VL); 1344 1345 /// \brief Gets the list of references to initializer variables for new 1346 /// private variables. 1347 MutableArrayRef<Expr *> getInits() { 1348 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size()); 1349 } 1350 ArrayRef<const Expr *> getInits() const { 1351 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size()); 1352 } 1353 1354public: 1355 /// \brief Creates clause with a list of variables \a VL. 1356 /// 1357 /// \param C AST context. 1358 /// \param StartLoc Starting location of the clause. 1359 /// \param LParenLoc Location of '('. 1360 /// \param EndLoc Ending location of the clause. 1361 /// \param VL List of references to the original variables. 1362 /// \param PrivateVL List of references to private copies with initializers. 1363 /// \param InitVL List of references to auto generated variables used for 1364 /// initialization of a single array element. Used if firstprivate variable is 1365 /// of array type. 1366 /// \param PreInit Statement that must be executed before entering the OpenMP 1367 /// region with this clause. 1368 static OMPFirstprivateClause * 1369 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 1370 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, 1371 ArrayRef<Expr *> InitVL, Stmt *PreInit); 1372 1373 /// \brief Creates an empty clause with the place for \a N variables. 1374 /// 1375 /// \param C AST context. 1376 /// \param N The number of variables. 1377 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N); 1378 1379 using private_copies_iterator = MutableArrayRef<Expr *>::iterator; 1380 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator; 1381 using private_copies_range = llvm::iterator_range<private_copies_iterator>; 1382 using private_copies_const_range = 1383 llvm::iterator_range<private_copies_const_iterator>; 1384 1385 private_copies_range private_copies() { 1386 return private_copies_range(getPrivateCopies().begin(), 1387 getPrivateCopies().end()); 1388 } 1389 private_copies_const_range private_copies() const { 1390 return private_copies_const_range(getPrivateCopies().begin(), 1391 getPrivateCopies().end()); 1392 } 1393 1394 using inits_iterator = MutableArrayRef<Expr *>::iterator; 1395 using inits_const_iterator = ArrayRef<const Expr *>::iterator; 1396 using inits_range = llvm::iterator_range<inits_iterator>; 1397 using inits_const_range = llvm::iterator_range<inits_const_iterator>; 1398 1399 inits_range inits() { 1400 return inits_range(getInits().begin(), getInits().end()); 1401 } 1402 inits_const_range inits() const { 1403 return inits_const_range(getInits().begin(), getInits().end()); 1404 } 1405 1406 child_range children() { 1407 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 1408 reinterpret_cast<Stmt **>(varlist_end())); 1409 } 1410 1411 static bool classof(const OMPClause *T) { 1412 return T->getClauseKind() == OMPC_firstprivate; 1413 } 1414}; 1415 1416/// \brief This represents clause 'lastprivate' in the '#pragma omp ...' 1417/// directives. 1418/// 1419/// \code 1420/// #pragma omp simd lastprivate(a,b) 1421/// \endcode 1422/// In this example directive '#pragma omp simd' has clause 'lastprivate' 1423/// with the variables 'a' and 'b'. 1424class OMPLastprivateClause final 1425 : public OMPVarListClause<OMPLastprivateClause>, 1426 public OMPClauseWithPostUpdate, 1427 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> { 1428 // There are 4 additional tail-allocated arrays at the end of the class: 1429 // 1. Contains list of pseudo variables with the default initialization for 1430 // each non-firstprivate variables. Used in codegen for initialization of 1431 // lastprivate copies. 1432 // 2. List of helper expressions for proper generation of assignment operation 1433 // required for lastprivate clause. This list represents private variables 1434 // (for arrays, single array element). 1435 // 3. List of helper expressions for proper generation of assignment operation 1436 // required for lastprivate clause. This list represents original variables 1437 // (for arrays, single array element). 1438 // 4. List of helper expressions that represents assignment operation: 1439 // \code 1440 // DstExprs = SrcExprs; 1441 // \endcode 1442 // Required for proper codegen of final assignment performed by the 1443 // lastprivate clause. 1444 friend class OMPClauseReader; 1445 friend OMPVarListClause; 1446 friend TrailingObjects; 1447 1448 /// \brief Build clause with number of variables \a N. 1449 /// 1450 /// \param StartLoc Starting location of the clause. 1451 /// \param LParenLoc Location of '('. 1452 /// \param EndLoc Ending location of the clause. 1453 /// \param N Number of the variables in the clause. 1454 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc, 1455 SourceLocation EndLoc, unsigned N) 1456 : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc, 1457 LParenLoc, EndLoc, N), 1458 OMPClauseWithPostUpdate(this) {} 1459 1460 /// \brief Build an empty clause. 1461 /// 1462 /// \param N Number of variables. 1463 explicit OMPLastprivateClause(unsigned N) 1464 : OMPVarListClause<OMPLastprivateClause>( 1465 OMPC_lastprivate, SourceLocation(), SourceLocation(), 1466 SourceLocation(), N), 1467 OMPClauseWithPostUpdate(this) {} 1468 1469 /// \brief Get the list of helper expressions for initialization of private 1470 /// copies for lastprivate variables. 1471 MutableArrayRef<Expr *> getPrivateCopies() { 1472 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 1473 } 1474 ArrayRef<const Expr *> getPrivateCopies() const { 1475 return llvm::makeArrayRef(varlist_end(), varlist_size()); 1476 } 1477 1478 /// \brief Set list of helper expressions, required for proper codegen of the 1479 /// clause. These expressions represent private variables (for arrays, single 1480 /// array element) in the final assignment statement performed by the 1481 /// lastprivate clause. 1482 void setSourceExprs(ArrayRef<Expr *> SrcExprs); 1483 1484 /// \brief Get the list of helper source expressions. 1485 MutableArrayRef<Expr *> getSourceExprs() { 1486 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size()); 1487 } 1488 ArrayRef<const Expr *> getSourceExprs() const { 1489 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size()); 1490 } 1491 1492 /// \brief Set list of helper expressions, required for proper codegen of the 1493 /// clause. These expressions represent original variables (for arrays, single 1494 /// array element) in the final assignment statement performed by the 1495 /// lastprivate clause. 1496 void setDestinationExprs(ArrayRef<Expr *> DstExprs); 1497 1498 /// \brief Get the list of helper destination expressions. 1499 MutableArrayRef<Expr *> getDestinationExprs() { 1500 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size()); 1501 } 1502 ArrayRef<const Expr *> getDestinationExprs() const { 1503 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size()); 1504 } 1505 1506 /// \brief Set list of helper assignment expressions, required for proper 1507 /// codegen of the clause. These expressions are assignment expressions that 1508 /// assign private copy of the variable to original variable. 1509 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps); 1510 1511 /// \brief Get the list of helper assignment expressions. 1512 MutableArrayRef<Expr *> getAssignmentOps() { 1513 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size()); 1514 } 1515 ArrayRef<const Expr *> getAssignmentOps() const { 1516 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size()); 1517 } 1518 1519public: 1520 /// \brief Creates clause with a list of variables \a VL. 1521 /// 1522 /// \param C AST context. 1523 /// \param StartLoc Starting location of the clause. 1524 /// \param LParenLoc Location of '('. 1525 /// \param EndLoc Ending location of the clause. 1526 /// \param VL List of references to the variables. 1527 /// \param SrcExprs List of helper expressions for proper generation of 1528 /// assignment operation required for lastprivate clause. This list represents 1529 /// private variables (for arrays, single array element). 1530 /// \param DstExprs List of helper expressions for proper generation of 1531 /// assignment operation required for lastprivate clause. This list represents 1532 /// original variables (for arrays, single array element). 1533 /// \param AssignmentOps List of helper expressions that represents assignment 1534 /// operation: 1535 /// \code 1536 /// DstExprs = SrcExprs; 1537 /// \endcode 1538 /// Required for proper codegen of final assignment performed by the 1539 /// lastprivate clause. 1540 /// \param PreInit Statement that must be executed before entering the OpenMP 1541 /// region with this clause. 1542 /// \param PostUpdate Expression that must be executed after exit from the 1543 /// OpenMP region with this clause. 1544 static OMPLastprivateClause * 1545 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 1546 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 1547 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, 1548 Stmt *PreInit, Expr *PostUpdate); 1549 1550 /// \brief Creates an empty clause with the place for \a N variables. 1551 /// 1552 /// \param C AST context. 1553 /// \param N The number of variables. 1554 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N); 1555 1556 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator; 1557 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator; 1558 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>; 1559 using helper_expr_const_range = 1560 llvm::iterator_range<helper_expr_const_iterator>; 1561 1562 /// \brief Set list of helper expressions, required for generation of private 1563 /// copies of original lastprivate variables. 1564 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies); 1565 1566 helper_expr_const_range private_copies() const { 1567 return helper_expr_const_range(getPrivateCopies().begin(), 1568 getPrivateCopies().end()); 1569 } 1570 1571 helper_expr_range private_copies() { 1572 return helper_expr_range(getPrivateCopies().begin(), 1573 getPrivateCopies().end()); 1574 } 1575 1576 helper_expr_const_range source_exprs() const { 1577 return helper_expr_const_range(getSourceExprs().begin(), 1578 getSourceExprs().end()); 1579 } 1580 1581 helper_expr_range source_exprs() { 1582 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end()); 1583 } 1584 1585 helper_expr_const_range destination_exprs() const { 1586 return helper_expr_const_range(getDestinationExprs().begin(), 1587 getDestinationExprs().end()); 1588 } 1589 1590 helper_expr_range destination_exprs() { 1591 return helper_expr_range(getDestinationExprs().begin(), 1592 getDestinationExprs().end()); 1593 } 1594 1595 helper_expr_const_range assignment_ops() const { 1596 return helper_expr_const_range(getAssignmentOps().begin(), 1597 getAssignmentOps().end()); 1598 } 1599 1600 helper_expr_range assignment_ops() { 1601 return helper_expr_range(getAssignmentOps().begin(), 1602 getAssignmentOps().end()); 1603 } 1604 1605 child_range children() { 1606 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 1607 reinterpret_cast<Stmt **>(varlist_end())); 1608 } 1609 1610 static bool classof(const OMPClause *T) { 1611 return T->getClauseKind() == OMPC_lastprivate; 1612 } 1613}; 1614 1615/// \brief This represents clause 'shared' in the '#pragma omp ...' directives. 1616/// 1617/// \code 1618/// #pragma omp parallel shared(a,b) 1619/// \endcode 1620/// In this example directive '#pragma omp parallel' has clause 'shared' 1621/// with the variables 'a' and 'b'. 1622class OMPSharedClause final 1623 : public OMPVarListClause<OMPSharedClause>, 1624 private llvm::TrailingObjects<OMPSharedClause, Expr *> { 1625 friend OMPVarListClause; 1626 friend TrailingObjects; 1627 1628 /// \brief Build clause with number of variables \a N. 1629 /// 1630 /// \param StartLoc Starting location of the clause. 1631 /// \param LParenLoc Location of '('. 1632 /// \param EndLoc Ending location of the clause. 1633 /// \param N Number of the variables in the clause. 1634 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc, 1635 SourceLocation EndLoc, unsigned N) 1636 : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc, 1637 EndLoc, N) {} 1638 1639 /// \brief Build an empty clause. 1640 /// 1641 /// \param N Number of variables. 1642 explicit OMPSharedClause(unsigned N) 1643 : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(), 1644 SourceLocation(), SourceLocation(), 1645 N) {} 1646 1647public: 1648 /// \brief Creates clause with a list of variables \a VL. 1649 /// 1650 /// \param C AST context. 1651 /// \param StartLoc Starting location of the clause. 1652 /// \param LParenLoc Location of '('. 1653 /// \param EndLoc Ending location of the clause. 1654 /// \param VL List of references to the variables. 1655 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc, 1656 SourceLocation LParenLoc, 1657 SourceLocation EndLoc, ArrayRef<Expr *> VL); 1658 1659 /// \brief Creates an empty clause with \a N variables. 1660 /// 1661 /// \param C AST context. 1662 /// \param N The number of variables. 1663 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N); 1664 1665 child_range children() { 1666 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 1667 reinterpret_cast<Stmt **>(varlist_end())); 1668 } 1669 1670 static bool classof(const OMPClause *T) { 1671 return T->getClauseKind() == OMPC_shared; 1672 } 1673}; 1674 1675/// \brief This represents clause 'reduction' in the '#pragma omp ...' 1676/// directives. 1677/// 1678/// \code 1679/// #pragma omp parallel reduction(+:a,b) 1680/// \endcode 1681/// In this example directive '#pragma omp parallel' has clause 'reduction' 1682/// with operator '+' and the variables 'a' and 'b'. 1683class OMPReductionClause final 1684 : public OMPVarListClause<OMPReductionClause>, 1685 public OMPClauseWithPostUpdate, 1686 private llvm::TrailingObjects<OMPReductionClause, Expr *> { 1687 friend class OMPClauseReader; 1688 friend OMPVarListClause; 1689 friend TrailingObjects; 1690 1691 /// \brief Location of ':'. 1692 SourceLocation ColonLoc; 1693 1694 /// \brief Nested name specifier for C++. 1695 NestedNameSpecifierLoc QualifierLoc; 1696 1697 /// \brief Name of custom operator. 1698 DeclarationNameInfo NameInfo; 1699 1700 /// \brief Build clause with number of variables \a N. 1701 /// 1702 /// \param StartLoc Starting location of the clause. 1703 /// \param LParenLoc Location of '('. 1704 /// \param EndLoc Ending location of the clause. 1705 /// \param ColonLoc Location of ':'. 1706 /// \param N Number of the variables in the clause. 1707 /// \param QualifierLoc The nested-name qualifier with location information 1708 /// \param NameInfo The full name info for reduction identifier. 1709 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc, 1710 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N, 1711 NestedNameSpecifierLoc QualifierLoc, 1712 const DeclarationNameInfo &NameInfo) 1713 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc, 1714 LParenLoc, EndLoc, N), 1715 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc), 1716 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {} 1717 1718 /// \brief Build an empty clause. 1719 /// 1720 /// \param N Number of variables. 1721 explicit OMPReductionClause(unsigned N) 1722 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(), 1723 SourceLocation(), SourceLocation(), 1724 N), 1725 OMPClauseWithPostUpdate(this) {} 1726 1727 /// \brief Sets location of ':' symbol in clause. 1728 void setColonLoc(SourceLocation CL) { ColonLoc = CL; } 1729 1730 /// \brief Sets the name info for specified reduction identifier. 1731 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; } 1732 1733 /// \brief Sets the nested name specifier. 1734 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; } 1735 1736 /// \brief Set list of helper expressions, required for proper codegen of the 1737 /// clause. These expressions represent private copy of the reduction 1738 /// variable. 1739 void setPrivates(ArrayRef<Expr *> Privates); 1740 1741 /// \brief Get the list of helper privates. 1742 MutableArrayRef<Expr *> getPrivates() { 1743 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 1744 } 1745 ArrayRef<const Expr *> getPrivates() const { 1746 return llvm::makeArrayRef(varlist_end(), varlist_size()); 1747 } 1748 1749 /// \brief Set list of helper expressions, required for proper codegen of the 1750 /// clause. These expressions represent LHS expression in the final 1751 /// reduction expression performed by the reduction clause. 1752 void setLHSExprs(ArrayRef<Expr *> LHSExprs); 1753 1754 /// \brief Get the list of helper LHS expressions. 1755 MutableArrayRef<Expr *> getLHSExprs() { 1756 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size()); 1757 } 1758 ArrayRef<const Expr *> getLHSExprs() const { 1759 return llvm::makeArrayRef(getPrivates().end(), varlist_size()); 1760 } 1761 1762 /// \brief Set list of helper expressions, required for proper codegen of the 1763 /// clause. These expressions represent RHS expression in the final 1764 /// reduction expression performed by the reduction clause. 1765 /// Also, variables in these expressions are used for proper initialization of 1766 /// reduction copies. 1767 void setRHSExprs(ArrayRef<Expr *> RHSExprs); 1768 1769 /// \brief Get the list of helper destination expressions. 1770 MutableArrayRef<Expr *> getRHSExprs() { 1771 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size()); 1772 } 1773 ArrayRef<const Expr *> getRHSExprs() const { 1774 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size()); 1775 } 1776 1777 /// \brief Set list of helper reduction expressions, required for proper 1778 /// codegen of the clause. These expressions are binary expressions or 1779 /// operator/custom reduction call that calculates new value from source 1780 /// helper expressions to destination helper expressions. 1781 void setReductionOps(ArrayRef<Expr *> ReductionOps); 1782 1783 /// \brief Get the list of helper reduction expressions. 1784 MutableArrayRef<Expr *> getReductionOps() { 1785 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size()); 1786 } 1787 ArrayRef<const Expr *> getReductionOps() const { 1788 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size()); 1789 } 1790 1791public: 1792 /// \brief Creates clause with a list of variables \a VL. 1793 /// 1794 /// \param StartLoc Starting location of the clause. 1795 /// \param LParenLoc Location of '('. 1796 /// \param ColonLoc Location of ':'. 1797 /// \param EndLoc Ending location of the clause. 1798 /// \param VL The variables in the clause. 1799 /// \param QualifierLoc The nested-name qualifier with location information 1800 /// \param NameInfo The full name info for reduction identifier. 1801 /// \param Privates List of helper expressions for proper generation of 1802 /// private copies. 1803 /// \param LHSExprs List of helper expressions for proper generation of 1804 /// assignment operation required for copyprivate clause. This list represents 1805 /// LHSs of the reduction expressions. 1806 /// \param RHSExprs List of helper expressions for proper generation of 1807 /// assignment operation required for copyprivate clause. This list represents 1808 /// RHSs of the reduction expressions. 1809 /// Also, variables in these expressions are used for proper initialization of 1810 /// reduction copies. 1811 /// \param ReductionOps List of helper expressions that represents reduction 1812 /// expressions: 1813 /// \code 1814 /// LHSExprs binop RHSExprs; 1815 /// operator binop(LHSExpr, RHSExpr); 1816 /// <CutomReduction>(LHSExpr, RHSExpr); 1817 /// \endcode 1818 /// Required for proper codegen of final reduction operation performed by the 1819 /// reduction clause. 1820 /// \param PreInit Statement that must be executed before entering the OpenMP 1821 /// region with this clause. 1822 /// \param PostUpdate Expression that must be executed after exit from the 1823 /// OpenMP region with this clause. 1824 static OMPReductionClause * 1825 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 1826 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, 1827 NestedNameSpecifierLoc QualifierLoc, 1828 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates, 1829 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs, 1830 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate); 1831 1832 /// \brief Creates an empty clause with the place for \a N variables. 1833 /// 1834 /// \param C AST context. 1835 /// \param N The number of variables. 1836 static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N); 1837 1838 /// \brief Gets location of ':' symbol in clause. 1839 SourceLocation getColonLoc() const { return ColonLoc; } 1840 1841 /// \brief Gets the name info for specified reduction identifier. 1842 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 1843 1844 /// \brief Gets the nested name specifier. 1845 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 1846 1847 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator; 1848 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator; 1849 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>; 1850 using helper_expr_const_range = 1851 llvm::iterator_range<helper_expr_const_iterator>; 1852 1853 helper_expr_const_range privates() const { 1854 return helper_expr_const_range(getPrivates().begin(), getPrivates().end()); 1855 } 1856 1857 helper_expr_range privates() { 1858 return helper_expr_range(getPrivates().begin(), getPrivates().end()); 1859 } 1860 1861 helper_expr_const_range lhs_exprs() const { 1862 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end()); 1863 } 1864 1865 helper_expr_range lhs_exprs() { 1866 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end()); 1867 } 1868 1869 helper_expr_const_range rhs_exprs() const { 1870 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end()); 1871 } 1872 1873 helper_expr_range rhs_exprs() { 1874 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end()); 1875 } 1876 1877 helper_expr_const_range reduction_ops() const { 1878 return helper_expr_const_range(getReductionOps().begin(), 1879 getReductionOps().end()); 1880 } 1881 1882 helper_expr_range reduction_ops() { 1883 return helper_expr_range(getReductionOps().begin(), 1884 getReductionOps().end()); 1885 } 1886 1887 child_range children() { 1888 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 1889 reinterpret_cast<Stmt **>(varlist_end())); 1890 } 1891 1892 static bool classof(const OMPClause *T) { 1893 return T->getClauseKind() == OMPC_reduction; 1894 } 1895}; 1896 1897/// This represents clause 'task_reduction' in the '#pragma omp taskgroup' 1898/// directives. 1899/// 1900/// \code 1901/// #pragma omp taskgroup task_reduction(+:a,b) 1902/// \endcode 1903/// In this example directive '#pragma omp taskgroup' has clause 1904/// 'task_reduction' with operator '+' and the variables 'a' and 'b'. 1905class OMPTaskReductionClause final 1906 : public OMPVarListClause<OMPTaskReductionClause>, 1907 public OMPClauseWithPostUpdate, 1908 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> { 1909 friend class OMPClauseReader; 1910 friend OMPVarListClause; 1911 friend TrailingObjects; 1912 1913 /// Location of ':'. 1914 SourceLocation ColonLoc; 1915 1916 /// Nested name specifier for C++. 1917 NestedNameSpecifierLoc QualifierLoc; 1918 1919 /// Name of custom operator. 1920 DeclarationNameInfo NameInfo; 1921 1922 /// Build clause with number of variables \a N. 1923 /// 1924 /// \param StartLoc Starting location of the clause. 1925 /// \param LParenLoc Location of '('. 1926 /// \param EndLoc Ending location of the clause. 1927 /// \param ColonLoc Location of ':'. 1928 /// \param N Number of the variables in the clause. 1929 /// \param QualifierLoc The nested-name qualifier with location information 1930 /// \param NameInfo The full name info for reduction identifier. 1931 OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc, 1932 SourceLocation ColonLoc, SourceLocation EndLoc, 1933 unsigned N, NestedNameSpecifierLoc QualifierLoc, 1934 const DeclarationNameInfo &NameInfo) 1935 : OMPVarListClause<OMPTaskReductionClause>(OMPC_task_reduction, StartLoc, 1936 LParenLoc, EndLoc, N), 1937 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc), 1938 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {} 1939 1940 /// Build an empty clause. 1941 /// 1942 /// \param N Number of variables. 1943 explicit OMPTaskReductionClause(unsigned N) 1944 : OMPVarListClause<OMPTaskReductionClause>( 1945 OMPC_task_reduction, SourceLocation(), SourceLocation(), 1946 SourceLocation(), N), 1947 OMPClauseWithPostUpdate(this) {} 1948 1949 /// Sets location of ':' symbol in clause. 1950 void setColonLoc(SourceLocation CL) { ColonLoc = CL; } 1951 1952 /// Sets the name info for specified reduction identifier. 1953 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; } 1954 1955 /// Sets the nested name specifier. 1956 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; } 1957 1958 /// Set list of helper expressions, required for proper codegen of the clause. 1959 /// These expressions represent private copy of the reduction variable. 1960 void setPrivates(ArrayRef<Expr *> Privates); 1961 1962 /// Get the list of helper privates. 1963 MutableArrayRef<Expr *> getPrivates() { 1964 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 1965 } 1966 ArrayRef<const Expr *> getPrivates() const { 1967 return llvm::makeArrayRef(varlist_end(), varlist_size()); 1968 } 1969 1970 /// Set list of helper expressions, required for proper codegen of the clause. 1971 /// These expressions represent LHS expression in the final reduction 1972 /// expression performed by the reduction clause. 1973 void setLHSExprs(ArrayRef<Expr *> LHSExprs); 1974 1975 /// Get the list of helper LHS expressions. 1976 MutableArrayRef<Expr *> getLHSExprs() { 1977 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size()); 1978 } 1979 ArrayRef<const Expr *> getLHSExprs() const { 1980 return llvm::makeArrayRef(getPrivates().end(), varlist_size()); 1981 } 1982 1983 /// Set list of helper expressions, required for proper codegen of the clause. 1984 /// These expressions represent RHS expression in the final reduction 1985 /// expression performed by the reduction clause. Also, variables in these 1986 /// expressions are used for proper initialization of reduction copies. 1987 void setRHSExprs(ArrayRef<Expr *> RHSExprs); 1988 1989 /// Get the list of helper destination expressions. 1990 MutableArrayRef<Expr *> getRHSExprs() { 1991 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size()); 1992 } 1993 ArrayRef<const Expr *> getRHSExprs() const { 1994 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size()); 1995 } 1996 1997 /// Set list of helper reduction expressions, required for proper 1998 /// codegen of the clause. These expressions are binary expressions or 1999 /// operator/custom reduction call that calculates new value from source 2000 /// helper expressions to destination helper expressions. 2001 void setReductionOps(ArrayRef<Expr *> ReductionOps); 2002 2003 /// Get the list of helper reduction expressions. 2004 MutableArrayRef<Expr *> getReductionOps() { 2005 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size()); 2006 } 2007 ArrayRef<const Expr *> getReductionOps() const { 2008 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size()); 2009 } 2010 2011public: 2012 /// Creates clause with a list of variables \a VL. 2013 /// 2014 /// \param StartLoc Starting location of the clause. 2015 /// \param LParenLoc Location of '('. 2016 /// \param ColonLoc Location of ':'. 2017 /// \param EndLoc Ending location of the clause. 2018 /// \param VL The variables in the clause. 2019 /// \param QualifierLoc The nested-name qualifier with location information 2020 /// \param NameInfo The full name info for reduction identifier. 2021 /// \param Privates List of helper expressions for proper generation of 2022 /// private copies. 2023 /// \param LHSExprs List of helper expressions for proper generation of 2024 /// assignment operation required for copyprivate clause. This list represents 2025 /// LHSs of the reduction expressions. 2026 /// \param RHSExprs List of helper expressions for proper generation of 2027 /// assignment operation required for copyprivate clause. This list represents 2028 /// RHSs of the reduction expressions. 2029 /// Also, variables in these expressions are used for proper initialization of 2030 /// reduction copies. 2031 /// \param ReductionOps List of helper expressions that represents reduction 2032 /// expressions: 2033 /// \code 2034 /// LHSExprs binop RHSExprs; 2035 /// operator binop(LHSExpr, RHSExpr); 2036 /// <CutomReduction>(LHSExpr, RHSExpr); 2037 /// \endcode 2038 /// Required for proper codegen of final reduction operation performed by the 2039 /// reduction clause. 2040 /// \param PreInit Statement that must be executed before entering the OpenMP 2041 /// region with this clause. 2042 /// \param PostUpdate Expression that must be executed after exit from the 2043 /// OpenMP region with this clause. 2044 static OMPTaskReductionClause * 2045 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 2046 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, 2047 NestedNameSpecifierLoc QualifierLoc, 2048 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates, 2049 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs, 2050 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate); 2051 2052 /// Creates an empty clause with the place for \a N variables. 2053 /// 2054 /// \param C AST context. 2055 /// \param N The number of variables. 2056 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N); 2057 2058 /// Gets location of ':' symbol in clause. 2059 SourceLocation getColonLoc() const { return ColonLoc; } 2060 2061 /// Gets the name info for specified reduction identifier. 2062 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2063 2064 /// Gets the nested name specifier. 2065 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2066 2067 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator; 2068 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator; 2069 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>; 2070 using helper_expr_const_range = 2071 llvm::iterator_range<helper_expr_const_iterator>; 2072 2073 helper_expr_const_range privates() const { 2074 return helper_expr_const_range(getPrivates().begin(), getPrivates().end()); 2075 } 2076 2077 helper_expr_range privates() { 2078 return helper_expr_range(getPrivates().begin(), getPrivates().end()); 2079 } 2080 2081 helper_expr_const_range lhs_exprs() const { 2082 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end()); 2083 } 2084 2085 helper_expr_range lhs_exprs() { 2086 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end()); 2087 } 2088 2089 helper_expr_const_range rhs_exprs() const { 2090 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end()); 2091 } 2092 2093 helper_expr_range rhs_exprs() { 2094 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end()); 2095 } 2096 2097 helper_expr_const_range reduction_ops() const { 2098 return helper_expr_const_range(getReductionOps().begin(), 2099 getReductionOps().end()); 2100 } 2101 2102 helper_expr_range reduction_ops() { 2103 return helper_expr_range(getReductionOps().begin(), 2104 getReductionOps().end()); 2105 } 2106 2107 child_range children() { 2108 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 2109 reinterpret_cast<Stmt **>(varlist_end())); 2110 } 2111 2112 static bool classof(const OMPClause *T) { 2113 return T->getClauseKind() == OMPC_task_reduction; 2114 } 2115}; 2116 2117/// This represents clause 'in_reduction' in the '#pragma omp task' directives. 2118/// 2119/// \code 2120/// #pragma omp task in_reduction(+:a,b) 2121/// \endcode 2122/// In this example directive '#pragma omp task' has clause 'in_reduction' with 2123/// operator '+' and the variables 'a' and 'b'. 2124class OMPInReductionClause final 2125 : public OMPVarListClause<OMPInReductionClause>, 2126 public OMPClauseWithPostUpdate, 2127 private llvm::TrailingObjects<OMPInReductionClause, Expr *> { 2128 friend class OMPClauseReader; 2129 friend OMPVarListClause; 2130 friend TrailingObjects; 2131 2132 /// Location of ':'. 2133 SourceLocation ColonLoc; 2134 2135 /// Nested name specifier for C++. 2136 NestedNameSpecifierLoc QualifierLoc; 2137 2138 /// Name of custom operator. 2139 DeclarationNameInfo NameInfo; 2140 2141 /// Build clause with number of variables \a N. 2142 /// 2143 /// \param StartLoc Starting location of the clause. 2144 /// \param LParenLoc Location of '('. 2145 /// \param EndLoc Ending location of the clause. 2146 /// \param ColonLoc Location of ':'. 2147 /// \param N Number of the variables in the clause. 2148 /// \param QualifierLoc The nested-name qualifier with location information 2149 /// \param NameInfo The full name info for reduction identifier. 2150 OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc, 2151 SourceLocation ColonLoc, SourceLocation EndLoc, 2152 unsigned N, NestedNameSpecifierLoc QualifierLoc, 2153 const DeclarationNameInfo &NameInfo) 2154 : OMPVarListClause<OMPInReductionClause>(OMPC_in_reduction, StartLoc, 2155 LParenLoc, EndLoc, N), 2156 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc), 2157 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {} 2158 2159 /// Build an empty clause. 2160 /// 2161 /// \param N Number of variables. 2162 explicit OMPInReductionClause(unsigned N) 2163 : OMPVarListClause<OMPInReductionClause>( 2164 OMPC_in_reduction, SourceLocation(), SourceLocation(), 2165 SourceLocation(), N), 2166 OMPClauseWithPostUpdate(this) {} 2167 2168 /// Sets location of ':' symbol in clause. 2169 void setColonLoc(SourceLocation CL) { ColonLoc = CL; } 2170 2171 /// Sets the name info for specified reduction identifier. 2172 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; } 2173 2174 /// Sets the nested name specifier. 2175 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; } 2176 2177 /// Set list of helper expressions, required for proper codegen of the clause. 2178 /// These expressions represent private copy of the reduction variable. 2179 void setPrivates(ArrayRef<Expr *> Privates); 2180 2181 /// Get the list of helper privates. 2182 MutableArrayRef<Expr *> getPrivates() { 2183 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 2184 } 2185 ArrayRef<const Expr *> getPrivates() const { 2186 return llvm::makeArrayRef(varlist_end(), varlist_size()); 2187 } 2188 2189 /// Set list of helper expressions, required for proper codegen of the clause. 2190 /// These expressions represent LHS expression in the final reduction 2191 /// expression performed by the reduction clause. 2192 void setLHSExprs(ArrayRef<Expr *> LHSExprs); 2193 2194 /// Get the list of helper LHS expressions. 2195 MutableArrayRef<Expr *> getLHSExprs() { 2196 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size()); 2197 } 2198 ArrayRef<const Expr *> getLHSExprs() const { 2199 return llvm::makeArrayRef(getPrivates().end(), varlist_size()); 2200 } 2201 2202 /// Set list of helper expressions, required for proper codegen of the clause. 2203 /// These expressions represent RHS expression in the final reduction 2204 /// expression performed by the reduction clause. Also, variables in these 2205 /// expressions are used for proper initialization of reduction copies. 2206 void setRHSExprs(ArrayRef<Expr *> RHSExprs); 2207 2208 /// Get the list of helper destination expressions. 2209 MutableArrayRef<Expr *> getRHSExprs() { 2210 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size()); 2211 } 2212 ArrayRef<const Expr *> getRHSExprs() const { 2213 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size()); 2214 } 2215 2216 /// Set list of helper reduction expressions, required for proper 2217 /// codegen of the clause. These expressions are binary expressions or 2218 /// operator/custom reduction call that calculates new value from source 2219 /// helper expressions to destination helper expressions. 2220 void setReductionOps(ArrayRef<Expr *> ReductionOps); 2221 2222 /// Get the list of helper reduction expressions. 2223 MutableArrayRef<Expr *> getReductionOps() { 2224 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size()); 2225 } 2226 ArrayRef<const Expr *> getReductionOps() const { 2227 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size()); 2228 } 2229 2230 /// Set list of helper reduction taskgroup descriptors. 2231 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps); 2232 2233 /// Get the list of helper reduction taskgroup descriptors. 2234 MutableArrayRef<Expr *> getTaskgroupDescriptors() { 2235 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size()); 2236 } 2237 ArrayRef<const Expr *> getTaskgroupDescriptors() const { 2238 return llvm::makeArrayRef(getReductionOps().end(), varlist_size()); 2239 } 2240 2241public: 2242 /// Creates clause with a list of variables \a VL. 2243 /// 2244 /// \param StartLoc Starting location of the clause. 2245 /// \param LParenLoc Location of '('. 2246 /// \param ColonLoc Location of ':'. 2247 /// \param EndLoc Ending location of the clause. 2248 /// \param VL The variables in the clause. 2249 /// \param QualifierLoc The nested-name qualifier with location information 2250 /// \param NameInfo The full name info for reduction identifier. 2251 /// \param Privates List of helper expressions for proper generation of 2252 /// private copies. 2253 /// \param LHSExprs List of helper expressions for proper generation of 2254 /// assignment operation required for copyprivate clause. This list represents 2255 /// LHSs of the reduction expressions. 2256 /// \param RHSExprs List of helper expressions for proper generation of 2257 /// assignment operation required for copyprivate clause. This list represents 2258 /// RHSs of the reduction expressions. 2259 /// Also, variables in these expressions are used for proper initialization of 2260 /// reduction copies. 2261 /// \param ReductionOps List of helper expressions that represents reduction 2262 /// expressions: 2263 /// \code 2264 /// LHSExprs binop RHSExprs; 2265 /// operator binop(LHSExpr, RHSExpr); 2266 /// <CutomReduction>(LHSExpr, RHSExpr); 2267 /// \endcode 2268 /// Required for proper codegen of final reduction operation performed by the 2269 /// reduction clause. 2270 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for 2271 /// corresponding items in parent taskgroup task_reduction clause. 2272 /// \param PreInit Statement that must be executed before entering the OpenMP 2273 /// region with this clause. 2274 /// \param PostUpdate Expression that must be executed after exit from the 2275 /// OpenMP region with this clause. 2276 static OMPInReductionClause * 2277 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 2278 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, 2279 NestedNameSpecifierLoc QualifierLoc, 2280 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates, 2281 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs, 2282 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors, 2283 Stmt *PreInit, Expr *PostUpdate); 2284 2285 /// Creates an empty clause with the place for \a N variables. 2286 /// 2287 /// \param C AST context. 2288 /// \param N The number of variables. 2289 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N); 2290 2291 /// Gets location of ':' symbol in clause. 2292 SourceLocation getColonLoc() const { return ColonLoc; } 2293 2294 /// Gets the name info for specified reduction identifier. 2295 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2296 2297 /// Gets the nested name specifier. 2298 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2299 2300 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator; 2301 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator; 2302 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>; 2303 using helper_expr_const_range = 2304 llvm::iterator_range<helper_expr_const_iterator>; 2305 2306 helper_expr_const_range privates() const { 2307 return helper_expr_const_range(getPrivates().begin(), getPrivates().end()); 2308 } 2309 2310 helper_expr_range privates() { 2311 return helper_expr_range(getPrivates().begin(), getPrivates().end()); 2312 } 2313 2314 helper_expr_const_range lhs_exprs() const { 2315 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end()); 2316 } 2317 2318 helper_expr_range lhs_exprs() { 2319 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end()); 2320 } 2321 2322 helper_expr_const_range rhs_exprs() const { 2323 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end()); 2324 } 2325 2326 helper_expr_range rhs_exprs() { 2327 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end()); 2328 } 2329 2330 helper_expr_const_range reduction_ops() const { 2331 return helper_expr_const_range(getReductionOps().begin(), 2332 getReductionOps().end()); 2333 } 2334 2335 helper_expr_range reduction_ops() { 2336 return helper_expr_range(getReductionOps().begin(), 2337 getReductionOps().end()); 2338 } 2339 2340 helper_expr_const_range taskgroup_descriptors() const { 2341 return helper_expr_const_range(getTaskgroupDescriptors().begin(), 2342 getTaskgroupDescriptors().end()); 2343 } 2344 2345 helper_expr_range taskgroup_descriptors() { 2346 return helper_expr_range(getTaskgroupDescriptors().begin(), 2347 getTaskgroupDescriptors().end()); 2348 } 2349 2350 child_range children() { 2351 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 2352 reinterpret_cast<Stmt **>(varlist_end())); 2353 } 2354 2355 static bool classof(const OMPClause *T) { 2356 return T->getClauseKind() == OMPC_in_reduction; 2357 } 2358}; 2359 2360/// \brief This represents clause 'linear' in the '#pragma omp ...' 2361/// directives. 2362/// 2363/// \code 2364/// #pragma omp simd linear(a,b : 2) 2365/// \endcode 2366/// In this example directive '#pragma omp simd' has clause 'linear' 2367/// with variables 'a', 'b' and linear step '2'. 2368class OMPLinearClause final 2369 : public OMPVarListClause<OMPLinearClause>, 2370 public OMPClauseWithPostUpdate, 2371 private llvm::TrailingObjects<OMPLinearClause, Expr *> { 2372 friend class OMPClauseReader; 2373 friend OMPVarListClause; 2374 friend TrailingObjects; 2375 2376 /// \brief Modifier of 'linear' clause. 2377 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val; 2378 2379 /// \brief Location of linear modifier if any. 2380 SourceLocation ModifierLoc; 2381 2382 /// \brief Location of ':'. 2383 SourceLocation ColonLoc; 2384 2385 /// \brief Sets the linear step for clause. 2386 void setStep(Expr *Step) { *(getFinals().end()) = Step; } 2387 2388 /// \brief Sets the expression to calculate linear step for clause. 2389 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; } 2390 2391 /// \brief Build 'linear' clause with given number of variables \a NumVars. 2392 /// 2393 /// \param StartLoc Starting location of the clause. 2394 /// \param LParenLoc Location of '('. 2395 /// \param ColonLoc Location of ':'. 2396 /// \param EndLoc Ending location of the clause. 2397 /// \param NumVars Number of variables. 2398 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc, 2399 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, 2400 SourceLocation ColonLoc, SourceLocation EndLoc, 2401 unsigned NumVars) 2402 : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc, 2403 EndLoc, NumVars), 2404 OMPClauseWithPostUpdate(this), Modifier(Modifier), 2405 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {} 2406 2407 /// \brief Build an empty clause. 2408 /// 2409 /// \param NumVars Number of variables. 2410 explicit OMPLinearClause(unsigned NumVars) 2411 : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(), 2412 SourceLocation(), SourceLocation(), 2413 NumVars), 2414 OMPClauseWithPostUpdate(this) {} 2415 2416 /// \brief Gets the list of initial values for linear variables. 2417 /// 2418 /// There are NumVars expressions with initial values allocated after the 2419 /// varlist, they are followed by NumVars update expressions (used to update 2420 /// the linear variable's value on current iteration) and they are followed by 2421 /// NumVars final expressions (used to calculate the linear variable's 2422 /// value after the loop body). After these lists, there are 2 helper 2423 /// expressions - linear step and a helper to calculate it before the 2424 /// loop body (used when the linear step is not constant): 2425 /// 2426 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[]; 2427 /// Finals[]; Step; CalcStep; } 2428 MutableArrayRef<Expr *> getPrivates() { 2429 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 2430 } 2431 ArrayRef<const Expr *> getPrivates() const { 2432 return llvm::makeArrayRef(varlist_end(), varlist_size()); 2433 } 2434 2435 MutableArrayRef<Expr *> getInits() { 2436 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size()); 2437 } 2438 ArrayRef<const Expr *> getInits() const { 2439 return llvm::makeArrayRef(getPrivates().end(), varlist_size()); 2440 } 2441 2442 /// \brief Sets the list of update expressions for linear variables. 2443 MutableArrayRef<Expr *> getUpdates() { 2444 return MutableArrayRef<Expr *>(getInits().end(), varlist_size()); 2445 } 2446 ArrayRef<const Expr *> getUpdates() const { 2447 return llvm::makeArrayRef(getInits().end(), varlist_size()); 2448 } 2449 2450 /// \brief Sets the list of final update expressions for linear variables. 2451 MutableArrayRef<Expr *> getFinals() { 2452 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size()); 2453 } 2454 ArrayRef<const Expr *> getFinals() const { 2455 return llvm::makeArrayRef(getUpdates().end(), varlist_size()); 2456 } 2457 2458 /// \brief Sets the list of the copies of original linear variables. 2459 /// \param PL List of expressions. 2460 void setPrivates(ArrayRef<Expr *> PL); 2461 2462 /// \brief Sets the list of the initial values for linear variables. 2463 /// \param IL List of expressions. 2464 void setInits(ArrayRef<Expr *> IL); 2465 2466public: 2467 /// \brief Creates clause with a list of variables \a VL and a linear step 2468 /// \a Step. 2469 /// 2470 /// \param C AST Context. 2471 /// \param StartLoc Starting location of the clause. 2472 /// \param LParenLoc Location of '('. 2473 /// \param Modifier Modifier of 'linear' clause. 2474 /// \param ModifierLoc Modifier location. 2475 /// \param ColonLoc Location of ':'. 2476 /// \param EndLoc Ending location of the clause. 2477 /// \param VL List of references to the variables. 2478 /// \param PL List of private copies of original variables. 2479 /// \param IL List of initial values for the variables. 2480 /// \param Step Linear step. 2481 /// \param CalcStep Calculation of the linear step. 2482 /// \param PreInit Statement that must be executed before entering the OpenMP 2483 /// region with this clause. 2484 /// \param PostUpdate Expression that must be executed after exit from the 2485 /// OpenMP region with this clause. 2486 static OMPLinearClause * 2487 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 2488 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, 2489 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, 2490 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, 2491 Stmt *PreInit, Expr *PostUpdate); 2492 2493 /// \brief Creates an empty clause with the place for \a NumVars variables. 2494 /// 2495 /// \param C AST context. 2496 /// \param NumVars Number of variables. 2497 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars); 2498 2499 /// \brief Set modifier. 2500 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; } 2501 2502 /// \brief Return modifier. 2503 OpenMPLinearClauseKind getModifier() const { return Modifier; } 2504 2505 /// \brief Set modifier location. 2506 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; } 2507 2508 /// \brief Return modifier location. 2509 SourceLocation getModifierLoc() const { return ModifierLoc; } 2510 2511 /// \brief Sets the location of ':'. 2512 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 2513 2514 /// \brief Returns the location of ':'. 2515 SourceLocation getColonLoc() const { return ColonLoc; } 2516 2517 /// \brief Returns linear step. 2518 Expr *getStep() { return *(getFinals().end()); } 2519 2520 /// \brief Returns linear step. 2521 const Expr *getStep() const { return *(getFinals().end()); } 2522 2523 /// \brief Returns expression to calculate linear step. 2524 Expr *getCalcStep() { return *(getFinals().end() + 1); } 2525 2526 /// \brief Returns expression to calculate linear step. 2527 const Expr *getCalcStep() const { return *(getFinals().end() + 1); } 2528 2529 /// \brief Sets the list of update expressions for linear variables. 2530 /// \param UL List of expressions. 2531 void setUpdates(ArrayRef<Expr *> UL); 2532 2533 /// \brief Sets the list of final update expressions for linear variables. 2534 /// \param FL List of expressions. 2535 void setFinals(ArrayRef<Expr *> FL); 2536 2537 using privates_iterator = MutableArrayRef<Expr *>::iterator; 2538 using privates_const_iterator = ArrayRef<const Expr *>::iterator; 2539 using privates_range = llvm::iterator_range<privates_iterator>; 2540 using privates_const_range = llvm::iterator_range<privates_const_iterator>; 2541 2542 privates_range privates() { 2543 return privates_range(getPrivates().begin(), getPrivates().end()); 2544 } 2545 2546 privates_const_range privates() const { 2547 return privates_const_range(getPrivates().begin(), getPrivates().end()); 2548 } 2549 2550 using inits_iterator = MutableArrayRef<Expr *>::iterator; 2551 using inits_const_iterator = ArrayRef<const Expr *>::iterator; 2552 using inits_range = llvm::iterator_range<inits_iterator>; 2553 using inits_const_range = llvm::iterator_range<inits_const_iterator>; 2554 2555 inits_range inits() { 2556 return inits_range(getInits().begin(), getInits().end()); 2557 } 2558 2559 inits_const_range inits() const { 2560 return inits_const_range(getInits().begin(), getInits().end()); 2561 } 2562 2563 using updates_iterator = MutableArrayRef<Expr *>::iterator; 2564 using updates_const_iterator = ArrayRef<const Expr *>::iterator; 2565 using updates_range = llvm::iterator_range<updates_iterator>; 2566 using updates_const_range = llvm::iterator_range<updates_const_iterator>; 2567 2568 updates_range updates() { 2569 return updates_range(getUpdates().begin(), getUpdates().end()); 2570 } 2571 2572 updates_const_range updates() const { 2573 return updates_const_range(getUpdates().begin(), getUpdates().end()); 2574 } 2575 2576 using finals_iterator = MutableArrayRef<Expr *>::iterator; 2577 using finals_const_iterator = ArrayRef<const Expr *>::iterator; 2578 using finals_range = llvm::iterator_range<finals_iterator>; 2579 using finals_const_range = llvm::iterator_range<finals_const_iterator>; 2580 2581 finals_range finals() { 2582 return finals_range(getFinals().begin(), getFinals().end()); 2583 } 2584 2585 finals_const_range finals() const { 2586 return finals_const_range(getFinals().begin(), getFinals().end()); 2587 } 2588 2589 child_range children() { 2590 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 2591 reinterpret_cast<Stmt **>(varlist_end())); 2592 } 2593 2594 static bool classof(const OMPClause *T) { 2595 return T->getClauseKind() == OMPC_linear; 2596 } 2597}; 2598 2599/// \brief This represents clause 'aligned' in the '#pragma omp ...' 2600/// directives. 2601/// 2602/// \code 2603/// #pragma omp simd aligned(a,b : 8) 2604/// \endcode 2605/// In this example directive '#pragma omp simd' has clause 'aligned' 2606/// with variables 'a', 'b' and alignment '8'. 2607class OMPAlignedClause final 2608 : public OMPVarListClause<OMPAlignedClause>, 2609 private llvm::TrailingObjects<OMPAlignedClause, Expr *> { 2610 friend class OMPClauseReader; 2611 friend OMPVarListClause; 2612 friend TrailingObjects; 2613 2614 /// \brief Location of ':'. 2615 SourceLocation ColonLoc; 2616 2617 /// \brief Sets the alignment for clause. 2618 void setAlignment(Expr *A) { *varlist_end() = A; } 2619 2620 /// \brief Build 'aligned' clause with given number of variables \a NumVars. 2621 /// 2622 /// \param StartLoc Starting location of the clause. 2623 /// \param LParenLoc Location of '('. 2624 /// \param ColonLoc Location of ':'. 2625 /// \param EndLoc Ending location of the clause. 2626 /// \param NumVars Number of variables. 2627 OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc, 2628 SourceLocation ColonLoc, SourceLocation EndLoc, 2629 unsigned NumVars) 2630 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc, 2631 EndLoc, NumVars), 2632 ColonLoc(ColonLoc) {} 2633 2634 /// \brief Build an empty clause. 2635 /// 2636 /// \param NumVars Number of variables. 2637 explicit OMPAlignedClause(unsigned NumVars) 2638 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(), 2639 SourceLocation(), SourceLocation(), 2640 NumVars) {} 2641 2642public: 2643 /// \brief Creates clause with a list of variables \a VL and alignment \a A. 2644 /// 2645 /// \param C AST Context. 2646 /// \param StartLoc Starting location of the clause. 2647 /// \param LParenLoc Location of '('. 2648 /// \param ColonLoc Location of ':'. 2649 /// \param EndLoc Ending location of the clause. 2650 /// \param VL List of references to the variables. 2651 /// \param A Alignment. 2652 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc, 2653 SourceLocation LParenLoc, 2654 SourceLocation ColonLoc, 2655 SourceLocation EndLoc, ArrayRef<Expr *> VL, 2656 Expr *A); 2657 2658 /// \brief Creates an empty clause with the place for \a NumVars variables. 2659 /// 2660 /// \param C AST context. 2661 /// \param NumVars Number of variables. 2662 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars); 2663 2664 /// \brief Sets the location of ':'. 2665 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 2666 2667 /// \brief Returns the location of ':'. 2668 SourceLocation getColonLoc() const { return ColonLoc; } 2669 2670 /// \brief Returns alignment. 2671 Expr *getAlignment() { return *varlist_end(); } 2672 2673 /// \brief Returns alignment. 2674 const Expr *getAlignment() const { return *varlist_end(); } 2675 2676 child_range children() { 2677 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 2678 reinterpret_cast<Stmt **>(varlist_end())); 2679 } 2680 2681 static bool classof(const OMPClause *T) { 2682 return T->getClauseKind() == OMPC_aligned; 2683 } 2684}; 2685 2686/// \brief This represents clause 'copyin' in the '#pragma omp ...' directives. 2687/// 2688/// \code 2689/// #pragma omp parallel copyin(a,b) 2690/// \endcode 2691/// In this example directive '#pragma omp parallel' has clause 'copyin' 2692/// with the variables 'a' and 'b'. 2693class OMPCopyinClause final 2694 : public OMPVarListClause<OMPCopyinClause>, 2695 private llvm::TrailingObjects<OMPCopyinClause, Expr *> { 2696 // Class has 3 additional tail allocated arrays: 2697 // 1. List of helper expressions for proper generation of assignment operation 2698 // required for copyin clause. This list represents sources. 2699 // 2. List of helper expressions for proper generation of assignment operation 2700 // required for copyin clause. This list represents destinations. 2701 // 3. List of helper expressions that represents assignment operation: 2702 // \code 2703 // DstExprs = SrcExprs; 2704 // \endcode 2705 // Required for proper codegen of propagation of master's thread values of 2706 // threadprivate variables to local instances of that variables in other 2707 // implicit threads. 2708 2709 friend class OMPClauseReader; 2710 friend OMPVarListClause; 2711 friend TrailingObjects; 2712 2713 /// \brief Build clause with number of variables \a N. 2714 /// 2715 /// \param StartLoc Starting location of the clause. 2716 /// \param LParenLoc Location of '('. 2717 /// \param EndLoc Ending location of the clause. 2718 /// \param N Number of the variables in the clause. 2719 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc, 2720 SourceLocation EndLoc, unsigned N) 2721 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc, 2722 EndLoc, N) {} 2723 2724 /// \brief Build an empty clause. 2725 /// 2726 /// \param N Number of variables. 2727 explicit OMPCopyinClause(unsigned N) 2728 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(), 2729 SourceLocation(), SourceLocation(), 2730 N) {} 2731 2732 /// \brief Set list of helper expressions, required for proper codegen of the 2733 /// clause. These expressions represent source expression in the final 2734 /// assignment statement performed by the copyin clause. 2735 void setSourceExprs(ArrayRef<Expr *> SrcExprs); 2736 2737 /// \brief Get the list of helper source expressions. 2738 MutableArrayRef<Expr *> getSourceExprs() { 2739 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 2740 } 2741 ArrayRef<const Expr *> getSourceExprs() const { 2742 return llvm::makeArrayRef(varlist_end(), varlist_size()); 2743 } 2744 2745 /// \brief Set list of helper expressions, required for proper codegen of the 2746 /// clause. These expressions represent destination expression in the final 2747 /// assignment statement performed by the copyin clause. 2748 void setDestinationExprs(ArrayRef<Expr *> DstExprs); 2749 2750 /// \brief Get the list of helper destination expressions. 2751 MutableArrayRef<Expr *> getDestinationExprs() { 2752 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size()); 2753 } 2754 ArrayRef<const Expr *> getDestinationExprs() const { 2755 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size()); 2756 } 2757 2758 /// \brief Set list of helper assignment expressions, required for proper 2759 /// codegen of the clause. These expressions are assignment expressions that 2760 /// assign source helper expressions to destination helper expressions 2761 /// correspondingly. 2762 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps); 2763 2764 /// \brief Get the list of helper assignment expressions. 2765 MutableArrayRef<Expr *> getAssignmentOps() { 2766 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size()); 2767 } 2768 ArrayRef<const Expr *> getAssignmentOps() const { 2769 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size()); 2770 } 2771 2772public: 2773 /// \brief Creates clause with a list of variables \a VL. 2774 /// 2775 /// \param C AST context. 2776 /// \param StartLoc Starting location of the clause. 2777 /// \param LParenLoc Location of '('. 2778 /// \param EndLoc Ending location of the clause. 2779 /// \param VL List of references to the variables. 2780 /// \param SrcExprs List of helper expressions for proper generation of 2781 /// assignment operation required for copyin clause. This list represents 2782 /// sources. 2783 /// \param DstExprs List of helper expressions for proper generation of 2784 /// assignment operation required for copyin clause. This list represents 2785 /// destinations. 2786 /// \param AssignmentOps List of helper expressions that represents assignment 2787 /// operation: 2788 /// \code 2789 /// DstExprs = SrcExprs; 2790 /// \endcode 2791 /// Required for proper codegen of propagation of master's thread values of 2792 /// threadprivate variables to local instances of that variables in other 2793 /// implicit threads. 2794 static OMPCopyinClause * 2795 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 2796 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 2797 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps); 2798 2799 /// \brief Creates an empty clause with \a N variables. 2800 /// 2801 /// \param C AST context. 2802 /// \param N The number of variables. 2803 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N); 2804 2805 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator; 2806 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator; 2807 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>; 2808 using helper_expr_const_range = 2809 llvm::iterator_range<helper_expr_const_iterator>; 2810 2811 helper_expr_const_range source_exprs() const { 2812 return helper_expr_const_range(getSourceExprs().begin(), 2813 getSourceExprs().end()); 2814 } 2815 2816 helper_expr_range source_exprs() { 2817 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end()); 2818 } 2819 2820 helper_expr_const_range destination_exprs() const { 2821 return helper_expr_const_range(getDestinationExprs().begin(), 2822 getDestinationExprs().end()); 2823 } 2824 2825 helper_expr_range destination_exprs() { 2826 return helper_expr_range(getDestinationExprs().begin(), 2827 getDestinationExprs().end()); 2828 } 2829 2830 helper_expr_const_range assignment_ops() const { 2831 return helper_expr_const_range(getAssignmentOps().begin(), 2832 getAssignmentOps().end()); 2833 } 2834 2835 helper_expr_range assignment_ops() { 2836 return helper_expr_range(getAssignmentOps().begin(), 2837 getAssignmentOps().end()); 2838 } 2839 2840 child_range children() { 2841 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 2842 reinterpret_cast<Stmt **>(varlist_end())); 2843 } 2844 2845 static bool classof(const OMPClause *T) { 2846 return T->getClauseKind() == OMPC_copyin; 2847 } 2848}; 2849 2850/// \brief This represents clause 'copyprivate' in the '#pragma omp ...' 2851/// directives. 2852/// 2853/// \code 2854/// #pragma omp single copyprivate(a,b) 2855/// \endcode 2856/// In this example directive '#pragma omp single' has clause 'copyprivate' 2857/// with the variables 'a' and 'b'. 2858class OMPCopyprivateClause final 2859 : public OMPVarListClause<OMPCopyprivateClause>, 2860 private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> { 2861 friend class OMPClauseReader; 2862 friend OMPVarListClause; 2863 friend TrailingObjects; 2864 2865 /// \brief Build clause with number of variables \a N. 2866 /// 2867 /// \param StartLoc Starting location of the clause. 2868 /// \param LParenLoc Location of '('. 2869 /// \param EndLoc Ending location of the clause. 2870 /// \param N Number of the variables in the clause. 2871 OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc, 2872 SourceLocation EndLoc, unsigned N) 2873 : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc, 2874 LParenLoc, EndLoc, N) {} 2875 2876 /// \brief Build an empty clause. 2877 /// 2878 /// \param N Number of variables. 2879 explicit OMPCopyprivateClause(unsigned N) 2880 : OMPVarListClause<OMPCopyprivateClause>( 2881 OMPC_copyprivate, SourceLocation(), SourceLocation(), 2882 SourceLocation(), N) {} 2883 2884 /// \brief Set list of helper expressions, required for proper codegen of the 2885 /// clause. These expressions represent source expression in the final 2886 /// assignment statement performed by the copyprivate clause. 2887 void setSourceExprs(ArrayRef<Expr *> SrcExprs); 2888 2889 /// \brief Get the list of helper source expressions. 2890 MutableArrayRef<Expr *> getSourceExprs() { 2891 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 2892 } 2893 ArrayRef<const Expr *> getSourceExprs() const { 2894 return llvm::makeArrayRef(varlist_end(), varlist_size()); 2895 } 2896 2897 /// \brief Set list of helper expressions, required for proper codegen of the 2898 /// clause. These expressions represent destination expression in the final 2899 /// assignment statement performed by the copyprivate clause. 2900 void setDestinationExprs(ArrayRef<Expr *> DstExprs); 2901 2902 /// \brief Get the list of helper destination expressions. 2903 MutableArrayRef<Expr *> getDestinationExprs() { 2904 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size()); 2905 } 2906 ArrayRef<const Expr *> getDestinationExprs() const { 2907 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size()); 2908 } 2909 2910 /// \brief Set list of helper assignment expressions, required for proper 2911 /// codegen of the clause. These expressions are assignment expressions that 2912 /// assign source helper expressions to destination helper expressions 2913 /// correspondingly. 2914 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps); 2915 2916 /// \brief Get the list of helper assignment expressions. 2917 MutableArrayRef<Expr *> getAssignmentOps() { 2918 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size()); 2919 } 2920 ArrayRef<const Expr *> getAssignmentOps() const { 2921 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size()); 2922 } 2923 2924public: 2925 /// \brief Creates clause with a list of variables \a VL. 2926 /// 2927 /// \param C AST context. 2928 /// \param StartLoc Starting location of the clause. 2929 /// \param LParenLoc Location of '('. 2930 /// \param EndLoc Ending location of the clause. 2931 /// \param VL List of references to the variables. 2932 /// \param SrcExprs List of helper expressions for proper generation of 2933 /// assignment operation required for copyprivate clause. This list represents 2934 /// sources. 2935 /// \param DstExprs List of helper expressions for proper generation of 2936 /// assignment operation required for copyprivate clause. This list represents 2937 /// destinations. 2938 /// \param AssignmentOps List of helper expressions that represents assignment 2939 /// operation: 2940 /// \code 2941 /// DstExprs = SrcExprs; 2942 /// \endcode 2943 /// Required for proper codegen of final assignment performed by the 2944 /// copyprivate clause. 2945 static OMPCopyprivateClause * 2946 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 2947 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, 2948 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps); 2949 2950 /// \brief Creates an empty clause with \a N variables. 2951 /// 2952 /// \param C AST context. 2953 /// \param N The number of variables. 2954 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N); 2955 2956 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator; 2957 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator; 2958 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>; 2959 using helper_expr_const_range = 2960 llvm::iterator_range<helper_expr_const_iterator>; 2961 2962 helper_expr_const_range source_exprs() const { 2963 return helper_expr_const_range(getSourceExprs().begin(), 2964 getSourceExprs().end()); 2965 } 2966 2967 helper_expr_range source_exprs() { 2968 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end()); 2969 } 2970 2971 helper_expr_const_range destination_exprs() const { 2972 return helper_expr_const_range(getDestinationExprs().begin(), 2973 getDestinationExprs().end()); 2974 } 2975 2976 helper_expr_range destination_exprs() { 2977 return helper_expr_range(getDestinationExprs().begin(), 2978 getDestinationExprs().end()); 2979 } 2980 2981 helper_expr_const_range assignment_ops() const { 2982 return helper_expr_const_range(getAssignmentOps().begin(), 2983 getAssignmentOps().end()); 2984 } 2985 2986 helper_expr_range assignment_ops() { 2987 return helper_expr_range(getAssignmentOps().begin(), 2988 getAssignmentOps().end()); 2989 } 2990 2991 child_range children() { 2992 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 2993 reinterpret_cast<Stmt **>(varlist_end())); 2994 } 2995 2996 static bool classof(const OMPClause *T) { 2997 return T->getClauseKind() == OMPC_copyprivate; 2998 } 2999}; 3000 3001/// \brief This represents implicit clause 'flush' for the '#pragma omp flush' 3002/// directive. 3003/// This clause does not exist by itself, it can be only as a part of 'omp 3004/// flush' directive. This clause is introduced to keep the original structure 3005/// of \a OMPExecutableDirective class and its derivatives and to use the 3006/// existing infrastructure of clauses with the list of variables. 3007/// 3008/// \code 3009/// #pragma omp flush(a,b) 3010/// \endcode 3011/// In this example directive '#pragma omp flush' has implicit clause 'flush' 3012/// with the variables 'a' and 'b'. 3013class OMPFlushClause final 3014 : public OMPVarListClause<OMPFlushClause>, 3015 private llvm::TrailingObjects<OMPFlushClause, Expr *> { 3016 friend OMPVarListClause; 3017 friend TrailingObjects; 3018 3019 /// \brief Build clause with number of variables \a N. 3020 /// 3021 /// \param StartLoc Starting location of the clause. 3022 /// \param LParenLoc Location of '('. 3023 /// \param EndLoc Ending location of the clause. 3024 /// \param N Number of the variables in the clause. 3025 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc, 3026 SourceLocation EndLoc, unsigned N) 3027 : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc, 3028 EndLoc, N) {} 3029 3030 /// \brief Build an empty clause. 3031 /// 3032 /// \param N Number of variables. 3033 explicit OMPFlushClause(unsigned N) 3034 : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(), 3035 SourceLocation(), SourceLocation(), 3036 N) {} 3037 3038public: 3039 /// \brief Creates clause with a list of variables \a VL. 3040 /// 3041 /// \param C AST context. 3042 /// \param StartLoc Starting location of the clause. 3043 /// \param LParenLoc Location of '('. 3044 /// \param EndLoc Ending location of the clause. 3045 /// \param VL List of references to the variables. 3046 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc, 3047 SourceLocation LParenLoc, SourceLocation EndLoc, 3048 ArrayRef<Expr *> VL); 3049 3050 /// \brief Creates an empty clause with \a N variables. 3051 /// 3052 /// \param C AST context. 3053 /// \param N The number of variables. 3054 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N); 3055 3056 child_range children() { 3057 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 3058 reinterpret_cast<Stmt **>(varlist_end())); 3059 } 3060 3061 static bool classof(const OMPClause *T) { 3062 return T->getClauseKind() == OMPC_flush; 3063 } 3064}; 3065 3066/// \brief This represents implicit clause 'depend' for the '#pragma omp task' 3067/// directive. 3068/// 3069/// \code 3070/// #pragma omp task depend(in:a,b) 3071/// \endcode 3072/// In this example directive '#pragma omp task' with clause 'depend' with the 3073/// variables 'a' and 'b' with dependency 'in'. 3074class OMPDependClause final 3075 : public OMPVarListClause<OMPDependClause>, 3076 private llvm::TrailingObjects<OMPDependClause, Expr *> { 3077 friend class OMPClauseReader; 3078 friend OMPVarListClause; 3079 friend TrailingObjects; 3080 3081 /// \brief Dependency type (one of in, out, inout). 3082 OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown; 3083 3084 /// \brief Dependency type location. 3085 SourceLocation DepLoc; 3086 3087 /// \brief Colon location. 3088 SourceLocation ColonLoc; 3089 3090 /// \brief Build clause with number of variables \a N. 3091 /// 3092 /// \param StartLoc Starting location of the clause. 3093 /// \param LParenLoc Location of '('. 3094 /// \param EndLoc Ending location of the clause. 3095 /// \param N Number of the variables in the clause. 3096 OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc, 3097 SourceLocation EndLoc, unsigned N) 3098 : OMPVarListClause<OMPDependClause>(OMPC_depend, StartLoc, LParenLoc, 3099 EndLoc, N) {} 3100 3101 /// \brief Build an empty clause. 3102 /// 3103 /// \param N Number of variables. 3104 explicit OMPDependClause(unsigned N) 3105 : OMPVarListClause<OMPDependClause>(OMPC_depend, SourceLocation(), 3106 SourceLocation(), SourceLocation(), 3107 N) {} 3108 3109 /// \brief Set dependency kind. 3110 void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; } 3111 3112 /// \brief Set dependency kind and its location. 3113 void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; } 3114 3115 /// \brief Set colon location. 3116 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 3117 3118public: 3119 /// \brief Creates clause with a list of variables \a VL. 3120 /// 3121 /// \param C AST context. 3122 /// \param StartLoc Starting location of the clause. 3123 /// \param LParenLoc Location of '('. 3124 /// \param EndLoc Ending location of the clause. 3125 /// \param DepKind Dependency type. 3126 /// \param DepLoc Location of the dependency type. 3127 /// \param ColonLoc Colon location. 3128 /// \param VL List of references to the variables. 3129 static OMPDependClause * 3130 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 3131 SourceLocation EndLoc, OpenMPDependClauseKind DepKind, 3132 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL); 3133 3134 /// \brief Creates an empty clause with \a N variables. 3135 /// 3136 /// \param C AST context. 3137 /// \param N The number of variables. 3138 static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N); 3139 3140 /// \brief Get dependency type. 3141 OpenMPDependClauseKind getDependencyKind() const { return DepKind; } 3142 3143 /// \brief Get dependency type location. 3144 SourceLocation getDependencyLoc() const { return DepLoc; } 3145 3146 /// \brief Get colon location. 3147 SourceLocation getColonLoc() const { return ColonLoc; } 3148 3149 /// Set the loop counter value for the depend clauses with 'sink|source' kind 3150 /// of dependency. Required for codegen. 3151 void setCounterValue(Expr *V); 3152 3153 /// Get the loop counter value. 3154 Expr *getCounterValue(); 3155 3156 /// Get the loop counter value. 3157 const Expr *getCounterValue() const; 3158 3159 child_range children() { 3160 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 3161 reinterpret_cast<Stmt **>(varlist_end())); 3162 } 3163 3164 static bool classof(const OMPClause *T) { 3165 return T->getClauseKind() == OMPC_depend; 3166 } 3167}; 3168 3169/// \brief This represents 'device' clause in the '#pragma omp ...' 3170/// directive. 3171/// 3172/// \code 3173/// #pragma omp target device(a) 3174/// \endcode 3175/// In this example directive '#pragma omp target' has clause 'device' 3176/// with single expression 'a'. 3177class OMPDeviceClause : public OMPClause, public OMPClauseWithPreInit { 3178 friend class OMPClauseReader; 3179 3180 /// \brief Location of '('. 3181 SourceLocation LParenLoc; 3182 3183 /// \brief Device number. 3184 Stmt *Device = nullptr; 3185 3186 /// \brief Set the device number. 3187 /// 3188 /// \param E Device number. 3189 void setDevice(Expr *E) { Device = E; } 3190 3191public: 3192 /// \brief Build 'device' clause. 3193 /// 3194 /// \param E Expression associated with this clause. 3195 /// \param StartLoc Starting location of the clause. 3196 /// \param LParenLoc Location of '('. 3197 /// \param EndLoc Ending location of the clause. 3198 OMPDeviceClause(Expr *E, Stmt *HelperE, SourceLocation StartLoc, 3199 SourceLocation LParenLoc, SourceLocation EndLoc) 3200 : OMPClause(OMPC_device, StartLoc, EndLoc), OMPClauseWithPreInit(this), 3201 LParenLoc(LParenLoc), Device(E) { 3202 setPreInitStmt(HelperE); 3203 } 3204 3205 /// \brief Build an empty clause. 3206 OMPDeviceClause() 3207 : OMPClause(OMPC_device, SourceLocation(), SourceLocation()), 3208 OMPClauseWithPreInit(this) {} 3209 3210 /// \brief Sets the location of '('. 3211 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 3212 3213 /// \brief Returns the location of '('. 3214 SourceLocation getLParenLoc() const { return LParenLoc; } 3215 3216 /// \brief Return device number. 3217 Expr *getDevice() { return cast<Expr>(Device); } 3218 3219 /// \brief Return device number. 3220 Expr *getDevice() const { return cast<Expr>(Device); } 3221 3222 child_range children() { return child_range(&Device, &Device + 1); } 3223 3224 static bool classof(const OMPClause *T) { 3225 return T->getClauseKind() == OMPC_device; 3226 } 3227}; 3228 3229/// \brief This represents 'threads' clause in the '#pragma omp ...' directive. 3230/// 3231/// \code 3232/// #pragma omp ordered threads 3233/// \endcode 3234/// In this example directive '#pragma omp ordered' has simple 'threads' clause. 3235class OMPThreadsClause : public OMPClause { 3236public: 3237 /// \brief Build 'threads' clause. 3238 /// 3239 /// \param StartLoc Starting location of the clause. 3240 /// \param EndLoc Ending location of the clause. 3241 OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc) 3242 : OMPClause(OMPC_threads, StartLoc, EndLoc) {} 3243 3244 /// \brief Build an empty clause. 3245 OMPThreadsClause() 3246 : OMPClause(OMPC_threads, SourceLocation(), SourceLocation()) {} 3247 3248 child_range children() { 3249 return child_range(child_iterator(), child_iterator()); 3250 } 3251 3252 static bool classof(const OMPClause *T) { 3253 return T->getClauseKind() == OMPC_threads; 3254 } 3255}; 3256 3257/// \brief This represents 'simd' clause in the '#pragma omp ...' directive. 3258/// 3259/// \code 3260/// #pragma omp ordered simd 3261/// \endcode 3262/// In this example directive '#pragma omp ordered' has simple 'simd' clause. 3263class OMPSIMDClause : public OMPClause { 3264public: 3265 /// \brief Build 'simd' clause. 3266 /// 3267 /// \param StartLoc Starting location of the clause. 3268 /// \param EndLoc Ending location of the clause. 3269 OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc) 3270 : OMPClause(OMPC_simd, StartLoc, EndLoc) {} 3271 3272 /// \brief Build an empty clause. 3273 OMPSIMDClause() : OMPClause(OMPC_simd, SourceLocation(), SourceLocation()) {} 3274 3275 child_range children() { 3276 return child_range(child_iterator(), child_iterator()); 3277 } 3278 3279 static bool classof(const OMPClause *T) { 3280 return T->getClauseKind() == OMPC_simd; 3281 } 3282}; 3283 3284/// \brief Struct that defines common infrastructure to handle mappable 3285/// expressions used in OpenMP clauses. 3286class OMPClauseMappableExprCommon { 3287public: 3288 // \brief Class that represents a component of a mappable expression. E.g. 3289 // for an expression S.a, the first component is a declaration reference 3290 // expression associated with 'S' and the second is a member expression 3291 // associated with the field declaration 'a'. If the expression is an array 3292 // subscript it may not have any associated declaration. In that case the 3293 // associated declaration is set to nullptr. 3294 class MappableComponent { 3295 // \brief Expression associated with the component. 3296 Expr *AssociatedExpression = nullptr; 3297 3298 // \brief Declaration associated with the declaration. If the component does 3299 // not have a declaration (e.g. array subscripts or section), this is set to 3300 // nullptr. 3301 ValueDecl *AssociatedDeclaration = nullptr; 3302 3303 public: 3304 explicit MappableComponent() = default; 3305 explicit MappableComponent(Expr *AssociatedExpression, 3306 ValueDecl *AssociatedDeclaration) 3307 : AssociatedExpression(AssociatedExpression), 3308 AssociatedDeclaration( 3309 AssociatedDeclaration 3310 ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl()) 3311 : nullptr) {} 3312 3313 Expr *getAssociatedExpression() const { return AssociatedExpression; } 3314 3315 ValueDecl *getAssociatedDeclaration() const { 3316 return AssociatedDeclaration; 3317 } 3318 }; 3319 3320 // \brief List of components of an expression. This first one is the whole 3321 // expression and the last one is the base expression. 3322 using MappableExprComponentList = SmallVector<MappableComponent, 8>; 3323 using MappableExprComponentListRef = ArrayRef<MappableComponent>; 3324 3325 // \brief List of all component lists associated to the same base declaration. 3326 // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have 3327 // their component list but the same base declaration 'S'. 3328 using MappableExprComponentLists = SmallVector<MappableExprComponentList, 8>; 3329 using MappableExprComponentListsRef = ArrayRef<MappableExprComponentList>; 3330 3331protected: 3332 // \brief Return the total number of elements in a list of component lists. 3333 static unsigned 3334 getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists); 3335 3336 // \brief Return the total number of elements in a list of declarations. All 3337 // declarations are expected to be canonical. 3338 static unsigned 3339 getUniqueDeclarationsTotalNumber(ArrayRef<ValueDecl *> Declarations); 3340}; 3341 3342/// \brief This represents clauses with a list of expressions that are mappable. 3343/// Examples of these clauses are 'map' in 3344/// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from 3345/// in '#pragma omp target update...' directives. 3346template <class T> 3347class OMPMappableExprListClause : public OMPVarListClause<T>, 3348 public OMPClauseMappableExprCommon { 3349 friend class OMPClauseReader; 3350 3351 /// \brief Number of unique declarations in this clause. 3352 unsigned NumUniqueDeclarations; 3353 3354 /// \brief Number of component lists in this clause. 3355 unsigned NumComponentLists; 3356 3357 /// \brief Total number of components in this clause. 3358 unsigned NumComponents; 3359 3360protected: 3361 /// \brief Build a clause for \a NumUniqueDeclarations declarations, \a 3362 /// NumComponentLists total component lists, and \a NumComponents total 3363 /// components. 3364 /// 3365 /// \param K Kind of the clause. 3366 /// \param StartLoc Starting location of the clause (the clause keyword). 3367 /// \param LParenLoc Location of '('. 3368 /// \param EndLoc Ending location of the clause. 3369 /// \param NumVars Number of expressions listed in the clause. 3370 /// \param NumUniqueDeclarations Number of unique base declarations in this 3371 /// clause. 3372 /// \param NumComponentLists Number of component lists in this clause - one 3373 /// list for each expression in the clause. 3374 /// \param NumComponents Total number of expression components in the clause. 3375 OMPMappableExprListClause(OpenMPClauseKind K, SourceLocation StartLoc, 3376 SourceLocation LParenLoc, SourceLocation EndLoc, 3377 unsigned NumVars, unsigned NumUniqueDeclarations, 3378 unsigned NumComponentLists, unsigned NumComponents) 3379 : OMPVarListClause<T>(K, StartLoc, LParenLoc, EndLoc, NumVars), 3380 NumUniqueDeclarations(NumUniqueDeclarations), 3381 NumComponentLists(NumComponentLists), NumComponents(NumComponents) {} 3382 3383 /// \brief Get the unique declarations that are in the trailing objects of the 3384 /// class. 3385 MutableArrayRef<ValueDecl *> getUniqueDeclsRef() { 3386 return MutableArrayRef<ValueDecl *>( 3387 static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(), 3388 NumUniqueDeclarations); 3389 } 3390 3391 /// \brief Get the unique declarations that are in the trailing objects of the 3392 /// class. 3393 ArrayRef<ValueDecl *> getUniqueDeclsRef() const { 3394 return ArrayRef<ValueDecl *>( 3395 static_cast<const T *>(this) 3396 ->template getTrailingObjects<ValueDecl *>(), 3397 NumUniqueDeclarations); 3398 } 3399 3400 /// \brief Set the unique declarations that are in the trailing objects of the 3401 /// class. 3402 void setUniqueDecls(ArrayRef<ValueDecl *> UDs) { 3403 assert(UDs.size() == NumUniqueDeclarations && 3404 "Unexpected amount of unique declarations."); 3405 std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin()); 3406 } 3407 3408 /// \brief Get the number of lists per declaration that are in the trailing 3409 /// objects of the class. 3410 MutableArrayRef<unsigned> getDeclNumListsRef() { 3411 return MutableArrayRef<unsigned>( 3412 static_cast<T *>(this)->template getTrailingObjects<unsigned>(), 3413 NumUniqueDeclarations); 3414 } 3415 3416 /// \brief Get the number of lists per declaration that are in the trailing 3417 /// objects of the class. 3418 ArrayRef<unsigned> getDeclNumListsRef() const { 3419 return ArrayRef<unsigned>( 3420 static_cast<const T *>(this)->template getTrailingObjects<unsigned>(), 3421 NumUniqueDeclarations); 3422 } 3423 3424 /// \brief Set the number of lists per declaration that are in the trailing 3425 /// objects of the class. 3426 void setDeclNumLists(ArrayRef<unsigned> DNLs) { 3427 assert(DNLs.size() == NumUniqueDeclarations && 3428 "Unexpected amount of list numbers."); 3429 std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin()); 3430 } 3431 3432 /// \brief Get the cumulative component lists sizes that are in the trailing 3433 /// objects of the class. They are appended after the number of lists. 3434 MutableArrayRef<unsigned> getComponentListSizesRef() { 3435 return MutableArrayRef<unsigned>( 3436 static_cast<T *>(this)->template getTrailingObjects<unsigned>() + 3437 NumUniqueDeclarations, 3438 NumComponentLists); 3439 } 3440 3441 /// \brief Get the cumulative component lists sizes that are in the trailing 3442 /// objects of the class. They are appended after the number of lists. 3443 ArrayRef<unsigned> getComponentListSizesRef() const { 3444 return ArrayRef<unsigned>( 3445 static_cast<const T *>(this)->template getTrailingObjects<unsigned>() + 3446 NumUniqueDeclarations, 3447 NumComponentLists); 3448 } 3449 3450 /// \brief Set the cumulative component lists sizes that are in the trailing 3451 /// objects of the class. 3452 void setComponentListSizes(ArrayRef<unsigned> CLSs) { 3453 assert(CLSs.size() == NumComponentLists && 3454 "Unexpected amount of component lists."); 3455 std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin()); 3456 } 3457 3458 /// \brief Get the components that are in the trailing objects of the class. 3459 MutableArrayRef<MappableComponent> getComponentsRef() { 3460 return MutableArrayRef<MappableComponent>( 3461 static_cast<T *>(this) 3462 ->template getTrailingObjects<MappableComponent>(), 3463 NumComponents); 3464 } 3465 3466 /// \brief Get the components that are in the trailing objects of the class. 3467 ArrayRef<MappableComponent> getComponentsRef() const { 3468 return ArrayRef<MappableComponent>( 3469 static_cast<const T *>(this) 3470 ->template getTrailingObjects<MappableComponent>(), 3471 NumComponents); 3472 } 3473 3474 /// \brief Set the components that are in the trailing objects of the class. 3475 /// This requires the list sizes so that it can also fill the original 3476 /// expressions, which are the first component of each list. 3477 void setComponents(ArrayRef<MappableComponent> Components, 3478 ArrayRef<unsigned> CLSs) { 3479 assert(Components.size() == NumComponents && 3480 "Unexpected amount of component lists."); 3481 assert(CLSs.size() == NumComponentLists && 3482 "Unexpected amount of list sizes."); 3483 std::copy(Components.begin(), Components.end(), getComponentsRef().begin()); 3484 } 3485 3486 /// \brief Fill the clause information from the list of declarations and 3487 /// associated component lists. 3488 void setClauseInfo(ArrayRef<ValueDecl *> Declarations, 3489 MappableExprComponentListsRef ComponentLists) { 3490 // Perform some checks to make sure the data sizes are consistent with the 3491 // information available when the clause was created. 3492 assert(getUniqueDeclarationsTotalNumber(Declarations) == 3493 NumUniqueDeclarations && 3494 "Unexpected number of mappable expression info entries!"); 3495 assert(getComponentsTotalNumber(ComponentLists) == NumComponents && 3496 "Unexpected total number of components!"); 3497 assert(Declarations.size() == ComponentLists.size() && 3498 "Declaration and component lists size is not consistent!"); 3499 assert(Declarations.size() == NumComponentLists && 3500 "Unexpected declaration and component lists size!"); 3501 3502 // Organize the components by declaration and retrieve the original 3503 // expression. Original expressions are always the first component of the 3504 // mappable component list. 3505 llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>> 3506 ComponentListMap; 3507 { 3508 auto CI = ComponentLists.begin(); 3509 for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE; 3510 ++DI, ++CI) { 3511 assert(!CI->empty() && "Invalid component list!"); 3512 ComponentListMap[*DI].push_back(*CI); 3513 } 3514 } 3515 3516 // Iterators of the target storage. 3517 auto UniqueDeclarations = getUniqueDeclsRef(); 3518 auto UDI = UniqueDeclarations.begin(); 3519 3520 auto DeclNumLists = getDeclNumListsRef(); 3521 auto DNLI = DeclNumLists.begin(); 3522 3523 auto ComponentListSizes = getComponentListSizesRef(); 3524 auto CLSI = ComponentListSizes.begin(); 3525 3526 auto Components = getComponentsRef(); 3527 auto CI = Components.begin(); 3528 3529 // Variable to compute the accumulation of the number of components. 3530 unsigned PrevSize = 0u; 3531 3532 // Scan all the declarations and associated component lists. 3533 for (auto &M : ComponentListMap) { 3534 // The declaration. 3535 auto *D = M.first; 3536 // The component lists. 3537 auto CL = M.second; 3538 3539 // Initialize the entry. 3540 *UDI = D; 3541 ++UDI; 3542 3543 *DNLI = CL.size(); 3544 ++DNLI; 3545 3546 // Obtain the cumulative sizes and concatenate all the components in the 3547 // reserved storage. 3548 for (auto C : CL) { 3549 // Accumulate with the previous size. 3550 PrevSize += C.size(); 3551 3552 // Save the size. 3553 *CLSI = PrevSize; 3554 ++CLSI; 3555 3556 // Append components after the current components iterator. 3557 CI = std::copy(C.begin(), C.end(), CI); 3558 } 3559 } 3560 } 3561 3562public: 3563 /// \brief Return the number of unique base declarations in this clause. 3564 unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; } 3565 3566 /// \brief Return the number of lists derived from the clause expressions. 3567 unsigned getTotalComponentListNum() const { return NumComponentLists; } 3568 3569 /// \brief Return the total number of components in all lists derived from the 3570 /// clause. 3571 unsigned getTotalComponentsNum() const { return NumComponents; } 3572 3573 /// \brief Iterator that browse the components by lists. It also allows 3574 /// browsing components of a single declaration. 3575 class const_component_lists_iterator 3576 : public llvm::iterator_adaptor_base< 3577 const_component_lists_iterator, 3578 MappableExprComponentListRef::const_iterator, 3579 std::forward_iterator_tag, MappableComponent, ptrdiff_t, 3580 MappableComponent, MappableComponent> { 3581 // The declaration the iterator currently refers to. 3582 ArrayRef<ValueDecl *>::iterator DeclCur; 3583 3584 // The list number associated with the current declaration. 3585 ArrayRef<unsigned>::iterator NumListsCur; 3586 3587 // Remaining lists for the current declaration. 3588 unsigned RemainingLists = 0; 3589 3590 // The cumulative size of the previous list, or zero if there is no previous 3591 // list. 3592 unsigned PrevListSize = 0; 3593 3594 // The cumulative sizes of the current list - it will delimit the remaining 3595 // range of interest. 3596 ArrayRef<unsigned>::const_iterator ListSizeCur; 3597 ArrayRef<unsigned>::const_iterator ListSizeEnd; 3598 3599 // Iterator to the end of the components storage. 3600 MappableExprComponentListRef::const_iterator End; 3601 3602 public: 3603 /// \brief Construct an iterator that scans all lists. 3604 explicit const_component_lists_iterator( 3605 ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum, 3606 ArrayRef<unsigned> CumulativeListSizes, 3607 MappableExprComponentListRef Components) 3608 : const_component_lists_iterator::iterator_adaptor_base( 3609 Components.begin()), 3610 DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()), 3611 ListSizeCur(CumulativeListSizes.begin()), 3612 ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) { 3613 assert(UniqueDecls.size() == DeclsListNum.size() && 3614 "Inconsistent number of declarations and list sizes!"); 3615 if (!DeclsListNum.empty()) 3616 RemainingLists = *NumListsCur; 3617 } 3618 3619 /// \brief Construct an iterator that scan lists for a given declaration \a 3620 /// Declaration. 3621 explicit const_component_lists_iterator( 3622 const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls, 3623 ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes, 3624 MappableExprComponentListRef Components) 3625 : const_component_lists_iterator(UniqueDecls, DeclsListNum, 3626 CumulativeListSizes, Components) { 3627 // Look for the desired declaration. While we are looking for it, we 3628 // update the state so that we know the component where a given list 3629 // starts. 3630 for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) { 3631 if (*DeclCur == Declaration) 3632 break; 3633 3634 assert(*NumListsCur > 0 && "No lists associated with declaration??"); 3635 3636 // Skip the lists associated with the current declaration, but save the 3637 // last list size that was skipped. 3638 std::advance(ListSizeCur, *NumListsCur - 1); 3639 PrevListSize = *ListSizeCur; 3640 ++ListSizeCur; 3641 } 3642 3643 // If we didn't find any declaration, advance the iterator to after the 3644 // last component and set remaining lists to zero. 3645 if (ListSizeCur == CumulativeListSizes.end()) { 3646 this->I = End; 3647 RemainingLists = 0u; 3648 return; 3649 } 3650 3651 // Set the remaining lists with the total number of lists of the current 3652 // declaration. 3653 RemainingLists = *NumListsCur; 3654 3655 // Adjust the list size end iterator to the end of the relevant range. 3656 ListSizeEnd = ListSizeCur; 3657 std::advance(ListSizeEnd, RemainingLists); 3658 3659 // Given that the list sizes are cumulative, the index of the component 3660 // that start the list is the size of the previous list. 3661 std::advance(this->I, PrevListSize); 3662 } 3663 3664 // Return the array with the current list. The sizes are cumulative, so the 3665 // array size is the difference between the current size and previous one. 3666 std::pair<const ValueDecl *, MappableExprComponentListRef> 3667 operator*() const { 3668 assert(ListSizeCur != ListSizeEnd && "Invalid iterator!"); 3669 return std::make_pair( 3670 *DeclCur, 3671 MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize)); 3672 } 3673 std::pair<const ValueDecl *, MappableExprComponentListRef> 3674 operator->() const { 3675 return **this; 3676 } 3677 3678 // Skip the components of the current list. 3679 const_component_lists_iterator &operator++() { 3680 assert(ListSizeCur != ListSizeEnd && RemainingLists && 3681 "Invalid iterator!"); 3682 3683 // If we don't have more lists just skip all the components. Otherwise, 3684 // advance the iterator by the number of components in the current list. 3685 if (std::next(ListSizeCur) == ListSizeEnd) { 3686 this->I = End; 3687 RemainingLists = 0; 3688 } else { 3689 std::advance(this->I, *ListSizeCur - PrevListSize); 3690 PrevListSize = *ListSizeCur; 3691 3692 // We are done with a declaration, move to the next one. 3693 if (!(--RemainingLists)) { 3694 ++DeclCur; 3695 ++NumListsCur; 3696 RemainingLists = *NumListsCur; 3697 assert(RemainingLists && "No lists in the following declaration??"); 3698 } 3699 } 3700 3701 ++ListSizeCur; 3702 return *this; 3703 } 3704 }; 3705 3706 using const_component_lists_range = 3707 llvm::iterator_range<const_component_lists_iterator>; 3708 3709 /// \brief Iterators for all component lists. 3710 const_component_lists_iterator component_lists_begin() const { 3711 return const_component_lists_iterator( 3712 getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(), 3713 getComponentsRef()); 3714 } 3715 const_component_lists_iterator component_lists_end() const { 3716 return const_component_lists_iterator( 3717 ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(), 3718 MappableExprComponentListRef(getComponentsRef().end(), 3719 getComponentsRef().end())); 3720 } 3721 const_component_lists_range component_lists() const { 3722 return {component_lists_begin(), component_lists_end()}; 3723 } 3724 3725 /// \brief Iterators for component lists associated with the provided 3726 /// declaration. 3727 const_component_lists_iterator 3728 decl_component_lists_begin(const ValueDecl *VD) const { 3729 return const_component_lists_iterator( 3730 VD, getUniqueDeclsRef(), getDeclNumListsRef(), 3731 getComponentListSizesRef(), getComponentsRef()); 3732 } 3733 const_component_lists_iterator decl_component_lists_end() const { 3734 return component_lists_end(); 3735 } 3736 const_component_lists_range decl_component_lists(const ValueDecl *VD) const { 3737 return {decl_component_lists_begin(VD), decl_component_lists_end()}; 3738 } 3739 3740 /// Iterators to access all the declarations, number of lists, list sizes, and 3741 /// components. 3742 using const_all_decls_iterator = ArrayRef<ValueDecl *>::iterator; 3743 using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>; 3744 3745 const_all_decls_range all_decls() const { 3746 auto A = getUniqueDeclsRef(); 3747 return const_all_decls_range(A.begin(), A.end()); 3748 } 3749 3750 using const_all_num_lists_iterator = ArrayRef<unsigned>::iterator; 3751 using const_all_num_lists_range = 3752 llvm::iterator_range<const_all_num_lists_iterator>; 3753 3754 const_all_num_lists_range all_num_lists() const { 3755 auto A = getDeclNumListsRef(); 3756 return const_all_num_lists_range(A.begin(), A.end()); 3757 } 3758 3759 using const_all_lists_sizes_iterator = ArrayRef<unsigned>::iterator; 3760 using const_all_lists_sizes_range = 3761 llvm::iterator_range<const_all_lists_sizes_iterator>; 3762 3763 const_all_lists_sizes_range all_lists_sizes() const { 3764 auto A = getComponentListSizesRef(); 3765 return const_all_lists_sizes_range(A.begin(), A.end()); 3766 } 3767 3768 using const_all_components_iterator = ArrayRef<MappableComponent>::iterator; 3769 using const_all_components_range = 3770 llvm::iterator_range<const_all_components_iterator>; 3771 3772 const_all_components_range all_components() const { 3773 auto A = getComponentsRef(); 3774 return const_all_components_range(A.begin(), A.end()); 3775 } 3776}; 3777 3778/// \brief This represents clause 'map' in the '#pragma omp ...' 3779/// directives. 3780/// 3781/// \code 3782/// #pragma omp target map(a,b) 3783/// \endcode 3784/// In this example directive '#pragma omp target' has clause 'map' 3785/// with the variables 'a' and 'b'. 3786class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>, 3787 private llvm::TrailingObjects< 3788 OMPMapClause, Expr *, ValueDecl *, unsigned, 3789 OMPClauseMappableExprCommon::MappableComponent> { 3790 friend class OMPClauseReader; 3791 friend OMPMappableExprListClause; 3792 friend OMPVarListClause; 3793 friend TrailingObjects; 3794 3795 /// Define the sizes of each trailing object array except the last one. This 3796 /// is required for TrailingObjects to work properly. 3797 size_t numTrailingObjects(OverloadToken<Expr *>) const { 3798 return varlist_size(); 3799 } 3800 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { 3801 return getUniqueDeclarationsNum(); 3802 } 3803 size_t numTrailingObjects(OverloadToken<unsigned>) const { 3804 return getUniqueDeclarationsNum() + getTotalComponentListNum(); 3805 } 3806 3807 /// \brief Map type modifier for the 'map' clause. 3808 OpenMPMapClauseKind MapTypeModifier = OMPC_MAP_unknown; 3809 3810 /// \brief Map type for the 'map' clause. 3811 OpenMPMapClauseKind MapType = OMPC_MAP_unknown; 3812 3813 /// \brief Is this an implicit map type or not. 3814 bool MapTypeIsImplicit = false; 3815 3816 /// \brief Location of the map type. 3817 SourceLocation MapLoc; 3818 3819 /// \brief Colon location. 3820 SourceLocation ColonLoc; 3821 3822 /// \brief Build a clause for \a NumVars listed expressions, \a 3823 /// NumUniqueDeclarations declarations, \a NumComponentLists total component 3824 /// lists, and \a NumComponents total expression components. 3825 /// 3826 /// \param MapTypeModifier Map type modifier. 3827 /// \param MapType Map type. 3828 /// \param MapTypeIsImplicit Map type is inferred implicitly. 3829 /// \param MapLoc Location of the map type. 3830 /// \param StartLoc Starting location of the clause. 3831 /// \param EndLoc Ending location of the clause. 3832 /// \param NumVars Number of expressions listed in this clause. 3833 /// \param NumUniqueDeclarations Number of unique base declarations in this 3834 /// clause. 3835 /// \param NumComponentLists Number of component lists in this clause. 3836 /// \param NumComponents Total number of expression components in the clause. 3837 explicit OMPMapClause(OpenMPMapClauseKind MapTypeModifier, 3838 OpenMPMapClauseKind MapType, bool MapTypeIsImplicit, 3839 SourceLocation MapLoc, SourceLocation StartLoc, 3840 SourceLocation LParenLoc, SourceLocation EndLoc, 3841 unsigned NumVars, unsigned NumUniqueDeclarations, 3842 unsigned NumComponentLists, unsigned NumComponents) 3843 : OMPMappableExprListClause(OMPC_map, StartLoc, LParenLoc, EndLoc, 3844 NumVars, NumUniqueDeclarations, 3845 NumComponentLists, NumComponents), 3846 MapTypeModifier(MapTypeModifier), MapType(MapType), 3847 MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {} 3848 3849 /// \brief Build an empty clause. 3850 /// 3851 /// \param NumVars Number of expressions listed in this clause. 3852 /// \param NumUniqueDeclarations Number of unique base declarations in this 3853 /// clause. 3854 /// \param NumComponentLists Number of component lists in this clause. 3855 /// \param NumComponents Total number of expression components in the clause. 3856 explicit OMPMapClause(unsigned NumVars, unsigned NumUniqueDeclarations, 3857 unsigned NumComponentLists, unsigned NumComponents) 3858 : OMPMappableExprListClause( 3859 OMPC_map, SourceLocation(), SourceLocation(), SourceLocation(), 3860 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {} 3861 3862 /// \brief Set type modifier for the clause. 3863 /// 3864 /// \param T Type Modifier for the clause. 3865 void setMapTypeModifier(OpenMPMapClauseKind T) { MapTypeModifier = T; } 3866 3867 /// \brief Set type for the clause. 3868 /// 3869 /// \param T Type for the clause. 3870 void setMapType(OpenMPMapClauseKind T) { MapType = T; } 3871 3872 /// \brief Set type location. 3873 /// 3874 /// \param TLoc Type location. 3875 void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; } 3876 3877 /// \brief Set colon location. 3878 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; } 3879 3880public: 3881 /// \brief Creates clause with a list of variables \a VL. 3882 /// 3883 /// \param C AST context. 3884 /// \param StartLoc Starting location of the clause. 3885 /// \param EndLoc Ending location of the clause. 3886 /// \param Vars The original expression used in the clause. 3887 /// \param Declarations Declarations used in the clause. 3888 /// \param ComponentLists Component lists used in the clause. 3889 /// \param TypeModifier Map type modifier. 3890 /// \param Type Map type. 3891 /// \param TypeIsImplicit Map type is inferred implicitly. 3892 /// \param TypeLoc Location of the map type. 3893 static OMPMapClause *Create(const ASTContext &C, SourceLocation StartLoc, 3894 SourceLocation LParenLoc, SourceLocation EndLoc, 3895 ArrayRef<Expr *> Vars, 3896 ArrayRef<ValueDecl *> Declarations, 3897 MappableExprComponentListsRef ComponentLists, 3898 OpenMPMapClauseKind TypeModifier, 3899 OpenMPMapClauseKind Type, bool TypeIsImplicit, 3900 SourceLocation TypeLoc); 3901 3902 /// \brief Creates an empty clause with the place for for \a NumVars original 3903 /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists 3904 /// lists, and \a NumComponents expression components. 3905 /// 3906 /// \param C AST context. 3907 /// \param NumVars Number of expressions listed in the clause. 3908 /// \param NumUniqueDeclarations Number of unique base declarations in this 3909 /// clause. 3910 /// \param NumComponentLists Number of unique base declarations in this 3911 /// clause. 3912 /// \param NumComponents Total number of expression components in the clause. 3913 static OMPMapClause *CreateEmpty(const ASTContext &C, unsigned NumVars, 3914 unsigned NumUniqueDeclarations, 3915 unsigned NumComponentLists, 3916 unsigned NumComponents); 3917 3918 /// \brief Fetches mapping kind for the clause. 3919 OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; } 3920 3921 /// \brief Is this an implicit map type? 3922 /// We have to capture 'IsMapTypeImplicit' from the parser for more 3923 /// informative error messages. It helps distinguish map(r) from 3924 /// map(tofrom: r), which is important to print more helpful error 3925 /// messages for some target directives. 3926 bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; } 3927 3928 /// \brief Fetches the map type modifier for the clause. 3929 OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY { 3930 return MapTypeModifier; 3931 } 3932 3933 /// \brief Fetches location of clause mapping kind. 3934 SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; } 3935 3936 /// \brief Get colon location. 3937 SourceLocation getColonLoc() const { return ColonLoc; } 3938 3939 child_range children() { 3940 return child_range( 3941 reinterpret_cast<Stmt **>(varlist_begin()), 3942 reinterpret_cast<Stmt **>(varlist_end())); 3943 } 3944 3945 static bool classof(const OMPClause *T) { 3946 return T->getClauseKind() == OMPC_map; 3947 } 3948}; 3949 3950/// \brief This represents 'num_teams' clause in the '#pragma omp ...' 3951/// directive. 3952/// 3953/// \code 3954/// #pragma omp teams num_teams(n) 3955/// \endcode 3956/// In this example directive '#pragma omp teams' has clause 'num_teams' 3957/// with single expression 'n'. 3958class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit { 3959 friend class OMPClauseReader; 3960 3961 /// \brief Location of '('. 3962 SourceLocation LParenLoc; 3963 3964 /// \brief NumTeams number. 3965 Stmt *NumTeams = nullptr; 3966 3967 /// \brief Set the NumTeams number. 3968 /// 3969 /// \param E NumTeams number. 3970 void setNumTeams(Expr *E) { NumTeams = E; } 3971 3972public: 3973 /// \brief Build 'num_teams' clause. 3974 /// 3975 /// \param E Expression associated with this clause. 3976 /// \param HelperE Helper Expression associated with this clause. 3977 /// \param CaptureRegion Innermost OpenMP region where expressions in this 3978 /// clause must be captured. 3979 /// \param StartLoc Starting location of the clause. 3980 /// \param LParenLoc Location of '('. 3981 /// \param EndLoc Ending location of the clause. 3982 OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion, 3983 SourceLocation StartLoc, SourceLocation LParenLoc, 3984 SourceLocation EndLoc) 3985 : OMPClause(OMPC_num_teams, StartLoc, EndLoc), OMPClauseWithPreInit(this), 3986 LParenLoc(LParenLoc), NumTeams(E) { 3987 setPreInitStmt(HelperE, CaptureRegion); 3988 } 3989 3990 /// \brief Build an empty clause. 3991 OMPNumTeamsClause() 3992 : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()), 3993 OMPClauseWithPreInit(this) {} 3994 3995 /// \brief Sets the location of '('. 3996 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 3997 3998 /// \brief Returns the location of '('. 3999 SourceLocation getLParenLoc() const { return LParenLoc; } 4000 4001 /// \brief Return NumTeams number. 4002 Expr *getNumTeams() { return cast<Expr>(NumTeams); } 4003 4004 /// \brief Return NumTeams number. 4005 Expr *getNumTeams() const { return cast<Expr>(NumTeams); } 4006 4007 child_range children() { return child_range(&NumTeams, &NumTeams + 1); } 4008 4009 static bool classof(const OMPClause *T) { 4010 return T->getClauseKind() == OMPC_num_teams; 4011 } 4012}; 4013 4014/// \brief This represents 'thread_limit' clause in the '#pragma omp ...' 4015/// directive. 4016/// 4017/// \code 4018/// #pragma omp teams thread_limit(n) 4019/// \endcode 4020/// In this example directive '#pragma omp teams' has clause 'thread_limit' 4021/// with single expression 'n'. 4022class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit { 4023 friend class OMPClauseReader; 4024 4025 /// \brief Location of '('. 4026 SourceLocation LParenLoc; 4027 4028 /// \brief ThreadLimit number. 4029 Stmt *ThreadLimit = nullptr; 4030 4031 /// \brief Set the ThreadLimit number. 4032 /// 4033 /// \param E ThreadLimit number. 4034 void setThreadLimit(Expr *E) { ThreadLimit = E; } 4035 4036public: 4037 /// \brief Build 'thread_limit' clause. 4038 /// 4039 /// \param E Expression associated with this clause. 4040 /// \param HelperE Helper Expression associated with this clause. 4041 /// \param CaptureRegion Innermost OpenMP region where expressions in this 4042 /// clause must be captured. 4043 /// \param StartLoc Starting location of the clause. 4044 /// \param LParenLoc Location of '('. 4045 /// \param EndLoc Ending location of the clause. 4046 OMPThreadLimitClause(Expr *E, Stmt *HelperE, 4047 OpenMPDirectiveKind CaptureRegion, 4048 SourceLocation StartLoc, SourceLocation LParenLoc, 4049 SourceLocation EndLoc) 4050 : OMPClause(OMPC_thread_limit, StartLoc, EndLoc), 4051 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) { 4052 setPreInitStmt(HelperE, CaptureRegion); 4053 } 4054 4055 /// \brief Build an empty clause. 4056 OMPThreadLimitClause() 4057 : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()), 4058 OMPClauseWithPreInit(this) {} 4059 4060 /// \brief Sets the location of '('. 4061 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 4062 4063 /// \brief Returns the location of '('. 4064 SourceLocation getLParenLoc() const { return LParenLoc; } 4065 4066 /// \brief Return ThreadLimit number. 4067 Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); } 4068 4069 /// \brief Return ThreadLimit number. 4070 Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); } 4071 4072 child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); } 4073 4074 static bool classof(const OMPClause *T) { 4075 return T->getClauseKind() == OMPC_thread_limit; 4076 } 4077}; 4078 4079/// \brief This represents 'priority' clause in the '#pragma omp ...' 4080/// directive. 4081/// 4082/// \code 4083/// #pragma omp task priority(n) 4084/// \endcode 4085/// In this example directive '#pragma omp teams' has clause 'priority' with 4086/// single expression 'n'. 4087class OMPPriorityClause : public OMPClause { 4088 friend class OMPClauseReader; 4089 4090 /// \brief Location of '('. 4091 SourceLocation LParenLoc; 4092 4093 /// \brief Priority number. 4094 Stmt *Priority = nullptr; 4095 4096 /// \brief Set the Priority number. 4097 /// 4098 /// \param E Priority number. 4099 void setPriority(Expr *E) { Priority = E; } 4100 4101public: 4102 /// \brief Build 'priority' clause. 4103 /// 4104 /// \param E Expression associated with this clause. 4105 /// \param StartLoc Starting location of the clause. 4106 /// \param LParenLoc Location of '('. 4107 /// \param EndLoc Ending location of the clause. 4108 OMPPriorityClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc, 4109 SourceLocation EndLoc) 4110 : OMPClause(OMPC_priority, StartLoc, EndLoc), LParenLoc(LParenLoc), 4111 Priority(E) {} 4112 4113 /// \brief Build an empty clause. 4114 OMPPriorityClause() 4115 : OMPClause(OMPC_priority, SourceLocation(), SourceLocation()) {} 4116 4117 /// \brief Sets the location of '('. 4118 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 4119 4120 /// \brief Returns the location of '('. 4121 SourceLocation getLParenLoc() const { return LParenLoc; } 4122 4123 /// \brief Return Priority number. 4124 Expr *getPriority() { return cast<Expr>(Priority); } 4125 4126 /// \brief Return Priority number. 4127 Expr *getPriority() const { return cast<Expr>(Priority); } 4128 4129 child_range children() { return child_range(&Priority, &Priority + 1); } 4130 4131 static bool classof(const OMPClause *T) { 4132 return T->getClauseKind() == OMPC_priority; 4133 } 4134}; 4135 4136/// \brief This represents 'grainsize' clause in the '#pragma omp ...' 4137/// directive. 4138/// 4139/// \code 4140/// #pragma omp taskloop grainsize(4) 4141/// \endcode 4142/// In this example directive '#pragma omp taskloop' has clause 'grainsize' 4143/// with single expression '4'. 4144class OMPGrainsizeClause : public OMPClause { 4145 friend class OMPClauseReader; 4146 4147 /// \brief Location of '('. 4148 SourceLocation LParenLoc; 4149 4150 /// \brief Safe iteration space distance. 4151 Stmt *Grainsize = nullptr; 4152 4153 /// \brief Set safelen. 4154 void setGrainsize(Expr *Size) { Grainsize = Size; } 4155 4156public: 4157 /// \brief Build 'grainsize' clause. 4158 /// 4159 /// \param Size Expression associated with this clause. 4160 /// \param StartLoc Starting location of the clause. 4161 /// \param EndLoc Ending location of the clause. 4162 OMPGrainsizeClause(Expr *Size, SourceLocation StartLoc, 4163 SourceLocation LParenLoc, SourceLocation EndLoc) 4164 : OMPClause(OMPC_grainsize, StartLoc, EndLoc), LParenLoc(LParenLoc), 4165 Grainsize(Size) {} 4166 4167 /// \brief Build an empty clause. 4168 explicit OMPGrainsizeClause() 4169 : OMPClause(OMPC_grainsize, SourceLocation(), SourceLocation()) {} 4170 4171 /// \brief Sets the location of '('. 4172 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 4173 4174 /// \brief Returns the location of '('. 4175 SourceLocation getLParenLoc() const { return LParenLoc; } 4176 4177 /// \brief Return safe iteration space distance. 4178 Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); } 4179 4180 child_range children() { return child_range(&Grainsize, &Grainsize + 1); } 4181 4182 static bool classof(const OMPClause *T) { 4183 return T->getClauseKind() == OMPC_grainsize; 4184 } 4185}; 4186 4187/// \brief This represents 'nogroup' clause in the '#pragma omp ...' directive. 4188/// 4189/// \code 4190/// #pragma omp taskloop nogroup 4191/// \endcode 4192/// In this example directive '#pragma omp taskloop' has 'nogroup' clause. 4193class OMPNogroupClause : public OMPClause { 4194public: 4195 /// \brief Build 'nogroup' clause. 4196 /// 4197 /// \param StartLoc Starting location of the clause. 4198 /// \param EndLoc Ending location of the clause. 4199 OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc) 4200 : OMPClause(OMPC_nogroup, StartLoc, EndLoc) {} 4201 4202 /// \brief Build an empty clause. 4203 OMPNogroupClause() 4204 : OMPClause(OMPC_nogroup, SourceLocation(), SourceLocation()) {} 4205 4206 child_range children() { 4207 return child_range(child_iterator(), child_iterator()); 4208 } 4209 4210 static bool classof(const OMPClause *T) { 4211 return T->getClauseKind() == OMPC_nogroup; 4212 } 4213}; 4214 4215/// \brief This represents 'num_tasks' clause in the '#pragma omp ...' 4216/// directive. 4217/// 4218/// \code 4219/// #pragma omp taskloop num_tasks(4) 4220/// \endcode 4221/// In this example directive '#pragma omp taskloop' has clause 'num_tasks' 4222/// with single expression '4'. 4223class OMPNumTasksClause : public OMPClause { 4224 friend class OMPClauseReader; 4225 4226 /// \brief Location of '('. 4227 SourceLocation LParenLoc; 4228 4229 /// \brief Safe iteration space distance. 4230 Stmt *NumTasks = nullptr; 4231 4232 /// \brief Set safelen. 4233 void setNumTasks(Expr *Size) { NumTasks = Size; } 4234 4235public: 4236 /// \brief Build 'num_tasks' clause. 4237 /// 4238 /// \param Size Expression associated with this clause. 4239 /// \param StartLoc Starting location of the clause. 4240 /// \param EndLoc Ending location of the clause. 4241 OMPNumTasksClause(Expr *Size, SourceLocation StartLoc, 4242 SourceLocation LParenLoc, SourceLocation EndLoc) 4243 : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), LParenLoc(LParenLoc), 4244 NumTasks(Size) {} 4245 4246 /// \brief Build an empty clause. 4247 explicit OMPNumTasksClause() 4248 : OMPClause(OMPC_num_tasks, SourceLocation(), SourceLocation()) {} 4249 4250 /// \brief Sets the location of '('. 4251 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 4252 4253 /// \brief Returns the location of '('. 4254 SourceLocation getLParenLoc() const { return LParenLoc; } 4255 4256 /// \brief Return safe iteration space distance. 4257 Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); } 4258 4259 child_range children() { return child_range(&NumTasks, &NumTasks + 1); } 4260 4261 static bool classof(const OMPClause *T) { 4262 return T->getClauseKind() == OMPC_num_tasks; 4263 } 4264}; 4265 4266/// \brief This represents 'hint' clause in the '#pragma omp ...' directive. 4267/// 4268/// \code 4269/// #pragma omp critical (name) hint(6) 4270/// \endcode 4271/// In this example directive '#pragma omp critical' has name 'name' and clause 4272/// 'hint' with argument '6'. 4273class OMPHintClause : public OMPClause { 4274 friend class OMPClauseReader; 4275 4276 /// \brief Location of '('. 4277 SourceLocation LParenLoc; 4278 4279 /// \brief Hint expression of the 'hint' clause. 4280 Stmt *Hint = nullptr; 4281 4282 /// \brief Set hint expression. 4283 void setHint(Expr *H) { Hint = H; } 4284 4285public: 4286 /// \brief Build 'hint' clause with expression \a Hint. 4287 /// 4288 /// \param Hint Hint expression. 4289 /// \param StartLoc Starting location of the clause. 4290 /// \param LParenLoc Location of '('. 4291 /// \param EndLoc Ending location of the clause. 4292 OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, 4293 SourceLocation EndLoc) 4294 : OMPClause(OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc), 4295 Hint(Hint) {} 4296 4297 /// \brief Build an empty clause. 4298 OMPHintClause() : OMPClause(OMPC_hint, SourceLocation(), SourceLocation()) {} 4299 4300 /// \brief Sets the location of '('. 4301 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 4302 4303 /// \brief Returns the location of '('. 4304 SourceLocation getLParenLoc() const { return LParenLoc; } 4305 4306 /// \brief Returns number of threads. 4307 Expr *getHint() const { return cast_or_null<Expr>(Hint); } 4308 4309 child_range children() { return child_range(&Hint, &Hint + 1); } 4310 4311 static bool classof(const OMPClause *T) { 4312 return T->getClauseKind() == OMPC_hint; 4313 } 4314}; 4315 4316/// \brief This represents 'dist_schedule' clause in the '#pragma omp ...' 4317/// directive. 4318/// 4319/// \code 4320/// #pragma omp distribute dist_schedule(static, 3) 4321/// \endcode 4322/// In this example directive '#pragma omp distribute' has 'dist_schedule' 4323/// clause with arguments 'static' and '3'. 4324class OMPDistScheduleClause : public OMPClause, public OMPClauseWithPreInit { 4325 friend class OMPClauseReader; 4326 4327 /// \brief Location of '('. 4328 SourceLocation LParenLoc; 4329 4330 /// \brief A kind of the 'schedule' clause. 4331 OpenMPDistScheduleClauseKind Kind = OMPC_DIST_SCHEDULE_unknown; 4332 4333 /// \brief Start location of the schedule kind in source code. 4334 SourceLocation KindLoc; 4335 4336 /// \brief Location of ',' (if any). 4337 SourceLocation CommaLoc; 4338 4339 /// \brief Chunk size. 4340 Expr *ChunkSize = nullptr; 4341 4342 /// \brief Set schedule kind. 4343 /// 4344 /// \param K Schedule kind. 4345 void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; } 4346 4347 /// \brief Sets the location of '('. 4348 /// 4349 /// \param Loc Location of '('. 4350 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 4351 4352 /// \brief Set schedule kind start location. 4353 /// 4354 /// \param KLoc Schedule kind location. 4355 void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; } 4356 4357 /// \brief Set location of ','. 4358 /// 4359 /// \param Loc Location of ','. 4360 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; } 4361 4362 /// \brief Set chunk size. 4363 /// 4364 /// \param E Chunk size. 4365 void setChunkSize(Expr *E) { ChunkSize = E; } 4366 4367public: 4368 /// \brief Build 'dist_schedule' clause with schedule kind \a Kind and chunk 4369 /// size expression \a ChunkSize. 4370 /// 4371 /// \param StartLoc Starting location of the clause. 4372 /// \param LParenLoc Location of '('. 4373 /// \param KLoc Starting location of the argument. 4374 /// \param CommaLoc Location of ','. 4375 /// \param EndLoc Ending location of the clause. 4376 /// \param Kind DistSchedule kind. 4377 /// \param ChunkSize Chunk size. 4378 /// \param HelperChunkSize Helper chunk size for combined directives. 4379 OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc, 4380 SourceLocation KLoc, SourceLocation CommaLoc, 4381 SourceLocation EndLoc, 4382 OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, 4383 Stmt *HelperChunkSize) 4384 : OMPClause(OMPC_dist_schedule, StartLoc, EndLoc), 4385 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind), 4386 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) { 4387 setPreInitStmt(HelperChunkSize); 4388 } 4389 4390 /// \brief Build an empty clause. 4391 explicit OMPDistScheduleClause() 4392 : OMPClause(OMPC_dist_schedule, SourceLocation(), SourceLocation()), 4393 OMPClauseWithPreInit(this) {} 4394 4395 /// \brief Get kind of the clause. 4396 OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; } 4397 4398 /// \brief Get location of '('. 4399 SourceLocation getLParenLoc() { return LParenLoc; } 4400 4401 /// \brief Get kind location. 4402 SourceLocation getDistScheduleKindLoc() { return KindLoc; } 4403 4404 /// \brief Get location of ','. 4405 SourceLocation getCommaLoc() { return CommaLoc; } 4406 4407 /// \brief Get chunk size. 4408 Expr *getChunkSize() { return ChunkSize; } 4409 4410 /// \brief Get chunk size. 4411 const Expr *getChunkSize() const { return ChunkSize; } 4412 4413 child_range children() { 4414 return child_range(reinterpret_cast<Stmt **>(&ChunkSize), 4415 reinterpret_cast<Stmt **>(&ChunkSize) + 1); 4416 } 4417 4418 static bool classof(const OMPClause *T) { 4419 return T->getClauseKind() == OMPC_dist_schedule; 4420 } 4421}; 4422 4423/// \brief This represents 'defaultmap' clause in the '#pragma omp ...' directive. 4424/// 4425/// \code 4426/// #pragma omp target defaultmap(tofrom: scalar) 4427/// \endcode 4428/// In this example directive '#pragma omp target' has 'defaultmap' clause of kind 4429/// 'scalar' with modifier 'tofrom'. 4430class OMPDefaultmapClause : public OMPClause { 4431 friend class OMPClauseReader; 4432 4433 /// \brief Location of '('. 4434 SourceLocation LParenLoc; 4435 4436 /// \brief Modifiers for 'defaultmap' clause. 4437 OpenMPDefaultmapClauseModifier Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown; 4438 4439 /// \brief Locations of modifiers. 4440 SourceLocation ModifierLoc; 4441 4442 /// \brief A kind of the 'defaultmap' clause. 4443 OpenMPDefaultmapClauseKind Kind = OMPC_DEFAULTMAP_unknown; 4444 4445 /// \brief Start location of the defaultmap kind in source code. 4446 SourceLocation KindLoc; 4447 4448 /// \brief Set defaultmap kind. 4449 /// 4450 /// \param K Defaultmap kind. 4451 void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; } 4452 4453 /// \brief Set the defaultmap modifier. 4454 /// 4455 /// \param M Defaultmap modifier. 4456 void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) { 4457 Modifier = M; 4458 } 4459 4460 /// \brief Set location of the defaultmap modifier. 4461 void setDefaultmapModifierLoc(SourceLocation Loc) { 4462 ModifierLoc = Loc; 4463 } 4464 4465 /// \brief Sets the location of '('. 4466 /// 4467 /// \param Loc Location of '('. 4468 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } 4469 4470 /// \brief Set defaultmap kind start location. 4471 /// 4472 /// \param KLoc Defaultmap kind location. 4473 void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; } 4474 4475public: 4476 /// \brief Build 'defaultmap' clause with defaultmap kind \a Kind 4477 /// 4478 /// \param StartLoc Starting location of the clause. 4479 /// \param LParenLoc Location of '('. 4480 /// \param KLoc Starting location of the argument. 4481 /// \param EndLoc Ending location of the clause. 4482 /// \param Kind Defaultmap kind. 4483 /// \param M The modifier applied to 'defaultmap' clause. 4484 /// \param MLoc Location of the modifier 4485 OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc, 4486 SourceLocation MLoc, SourceLocation KLoc, 4487 SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind, 4488 OpenMPDefaultmapClauseModifier M) 4489 : OMPClause(OMPC_defaultmap, StartLoc, EndLoc), LParenLoc(LParenLoc), 4490 Modifier(M), ModifierLoc(MLoc), Kind(Kind), KindLoc(KLoc) {} 4491 4492 /// \brief Build an empty clause. 4493 explicit OMPDefaultmapClause() 4494 : OMPClause(OMPC_defaultmap, SourceLocation(), SourceLocation()) {} 4495 4496 /// \brief Get kind of the clause. 4497 OpenMPDefaultmapClauseKind getDefaultmapKind() const { return Kind; } 4498 4499 /// \brief Get the modifier of the clause. 4500 OpenMPDefaultmapClauseModifier getDefaultmapModifier() const { 4501 return Modifier; 4502 } 4503 4504 /// \brief Get location of '('. 4505 SourceLocation getLParenLoc() { return LParenLoc; } 4506 4507 /// \brief Get kind location. 4508 SourceLocation getDefaultmapKindLoc() { return KindLoc; } 4509 4510 /// \brief Get the modifier location. 4511 SourceLocation getDefaultmapModifierLoc() const { 4512 return ModifierLoc; 4513 } 4514 4515 child_range children() { 4516 return child_range(child_iterator(), child_iterator()); 4517 } 4518 4519 static bool classof(const OMPClause *T) { 4520 return T->getClauseKind() == OMPC_defaultmap; 4521 } 4522}; 4523 4524/// \brief This represents clause 'to' in the '#pragma omp ...' 4525/// directives. 4526/// 4527/// \code 4528/// #pragma omp target update to(a,b) 4529/// \endcode 4530/// In this example directive '#pragma omp target update' has clause 'to' 4531/// with the variables 'a' and 'b'. 4532class OMPToClause final : public OMPMappableExprListClause<OMPToClause>, 4533 private llvm::TrailingObjects< 4534 OMPToClause, Expr *, ValueDecl *, unsigned, 4535 OMPClauseMappableExprCommon::MappableComponent> { 4536 friend class OMPClauseReader; 4537 friend OMPMappableExprListClause; 4538 friend OMPVarListClause; 4539 friend TrailingObjects; 4540 4541 /// \brief Build clause with number of variables \a NumVars. 4542 /// 4543 /// \param StartLoc Starting location of the clause. 4544 /// \param EndLoc Ending location of the clause. 4545 /// \param NumVars Number of expressions listed in this clause. 4546 /// \param NumUniqueDeclarations Number of unique base declarations in this 4547 /// clause. 4548 /// \param NumComponentLists Number of component lists in this clause. 4549 /// \param NumComponents Total number of expression components in the clause. 4550 explicit OMPToClause(SourceLocation StartLoc, SourceLocation LParenLoc, 4551 SourceLocation EndLoc, unsigned NumVars, 4552 unsigned NumUniqueDeclarations, 4553 unsigned NumComponentLists, unsigned NumComponents) 4554 : OMPMappableExprListClause(OMPC_to, StartLoc, LParenLoc, EndLoc, NumVars, 4555 NumUniqueDeclarations, NumComponentLists, 4556 NumComponents) {} 4557 4558 /// \brief Build an empty clause. 4559 /// 4560 /// \param NumVars Number of expressions listed in this clause. 4561 /// \param NumUniqueDeclarations Number of unique base declarations in this 4562 /// clause. 4563 /// \param NumComponentLists Number of component lists in this clause. 4564 /// \param NumComponents Total number of expression components in the clause. 4565 explicit OMPToClause(unsigned NumVars, unsigned NumUniqueDeclarations, 4566 unsigned NumComponentLists, unsigned NumComponents) 4567 : OMPMappableExprListClause( 4568 OMPC_to, SourceLocation(), SourceLocation(), SourceLocation(), 4569 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {} 4570 4571 /// Define the sizes of each trailing object array except the last one. This 4572 /// is required for TrailingObjects to work properly. 4573 size_t numTrailingObjects(OverloadToken<Expr *>) const { 4574 return varlist_size(); 4575 } 4576 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { 4577 return getUniqueDeclarationsNum(); 4578 } 4579 size_t numTrailingObjects(OverloadToken<unsigned>) const { 4580 return getUniqueDeclarationsNum() + getTotalComponentListNum(); 4581 } 4582 4583public: 4584 /// \brief Creates clause with a list of variables \a Vars. 4585 /// 4586 /// \param C AST context. 4587 /// \param StartLoc Starting location of the clause. 4588 /// \param EndLoc Ending location of the clause. 4589 /// \param Vars The original expression used in the clause. 4590 /// \param Declarations Declarations used in the clause. 4591 /// \param ComponentLists Component lists used in the clause. 4592 static OMPToClause *Create(const ASTContext &C, SourceLocation StartLoc, 4593 SourceLocation LParenLoc, SourceLocation EndLoc, 4594 ArrayRef<Expr *> Vars, 4595 ArrayRef<ValueDecl *> Declarations, 4596 MappableExprComponentListsRef ComponentLists); 4597 4598 /// \brief Creates an empty clause with the place for \a NumVars variables. 4599 /// 4600 /// \param C AST context. 4601 /// \param NumVars Number of expressions listed in the clause. 4602 /// \param NumUniqueDeclarations Number of unique base declarations in this 4603 /// clause. 4604 /// \param NumComponentLists Number of unique base declarations in this 4605 /// clause. 4606 /// \param NumComponents Total number of expression components in the clause. 4607 static OMPToClause *CreateEmpty(const ASTContext &C, unsigned NumVars, 4608 unsigned NumUniqueDeclarations, 4609 unsigned NumComponentLists, 4610 unsigned NumComponents); 4611 4612 child_range children() { 4613 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 4614 reinterpret_cast<Stmt **>(varlist_end())); 4615 } 4616 4617 static bool classof(const OMPClause *T) { 4618 return T->getClauseKind() == OMPC_to; 4619 } 4620}; 4621 4622/// \brief This represents clause 'from' in the '#pragma omp ...' 4623/// directives. 4624/// 4625/// \code 4626/// #pragma omp target update from(a,b) 4627/// \endcode 4628/// In this example directive '#pragma omp target update' has clause 'from' 4629/// with the variables 'a' and 'b'. 4630class OMPFromClause final 4631 : public OMPMappableExprListClause<OMPFromClause>, 4632 private llvm::TrailingObjects< 4633 OMPFromClause, Expr *, ValueDecl *, unsigned, 4634 OMPClauseMappableExprCommon::MappableComponent> { 4635 friend class OMPClauseReader; 4636 friend OMPMappableExprListClause; 4637 friend OMPVarListClause; 4638 friend TrailingObjects; 4639 4640 /// \brief Build clause with number of variables \a NumVars. 4641 /// 4642 /// \param StartLoc Starting location of the clause. 4643 /// \param EndLoc Ending location of the clause. 4644 /// \param NumVars Number of expressions listed in this clause. 4645 /// \param NumUniqueDeclarations Number of unique base declarations in this 4646 /// clause. 4647 /// \param NumComponentLists Number of component lists in this clause. 4648 /// \param NumComponents Total number of expression components in the clause. 4649 explicit OMPFromClause(SourceLocation StartLoc, SourceLocation LParenLoc, 4650 SourceLocation EndLoc, unsigned NumVars, 4651 unsigned NumUniqueDeclarations, 4652 unsigned NumComponentLists, unsigned NumComponents) 4653 : OMPMappableExprListClause(OMPC_from, StartLoc, LParenLoc, EndLoc, 4654 NumVars, NumUniqueDeclarations, 4655 NumComponentLists, NumComponents) {} 4656 4657 /// \brief Build an empty clause. 4658 /// 4659 /// \param NumVars Number of expressions listed in this clause. 4660 /// \param NumUniqueDeclarations Number of unique base declarations in this 4661 /// clause. 4662 /// \param NumComponentLists Number of component lists in this clause. 4663 /// \param NumComponents Total number of expression components in the clause. 4664 explicit OMPFromClause(unsigned NumVars, unsigned NumUniqueDeclarations, 4665 unsigned NumComponentLists, unsigned NumComponents) 4666 : OMPMappableExprListClause( 4667 OMPC_from, SourceLocation(), SourceLocation(), SourceLocation(), 4668 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {} 4669 4670 /// Define the sizes of each trailing object array except the last one. This 4671 /// is required for TrailingObjects to work properly. 4672 size_t numTrailingObjects(OverloadToken<Expr *>) const { 4673 return varlist_size(); 4674 } 4675 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { 4676 return getUniqueDeclarationsNum(); 4677 } 4678 size_t numTrailingObjects(OverloadToken<unsigned>) const { 4679 return getUniqueDeclarationsNum() + getTotalComponentListNum(); 4680 } 4681 4682public: 4683 /// \brief Creates clause with a list of variables \a Vars. 4684 /// 4685 /// \param C AST context. 4686 /// \param StartLoc Starting location of the clause. 4687 /// \param EndLoc Ending location of the clause. 4688 /// \param Vars The original expression used in the clause. 4689 /// \param Declarations Declarations used in the clause. 4690 /// \param ComponentLists Component lists used in the clause. 4691 static OMPFromClause *Create(const ASTContext &C, SourceLocation StartLoc, 4692 SourceLocation LParenLoc, SourceLocation EndLoc, 4693 ArrayRef<Expr *> Vars, 4694 ArrayRef<ValueDecl *> Declarations, 4695 MappableExprComponentListsRef ComponentLists); 4696 4697 /// \brief Creates an empty clause with the place for \a NumVars variables. 4698 /// 4699 /// \param C AST context. 4700 /// \param NumVars Number of expressions listed in the clause. 4701 /// \param NumUniqueDeclarations Number of unique base declarations in this 4702 /// clause. 4703 /// \param NumComponentLists Number of unique base declarations in this 4704 /// clause. 4705 /// \param NumComponents Total number of expression components in the clause. 4706 static OMPFromClause *CreateEmpty(const ASTContext &C, unsigned NumVars, 4707 unsigned NumUniqueDeclarations, 4708 unsigned NumComponentLists, 4709 unsigned NumComponents); 4710 4711 child_range children() { 4712 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 4713 reinterpret_cast<Stmt **>(varlist_end())); 4714 } 4715 4716 static bool classof(const OMPClause *T) { 4717 return T->getClauseKind() == OMPC_from; 4718 } 4719}; 4720 4721/// This represents clause 'use_device_ptr' in the '#pragma omp ...' 4722/// directives. 4723/// 4724/// \code 4725/// #pragma omp target data use_device_ptr(a,b) 4726/// \endcode 4727/// In this example directive '#pragma omp target data' has clause 4728/// 'use_device_ptr' with the variables 'a' and 'b'. 4729class OMPUseDevicePtrClause final 4730 : public OMPMappableExprListClause<OMPUseDevicePtrClause>, 4731 private llvm::TrailingObjects< 4732 OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned, 4733 OMPClauseMappableExprCommon::MappableComponent> { 4734 friend class OMPClauseReader; 4735 friend OMPMappableExprListClause; 4736 friend OMPVarListClause; 4737 friend TrailingObjects; 4738 4739 /// Build clause with number of variables \a NumVars. 4740 /// 4741 /// \param StartLoc Starting location of the clause. 4742 /// \param EndLoc Ending location of the clause. 4743 /// \param NumVars Number of expressions listed in this clause. 4744 /// \param NumUniqueDeclarations Number of unique base declarations in this 4745 /// clause. 4746 /// \param NumComponentLists Number of component lists in this clause. 4747 /// \param NumComponents Total number of expression components in the clause. 4748 explicit OMPUseDevicePtrClause(SourceLocation StartLoc, 4749 SourceLocation LParenLoc, 4750 SourceLocation EndLoc, unsigned NumVars, 4751 unsigned NumUniqueDeclarations, 4752 unsigned NumComponentLists, 4753 unsigned NumComponents) 4754 : OMPMappableExprListClause(OMPC_use_device_ptr, StartLoc, LParenLoc, 4755 EndLoc, NumVars, NumUniqueDeclarations, 4756 NumComponentLists, NumComponents) {} 4757 4758 /// Build an empty clause. 4759 /// 4760 /// \param NumVars Number of expressions listed in this clause. 4761 /// \param NumUniqueDeclarations Number of unique base declarations in this 4762 /// clause. 4763 /// \param NumComponentLists Number of component lists in this clause. 4764 /// \param NumComponents Total number of expression components in the clause. 4765 explicit OMPUseDevicePtrClause(unsigned NumVars, 4766 unsigned NumUniqueDeclarations, 4767 unsigned NumComponentLists, 4768 unsigned NumComponents) 4769 : OMPMappableExprListClause(OMPC_use_device_ptr, SourceLocation(), 4770 SourceLocation(), SourceLocation(), NumVars, 4771 NumUniqueDeclarations, NumComponentLists, 4772 NumComponents) {} 4773 4774 /// Define the sizes of each trailing object array except the last one. This 4775 /// is required for TrailingObjects to work properly. 4776 size_t numTrailingObjects(OverloadToken<Expr *>) const { 4777 return 3 * varlist_size(); 4778 } 4779 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { 4780 return getUniqueDeclarationsNum(); 4781 } 4782 size_t numTrailingObjects(OverloadToken<unsigned>) const { 4783 return getUniqueDeclarationsNum() + getTotalComponentListNum(); 4784 } 4785 4786 /// Sets the list of references to private copies with initializers for new 4787 /// private variables. 4788 /// \param VL List of references. 4789 void setPrivateCopies(ArrayRef<Expr *> VL); 4790 4791 /// Gets the list of references to private copies with initializers for new 4792 /// private variables. 4793 MutableArrayRef<Expr *> getPrivateCopies() { 4794 return MutableArrayRef<Expr *>(varlist_end(), varlist_size()); 4795 } 4796 ArrayRef<const Expr *> getPrivateCopies() const { 4797 return llvm::makeArrayRef(varlist_end(), varlist_size()); 4798 } 4799 4800 /// Sets the list of references to initializer variables for new private 4801 /// variables. 4802 /// \param VL List of references. 4803 void setInits(ArrayRef<Expr *> VL); 4804 4805 /// Gets the list of references to initializer variables for new private 4806 /// variables. 4807 MutableArrayRef<Expr *> getInits() { 4808 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size()); 4809 } 4810 ArrayRef<const Expr *> getInits() const { 4811 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size()); 4812 } 4813 4814public: 4815 /// Creates clause with a list of variables \a Vars. 4816 /// 4817 /// \param C AST context. 4818 /// \param StartLoc Starting location of the clause. 4819 /// \param EndLoc Ending location of the clause. 4820 /// \param Vars The original expression used in the clause. 4821 /// \param PrivateVars Expressions referring to private copies. 4822 /// \param Inits Expressions referring to private copy initializers. 4823 /// \param Declarations Declarations used in the clause. 4824 /// \param ComponentLists Component lists used in the clause. 4825 static OMPUseDevicePtrClause * 4826 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 4827 SourceLocation EndLoc, ArrayRef<Expr *> Vars, 4828 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits, 4829 ArrayRef<ValueDecl *> Declarations, 4830 MappableExprComponentListsRef ComponentLists); 4831 4832 /// Creates an empty clause with the place for \a NumVars variables. 4833 /// 4834 /// \param C AST context. 4835 /// \param NumVars Number of expressions listed in the clause. 4836 /// \param NumUniqueDeclarations Number of unique base declarations in this 4837 /// clause. 4838 /// \param NumComponentLists Number of unique base declarations in this 4839 /// clause. 4840 /// \param NumComponents Total number of expression components in the clause. 4841 static OMPUseDevicePtrClause *CreateEmpty(const ASTContext &C, 4842 unsigned NumVars, 4843 unsigned NumUniqueDeclarations, 4844 unsigned NumComponentLists, 4845 unsigned NumComponents); 4846 4847 using private_copies_iterator = MutableArrayRef<Expr *>::iterator; 4848 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator; 4849 using private_copies_range = llvm::iterator_range<private_copies_iterator>; 4850 using private_copies_const_range = 4851 llvm::iterator_range<private_copies_const_iterator>; 4852 4853 private_copies_range private_copies() { 4854 return private_copies_range(getPrivateCopies().begin(), 4855 getPrivateCopies().end()); 4856 } 4857 4858 private_copies_const_range private_copies() const { 4859 return private_copies_const_range(getPrivateCopies().begin(), 4860 getPrivateCopies().end()); 4861 } 4862 4863 using inits_iterator = MutableArrayRef<Expr *>::iterator; 4864 using inits_const_iterator = ArrayRef<const Expr *>::iterator; 4865 using inits_range = llvm::iterator_range<inits_iterator>; 4866 using inits_const_range = llvm::iterator_range<inits_const_iterator>; 4867 4868 inits_range inits() { 4869 return inits_range(getInits().begin(), getInits().end()); 4870 } 4871 4872 inits_const_range inits() const { 4873 return inits_const_range(getInits().begin(), getInits().end()); 4874 } 4875 4876 child_range children() { 4877 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 4878 reinterpret_cast<Stmt **>(varlist_end())); 4879 } 4880 4881 static bool classof(const OMPClause *T) { 4882 return T->getClauseKind() == OMPC_use_device_ptr; 4883 } 4884}; 4885 4886/// This represents clause 'is_device_ptr' in the '#pragma omp ...' 4887/// directives. 4888/// 4889/// \code 4890/// #pragma omp target is_device_ptr(a,b) 4891/// \endcode 4892/// In this example directive '#pragma omp target' has clause 4893/// 'is_device_ptr' with the variables 'a' and 'b'. 4894class OMPIsDevicePtrClause final 4895 : public OMPMappableExprListClause<OMPIsDevicePtrClause>, 4896 private llvm::TrailingObjects< 4897 OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned, 4898 OMPClauseMappableExprCommon::MappableComponent> { 4899 friend class OMPClauseReader; 4900 friend OMPMappableExprListClause; 4901 friend OMPVarListClause; 4902 friend TrailingObjects; 4903 4904 /// Build clause with number of variables \a NumVars. 4905 /// 4906 /// \param StartLoc Starting location of the clause. 4907 /// \param EndLoc Ending location of the clause. 4908 /// \param NumVars Number of expressions listed in this clause. 4909 /// \param NumUniqueDeclarations Number of unique base declarations in this 4910 /// clause. 4911 /// \param NumComponentLists Number of component lists in this clause. 4912 /// \param NumComponents Total number of expression components in the clause. 4913 explicit OMPIsDevicePtrClause(SourceLocation StartLoc, 4914 SourceLocation LParenLoc, SourceLocation EndLoc, 4915 unsigned NumVars, 4916 unsigned NumUniqueDeclarations, 4917 unsigned NumComponentLists, 4918 unsigned NumComponents) 4919 : OMPMappableExprListClause(OMPC_is_device_ptr, StartLoc, LParenLoc, 4920 EndLoc, NumVars, NumUniqueDeclarations, 4921 NumComponentLists, NumComponents) {} 4922 4923 /// Build an empty clause. 4924 /// 4925 /// \param NumVars Number of expressions listed in this clause. 4926 /// \param NumUniqueDeclarations Number of unique base declarations in this 4927 /// clause. 4928 /// \param NumComponentLists Number of component lists in this clause. 4929 /// \param NumComponents Total number of expression components in the clause. 4930 explicit OMPIsDevicePtrClause(unsigned NumVars, 4931 unsigned NumUniqueDeclarations, 4932 unsigned NumComponentLists, 4933 unsigned NumComponents) 4934 : OMPMappableExprListClause(OMPC_is_device_ptr, SourceLocation(), 4935 SourceLocation(), SourceLocation(), NumVars, 4936 NumUniqueDeclarations, NumComponentLists, 4937 NumComponents) {} 4938 4939 /// Define the sizes of each trailing object array except the last one. This 4940 /// is required for TrailingObjects to work properly. 4941 size_t numTrailingObjects(OverloadToken<Expr *>) const { 4942 return varlist_size(); 4943 } 4944 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const { 4945 return getUniqueDeclarationsNum(); 4946 } 4947 size_t numTrailingObjects(OverloadToken<unsigned>) const { 4948 return getUniqueDeclarationsNum() + getTotalComponentListNum(); 4949 } 4950 4951public: 4952 /// Creates clause with a list of variables \a Vars. 4953 /// 4954 /// \param C AST context. 4955 /// \param StartLoc Starting location of the clause. 4956 /// \param EndLoc Ending location of the clause. 4957 /// \param Vars The original expression used in the clause. 4958 /// \param Declarations Declarations used in the clause. 4959 /// \param ComponentLists Component lists used in the clause. 4960 static OMPIsDevicePtrClause * 4961 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 4962 SourceLocation EndLoc, ArrayRef<Expr *> Vars, 4963 ArrayRef<ValueDecl *> Declarations, 4964 MappableExprComponentListsRef ComponentLists); 4965 4966 /// Creates an empty clause with the place for \a NumVars variables. 4967 /// 4968 /// \param C AST context. 4969 /// \param NumVars Number of expressions listed in the clause. 4970 /// \param NumUniqueDeclarations Number of unique base declarations in this 4971 /// clause. 4972 /// \param NumComponentLists Number of unique base declarations in this 4973 /// clause. 4974 /// \param NumComponents Total number of expression components in the clause. 4975 static OMPIsDevicePtrClause *CreateEmpty(const ASTContext &C, 4976 unsigned NumVars, 4977 unsigned NumUniqueDeclarations, 4978 unsigned NumComponentLists, 4979 unsigned NumComponents); 4980 4981 child_range children() { 4982 return child_range(reinterpret_cast<Stmt **>(varlist_begin()), 4983 reinterpret_cast<Stmt **>(varlist_end())); 4984 } 4985 4986 static bool classof(const OMPClause *T) { 4987 return T->getClauseKind() == OMPC_is_device_ptr; 4988 } 4989}; 4990 4991} // namespace clang 4992 4993#endif // LLVM_CLANG_AST_OPENMPCLAUSE_H 4994