LLVM  3.7.0
Value.h
Go to the documentation of this file.
1 //===-- llvm/Value.h - Definition of the Value class ------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the Value class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IR_VALUE_H
15 #define LLVM_IR_VALUE_H
16 
17 #include "llvm-c/Core.h"
19 #include "llvm/IR/Use.h"
21 #include "llvm/Support/Casting.h"
22 #include "llvm/Support/Compiler.h"
23 
24 namespace llvm {
25 
26 class APInt;
27 class Argument;
28 class AssemblyAnnotationWriter;
29 class BasicBlock;
30 class Constant;
31 class DataLayout;
32 class Function;
33 class GlobalAlias;
34 class GlobalObject;
35 class GlobalValue;
36 class GlobalVariable;
37 class InlineAsm;
38 class Instruction;
39 class LLVMContext;
40 class Module;
41 class ModuleSlotTracker;
42 class StringRef;
43 class Twine;
44 class Type;
45 class ValueHandleBase;
46 class ValueSymbolTable;
47 class raw_ostream;
48 
49 template<typename ValueTy> class StringMapEntry;
51 
52 //===----------------------------------------------------------------------===//
53 // Value Class
54 //===----------------------------------------------------------------------===//
55 
56 /// \brief LLVM Value Representation
57 ///
58 /// This is a very important LLVM class. It is the base class of all values
59 /// computed by a program that may be used as operands to other values. Value is
60 /// the super class of other important classes such as Instruction and Function.
61 /// All Values have a Type. Type is not a subclass of Value. Some values can
62 /// have a name and they belong to some Module. Setting the name on the Value
63 /// automatically updates the module's symbol table.
64 ///
65 /// Every value has a "use list" that keeps track of which other Values are
66 /// using this Value. A Value can also have an arbitrary number of ValueHandle
67 /// objects that watch it and listen to RAUW and Destroy events. See
68 /// llvm/IR/ValueHandle.h for details.
69 class Value {
70  Type *VTy;
71  Use *UseList;
72 
73  friend class ValueAsMetadata; // Allow access to IsUsedByMD.
74  friend class ValueHandleBase;
75 
76  const unsigned char SubclassID; // Subclass identifier (for isa/dyn_cast)
77  unsigned char HasValueHandle : 1; // Has a ValueHandle pointing to this?
78 protected:
79  /// \brief Hold subclass data that can be dropped.
80  ///
81  /// This member is similar to SubclassData, however it is for holding
82  /// information which may be used to aid optimization, but which may be
83  /// cleared to zero without affecting conservative interpretation.
84  unsigned char SubclassOptionalData : 7;
85 
86 private:
87  /// \brief Hold arbitrary subclass data.
88  ///
89  /// This member is defined by this class, but is not used for anything.
90  /// Subclasses can use it to hold whatever state they find useful. This
91  /// field is initialized to zero by the ctor.
92  unsigned short SubclassData;
93 
94 protected:
95  /// \brief The number of operands in the subclass.
96  ///
97  /// This member is defined by this class, but not used for anything.
98  /// Subclasses can use it to store their number of operands, if they have
99  /// any.
100  ///
101  /// This is stored here to save space in User on 64-bit hosts. Since most
102  /// instances of Value have operands, 32-bit hosts aren't significantly
103  /// affected.
104  ///
105  /// Note, this should *NOT* be used directly by any class other than User.
106  /// User uses this value to find the Use list.
107  enum : unsigned { NumUserOperandsBits = 29 };
109 
110  bool IsUsedByMD : 1;
111  bool HasName : 1;
112  bool HasHungOffUses : 1;
113 
114 private:
115  template <typename UseT> // UseT == 'Use' or 'const Use'
116  class use_iterator_impl
117  : public std::iterator<std::forward_iterator_tag, UseT *> {
118  UseT *U;
119  explicit use_iterator_impl(UseT *u) : U(u) {}
120  friend class Value;
121 
122  public:
123  use_iterator_impl() : U() {}
124 
125  bool operator==(const use_iterator_impl &x) const { return U == x.U; }
126  bool operator!=(const use_iterator_impl &x) const { return !operator==(x); }
127 
128  use_iterator_impl &operator++() { // Preincrement
129  assert(U && "Cannot increment end iterator!");
130  U = U->getNext();
131  return *this;
132  }
133  use_iterator_impl operator++(int) { // Postincrement
134  auto tmp = *this;
135  ++*this;
136  return tmp;
137  }
138 
139  UseT &operator*() const {
140  assert(U && "Cannot dereference end iterator!");
141  return *U;
142  }
143 
144  UseT *operator->() const { return &operator*(); }
145 
146  operator use_iterator_impl<const UseT>() const {
147  return use_iterator_impl<const UseT>(U);
148  }
149  };
150 
151  template <typename UserTy> // UserTy == 'User' or 'const User'
152  class user_iterator_impl
153  : public std::iterator<std::forward_iterator_tag, UserTy *> {
154  use_iterator_impl<Use> UI;
155  explicit user_iterator_impl(Use *U) : UI(U) {}
156  friend class Value;
157 
158  public:
159  user_iterator_impl() {}
160 
161  bool operator==(const user_iterator_impl &x) const { return UI == x.UI; }
162  bool operator!=(const user_iterator_impl &x) const { return !operator==(x); }
163 
164  /// \brief Returns true if this iterator is equal to user_end() on the value.
165  bool atEnd() const { return *this == user_iterator_impl(); }
166 
167  user_iterator_impl &operator++() { // Preincrement
168  ++UI;
169  return *this;
170  }
171  user_iterator_impl operator++(int) { // Postincrement
172  auto tmp = *this;
173  ++*this;
174  return tmp;
175  }
176 
177  // Retrieve a pointer to the current User.
178  UserTy *operator*() const {
179  return UI->getUser();
180  }
181 
182  UserTy *operator->() const { return operator*(); }
183 
184  operator user_iterator_impl<const UserTy>() const {
185  return user_iterator_impl<const UserTy>(*UI);
186  }
187 
188  Use &getUse() const { return *UI; }
189  };
190 
191  void operator=(const Value &) = delete;
192  Value(const Value &) = delete;
193 
194 protected:
195  Value(Type *Ty, unsigned scid);
196 public:
197  virtual ~Value();
198 
199  /// \brief Support for debugging, callable in GDB: V->dump()
200  void dump() const;
201 
202  /// \brief Implement operator<< on Value.
203  /// @{
204  void print(raw_ostream &O) const;
205  void print(raw_ostream &O, ModuleSlotTracker &MST) const;
206  /// @}
207 
208  /// \brief Print the name of this Value out to the specified raw_ostream.
209  ///
210  /// This is useful when you just want to print 'int %reg126', not the
211  /// instruction that generated it. If you specify a Module for context, then
212  /// even constanst get pretty-printed; for example, the type of a null
213  /// pointer is printed symbolically.
214  /// @{
215  void printAsOperand(raw_ostream &O, bool PrintType = true,
216  const Module *M = nullptr) const;
217  void printAsOperand(raw_ostream &O, bool PrintType,
218  ModuleSlotTracker &MST) const;
219  /// @}
220 
221  /// \brief All values are typed, get the type of this value.
222  Type *getType() const { return VTy; }
223 
224  /// \brief All values hold a context through their type.
225  LLVMContext &getContext() const;
226 
227  // \brief All values can potentially be named.
228  bool hasName() const { return HasName; }
229  ValueName *getValueName() const;
230  void setValueName(ValueName *VN);
231 
232 private:
233  void destroyValueName();
234  void setNameImpl(const Twine &Name);
235 
236 public:
237  /// \brief Return a constant reference to the value's name.
238  ///
239  /// This is cheap and guaranteed to return the same reference as long as the
240  /// value is not modified.
241  StringRef getName() const;
242 
243  /// \brief Change the name of the value.
244  ///
245  /// Choose a new unique name if the provided name is taken.
246  ///
247  /// \param Name The new name; or "" if the value's name should be removed.
248  void setName(const Twine &Name);
249 
250 
251  /// \brief Transfer the name from V to this value.
252  ///
253  /// After taking V's name, sets V's name to empty.
254  ///
255  /// \note It is an error to call V->takeName(V).
256  void takeName(Value *V);
257 
258  /// \brief Change all uses of this to point to a new Value.
259  ///
260  /// Go through the uses list for this definition and make each use point to
261  /// "V" instead of "this". After this completes, 'this's use list is
262  /// guaranteed to be empty.
263  void replaceAllUsesWith(Value *V);
264 
265  /// replaceUsesOutsideBlock - Go through the uses list for this definition and
266  /// make each use point to "V" instead of "this" when the use is outside the
267  /// block. 'This's use list is expected to have at least one element.
268  /// Unlike replaceAllUsesWith this function does not support basic block
269  /// values or constant users.
271 
272  //----------------------------------------------------------------------
273  // Methods for handling the chain of uses of this Value.
274  //
275  bool use_empty() const { return UseList == nullptr; }
276 
277  typedef use_iterator_impl<Use> use_iterator;
278  typedef use_iterator_impl<const Use> const_use_iterator;
279  use_iterator use_begin() { return use_iterator(UseList); }
280  const_use_iterator use_begin() const { return const_use_iterator(UseList); }
285  }
288  }
289 
290  bool user_empty() const { return UseList == nullptr; }
291 
292  typedef user_iterator_impl<User> user_iterator;
293  typedef user_iterator_impl<const User> const_user_iterator;
294  user_iterator user_begin() { return user_iterator(UseList); }
298  User *user_back() { return *user_begin(); }
299  const User *user_back() const { return *user_begin(); }
302  }
305  }
306 
307  /// \brief Return true if there is exactly one user of this value.
308  ///
309  /// This is specialized because it is a common request and does not require
310  /// traversing the whole use list.
311  bool hasOneUse() const {
313  if (I == E) return false;
314  return ++I == E;
315  }
316 
317  /// \brief Return true if this Value has exactly N users.
318  bool hasNUses(unsigned N) const;
319 
320  /// \brief Return true if this value has N users or more.
321  ///
322  /// This is logically equivalent to getNumUses() >= N.
323  bool hasNUsesOrMore(unsigned N) const;
324 
325  /// \brief Check if this value is used in the specified basic block.
326  bool isUsedInBasicBlock(const BasicBlock *BB) const;
327 
328  /// \brief This method computes the number of uses of this Value.
329  ///
330  /// This is a linear time operation. Use hasOneUse, hasNUses, or
331  /// hasNUsesOrMore to check for specific values.
332  unsigned getNumUses() const;
333 
334  /// \brief This method should only be used by the Use class.
335  void addUse(Use &U) { U.addToList(&UseList); }
336 
337  /// \brief Concrete subclass of this.
338  ///
339  /// An enumeration for keeping track of the concrete subclass of Value that
340  /// is actually instantiated. Values of this enumeration are kept in the
341  /// Value classes SubclassID field. They are used for concrete type
342  /// identification.
343  enum ValueTy {
344 #define HANDLE_VALUE(Name) Name##Val,
345 #include "llvm/IR/Value.def"
346 
347  // Markers:
348 #define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
349 #include "llvm/IR/Value.def"
350  };
351 
352  /// \brief Return an ID for the concrete type of this object.
353  ///
354  /// This is used to implement the classof checks. This should not be used
355  /// for any other purpose, as the values may change as LLVM evolves. Also,
356  /// note that for instructions, the Instruction's opcode is added to
357  /// InstructionVal. So this means three things:
358  /// # there is no value with code InstructionVal (no opcode==0).
359  /// # there are more possible values for the value type than in ValueTy enum.
360  /// # the InstructionVal enumerator must be the highest valued enumerator in
361  /// the ValueTy enum.
362  unsigned getValueID() const {
363  return SubclassID;
364  }
365 
366  /// \brief Return the raw optional flags value contained in this value.
367  ///
368  /// This should only be used when testing two Values for equivalence.
369  unsigned getRawSubclassOptionalData() const {
370  return SubclassOptionalData;
371  }
372 
373  /// \brief Clear the optional flags contained in this value.
376  }
377 
378  /// \brief Check the optional flags for equality.
379  bool hasSameSubclassOptionalData(const Value *V) const {
381  }
382 
383  /// \brief Clear any optional flags not set in the given Value.
386  }
387 
388  /// \brief Return true if there is a value handle associated with this value.
389  bool hasValueHandle() const { return HasValueHandle; }
390 
391  /// \brief Return true if there is metadata referencing this value.
392  bool isUsedByMetadata() const { return IsUsedByMD; }
393 
394  /// \brief Strip off pointer casts, all-zero GEPs, and aliases.
395  ///
396  /// Returns the original uncasted value. If this is called on a non-pointer
397  /// value, it returns 'this'.
399  const Value *stripPointerCasts() const {
400  return const_cast<Value*>(this)->stripPointerCasts();
401  }
402 
403  /// \brief Strip off pointer casts and all-zero GEPs.
404  ///
405  /// Returns the original uncasted value. If this is called on a non-pointer
406  /// value, it returns 'this'.
409  return const_cast<Value*>(this)->stripPointerCastsNoFollowAliases();
410  }
411 
412  /// \brief Strip off pointer casts and all-constant inbounds GEPs.
413  ///
414  /// Returns the original pointer value. If this is called on a non-pointer
415  /// value, it returns 'this'.
418  return const_cast<Value*>(this)->stripInBoundsConstantOffsets();
419  }
420 
421  /// \brief Accumulate offsets from \a stripInBoundsConstantOffsets().
422  ///
423  /// Stores the resulting constant offset stripped into the APInt provided.
424  /// The provided APInt will be extended or truncated as needed to be the
425  /// correct bitwidth for an offset of this pointer type.
426  ///
427  /// If this is called on a non-pointer value, it returns 'this'.
429  APInt &Offset);
431  APInt &Offset) const {
432  return const_cast<Value *>(this)
434  }
435 
436  /// \brief Strip off pointer casts and inbounds GEPs.
437  ///
438  /// Returns the original pointer value. If this is called on a non-pointer
439  /// value, it returns 'this'.
441  const Value *stripInBoundsOffsets() const {
442  return const_cast<Value*>(this)->stripInBoundsOffsets();
443  }
444 
445  /// \brief Translate PHI node to its predecessor from the given basic block.
446  ///
447  /// If this value is a PHI node with CurBB as its parent, return the value in
448  /// the PHI node corresponding to PredBB. If not, return ourself. This is
449  /// useful if you want to know the value something has in a predecessor
450  /// block.
451  Value *DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB);
452 
453  const Value *DoPHITranslation(const BasicBlock *CurBB,
454  const BasicBlock *PredBB) const{
455  return const_cast<Value*>(this)->DoPHITranslation(CurBB, PredBB);
456  }
457 
458  /// \brief The maximum alignment for instructions.
459  ///
460  /// This is the greatest alignment value supported by load, store, and alloca
461  /// instructions, and global values.
462  static const unsigned MaxAlignmentExponent = 29;
463  static const unsigned MaximumAlignment = 1u << MaxAlignmentExponent;
464 
465  /// \brief Mutate the type of this Value to be of the specified type.
466  ///
467  /// Note that this is an extremely dangerous operation which can create
468  /// completely invalid IR very easily. It is strongly recommended that you
469  /// recreate IR objects with the right types instead of mutating them in
470  /// place.
471  void mutateType(Type *Ty) {
472  VTy = Ty;
473  }
474 
475  /// \brief Sort the use-list.
476  ///
477  /// Sorts the Value's use-list by Cmp using a stable mergesort. Cmp is
478  /// expected to compare two \a Use references.
479  template <class Compare> void sortUseList(Compare Cmp);
480 
481  /// \brief Reverse the use-list.
482  void reverseUseList();
483 
484 private:
485  /// \brief Merge two lists together.
486  ///
487  /// Merges \c L and \c R using \c Cmp. To enable stable sorts, always pushes
488  /// "equal" items from L before items from R.
489  ///
490  /// \return the first element in the list.
491  ///
492  /// \note Completely ignores \a Use::Prev (doesn't read, doesn't update).
493  template <class Compare>
494  static Use *mergeUseLists(Use *L, Use *R, Compare Cmp) {
495  Use *Merged;
496  mergeUseListsImpl(L, R, &Merged, Cmp);
497  return Merged;
498  }
499 
500  /// \brief Tail-recursive helper for \a mergeUseLists().
501  ///
502  /// \param[out] Next the first element in the list.
503  template <class Compare>
504  static void mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp);
505 
506 protected:
507  unsigned short getSubclassDataFromValue() const { return SubclassData; }
508  void setValueSubclassData(unsigned short D) { SubclassData = D; }
509 };
510 
511 inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) {
512  V.print(OS);
513  return OS;
514 }
515 
516 void Use::set(Value *V) {
517  if (Val) removeFromList();
518  Val = V;
519  if (V) V->addUse(*this);
520 }
521 
522 template <class Compare> void Value::sortUseList(Compare Cmp) {
523  if (!UseList || !UseList->Next)
524  // No need to sort 0 or 1 uses.
525  return;
526 
527  // Note: this function completely ignores Prev pointers until the end when
528  // they're fixed en masse.
529 
530  // Create a binomial vector of sorted lists, visiting uses one at a time and
531  // merging lists as necessary.
532  const unsigned MaxSlots = 32;
533  Use *Slots[MaxSlots];
534 
535  // Collect the first use, turning it into a single-item list.
536  Use *Next = UseList->Next;
537  UseList->Next = nullptr;
538  unsigned NumSlots = 1;
539  Slots[0] = UseList;
540 
541  // Collect all but the last use.
542  while (Next->Next) {
543  Use *Current = Next;
544  Next = Current->Next;
545 
546  // Turn Current into a single-item list.
547  Current->Next = nullptr;
548 
549  // Save Current in the first available slot, merging on collisions.
550  unsigned I;
551  for (I = 0; I < NumSlots; ++I) {
552  if (!Slots[I])
553  break;
554 
555  // Merge two lists, doubling the size of Current and emptying slot I.
556  //
557  // Since the uses in Slots[I] originally preceded those in Current, send
558  // Slots[I] in as the left parameter to maintain a stable sort.
559  Current = mergeUseLists(Slots[I], Current, Cmp);
560  Slots[I] = nullptr;
561  }
562  // Check if this is a new slot.
563  if (I == NumSlots) {
564  ++NumSlots;
565  assert(NumSlots <= MaxSlots && "Use list bigger than 2^32");
566  }
567 
568  // Found an open slot.
569  Slots[I] = Current;
570  }
571 
572  // Merge all the lists together.
573  assert(Next && "Expected one more Use");
574  assert(!Next->Next && "Expected only one Use");
575  UseList = Next;
576  for (unsigned I = 0; I < NumSlots; ++I)
577  if (Slots[I])
578  // Since the uses in Slots[I] originally preceded those in UseList, send
579  // Slots[I] in as the left parameter to maintain a stable sort.
580  UseList = mergeUseLists(Slots[I], UseList, Cmp);
581 
582  // Fix the Prev pointers.
583  for (Use *I = UseList, **Prev = &UseList; I; I = I->Next) {
584  I->setPrev(Prev);
585  Prev = &I->Next;
586  }
587 }
588 
589 template <class Compare>
590 void Value::mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp) {
591  if (!L) {
592  *Next = R;
593  return;
594  }
595  if (!R) {
596  *Next = L;
597  return;
598  }
599  if (Cmp(*R, *L)) {
600  *Next = R;
601  mergeUseListsImpl(L, R->Next, &R->Next, Cmp);
602  return;
603  }
604  *Next = L;
605  mergeUseListsImpl(L->Next, R, &L->Next, Cmp);
606 }
607 
608 // isa - Provide some specializations of isa so that we don't have to include
609 // the subtype header files to test to see if the value is a subclass...
610 //
611 template <> struct isa_impl<Constant, Value> {
612  static inline bool doit(const Value &Val) {
613  return Val.getValueID() >= Value::ConstantFirstVal &&
614  Val.getValueID() <= Value::ConstantLastVal;
615  }
616 };
617 
618 template <> struct isa_impl<Argument, Value> {
619  static inline bool doit (const Value &Val) {
620  return Val.getValueID() == Value::ArgumentVal;
621  }
622 };
623 
624 template <> struct isa_impl<InlineAsm, Value> {
625  static inline bool doit(const Value &Val) {
626  return Val.getValueID() == Value::InlineAsmVal;
627  }
628 };
629 
630 template <> struct isa_impl<Instruction, Value> {
631  static inline bool doit(const Value &Val) {
632  return Val.getValueID() >= Value::InstructionVal;
633  }
634 };
635 
636 template <> struct isa_impl<BasicBlock, Value> {
637  static inline bool doit(const Value &Val) {
638  return Val.getValueID() == Value::BasicBlockVal;
639  }
640 };
641 
642 template <> struct isa_impl<Function, Value> {
643  static inline bool doit(const Value &Val) {
644  return Val.getValueID() == Value::FunctionVal;
645  }
646 };
647 
648 template <> struct isa_impl<GlobalVariable, Value> {
649  static inline bool doit(const Value &Val) {
650  return Val.getValueID() == Value::GlobalVariableVal;
651  }
652 };
653 
654 template <> struct isa_impl<GlobalAlias, Value> {
655  static inline bool doit(const Value &Val) {
656  return Val.getValueID() == Value::GlobalAliasVal;
657  }
658 };
659 
660 template <> struct isa_impl<GlobalValue, Value> {
661  static inline bool doit(const Value &Val) {
662  return isa<GlobalObject>(Val) || isa<GlobalAlias>(Val);
663  }
664 };
665 
666 template <> struct isa_impl<GlobalObject, Value> {
667  static inline bool doit(const Value &Val) {
668  return isa<GlobalVariable>(Val) || isa<Function>(Val);
669  }
670 };
671 
672 // Value* is only 4-byte aligned.
673 template<>
675  typedef Value* PT;
676 public:
677  static inline void *getAsVoidPointer(PT P) { return P; }
678  static inline PT getFromVoidPointer(void *P) {
679  return static_cast<PT>(P);
680  }
681  enum { NumLowBitsAvailable = 2 };
682 };
683 
684 // Create wrappers for C Binding types (see CBindingWrapping.h).
686 
687 /* Specialized opaque value conversions.
688  */
690  return reinterpret_cast<Value**>(Vals);
691 }
692 
693 template<typename T>
694 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
695 #ifdef DEBUG
696  for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
697  cast<T>(*I);
698 #endif
699  (void)Length;
700  return reinterpret_cast<T**>(Vals);
701 }
702 
703 inline LLVMValueRef *wrap(const Value **Vals) {
704  return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
705 }
706 
707 } // End llvm namespace
708 
709 #endif
This is the common base class of value handles.
Definition: ValueHandle.h:41
void sortUseList(Compare Cmp)
Sort the use-list.
Definition: Value.h:522
use_iterator use_end()
Definition: Value.h:281
use_iterator_impl< Use > use_iterator
Definition: Value.h:277
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:104
Value * stripInBoundsConstantOffsets()
Strip off pointer casts and all-constant inbounds GEPs.
Definition: Value.cpp:466
iterator_range< use_iterator > uses()
Definition: Value.h:283
LLVM Argument representation.
Definition: Argument.h:35
const Value * stripInBoundsConstantOffsets() const
Definition: Value.h:417
bool hasName() const
Definition: Value.h:228
void addUse(Use &U)
This method should only be used by the Use class.
Definition: Value.h:335
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:28
Various leaf nodes.
Definition: ISDOpcodes.h:60
const Value * stripPointerCastsNoFollowAliases() const
Definition: Value.h:408
bool hasNUses(unsigned N) const
Return true if this Value has exactly N users.
Definition: Value.cpp:96
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
static bool doit(const Value &Val)
Definition: Value.h:649
static void * getAsVoidPointer(PT P)
Definition: Value.h:677
const_user_iterator user_begin() const
Definition: Value.h:295
This defines the Use class.
bool HasHungOffUses
Definition: Value.h:112
PointerLikeTypeTraits - This is a traits object that is used to handle pointer types and things that ...
static PT getFromVoidPointer(void *P)
Definition: Value.h:678
const_use_iterator use_begin() const
Definition: Value.h:280
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Definition: Value.h:453
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:188
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
A Use represents the edge between a Value definition and its users.
Definition: Use.h:69
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:250
void print(raw_ostream &O) const
Implement operator<< on Value.
Definition: AsmWriter.cpp:3209
static bool doit(const Value &Val)
Definition: Value.h:637
static const unsigned MaximumAlignment
Definition: Value.h:463
Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset)
Accumulate offsets from stripInBoundsConstantOffsets().
Definition: Value.cpp:470
#define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)
static bool doit(const Value &Val)
Definition: Value.h:625
LLVMTargetDataRef wrap(const DataLayout *P)
Definition: DataLayout.h:469
user_iterator_impl< User > user_iterator
Definition: Value.h:292
bool HasName
Definition: Value.h:111
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
Definition: AsmWriter.cpp:3287
iterator_range< const_use_iterator > uses() const
Definition: Value.h:286
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:351
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:252
bool IsUsedByMD
Definition: Value.h:110
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:256
ValueName * getValueName() const
Definition: Value.cpp:160
Value * stripPointerCastsNoFollowAliases()
Strip off pointer casts and all-zero GEPs.
Definition: Value.cpp:462
#define P(N)
void intersectOptionalDataWith(const Value *V)
Clear any optional flags not set in the given Value.
Definition: Value.h:384
always inline
DataLayout * unwrap(LLVMTargetDataRef P)
Definition: DataLayout.h:465
void set(Value *Val)
Definition: Value.h:516
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:41
This is an important base class in LLVM.
Definition: Constant.h:41
Value * stripInBoundsOffsets()
Strip off pointer casts and inbounds GEPs.
Definition: Value.cpp:507
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
Definition: Value.h:392
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:362
bool hasValueHandle() const
Return true if there is a value handle associated with this value.
Definition: Value.h:389
iterator_range< const_user_iterator > users() const
Definition: Value.h:303
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:519
use_iterator_impl< const Use > const_use_iterator
Definition: Value.h:278
bool isUsedInBasicBlock(const BasicBlock *BB) const
Check if this value is used in the specified basic block.
Definition: Value.cpp:113
bool hasSameSubclassOptionalData(const Value *V) const
Check the optional flags for equality.
Definition: Value.h:379
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Core.h:92
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition: Value.h:84
void dump() const
Support for debugging, callable in GDB: V->dump()
Definition: AsmWriter.cpp:3353
const User * user_back() const
Definition: Value.h:299
static const unsigned MaxAlignmentExponent
The maximum alignment for instructions.
Definition: Value.h:462
BlockMass operator*(const BlockMass &L, const BranchProbability &R)
static bool doit(const Value &Val)
Definition: Value.h:667
Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB)
Translate PHI node to its predecessor from the given basic block.
Definition: Value.cpp:511
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:222
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
Definition: Value.cpp:458
unsigned NumUserOperands
Definition: Value.h:108
ValueTy
Concrete subclass of this.
Definition: Value.h:343
void setValueSubclassData(unsigned short D)
Definition: Value.h:508
const Value * stripInBoundsOffsets() const
Definition: Value.h:441
A range adaptor for a pair of iterators.
Class for arbitrary precision integers.
Definition: APInt.h:73
iterator_range< user_iterator > users()
Definition: Value.h:300
void reverseUseList()
Reverse the use-list.
Definition: Value.cpp:521
const Value * stripPointerCasts() const
Definition: Value.h:399
use_iterator use_begin()
Definition: Value.h:279
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:1736
user_iterator_impl< const User > const_user_iterator
Definition: Value.h:293
unsigned short getSubclassDataFromValue() const
Definition: Value.h:507
static bool doit(const Value &Val)
Definition: Value.h:631
unsigned getRawSubclassOptionalData() const
Return the raw optional flags value contained in this value.
Definition: Value.h:369
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
bool hasOneUse() const
Return true if there is exactly one user of this value.
Definition: Value.h:311
static bool doit(const Value &Val)
Definition: Value.h:612
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:1738
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
Definition: Value.h:471
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
Definition: Value.cpp:104
virtual ~Value()
Definition: Value.cpp:63
bool use_empty() const
Definition: Value.h:275
user_iterator user_begin()
Definition: Value.h:294
StringMapEntry< Value * > ValueName
Definition: Value.h:49
LLVM Value Representation.
Definition: Value.h:69
void clearSubclassOptionalData()
Clear the optional flags contained in this value.
Definition: Value.h:374
bool user_empty() const
Definition: Value.h:290
static bool doit(const Value &Val)
Definition: Value.h:619
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
void setValueName(ValueName *VN)
Definition: Value.cpp:171
static bool doit(const Value &Val)
Definition: Value.h:661
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
const_use_iterator use_end() const
Definition: Value.h:282
static bool doit(const Value &Val)
Definition: Value.h:655
void replaceUsesOutsideBlock(Value *V, BasicBlock *BB)
replaceUsesOutsideBlock - Go through the uses list for this definition and make each use point to "V"...
Definition: Value.cpp:384
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:1734
unsigned getNumUses() const
This method computes the number of uses of this Value.
Definition: Value.cpp:134
const_user_iterator user_end() const
Definition: Value.h:297
static bool doit(const Value &Val)
Definition: Value.h:643
const Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset) const
Definition: Value.h:430
User * user_back()
Definition: Value.h:298
user_iterator user_end()
Definition: Value.h:296