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