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