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