LLVM API Documentation

Value.h
Go to the documentation of this file.
00001 //===-- llvm/Value.h - Definition of the Value class ------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the Value class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_IR_VALUE_H
00015 #define LLVM_IR_VALUE_H
00016 
00017 #include "llvm-c/Core.h"
00018 #include "llvm/ADT/iterator_range.h"
00019 #include "llvm/IR/Use.h"
00020 #include "llvm/Support/CBindingWrapping.h"
00021 #include "llvm/Support/Casting.h"
00022 #include "llvm/Support/Compiler.h"
00023 
00024 namespace llvm {
00025 
00026 class APInt;
00027 class Argument;
00028 class AssemblyAnnotationWriter;
00029 class BasicBlock;
00030 class Constant;
00031 class DataLayout;
00032 class Function;
00033 class GlobalAlias;
00034 class GlobalObject;
00035 class GlobalValue;
00036 class GlobalVariable;
00037 class InlineAsm;
00038 class Instruction;
00039 class LLVMContext;
00040 class MDNode;
00041 class Module;
00042 class StringRef;
00043 class Twine;
00044 class Type;
00045 class ValueHandleBase;
00046 class ValueSymbolTable;
00047 class raw_ostream;
00048 
00049 template<typename ValueTy> class StringMapEntry;
00050 typedef StringMapEntry<Value*> ValueName;
00051 
00052 //===----------------------------------------------------------------------===//
00053 //                                 Value Class
00054 //===----------------------------------------------------------------------===//
00055 
00056 /// This is a very important LLVM class. It is the base class of all values
00057 /// computed by a program that may be used as operands to other values. Value is
00058 /// the super class of other important classes such as Instruction and Function.
00059 /// All Values have a Type. Type is not a subclass of Value. Some values can
00060 /// have a name and they belong to some Module.  Setting the name on the Value
00061 /// automatically updates the module's symbol table.
00062 ///
00063 /// Every value has a "use list" that keeps track of which other Values are
00064 /// using this Value.  A Value can also have an arbitrary number of ValueHandle
00065 /// objects that watch it and listen to RAUW and Destroy events.  See
00066 /// llvm/IR/ValueHandle.h for details.
00067 ///
00068 /// @brief LLVM Value Representation
00069 class Value {
00070   Type *VTy;
00071   Use *UseList;
00072 
00073   friend class ValueSymbolTable; // Allow ValueSymbolTable to directly mod Name.
00074   friend class ValueHandleBase;
00075   ValueName *Name;
00076 
00077   const unsigned char SubclassID;   // Subclass identifier (for isa/dyn_cast)
00078   unsigned char HasValueHandle : 1; // Has a ValueHandle pointing to this?
00079 protected:
00080   /// SubclassOptionalData - This member is similar to SubclassData, however it
00081   /// is for holding information which may be used to aid optimization, but
00082   /// which may be cleared to zero without affecting conservative
00083   /// interpretation.
00084   unsigned char SubclassOptionalData : 7;
00085 
00086 private:
00087   /// SubclassData - This member is defined by this class, but is not used for
00088   /// anything.  Subclasses can use it to hold whatever state they find useful.
00089   /// This field is initialized to zero by the ctor.
00090   unsigned short SubclassData;
00091 
00092   template <typename UseT> // UseT == 'Use' or 'const Use'
00093   class use_iterator_impl
00094       : public std::iterator<std::forward_iterator_tag, UseT *, ptrdiff_t> {
00095     typedef std::iterator<std::forward_iterator_tag, UseT *, ptrdiff_t> super;
00096 
00097     UseT *U;
00098     explicit use_iterator_impl(UseT *u) : U(u) {}
00099     friend class Value;
00100 
00101   public:
00102     typedef typename super::reference reference;
00103     typedef typename super::pointer pointer;
00104 
00105     use_iterator_impl() : U() {}
00106 
00107     bool operator==(const use_iterator_impl &x) const { return U == x.U; }
00108     bool operator!=(const use_iterator_impl &x) const { return !operator==(x); }
00109 
00110     use_iterator_impl &operator++() { // Preincrement
00111       assert(U && "Cannot increment end iterator!");
00112       U = U->getNext();
00113       return *this;
00114     }
00115     use_iterator_impl operator++(int) { // Postincrement
00116       auto tmp = *this;
00117       ++*this;
00118       return tmp;
00119     }
00120 
00121     UseT &operator*() const {
00122       assert(U && "Cannot dereference end iterator!");
00123       return *U;
00124     }
00125 
00126     UseT *operator->() const { return &operator*(); }
00127 
00128     operator use_iterator_impl<const UseT>() const {
00129       return use_iterator_impl<const UseT>(U);
00130     }
00131   };
00132 
00133   template <typename UserTy> // UserTy == 'User' or 'const User'
00134   class user_iterator_impl
00135       : public std::iterator<std::forward_iterator_tag, UserTy *, ptrdiff_t> {
00136     typedef std::iterator<std::forward_iterator_tag, UserTy *, ptrdiff_t> super;
00137 
00138     use_iterator_impl<Use> UI;
00139     explicit user_iterator_impl(Use *U) : UI(U) {}
00140     friend class Value;
00141 
00142   public:
00143     typedef typename super::reference reference;
00144     typedef typename super::pointer pointer;
00145 
00146     user_iterator_impl() {}
00147 
00148     bool operator==(const user_iterator_impl &x) const { return UI == x.UI; }
00149     bool operator!=(const user_iterator_impl &x) const { return !operator==(x); }
00150 
00151     /// \brief Returns true if this iterator is equal to user_end() on the value.
00152     bool atEnd() const { return *this == user_iterator_impl(); }
00153 
00154     user_iterator_impl &operator++() { // Preincrement
00155       ++UI;
00156       return *this;
00157     }
00158     user_iterator_impl operator++(int) { // Postincrement
00159       auto tmp = *this;
00160       ++*this;
00161       return tmp;
00162     }
00163 
00164     // Retrieve a pointer to the current User.
00165     UserTy *operator*() const {
00166       return UI->getUser();
00167     }
00168 
00169     UserTy *operator->() const { return operator*(); }
00170 
00171     operator user_iterator_impl<const UserTy>() const {
00172       return user_iterator_impl<const UserTy>(*UI);
00173     }
00174 
00175     Use &getUse() const { return *UI; }
00176 
00177     /// \brief Return the operand # of this use in its User.
00178     /// FIXME: Replace all callers with a direct call to Use::getOperandNo.
00179     unsigned getOperandNo() const { return UI->getOperandNo(); }
00180   };
00181 
00182   void operator=(const Value &) LLVM_DELETED_FUNCTION;
00183   Value(const Value &) LLVM_DELETED_FUNCTION;
00184 
00185 protected:
00186   Value(Type *Ty, unsigned scid);
00187 public:
00188   virtual ~Value();
00189 
00190   /// dump - Support for debugging, callable in GDB: V->dump()
00191   //
00192   void dump() const;
00193 
00194   /// print - Implement operator<< on Value.
00195   ///
00196   void print(raw_ostream &O) const;
00197 
00198   /// \brief Print the name of this Value out to the specified raw_ostream.
00199   /// This is useful when you just want to print 'int %reg126', not the
00200   /// instruction that generated it. If you specify a Module for context, then
00201   /// even constanst get pretty-printed; for example, the type of a null
00202   /// pointer is printed symbolically.
00203   void printAsOperand(raw_ostream &O, bool PrintType = true,
00204                       const Module *M = nullptr) const;
00205 
00206   /// All values are typed, get the type of this value.
00207   ///
00208   Type *getType() const { return VTy; }
00209 
00210   /// All values hold a context through their type.
00211   LLVMContext &getContext() const;
00212 
00213   // All values can potentially be named.
00214   bool hasName() const { return Name != nullptr && SubclassID != MDStringVal; }
00215   ValueName *getValueName() const { return Name; }
00216   void setValueName(ValueName *VN) { Name = VN; }
00217 
00218   /// getName() - Return a constant reference to the value's name. This is cheap
00219   /// and guaranteed to return the same reference as long as the value is not
00220   /// modified.
00221   StringRef getName() const;
00222 
00223   /// setName() - Change the name of the value, choosing a new unique name if
00224   /// the provided name is taken.
00225   ///
00226   /// \param Name The new name; or "" if the value's name should be removed.
00227   void setName(const Twine &Name);
00228 
00229 
00230   /// takeName - transfer the name from V to this value, setting V's name to
00231   /// empty.  It is an error to call V->takeName(V).
00232   void takeName(Value *V);
00233 
00234   /// replaceAllUsesWith - Go through the uses list for this definition and make
00235   /// each use point to "V" instead of "this".  After this completes, 'this's
00236   /// use list is guaranteed to be empty.
00237   ///
00238   void replaceAllUsesWith(Value *V);
00239 
00240   //----------------------------------------------------------------------
00241   // Methods for handling the chain of uses of this Value.
00242   //
00243   bool               use_empty() const { return UseList == nullptr; }
00244 
00245   typedef use_iterator_impl<Use>       use_iterator;
00246   typedef use_iterator_impl<const Use> const_use_iterator;
00247   use_iterator       use_begin()       { return use_iterator(UseList); }
00248   const_use_iterator use_begin() const { return const_use_iterator(UseList); }
00249   use_iterator       use_end()         { return use_iterator();   }
00250   const_use_iterator use_end()   const { return const_use_iterator();   }
00251   iterator_range<use_iterator> uses() {
00252     return iterator_range<use_iterator>(use_begin(), use_end());
00253   }
00254   iterator_range<const_use_iterator> uses() const {
00255     return iterator_range<const_use_iterator>(use_begin(), use_end());
00256   }
00257 
00258   typedef user_iterator_impl<User>       user_iterator;
00259   typedef user_iterator_impl<const User> const_user_iterator;
00260   user_iterator       user_begin()       { return user_iterator(UseList); }
00261   const_user_iterator user_begin() const { return const_user_iterator(UseList); }
00262   user_iterator       user_end()         { return user_iterator();   }
00263   const_user_iterator user_end()   const { return const_user_iterator();   }
00264   User               *user_back()        { return *user_begin(); }
00265   const User         *user_back()  const { return *user_begin(); }
00266   iterator_range<user_iterator> users() {
00267     return iterator_range<user_iterator>(user_begin(), user_end());
00268   }
00269   iterator_range<const_user_iterator> users() const {
00270     return iterator_range<const_user_iterator>(user_begin(), user_end());
00271   }
00272 
00273   /// hasOneUse - Return true if there is exactly one user of this value.  This
00274   /// is specialized because it is a common request and does not require
00275   /// traversing the whole use list.
00276   ///
00277   bool hasOneUse() const {
00278     const_use_iterator I = use_begin(), E = use_end();
00279     if (I == E) return false;
00280     return ++I == E;
00281   }
00282 
00283   /// hasNUses - Return true if this Value has exactly N users.
00284   ///
00285   bool hasNUses(unsigned N) const;
00286 
00287   /// hasNUsesOrMore - Return true if this value has N users or more.  This is
00288   /// logically equivalent to getNumUses() >= N.
00289   ///
00290   bool hasNUsesOrMore(unsigned N) const;
00291 
00292   bool isUsedInBasicBlock(const BasicBlock *BB) const;
00293 
00294   /// getNumUses - This method computes the number of uses of this Value.  This
00295   /// is a linear time operation.  Use hasOneUse, hasNUses, or hasNUsesOrMore
00296   /// to check for specific values.
00297   unsigned getNumUses() const;
00298 
00299   /// addUse - This method should only be used by the Use class.
00300   ///
00301   void addUse(Use &U) { U.addToList(&UseList); }
00302 
00303   /// An enumeration for keeping track of the concrete subclass of Value that
00304   /// is actually instantiated. Values of this enumeration are kept in the
00305   /// Value classes SubclassID field. They are used for concrete type
00306   /// identification.
00307   enum ValueTy {
00308     ArgumentVal,              // This is an instance of Argument
00309     BasicBlockVal,            // This is an instance of BasicBlock
00310     FunctionVal,              // This is an instance of Function
00311     GlobalAliasVal,           // This is an instance of GlobalAlias
00312     GlobalVariableVal,        // This is an instance of GlobalVariable
00313     UndefValueVal,            // This is an instance of UndefValue
00314     BlockAddressVal,          // This is an instance of BlockAddress
00315     ConstantExprVal,          // This is an instance of ConstantExpr
00316     ConstantAggregateZeroVal, // This is an instance of ConstantAggregateZero
00317     ConstantDataArrayVal,     // This is an instance of ConstantDataArray
00318     ConstantDataVectorVal,    // This is an instance of ConstantDataVector
00319     ConstantIntVal,           // This is an instance of ConstantInt
00320     ConstantFPVal,            // This is an instance of ConstantFP
00321     ConstantArrayVal,         // This is an instance of ConstantArray
00322     ConstantStructVal,        // This is an instance of ConstantStruct
00323     ConstantVectorVal,        // This is an instance of ConstantVector
00324     ConstantPointerNullVal,   // This is an instance of ConstantPointerNull
00325     MDNodeVal,                // This is an instance of MDNode
00326     MDStringVal,              // This is an instance of MDString
00327     InlineAsmVal,             // This is an instance of InlineAsm
00328     InstructionVal,           // This is an instance of Instruction
00329     // Enum values starting at InstructionVal are used for Instructions;
00330     // don't add new values here!
00331 
00332     // Markers:
00333     ConstantFirstVal = FunctionVal,
00334     ConstantLastVal  = ConstantPointerNullVal
00335   };
00336 
00337   /// getValueID - Return an ID for the concrete type of this object.  This is
00338   /// used to implement the classof checks.  This should not be used for any
00339   /// other purpose, as the values may change as LLVM evolves.  Also, note that
00340   /// for instructions, the Instruction's opcode is added to InstructionVal. So
00341   /// this means three things:
00342   /// # there is no value with code InstructionVal (no opcode==0).
00343   /// # there are more possible values for the value type than in ValueTy enum.
00344   /// # the InstructionVal enumerator must be the highest valued enumerator in
00345   ///   the ValueTy enum.
00346   unsigned getValueID() const {
00347     return SubclassID;
00348   }
00349 
00350   /// getRawSubclassOptionalData - Return the raw optional flags value
00351   /// contained in this value. This should only be used when testing two
00352   /// Values for equivalence.
00353   unsigned getRawSubclassOptionalData() const {
00354     return SubclassOptionalData;
00355   }
00356 
00357   /// clearSubclassOptionalData - Clear the optional flags contained in
00358   /// this value.
00359   void clearSubclassOptionalData() {
00360     SubclassOptionalData = 0;
00361   }
00362 
00363   /// hasSameSubclassOptionalData - Test whether the optional flags contained
00364   /// in this value are equal to the optional flags in the given value.
00365   bool hasSameSubclassOptionalData(const Value *V) const {
00366     return SubclassOptionalData == V->SubclassOptionalData;
00367   }
00368 
00369   /// intersectOptionalDataWith - Clear any optional flags in this value
00370   /// that are not also set in the given value.
00371   void intersectOptionalDataWith(const Value *V) {
00372     SubclassOptionalData &= V->SubclassOptionalData;
00373   }
00374 
00375   /// hasValueHandle - Return true if there is a value handle associated with
00376   /// this value.
00377   bool hasValueHandle() const { return HasValueHandle; }
00378 
00379   /// \brief Strips off any unneeded pointer casts, all-zero GEPs and aliases
00380   /// from the specified value, returning the original uncasted value.
00381   ///
00382   /// If this is called on a non-pointer value, it returns 'this'.
00383   Value *stripPointerCasts();
00384   const Value *stripPointerCasts() const {
00385     return const_cast<Value*>(this)->stripPointerCasts();
00386   }
00387 
00388   /// \brief Strips off any unneeded pointer casts and all-zero GEPs from the
00389   /// specified value, returning the original uncasted value.
00390   ///
00391   /// If this is called on a non-pointer value, it returns 'this'.
00392   Value *stripPointerCastsNoFollowAliases();
00393   const Value *stripPointerCastsNoFollowAliases() const {
00394     return const_cast<Value*>(this)->stripPointerCastsNoFollowAliases();
00395   }
00396 
00397   /// \brief Strips off unneeded pointer casts and all-constant GEPs from the
00398   /// specified value, returning the original pointer value.
00399   ///
00400   /// If this is called on a non-pointer value, it returns 'this'.
00401   Value *stripInBoundsConstantOffsets();
00402   const Value *stripInBoundsConstantOffsets() const {
00403     return const_cast<Value*>(this)->stripInBoundsConstantOffsets();
00404   }
00405 
00406   /// \brief Strips like \c stripInBoundsConstantOffsets but also accumulates
00407   /// the constant offset stripped.
00408   ///
00409   /// Stores the resulting constant offset stripped into the APInt provided.
00410   /// The provided APInt will be extended or truncated as needed to be the
00411   /// correct bitwidth for an offset of this pointer type.
00412   ///
00413   /// If this is called on a non-pointer value, it returns 'this'.
00414   Value *stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL,
00415                                                    APInt &Offset);
00416   const Value *stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL,
00417                                                          APInt &Offset) const {
00418     return const_cast<Value *>(this)
00419         ->stripAndAccumulateInBoundsConstantOffsets(DL, Offset);
00420   }
00421 
00422   /// \brief Strips off unneeded pointer casts and any in-bounds offsets from
00423   /// the specified value, returning the original pointer value.
00424   ///
00425   /// If this is called on a non-pointer value, it returns 'this'.
00426   Value *stripInBoundsOffsets();
00427   const Value *stripInBoundsOffsets() const {
00428     return const_cast<Value*>(this)->stripInBoundsOffsets();
00429   }
00430 
00431   /// isDereferenceablePointer - Test if this value is always a pointer to
00432   /// allocated and suitably aligned memory for a simple load or store.
00433   bool isDereferenceablePointer(const DataLayout *DL = nullptr) const;
00434 
00435   /// DoPHITranslation - If this value is a PHI node with CurBB as its parent,
00436   /// return the value in the PHI node corresponding to PredBB.  If not, return
00437   /// ourself.  This is useful if you want to know the value something has in a
00438   /// predecessor block.
00439   Value *DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB);
00440 
00441   const Value *DoPHITranslation(const BasicBlock *CurBB,
00442                                 const BasicBlock *PredBB) const{
00443     return const_cast<Value*>(this)->DoPHITranslation(CurBB, PredBB);
00444   }
00445 
00446   /// MaximumAlignment - This is the greatest alignment value supported by
00447   /// load, store, and alloca instructions, and global values.
00448   static const unsigned MaximumAlignment = 1u << 29;
00449 
00450   /// mutateType - Mutate the type of this Value to be of the specified type.
00451   /// Note that this is an extremely dangerous operation which can create
00452   /// completely invalid IR very easily.  It is strongly recommended that you
00453   /// recreate IR objects with the right types instead of mutating them in
00454   /// place.
00455   void mutateType(Type *Ty) {
00456     VTy = Ty;
00457   }
00458 
00459   /// \brief Sort the use-list.
00460   ///
00461   /// Sorts the Value's use-list by Cmp using a stable mergesort.  Cmp is
00462   /// expected to compare two \a Use references.
00463   template <class Compare> void sortUseList(Compare Cmp);
00464 
00465 private:
00466   /// \brief Merge two lists together.
00467   ///
00468   /// Merges \c L and \c R using \c Cmp.  To enable stable sorts, always pushes
00469   /// "equal" items from L before items from R.
00470   ///
00471   /// \return the first element in the list.
00472   ///
00473   /// \note Completely ignores \a Use::Prev (doesn't read, doesn't update).
00474   template <class Compare>
00475   static Use *mergeUseLists(Use *L, Use *R, Compare Cmp) {
00476     Use *Merged;
00477     mergeUseListsImpl(L, R, &Merged, Cmp);
00478     return Merged;
00479   }
00480 
00481   /// \brief Tail-recursive helper for \a mergeUseLists().
00482   ///
00483   /// \param[out] Next the first element in the list.
00484   template <class Compare>
00485   static void mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp);
00486 
00487 protected:
00488   unsigned short getSubclassDataFromValue() const { return SubclassData; }
00489   void setValueSubclassData(unsigned short D) { SubclassData = D; }
00490 };
00491 
00492 inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) {
00493   V.print(OS);
00494   return OS;
00495 }
00496 
00497 void Use::set(Value *V) {
00498   if (Val) removeFromList();
00499   Val = V;
00500   if (V) V->addUse(*this);
00501 }
00502 
00503 template <class Compare> void Value::sortUseList(Compare Cmp) {
00504   if (!UseList || !UseList->Next)
00505     // No need to sort 0 or 1 uses.
00506     return;
00507 
00508   // Note: this function completely ignores Prev pointers until the end when
00509   // they're fixed en masse.
00510 
00511   // Create a binomial vector of sorted lists, visiting uses one at a time and
00512   // merging lists as necessary.
00513   const unsigned MaxSlots = 32;
00514   Use *Slots[MaxSlots];
00515 
00516   // Collect the first use, turning it into a single-item list.
00517   Use *Next = UseList->Next;
00518   UseList->Next = nullptr;
00519   unsigned NumSlots = 1;
00520   Slots[0] = UseList;
00521 
00522   // Collect all but the last use.
00523   while (Next->Next) {
00524     Use *Current = Next;
00525     Next = Current->Next;
00526 
00527     // Turn Current into a single-item list.
00528     Current->Next = nullptr;
00529 
00530     // Save Current in the first available slot, merging on collisions.
00531     unsigned I;
00532     for (I = 0; I < NumSlots; ++I) {
00533       if (!Slots[I])
00534         break;
00535 
00536       // Merge two lists, doubling the size of Current and emptying slot I.
00537       //
00538       // Since the uses in Slots[I] originally preceded those in Current, send
00539       // Slots[I] in as the left parameter to maintain a stable sort.
00540       Current = mergeUseLists(Slots[I], Current, Cmp);
00541       Slots[I] = nullptr;
00542     }
00543     // Check if this is a new slot.
00544     if (I == NumSlots) {
00545       ++NumSlots;
00546       assert(NumSlots <= MaxSlots && "Use list bigger than 2^32");
00547     }
00548 
00549     // Found an open slot.
00550     Slots[I] = Current;
00551   }
00552 
00553   // Merge all the lists together.
00554   assert(Next && "Expected one more Use");
00555   assert(!Next->Next && "Expected only one Use");
00556   UseList = Next;
00557   for (unsigned I = 0; I < NumSlots; ++I)
00558     if (Slots[I])
00559       // Since the uses in Slots[I] originally preceded those in UseList, send
00560       // Slots[I] in as the left parameter to maintain a stable sort.
00561       UseList = mergeUseLists(Slots[I], UseList, Cmp);
00562 
00563   // Fix the Prev pointers.
00564   for (Use *I = UseList, **Prev = &UseList; I; I = I->Next) {
00565     I->setPrev(Prev);
00566     Prev = &I->Next;
00567   }
00568 }
00569 
00570 template <class Compare>
00571 void Value::mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp) {
00572   if (!L) {
00573     *Next = R;
00574     return;
00575   }
00576   if (!R) {
00577     *Next = L;
00578     return;
00579   }
00580   if (Cmp(*R, *L)) {
00581     *Next = R;
00582     mergeUseListsImpl(L, R->Next, &R->Next, Cmp);
00583     return;
00584   }
00585   *Next = L;
00586   mergeUseListsImpl(L->Next, R, &L->Next, Cmp);
00587 }
00588 
00589 // isa - Provide some specializations of isa so that we don't have to include
00590 // the subtype header files to test to see if the value is a subclass...
00591 //
00592 template <> struct isa_impl<Constant, Value> {
00593   static inline bool doit(const Value &Val) {
00594     return Val.getValueID() >= Value::ConstantFirstVal &&
00595       Val.getValueID() <= Value::ConstantLastVal;
00596   }
00597 };
00598 
00599 template <> struct isa_impl<Argument, Value> {
00600   static inline bool doit (const Value &Val) {
00601     return Val.getValueID() == Value::ArgumentVal;
00602   }
00603 };
00604 
00605 template <> struct isa_impl<InlineAsm, Value> {
00606   static inline bool doit(const Value &Val) {
00607     return Val.getValueID() == Value::InlineAsmVal;
00608   }
00609 };
00610 
00611 template <> struct isa_impl<Instruction, Value> {
00612   static inline bool doit(const Value &Val) {
00613     return Val.getValueID() >= Value::InstructionVal;
00614   }
00615 };
00616 
00617 template <> struct isa_impl<BasicBlock, Value> {
00618   static inline bool doit(const Value &Val) {
00619     return Val.getValueID() == Value::BasicBlockVal;
00620   }
00621 };
00622 
00623 template <> struct isa_impl<Function, Value> {
00624   static inline bool doit(const Value &Val) {
00625     return Val.getValueID() == Value::FunctionVal;
00626   }
00627 };
00628 
00629 template <> struct isa_impl<GlobalVariable, Value> {
00630   static inline bool doit(const Value &Val) {
00631     return Val.getValueID() == Value::GlobalVariableVal;
00632   }
00633 };
00634 
00635 template <> struct isa_impl<GlobalAlias, Value> {
00636   static inline bool doit(const Value &Val) {
00637     return Val.getValueID() == Value::GlobalAliasVal;
00638   }
00639 };
00640 
00641 template <> struct isa_impl<GlobalValue, Value> {
00642   static inline bool doit(const Value &Val) {
00643     return isa<GlobalObject>(Val) || isa<GlobalAlias>(Val);
00644   }
00645 };
00646 
00647 template <> struct isa_impl<GlobalObject, Value> {
00648   static inline bool doit(const Value &Val) {
00649     return isa<GlobalVariable>(Val) || isa<Function>(Val);
00650   }
00651 };
00652 
00653 template <> struct isa_impl<MDNode, Value> {
00654   static inline bool doit(const Value &Val) {
00655     return Val.getValueID() == Value::MDNodeVal;
00656   }
00657 };
00658 
00659 // Value* is only 4-byte aligned.
00660 template<>
00661 class PointerLikeTypeTraits<Value*> {
00662   typedef Value* PT;
00663 public:
00664   static inline void *getAsVoidPointer(PT P) { return P; }
00665   static inline PT getFromVoidPointer(void *P) {
00666     return static_cast<PT>(P);
00667   }
00668   enum { NumLowBitsAvailable = 2 };
00669 };
00670 
00671 // Create wrappers for C Binding types (see CBindingWrapping.h).
00672 DEFINE_ISA_CONVERSION_FUNCTIONS(Value, LLVMValueRef)
00673 
00674 /* Specialized opaque value conversions.
00675  */
00676 inline Value **unwrap(LLVMValueRef *Vals) {
00677   return reinterpret_cast<Value**>(Vals);
00678 }
00679 
00680 template<typename T>
00681 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
00682 #ifdef DEBUG
00683   for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
00684     cast<T>(*I);
00685 #endif
00686   (void)Length;
00687   return reinterpret_cast<T**>(Vals);
00688 }
00689 
00690 inline LLVMValueRef *wrap(const Value **Vals) {
00691   return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
00692 }
00693 
00694 } // End llvm namespace
00695 
00696 #endif