make mayWriteToMemory a non-virtual function
[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,
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, 0, InsertBefore) {
832     setName(Name);
833   }
834   VAArgInst(Value *List, const Type *Ty, const std::string &Name,
835             BasicBlock *InsertAtEnd)
836     : UnaryInstruction(Ty, VAArg, List, 0, 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, Name, InsertBefore),
1026       ReservedSpace(0) {
1027   }
1028
1029   PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1030     : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
1031       ReservedSpace(0) {
1032   }
1033
1034   ~PHINode();
1035
1036   /// reserveOperandSpace - This method can be used to avoid repeated
1037   /// reallocation of PHI operand lists by reserving space for the correct
1038   /// number of operands before adding them.  Unlike normal vector reserves,
1039   /// this method can also be used to trim the operand space.
1040   void reserveOperandSpace(unsigned NumValues) {
1041     resizeOperands(NumValues*2);
1042   }
1043
1044   virtual PHINode *clone() const;
1045
1046   /// getNumIncomingValues - Return the number of incoming edges
1047   ///
1048   unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1049
1050   /// getIncomingValue - Return incoming value number x
1051   ///
1052   Value *getIncomingValue(unsigned i) const {
1053     assert(i*2 < getNumOperands() && "Invalid value number!");
1054     return getOperand(i*2);
1055   }
1056   void setIncomingValue(unsigned i, Value *V) {
1057     assert(i*2 < getNumOperands() && "Invalid value number!");
1058     setOperand(i*2, V);
1059   }
1060   unsigned getOperandNumForIncomingValue(unsigned i) {
1061     return i*2;
1062   }
1063
1064   /// getIncomingBlock - Return incoming basic block number x
1065   ///
1066   BasicBlock *getIncomingBlock(unsigned i) const {
1067     return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1068   }
1069   void setIncomingBlock(unsigned i, BasicBlock *BB) {
1070     setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1071   }
1072   unsigned getOperandNumForIncomingBlock(unsigned i) {
1073     return i*2+1;
1074   }
1075
1076   /// addIncoming - Add an incoming value to the end of the PHI list
1077   ///
1078   void addIncoming(Value *V, BasicBlock *BB) {
1079     assert(getType() == V->getType() &&
1080            "All operands to PHI node must be the same type as the PHI node!");
1081     unsigned OpNo = NumOperands;
1082     if (OpNo+2 > ReservedSpace)
1083       resizeOperands(0);  // Get more space!
1084     // Initialize some new operands.
1085     NumOperands = OpNo+2;
1086     OperandList[OpNo].init(V, this);
1087     OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1088   }
1089
1090   /// removeIncomingValue - Remove an incoming value.  This is useful if a
1091   /// predecessor basic block is deleted.  The value removed is returned.
1092   ///
1093   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1094   /// is true), the PHI node is destroyed and any uses of it are replaced with
1095   /// dummy values.  The only time there should be zero incoming values to a PHI
1096   /// node is when the block is dead, so this strategy is sound.
1097   ///
1098   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1099
1100   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1101     int Idx = getBasicBlockIndex(BB);
1102     assert(Idx >= 0 && "Invalid basic block argument to remove!");
1103     return removeIncomingValue(Idx, DeletePHIIfEmpty);
1104   }
1105
1106   /// getBasicBlockIndex - Return the first index of the specified basic
1107   /// block in the value list for this PHI.  Returns -1 if no instance.
1108   ///
1109   int getBasicBlockIndex(const BasicBlock *BB) const {
1110     Use *OL = OperandList;
1111     for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1112       if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1113     return -1;
1114   }
1115
1116   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1117     return getIncomingValue(getBasicBlockIndex(BB));
1118   }
1119
1120   /// hasConstantValue - If the specified PHI node always merges together the
1121   /// same value, return the value, otherwise return null.
1122   ///
1123   Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1124
1125   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1126   static inline bool classof(const PHINode *) { return true; }
1127   static inline bool classof(const Instruction *I) {
1128     return I->getOpcode() == Instruction::PHI;
1129   }
1130   static inline bool classof(const Value *V) {
1131     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1132   }
1133  private:
1134   void resizeOperands(unsigned NumOperands);
1135 };
1136
1137 //===----------------------------------------------------------------------===//
1138 //                               ReturnInst Class
1139 //===----------------------------------------------------------------------===//
1140
1141 //===---------------------------------------------------------------------------
1142 /// ReturnInst - Return a value (possibly void), from a function.  Execution
1143 /// does not continue in this function any longer.
1144 ///
1145 class ReturnInst : public TerminatorInst {
1146   Use RetVal;  // Possibly null retval.
1147   ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
1148                                                     RI.getNumOperands()) {
1149     if (RI.getNumOperands())
1150       RetVal.init(RI.RetVal, this);
1151   }
1152
1153   void init(Value *RetVal);
1154
1155 public:
1156   // ReturnInst constructors:
1157   // ReturnInst()                  - 'ret void' instruction
1158   // ReturnInst(    null)          - 'ret void' instruction
1159   // ReturnInst(Value* X)          - 'ret X'    instruction
1160   // ReturnInst(    null, Inst *)  - 'ret void' instruction, insert before I
1161   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
1162   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of BB
1163   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of BB
1164   //
1165   // NOTE: If the Value* passed is of type void then the constructor behaves as
1166   // if it was passed NULL.
1167   explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
1168     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
1169     init(retVal);
1170   }
1171   ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
1172     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1173     init(retVal);
1174   }
1175   explicit ReturnInst(BasicBlock *InsertAtEnd)
1176     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1177   }
1178
1179   virtual ReturnInst *clone() const;
1180
1181   // Transparently provide more efficient getOperand methods.
1182   Value *getOperand(unsigned i) const {
1183     assert(i < getNumOperands() && "getOperand() out of range!");
1184     return RetVal;
1185   }
1186   void setOperand(unsigned i, Value *Val) {
1187     assert(i < getNumOperands() && "setOperand() out of range!");
1188     RetVal = Val;
1189   }
1190
1191   Value *getReturnValue() const { return RetVal; }
1192
1193   unsigned getNumSuccessors() const { return 0; }
1194
1195   // Methods for support type inquiry through isa, cast, and dyn_cast:
1196   static inline bool classof(const ReturnInst *) { return true; }
1197   static inline bool classof(const Instruction *I) {
1198     return (I->getOpcode() == Instruction::Ret);
1199   }
1200   static inline bool classof(const Value *V) {
1201     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1202   }
1203  private:
1204   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1205   virtual unsigned getNumSuccessorsV() const;
1206   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1207 };
1208
1209 //===----------------------------------------------------------------------===//
1210 //                               BranchInst Class
1211 //===----------------------------------------------------------------------===//
1212
1213 //===---------------------------------------------------------------------------
1214 /// BranchInst - Conditional or Unconditional Branch instruction.
1215 ///
1216 class BranchInst : public TerminatorInst {
1217   /// Ops list - Branches are strange.  The operands are ordered:
1218   ///  TrueDest, FalseDest, Cond.  This makes some accessors faster because
1219   /// they don't have to check for cond/uncond branchness.
1220   Use Ops[3];
1221   BranchInst(const BranchInst &BI);
1222   void AssertOK();
1223 public:
1224   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1225   // BranchInst(BB *B)                           - 'br B'
1226   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
1227   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
1228   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1229   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
1230   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
1231   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1232     : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1233     assert(IfTrue != 0 && "Branch destination may not be null!");
1234     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1235   }
1236   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1237              Instruction *InsertBefore = 0)
1238     : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1239     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1240     Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1241     Ops[2].init(Cond, this);
1242 #ifndef NDEBUG
1243     AssertOK();
1244 #endif
1245   }
1246
1247   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1248     : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1249     assert(IfTrue != 0 && "Branch destination may not be null!");
1250     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1251   }
1252
1253   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1254              BasicBlock *InsertAtEnd)
1255     : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1256     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1257     Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1258     Ops[2].init(Cond, this);
1259 #ifndef NDEBUG
1260     AssertOK();
1261 #endif
1262   }
1263
1264
1265   /// Transparently provide more efficient getOperand methods.
1266   Value *getOperand(unsigned i) const {
1267     assert(i < getNumOperands() && "getOperand() out of range!");
1268     return Ops[i];
1269   }
1270   void setOperand(unsigned i, Value *Val) {
1271     assert(i < getNumOperands() && "setOperand() out of range!");
1272     Ops[i] = Val;
1273   }
1274
1275   virtual BranchInst *clone() const;
1276
1277   inline bool isUnconditional() const { return getNumOperands() == 1; }
1278   inline bool isConditional()   const { return getNumOperands() == 3; }
1279
1280   inline Value *getCondition() const {
1281     assert(isConditional() && "Cannot get condition of an uncond branch!");
1282     return getOperand(2);
1283   }
1284
1285   void setCondition(Value *V) {
1286     assert(isConditional() && "Cannot set condition of unconditional branch!");
1287     setOperand(2, V);
1288   }
1289
1290   // setUnconditionalDest - Change the current branch to an unconditional branch
1291   // targeting the specified block.
1292   // FIXME: Eliminate this ugly method.
1293   void setUnconditionalDest(BasicBlock *Dest) {
1294     if (isConditional()) {  // Convert this to an uncond branch.
1295       NumOperands = 1;
1296       Ops[1].set(0);
1297       Ops[2].set(0);
1298     }
1299     setOperand(0, reinterpret_cast<Value*>(Dest));
1300   }
1301
1302   unsigned getNumSuccessors() const { return 1+isConditional(); }
1303
1304   BasicBlock *getSuccessor(unsigned i) const {
1305     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1306     return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1307                       cast<BasicBlock>(getOperand(1));
1308   }
1309
1310   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1311     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1312     setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1313   }
1314
1315   // Methods for support type inquiry through isa, cast, and dyn_cast:
1316   static inline bool classof(const BranchInst *) { return true; }
1317   static inline bool classof(const Instruction *I) {
1318     return (I->getOpcode() == Instruction::Br);
1319   }
1320   static inline bool classof(const Value *V) {
1321     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1322   }
1323 private:
1324   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1325   virtual unsigned getNumSuccessorsV() const;
1326   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1327 };
1328
1329 //===----------------------------------------------------------------------===//
1330 //                               SwitchInst Class
1331 //===----------------------------------------------------------------------===//
1332
1333 //===---------------------------------------------------------------------------
1334 /// SwitchInst - Multiway switch
1335 ///
1336 class SwitchInst : public TerminatorInst {
1337   unsigned ReservedSpace;
1338   // Operand[0]    = Value to switch on
1339   // Operand[1]    = Default basic block destination
1340   // Operand[2n  ] = Value to match
1341   // Operand[2n+1] = BasicBlock to go to on match
1342   SwitchInst(const SwitchInst &RI);
1343   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1344   void resizeOperands(unsigned No);
1345 public:
1346   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1347   /// switch on and a default destination.  The number of additional cases can
1348   /// be specified here to make memory allocation more efficient.  This
1349   /// constructor can also autoinsert before another instruction.
1350   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1351              Instruction *InsertBefore = 0)
1352     : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1353     init(Value, Default, NumCases);
1354   }
1355
1356   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1357   /// switch on and a default destination.  The number of additional cases can
1358   /// be specified here to make memory allocation more efficient.  This
1359   /// constructor also autoinserts at the end of the specified BasicBlock.
1360   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1361              BasicBlock *InsertAtEnd)
1362     : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1363     init(Value, Default, NumCases);
1364   }
1365   ~SwitchInst();
1366
1367
1368   // Accessor Methods for Switch stmt
1369   inline Value *getCondition() const { return getOperand(0); }
1370   void setCondition(Value *V) { setOperand(0, V); }
1371
1372   inline BasicBlock *getDefaultDest() const {
1373     return cast<BasicBlock>(getOperand(1));
1374   }
1375
1376   /// getNumCases - return the number of 'cases' in this switch instruction.
1377   /// Note that case #0 is always the default case.
1378   unsigned getNumCases() const {
1379     return getNumOperands()/2;
1380   }
1381
1382   /// getCaseValue - Return the specified case value.  Note that case #0, the
1383   /// default destination, does not have a case value.
1384   ConstantInt *getCaseValue(unsigned i) {
1385     assert(i && i < getNumCases() && "Illegal case value to get!");
1386     return getSuccessorValue(i);
1387   }
1388
1389   /// getCaseValue - Return the specified case value.  Note that case #0, the
1390   /// default destination, does not have a case value.
1391   const ConstantInt *getCaseValue(unsigned i) const {
1392     assert(i && i < getNumCases() && "Illegal case value to get!");
1393     return getSuccessorValue(i);
1394   }
1395
1396   /// findCaseValue - Search all of the case values for the specified constant.
1397   /// If it is explicitly handled, return the case number of it, otherwise
1398   /// return 0 to indicate that it is handled by the default handler.
1399   unsigned findCaseValue(const ConstantInt *C) const {
1400     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1401       if (getCaseValue(i) == C)
1402         return i;
1403     return 0;
1404   }
1405
1406   /// findCaseDest - Finds the unique case value for a given successor. Returns
1407   /// null if the successor is not found, not unique, or is the default case.
1408   ConstantInt *findCaseDest(BasicBlock *BB) {
1409     if (BB == getDefaultDest()) return NULL;
1410
1411     ConstantInt *CI = NULL;
1412     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1413       if (getSuccessor(i) == BB) {
1414         if (CI) return NULL;   // Multiple cases lead to BB.
1415         else CI = getCaseValue(i);
1416       }
1417     }
1418     return CI;
1419   }
1420
1421   /// addCase - Add an entry to the switch instruction...
1422   ///
1423   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1424
1425   /// removeCase - This method removes the specified successor from the switch
1426   /// instruction.  Note that this cannot be used to remove the default
1427   /// destination (successor #0).
1428   ///
1429   void removeCase(unsigned idx);
1430
1431   virtual SwitchInst *clone() const;
1432
1433   unsigned getNumSuccessors() const { return getNumOperands()/2; }
1434   BasicBlock *getSuccessor(unsigned idx) const {
1435     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1436     return cast<BasicBlock>(getOperand(idx*2+1));
1437   }
1438   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1439     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1440     setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1441   }
1442
1443   // getSuccessorValue - Return the value associated with the specified
1444   // successor.
1445   inline ConstantInt *getSuccessorValue(unsigned idx) const {
1446     assert(idx < getNumSuccessors() && "Successor # out of range!");
1447     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1448   }
1449
1450   // Methods for support type inquiry through isa, cast, and dyn_cast:
1451   static inline bool classof(const SwitchInst *) { return true; }
1452   static inline bool classof(const Instruction *I) {
1453     return I->getOpcode() == Instruction::Switch;
1454   }
1455   static inline bool classof(const Value *V) {
1456     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1457   }
1458 private:
1459   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1460   virtual unsigned getNumSuccessorsV() const;
1461   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1462 };
1463
1464 //===----------------------------------------------------------------------===//
1465 //                               InvokeInst Class
1466 //===----------------------------------------------------------------------===//
1467
1468 //===---------------------------------------------------------------------------
1469
1470 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
1471 /// calling convention of the call.
1472 ///
1473 class InvokeInst : public TerminatorInst {
1474   InvokeInst(const InvokeInst &BI);
1475   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1476             Value* const *Args, unsigned NumArgs);
1477 public:
1478   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1479              Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1480              Instruction *InsertBefore = 0);
1481   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1482              Value* const* Args, unsigned NumArgs, const std::string &Name,
1483              BasicBlock *InsertAtEnd);
1484   ~InvokeInst();
1485
1486   virtual InvokeInst *clone() const;
1487
1488   /// getCallingConv/setCallingConv - Get or set the calling convention of this
1489   /// function call.
1490   unsigned getCallingConv() const { return SubclassData; }
1491   void setCallingConv(unsigned CC) {
1492     SubclassData = CC;
1493   }
1494
1495   /// getCalledFunction - Return the function called, or null if this is an
1496   /// indirect function invocation.
1497   ///
1498   Function *getCalledFunction() const {
1499     return dyn_cast<Function>(getOperand(0));
1500   }
1501
1502   // getCalledValue - Get a pointer to a function that is invoked by this inst.
1503   inline Value *getCalledValue() const { return getOperand(0); }
1504
1505   // get*Dest - Return the destination basic blocks...
1506   BasicBlock *getNormalDest() const {
1507     return cast<BasicBlock>(getOperand(1));
1508   }
1509   BasicBlock *getUnwindDest() const {
1510     return cast<BasicBlock>(getOperand(2));
1511   }
1512   void setNormalDest(BasicBlock *B) {
1513     setOperand(1, reinterpret_cast<Value*>(B));
1514   }
1515
1516   void setUnwindDest(BasicBlock *B) {
1517     setOperand(2, reinterpret_cast<Value*>(B));
1518   }
1519
1520   inline BasicBlock *getSuccessor(unsigned i) const {
1521     assert(i < 2 && "Successor # out of range for invoke!");
1522     return i == 0 ? getNormalDest() : getUnwindDest();
1523   }
1524
1525   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1526     assert(idx < 2 && "Successor # out of range for invoke!");
1527     setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1528   }
1529
1530   unsigned getNumSuccessors() const { return 2; }
1531
1532   // Methods for support type inquiry through isa, cast, and dyn_cast:
1533   static inline bool classof(const InvokeInst *) { return true; }
1534   static inline bool classof(const Instruction *I) {
1535     return (I->getOpcode() == Instruction::Invoke);
1536   }
1537   static inline bool classof(const Value *V) {
1538     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1539   }
1540 private:
1541   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1542   virtual unsigned getNumSuccessorsV() const;
1543   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1544 };
1545
1546
1547 //===----------------------------------------------------------------------===//
1548 //                              UnwindInst Class
1549 //===----------------------------------------------------------------------===//
1550
1551 //===---------------------------------------------------------------------------
1552 /// UnwindInst - Immediately exit the current function, unwinding the stack
1553 /// until an invoke instruction is found.
1554 ///
1555 class UnwindInst : public TerminatorInst {
1556 public:
1557   explicit UnwindInst(Instruction *InsertBefore = 0)
1558     : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1559   }
1560   explicit UnwindInst(BasicBlock *InsertAtEnd)
1561     : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1562   }
1563
1564   virtual UnwindInst *clone() const;
1565
1566   unsigned getNumSuccessors() const { return 0; }
1567
1568   // Methods for support type inquiry through isa, cast, and dyn_cast:
1569   static inline bool classof(const UnwindInst *) { return true; }
1570   static inline bool classof(const Instruction *I) {
1571     return I->getOpcode() == Instruction::Unwind;
1572   }
1573   static inline bool classof(const Value *V) {
1574     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1575   }
1576 private:
1577   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1578   virtual unsigned getNumSuccessorsV() const;
1579   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1580 };
1581
1582 //===----------------------------------------------------------------------===//
1583 //                           UnreachableInst Class
1584 //===----------------------------------------------------------------------===//
1585
1586 //===---------------------------------------------------------------------------
1587 /// UnreachableInst - This function has undefined behavior.  In particular, the
1588 /// presence of this instruction indicates some higher level knowledge that the
1589 /// end of the block cannot be reached.
1590 ///
1591 class UnreachableInst : public TerminatorInst {
1592 public:
1593   explicit UnreachableInst(Instruction *InsertBefore = 0)
1594     : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1595   }
1596   explicit UnreachableInst(BasicBlock *InsertAtEnd)
1597     : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1598   }
1599
1600   virtual UnreachableInst *clone() const;
1601
1602   unsigned getNumSuccessors() const { return 0; }
1603
1604   // Methods for support type inquiry through isa, cast, and dyn_cast:
1605   static inline bool classof(const UnreachableInst *) { return true; }
1606   static inline bool classof(const Instruction *I) {
1607     return I->getOpcode() == Instruction::Unreachable;
1608   }
1609   static inline bool classof(const Value *V) {
1610     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1611   }
1612 private:
1613   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1614   virtual unsigned getNumSuccessorsV() const;
1615   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1616 };
1617
1618 //===----------------------------------------------------------------------===//
1619 //                                 TruncInst Class
1620 //===----------------------------------------------------------------------===//
1621
1622 /// @brief This class represents a truncation of integer types.
1623 class TruncInst : public CastInst {
1624   /// Private copy constructor
1625   TruncInst(const TruncInst &CI)
1626     : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1627   }
1628 public:
1629   /// @brief Constructor with insert-before-instruction semantics
1630   TruncInst(
1631     Value *S,                     ///< The value to be truncated
1632     const Type *Ty,               ///< The (smaller) type to truncate to
1633     const std::string &Name = "", ///< A name for the new instruction
1634     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1635   );
1636
1637   /// @brief Constructor with insert-at-end-of-block semantics
1638   TruncInst(
1639     Value *S,                     ///< The value to be truncated
1640     const Type *Ty,               ///< The (smaller) type to truncate to
1641     const std::string &Name,      ///< A name for the new instruction
1642     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1643   );
1644
1645   /// @brief Clone an identical TruncInst
1646   virtual CastInst *clone() const;
1647
1648   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1649   static inline bool classof(const TruncInst *) { return true; }
1650   static inline bool classof(const Instruction *I) {
1651     return I->getOpcode() == Trunc;
1652   }
1653   static inline bool classof(const Value *V) {
1654     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1655   }
1656 };
1657
1658 //===----------------------------------------------------------------------===//
1659 //                                 ZExtInst Class
1660 //===----------------------------------------------------------------------===//
1661
1662 /// @brief This class represents zero extension of integer types.
1663 class ZExtInst : public CastInst {
1664   /// @brief Private copy constructor
1665   ZExtInst(const ZExtInst &CI)
1666     : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1667   }
1668 public:
1669   /// @brief Constructor with insert-before-instruction semantics
1670   ZExtInst(
1671     Value *S,                     ///< The value to be zero extended
1672     const Type *Ty,               ///< The type to zero extend to
1673     const std::string &Name = "", ///< A name for the new instruction
1674     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1675   );
1676
1677   /// @brief Constructor with insert-at-end semantics.
1678   ZExtInst(
1679     Value *S,                     ///< The value to be zero extended
1680     const Type *Ty,               ///< The type to zero extend to
1681     const std::string &Name,      ///< A name for the new instruction
1682     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1683   );
1684
1685   /// @brief Clone an identical ZExtInst
1686   virtual CastInst *clone() const;
1687
1688   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1689   static inline bool classof(const ZExtInst *) { return true; }
1690   static inline bool classof(const Instruction *I) {
1691     return I->getOpcode() == ZExt;
1692   }
1693   static inline bool classof(const Value *V) {
1694     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1695   }
1696 };
1697
1698 //===----------------------------------------------------------------------===//
1699 //                                 SExtInst Class
1700 //===----------------------------------------------------------------------===//
1701
1702 /// @brief This class represents a sign extension of integer types.
1703 class SExtInst : public CastInst {
1704   /// @brief Private copy constructor
1705   SExtInst(const SExtInst &CI)
1706     : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1707   }
1708 public:
1709   /// @brief Constructor with insert-before-instruction semantics
1710   SExtInst(
1711     Value *S,                     ///< The value to be sign extended
1712     const Type *Ty,               ///< The type to sign extend to
1713     const std::string &Name = "", ///< A name for the new instruction
1714     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1715   );
1716
1717   /// @brief Constructor with insert-at-end-of-block semantics
1718   SExtInst(
1719     Value *S,                     ///< The value to be sign extended
1720     const Type *Ty,               ///< The type to sign extend to
1721     const std::string &Name,      ///< A name for the new instruction
1722     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1723   );
1724
1725   /// @brief Clone an identical SExtInst
1726   virtual CastInst *clone() const;
1727
1728   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1729   static inline bool classof(const SExtInst *) { return true; }
1730   static inline bool classof(const Instruction *I) {
1731     return I->getOpcode() == SExt;
1732   }
1733   static inline bool classof(const Value *V) {
1734     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1735   }
1736 };
1737
1738 //===----------------------------------------------------------------------===//
1739 //                                 FPTruncInst Class
1740 //===----------------------------------------------------------------------===//
1741
1742 /// @brief This class represents a truncation of floating point types.
1743 class FPTruncInst : public CastInst {
1744   FPTruncInst(const FPTruncInst &CI)
1745     : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1746   }
1747 public:
1748   /// @brief Constructor with insert-before-instruction semantics
1749   FPTruncInst(
1750     Value *S,                     ///< The value to be truncated
1751     const Type *Ty,               ///< The type to truncate to
1752     const std::string &Name = "", ///< A name for the new instruction
1753     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1754   );
1755
1756   /// @brief Constructor with insert-before-instruction semantics
1757   FPTruncInst(
1758     Value *S,                     ///< The value to be truncated
1759     const Type *Ty,               ///< The type to truncate to
1760     const std::string &Name,      ///< A name for the new instruction
1761     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1762   );
1763
1764   /// @brief Clone an identical FPTruncInst
1765   virtual CastInst *clone() const;
1766
1767   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1768   static inline bool classof(const FPTruncInst *) { return true; }
1769   static inline bool classof(const Instruction *I) {
1770     return I->getOpcode() == FPTrunc;
1771   }
1772   static inline bool classof(const Value *V) {
1773     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1774   }
1775 };
1776
1777 //===----------------------------------------------------------------------===//
1778 //                                 FPExtInst Class
1779 //===----------------------------------------------------------------------===//
1780
1781 /// @brief This class represents an extension of floating point types.
1782 class FPExtInst : public CastInst {
1783   FPExtInst(const FPExtInst &CI)
1784     : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1785   }
1786 public:
1787   /// @brief Constructor with insert-before-instruction semantics
1788   FPExtInst(
1789     Value *S,                     ///< The value to be extended
1790     const Type *Ty,               ///< The type to extend to
1791     const std::string &Name = "", ///< A name for the new instruction
1792     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1793   );
1794
1795   /// @brief Constructor with insert-at-end-of-block semantics
1796   FPExtInst(
1797     Value *S,                     ///< The value to be extended
1798     const Type *Ty,               ///< The type to extend to
1799     const std::string &Name,      ///< A name for the new instruction
1800     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1801   );
1802
1803   /// @brief Clone an identical FPExtInst
1804   virtual CastInst *clone() const;
1805
1806   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1807   static inline bool classof(const FPExtInst *) { return true; }
1808   static inline bool classof(const Instruction *I) {
1809     return I->getOpcode() == FPExt;
1810   }
1811   static inline bool classof(const Value *V) {
1812     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1813   }
1814 };
1815
1816 //===----------------------------------------------------------------------===//
1817 //                                 UIToFPInst Class
1818 //===----------------------------------------------------------------------===//
1819
1820 /// @brief This class represents a cast unsigned integer to floating point.
1821 class UIToFPInst : public CastInst {
1822   UIToFPInst(const UIToFPInst &CI)
1823     : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1824   }
1825 public:
1826   /// @brief Constructor with insert-before-instruction semantics
1827   UIToFPInst(
1828     Value *S,                     ///< The value to be converted
1829     const Type *Ty,               ///< The type to convert to
1830     const std::string &Name = "", ///< A name for the new instruction
1831     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1832   );
1833
1834   /// @brief Constructor with insert-at-end-of-block semantics
1835   UIToFPInst(
1836     Value *S,                     ///< The value to be converted
1837     const Type *Ty,               ///< The type to convert to
1838     const std::string &Name,      ///< A name for the new instruction
1839     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1840   );
1841
1842   /// @brief Clone an identical UIToFPInst
1843   virtual CastInst *clone() const;
1844
1845   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1846   static inline bool classof(const UIToFPInst *) { return true; }
1847   static inline bool classof(const Instruction *I) {
1848     return I->getOpcode() == UIToFP;
1849   }
1850   static inline bool classof(const Value *V) {
1851     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1852   }
1853 };
1854
1855 //===----------------------------------------------------------------------===//
1856 //                                 SIToFPInst Class
1857 //===----------------------------------------------------------------------===//
1858
1859 /// @brief This class represents a cast from signed integer to floating point.
1860 class SIToFPInst : public CastInst {
1861   SIToFPInst(const SIToFPInst &CI)
1862     : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1863   }
1864 public:
1865   /// @brief Constructor with insert-before-instruction semantics
1866   SIToFPInst(
1867     Value *S,                     ///< The value to be converted
1868     const Type *Ty,               ///< The type to convert to
1869     const std::string &Name = "", ///< A name for the new instruction
1870     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1871   );
1872
1873   /// @brief Constructor with insert-at-end-of-block semantics
1874   SIToFPInst(
1875     Value *S,                     ///< The value to be converted
1876     const Type *Ty,               ///< The type to convert to
1877     const std::string &Name,      ///< A name for the new instruction
1878     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1879   );
1880
1881   /// @brief Clone an identical SIToFPInst
1882   virtual CastInst *clone() const;
1883
1884   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1885   static inline bool classof(const SIToFPInst *) { return true; }
1886   static inline bool classof(const Instruction *I) {
1887     return I->getOpcode() == SIToFP;
1888   }
1889   static inline bool classof(const Value *V) {
1890     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1891   }
1892 };
1893
1894 //===----------------------------------------------------------------------===//
1895 //                                 FPToUIInst Class
1896 //===----------------------------------------------------------------------===//
1897
1898 /// @brief This class represents a cast from floating point to unsigned integer
1899 class FPToUIInst  : public CastInst {
1900   FPToUIInst(const FPToUIInst &CI)
1901     : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1902   }
1903 public:
1904   /// @brief Constructor with insert-before-instruction semantics
1905   FPToUIInst(
1906     Value *S,                     ///< The value to be converted
1907     const Type *Ty,               ///< The type to convert to
1908     const std::string &Name = "", ///< A name for the new instruction
1909     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1910   );
1911
1912   /// @brief Constructor with insert-at-end-of-block semantics
1913   FPToUIInst(
1914     Value *S,                     ///< The value to be converted
1915     const Type *Ty,               ///< The type to convert to
1916     const std::string &Name,      ///< A name for the new instruction
1917     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
1918   );
1919
1920   /// @brief Clone an identical FPToUIInst
1921   virtual CastInst *clone() const;
1922
1923   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1924   static inline bool classof(const FPToUIInst *) { return true; }
1925   static inline bool classof(const Instruction *I) {
1926     return I->getOpcode() == FPToUI;
1927   }
1928   static inline bool classof(const Value *V) {
1929     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1930   }
1931 };
1932
1933 //===----------------------------------------------------------------------===//
1934 //                                 FPToSIInst Class
1935 //===----------------------------------------------------------------------===//
1936
1937 /// @brief This class represents a cast from floating point to signed integer.
1938 class FPToSIInst  : public CastInst {
1939   FPToSIInst(const FPToSIInst &CI)
1940     : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1941   }
1942 public:
1943   /// @brief Constructor with insert-before-instruction semantics
1944   FPToSIInst(
1945     Value *S,                     ///< The value to be converted
1946     const Type *Ty,               ///< The type to convert to
1947     const std::string &Name = "", ///< A name for the new instruction
1948     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1949   );
1950
1951   /// @brief Constructor with insert-at-end-of-block semantics
1952   FPToSIInst(
1953     Value *S,                     ///< The value to be converted
1954     const Type *Ty,               ///< The type to convert to
1955     const std::string &Name,      ///< A name for the new instruction
1956     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1957   );
1958
1959   /// @brief Clone an identical FPToSIInst
1960   virtual CastInst *clone() const;
1961
1962   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1963   static inline bool classof(const FPToSIInst *) { return true; }
1964   static inline bool classof(const Instruction *I) {
1965     return I->getOpcode() == FPToSI;
1966   }
1967   static inline bool classof(const Value *V) {
1968     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1969   }
1970 };
1971
1972 //===----------------------------------------------------------------------===//
1973 //                                 IntToPtrInst Class
1974 //===----------------------------------------------------------------------===//
1975
1976 /// @brief This class represents a cast from an integer to a pointer.
1977 class IntToPtrInst : public CastInst {
1978   IntToPtrInst(const IntToPtrInst &CI)
1979     : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1980   }
1981 public:
1982   /// @brief Constructor with insert-before-instruction semantics
1983   IntToPtrInst(
1984     Value *S,                     ///< The value to be converted
1985     const Type *Ty,               ///< The type to convert to
1986     const std::string &Name = "", ///< A name for the new instruction
1987     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1988   );
1989
1990   /// @brief Constructor with insert-at-end-of-block semantics
1991   IntToPtrInst(
1992     Value *S,                     ///< The value to be converted
1993     const Type *Ty,               ///< The type to convert to
1994     const std::string &Name,      ///< A name for the new instruction
1995     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1996   );
1997
1998   /// @brief Clone an identical IntToPtrInst
1999   virtual CastInst *clone() const;
2000
2001   // Methods for support type inquiry through isa, cast, and dyn_cast:
2002   static inline bool classof(const IntToPtrInst *) { return true; }
2003   static inline bool classof(const Instruction *I) {
2004     return I->getOpcode() == IntToPtr;
2005   }
2006   static inline bool classof(const Value *V) {
2007     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2008   }
2009 };
2010
2011 //===----------------------------------------------------------------------===//
2012 //                                 PtrToIntInst Class
2013 //===----------------------------------------------------------------------===//
2014
2015 /// @brief This class represents a cast from a pointer to an integer
2016 class PtrToIntInst : public CastInst {
2017   PtrToIntInst(const PtrToIntInst &CI)
2018     : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2019   }
2020 public:
2021   /// @brief Constructor with insert-before-instruction semantics
2022   PtrToIntInst(
2023     Value *S,                     ///< The value to be converted
2024     const Type *Ty,               ///< The type to convert to
2025     const std::string &Name = "", ///< A name for the new instruction
2026     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2027   );
2028
2029   /// @brief Constructor with insert-at-end-of-block semantics
2030   PtrToIntInst(
2031     Value *S,                     ///< The value to be converted
2032     const Type *Ty,               ///< The type to convert to
2033     const std::string &Name,      ///< A name for the new instruction
2034     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2035   );
2036
2037   /// @brief Clone an identical PtrToIntInst
2038   virtual CastInst *clone() const;
2039
2040   // Methods for support type inquiry through isa, cast, and dyn_cast:
2041   static inline bool classof(const PtrToIntInst *) { return true; }
2042   static inline bool classof(const Instruction *I) {
2043     return I->getOpcode() == PtrToInt;
2044   }
2045   static inline bool classof(const Value *V) {
2046     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2047   }
2048 };
2049
2050 //===----------------------------------------------------------------------===//
2051 //                             BitCastInst Class
2052 //===----------------------------------------------------------------------===//
2053
2054 /// @brief This class represents a no-op cast from one type to another.
2055 class BitCastInst : public CastInst {
2056   BitCastInst(const BitCastInst &CI)
2057     : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2058   }
2059 public:
2060   /// @brief Constructor with insert-before-instruction semantics
2061   BitCastInst(
2062     Value *S,                     ///< The value to be casted
2063     const Type *Ty,               ///< The type to casted to
2064     const std::string &Name = "", ///< A name for the new instruction
2065     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2066   );
2067
2068   /// @brief Constructor with insert-at-end-of-block semantics
2069   BitCastInst(
2070     Value *S,                     ///< The value to be casted
2071     const Type *Ty,               ///< The type to casted to
2072     const std::string &Name,      ///< A name for the new instruction
2073     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2074   );
2075
2076   /// @brief Clone an identical BitCastInst
2077   virtual CastInst *clone() const;
2078
2079   // Methods for support type inquiry through isa, cast, and dyn_cast:
2080   static inline bool classof(const BitCastInst *) { return true; }
2081   static inline bool classof(const Instruction *I) {
2082     return I->getOpcode() == BitCast;
2083   }
2084   static inline bool classof(const Value *V) {
2085     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2086   }
2087 };
2088
2089 } // End llvm namespace
2090
2091 #endif