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