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