Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:37

0001 //===--- ExprOpenMP.h - Classes for representing expressions ----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines the Expr interface and subclasses.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_AST_EXPROPENMP_H
0014 #define LLVM_CLANG_AST_EXPROPENMP_H
0015 
0016 #include "clang/AST/ComputeDependence.h"
0017 #include "clang/AST/Expr.h"
0018 
0019 namespace clang {
0020 /// An explicit cast in C or a C-style cast in C++, which uses the syntax
0021 /// ([s1][s2]...[sn])expr. For example: @c ([3][3])f.
0022 class OMPArrayShapingExpr final
0023     : public Expr,
0024       private llvm::TrailingObjects<OMPArrayShapingExpr, Expr *, SourceRange> {
0025   friend TrailingObjects;
0026   friend class ASTStmtReader;
0027   friend class ASTStmtWriter;
0028   /// Base node.
0029   SourceLocation LPLoc; /// The location of the left paren
0030   SourceLocation RPLoc; /// The location of the right paren
0031   unsigned NumDims = 0; /// Number of dimensions in the shaping expression.
0032 
0033   /// Construct full expression.
0034   OMPArrayShapingExpr(QualType ExprTy, Expr *Op, SourceLocation L,
0035                       SourceLocation R, ArrayRef<Expr *> Dims);
0036 
0037   /// Construct an empty expression.
0038   explicit OMPArrayShapingExpr(EmptyShell Shell, unsigned NumDims)
0039       : Expr(OMPArrayShapingExprClass, Shell), NumDims(NumDims) {}
0040 
0041   /// Sets the dimensions for the array shaping.
0042   void setDimensions(ArrayRef<Expr *> Dims);
0043 
0044   /// Sets the base expression for array shaping operation.
0045   void setBase(Expr *Op) { getTrailingObjects<Expr *>()[NumDims] = Op; }
0046 
0047   /// Sets source ranges for the brackets in the array shaping operation.
0048   void setBracketsRanges(ArrayRef<SourceRange> BR);
0049 
0050   unsigned numTrailingObjects(OverloadToken<Expr *>) const {
0051     // Add an extra one for the base expression.
0052     return NumDims + 1;
0053   }
0054 
0055   unsigned numTrailingObjects(OverloadToken<SourceRange>) const {
0056     return NumDims;
0057   }
0058 
0059 public:
0060   static OMPArrayShapingExpr *Create(const ASTContext &Context, QualType T,
0061                                      Expr *Op, SourceLocation L,
0062                                      SourceLocation R, ArrayRef<Expr *> Dims,
0063                                      ArrayRef<SourceRange> BracketRanges);
0064 
0065   static OMPArrayShapingExpr *CreateEmpty(const ASTContext &Context,
0066                                           unsigned NumDims);
0067 
0068   SourceLocation getLParenLoc() const { return LPLoc; }
0069   void setLParenLoc(SourceLocation L) { LPLoc = L; }
0070 
0071   SourceLocation getRParenLoc() const { return RPLoc; }
0072   void setRParenLoc(SourceLocation L) { RPLoc = L; }
0073 
0074   SourceLocation getBeginLoc() const LLVM_READONLY { return LPLoc; }
0075   SourceLocation getEndLoc() const LLVM_READONLY {
0076     return getBase()->getEndLoc();
0077   }
0078 
0079   /// Fetches the dimensions for array shaping expression.
0080   ArrayRef<Expr *> getDimensions() const {
0081     return llvm::ArrayRef(getTrailingObjects<Expr *>(), NumDims);
0082   }
0083 
0084   /// Fetches source ranges for the brackets os the array shaping expression.
0085   ArrayRef<SourceRange> getBracketsRanges() const {
0086     return llvm::ArrayRef(getTrailingObjects<SourceRange>(), NumDims);
0087   }
0088 
0089   /// Fetches base expression of array shaping expression.
0090   Expr *getBase() { return getTrailingObjects<Expr *>()[NumDims]; }
0091   const Expr *getBase() const { return getTrailingObjects<Expr *>()[NumDims]; }
0092 
0093   static bool classof(const Stmt *T) {
0094     return T->getStmtClass() == OMPArrayShapingExprClass;
0095   }
0096 
0097   // Iterators
0098   child_range children() {
0099     Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
0100     return child_range(Begin, Begin + NumDims + 1);
0101   }
0102   const_child_range children() const {
0103     Stmt *const *Begin =
0104         reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
0105     return const_child_range(Begin, Begin + NumDims + 1);
0106   }
0107 };
0108 
0109 /// Helper expressions and declaration for OMPIteratorExpr class for each
0110 /// iteration space.
0111 struct OMPIteratorHelperData {
0112   /// Internal normalized counter.
0113   VarDecl *CounterVD = nullptr;
0114   /// Normalized upper bound. Normalized loop iterates from 0 to Upper with
0115   /// step 1.
0116   Expr *Upper = nullptr;
0117   /// Update expression for the originally specified iteration variable,
0118   /// calculated as VD = Begin + CounterVD * Step;
0119   Expr *Update = nullptr;
0120   /// Updater for the internal counter: ++CounterVD;
0121   Expr *CounterUpdate = nullptr;
0122 };
0123 
0124 /// OpenMP 5.0 [2.1.6 Iterators]
0125 /// Iterators are identifiers that expand to multiple values in the clause on
0126 /// which they appear.
0127 /// The syntax of the iterator modifier is as follows:
0128 /// \code
0129 /// iterator(iterators-definition)
0130 /// \endcode
0131 /// where iterators-definition is one of the following:
0132 /// \code
0133 /// iterator-specifier [, iterators-definition ]
0134 /// \endcode
0135 /// where iterator-specifier is one of the following:
0136 /// \code
0137 /// [ iterator-type ] identifier = range-specification
0138 /// \endcode
0139 /// where identifier is a base language identifier.
0140 /// iterator-type is a type name.
0141 /// range-specification is of the form begin:end[:step], where begin and end are
0142 /// expressions for which their types can be converted to iterator-type and step
0143 /// is an integral expression.
0144 /// In an iterator-specifier, if the iterator-type is not specified then the
0145 /// type of that iterator is of int type.
0146 /// The iterator-type must be an integral or pointer type.
0147 /// The iterator-type must not be const qualified.
0148 class OMPIteratorExpr final
0149     : public Expr,
0150       private llvm::TrailingObjects<OMPIteratorExpr, Decl *, Expr *,
0151                                     SourceLocation, OMPIteratorHelperData> {
0152 public:
0153   /// Iterator range representation begin:end[:step].
0154   struct IteratorRange {
0155     Expr *Begin = nullptr;
0156     Expr *End = nullptr;
0157     Expr *Step = nullptr;
0158   };
0159   /// Iterator definition representation.
0160   struct IteratorDefinition {
0161     Decl *IteratorDecl = nullptr;
0162     IteratorRange Range;
0163     SourceLocation AssignmentLoc;
0164     SourceLocation ColonLoc, SecondColonLoc;
0165   };
0166 
0167 private:
0168   friend TrailingObjects;
0169   friend class ASTStmtReader;
0170   friend class ASTStmtWriter;
0171 
0172   /// Offset in the list of expressions for subelements of the ranges.
0173   enum class RangeExprOffset {
0174     Begin = 0,
0175     End = 1,
0176     Step = 2,
0177     Total = 3,
0178   };
0179   /// Offset in the list of locations for subelements of colon symbols
0180   /// locations.
0181   enum class RangeLocOffset {
0182     AssignLoc = 0,
0183     FirstColonLoc = 1,
0184     SecondColonLoc = 2,
0185     Total = 3,
0186   };
0187   /// Location of 'iterator' keyword.
0188   SourceLocation IteratorKwLoc;
0189   /// Location of '('.
0190   SourceLocation LPLoc;
0191   /// Location of ')'.
0192   SourceLocation RPLoc;
0193   /// Number of iterator definitions.
0194   unsigned NumIterators = 0;
0195 
0196   OMPIteratorExpr(QualType ExprTy, SourceLocation IteratorKwLoc,
0197                   SourceLocation L, SourceLocation R,
0198                   ArrayRef<IteratorDefinition> Data,
0199                   ArrayRef<OMPIteratorHelperData> Helpers);
0200 
0201   /// Construct an empty expression.
0202   explicit OMPIteratorExpr(EmptyShell Shell, unsigned NumIterators)
0203       : Expr(OMPIteratorExprClass, Shell), NumIterators(NumIterators) {}
0204 
0205   /// Sets basic declaration for the specified iterator definition.
0206   void setIteratorDeclaration(unsigned I, Decl *D);
0207 
0208   /// Sets the location of the assignment symbol for the specified iterator
0209   /// definition.
0210   void setAssignmentLoc(unsigned I, SourceLocation Loc);
0211 
0212   /// Sets begin, end and optional step expressions for specified iterator
0213   /// definition.
0214   void setIteratorRange(unsigned I, Expr *Begin, SourceLocation ColonLoc,
0215                         Expr *End, SourceLocation SecondColonLoc, Expr *Step);
0216 
0217   /// Sets helpers for the specified iteration space.
0218   void setHelper(unsigned I, const OMPIteratorHelperData &D);
0219 
0220   unsigned numTrailingObjects(OverloadToken<Decl *>) const {
0221     return NumIterators;
0222   }
0223 
0224   unsigned numTrailingObjects(OverloadToken<Expr *>) const {
0225     return NumIterators * static_cast<int>(RangeExprOffset::Total);
0226   }
0227 
0228   unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
0229     return NumIterators * static_cast<int>(RangeLocOffset::Total);
0230   }
0231 
0232 public:
0233   static OMPIteratorExpr *Create(const ASTContext &Context, QualType T,
0234                                  SourceLocation IteratorKwLoc, SourceLocation L,
0235                                  SourceLocation R,
0236                                  ArrayRef<IteratorDefinition> Data,
0237                                  ArrayRef<OMPIteratorHelperData> Helpers);
0238 
0239   static OMPIteratorExpr *CreateEmpty(const ASTContext &Context,
0240                                       unsigned NumIterators);
0241 
0242   SourceLocation getLParenLoc() const { return LPLoc; }
0243   void setLParenLoc(SourceLocation L) { LPLoc = L; }
0244 
0245   SourceLocation getRParenLoc() const { return RPLoc; }
0246   void setRParenLoc(SourceLocation L) { RPLoc = L; }
0247 
0248   SourceLocation getIteratorKwLoc() const { return IteratorKwLoc; }
0249   void setIteratorKwLoc(SourceLocation L) { IteratorKwLoc = L; }
0250   SourceLocation getBeginLoc() const LLVM_READONLY { return IteratorKwLoc; }
0251   SourceLocation getEndLoc() const LLVM_READONLY { return RPLoc; }
0252 
0253   /// Gets the iterator declaration for the given iterator.
0254   Decl *getIteratorDecl(unsigned I);
0255   const Decl *getIteratorDecl(unsigned I) const {
0256     return const_cast<OMPIteratorExpr *>(this)->getIteratorDecl(I);
0257   }
0258 
0259   /// Gets the iterator range for the given iterator.
0260   IteratorRange getIteratorRange(unsigned I);
0261   const IteratorRange getIteratorRange(unsigned I) const {
0262     return const_cast<OMPIteratorExpr *>(this)->getIteratorRange(I);
0263   }
0264 
0265   /// Gets the location of '=' for the given iterator definition.
0266   SourceLocation getAssignLoc(unsigned I) const;
0267   /// Gets the location of the first ':' in the range for the given iterator
0268   /// definition.
0269   SourceLocation getColonLoc(unsigned I) const;
0270   /// Gets the location of the second ':' (if any) in the range for the given
0271   /// iteratori definition.
0272   SourceLocation getSecondColonLoc(unsigned I) const;
0273 
0274   /// Returns number of iterator definitions.
0275   unsigned numOfIterators() const { return NumIterators; }
0276 
0277   /// Fetches helper data for the specified iteration space.
0278   OMPIteratorHelperData &getHelper(unsigned I);
0279   const OMPIteratorHelperData &getHelper(unsigned I) const;
0280 
0281   static bool classof(const Stmt *T) {
0282     return T->getStmtClass() == OMPIteratorExprClass;
0283   }
0284 
0285   // Iterators
0286   child_range children() {
0287     Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
0288     return child_range(
0289         Begin, Begin + NumIterators * static_cast<int>(RangeExprOffset::Total));
0290   }
0291   const_child_range children() const {
0292     Stmt *const *Begin =
0293         reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
0294     return const_child_range(
0295         Begin, Begin + NumIterators * static_cast<int>(RangeExprOffset::Total));
0296   }
0297 };
0298 
0299 } // end namespace clang
0300 
0301 #endif