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