931eb48a6d513bcd0af7681334294e69070204f1
[oota-llvm.git] / include / llvm / IR / Value.h
1 //===-- llvm/Value.h - Definition of the Value class ------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the Value class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_IR_VALUE_H
15 #define LLVM_IR_VALUE_H
16
17 #include "llvm-c/Core.h"
18 #include "llvm/ADT/iterator_range.h"
19 #include "llvm/IR/Use.h"
20 #include "llvm/Support/CBindingWrapping.h"
21 #include "llvm/Support/Casting.h"
22 #include "llvm/Support/Compiler.h"
23
24 namespace llvm {
25
26 class APInt;
27 class Argument;
28 class AssemblyAnnotationWriter;
29 class BasicBlock;
30 class Constant;
31 class DataLayout;
32 class Function;
33 class GlobalAlias;
34 class GlobalObject;
35 class GlobalValue;
36 class GlobalVariable;
37 class InlineAsm;
38 class Instruction;
39 class LLVMContext;
40 class Module;
41 class ModuleSlotTracker;
42 class StringRef;
43 class Twine;
44 class Type;
45 class ValueHandleBase;
46 class ValueSymbolTable;
47 class raw_ostream;
48
49 template<typename ValueTy> class StringMapEntry;
50 typedef StringMapEntry<Value*> ValueName;
51
52 //===----------------------------------------------------------------------===//
53 //                                 Value Class
54 //===----------------------------------------------------------------------===//
55
56 /// \brief LLVM Value Representation
57 ///
58 /// This is a very important LLVM class. It is the base class of all values
59 /// computed by a program that may be used as operands to other values. Value is
60 /// the super class of other important classes such as Instruction and Function.
61 /// All Values have a Type. Type is not a subclass of Value. Some values can
62 /// have a name and they belong to some Module.  Setting the name on the Value
63 /// automatically updates the module's symbol table.
64 ///
65 /// Every value has a "use list" that keeps track of which other Values are
66 /// using this Value.  A Value can also have an arbitrary number of ValueHandle
67 /// objects that watch it and listen to RAUW and Destroy events.  See
68 /// llvm/IR/ValueHandle.h for details.
69 class Value {
70   Type *VTy;
71   Use *UseList;
72
73   friend class ValueAsMetadata; // Allow access to IsUsedByMD.
74   friend class ValueHandleBase;
75
76   const unsigned char SubclassID;   // Subclass identifier (for isa/dyn_cast)
77   unsigned char HasValueHandle : 1; // Has a ValueHandle pointing to this?
78 protected:
79   /// \brief Hold subclass data that can be dropped.
80   ///
81   /// This member is similar to SubclassData, however it is for holding
82   /// information which may be used to aid optimization, but which may be
83   /// cleared to zero without affecting conservative interpretation.
84   unsigned char SubclassOptionalData : 7;
85
86 private:
87   /// \brief Hold arbitrary subclass data.
88   ///
89   /// This member is defined by this class, but is not used for anything.
90   /// Subclasses can use it to hold whatever state they find useful.  This
91   /// field is initialized to zero by the ctor.
92   unsigned short SubclassData;
93
94 protected:
95   /// \brief The number of operands in the subclass.
96   ///
97   /// This member is defined by this class, but not used for anything.
98   /// Subclasses can use it to store their number of operands, if they have
99   /// any.
100   ///
101   /// This is stored here to save space in User on 64-bit hosts.  Since most
102   /// instances of Value have operands, 32-bit hosts aren't significantly
103   /// affected.
104   ///
105   /// Note, this should *NOT* be used directly by any class other than User.
106   /// User uses this value to find the Use list.
107   static const unsigned NumUserOperandsBits = 29;
108   unsigned NumUserOperands : 29;
109
110   bool IsUsedByMD : 1;
111   bool HasName : 1;
112   bool HasHungOffUses : 1;
113
114 private:
115   template <typename UseT> // UseT == 'Use' or 'const Use'
116   class use_iterator_impl
117       : public std::iterator<std::forward_iterator_tag, UseT *> {
118     UseT *U;
119     explicit use_iterator_impl(UseT *u) : U(u) {}
120     friend class Value;
121
122   public:
123     use_iterator_impl() : U() {}
124
125     bool operator==(const use_iterator_impl &x) const { return U == x.U; }
126     bool operator!=(const use_iterator_impl &x) const { return !operator==(x); }
127
128     use_iterator_impl &operator++() { // Preincrement
129       assert(U && "Cannot increment end iterator!");
130       U = U->getNext();
131       return *this;
132     }
133     use_iterator_impl operator++(int) { // Postincrement
134       auto tmp = *this;
135       ++*this;
136       return tmp;
137     }
138
139     UseT &operator*() const {
140       assert(U && "Cannot dereference end iterator!");
141       return *U;
142     }
143
144     UseT *operator->() const { return &operator*(); }
145
146     operator use_iterator_impl<const UseT>() const {
147       return use_iterator_impl<const UseT>(U);
148     }
149   };
150
151   template <typename UserTy> // UserTy == 'User' or 'const User'
152   class user_iterator_impl
153       : public std::iterator<std::forward_iterator_tag, UserTy *> {
154     use_iterator_impl<Use> UI;
155     explicit user_iterator_impl(Use *U) : UI(U) {}
156     friend class Value;
157
158   public:
159     user_iterator_impl() {}
160
161     bool operator==(const user_iterator_impl &x) const { return UI == x.UI; }
162     bool operator!=(const user_iterator_impl &x) const { return !operator==(x); }
163
164     /// \brief Returns true if this iterator is equal to user_end() on the value.
165     bool atEnd() const { return *this == user_iterator_impl(); }
166
167     user_iterator_impl &operator++() { // Preincrement
168       ++UI;
169       return *this;
170     }
171     user_iterator_impl operator++(int) { // Postincrement
172       auto tmp = *this;
173       ++*this;
174       return tmp;
175     }
176
177     // Retrieve a pointer to the current User.
178     UserTy *operator*() const {
179       return UI->getUser();
180     }
181
182     UserTy *operator->() const { return operator*(); }
183
184     operator user_iterator_impl<const UserTy>() const {
185       return user_iterator_impl<const UserTy>(*UI);
186     }
187
188     Use &getUse() const { return *UI; }
189   };
190
191   void operator=(const Value &) = delete;
192   Value(const Value &) = delete;
193
194 protected:
195   Value(Type *Ty, unsigned scid);
196 public:
197   virtual ~Value();
198
199   /// \brief Support for debugging, callable in GDB: V->dump()
200   void dump() const;
201
202   /// \brief Implement operator<< on Value.
203   void print(raw_ostream &O) const;
204
205   /// \brief Print the name of this Value out to the specified raw_ostream.
206   ///
207   /// This is useful when you just want to print 'int %reg126', not the
208   /// instruction that generated it. If you specify a Module for context, then
209   /// even constanst get pretty-printed; for example, the type of a null
210   /// pointer is printed symbolically.
211   /// @{
212   void printAsOperand(raw_ostream &O, bool PrintType = true,
213                       const Module *M = nullptr) const;
214   void printAsOperand(raw_ostream &O, bool PrintType,
215                       ModuleSlotTracker &MST) const;
216   /// @}
217
218   /// \brief All values are typed, get the type of this value.
219   Type *getType() const { return VTy; }
220
221   /// \brief All values hold a context through their type.
222   LLVMContext &getContext() const;
223
224   // \brief All values can potentially be named.
225   bool hasName() const { return HasName; }
226   ValueName *getValueName() const;
227   void setValueName(ValueName *VN);
228
229 private:
230   void destroyValueName();
231   void setNameImpl(const Twine &Name);
232
233 public:
234   /// \brief Return a constant reference to the value's name.
235   ///
236   /// This is cheap and guaranteed to return the same reference as long as the
237   /// value is not modified.
238   StringRef getName() const;
239
240   /// \brief Change the name of the value.
241   ///
242   /// Choose a new unique name if the provided name is taken.
243   ///
244   /// \param Name The new name; or "" if the value's name should be removed.
245   void setName(const Twine &Name);
246
247
248   /// \brief Transfer the name from V to this value.
249   ///
250   /// After taking V's name, sets V's name to empty.
251   ///
252   /// \note It is an error to call V->takeName(V).
253   void takeName(Value *V);
254
255   /// \brief Change all uses of this to point to a new Value.
256   ///
257   /// Go through the uses list for this definition and make each use point to
258   /// "V" instead of "this".  After this completes, 'this's use list is
259   /// guaranteed to be empty.
260   void replaceAllUsesWith(Value *V);
261
262   /// replaceUsesOutsideBlock - Go through the uses list for this definition and
263   /// make each use point to "V" instead of "this" when the use is outside the
264   /// block. 'This's use list is expected to have at least one element.
265   /// Unlike replaceAllUsesWith this function does not support basic block
266   /// values or constant users.
267   void replaceUsesOutsideBlock(Value *V, BasicBlock *BB);
268
269   //----------------------------------------------------------------------
270   // Methods for handling the chain of uses of this Value.
271   //
272   bool               use_empty() const { return UseList == nullptr; }
273
274   typedef use_iterator_impl<Use>       use_iterator;
275   typedef use_iterator_impl<const Use> const_use_iterator;
276   use_iterator       use_begin()       { return use_iterator(UseList); }
277   const_use_iterator use_begin() const { return const_use_iterator(UseList); }
278   use_iterator       use_end()         { return use_iterator();   }
279   const_use_iterator use_end()   const { return const_use_iterator();   }
280   iterator_range<use_iterator> uses() {
281     return iterator_range<use_iterator>(use_begin(), use_end());
282   }
283   iterator_range<const_use_iterator> uses() const {
284     return iterator_range<const_use_iterator>(use_begin(), use_end());
285   }
286
287   bool               user_empty() const { return UseList == nullptr; }
288
289   typedef user_iterator_impl<User>       user_iterator;
290   typedef user_iterator_impl<const User> const_user_iterator;
291   user_iterator       user_begin()       { return user_iterator(UseList); }
292   const_user_iterator user_begin() const { return const_user_iterator(UseList); }
293   user_iterator       user_end()         { return user_iterator();   }
294   const_user_iterator user_end()   const { return const_user_iterator();   }
295   User               *user_back()        { return *user_begin(); }
296   const User         *user_back()  const { return *user_begin(); }
297   iterator_range<user_iterator> users() {
298     return iterator_range<user_iterator>(user_begin(), user_end());
299   }
300   iterator_range<const_user_iterator> users() const {
301     return iterator_range<const_user_iterator>(user_begin(), user_end());
302   }
303
304   /// \brief Return true if there is exactly one user of this value.
305   ///
306   /// This is specialized because it is a common request and does not require
307   /// traversing the whole use list.
308   bool hasOneUse() const {
309     const_use_iterator I = use_begin(), E = use_end();
310     if (I == E) return false;
311     return ++I == E;
312   }
313
314   /// \brief Return true if this Value has exactly N users.
315   bool hasNUses(unsigned N) const;
316
317   /// \brief Return true if this value has N users or more.
318   ///
319   /// This is logically equivalent to getNumUses() >= N.
320   bool hasNUsesOrMore(unsigned N) const;
321
322   /// \brief Check if this value is used in the specified basic block.
323   bool isUsedInBasicBlock(const BasicBlock *BB) const;
324
325   /// \brief This method computes the number of uses of this Value.
326   ///
327   /// This is a linear time operation.  Use hasOneUse, hasNUses, or
328   /// hasNUsesOrMore to check for specific values.
329   unsigned getNumUses() const;
330
331   /// \brief This method should only be used by the Use class.
332   void addUse(Use &U) { U.addToList(&UseList); }
333
334   /// \brief Concrete subclass of this.
335   ///
336   /// An enumeration for keeping track of the concrete subclass of Value that
337   /// is actually instantiated. Values of this enumeration are kept in the
338   /// Value classes SubclassID field. They are used for concrete type
339   /// identification.
340   enum ValueTy {
341 #define HANDLE_VALUE(Name) Name##Val,
342 #include "llvm/IR/Value.def"
343
344     // Markers:
345 #define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
346 #include "llvm/IR/Value.def"
347   };
348
349   /// \brief Return an ID for the concrete type of this object.
350   ///
351   /// This is used to implement the classof checks.  This should not be used
352   /// for any other purpose, as the values may change as LLVM evolves.  Also,
353   /// note that for instructions, the Instruction's opcode is added to
354   /// InstructionVal. So this means three things:
355   /// # there is no value with code InstructionVal (no opcode==0).
356   /// # there are more possible values for the value type than in ValueTy enum.
357   /// # the InstructionVal enumerator must be the highest valued enumerator in
358   ///   the ValueTy enum.
359   unsigned getValueID() const {
360     return SubclassID;
361   }
362
363   /// \brief Return the raw optional flags value contained in this value.
364   ///
365   /// This should only be used when testing two Values for equivalence.
366   unsigned getRawSubclassOptionalData() const {
367     return SubclassOptionalData;
368   }
369
370   /// \brief Clear the optional flags contained in this value.
371   void clearSubclassOptionalData() {
372     SubclassOptionalData = 0;
373   }
374
375   /// \brief Check the optional flags for equality.
376   bool hasSameSubclassOptionalData(const Value *V) const {
377     return SubclassOptionalData == V->SubclassOptionalData;
378   }
379
380   /// \brief Clear any optional flags not set in the given Value.
381   void intersectOptionalDataWith(const Value *V) {
382     SubclassOptionalData &= V->SubclassOptionalData;
383   }
384
385   /// \brief Return true if there is a value handle associated with this value.
386   bool hasValueHandle() const { return HasValueHandle; }
387
388   /// \brief Return true if there is metadata referencing this value.
389   bool isUsedByMetadata() const { return IsUsedByMD; }
390
391   /// \brief Strip off pointer casts, all-zero GEPs, and aliases.
392   ///
393   /// Returns the original uncasted value.  If this is called on a non-pointer
394   /// value, it returns 'this'.
395   Value *stripPointerCasts();
396   const Value *stripPointerCasts() const {
397     return const_cast<Value*>(this)->stripPointerCasts();
398   }
399
400   /// \brief Strip off pointer casts and all-zero GEPs.
401   ///
402   /// Returns the original uncasted value.  If this is called on a non-pointer
403   /// value, it returns 'this'.
404   Value *stripPointerCastsNoFollowAliases();
405   const Value *stripPointerCastsNoFollowAliases() const {
406     return const_cast<Value*>(this)->stripPointerCastsNoFollowAliases();
407   }
408
409   /// \brief Strip off pointer casts and all-constant inbounds GEPs.
410   ///
411   /// Returns the original pointer value.  If this is called on a non-pointer
412   /// value, it returns 'this'.
413   Value *stripInBoundsConstantOffsets();
414   const Value *stripInBoundsConstantOffsets() const {
415     return const_cast<Value*>(this)->stripInBoundsConstantOffsets();
416   }
417
418   /// \brief Accumulate offsets from \a stripInBoundsConstantOffsets().
419   ///
420   /// Stores the resulting constant offset stripped into the APInt provided.
421   /// The provided APInt will be extended or truncated as needed to be the
422   /// correct bitwidth for an offset of this pointer type.
423   ///
424   /// If this is called on a non-pointer value, it returns 'this'.
425   Value *stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL,
426                                                    APInt &Offset);
427   const Value *stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL,
428                                                          APInt &Offset) const {
429     return const_cast<Value *>(this)
430         ->stripAndAccumulateInBoundsConstantOffsets(DL, Offset);
431   }
432
433   /// \brief Strip off pointer casts and inbounds GEPs.
434   ///
435   /// Returns the original pointer value.  If this is called on a non-pointer
436   /// value, it returns 'this'.
437   Value *stripInBoundsOffsets();
438   const Value *stripInBoundsOffsets() const {
439     return const_cast<Value*>(this)->stripInBoundsOffsets();
440   }
441
442   /// \brief Translate PHI node to its predecessor from the given basic block.
443   ///
444   /// If this value is a PHI node with CurBB as its parent, return the value in
445   /// the PHI node corresponding to PredBB.  If not, return ourself.  This is
446   /// useful if you want to know the value something has in a predecessor
447   /// block.
448   Value *DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB);
449
450   const Value *DoPHITranslation(const BasicBlock *CurBB,
451                                 const BasicBlock *PredBB) const{
452     return const_cast<Value*>(this)->DoPHITranslation(CurBB, PredBB);
453   }
454
455   /// \brief The maximum alignment for instructions.
456   ///
457   /// This is the greatest alignment value supported by load, store, and alloca
458   /// instructions, and global values.
459   static const unsigned MaxAlignmentExponent = 29;
460   static const unsigned MaximumAlignment = 1u << MaxAlignmentExponent;
461
462   /// \brief Mutate the type of this Value to be of the specified type.
463   ///
464   /// Note that this is an extremely dangerous operation which can create
465   /// completely invalid IR very easily.  It is strongly recommended that you
466   /// recreate IR objects with the right types instead of mutating them in
467   /// place.
468   void mutateType(Type *Ty) {
469     VTy = Ty;
470   }
471
472   /// \brief Sort the use-list.
473   ///
474   /// Sorts the Value's use-list by Cmp using a stable mergesort.  Cmp is
475   /// expected to compare two \a Use references.
476   template <class Compare> void sortUseList(Compare Cmp);
477
478   /// \brief Reverse the use-list.
479   void reverseUseList();
480
481 private:
482   /// \brief Merge two lists together.
483   ///
484   /// Merges \c L and \c R using \c Cmp.  To enable stable sorts, always pushes
485   /// "equal" items from L before items from R.
486   ///
487   /// \return the first element in the list.
488   ///
489   /// \note Completely ignores \a Use::Prev (doesn't read, doesn't update).
490   template <class Compare>
491   static Use *mergeUseLists(Use *L, Use *R, Compare Cmp) {
492     Use *Merged;
493     mergeUseListsImpl(L, R, &Merged, Cmp);
494     return Merged;
495   }
496
497   /// \brief Tail-recursive helper for \a mergeUseLists().
498   ///
499   /// \param[out] Next the first element in the list.
500   template <class Compare>
501   static void mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp);
502
503 protected:
504   unsigned short getSubclassDataFromValue() const { return SubclassData; }
505   void setValueSubclassData(unsigned short D) { SubclassData = D; }
506 };
507
508 inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) {
509   V.print(OS);
510   return OS;
511 }
512
513 void Use::set(Value *V) {
514   if (Val) removeFromList();
515   Val = V;
516   if (V) V->addUse(*this);
517 }
518
519 template <class Compare> void Value::sortUseList(Compare Cmp) {
520   if (!UseList || !UseList->Next)
521     // No need to sort 0 or 1 uses.
522     return;
523
524   // Note: this function completely ignores Prev pointers until the end when
525   // they're fixed en masse.
526
527   // Create a binomial vector of sorted lists, visiting uses one at a time and
528   // merging lists as necessary.
529   const unsigned MaxSlots = 32;
530   Use *Slots[MaxSlots];
531
532   // Collect the first use, turning it into a single-item list.
533   Use *Next = UseList->Next;
534   UseList->Next = nullptr;
535   unsigned NumSlots = 1;
536   Slots[0] = UseList;
537
538   // Collect all but the last use.
539   while (Next->Next) {
540     Use *Current = Next;
541     Next = Current->Next;
542
543     // Turn Current into a single-item list.
544     Current->Next = nullptr;
545
546     // Save Current in the first available slot, merging on collisions.
547     unsigned I;
548     for (I = 0; I < NumSlots; ++I) {
549       if (!Slots[I])
550         break;
551
552       // Merge two lists, doubling the size of Current and emptying slot I.
553       //
554       // Since the uses in Slots[I] originally preceded those in Current, send
555       // Slots[I] in as the left parameter to maintain a stable sort.
556       Current = mergeUseLists(Slots[I], Current, Cmp);
557       Slots[I] = nullptr;
558     }
559     // Check if this is a new slot.
560     if (I == NumSlots) {
561       ++NumSlots;
562       assert(NumSlots <= MaxSlots && "Use list bigger than 2^32");
563     }
564
565     // Found an open slot.
566     Slots[I] = Current;
567   }
568
569   // Merge all the lists together.
570   assert(Next && "Expected one more Use");
571   assert(!Next->Next && "Expected only one Use");
572   UseList = Next;
573   for (unsigned I = 0; I < NumSlots; ++I)
574     if (Slots[I])
575       // Since the uses in Slots[I] originally preceded those in UseList, send
576       // Slots[I] in as the left parameter to maintain a stable sort.
577       UseList = mergeUseLists(Slots[I], UseList, Cmp);
578
579   // Fix the Prev pointers.
580   for (Use *I = UseList, **Prev = &UseList; I; I = I->Next) {
581     I->setPrev(Prev);
582     Prev = &I->Next;
583   }
584 }
585
586 template <class Compare>
587 void Value::mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp) {
588   if (!L) {
589     *Next = R;
590     return;
591   }
592   if (!R) {
593     *Next = L;
594     return;
595   }
596   if (Cmp(*R, *L)) {
597     *Next = R;
598     mergeUseListsImpl(L, R->Next, &R->Next, Cmp);
599     return;
600   }
601   *Next = L;
602   mergeUseListsImpl(L->Next, R, &L->Next, Cmp);
603 }
604
605 // isa - Provide some specializations of isa so that we don't have to include
606 // the subtype header files to test to see if the value is a subclass...
607 //
608 template <> struct isa_impl<Constant, Value> {
609   static inline bool doit(const Value &Val) {
610     return Val.getValueID() >= Value::ConstantFirstVal &&
611       Val.getValueID() <= Value::ConstantLastVal;
612   }
613 };
614
615 template <> struct isa_impl<Argument, Value> {
616   static inline bool doit (const Value &Val) {
617     return Val.getValueID() == Value::ArgumentVal;
618   }
619 };
620
621 template <> struct isa_impl<InlineAsm, Value> {
622   static inline bool doit(const Value &Val) {
623     return Val.getValueID() == Value::InlineAsmVal;
624   }
625 };
626
627 template <> struct isa_impl<Instruction, Value> {
628   static inline bool doit(const Value &Val) {
629     return Val.getValueID() >= Value::InstructionVal;
630   }
631 };
632
633 template <> struct isa_impl<BasicBlock, Value> {
634   static inline bool doit(const Value &Val) {
635     return Val.getValueID() == Value::BasicBlockVal;
636   }
637 };
638
639 template <> struct isa_impl<Function, Value> {
640   static inline bool doit(const Value &Val) {
641     return Val.getValueID() == Value::FunctionVal;
642   }
643 };
644
645 template <> struct isa_impl<GlobalVariable, Value> {
646   static inline bool doit(const Value &Val) {
647     return Val.getValueID() == Value::GlobalVariableVal;
648   }
649 };
650
651 template <> struct isa_impl<GlobalAlias, Value> {
652   static inline bool doit(const Value &Val) {
653     return Val.getValueID() == Value::GlobalAliasVal;
654   }
655 };
656
657 template <> struct isa_impl<GlobalValue, Value> {
658   static inline bool doit(const Value &Val) {
659     return isa<GlobalObject>(Val) || isa<GlobalAlias>(Val);
660   }
661 };
662
663 template <> struct isa_impl<GlobalObject, Value> {
664   static inline bool doit(const Value &Val) {
665     return isa<GlobalVariable>(Val) || isa<Function>(Val);
666   }
667 };
668
669 // Value* is only 4-byte aligned.
670 template<>
671 class PointerLikeTypeTraits<Value*> {
672   typedef Value* PT;
673 public:
674   static inline void *getAsVoidPointer(PT P) { return P; }
675   static inline PT getFromVoidPointer(void *P) {
676     return static_cast<PT>(P);
677   }
678   enum { NumLowBitsAvailable = 2 };
679 };
680
681 // Create wrappers for C Binding types (see CBindingWrapping.h).
682 DEFINE_ISA_CONVERSION_FUNCTIONS(Value, LLVMValueRef)
683
684 /* Specialized opaque value conversions.
685  */
686 inline Value **unwrap(LLVMValueRef *Vals) {
687   return reinterpret_cast<Value**>(Vals);
688 }
689
690 template<typename T>
691 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
692 #ifdef DEBUG
693   for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
694     cast<T>(*I);
695 #endif
696   (void)Length;
697   return reinterpret_cast<T**>(Vals);
698 }
699
700 inline LLVMValueRef *wrap(const Value **Vals) {
701   return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
702 }
703
704 } // End llvm namespace
705
706 #endif