Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/IR/ValueHandle.h
Line
Count
Source (jump to first uncovered line)
1
//===- ValueHandle.h - Value Smart Pointer classes --------------*- 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
// This file declares the ValueHandle class and its sub-classes.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_IR_VALUEHANDLE_H
14
#define LLVM_IR_VALUEHANDLE_H
15
16
#include "llvm/ADT/DenseMapInfo.h"
17
#include "llvm/ADT/PointerIntPair.h"
18
#include "llvm/IR/Value.h"
19
#include "llvm/Support/Casting.h"
20
#include <cassert>
21
22
namespace llvm {
23
24
/// This is the common base class of value handles.
25
///
26
/// ValueHandle's are smart pointers to Value's that have special behavior when
27
/// the value is deleted or ReplaceAllUsesWith'd.  See the specific handles
28
/// below for details.
29
class ValueHandleBase {
30
  friend class Value;
31
32
protected:
33
  /// This indicates what sub class the handle actually is.
34
  ///
35
  /// This is to avoid having a vtable for the light-weight handle pointers. The
36
  /// fully general Callback version does have a vtable.
37
  enum HandleBaseKind { Assert, Callback, Weak, WeakTracking };
38
39
  ValueHandleBase(const ValueHandleBase &RHS)
40
480M
      : ValueHandleBase(RHS.PrevPair.getInt(), RHS) {}
41
42
  ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
43
548M
      : PrevPair(nullptr, Kind), Val(RHS.getValPtr()) {
44
548M
    if (isValid(getValPtr()))
45
74.7M
      AddToExistingUseList(RHS.getPrevPtr());
46
548M
  }
47
48
private:
49
  PointerIntPair<ValueHandleBase**, 2, HandleBaseKind> PrevPair;
50
  ValueHandleBase *Next = nullptr;
51
  Value *Val = nullptr;
52
53
90.7M
  void setValPtr(Value *V) { Val = V; }
54
55
public:
56
  explicit ValueHandleBase(HandleBaseKind Kind)
57
22.6M
      : PrevPair(nullptr, Kind) {}
58
  ValueHandleBase(HandleBaseKind Kind, Value *V)
59
583M
      : PrevPair(nullptr, Kind), Val(V) {
60
583M
    if (isValid(getValPtr()))
61
102M
      AddToUseList();
62
583M
  }
63
64
1.15G
  ~ValueHandleBase() {
65
1.15G
    if (isValid(getValPtr()))
66
232M
      RemoveFromUseList();
67
1.15G
  }
68
69
22.9M
  Value *operator=(Value *RHS) {
70
22.9M
    if (getValPtr() == RHS)
71
2.44k
      return RHS;
72
22.9M
    if (isValid(getValPtr()))
73
1.96M
      RemoveFromUseList();
74
22.9M
    setValPtr(RHS);
75
22.9M
    if (isValid(getValPtr()))
76
22.2M
      AddToUseList();
77
22.9M
    return RHS;
78
22.9M
  }
79
80
68.1M
  Value *operator=(const ValueHandleBase &RHS) {
81
68.1M
    if (getValPtr() == RHS.getValPtr())
82
305k
      return RHS.getValPtr();
83
67.8M
    if (isValid(getValPtr()))
84
17.3M
      RemoveFromUseList();
85
67.8M
    setValPtr(RHS.getValPtr());
86
67.8M
    if (isValid(getValPtr()))
87
51.7M
      AddToExistingUseList(RHS.getPrevPtr());
88
67.8M
    return getValPtr();
89
67.8M
  }
90
91
252k
  Value *operator->() const { return getValPtr(); }
92
607k
  Value &operator*() const { return *getValPtr(); }
93
94
protected:
95
6.90G
  Value *getValPtr() const { return Val; }
96
97
2.46G
  static bool isValid(Value *V) {
98
2.46G
    return V &&
99
2.46G
           
V != DenseMapInfo<Value *>::getEmptyKey()2.42G
&&
100
2.46G
           
V != DenseMapInfo<Value *>::getTombstoneKey()955M
;
101
2.46G
  }
102
103
  /// Remove this ValueHandle from its current use list.
104
  void RemoveFromUseList();
105
106
  /// Clear the underlying pointer without clearing the use list.
107
  ///
108
  /// This should only be used if a derived class has manually removed the
109
  /// handle from the use list.
110
0
  void clearValPtr() { setValPtr(nullptr); }
111
112
public:
113
  // Callbacks made from Value.
114
  static void ValueIsDeleted(Value *V);
115
  static void ValueIsRAUWd(Value *Old, Value *New);
116
117
private:
118
  // Internal implementation details.
119
381M
  ValueHandleBase **getPrevPtr() const { return PrevPair.getPointer(); }
120
3.57M
  HandleBaseKind getKind() const { return PrevPair.getInt(); }
121
555M
  void setPrevPtr(ValueHandleBase **Ptr) { PrevPair.setPointer(Ptr); }
122
123
  /// Add this ValueHandle to the use list for V.
124
  ///
125
  /// List is the address of either the head of the list or a Next node within
126
  /// the existing use list.
127
  void AddToExistingUseList(ValueHandleBase **List);
128
129
  /// Add this ValueHandle to the use list after Node.
130
  void AddToExistingUseListAfter(ValueHandleBase *Node);
131
132
  /// Add this ValueHandle to the use list for V.
133
  void AddToUseList();
134
};
135
136
/// A nullable Value handle that is nullable.
137
///
138
/// This is a value handle that points to a value, and nulls itself
139
/// out if that value is deleted.
140
class WeakVH : public ValueHandleBase {
141
public:
142
0
  WeakVH() : ValueHandleBase(Weak) {}
143
3.93M
  WeakVH(Value *P) : ValueHandleBase(Weak, P) {}
144
  WeakVH(const WeakVH &RHS)
145
5.77M
      : ValueHandleBase(Weak, RHS) {}
146
147
0
  WeakVH &operator=(const WeakVH &RHS) = default;
148
149
  Value *operator=(Value *RHS) {
150
    return ValueHandleBase::operator=(RHS);
151
  }
152
0
  Value *operator=(const ValueHandleBase &RHS) {
153
0
    return ValueHandleBase::operator=(RHS);
154
0
  }
155
156
6.67M
  operator Value*() const {
157
6.67M
    return getValPtr();
158
6.67M
  }
159
};
160
161
// Specialize simplify_type to allow WeakVH to participate in
162
// dyn_cast, isa, etc.
163
template <> struct simplify_type<WeakVH> {
164
  using SimpleType = Value *;
165
166
1.21M
  static SimpleType getSimplifiedValue(WeakVH &WVH) { return WVH; }
167
};
168
template <> struct simplify_type<const WeakVH> {
169
  using SimpleType = Value *;
170
171
2.44M
  static SimpleType getSimplifiedValue(const WeakVH &WVH) { return WVH; }
172
};
173
174
/// Value handle that is nullable, but tries to track the Value.
175
///
176
/// This is a value handle that tries hard to point to a Value, even across
177
/// RAUW operations, but will null itself out if the value is destroyed.  this
178
/// is useful for advisory sorts of information, but should not be used as the
179
/// key of a map (since the map would have to rearrange itself when the pointer
180
/// changes).
181
class WeakTrackingVH : public ValueHandleBase {
182
public:
183
22.6M
  WeakTrackingVH() : ValueHandleBase(WeakTracking) {}
184
37.8M
  WeakTrackingVH(Value *P) : ValueHandleBase(WeakTracking, P) {}
185
  WeakTrackingVH(const WeakTrackingVH &RHS)
186
59.8M
      : ValueHandleBase(WeakTracking, RHS) {}
187
188
3.27M
  WeakTrackingVH &operator=(const WeakTrackingVH &RHS) = default;
189
190
21.4M
  Value *operator=(Value *RHS) {
191
21.4M
    return ValueHandleBase::operator=(RHS);
192
21.4M
  }
193
0
  Value *operator=(const ValueHandleBase &RHS) {
194
0
    return ValueHandleBase::operator=(RHS);
195
0
  }
196
197
117M
  operator Value*() const {
198
117M
    return getValPtr();
199
117M
  }
200
201
313k
  bool pointsToAliveValue() const {
202
313k
    return ValueHandleBase::isValid(getValPtr());
203
313k
  }
204
};
205
206
// Specialize simplify_type to allow WeakTrackingVH to participate in
207
// dyn_cast, isa, etc.
208
template <> struct simplify_type<WeakTrackingVH> {
209
  using SimpleType = Value *;
210
211
7.75M
  static SimpleType getSimplifiedValue(WeakTrackingVH &WVH) { return WVH; }
212
};
213
template <> struct simplify_type<const WeakTrackingVH> {
214
  using SimpleType = Value *;
215
216
7.28M
  static SimpleType getSimplifiedValue(const WeakTrackingVH &WVH) {
217
7.28M
    return WVH;
218
7.28M
  }
219
};
220
221
/// Value handle that asserts if the Value is deleted.
222
///
223
/// This is a Value Handle that points to a value and asserts out if the value
224
/// is destroyed while the handle is still live.  This is very useful for
225
/// catching dangling pointer bugs and other things which can be non-obvious.
226
/// One particularly useful place to use this is as the Key of a map.  Dangling
227
/// pointer bugs often lead to really subtle bugs that only occur if another
228
/// object happens to get allocated to the same address as the old one.  Using
229
/// an AssertingVH ensures that an assert is triggered as soon as the bad
230
/// delete occurs.
231
///
232
/// Note that an AssertingVH handle does *not* follow values across RAUW
233
/// operations.  This means that RAUW's need to explicitly update the
234
/// AssertingVH's as it moves.  This is required because in non-assert mode this
235
/// class turns into a trivial wrapper around a pointer.
236
template <typename ValueTy>
237
class AssertingVH
238
#ifndef NDEBUG
239
  : public ValueHandleBase
240
#endif
241
  {
242
  friend struct DenseMapInfo<AssertingVH<ValueTy>>;
243
244
#ifndef NDEBUG
245
  Value *getRawValPtr() const { return ValueHandleBase::getValPtr(); }
246
  void setRawValPtr(Value *P) { ValueHandleBase::operator=(P); }
247
#else
248
  Value *ThePtr;
249
1.23G
  Value *getRawValPtr() const { return ThePtr; }
llvm::AssertingVH<llvm::Value const>::getRawValPtr() const
Line
Count
Source
249
43.5k
  Value *getRawValPtr() const { return ThePtr; }
llvm::AssertingVH<llvm::BasicBlock>::getRawValPtr() const
Line
Count
Source
249
148M
  Value *getRawValPtr() const { return ThePtr; }
llvm::AssertingVH<llvm::Value>::getRawValPtr() const
Line
Count
Source
249
433M
  Value *getRawValPtr() const { return ThePtr; }
llvm::AssertingVH<llvm::PHINode>::getRawValPtr() const
Line
Count
Source
249
298k
  Value *getRawValPtr() const { return ThePtr; }
llvm::AssertingVH<llvm::MemoryPhi>::getRawValPtr() const
Line
Count
Source
249
78
  Value *getRawValPtr() const { return ThePtr; }
llvm::AssertingVH<llvm::GetElementPtrInst>::getRawValPtr() const
Line
Count
Source
249
9.09M
  Value *getRawValPtr() const { return ThePtr; }
llvm::AssertingVH<llvm::Function>::getRawValPtr() const
Line
Count
Source
249
86.4k
  Value *getRawValPtr() const { return ThePtr; }
llvm::AssertingVH<llvm::Instruction>::getRawValPtr() const
Line
Count
Source
249
647M
  Value *getRawValPtr() const { return ThePtr; }
llvm::AssertingVH<llvm::Constant>::getRawValPtr() const
Line
Count
Source
249
1.29k
  Value *getRawValPtr() const { return ThePtr; }
llvm::AssertingVH<llvm::LoadInst>::getRawValPtr() const
Line
Count
Source
249
534k
  Value *getRawValPtr() const { return ThePtr; }
llvm::AssertingVH<llvm::AllocaInst>::getRawValPtr() const
Line
Count
Source
249
1.07k
  Value *getRawValPtr() const { return ThePtr; }
250
279M
  void setRawValPtr(Value *P) { ThePtr = P; }
llvm::AssertingVH<llvm::Value const>::setRawValPtr(llvm::Value*)
Line
Count
Source
250
82
  void setRawValPtr(Value *P) { ThePtr = P; }
llvm::AssertingVH<llvm::Value>::setRawValPtr(llvm::Value*)
Line
Count
Source
250
76.1M
  void setRawValPtr(Value *P) { ThePtr = P; }
llvm::AssertingVH<llvm::PHINode>::setRawValPtr(llvm::Value*)
Line
Count
Source
250
12.0k
  void setRawValPtr(Value *P) { ThePtr = P; }
Unexecuted instantiation: llvm::AssertingVH<llvm::MemoryPhi>::setRawValPtr(llvm::Value*)
llvm::AssertingVH<llvm::GetElementPtrInst>::setRawValPtr(llvm::Value*)
Line
Count
Source
250
248k
  void setRawValPtr(Value *P) { ThePtr = P; }
llvm::AssertingVH<llvm::Function>::setRawValPtr(llvm::Value*)
Line
Count
Source
250
1.13k
  void setRawValPtr(Value *P) { ThePtr = P; }
llvm::AssertingVH<llvm::BasicBlock>::setRawValPtr(llvm::Value*)
Line
Count
Source
250
37.9M
  void setRawValPtr(Value *P) { ThePtr = P; }
llvm::AssertingVH<llvm::Instruction>::setRawValPtr(llvm::Value*)
Line
Count
Source
250
165M
  void setRawValPtr(Value *P) { ThePtr = P; }
llvm::AssertingVH<llvm::Constant>::setRawValPtr(llvm::Value*)
Line
Count
Source
250
229
  void setRawValPtr(Value *P) { ThePtr = P; }
llvm::AssertingVH<llvm::LoadInst>::setRawValPtr(llvm::Value*)
Line
Count
Source
250
61.1k
  void setRawValPtr(Value *P) { ThePtr = P; }
llvm::AssertingVH<llvm::AllocaInst>::setRawValPtr(llvm::Value*)
Line
Count
Source
250
165
  void setRawValPtr(Value *P) { ThePtr = P; }
251
#endif
252
  // Convert a ValueTy*, which may be const, to the raw Value*.
253
73.2M
  static Value *GetAsValue(Value *V) { return V; }
llvm::AssertingVH<llvm::BasicBlock>::GetAsValue(llvm::Value*)
Line
Count
Source
253
23.2M
  static Value *GetAsValue(Value *V) { return V; }
llvm::AssertingVH<llvm::Value>::GetAsValue(llvm::Value*)
Line
Count
Source
253
39.8M
  static Value *GetAsValue(Value *V) { return V; }
llvm::AssertingVH<llvm::PHINode>::GetAsValue(llvm::Value*)
Line
Count
Source
253
7.23k
  static Value *GetAsValue(Value *V) { return V; }
llvm::AssertingVH<llvm::MemoryPhi>::GetAsValue(llvm::Value*)
Line
Count
Source
253
1.29k
  static Value *GetAsValue(Value *V) { return V; }
llvm::AssertingVH<llvm::GetElementPtrInst>::GetAsValue(llvm::Value*)
Line
Count
Source
253
8.44M
  static Value *GetAsValue(Value *V) { return V; }
llvm::AssertingVH<llvm::Function>::GetAsValue(llvm::Value*)
Line
Count
Source
253
41.1k
  static Value *GetAsValue(Value *V) { return V; }
llvm::AssertingVH<llvm::Instruction>::GetAsValue(llvm::Value*)
Line
Count
Source
253
1.59M
  static Value *GetAsValue(Value *V) { return V; }
llvm::AssertingVH<llvm::Constant>::GetAsValue(llvm::Value*)
Line
Count
Source
253
458
  static Value *GetAsValue(Value *V) { return V; }
llvm::AssertingVH<llvm::LoadInst>::GetAsValue(llvm::Value*)
Line
Count
Source
253
38.2k
  static Value *GetAsValue(Value *V) { return V; }
llvm::AssertingVH<llvm::AllocaInst>::GetAsValue(llvm::Value*)
Line
Count
Source
253
165
  static Value *GetAsValue(Value *V) { return V; }
254
2.05M
  static Value *GetAsValue(const Value *V) { return const_cast<Value*>(V); }
255
256
75.9M
  ValueTy *getValPtr() const { return static_cast<ValueTy *>(getRawValPtr()); }
llvm::AssertingVH<llvm::BasicBlock>::getValPtr() const
Line
Count
Source
256
17.6M
  ValueTy *getValPtr() const { return static_cast<ValueTy *>(getRawValPtr()); }
llvm::AssertingVH<llvm::Value>::getValPtr() const
Line
Count
Source
256
45.9M
  ValueTy *getValPtr() const { return static_cast<ValueTy *>(getRawValPtr()); }
llvm::AssertingVH<llvm::PHINode>::getValPtr() const
Line
Count
Source
256
5.23k
  ValueTy *getValPtr() const { return static_cast<ValueTy *>(getRawValPtr()); }
llvm::AssertingVH<llvm::Value const>::getValPtr() const
Line
Count
Source
256
42.8k
  ValueTy *getValPtr() const { return static_cast<ValueTy *>(getRawValPtr()); }
llvm::AssertingVH<llvm::MemoryPhi>::getValPtr() const
Line
Count
Source
256
78
  ValueTy *getValPtr() const { return static_cast<ValueTy *>(getRawValPtr()); }
llvm::AssertingVH<llvm::GetElementPtrInst>::getValPtr() const
Line
Count
Source
256
8.14M
  ValueTy *getValPtr() const { return static_cast<ValueTy *>(getRawValPtr()); }
llvm::AssertingVH<llvm::Function>::getValPtr() const
Line
Count
Source
256
70.1k
  ValueTy *getValPtr() const { return static_cast<ValueTy *>(getRawValPtr()); }
llvm::AssertingVH<llvm::Instruction>::getValPtr() const
Line
Count
Source
256
4.14M
  ValueTy *getValPtr() const { return static_cast<ValueTy *>(getRawValPtr()); }
llvm::AssertingVH<llvm::Constant>::getValPtr() const
Line
Count
Source
256
1.29k
  ValueTy *getValPtr() const { return static_cast<ValueTy *>(getRawValPtr()); }
llvm::AssertingVH<llvm::LoadInst>::getValPtr() const
Line
Count
Source
256
14.4k
  ValueTy *getValPtr() const { return static_cast<ValueTy *>(getRawValPtr()); }
llvm::AssertingVH<llvm::AllocaInst>::getValPtr() const
Line
Count
Source
256
1.07k
  ValueTy *getValPtr() const { return static_cast<ValueTy *>(getRawValPtr()); }
257
31.1M
  void setValPtr(ValueTy *P) { setRawValPtr(GetAsValue(P)); }
llvm::AssertingVH<llvm::Value>::setValPtr(llvm::Value*)
Line
Count
Source
257
22.7M
  void setValPtr(ValueTy *P) { setRawValPtr(GetAsValue(P)); }
llvm::AssertingVH<llvm::PHINode>::setValPtr(llvm::PHINode*)
Line
Count
Source
257
2.61k
  void setValPtr(ValueTy *P) { setRawValPtr(GetAsValue(P)); }
llvm::AssertingVH<llvm::Value const>::setValPtr(llvm::Value const*)
Line
Count
Source
257
12
  void setValPtr(ValueTy *P) { setRawValPtr(GetAsValue(P)); }
Unexecuted instantiation: llvm::AssertingVH<llvm::MemoryPhi>::setValPtr(llvm::MemoryPhi*)
llvm::AssertingVH<llvm::GetElementPtrInst>::setValPtr(llvm::GetElementPtrInst*)
Line
Count
Source
257
123k
  void setValPtr(ValueTy *P) { setRawValPtr(GetAsValue(P)); }
llvm::AssertingVH<llvm::BasicBlock>::setValPtr(llvm::BasicBlock*)
Line
Count
Source
257
7.07M
  void setValPtr(ValueTy *P) { setRawValPtr(GetAsValue(P)); }
llvm::AssertingVH<llvm::Function>::setValPtr(llvm::Function*)
Line
Count
Source
257
326
  void setValPtr(ValueTy *P) { setRawValPtr(GetAsValue(P)); }
llvm::AssertingVH<llvm::Instruction>::setValPtr(llvm::Instruction*)
Line
Count
Source
257
1.22M
  void setValPtr(ValueTy *P) { setRawValPtr(GetAsValue(P)); }
llvm::AssertingVH<llvm::Constant>::setValPtr(llvm::Constant*)
Line
Count
Source
257
229
  void setValPtr(ValueTy *P) { setRawValPtr(GetAsValue(P)); }
llvm::AssertingVH<llvm::LoadInst>::setValPtr(llvm::LoadInst*)
Line
Count
Source
257
6.10k
  void setValPtr(ValueTy *P) { setRawValPtr(GetAsValue(P)); }
llvm::AssertingVH<llvm::AllocaInst>::setValPtr(llvm::AllocaInst*)
Line
Count
Source
257
165
  void setValPtr(ValueTy *P) { setRawValPtr(GetAsValue(P)); }
258
259
public:
260
#ifndef NDEBUG
261
  AssertingVH() : ValueHandleBase(Assert) {}
262
  AssertingVH(ValueTy *P) : ValueHandleBase(Assert, GetAsValue(P)) {}
263
  AssertingVH(const AssertingVH &RHS) : ValueHandleBase(Assert, RHS) {}
264
#else
265
249M
  AssertingVH() : ThePtr(nullptr) {}
llvm::AssertingVH<llvm::Value>::AssertingVH()
Line
Count
Source
265
53.4M
  AssertingVH() : ThePtr(nullptr) {}
llvm::AssertingVH<llvm::PHINode>::AssertingVH()
Line
Count
Source
265
9.42k
  AssertingVH() : ThePtr(nullptr) {}
llvm::AssertingVH<llvm::Value const>::AssertingVH()
Line
Count
Source
265
70
  AssertingVH() : ThePtr(nullptr) {}
llvm::AssertingVH<llvm::GetElementPtrInst>::AssertingVH()
Line
Count
Source
265
124k
  AssertingVH() : ThePtr(nullptr) {}
llvm::AssertingVH<llvm::Function>::AssertingVH()
Line
Count
Source
265
811
  AssertingVH() : ThePtr(nullptr) {}
llvm::AssertingVH<llvm::BasicBlock>::AssertingVH()
Line
Count
Source
265
30.8M
  AssertingVH() : ThePtr(nullptr) {}
llvm::AssertingVH<llvm::Instruction>::AssertingVH()
Line
Count
Source
265
164M
  AssertingVH() : ThePtr(nullptr) {}
llvm::AssertingVH<llvm::LoadInst>::AssertingVH()
Line
Count
Source
265
55.0k
  AssertingVH() : ThePtr(nullptr) {}
llvm::AssertingVH<llvm::AllocaInst>::AssertingVH()
Line
Count
Source
265
165
  AssertingVH() : ThePtr(nullptr) {}
266
44.1M
  AssertingVH(ValueTy *P) : ThePtr(GetAsValue(P)) {}
llvm::AssertingVH<llvm::BasicBlock>::AssertingVH(llvm::BasicBlock*)
Line
Count
Source
266
16.2M
  AssertingVH(ValueTy *P) : ThePtr(GetAsValue(P)) {}
llvm::AssertingVH<llvm::Value const>::AssertingVH(llvm::Value const*)
Line
Count
Source
266
2.05M
  AssertingVH(ValueTy *P) : ThePtr(GetAsValue(P)) {}
llvm::AssertingVH<llvm::MemoryPhi>::AssertingVH(llvm::MemoryPhi*)
Line
Count
Source
266
1.29k
  AssertingVH(ValueTy *P) : ThePtr(GetAsValue(P)) {}
llvm::AssertingVH<llvm::Value>::AssertingVH(llvm::Value*)
Line
Count
Source
266
17.0M
  AssertingVH(ValueTy *P) : ThePtr(GetAsValue(P)) {}
llvm::AssertingVH<llvm::PHINode>::AssertingVH(llvm::PHINode*)
Line
Count
Source
266
4.62k
  AssertingVH(ValueTy *P) : ThePtr(GetAsValue(P)) {}
llvm::AssertingVH<llvm::GetElementPtrInst>::AssertingVH(llvm::GetElementPtrInst*)
Line
Count
Source
266
8.31M
  AssertingVH(ValueTy *P) : ThePtr(GetAsValue(P)) {}
llvm::AssertingVH<llvm::Function>::AssertingVH(llvm::Function*)
Line
Count
Source
266
40.8k
  AssertingVH(ValueTy *P) : ThePtr(GetAsValue(P)) {}
llvm::AssertingVH<llvm::Instruction>::AssertingVH(llvm::Instruction*)
Line
Count
Source
266
363k
  AssertingVH(ValueTy *P) : ThePtr(GetAsValue(P)) {}
llvm::AssertingVH<llvm::Constant>::AssertingVH(llvm::Constant*)
Line
Count
Source
266
229
  AssertingVH(ValueTy *P) : ThePtr(GetAsValue(P)) {}
llvm::AssertingVH<llvm::LoadInst>::AssertingVH(llvm::LoadInst*)
Line
Count
Source
266
32.1k
  AssertingVH(ValueTy *P) : ThePtr(GetAsValue(P)) {}
267
#endif
268
269
14.3M
  operator ValueTy*() const {
270
14.3M
    return getValPtr();
271
14.3M
  }
llvm::AssertingVH<llvm::BasicBlock>::operator llvm::BasicBlock*() const
Line
Count
Source
269
3.46M
  operator ValueTy*() const {
270
3.46M
    return getValPtr();
271
3.46M
  }
llvm::AssertingVH<llvm::MemoryPhi>::operator llvm::MemoryPhi*() const
Line
Count
Source
269
68
  operator ValueTy*() const {
270
68
    return getValPtr();
271
68
  }
llvm::AssertingVH<llvm::GetElementPtrInst>::operator llvm::GetElementPtrInst*() const
Line
Count
Source
269
7.91M
  operator ValueTy*() const {
270
7.91M
    return getValPtr();
271
7.91M
  }
llvm::AssertingVH<llvm::Value>::operator llvm::Value*() const
Line
Count
Source
269
384k
  operator ValueTy*() const {
270
384k
    return getValPtr();
271
384k
  }
llvm::AssertingVH<llvm::Function>::operator llvm::Function*() const
Line
Count
Source
269
29.1k
  operator ValueTy*() const {
270
29.1k
    return getValPtr();
271
29.1k
  }
llvm::AssertingVH<llvm::Instruction>::operator llvm::Instruction*() const
Line
Count
Source
269
2.46M
  operator ValueTy*() const {
270
2.46M
    return getValPtr();
271
2.46M
  }
llvm::AssertingVH<llvm::Constant>::operator llvm::Constant*() const
Line
Count
Source
269
646
  operator ValueTy*() const {
270
646
    return getValPtr();
271
646
  }
llvm::AssertingVH<llvm::Value const>::operator llvm::Value const*() const
Line
Count
Source
269
42.8k
  operator ValueTy*() const {
270
42.8k
    return getValPtr();
271
42.8k
  }
llvm::AssertingVH<llvm::LoadInst>::operator llvm::LoadInst*() const
Line
Count
Source
269
2.24k
  operator ValueTy*() const {
270
2.24k
    return getValPtr();
271
2.24k
  }
llvm::AssertingVH<llvm::AllocaInst>::operator llvm::AllocaInst*() const
Line
Count
Source
269
602
  operator ValueTy*() const {
270
602
    return getValPtr();
271
602
  }
272
273
801k
  ValueTy *operator=(ValueTy *RHS) {
274
801k
    setValPtr(RHS);
275
801k
    return getValPtr();
276
801k
  }
llvm::AssertingVH<llvm::GetElementPtrInst>::operator=(llvm::GetElementPtrInst*)
Line
Count
Source
273
19.9k
  ValueTy *operator=(ValueTy *RHS) {
274
19.9k
    setValPtr(RHS);
275
19.9k
    return getValPtr();
276
19.9k
  }
llvm::AssertingVH<llvm::Function>::operator=(llvm::Function*)
Line
Count
Source
273
20
  ValueTy *operator=(ValueTy *RHS) {
274
20
    setValPtr(RHS);
275
20
    return getValPtr();
276
20
  }
llvm::AssertingVH<llvm::Value>::operator=(llvm::Value*)
Line
Count
Source
273
3.01k
  ValueTy *operator=(ValueTy *RHS) {
274
3.01k
    setValPtr(RHS);
275
3.01k
    return getValPtr();
276
3.01k
  }
llvm::AssertingVH<llvm::Instruction>::operator=(llvm::Instruction*)
Line
Count
Source
273
777k
  ValueTy *operator=(ValueTy *RHS) {
274
777k
    setValPtr(RHS);
275
777k
    return getValPtr();
276
777k
  }
llvm::AssertingVH<llvm::Constant>::operator=(llvm::Constant*)
Line
Count
Source
273
229
  ValueTy *operator=(ValueTy *RHS) {
274
229
    setValPtr(RHS);
275
229
    return getValPtr();
276
229
  }
llvm::AssertingVH<llvm::AllocaInst>::operator=(llvm::AllocaInst*)
Line
Count
Source
273
165
  ValueTy *operator=(ValueTy *RHS) {
274
165
    setValPtr(RHS);
275
165
    return getValPtr();
276
165
  }
277
30.3M
  ValueTy *operator=(const AssertingVH<ValueTy> &RHS) {
278
30.3M
    setValPtr(RHS.getValPtr());
279
30.3M
    return getValPtr();
280
30.3M
  }
llvm::AssertingVH<llvm::Value>::operator=(llvm::AssertingVH<llvm::Value> const&)
Line
Count
Source
277
22.7M
  ValueTy *operator=(const AssertingVH<ValueTy> &RHS) {
278
22.7M
    setValPtr(RHS.getValPtr());
279
22.7M
    return getValPtr();
280
22.7M
  }
llvm::AssertingVH<llvm::PHINode>::operator=(llvm::AssertingVH<llvm::PHINode> const&)
Line
Count
Source
277
2.61k
  ValueTy *operator=(const AssertingVH<ValueTy> &RHS) {
278
2.61k
    setValPtr(RHS.getValPtr());
279
2.61k
    return getValPtr();
280
2.61k
  }
llvm::AssertingVH<llvm::Value const>::operator=(llvm::AssertingVH<llvm::Value const> const&)
Line
Count
Source
277
12
  ValueTy *operator=(const AssertingVH<ValueTy> &RHS) {
278
12
    setValPtr(RHS.getValPtr());
279
12
    return getValPtr();
280
12
  }
Unexecuted instantiation: llvm::AssertingVH<llvm::MemoryPhi>::operator=(llvm::AssertingVH<llvm::MemoryPhi> const&)
llvm::AssertingVH<llvm::GetElementPtrInst>::operator=(llvm::AssertingVH<llvm::GetElementPtrInst> const&)
Line
Count
Source
277
103k
  ValueTy *operator=(const AssertingVH<ValueTy> &RHS) {
278
103k
    setValPtr(RHS.getValPtr());
279
103k
    return getValPtr();
280
103k
  }
llvm::AssertingVH<llvm::BasicBlock>::operator=(llvm::AssertingVH<llvm::BasicBlock> const&)
Line
Count
Source
277
7.07M
  ValueTy *operator=(const AssertingVH<ValueTy> &RHS) {
278
7.07M
    setValPtr(RHS.getValPtr());
279
7.07M
    return getValPtr();
280
7.07M
  }
llvm::AssertingVH<llvm::Function>::operator=(llvm::AssertingVH<llvm::Function> const&)
Line
Count
Source
277
306
  ValueTy *operator=(const AssertingVH<ValueTy> &RHS) {
278
306
    setValPtr(RHS.getValPtr());
279
306
    return getValPtr();
280
306
  }
llvm::AssertingVH<llvm::Instruction>::operator=(llvm::AssertingVH<llvm::Instruction> const&)
Line
Count
Source
277
448k
  ValueTy *operator=(const AssertingVH<ValueTy> &RHS) {
278
448k
    setValPtr(RHS.getValPtr());
279
448k
    return getValPtr();
280
448k
  }
llvm::AssertingVH<llvm::LoadInst>::operator=(llvm::AssertingVH<llvm::LoadInst> const&)
Line
Count
Source
277
6.10k
  ValueTy *operator=(const AssertingVH<ValueTy> &RHS) {
278
6.10k
    setValPtr(RHS.getValPtr());
279
6.10k
    return getValPtr();
280
6.10k
  }
281
282
11.8k
  ValueTy *operator->() const { return getValPtr(); }
llvm::AssertingVH<llvm::MemoryPhi>::operator->() const
Line
Count
Source
282
6
  ValueTy *operator->() const { return getValPtr(); }
llvm::AssertingVH<llvm::Instruction>::operator->() const
Line
Count
Source
282
11.6k
  ValueTy *operator->() const { return getValPtr(); }
llvm::AssertingVH<llvm::Value>::operator->() const
Line
Count
Source
282
8
  ValueTy *operator->() const { return getValPtr(); }
llvm::AssertingVH<llvm::AllocaInst>::operator->() const
Line
Count
Source
282
131
  ValueTy *operator->() const { return getValPtr(); }
283
107k
  ValueTy &operator*() const { return *getValPtr(); }
llvm::AssertingVH<llvm::MemoryPhi>::operator*() const
Line
Count
Source
283
4
  ValueTy &operator*() const { return *getValPtr(); }
llvm::AssertingVH<llvm::Value>::operator*() const
Line
Count
Source
283
66.9k
  ValueTy &operator*() const { return *getValPtr(); }
llvm::AssertingVH<llvm::Function>::operator*() const
Line
Count
Source
283
40.3k
  ValueTy &operator*() const { return *getValPtr(); }
llvm::AssertingVH<llvm::Constant>::operator*() const
Line
Count
Source
283
417
  ValueTy &operator*() const { return *getValPtr(); }
llvm::AssertingVH<llvm::AllocaInst>::operator*() const
Line
Count
Source
283
172
  ValueTy &operator*() const { return *getValPtr(); }
284
};
285
286
// Specialize DenseMapInfo to allow AssertingVH to participate in DenseMap.
287
template<typename T>
288
struct DenseMapInfo<AssertingVH<T>> {
289
183M
  static inline AssertingVH<T> getEmptyKey() {
290
183M
    AssertingVH<T> Res;
291
183M
    Res.setRawValPtr(DenseMapInfo<Value *>::getEmptyKey());
292
183M
    return Res;
293
183M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Value const> >::getEmptyKey()
Line
Count
Source
289
37
  static inline AssertingVH<T> getEmptyKey() {
290
37
    AssertingVH<T> Res;
291
37
    Res.setRawValPtr(DenseMapInfo<Value *>::getEmptyKey());
292
37
    return Res;
293
37
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Value> >::getEmptyKey()
Line
Count
Source
289
32.4M
  static inline AssertingVH<T> getEmptyKey() {
290
32.4M
    AssertingVH<T> Res;
291
32.4M
    Res.setRawValPtr(DenseMapInfo<Value *>::getEmptyKey());
292
32.4M
    return Res;
293
32.4M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::PHINode> >::getEmptyKey()
Line
Count
Source
289
5.91k
  static inline AssertingVH<T> getEmptyKey() {
290
5.91k
    AssertingVH<T> Res;
291
5.91k
    Res.setRawValPtr(DenseMapInfo<Value *>::getEmptyKey());
292
5.91k
    return Res;
293
5.91k
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::GetElementPtrInst> >::getEmptyKey()
Line
Count
Source
289
67.7k
  static inline AssertingVH<T> getEmptyKey() {
290
67.7k
    AssertingVH<T> Res;
291
67.7k
    Res.setRawValPtr(DenseMapInfo<Value *>::getEmptyKey());
292
67.7k
    return Res;
293
67.7k
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Function> >::getEmptyKey()
Line
Count
Source
289
494
  static inline AssertingVH<T> getEmptyKey() {
290
494
    AssertingVH<T> Res;
291
494
    Res.setRawValPtr(DenseMapInfo<Value *>::getEmptyKey());
292
494
    return Res;
293
494
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::BasicBlock> >::getEmptyKey()
Line
Count
Source
289
17.2M
  static inline AssertingVH<T> getEmptyKey() {
290
17.2M
    AssertingVH<T> Res;
291
17.2M
    Res.setRawValPtr(DenseMapInfo<Value *>::getEmptyKey());
292
17.2M
    return Res;
293
17.2M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Instruction> >::getEmptyKey()
Line
Count
Source
289
133M
  static inline AssertingVH<T> getEmptyKey() {
290
133M
    AssertingVH<T> Res;
291
133M
    Res.setRawValPtr(DenseMapInfo<Value *>::getEmptyKey());
292
133M
    return Res;
293
133M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::LoadInst> >::getEmptyKey()
Line
Count
Source
289
32.2k
  static inline AssertingVH<T> getEmptyKey() {
290
32.2k
    AssertingVH<T> Res;
291
32.2k
    Res.setRawValPtr(DenseMapInfo<Value *>::getEmptyKey());
292
32.2k
    return Res;
293
32.2k
  }
294
295
65.2M
  static inline AssertingVH<T> getTombstoneKey() {
296
65.2M
    AssertingVH<T> Res;
297
65.2M
    Res.setRawValPtr(DenseMapInfo<Value *>::getTombstoneKey());
298
65.2M
    return Res;
299
65.2M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Value const> >::getTombstoneKey()
Line
Count
Source
295
33
  static inline AssertingVH<T> getTombstoneKey() {
296
33
    AssertingVH<T> Res;
297
33
    Res.setRawValPtr(DenseMapInfo<Value *>::getTombstoneKey());
298
33
    return Res;
299
33
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Value> >::getTombstoneKey()
Line
Count
Source
295
20.9M
  static inline AssertingVH<T> getTombstoneKey() {
296
20.9M
    AssertingVH<T> Res;
297
20.9M
    Res.setRawValPtr(DenseMapInfo<Value *>::getTombstoneKey());
298
20.9M
    return Res;
299
20.9M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::PHINode> >::getTombstoneKey()
Line
Count
Source
295
3.51k
  static inline AssertingVH<T> getTombstoneKey() {
296
3.51k
    AssertingVH<T> Res;
297
3.51k
    Res.setRawValPtr(DenseMapInfo<Value *>::getTombstoneKey());
298
3.51k
    return Res;
299
3.51k
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::GetElementPtrInst> >::getTombstoneKey()
Line
Count
Source
295
57.1k
  static inline AssertingVH<T> getTombstoneKey() {
296
57.1k
    AssertingVH<T> Res;
297
57.1k
    Res.setRawValPtr(DenseMapInfo<Value *>::getTombstoneKey());
298
57.1k
    return Res;
299
57.1k
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Function> >::getTombstoneKey()
Line
Count
Source
295
317
  static inline AssertingVH<T> getTombstoneKey() {
296
317
    AssertingVH<T> Res;
297
317
    Res.setRawValPtr(DenseMapInfo<Value *>::getTombstoneKey());
298
317
    return Res;
299
317
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::BasicBlock> >::getTombstoneKey()
Line
Count
Source
295
13.5M
  static inline AssertingVH<T> getTombstoneKey() {
296
13.5M
    AssertingVH<T> Res;
297
13.5M
    Res.setRawValPtr(DenseMapInfo<Value *>::getTombstoneKey());
298
13.5M
    return Res;
299
13.5M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Instruction> >::getTombstoneKey()
Line
Count
Source
295
30.6M
  static inline AssertingVH<T> getTombstoneKey() {
296
30.6M
    AssertingVH<T> Res;
297
30.6M
    Res.setRawValPtr(DenseMapInfo<Value *>::getTombstoneKey());
298
30.6M
    return Res;
299
30.6M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::LoadInst> >::getTombstoneKey()
Line
Count
Source
295
22.8k
  static inline AssertingVH<T> getTombstoneKey() {
296
22.8k
    AssertingVH<T> Res;
297
22.8k
    Res.setRawValPtr(DenseMapInfo<Value *>::getTombstoneKey());
298
22.8k
    return Res;
299
22.8k
  }
300
301
34.0M
  static unsigned getHashValue(const AssertingVH<T> &Val) {
302
34.0M
    return DenseMapInfo<Value *>::getHashValue(Val.getRawValPtr());
303
34.0M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Value> >::getHashValue(llvm::AssertingVH<llvm::Value> const&)
Line
Count
Source
301
20.0M
  static unsigned getHashValue(const AssertingVH<T> &Val) {
302
20.0M
    return DenseMapInfo<Value *>::getHashValue(Val.getRawValPtr());
303
20.0M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::PHINode> >::getHashValue(llvm::AssertingVH<llvm::PHINode> const&)
Line
Count
Source
301
1.30k
  static unsigned getHashValue(const AssertingVH<T> &Val) {
302
1.30k
    return DenseMapInfo<Value *>::getHashValue(Val.getRawValPtr());
303
1.30k
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Value const> >::getHashValue(llvm::AssertingVH<llvm::Value const> const&)
Line
Count
Source
301
23
  static unsigned getHashValue(const AssertingVH<T> &Val) {
302
23
    return DenseMapInfo<Value *>::getHashValue(Val.getRawValPtr());
303
23
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::GetElementPtrInst> >::getHashValue(llvm::AssertingVH<llvm::GetElementPtrInst> const&)
Line
Count
Source
301
46.0k
  static unsigned getHashValue(const AssertingVH<T> &Val) {
302
46.0k
    return DenseMapInfo<Value *>::getHashValue(Val.getRawValPtr());
303
46.0k
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::BasicBlock> >::getHashValue(llvm::AssertingVH<llvm::BasicBlock> const&)
Line
Count
Source
301
13.4M
  static unsigned getHashValue(const AssertingVH<T> &Val) {
302
13.4M
    return DenseMapInfo<Value *>::getHashValue(Val.getRawValPtr());
303
13.4M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Function> >::getHashValue(llvm::AssertingVH<llvm::Function> const&)
Line
Count
Source
301
178
  static unsigned getHashValue(const AssertingVH<T> &Val) {
302
178
    return DenseMapInfo<Value *>::getHashValue(Val.getRawValPtr());
303
178
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Instruction> >::getHashValue(llvm::AssertingVH<llvm::Instruction> const&)
Line
Count
Source
301
502k
  static unsigned getHashValue(const AssertingVH<T> &Val) {
302
502k
    return DenseMapInfo<Value *>::getHashValue(Val.getRawValPtr());
303
502k
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::LoadInst> >::getHashValue(llvm::AssertingVH<llvm::LoadInst> const&)
Line
Count
Source
301
19.6k
  static unsigned getHashValue(const AssertingVH<T> &Val) {
302
19.6k
    return DenseMapInfo<Value *>::getHashValue(Val.getRawValPtr());
303
19.6k
  }
304
305
564M
  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
306
564M
    return DenseMapInfo<Value *>::isEqual(LHS.getRawValPtr(),
307
564M
                                          RHS.getRawValPtr());
308
564M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Value const> >::isEqual(llvm::AssertingVH<llvm::Value const> const&, llvm::AssertingVH<llvm::Value const> const&)
Line
Count
Source
305
301
  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
306
301
    return DenseMapInfo<Value *>::isEqual(LHS.getRawValPtr(),
307
301
                                          RHS.getRawValPtr());
308
301
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Value> >::isEqual(llvm::AssertingVH<llvm::Value> const&, llvm::AssertingVH<llvm::Value> const&)
Line
Count
Source
305
183M
  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
306
183M
    return DenseMapInfo<Value *>::isEqual(LHS.getRawValPtr(),
307
183M
                                          RHS.getRawValPtr());
308
183M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::PHINode> >::isEqual(llvm::AssertingVH<llvm::PHINode> const&, llvm::AssertingVH<llvm::PHINode> const&)
Line
Count
Source
305
146k
  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
306
146k
    return DenseMapInfo<Value *>::isEqual(LHS.getRawValPtr(),
307
146k
                                          RHS.getRawValPtr());
308
146k
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::GetElementPtrInst> >::isEqual(llvm::AssertingVH<llvm::GetElementPtrInst> const&, llvm::AssertingVH<llvm::GetElementPtrInst> const&)
Line
Count
Source
305
450k
  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
306
450k
    return DenseMapInfo<Value *>::isEqual(LHS.getRawValPtr(),
307
450k
                                          RHS.getRawValPtr());
308
450k
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Function> >::isEqual(llvm::AssertingVH<llvm::Function> const&, llvm::AssertingVH<llvm::Function> const&)
Line
Count
Source
305
8.06k
  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
306
8.06k
    return DenseMapInfo<Value *>::isEqual(LHS.getRawValPtr(),
307
8.06k
                                          RHS.getRawValPtr());
308
8.06k
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::BasicBlock> >::isEqual(llvm::AssertingVH<llvm::BasicBlock> const&, llvm::AssertingVH<llvm::BasicBlock> const&)
Line
Count
Source
305
58.9M
  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
306
58.9M
    return DenseMapInfo<Value *>::isEqual(LHS.getRawValPtr(),
307
58.9M
                                          RHS.getRawValPtr());
308
58.9M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::Instruction> >::isEqual(llvm::AssertingVH<llvm::Instruction> const&, llvm::AssertingVH<llvm::Instruction> const&)
Line
Count
Source
305
321M
  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
306
321M
    return DenseMapInfo<Value *>::isEqual(LHS.getRawValPtr(),
307
321M
                                          RHS.getRawValPtr());
308
321M
  }
llvm::DenseMapInfo<llvm::AssertingVH<llvm::LoadInst> >::isEqual(llvm::AssertingVH<llvm::LoadInst> const&, llvm::AssertingVH<llvm::LoadInst> const&)
Line
Count
Source
305
250k
  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
306
250k
    return DenseMapInfo<Value *>::isEqual(LHS.getRawValPtr(),
307
250k
                                          RHS.getRawValPtr());
308
250k
  }
309
};
310
311
/// Value handle that tracks a Value across RAUW.
312
///
313
/// TrackingVH is designed for situations where a client needs to hold a handle
314
/// to a Value (or subclass) across some operations which may move that value,
315
/// but should never destroy it or replace it with some unacceptable type.
316
///
317
/// It is an error to attempt to replace a value with one of a type which is
318
/// incompatible with any of its outstanding TrackingVHs.
319
///
320
/// It is an error to read from a TrackingVH that does not point to a valid
321
/// value.  A TrackingVH is said to not point to a valid value if either it
322
/// hasn't yet been assigned a value yet or because the value it was tracking
323
/// has since been deleted.
324
///
325
/// Assigning a value to a TrackingVH is always allowed, even if said TrackingVH
326
/// no longer points to a valid value.
327
template <typename ValueTy> class TrackingVH {
328
  WeakTrackingVH InnerHandle;
329
330
public:
331
4.37M
  ValueTy *getValPtr() const {
332
4.37M
    assert(InnerHandle.pointsToAliveValue() &&
333
4.37M
           "TrackingVH must be non-null and valid on dereference!");
334
4.37M
335
4.37M
    // Check that the value is a member of the correct subclass. We would like
336
4.37M
    // to check this property on assignment for better debugging, but we don't
337
4.37M
    // want to require a virtual interface on this VH. Instead we allow RAUW to
338
4.37M
    // replace this value with a value of an invalid type, and check it here.
339
4.37M
    assert(isa<ValueTy>(InnerHandle) &&
340
4.37M
           "Tracked Value was replaced by one with an invalid type!");
341
4.37M
    return cast<ValueTy>(InnerHandle);
342
4.37M
  }
llvm::TrackingVH<llvm::Value>::getValPtr() const
Line
Count
Source
331
4.37M
  ValueTy *getValPtr() const {
332
4.37M
    assert(InnerHandle.pointsToAliveValue() &&
333
4.37M
           "TrackingVH must be non-null and valid on dereference!");
334
4.37M
335
4.37M
    // Check that the value is a member of the correct subclass. We would like
336
4.37M
    // to check this property on assignment for better debugging, but we don't
337
4.37M
    // want to require a virtual interface on this VH. Instead we allow RAUW to
338
4.37M
    // replace this value with a value of an invalid type, and check it here.
339
4.37M
    assert(isa<ValueTy>(InnerHandle) &&
340
4.37M
           "Tracked Value was replaced by one with an invalid type!");
341
4.37M
    return cast<ValueTy>(InnerHandle);
342
4.37M
  }
llvm::TrackingVH<llvm::MemoryAccess>::getValPtr() const
Line
Count
Source
331
432
  ValueTy *getValPtr() const {
332
432
    assert(InnerHandle.pointsToAliveValue() &&
333
432
           "TrackingVH must be non-null and valid on dereference!");
334
432
335
432
    // Check that the value is a member of the correct subclass. We would like
336
432
    // to check this property on assignment for better debugging, but we don't
337
432
    // want to require a virtual interface on this VH. Instead we allow RAUW to
338
432
    // replace this value with a value of an invalid type, and check it here.
339
432
    assert(isa<ValueTy>(InnerHandle) &&
340
432
           "Tracked Value was replaced by one with an invalid type!");
341
432
    return cast<ValueTy>(InnerHandle);
342
432
  }
llvm::TrackingVH<llvm::Constant>::getValPtr() const
Line
Count
Source
331
266
  ValueTy *getValPtr() const {
332
266
    assert(InnerHandle.pointsToAliveValue() &&
333
266
           "TrackingVH must be non-null and valid on dereference!");
334
266
335
266
    // Check that the value is a member of the correct subclass. We would like
336
266
    // to check this property on assignment for better debugging, but we don't
337
266
    // want to require a virtual interface on this VH. Instead we allow RAUW to
338
266
    // replace this value with a value of an invalid type, and check it here.
339
266
    assert(isa<ValueTy>(InnerHandle) &&
340
266
           "Tracked Value was replaced by one with an invalid type!");
341
266
    return cast<ValueTy>(InnerHandle);
342
266
  }
343
344
2.87M
  void setValPtr(ValueTy *P) {
345
2.87M
    // Assigning to non-valid TrackingVH's are fine so we just unconditionally
346
2.87M
    // assign here.
347
2.87M
    InnerHandle = GetAsValue(P);
348
2.87M
  }
llvm::TrackingVH<llvm::Value>::setValPtr(llvm::Value*)
Line
Count
Source
344
2.87M
  void setValPtr(ValueTy *P) {
345
2.87M
    // Assigning to non-valid TrackingVH's are fine so we just unconditionally
346
2.87M
    // assign here.
347
2.87M
    InnerHandle = GetAsValue(P);
348
2.87M
  }
llvm::TrackingVH<llvm::MemoryAccess>::setValPtr(llvm::MemoryAccess*)
Line
Count
Source
344
652
  void setValPtr(ValueTy *P) {
345
652
    // Assigning to non-valid TrackingVH's are fine so we just unconditionally
346
652
    // assign here.
347
652
    InnerHandle = GetAsValue(P);
348
652
  }
llvm::TrackingVH<llvm::Constant>::setValPtr(llvm::Constant*)
Line
Count
Source
344
139
  void setValPtr(ValueTy *P) {
345
139
    // Assigning to non-valid TrackingVH's are fine so we just unconditionally
346
139
    // assign here.
347
139
    InnerHandle = GetAsValue(P);
348
139
  }
349
350
  // Convert a ValueTy*, which may be const, to the type the base
351
  // class expects.
352
2.87M
  static Value *GetAsValue(Value *V) { return V; }
llvm::TrackingVH<llvm::Value>::GetAsValue(llvm::Value*)
Line
Count
Source
352
2.87M
  static Value *GetAsValue(Value *V) { return V; }
llvm::TrackingVH<llvm::MemoryAccess>::GetAsValue(llvm::Value*)
Line
Count
Source
352
652
  static Value *GetAsValue(Value *V) { return V; }
llvm::TrackingVH<llvm::Constant>::GetAsValue(llvm::Value*)
Line
Count
Source
352
139
  static Value *GetAsValue(Value *V) { return V; }
353
  static Value *GetAsValue(const Value *V) { return const_cast<Value*>(V); }
354
355
public:
356
2.97M
  TrackingVH() = default;
llvm::TrackingVH<llvm::Value>::TrackingVH()
Line
Count
Source
356
2.97M
  TrackingVH() = default;
llvm::TrackingVH<llvm::Constant>::TrackingVH()
Line
Count
Source
356
127
  TrackingVH() = default;
357
189k
  TrackingVH(ValueTy *P) { setValPtr(P); }
llvm::TrackingVH<llvm::Value>::TrackingVH(llvm::Value*)
Line
Count
Source
357
188k
  TrackingVH(ValueTy *P) { setValPtr(P); }
llvm::TrackingVH<llvm::MemoryAccess>::TrackingVH(llvm::MemoryAccess*)
Line
Count
Source
357
652
  TrackingVH(ValueTy *P) { setValPtr(P); }
358
359
1.67M
  operator ValueTy*() const {
360
1.67M
    return getValPtr();
361
1.67M
  }
llvm::TrackingVH<llvm::Value>::operator llvm::Value*() const
Line
Count
Source
359
1.67M
  operator ValueTy*() const {
360
1.67M
    return getValPtr();
361
1.67M
  }
llvm::TrackingVH<llvm::MemoryAccess>::operator llvm::MemoryAccess*() const
Line
Count
Source
359
404
  operator ValueTy*() const {
360
404
    return getValPtr();
361
404
  }
llvm::TrackingVH<llvm::Constant>::operator llvm::Constant*() const
Line
Count
Source
359
127
  operator ValueTy*() const {
360
127
    return getValPtr();
361
127
  }
362
363
2.68M
  ValueTy *operator=(ValueTy *RHS) {
364
2.68M
    setValPtr(RHS);
365
2.68M
    return getValPtr();
366
2.68M
  }
llvm::TrackingVH<llvm::Value>::operator=(llvm::Value*)
Line
Count
Source
363
2.68M
  ValueTy *operator=(ValueTy *RHS) {
364
2.68M
    setValPtr(RHS);
365
2.68M
    return getValPtr();
366
2.68M
  }
llvm::TrackingVH<llvm::Constant>::operator=(llvm::Constant*)
Line
Count
Source
363
139
  ValueTy *operator=(ValueTy *RHS) {
364
139
    setValPtr(RHS);
365
139
    return getValPtr();
366
139
  }
367
368
6.82k
  ValueTy *operator->() const { return getValPtr(); }
369
1.05k
  ValueTy &operator*() const { return *getValPtr(); }
llvm::TrackingVH<llvm::Value>::operator*() const
Line
Count
Source
369
1.02k
  ValueTy &operator*() const { return *getValPtr(); }
llvm::TrackingVH<llvm::MemoryAccess>::operator*() const
Line
Count
Source
369
28
  ValueTy &operator*() const { return *getValPtr(); }
370
};
371
372
/// Value handle with callbacks on RAUW and destruction.
373
///
374
/// This is a value handle that allows subclasses to define callbacks that run
375
/// when the underlying Value has RAUW called on it or is destroyed.  This
376
/// class can be used as the key of a map, as long as the user takes it out of
377
/// the map before calling setValPtr() (since the map has to rearrange itself
378
/// when the pointer changes).  Unlike ValueHandleBase, this class has a vtable.
379
class CallbackVH : public ValueHandleBase {
380
  virtual void anchor();
381
protected:
382
1.02G
  ~CallbackVH() = default;
383
480M
  CallbackVH(const CallbackVH &) = default;
384
64.8M
  CallbackVH &operator=(const CallbackVH &) = default;
385
386
128k
  void setValPtr(Value *P) {
387
128k
    ValueHandleBase::operator=(P);
388
128k
  }
389
390
public:
391
  CallbackVH() : ValueHandleBase(Callback) {}
392
542M
  CallbackVH(Value *P) : ValueHandleBase(Callback, P) {}
393
394
2.51G
  operator Value*() const {
395
2.51G
    return getValPtr();
396
2.51G
  }
397
398
  /// Callback for Value destruction.
399
  ///
400
  /// Called when this->getValPtr() is destroyed, inside ~Value(), so you
401
  /// may call any non-virtual Value method on getValPtr(), but no subclass
402
  /// methods.  If WeakTrackingVH were implemented as a CallbackVH, it would use
403
  /// this
404
  /// method to call setValPtr(NULL).  AssertingVH would use this method to
405
  /// cause an assertion failure.
406
  ///
407
  /// All implementations must remove the reference from this object to the
408
  /// Value that's being destroyed.
409
6
  virtual void deleted() { setValPtr(nullptr); }
410
411
  /// Callback for Value RAUW.
412
  ///
413
  /// Called when this->getValPtr()->replaceAllUsesWith(new_value) is called,
414
  /// _before_ any of the uses have actually been replaced.  If WeakTrackingVH
415
  /// were
416
  /// implemented as a CallbackVH, it would use this method to call
417
  /// setValPtr(new_value).  AssertingVH would do nothing in this method.
418
99.6k
  virtual void allUsesReplacedWith(Value *) {}
419
};
420
421
/// Value handle that poisons itself if the Value is deleted.
422
///
423
/// This is a Value Handle that points to a value and poisons itself if the
424
/// value is destroyed while the handle is still live.  This is very useful for
425
/// catching dangling pointer bugs where an \c AssertingVH cannot be used
426
/// because the dangling handle needs to outlive the value without ever being
427
/// used.
428
///
429
/// One particularly useful place to use this is as the Key of a map. Dangling
430
/// pointer bugs often lead to really subtle bugs that only occur if another
431
/// object happens to get allocated to the same address as the old one. Using
432
/// a PoisoningVH ensures that an assert is triggered if looking up a new value
433
/// in the map finds a handle from the old value.
434
///
435
/// Note that a PoisoningVH handle does *not* follow values across RAUW
436
/// operations. This means that RAUW's need to explicitly update the
437
/// PoisoningVH's as it moves. This is required because in non-assert mode this
438
/// class turns into a trivial wrapper around a pointer.
439
template <typename ValueTy>
440
class PoisoningVH
441
#ifndef NDEBUG
442
    final : public CallbackVH
443
#endif
444
{
445
  friend struct DenseMapInfo<PoisoningVH<ValueTy>>;
446
447
  // Convert a ValueTy*, which may be const, to the raw Value*.
448
203M
  static Value *GetAsValue(Value *V) { return V; }
449
  static Value *GetAsValue(const Value *V) { return const_cast<Value *>(V); }
450
451
#ifndef NDEBUG
452
  /// A flag tracking whether this value has been poisoned.
453
  ///
454
  /// On delete and RAUW, we leave the value pointer alone so that as a raw
455
  /// pointer it produces the same value (and we fit into the same key of
456
  /// a hash table, etc), but we poison the handle so that any top-level usage
457
  /// will fail.
458
  bool Poisoned = false;
459
460
  Value *getRawValPtr() const { return ValueHandleBase::getValPtr(); }
461
  void setRawValPtr(Value *P) { ValueHandleBase::operator=(P); }
462
463
  /// Handle deletion by poisoning the handle.
464
  void deleted() override {
465
    assert(!Poisoned && "Tried to delete an already poisoned handle!");
466
    Poisoned = true;
467
    RemoveFromUseList();
468
  }
469
470
  /// Handle RAUW by poisoning the handle.
471
  void allUsesReplacedWith(Value *) override {
472
    assert(!Poisoned && "Tried to RAUW an already poisoned handle!");
473
    Poisoned = true;
474
    RemoveFromUseList();
475
  }
476
#else // NDEBUG
477
  Value *ThePtr = nullptr;
478
479
1.57G
  Value *getRawValPtr() const { return ThePtr; }
480
454M
  void setRawValPtr(Value *P) { ThePtr = P; }
481
#endif
482
483
1.48M
  ValueTy *getValPtr() const {
484
1.48M
    assert(!Poisoned && "Accessed a poisoned value handle!");
485
1.48M
    return static_cast<ValueTy *>(getRawValPtr());
486
1.48M
  }
487
  void setValPtr(ValueTy *P) { setRawValPtr(GetAsValue(P)); }
488
489
public:
490
454M
  PoisoningVH() = default;
491
#ifndef NDEBUG
492
  PoisoningVH(ValueTy *P) : CallbackVH(GetAsValue(P)) {}
493
  PoisoningVH(const PoisoningVH &RHS)
494
      : CallbackVH(RHS), Poisoned(RHS.Poisoned) {}
495
496
  ~PoisoningVH() {
497
    if (Poisoned)
498
      clearValPtr();
499
  }
500
501
  PoisoningVH &operator=(const PoisoningVH &RHS) {
502
    if (Poisoned)
503
      clearValPtr();
504
    CallbackVH::operator=(RHS);
505
    Poisoned = RHS.Poisoned;
506
    return *this;
507
  }
508
#else
509
203M
  PoisoningVH(ValueTy *P) : ThePtr(GetAsValue(P)) {}
510
#endif
511
512
1.48M
  operator ValueTy *() const { return getValPtr(); }
513
514
  ValueTy *operator->() const { return getValPtr(); }
515
  ValueTy &operator*() const { return *getValPtr(); }
516
};
517
518
// Specialize DenseMapInfo to allow PoisoningVH to participate in DenseMap.
519
template <typename T> struct DenseMapInfo<PoisoningVH<T>> {
520
240M
  static inline PoisoningVH<T> getEmptyKey() {
521
240M
    PoisoningVH<T> Res;
522
240M
    Res.setRawValPtr(DenseMapInfo<Value *>::getEmptyKey());
523
240M
    return Res;
524
240M
  }
525
526
214M
  static inline PoisoningVH<T> getTombstoneKey() {
527
214M
    PoisoningVH<T> Res;
528
214M
    Res.setRawValPtr(DenseMapInfo<Value *>::getTombstoneKey());
529
214M
    return Res;
530
214M
  }
531
532
205M
  static unsigned getHashValue(const PoisoningVH<T> &Val) {
533
205M
    return DenseMapInfo<Value *>::getHashValue(Val.getRawValPtr());
534
205M
  }
535
536
685M
  static bool isEqual(const PoisoningVH<T> &LHS, const PoisoningVH<T> &RHS) {
537
685M
    return DenseMapInfo<Value *>::isEqual(LHS.getRawValPtr(),
538
685M
                                          RHS.getRawValPtr());
539
685M
  }
540
};
541
542
} // end namespace llvm
543
544
#endif // LLVM_IR_VALUEHANDLE_H