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