Coverage Report

Created: 2019-03-22 08:08

/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
/// GlobalDecl - represents a global declaration. This can either be a
31
/// CXXConstructorDecl and the constructor type (Base, Complete).
32
/// a CXXDestructorDecl and the destructor type (Base, Complete) or
33
/// a VarDecl, a FunctionDecl or a BlockDecl.
34
class GlobalDecl {
35
  llvm::PointerIntPair<const Decl *, 2> Value;
36
  unsigned MultiVersionIndex = 0;
37
38
7.23M
  void Init(const Decl *D) {
39
7.23M
    assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
40
7.23M
    assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
41
7.23M
42
7.23M
    Value.setPointer(D);
43
7.23M
  }
44
45
public:
46
29.2M
  GlobalDecl() = default;
47
1.54M
  GlobalDecl(const VarDecl *D) { Init(D);}
48
  GlobalDecl(const FunctionDecl *D, unsigned MVIndex = 0)
49
5.64M
      : MultiVersionIndex(MVIndex) {
50
5.64M
    Init(D);
51
5.64M
  }
52
4.78k
  GlobalDecl(const BlockDecl *D) { Init(D); }
53
42.3k
  GlobalDecl(const CapturedDecl *D) { Init(D); }
54
4.61k
  GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
55
6
  GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
56
990k
  GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {}
57
451k
  GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
58
59
4.44M
  GlobalDecl getCanonicalDecl() const {
60
4.44M
    GlobalDecl CanonGD;
61
4.44M
    CanonGD.Value.setPointer(Value.getPointer()->getCanonicalDecl());
62
4.44M
    CanonGD.Value.setInt(Value.getInt());
63
4.44M
    CanonGD.MultiVersionIndex = MultiVersionIndex;
64
4.44M
65
4.44M
    return CanonGD;
66
4.44M
  }
67
68
32.0M
  const Decl *getDecl() const { return Value.getPointer(); }
69
70
437k
  CXXCtorType getCtorType() const {
71
437k
    assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
72
437k
    return static_cast<CXXCtorType>(Value.getInt());
73
437k
  }
74
75
432k
  CXXDtorType getDtorType() const {
76
432k
    assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
77
432k
    return static_cast<CXXDtorType>(Value.getInt());
78
432k
  }
79
80
84
  unsigned getMultiVersionIndex() const {
81
84
    assert(isa<FunctionDecl>(getDecl()) &&
82
84
           !isa<CXXConstructorDecl>(getDecl()) &&
83
84
           !isa<CXXDestructorDecl>(getDecl()) &&
84
84
           "Decl is not a plain FunctionDecl!");
85
84
    return MultiVersionIndex;
86
84
  }
87
88
61.0M
  friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS) {
89
61.0M
    return LHS.Value == RHS.Value &&
90
61.0M
           
LHS.MultiVersionIndex == RHS.MultiVersionIndex16.4M
;
91
61.0M
  }
92
93
9.56M
  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
94
95
9.64M
  static GlobalDecl getFromOpaquePtr(void *P) {
96
9.64M
    GlobalDecl GD;
97
9.64M
    GD.Value.setFromOpaqueValue(P);
98
9.64M
    return GD;
99
9.64M
  }
100
101
40.7k
  GlobalDecl getWithDecl(const Decl *D) {
102
40.7k
    GlobalDecl Result(*this);
103
40.7k
    Result.Value.setPointer(D);
104
40.7k
    return Result;
105
40.7k
  }
106
107
70
  GlobalDecl getWithMultiVersionIndex(unsigned Index) {
108
70
    assert(isa<FunctionDecl>(getDecl()) &&
109
70
           !isa<CXXConstructorDecl>(getDecl()) &&
110
70
           !isa<CXXDestructorDecl>(getDecl()) &&
111
70
           "Decl is not a plain FunctionDecl!");
112
70
    GlobalDecl Result(*this);
113
70
    Result.MultiVersionIndex = Index;
114
70
    return Result;
115
70
  }
116
};
117
118
} // namespace clang
119
120
namespace llvm {
121
122
  template<> struct DenseMapInfo<clang::GlobalDecl> {
123
11.9M
    static inline clang::GlobalDecl getEmptyKey() {
124
11.9M
      return clang::GlobalDecl();
125
11.9M
    }
126
127
9.64M
    static inline clang::GlobalDecl getTombstoneKey() {
128
9.64M
      return clang::GlobalDecl::
129
9.64M
        getFromOpaquePtr(reinterpret_cast<void*>(-1));
130
9.64M
    }
131
132
9.56M
    static unsigned getHashValue(clang::GlobalDecl GD) {
133
9.56M
      return DenseMapInfo<void*>::getHashValue(GD.getAsOpaquePtr());
134
9.56M
    }
135
136
    static bool isEqual(clang::GlobalDecl LHS,
137
61.0M
                        clang::GlobalDecl RHS) {
138
61.0M
      return LHS == RHS;
139
61.0M
    }
140
  };
141
142
} // namespace llvm
143
144
#endif // LLVM_CLANG_AST_GLOBALDECL_H