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