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