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