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