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