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