clang  8.0.0svn
DeclOpenMP.h
Go to the documentation of this file.
1 //===- DeclOpenMP.h - Classes for representing OpenMP directives -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file defines OpenMP nodes for declarative directives.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_AST_DECLOPENMP_H
16 #define LLVM_CLANG_AST_DECLOPENMP_H
17 
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/Expr.h"
21 #include "clang/AST/Type.h"
22 #include "llvm/ADT/ArrayRef.h"
23 #include "llvm/Support/TrailingObjects.h"
24 
25 namespace clang {
26 
27 /// This represents '#pragma omp threadprivate ...' directive.
28 /// For example, in the following, both 'a' and 'A::b' are threadprivate:
29 ///
30 /// \code
31 /// int a;
32 /// #pragma omp threadprivate(a)
33 /// struct A {
34 /// static int b;
35 /// #pragma omp threadprivate(b)
36 /// };
37 /// \endcode
38 ///
40  : public Decl,
41  private llvm::TrailingObjects<OMPThreadPrivateDecl, Expr *> {
42  friend class ASTDeclReader;
43  friend TrailingObjects;
44 
45  unsigned NumVars;
46 
47  virtual void anchor();
48 
50  Decl(DK, DC, L), NumVars(0) { }
51 
52  ArrayRef<const Expr *> getVars() const {
53  return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumVars);
54  }
55 
56  MutableArrayRef<Expr *> getVars() {
57  return MutableArrayRef<Expr *>(getTrailingObjects<Expr *>(), NumVars);
58  }
59 
60  void setVars(ArrayRef<Expr *> VL);
61 
62 public:
65  ArrayRef<Expr *> VL);
67  unsigned ID, unsigned N);
68 
71  typedef llvm::iterator_range<varlist_iterator> varlist_range;
72  typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
73 
74  unsigned varlist_size() const { return NumVars; }
75  bool varlist_empty() const { return NumVars == 0; }
76 
77  varlist_range varlists() {
79  }
80  varlist_const_range varlists() const {
82  }
83  varlist_iterator varlist_begin() { return getVars().begin(); }
84  varlist_iterator varlist_end() { return getVars().end(); }
85  varlist_const_iterator varlist_begin() const { return getVars().begin(); }
86  varlist_const_iterator varlist_end() const { return getVars().end(); }
87 
88  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
89  static bool classofKind(Kind K) { return K == OMPThreadPrivate; }
90 };
91 
92 /// This represents '#pragma omp declare reduction ...' directive.
93 /// For example, in the following, declared reduction 'foo' for types 'int' and
94 /// 'float':
95 ///
96 /// \code
97 /// #pragma omp declare reduction (foo : int,float : omp_out += omp_in) \
98 /// initializer (omp_priv = 0)
99 /// \endcode
100 ///
101 /// Here 'omp_out += omp_in' is a combiner and 'omp_priv = 0' is an initializer.
102 class OMPDeclareReductionDecl final : public ValueDecl, public DeclContext {
103  // This class stores some data in DeclContext::OMPDeclareReductionDeclBits
104  // to save some space. Use the provided accessors to access it.
105 public:
106  enum InitKind {
107  CallInit, // Initialized by function call.
108  DirectInit, // omp_priv(<expr>)
109  CopyInit // omp_priv = <expr>
110  };
111 
112 private:
113  friend class ASTDeclReader;
114  /// Combiner for declare reduction construct.
115  Expr *Combiner;
116  /// Initializer for declare reduction construct.
117  Expr *Initializer;
118 
119  /// Reference to the previous declare reduction construct in the same
120  /// scope with the same name. Required for proper templates instantiation if
121  /// the declare reduction construct is declared inside compound statement.
122  LazyDeclPtr PrevDeclInScope;
123 
124  virtual void anchor();
125 
127  DeclarationName Name, QualType Ty,
128  OMPDeclareReductionDecl *PrevDeclInScope);
129 
130  void setPrevDeclInScope(OMPDeclareReductionDecl *Prev) {
131  PrevDeclInScope = Prev;
132  }
133 
134 public:
135  /// Create declare reduction node.
136  static OMPDeclareReductionDecl *
138  QualType T, OMPDeclareReductionDecl *PrevDeclInScope);
139  /// Create deserialized declare reduction node.
141  unsigned ID);
142 
143  /// Get combiner expression of the declare reduction construct.
144  Expr *getCombiner() { return Combiner; }
145  const Expr *getCombiner() const { return Combiner; }
146  /// Set combiner expression for the declare reduction construct.
147  void setCombiner(Expr *E) { Combiner = E; }
148 
149  /// Get initializer expression (if specified) of the declare reduction
150  /// construct.
151  Expr *getInitializer() { return Initializer; }
152  const Expr *getInitializer() const { return Initializer; }
153  /// Get initializer kind.
155  return static_cast<InitKind>(OMPDeclareReductionDeclBits.InitializerKind);
156  }
157  /// Set initializer expression for the declare reduction construct.
158  void setInitializer(Expr *E, InitKind IK) {
159  Initializer = E;
160  OMPDeclareReductionDeclBits.InitializerKind = IK;
161  }
162 
163  /// Get reference to previous declare reduction construct in the same
164  /// scope with the same name.
165  OMPDeclareReductionDecl *getPrevDeclInScope();
166  const OMPDeclareReductionDecl *getPrevDeclInScope() const;
167 
168  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
169  static bool classofKind(Kind K) { return K == OMPDeclareReduction; }
171  return static_cast<DeclContext *>(const_cast<OMPDeclareReductionDecl *>(D));
172  }
174  return static_cast<OMPDeclareReductionDecl *>(
175  const_cast<DeclContext *>(DC));
176  }
177 };
178 
179 /// Pseudo declaration for capturing expressions. Also is used for capturing of
180 /// non-static data members in non-static member functions.
181 ///
182 /// Clang supports capturing of variables only, but OpenMP 4.5 allows to
183 /// privatize non-static members of current class in non-static member
184 /// functions. This pseudo-declaration allows properly handle this kind of
185 /// capture by wrapping captured expression into a variable-like declaration.
186 class OMPCapturedExprDecl final : public VarDecl {
187  friend class ASTDeclReader;
188  void anchor() override;
189 
191  QualType Type, TypeSourceInfo *TInfo,
192  SourceLocation StartLoc)
193  : VarDecl(OMPCapturedExpr, C, DC, StartLoc, StartLoc, Id, Type, TInfo,
194  SC_None) {
195  setImplicit();
196  }
197 
198 public:
201  SourceLocation StartLoc);
202 
204 
205  SourceRange getSourceRange() const override LLVM_READONLY;
206 
207  // Implement isa/cast/dyncast/etc.
208  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
209  static bool classofKind(Kind K) { return K == OMPCapturedExpr; }
210 };
211 
212 } // end namespace clang
213 
214 #endif
void setImplicit(bool I=true)
Definition: DeclBase.h:561
const Expr * getCombiner() const
Definition: DeclOpenMP.h:145
A (possibly-)qualified type.
Definition: Type.h:640
C Language Family Type Representation.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
The base class of the type hierarchy.
Definition: Type.h:1413
static OMPDeclareReductionDecl * castFromDeclContext(const DeclContext *DC)
Definition: DeclOpenMP.h:173
A container of type source information.
Definition: Decl.h:86
llvm::iterator_range< varlist_const_iterator > varlist_const_range
Definition: DeclOpenMP.h:72
Represents a variable declaration or definition.
Definition: Decl.h:820
static bool classofKind(Kind K)
Definition: DeclOpenMP.h:169
static bool classof(const Decl *D)
Definition: DeclOpenMP.h:168
One of these records is kept for each identifier that is lexed.
static OMPThreadPrivateDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned N)
Definition: DeclOpenMP.cpp:41
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:153
varlist_const_range varlists() const
Definition: DeclOpenMP.h:80
InitKind getInitializerKind() const
Get initializer kind.
Definition: DeclOpenMP.h:154
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition: DeclBase.h:405
static bool classof(const Decl *D)
Definition: DeclOpenMP.h:88
Expr * getInitializer()
Get initializer expression (if specified) of the declare reduction construct.
Definition: DeclOpenMP.h:151
varlist_const_iterator varlist_begin() const
Definition: DeclOpenMP.h:85
Expr * getCombiner()
Get combiner expression of the declare reduction construct.
Definition: DeclOpenMP.h:144
MutableArrayRef< Expr * >::iterator varlist_iterator
Definition: DeclOpenMP.h:69
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:640
Expr - This represents one expression.
Definition: Expr.h:106
int Id
Definition: ASTDiff.cpp:191
Encodes a location in the source.
This represents &#39;#pragma omp declare reduction ...&#39; directive.
Definition: DeclOpenMP.h:102
Pseudo declaration for capturing expressions.
Definition: DeclOpenMP.h:186
varlist_iterator varlist_begin()
Definition: DeclOpenMP.h:83
void setInitializer(Expr *E, InitKind IK)
Set initializer expression for the declare reduction construct.
Definition: DeclOpenMP.h:158
static bool classofKind(Kind K)
Definition: DeclOpenMP.h:209
static DeclContext * castToDeclContext(const OMPDeclareReductionDecl *D)
Definition: DeclOpenMP.h:170
bool varlist_empty() const
Definition: DeclOpenMP.h:75
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1272
static OMPThreadPrivateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< Expr *> VL)
Definition: DeclOpenMP.cpp:29
DeclarationName - The name of a declaration.
Kind getKind() const
Definition: DeclBase.h:428
varlist_const_iterator varlist_end() const
Definition: DeclOpenMP.h:86
static bool classofKind(Kind K)
Definition: DeclOpenMP.h:89
friend TrailingObjects
Definition: OpenMPClause.h:93
void setCombiner(Expr *E)
Set combiner expression for the declare reduction construct.
Definition: DeclOpenMP.h:147
const Expr * getInitializer() const
Definition: DeclOpenMP.h:152
varlist_iterator varlist_end()
Definition: DeclOpenMP.h:84
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:89
unsigned varlist_size() const
Definition: DeclOpenMP.h:74
varlist_range varlists()
Definition: DeclOpenMP.h:77
llvm::iterator_range< varlist_iterator > varlist_range
Definition: DeclOpenMP.h:71
A trivial tuple used to represent a source range.
ArrayRef< const Expr * >::iterator varlist_const_iterator
Definition: DeclOpenMP.h:70
This represents &#39;#pragma omp threadprivate ...&#39; directive.
Definition: DeclOpenMP.h:39