Long double, part 1 of N. Support in IR.
[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   // Methods for support type inquiry through isa, cast, and dyn_cast:
607   static inline bool classof(const ICmpInst *) { return true; }
608   static inline bool classof(const Instruction *I) {
609     return I->getOpcode() == Instruction::ICmp;
610   }
611   static inline bool classof(const Value *V) {
612     return isa<Instruction>(V) && classof(cast<Instruction>(V));
613   }
614 };
615
616 //===----------------------------------------------------------------------===//
617 //                               FCmpInst Class
618 //===----------------------------------------------------------------------===//
619
620 /// This instruction compares its operands according to the predicate given
621 /// to the constructor. It only operates on floating point values or packed     
622 /// vectors of floating point values. The operands must be identical types.
623 /// @brief Represents a floating point comparison operator.
624 class FCmpInst: public CmpInst {
625 public:
626   /// This enumeration lists the possible predicates for the FCmpInst. Values
627   /// in the range 0-31 are reserved for FCmpInst.
628   enum Predicate {
629     // Opcode        U L G E    Intuitive operation
630     FCMP_FALSE = 0, ///<  0 0 0 0    Always false (always folded)
631     FCMP_OEQ   = 1, ///<  0 0 0 1    True if ordered and equal
632     FCMP_OGT   = 2, ///<  0 0 1 0    True if ordered and greater than
633     FCMP_OGE   = 3, ///<  0 0 1 1    True if ordered and greater than or equal
634     FCMP_OLT   = 4, ///<  0 1 0 0    True if ordered and less than
635     FCMP_OLE   = 5, ///<  0 1 0 1    True if ordered and less than or equal
636     FCMP_ONE   = 6, ///<  0 1 1 0    True if ordered and operands are unequal
637     FCMP_ORD   = 7, ///<  0 1 1 1    True if ordered (no nans)
638     FCMP_UNO   = 8, ///<  1 0 0 0    True if unordered: isnan(X) | isnan(Y)
639     FCMP_UEQ   = 9, ///<  1 0 0 1    True if unordered or equal
640     FCMP_UGT   =10, ///<  1 0 1 0    True if unordered or greater than
641     FCMP_UGE   =11, ///<  1 0 1 1    True if unordered, greater than, or equal
642     FCMP_ULT   =12, ///<  1 1 0 0    True if unordered or less than
643     FCMP_ULE   =13, ///<  1 1 0 1    True if unordered, less than, or equal
644     FCMP_UNE   =14, ///<  1 1 1 0    True if unordered or not equal
645     FCMP_TRUE  =15, ///<  1 1 1 1    Always true (always folded)
646     FIRST_FCMP_PREDICATE = FCMP_FALSE,
647     LAST_FCMP_PREDICATE = FCMP_TRUE,
648     BAD_FCMP_PREDICATE = FCMP_TRUE + 1
649   };
650
651   /// @brief Constructor with insert-before-instruction semantics.
652   FCmpInst(
653     Predicate pred,  ///< The predicate to use for the comparison
654     Value *LHS,      ///< The left-hand-side of the expression
655     Value *RHS,      ///< The right-hand-side of the expression
656     const std::string &Name = "",  ///< Name of the instruction
657     Instruction *InsertBefore = 0  ///< Where to insert
658   ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
659   }
660
661   /// @brief Constructor with insert-at-block-end semantics.
662   FCmpInst(
663     Predicate pred, ///< The predicate to use for the comparison
664     Value *LHS,     ///< The left-hand-side of the expression
665     Value *RHS,     ///< The right-hand-side of the expression
666     const std::string &Name,  ///< Name of the instruction
667     BasicBlock *InsertAtEnd   ///< Block to insert into.
668   ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
669   }
670
671   /// @brief Return the predicate for this instruction.
672   Predicate getPredicate() const { return Predicate(SubclassData); }
673
674   /// @brief Set the predicate for this instruction to the specified value.
675   void setPredicate(Predicate P) { SubclassData = P; }
676
677   /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
678   /// @returns the inverse predicate for the instructions current predicate. 
679   /// @brief Return the inverse of the predicate
680   Predicate getInversePredicate() const {
681     return getInversePredicate(getPredicate());
682   }
683
684   /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
685   /// @returns the inverse predicate for \p pred.
686   /// @brief Return the inverse of a given predicate
687   static Predicate getInversePredicate(Predicate pred);
688
689   /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
690   /// @returns the predicate that would be the result of exchanging the two 
691   /// operands of the ICmpInst instruction without changing the result 
692   /// produced.  
693   /// @brief Return the predicate as if the operands were swapped
694   Predicate getSwappedPredicate() const {
695     return getSwappedPredicate(getPredicate());
696   }
697
698   /// This is a static version that you can use without an instruction 
699   /// available.
700   /// @brief Return the predicate as if the operands were swapped.
701   static Predicate getSwappedPredicate(Predicate Opcode);
702
703   /// This also tests for commutativity. If isEquality() returns true then
704   /// the predicate is also commutative. Only the equality predicates are
705   /// commutative.
706   /// @returns true if the predicate of this instruction is EQ or NE.
707   /// @brief Determine if this is an equality predicate.
708   bool isEquality() const {
709     return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
710            SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
711   }
712   bool isCommutative() const { return isEquality(); }
713
714   /// @returns true if the predicate is relational (not EQ or NE). 
715   /// @brief Determine if this a relational predicate.
716   bool isRelational() const { return !isEquality(); }
717
718   /// Exchange the two operands to this instruction in such a way that it does
719   /// not modify the semantics of the instruction. The predicate value may be
720   /// changed to retain the same result if the predicate is order dependent
721   /// (e.g. ult). 
722   /// @brief Swap operands and adjust predicate.
723   void swapOperands() {
724     SubclassData = getSwappedPredicate();
725     std::swap(Ops[0], Ops[1]);
726   }
727
728   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
729   static inline bool classof(const FCmpInst *) { return true; }
730   static inline bool classof(const Instruction *I) {
731     return I->getOpcode() == Instruction::FCmp;
732   }
733   static inline bool classof(const Value *V) {
734     return isa<Instruction>(V) && classof(cast<Instruction>(V));
735   }
736 };
737
738 //===----------------------------------------------------------------------===//
739 //                                 CallInst Class
740 //===----------------------------------------------------------------------===//
741 /// CallInst - This class represents a function call, abstracting a target
742 /// machine's calling convention.  This class uses low bit of the SubClassData
743 /// field to indicate whether or not this is a tail call.  The rest of the bits
744 /// hold the calling convention of the call.
745 ///
746
747 class CallInst : public Instruction {
748   ParamAttrsList *ParamAttrs; ///< parameter attributes for call
749   CallInst(const CallInst &CI);
750   void init(Value *Func, Value* const *Params, unsigned NumParams);
751   void init(Value *Func, Value *Actual1, Value *Actual2);
752   void init(Value *Func, Value *Actual);
753   void init(Value *Func);
754
755   template<typename InputIterator>
756   void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
757             const std::string &Name,
758             // This argument ensures that we have an iterator we can
759             // do arithmetic on in constant time
760             std::random_access_iterator_tag) {
761     typename std::iterator_traits<InputIterator>::difference_type NumArgs = 
762       std::distance(ArgBegin, ArgEnd);
763     
764     if (NumArgs > 0) {
765       // This requires that the iterator points to contiguous memory.
766       init(Func, &*ArgBegin, NumArgs);
767     }
768     else {
769       init(Func, 0, NumArgs);
770     }
771     
772     setName(Name);
773   }
774
775 public:
776   /// Construct a CallInst given a range of arguments.  InputIterator
777   /// must be a random-access iterator pointing to contiguous storage
778   /// (e.g. a std::vector<>::iterator).  Checks are made for
779   /// random-accessness but not for contiguous storage as that would
780   /// incur runtime overhead.
781   /// @brief Construct a CallInst from a range of arguments
782   template<typename InputIterator>
783   CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
784            const std::string &Name = "", Instruction *InsertBefore = 0)
785       : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
786                                        ->getElementType())->getReturnType(),
787                     Instruction::Call, 0, 0, InsertBefore) {
788     init(Func, ArgBegin, ArgEnd, Name, 
789          typename std::iterator_traits<InputIterator>::iterator_category());
790   }
791
792   /// Construct a CallInst given a range of arguments.  InputIterator
793   /// must be a random-access iterator pointing to contiguous storage
794   /// (e.g. a std::vector<>::iterator).  Checks are made for
795   /// random-accessness but not for contiguous storage as that would
796   /// incur runtime overhead.
797   /// @brief Construct a CallInst from a range of arguments
798   template<typename InputIterator>
799   CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
800            const std::string &Name, BasicBlock *InsertAtEnd)
801       : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
802                                        ->getElementType())->getReturnType(),
803                     Instruction::Call, 0, 0, InsertAtEnd) {
804     init(Func, ArgBegin, ArgEnd, Name,
805          typename std::iterator_traits<InputIterator>::iterator_category());
806   }
807
808 #if 0
809   // Leave these here for llvm-gcc
810   CallInst(Value *F, Value* const *Args, unsigned NumArgs,
811            const std::string &Name = "", Instruction *InsertBefore = 0);
812   CallInst(Value *F, Value *const *Args, unsigned NumArgs,
813            const std::string &Name, BasicBlock *InsertAtEnd);
814
815   // Alternate CallInst ctors w/ two actuals, w/ one actual and no
816   // actuals, respectively.
817   CallInst(Value *F, Value *Actual1, Value *Actual2,
818            const std::string& Name = "", Instruction *InsertBefore = 0);
819   CallInst(Value *F, Value *Actual1, Value *Actual2,
820            const std::string& Name, BasicBlock *InsertAtEnd);
821 #endif
822   CallInst(Value *F, Value *Actual, const std::string& Name = "",
823            Instruction *InsertBefore = 0);
824   CallInst(Value *F, Value *Actual, const std::string& Name,
825            BasicBlock *InsertAtEnd);
826   explicit CallInst(Value *F, const std::string &Name = "",
827                     Instruction *InsertBefore = 0);
828   CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
829   ~CallInst();
830
831   virtual CallInst *clone() const;
832   
833   bool isTailCall() const           { return SubclassData & 1; }
834   void setTailCall(bool isTailCall = true) {
835     SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
836   }
837
838   /// getCallingConv/setCallingConv - Get or set the calling convention of this
839   /// function call.
840   unsigned getCallingConv() const { return SubclassData >> 1; }
841   void setCallingConv(unsigned CC) {
842     SubclassData = (SubclassData & 1) | (CC << 1);
843   }
844
845   /// Obtains a pointer to the ParamAttrsList object which holds the
846   /// parameter attributes information, if any.
847   /// @returns 0 if no attributes have been set.
848   /// @brief Get the parameter attributes.
849   ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
850
851   /// Sets the parameter attributes for this CallInst. To construct a 
852   /// ParamAttrsList, see ParameterAttributes.h
853   /// @brief Set the parameter attributes.
854   void setParamAttrs(ParamAttrsList *attrs);
855
856   /// getCalledFunction - Return the function being called by this instruction
857   /// if it is a direct call.  If it is a call through a function pointer,
858   /// return null.
859   Function *getCalledFunction() const {
860     return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
861   }
862
863   /// getCalledValue - Get a pointer to the function that is invoked by this 
864   /// instruction
865   inline const Value *getCalledValue() const { return getOperand(0); }
866   inline       Value *getCalledValue()       { return getOperand(0); }
867
868   // Methods for support type inquiry through isa, cast, and dyn_cast:
869   static inline bool classof(const CallInst *) { return true; }
870   static inline bool classof(const Instruction *I) {
871     return I->getOpcode() == Instruction::Call;
872   }
873   static inline bool classof(const Value *V) {
874     return isa<Instruction>(V) && classof(cast<Instruction>(V));
875   }
876 };
877
878 //===----------------------------------------------------------------------===//
879 //                               SelectInst Class
880 //===----------------------------------------------------------------------===//
881
882 /// SelectInst - This class represents the LLVM 'select' instruction.
883 ///
884 class SelectInst : public Instruction {
885   Use Ops[3];
886
887   void init(Value *C, Value *S1, Value *S2) {
888     Ops[0].init(C, this);
889     Ops[1].init(S1, this);
890     Ops[2].init(S2, this);
891   }
892
893   SelectInst(const SelectInst &SI)
894     : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
895     init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
896   }
897 public:
898   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
899              Instruction *InsertBefore = 0)
900     : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
901     init(C, S1, S2);
902     setName(Name);
903   }
904   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
905              BasicBlock *InsertAtEnd)
906     : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
907     init(C, S1, S2);
908     setName(Name);
909   }
910
911   Value *getCondition() const { return Ops[0]; }
912   Value *getTrueValue() const { return Ops[1]; }
913   Value *getFalseValue() const { return Ops[2]; }
914
915   /// Transparently provide more efficient getOperand methods.
916   Value *getOperand(unsigned i) const {
917     assert(i < 3 && "getOperand() out of range!");
918     return Ops[i];
919   }
920   void setOperand(unsigned i, Value *Val) {
921     assert(i < 3 && "setOperand() out of range!");
922     Ops[i] = Val;
923   }
924   unsigned getNumOperands() const { return 3; }
925
926   OtherOps getOpcode() const {
927     return static_cast<OtherOps>(Instruction::getOpcode());
928   }
929
930   virtual SelectInst *clone() const;
931
932   // Methods for support type inquiry through isa, cast, and dyn_cast:
933   static inline bool classof(const SelectInst *) { return true; }
934   static inline bool classof(const Instruction *I) {
935     return I->getOpcode() == Instruction::Select;
936   }
937   static inline bool classof(const Value *V) {
938     return isa<Instruction>(V) && classof(cast<Instruction>(V));
939   }
940 };
941
942 //===----------------------------------------------------------------------===//
943 //                                VAArgInst Class
944 //===----------------------------------------------------------------------===//
945
946 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
947 /// an argument of the specified type given a va_list and increments that list
948 ///
949 class VAArgInst : public UnaryInstruction {
950   VAArgInst(const VAArgInst &VAA)
951     : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
952 public:
953   VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
954              Instruction *InsertBefore = 0)
955     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
956     setName(Name);
957   }
958   VAArgInst(Value *List, const Type *Ty, const std::string &Name,
959             BasicBlock *InsertAtEnd)
960     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
961     setName(Name);
962   }
963
964   virtual VAArgInst *clone() const;
965
966   // Methods for support type inquiry through isa, cast, and dyn_cast:
967   static inline bool classof(const VAArgInst *) { return true; }
968   static inline bool classof(const Instruction *I) {
969     return I->getOpcode() == VAArg;
970   }
971   static inline bool classof(const Value *V) {
972     return isa<Instruction>(V) && classof(cast<Instruction>(V));
973   }
974 };
975
976 //===----------------------------------------------------------------------===//
977 //                                ExtractElementInst Class
978 //===----------------------------------------------------------------------===//
979
980 /// ExtractElementInst - This instruction extracts a single (scalar)
981 /// element from a VectorType value
982 ///
983 class ExtractElementInst : public Instruction {
984   Use Ops[2];
985   ExtractElementInst(const ExtractElementInst &EE) :
986     Instruction(EE.getType(), ExtractElement, Ops, 2) {
987     Ops[0].init(EE.Ops[0], this);
988     Ops[1].init(EE.Ops[1], this);
989   }
990
991 public:
992   ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
993                      Instruction *InsertBefore = 0);
994   ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
995                      Instruction *InsertBefore = 0);
996   ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
997                      BasicBlock *InsertAtEnd);
998   ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
999                      BasicBlock *InsertAtEnd);
1000
1001   /// isValidOperands - Return true if an extractelement instruction can be
1002   /// formed with the specified operands.
1003   static bool isValidOperands(const Value *Vec, const Value *Idx);
1004
1005   virtual ExtractElementInst *clone() const;
1006
1007   /// Transparently provide more efficient getOperand methods.
1008   Value *getOperand(unsigned i) const {
1009     assert(i < 2 && "getOperand() out of range!");
1010     return Ops[i];
1011   }
1012   void setOperand(unsigned i, Value *Val) {
1013     assert(i < 2 && "setOperand() out of range!");
1014     Ops[i] = Val;
1015   }
1016   unsigned getNumOperands() const { return 2; }
1017
1018   // Methods for support type inquiry through isa, cast, and dyn_cast:
1019   static inline bool classof(const ExtractElementInst *) { return true; }
1020   static inline bool classof(const Instruction *I) {
1021     return I->getOpcode() == Instruction::ExtractElement;
1022   }
1023   static inline bool classof(const Value *V) {
1024     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1025   }
1026 };
1027
1028 //===----------------------------------------------------------------------===//
1029 //                                InsertElementInst Class
1030 //===----------------------------------------------------------------------===//
1031
1032 /// InsertElementInst - This instruction inserts a single (scalar)
1033 /// element into a VectorType value
1034 ///
1035 class InsertElementInst : public Instruction {
1036   Use Ops[3];
1037   InsertElementInst(const InsertElementInst &IE);
1038 public:
1039   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1040                     const std::string &Name = "",Instruction *InsertBefore = 0);
1041   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1042                     const std::string &Name = "",Instruction *InsertBefore = 0);
1043   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1044                     const std::string &Name, BasicBlock *InsertAtEnd);
1045   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1046                     const std::string &Name, BasicBlock *InsertAtEnd);
1047
1048   /// isValidOperands - Return true if an insertelement instruction can be
1049   /// formed with the specified operands.
1050   static bool isValidOperands(const Value *Vec, const Value *NewElt,
1051                               const Value *Idx);
1052
1053   virtual InsertElementInst *clone() const;
1054
1055   /// getType - Overload to return most specific vector type.
1056   ///
1057   inline const VectorType *getType() const {
1058     return reinterpret_cast<const VectorType*>(Instruction::getType());
1059   }
1060
1061   /// Transparently provide more efficient getOperand methods.
1062   Value *getOperand(unsigned i) const {
1063     assert(i < 3 && "getOperand() out of range!");
1064     return Ops[i];
1065   }
1066   void setOperand(unsigned i, Value *Val) {
1067     assert(i < 3 && "setOperand() out of range!");
1068     Ops[i] = Val;
1069   }
1070   unsigned getNumOperands() const { return 3; }
1071
1072   // Methods for support type inquiry through isa, cast, and dyn_cast:
1073   static inline bool classof(const InsertElementInst *) { return true; }
1074   static inline bool classof(const Instruction *I) {
1075     return I->getOpcode() == Instruction::InsertElement;
1076   }
1077   static inline bool classof(const Value *V) {
1078     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1079   }
1080 };
1081
1082 //===----------------------------------------------------------------------===//
1083 //                           ShuffleVectorInst Class
1084 //===----------------------------------------------------------------------===//
1085
1086 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1087 /// input vectors.
1088 ///
1089 class ShuffleVectorInst : public Instruction {
1090   Use Ops[3];
1091   ShuffleVectorInst(const ShuffleVectorInst &IE);
1092 public:
1093   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1094                     const std::string &Name = "", Instruction *InsertBefor = 0);
1095   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1096                     const std::string &Name, BasicBlock *InsertAtEnd);
1097
1098   /// isValidOperands - Return true if a shufflevector instruction can be
1099   /// formed with the specified operands.
1100   static bool isValidOperands(const Value *V1, const Value *V2,
1101                               const Value *Mask);
1102
1103   virtual ShuffleVectorInst *clone() const;
1104
1105   /// getType - Overload to return most specific vector type.
1106   ///
1107   inline const VectorType *getType() const {
1108     return reinterpret_cast<const VectorType*>(Instruction::getType());
1109   }
1110
1111   /// Transparently provide more efficient getOperand methods.
1112   Value *getOperand(unsigned i) const {
1113     assert(i < 3 && "getOperand() out of range!");
1114     return Ops[i];
1115   }
1116   void setOperand(unsigned i, Value *Val) {
1117     assert(i < 3 && "setOperand() out of range!");
1118     Ops[i] = Val;
1119   }
1120   unsigned getNumOperands() const { return 3; }
1121
1122   // Methods for support type inquiry through isa, cast, and dyn_cast:
1123   static inline bool classof(const ShuffleVectorInst *) { return true; }
1124   static inline bool classof(const Instruction *I) {
1125     return I->getOpcode() == Instruction::ShuffleVector;
1126   }
1127   static inline bool classof(const Value *V) {
1128     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1129   }
1130 };
1131
1132
1133 //===----------------------------------------------------------------------===//
1134 //                               PHINode Class
1135 //===----------------------------------------------------------------------===//
1136
1137 // PHINode - The PHINode class is used to represent the magical mystical PHI
1138 // node, that can not exist in nature, but can be synthesized in a computer
1139 // scientist's overactive imagination.
1140 //
1141 class PHINode : public Instruction {
1142   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1143   /// the number actually in use.
1144   unsigned ReservedSpace;
1145   PHINode(const PHINode &PN);
1146 public:
1147   explicit PHINode(const Type *Ty, const std::string &Name = "",
1148                    Instruction *InsertBefore = 0)
1149     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1150       ReservedSpace(0) {
1151     setName(Name);
1152   }
1153
1154   PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1155     : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1156       ReservedSpace(0) {
1157     setName(Name);
1158   }
1159
1160   ~PHINode();
1161
1162   /// reserveOperandSpace - This method can be used to avoid repeated
1163   /// reallocation of PHI operand lists by reserving space for the correct
1164   /// number of operands before adding them.  Unlike normal vector reserves,
1165   /// this method can also be used to trim the operand space.
1166   void reserveOperandSpace(unsigned NumValues) {
1167     resizeOperands(NumValues*2);
1168   }
1169
1170   virtual PHINode *clone() const;
1171
1172   /// getNumIncomingValues - Return the number of incoming edges
1173   ///
1174   unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1175
1176   /// getIncomingValue - Return incoming value number x
1177   ///
1178   Value *getIncomingValue(unsigned i) const {
1179     assert(i*2 < getNumOperands() && "Invalid value number!");
1180     return getOperand(i*2);
1181   }
1182   void setIncomingValue(unsigned i, Value *V) {
1183     assert(i*2 < getNumOperands() && "Invalid value number!");
1184     setOperand(i*2, V);
1185   }
1186   unsigned getOperandNumForIncomingValue(unsigned i) {
1187     return i*2;
1188   }
1189
1190   /// getIncomingBlock - Return incoming basic block number x
1191   ///
1192   BasicBlock *getIncomingBlock(unsigned i) const {
1193     return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1194   }
1195   void setIncomingBlock(unsigned i, BasicBlock *BB) {
1196     setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1197   }
1198   unsigned getOperandNumForIncomingBlock(unsigned i) {
1199     return i*2+1;
1200   }
1201
1202   /// addIncoming - Add an incoming value to the end of the PHI list
1203   ///
1204   void addIncoming(Value *V, BasicBlock *BB) {
1205     assert(getType() == V->getType() &&
1206            "All operands to PHI node must be the same type as the PHI node!");
1207     unsigned OpNo = NumOperands;
1208     if (OpNo+2 > ReservedSpace)
1209       resizeOperands(0);  // Get more space!
1210     // Initialize some new operands.
1211     NumOperands = OpNo+2;
1212     OperandList[OpNo].init(V, this);
1213     OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1214   }
1215
1216   /// removeIncomingValue - Remove an incoming value.  This is useful if a
1217   /// predecessor basic block is deleted.  The value removed is returned.
1218   ///
1219   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1220   /// is true), the PHI node is destroyed and any uses of it are replaced with
1221   /// dummy values.  The only time there should be zero incoming values to a PHI
1222   /// node is when the block is dead, so this strategy is sound.
1223   ///
1224   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1225
1226   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1227     int Idx = getBasicBlockIndex(BB);
1228     assert(Idx >= 0 && "Invalid basic block argument to remove!");
1229     return removeIncomingValue(Idx, DeletePHIIfEmpty);
1230   }
1231
1232   /// getBasicBlockIndex - Return the first index of the specified basic
1233   /// block in the value list for this PHI.  Returns -1 if no instance.
1234   ///
1235   int getBasicBlockIndex(const BasicBlock *BB) const {
1236     Use *OL = OperandList;
1237     for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1238       if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1239     return -1;
1240   }
1241
1242   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1243     return getIncomingValue(getBasicBlockIndex(BB));
1244   }
1245
1246   /// hasConstantValue - If the specified PHI node always merges together the
1247   /// same value, return the value, otherwise return null.
1248   ///
1249   Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1250
1251   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1252   static inline bool classof(const PHINode *) { return true; }
1253   static inline bool classof(const Instruction *I) {
1254     return I->getOpcode() == Instruction::PHI;
1255   }
1256   static inline bool classof(const Value *V) {
1257     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1258   }
1259  private:
1260   void resizeOperands(unsigned NumOperands);
1261 };
1262
1263 //===----------------------------------------------------------------------===//
1264 //                               ReturnInst Class
1265 //===----------------------------------------------------------------------===//
1266
1267 //===---------------------------------------------------------------------------
1268 /// ReturnInst - Return a value (possibly void), from a function.  Execution
1269 /// does not continue in this function any longer.
1270 ///
1271 class ReturnInst : public TerminatorInst {
1272   Use RetVal;  // Return Value: null if 'void'.
1273   ReturnInst(const ReturnInst &RI);
1274   void init(Value *RetVal);
1275
1276 public:
1277   // ReturnInst constructors:
1278   // ReturnInst()                  - 'ret void' instruction
1279   // ReturnInst(    null)          - 'ret void' instruction
1280   // ReturnInst(Value* X)          - 'ret X'    instruction
1281   // ReturnInst(    null, Inst *)  - 'ret void' instruction, insert before I
1282   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
1283   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of BB
1284   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of BB
1285   //
1286   // NOTE: If the Value* passed is of type void then the constructor behaves as
1287   // if it was passed NULL.
1288   explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1289   ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1290   explicit ReturnInst(BasicBlock *InsertAtEnd);
1291
1292   virtual ReturnInst *clone() const;
1293
1294   // Transparently provide more efficient getOperand methods.
1295   Value *getOperand(unsigned i) const {
1296     assert(i < getNumOperands() && "getOperand() out of range!");
1297     return RetVal;
1298   }
1299   void setOperand(unsigned i, Value *Val) {
1300     assert(i < getNumOperands() && "setOperand() out of range!");
1301     RetVal = Val;
1302   }
1303
1304   Value *getReturnValue() const { return RetVal; }
1305
1306   unsigned getNumSuccessors() const { return 0; }
1307
1308   // Methods for support type inquiry through isa, cast, and dyn_cast:
1309   static inline bool classof(const ReturnInst *) { return true; }
1310   static inline bool classof(const Instruction *I) {
1311     return (I->getOpcode() == Instruction::Ret);
1312   }
1313   static inline bool classof(const Value *V) {
1314     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1315   }
1316  private:
1317   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1318   virtual unsigned getNumSuccessorsV() const;
1319   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1320 };
1321
1322 //===----------------------------------------------------------------------===//
1323 //                               BranchInst Class
1324 //===----------------------------------------------------------------------===//
1325
1326 //===---------------------------------------------------------------------------
1327 /// BranchInst - Conditional or Unconditional Branch instruction.
1328 ///
1329 class BranchInst : public TerminatorInst {
1330   /// Ops list - Branches are strange.  The operands are ordered:
1331   ///  TrueDest, FalseDest, Cond.  This makes some accessors faster because
1332   /// they don't have to check for cond/uncond branchness.
1333   Use Ops[3];
1334   BranchInst(const BranchInst &BI);
1335   void AssertOK();
1336 public:
1337   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1338   // BranchInst(BB *B)                           - 'br B'
1339   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
1340   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
1341   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1342   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
1343   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
1344   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1345   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1346              Instruction *InsertBefore = 0);
1347   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1348   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1349              BasicBlock *InsertAtEnd);
1350
1351   /// Transparently provide more efficient getOperand methods.
1352   Value *getOperand(unsigned i) const {
1353     assert(i < getNumOperands() && "getOperand() out of range!");
1354     return Ops[i];
1355   }
1356   void setOperand(unsigned i, Value *Val) {
1357     assert(i < getNumOperands() && "setOperand() out of range!");
1358     Ops[i] = Val;
1359   }
1360
1361   virtual BranchInst *clone() const;
1362
1363   inline bool isUnconditional() const { return getNumOperands() == 1; }
1364   inline bool isConditional()   const { return getNumOperands() == 3; }
1365
1366   inline Value *getCondition() const {
1367     assert(isConditional() && "Cannot get condition of an uncond branch!");
1368     return getOperand(2);
1369   }
1370
1371   void setCondition(Value *V) {
1372     assert(isConditional() && "Cannot set condition of unconditional branch!");
1373     setOperand(2, V);
1374   }
1375
1376   // setUnconditionalDest - Change the current branch to an unconditional branch
1377   // targeting the specified block.
1378   // FIXME: Eliminate this ugly method.
1379   void setUnconditionalDest(BasicBlock *Dest) {
1380     if (isConditional()) {  // Convert this to an uncond branch.
1381       NumOperands = 1;
1382       Ops[1].set(0);
1383       Ops[2].set(0);
1384     }
1385     setOperand(0, reinterpret_cast<Value*>(Dest));
1386   }
1387
1388   unsigned getNumSuccessors() const { return 1+isConditional(); }
1389
1390   BasicBlock *getSuccessor(unsigned i) const {
1391     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1392     return cast<BasicBlock>(getOperand(i));
1393   }
1394
1395   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1396     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1397     setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1398   }
1399
1400   // Methods for support type inquiry through isa, cast, and dyn_cast:
1401   static inline bool classof(const BranchInst *) { return true; }
1402   static inline bool classof(const Instruction *I) {
1403     return (I->getOpcode() == Instruction::Br);
1404   }
1405   static inline bool classof(const Value *V) {
1406     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1407   }
1408 private:
1409   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1410   virtual unsigned getNumSuccessorsV() const;
1411   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1412 };
1413
1414 //===----------------------------------------------------------------------===//
1415 //                               SwitchInst Class
1416 //===----------------------------------------------------------------------===//
1417
1418 //===---------------------------------------------------------------------------
1419 /// SwitchInst - Multiway switch
1420 ///
1421 class SwitchInst : public TerminatorInst {
1422   unsigned ReservedSpace;
1423   // Operand[0]    = Value to switch on
1424   // Operand[1]    = Default basic block destination
1425   // Operand[2n  ] = Value to match
1426   // Operand[2n+1] = BasicBlock to go to on match
1427   SwitchInst(const SwitchInst &RI);
1428   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1429   void resizeOperands(unsigned No);
1430 public:
1431   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1432   /// switch on and a default destination.  The number of additional cases can
1433   /// be specified here to make memory allocation more efficient.  This
1434   /// constructor can also autoinsert before another instruction.
1435   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1436              Instruction *InsertBefore = 0);
1437   
1438   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1439   /// switch on and a default destination.  The number of additional cases can
1440   /// be specified here to make memory allocation more efficient.  This
1441   /// constructor also autoinserts at the end of the specified BasicBlock.
1442   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1443              BasicBlock *InsertAtEnd);
1444   ~SwitchInst();
1445
1446
1447   // Accessor Methods for Switch stmt
1448   inline Value *getCondition() const { return getOperand(0); }
1449   void setCondition(Value *V) { setOperand(0, V); }
1450
1451   inline BasicBlock *getDefaultDest() const {
1452     return cast<BasicBlock>(getOperand(1));
1453   }
1454
1455   /// getNumCases - return the number of 'cases' in this switch instruction.
1456   /// Note that case #0 is always the default case.
1457   unsigned getNumCases() const {
1458     return getNumOperands()/2;
1459   }
1460
1461   /// getCaseValue - Return the specified case value.  Note that case #0, the
1462   /// default destination, does not have a case value.
1463   ConstantInt *getCaseValue(unsigned i) {
1464     assert(i && i < getNumCases() && "Illegal case value to get!");
1465     return getSuccessorValue(i);
1466   }
1467
1468   /// getCaseValue - Return the specified case value.  Note that case #0, the
1469   /// default destination, does not have a case value.
1470   const ConstantInt *getCaseValue(unsigned i) const {
1471     assert(i && i < getNumCases() && "Illegal case value to get!");
1472     return getSuccessorValue(i);
1473   }
1474
1475   /// findCaseValue - Search all of the case values for the specified constant.
1476   /// If it is explicitly handled, return the case number of it, otherwise
1477   /// return 0 to indicate that it is handled by the default handler.
1478   unsigned findCaseValue(const ConstantInt *C) const {
1479     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1480       if (getCaseValue(i) == C)
1481         return i;
1482     return 0;
1483   }
1484
1485   /// findCaseDest - Finds the unique case value for a given successor. Returns
1486   /// null if the successor is not found, not unique, or is the default case.
1487   ConstantInt *findCaseDest(BasicBlock *BB) {
1488     if (BB == getDefaultDest()) return NULL;
1489
1490     ConstantInt *CI = NULL;
1491     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1492       if (getSuccessor(i) == BB) {
1493         if (CI) return NULL;   // Multiple cases lead to BB.
1494         else CI = getCaseValue(i);
1495       }
1496     }
1497     return CI;
1498   }
1499
1500   /// addCase - Add an entry to the switch instruction...
1501   ///
1502   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1503
1504   /// removeCase - This method removes the specified successor from the switch
1505   /// instruction.  Note that this cannot be used to remove the default
1506   /// destination (successor #0).
1507   ///
1508   void removeCase(unsigned idx);
1509
1510   virtual SwitchInst *clone() const;
1511
1512   unsigned getNumSuccessors() const { return getNumOperands()/2; }
1513   BasicBlock *getSuccessor(unsigned idx) const {
1514     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1515     return cast<BasicBlock>(getOperand(idx*2+1));
1516   }
1517   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1518     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1519     setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1520   }
1521
1522   // getSuccessorValue - Return the value associated with the specified
1523   // successor.
1524   inline ConstantInt *getSuccessorValue(unsigned idx) const {
1525     assert(idx < getNumSuccessors() && "Successor # out of range!");
1526     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1527   }
1528
1529   // Methods for support type inquiry through isa, cast, and dyn_cast:
1530   static inline bool classof(const SwitchInst *) { return true; }
1531   static inline bool classof(const Instruction *I) {
1532     return I->getOpcode() == Instruction::Switch;
1533   }
1534   static inline bool classof(const Value *V) {
1535     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1536   }
1537 private:
1538   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1539   virtual unsigned getNumSuccessorsV() const;
1540   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1541 };
1542
1543 //===----------------------------------------------------------------------===//
1544 //                               InvokeInst Class
1545 //===----------------------------------------------------------------------===//
1546
1547 //===---------------------------------------------------------------------------
1548
1549 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
1550 /// calling convention of the call.
1551 ///
1552 class InvokeInst : public TerminatorInst {
1553   ParamAttrsList *ParamAttrs;
1554   InvokeInst(const InvokeInst &BI);
1555   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1556             Value* const *Args, unsigned NumArgs);
1557 public:
1558   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1559              Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1560              Instruction *InsertBefore = 0);
1561   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1562              Value* const* Args, unsigned NumArgs, const std::string &Name,
1563              BasicBlock *InsertAtEnd);
1564   ~InvokeInst();
1565
1566   virtual InvokeInst *clone() const;
1567
1568   /// getCallingConv/setCallingConv - Get or set the calling convention of this
1569   /// function call.
1570   unsigned getCallingConv() const { return SubclassData; }
1571   void setCallingConv(unsigned CC) {
1572     SubclassData = CC;
1573   }
1574
1575   /// Obtains a pointer to the ParamAttrsList object which holds the
1576   /// parameter attributes information, if any.
1577   /// @returns 0 if no attributes have been set.
1578   /// @brief Get the parameter attributes.
1579   ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
1580
1581   /// Sets the parameter attributes for this InvokeInst. To construct a 
1582   /// ParamAttrsList, see ParameterAttributes.h
1583   /// @brief Set the parameter attributes.
1584   void setParamAttrs(ParamAttrsList *attrs);
1585
1586   /// getCalledFunction - Return the function called, or null if this is an
1587   /// indirect function invocation.
1588   ///
1589   Function *getCalledFunction() const {
1590     return dyn_cast<Function>(getOperand(0));
1591   }
1592
1593   // getCalledValue - Get a pointer to a function that is invoked by this inst.
1594   inline Value *getCalledValue() const { return getOperand(0); }
1595
1596   // get*Dest - Return the destination basic blocks...
1597   BasicBlock *getNormalDest() const {
1598     return cast<BasicBlock>(getOperand(1));
1599   }
1600   BasicBlock *getUnwindDest() const {
1601     return cast<BasicBlock>(getOperand(2));
1602   }
1603   void setNormalDest(BasicBlock *B) {
1604     setOperand(1, reinterpret_cast<Value*>(B));
1605   }
1606
1607   void setUnwindDest(BasicBlock *B) {
1608     setOperand(2, reinterpret_cast<Value*>(B));
1609   }
1610
1611   inline BasicBlock *getSuccessor(unsigned i) const {
1612     assert(i < 2 && "Successor # out of range for invoke!");
1613     return i == 0 ? getNormalDest() : getUnwindDest();
1614   }
1615
1616   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1617     assert(idx < 2 && "Successor # out of range for invoke!");
1618     setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1619   }
1620
1621   unsigned getNumSuccessors() const { return 2; }
1622
1623   // Methods for support type inquiry through isa, cast, and dyn_cast:
1624   static inline bool classof(const InvokeInst *) { return true; }
1625   static inline bool classof(const Instruction *I) {
1626     return (I->getOpcode() == Instruction::Invoke);
1627   }
1628   static inline bool classof(const Value *V) {
1629     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1630   }
1631 private:
1632   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1633   virtual unsigned getNumSuccessorsV() const;
1634   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1635 };
1636
1637
1638 //===----------------------------------------------------------------------===//
1639 //                              UnwindInst Class
1640 //===----------------------------------------------------------------------===//
1641
1642 //===---------------------------------------------------------------------------
1643 /// UnwindInst - Immediately exit the current function, unwinding the stack
1644 /// until an invoke instruction is found.
1645 ///
1646 class UnwindInst : public TerminatorInst {
1647 public:
1648   explicit UnwindInst(Instruction *InsertBefore = 0);
1649   explicit UnwindInst(BasicBlock *InsertAtEnd);
1650
1651   virtual UnwindInst *clone() const;
1652
1653   unsigned getNumSuccessors() const { return 0; }
1654
1655   // Methods for support type inquiry through isa, cast, and dyn_cast:
1656   static inline bool classof(const UnwindInst *) { return true; }
1657   static inline bool classof(const Instruction *I) {
1658     return I->getOpcode() == Instruction::Unwind;
1659   }
1660   static inline bool classof(const Value *V) {
1661     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1662   }
1663 private:
1664   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1665   virtual unsigned getNumSuccessorsV() const;
1666   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1667 };
1668
1669 //===----------------------------------------------------------------------===//
1670 //                           UnreachableInst Class
1671 //===----------------------------------------------------------------------===//
1672
1673 //===---------------------------------------------------------------------------
1674 /// UnreachableInst - This function has undefined behavior.  In particular, the
1675 /// presence of this instruction indicates some higher level knowledge that the
1676 /// end of the block cannot be reached.
1677 ///
1678 class UnreachableInst : public TerminatorInst {
1679 public:
1680   explicit UnreachableInst(Instruction *InsertBefore = 0);
1681   explicit UnreachableInst(BasicBlock *InsertAtEnd);
1682
1683   virtual UnreachableInst *clone() const;
1684
1685   unsigned getNumSuccessors() const { return 0; }
1686
1687   // Methods for support type inquiry through isa, cast, and dyn_cast:
1688   static inline bool classof(const UnreachableInst *) { return true; }
1689   static inline bool classof(const Instruction *I) {
1690     return I->getOpcode() == Instruction::Unreachable;
1691   }
1692   static inline bool classof(const Value *V) {
1693     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1694   }
1695 private:
1696   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1697   virtual unsigned getNumSuccessorsV() const;
1698   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1699 };
1700
1701 //===----------------------------------------------------------------------===//
1702 //                                 TruncInst Class
1703 //===----------------------------------------------------------------------===//
1704
1705 /// @brief This class represents a truncation of integer types.
1706 class TruncInst : public CastInst {
1707   /// Private copy constructor
1708   TruncInst(const TruncInst &CI)
1709     : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1710   }
1711 public:
1712   /// @brief Constructor with insert-before-instruction semantics
1713   TruncInst(
1714     Value *S,                     ///< The value to be truncated
1715     const Type *Ty,               ///< The (smaller) type to truncate to
1716     const std::string &Name = "", ///< A name for the new instruction
1717     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1718   );
1719
1720   /// @brief Constructor with insert-at-end-of-block semantics
1721   TruncInst(
1722     Value *S,                     ///< The value to be truncated
1723     const Type *Ty,               ///< The (smaller) type to truncate to
1724     const std::string &Name,      ///< A name for the new instruction
1725     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1726   );
1727
1728   /// @brief Clone an identical TruncInst
1729   virtual CastInst *clone() const;
1730
1731   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1732   static inline bool classof(const TruncInst *) { return true; }
1733   static inline bool classof(const Instruction *I) {
1734     return I->getOpcode() == Trunc;
1735   }
1736   static inline bool classof(const Value *V) {
1737     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1738   }
1739 };
1740
1741 //===----------------------------------------------------------------------===//
1742 //                                 ZExtInst Class
1743 //===----------------------------------------------------------------------===//
1744
1745 /// @brief This class represents zero extension of integer types.
1746 class ZExtInst : public CastInst {
1747   /// @brief Private copy constructor
1748   ZExtInst(const ZExtInst &CI)
1749     : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1750   }
1751 public:
1752   /// @brief Constructor with insert-before-instruction semantics
1753   ZExtInst(
1754     Value *S,                     ///< The value to be zero extended
1755     const Type *Ty,               ///< The type to zero extend to
1756     const std::string &Name = "", ///< A name for the new instruction
1757     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1758   );
1759
1760   /// @brief Constructor with insert-at-end semantics.
1761   ZExtInst(
1762     Value *S,                     ///< The value to be zero extended
1763     const Type *Ty,               ///< The type to zero extend to
1764     const std::string &Name,      ///< A name for the new instruction
1765     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1766   );
1767
1768   /// @brief Clone an identical ZExtInst
1769   virtual CastInst *clone() const;
1770
1771   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1772   static inline bool classof(const ZExtInst *) { return true; }
1773   static inline bool classof(const Instruction *I) {
1774     return I->getOpcode() == ZExt;
1775   }
1776   static inline bool classof(const Value *V) {
1777     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1778   }
1779 };
1780
1781 //===----------------------------------------------------------------------===//
1782 //                                 SExtInst Class
1783 //===----------------------------------------------------------------------===//
1784
1785 /// @brief This class represents a sign extension of integer types.
1786 class SExtInst : public CastInst {
1787   /// @brief Private copy constructor
1788   SExtInst(const SExtInst &CI)
1789     : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1790   }
1791 public:
1792   /// @brief Constructor with insert-before-instruction semantics
1793   SExtInst(
1794     Value *S,                     ///< The value to be sign extended
1795     const Type *Ty,               ///< The type to sign extend to
1796     const std::string &Name = "", ///< A name for the new instruction
1797     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1798   );
1799
1800   /// @brief Constructor with insert-at-end-of-block semantics
1801   SExtInst(
1802     Value *S,                     ///< The value to be sign extended
1803     const Type *Ty,               ///< The type to sign extend to
1804     const std::string &Name,      ///< A name for the new instruction
1805     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1806   );
1807
1808   /// @brief Clone an identical SExtInst
1809   virtual CastInst *clone() const;
1810
1811   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1812   static inline bool classof(const SExtInst *) { return true; }
1813   static inline bool classof(const Instruction *I) {
1814     return I->getOpcode() == SExt;
1815   }
1816   static inline bool classof(const Value *V) {
1817     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1818   }
1819 };
1820
1821 //===----------------------------------------------------------------------===//
1822 //                                 FPTruncInst Class
1823 //===----------------------------------------------------------------------===//
1824
1825 /// @brief This class represents a truncation of floating point types.
1826 class FPTruncInst : public CastInst {
1827   FPTruncInst(const FPTruncInst &CI)
1828     : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1829   }
1830 public:
1831   /// @brief Constructor with insert-before-instruction semantics
1832   FPTruncInst(
1833     Value *S,                     ///< The value to be truncated
1834     const Type *Ty,               ///< The type to truncate to
1835     const std::string &Name = "", ///< A name for the new instruction
1836     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1837   );
1838
1839   /// @brief Constructor with insert-before-instruction semantics
1840   FPTruncInst(
1841     Value *S,                     ///< The value to be truncated
1842     const Type *Ty,               ///< The type to truncate to
1843     const std::string &Name,      ///< A name for the new instruction
1844     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1845   );
1846
1847   /// @brief Clone an identical FPTruncInst
1848   virtual CastInst *clone() const;
1849
1850   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1851   static inline bool classof(const FPTruncInst *) { return true; }
1852   static inline bool classof(const Instruction *I) {
1853     return I->getOpcode() == FPTrunc;
1854   }
1855   static inline bool classof(const Value *V) {
1856     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1857   }
1858 };
1859
1860 //===----------------------------------------------------------------------===//
1861 //                                 FPExtInst Class
1862 //===----------------------------------------------------------------------===//
1863
1864 /// @brief This class represents an extension of floating point types.
1865 class FPExtInst : public CastInst {
1866   FPExtInst(const FPExtInst &CI)
1867     : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1868   }
1869 public:
1870   /// @brief Constructor with insert-before-instruction semantics
1871   FPExtInst(
1872     Value *S,                     ///< The value to be extended
1873     const Type *Ty,               ///< The type to extend to
1874     const std::string &Name = "", ///< A name for the new instruction
1875     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1876   );
1877
1878   /// @brief Constructor with insert-at-end-of-block semantics
1879   FPExtInst(
1880     Value *S,                     ///< The value to be extended
1881     const Type *Ty,               ///< The type to extend to
1882     const std::string &Name,      ///< A name for the new instruction
1883     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1884   );
1885
1886   /// @brief Clone an identical FPExtInst
1887   virtual CastInst *clone() const;
1888
1889   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1890   static inline bool classof(const FPExtInst *) { return true; }
1891   static inline bool classof(const Instruction *I) {
1892     return I->getOpcode() == FPExt;
1893   }
1894   static inline bool classof(const Value *V) {
1895     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1896   }
1897 };
1898
1899 //===----------------------------------------------------------------------===//
1900 //                                 UIToFPInst Class
1901 //===----------------------------------------------------------------------===//
1902
1903 /// @brief This class represents a cast unsigned integer to floating point.
1904 class UIToFPInst : public CastInst {
1905   UIToFPInst(const UIToFPInst &CI)
1906     : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1907   }
1908 public:
1909   /// @brief Constructor with insert-before-instruction semantics
1910   UIToFPInst(
1911     Value *S,                     ///< The value to be converted
1912     const Type *Ty,               ///< The type to convert to
1913     const std::string &Name = "", ///< A name for the new instruction
1914     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1915   );
1916
1917   /// @brief Constructor with insert-at-end-of-block semantics
1918   UIToFPInst(
1919     Value *S,                     ///< The value to be converted
1920     const Type *Ty,               ///< The type to convert to
1921     const std::string &Name,      ///< A name for the new instruction
1922     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1923   );
1924
1925   /// @brief Clone an identical UIToFPInst
1926   virtual CastInst *clone() const;
1927
1928   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1929   static inline bool classof(const UIToFPInst *) { return true; }
1930   static inline bool classof(const Instruction *I) {
1931     return I->getOpcode() == UIToFP;
1932   }
1933   static inline bool classof(const Value *V) {
1934     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1935   }
1936 };
1937
1938 //===----------------------------------------------------------------------===//
1939 //                                 SIToFPInst Class
1940 //===----------------------------------------------------------------------===//
1941
1942 /// @brief This class represents a cast from signed integer to floating point.
1943 class SIToFPInst : public CastInst {
1944   SIToFPInst(const SIToFPInst &CI)
1945     : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1946   }
1947 public:
1948   /// @brief Constructor with insert-before-instruction semantics
1949   SIToFPInst(
1950     Value *S,                     ///< The value to be converted
1951     const Type *Ty,               ///< The type to convert to
1952     const std::string &Name = "", ///< A name for the new instruction
1953     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1954   );
1955
1956   /// @brief Constructor with insert-at-end-of-block semantics
1957   SIToFPInst(
1958     Value *S,                     ///< The value to be converted
1959     const Type *Ty,               ///< The type to convert to
1960     const std::string &Name,      ///< A name for the new instruction
1961     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1962   );
1963
1964   /// @brief Clone an identical SIToFPInst
1965   virtual CastInst *clone() const;
1966
1967   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1968   static inline bool classof(const SIToFPInst *) { return true; }
1969   static inline bool classof(const Instruction *I) {
1970     return I->getOpcode() == SIToFP;
1971   }
1972   static inline bool classof(const Value *V) {
1973     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1974   }
1975 };
1976
1977 //===----------------------------------------------------------------------===//
1978 //                                 FPToUIInst Class
1979 //===----------------------------------------------------------------------===//
1980
1981 /// @brief This class represents a cast from floating point to unsigned integer
1982 class FPToUIInst  : public CastInst {
1983   FPToUIInst(const FPToUIInst &CI)
1984     : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1985   }
1986 public:
1987   /// @brief Constructor with insert-before-instruction semantics
1988   FPToUIInst(
1989     Value *S,                     ///< The value to be converted
1990     const Type *Ty,               ///< The type to convert to
1991     const std::string &Name = "", ///< A name for the new instruction
1992     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1993   );
1994
1995   /// @brief Constructor with insert-at-end-of-block semantics
1996   FPToUIInst(
1997     Value *S,                     ///< The value to be converted
1998     const Type *Ty,               ///< The type to convert to
1999     const std::string &Name,      ///< A name for the new instruction
2000     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
2001   );
2002
2003   /// @brief Clone an identical FPToUIInst
2004   virtual CastInst *clone() const;
2005
2006   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2007   static inline bool classof(const FPToUIInst *) { return true; }
2008   static inline bool classof(const Instruction *I) {
2009     return I->getOpcode() == FPToUI;
2010   }
2011   static inline bool classof(const Value *V) {
2012     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2013   }
2014 };
2015
2016 //===----------------------------------------------------------------------===//
2017 //                                 FPToSIInst Class
2018 //===----------------------------------------------------------------------===//
2019
2020 /// @brief This class represents a cast from floating point to signed integer.
2021 class FPToSIInst  : public CastInst {
2022   FPToSIInst(const FPToSIInst &CI)
2023     : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2024   }
2025 public:
2026   /// @brief Constructor with insert-before-instruction semantics
2027   FPToSIInst(
2028     Value *S,                     ///< The value to be converted
2029     const Type *Ty,               ///< The type to convert to
2030     const std::string &Name = "", ///< A name for the new instruction
2031     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2032   );
2033
2034   /// @brief Constructor with insert-at-end-of-block semantics
2035   FPToSIInst(
2036     Value *S,                     ///< The value to be converted
2037     const Type *Ty,               ///< The type to convert to
2038     const std::string &Name,      ///< A name for the new instruction
2039     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2040   );
2041
2042   /// @brief Clone an identical FPToSIInst
2043   virtual CastInst *clone() const;
2044
2045   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2046   static inline bool classof(const FPToSIInst *) { return true; }
2047   static inline bool classof(const Instruction *I) {
2048     return I->getOpcode() == FPToSI;
2049   }
2050   static inline bool classof(const Value *V) {
2051     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2052   }
2053 };
2054
2055 //===----------------------------------------------------------------------===//
2056 //                                 IntToPtrInst Class
2057 //===----------------------------------------------------------------------===//
2058
2059 /// @brief This class represents a cast from an integer to a pointer.
2060 class IntToPtrInst : public CastInst {
2061   IntToPtrInst(const IntToPtrInst &CI)
2062     : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2063   }
2064 public:
2065   /// @brief Constructor with insert-before-instruction semantics
2066   IntToPtrInst(
2067     Value *S,                     ///< The value to be converted
2068     const Type *Ty,               ///< The type to convert to
2069     const std::string &Name = "", ///< A name for the new instruction
2070     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2071   );
2072
2073   /// @brief Constructor with insert-at-end-of-block semantics
2074   IntToPtrInst(
2075     Value *S,                     ///< The value to be converted
2076     const Type *Ty,               ///< The type to convert to
2077     const std::string &Name,      ///< A name for the new instruction
2078     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2079   );
2080
2081   /// @brief Clone an identical IntToPtrInst
2082   virtual CastInst *clone() const;
2083
2084   // Methods for support type inquiry through isa, cast, and dyn_cast:
2085   static inline bool classof(const IntToPtrInst *) { return true; }
2086   static inline bool classof(const Instruction *I) {
2087     return I->getOpcode() == IntToPtr;
2088   }
2089   static inline bool classof(const Value *V) {
2090     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2091   }
2092 };
2093
2094 //===----------------------------------------------------------------------===//
2095 //                                 PtrToIntInst Class
2096 //===----------------------------------------------------------------------===//
2097
2098 /// @brief This class represents a cast from a pointer to an integer
2099 class PtrToIntInst : public CastInst {
2100   PtrToIntInst(const PtrToIntInst &CI)
2101     : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2102   }
2103 public:
2104   /// @brief Constructor with insert-before-instruction semantics
2105   PtrToIntInst(
2106     Value *S,                     ///< The value to be converted
2107     const Type *Ty,               ///< The type to convert to
2108     const std::string &Name = "", ///< A name for the new instruction
2109     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2110   );
2111
2112   /// @brief Constructor with insert-at-end-of-block semantics
2113   PtrToIntInst(
2114     Value *S,                     ///< The value to be converted
2115     const Type *Ty,               ///< The type to convert to
2116     const std::string &Name,      ///< A name for the new instruction
2117     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2118   );
2119
2120   /// @brief Clone an identical PtrToIntInst
2121   virtual CastInst *clone() const;
2122
2123   // Methods for support type inquiry through isa, cast, and dyn_cast:
2124   static inline bool classof(const PtrToIntInst *) { return true; }
2125   static inline bool classof(const Instruction *I) {
2126     return I->getOpcode() == PtrToInt;
2127   }
2128   static inline bool classof(const Value *V) {
2129     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2130   }
2131 };
2132
2133 //===----------------------------------------------------------------------===//
2134 //                             BitCastInst Class
2135 //===----------------------------------------------------------------------===//
2136
2137 /// @brief This class represents a no-op cast from one type to another.
2138 class BitCastInst : public CastInst {
2139   BitCastInst(const BitCastInst &CI)
2140     : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2141   }
2142 public:
2143   /// @brief Constructor with insert-before-instruction semantics
2144   BitCastInst(
2145     Value *S,                     ///< The value to be casted
2146     const Type *Ty,               ///< The type to casted to
2147     const std::string &Name = "", ///< A name for the new instruction
2148     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2149   );
2150
2151   /// @brief Constructor with insert-at-end-of-block semantics
2152   BitCastInst(
2153     Value *S,                     ///< The value to be casted
2154     const Type *Ty,               ///< The type to casted to
2155     const std::string &Name,      ///< A name for the new instruction
2156     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2157   );
2158
2159   /// @brief Clone an identical BitCastInst
2160   virtual CastInst *clone() const;
2161
2162   // Methods for support type inquiry through isa, cast, and dyn_cast:
2163   static inline bool classof(const BitCastInst *) { return true; }
2164   static inline bool classof(const Instruction *I) {
2165     return I->getOpcode() == BitCast;
2166   }
2167   static inline bool classof(const Value *V) {
2168     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2169   }
2170 };
2171
2172 } // End llvm namespace
2173
2174 #endif