Devirtualizing Value destructor (PR889). Patch by Pawel Kunio!
[oota-llvm.git] / include / llvm / Instructions.h
1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class.  This is meant to be an easy way to get access to all
12 // instruction subclasses.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
18
19 #include <iterator>
20
21 #include "llvm/InstrTypes.h"
22 #include "llvm/DerivedTypes.h"
23 #include "llvm/ParameterAttributes.h"
24
25 namespace llvm {
26
27 class BasicBlock;
28 class ConstantInt;
29 class PointerType;
30 class VectorType;
31 class ConstantRange;
32 class APInt;
33 class ParamAttrsList;
34
35 //===----------------------------------------------------------------------===//
36 //                             AllocationInst Class
37 //===----------------------------------------------------------------------===//
38
39 /// AllocationInst - This class is the common base class of MallocInst and
40 /// AllocaInst.
41 ///
42 class AllocationInst : public UnaryInstruction {
43   unsigned Alignment;
44 protected:
45   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
46                  const std::string &Name = "", Instruction *InsertBefore = 0);
47   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
48                  const std::string &Name, BasicBlock *InsertAtEnd);
49 public:
50   /// isArrayAllocation - Return true if there is an allocation size parameter
51   /// to the allocation instruction that is not 1.
52   ///
53   bool isArrayAllocation() const;
54
55   /// getArraySize - Get the number of element allocated, for a simple
56   /// allocation of a single element, this will return a constant 1 value.
57   ///
58   inline const Value *getArraySize() const { return getOperand(0); }
59   inline Value *getArraySize() { return getOperand(0); }
60
61   /// getType - Overload to return most specific pointer type
62   ///
63   inline const PointerType *getType() const {
64     return reinterpret_cast<const PointerType*>(Instruction::getType());
65   }
66
67   /// getAllocatedType - Return the type that is being allocated by the
68   /// instruction.
69   ///
70   const Type *getAllocatedType() const;
71
72   /// getAlignment - Return the alignment of the memory that is being allocated
73   /// by the instruction.
74   ///
75   unsigned getAlignment() const { return Alignment; }
76   void setAlignment(unsigned Align) {
77     assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
78     Alignment = Align;
79   }
80
81   virtual Instruction *clone() const = 0;
82
83   // Methods for support type inquiry through isa, cast, and dyn_cast:
84   static inline bool classof(const AllocationInst *) { return true; }
85   static inline bool classof(const Instruction *I) {
86     return I->getOpcode() == Instruction::Alloca ||
87            I->getOpcode() == Instruction::Malloc;
88   }
89   static inline bool classof(const Value *V) {
90     return isa<Instruction>(V) && classof(cast<Instruction>(V));
91   }
92 };
93
94
95 //===----------------------------------------------------------------------===//
96 //                                MallocInst Class
97 //===----------------------------------------------------------------------===//
98
99 /// MallocInst - an instruction to allocated memory on the heap
100 ///
101 class MallocInst : public AllocationInst {
102   MallocInst(const MallocInst &MI);
103 public:
104   explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
105                       const std::string &Name = "",
106                       Instruction *InsertBefore = 0)
107     : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
108   MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
109              BasicBlock *InsertAtEnd)
110     : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
111
112   MallocInst(const Type *Ty, const std::string &Name,
113              Instruction *InsertBefore = 0)
114     : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
115   MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
116     : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
117
118   MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
119              const std::string &Name, BasicBlock *InsertAtEnd)
120     : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
121   MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
122                       const std::string &Name = "",
123                       Instruction *InsertBefore = 0)
124     : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
125
126   virtual MallocInst *clone() const;
127
128   // Methods for support type inquiry through isa, cast, and dyn_cast:
129   static inline bool classof(const MallocInst *) { return true; }
130   static inline bool classof(const Instruction *I) {
131     return (I->getOpcode() == Instruction::Malloc);
132   }
133   static inline bool classof(const Value *V) {
134     return isa<Instruction>(V) && classof(cast<Instruction>(V));
135   }
136 };
137
138
139 //===----------------------------------------------------------------------===//
140 //                                AllocaInst Class
141 //===----------------------------------------------------------------------===//
142
143 /// AllocaInst - an instruction to allocate memory on the stack
144 ///
145 class AllocaInst : public AllocationInst {
146   AllocaInst(const AllocaInst &);
147 public:
148   explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
149                       const std::string &Name = "",
150                       Instruction *InsertBefore = 0)
151     : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
152   AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
153              BasicBlock *InsertAtEnd)
154     : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
155
156   AllocaInst(const Type *Ty, const std::string &Name,
157              Instruction *InsertBefore = 0)
158     : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
159   AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
160     : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
161
162   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
163              const std::string &Name = "", Instruction *InsertBefore = 0)
164     : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
165   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
166              const std::string &Name, BasicBlock *InsertAtEnd)
167     : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
168
169   virtual AllocaInst *clone() const;
170
171   // Methods for support type inquiry through isa, cast, and dyn_cast:
172   static inline bool classof(const AllocaInst *) { return true; }
173   static inline bool classof(const Instruction *I) {
174     return (I->getOpcode() == Instruction::Alloca);
175   }
176   static inline bool classof(const Value *V) {
177     return isa<Instruction>(V) && classof(cast<Instruction>(V));
178   }
179 };
180
181
182 //===----------------------------------------------------------------------===//
183 //                                 FreeInst Class
184 //===----------------------------------------------------------------------===//
185
186 /// FreeInst - an instruction to deallocate memory
187 ///
188 class FreeInst : public UnaryInstruction {
189   void AssertOK();
190 protected:
191   static void destroyThis(FreeInst* v) {
192     UnaryInstruction::destroyThis(v);
193   }
194   friend class Value;
195 public:
196   explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
197   FreeInst(Value *Ptr, BasicBlock *InsertAfter);
198
199   virtual FreeInst *clone() const;
200   
201   // Accessor methods for consistency with other memory operations
202   Value *getPointerOperand() { return getOperand(0); }
203   const Value *getPointerOperand() const { return getOperand(0); }
204
205   // Methods for support type inquiry through isa, cast, and dyn_cast:
206   static inline bool classof(const FreeInst *) { return true; }
207   static inline bool classof(const Instruction *I) {
208     return (I->getOpcode() == Instruction::Free);
209   }
210   static inline bool classof(const Value *V) {
211     return isa<Instruction>(V) && classof(cast<Instruction>(V));
212   }
213 };
214
215
216 //===----------------------------------------------------------------------===//
217 //                                LoadInst Class
218 //===----------------------------------------------------------------------===//
219
220 /// LoadInst - an instruction for reading from memory.  This uses the
221 /// SubclassData field in Value to store whether or not the load is volatile.
222 ///
223 class LoadInst : public UnaryInstruction {
224
225   LoadInst(const LoadInst &LI)
226     : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
227     setVolatile(LI.isVolatile());
228     setAlignment(LI.getAlignment());
229
230 #ifndef NDEBUG
231     AssertOK();
232 #endif
233   }
234   void AssertOK();
235 protected:
236   static void destroyThis(LoadInst* v) {
237     UnaryInstruction::destroyThis(v);
238   }
239   friend class Value;
240 public:
241   LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
242   LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
243   LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false, 
244            Instruction *InsertBefore = 0);
245   LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
246            Instruction *InsertBefore = 0);
247   LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
248            BasicBlock *InsertAtEnd);
249   LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
250            BasicBlock *InsertAtEnd);
251
252   LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
253   LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
254   explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false, 
255                     Instruction *InsertBefore = 0);
256   LoadInst(Value *Ptr, const char *Name, bool isVolatile,
257            BasicBlock *InsertAtEnd);
258   
259   /// isVolatile - Return true if this is a load from a volatile memory
260   /// location.
261   ///
262   bool isVolatile() const { return SubclassData & 1; }
263
264   /// setVolatile - Specify whether this is a volatile load or not.
265   ///
266   void setVolatile(bool V) { 
267     SubclassData = (SubclassData & ~1) | (V ? 1 : 0); 
268   }
269
270   virtual LoadInst *clone() const;
271
272   /// getAlignment - Return the alignment of the access that is being performed
273   ///
274   unsigned getAlignment() const {
275     return (1 << (SubclassData>>1)) >> 1;
276   }
277   
278   void setAlignment(unsigned Align);
279
280   Value *getPointerOperand() { return getOperand(0); }
281   const Value *getPointerOperand() const { return getOperand(0); }
282   static unsigned getPointerOperandIndex() { return 0U; }
283
284   // Methods for support type inquiry through isa, cast, and dyn_cast:
285   static inline bool classof(const LoadInst *) { return true; }
286   static inline bool classof(const Instruction *I) {
287     return I->getOpcode() == Instruction::Load;
288   }
289   static inline bool classof(const Value *V) {
290     return isa<Instruction>(V) && classof(cast<Instruction>(V));
291   }
292 };
293
294
295 //===----------------------------------------------------------------------===//
296 //                                StoreInst Class
297 //===----------------------------------------------------------------------===//
298
299 /// StoreInst - an instruction for storing to memory
300 ///
301 class StoreInst : public Instruction {
302   Use Ops[2];
303   
304   StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
305     Ops[0].init(SI.Ops[0], this);
306     Ops[1].init(SI.Ops[1], this);
307     setVolatile(SI.isVolatile());
308     setAlignment(SI.getAlignment());
309     
310 #ifndef NDEBUG
311     AssertOK();
312 #endif
313   }
314   void AssertOK();
315 protected:
316   static void destroyThis(StoreInst* v) {
317     Instruction::destroyThis(v);
318   }
319   friend class Value;
320 public:
321   StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
322   StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
323   StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
324             Instruction *InsertBefore = 0);
325   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
326             unsigned Align, Instruction *InsertBefore = 0);
327   StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
328   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
329             unsigned Align, BasicBlock *InsertAtEnd);
330
331
332   /// isVolatile - Return true if this is a load from a volatile memory
333   /// location.
334   ///
335   bool isVolatile() const { return SubclassData & 1; }
336
337   /// setVolatile - Specify whether this is a volatile load or not.
338   ///
339   void setVolatile(bool V) { 
340     SubclassData = (SubclassData & ~1) | (V ? 1 : 0); 
341   }
342
343   /// Transparently provide more efficient getOperand methods.
344   Value *getOperand(unsigned i) const {
345     assert(i < 2 && "getOperand() out of range!");
346     return Ops[i];
347   }
348   void setOperand(unsigned i, Value *Val) {
349     assert(i < 2 && "setOperand() out of range!");
350     Ops[i] = Val;
351   }
352   unsigned getNumOperands() const { return 2; }
353
354   /// getAlignment - Return the alignment of the access that is being performed
355   ///
356   unsigned getAlignment() const {
357     return (1 << (SubclassData>>1)) >> 1;
358   }
359   
360   void setAlignment(unsigned Align);
361   
362   virtual StoreInst *clone() const;
363
364   Value *getPointerOperand() { return getOperand(1); }
365   const Value *getPointerOperand() const { return getOperand(1); }
366   static unsigned getPointerOperandIndex() { return 1U; }
367
368   // Methods for support type inquiry through isa, cast, and dyn_cast:
369   static inline bool classof(const StoreInst *) { return true; }
370   static inline bool classof(const Instruction *I) {
371     return I->getOpcode() == Instruction::Store;
372   }
373   static inline bool classof(const Value *V) {
374     return isa<Instruction>(V) && classof(cast<Instruction>(V));
375   }
376 };
377
378
379 //===----------------------------------------------------------------------===//
380 //                             GetElementPtrInst Class
381 //===----------------------------------------------------------------------===//
382
383 // checkType - Simple wrapper function to give a better assertion failure
384 // message on bad indexes for a gep instruction.
385 //
386 static inline const Type *checkType(const Type *Ty) {
387   assert(Ty && "Invalid GetElementPtrInst indices for type!");
388   return Ty;
389 }
390
391 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
392 /// access elements of arrays and structs
393 ///
394 class GetElementPtrInst : public Instruction {
395   GetElementPtrInst(const GetElementPtrInst &GEPI)
396     : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
397                   0, GEPI.getNumOperands()) {
398     Use *OL = OperandList = new Use[NumOperands];
399     Use *GEPIOL = GEPI.OperandList;
400     for (unsigned i = 0, E = NumOperands; i != E; ++i)
401       OL[i].init(GEPIOL[i], this);
402   }
403   void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
404   void init(Value *Ptr, Value *Idx);
405
406   template<typename InputIterator>
407   void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
408             const std::string &Name,
409             // This argument ensures that we have an iterator we can
410             // do arithmetic on in constant time
411             std::random_access_iterator_tag) {
412     typename std::iterator_traits<InputIterator>::difference_type NumIdx = 
413       std::distance(IdxBegin, IdxEnd);
414     
415     if (NumIdx > 0) {
416       // This requires that the itoerator points to contiguous memory.
417       init(Ptr, &*IdxBegin, NumIdx);
418     }
419     else {
420       init(Ptr, 0, NumIdx);
421     }
422
423     setName(Name);
424   }
425
426   /// getIndexedType - Returns the type of the element that would be loaded with
427   /// a load instruction with the specified parameters.
428   ///
429   /// A null type is returned if the indices are invalid for the specified
430   /// pointer type.
431   ///
432   static const Type *getIndexedType(const Type *Ptr,
433                                     Value* const *Idx, unsigned NumIdx,
434                                     bool AllowStructLeaf = false);
435
436   template<typename InputIterator>
437   static const Type *getIndexedType(const Type *Ptr,
438                                     InputIterator IdxBegin, 
439                                     InputIterator IdxEnd,
440                                     bool AllowStructLeaf,
441                                     // This argument ensures that we
442                                     // have an iterator we can do
443                                     // arithmetic on in constant time
444                                     std::random_access_iterator_tag) {
445     typename std::iterator_traits<InputIterator>::difference_type NumIdx = 
446       std::distance(IdxBegin, IdxEnd);
447
448     if (NumIdx > 0) {
449       // This requires that the iterator points to contiguous memory.
450       return(getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx,
451                             AllowStructLeaf));
452     }
453     else {
454       return(getIndexedType(Ptr, (Value *const*)0, NumIdx, AllowStructLeaf));
455     }
456   }
457
458 protected:
459   static void destroyThis(GetElementPtrInst*v);
460   friend class Value;
461 public:
462   /// Constructors - Create a getelementptr instruction with a base pointer an
463   /// list of indices.  The first ctor can optionally insert before an existing
464   /// instruction, the second appends the new instruction to the specified
465   /// BasicBlock.
466   template<typename InputIterator>
467   GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, 
468                     InputIterator IdxEnd,
469                     const std::string &Name = "",
470                     Instruction *InsertBefore =0)
471       : Instruction(PointerType::get(
472                       checkType(getIndexedType(Ptr->getType(),
473                                                IdxBegin, IdxEnd, true))),
474                     GetElementPtr, 0, 0, InsertBefore) {
475     init(Ptr, IdxBegin, IdxEnd, Name,
476          typename std::iterator_traits<InputIterator>::iterator_category());
477   }
478   template<typename InputIterator>
479   GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
480                     const std::string &Name, BasicBlock *InsertAtEnd)
481       : Instruction(PointerType::get(
482                       checkType(getIndexedType(Ptr->getType(),
483                                                IdxBegin, IdxEnd, true))),
484                     GetElementPtr, 0, 0, InsertAtEnd) {
485     init(Ptr, IdxBegin, IdxEnd, Name,
486          typename std::iterator_traits<InputIterator>::iterator_category());
487   }
488
489   /// Constructors - These two constructors are convenience methods because one
490   /// and two index getelementptr instructions are so common.
491   GetElementPtrInst(Value *Ptr, Value *Idx,
492                     const std::string &Name = "", Instruction *InsertBefore =0);
493   GetElementPtrInst(Value *Ptr, Value *Idx,
494                     const std::string &Name, BasicBlock *InsertAtEnd);
495
496   virtual GetElementPtrInst *clone() const;
497
498   // getType - Overload to return most specific pointer type...
499   inline const PointerType *getType() const {
500     return reinterpret_cast<const PointerType*>(Instruction::getType());
501   }
502
503   /// getIndexedType - Returns the type of the element that would be loaded with
504   /// a load instruction with the specified parameters.
505   ///
506   /// A null type is returned if the indices are invalid for the specified
507   /// pointer type.
508   ///
509   template<typename InputIterator>
510   static const Type *getIndexedType(const Type *Ptr,
511                                     InputIterator IdxBegin,
512                                     InputIterator IdxEnd,
513                                     bool AllowStructLeaf = false) {
514     return(getIndexedType(Ptr, IdxBegin, IdxEnd, AllowStructLeaf, 
515                           typename std::iterator_traits<InputIterator>::
516                           iterator_category()));
517   }  
518   static const Type *getIndexedType(const Type *Ptr, Value *Idx);
519
520   inline op_iterator       idx_begin()       { return op_begin()+1; }
521   inline const_op_iterator idx_begin() const { return op_begin()+1; }
522   inline op_iterator       idx_end()         { return op_end(); }
523   inline const_op_iterator idx_end()   const { return op_end(); }
524
525   Value *getPointerOperand() {
526     return getOperand(0);
527   }
528   const Value *getPointerOperand() const {
529     return getOperand(0);
530   }
531   static unsigned getPointerOperandIndex() {
532     return 0U;                      // get index for modifying correct operand
533   }
534
535   inline unsigned getNumIndices() const {  // Note: always non-negative
536     return getNumOperands() - 1;
537   }
538
539   inline bool hasIndices() const {
540     return getNumOperands() > 1;
541   }
542   
543   /// hasAllZeroIndices - Return true if all of the indices of this GEP are
544   /// zeros.  If so, the result pointer and the first operand have the same
545   /// value, just potentially different types.
546   bool hasAllZeroIndices() const;
547   
548   /// hasAllConstantIndices - Return true if all of the indices of this GEP are
549   /// constant integers.  If so, the result pointer and the first operand have
550   /// a constant offset between them.
551   bool hasAllConstantIndices() const;
552   
553
554   // Methods for support type inquiry through isa, cast, and dyn_cast:
555   static inline bool classof(const GetElementPtrInst *) { return true; }
556   static inline bool classof(const Instruction *I) {
557     return (I->getOpcode() == Instruction::GetElementPtr);
558   }
559   static inline bool classof(const Value *V) {
560     return isa<Instruction>(V) && classof(cast<Instruction>(V));
561   }
562 };
563
564 //===----------------------------------------------------------------------===//
565 //                               ICmpInst Class
566 //===----------------------------------------------------------------------===//
567
568 /// This instruction compares its operands according to the predicate given
569 /// to the constructor. It only operates on integers, pointers, or packed 
570 /// vectors of integrals. The two operands must be the same type.
571 /// @brief Represent an integer comparison operator.
572 class ICmpInst: public CmpInst {
573 protected:
574   static void destroyThis(ICmpInst* v) {
575     CmpInst::destroyThis(v);
576   }
577   friend class Value;
578 public:
579   /// This enumeration lists the possible predicates for the ICmpInst. The
580   /// values in the range 0-31 are reserved for FCmpInst while values in the
581   /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
582   /// predicate values are not overlapping between the classes.
583   enum Predicate {
584     ICMP_EQ  = 32,    ///< equal
585     ICMP_NE  = 33,    ///< not equal
586     ICMP_UGT = 34,    ///< unsigned greater than
587     ICMP_UGE = 35,    ///< unsigned greater or equal
588     ICMP_ULT = 36,    ///< unsigned less than
589     ICMP_ULE = 37,    ///< unsigned less or equal
590     ICMP_SGT = 38,    ///< signed greater than
591     ICMP_SGE = 39,    ///< signed greater or equal
592     ICMP_SLT = 40,    ///< signed less than
593     ICMP_SLE = 41,    ///< signed less or equal
594     FIRST_ICMP_PREDICATE = ICMP_EQ,
595     LAST_ICMP_PREDICATE = ICMP_SLE,
596     BAD_ICMP_PREDICATE = ICMP_SLE + 1
597   };
598
599   /// @brief Constructor with insert-before-instruction semantics.
600   ICmpInst(
601     Predicate pred,  ///< The predicate to use for the comparison
602     Value *LHS,      ///< The left-hand-side of the expression
603     Value *RHS,      ///< The right-hand-side of the expression
604     const std::string &Name = "",  ///< Name of the instruction
605     Instruction *InsertBefore = 0  ///< Where to insert
606   ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
607   }
608
609   /// @brief Constructor with insert-at-block-end semantics.
610   ICmpInst(
611     Predicate pred, ///< The predicate to use for the comparison
612     Value *LHS,     ///< The left-hand-side of the expression
613     Value *RHS,     ///< The right-hand-side of the expression
614     const std::string &Name,  ///< Name of the instruction
615     BasicBlock *InsertAtEnd   ///< Block to insert into.
616   ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
617   }
618
619   /// @brief Return the predicate for this instruction.
620   Predicate getPredicate() const { return Predicate(SubclassData); }
621
622   /// @brief Set the predicate for this instruction to the specified value.
623   void setPredicate(Predicate P) { SubclassData = P; }
624   
625   /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
626   /// @returns the inverse predicate for the instruction's current predicate. 
627   /// @brief Return the inverse of the instruction's predicate.
628   Predicate getInversePredicate() const {
629     return getInversePredicate(getPredicate());
630   }
631
632   /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
633   /// @returns the inverse predicate for predicate provided in \p pred. 
634   /// @brief Return the inverse of a given predicate
635   static Predicate getInversePredicate(Predicate pred);
636
637   /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
638   /// @returns the predicate that would be the result of exchanging the two 
639   /// operands of the ICmpInst instruction without changing the result 
640   /// produced.  
641   /// @brief Return the predicate as if the operands were swapped
642   Predicate getSwappedPredicate() const {
643     return getSwappedPredicate(getPredicate());
644   }
645
646   /// This is a static version that you can use without an instruction 
647   /// available.
648   /// @brief Return the predicate as if the operands were swapped.
649   static Predicate getSwappedPredicate(Predicate pred);
650
651   /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
652   /// @returns the predicate that would be the result if the operand were
653   /// regarded as signed.
654   /// @brief Return the signed version of the predicate
655   Predicate getSignedPredicate() const {
656     return getSignedPredicate(getPredicate());
657   }
658
659   /// This is a static version that you can use without an instruction.
660   /// @brief Return the signed version of the predicate.
661   static Predicate getSignedPredicate(Predicate pred);
662
663   /// isEquality - Return true if this predicate is either EQ or NE.  This also
664   /// tests for commutativity.
665   static bool isEquality(Predicate P) {
666     return P == ICMP_EQ || P == ICMP_NE;
667   }
668   
669   /// isEquality - Return true if this predicate is either EQ or NE.  This also
670   /// tests for commutativity.
671   bool isEquality() const {
672     return isEquality(getPredicate());
673   }
674
675   /// @returns true if the predicate of this ICmpInst is commutative
676   /// @brief Determine if this relation is commutative.
677   bool isCommutative() const { return isEquality(); }
678
679   /// isRelational - Return true if the predicate is relational (not EQ or NE). 
680   ///
681   bool isRelational() const {
682     return !isEquality();
683   }
684
685   /// isRelational - Return true if the predicate is relational (not EQ or NE). 
686   ///
687   static bool isRelational(Predicate P) {
688     return !isEquality(P);
689   }
690   
691   /// @returns true if the predicate of this ICmpInst is signed, false otherwise
692   /// @brief Determine if this instruction's predicate is signed.
693   bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
694
695   /// @returns true if the predicate provided is signed, false otherwise
696   /// @brief Determine if the predicate is signed.
697   static bool isSignedPredicate(Predicate pred);
698
699   /// Initialize a set of values that all satisfy the predicate with C. 
700   /// @brief Make a ConstantRange for a relation with a constant value.
701   static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
702
703   /// Exchange the two operands to this instruction in such a way that it does
704   /// not modify the semantics of the instruction. The predicate value may be
705   /// changed to retain the same result if the predicate is order dependent
706   /// (e.g. ult). 
707   /// @brief Swap operands and adjust predicate.
708   void swapOperands() {
709     SubclassData = getSwappedPredicate();
710     std::swap(Ops[0], Ops[1]);
711   }
712
713   virtual ICmpInst *clone() const;
714
715   // Methods for support type inquiry through isa, cast, and dyn_cast:
716   static inline bool classof(const ICmpInst *) { return true; }
717   static inline bool classof(const Instruction *I) {
718     return I->getOpcode() == Instruction::ICmp;
719   }
720   static inline bool classof(const Value *V) {
721     return isa<Instruction>(V) && classof(cast<Instruction>(V));
722   }
723 };
724
725 //===----------------------------------------------------------------------===//
726 //                               FCmpInst Class
727 //===----------------------------------------------------------------------===//
728
729 /// This instruction compares its operands according to the predicate given
730 /// to the constructor. It only operates on floating point values or packed     
731 /// vectors of floating point values. The operands must be identical types.
732 /// @brief Represents a floating point comparison operator.
733 class FCmpInst: public CmpInst {
734 protected:
735   static void destroyThis(FCmpInst* v) {
736     CmpInst::destroyThis(v);
737   }
738   friend class Value;
739 public:
740   /// This enumeration lists the possible predicates for the FCmpInst. Values
741   /// in the range 0-31 are reserved for FCmpInst.
742   enum Predicate {
743     // Opcode        U L G E    Intuitive operation
744     FCMP_FALSE = 0, ///<  0 0 0 0    Always false (always folded)
745     FCMP_OEQ   = 1, ///<  0 0 0 1    True if ordered and equal
746     FCMP_OGT   = 2, ///<  0 0 1 0    True if ordered and greater than
747     FCMP_OGE   = 3, ///<  0 0 1 1    True if ordered and greater than or equal
748     FCMP_OLT   = 4, ///<  0 1 0 0    True if ordered and less than
749     FCMP_OLE   = 5, ///<  0 1 0 1    True if ordered and less than or equal
750     FCMP_ONE   = 6, ///<  0 1 1 0    True if ordered and operands are unequal
751     FCMP_ORD   = 7, ///<  0 1 1 1    True if ordered (no nans)
752     FCMP_UNO   = 8, ///<  1 0 0 0    True if unordered: isnan(X) | isnan(Y)
753     FCMP_UEQ   = 9, ///<  1 0 0 1    True if unordered or equal
754     FCMP_UGT   =10, ///<  1 0 1 0    True if unordered or greater than
755     FCMP_UGE   =11, ///<  1 0 1 1    True if unordered, greater than, or equal
756     FCMP_ULT   =12, ///<  1 1 0 0    True if unordered or less than
757     FCMP_ULE   =13, ///<  1 1 0 1    True if unordered, less than, or equal
758     FCMP_UNE   =14, ///<  1 1 1 0    True if unordered or not equal
759     FCMP_TRUE  =15, ///<  1 1 1 1    Always true (always folded)
760     FIRST_FCMP_PREDICATE = FCMP_FALSE,
761     LAST_FCMP_PREDICATE = FCMP_TRUE,
762     BAD_FCMP_PREDICATE = FCMP_TRUE + 1
763   };
764
765   /// @brief Constructor with insert-before-instruction semantics.
766   FCmpInst(
767     Predicate pred,  ///< The predicate to use for the comparison
768     Value *LHS,      ///< The left-hand-side of the expression
769     Value *RHS,      ///< The right-hand-side of the expression
770     const std::string &Name = "",  ///< Name of the instruction
771     Instruction *InsertBefore = 0  ///< Where to insert
772   ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
773   }
774
775   /// @brief Constructor with insert-at-block-end semantics.
776   FCmpInst(
777     Predicate pred, ///< The predicate to use for the comparison
778     Value *LHS,     ///< The left-hand-side of the expression
779     Value *RHS,     ///< The right-hand-side of the expression
780     const std::string &Name,  ///< Name of the instruction
781     BasicBlock *InsertAtEnd   ///< Block to insert into.
782   ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
783   }
784
785   /// @brief Return the predicate for this instruction.
786   Predicate getPredicate() const { return Predicate(SubclassData); }
787
788   /// @brief Set the predicate for this instruction to the specified value.
789   void setPredicate(Predicate P) { SubclassData = P; }
790
791   /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
792   /// @returns the inverse predicate for the instructions current predicate. 
793   /// @brief Return the inverse of the predicate
794   Predicate getInversePredicate() const {
795     return getInversePredicate(getPredicate());
796   }
797
798   /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
799   /// @returns the inverse predicate for \p pred.
800   /// @brief Return the inverse of a given predicate
801   static Predicate getInversePredicate(Predicate pred);
802
803   /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
804   /// @returns the predicate that would be the result of exchanging the two 
805   /// operands of the ICmpInst instruction without changing the result 
806   /// produced.  
807   /// @brief Return the predicate as if the operands were swapped
808   Predicate getSwappedPredicate() const {
809     return getSwappedPredicate(getPredicate());
810   }
811
812   /// This is a static version that you can use without an instruction 
813   /// available.
814   /// @brief Return the predicate as if the operands were swapped.
815   static Predicate getSwappedPredicate(Predicate Opcode);
816
817   /// This also tests for commutativity. If isEquality() returns true then
818   /// the predicate is also commutative. Only the equality predicates are
819   /// commutative.
820   /// @returns true if the predicate of this instruction is EQ or NE.
821   /// @brief Determine if this is an equality predicate.
822   bool isEquality() const {
823     return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
824            SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
825   }
826   bool isCommutative() const { return isEquality(); }
827
828   /// @returns true if the predicate is relational (not EQ or NE). 
829   /// @brief Determine if this a relational predicate.
830   bool isRelational() const { return !isEquality(); }
831
832   /// Exchange the two operands to this instruction in such a way that it does
833   /// not modify the semantics of the instruction. The predicate value may be
834   /// changed to retain the same result if the predicate is order dependent
835   /// (e.g. ult). 
836   /// @brief Swap operands and adjust predicate.
837   void swapOperands() {
838     SubclassData = getSwappedPredicate();
839     std::swap(Ops[0], Ops[1]);
840   }
841
842   virtual FCmpInst *clone() const;
843
844   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
845   static inline bool classof(const FCmpInst *) { return true; }
846   static inline bool classof(const Instruction *I) {
847     return I->getOpcode() == Instruction::FCmp;
848   }
849   static inline bool classof(const Value *V) {
850     return isa<Instruction>(V) && classof(cast<Instruction>(V));
851   }
852 };
853
854 //===----------------------------------------------------------------------===//
855 //                                 CallInst Class
856 //===----------------------------------------------------------------------===//
857 /// CallInst - This class represents a function call, abstracting a target
858 /// machine's calling convention.  This class uses low bit of the SubClassData
859 /// field to indicate whether or not this is a tail call.  The rest of the bits
860 /// hold the calling convention of the call.
861 ///
862
863 class CallInst : public Instruction {
864   const ParamAttrsList *ParamAttrs; ///< parameter attributes for call
865   CallInst(const CallInst &CI);
866   void init(Value *Func, Value* const *Params, unsigned NumParams);
867   void init(Value *Func, Value *Actual1, Value *Actual2);
868   void init(Value *Func, Value *Actual);
869   void init(Value *Func);
870
871   template<typename InputIterator>
872   void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
873             const std::string &Name,
874             // This argument ensures that we have an iterator we can
875             // do arithmetic on in constant time
876             std::random_access_iterator_tag) {
877     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
878     
879     // This requires that the iterator points to contiguous memory.
880     init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
881     setName(Name);
882   }
883
884 protected:
885   static void destroyThis(CallInst*v);
886   friend class Value;
887 public:
888   /// Construct a CallInst given a range of arguments.  InputIterator
889   /// must be a random-access iterator pointing to contiguous storage
890   /// (e.g. a std::vector<>::iterator).  Checks are made for
891   /// random-accessness but not for contiguous storage as that would
892   /// incur runtime overhead.
893   /// @brief Construct a CallInst from a range of arguments
894   template<typename InputIterator>
895   CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
896            const std::string &Name = "", Instruction *InsertBefore = 0)
897       : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
898                                        ->getElementType())->getReturnType(),
899                     Instruction::Call, 0, 0, InsertBefore) {
900     init(Func, ArgBegin, ArgEnd, Name, 
901          typename std::iterator_traits<InputIterator>::iterator_category());
902   }
903
904   /// Construct a CallInst given a range of arguments.  InputIterator
905   /// must be a random-access iterator pointing to contiguous storage
906   /// (e.g. a std::vector<>::iterator).  Checks are made for
907   /// random-accessness but not for contiguous storage as that would
908   /// incur runtime overhead.
909   /// @brief Construct a CallInst from a range of arguments
910   template<typename InputIterator>
911   CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
912            const std::string &Name, BasicBlock *InsertAtEnd)
913       : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
914                                        ->getElementType())->getReturnType(),
915                     Instruction::Call, 0, 0, InsertAtEnd) {
916     init(Func, ArgBegin, ArgEnd, Name,
917          typename std::iterator_traits<InputIterator>::iterator_category());
918   }
919
920   CallInst(Value *F, Value *Actual, const std::string& Name = "",
921            Instruction *InsertBefore = 0);
922   CallInst(Value *F, Value *Actual, const std::string& Name,
923            BasicBlock *InsertAtEnd);
924   explicit CallInst(Value *F, const std::string &Name = "",
925                     Instruction *InsertBefore = 0);
926   CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
927
928   virtual CallInst *clone() const;
929   
930   bool isTailCall() const           { return SubclassData & 1; }
931   void setTailCall(bool isTailCall = true) {
932     SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
933   }
934
935   /// getCallingConv/setCallingConv - Get or set the calling convention of this
936   /// function call.
937   unsigned getCallingConv() const { return SubclassData >> 1; }
938   void setCallingConv(unsigned CC) {
939     SubclassData = (SubclassData & 1) | (CC << 1);
940   }
941
942   /// Obtains a pointer to the ParamAttrsList object which holds the
943   /// parameter attributes information, if any.
944   /// @returns 0 if no attributes have been set.
945   /// @brief Get the parameter attributes.
946   const ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
947
948   /// Sets the parameter attributes for this CallInst. To construct a 
949   /// ParamAttrsList, see ParameterAttributes.h
950   /// @brief Set the parameter attributes.
951   void setParamAttrs(const ParamAttrsList *attrs);
952
953   /// @brief Determine whether the call or the callee has the given attribute.
954   bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
955
956   /// @brief Determine if the call does not access memory.
957   bool doesNotAccessMemory() const {
958     return paramHasAttr(0, ParamAttr::ReadNone);
959   }
960
961   /// @brief Determine if the call does not access or only reads memory.
962   bool onlyReadsMemory() const {
963     return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
964   }
965
966   /// @brief Determine if the call cannot unwind.
967   bool isNoUnwind() const {
968     return paramHasAttr(0, ParamAttr::NoUnwind);
969   }
970
971   /// @brief Determine if the call returns a structure.
972   bool isStructReturn() const {
973     // Be friendly and also check the callee.
974     return paramHasAttr(1, ParamAttr::StructRet);
975   }
976
977   /// getCalledFunction - Return the function being called by this instruction
978   /// if it is a direct call.  If it is a call through a function pointer,
979   /// return null.
980   Function *getCalledFunction() const {
981     return dyn_cast<Function>(getOperand(0));
982   }
983
984   /// getCalledValue - Get a pointer to the function that is invoked by this 
985   /// instruction
986   inline const Value *getCalledValue() const { return getOperand(0); }
987   inline       Value *getCalledValue()       { return getOperand(0); }
988
989   // Methods for support type inquiry through isa, cast, and dyn_cast:
990   static inline bool classof(const CallInst *) { return true; }
991   static inline bool classof(const Instruction *I) {
992     return I->getOpcode() == Instruction::Call;
993   }
994   static inline bool classof(const Value *V) {
995     return isa<Instruction>(V) && classof(cast<Instruction>(V));
996   }
997 };
998
999 //===----------------------------------------------------------------------===//
1000 //                               SelectInst Class
1001 //===----------------------------------------------------------------------===//
1002
1003 /// SelectInst - This class represents the LLVM 'select' instruction.
1004 ///
1005 class SelectInst : public Instruction {
1006   Use Ops[3];
1007
1008   void init(Value *C, Value *S1, Value *S2) {
1009     Ops[0].init(C, this);
1010     Ops[1].init(S1, this);
1011     Ops[2].init(S2, this);
1012   }
1013
1014   SelectInst(const SelectInst &SI)
1015     : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
1016     init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
1017   }
1018 protected:
1019   static void destroyThis(SelectInst* v) {
1020     Instruction::destroyThis(v);
1021   }
1022   friend class Value;
1023 public:
1024   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
1025              Instruction *InsertBefore = 0)
1026     : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
1027     init(C, S1, S2);
1028     setName(Name);
1029   }
1030   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1031              BasicBlock *InsertAtEnd)
1032     : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
1033     init(C, S1, S2);
1034     setName(Name);
1035   }
1036
1037   Value *getCondition() const { return Ops[0]; }
1038   Value *getTrueValue() const { return Ops[1]; }
1039   Value *getFalseValue() const { return Ops[2]; }
1040
1041   /// Transparently provide more efficient getOperand methods.
1042   Value *getOperand(unsigned i) const {
1043     assert(i < 3 && "getOperand() out of range!");
1044     return Ops[i];
1045   }
1046   void setOperand(unsigned i, Value *Val) {
1047     assert(i < 3 && "setOperand() out of range!");
1048     Ops[i] = Val;
1049   }
1050   unsigned getNumOperands() const { return 3; }
1051
1052   OtherOps getOpcode() const {
1053     return static_cast<OtherOps>(Instruction::getOpcode());
1054   }
1055
1056   virtual SelectInst *clone() const;
1057
1058   // Methods for support type inquiry through isa, cast, and dyn_cast:
1059   static inline bool classof(const SelectInst *) { return true; }
1060   static inline bool classof(const Instruction *I) {
1061     return I->getOpcode() == Instruction::Select;
1062   }
1063   static inline bool classof(const Value *V) {
1064     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1065   }
1066 };
1067
1068 //===----------------------------------------------------------------------===//
1069 //                                VAArgInst Class
1070 //===----------------------------------------------------------------------===//
1071
1072 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1073 /// an argument of the specified type given a va_list and increments that list
1074 ///
1075 class VAArgInst : public UnaryInstruction {
1076   VAArgInst(const VAArgInst &VAA)
1077     : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
1078 protected:
1079   static void destroyThis(VAArgInst* v) {
1080     UnaryInstruction::destroyThis(v);
1081   }
1082   friend class Value;
1083 public:
1084   VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
1085              Instruction *InsertBefore = 0)
1086     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1087     setName(Name);
1088   }
1089   VAArgInst(Value *List, const Type *Ty, const std::string &Name,
1090             BasicBlock *InsertAtEnd)
1091     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1092     setName(Name);
1093   }
1094
1095   virtual VAArgInst *clone() const;
1096
1097   // Methods for support type inquiry through isa, cast, and dyn_cast:
1098   static inline bool classof(const VAArgInst *) { return true; }
1099   static inline bool classof(const Instruction *I) {
1100     return I->getOpcode() == VAArg;
1101   }
1102   static inline bool classof(const Value *V) {
1103     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1104   }
1105 };
1106
1107 //===----------------------------------------------------------------------===//
1108 //                                ExtractElementInst Class
1109 //===----------------------------------------------------------------------===//
1110
1111 /// ExtractElementInst - This instruction extracts a single (scalar)
1112 /// element from a VectorType value
1113 ///
1114 class ExtractElementInst : public Instruction {
1115   Use Ops[2];
1116   ExtractElementInst(const ExtractElementInst &EE) :
1117     Instruction(EE.getType(), ExtractElement, Ops, 2) {
1118     Ops[0].init(EE.Ops[0], this);
1119     Ops[1].init(EE.Ops[1], this);
1120   }
1121
1122 protected:
1123   static void destroyThis(ExtractElementInst* v) {
1124     Instruction::destroyThis(v);
1125   }
1126   friend class Value;
1127 public:
1128   ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
1129                      Instruction *InsertBefore = 0);
1130   ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
1131                      Instruction *InsertBefore = 0);
1132   ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
1133                      BasicBlock *InsertAtEnd);
1134   ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
1135                      BasicBlock *InsertAtEnd);
1136
1137   /// isValidOperands - Return true if an extractelement instruction can be
1138   /// formed with the specified operands.
1139   static bool isValidOperands(const Value *Vec, const Value *Idx);
1140
1141   virtual ExtractElementInst *clone() const;
1142
1143   /// Transparently provide more efficient getOperand methods.
1144   Value *getOperand(unsigned i) const {
1145     assert(i < 2 && "getOperand() out of range!");
1146     return Ops[i];
1147   }
1148   void setOperand(unsigned i, Value *Val) {
1149     assert(i < 2 && "setOperand() out of range!");
1150     Ops[i] = Val;
1151   }
1152   unsigned getNumOperands() const { return 2; }
1153
1154   // Methods for support type inquiry through isa, cast, and dyn_cast:
1155   static inline bool classof(const ExtractElementInst *) { return true; }
1156   static inline bool classof(const Instruction *I) {
1157     return I->getOpcode() == Instruction::ExtractElement;
1158   }
1159   static inline bool classof(const Value *V) {
1160     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1161   }
1162 };
1163
1164 //===----------------------------------------------------------------------===//
1165 //                                InsertElementInst Class
1166 //===----------------------------------------------------------------------===//
1167
1168 /// InsertElementInst - This instruction inserts a single (scalar)
1169 /// element into a VectorType value
1170 ///
1171 class InsertElementInst : public Instruction {
1172   Use Ops[3];
1173   InsertElementInst(const InsertElementInst &IE);
1174 protected:
1175   static void destroyThis(InsertElementInst* v) {
1176     Instruction::destroyThis(v);
1177   }
1178   friend class Value;
1179 public:
1180   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1181                     const std::string &Name = "",Instruction *InsertBefore = 0);
1182   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1183                     const std::string &Name = "",Instruction *InsertBefore = 0);
1184   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1185                     const std::string &Name, BasicBlock *InsertAtEnd);
1186   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1187                     const std::string &Name, BasicBlock *InsertAtEnd);
1188
1189   /// isValidOperands - Return true if an insertelement instruction can be
1190   /// formed with the specified operands.
1191   static bool isValidOperands(const Value *Vec, const Value *NewElt,
1192                               const Value *Idx);
1193
1194   virtual InsertElementInst *clone() const;
1195
1196   /// getType - Overload to return most specific vector type.
1197   ///
1198   inline const VectorType *getType() const {
1199     return reinterpret_cast<const VectorType*>(Instruction::getType());
1200   }
1201
1202   /// Transparently provide more efficient getOperand methods.
1203   Value *getOperand(unsigned i) const {
1204     assert(i < 3 && "getOperand() out of range!");
1205     return Ops[i];
1206   }
1207   void setOperand(unsigned i, Value *Val) {
1208     assert(i < 3 && "setOperand() out of range!");
1209     Ops[i] = Val;
1210   }
1211   unsigned getNumOperands() const { return 3; }
1212
1213   // Methods for support type inquiry through isa, cast, and dyn_cast:
1214   static inline bool classof(const InsertElementInst *) { return true; }
1215   static inline bool classof(const Instruction *I) {
1216     return I->getOpcode() == Instruction::InsertElement;
1217   }
1218   static inline bool classof(const Value *V) {
1219     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1220   }
1221 };
1222
1223 //===----------------------------------------------------------------------===//
1224 //                           ShuffleVectorInst Class
1225 //===----------------------------------------------------------------------===//
1226
1227 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1228 /// input vectors.
1229 ///
1230 class ShuffleVectorInst : public Instruction {
1231   Use Ops[3];
1232   ShuffleVectorInst(const ShuffleVectorInst &IE);
1233 protected:
1234   static void destroyThis(ShuffleVectorInst* v) {
1235     Instruction::destroyThis(v);
1236   }
1237   friend class Value;
1238 public:
1239   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1240                     const std::string &Name = "", Instruction *InsertBefor = 0);
1241   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1242                     const std::string &Name, BasicBlock *InsertAtEnd);
1243
1244   /// isValidOperands - Return true if a shufflevector instruction can be
1245   /// formed with the specified operands.
1246   static bool isValidOperands(const Value *V1, const Value *V2,
1247                               const Value *Mask);
1248
1249   virtual ShuffleVectorInst *clone() const;
1250
1251   /// getType - Overload to return most specific vector type.
1252   ///
1253   inline const VectorType *getType() const {
1254     return reinterpret_cast<const VectorType*>(Instruction::getType());
1255   }
1256
1257   /// Transparently provide more efficient getOperand methods.
1258   Value *getOperand(unsigned i) const {
1259     assert(i < 3 && "getOperand() out of range!");
1260     return Ops[i];
1261   }
1262   void setOperand(unsigned i, Value *Val) {
1263     assert(i < 3 && "setOperand() out of range!");
1264     Ops[i] = Val;
1265   }
1266   unsigned getNumOperands() const { return 3; }
1267
1268   // Methods for support type inquiry through isa, cast, and dyn_cast:
1269   static inline bool classof(const ShuffleVectorInst *) { return true; }
1270   static inline bool classof(const Instruction *I) {
1271     return I->getOpcode() == Instruction::ShuffleVector;
1272   }
1273   static inline bool classof(const Value *V) {
1274     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1275   }
1276 };
1277
1278
1279 //===----------------------------------------------------------------------===//
1280 //                               PHINode Class
1281 //===----------------------------------------------------------------------===//
1282
1283 // PHINode - The PHINode class is used to represent the magical mystical PHI
1284 // node, that can not exist in nature, but can be synthesized in a computer
1285 // scientist's overactive imagination.
1286 //
1287 class PHINode : public Instruction {
1288   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1289   /// the number actually in use.
1290   unsigned ReservedSpace;
1291   PHINode(const PHINode &PN);
1292 protected:
1293   static void destroyThis(PHINode*);
1294   friend class Value;
1295 public:
1296   explicit PHINode(const Type *Ty, const std::string &Name = "",
1297                    Instruction *InsertBefore = 0)
1298     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1299       ReservedSpace(0) {
1300     setName(Name);
1301   }
1302
1303   PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1304     : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1305       ReservedSpace(0) {
1306     setName(Name);
1307   }
1308
1309   /// reserveOperandSpace - This method can be used to avoid repeated
1310   /// reallocation of PHI operand lists by reserving space for the correct
1311   /// number of operands before adding them.  Unlike normal vector reserves,
1312   /// this method can also be used to trim the operand space.
1313   void reserveOperandSpace(unsigned NumValues) {
1314     resizeOperands(NumValues*2);
1315   }
1316
1317   virtual PHINode *clone() const;
1318
1319   /// getNumIncomingValues - Return the number of incoming edges
1320   ///
1321   unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1322
1323   /// getIncomingValue - Return incoming value number x
1324   ///
1325   Value *getIncomingValue(unsigned i) const {
1326     assert(i*2 < getNumOperands() && "Invalid value number!");
1327     return getOperand(i*2);
1328   }
1329   void setIncomingValue(unsigned i, Value *V) {
1330     assert(i*2 < getNumOperands() && "Invalid value number!");
1331     setOperand(i*2, V);
1332   }
1333   unsigned getOperandNumForIncomingValue(unsigned i) {
1334     return i*2;
1335   }
1336
1337   /// getIncomingBlock - Return incoming basic block number x
1338   ///
1339   BasicBlock *getIncomingBlock(unsigned i) const {
1340     return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1341   }
1342   void setIncomingBlock(unsigned i, BasicBlock *BB) {
1343     setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1344   }
1345   unsigned getOperandNumForIncomingBlock(unsigned i) {
1346     return i*2+1;
1347   }
1348
1349   /// addIncoming - Add an incoming value to the end of the PHI list
1350   ///
1351   void addIncoming(Value *V, BasicBlock *BB) {
1352     assert(getType() == V->getType() &&
1353            "All operands to PHI node must be the same type as the PHI node!");
1354     unsigned OpNo = NumOperands;
1355     if (OpNo+2 > ReservedSpace)
1356       resizeOperands(0);  // Get more space!
1357     // Initialize some new operands.
1358     NumOperands = OpNo+2;
1359     OperandList[OpNo].init(V, this);
1360     OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1361   }
1362
1363   /// removeIncomingValue - Remove an incoming value.  This is useful if a
1364   /// predecessor basic block is deleted.  The value removed is returned.
1365   ///
1366   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1367   /// is true), the PHI node is destroyed and any uses of it are replaced with
1368   /// dummy values.  The only time there should be zero incoming values to a PHI
1369   /// node is when the block is dead, so this strategy is sound.
1370   ///
1371   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1372
1373   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1374     int Idx = getBasicBlockIndex(BB);
1375     assert(Idx >= 0 && "Invalid basic block argument to remove!");
1376     return removeIncomingValue(Idx, DeletePHIIfEmpty);
1377   }
1378
1379   /// getBasicBlockIndex - Return the first index of the specified basic
1380   /// block in the value list for this PHI.  Returns -1 if no instance.
1381   ///
1382   int getBasicBlockIndex(const BasicBlock *BB) const {
1383     Use *OL = OperandList;
1384     for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1385       if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1386     return -1;
1387   }
1388
1389   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1390     return getIncomingValue(getBasicBlockIndex(BB));
1391   }
1392
1393   /// hasConstantValue - If the specified PHI node always merges together the
1394   /// same value, return the value, otherwise return null.
1395   ///
1396   Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1397
1398   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1399   static inline bool classof(const PHINode *) { return true; }
1400   static inline bool classof(const Instruction *I) {
1401     return I->getOpcode() == Instruction::PHI;
1402   }
1403   static inline bool classof(const Value *V) {
1404     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1405   }
1406  private:
1407   void resizeOperands(unsigned NumOperands);
1408 };
1409
1410 //===----------------------------------------------------------------------===//
1411 //                               ReturnInst Class
1412 //===----------------------------------------------------------------------===//
1413
1414 //===---------------------------------------------------------------------------
1415 /// ReturnInst - Return a value (possibly void), from a function.  Execution
1416 /// does not continue in this function any longer.
1417 ///
1418 class ReturnInst : public TerminatorInst {
1419   Use RetVal;  // Return Value: null if 'void'.
1420   ReturnInst(const ReturnInst &RI);
1421   void init(Value *RetVal);
1422
1423 public:
1424   // ReturnInst constructors:
1425   // ReturnInst()                  - 'ret void' instruction
1426   // ReturnInst(    null)          - 'ret void' instruction
1427   // ReturnInst(Value* X)          - 'ret X'    instruction
1428   // ReturnInst(    null, Inst *)  - 'ret void' instruction, insert before I
1429   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
1430   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of BB
1431   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of BB
1432   //
1433   // NOTE: If the Value* passed is of type void then the constructor behaves as
1434   // if it was passed NULL.
1435   explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1436   ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1437   explicit ReturnInst(BasicBlock *InsertAtEnd);
1438
1439   virtual ReturnInst *clone() const;
1440
1441   // Transparently provide more efficient getOperand methods.
1442   Value *getOperand(unsigned i) const {
1443     assert(i < getNumOperands() && "getOperand() out of range!");
1444     return RetVal;
1445   }
1446   void setOperand(unsigned i, Value *Val) {
1447     assert(i < getNumOperands() && "setOperand() out of range!");
1448     RetVal = Val;
1449   }
1450
1451   Value *getReturnValue() const { return RetVal; }
1452
1453   unsigned getNumSuccessors() const { return 0; }
1454
1455   // Methods for support type inquiry through isa, cast, and dyn_cast:
1456   static inline bool classof(const ReturnInst *) { return true; }
1457   static inline bool classof(const Instruction *I) {
1458     return (I->getOpcode() == Instruction::Ret);
1459   }
1460   static inline bool classof(const Value *V) {
1461     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1462   }
1463  private:
1464   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1465   virtual unsigned getNumSuccessorsV() const;
1466   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1467 };
1468
1469 //===----------------------------------------------------------------------===//
1470 //                               BranchInst Class
1471 //===----------------------------------------------------------------------===//
1472
1473 //===---------------------------------------------------------------------------
1474 /// BranchInst - Conditional or Unconditional Branch instruction.
1475 ///
1476 class BranchInst : public TerminatorInst {
1477   /// Ops list - Branches are strange.  The operands are ordered:
1478   ///  TrueDest, FalseDest, Cond.  This makes some accessors faster because
1479   /// they don't have to check for cond/uncond branchness.
1480   Use Ops[3];
1481   BranchInst(const BranchInst &BI);
1482   void AssertOK();
1483 public:
1484   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1485   // BranchInst(BB *B)                           - 'br B'
1486   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
1487   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
1488   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1489   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
1490   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
1491   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1492   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1493              Instruction *InsertBefore = 0);
1494   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1495   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1496              BasicBlock *InsertAtEnd);
1497
1498   /// Transparently provide more efficient getOperand methods.
1499   Value *getOperand(unsigned i) const {
1500     assert(i < getNumOperands() && "getOperand() out of range!");
1501     return Ops[i];
1502   }
1503   void setOperand(unsigned i, Value *Val) {
1504     assert(i < getNumOperands() && "setOperand() out of range!");
1505     Ops[i] = Val;
1506   }
1507
1508   virtual BranchInst *clone() const;
1509
1510   inline bool isUnconditional() const { return getNumOperands() == 1; }
1511   inline bool isConditional()   const { return getNumOperands() == 3; }
1512
1513   inline Value *getCondition() const {
1514     assert(isConditional() && "Cannot get condition of an uncond branch!");
1515     return getOperand(2);
1516   }
1517
1518   void setCondition(Value *V) {
1519     assert(isConditional() && "Cannot set condition of unconditional branch!");
1520     setOperand(2, V);
1521   }
1522
1523   // setUnconditionalDest - Change the current branch to an unconditional branch
1524   // targeting the specified block.
1525   // FIXME: Eliminate this ugly method.
1526   void setUnconditionalDest(BasicBlock *Dest) {
1527     if (isConditional()) {  // Convert this to an uncond branch.
1528       NumOperands = 1;
1529       Ops[1].set(0);
1530       Ops[2].set(0);
1531     }
1532     setOperand(0, reinterpret_cast<Value*>(Dest));
1533   }
1534
1535   unsigned getNumSuccessors() const { return 1+isConditional(); }
1536
1537   BasicBlock *getSuccessor(unsigned i) const {
1538     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1539     return cast<BasicBlock>(getOperand(i));
1540   }
1541
1542   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1543     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1544     setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1545   }
1546
1547   // Methods for support type inquiry through isa, cast, and dyn_cast:
1548   static inline bool classof(const BranchInst *) { return true; }
1549   static inline bool classof(const Instruction *I) {
1550     return (I->getOpcode() == Instruction::Br);
1551   }
1552   static inline bool classof(const Value *V) {
1553     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1554   }
1555 private:
1556   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1557   virtual unsigned getNumSuccessorsV() const;
1558   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1559 };
1560
1561 //===----------------------------------------------------------------------===//
1562 //                               SwitchInst Class
1563 //===----------------------------------------------------------------------===//
1564
1565 //===---------------------------------------------------------------------------
1566 /// SwitchInst - Multiway switch
1567 ///
1568 class SwitchInst : public TerminatorInst {
1569   unsigned ReservedSpace;
1570   // Operand[0]    = Value to switch on
1571   // Operand[1]    = Default basic block destination
1572   // Operand[2n  ] = Value to match
1573   // Operand[2n+1] = BasicBlock to go to on match
1574   SwitchInst(const SwitchInst &RI);
1575   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1576   void resizeOperands(unsigned No);
1577 protected:
1578   static void destroyThis(SwitchInst*v);
1579   friend class Value;
1580 public:
1581   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1582   /// switch on and a default destination.  The number of additional cases can
1583   /// be specified here to make memory allocation more efficient.  This
1584   /// constructor can also autoinsert before another instruction.
1585   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1586              Instruction *InsertBefore = 0);
1587   
1588   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1589   /// switch on and a default destination.  The number of additional cases can
1590   /// be specified here to make memory allocation more efficient.  This
1591   /// constructor also autoinserts at the end of the specified BasicBlock.
1592   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1593              BasicBlock *InsertAtEnd);
1594
1595
1596   // Accessor Methods for Switch stmt
1597   inline Value *getCondition() const { return getOperand(0); }
1598   void setCondition(Value *V) { setOperand(0, V); }
1599
1600   inline BasicBlock *getDefaultDest() const {
1601     return cast<BasicBlock>(getOperand(1));
1602   }
1603
1604   /// getNumCases - return the number of 'cases' in this switch instruction.
1605   /// Note that case #0 is always the default case.
1606   unsigned getNumCases() const {
1607     return getNumOperands()/2;
1608   }
1609
1610   /// getCaseValue - Return the specified case value.  Note that case #0, the
1611   /// default destination, does not have a case value.
1612   ConstantInt *getCaseValue(unsigned i) {
1613     assert(i && i < getNumCases() && "Illegal case value to get!");
1614     return getSuccessorValue(i);
1615   }
1616
1617   /// getCaseValue - Return the specified case value.  Note that case #0, the
1618   /// default destination, does not have a case value.
1619   const ConstantInt *getCaseValue(unsigned i) const {
1620     assert(i && i < getNumCases() && "Illegal case value to get!");
1621     return getSuccessorValue(i);
1622   }
1623
1624   /// findCaseValue - Search all of the case values for the specified constant.
1625   /// If it is explicitly handled, return the case number of it, otherwise
1626   /// return 0 to indicate that it is handled by the default handler.
1627   unsigned findCaseValue(const ConstantInt *C) const {
1628     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1629       if (getCaseValue(i) == C)
1630         return i;
1631     return 0;
1632   }
1633
1634   /// findCaseDest - Finds the unique case value for a given successor. Returns
1635   /// null if the successor is not found, not unique, or is the default case.
1636   ConstantInt *findCaseDest(BasicBlock *BB) {
1637     if (BB == getDefaultDest()) return NULL;
1638
1639     ConstantInt *CI = NULL;
1640     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1641       if (getSuccessor(i) == BB) {
1642         if (CI) return NULL;   // Multiple cases lead to BB.
1643         else CI = getCaseValue(i);
1644       }
1645     }
1646     return CI;
1647   }
1648
1649   /// addCase - Add an entry to the switch instruction...
1650   ///
1651   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1652
1653   /// removeCase - This method removes the specified successor from the switch
1654   /// instruction.  Note that this cannot be used to remove the default
1655   /// destination (successor #0).
1656   ///
1657   void removeCase(unsigned idx);
1658
1659   virtual SwitchInst *clone() const;
1660
1661   unsigned getNumSuccessors() const { return getNumOperands()/2; }
1662   BasicBlock *getSuccessor(unsigned idx) const {
1663     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1664     return cast<BasicBlock>(getOperand(idx*2+1));
1665   }
1666   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1667     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1668     setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1669   }
1670
1671   // getSuccessorValue - Return the value associated with the specified
1672   // successor.
1673   inline ConstantInt *getSuccessorValue(unsigned idx) const {
1674     assert(idx < getNumSuccessors() && "Successor # out of range!");
1675     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1676   }
1677
1678   // Methods for support type inquiry through isa, cast, and dyn_cast:
1679   static inline bool classof(const SwitchInst *) { return true; }
1680   static inline bool classof(const Instruction *I) {
1681     return I->getOpcode() == Instruction::Switch;
1682   }
1683   static inline bool classof(const Value *V) {
1684     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1685   }
1686 private:
1687   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1688   virtual unsigned getNumSuccessorsV() const;
1689   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1690 };
1691
1692 //===----------------------------------------------------------------------===//
1693 //                               InvokeInst Class
1694 //===----------------------------------------------------------------------===//
1695
1696 //===---------------------------------------------------------------------------
1697
1698 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
1699 /// calling convention of the call.
1700 ///
1701 class InvokeInst : public TerminatorInst {
1702   const ParamAttrsList *ParamAttrs;
1703   InvokeInst(const InvokeInst &BI);
1704   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1705             Value* const *Args, unsigned NumArgs);
1706
1707   template<typename InputIterator>
1708   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1709             InputIterator ArgBegin, InputIterator ArgEnd,
1710             const std::string &Name,
1711             // This argument ensures that we have an iterator we can
1712             // do arithmetic on in constant time
1713             std::random_access_iterator_tag) {
1714     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
1715     
1716     // This requires that the iterator points to contiguous memory.
1717     init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
1718     setName(Name);
1719   }
1720
1721 protected:
1722   static void destroyThis(InvokeInst*v);
1723   friend class Value;
1724 public:
1725   /// Construct an InvokeInst given a range of arguments.
1726   /// InputIterator must be a random-access iterator pointing to
1727   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
1728   /// made for random-accessness but not for contiguous storage as
1729   /// that would incur runtime overhead.
1730   ///
1731   /// @brief Construct an InvokeInst from a range of arguments
1732   template<typename InputIterator>
1733   InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1734              InputIterator ArgBegin, InputIterator ArgEnd,
1735              const std::string &Name = "", Instruction *InsertBefore = 0)
1736       : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1737                                           ->getElementType())->getReturnType(),
1738                        Instruction::Invoke, 0, 0, InsertBefore) {
1739     init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1740          typename std::iterator_traits<InputIterator>::iterator_category());
1741   }
1742
1743   /// Construct an InvokeInst given a range of arguments.
1744   /// InputIterator must be a random-access iterator pointing to
1745   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
1746   /// made for random-accessness but not for contiguous storage as
1747   /// that would incur runtime overhead.
1748   ///
1749   /// @brief Construct an InvokeInst from a range of arguments
1750   template<typename InputIterator>
1751   InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1752              InputIterator ArgBegin, InputIterator ArgEnd,
1753              const std::string &Name, BasicBlock *InsertAtEnd)
1754       : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1755                                           ->getElementType())->getReturnType(),
1756                        Instruction::Invoke, 0, 0, InsertAtEnd) {
1757     init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1758          typename std::iterator_traits<InputIterator>::iterator_category());
1759   }
1760
1761   virtual InvokeInst *clone() const;
1762
1763   /// getCallingConv/setCallingConv - Get or set the calling convention of this
1764   /// function call.
1765   unsigned getCallingConv() const { return SubclassData; }
1766   void setCallingConv(unsigned CC) {
1767     SubclassData = CC;
1768   }
1769
1770   /// Obtains a pointer to the ParamAttrsList object which holds the
1771   /// parameter attributes information, if any.
1772   /// @returns 0 if no attributes have been set.
1773   /// @brief Get the parameter attributes.
1774   const ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
1775
1776   /// Sets the parameter attributes for this InvokeInst. To construct a 
1777   /// ParamAttrsList, see ParameterAttributes.h
1778   /// @brief Set the parameter attributes.
1779   void setParamAttrs(const ParamAttrsList *attrs);
1780
1781   /// @brief Determine whether the call or the callee has the given attribute.
1782   bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
1783
1784   /// @brief Determine if the call does not access memory.
1785   bool doesNotAccessMemory() const {
1786     return paramHasAttr(0, ParamAttr::ReadNone);
1787   }
1788
1789   /// @brief Determine if the call does not access or only reads memory.
1790   bool onlyReadsMemory() const {
1791     return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
1792   }
1793
1794   /// @brief Determine if the call cannot unwind.
1795   bool isNoUnwind() const {
1796     return paramHasAttr(0, ParamAttr::NoUnwind);
1797   }
1798
1799   /// @brief Determine if the call returns a structure.
1800   bool isStructReturn() const {
1801     // Be friendly and also check the callee.
1802     return paramHasAttr(1, ParamAttr::StructRet);
1803   }
1804
1805   /// getCalledFunction - Return the function called, or null if this is an
1806   /// indirect function invocation.
1807   ///
1808   Function *getCalledFunction() const {
1809     return dyn_cast<Function>(getOperand(0));
1810   }
1811
1812   // getCalledValue - Get a pointer to a function that is invoked by this inst.
1813   inline Value *getCalledValue() const { return getOperand(0); }
1814
1815   // get*Dest - Return the destination basic blocks...
1816   BasicBlock *getNormalDest() const {
1817     return cast<BasicBlock>(getOperand(1));
1818   }
1819   BasicBlock *getUnwindDest() const {
1820     return cast<BasicBlock>(getOperand(2));
1821   }
1822   void setNormalDest(BasicBlock *B) {
1823     setOperand(1, reinterpret_cast<Value*>(B));
1824   }
1825
1826   void setUnwindDest(BasicBlock *B) {
1827     setOperand(2, reinterpret_cast<Value*>(B));
1828   }
1829
1830   inline BasicBlock *getSuccessor(unsigned i) const {
1831     assert(i < 2 && "Successor # out of range for invoke!");
1832     return i == 0 ? getNormalDest() : getUnwindDest();
1833   }
1834
1835   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1836     assert(idx < 2 && "Successor # out of range for invoke!");
1837     setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1838   }
1839
1840   unsigned getNumSuccessors() const { return 2; }
1841
1842   // Methods for support type inquiry through isa, cast, and dyn_cast:
1843   static inline bool classof(const InvokeInst *) { return true; }
1844   static inline bool classof(const Instruction *I) {
1845     return (I->getOpcode() == Instruction::Invoke);
1846   }
1847   static inline bool classof(const Value *V) {
1848     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1849   }
1850 private:
1851   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1852   virtual unsigned getNumSuccessorsV() const;
1853   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1854 };
1855
1856
1857 //===----------------------------------------------------------------------===//
1858 //                              UnwindInst Class
1859 //===----------------------------------------------------------------------===//
1860
1861 //===---------------------------------------------------------------------------
1862 /// UnwindInst - Immediately exit the current function, unwinding the stack
1863 /// until an invoke instruction is found.
1864 ///
1865 class UnwindInst : public TerminatorInst {
1866 public:
1867   explicit UnwindInst(Instruction *InsertBefore = 0);
1868   explicit UnwindInst(BasicBlock *InsertAtEnd);
1869
1870   virtual UnwindInst *clone() const;
1871
1872   unsigned getNumSuccessors() const { return 0; }
1873
1874   // Methods for support type inquiry through isa, cast, and dyn_cast:
1875   static inline bool classof(const UnwindInst *) { return true; }
1876   static inline bool classof(const Instruction *I) {
1877     return I->getOpcode() == Instruction::Unwind;
1878   }
1879   static inline bool classof(const Value *V) {
1880     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1881   }
1882 private:
1883   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1884   virtual unsigned getNumSuccessorsV() const;
1885   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1886 };
1887
1888 //===----------------------------------------------------------------------===//
1889 //                           UnreachableInst Class
1890 //===----------------------------------------------------------------------===//
1891
1892 //===---------------------------------------------------------------------------
1893 /// UnreachableInst - This function has undefined behavior.  In particular, the
1894 /// presence of this instruction indicates some higher level knowledge that the
1895 /// end of the block cannot be reached.
1896 ///
1897 class UnreachableInst : public TerminatorInst {
1898 public:
1899   explicit UnreachableInst(Instruction *InsertBefore = 0);
1900   explicit UnreachableInst(BasicBlock *InsertAtEnd);
1901
1902   virtual UnreachableInst *clone() const;
1903
1904   unsigned getNumSuccessors() const { return 0; }
1905
1906   // Methods for support type inquiry through isa, cast, and dyn_cast:
1907   static inline bool classof(const UnreachableInst *) { return true; }
1908   static inline bool classof(const Instruction *I) {
1909     return I->getOpcode() == Instruction::Unreachable;
1910   }
1911   static inline bool classof(const Value *V) {
1912     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1913   }
1914 private:
1915   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1916   virtual unsigned getNumSuccessorsV() const;
1917   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1918 };
1919
1920 //===----------------------------------------------------------------------===//
1921 //                                 TruncInst Class
1922 //===----------------------------------------------------------------------===//
1923
1924 /// @brief This class represents a truncation of integer types.
1925 class TruncInst : public CastInst {
1926   /// Private copy constructor
1927   TruncInst(const TruncInst &CI)
1928     : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1929   }
1930 protected:
1931   static void destroyThis(TruncInst* v) {
1932     CastInst::destroyThis(v);
1933   }
1934   friend class Value;
1935 public:
1936   /// @brief Constructor with insert-before-instruction semantics
1937   TruncInst(
1938     Value *S,                     ///< The value to be truncated
1939     const Type *Ty,               ///< The (smaller) type to truncate to
1940     const std::string &Name = "", ///< A name for the new instruction
1941     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1942   );
1943
1944   /// @brief Constructor with insert-at-end-of-block semantics
1945   TruncInst(
1946     Value *S,                     ///< The value to be truncated
1947     const Type *Ty,               ///< The (smaller) type to truncate to
1948     const std::string &Name,      ///< A name for the new instruction
1949     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1950   );
1951
1952   /// @brief Clone an identical TruncInst
1953   virtual CastInst *clone() const;
1954
1955   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1956   static inline bool classof(const TruncInst *) { return true; }
1957   static inline bool classof(const Instruction *I) {
1958     return I->getOpcode() == Trunc;
1959   }
1960   static inline bool classof(const Value *V) {
1961     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1962   }
1963 };
1964
1965 //===----------------------------------------------------------------------===//
1966 //                                 ZExtInst Class
1967 //===----------------------------------------------------------------------===//
1968
1969 /// @brief This class represents zero extension of integer types.
1970 class ZExtInst : public CastInst {
1971   /// @brief Private copy constructor
1972   ZExtInst(const ZExtInst &CI)
1973     : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1974   }
1975 protected:
1976   static void destroyThis(ZExtInst* v) {
1977     CastInst::destroyThis(v);
1978   }
1979   friend class Value;
1980 public:
1981   /// @brief Constructor with insert-before-instruction semantics
1982   ZExtInst(
1983     Value *S,                     ///< The value to be zero extended
1984     const Type *Ty,               ///< The type to zero extend to
1985     const std::string &Name = "", ///< A name for the new instruction
1986     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1987   );
1988
1989   /// @brief Constructor with insert-at-end semantics.
1990   ZExtInst(
1991     Value *S,                     ///< The value to be zero extended
1992     const Type *Ty,               ///< The type to zero extend to
1993     const std::string &Name,      ///< A name for the new instruction
1994     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1995   );
1996
1997   /// @brief Clone an identical ZExtInst
1998   virtual CastInst *clone() const;
1999
2000   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2001   static inline bool classof(const ZExtInst *) { return true; }
2002   static inline bool classof(const Instruction *I) {
2003     return I->getOpcode() == ZExt;
2004   }
2005   static inline bool classof(const Value *V) {
2006     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2007   }
2008 };
2009
2010 //===----------------------------------------------------------------------===//
2011 //                                 SExtInst Class
2012 //===----------------------------------------------------------------------===//
2013
2014 /// @brief This class represents a sign extension of integer types.
2015 class SExtInst : public CastInst {
2016   /// @brief Private copy constructor
2017   SExtInst(const SExtInst &CI)
2018     : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
2019   }
2020 protected:
2021   static void destroyThis(SExtInst* v) {
2022     CastInst::destroyThis(v);
2023   }
2024   friend class Value;
2025 public:
2026   /// @brief Constructor with insert-before-instruction semantics
2027   SExtInst(
2028     Value *S,                     ///< The value to be sign extended
2029     const Type *Ty,               ///< The type to sign extend to
2030     const std::string &Name = "", ///< A name for the new instruction
2031     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2032   );
2033
2034   /// @brief Constructor with insert-at-end-of-block semantics
2035   SExtInst(
2036     Value *S,                     ///< The value to be sign extended
2037     const Type *Ty,               ///< The type to sign extend to
2038     const std::string &Name,      ///< A name for the new instruction
2039     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2040   );
2041
2042   /// @brief Clone an identical SExtInst
2043   virtual CastInst *clone() const;
2044
2045   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2046   static inline bool classof(const SExtInst *) { return true; }
2047   static inline bool classof(const Instruction *I) {
2048     return I->getOpcode() == SExt;
2049   }
2050   static inline bool classof(const Value *V) {
2051     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2052   }
2053 };
2054
2055 //===----------------------------------------------------------------------===//
2056 //                                 FPTruncInst Class
2057 //===----------------------------------------------------------------------===//
2058
2059 /// @brief This class represents a truncation of floating point types.
2060 class FPTruncInst : public CastInst {
2061   FPTruncInst(const FPTruncInst &CI)
2062     : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
2063   }
2064 protected:
2065   static void destroyThis(FPTruncInst* v) {
2066     CastInst::destroyThis(v);
2067   }
2068   friend class Value;
2069 public:
2070   /// @brief Constructor with insert-before-instruction semantics
2071   FPTruncInst(
2072     Value *S,                     ///< The value to be truncated
2073     const Type *Ty,               ///< The type to truncate to
2074     const std::string &Name = "", ///< A name for the new instruction
2075     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2076   );
2077
2078   /// @brief Constructor with insert-before-instruction semantics
2079   FPTruncInst(
2080     Value *S,                     ///< The value to be truncated
2081     const Type *Ty,               ///< The type to truncate to
2082     const std::string &Name,      ///< A name for the new instruction
2083     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2084   );
2085
2086   /// @brief Clone an identical FPTruncInst
2087   virtual CastInst *clone() const;
2088
2089   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2090   static inline bool classof(const FPTruncInst *) { return true; }
2091   static inline bool classof(const Instruction *I) {
2092     return I->getOpcode() == FPTrunc;
2093   }
2094   static inline bool classof(const Value *V) {
2095     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2096   }
2097 };
2098
2099 //===----------------------------------------------------------------------===//
2100 //                                 FPExtInst Class
2101 //===----------------------------------------------------------------------===//
2102
2103 /// @brief This class represents an extension of floating point types.
2104 class FPExtInst : public CastInst {
2105   FPExtInst(const FPExtInst &CI)
2106     : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
2107   }
2108 protected:
2109   static void destroyThis(FPExtInst* v) {
2110     CastInst::destroyThis(v);
2111   }
2112   friend class Value;
2113 public:
2114   /// @brief Constructor with insert-before-instruction semantics
2115   FPExtInst(
2116     Value *S,                     ///< The value to be extended
2117     const Type *Ty,               ///< The type to extend to
2118     const std::string &Name = "", ///< A name for the new instruction
2119     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2120   );
2121
2122   /// @brief Constructor with insert-at-end-of-block semantics
2123   FPExtInst(
2124     Value *S,                     ///< The value to be extended
2125     const Type *Ty,               ///< The type to extend to
2126     const std::string &Name,      ///< A name for the new instruction
2127     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2128   );
2129
2130   /// @brief Clone an identical FPExtInst
2131   virtual CastInst *clone() const;
2132
2133   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2134   static inline bool classof(const FPExtInst *) { return true; }
2135   static inline bool classof(const Instruction *I) {
2136     return I->getOpcode() == FPExt;
2137   }
2138   static inline bool classof(const Value *V) {
2139     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2140   }
2141 };
2142
2143 //===----------------------------------------------------------------------===//
2144 //                                 UIToFPInst Class
2145 //===----------------------------------------------------------------------===//
2146
2147 /// @brief This class represents a cast unsigned integer to floating point.
2148 class UIToFPInst : public CastInst {
2149   UIToFPInst(const UIToFPInst &CI)
2150     : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
2151   }
2152 protected:
2153   static void destroyThis(UIToFPInst* v) {
2154     CastInst::destroyThis(v);
2155   }
2156   friend class Value;
2157 public:
2158   /// @brief Constructor with insert-before-instruction semantics
2159   UIToFPInst(
2160     Value *S,                     ///< The value to be converted
2161     const Type *Ty,               ///< The type to convert to
2162     const std::string &Name = "", ///< A name for the new instruction
2163     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2164   );
2165
2166   /// @brief Constructor with insert-at-end-of-block semantics
2167   UIToFPInst(
2168     Value *S,                     ///< The value to be converted
2169     const Type *Ty,               ///< The type to convert to
2170     const std::string &Name,      ///< A name for the new instruction
2171     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2172   );
2173
2174   /// @brief Clone an identical UIToFPInst
2175   virtual CastInst *clone() const;
2176
2177   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2178   static inline bool classof(const UIToFPInst *) { return true; }
2179   static inline bool classof(const Instruction *I) {
2180     return I->getOpcode() == UIToFP;
2181   }
2182   static inline bool classof(const Value *V) {
2183     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2184   }
2185 };
2186
2187 //===----------------------------------------------------------------------===//
2188 //                                 SIToFPInst Class
2189 //===----------------------------------------------------------------------===//
2190
2191 /// @brief This class represents a cast from signed integer to floating point.
2192 class SIToFPInst : public CastInst {
2193   SIToFPInst(const SIToFPInst &CI)
2194     : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
2195   }
2196 protected:
2197   static void destroyThis(SIToFPInst* v) {
2198     CastInst::destroyThis(v);
2199   }
2200   friend class Value;
2201 public:
2202   /// @brief Constructor with insert-before-instruction semantics
2203   SIToFPInst(
2204     Value *S,                     ///< The value to be converted
2205     const Type *Ty,               ///< The type to convert to
2206     const std::string &Name = "", ///< A name for the new instruction
2207     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2208   );
2209
2210   /// @brief Constructor with insert-at-end-of-block semantics
2211   SIToFPInst(
2212     Value *S,                     ///< The value to be converted
2213     const Type *Ty,               ///< The type to convert to
2214     const std::string &Name,      ///< A name for the new instruction
2215     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2216   );
2217
2218   /// @brief Clone an identical SIToFPInst
2219   virtual CastInst *clone() const;
2220
2221   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2222   static inline bool classof(const SIToFPInst *) { return true; }
2223   static inline bool classof(const Instruction *I) {
2224     return I->getOpcode() == SIToFP;
2225   }
2226   static inline bool classof(const Value *V) {
2227     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2228   }
2229 };
2230
2231 //===----------------------------------------------------------------------===//
2232 //                                 FPToUIInst Class
2233 //===----------------------------------------------------------------------===//
2234
2235 /// @brief This class represents a cast from floating point to unsigned integer
2236 class FPToUIInst  : public CastInst {
2237   FPToUIInst(const FPToUIInst &CI)
2238     : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
2239   }
2240 protected:
2241   static void destroyThis(FPToUIInst* v) {
2242     CastInst::destroyThis(v);
2243   }
2244   friend class Value;
2245 public:
2246   /// @brief Constructor with insert-before-instruction semantics
2247   FPToUIInst(
2248     Value *S,                     ///< The value to be converted
2249     const Type *Ty,               ///< The type to convert to
2250     const std::string &Name = "", ///< A name for the new instruction
2251     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2252   );
2253
2254   /// @brief Constructor with insert-at-end-of-block semantics
2255   FPToUIInst(
2256     Value *S,                     ///< The value to be converted
2257     const Type *Ty,               ///< The type to convert to
2258     const std::string &Name,      ///< A name for the new instruction
2259     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
2260   );
2261
2262   /// @brief Clone an identical FPToUIInst
2263   virtual CastInst *clone() const;
2264
2265   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2266   static inline bool classof(const FPToUIInst *) { return true; }
2267   static inline bool classof(const Instruction *I) {
2268     return I->getOpcode() == FPToUI;
2269   }
2270   static inline bool classof(const Value *V) {
2271     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2272   }
2273 };
2274
2275 //===----------------------------------------------------------------------===//
2276 //                                 FPToSIInst Class
2277 //===----------------------------------------------------------------------===//
2278
2279 /// @brief This class represents a cast from floating point to signed integer.
2280 class FPToSIInst  : public CastInst {
2281   FPToSIInst(const FPToSIInst &CI)
2282     : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2283   }
2284 protected:
2285   static void destroyThis(FPToSIInst* v) {
2286     CastInst::destroyThis(v);
2287   }
2288   friend class Value;
2289 public:
2290   /// @brief Constructor with insert-before-instruction semantics
2291   FPToSIInst(
2292     Value *S,                     ///< The value to be converted
2293     const Type *Ty,               ///< The type to convert to
2294     const std::string &Name = "", ///< A name for the new instruction
2295     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2296   );
2297
2298   /// @brief Constructor with insert-at-end-of-block semantics
2299   FPToSIInst(
2300     Value *S,                     ///< The value to be converted
2301     const Type *Ty,               ///< The type to convert to
2302     const std::string &Name,      ///< A name for the new instruction
2303     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2304   );
2305
2306   /// @brief Clone an identical FPToSIInst
2307   virtual CastInst *clone() const;
2308
2309   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2310   static inline bool classof(const FPToSIInst *) { return true; }
2311   static inline bool classof(const Instruction *I) {
2312     return I->getOpcode() == FPToSI;
2313   }
2314   static inline bool classof(const Value *V) {
2315     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2316   }
2317 };
2318
2319 //===----------------------------------------------------------------------===//
2320 //                                 IntToPtrInst Class
2321 //===----------------------------------------------------------------------===//
2322
2323 /// @brief This class represents a cast from an integer to a pointer.
2324 class IntToPtrInst : public CastInst {
2325   IntToPtrInst(const IntToPtrInst &CI)
2326     : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2327   }
2328 protected:
2329   static void destroyThis(IntToPtrInst* v) {
2330     CastInst::destroyThis(v);
2331   }
2332   friend class Value;
2333 public:
2334   /// @brief Constructor with insert-before-instruction semantics
2335   IntToPtrInst(
2336     Value *S,                     ///< The value to be converted
2337     const Type *Ty,               ///< The type to convert to
2338     const std::string &Name = "", ///< A name for the new instruction
2339     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2340   );
2341
2342   /// @brief Constructor with insert-at-end-of-block semantics
2343   IntToPtrInst(
2344     Value *S,                     ///< The value to be converted
2345     const Type *Ty,               ///< The type to convert to
2346     const std::string &Name,      ///< A name for the new instruction
2347     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2348   );
2349
2350   /// @brief Clone an identical IntToPtrInst
2351   virtual CastInst *clone() const;
2352
2353   // Methods for support type inquiry through isa, cast, and dyn_cast:
2354   static inline bool classof(const IntToPtrInst *) { return true; }
2355   static inline bool classof(const Instruction *I) {
2356     return I->getOpcode() == IntToPtr;
2357   }
2358   static inline bool classof(const Value *V) {
2359     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2360   }
2361 };
2362
2363 //===----------------------------------------------------------------------===//
2364 //                                 PtrToIntInst Class
2365 //===----------------------------------------------------------------------===//
2366
2367 /// @brief This class represents a cast from a pointer to an integer
2368 class PtrToIntInst : public CastInst {
2369   PtrToIntInst(const PtrToIntInst &CI)
2370     : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2371   }
2372 protected:
2373   static void destroyThis(PtrToIntInst* v) {
2374     CastInst::destroyThis(v);
2375   }
2376   friend class Value;
2377 public:
2378   /// @brief Constructor with insert-before-instruction semantics
2379   PtrToIntInst(
2380     Value *S,                     ///< The value to be converted
2381     const Type *Ty,               ///< The type to convert to
2382     const std::string &Name = "", ///< A name for the new instruction
2383     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2384   );
2385
2386   /// @brief Constructor with insert-at-end-of-block semantics
2387   PtrToIntInst(
2388     Value *S,                     ///< The value to be converted
2389     const Type *Ty,               ///< The type to convert to
2390     const std::string &Name,      ///< A name for the new instruction
2391     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2392   );
2393
2394   /// @brief Clone an identical PtrToIntInst
2395   virtual CastInst *clone() const;
2396
2397   // Methods for support type inquiry through isa, cast, and dyn_cast:
2398   static inline bool classof(const PtrToIntInst *) { return true; }
2399   static inline bool classof(const Instruction *I) {
2400     return I->getOpcode() == PtrToInt;
2401   }
2402   static inline bool classof(const Value *V) {
2403     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2404   }
2405 };
2406
2407 //===----------------------------------------------------------------------===//
2408 //                             BitCastInst Class
2409 //===----------------------------------------------------------------------===//
2410
2411 /// @brief This class represents a no-op cast from one type to another.
2412 class BitCastInst : public CastInst {
2413   BitCastInst(const BitCastInst &CI)
2414     : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2415   }
2416 protected:
2417   static void destroyThis(BitCastInst* v) {
2418     CastInst::destroyThis(v);
2419   }
2420   friend class Value;
2421 public:
2422   /// @brief Constructor with insert-before-instruction semantics
2423   BitCastInst(
2424     Value *S,                     ///< The value to be casted
2425     const Type *Ty,               ///< The type to casted to
2426     const std::string &Name = "", ///< A name for the new instruction
2427     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2428   );
2429
2430   /// @brief Constructor with insert-at-end-of-block semantics
2431   BitCastInst(
2432     Value *S,                     ///< The value to be casted
2433     const Type *Ty,               ///< The type to casted to
2434     const std::string &Name,      ///< A name for the new instruction
2435     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2436   );
2437
2438   /// @brief Clone an identical BitCastInst
2439   virtual CastInst *clone() const;
2440
2441   // Methods for support type inquiry through isa, cast, and dyn_cast:
2442   static inline bool classof(const BitCastInst *) { return true; }
2443   static inline bool classof(const Instruction *I) {
2444     return I->getOpcode() == BitCast;
2445   }
2446   static inline bool classof(const Value *V) {
2447     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2448   }
2449 };
2450
2451 } // End llvm namespace
2452
2453 #endif