Coverage Report

Created: 2018-09-25 23:22

/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/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
///
39
class OMPThreadPrivateDecl final
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
49
  OMPThreadPrivateDecl(Kind DK, DeclContext *DC, SourceLocation L) :
50
1.77k
    Decl(DK, DC, L), NumVars(0) { }
51
52
102
  ArrayRef<const Expr *> getVars() const {
53
102
    return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumVars);
54
102
  }
55
56
1.64k
  MutableArrayRef<Expr *> getVars() {
57
1.64k
    return MutableArrayRef<Expr *>(getTrailingObjects<Expr *>(), NumVars);
58
1.64k
  }
59
60
  void setVars(ArrayRef<Expr *> VL);
61
62
public:
63
  static OMPThreadPrivateDecl *Create(ASTContext &C, DeclContext *DC,
64
                                      SourceLocation L,
65
                                      ArrayRef<Expr *> VL);
66
  static OMPThreadPrivateDecl *CreateDeserialized(ASTContext &C,
67
                                                  unsigned ID, unsigned N);
68
69
  typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
70
  typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
71
  typedef llvm::iterator_range<varlist_iterator> varlist_range;
72
  typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
73
74
378
  unsigned varlist_size() const { return NumVars; }
75
322
  bool varlist_empty() const { return NumVars == 0; }
76
77
337
  varlist_range varlists() {
78
337
    return varlist_range(varlist_begin(), varlist_end());
79
337
  }
80
51
  varlist_const_range varlists() const {
81
51
    return varlist_const_range(varlist_begin(), varlist_end());
82
51
  }
83
989
  varlist_iterator varlist_begin() { return getVars().begin(); }
84
659
  varlist_iterator varlist_end() { return getVars().end(); }
85
51
  varlist_const_iterator varlist_begin() const { return getVars().begin(); }
86
51
  varlist_const_iterator varlist_end() const { return getVars().end(); }
87
88
465k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
89
465k
  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 = nullptr;
116
  /// Initializer for declare reduction construct.
117
  Expr *Initializer = nullptr;
118
  /// In parameter of the combiner.
119
  Expr *In = nullptr;
120
  /// Out parameter of the combiner.
121
  Expr *Out = nullptr;
122
  /// Priv parameter of the initializer.
123
  Expr *Priv = nullptr;
124
  /// Orig parameter of the initializer.
125
  Expr *Orig = nullptr;
126
127
  /// Reference to the previous declare reduction construct in the same
128
  /// scope with the same name. Required for proper templates instantiation if
129
  /// the declare reduction construct is declared inside compound statement.
130
  LazyDeclPtr PrevDeclInScope;
131
132
  virtual void anchor();
133
134
  OMPDeclareReductionDecl(Kind DK, DeclContext *DC, SourceLocation L,
135
                          DeclarationName Name, QualType Ty,
136
                          OMPDeclareReductionDecl *PrevDeclInScope);
137
138
0
  void setPrevDeclInScope(OMPDeclareReductionDecl *Prev) {
139
0
    PrevDeclInScope = Prev;
140
0
  }
141
142
public:
143
  /// Create declare reduction node.
144
  static OMPDeclareReductionDecl *
145
  Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
146
         QualType T, OMPDeclareReductionDecl *PrevDeclInScope);
147
  /// Create deserialized declare reduction node.
148
  static OMPDeclareReductionDecl *CreateDeserialized(ASTContext &C,
149
                                                     unsigned ID);
150
151
  /// Get combiner expression of the declare reduction construct.
152
392
  Expr *getCombiner() { return Combiner; }
153
97
  const Expr *getCombiner() const { return Combiner; }
154
  /// Get In variable of the combiner.
155
320
  Expr *getCombinerIn() { return In; }
156
91
  const Expr *getCombinerIn() const { return In; }
157
  /// Get Out variable of the combiner.
158
320
  Expr *getCombinerOut() { return Out; }
159
91
  const Expr *getCombinerOut() const { return Out; }
160
  /// Set combiner expression for the declare reduction construct.
161
688
  void setCombiner(Expr *E) { Combiner = E; }
162
  /// Set combiner In and Out vars.
163
744
  void setCombinerData(Expr *InE, Expr *OutE) {
164
744
    In = InE;
165
744
    Out = OutE;
166
744
  }
167
168
  /// Get initializer expression (if specified) of the declare reduction
169
  /// construct.
170
588
  Expr *getInitializer() { return Initializer; }
171
195
  const Expr *getInitializer() const { return Initializer; }
172
  /// Get initializer kind.
173
315
  InitKind getInitializerKind() const {
174
315
    return static_cast<InitKind>(OMPDeclareReductionDeclBits.InitializerKind);
175
315
  }
176
  /// Get Orig variable of the initializer.
177
174
  Expr *getInitOrig() { return Orig; }
178
51
  const Expr *getInitOrig() const { return Orig; }
179
  /// Get Priv variable of the initializer.
180
174
  Expr *getInitPriv() { return Priv; }
181
51
  const Expr *getInitPriv() const { return Priv; }
182
  /// Set initializer expression for the declare reduction construct.
183
1.04k
  void setInitializer(Expr *E, InitKind IK) {
184
1.04k
    Initializer = E;
185
1.04k
    OMPDeclareReductionDeclBits.InitializerKind = IK;
186
1.04k
  }
187
  /// Set initializer Orig and Priv vars.
188
338
  void setInitializerData(Expr *OrigE, Expr *PrivE) {
189
338
    Orig = OrigE;
190
338
    Priv = PrivE;
191
338
  }
192
193
  /// Get reference to previous declare reduction construct in the same
194
  /// scope with the same name.
195
  OMPDeclareReductionDecl *getPrevDeclInScope();
196
  const OMPDeclareReductionDecl *getPrevDeclInScope() const;
197
198
410k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
199
75.8M
  static bool classofKind(Kind K) { return K == OMPDeclareReduction; }
200
0
  static DeclContext *castToDeclContext(const OMPDeclareReductionDecl *D) {
201
0
    return static_cast<DeclContext *>(const_cast<OMPDeclareReductionDecl *>(D));
202
0
  }
203
0
  static OMPDeclareReductionDecl *castFromDeclContext(const DeclContext *DC) {
204
0
    return static_cast<OMPDeclareReductionDecl *>(
205
0
        const_cast<DeclContext *>(DC));
206
0
  }
207
};
208
209
/// Pseudo declaration for capturing expressions. Also is used for capturing of
210
/// non-static data members in non-static member functions.
211
///
212
/// Clang supports capturing of variables only, but OpenMP 4.5 allows to
213
/// privatize non-static members of current class in non-static member
214
/// functions. This pseudo-declaration allows properly handle this kind of
215
/// capture by wrapping captured expression into a variable-like declaration.
216
class OMPCapturedExprDecl final : public VarDecl {
217
  friend class ASTDeclReader;
218
  void anchor() override;
219
220
  OMPCapturedExprDecl(ASTContext &C, DeclContext *DC, IdentifierInfo *Id,
221
                      QualType Type, TypeSourceInfo *TInfo,
222
                      SourceLocation StartLoc)
223
      : VarDecl(OMPCapturedExpr, C, DC, StartLoc, StartLoc, Id, Type, TInfo,
224
37.7k
                SC_None) {
225
37.7k
    setImplicit();
226
37.7k
  }
227
228
public:
229
  static OMPCapturedExprDecl *Create(ASTContext &C, DeclContext *DC,
230
                                     IdentifierInfo *Id, QualType T,
231
                                     SourceLocation StartLoc);
232
233
  static OMPCapturedExprDecl *CreateDeserialized(ASTContext &C, unsigned ID);
234
235
  SourceRange getSourceRange() const override LLVM_READONLY;
236
237
  // Implement isa/cast/dyncast/etc.
238
6.76M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
239
6.76M
  static bool classofKind(Kind K) { return K == OMPCapturedExpr; }
240
};
241
242
} // end namespace clang
243
244
#endif