remove some dead methods.
[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 #include <vector>  // fixme remove.
21
22 namespace llvm {
23
24 class BasicBlock;
25 class ConstantInt;
26 class PointerType;
27 class PackedType;
28
29 //===----------------------------------------------------------------------===//
30 //                             AllocationInst Class
31 //===----------------------------------------------------------------------===//
32
33 /// AllocationInst - This class is the common base class of MallocInst and
34 /// AllocaInst.
35 ///
36 class AllocationInst : public UnaryInstruction {
37   unsigned Alignment;
38 protected:
39   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
40                  const std::string &Name = "", Instruction *InsertBefore = 0);
41   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
42                  const std::string &Name, BasicBlock *InsertAtEnd);
43 public:
44   // Out of line virtual method, so the vtable, etc has a home.
45   virtual ~AllocationInst();
46
47   /// isArrayAllocation - Return true if there is an allocation size parameter
48   /// to the allocation instruction that is not 1.
49   ///
50   bool isArrayAllocation() const;
51
52   /// getArraySize - Get the number of element allocated, for a simple
53   /// allocation of a single element, this will return a constant 1 value.
54   ///
55   inline const Value *getArraySize() const { return getOperand(0); }
56   inline Value *getArraySize() { return getOperand(0); }
57
58   /// getType - Overload to return most specific pointer type
59   ///
60   inline const PointerType *getType() const {
61     return reinterpret_cast<const PointerType*>(Instruction::getType());
62   }
63
64   /// getAllocatedType - Return the type that is being allocated by the
65   /// instruction.
66   ///
67   const Type *getAllocatedType() const;
68
69   /// getAlignment - Return the alignment of the memory that is being allocated
70   /// by the instruction.
71   ///
72   unsigned getAlignment() const { return Alignment; }
73   void setAlignment(unsigned Align) {
74     assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
75     Alignment = Align;
76   }
77
78   virtual Instruction *clone() const = 0;
79
80   // Methods for support type inquiry through isa, cast, and dyn_cast:
81   static inline bool classof(const AllocationInst *) { return true; }
82   static inline bool classof(const Instruction *I) {
83     return I->getOpcode() == Instruction::Alloca ||
84            I->getOpcode() == Instruction::Malloc;
85   }
86   static inline bool classof(const Value *V) {
87     return isa<Instruction>(V) && classof(cast<Instruction>(V));
88   }
89 };
90
91
92 //===----------------------------------------------------------------------===//
93 //                                MallocInst Class
94 //===----------------------------------------------------------------------===//
95
96 /// MallocInst - an instruction to allocated memory on the heap
97 ///
98 class MallocInst : public AllocationInst {
99   MallocInst(const MallocInst &MI);
100 public:
101   explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
102                       const std::string &Name = "",
103                       Instruction *InsertBefore = 0)
104     : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
105   MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
106              BasicBlock *InsertAtEnd)
107     : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
108
109   MallocInst(const Type *Ty, const std::string &Name,
110              Instruction *InsertBefore = 0)
111     : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
112   MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
113     : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
114
115   MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
116              const std::string &Name, BasicBlock *InsertAtEnd)
117     : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
118   MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
119                       const std::string &Name = "",
120                       Instruction *InsertBefore = 0)
121     : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
122
123   virtual MallocInst *clone() const;
124
125   // Methods for support type inquiry through isa, cast, and dyn_cast:
126   static inline bool classof(const MallocInst *) { return true; }
127   static inline bool classof(const Instruction *I) {
128     return (I->getOpcode() == Instruction::Malloc);
129   }
130   static inline bool classof(const Value *V) {
131     return isa<Instruction>(V) && classof(cast<Instruction>(V));
132   }
133 };
134
135
136 //===----------------------------------------------------------------------===//
137 //                                AllocaInst Class
138 //===----------------------------------------------------------------------===//
139
140 /// AllocaInst - an instruction to allocate memory on the stack
141 ///
142 class AllocaInst : public AllocationInst {
143   AllocaInst(const AllocaInst &);
144 public:
145   explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
146                       const std::string &Name = "",
147                       Instruction *InsertBefore = 0)
148     : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
149   AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
150              BasicBlock *InsertAtEnd)
151     : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
152
153   AllocaInst(const Type *Ty, const std::string &Name,
154              Instruction *InsertBefore = 0)
155     : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
156   AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
157     : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
158
159   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
160              const std::string &Name = "", Instruction *InsertBefore = 0)
161     : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
162   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
163              const std::string &Name, BasicBlock *InsertAtEnd)
164     : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
165
166   virtual AllocaInst *clone() const;
167
168   // Methods for support type inquiry through isa, cast, and dyn_cast:
169   static inline bool classof(const AllocaInst *) { return true; }
170   static inline bool classof(const Instruction *I) {
171     return (I->getOpcode() == Instruction::Alloca);
172   }
173   static inline bool classof(const Value *V) {
174     return isa<Instruction>(V) && classof(cast<Instruction>(V));
175   }
176 };
177
178
179 //===----------------------------------------------------------------------===//
180 //                                 FreeInst Class
181 //===----------------------------------------------------------------------===//
182
183 /// FreeInst - an instruction to deallocate memory
184 ///
185 class FreeInst : public UnaryInstruction {
186   void AssertOK();
187 public:
188   explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
189   FreeInst(Value *Ptr, BasicBlock *InsertAfter);
190
191   virtual FreeInst *clone() const;
192
193   virtual bool mayWriteToMemory() const { return true; }
194
195   // Methods for support type inquiry through isa, cast, and dyn_cast:
196   static inline bool classof(const FreeInst *) { return true; }
197   static inline bool classof(const Instruction *I) {
198     return (I->getOpcode() == Instruction::Free);
199   }
200   static inline bool classof(const Value *V) {
201     return isa<Instruction>(V) && classof(cast<Instruction>(V));
202   }
203 };
204
205
206 //===----------------------------------------------------------------------===//
207 //                                LoadInst Class
208 //===----------------------------------------------------------------------===//
209
210 /// LoadInst - an instruction for reading from memory.  This uses the
211 /// SubclassData field in Value to store whether or not the load is volatile.
212 ///
213 class LoadInst : public UnaryInstruction {
214   LoadInst(const LoadInst &LI)
215     : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
216     setVolatile(LI.isVolatile());
217
218 #ifndef NDEBUG
219     AssertOK();
220 #endif
221   }
222   void AssertOK();
223 public:
224   LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
225   LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
226   explicit LoadInst(Value *Ptr, const std::string &Name = "",
227                     bool isVolatile = false, Instruction *InsertBefore = 0);
228   LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
229            BasicBlock *InsertAtEnd);
230
231   /// isVolatile - Return true if this is a load from a volatile memory
232   /// location.
233   ///
234   bool isVolatile() const { return SubclassData; }
235
236   /// setVolatile - Specify whether this is a volatile load or not.
237   ///
238   void setVolatile(bool V) { SubclassData = V; }
239
240   virtual LoadInst *clone() const;
241
242   virtual bool mayWriteToMemory() const { return isVolatile(); }
243
244   Value *getPointerOperand() { return getOperand(0); }
245   const Value *getPointerOperand() const { return getOperand(0); }
246   static unsigned getPointerOperandIndex() { return 0U; }
247
248   // Methods for support type inquiry through isa, cast, and dyn_cast:
249   static inline bool classof(const LoadInst *) { return true; }
250   static inline bool classof(const Instruction *I) {
251     return I->getOpcode() == Instruction::Load;
252   }
253   static inline bool classof(const Value *V) {
254     return isa<Instruction>(V) && classof(cast<Instruction>(V));
255   }
256 };
257
258
259 //===----------------------------------------------------------------------===//
260 //                                StoreInst Class
261 //===----------------------------------------------------------------------===//
262
263 /// StoreInst - an instruction for storing to memory
264 ///
265 class StoreInst : public Instruction {
266   Use Ops[2];
267   StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
268     Ops[0].init(SI.Ops[0], this);
269     Ops[1].init(SI.Ops[1], this);
270     setVolatile(SI.isVolatile());
271 #ifndef NDEBUG
272     AssertOK();
273 #endif
274   }
275   void AssertOK();
276 public:
277   StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
278   StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
279   StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
280             Instruction *InsertBefore = 0);
281   StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
282
283
284   /// isVolatile - Return true if this is a load from a volatile memory
285   /// location.
286   ///
287   bool isVolatile() const { return SubclassData; }
288
289   /// setVolatile - Specify whether this is a volatile load or not.
290   ///
291   void setVolatile(bool V) { SubclassData = V; }
292
293   /// Transparently provide more efficient getOperand methods.
294   Value *getOperand(unsigned i) const {
295     assert(i < 2 && "getOperand() out of range!");
296     return Ops[i];
297   }
298   void setOperand(unsigned i, Value *Val) {
299     assert(i < 2 && "setOperand() out of range!");
300     Ops[i] = Val;
301   }
302   unsigned getNumOperands() const { return 2; }
303
304
305   virtual StoreInst *clone() const;
306
307   virtual bool mayWriteToMemory() const { return true; }
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, const std::vector<Value*> &Par,
699            const std::string &Name = "", Instruction *InsertBefore = 0);
700   CallInst(Value *F, const std::vector<Value*> &Par,
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   bool mayWriteToMemory() const { return true; }
720
721   bool isTailCall() const           { return SubclassData & 1; }
722   void setTailCall(bool isTailCall = true) {
723     SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
724   }
725
726   /// getCallingConv/setCallingConv - Get or set the calling convention of this
727   /// function call.
728   unsigned getCallingConv() const { return SubclassData >> 1; }
729   void setCallingConv(unsigned CC) {
730     SubclassData = (SubclassData & 1) | (CC << 1);
731   }
732
733   /// getCalledFunction - Return the function being called by this instruction
734   /// if it is a direct call.  If it is a call through a function pointer,
735   /// return null.
736   Function *getCalledFunction() const {
737     return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
738   }
739
740   /// getCalledValue - Get a pointer to the function that is invoked by this 
741   /// instruction
742   inline const Value *getCalledValue() const { return getOperand(0); }
743   inline       Value *getCalledValue()       { return getOperand(0); }
744
745   // Methods for support type inquiry through isa, cast, and dyn_cast:
746   static inline bool classof(const CallInst *) { return true; }
747   static inline bool classof(const Instruction *I) {
748     return I->getOpcode() == Instruction::Call;
749   }
750   static inline bool classof(const Value *V) {
751     return isa<Instruction>(V) && classof(cast<Instruction>(V));
752   }
753 };
754
755 //===----------------------------------------------------------------------===//
756 //                               SelectInst Class
757 //===----------------------------------------------------------------------===//
758
759 /// SelectInst - This class represents the LLVM 'select' instruction.
760 ///
761 class SelectInst : public Instruction {
762   Use Ops[3];
763
764   void init(Value *C, Value *S1, Value *S2) {
765     Ops[0].init(C, this);
766     Ops[1].init(S1, this);
767     Ops[2].init(S2, this);
768   }
769
770   SelectInst(const SelectInst &SI)
771     : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
772     init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
773   }
774 public:
775   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
776              Instruction *InsertBefore = 0)
777     : Instruction(S1->getType(), Instruction::Select, Ops, 3,
778                   Name, InsertBefore) {
779     init(C, S1, S2);
780   }
781   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
782              BasicBlock *InsertAtEnd)
783     : Instruction(S1->getType(), Instruction::Select, Ops, 3,
784                   Name, InsertAtEnd) {
785     init(C, S1, S2);
786   }
787
788   Value *getCondition() const { return Ops[0]; }
789   Value *getTrueValue() const { return Ops[1]; }
790   Value *getFalseValue() const { return Ops[2]; }
791
792   /// Transparently provide more efficient getOperand methods.
793   Value *getOperand(unsigned i) const {
794     assert(i < 3 && "getOperand() out of range!");
795     return Ops[i];
796   }
797   void setOperand(unsigned i, Value *Val) {
798     assert(i < 3 && "setOperand() out of range!");
799     Ops[i] = Val;
800   }
801   unsigned getNumOperands() const { return 3; }
802
803   OtherOps getOpcode() const {
804     return static_cast<OtherOps>(Instruction::getOpcode());
805   }
806
807   virtual SelectInst *clone() const;
808
809   // Methods for support type inquiry through isa, cast, and dyn_cast:
810   static inline bool classof(const SelectInst *) { return true; }
811   static inline bool classof(const Instruction *I) {
812     return I->getOpcode() == Instruction::Select;
813   }
814   static inline bool classof(const Value *V) {
815     return isa<Instruction>(V) && classof(cast<Instruction>(V));
816   }
817 };
818
819 //===----------------------------------------------------------------------===//
820 //                                VAArgInst Class
821 //===----------------------------------------------------------------------===//
822
823 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
824 /// an argument of the specified type given a va_list and increments that list
825 ///
826 class VAArgInst : public UnaryInstruction {
827   VAArgInst(const VAArgInst &VAA)
828     : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
829 public:
830   VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
831              Instruction *InsertBefore = 0)
832     : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
833   }
834   VAArgInst(Value *List, const Type *Ty, const std::string &Name,
835             BasicBlock *InsertAtEnd)
836     : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
837   }
838
839   virtual VAArgInst *clone() const;
840   bool mayWriteToMemory() const { return true; }
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 PackedType 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   virtual bool mayWriteToMemory() const { return false; }
884
885   /// Transparently provide more efficient getOperand methods.
886   Value *getOperand(unsigned i) const {
887     assert(i < 2 && "getOperand() out of range!");
888     return Ops[i];
889   }
890   void setOperand(unsigned i, Value *Val) {
891     assert(i < 2 && "setOperand() out of range!");
892     Ops[i] = Val;
893   }
894   unsigned getNumOperands() const { return 2; }
895
896   // Methods for support type inquiry through isa, cast, and dyn_cast:
897   static inline bool classof(const ExtractElementInst *) { return true; }
898   static inline bool classof(const Instruction *I) {
899     return I->getOpcode() == Instruction::ExtractElement;
900   }
901   static inline bool classof(const Value *V) {
902     return isa<Instruction>(V) && classof(cast<Instruction>(V));
903   }
904 };
905
906 //===----------------------------------------------------------------------===//
907 //                                InsertElementInst Class
908 //===----------------------------------------------------------------------===//
909
910 /// InsertElementInst - This instruction inserts a single (scalar)
911 /// element into a PackedType value
912 ///
913 class InsertElementInst : public Instruction {
914   Use Ops[3];
915   InsertElementInst(const InsertElementInst &IE);
916 public:
917   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
918                     const std::string &Name = "",Instruction *InsertBefore = 0);
919   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
920                     const std::string &Name = "",Instruction *InsertBefore = 0);
921   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
922                     const std::string &Name, BasicBlock *InsertAtEnd);
923   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
924                     const std::string &Name, BasicBlock *InsertAtEnd);
925
926   /// isValidOperands - Return true if an insertelement instruction can be
927   /// formed with the specified operands.
928   static bool isValidOperands(const Value *Vec, const Value *NewElt,
929                               const Value *Idx);
930
931   virtual InsertElementInst *clone() const;
932
933   virtual bool mayWriteToMemory() const { return false; }
934
935   /// getType - Overload to return most specific packed type.
936   ///
937   inline const PackedType *getType() const {
938     return reinterpret_cast<const PackedType*>(Instruction::getType());
939   }
940
941   /// Transparently provide more efficient getOperand methods.
942   Value *getOperand(unsigned i) const {
943     assert(i < 3 && "getOperand() out of range!");
944     return Ops[i];
945   }
946   void setOperand(unsigned i, Value *Val) {
947     assert(i < 3 && "setOperand() out of range!");
948     Ops[i] = Val;
949   }
950   unsigned getNumOperands() const { return 3; }
951
952   // Methods for support type inquiry through isa, cast, and dyn_cast:
953   static inline bool classof(const InsertElementInst *) { return true; }
954   static inline bool classof(const Instruction *I) {
955     return I->getOpcode() == Instruction::InsertElement;
956   }
957   static inline bool classof(const Value *V) {
958     return isa<Instruction>(V) && classof(cast<Instruction>(V));
959   }
960 };
961
962 //===----------------------------------------------------------------------===//
963 //                           ShuffleVectorInst Class
964 //===----------------------------------------------------------------------===//
965
966 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
967 /// input vectors.
968 ///
969 class ShuffleVectorInst : public Instruction {
970   Use Ops[3];
971   ShuffleVectorInst(const ShuffleVectorInst &IE);
972 public:
973   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
974                     const std::string &Name = "", Instruction *InsertBefor = 0);
975   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
976                     const std::string &Name, BasicBlock *InsertAtEnd);
977
978   /// isValidOperands - Return true if a shufflevector instruction can be
979   /// formed with the specified operands.
980   static bool isValidOperands(const Value *V1, const Value *V2,
981                               const Value *Mask);
982
983   virtual ShuffleVectorInst *clone() const;
984
985   virtual bool mayWriteToMemory() const { return false; }
986
987   /// getType - Overload to return most specific packed type.
988   ///
989   inline const PackedType *getType() const {
990     return reinterpret_cast<const PackedType*>(Instruction::getType());
991   }
992
993   /// Transparently provide more efficient getOperand methods.
994   Value *getOperand(unsigned i) const {
995     assert(i < 3 && "getOperand() out of range!");
996     return Ops[i];
997   }
998   void setOperand(unsigned i, Value *Val) {
999     assert(i < 3 && "setOperand() out of range!");
1000     Ops[i] = Val;
1001   }
1002   unsigned getNumOperands() const { return 3; }
1003
1004   // Methods for support type inquiry through isa, cast, and dyn_cast:
1005   static inline bool classof(const ShuffleVectorInst *) { return true; }
1006   static inline bool classof(const Instruction *I) {
1007     return I->getOpcode() == Instruction::ShuffleVector;
1008   }
1009   static inline bool classof(const Value *V) {
1010     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1011   }
1012 };
1013
1014
1015 //===----------------------------------------------------------------------===//
1016 //                               PHINode Class
1017 //===----------------------------------------------------------------------===//
1018
1019 // PHINode - The PHINode class is used to represent the magical mystical PHI
1020 // node, that can not exist in nature, but can be synthesized in a computer
1021 // scientist's overactive imagination.
1022 //
1023 class PHINode : public Instruction {
1024   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1025   /// the number actually in use.
1026   unsigned ReservedSpace;
1027   PHINode(const PHINode &PN);
1028 public:
1029   explicit PHINode(const Type *Ty, const std::string &Name = "",
1030                    Instruction *InsertBefore = 0)
1031     : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
1032       ReservedSpace(0) {
1033   }
1034
1035   PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1036     : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
1037       ReservedSpace(0) {
1038   }
1039
1040   ~PHINode();
1041
1042   /// reserveOperandSpace - This method can be used to avoid repeated
1043   /// reallocation of PHI operand lists by reserving space for the correct
1044   /// number of operands before adding them.  Unlike normal vector reserves,
1045   /// this method can also be used to trim the operand space.
1046   void reserveOperandSpace(unsigned NumValues) {
1047     resizeOperands(NumValues*2);
1048   }
1049
1050   virtual PHINode *clone() const;
1051
1052   /// getNumIncomingValues - Return the number of incoming edges
1053   ///
1054   unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1055
1056   /// getIncomingValue - Return incoming value number x
1057   ///
1058   Value *getIncomingValue(unsigned i) const {
1059     assert(i*2 < getNumOperands() && "Invalid value number!");
1060     return getOperand(i*2);
1061   }
1062   void setIncomingValue(unsigned i, Value *V) {
1063     assert(i*2 < getNumOperands() && "Invalid value number!");
1064     setOperand(i*2, V);
1065   }
1066   unsigned getOperandNumForIncomingValue(unsigned i) {
1067     return i*2;
1068   }
1069
1070   /// getIncomingBlock - Return incoming basic block number x
1071   ///
1072   BasicBlock *getIncomingBlock(unsigned i) const {
1073     return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1074   }
1075   void setIncomingBlock(unsigned i, BasicBlock *BB) {
1076     setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1077   }
1078   unsigned getOperandNumForIncomingBlock(unsigned i) {
1079     return i*2+1;
1080   }
1081
1082   /// addIncoming - Add an incoming value to the end of the PHI list
1083   ///
1084   void addIncoming(Value *V, BasicBlock *BB) {
1085     assert(getType() == V->getType() &&
1086            "All operands to PHI node must be the same type as the PHI node!");
1087     unsigned OpNo = NumOperands;
1088     if (OpNo+2 > ReservedSpace)
1089       resizeOperands(0);  // Get more space!
1090     // Initialize some new operands.
1091     NumOperands = OpNo+2;
1092     OperandList[OpNo].init(V, this);
1093     OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1094   }
1095
1096   /// removeIncomingValue - Remove an incoming value.  This is useful if a
1097   /// predecessor basic block is deleted.  The value removed is returned.
1098   ///
1099   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1100   /// is true), the PHI node is destroyed and any uses of it are replaced with
1101   /// dummy values.  The only time there should be zero incoming values to a PHI
1102   /// node is when the block is dead, so this strategy is sound.
1103   ///
1104   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1105
1106   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1107     int Idx = getBasicBlockIndex(BB);
1108     assert(Idx >= 0 && "Invalid basic block argument to remove!");
1109     return removeIncomingValue(Idx, DeletePHIIfEmpty);
1110   }
1111
1112   /// getBasicBlockIndex - Return the first index of the specified basic
1113   /// block in the value list for this PHI.  Returns -1 if no instance.
1114   ///
1115   int getBasicBlockIndex(const BasicBlock *BB) const {
1116     Use *OL = OperandList;
1117     for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1118       if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1119     return -1;
1120   }
1121
1122   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1123     return getIncomingValue(getBasicBlockIndex(BB));
1124   }
1125
1126   /// hasConstantValue - If the specified PHI node always merges together the
1127   /// same value, return the value, otherwise return null.
1128   ///
1129   Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1130
1131   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1132   static inline bool classof(const PHINode *) { return true; }
1133   static inline bool classof(const Instruction *I) {
1134     return I->getOpcode() == Instruction::PHI;
1135   }
1136   static inline bool classof(const Value *V) {
1137     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1138   }
1139  private:
1140   void resizeOperands(unsigned NumOperands);
1141 };
1142
1143 //===----------------------------------------------------------------------===//
1144 //                               ReturnInst Class
1145 //===----------------------------------------------------------------------===//
1146
1147 //===---------------------------------------------------------------------------
1148 /// ReturnInst - Return a value (possibly void), from a function.  Execution
1149 /// does not continue in this function any longer.
1150 ///
1151 class ReturnInst : public TerminatorInst {
1152   Use RetVal;  // Possibly null retval.
1153   ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
1154                                                     RI.getNumOperands()) {
1155     if (RI.getNumOperands())
1156       RetVal.init(RI.RetVal, this);
1157   }
1158
1159   void init(Value *RetVal);
1160
1161 public:
1162   // ReturnInst constructors:
1163   // ReturnInst()                  - 'ret void' instruction
1164   // ReturnInst(    null)          - 'ret void' instruction
1165   // ReturnInst(Value* X)          - 'ret X'    instruction
1166   // ReturnInst(    null, Inst *)  - 'ret void' instruction, insert before I
1167   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
1168   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of BB
1169   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of BB
1170   //
1171   // NOTE: If the Value* passed is of type void then the constructor behaves as
1172   // if it was passed NULL.
1173   explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
1174     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
1175     init(retVal);
1176   }
1177   ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
1178     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1179     init(retVal);
1180   }
1181   explicit ReturnInst(BasicBlock *InsertAtEnd)
1182     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1183   }
1184
1185   virtual ReturnInst *clone() const;
1186
1187   // Transparently provide more efficient getOperand methods.
1188   Value *getOperand(unsigned i) const {
1189     assert(i < getNumOperands() && "getOperand() out of range!");
1190     return RetVal;
1191   }
1192   void setOperand(unsigned i, Value *Val) {
1193     assert(i < getNumOperands() && "setOperand() out of range!");
1194     RetVal = Val;
1195   }
1196
1197   Value *getReturnValue() const { return RetVal; }
1198
1199   unsigned getNumSuccessors() const { return 0; }
1200
1201   // Methods for support type inquiry through isa, cast, and dyn_cast:
1202   static inline bool classof(const ReturnInst *) { return true; }
1203   static inline bool classof(const Instruction *I) {
1204     return (I->getOpcode() == Instruction::Ret);
1205   }
1206   static inline bool classof(const Value *V) {
1207     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1208   }
1209  private:
1210   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1211   virtual unsigned getNumSuccessorsV() const;
1212   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1213 };
1214
1215 //===----------------------------------------------------------------------===//
1216 //                               BranchInst Class
1217 //===----------------------------------------------------------------------===//
1218
1219 //===---------------------------------------------------------------------------
1220 /// BranchInst - Conditional or Unconditional Branch instruction.
1221 ///
1222 class BranchInst : public TerminatorInst {
1223   /// Ops list - Branches are strange.  The operands are ordered:
1224   ///  TrueDest, FalseDest, Cond.  This makes some accessors faster because
1225   /// they don't have to check for cond/uncond branchness.
1226   Use Ops[3];
1227   BranchInst(const BranchInst &BI);
1228   void AssertOK();
1229 public:
1230   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1231   // BranchInst(BB *B)                           - 'br B'
1232   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
1233   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
1234   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1235   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
1236   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
1237   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1238     : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1239     assert(IfTrue != 0 && "Branch destination may not be null!");
1240     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1241   }
1242   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1243              Instruction *InsertBefore = 0)
1244     : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1245     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1246     Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1247     Ops[2].init(Cond, this);
1248 #ifndef NDEBUG
1249     AssertOK();
1250 #endif
1251   }
1252
1253   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1254     : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1255     assert(IfTrue != 0 && "Branch destination may not be null!");
1256     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1257   }
1258
1259   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1260              BasicBlock *InsertAtEnd)
1261     : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1262     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1263     Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1264     Ops[2].init(Cond, this);
1265 #ifndef NDEBUG
1266     AssertOK();
1267 #endif
1268   }
1269
1270
1271   /// Transparently provide more efficient getOperand methods.
1272   Value *getOperand(unsigned i) const {
1273     assert(i < getNumOperands() && "getOperand() out of range!");
1274     return Ops[i];
1275   }
1276   void setOperand(unsigned i, Value *Val) {
1277     assert(i < getNumOperands() && "setOperand() out of range!");
1278     Ops[i] = Val;
1279   }
1280
1281   virtual BranchInst *clone() const;
1282
1283   inline bool isUnconditional() const { return getNumOperands() == 1; }
1284   inline bool isConditional()   const { return getNumOperands() == 3; }
1285
1286   inline Value *getCondition() const {
1287     assert(isConditional() && "Cannot get condition of an uncond branch!");
1288     return getOperand(2);
1289   }
1290
1291   void setCondition(Value *V) {
1292     assert(isConditional() && "Cannot set condition of unconditional branch!");
1293     setOperand(2, V);
1294   }
1295
1296   // setUnconditionalDest - Change the current branch to an unconditional branch
1297   // targeting the specified block.
1298   // FIXME: Eliminate this ugly method.
1299   void setUnconditionalDest(BasicBlock *Dest) {
1300     if (isConditional()) {  // Convert this to an uncond branch.
1301       NumOperands = 1;
1302       Ops[1].set(0);
1303       Ops[2].set(0);
1304     }
1305     setOperand(0, reinterpret_cast<Value*>(Dest));
1306   }
1307
1308   unsigned getNumSuccessors() const { return 1+isConditional(); }
1309
1310   BasicBlock *getSuccessor(unsigned i) const {
1311     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1312     return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1313                       cast<BasicBlock>(getOperand(1));
1314   }
1315
1316   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1317     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1318     setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1319   }
1320
1321   // Methods for support type inquiry through isa, cast, and dyn_cast:
1322   static inline bool classof(const BranchInst *) { return true; }
1323   static inline bool classof(const Instruction *I) {
1324     return (I->getOpcode() == Instruction::Br);
1325   }
1326   static inline bool classof(const Value *V) {
1327     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1328   }
1329 private:
1330   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1331   virtual unsigned getNumSuccessorsV() const;
1332   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1333 };
1334
1335 //===----------------------------------------------------------------------===//
1336 //                               SwitchInst Class
1337 //===----------------------------------------------------------------------===//
1338
1339 //===---------------------------------------------------------------------------
1340 /// SwitchInst - Multiway switch
1341 ///
1342 class SwitchInst : public TerminatorInst {
1343   unsigned ReservedSpace;
1344   // Operand[0]    = Value to switch on
1345   // Operand[1]    = Default basic block destination
1346   // Operand[2n  ] = Value to match
1347   // Operand[2n+1] = BasicBlock to go to on match
1348   SwitchInst(const SwitchInst &RI);
1349   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1350   void resizeOperands(unsigned No);
1351 public:
1352   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1353   /// switch on and a default destination.  The number of additional cases can
1354   /// be specified here to make memory allocation more efficient.  This
1355   /// constructor can also autoinsert before another instruction.
1356   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1357              Instruction *InsertBefore = 0)
1358     : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1359     init(Value, Default, NumCases);
1360   }
1361
1362   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1363   /// switch on and a default destination.  The number of additional cases can
1364   /// be specified here to make memory allocation more efficient.  This
1365   /// constructor also autoinserts at the end of the specified BasicBlock.
1366   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1367              BasicBlock *InsertAtEnd)
1368     : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1369     init(Value, Default, NumCases);
1370   }
1371   ~SwitchInst();
1372
1373
1374   // Accessor Methods for Switch stmt
1375   inline Value *getCondition() const { return getOperand(0); }
1376   void setCondition(Value *V) { setOperand(0, V); }
1377
1378   inline BasicBlock *getDefaultDest() const {
1379     return cast<BasicBlock>(getOperand(1));
1380   }
1381
1382   /// getNumCases - return the number of 'cases' in this switch instruction.
1383   /// Note that case #0 is always the default case.
1384   unsigned getNumCases() const {
1385     return getNumOperands()/2;
1386   }
1387
1388   /// getCaseValue - Return the specified case value.  Note that case #0, the
1389   /// default destination, does not have a case value.
1390   ConstantInt *getCaseValue(unsigned i) {
1391     assert(i && i < getNumCases() && "Illegal case value to get!");
1392     return getSuccessorValue(i);
1393   }
1394
1395   /// getCaseValue - Return the specified case value.  Note that case #0, the
1396   /// default destination, does not have a case value.
1397   const ConstantInt *getCaseValue(unsigned i) const {
1398     assert(i && i < getNumCases() && "Illegal case value to get!");
1399     return getSuccessorValue(i);
1400   }
1401
1402   /// findCaseValue - Search all of the case values for the specified constant.
1403   /// If it is explicitly handled, return the case number of it, otherwise
1404   /// return 0 to indicate that it is handled by the default handler.
1405   unsigned findCaseValue(const ConstantInt *C) const {
1406     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1407       if (getCaseValue(i) == C)
1408         return i;
1409     return 0;
1410   }
1411
1412   /// findCaseDest - Finds the unique case value for a given successor. Returns
1413   /// null if the successor is not found, not unique, or is the default case.
1414   ConstantInt *findCaseDest(BasicBlock *BB) {
1415     if (BB == getDefaultDest()) return NULL;
1416
1417     ConstantInt *CI = NULL;
1418     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1419       if (getSuccessor(i) == BB) {
1420         if (CI) return NULL;   // Multiple cases lead to BB.
1421         else CI = getCaseValue(i);
1422       }
1423     }
1424     return CI;
1425   }
1426
1427   /// addCase - Add an entry to the switch instruction...
1428   ///
1429   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1430
1431   /// removeCase - This method removes the specified successor from the switch
1432   /// instruction.  Note that this cannot be used to remove the default
1433   /// destination (successor #0).
1434   ///
1435   void removeCase(unsigned idx);
1436
1437   virtual SwitchInst *clone() const;
1438
1439   unsigned getNumSuccessors() const { return getNumOperands()/2; }
1440   BasicBlock *getSuccessor(unsigned idx) const {
1441     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1442     return cast<BasicBlock>(getOperand(idx*2+1));
1443   }
1444   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1445     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1446     setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1447   }
1448
1449   // getSuccessorValue - Return the value associated with the specified
1450   // successor.
1451   inline ConstantInt *getSuccessorValue(unsigned idx) const {
1452     assert(idx < getNumSuccessors() && "Successor # out of range!");
1453     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1454   }
1455
1456   // Methods for support type inquiry through isa, cast, and dyn_cast:
1457   static inline bool classof(const SwitchInst *) { return true; }
1458   static inline bool classof(const Instruction *I) {
1459     return I->getOpcode() == Instruction::Switch;
1460   }
1461   static inline bool classof(const Value *V) {
1462     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1463   }
1464 private:
1465   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1466   virtual unsigned getNumSuccessorsV() const;
1467   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1468 };
1469
1470 //===----------------------------------------------------------------------===//
1471 //                               InvokeInst Class
1472 //===----------------------------------------------------------------------===//
1473
1474 //===---------------------------------------------------------------------------
1475
1476 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
1477 /// calling convention of the call.
1478 ///
1479 class InvokeInst : public TerminatorInst {
1480   InvokeInst(const InvokeInst &BI);
1481   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1482             const std::vector<Value*> &Params);
1483 public:
1484   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1485              const std::vector<Value*> &Params, const std::string &Name = "",
1486              Instruction *InsertBefore = 0);
1487   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1488              const std::vector<Value*> &Params, const std::string &Name,
1489              BasicBlock *InsertAtEnd);
1490   ~InvokeInst();
1491
1492   virtual InvokeInst *clone() const;
1493
1494   bool mayWriteToMemory() const { return true; }
1495
1496   /// getCallingConv/setCallingConv - Get or set the calling convention of this
1497   /// function call.
1498   unsigned getCallingConv() const { return SubclassData; }
1499   void setCallingConv(unsigned CC) {
1500     SubclassData = CC;
1501   }
1502
1503   /// getCalledFunction - Return the function called, or null if this is an
1504   /// indirect function invocation.
1505   ///
1506   Function *getCalledFunction() const {
1507     return dyn_cast<Function>(getOperand(0));
1508   }
1509
1510   // getCalledValue - Get a pointer to a function that is invoked by this inst.
1511   inline Value *getCalledValue() const { return getOperand(0); }
1512
1513   // get*Dest - Return the destination basic blocks...
1514   BasicBlock *getNormalDest() const {
1515     return cast<BasicBlock>(getOperand(1));
1516   }
1517   BasicBlock *getUnwindDest() const {
1518     return cast<BasicBlock>(getOperand(2));
1519   }
1520   void setNormalDest(BasicBlock *B) {
1521     setOperand(1, reinterpret_cast<Value*>(B));
1522   }
1523
1524   void setUnwindDest(BasicBlock *B) {
1525     setOperand(2, reinterpret_cast<Value*>(B));
1526   }
1527
1528   inline BasicBlock *getSuccessor(unsigned i) const {
1529     assert(i < 2 && "Successor # out of range for invoke!");
1530     return i == 0 ? getNormalDest() : getUnwindDest();
1531   }
1532
1533   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1534     assert(idx < 2 && "Successor # out of range for invoke!");
1535     setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1536   }
1537
1538   unsigned getNumSuccessors() const { return 2; }
1539
1540   // Methods for support type inquiry through isa, cast, and dyn_cast:
1541   static inline bool classof(const InvokeInst *) { return true; }
1542   static inline bool classof(const Instruction *I) {
1543     return (I->getOpcode() == Instruction::Invoke);
1544   }
1545   static inline bool classof(const Value *V) {
1546     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1547   }
1548 private:
1549   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1550   virtual unsigned getNumSuccessorsV() const;
1551   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1552 };
1553
1554
1555 //===----------------------------------------------------------------------===//
1556 //                              UnwindInst Class
1557 //===----------------------------------------------------------------------===//
1558
1559 //===---------------------------------------------------------------------------
1560 /// UnwindInst - Immediately exit the current function, unwinding the stack
1561 /// until an invoke instruction is found.
1562 ///
1563 class UnwindInst : public TerminatorInst {
1564 public:
1565   explicit UnwindInst(Instruction *InsertBefore = 0)
1566     : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1567   }
1568   explicit UnwindInst(BasicBlock *InsertAtEnd)
1569     : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1570   }
1571
1572   virtual UnwindInst *clone() const;
1573
1574   unsigned getNumSuccessors() const { return 0; }
1575
1576   // Methods for support type inquiry through isa, cast, and dyn_cast:
1577   static inline bool classof(const UnwindInst *) { return true; }
1578   static inline bool classof(const Instruction *I) {
1579     return I->getOpcode() == Instruction::Unwind;
1580   }
1581   static inline bool classof(const Value *V) {
1582     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1583   }
1584 private:
1585   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1586   virtual unsigned getNumSuccessorsV() const;
1587   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1588 };
1589
1590 //===----------------------------------------------------------------------===//
1591 //                           UnreachableInst Class
1592 //===----------------------------------------------------------------------===//
1593
1594 //===---------------------------------------------------------------------------
1595 /// UnreachableInst - This function has undefined behavior.  In particular, the
1596 /// presence of this instruction indicates some higher level knowledge that the
1597 /// end of the block cannot be reached.
1598 ///
1599 class UnreachableInst : public TerminatorInst {
1600 public:
1601   explicit UnreachableInst(Instruction *InsertBefore = 0)
1602     : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1603   }
1604   explicit UnreachableInst(BasicBlock *InsertAtEnd)
1605     : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1606   }
1607
1608   virtual UnreachableInst *clone() const;
1609
1610   unsigned getNumSuccessors() const { return 0; }
1611
1612   // Methods for support type inquiry through isa, cast, and dyn_cast:
1613   static inline bool classof(const UnreachableInst *) { return true; }
1614   static inline bool classof(const Instruction *I) {
1615     return I->getOpcode() == Instruction::Unreachable;
1616   }
1617   static inline bool classof(const Value *V) {
1618     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1619   }
1620 private:
1621   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1622   virtual unsigned getNumSuccessorsV() const;
1623   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1624 };
1625
1626 //===----------------------------------------------------------------------===//
1627 //                                 TruncInst Class
1628 //===----------------------------------------------------------------------===//
1629
1630 /// @brief This class represents a truncation of integer types.
1631 class TruncInst : public CastInst {
1632   /// Private copy constructor
1633   TruncInst(const TruncInst &CI)
1634     : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1635   }
1636 public:
1637   /// @brief Constructor with insert-before-instruction 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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1643   );
1644
1645   /// @brief Constructor with insert-at-end-of-block semantics
1646   TruncInst(
1647     Value *S,                     ///< The value to be truncated
1648     const Type *Ty,               ///< The (smaller) type to truncate to
1649     const std::string &Name,      ///< A name for the new instruction
1650     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1651   );
1652
1653   /// @brief Clone an identical TruncInst
1654   virtual CastInst *clone() const;
1655
1656   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1657   static inline bool classof(const TruncInst *) { return true; }
1658   static inline bool classof(const Instruction *I) {
1659     return I->getOpcode() == Trunc;
1660   }
1661   static inline bool classof(const Value *V) {
1662     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1663   }
1664 };
1665
1666 //===----------------------------------------------------------------------===//
1667 //                                 ZExtInst Class
1668 //===----------------------------------------------------------------------===//
1669
1670 /// @brief This class represents zero extension of integer types.
1671 class ZExtInst : public CastInst {
1672   /// @brief Private copy constructor
1673   ZExtInst(const ZExtInst &CI)
1674     : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1675   }
1676 public:
1677   /// @brief Constructor with insert-before-instruction 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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1683   );
1684
1685   /// @brief Constructor with insert-at-end semantics.
1686   ZExtInst(
1687     Value *S,                     ///< The value to be zero extended
1688     const Type *Ty,               ///< The type to zero extend to
1689     const std::string &Name,      ///< A name for the new instruction
1690     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1691   );
1692
1693   /// @brief Clone an identical ZExtInst
1694   virtual CastInst *clone() const;
1695
1696   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1697   static inline bool classof(const ZExtInst *) { return true; }
1698   static inline bool classof(const Instruction *I) {
1699     return I->getOpcode() == ZExt;
1700   }
1701   static inline bool classof(const Value *V) {
1702     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1703   }
1704 };
1705
1706 //===----------------------------------------------------------------------===//
1707 //                                 SExtInst Class
1708 //===----------------------------------------------------------------------===//
1709
1710 /// @brief This class represents a sign extension of integer types.
1711 class SExtInst : public CastInst {
1712   /// @brief Private copy constructor
1713   SExtInst(const SExtInst &CI)
1714     : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1715   }
1716 public:
1717   /// @brief Constructor with insert-before-instruction 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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1723   );
1724
1725   /// @brief Constructor with insert-at-end-of-block semantics
1726   SExtInst(
1727     Value *S,                     ///< The value to be sign extended
1728     const Type *Ty,               ///< The type to sign extend to
1729     const std::string &Name,      ///< A name for the new instruction
1730     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1731   );
1732
1733   /// @brief Clone an identical SExtInst
1734   virtual CastInst *clone() const;
1735
1736   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1737   static inline bool classof(const SExtInst *) { return true; }
1738   static inline bool classof(const Instruction *I) {
1739     return I->getOpcode() == SExt;
1740   }
1741   static inline bool classof(const Value *V) {
1742     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1743   }
1744 };
1745
1746 //===----------------------------------------------------------------------===//
1747 //                                 FPTruncInst Class
1748 //===----------------------------------------------------------------------===//
1749
1750 /// @brief This class represents a truncation of floating point types.
1751 class FPTruncInst : public CastInst {
1752   FPTruncInst(const FPTruncInst &CI)
1753     : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1754   }
1755 public:
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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1762   );
1763
1764   /// @brief Constructor with insert-before-instruction semantics
1765   FPTruncInst(
1766     Value *S,                     ///< The value to be truncated
1767     const Type *Ty,               ///< The type to truncate to
1768     const std::string &Name,      ///< A name for the new instruction
1769     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1770   );
1771
1772   /// @brief Clone an identical FPTruncInst
1773   virtual CastInst *clone() const;
1774
1775   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1776   static inline bool classof(const FPTruncInst *) { return true; }
1777   static inline bool classof(const Instruction *I) {
1778     return I->getOpcode() == FPTrunc;
1779   }
1780   static inline bool classof(const Value *V) {
1781     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1782   }
1783 };
1784
1785 //===----------------------------------------------------------------------===//
1786 //                                 FPExtInst Class
1787 //===----------------------------------------------------------------------===//
1788
1789 /// @brief This class represents an extension of floating point types.
1790 class FPExtInst : public CastInst {
1791   FPExtInst(const FPExtInst &CI)
1792     : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1793   }
1794 public:
1795   /// @brief Constructor with insert-before-instruction 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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1801   );
1802
1803   /// @brief Constructor with insert-at-end-of-block semantics
1804   FPExtInst(
1805     Value *S,                     ///< The value to be extended
1806     const Type *Ty,               ///< The type to extend to
1807     const std::string &Name,      ///< A name for the new instruction
1808     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1809   );
1810
1811   /// @brief Clone an identical FPExtInst
1812   virtual CastInst *clone() const;
1813
1814   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1815   static inline bool classof(const FPExtInst *) { return true; }
1816   static inline bool classof(const Instruction *I) {
1817     return I->getOpcode() == FPExt;
1818   }
1819   static inline bool classof(const Value *V) {
1820     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1821   }
1822 };
1823
1824 //===----------------------------------------------------------------------===//
1825 //                                 UIToFPInst Class
1826 //===----------------------------------------------------------------------===//
1827
1828 /// @brief This class represents a cast unsigned integer to floating point.
1829 class UIToFPInst : public CastInst {
1830   UIToFPInst(const UIToFPInst &CI)
1831     : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1832   }
1833 public:
1834   /// @brief Constructor with insert-before-instruction 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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1840   );
1841
1842   /// @brief Constructor with insert-at-end-of-block semantics
1843   UIToFPInst(
1844     Value *S,                     ///< The value to be converted
1845     const Type *Ty,               ///< The type to convert to
1846     const std::string &Name,      ///< A name for the new instruction
1847     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1848   );
1849
1850   /// @brief Clone an identical UIToFPInst
1851   virtual CastInst *clone() const;
1852
1853   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1854   static inline bool classof(const UIToFPInst *) { return true; }
1855   static inline bool classof(const Instruction *I) {
1856     return I->getOpcode() == UIToFP;
1857   }
1858   static inline bool classof(const Value *V) {
1859     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1860   }
1861 };
1862
1863 //===----------------------------------------------------------------------===//
1864 //                                 SIToFPInst Class
1865 //===----------------------------------------------------------------------===//
1866
1867 /// @brief This class represents a cast from signed integer to floating point.
1868 class SIToFPInst : public CastInst {
1869   SIToFPInst(const SIToFPInst &CI)
1870     : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1871   }
1872 public:
1873   /// @brief Constructor with insert-before-instruction 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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1879   );
1880
1881   /// @brief Constructor with insert-at-end-of-block semantics
1882   SIToFPInst(
1883     Value *S,                     ///< The value to be converted
1884     const Type *Ty,               ///< The type to convert to
1885     const std::string &Name,      ///< A name for the new instruction
1886     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1887   );
1888
1889   /// @brief Clone an identical SIToFPInst
1890   virtual CastInst *clone() const;
1891
1892   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1893   static inline bool classof(const SIToFPInst *) { return true; }
1894   static inline bool classof(const Instruction *I) {
1895     return I->getOpcode() == SIToFP;
1896   }
1897   static inline bool classof(const Value *V) {
1898     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1899   }
1900 };
1901
1902 //===----------------------------------------------------------------------===//
1903 //                                 FPToUIInst Class
1904 //===----------------------------------------------------------------------===//
1905
1906 /// @brief This class represents a cast from floating point to unsigned integer
1907 class FPToUIInst  : public CastInst {
1908   FPToUIInst(const FPToUIInst &CI)
1909     : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1910   }
1911 public:
1912   /// @brief Constructor with insert-before-instruction 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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1918   );
1919
1920   /// @brief Constructor with insert-at-end-of-block semantics
1921   FPToUIInst(
1922     Value *S,                     ///< The value to be converted
1923     const Type *Ty,               ///< The type to convert to
1924     const std::string &Name,      ///< A name for the new instruction
1925     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
1926   );
1927
1928   /// @brief Clone an identical FPToUIInst
1929   virtual CastInst *clone() const;
1930
1931   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1932   static inline bool classof(const FPToUIInst *) { return true; }
1933   static inline bool classof(const Instruction *I) {
1934     return I->getOpcode() == FPToUI;
1935   }
1936   static inline bool classof(const Value *V) {
1937     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1938   }
1939 };
1940
1941 //===----------------------------------------------------------------------===//
1942 //                                 FPToSIInst Class
1943 //===----------------------------------------------------------------------===//
1944
1945 /// @brief This class represents a cast from floating point to signed integer.
1946 class FPToSIInst  : public CastInst {
1947   FPToSIInst(const FPToSIInst &CI)
1948     : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1949   }
1950 public:
1951   /// @brief Constructor with insert-before-instruction 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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1957   );
1958
1959   /// @brief Constructor with insert-at-end-of-block semantics
1960   FPToSIInst(
1961     Value *S,                     ///< The value to be converted
1962     const Type *Ty,               ///< The type to convert to
1963     const std::string &Name,      ///< A name for the new instruction
1964     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1965   );
1966
1967   /// @brief Clone an identical FPToSIInst
1968   virtual CastInst *clone() const;
1969
1970   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1971   static inline bool classof(const FPToSIInst *) { return true; }
1972   static inline bool classof(const Instruction *I) {
1973     return I->getOpcode() == FPToSI;
1974   }
1975   static inline bool classof(const Value *V) {
1976     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1977   }
1978 };
1979
1980 //===----------------------------------------------------------------------===//
1981 //                                 IntToPtrInst Class
1982 //===----------------------------------------------------------------------===//
1983
1984 /// @brief This class represents a cast from an integer to a pointer.
1985 class IntToPtrInst : public CastInst {
1986   IntToPtrInst(const IntToPtrInst &CI)
1987     : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1988   }
1989 public:
1990   /// @brief Constructor with insert-before-instruction 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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1996   );
1997
1998   /// @brief Constructor with insert-at-end-of-block semantics
1999   IntToPtrInst(
2000     Value *S,                     ///< The value to be converted
2001     const Type *Ty,               ///< The type to convert to
2002     const std::string &Name,      ///< A name for the new instruction
2003     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2004   );
2005
2006   /// @brief Clone an identical IntToPtrInst
2007   virtual CastInst *clone() const;
2008
2009   // Methods for support type inquiry through isa, cast, and dyn_cast:
2010   static inline bool classof(const IntToPtrInst *) { return true; }
2011   static inline bool classof(const Instruction *I) {
2012     return I->getOpcode() == IntToPtr;
2013   }
2014   static inline bool classof(const Value *V) {
2015     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2016   }
2017 };
2018
2019 //===----------------------------------------------------------------------===//
2020 //                                 PtrToIntInst Class
2021 //===----------------------------------------------------------------------===//
2022
2023 /// @brief This class represents a cast from a pointer to an integer
2024 class PtrToIntInst : public CastInst {
2025   PtrToIntInst(const PtrToIntInst &CI)
2026     : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2027   }
2028 public:
2029   /// @brief Constructor with insert-before-instruction 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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2035   );
2036
2037   /// @brief Constructor with insert-at-end-of-block semantics
2038   PtrToIntInst(
2039     Value *S,                     ///< The value to be converted
2040     const Type *Ty,               ///< The type to convert to
2041     const std::string &Name,      ///< A name for the new instruction
2042     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2043   );
2044
2045   /// @brief Clone an identical PtrToIntInst
2046   virtual CastInst *clone() const;
2047
2048   // Methods for support type inquiry through isa, cast, and dyn_cast:
2049   static inline bool classof(const PtrToIntInst *) { return true; }
2050   static inline bool classof(const Instruction *I) {
2051     return I->getOpcode() == PtrToInt;
2052   }
2053   static inline bool classof(const Value *V) {
2054     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2055   }
2056 };
2057
2058 //===----------------------------------------------------------------------===//
2059 //                             BitCastInst Class
2060 //===----------------------------------------------------------------------===//
2061
2062 /// @brief This class represents a no-op cast from one type to another.
2063 class BitCastInst : public CastInst {
2064   BitCastInst(const BitCastInst &CI)
2065     : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2066   }
2067 public:
2068   /// @brief Constructor with insert-before-instruction 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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2074   );
2075
2076   /// @brief Constructor with insert-at-end-of-block semantics
2077   BitCastInst(
2078     Value *S,                     ///< The value to be casted
2079     const Type *Ty,               ///< The type to casted to
2080     const std::string &Name,      ///< A name for the new instruction
2081     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2082   );
2083
2084   /// @brief Clone an identical BitCastInst
2085   virtual CastInst *clone() const;
2086
2087   // Methods for support type inquiry through isa, cast, and dyn_cast:
2088   static inline bool classof(const BitCastInst *) { return true; }
2089   static inline bool classof(const Instruction *I) {
2090     return I->getOpcode() == BitCast;
2091   }
2092   static inline bool classof(const Value *V) {
2093     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2094   }
2095 };
2096
2097 } // End llvm namespace
2098
2099 #endif