For PR950:
[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 a method that is invoked by this inst.
733   inline const Value *getCalledValue() const { return getOperand(0); }
734   inline       Value *getCalledValue()       { return getOperand(0); }
735
736   // Methods for support type inquiry through isa, cast, and dyn_cast:
737   static inline bool classof(const CallInst *) { return true; }
738   static inline bool classof(const Instruction *I) {
739     return I->getOpcode() == Instruction::Call;
740   }
741   static inline bool classof(const Value *V) {
742     return isa<Instruction>(V) && classof(cast<Instruction>(V));
743   }
744 };
745
746
747 //===----------------------------------------------------------------------===//
748 //                                 ShiftInst Class
749 //===----------------------------------------------------------------------===//
750
751 /// ShiftInst - This class represents left and right shift instructions.
752 ///
753 class ShiftInst : public Instruction {
754   Use Ops[2];
755   ShiftInst(const ShiftInst &SI)
756     : Instruction(SI.getType(), SI.getOpcode(), Ops, 2) {
757     Ops[0].init(SI.Ops[0], this);
758     Ops[1].init(SI.Ops[1], this);
759   }
760   void init(OtherOps Opcode, Value *S, Value *SA) {
761     assert((Opcode == Shl || Opcode == LShr || Opcode == AShr) && 
762       "ShiftInst Opcode invalid!");
763     Ops[0].init(S, this);
764     Ops[1].init(SA, this);
765   }
766
767 public:
768   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
769             Instruction *InsertBefore = 0)
770     : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) {
771     init(Opcode, S, SA);
772   }
773   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
774             BasicBlock *InsertAtEnd)
775     : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) {
776     init(Opcode, S, SA);
777   }
778
779   OtherOps getOpcode() const {
780     return static_cast<OtherOps>(Instruction::getOpcode());
781   }
782
783   /// Transparently provide more efficient getOperand methods.
784   Value *getOperand(unsigned i) const {
785     assert(i < 2 && "getOperand() out of range!");
786     return Ops[i];
787   }
788   void setOperand(unsigned i, Value *Val) {
789     assert(i < 2 && "setOperand() out of range!");
790     Ops[i] = Val;
791   }
792   unsigned getNumOperands() const { return 2; }
793
794   /// isLogicalShift - Return true if this is a logical shift left or a logical
795   /// shift right.
796   bool isLogicalShift() const {
797     unsigned opcode = getOpcode();
798     return opcode == Instruction::Shl || opcode == Instruction::LShr;
799   }
800
801
802   /// isArithmeticShift - Return true if this is a sign-extending shift right
803   /// operation.
804   bool isArithmeticShift() const {
805     return !isLogicalShift();
806   }
807
808
809   virtual ShiftInst *clone() const;
810
811   // Methods for support type inquiry through isa, cast, and dyn_cast:
812   static inline bool classof(const ShiftInst *) { return true; }
813   static inline bool classof(const Instruction *I) {
814     return (I->getOpcode() == Instruction::LShr) |
815            (I->getOpcode() == Instruction::AShr) |
816            (I->getOpcode() == Instruction::Shl);
817   }
818   static inline bool classof(const Value *V) {
819     return isa<Instruction>(V) && classof(cast<Instruction>(V));
820   }
821 };
822
823 //===----------------------------------------------------------------------===//
824 //                               SelectInst Class
825 //===----------------------------------------------------------------------===//
826
827 /// SelectInst - This class represents the LLVM 'select' instruction.
828 ///
829 class SelectInst : public Instruction {
830   Use Ops[3];
831
832   void init(Value *C, Value *S1, Value *S2) {
833     Ops[0].init(C, this);
834     Ops[1].init(S1, this);
835     Ops[2].init(S2, this);
836   }
837
838   SelectInst(const SelectInst &SI)
839     : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
840     init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
841   }
842 public:
843   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
844              Instruction *InsertBefore = 0)
845     : Instruction(S1->getType(), Instruction::Select, Ops, 3,
846                   Name, InsertBefore) {
847     init(C, S1, S2);
848   }
849   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
850              BasicBlock *InsertAtEnd)
851     : Instruction(S1->getType(), Instruction::Select, Ops, 3,
852                   Name, InsertAtEnd) {
853     init(C, S1, S2);
854   }
855
856   Value *getCondition() const { return Ops[0]; }
857   Value *getTrueValue() const { return Ops[1]; }
858   Value *getFalseValue() const { return Ops[2]; }
859
860   /// Transparently provide more efficient getOperand methods.
861   Value *getOperand(unsigned i) const {
862     assert(i < 3 && "getOperand() out of range!");
863     return Ops[i];
864   }
865   void setOperand(unsigned i, Value *Val) {
866     assert(i < 3 && "setOperand() out of range!");
867     Ops[i] = Val;
868   }
869   unsigned getNumOperands() const { return 3; }
870
871   OtherOps getOpcode() const {
872     return static_cast<OtherOps>(Instruction::getOpcode());
873   }
874
875   virtual SelectInst *clone() const;
876
877   // Methods for support type inquiry through isa, cast, and dyn_cast:
878   static inline bool classof(const SelectInst *) { return true; }
879   static inline bool classof(const Instruction *I) {
880     return I->getOpcode() == Instruction::Select;
881   }
882   static inline bool classof(const Value *V) {
883     return isa<Instruction>(V) && classof(cast<Instruction>(V));
884   }
885 };
886
887 //===----------------------------------------------------------------------===//
888 //                                VAArgInst Class
889 //===----------------------------------------------------------------------===//
890
891 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
892 /// an argument of the specified type given a va_list and increments that list
893 ///
894 class VAArgInst : public UnaryInstruction {
895   VAArgInst(const VAArgInst &VAA)
896     : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
897 public:
898   VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
899              Instruction *InsertBefore = 0)
900     : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
901   }
902   VAArgInst(Value *List, const Type *Ty, const std::string &Name,
903             BasicBlock *InsertAtEnd)
904     : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
905   }
906
907   virtual VAArgInst *clone() const;
908   bool mayWriteToMemory() const { return true; }
909
910   // Methods for support type inquiry through isa, cast, and dyn_cast:
911   static inline bool classof(const VAArgInst *) { return true; }
912   static inline bool classof(const Instruction *I) {
913     return I->getOpcode() == VAArg;
914   }
915   static inline bool classof(const Value *V) {
916     return isa<Instruction>(V) && classof(cast<Instruction>(V));
917   }
918 };
919
920 //===----------------------------------------------------------------------===//
921 //                                ExtractElementInst Class
922 //===----------------------------------------------------------------------===//
923
924 /// ExtractElementInst - This instruction extracts a single (scalar)
925 /// element from a PackedType value
926 ///
927 class ExtractElementInst : public Instruction {
928   Use Ops[2];
929   ExtractElementInst(const ExtractElementInst &EE) :
930     Instruction(EE.getType(), ExtractElement, Ops, 2) {
931     Ops[0].init(EE.Ops[0], this);
932     Ops[1].init(EE.Ops[1], this);
933   }
934
935 public:
936   ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
937                      Instruction *InsertBefore = 0);
938   ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
939                      Instruction *InsertBefore = 0);
940   ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
941                      BasicBlock *InsertAtEnd);
942   ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
943                      BasicBlock *InsertAtEnd);
944
945   /// isValidOperands - Return true if an extractelement instruction can be
946   /// formed with the specified operands.
947   static bool isValidOperands(const Value *Vec, const Value *Idx);
948
949   virtual ExtractElementInst *clone() const;
950
951   virtual bool mayWriteToMemory() const { return false; }
952
953   /// Transparently provide more efficient getOperand methods.
954   Value *getOperand(unsigned i) const {
955     assert(i < 2 && "getOperand() out of range!");
956     return Ops[i];
957   }
958   void setOperand(unsigned i, Value *Val) {
959     assert(i < 2 && "setOperand() out of range!");
960     Ops[i] = Val;
961   }
962   unsigned getNumOperands() const { return 2; }
963
964   // Methods for support type inquiry through isa, cast, and dyn_cast:
965   static inline bool classof(const ExtractElementInst *) { return true; }
966   static inline bool classof(const Instruction *I) {
967     return I->getOpcode() == Instruction::ExtractElement;
968   }
969   static inline bool classof(const Value *V) {
970     return isa<Instruction>(V) && classof(cast<Instruction>(V));
971   }
972 };
973
974 //===----------------------------------------------------------------------===//
975 //                                InsertElementInst Class
976 //===----------------------------------------------------------------------===//
977
978 /// InsertElementInst - This instruction inserts a single (scalar)
979 /// element into a PackedType value
980 ///
981 class InsertElementInst : public Instruction {
982   Use Ops[3];
983   InsertElementInst(const InsertElementInst &IE);
984 public:
985   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
986                     const std::string &Name = "",Instruction *InsertBefore = 0);
987   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
988                     const std::string &Name = "",Instruction *InsertBefore = 0);
989   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
990                     const std::string &Name, BasicBlock *InsertAtEnd);
991   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
992                     const std::string &Name, BasicBlock *InsertAtEnd);
993
994   /// isValidOperands - Return true if an insertelement instruction can be
995   /// formed with the specified operands.
996   static bool isValidOperands(const Value *Vec, const Value *NewElt,
997                               const Value *Idx);
998
999   virtual InsertElementInst *clone() const;
1000
1001   virtual bool mayWriteToMemory() const { return false; }
1002
1003   /// getType - Overload to return most specific packed type.
1004   ///
1005   inline const PackedType *getType() const {
1006     return reinterpret_cast<const PackedType*>(Instruction::getType());
1007   }
1008
1009   /// Transparently provide more efficient getOperand methods.
1010   Value *getOperand(unsigned i) const {
1011     assert(i < 3 && "getOperand() out of range!");
1012     return Ops[i];
1013   }
1014   void setOperand(unsigned i, Value *Val) {
1015     assert(i < 3 && "setOperand() out of range!");
1016     Ops[i] = Val;
1017   }
1018   unsigned getNumOperands() const { return 3; }
1019
1020   // Methods for support type inquiry through isa, cast, and dyn_cast:
1021   static inline bool classof(const InsertElementInst *) { return true; }
1022   static inline bool classof(const Instruction *I) {
1023     return I->getOpcode() == Instruction::InsertElement;
1024   }
1025   static inline bool classof(const Value *V) {
1026     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1027   }
1028 };
1029
1030 //===----------------------------------------------------------------------===//
1031 //                           ShuffleVectorInst Class
1032 //===----------------------------------------------------------------------===//
1033
1034 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1035 /// input vectors.
1036 ///
1037 class ShuffleVectorInst : public Instruction {
1038   Use Ops[3];
1039   ShuffleVectorInst(const ShuffleVectorInst &IE);
1040 public:
1041   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1042                     const std::string &Name = "", Instruction *InsertBefor = 0);
1043   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1044                     const std::string &Name, BasicBlock *InsertAtEnd);
1045
1046   /// isValidOperands - Return true if a shufflevector instruction can be
1047   /// formed with the specified operands.
1048   static bool isValidOperands(const Value *V1, const Value *V2,
1049                               const Value *Mask);
1050
1051   virtual ShuffleVectorInst *clone() const;
1052
1053   virtual bool mayWriteToMemory() const { return false; }
1054
1055   /// getType - Overload to return most specific packed type.
1056   ///
1057   inline const PackedType *getType() const {
1058     return reinterpret_cast<const PackedType*>(Instruction::getType());
1059   }
1060
1061   /// Transparently provide more efficient getOperand methods.
1062   Value *getOperand(unsigned i) const {
1063     assert(i < 3 && "getOperand() out of range!");
1064     return Ops[i];
1065   }
1066   void setOperand(unsigned i, Value *Val) {
1067     assert(i < 3 && "setOperand() out of range!");
1068     Ops[i] = Val;
1069   }
1070   unsigned getNumOperands() const { return 3; }
1071
1072   // Methods for support type inquiry through isa, cast, and dyn_cast:
1073   static inline bool classof(const ShuffleVectorInst *) { return true; }
1074   static inline bool classof(const Instruction *I) {
1075     return I->getOpcode() == Instruction::ShuffleVector;
1076   }
1077   static inline bool classof(const Value *V) {
1078     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1079   }
1080 };
1081
1082
1083 //===----------------------------------------------------------------------===//
1084 //                               PHINode Class
1085 //===----------------------------------------------------------------------===//
1086
1087 // PHINode - The PHINode class is used to represent the magical mystical PHI
1088 // node, that can not exist in nature, but can be synthesized in a computer
1089 // scientist's overactive imagination.
1090 //
1091 class PHINode : public Instruction {
1092   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1093   /// the number actually in use.
1094   unsigned ReservedSpace;
1095   PHINode(const PHINode &PN);
1096 public:
1097   explicit PHINode(const Type *Ty, const std::string &Name = "",
1098                    Instruction *InsertBefore = 0)
1099     : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
1100       ReservedSpace(0) {
1101   }
1102
1103   PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1104     : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
1105       ReservedSpace(0) {
1106   }
1107
1108   ~PHINode();
1109
1110   /// reserveOperandSpace - This method can be used to avoid repeated
1111   /// reallocation of PHI operand lists by reserving space for the correct
1112   /// number of operands before adding them.  Unlike normal vector reserves,
1113   /// this method can also be used to trim the operand space.
1114   void reserveOperandSpace(unsigned NumValues) {
1115     resizeOperands(NumValues*2);
1116   }
1117
1118   virtual PHINode *clone() const;
1119
1120   /// getNumIncomingValues - Return the number of incoming edges
1121   ///
1122   unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1123
1124   /// getIncomingValue - Return incoming value number x
1125   ///
1126   Value *getIncomingValue(unsigned i) const {
1127     assert(i*2 < getNumOperands() && "Invalid value number!");
1128     return getOperand(i*2);
1129   }
1130   void setIncomingValue(unsigned i, Value *V) {
1131     assert(i*2 < getNumOperands() && "Invalid value number!");
1132     setOperand(i*2, V);
1133   }
1134   unsigned getOperandNumForIncomingValue(unsigned i) {
1135     return i*2;
1136   }
1137
1138   /// getIncomingBlock - Return incoming basic block number x
1139   ///
1140   BasicBlock *getIncomingBlock(unsigned i) const {
1141     return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1142   }
1143   void setIncomingBlock(unsigned i, BasicBlock *BB) {
1144     setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1145   }
1146   unsigned getOperandNumForIncomingBlock(unsigned i) {
1147     return i*2+1;
1148   }
1149
1150   /// addIncoming - Add an incoming value to the end of the PHI list
1151   ///
1152   void addIncoming(Value *V, BasicBlock *BB) {
1153     assert(getType() == V->getType() &&
1154            "All operands to PHI node must be the same type as the PHI node!");
1155     unsigned OpNo = NumOperands;
1156     if (OpNo+2 > ReservedSpace)
1157       resizeOperands(0);  // Get more space!
1158     // Initialize some new operands.
1159     NumOperands = OpNo+2;
1160     OperandList[OpNo].init(V, this);
1161     OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1162   }
1163
1164   /// removeIncomingValue - Remove an incoming value.  This is useful if a
1165   /// predecessor basic block is deleted.  The value removed is returned.
1166   ///
1167   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1168   /// is true), the PHI node is destroyed and any uses of it are replaced with
1169   /// dummy values.  The only time there should be zero incoming values to a PHI
1170   /// node is when the block is dead, so this strategy is sound.
1171   ///
1172   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1173
1174   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1175     int Idx = getBasicBlockIndex(BB);
1176     assert(Idx >= 0 && "Invalid basic block argument to remove!");
1177     return removeIncomingValue(Idx, DeletePHIIfEmpty);
1178   }
1179
1180   /// getBasicBlockIndex - Return the first index of the specified basic
1181   /// block in the value list for this PHI.  Returns -1 if no instance.
1182   ///
1183   int getBasicBlockIndex(const BasicBlock *BB) const {
1184     Use *OL = OperandList;
1185     for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1186       if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1187     return -1;
1188   }
1189
1190   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1191     return getIncomingValue(getBasicBlockIndex(BB));
1192   }
1193
1194   /// hasConstantValue - If the specified PHI node always merges together the
1195   /// same value, return the value, otherwise return null.
1196   ///
1197   Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1198
1199   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1200   static inline bool classof(const PHINode *) { return true; }
1201   static inline bool classof(const Instruction *I) {
1202     return I->getOpcode() == Instruction::PHI;
1203   }
1204   static inline bool classof(const Value *V) {
1205     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1206   }
1207  private:
1208   void resizeOperands(unsigned NumOperands);
1209 };
1210
1211 //===----------------------------------------------------------------------===//
1212 //                               ReturnInst Class
1213 //===----------------------------------------------------------------------===//
1214
1215 //===---------------------------------------------------------------------------
1216 /// ReturnInst - Return a value (possibly void), from a function.  Execution
1217 /// does not continue in this function any longer.
1218 ///
1219 class ReturnInst : public TerminatorInst {
1220   Use RetVal;  // Possibly null retval.
1221   ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
1222                                                     RI.getNumOperands()) {
1223     if (RI.getNumOperands())
1224       RetVal.init(RI.RetVal, this);
1225   }
1226
1227   void init(Value *RetVal);
1228
1229 public:
1230   // ReturnInst constructors:
1231   // ReturnInst()                  - 'ret void' instruction
1232   // ReturnInst(    null)          - 'ret void' instruction
1233   // ReturnInst(Value* X)          - 'ret X'    instruction
1234   // ReturnInst(    null, Inst *)  - 'ret void' instruction, insert before I
1235   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
1236   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of BB
1237   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of BB
1238   //
1239   // NOTE: If the Value* passed is of type void then the constructor behaves as
1240   // if it was passed NULL.
1241   explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
1242     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
1243     init(retVal);
1244   }
1245   ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
1246     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1247     init(retVal);
1248   }
1249   explicit ReturnInst(BasicBlock *InsertAtEnd)
1250     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1251   }
1252
1253   virtual ReturnInst *clone() const;
1254
1255   // Transparently provide more efficient getOperand methods.
1256   Value *getOperand(unsigned i) const {
1257     assert(i < getNumOperands() && "getOperand() out of range!");
1258     return RetVal;
1259   }
1260   void setOperand(unsigned i, Value *Val) {
1261     assert(i < getNumOperands() && "setOperand() out of range!");
1262     RetVal = Val;
1263   }
1264
1265   Value *getReturnValue() const { return RetVal; }
1266
1267   unsigned getNumSuccessors() const { return 0; }
1268
1269   // Methods for support type inquiry through isa, cast, and dyn_cast:
1270   static inline bool classof(const ReturnInst *) { return true; }
1271   static inline bool classof(const Instruction *I) {
1272     return (I->getOpcode() == Instruction::Ret);
1273   }
1274   static inline bool classof(const Value *V) {
1275     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1276   }
1277  private:
1278   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1279   virtual unsigned getNumSuccessorsV() const;
1280   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1281 };
1282
1283 //===----------------------------------------------------------------------===//
1284 //                               BranchInst Class
1285 //===----------------------------------------------------------------------===//
1286
1287 //===---------------------------------------------------------------------------
1288 /// BranchInst - Conditional or Unconditional Branch instruction.
1289 ///
1290 class BranchInst : public TerminatorInst {
1291   /// Ops list - Branches are strange.  The operands are ordered:
1292   ///  TrueDest, FalseDest, Cond.  This makes some accessors faster because
1293   /// they don't have to check for cond/uncond branchness.
1294   Use Ops[3];
1295   BranchInst(const BranchInst &BI);
1296   void AssertOK();
1297 public:
1298   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1299   // BranchInst(BB *B)                           - 'br B'
1300   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
1301   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
1302   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1303   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
1304   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
1305   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1306     : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1307     assert(IfTrue != 0 && "Branch destination may not be null!");
1308     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1309   }
1310   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1311              Instruction *InsertBefore = 0)
1312     : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1313     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1314     Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1315     Ops[2].init(Cond, this);
1316 #ifndef NDEBUG
1317     AssertOK();
1318 #endif
1319   }
1320
1321   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1322     : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1323     assert(IfTrue != 0 && "Branch destination may not be null!");
1324     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1325   }
1326
1327   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1328              BasicBlock *InsertAtEnd)
1329     : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1330     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1331     Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1332     Ops[2].init(Cond, this);
1333 #ifndef NDEBUG
1334     AssertOK();
1335 #endif
1336   }
1337
1338
1339   /// Transparently provide more efficient getOperand methods.
1340   Value *getOperand(unsigned i) const {
1341     assert(i < getNumOperands() && "getOperand() out of range!");
1342     return Ops[i];
1343   }
1344   void setOperand(unsigned i, Value *Val) {
1345     assert(i < getNumOperands() && "setOperand() out of range!");
1346     Ops[i] = Val;
1347   }
1348
1349   virtual BranchInst *clone() const;
1350
1351   inline bool isUnconditional() const { return getNumOperands() == 1; }
1352   inline bool isConditional()   const { return getNumOperands() == 3; }
1353
1354   inline Value *getCondition() const {
1355     assert(isConditional() && "Cannot get condition of an uncond branch!");
1356     return getOperand(2);
1357   }
1358
1359   void setCondition(Value *V) {
1360     assert(isConditional() && "Cannot set condition of unconditional branch!");
1361     setOperand(2, V);
1362   }
1363
1364   // setUnconditionalDest - Change the current branch to an unconditional branch
1365   // targeting the specified block.
1366   // FIXME: Eliminate this ugly method.
1367   void setUnconditionalDest(BasicBlock *Dest) {
1368     if (isConditional()) {  // Convert this to an uncond branch.
1369       NumOperands = 1;
1370       Ops[1].set(0);
1371       Ops[2].set(0);
1372     }
1373     setOperand(0, reinterpret_cast<Value*>(Dest));
1374   }
1375
1376   unsigned getNumSuccessors() const { return 1+isConditional(); }
1377
1378   BasicBlock *getSuccessor(unsigned i) const {
1379     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1380     return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1381                       cast<BasicBlock>(getOperand(1));
1382   }
1383
1384   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1385     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1386     setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1387   }
1388
1389   // Methods for support type inquiry through isa, cast, and dyn_cast:
1390   static inline bool classof(const BranchInst *) { return true; }
1391   static inline bool classof(const Instruction *I) {
1392     return (I->getOpcode() == Instruction::Br);
1393   }
1394   static inline bool classof(const Value *V) {
1395     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1396   }
1397 private:
1398   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1399   virtual unsigned getNumSuccessorsV() const;
1400   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1401 };
1402
1403 //===----------------------------------------------------------------------===//
1404 //                               SwitchInst Class
1405 //===----------------------------------------------------------------------===//
1406
1407 //===---------------------------------------------------------------------------
1408 /// SwitchInst - Multiway switch
1409 ///
1410 class SwitchInst : public TerminatorInst {
1411   unsigned ReservedSpace;
1412   // Operand[0]    = Value to switch on
1413   // Operand[1]    = Default basic block destination
1414   // Operand[2n  ] = Value to match
1415   // Operand[2n+1] = BasicBlock to go to on match
1416   SwitchInst(const SwitchInst &RI);
1417   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1418   void resizeOperands(unsigned No);
1419 public:
1420   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1421   /// switch on and a default destination.  The number of additional cases can
1422   /// be specified here to make memory allocation more efficient.  This
1423   /// constructor can also autoinsert before another instruction.
1424   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1425              Instruction *InsertBefore = 0)
1426     : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1427     init(Value, Default, NumCases);
1428   }
1429
1430   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1431   /// switch on and a default destination.  The number of additional cases can
1432   /// be specified here to make memory allocation more efficient.  This
1433   /// constructor also autoinserts at the end of the specified BasicBlock.
1434   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1435              BasicBlock *InsertAtEnd)
1436     : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1437     init(Value, Default, NumCases);
1438   }
1439   ~SwitchInst();
1440
1441
1442   // Accessor Methods for Switch stmt
1443   inline Value *getCondition() const { return getOperand(0); }
1444   void setCondition(Value *V) { setOperand(0, V); }
1445
1446   inline BasicBlock *getDefaultDest() const {
1447     return cast<BasicBlock>(getOperand(1));
1448   }
1449
1450   /// getNumCases - return the number of 'cases' in this switch instruction.
1451   /// Note that case #0 is always the default case.
1452   unsigned getNumCases() const {
1453     return getNumOperands()/2;
1454   }
1455
1456   /// getCaseValue - Return the specified case value.  Note that case #0, the
1457   /// default destination, does not have a case value.
1458   ConstantInt *getCaseValue(unsigned i) {
1459     assert(i && i < getNumCases() && "Illegal case value to get!");
1460     return getSuccessorValue(i);
1461   }
1462
1463   /// getCaseValue - Return the specified case value.  Note that case #0, the
1464   /// default destination, does not have a case value.
1465   const ConstantInt *getCaseValue(unsigned i) const {
1466     assert(i && i < getNumCases() && "Illegal case value to get!");
1467     return getSuccessorValue(i);
1468   }
1469
1470   /// findCaseValue - Search all of the case values for the specified constant.
1471   /// If it is explicitly handled, return the case number of it, otherwise
1472   /// return 0 to indicate that it is handled by the default handler.
1473   unsigned findCaseValue(const ConstantInt *C) const {
1474     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1475       if (getCaseValue(i) == C)
1476         return i;
1477     return 0;
1478   }
1479
1480   /// findCaseDest - Finds the unique case value for a given successor. Returns
1481   /// null if the successor is not found, not unique, or is the default case.
1482   ConstantInt *findCaseDest(BasicBlock *BB) {
1483     if (BB == getDefaultDest()) return NULL;
1484
1485     ConstantInt *CI = NULL;
1486     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1487       if (getSuccessor(i) == BB) {
1488         if (CI) return NULL;   // Multiple cases lead to BB.
1489         else CI = getCaseValue(i);
1490       }
1491     }
1492     return CI;
1493   }
1494
1495   /// addCase - Add an entry to the switch instruction...
1496   ///
1497   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1498
1499   /// removeCase - This method removes the specified successor from the switch
1500   /// instruction.  Note that this cannot be used to remove the default
1501   /// destination (successor #0).
1502   ///
1503   void removeCase(unsigned idx);
1504
1505   virtual SwitchInst *clone() const;
1506
1507   unsigned getNumSuccessors() const { return getNumOperands()/2; }
1508   BasicBlock *getSuccessor(unsigned idx) const {
1509     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1510     return cast<BasicBlock>(getOperand(idx*2+1));
1511   }
1512   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1513     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1514     setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1515   }
1516
1517   // getSuccessorValue - Return the value associated with the specified
1518   // successor.
1519   inline ConstantInt *getSuccessorValue(unsigned idx) const {
1520     assert(idx < getNumSuccessors() && "Successor # out of range!");
1521     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1522   }
1523
1524   // Methods for support type inquiry through isa, cast, and dyn_cast:
1525   static inline bool classof(const SwitchInst *) { return true; }
1526   static inline bool classof(const Instruction *I) {
1527     return I->getOpcode() == Instruction::Switch;
1528   }
1529   static inline bool classof(const Value *V) {
1530     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1531   }
1532 private:
1533   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1534   virtual unsigned getNumSuccessorsV() const;
1535   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1536 };
1537
1538 //===----------------------------------------------------------------------===//
1539 //                               InvokeInst Class
1540 //===----------------------------------------------------------------------===//
1541
1542 //===---------------------------------------------------------------------------
1543
1544 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
1545 /// calling convention of the call.
1546 ///
1547 class InvokeInst : public TerminatorInst {
1548   InvokeInst(const InvokeInst &BI);
1549   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1550             const std::vector<Value*> &Params);
1551 public:
1552   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1553              const std::vector<Value*> &Params, const std::string &Name = "",
1554              Instruction *InsertBefore = 0);
1555   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1556              const std::vector<Value*> &Params, const std::string &Name,
1557              BasicBlock *InsertAtEnd);
1558   ~InvokeInst();
1559
1560   virtual InvokeInst *clone() const;
1561
1562   bool mayWriteToMemory() const { return true; }
1563
1564   /// getCallingConv/setCallingConv - Get or set the calling convention of this
1565   /// function call.
1566   unsigned getCallingConv() const { return SubclassData; }
1567   void setCallingConv(unsigned CC) {
1568     SubclassData = CC;
1569   }
1570
1571   /// getCalledFunction - Return the function called, or null if this is an
1572   /// indirect function invocation.
1573   ///
1574   Function *getCalledFunction() const {
1575     return dyn_cast<Function>(getOperand(0));
1576   }
1577
1578   // getCalledValue - Get a pointer to a function that is invoked by this inst.
1579   inline Value *getCalledValue() const { return getOperand(0); }
1580
1581   // get*Dest - Return the destination basic blocks...
1582   BasicBlock *getNormalDest() const {
1583     return cast<BasicBlock>(getOperand(1));
1584   }
1585   BasicBlock *getUnwindDest() const {
1586     return cast<BasicBlock>(getOperand(2));
1587   }
1588   void setNormalDest(BasicBlock *B) {
1589     setOperand(1, reinterpret_cast<Value*>(B));
1590   }
1591
1592   void setUnwindDest(BasicBlock *B) {
1593     setOperand(2, reinterpret_cast<Value*>(B));
1594   }
1595
1596   inline BasicBlock *getSuccessor(unsigned i) const {
1597     assert(i < 2 && "Successor # out of range for invoke!");
1598     return i == 0 ? getNormalDest() : getUnwindDest();
1599   }
1600
1601   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1602     assert(idx < 2 && "Successor # out of range for invoke!");
1603     setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1604   }
1605
1606   unsigned getNumSuccessors() const { return 2; }
1607
1608   // Methods for support type inquiry through isa, cast, and dyn_cast:
1609   static inline bool classof(const InvokeInst *) { return true; }
1610   static inline bool classof(const Instruction *I) {
1611     return (I->getOpcode() == Instruction::Invoke);
1612   }
1613   static inline bool classof(const Value *V) {
1614     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1615   }
1616 private:
1617   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1618   virtual unsigned getNumSuccessorsV() const;
1619   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1620 };
1621
1622
1623 //===----------------------------------------------------------------------===//
1624 //                              UnwindInst Class
1625 //===----------------------------------------------------------------------===//
1626
1627 //===---------------------------------------------------------------------------
1628 /// UnwindInst - Immediately exit the current function, unwinding the stack
1629 /// until an invoke instruction is found.
1630 ///
1631 class UnwindInst : public TerminatorInst {
1632 public:
1633   explicit UnwindInst(Instruction *InsertBefore = 0)
1634     : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1635   }
1636   explicit UnwindInst(BasicBlock *InsertAtEnd)
1637     : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1638   }
1639
1640   virtual UnwindInst *clone() const;
1641
1642   unsigned getNumSuccessors() const { return 0; }
1643
1644   // Methods for support type inquiry through isa, cast, and dyn_cast:
1645   static inline bool classof(const UnwindInst *) { return true; }
1646   static inline bool classof(const Instruction *I) {
1647     return I->getOpcode() == Instruction::Unwind;
1648   }
1649   static inline bool classof(const Value *V) {
1650     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1651   }
1652 private:
1653   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1654   virtual unsigned getNumSuccessorsV() const;
1655   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1656 };
1657
1658 //===----------------------------------------------------------------------===//
1659 //                           UnreachableInst Class
1660 //===----------------------------------------------------------------------===//
1661
1662 //===---------------------------------------------------------------------------
1663 /// UnreachableInst - This function has undefined behavior.  In particular, the
1664 /// presence of this instruction indicates some higher level knowledge that the
1665 /// end of the block cannot be reached.
1666 ///
1667 class UnreachableInst : public TerminatorInst {
1668 public:
1669   explicit UnreachableInst(Instruction *InsertBefore = 0)
1670     : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1671   }
1672   explicit UnreachableInst(BasicBlock *InsertAtEnd)
1673     : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1674   }
1675
1676   virtual UnreachableInst *clone() const;
1677
1678   unsigned getNumSuccessors() const { return 0; }
1679
1680   // Methods for support type inquiry through isa, cast, and dyn_cast:
1681   static inline bool classof(const UnreachableInst *) { return true; }
1682   static inline bool classof(const Instruction *I) {
1683     return I->getOpcode() == Instruction::Unreachable;
1684   }
1685   static inline bool classof(const Value *V) {
1686     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1687   }
1688 private:
1689   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1690   virtual unsigned getNumSuccessorsV() const;
1691   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1692 };
1693
1694 //===----------------------------------------------------------------------===//
1695 //                                 TruncInst Class
1696 //===----------------------------------------------------------------------===//
1697
1698 /// @brief This class represents a truncation of integer types.
1699 class TruncInst : public CastInst {
1700   /// Private copy constructor
1701   TruncInst(const TruncInst &CI)
1702     : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1703   }
1704 public:
1705   /// @brief Constructor with insert-before-instruction semantics
1706   TruncInst(
1707     Value *S,                     ///< The value to be truncated
1708     const Type *Ty,               ///< The (smaller) type to truncate to
1709     const std::string &Name = "", ///< A name for the new instruction
1710     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1711   );
1712
1713   /// @brief Constructor with insert-at-end-of-block semantics
1714   TruncInst(
1715     Value *S,                     ///< The value to be truncated
1716     const Type *Ty,               ///< The (smaller) type to truncate to
1717     const std::string &Name,      ///< A name for the new instruction
1718     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1719   );
1720
1721   /// @brief Clone an identical TruncInst
1722   virtual CastInst *clone() const;
1723
1724   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1725   static inline bool classof(const TruncInst *) { return true; }
1726   static inline bool classof(const Instruction *I) {
1727     return I->getOpcode() == Trunc;
1728   }
1729   static inline bool classof(const Value *V) {
1730     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1731   }
1732 };
1733
1734 //===----------------------------------------------------------------------===//
1735 //                                 ZExtInst Class
1736 //===----------------------------------------------------------------------===//
1737
1738 /// @brief This class represents zero extension of integer types.
1739 class ZExtInst : public CastInst {
1740   /// @brief Private copy constructor
1741   ZExtInst(const ZExtInst &CI)
1742     : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1743   }
1744 public:
1745   /// @brief Constructor with insert-before-instruction semantics
1746   ZExtInst(
1747     Value *S,                     ///< The value to be zero extended
1748     const Type *Ty,               ///< The type to zero extend to
1749     const std::string &Name = "", ///< A name for the new instruction
1750     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1751   );
1752
1753   /// @brief Constructor with insert-at-end semantics.
1754   ZExtInst(
1755     Value *S,                     ///< The value to be zero extended
1756     const Type *Ty,               ///< The type to zero extend to
1757     const std::string &Name,      ///< A name for the new instruction
1758     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1759   );
1760
1761   /// @brief Clone an identical ZExtInst
1762   virtual CastInst *clone() const;
1763
1764   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1765   static inline bool classof(const ZExtInst *) { return true; }
1766   static inline bool classof(const Instruction *I) {
1767     return I->getOpcode() == ZExt;
1768   }
1769   static inline bool classof(const Value *V) {
1770     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1771   }
1772 };
1773
1774 //===----------------------------------------------------------------------===//
1775 //                                 SExtInst Class
1776 //===----------------------------------------------------------------------===//
1777
1778 /// @brief This class represents a sign extension of integer types.
1779 class SExtInst : public CastInst {
1780   /// @brief Private copy constructor
1781   SExtInst(const SExtInst &CI)
1782     : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1783   }
1784 public:
1785   /// @brief Constructor with insert-before-instruction semantics
1786   SExtInst(
1787     Value *S,                     ///< The value to be sign extended
1788     const Type *Ty,               ///< The type to sign extend to
1789     const std::string &Name = "", ///< A name for the new instruction
1790     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1791   );
1792
1793   /// @brief Constructor with insert-at-end-of-block semantics
1794   SExtInst(
1795     Value *S,                     ///< The value to be sign extended
1796     const Type *Ty,               ///< The type to sign extend to
1797     const std::string &Name,      ///< A name for the new instruction
1798     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1799   );
1800
1801   /// @brief Clone an identical SExtInst
1802   virtual CastInst *clone() const;
1803
1804   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1805   static inline bool classof(const SExtInst *) { return true; }
1806   static inline bool classof(const Instruction *I) {
1807     return I->getOpcode() == SExt;
1808   }
1809   static inline bool classof(const Value *V) {
1810     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1811   }
1812 };
1813
1814 //===----------------------------------------------------------------------===//
1815 //                                 FPTruncInst Class
1816 //===----------------------------------------------------------------------===//
1817
1818 /// @brief This class represents a truncation of floating point types.
1819 class FPTruncInst : public CastInst {
1820   FPTruncInst(const FPTruncInst &CI)
1821     : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1822   }
1823 public:
1824   /// @brief Constructor with insert-before-instruction semantics
1825   FPTruncInst(
1826     Value *S,                     ///< The value to be truncated
1827     const Type *Ty,               ///< The type to truncate to
1828     const std::string &Name = "", ///< A name for the new instruction
1829     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1830   );
1831
1832   /// @brief Constructor with insert-before-instruction semantics
1833   FPTruncInst(
1834     Value *S,                     ///< The value to be truncated
1835     const Type *Ty,               ///< The type to truncate to
1836     const std::string &Name,      ///< A name for the new instruction
1837     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1838   );
1839
1840   /// @brief Clone an identical FPTruncInst
1841   virtual CastInst *clone() const;
1842
1843   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1844   static inline bool classof(const FPTruncInst *) { return true; }
1845   static inline bool classof(const Instruction *I) {
1846     return I->getOpcode() == FPTrunc;
1847   }
1848   static inline bool classof(const Value *V) {
1849     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1850   }
1851 };
1852
1853 //===----------------------------------------------------------------------===//
1854 //                                 FPExtInst Class
1855 //===----------------------------------------------------------------------===//
1856
1857 /// @brief This class represents an extension of floating point types.
1858 class FPExtInst : public CastInst {
1859   FPExtInst(const FPExtInst &CI)
1860     : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1861   }
1862 public:
1863   /// @brief Constructor with insert-before-instruction semantics
1864   FPExtInst(
1865     Value *S,                     ///< The value to be extended
1866     const Type *Ty,               ///< The type to extend to
1867     const std::string &Name = "", ///< A name for the new instruction
1868     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1869   );
1870
1871   /// @brief Constructor with insert-at-end-of-block semantics
1872   FPExtInst(
1873     Value *S,                     ///< The value to be extended
1874     const Type *Ty,               ///< The type to extend to
1875     const std::string &Name,      ///< A name for the new instruction
1876     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1877   );
1878
1879   /// @brief Clone an identical FPExtInst
1880   virtual CastInst *clone() const;
1881
1882   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1883   static inline bool classof(const FPExtInst *) { return true; }
1884   static inline bool classof(const Instruction *I) {
1885     return I->getOpcode() == FPExt;
1886   }
1887   static inline bool classof(const Value *V) {
1888     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1889   }
1890 };
1891
1892 //===----------------------------------------------------------------------===//
1893 //                                 UIToFPInst Class
1894 //===----------------------------------------------------------------------===//
1895
1896 /// @brief This class represents a cast unsigned integer to floating point.
1897 class UIToFPInst : public CastInst {
1898   UIToFPInst(const UIToFPInst &CI)
1899     : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1900   }
1901 public:
1902   /// @brief Constructor with insert-before-instruction semantics
1903   UIToFPInst(
1904     Value *S,                     ///< The value to be converted
1905     const Type *Ty,               ///< The type to convert to
1906     const std::string &Name = "", ///< A name for the new instruction
1907     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1908   );
1909
1910   /// @brief Constructor with insert-at-end-of-block semantics
1911   UIToFPInst(
1912     Value *S,                     ///< The value to be converted
1913     const Type *Ty,               ///< The type to convert to
1914     const std::string &Name,      ///< A name for the new instruction
1915     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1916   );
1917
1918   /// @brief Clone an identical UIToFPInst
1919   virtual CastInst *clone() const;
1920
1921   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1922   static inline bool classof(const UIToFPInst *) { return true; }
1923   static inline bool classof(const Instruction *I) {
1924     return I->getOpcode() == UIToFP;
1925   }
1926   static inline bool classof(const Value *V) {
1927     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1928   }
1929 };
1930
1931 //===----------------------------------------------------------------------===//
1932 //                                 SIToFPInst Class
1933 //===----------------------------------------------------------------------===//
1934
1935 /// @brief This class represents a cast from signed integer to floating point.
1936 class SIToFPInst : public CastInst {
1937   SIToFPInst(const SIToFPInst &CI)
1938     : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1939   }
1940 public:
1941   /// @brief Constructor with insert-before-instruction semantics
1942   SIToFPInst(
1943     Value *S,                     ///< The value to be converted
1944     const Type *Ty,               ///< The type to convert to
1945     const std::string &Name = "", ///< A name for the new instruction
1946     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1947   );
1948
1949   /// @brief Constructor with insert-at-end-of-block semantics
1950   SIToFPInst(
1951     Value *S,                     ///< The value to be converted
1952     const Type *Ty,               ///< The type to convert to
1953     const std::string &Name,      ///< A name for the new instruction
1954     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1955   );
1956
1957   /// @brief Clone an identical SIToFPInst
1958   virtual CastInst *clone() const;
1959
1960   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1961   static inline bool classof(const SIToFPInst *) { return true; }
1962   static inline bool classof(const Instruction *I) {
1963     return I->getOpcode() == SIToFP;
1964   }
1965   static inline bool classof(const Value *V) {
1966     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1967   }
1968 };
1969
1970 //===----------------------------------------------------------------------===//
1971 //                                 FPToUIInst Class
1972 //===----------------------------------------------------------------------===//
1973
1974 /// @brief This class represents a cast from floating point to unsigned integer
1975 class FPToUIInst  : public CastInst {
1976   FPToUIInst(const FPToUIInst &CI)
1977     : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1978   }
1979 public:
1980   /// @brief Constructor with insert-before-instruction semantics
1981   FPToUIInst(
1982     Value *S,                     ///< The value to be converted
1983     const Type *Ty,               ///< The type to convert to
1984     const std::string &Name = "", ///< A name for the new instruction
1985     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1986   );
1987
1988   /// @brief Constructor with insert-at-end-of-block semantics
1989   FPToUIInst(
1990     Value *S,                     ///< The value to be converted
1991     const Type *Ty,               ///< The type to convert to
1992     const std::string &Name,      ///< A name for the new instruction
1993     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
1994   );
1995
1996   /// @brief Clone an identical FPToUIInst
1997   virtual CastInst *clone() const;
1998
1999   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2000   static inline bool classof(const FPToUIInst *) { return true; }
2001   static inline bool classof(const Instruction *I) {
2002     return I->getOpcode() == FPToUI;
2003   }
2004   static inline bool classof(const Value *V) {
2005     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2006   }
2007 };
2008
2009 //===----------------------------------------------------------------------===//
2010 //                                 FPToSIInst Class
2011 //===----------------------------------------------------------------------===//
2012
2013 /// @brief This class represents a cast from floating point to signed integer.
2014 class FPToSIInst  : public CastInst {
2015   FPToSIInst(const FPToSIInst &CI)
2016     : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2017   }
2018 public:
2019   /// @brief Constructor with insert-before-instruction semantics
2020   FPToSIInst(
2021     Value *S,                     ///< The value to be converted
2022     const Type *Ty,               ///< The type to convert to
2023     const std::string &Name = "", ///< A name for the new instruction
2024     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2025   );
2026
2027   /// @brief Constructor with insert-at-end-of-block semantics
2028   FPToSIInst(
2029     Value *S,                     ///< The value to be converted
2030     const Type *Ty,               ///< The type to convert to
2031     const std::string &Name,      ///< A name for the new instruction
2032     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2033   );
2034
2035   /// @brief Clone an identical FPToSIInst
2036   virtual CastInst *clone() const;
2037
2038   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2039   static inline bool classof(const FPToSIInst *) { return true; }
2040   static inline bool classof(const Instruction *I) {
2041     return I->getOpcode() == FPToSI;
2042   }
2043   static inline bool classof(const Value *V) {
2044     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2045   }
2046 };
2047
2048 //===----------------------------------------------------------------------===//
2049 //                                 IntToPtrInst Class
2050 //===----------------------------------------------------------------------===//
2051
2052 /// @brief This class represents a cast from an integer to a pointer.
2053 class IntToPtrInst : public CastInst {
2054   IntToPtrInst(const IntToPtrInst &CI)
2055     : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2056   }
2057 public:
2058   /// @brief Constructor with insert-before-instruction semantics
2059   IntToPtrInst(
2060     Value *S,                     ///< The value to be converted
2061     const Type *Ty,               ///< The type to convert to
2062     const std::string &Name = "", ///< A name for the new instruction
2063     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2064   );
2065
2066   /// @brief Constructor with insert-at-end-of-block semantics
2067   IntToPtrInst(
2068     Value *S,                     ///< The value to be converted
2069     const Type *Ty,               ///< The type to convert to
2070     const std::string &Name,      ///< A name for the new instruction
2071     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2072   );
2073
2074   /// @brief Clone an identical IntToPtrInst
2075   virtual CastInst *clone() const;
2076
2077   // Methods for support type inquiry through isa, cast, and dyn_cast:
2078   static inline bool classof(const IntToPtrInst *) { return true; }
2079   static inline bool classof(const Instruction *I) {
2080     return I->getOpcode() == IntToPtr;
2081   }
2082   static inline bool classof(const Value *V) {
2083     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2084   }
2085 };
2086
2087 //===----------------------------------------------------------------------===//
2088 //                                 PtrToIntInst Class
2089 //===----------------------------------------------------------------------===//
2090
2091 /// @brief This class represents a cast from a pointer to an integer
2092 class PtrToIntInst : public CastInst {
2093   PtrToIntInst(const PtrToIntInst &CI)
2094     : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2095   }
2096 public:
2097   /// @brief Constructor with insert-before-instruction semantics
2098   PtrToIntInst(
2099     Value *S,                     ///< The value to be converted
2100     const Type *Ty,               ///< The type to convert to
2101     const std::string &Name = "", ///< A name for the new instruction
2102     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2103   );
2104
2105   /// @brief Constructor with insert-at-end-of-block semantics
2106   PtrToIntInst(
2107     Value *S,                     ///< The value to be converted
2108     const Type *Ty,               ///< The type to convert to
2109     const std::string &Name,      ///< A name for the new instruction
2110     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2111   );
2112
2113   /// @brief Clone an identical PtrToIntInst
2114   virtual CastInst *clone() const;
2115
2116   // Methods for support type inquiry through isa, cast, and dyn_cast:
2117   static inline bool classof(const PtrToIntInst *) { return true; }
2118   static inline bool classof(const Instruction *I) {
2119     return I->getOpcode() == PtrToInt;
2120   }
2121   static inline bool classof(const Value *V) {
2122     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2123   }
2124 };
2125
2126 //===----------------------------------------------------------------------===//
2127 //                             BitCastInst Class
2128 //===----------------------------------------------------------------------===//
2129
2130 /// @brief This class represents a no-op cast from one type to another.
2131 class BitCastInst : public CastInst {
2132   BitCastInst(const BitCastInst &CI)
2133     : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2134   }
2135 public:
2136   /// @brief Constructor with insert-before-instruction semantics
2137   BitCastInst(
2138     Value *S,                     ///< The value to be casted
2139     const Type *Ty,               ///< The type to casted to
2140     const std::string &Name = "", ///< A name for the new instruction
2141     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2142   );
2143
2144   /// @brief Constructor with insert-at-end-of-block semantics
2145   BitCastInst(
2146     Value *S,                     ///< The value to be casted
2147     const Type *Ty,               ///< The type to casted to
2148     const std::string &Name,      ///< A name for the new instruction
2149     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2150   );
2151
2152   /// @brief Clone an identical BitCastInst
2153   virtual CastInst *clone() const;
2154
2155   // Methods for support type inquiry through isa, cast, and dyn_cast:
2156   static inline bool classof(const BitCastInst *) { return true; }
2157   static inline bool classof(const Instruction *I) {
2158     return I->getOpcode() == BitCast;
2159   }
2160   static inline bool classof(const Value *V) {
2161     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2162   }
2163 };
2164
2165 } // End llvm namespace
2166
2167 #endif