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