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