LLVM API Documentation
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 /// \brief Reverse the use-list. 00466 void reverseUseList(); 00467 00468 private: 00469 /// \brief Merge two lists together. 00470 /// 00471 /// Merges \c L and \c R using \c Cmp. To enable stable sorts, always pushes 00472 /// "equal" items from L before items from R. 00473 /// 00474 /// \return the first element in the list. 00475 /// 00476 /// \note Completely ignores \a Use::Prev (doesn't read, doesn't update). 00477 template <class Compare> 00478 static Use *mergeUseLists(Use *L, Use *R, Compare Cmp) { 00479 Use *Merged; 00480 mergeUseListsImpl(L, R, &Merged, Cmp); 00481 return Merged; 00482 } 00483 00484 /// \brief Tail-recursive helper for \a mergeUseLists(). 00485 /// 00486 /// \param[out] Next the first element in the list. 00487 template <class Compare> 00488 static void mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp); 00489 00490 protected: 00491 unsigned short getSubclassDataFromValue() const { return SubclassData; } 00492 void setValueSubclassData(unsigned short D) { SubclassData = D; } 00493 }; 00494 00495 inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) { 00496 V.print(OS); 00497 return OS; 00498 } 00499 00500 void Use::set(Value *V) { 00501 if (Val) removeFromList(); 00502 Val = V; 00503 if (V) V->addUse(*this); 00504 } 00505 00506 template <class Compare> void Value::sortUseList(Compare Cmp) { 00507 if (!UseList || !UseList->Next) 00508 // No need to sort 0 or 1 uses. 00509 return; 00510 00511 // Note: this function completely ignores Prev pointers until the end when 00512 // they're fixed en masse. 00513 00514 // Create a binomial vector of sorted lists, visiting uses one at a time and 00515 // merging lists as necessary. 00516 const unsigned MaxSlots = 32; 00517 Use *Slots[MaxSlots]; 00518 00519 // Collect the first use, turning it into a single-item list. 00520 Use *Next = UseList->Next; 00521 UseList->Next = nullptr; 00522 unsigned NumSlots = 1; 00523 Slots[0] = UseList; 00524 00525 // Collect all but the last use. 00526 while (Next->Next) { 00527 Use *Current = Next; 00528 Next = Current->Next; 00529 00530 // Turn Current into a single-item list. 00531 Current->Next = nullptr; 00532 00533 // Save Current in the first available slot, merging on collisions. 00534 unsigned I; 00535 for (I = 0; I < NumSlots; ++I) { 00536 if (!Slots[I]) 00537 break; 00538 00539 // Merge two lists, doubling the size of Current and emptying slot I. 00540 // 00541 // Since the uses in Slots[I] originally preceded those in Current, send 00542 // Slots[I] in as the left parameter to maintain a stable sort. 00543 Current = mergeUseLists(Slots[I], Current, Cmp); 00544 Slots[I] = nullptr; 00545 } 00546 // Check if this is a new slot. 00547 if (I == NumSlots) { 00548 ++NumSlots; 00549 assert(NumSlots <= MaxSlots && "Use list bigger than 2^32"); 00550 } 00551 00552 // Found an open slot. 00553 Slots[I] = Current; 00554 } 00555 00556 // Merge all the lists together. 00557 assert(Next && "Expected one more Use"); 00558 assert(!Next->Next && "Expected only one Use"); 00559 UseList = Next; 00560 for (unsigned I = 0; I < NumSlots; ++I) 00561 if (Slots[I]) 00562 // Since the uses in Slots[I] originally preceded those in UseList, send 00563 // Slots[I] in as the left parameter to maintain a stable sort. 00564 UseList = mergeUseLists(Slots[I], UseList, Cmp); 00565 00566 // Fix the Prev pointers. 00567 for (Use *I = UseList, **Prev = &UseList; I; I = I->Next) { 00568 I->setPrev(Prev); 00569 Prev = &I->Next; 00570 } 00571 } 00572 00573 template <class Compare> 00574 void Value::mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp) { 00575 if (!L) { 00576 *Next = R; 00577 return; 00578 } 00579 if (!R) { 00580 *Next = L; 00581 return; 00582 } 00583 if (Cmp(*R, *L)) { 00584 *Next = R; 00585 mergeUseListsImpl(L, R->Next, &R->Next, Cmp); 00586 return; 00587 } 00588 *Next = L; 00589 mergeUseListsImpl(L->Next, R, &L->Next, Cmp); 00590 } 00591 00592 // isa - Provide some specializations of isa so that we don't have to include 00593 // the subtype header files to test to see if the value is a subclass... 00594 // 00595 template <> struct isa_impl<Constant, Value> { 00596 static inline bool doit(const Value &Val) { 00597 return Val.getValueID() >= Value::ConstantFirstVal && 00598 Val.getValueID() <= Value::ConstantLastVal; 00599 } 00600 }; 00601 00602 template <> struct isa_impl<Argument, Value> { 00603 static inline bool doit (const Value &Val) { 00604 return Val.getValueID() == Value::ArgumentVal; 00605 } 00606 }; 00607 00608 template <> struct isa_impl<InlineAsm, Value> { 00609 static inline bool doit(const Value &Val) { 00610 return Val.getValueID() == Value::InlineAsmVal; 00611 } 00612 }; 00613 00614 template <> struct isa_impl<Instruction, Value> { 00615 static inline bool doit(const Value &Val) { 00616 return Val.getValueID() >= Value::InstructionVal; 00617 } 00618 }; 00619 00620 template <> struct isa_impl<BasicBlock, Value> { 00621 static inline bool doit(const Value &Val) { 00622 return Val.getValueID() == Value::BasicBlockVal; 00623 } 00624 }; 00625 00626 template <> struct isa_impl<Function, Value> { 00627 static inline bool doit(const Value &Val) { 00628 return Val.getValueID() == Value::FunctionVal; 00629 } 00630 }; 00631 00632 template <> struct isa_impl<GlobalVariable, Value> { 00633 static inline bool doit(const Value &Val) { 00634 return Val.getValueID() == Value::GlobalVariableVal; 00635 } 00636 }; 00637 00638 template <> struct isa_impl<GlobalAlias, Value> { 00639 static inline bool doit(const Value &Val) { 00640 return Val.getValueID() == Value::GlobalAliasVal; 00641 } 00642 }; 00643 00644 template <> struct isa_impl<GlobalValue, Value> { 00645 static inline bool doit(const Value &Val) { 00646 return isa<GlobalObject>(Val) || isa<GlobalAlias>(Val); 00647 } 00648 }; 00649 00650 template <> struct isa_impl<GlobalObject, Value> { 00651 static inline bool doit(const Value &Val) { 00652 return isa<GlobalVariable>(Val) || isa<Function>(Val); 00653 } 00654 }; 00655 00656 template <> struct isa_impl<MDNode, Value> { 00657 static inline bool doit(const Value &Val) { 00658 return Val.getValueID() == Value::MDNodeVal; 00659 } 00660 }; 00661 00662 // Value* is only 4-byte aligned. 00663 template<> 00664 class PointerLikeTypeTraits<Value*> { 00665 typedef Value* PT; 00666 public: 00667 static inline void *getAsVoidPointer(PT P) { return P; } 00668 static inline PT getFromVoidPointer(void *P) { 00669 return static_cast<PT>(P); 00670 } 00671 enum { NumLowBitsAvailable = 2 }; 00672 }; 00673 00674 // Create wrappers for C Binding types (see CBindingWrapping.h). 00675 DEFINE_ISA_CONVERSION_FUNCTIONS(Value, LLVMValueRef) 00676 00677 /* Specialized opaque value conversions. 00678 */ 00679 inline Value **unwrap(LLVMValueRef *Vals) { 00680 return reinterpret_cast<Value**>(Vals); 00681 } 00682 00683 template<typename T> 00684 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) { 00685 #ifdef DEBUG 00686 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I) 00687 cast<T>(*I); 00688 #endif 00689 (void)Length; 00690 return reinterpret_cast<T**>(Vals); 00691 } 00692 00693 inline LLVMValueRef *wrap(const Value **Vals) { 00694 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals)); 00695 } 00696 00697 } // End llvm namespace 00698 00699 #endif