LLVM  6.0.0svn
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/Types.h"
19 #include "llvm/IR/Use.h"
21 #include "llvm/Support/Casting.h"
22 #include <cassert>
23 #include <iterator>
24 #include <memory>
25 
26 namespace llvm {
27 
28 class APInt;
29 class Argument;
30 class BasicBlock;
31 class Constant;
32 class ConstantData;
33 class ConstantAggregate;
34 class DataLayout;
35 class Function;
36 class GlobalAlias;
37 class GlobalIFunc;
38 class GlobalIndirectSymbol;
39 class GlobalObject;
40 class GlobalValue;
41 class GlobalVariable;
42 class InlineAsm;
43 class Instruction;
44 class LLVMContext;
45 class Module;
46 class ModuleSlotTracker;
47 class raw_ostream;
48 template<typename ValueTy> class StringMapEntry;
49 class StringRef;
50 class Twine;
51 class Type;
52 class User;
53 
55 
56 //===----------------------------------------------------------------------===//
57 // Value Class
58 //===----------------------------------------------------------------------===//
59 
60 /// \brief LLVM Value Representation
61 ///
62 /// This is a very important LLVM class. It is the base class of all values
63 /// computed by a program that may be used as operands to other values. Value is
64 /// the super class of other important classes such as Instruction and Function.
65 /// All Values have a Type. Type is not a subclass of Value. Some values can
66 /// have a name and they belong to some Module. Setting the name on the Value
67 /// automatically updates the module's symbol table.
68 ///
69 /// Every value has a "use list" that keeps track of which other Values are
70 /// using this Value. A Value can also have an arbitrary number of ValueHandle
71 /// objects that watch it and listen to RAUW and Destroy events. See
72 /// llvm/IR/ValueHandle.h for details.
73 class Value {
74  // The least-significant bit of the first word of Value *must* be zero:
75  // http://www.llvm.org/docs/ProgrammersManual.html#the-waymarking-algorithm
76  Type *VTy;
77  Use *UseList;
78 
79  friend class ValueAsMetadata; // Allow access to IsUsedByMD.
80  friend class ValueHandleBase;
81 
82  const unsigned char SubclassID; // Subclass identifier (for isa/dyn_cast)
83  unsigned char HasValueHandle : 1; // Has a ValueHandle pointing to this?
84 
85 protected:
86  /// \brief Hold subclass data that can be dropped.
87  ///
88  /// This member is similar to SubclassData, however it is for holding
89  /// information which may be used to aid optimization, but which may be
90  /// cleared to zero without affecting conservative interpretation.
91  unsigned char SubclassOptionalData : 7;
92 
93 private:
94  /// \brief Hold arbitrary subclass data.
95  ///
96  /// This member is defined by this class, but is not used for anything.
97  /// Subclasses can use it to hold whatever state they find useful. This
98  /// field is initialized to zero by the ctor.
99  unsigned short SubclassData;
100 
101 protected:
102  /// \brief The number of operands in the subclass.
103  ///
104  /// This member is defined by this class, but not used for anything.
105  /// Subclasses can use it to store their number of operands, if they have
106  /// any.
107  ///
108  /// This is stored here to save space in User on 64-bit hosts. Since most
109  /// instances of Value have operands, 32-bit hosts aren't significantly
110  /// affected.
111  ///
112  /// Note, this should *NOT* be used directly by any class other than User.
113  /// User uses this value to find the Use list.
114  enum : unsigned { NumUserOperandsBits = 28 };
116 
117  // Use the same type as the bitfield above so that MSVC will pack them.
118  unsigned IsUsedByMD : 1;
119  unsigned HasName : 1;
120  unsigned HasHungOffUses : 1;
121  unsigned HasDescriptor : 1;
122 
123 private:
124  template <typename UseT> // UseT == 'Use' or 'const Use'
125  class use_iterator_impl
126  : public std::iterator<std::forward_iterator_tag, UseT *> {
127  friend class Value;
128 
129  UseT *U;
130 
131  explicit use_iterator_impl(UseT *u) : U(u) {}
132 
133  public:
134  use_iterator_impl() : U() {}
135 
136  bool operator==(const use_iterator_impl &x) const { return U == x.U; }
137  bool operator!=(const use_iterator_impl &x) const { return !operator==(x); }
138 
139  use_iterator_impl &operator++() { // Preincrement
140  assert(U && "Cannot increment end iterator!");
141  U = U->getNext();
142  return *this;
143  }
144 
145  use_iterator_impl operator++(int) { // Postincrement
146  auto tmp = *this;
147  ++*this;
148  return tmp;
149  }
150 
151  UseT &operator*() const {
152  assert(U && "Cannot dereference end iterator!");
153  return *U;
154  }
155 
156  UseT *operator->() const { return &operator*(); }
157 
158  operator use_iterator_impl<const UseT>() const {
159  return use_iterator_impl<const UseT>(U);
160  }
161  };
162 
163  template <typename UserTy> // UserTy == 'User' or 'const User'
164  class user_iterator_impl
165  : public std::iterator<std::forward_iterator_tag, UserTy *> {
166  use_iterator_impl<Use> UI;
167  explicit user_iterator_impl(Use *U) : UI(U) {}
168  friend class Value;
169 
170  public:
171  user_iterator_impl() = default;
172 
173  bool operator==(const user_iterator_impl &x) const { return UI == x.UI; }
174  bool operator!=(const user_iterator_impl &x) const { return !operator==(x); }
175 
176  /// \brief Returns true if this iterator is equal to user_end() on the value.
177  bool atEnd() const { return *this == user_iterator_impl(); }
178 
179  user_iterator_impl &operator++() { // Preincrement
180  ++UI;
181  return *this;
182  }
183 
184  user_iterator_impl operator++(int) { // Postincrement
185  auto tmp = *this;
186  ++*this;
187  return tmp;
188  }
189 
190  // Retrieve a pointer to the current User.
191  UserTy *operator*() const {
192  return UI->getUser();
193  }
194 
195  UserTy *operator->() const { return operator*(); }
196 
197  operator user_iterator_impl<const UserTy>() const {
198  return user_iterator_impl<const UserTy>(*UI);
199  }
200 
201  Use &getUse() const { return *UI; }
202  };
203 
204 protected:
205  Value(Type *Ty, unsigned scid);
206 
207  /// Value's destructor should be virtual by design, but that would require
208  /// that Value and all of its subclasses have a vtable that effectively
209  /// duplicates the information in the value ID. As a size optimization, the
210  /// destructor has been protected, and the caller should manually call
211  /// deleteValue.
212  ~Value(); // Use deleteValue() to delete a generic Value.
213 
214 public:
215  Value(const Value &) = delete;
216  Value &operator=(const Value &) = delete;
217 
218  /// Delete a pointer to a generic Value.
219  void deleteValue();
220 
221  /// \brief Support for debugging, callable in GDB: V->dump()
222  void dump() const;
223 
224  /// \brief Implement operator<< on Value.
225  /// @{
226  void print(raw_ostream &O, bool IsForDebug = false) const;
227  void print(raw_ostream &O, ModuleSlotTracker &MST,
228  bool IsForDebug = false) const;
229  /// @}
230 
231  /// \brief Print the name of this Value out to the specified raw_ostream.
232  ///
233  /// This is useful when you just want to print 'int %reg126', not the
234  /// instruction that generated it. If you specify a Module for context, then
235  /// even constanst get pretty-printed; for example, the type of a null
236  /// pointer is printed symbolically.
237  /// @{
238  void printAsOperand(raw_ostream &O, bool PrintType = true,
239  const Module *M = nullptr) const;
240  void printAsOperand(raw_ostream &O, bool PrintType,
241  ModuleSlotTracker &MST) const;
242  /// @}
243 
244  /// \brief All values are typed, get the type of this value.
245  Type *getType() const { return VTy; }
246 
247  /// \brief All values hold a context through their type.
248  LLVMContext &getContext() const;
249 
250  // \brief All values can potentially be named.
251  bool hasName() const { return HasName; }
252  ValueName *getValueName() const;
253  void setValueName(ValueName *VN);
254 
255 private:
256  void destroyValueName();
257  void doRAUW(Value *New, bool NoMetadata);
258  void setNameImpl(const Twine &Name);
259 
260 public:
261  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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.
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.
301 
302  /// replaceUsesExceptBlockAddr - Go through the uses list for this definition
303  /// and make each use point to "V" instead of "this" when the use is outside
304  /// the block. 'This's use list is expected to have at least one element.
305  /// Unlike replaceAllUsesWith this function skips blockaddr uses.
307 
308  //----------------------------------------------------------------------
309  // Methods for handling the chain of uses of this Value.
310  //
311  // Materializing a function can introduce new uses, so these methods come in
312  // two variants:
313  // The methods that start with materialized_ check the uses that are
314  // currently known given which functions are materialized. Be very careful
315  // when using them since you might not get all uses.
316  // The methods that don't start with materialized_ assert that modules is
317  // fully materialized.
318  void assertModuleIsMaterializedImpl() const;
319  // This indirection exists so we can keep assertModuleIsMaterializedImpl()
320  // around in release builds of Value.cpp to be linked with other code built
321  // in debug mode. But this avoids calling it in any of the release built code.
323 #ifndef NDEBUG
325 #endif
326  }
327 
328  bool use_empty() const {
330  return UseList == nullptr;
331  }
332 
333  using use_iterator = use_iterator_impl<Use>;
334  using const_use_iterator = use_iterator_impl<const Use>;
335 
338  return const_use_iterator(UseList);
339  }
342  return materialized_use_begin();
343  }
346  return materialized_use_begin();
347  }
352  }
355  }
358  return materialized_uses();
359  }
362  return materialized_uses();
363  }
364 
365  bool user_empty() const {
367  return UseList == nullptr;
368  }
369 
370  using user_iterator = user_iterator_impl<User>;
371  using const_user_iterator = user_iterator_impl<const User>;
372 
375  return const_user_iterator(UseList);
376  }
379  return materialized_user_begin();
380  }
383  return materialized_user_begin();
384  }
389  return *materialized_user_begin();
390  }
391  const User *user_back() const {
393  return *materialized_user_begin();
394  }
397  }
400  }
403  return materialized_users();
404  }
407  return materialized_users();
408  }
409 
410  /// \brief Return true if there is exactly one user of this value.
411  ///
412  /// This is specialized because it is a common request and does not require
413  /// traversing the whole use list.
414  bool hasOneUse() const {
416  if (I == E) return false;
417  return ++I == E;
418  }
419 
420  /// \brief Return true if this Value has exactly N users.
421  bool hasNUses(unsigned N) const;
422 
423  /// \brief Return true if this value has N users or more.
424  ///
425  /// This is logically equivalent to getNumUses() >= N.
426  bool hasNUsesOrMore(unsigned N) const;
427 
428  /// \brief Check if this value is used in the specified basic block.
429  bool isUsedInBasicBlock(const BasicBlock *BB) const;
430 
431  /// \brief This method computes the number of uses of this Value.
432  ///
433  /// This is a linear time operation. Use hasOneUse, hasNUses, or
434  /// hasNUsesOrMore to check for specific values.
435  unsigned getNumUses() const;
436 
437  /// \brief This method should only be used by the Use class.
438  void addUse(Use &U) { U.addToList(&UseList); }
439 
440  /// \brief Concrete subclass of this.
441  ///
442  /// An enumeration for keeping track of the concrete subclass of Value that
443  /// is actually instantiated. Values of this enumeration are kept in the
444  /// Value classes SubclassID field. They are used for concrete type
445  /// identification.
446  enum ValueTy {
447 #define HANDLE_VALUE(Name) Name##Val,
448 #include "llvm/IR/Value.def"
449 
450  // Markers:
451 #define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
452 #include "llvm/IR/Value.def"
453  };
454 
455  /// \brief Return an ID for the concrete type of this object.
456  ///
457  /// This is used to implement the classof checks. This should not be used
458  /// for any other purpose, as the values may change as LLVM evolves. Also,
459  /// note that for instructions, the Instruction's opcode is added to
460  /// InstructionVal. So this means three things:
461  /// # there is no value with code InstructionVal (no opcode==0).
462  /// # there are more possible values for the value type than in ValueTy enum.
463  /// # the InstructionVal enumerator must be the highest valued enumerator in
464  /// the ValueTy enum.
465  unsigned getValueID() const {
466  return SubclassID;
467  }
468 
469  /// \brief Return the raw optional flags value contained in this value.
470  ///
471  /// This should only be used when testing two Values for equivalence.
472  unsigned getRawSubclassOptionalData() const {
473  return SubclassOptionalData;
474  }
475 
476  /// \brief Clear the optional flags contained in this value.
479  }
480 
481  /// \brief Check the optional flags for equality.
482  bool hasSameSubclassOptionalData(const Value *V) const {
484  }
485 
486  /// \brief Return true if there is a value handle associated with this value.
487  bool hasValueHandle() const { return HasValueHandle; }
488 
489  /// \brief Return true if there is metadata referencing this value.
490  bool isUsedByMetadata() const { return IsUsedByMD; }
491 
492  /// \brief Return true if this value is a swifterror value.
493  ///
494  /// swifterror values can be either a function argument or an alloca with a
495  /// swifterror attribute.
496  bool isSwiftError() const;
497 
498  /// \brief Strip off pointer casts, all-zero GEPs, and aliases.
499  ///
500  /// Returns the original uncasted value. If this is called on a non-pointer
501  /// value, it returns 'this'.
502  const Value *stripPointerCasts() const;
504  return const_cast<Value *>(
505  static_cast<const Value *>(this)->stripPointerCasts());
506  }
507 
508  /// \brief Strip off pointer casts, all-zero GEPs, aliases and barriers.
509  ///
510  /// Returns the original uncasted value. If this is called on a non-pointer
511  /// value, it returns 'this'. This function should be used only in
512  /// Alias analysis.
513  const Value *stripPointerCastsAndBarriers() const;
515  return const_cast<Value *>(
516  static_cast<const Value *>(this)->stripPointerCastsAndBarriers());
517  }
518 
519  /// \brief Strip off pointer casts and all-zero GEPs.
520  ///
521  /// Returns the original uncasted value. If this is called on a non-pointer
522  /// value, it returns 'this'.
525  return const_cast<Value *>(
526  static_cast<const Value *>(this)->stripPointerCastsNoFollowAliases());
527  }
528 
529  /// \brief Strip off pointer casts and all-constant inbounds GEPs.
530  ///
531  /// Returns the original pointer value. If this is called on a non-pointer
532  /// value, it returns 'this'.
533  const Value *stripInBoundsConstantOffsets() const;
535  return const_cast<Value *>(
536  static_cast<const Value *>(this)->stripInBoundsConstantOffsets());
537  }
538 
539  /// \brief Accumulate offsets from \a stripInBoundsConstantOffsets().
540  ///
541  /// Stores the resulting constant offset stripped into the APInt provided.
542  /// The provided APInt will be extended or truncated as needed to be the
543  /// correct bitwidth for an offset of this pointer type.
544  ///
545  /// If this is called on a non-pointer value, it returns 'this'.
547  APInt &Offset) const;
549  APInt &Offset) {
550  return const_cast<Value *>(static_cast<const Value *>(this)
552  }
553 
554  /// \brief Strip off pointer casts and inbounds GEPs.
555  ///
556  /// Returns the original pointer value. If this is called on a non-pointer
557  /// value, it returns 'this'.
558  const Value *stripInBoundsOffsets() const;
560  return const_cast<Value *>(
561  static_cast<const Value *>(this)->stripInBoundsOffsets());
562  }
563 
564  /// \brief Returns the number of bytes known to be dereferenceable for the
565  /// pointer value.
566  ///
567  /// If CanBeNull is set by this function the pointer can either be null or be
568  /// dereferenceable up to the returned number of bytes.
569  unsigned getPointerDereferenceableBytes(const DataLayout &DL,
570  bool &CanBeNull) const;
571 
572  /// \brief Returns an alignment of the pointer value.
573  ///
574  /// Returns an alignment which is either specified explicitly, e.g. via
575  /// align attribute of a function argument, or guaranteed by DataLayout.
576  unsigned getPointerAlignment(const DataLayout &DL) const;
577 
578  /// \brief Translate PHI node to its predecessor from the given basic block.
579  ///
580  /// If this value is a PHI node with CurBB as its parent, return the value in
581  /// the PHI node corresponding to PredBB. If not, return ourself. This is
582  /// useful if you want to know the value something has in a predecessor
583  /// block.
584  const Value *DoPHITranslation(const BasicBlock *CurBB,
585  const BasicBlock *PredBB) const;
586  Value *DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) {
587  return const_cast<Value *>(
588  static_cast<const Value *>(this)->DoPHITranslation(CurBB, PredBB));
589  }
590 
591  /// \brief The maximum alignment for instructions.
592  ///
593  /// This is the greatest alignment value supported by load, store, and alloca
594  /// instructions, and global values.
595  static const unsigned MaxAlignmentExponent = 29;
596  static const unsigned MaximumAlignment = 1u << MaxAlignmentExponent;
597 
598  /// \brief Mutate the type of this Value to be of the specified type.
599  ///
600  /// Note that this is an extremely dangerous operation which can create
601  /// completely invalid IR very easily. It is strongly recommended that you
602  /// recreate IR objects with the right types instead of mutating them in
603  /// place.
604  void mutateType(Type *Ty) {
605  VTy = Ty;
606  }
607 
608  /// \brief Sort the use-list.
609  ///
610  /// Sorts the Value's use-list by Cmp using a stable mergesort. Cmp is
611  /// expected to compare two \a Use references.
612  template <class Compare> void sortUseList(Compare Cmp);
613 
614  /// \brief Reverse the use-list.
615  void reverseUseList();
616 
617 private:
618  /// \brief Merge two lists together.
619  ///
620  /// Merges \c L and \c R using \c Cmp. To enable stable sorts, always pushes
621  /// "equal" items from L before items from R.
622  ///
623  /// \return the first element in the list.
624  ///
625  /// \note Completely ignores \a Use::Prev (doesn't read, doesn't update).
626  template <class Compare>
627  static Use *mergeUseLists(Use *L, Use *R, Compare Cmp) {
628  Use *Merged;
629  Use **Next = &Merged;
630 
631  while (true) {
632  if (!L) {
633  *Next = R;
634  break;
635  }
636  if (!R) {
637  *Next = L;
638  break;
639  }
640  if (Cmp(*R, *L)) {
641  *Next = R;
642  Next = &R->Next;
643  R = R->Next;
644  } else {
645  *Next = L;
646  Next = &L->Next;
647  L = L->Next;
648  }
649  }
650 
651  return Merged;
652  }
653 
654  /// \brief Tail-recursive helper for \a mergeUseLists().
655  ///
656  /// \param[out] Next the first element in the list.
657  template <class Compare>
658  static void mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp);
659 
660 protected:
661  unsigned short getSubclassDataFromValue() const { return SubclassData; }
662  void setValueSubclassData(unsigned short D) { SubclassData = D; }
663 };
664 
665 struct ValueDeleter { void operator()(Value *V) { V->deleteValue(); } };
666 
667 /// Use this instead of std::unique_ptr<Value> or std::unique_ptr<Instruction>.
668 /// Those don't work because Value and Instruction's destructors are protected,
669 /// aren't virtual, and won't destroy the complete object.
670 using unique_value = std::unique_ptr<Value, ValueDeleter>;
671 
672 inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) {
673  V.print(OS);
674  return OS;
675 }
676 
677 void Use::set(Value *V) {
678  if (Val) removeFromList();
679  Val = V;
680  if (V) V->addUse(*this);
681 }
682 
684  set(RHS);
685  return RHS;
686 }
687 
688 const Use &Use::operator=(const Use &RHS) {
689  set(RHS.Val);
690  return *this;
691 }
692 
693 template <class Compare> void Value::sortUseList(Compare Cmp) {
694  if (!UseList || !UseList->Next)
695  // No need to sort 0 or 1 uses.
696  return;
697 
698  // Note: this function completely ignores Prev pointers until the end when
699  // they're fixed en masse.
700 
701  // Create a binomial vector of sorted lists, visiting uses one at a time and
702  // merging lists as necessary.
703  const unsigned MaxSlots = 32;
704  Use *Slots[MaxSlots];
705 
706  // Collect the first use, turning it into a single-item list.
707  Use *Next = UseList->Next;
708  UseList->Next = nullptr;
709  unsigned NumSlots = 1;
710  Slots[0] = UseList;
711 
712  // Collect all but the last use.
713  while (Next->Next) {
714  Use *Current = Next;
715  Next = Current->Next;
716 
717  // Turn Current into a single-item list.
718  Current->Next = nullptr;
719 
720  // Save Current in the first available slot, merging on collisions.
721  unsigned I;
722  for (I = 0; I < NumSlots; ++I) {
723  if (!Slots[I])
724  break;
725 
726  // Merge two lists, doubling the size of Current and emptying slot I.
727  //
728  // Since the uses in Slots[I] originally preceded those in Current, send
729  // Slots[I] in as the left parameter to maintain a stable sort.
730  Current = mergeUseLists(Slots[I], Current, Cmp);
731  Slots[I] = nullptr;
732  }
733  // Check if this is a new slot.
734  if (I == NumSlots) {
735  ++NumSlots;
736  assert(NumSlots <= MaxSlots && "Use list bigger than 2^32");
737  }
738 
739  // Found an open slot.
740  Slots[I] = Current;
741  }
742 
743  // Merge all the lists together.
744  assert(Next && "Expected one more Use");
745  assert(!Next->Next && "Expected only one Use");
746  UseList = Next;
747  for (unsigned I = 0; I < NumSlots; ++I)
748  if (Slots[I])
749  // Since the uses in Slots[I] originally preceded those in UseList, send
750  // Slots[I] in as the left parameter to maintain a stable sort.
751  UseList = mergeUseLists(Slots[I], UseList, Cmp);
752 
753  // Fix the Prev pointers.
754  for (Use *I = UseList, **Prev = &UseList; I; I = I->Next) {
755  I->setPrev(Prev);
756  Prev = &I->Next;
757  }
758 }
759 
760 // isa - Provide some specializations of isa so that we don't have to include
761 // the subtype header files to test to see if the value is a subclass...
762 //
763 template <> struct isa_impl<Constant, Value> {
764  static inline bool doit(const Value &Val) {
765  static_assert(Value::ConstantFirstVal == 0, "Val.getValueID() >= Value::ConstantFirstVal");
766  return Val.getValueID() <= Value::ConstantLastVal;
767  }
768 };
769 
770 template <> struct isa_impl<ConstantData, Value> {
771  static inline bool doit(const Value &Val) {
772  return Val.getValueID() >= Value::ConstantDataFirstVal &&
773  Val.getValueID() <= Value::ConstantDataLastVal;
774  }
775 };
776 
777 template <> struct isa_impl<ConstantAggregate, Value> {
778  static inline bool doit(const Value &Val) {
779  return Val.getValueID() >= Value::ConstantAggregateFirstVal &&
780  Val.getValueID() <= Value::ConstantAggregateLastVal;
781  }
782 };
783 
784 template <> struct isa_impl<Argument, Value> {
785  static inline bool doit (const Value &Val) {
786  return Val.getValueID() == Value::ArgumentVal;
787  }
788 };
789 
790 template <> struct isa_impl<InlineAsm, Value> {
791  static inline bool doit(const Value &Val) {
792  return Val.getValueID() == Value::InlineAsmVal;
793  }
794 };
795 
796 template <> struct isa_impl<Instruction, Value> {
797  static inline bool doit(const Value &Val) {
798  return Val.getValueID() >= Value::InstructionVal;
799  }
800 };
801 
802 template <> struct isa_impl<BasicBlock, Value> {
803  static inline bool doit(const Value &Val) {
804  return Val.getValueID() == Value::BasicBlockVal;
805  }
806 };
807 
808 template <> struct isa_impl<Function, Value> {
809  static inline bool doit(const Value &Val) {
810  return Val.getValueID() == Value::FunctionVal;
811  }
812 };
813 
814 template <> struct isa_impl<GlobalVariable, Value> {
815  static inline bool doit(const Value &Val) {
816  return Val.getValueID() == Value::GlobalVariableVal;
817  }
818 };
819 
820 template <> struct isa_impl<GlobalAlias, Value> {
821  static inline bool doit(const Value &Val) {
822  return Val.getValueID() == Value::GlobalAliasVal;
823  }
824 };
825 
826 template <> struct isa_impl<GlobalIFunc, Value> {
827  static inline bool doit(const Value &Val) {
828  return Val.getValueID() == Value::GlobalIFuncVal;
829  }
830 };
831 
832 template <> struct isa_impl<GlobalIndirectSymbol, Value> {
833  static inline bool doit(const Value &Val) {
834  return isa<GlobalAlias>(Val) || isa<GlobalIFunc>(Val);
835  }
836 };
837 
838 template <> struct isa_impl<GlobalValue, Value> {
839  static inline bool doit(const Value &Val) {
840  return isa<GlobalObject>(Val) || isa<GlobalIndirectSymbol>(Val);
841  }
842 };
843 
844 template <> struct isa_impl<GlobalObject, Value> {
845  static inline bool doit(const Value &Val) {
846  return isa<GlobalVariable>(Val) || isa<Function>(Val);
847  }
848 };
849 
850 // Create wrappers for C Binding types (see CBindingWrapping.h).
852 
853 // Specialized opaque value conversions.
855  return reinterpret_cast<Value**>(Vals);
856 }
857 
858 template<typename T>
859 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
860 #ifndef NDEBUG
861  for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
862  unwrap<T>(*I); // For side effect of calling assert on invalid usage.
863 #endif
864  (void)Length;
865  return reinterpret_cast<T**>(Vals);
866 }
867 
868 inline LLVMValueRef *wrap(const Value **Vals) {
869  return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
870 }
871 
872 } // end namespace llvm
873 
874 #endif // LLVM_IR_VALUE_H
This is the common base class of value handles.
Definition: ValueHandle.h:30
unsigned short getSubclassDataFromValue() const
Definition: Value.h:661
void sortUseList(Compare Cmp)
Sort the use-list.
Definition: Value.h:693
use_iterator use_end()
Definition: Value.h:348
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
unsigned HasDescriptor
Definition: Value.h:121
iterator_range< use_iterator > uses()
Definition: Value.h:356
void operator()(Value *V)
Definition: Value.h:665
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:465
const Value * stripInBoundsOffsets() const
Strip off pointer casts and inbounds GEPs.
Definition: Value.cpp:618
static bool doit(const Value &Val)
Definition: Value.h:778
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void addUse(Use &U)
This method should only be used by the Use class.
Definition: Value.h:438
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:126
Various leaf nodes.
Definition: ISDOpcodes.h:60
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
bool user_empty() const
Definition: Value.h:365
const Value * stripPointerCastsAndBarriers() const
Strip off pointer casts, all-zero GEPs, aliases and barriers.
Definition: Value.cpp:570
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
use_iterator materialized_use_begin()
Definition: Value.h:336
bool hasValueHandle() const
Return true if there is a value handle associated with this value.
Definition: Value.h:487
iterator_range< const_user_iterator > users() const
Definition: Value.h:405
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:728
static bool doit(const Value &Val)
Definition: Value.h:815
void deleteValue()
Delete a pointer to a generic Value.
Definition: Value.cpp:95
Manage lifetime of a slot tracker for printing IR.
This defines the Use class.
use_iterator_impl< const Use > const_use_iterator
Definition: Value.h:334
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Translate PHI node to its predecessor from the given basic block.
Definition: Value.cpp:720
unsigned getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
Definition: Value.cpp:673
iterator_range< user_iterator > materialized_users()
Definition: Value.h:395
void dump() const
Support for debugging, callable in GDB: V->dump()
Definition: AsmWriter.cpp:3641
const_user_iterator materialized_user_begin() const
Definition: Value.h:374
iterator_range< const_user_iterator > materialized_users() const
Definition: Value.h:398
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:195
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:286
void assertModuleIsMaterializedImpl() const
Definition: Value.cpp:352
static bool doit(const Value &Val)
Definition: Value.h:803
static const unsigned MaximumAlignment
Definition: Value.h:596
#define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)
APInt operator*(APInt a, uint64_t RHS)
Definition: APInt.h:2070
static bool doit(const Value &Val)
Definition: Value.h:791
unsigned getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull) const
Returns the number of bytes known to be dereferenceable for the pointer value.
Definition: Value.cpp:622
Value * stripInBoundsOffsets()
Definition: Value.h:559
unsigned HasHungOffUses
Definition: Value.h:120
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
iterator_range< const_use_iterator > materialized_uses() const
Definition: Value.h:353
bool isSwiftError() const
Return true if this value is a swifterror value.
Definition: Value.cpp:749
static bool doit(const Value &Val)
Definition: Value.h:833
const_use_iterator use_end() const
Definition: Value.h:349
const_use_iterator materialized_use_begin() const
Definition: Value.h:337
Value * stripPointerCastsNoFollowAliases()
Definition: Value.h:524
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:430
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:337
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:292
use_iterator_impl< Use > use_iterator
Definition: Value.h:333
unsigned getRawSubclassOptionalData() const
Return the raw optional flags value contained in this value.
Definition: Value.h:472
const_use_iterator use_begin() const
Definition: Value.h:344
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
Definition: Value.cpp:136
bool hasNUses(unsigned N) const
Return true if this Value has exactly N users.
Definition: Value.cpp:128
void set(Value *Val)
Definition: Value.h:677
bool hasName() const
Definition: Value.h:251
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
void replaceNonMetadataUsesWith(Value *V)
Change non-metadata uses of this to point to a new Value.
Definition: Value.cpp:434
amdgpu inline
iterator_range< use_iterator > materialized_uses()
Definition: Value.h:350
bool isUsedInBasicBlock(const BasicBlock *BB) const
Check if this value is used in the specified basic block.
Definition: Value.cpp:145
bool hasSameSubclassOptionalData(const Value *V) const
Check the optional flags for equality.
Definition: Value.h:482
static bool doit(const Value &Val)
Definition: Value.h:827
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
Definition: AsmWriter.cpp:3494
Value * stripInBoundsConstantOffsets()
Definition: Value.h:534
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Definition: Value.cpp:558
Value(Type *Ty, unsigned scid)
Definition: Value.cpp:50
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:3573
Value * stripPointerCasts()
Definition: Value.h:503
Value & operator=(const Value &)=delete
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition: Value.h:91
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static const unsigned MaxAlignmentExponent
The maximum alignment for instructions.
Definition: Value.h:595
unsigned IsUsedByMD
Definition: Value.h:118
void assertModuleIsMaterialized() const
Definition: Value.h:322
static bool doit(const Value &Val)
Definition: Value.h:845
ValueName * getValueName() const
Definition: Value.cpp:192
const User * user_back() const
Definition: Value.h:391
std::unique_ptr< Value, ValueDeleter > unique_value
Use this instead of std::unique_ptr<Value> or std::unique_ptr<Instruction>.
Definition: Value.h:670
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
unsigned NumUserOperands
Definition: Value.h:115
ValueTy
Concrete subclass of this.
Definition: Value.h:446
void setValueSubclassData(unsigned short D)
Definition: Value.h:662
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
Definition: Value.h:490
A range adaptor for a pair of iterators.
const Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset) const
Accumulate offsets from stripInBoundsConstantOffsets().
Definition: Value.cpp:576
Class for arbitrary precision integers.
Definition: APInt.h:69
const_user_iterator user_begin() const
Definition: Value.h:381
iterator_range< user_iterator > users()
Definition: Value.h:401
user_iterator_impl< const User > const_user_iterator
Definition: Value.h:371
could "use" a pointer
void reverseUseList()
Reverse the use-list.
Definition: Value.cpp:730
iterator_range< const_use_iterator > uses() const
Definition: Value.h:360
use_iterator use_begin()
Definition: Value.h:340
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:1948
unsigned getNumUses() const
This method computes the number of uses of this Value.
Definition: Value.cpp:166
unsigned HasName
Definition: Value.h:119
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:190
static bool doit(const Value &Val)
Definition: Value.h:797
const Value * stripPointerCastsNoFollowAliases() const
Strip off pointer casts and all-zero GEPs.
Definition: Value.cpp:562
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:220
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
user_iterator_impl< User > user_iterator
Definition: Value.h:370
Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB)
Definition: Value.h:586
static bool doit(const Value &Val)
Definition: Value.h:764
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2018
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
Definition: Value.h:604
~Value()
Value&#39;s destructor should be virtual by design, but that would require that Value and all of its subc...
Definition: Value.cpp:69
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
Definition: Value.h:377
Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset)
Definition: Value.h:548
Base class for aggregate constants (with operands).
Definition: Constants.h:381
LLVM Value Representation.
Definition: Value.h:73
const_user_iterator user_end() const
Definition: Value.h:386
void clearSubclassOptionalData()
Clear the optional flags contained in this value.
Definition: Value.h:477
static bool doit(const Value &Val)
Definition: Value.h:785
Value * stripPointerCastsAndBarriers()
Definition: Value.h:514
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
user_iterator materialized_user_begin()
Definition: Value.h:373
void setValueName(ValueName *VN)
Definition: Value.cpp:203
static bool doit(const Value &Val)
Definition: Value.h:839
bool hasOneUse() const
Return true if there is exactly one user of this value.
Definition: Value.h:414
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static bool doit(const Value &Val)
Definition: Value.h:821
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:440
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:1946
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
Definition: Value.cpp:566
void replaceUsesExceptBlockAddr(Value *New)
replaceUsesExceptBlockAddr - Go through the uses list for this definition and make each use point to ...
Definition: Value.cpp:459
Base class for constants with no operands.
Definition: Constants.h:58
Value * operator=(Value *RHS)
Definition: Value.h:683
bool use_empty() const
Definition: Value.h:328
static bool doit(const Value &Val)
Definition: Value.h:809
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:76
User * user_back()
Definition: Value.h:387
static bool doit(const Value &Val)
Definition: Value.h:771
user_iterator user_end()
Definition: Value.h:385