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