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