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