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