Coverage Report

Created: 2018-12-11 17:59

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/DeclOpenMP.h
Line
Count
Source (jump to first uncovered line)
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"
20
#include "clang/AST/ExternalASTSource.h"
21
#include "clang/AST/OpenMPClause.h"
22
#include "clang/AST/Type.h"
23
#include "llvm/ADT/ArrayRef.h"
24
#include "llvm/Support/TrailingObjects.h"
25
26
namespace clang {
27
28
/// This represents '#pragma omp threadprivate ...' directive.
29
/// For example, in the following, both 'a' and 'A::b' are threadprivate:
30
///
31
/// \code
32
/// int a;
33
/// #pragma omp threadprivate(a)
34
/// struct A {
35
///   static int b;
36
/// #pragma omp threadprivate(b)
37
/// };
38
/// \endcode
39
///
40
class OMPThreadPrivateDecl final
41
    : public Decl,
42
      private llvm::TrailingObjects<OMPThreadPrivateDecl, Expr *> {
43
  friend class ASTDeclReader;
44
  friend TrailingObjects;
45
46
  unsigned NumVars;
47
48
  virtual void anchor();
49
50
  OMPThreadPrivateDecl(Kind DK, DeclContext *DC, SourceLocation L) :
51
1.77k
    Decl(DK, DC, L), NumVars(0) { }
52
53
102
  ArrayRef<const Expr *> getVars() const {
54
102
    return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumVars);
55
102
  }
56
57
1.64k
  MutableArrayRef<Expr *> getVars() {
58
1.64k
    return MutableArrayRef<Expr *>(getTrailingObjects<Expr *>(), NumVars);
59
1.64k
  }
60
61
  void setVars(ArrayRef<Expr *> VL);
62
63
public:
64
  static OMPThreadPrivateDecl *Create(ASTContext &C, DeclContext *DC,
65
                                      SourceLocation L,
66
                                      ArrayRef<Expr *> VL);
67
  static OMPThreadPrivateDecl *CreateDeserialized(ASTContext &C,
68
                                                  unsigned ID, unsigned N);
69
70
  typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
71
  typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
72
  typedef llvm::iterator_range<varlist_iterator> varlist_range;
73
  typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
74
75
378
  unsigned varlist_size() const { return NumVars; }
76
322
  bool varlist_empty() const { return NumVars == 0; }
77
78
337
  varlist_range varlists() {
79
337
    return varlist_range(varlist_begin(), varlist_end());
80
337
  }
81
51
  varlist_const_range varlists() const {
82
51
    return varlist_const_range(varlist_begin(), varlist_end());
83
51
  }
84
989
  varlist_iterator varlist_begin() { return getVars().begin(); }
85
659
  varlist_iterator varlist_end() { return getVars().end(); }
86
51
  varlist_const_iterator varlist_begin() const { return getVars().begin(); }
87
51
  varlist_const_iterator varlist_end() const { return getVars().end(); }
88
89
472k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
90
472k
  static bool classofKind(Kind K) { return K == OMPThreadPrivate; }
91
};
92
93
/// This represents '#pragma omp declare reduction ...' directive.
94
/// For example, in the following, declared reduction 'foo' for types 'int' and
95
/// 'float':
96
///
97
/// \code
98
/// #pragma omp declare reduction (foo : int,float : omp_out += omp_in) \
99
///                     initializer (omp_priv = 0)
100
/// \endcode
101
///
102
/// Here 'omp_out += omp_in' is a combiner and 'omp_priv = 0' is an initializer.
103
class OMPDeclareReductionDecl final : public ValueDecl, public DeclContext {
104
  // This class stores some data in DeclContext::OMPDeclareReductionDeclBits
105
  // to save some space. Use the provided accessors to access it.
106
public:
107
  enum InitKind {
108
    CallInit,   // Initialized by function call.
109
    DirectInit, // omp_priv(<expr>)
110
    CopyInit    // omp_priv = <expr>
111
  };
112
113
private:
114
  friend class ASTDeclReader;
115
  /// Combiner for declare reduction construct.
116
  Expr *Combiner = nullptr;
117
  /// Initializer for declare reduction construct.
118
  Expr *Initializer = nullptr;
119
  /// In parameter of the combiner.
120
  Expr *In = nullptr;
121
  /// Out parameter of the combiner.
122
  Expr *Out = nullptr;
123
  /// Priv parameter of the initializer.
124
  Expr *Priv = nullptr;
125
  /// Orig parameter of the initializer.
126
  Expr *Orig = nullptr;
127
128
  /// Reference to the previous declare reduction construct in the same
129
  /// scope with the same name. Required for proper templates instantiation if
130
  /// the declare reduction construct is declared inside compound statement.
131
  LazyDeclPtr PrevDeclInScope;
132
133
  virtual void anchor();
134
135
  OMPDeclareReductionDecl(Kind DK, DeclContext *DC, SourceLocation L,
136
                          DeclarationName Name, QualType Ty,
137
                          OMPDeclareReductionDecl *PrevDeclInScope);
138
139
0
  void setPrevDeclInScope(OMPDeclareReductionDecl *Prev) {
140
0
    PrevDeclInScope = Prev;
141
0
  }
142
143
public:
144
  /// Create declare reduction node.
145
  static OMPDeclareReductionDecl *
146
  Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
147
         QualType T, OMPDeclareReductionDecl *PrevDeclInScope);
148
  /// Create deserialized declare reduction node.
149
  static OMPDeclareReductionDecl *CreateDeserialized(ASTContext &C,
150
                                                     unsigned ID);
151
152
  /// Get combiner expression of the declare reduction construct.
153
392
  Expr *getCombiner() { return Combiner; }
154
103
  const Expr *getCombiner() const { return Combiner; }
155
  /// Get In variable of the combiner.
156
320
  Expr *getCombinerIn() { return In; }
157
91
  const Expr *getCombinerIn() const { return In; }
158
  /// Get Out variable of the combiner.
159
320
  Expr *getCombinerOut() { return Out; }
160
91
  const Expr *getCombinerOut() const { return Out; }
161
  /// Set combiner expression for the declare reduction construct.
162
688
  void setCombiner(Expr *E) { Combiner = E; }
163
  /// Set combiner In and Out vars.
164
744
  void setCombinerData(Expr *InE, Expr *OutE) {
165
744
    In = InE;
166
744
    Out = OutE;
167
744
  }
168
169
  /// Get initializer expression (if specified) of the declare reduction
170
  /// construct.
171
588
  Expr *getInitializer() { return Initializer; }
172
201
  const Expr *getInitializer() const { return Initializer; }
173
  /// Get initializer kind.
174
315
  InitKind getInitializerKind() const {
175
315
    return static_cast<InitKind>(OMPDeclareReductionDeclBits.InitializerKind);
176
315
  }
177
  /// Get Orig variable of the initializer.
178
174
  Expr *getInitOrig() { return Orig; }
179
51
  const Expr *getInitOrig() const { return Orig; }
180
  /// Get Priv variable of the initializer.
181
174
  Expr *getInitPriv() { return Priv; }
182
51
  const Expr *getInitPriv() const { return Priv; }
183
  /// Set initializer expression for the declare reduction construct.
184
1.04k
  void setInitializer(Expr *E, InitKind IK) {
185
1.04k
    Initializer = E;
186
1.04k
    OMPDeclareReductionDeclBits.InitializerKind = IK;
187
1.04k
  }
188
  /// Set initializer Orig and Priv vars.
189
338
  void setInitializerData(Expr *OrigE, Expr *PrivE) {
190
338
    Orig = OrigE;
191
338
    Priv = PrivE;
192
338
  }
193
194
  /// Get reference to previous declare reduction construct in the same
195
  /// scope with the same name.
196
  OMPDeclareReductionDecl *getPrevDeclInScope();
197
  const OMPDeclareReductionDecl *getPrevDeclInScope() const;
198
199
416k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
200
102M
  static bool classofKind(Kind K) { return K == OMPDeclareReduction; }
201
0
  static DeclContext *castToDeclContext(const OMPDeclareReductionDecl *D) {
202
0
    return static_cast<DeclContext *>(const_cast<OMPDeclareReductionDecl *>(D));
203
0
  }
204
0
  static OMPDeclareReductionDecl *castFromDeclContext(const DeclContext *DC) {
205
0
    return static_cast<OMPDeclareReductionDecl *>(
206
0
        const_cast<DeclContext *>(DC));
207
0
  }
208
};
209
210
/// Pseudo declaration for capturing expressions. Also is used for capturing of
211
/// non-static data members in non-static member functions.
212
///
213
/// Clang supports capturing of variables only, but OpenMP 4.5 allows to
214
/// privatize non-static members of current class in non-static member
215
/// functions. This pseudo-declaration allows properly handle this kind of
216
/// capture by wrapping captured expression into a variable-like declaration.
217
class OMPCapturedExprDecl final : public VarDecl {
218
  friend class ASTDeclReader;
219
  void anchor() override;
220
221
  OMPCapturedExprDecl(ASTContext &C, DeclContext *DC, IdentifierInfo *Id,
222
                      QualType Type, TypeSourceInfo *TInfo,
223
                      SourceLocation StartLoc)
224
      : VarDecl(OMPCapturedExpr, C, DC, StartLoc, StartLoc, Id, Type, TInfo,
225
37.7k
                SC_None) {
226
37.7k
    setImplicit();
227
37.7k
  }
228
229
public:
230
  static OMPCapturedExprDecl *Create(ASTContext &C, DeclContext *DC,
231
                                     IdentifierInfo *Id, QualType T,
232
                                     SourceLocation StartLoc);
233
234
  static OMPCapturedExprDecl *CreateDeserialized(ASTContext &C, unsigned ID);
235
236
  SourceRange getSourceRange() const override LLVM_READONLY;
237
238
  // Implement isa/cast/dyncast/etc.
239
6.92M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
240
6.92M
  static bool classofKind(Kind K) { return K == OMPCapturedExpr; }
241
};
242
243
/// This represents '#pragma omp requires...' directive.
244
/// For example
245
///
246
/// \code
247
/// #pragma omp requires unified_address
248
/// \endcode
249
///
250
class OMPRequiresDecl final
251
    : public Decl,
252
      private llvm::TrailingObjects<OMPRequiresDecl, OMPClause *> {
253
  friend class ASTDeclReader;
254
  friend TrailingObjects;
255
256
  // Number of clauses associated with this requires declaration
257
  unsigned NumClauses = 0;
258
259
  virtual void anchor();
260
261
  OMPRequiresDecl(Kind DK, DeclContext *DC, SourceLocation L)
262
63
      : Decl(DK, DC, L), NumClauses(0) {}
263
264
  /// Returns an array of immutable clauses associated with this requires
265
  /// declaration
266
276
  ArrayRef<const OMPClause *> getClauses() const {
267
276
    return llvm::makeArrayRef(getTrailingObjects<OMPClause *>(), NumClauses);
268
276
  }
269
270
  /// Returns an array of clauses associated with this requires declaration
271
84
  MutableArrayRef<OMPClause *> getClauses() {
272
84
    return MutableArrayRef<OMPClause *>(getTrailingObjects<OMPClause *>(),
273
84
                                        NumClauses);
274
84
  }
275
276
  /// Sets an array of clauses to this requires declaration
277
  void setClauses(ArrayRef<OMPClause *> CL);
278
279
public:
280
  /// Create requires node.
281
  static OMPRequiresDecl *Create(ASTContext &C, DeclContext *DC,
282
                                 SourceLocation L, ArrayRef<OMPClause *> CL);
283
  /// Create deserialized requires node.
284
  static OMPRequiresDecl *CreateDeserialized(ASTContext &C, unsigned ID,
285
                                             unsigned N);
286
287
  using clauselist_iterator = MutableArrayRef<OMPClause *>::iterator;
288
  using clauselist_const_iterator = ArrayRef<const OMPClause *>::iterator;
289
  using clauselist_range = llvm::iterator_range<clauselist_iterator>;
290
  using clauselist_const_range = llvm::iterator_range<clauselist_const_iterator>;
291
292
28
  unsigned clauselist_size() const { return NumClauses; }
293
28
  bool clauselist_empty() const { return NumClauses == 0; }
294
295
14
  clauselist_range clauselists() {
296
14
    return clauselist_range(clauselist_begin(), clauselist_end());
297
14
  }
298
138
  clauselist_const_range clauselists() const {
299
138
    return clauselist_const_range(clauselist_begin(), clauselist_end());
300
138
  }
301
42
  clauselist_iterator clauselist_begin() { return getClauses().begin(); }
302
42
  clauselist_iterator clauselist_end() { return getClauses().end(); }
303
138
  clauselist_const_iterator clauselist_begin() const {
304
138
    return getClauses().begin();
305
138
  }
306
138
  clauselist_const_iterator clauselist_end() const {
307
138
    return getClauses().end();
308
138
  }
309
310
7.50k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
311
7.50k
  static bool classofKind(Kind K) { return K == OMPRequires; }
312
};
313
} // end namespace clang
314
315
#endif