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