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