Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/IR/Value.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/Value.h - Definition of the Value class -------------*- 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 Value class.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_IR_VALUE_H
14
#define LLVM_IR_VALUE_H
15
16
#include "llvm-c/Types.h"
17
#include "llvm/ADT/iterator_range.h"
18
#include "llvm/IR/Use.h"
19
#include "llvm/Support/CBindingWrapping.h"
20
#include "llvm/Support/Casting.h"
21
#include <cassert>
22
#include <iterator>
23
#include <memory>
24
25
namespace llvm {
26
27
class APInt;
28
class Argument;
29
class BasicBlock;
30
class Constant;
31
class ConstantData;
32
class ConstantAggregate;
33
class DataLayout;
34
class Function;
35
class GlobalAlias;
36
class GlobalIFunc;
37
class GlobalIndirectSymbol;
38
class GlobalObject;
39
class GlobalValue;
40
class GlobalVariable;
41
class InlineAsm;
42
class Instruction;
43
class LLVMContext;
44
class Module;
45
class ModuleSlotTracker;
46
class raw_ostream;
47
template<typename ValueTy> class StringMapEntry;
48
class StringRef;
49
class Twine;
50
class Type;
51
class User;
52
53
using ValueName = StringMapEntry<Value *>;
54
55
//===----------------------------------------------------------------------===//
56
//                                 Value Class
57
//===----------------------------------------------------------------------===//
58
59
/// LLVM Value Representation
60
///
61
/// This is a very important LLVM class. It is the base class of all values
62
/// computed by a program that may be used as operands to other values. Value is
63
/// the super class of other important classes such as Instruction and Function.
64
/// All Values have a Type. Type is not a subclass of Value. Some values can
65
/// have a name and they belong to some Module.  Setting the name on the Value
66
/// automatically updates the module's symbol table.
67
///
68
/// Every value has a "use list" that keeps track of which other Values are
69
/// using this Value.  A Value can also have an arbitrary number of ValueHandle
70
/// objects that watch it and listen to RAUW and Destroy events.  See
71
/// llvm/IR/ValueHandle.h for details.
72
class Value {
73
  // The least-significant bit of the first word of Value *must* be zero:
74
  //   http://www.llvm.org/docs/ProgrammersManual.html#the-waymarking-algorithm
75
  Type *VTy;
76
  Use *UseList;
77
78
  friend class ValueAsMetadata; // Allow access to IsUsedByMD.
79
  friend class ValueHandleBase;
80
81
  const unsigned char SubclassID;   // Subclass identifier (for isa/dyn_cast)
82
  unsigned char HasValueHandle : 1; // Has a ValueHandle pointing to this?
83
84
protected:
85
  /// Hold subclass data that can be dropped.
86
  ///
87
  /// This member is similar to SubclassData, however it is for holding
88
  /// information which may be used to aid optimization, but which may be
89
  /// cleared to zero without affecting conservative interpretation.
90
  unsigned char SubclassOptionalData : 7;
91
92
private:
93
  /// Hold arbitrary subclass data.
94
  ///
95
  /// This member is defined by this class, but is not used for anything.
96
  /// Subclasses can use it to hold whatever state they find useful.  This
97
  /// field is initialized to zero by the ctor.
98
  unsigned short SubclassData;
99
100
protected:
101
  /// The number of operands in the subclass.
102
  ///
103
  /// This member is defined by this class, but not used for anything.
104
  /// Subclasses can use it to store their number of operands, if they have
105
  /// any.
106
  ///
107
  /// This is stored here to save space in User on 64-bit hosts.  Since most
108
  /// instances of Value have operands, 32-bit hosts aren't significantly
109
  /// affected.
110
  ///
111
  /// Note, this should *NOT* be used directly by any class other than User.
112
  /// User uses this value to find the Use list.
113
  enum : unsigned { NumUserOperandsBits = 28 };
114
  unsigned NumUserOperands : NumUserOperandsBits;
115
116
  // Use the same type as the bitfield above so that MSVC will pack them.
117
  unsigned IsUsedByMD : 1;
118
  unsigned HasName : 1;
119
  unsigned HasHungOffUses : 1;
120
  unsigned HasDescriptor : 1;
121
122
private:
123
  template <typename UseT> // UseT == 'Use' or 'const Use'
124
  class use_iterator_impl
125
      : public std::iterator<std::forward_iterator_tag, UseT *> {
126
    friend class Value;
127
128
    UseT *U;
129
130
1.74G
    explicit use_iterator_impl(UseT *u) : U(u) {}
llvm::Value::use_iterator_impl<llvm::Use const>::use_iterator_impl(llvm::Use const*)
Line
Count
Source
130
795M
    explicit use_iterator_impl(UseT *u) : U(u) {}
llvm::Value::use_iterator_impl<llvm::Use>::use_iterator_impl(llvm::Use*)
Line
Count
Source
130
944M
    explicit use_iterator_impl(UseT *u) : U(u) {}
131
132
  public:
133
2.67G
    use_iterator_impl() : U() {}
llvm::Value::use_iterator_impl<llvm::Use const>::use_iterator_impl()
Line
Count
Source
133
795M
    use_iterator_impl() : U() {}
llvm::Value::use_iterator_impl<llvm::Use>::use_iterator_impl()
Line
Count
Source
133
1.87G
    use_iterator_impl() : U() {}
134
135
4.42G
    bool operator==(const use_iterator_impl &x) const { return U == x.U; }
llvm::Value::use_iterator_impl<llvm::Use const>::operator==(llvm::Value::use_iterator_impl<llvm::Use const> const&) const
Line
Count
Source
135
1.60G
    bool operator==(const use_iterator_impl &x) const { return U == x.U; }
llvm::Value::use_iterator_impl<llvm::Use>::operator==(llvm::Value::use_iterator_impl<llvm::Use> const&) const
Line
Count
Source
135
2.81G
    bool operator==(const use_iterator_impl &x) const { return U == x.U; }
136
237M
    bool operator!=(const use_iterator_impl &x) const { return !operator==(x); }
llvm::Value::use_iterator_impl<llvm::Use>::operator!=(llvm::Value::use_iterator_impl<llvm::Use> const&) const
Line
Count
Source
136
93.0M
    bool operator!=(const use_iterator_impl &x) const { return !operator==(x); }
llvm::Value::use_iterator_impl<llvm::Use const>::operator!=(llvm::Value::use_iterator_impl<llvm::Use const> const&) const
Line
Count
Source
136
143M
    bool operator!=(const use_iterator_impl &x) const { return !operator==(x); }
137
138
1.72G
    use_iterator_impl &operator++() { // Preincrement
139
1.72G
      assert(U && "Cannot increment end iterator!");
140
1.72G
      U = U->getNext();
141
1.72G
      return *this;
142
1.72G
    }
llvm::Value::use_iterator_impl<llvm::Use const>::operator++()
Line
Count
Source
138
807M
    use_iterator_impl &operator++() { // Preincrement
139
807M
      assert(U && "Cannot increment end iterator!");
140
807M
      U = U->getNext();
141
807M
      return *this;
142
807M
    }
llvm::Value::use_iterator_impl<llvm::Use>::operator++()
Line
Count
Source
138
922M
    use_iterator_impl &operator++() { // Preincrement
139
922M
      assert(U && "Cannot increment end iterator!");
140
922M
      U = U->getNext();
141
922M
      return *this;
142
922M
    }
143
144
6.56M
    use_iterator_impl operator++(int) { // Postincrement
145
6.56M
      auto tmp = *this;
146
6.56M
      ++*this;
147
6.56M
      return tmp;
148
6.56M
    }
149
150
1.93G
    UseT &operator*() const {
151
1.93G
      assert(U && "Cannot dereference end iterator!");
152
1.93G
      return *U;
153
1.93G
    }
llvm::Value::use_iterator_impl<llvm::Use>::operator*() const
Line
Count
Source
150
1.83G
    UseT &operator*() const {
151
1.83G
      assert(U && "Cannot dereference end iterator!");
152
1.83G
      return *U;
153
1.83G
    }
llvm::Value::use_iterator_impl<llvm::Use const>::operator*() const
Line
Count
Source
150
109M
    UseT &operator*() const {
151
109M
      assert(U && "Cannot dereference end iterator!");
152
109M
      return *U;
153
109M
    }
154
155
1.74G
    UseT *operator->() const { return &operator*(); }
llvm::Value::use_iterator_impl<llvm::Use>::operator->() const
Line
Count
Source
155
1.74G
    UseT *operator->() const { return &operator*(); }
llvm::Value::use_iterator_impl<llvm::Use const>::operator->() const
Line
Count
Source
155
108k
    UseT *operator->() const { return &operator*(); }
156
157
    operator use_iterator_impl<const UseT>() const {
158
      return use_iterator_impl<const UseT>(U);
159
    }
160
  };
161
162
  template <typename UserTy> // UserTy == 'User' or 'const User'
163
  class user_iterator_impl
164
      : public std::iterator<std::forward_iterator_tag, UserTy *> {
165
    use_iterator_impl<Use> UI;
166
906M
    explicit user_iterator_impl(Use *U) : UI(U) {}
llvm::Value::user_iterator_impl<llvm::User>::user_iterator_impl(llvm::Use*)
Line
Count
Source
166
496M
    explicit user_iterator_impl(Use *U) : UI(U) {}
llvm::Value::user_iterator_impl<llvm::User const>::user_iterator_impl(llvm::Use*)
Line
Count
Source
166
409M
    explicit user_iterator_impl(Use *U) : UI(U) {}
167
    friend class Value;
168
169
  public:
170
1.84G
    user_iterator_impl() = default;
llvm::Value::user_iterator_impl<llvm::User const>::user_iterator_impl()
Line
Count
Source
170
1.00G
    user_iterator_impl() = default;
llvm::Value::user_iterator_impl<llvm::User>::user_iterator_impl()
Line
Count
Source
170
835M
    user_iterator_impl() = default;
171
172
2.72G
    bool operator==(const user_iterator_impl &x) const { return UI == x.UI; }
llvm::Value::user_iterator_impl<llvm::User>::operator==(llvm::Value::user_iterator_impl<llvm::User> const&) const
Line
Count
Source
172
1.32G
    bool operator==(const user_iterator_impl &x) const { return UI == x.UI; }
llvm::Value::user_iterator_impl<llvm::User const>::operator==(llvm::Value::user_iterator_impl<llvm::User const> const&) const
Line
Count
Source
172
1.39G
    bool operator==(const user_iterator_impl &x) const { return UI == x.UI; }
173
490M
    bool operator!=(const user_iterator_impl &x) const { return !operator==(x); }
llvm::Value::user_iterator_impl<llvm::User>::operator!=(llvm::Value::user_iterator_impl<llvm::User> const&) const
Line
Count
Source
173
296M
    bool operator!=(const user_iterator_impl &x) const { return !operator==(x); }
llvm::Value::user_iterator_impl<llvm::User const>::operator!=(llvm::Value::user_iterator_impl<llvm::User const> const&) const
Line
Count
Source
173
193M
    bool operator!=(const user_iterator_impl &x) const { return !operator==(x); }
174
175
    /// Returns true if this iterator is equal to user_end() on the value.
176
1.10G
    bool atEnd() const { return *this == user_iterator_impl(); }
llvm::Value::user_iterator_impl<llvm::User>::atEnd() const
Line
Count
Source
176
503M
    bool atEnd() const { return *this == user_iterator_impl(); }
llvm::Value::user_iterator_impl<llvm::User const>::atEnd() const
Line
Count
Source
176
603M
    bool atEnd() const { return *this == user_iterator_impl(); }
177
178
862M
    user_iterator_impl &operator++() { // Preincrement
179
862M
      ++UI;
180
862M
      return *this;
181
862M
    }
llvm::Value::user_iterator_impl<llvm::User const>::operator++()
Line
Count
Source
178
394M
    user_iterator_impl &operator++() { // Preincrement
179
394M
      ++UI;
180
394M
      return *this;
181
394M
    }
llvm::Value::user_iterator_impl<llvm::User>::operator++()
Line
Count
Source
178
468M
    user_iterator_impl &operator++() { // Preincrement
179
468M
      ++UI;
180
468M
      return *this;
181
468M
    }
182
183
5.51M
    user_iterator_impl operator++(int) { // Postincrement
184
5.51M
      auto tmp = *this;
185
5.51M
      ++*this;
186
5.51M
      return tmp;
187
5.51M
    }
llvm::Value::user_iterator_impl<llvm::User const>::operator++(int)
Line
Count
Source
183
349
    user_iterator_impl operator++(int) { // Postincrement
184
349
      auto tmp = *this;
185
349
      ++*this;
186
349
      return tmp;
187
349
    }
llvm::Value::user_iterator_impl<llvm::User>::operator++(int)
Line
Count
Source
183
5.51M
    user_iterator_impl operator++(int) { // Postincrement
184
5.51M
      auto tmp = *this;
185
5.51M
      ++*this;
186
5.51M
      return tmp;
187
5.51M
    }
188
189
    // Retrieve a pointer to the current User.
190
1.74G
    UserTy *operator*() const {
191
1.74G
      return UI->getUser();
192
1.74G
    }
llvm::Value::user_iterator_impl<llvm::User>::operator*() const
Line
Count
Source
190
967M
    UserTy *operator*() const {
191
967M
      return UI->getUser();
192
967M
    }
llvm::Value::user_iterator_impl<llvm::User const>::operator*() const
Line
Count
Source
190
780M
    UserTy *operator*() const {
191
780M
      return UI->getUser();
192
780M
    }
193
194
    UserTy *operator->() const { return operator*(); }
195
196
    operator user_iterator_impl<const UserTy>() const {
197
      return user_iterator_impl<const UserTy>(*UI);
198
    }
199
200
12.1M
    Use &getUse() const { return *UI; }
llvm::Value::user_iterator_impl<llvm::User const>::getUse() const
Line
Count
Source
200
135
    Use &getUse() const { return *UI; }
llvm::Value::user_iterator_impl<llvm::User>::getUse() const
Line
Count
Source
200
12.1M
    Use &getUse() const { return *UI; }
201
  };
202
203
protected:
204
  Value(Type *Ty, unsigned scid);
205
206
  /// Value's destructor should be virtual by design, but that would require
207
  /// that Value and all of its subclasses have a vtable that effectively
208
  /// duplicates the information in the value ID. As a size optimization, the
209
  /// destructor has been protected, and the caller should manually call
210
  /// deleteValue.
211
  ~Value(); // Use deleteValue() to delete a generic Value.
212
213
public:
214
  Value(const Value &) = delete;
215
  Value &operator=(const Value &) = delete;
216
217
  /// Delete a pointer to a generic Value.
218
  void deleteValue();
219
220
  /// Support for debugging, callable in GDB: V->dump()
221
  void dump() const;
222
223
  /// Implement operator<< on Value.
224
  /// @{
225
  void print(raw_ostream &O, bool IsForDebug = false) const;
226
  void print(raw_ostream &O, ModuleSlotTracker &MST,
227
             bool IsForDebug = false) const;
228
  /// @}
229
230
  /// Print the name of this Value out to the specified raw_ostream.
231
  ///
232
  /// This is useful when you just want to print 'int %reg126', not the
233
  /// instruction that generated it. If you specify a Module for context, then
234
  /// even constanst get pretty-printed; for example, the type of a null
235
  /// pointer is printed symbolically.
236
  /// @{
237
  void printAsOperand(raw_ostream &O, bool PrintType = true,
238
                      const Module *M = nullptr) const;
239
  void printAsOperand(raw_ostream &O, bool PrintType,
240
                      ModuleSlotTracker &MST) const;
241
  /// @}
242
243
  /// All values are typed, get the type of this value.
244
8.21G
  Type *getType() const { return VTy; }
245
246
  /// All values hold a context through their type.
247
  LLVMContext &getContext() const;
248
249
  // All values can potentially be named.
250
732M
  bool hasName() const { return HasName; }
251
  ValueName *getValueName() const;
252
  void setValueName(ValueName *VN);
253
254
private:
255
  void destroyValueName();
256
  enum class ReplaceMetadataUses { No, Yes };
257
  void doRAUW(Value *New, ReplaceMetadataUses);
258
  void setNameImpl(const Twine &Name);
259
260
public:
261
  /// Return a constant reference to the value's name.
262
  ///
263
  /// This guaranteed to return the same reference as long as the value is not
264
  /// modified.  If the value has a name, this does a hashtable lookup, so it's
265
  /// not free.
266
  StringRef getName() const;
267
268
  /// Change the name of the value.
269
  ///
270
  /// Choose a new unique name if the provided name is taken.
271
  ///
272
  /// \param Name The new name; or "" if the value's name should be removed.
273
  void setName(const Twine &Name);
274
275
  /// Transfer the name from V to this value.
276
  ///
277
  /// After taking V's name, sets V's name to empty.
278
  ///
279
  /// \note It is an error to call V->takeName(V).
280
  void takeName(Value *V);
281
282
  /// Change all uses of this to point to a new Value.
283
  ///
284
  /// Go through the uses list for this definition and make each use point to
285
  /// "V" instead of "this".  After this completes, 'this's use list is
286
  /// guaranteed to be empty.
287
  void replaceAllUsesWith(Value *V);
288
289
  /// Change non-metadata uses of this to point to a new Value.
290
  ///
291
  /// Go through the uses list for this definition and make each use point to
292
  /// "V" instead of "this". This function skips metadata entries in the list.
293
  void replaceNonMetadataUsesWith(Value *V);
294
295
  /// replaceUsesOutsideBlock - Go through the uses list for this definition and
296
  /// make each use point to "V" instead of "this" when the use is outside the
297
  /// block. 'This's use list is expected to have at least one element.
298
  /// Unlike replaceAllUsesWith this function does not support basic block
299
  /// values or constant users.
300
  void replaceUsesOutsideBlock(Value *V, BasicBlock *BB);
301
302
  //----------------------------------------------------------------------
303
  // Methods for handling the chain of uses of this Value.
304
  //
305
  // Materializing a function can introduce new uses, so these methods come in
306
  // two variants:
307
  // The methods that start with materialized_ check the uses that are
308
  // currently known given which functions are materialized. Be very careful
309
  // when using them since you might not get all uses.
310
  // The methods that don't start with materialized_ assert that modules is
311
  // fully materialized.
312
  void assertModuleIsMaterializedImpl() const;
313
  // This indirection exists so we can keep assertModuleIsMaterializedImpl()
314
  // around in release builds of Value.cpp to be linked with other code built
315
  // in debug mode. But this avoids calling it in any of the release built code.
316
2.79G
  void assertModuleIsMaterialized() const {
317
#ifndef NDEBUG
318
    assertModuleIsMaterializedImpl();
319
#endif
320
  }
321
322
1.05G
  bool use_empty() const {
323
1.05G
    assertModuleIsMaterialized();
324
1.05G
    return UseList == nullptr;
325
1.05G
  }
326
327
35.0M
  bool materialized_use_empty() const {
328
35.0M
    return UseList == nullptr;
329
35.0M
  }
330
331
  using use_iterator = use_iterator_impl<Use>;
332
  using const_use_iterator = use_iterator_impl<const Use>;
333
334
38.2M
  use_iterator materialized_use_begin() { return use_iterator(UseList); }
335
795M
  const_use_iterator materialized_use_begin() const {
336
795M
    return const_use_iterator(UseList);
337
795M
  }
338
9.92M
  use_iterator use_begin() {
339
9.92M
    assertModuleIsMaterialized();
340
9.92M
    return materialized_use_begin();
341
9.92M
  }
342
756M
  const_use_iterator use_begin() const {
343
756M
    assertModuleIsMaterialized();
344
756M
    return materialized_use_begin();
345
756M
  }
346
32.2M
  use_iterator use_end() { return use_iterator(); }
347
795M
  const_use_iterator use_end() const { return const_use_iterator(); }
348
28.3M
  iterator_range<use_iterator> materialized_uses() {
349
28.3M
    return make_range(materialized_use_begin(), use_end());
350
28.3M
  }
351
39.4M
  iterator_range<const_use_iterator> materialized_uses() const {
352
39.4M
    return make_range(materialized_use_begin(), use_end());
353
39.4M
  }
354
28.3M
  iterator_range<use_iterator> uses() {
355
28.3M
    assertModuleIsMaterialized();
356
28.3M
    return materialized_uses();
357
28.3M
  }
358
39.4M
  iterator_range<const_use_iterator> uses() const {
359
39.4M
    assertModuleIsMaterialized();
360
39.4M
    return materialized_uses();
361
39.4M
  }
362
363
694k
  bool user_empty() const {
364
694k
    assertModuleIsMaterialized();
365
694k
    return UseList == nullptr;
366
694k
  }
367
368
  using user_iterator = user_iterator_impl<User>;
369
  using const_user_iterator = user_iterator_impl<const User>;
370
371
496M
  user_iterator materialized_user_begin() { return user_iterator(UseList); }
372
409M
  const_user_iterator materialized_user_begin() const {
373
409M
    return const_user_iterator(UseList);
374
409M
  }
375
386M
  user_iterator user_begin() {
376
386M
    assertModuleIsMaterialized();
377
386M
    return materialized_user_begin();
378
386M
  }
379
343M
  const_user_iterator user_begin() const {
380
343M
    assertModuleIsMaterialized();
381
343M
    return materialized_user_begin();
382
343M
  }
383
332M
  user_iterator user_end() { return user_iterator(); }
384
403M
  const_user_iterator user_end() const { return const_user_iterator(); }
385
472k
  User *user_back() {
386
472k
    assertModuleIsMaterialized();
387
472k
    return *materialized_user_begin();
388
472k
  }
389
5.57M
  const User *user_back() const {
390
5.57M
    assertModuleIsMaterialized();
391
5.57M
    return *materialized_user_begin();
392
5.57M
  }
393
108M
  iterator_range<user_iterator> materialized_users() {
394
108M
    return make_range(materialized_user_begin(), user_end());
395
108M
  }
396
60.3M
  iterator_range<const_user_iterator> materialized_users() const {
397
60.3M
    return make_range(materialized_user_begin(), user_end());
398
60.3M
  }
399
108M
  iterator_range<user_iterator> users() {
400
108M
    assertModuleIsMaterialized();
401
108M
    return materialized_users();
402
108M
  }
403
58.6M
  iterator_range<const_user_iterator> users() const {
404
58.6M
    assertModuleIsMaterialized();
405
58.6M
    return materialized_users();
406
58.6M
  }
407
408
  /// Return true if there is exactly one user of this value.
409
  ///
410
  /// This is specialized because it is a common request and does not require
411
  /// traversing the whole use list.
412
755M
  bool hasOneUse() const {
413
755M
    const_use_iterator I = use_begin(), E = use_end();
414
755M
    if (I == E) 
return false54.5M
;
415
700M
    return ++I == E;
416
700M
  }
417
418
  /// Return true if this Value has exactly N users.
419
  bool hasNUses(unsigned N) const;
420
421
  /// Return true if this value has N users or more.
422
  ///
423
  /// This is logically equivalent to getNumUses() >= N.
424
  bool hasNUsesOrMore(unsigned N) const;
425
426
  /// Check if this value is used in the specified basic block.
427
  bool isUsedInBasicBlock(const BasicBlock *BB) const;
428
429
  /// This method computes the number of uses of this Value.
430
  ///
431
  /// This is a linear time operation.  Use hasOneUse, hasNUses, or
432
  /// hasNUsesOrMore to check for specific values.
433
  unsigned getNumUses() const;
434
435
  /// This method should only be used by the Use class.
436
168M
  void addUse(Use &U) { U.addToList(&UseList); }
437
438
  /// Concrete subclass of this.
439
  ///
440
  /// An enumeration for keeping track of the concrete subclass of Value that
441
  /// is actually instantiated. Values of this enumeration are kept in the
442
  /// Value classes SubclassID field. They are used for concrete type
443
  /// identification.
444
  enum ValueTy {
445
#define HANDLE_VALUE(Name) Name##Val,
446
#include "llvm/IR/Value.def"
447
448
    // Markers:
449
#define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
450
#include "llvm/IR/Value.def"
451
  };
452
453
  /// Return an ID for the concrete type of this object.
454
  ///
455
  /// This is used to implement the classof checks.  This should not be used
456
  /// for any other purpose, as the values may change as LLVM evolves.  Also,
457
  /// note that for instructions, the Instruction's opcode is added to
458
  /// InstructionVal. So this means three things:
459
  /// # there is no value with code InstructionVal (no opcode==0).
460
  /// # there are more possible values for the value type than in ValueTy enum.
461
  /// # the InstructionVal enumerator must be the highest valued enumerator in
462
  ///   the ValueTy enum.
463
61.6G
  unsigned getValueID() const {
464
61.6G
    return SubclassID;
465
61.6G
  }
466
467
  /// Return the raw optional flags value contained in this value.
468
  ///
469
  /// This should only be used when testing two Values for equivalence.
470
21.8M
  unsigned getRawSubclassOptionalData() const {
471
21.8M
    return SubclassOptionalData;
472
21.8M
  }
473
474
  /// Clear the optional flags contained in this value.
475
76.9k
  void clearSubclassOptionalData() {
476
76.9k
    SubclassOptionalData = 0;
477
76.9k
  }
478
479
  /// Check the optional flags for equality.
480
0
  bool hasSameSubclassOptionalData(const Value *V) const {
481
0
    return SubclassOptionalData == V->SubclassOptionalData;
482
0
  }
483
484
  /// Return true if there is a value handle associated with this value.
485
1.30M
  bool hasValueHandle() const { return HasValueHandle; }
486
487
  /// Return true if there is metadata referencing this value.
488
90.1M
  bool isUsedByMetadata() const { return IsUsedByMD; }
489
490
  /// Return true if this value is a swifterror value.
491
  ///
492
  /// swifterror values can be either a function argument or an alloca with a
493
  /// swifterror attribute.
494
  bool isSwiftError() const;
495
496
  /// Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
497
  ///
498
  /// Returns the original uncasted value.  If this is called on a non-pointer
499
  /// value, it returns 'this'.
500
  const Value *stripPointerCasts() const;
501
145M
  Value *stripPointerCasts() {
502
145M
    return const_cast<Value *>(
503
145M
                         static_cast<const Value *>(this)->stripPointerCasts());
504
145M
  }
505
506
  /// Strip off pointer casts, all-zero GEPs, address space casts, and aliases
507
  /// but ensures the representation of the result stays the same.
508
  ///
509
  /// Returns the original uncasted value with the same representation. If this
510
  /// is called on a non-pointer value, it returns 'this'.
511
  const Value *stripPointerCastsSameRepresentation() const;
512
3.44M
  Value *stripPointerCastsSameRepresentation() {
513
3.44M
    return const_cast<Value *>(static_cast<const Value *>(this)
514
3.44M
                                   ->stripPointerCastsSameRepresentation());
515
3.44M
  }
516
517
  /// Strip off pointer casts, all-zero GEPs, aliases and invariant group
518
  /// info.
519
  ///
520
  /// Returns the original uncasted value.  If this is called on a non-pointer
521
  /// value, it returns 'this'. This function should be used only in
522
  /// Alias analysis.
523
  const Value *stripPointerCastsAndInvariantGroups() const;
524
170
  Value *stripPointerCastsAndInvariantGroups() {
525
170
    return const_cast<Value *>(
526
170
        static_cast<const Value *>(this)->stripPointerCastsAndInvariantGroups());
527
170
  }
528
529
  /// Strip off pointer casts and all-zero GEPs.
530
  ///
531
  /// Returns the original uncasted value.  If this is called on a non-pointer
532
  /// value, it returns 'this'.
533
  const Value *stripPointerCastsNoFollowAliases() const;
534
13.2M
  Value *stripPointerCastsNoFollowAliases() {
535
13.2M
    return const_cast<Value *>(
536
13.2M
          static_cast<const Value *>(this)->stripPointerCastsNoFollowAliases());
537
13.2M
  }
538
539
  /// Strip off pointer casts and all-constant inbounds GEPs.
540
  ///
541
  /// Returns the original pointer value.  If this is called on a non-pointer
542
  /// value, it returns 'this'.
543
  const Value *stripInBoundsConstantOffsets() const;
544
126
  Value *stripInBoundsConstantOffsets() {
545
126
    return const_cast<Value *>(
546
126
              static_cast<const Value *>(this)->stripInBoundsConstantOffsets());
547
126
  }
548
549
  /// Accumulate the constant offset this value has compared to a base pointer.
550
  /// Only 'getelementptr' instructions (GEPs) with constant indices are
551
  /// accumulated but other instructions, e.g., casts, are stripped away as
552
  /// well. The accumulated constant offset is added to \p Offset and the base
553
  /// pointer is returned.
554
  ///
555
  /// The APInt \p Offset has to have a bit-width equal to the IntPtr type for
556
  /// the address space of 'this' pointer value, e.g., use
557
  /// DataLayout::getIndexTypeSizeInBits(Ty).
558
  ///
559
  /// If \p AllowNonInbounds is true, constant offsets in GEPs are stripped and
560
  /// accumulated even if the GEP is not "inbounds".
561
  ///
562
  /// If this is called on a non-pointer value, it returns 'this' and the
563
  /// \p Offset is not modified.
564
  ///
565
  /// Note that this function will never return a nullptr. It will also never
566
  /// manipulate the \p Offset in a way that would not match the difference
567
  /// between the underlying value and the returned one. Thus, if no constant
568
  /// offset was found, the returned value is the underlying one and \p Offset
569
  /// is unchanged.
570
  const Value *stripAndAccumulateConstantOffsets(const DataLayout &DL,
571
                                                 APInt &Offset,
572
                                                 bool AllowNonInbounds) const;
573
  Value *stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset,
574
36.3M
                                           bool AllowNonInbounds) {
575
36.3M
    return const_cast<Value *>(
576
36.3M
        static_cast<const Value *>(this)->stripAndAccumulateConstantOffsets(
577
36.3M
            DL, Offset, AllowNonInbounds));
578
36.3M
  }
579
580
  /// This is a wrapper around stripAndAccumulateConstantOffsets with the
581
  /// in-bounds requirement set to false.
582
  const Value *stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL,
583
1.01k
                                                         APInt &Offset) const {
584
1.01k
    return stripAndAccumulateConstantOffsets(DL, Offset,
585
1.01k
                                             /* AllowNonInbounds */ false);
586
1.01k
  }
587
  Value *stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL,
588
11.6M
                                                   APInt &Offset) {
589
11.6M
    return stripAndAccumulateConstantOffsets(DL, Offset,
590
11.6M
                                             /* AllowNonInbounds */ false);
591
11.6M
  }
592
593
  /// Strip off pointer casts and inbounds GEPs.
594
  ///
595
  /// Returns the original pointer value.  If this is called on a non-pointer
596
  /// value, it returns 'this'.
597
  const Value *stripInBoundsOffsets() const;
598
543k
  Value *stripInBoundsOffsets() {
599
543k
    return const_cast<Value *>(
600
543k
                      static_cast<const Value *>(this)->stripInBoundsOffsets());
601
543k
  }
602
603
  /// Returns the number of bytes known to be dereferenceable for the
604
  /// pointer value.
605
  ///
606
  /// If CanBeNull is set by this function the pointer can either be null or be
607
  /// dereferenceable up to the returned number of bytes.
608
  uint64_t getPointerDereferenceableBytes(const DataLayout &DL,
609
                                          bool &CanBeNull) const;
610
611
  /// Returns an alignment of the pointer value.
612
  ///
613
  /// Returns an alignment which is either specified explicitly, e.g. via
614
  /// align attribute of a function argument, or guaranteed by DataLayout.
615
  unsigned getPointerAlignment(const DataLayout &DL) const;
616
617
  /// Translate PHI node to its predecessor from the given basic block.
618
  ///
619
  /// If this value is a PHI node with CurBB as its parent, return the value in
620
  /// the PHI node corresponding to PredBB.  If not, return ourself.  This is
621
  /// useful if you want to know the value something has in a predecessor
622
  /// block.
623
  const Value *DoPHITranslation(const BasicBlock *CurBB,
624
                                const BasicBlock *PredBB) const;
625
726k
  Value *DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) {
626
726k
    return const_cast<Value *>(
627
726k
             static_cast<const Value *>(this)->DoPHITranslation(CurBB, PredBB));
628
726k
  }
629
630
  /// The maximum alignment for instructions.
631
  ///
632
  /// This is the greatest alignment value supported by load, store, and alloca
633
  /// instructions, and global values.
634
  static const unsigned MaxAlignmentExponent = 29;
635
  static const unsigned MaximumAlignment = 1u << MaxAlignmentExponent;
636
637
  /// Mutate the type of this Value to be of the specified type.
638
  ///
639
  /// Note that this is an extremely dangerous operation which can create
640
  /// completely invalid IR very easily.  It is strongly recommended that you
641
  /// recreate IR objects with the right types instead of mutating them in
642
  /// place.
643
215k
  void mutateType(Type *Ty) {
644
215k
    VTy = Ty;
645
215k
  }
646
647
  /// Sort the use-list.
648
  ///
649
  /// Sorts the Value's use-list by Cmp using a stable mergesort.  Cmp is
650
  /// expected to compare two \a Use references.
651
  template <class Compare> void sortUseList(Compare Cmp);
652
653
  /// Reverse the use-list.
654
  void reverseUseList();
655
656
private:
657
  /// Merge two lists together.
658
  ///
659
  /// Merges \c L and \c R using \c Cmp.  To enable stable sorts, always pushes
660
  /// "equal" items from L before items from R.
661
  ///
662
  /// \return the first element in the list.
663
  ///
664
  /// \note Completely ignores \a Use::Prev (doesn't read, doesn't update).
665
  template <class Compare>
666
10.2k
  static Use *mergeUseLists(Use *L, Use *R, Compare Cmp) {
667
10.2k
    Use *Merged;
668
10.2k
    Use **Next = &Merged;
669
10.2k
670
49.8k
    while (
true49.8k
) {
671
49.8k
      if (!L) {
672
5.41k
        *Next = R;
673
5.41k
        break;
674
5.41k
      }
675
44.3k
      if (!R) {
676
4.84k
        *Next = L;
677
4.84k
        break;
678
4.84k
      }
679
39.5k
      if (Cmp(*R, *L)) {
680
11.9k
        *Next = R;
681
11.9k
        Next = &R->Next;
682
11.9k
        R = R->Next;
683
27.6k
      } else {
684
27.6k
        *Next = L;
685
27.6k
        Next = &L->Next;
686
27.6k
        L = L->Next;
687
27.6k
      }
688
39.5k
    }
689
10.2k
690
10.2k
    return Merged;
691
10.2k
  }
LLParser.cpp:llvm::Use* llvm::Value::mergeUseLists<llvm::LLParser::sortUseListOrder(llvm::Value*, llvm::ArrayRef<unsigned int>, llvm::SMLoc)::$_26>(llvm::Use*, llvm::Use*, llvm::LLParser::sortUseListOrder(llvm::Value*, llvm::ArrayRef<unsigned int>, llvm::SMLoc)::$_26)
Line
Count
Source
666
2.39k
  static Use *mergeUseLists(Use *L, Use *R, Compare Cmp) {
667
2.39k
    Use *Merged;
668
2.39k
    Use **Next = &Merged;
669
2.39k
670
6.88k
    while (true) {
671
6.88k
      if (!L) {
672
627
        *Next = R;
673
627
        break;
674
627
      }
675
6.26k
      if (!R) {
676
1.76k
        *Next = L;
677
1.76k
        break;
678
1.76k
      }
679
4.49k
      if (Cmp(*R, *L)) {
680
2.80k
        *Next = R;
681
2.80k
        Next = &R->Next;
682
2.80k
        R = R->Next;
683
2.80k
      } else {
684
1.69k
        *Next = L;
685
1.69k
        Next = &L->Next;
686
1.69k
        L = L->Next;
687
1.69k
      }
688
4.49k
    }
689
2.39k
690
2.39k
    return Merged;
691
2.39k
  }
BitcodeReader.cpp:llvm::Use* llvm::Value::mergeUseLists<(anonymous namespace)::BitcodeReader::parseUseLists()::$_1>(llvm::Use*, llvm::Use*, (anonymous namespace)::BitcodeReader::parseUseLists()::$_1)
Line
Count
Source
666
7.86k
  static Use *mergeUseLists(Use *L, Use *R, Compare Cmp) {
667
7.86k
    Use *Merged;
668
7.86k
    Use **Next = &Merged;
669
7.86k
670
42.9k
    while (
true42.9k
) {
671
42.9k
      if (!L) {
672
4.78k
        *Next = R;
673
4.78k
        break;
674
4.78k
      }
675
38.1k
      if (!R) {
676
3.07k
        *Next = L;
677
3.07k
        break;
678
3.07k
      }
679
35.0k
      if (Cmp(*R, *L)) {
680
9.13k
        *Next = R;
681
9.13k
        Next = &R->Next;
682
9.13k
        R = R->Next;
683
25.9k
      } else {
684
25.9k
        *Next = L;
685
25.9k
        Next = &L->Next;
686
25.9k
        L = L->Next;
687
25.9k
      }
688
35.0k
    }
689
7.86k
690
7.86k
    return Merged;
691
7.86k
  }
692
693
protected:
694
2.97G
  unsigned short getSubclassDataFromValue() const { return SubclassData; }
695
81.6M
  void setValueSubclassData(unsigned short D) { SubclassData = D; }
696
};
697
698
953k
struct ValueDeleter { void operator()(Value *V) { V->deleteValue(); } };
699
700
/// Use this instead of std::unique_ptr<Value> or std::unique_ptr<Instruction>.
701
/// Those don't work because Value and Instruction's destructors are protected,
702
/// aren't virtual, and won't destroy the complete object.
703
using unique_value = std::unique_ptr<Value, ValueDeleter>;
704
705
61.3k
inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) {
706
61.3k
  V.print(OS);
707
61.3k
  return OS;
708
61.3k
}
709
710
234M
void Use::set(Value *V) {
711
234M
  if (Val) 
removeFromList()92.8M
;
712
234M
  Val = V;
713
234M
  if (V) 
V->addUse(*this)167M
;
714
234M
}
715
716
140M
Value *Use::operator=(Value *RHS) {
717
140M
  set(RHS);
718
140M
  return RHS;
719
140M
}
720
721
21.2M
const Use &Use::operator=(const Use &RHS) {
722
21.2M
  set(RHS.Val);
723
21.2M
  return *this;
724
21.2M
}
725
726
2.15k
template <class Compare> void Value::sortUseList(Compare Cmp) {
727
2.15k
  if (!UseList || !UseList->Next)
728
0
    // No need to sort 0 or 1 uses.
729
0
    return;
730
2.15k
731
2.15k
  // Note: this function completely ignores Prev pointers until the end when
732
2.15k
  // they're fixed en masse.
733
2.15k
734
2.15k
  // Create a binomial vector of sorted lists, visiting uses one at a time and
735
2.15k
  // merging lists as necessary.
736
2.15k
  const unsigned MaxSlots = 32;
737
2.15k
  Use *Slots[MaxSlots];
738
2.15k
739
2.15k
  // Collect the first use, turning it into a single-item list.
740
2.15k
  Use *Next = UseList->Next;
741
2.15k
  UseList->Next = nullptr;
742
2.15k
  unsigned NumSlots = 1;
743
2.15k
  Slots[0] = UseList;
744
2.15k
745
2.15k
  // Collect all but the last use.
746
10.2k
  while (Next->Next) {
747
8.10k
    Use *Current = Next;
748
8.10k
    Next = Current->Next;
749
8.10k
750
8.10k
    // Turn Current into a single-item list.
751
8.10k
    Current->Next = nullptr;
752
8.10k
753
8.10k
    // Save Current in the first available slot, merging on collisions.
754
8.10k
    unsigned I;
755
15.5k
    for (I = 0; I < NumSlots; 
++I7.41k
) {
756
13.8k
      if (!Slots[I])
757
6.43k
        break;
758
7.41k
759
7.41k
      // Merge two lists, doubling the size of Current and emptying slot I.
760
7.41k
      //
761
7.41k
      // Since the uses in Slots[I] originally preceded those in Current, send
762
7.41k
      // Slots[I] in as the left parameter to maintain a stable sort.
763
7.41k
      Current = mergeUseLists(Slots[I], Current, Cmp);
764
7.41k
      Slots[I] = nullptr;
765
7.41k
    }
766
8.10k
    // Check if this is a new slot.
767
8.10k
    if (I == NumSlots) {
768
1.67k
      ++NumSlots;
769
1.67k
      assert(NumSlots <= MaxSlots && "Use list bigger than 2^32");
770
1.67k
    }
771
8.10k
772
8.10k
    // Found an open slot.
773
8.10k
    Slots[I] = Current;
774
8.10k
  }
775
2.15k
776
2.15k
  // Merge all the lists together.
777
2.15k
  assert(Next && "Expected one more Use");
778
2.15k
  assert(!Next->Next && "Expected only one Use");
779
2.15k
  UseList = Next;
780
5.97k
  for (unsigned I = 0; I < NumSlots; 
++I3.82k
)
781
3.82k
    if (Slots[I])
782
2.84k
      // Since the uses in Slots[I] originally preceded those in UseList, send
783
2.84k
      // Slots[I] in as the left parameter to maintain a stable sort.
784
2.84k
      UseList = mergeUseLists(Slots[I], UseList, Cmp);
785
2.15k
786
2.15k
  // Fix the Prev pointers.
787
14.5k
  for (Use *I = UseList, **Prev = &UseList; I; 
I = I->Next12.4k
) {
788
12.4k
    I->setPrev(Prev);
789
12.4k
    Prev = &I->Next;
790
12.4k
  }
791
2.15k
}
LLParser.cpp:void llvm::Value::sortUseList<llvm::LLParser::sortUseListOrder(llvm::Value*, llvm::ArrayRef<unsigned int>, llvm::SMLoc)::$_26>(llvm::LLParser::sortUseListOrder(llvm::Value*, llvm::ArrayRef<unsigned int>, llvm::SMLoc)::$_26)
Line
Count
Source
726
889
template <class Compare> void Value::sortUseList(Compare Cmp) {
727
889
  if (!UseList || !UseList->Next)
728
0
    // No need to sort 0 or 1 uses.
729
0
    return;
730
889
731
889
  // Note: this function completely ignores Prev pointers until the end when
732
889
  // they're fixed en masse.
733
889
734
889
  // Create a binomial vector of sorted lists, visiting uses one at a time and
735
889
  // merging lists as necessary.
736
889
  const unsigned MaxSlots = 32;
737
889
  Use *Slots[MaxSlots];
738
889
739
889
  // Collect the first use, turning it into a single-item list.
740
889
  Use *Next = UseList->Next;
741
889
  UseList->Next = nullptr;
742
889
  unsigned NumSlots = 1;
743
889
  Slots[0] = UseList;
744
889
745
889
  // Collect all but the last use.
746
2.39k
  while (Next->Next) {
747
1.50k
    Use *Current = Next;
748
1.50k
    Next = Current->Next;
749
1.50k
750
1.50k
    // Turn Current into a single-item list.
751
1.50k
    Current->Next = nullptr;
752
1.50k
753
1.50k
    // Save Current in the first available slot, merging on collisions.
754
1.50k
    unsigned I;
755
2.73k
    for (I = 0; I < NumSlots; 
++I1.23k
) {
756
2.10k
      if (!Slots[I])
757
876
        break;
758
1.23k
759
1.23k
      // Merge two lists, doubling the size of Current and emptying slot I.
760
1.23k
      //
761
1.23k
      // Since the uses in Slots[I] originally preceded those in Current, send
762
1.23k
      // Slots[I] in as the left parameter to maintain a stable sort.
763
1.23k
      Current = mergeUseLists(Slots[I], Current, Cmp);
764
1.23k
      Slots[I] = nullptr;
765
1.23k
    }
766
1.50k
    // Check if this is a new slot.
767
1.50k
    if (I == NumSlots) {
768
625
      ++NumSlots;
769
625
      assert(NumSlots <= MaxSlots && "Use list bigger than 2^32");
770
625
    }
771
1.50k
772
1.50k
    // Found an open slot.
773
1.50k
    Slots[I] = Current;
774
1.50k
  }
775
889
776
889
  // Merge all the lists together.
777
889
  assert(Next && "Expected one more Use");
778
889
  assert(!Next->Next && "Expected only one Use");
779
889
  UseList = Next;
780
2.40k
  for (unsigned I = 0; I < NumSlots; 
++I1.51k
)
781
1.51k
    if (Slots[I])
782
1.16k
      // Since the uses in Slots[I] originally preceded those in UseList, send
783
1.16k
      // Slots[I] in as the left parameter to maintain a stable sort.
784
1.16k
      UseList = mergeUseLists(Slots[I], UseList, Cmp);
785
889
786
889
  // Fix the Prev pointers.
787
4.16k
  for (Use *I = UseList, **Prev = &UseList; I; 
I = I->Next3.27k
) {
788
3.27k
    I->setPrev(Prev);
789
3.27k
    Prev = &I->Next;
790
3.27k
  }
791
889
}
BitcodeReader.cpp:void llvm::Value::sortUseList<(anonymous namespace)::BitcodeReader::parseUseLists()::$_1>((anonymous namespace)::BitcodeReader::parseUseLists()::$_1)
Line
Count
Source
726
1.26k
template <class Compare> void Value::sortUseList(Compare Cmp) {
727
1.26k
  if (!UseList || !UseList->Next)
728
0
    // No need to sort 0 or 1 uses.
729
0
    return;
730
1.26k
731
1.26k
  // Note: this function completely ignores Prev pointers until the end when
732
1.26k
  // they're fixed en masse.
733
1.26k
734
1.26k
  // Create a binomial vector of sorted lists, visiting uses one at a time and
735
1.26k
  // merging lists as necessary.
736
1.26k
  const unsigned MaxSlots = 32;
737
1.26k
  Use *Slots[MaxSlots];
738
1.26k
739
1.26k
  // Collect the first use, turning it into a single-item list.
740
1.26k
  Use *Next = UseList->Next;
741
1.26k
  UseList->Next = nullptr;
742
1.26k
  unsigned NumSlots = 1;
743
1.26k
  Slots[0] = UseList;
744
1.26k
745
1.26k
  // Collect all but the last use.
746
7.86k
  while (Next->Next) {
747
6.60k
    Use *Current = Next;
748
6.60k
    Next = Current->Next;
749
6.60k
750
6.60k
    // Turn Current into a single-item list.
751
6.60k
    Current->Next = nullptr;
752
6.60k
753
6.60k
    // Save Current in the first available slot, merging on collisions.
754
6.60k
    unsigned I;
755
12.7k
    for (I = 0; I < NumSlots; 
++I6.18k
) {
756
11.7k
      if (!Slots[I])
757
5.55k
        break;
758
6.18k
759
6.18k
      // Merge two lists, doubling the size of Current and emptying slot I.
760
6.18k
      //
761
6.18k
      // Since the uses in Slots[I] originally preceded those in Current, send
762
6.18k
      // Slots[I] in as the left parameter to maintain a stable sort.
763
6.18k
      Current = mergeUseLists(Slots[I], Current, Cmp);
764
6.18k
      Slots[I] = nullptr;
765
6.18k
    }
766
6.60k
    // Check if this is a new slot.
767
6.60k
    if (I == NumSlots) {
768
1.04k
      ++NumSlots;
769
1.04k
      assert(NumSlots <= MaxSlots && "Use list bigger than 2^32");
770
1.04k
    }
771
6.60k
772
6.60k
    // Found an open slot.
773
6.60k
    Slots[I] = Current;
774
6.60k
  }
775
1.26k
776
1.26k
  // Merge all the lists together.
777
1.26k
  assert(Next && "Expected one more Use");
778
1.26k
  assert(!Next->Next && "Expected only one Use");
779
1.26k
  UseList = Next;
780
3.57k
  for (unsigned I = 0; I < NumSlots; 
++I2.30k
)
781
2.30k
    if (Slots[I])
782
1.68k
      // Since the uses in Slots[I] originally preceded those in UseList, send
783
1.68k
      // Slots[I] in as the left parameter to maintain a stable sort.
784
1.68k
      UseList = mergeUseLists(Slots[I], UseList, Cmp);
785
1.26k
786
1.26k
  // Fix the Prev pointers.
787
10.3k
  for (Use *I = UseList, **Prev = &UseList; I; 
I = I->Next9.12k
) {
788
9.12k
    I->setPrev(Prev);
789
9.12k
    Prev = &I->Next;
790
9.12k
  }
791
1.26k
}
792
793
// isa - Provide some specializations of isa so that we don't have to include
794
// the subtype header files to test to see if the value is a subclass...
795
//
796
template <> struct isa_impl<Constant, Value> {
797
1.63G
  static inline bool doit(const Value &Val) {
798
1.63G
    static_assert(Value::ConstantFirstVal == 0, "Val.getValueID() >= Value::ConstantFirstVal");
799
1.63G
    return Val.getValueID() <= Value::ConstantLastVal;
800
1.63G
  }
801
};
802
803
template <> struct isa_impl<ConstantData, Value> {
804
125
  static inline bool doit(const Value &Val) {
805
125
    return Val.getValueID() >= Value::ConstantDataFirstVal &&
806
125
           
Val.getValueID() <= Value::ConstantDataLastVal124
;
807
125
  }
808
};
809
810
template <> struct isa_impl<ConstantAggregate, Value> {
811
0
  static inline bool doit(const Value &Val) {
812
0
    return Val.getValueID() >= Value::ConstantAggregateFirstVal &&
813
0
           Val.getValueID() <= Value::ConstantAggregateLastVal;
814
0
  }
815
};
816
817
template <> struct isa_impl<Argument, Value> {
818
655M
  static inline bool doit (const Value &Val) {
819
655M
    return Val.getValueID() == Value::ArgumentVal;
820
655M
  }
821
};
822
823
template <> struct isa_impl<InlineAsm, Value> {
824
41.4M
  static inline bool doit(const Value &Val) {
825
41.4M
    return Val.getValueID() == Value::InlineAsmVal;
826
41.4M
  }
827
};
828
829
template <> struct isa_impl<Instruction, Value> {
830
12.7G
  static inline bool doit(const Value &Val) {
831
12.7G
    return Val.getValueID() >= Value::InstructionVal;
832
12.7G
  }
833
};
834
835
template <> struct isa_impl<BasicBlock, Value> {
836
39.0M
  static inline bool doit(const Value &Val) {
837
39.0M
    return Val.getValueID() == Value::BasicBlockVal;
838
39.0M
  }
839
};
840
841
template <> struct isa_impl<Function, Value> {
842
2.43G
  static inline bool doit(const Value &Val) {
843
2.43G
    return Val.getValueID() == Value::FunctionVal;
844
2.43G
  }
845
};
846
847
template <> struct isa_impl<GlobalVariable, Value> {
848
638M
  static inline bool doit(const Value &Val) {
849
638M
    return Val.getValueID() == Value::GlobalVariableVal;
850
638M
  }
851
};
852
853
template <> struct isa_impl<GlobalAlias, Value> {
854
1.48G
  static inline bool doit(const Value &Val) {
855
1.48G
    return Val.getValueID() == Value::GlobalAliasVal;
856
1.48G
  }
857
};
858
859
template <> struct isa_impl<GlobalIFunc, Value> {
860
285M
  static inline bool doit(const Value &Val) {
861
285M
    return Val.getValueID() == Value::GlobalIFuncVal;
862
285M
  }
863
};
864
865
template <> struct isa_impl<GlobalIndirectSymbol, Value> {
866
285M
  static inline bool doit(const Value &Val) {
867
285M
    return isa<GlobalAlias>(Val) || 
isa<GlobalIFunc>(Val)285M
;
868
285M
  }
869
};
870
871
template <> struct isa_impl<GlobalValue, Value> {
872
324M
  static inline bool doit(const Value &Val) {
873
324M
    return isa<GlobalObject>(Val) || 
isa<GlobalIndirectSymbol>(Val)285M
;
874
324M
  }
875
};
876
877
template <> struct isa_impl<GlobalObject, Value> {
878
479M
  static inline bool doit(const Value &Val) {
879
479M
    return isa<GlobalVariable>(Val) || 
isa<Function>(Val)438M
;
880
479M
  }
881
};
882
883
// Create wrappers for C Binding types (see CBindingWrapping.h).
884
DEFINE_ISA_CONVERSION_FUNCTIONS(Value, LLVMValueRef)
885
886
// Specialized opaque value conversions.
887
30
inline Value **unwrap(LLVMValueRef *Vals) {
888
30
  return reinterpret_cast<Value**>(Vals);
889
30
}
890
891
template<typename T>
892
13
inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
893
#ifndef NDEBUG
894
  for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
895
    unwrap<T>(*I); // For side effect of calling assert on invalid usage.
896
#endif
897
  (void)Length;
898
13
  return reinterpret_cast<T**>(Vals);
899
13
}
900
901
0
inline LLVMValueRef *wrap(const Value **Vals) {
902
0
  return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
903
0
}
904
905
} // end namespace llvm
906
907
#endif // LLVM_IR_VALUE_H