Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/GlobalDecl.h
Line
Count
Source
1
//===- GlobalDecl.h - Global declaration holder -----------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// A GlobalDecl can hold either a regular variable/function or a C++ ctor/dtor
10
// together with its type.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_GLOBALDECL_H
15
#define LLVM_CLANG_AST_GLOBALDECL_H
16
17
#include "clang/AST/DeclCXX.h"
18
#include "clang/AST/DeclObjC.h"
19
#include "clang/AST/DeclOpenMP.h"
20
#include "clang/Basic/ABI.h"
21
#include "clang/Basic/LLVM.h"
22
#include "llvm/ADT/DenseMapInfo.h"
23
#include "llvm/ADT/PointerIntPair.h"
24
#include "llvm/Support/Casting.h"
25
#include "llvm/Support/type_traits.h"
26
#include <cassert>
27
28
namespace clang {
29
30
enum class DynamicInitKind : unsigned {
31
  NoStub = 0,
32
  Initializer,
33
  AtExit,
34
};
35
36
/// GlobalDecl - represents a global declaration. This can either be a
37
/// CXXConstructorDecl and the constructor type (Base, Complete).
38
/// a CXXDestructorDecl and the destructor type (Base, Complete) or
39
/// a VarDecl, a FunctionDecl or a BlockDecl.
40
class GlobalDecl {
41
  llvm::PointerIntPair<const Decl *, 2> Value;
42
  unsigned MultiVersionIndex = 0;
43
44
7.70M
  void Init(const Decl *D) {
45
7.70M
    assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
46
7.70M
    assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
47
7.70M
48
7.70M
    Value.setPointer(D);
49
7.70M
  }
50
51
public:
52
30.6M
  GlobalDecl() = default;
53
1.66M
  GlobalDecl(const VarDecl *D) { Init(D);}
54
  GlobalDecl(const FunctionDecl *D, unsigned MVIndex = 0)
55
5.98M
      : MultiVersionIndex(MVIndex) {
56
5.98M
    Init(D);
57
5.98M
  }
58
4.80k
  GlobalDecl(const BlockDecl *D) { Init(D); }
59
42.5k
  GlobalDecl(const CapturedDecl *D) { Init(D); }
60
4.69k
  GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
61
6
  GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
62
574k
  GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {}
63
125k
  GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
64
  GlobalDecl(const VarDecl *D, DynamicInitKind StubKind)
65
4.83k
      : Value(D, unsigned(StubKind)) {}
66
67
4.77M
  GlobalDecl getCanonicalDecl() const {
68
4.77M
    GlobalDecl CanonGD;
69
4.77M
    CanonGD.Value.setPointer(Value.getPointer()->getCanonicalDecl());
70
4.77M
    CanonGD.Value.setInt(Value.getInt());
71
4.77M
    CanonGD.MultiVersionIndex = MultiVersionIndex;
72
4.77M
73
4.77M
    return CanonGD;
74
4.77M
  }
75
76
36.1M
  const Decl *getDecl() const { return Value.getPointer(); }
77
78
592k
  CXXCtorType getCtorType() const {
79
592k
    assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
80
592k
    return static_cast<CXXCtorType>(Value.getInt());
81
592k
  }
82
83
601k
  CXXDtorType getDtorType() const {
84
601k
    assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
85
601k
    return static_cast<CXXDtorType>(Value.getInt());
86
601k
  }
87
88
483
  DynamicInitKind getDynamicInitKind() const {
89
483
    assert(isa<VarDecl>(getDecl()) &&
90
483
           cast<VarDecl>(getDecl())->hasGlobalStorage() &&
91
483
           "Decl is not a global variable!");
92
483
    return static_cast<DynamicInitKind>(Value.getInt());
93
483
  }
94
95
84
  unsigned getMultiVersionIndex() const {
96
84
    assert(isa<FunctionDecl>(getDecl()) &&
97
84
           !isa<CXXConstructorDecl>(getDecl()) &&
98
84
           !isa<CXXDestructorDecl>(getDecl()) &&
99
84
           "Decl is not a plain FunctionDecl!");
100
84
    return MultiVersionIndex;
101
84
  }
102
103
66.0M
  friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS) {
104
66.0M
    return LHS.Value == RHS.Value &&
105
66.0M
           
LHS.MultiVersionIndex == RHS.MultiVersionIndex17.6M
;
106
66.0M
  }
107
108
10.3M
  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
109
110
10.4M
  static GlobalDecl getFromOpaquePtr(void *P) {
111
10.4M
    GlobalDecl GD;
112
10.4M
    GD.Value.setFromOpaqueValue(P);
113
10.4M
    return GD;
114
10.4M
  }
115
116
42.4k
  GlobalDecl getWithDecl(const Decl *D) {
117
42.4k
    GlobalDecl Result(*this);
118
42.4k
    Result.Value.setPointer(D);
119
42.4k
    return Result;
120
42.4k
  }
121
122
23.2k
  GlobalDecl getWithCtorType(CXXCtorType Type) {
123
23.2k
    assert(isa<CXXConstructorDecl>(getDecl()));
124
23.2k
    GlobalDecl Result(*this);
125
23.2k
    Result.Value.setInt(Type);
126
23.2k
    return Result;
127
23.2k
  }
128
129
9.99k
  GlobalDecl getWithDtorType(CXXDtorType Type) {
130
9.99k
    assert(isa<CXXDestructorDecl>(getDecl()));
131
9.99k
    GlobalDecl Result(*this);
132
9.99k
    Result.Value.setInt(Type);
133
9.99k
    return Result;
134
9.99k
  }
135
136
70
  GlobalDecl getWithMultiVersionIndex(unsigned Index) {
137
70
    assert(isa<FunctionDecl>(getDecl()) &&
138
70
           !isa<CXXConstructorDecl>(getDecl()) &&
139
70
           !isa<CXXDestructorDecl>(getDecl()) &&
140
70
           "Decl is not a plain FunctionDecl!");
141
70
    GlobalDecl Result(*this);
142
70
    Result.MultiVersionIndex = Index;
143
70
    return Result;
144
70
  }
145
};
146
147
} // namespace clang
148
149
namespace llvm {
150
151
  template<> struct DenseMapInfo<clang::GlobalDecl> {
152
12.8M
    static inline clang::GlobalDecl getEmptyKey() {
153
12.8M
      return clang::GlobalDecl();
154
12.8M
    }
155
156
10.4M
    static inline clang::GlobalDecl getTombstoneKey() {
157
10.4M
      return clang::GlobalDecl::
158
10.4M
        getFromOpaquePtr(reinterpret_cast<void*>(-1));
159
10.4M
    }
160
161
10.3M
    static unsigned getHashValue(clang::GlobalDecl GD) {
162
10.3M
      return DenseMapInfo<void*>::getHashValue(GD.getAsOpaquePtr());
163
10.3M
    }
164
165
    static bool isEqual(clang::GlobalDecl LHS,
166
66.0M
                        clang::GlobalDecl RHS) {
167
66.0M
      return LHS == RHS;
168
66.0M
    }
169
  };
170
171
} // namespace llvm
172
173
#endif // LLVM_CLANG_AST_GLOBALDECL_H