Remove ICmpInst::isSignedPredicate which was a reimplementation
[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 "llvm/InstrTypes.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Attributes.h"
22 #include "llvm/BasicBlock.h"
23 #include "llvm/CallingConv.h"
24 #include "llvm/LLVMContext.h"
25 #include "llvm/ADT/SmallVector.h"
26 #include <iterator>
27
28 namespace llvm {
29
30 class ConstantInt;
31 class ConstantRange;
32 class APInt;
33 class LLVMContext;
34 class DominatorTree;
35
36 //===----------------------------------------------------------------------===//
37 //                                AllocaInst Class
38 //===----------------------------------------------------------------------===//
39
40 /// AllocaInst - an instruction to allocate memory on the stack
41 ///
42 class AllocaInst : public UnaryInstruction {
43 public:
44   explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
45                       const Twine &Name = "", Instruction *InsertBefore = 0);
46   AllocaInst(const Type *Ty, Value *ArraySize, 
47              const Twine &Name, BasicBlock *InsertAtEnd);
48
49   AllocaInst(const Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
50   AllocaInst(const Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
51
52   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
53              const Twine &Name = "", Instruction *InsertBefore = 0);
54   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
55              const Twine &Name, BasicBlock *InsertAtEnd);
56
57   // Out of line virtual method, so the vtable, etc. has a home.
58   virtual ~AllocaInst();
59
60   /// isArrayAllocation - Return true if there is an allocation size parameter
61   /// to the allocation instruction that is not 1.
62   ///
63   bool isArrayAllocation() const;
64
65   /// getArraySize - Get the number of elements allocated. For a simple
66   /// allocation of a single element, this will return a constant 1 value.
67   ///
68   const Value *getArraySize() const { return getOperand(0); }
69   Value *getArraySize() { return getOperand(0); }
70
71   /// getType - Overload to return most specific pointer type
72   ///
73   const PointerType *getType() const {
74     return reinterpret_cast<const PointerType*>(Instruction::getType());
75   }
76
77   /// getAllocatedType - Return the type that is being allocated by the
78   /// instruction.
79   ///
80   const Type *getAllocatedType() const;
81
82   /// getAlignment - Return the alignment of the memory that is being allocated
83   /// by the instruction.
84   ///
85   unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
86   void setAlignment(unsigned Align);
87
88   /// isStaticAlloca - Return true if this alloca is in the entry block of the
89   /// function and is a constant size.  If so, the code generator will fold it
90   /// into the prolog/epilog code, so it is basically free.
91   bool isStaticAlloca() const;
92
93   virtual AllocaInst *clone() const;
94
95   // Methods for support type inquiry through isa, cast, and dyn_cast:
96   static inline bool classof(const AllocaInst *) { return true; }
97   static inline bool classof(const Instruction *I) {
98     return (I->getOpcode() == Instruction::Alloca);
99   }
100   static inline bool classof(const Value *V) {
101     return isa<Instruction>(V) && classof(cast<Instruction>(V));
102   }
103 };
104
105
106 //===----------------------------------------------------------------------===//
107 //                                 FreeInst Class
108 //===----------------------------------------------------------------------===//
109
110 /// FreeInst - an instruction to deallocate memory
111 ///
112 class FreeInst : public UnaryInstruction {
113   void AssertOK();
114 public:
115   explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
116   FreeInst(Value *Ptr, BasicBlock *InsertAfter);
117
118   virtual FreeInst *clone() const;
119
120   // Accessor methods for consistency with other memory operations
121   Value *getPointerOperand() { return getOperand(0); }
122   const Value *getPointerOperand() const { return getOperand(0); }
123
124   // Methods for support type inquiry through isa, cast, and dyn_cast:
125   static inline bool classof(const FreeInst *) { return true; }
126   static inline bool classof(const Instruction *I) {
127     return (I->getOpcode() == Instruction::Free);
128   }
129   static inline bool classof(const Value *V) {
130     return isa<Instruction>(V) && classof(cast<Instruction>(V));
131   }
132 };
133
134
135 //===----------------------------------------------------------------------===//
136 //                                LoadInst Class
137 //===----------------------------------------------------------------------===//
138
139 /// LoadInst - an instruction for reading from memory.  This uses the
140 /// SubclassData field in Value to store whether or not the load is volatile.
141 ///
142 class LoadInst : public UnaryInstruction {
143   void AssertOK();
144 public:
145   LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
146   LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
147   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
148            Instruction *InsertBefore = 0);
149   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
150            unsigned Align, Instruction *InsertBefore = 0);
151   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
152            BasicBlock *InsertAtEnd);
153   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
154            unsigned Align, BasicBlock *InsertAtEnd);
155
156   LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
157   LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
158   explicit LoadInst(Value *Ptr, const char *NameStr = 0,
159                     bool isVolatile = false,  Instruction *InsertBefore = 0);
160   LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
161            BasicBlock *InsertAtEnd);
162
163   /// isVolatile - Return true if this is a load from a volatile memory
164   /// location.
165   ///
166   bool isVolatile() const { return SubclassData & 1; }
167
168   /// setVolatile - Specify whether this is a volatile load or not.
169   ///
170   void setVolatile(bool V) {
171     SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
172   }
173
174   virtual LoadInst *clone() const;
175
176   /// getAlignment - Return the alignment of the access that is being performed
177   ///
178   unsigned getAlignment() const {
179     return (1 << (SubclassData>>1)) >> 1;
180   }
181
182   void setAlignment(unsigned Align);
183
184   Value *getPointerOperand() { return getOperand(0); }
185   const Value *getPointerOperand() const { return getOperand(0); }
186   static unsigned getPointerOperandIndex() { return 0U; }
187
188   unsigned getPointerAddressSpace() const {
189     return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
190   }
191   
192   
193   // Methods for support type inquiry through isa, cast, and dyn_cast:
194   static inline bool classof(const LoadInst *) { return true; }
195   static inline bool classof(const Instruction *I) {
196     return I->getOpcode() == Instruction::Load;
197   }
198   static inline bool classof(const Value *V) {
199     return isa<Instruction>(V) && classof(cast<Instruction>(V));
200   }
201 };
202
203
204 //===----------------------------------------------------------------------===//
205 //                                StoreInst Class
206 //===----------------------------------------------------------------------===//
207
208 /// StoreInst - an instruction for storing to memory
209 ///
210 class StoreInst : public Instruction {
211   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
212   void AssertOK();
213 public:
214   // allocate space for exactly two operands
215   void *operator new(size_t s) {
216     return User::operator new(s, 2);
217   }
218   StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
219   StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
220   StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
221             Instruction *InsertBefore = 0);
222   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
223             unsigned Align, Instruction *InsertBefore = 0);
224   StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
225   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
226             unsigned Align, BasicBlock *InsertAtEnd);
227
228
229   /// isVolatile - Return true if this is a load from a volatile memory
230   /// location.
231   ///
232   bool isVolatile() const { return SubclassData & 1; }
233
234   /// setVolatile - Specify whether this is a volatile load or not.
235   ///
236   void setVolatile(bool V) {
237     SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
238   }
239
240   /// Transparently provide more efficient getOperand methods.
241   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
242
243   /// getAlignment - Return the alignment of the access that is being performed
244   ///
245   unsigned getAlignment() const {
246     return (1 << (SubclassData>>1)) >> 1;
247   }
248
249   void setAlignment(unsigned Align);
250
251   virtual StoreInst *clone() const;
252
253   Value *getPointerOperand() { return getOperand(1); }
254   const Value *getPointerOperand() const { return getOperand(1); }
255   static unsigned getPointerOperandIndex() { return 1U; }
256
257   unsigned getPointerAddressSpace() const {
258     return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
259   }
260   
261   // Methods for support type inquiry through isa, cast, and dyn_cast:
262   static inline bool classof(const StoreInst *) { return true; }
263   static inline bool classof(const Instruction *I) {
264     return I->getOpcode() == Instruction::Store;
265   }
266   static inline bool classof(const Value *V) {
267     return isa<Instruction>(V) && classof(cast<Instruction>(V));
268   }
269 };
270
271 template <>
272 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<2> {
273 };
274
275 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
276
277 //===----------------------------------------------------------------------===//
278 //                             GetElementPtrInst Class
279 //===----------------------------------------------------------------------===//
280
281 // checkType - Simple wrapper function to give a better assertion failure
282 // message on bad indexes for a gep instruction.
283 //
284 static inline const Type *checkType(const Type *Ty) {
285   assert(Ty && "Invalid GetElementPtrInst indices for type!");
286   return Ty;
287 }
288
289 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
290 /// access elements of arrays and structs
291 ///
292 class GetElementPtrInst : public Instruction {
293   GetElementPtrInst(const GetElementPtrInst &GEPI);
294   void init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
295             const Twine &NameStr);
296   void init(Value *Ptr, Value *Idx, const Twine &NameStr);
297
298   template<typename InputIterator>
299   void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
300             const Twine &NameStr,
301             // This argument ensures that we have an iterator we can
302             // do arithmetic on in constant time
303             std::random_access_iterator_tag) {
304     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
305
306     if (NumIdx > 0) {
307       // This requires that the iterator points to contiguous memory.
308       init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
309                                      // we have to build an array here
310     }
311     else {
312       init(Ptr, 0, NumIdx, NameStr);
313     }
314   }
315
316   /// getIndexedType - Returns the type of the element that would be loaded with
317   /// a load instruction with the specified parameters.
318   ///
319   /// Null is returned if the indices are invalid for the specified
320   /// pointer type.
321   ///
322   template<typename InputIterator>
323   static const Type *getIndexedType(const Type *Ptr,
324                                     InputIterator IdxBegin,
325                                     InputIterator IdxEnd,
326                                     // This argument ensures that we
327                                     // have an iterator we can do
328                                     // arithmetic on in constant time
329                                     std::random_access_iterator_tag) {
330     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
331
332     if (NumIdx > 0)
333       // This requires that the iterator points to contiguous memory.
334       return getIndexedType(Ptr, &*IdxBegin, NumIdx);
335     else
336       return getIndexedType(Ptr, (Value *const*)0, NumIdx);
337   }
338
339   /// Constructors - Create a getelementptr instruction with a base pointer an
340   /// list of indices.  The first ctor can optionally insert before an existing
341   /// instruction, the second appends the new instruction to the specified
342   /// BasicBlock.
343   template<typename InputIterator>
344   inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
345                            InputIterator IdxEnd,
346                            unsigned Values,
347                            const Twine &NameStr,
348                            Instruction *InsertBefore);
349   template<typename InputIterator>
350   inline GetElementPtrInst(Value *Ptr,
351                            InputIterator IdxBegin, InputIterator IdxEnd,
352                            unsigned Values,
353                            const Twine &NameStr, BasicBlock *InsertAtEnd);
354
355   /// Constructors - These two constructors are convenience methods because one
356   /// and two index getelementptr instructions are so common.
357   GetElementPtrInst(Value *Ptr, Value *Idx, const Twine &NameStr = "",
358                     Instruction *InsertBefore = 0);
359   GetElementPtrInst(Value *Ptr, Value *Idx,
360                     const Twine &NameStr, BasicBlock *InsertAtEnd);
361 public:
362   template<typename InputIterator>
363   static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
364                                    InputIterator IdxEnd,
365                                    const Twine &NameStr = "",
366                                    Instruction *InsertBefore = 0) {
367     typename std::iterator_traits<InputIterator>::difference_type Values =
368       1 + std::distance(IdxBegin, IdxEnd);
369     return new(Values)
370       GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
371   }
372   template<typename InputIterator>
373   static GetElementPtrInst *Create(Value *Ptr,
374                                    InputIterator IdxBegin, InputIterator IdxEnd,
375                                    const Twine &NameStr,
376                                    BasicBlock *InsertAtEnd) {
377     typename std::iterator_traits<InputIterator>::difference_type Values =
378       1 + std::distance(IdxBegin, IdxEnd);
379     return new(Values)
380       GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
381   }
382
383   /// Constructors - These two creators are convenience methods because one
384   /// index getelementptr instructions are so common.
385   static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
386                                    const Twine &NameStr = "",
387                                    Instruction *InsertBefore = 0) {
388     return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore);
389   }
390   static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
391                                    const Twine &NameStr,
392                                    BasicBlock *InsertAtEnd) {
393     return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
394   }
395
396   /// Create an "inbounds" getelementptr. See the documentation for the
397   /// "inbounds" flag in LangRef.html for details.
398   template<typename InputIterator>
399   static GetElementPtrInst *CreateInBounds(Value *Ptr, InputIterator IdxBegin,
400                                            InputIterator IdxEnd,
401                                            const Twine &NameStr = "",
402                                            Instruction *InsertBefore = 0) {
403     GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
404                                     NameStr, InsertBefore);
405     GEP->setIsInBounds(true);
406     return GEP;
407   }
408   template<typename InputIterator>
409   static GetElementPtrInst *CreateInBounds(Value *Ptr,
410                                            InputIterator IdxBegin,
411                                            InputIterator IdxEnd,
412                                            const Twine &NameStr,
413                                            BasicBlock *InsertAtEnd) {
414     GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
415                                     NameStr, InsertAtEnd);
416     GEP->setIsInBounds(true);
417     return GEP;
418   }
419   static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
420                                            const Twine &NameStr = "",
421                                            Instruction *InsertBefore = 0) {
422     GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore);
423     GEP->setIsInBounds(true);
424     return GEP;
425   }
426   static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
427                                            const Twine &NameStr,
428                                            BasicBlock *InsertAtEnd) {
429     GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd);
430     GEP->setIsInBounds(true);
431     return GEP;
432   }
433
434   virtual GetElementPtrInst *clone() const;
435
436   /// Transparently provide more efficient getOperand methods.
437   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
438
439   // getType - Overload to return most specific pointer type...
440   const PointerType *getType() const {
441     return reinterpret_cast<const PointerType*>(Instruction::getType());
442   }
443
444   /// getIndexedType - Returns the type of the element that would be loaded with
445   /// a load instruction with the specified parameters.
446   ///
447   /// Null is returned if the indices are invalid for the specified
448   /// pointer type.
449   ///
450   template<typename InputIterator>
451   static const Type *getIndexedType(const Type *Ptr,
452                                     InputIterator IdxBegin,
453                                     InputIterator IdxEnd) {
454     return getIndexedType(Ptr, IdxBegin, IdxEnd,
455                           typename std::iterator_traits<InputIterator>::
456                           iterator_category());
457   }
458
459   static const Type *getIndexedType(const Type *Ptr,
460                                     Value* const *Idx, unsigned NumIdx);
461
462   static const Type *getIndexedType(const Type *Ptr,
463                                     uint64_t const *Idx, unsigned NumIdx);
464
465   static const Type *getIndexedType(const Type *Ptr, Value *Idx);
466
467   inline op_iterator       idx_begin()       { return op_begin()+1; }
468   inline const_op_iterator idx_begin() const { return op_begin()+1; }
469   inline op_iterator       idx_end()         { return op_end(); }
470   inline const_op_iterator idx_end()   const { return op_end(); }
471
472   Value *getPointerOperand() {
473     return getOperand(0);
474   }
475   const Value *getPointerOperand() const {
476     return getOperand(0);
477   }
478   static unsigned getPointerOperandIndex() {
479     return 0U;                      // get index for modifying correct operand
480   }
481   
482   unsigned getPointerAddressSpace() const {
483     return cast<PointerType>(getType())->getAddressSpace();
484   }
485
486   /// getPointerOperandType - Method to return the pointer operand as a
487   /// PointerType.
488   const PointerType *getPointerOperandType() const {
489     return reinterpret_cast<const PointerType*>(getPointerOperand()->getType());
490   }
491
492
493   unsigned getNumIndices() const {  // Note: always non-negative
494     return getNumOperands() - 1;
495   }
496
497   bool hasIndices() const {
498     return getNumOperands() > 1;
499   }
500
501   /// hasAllZeroIndices - Return true if all of the indices of this GEP are
502   /// zeros.  If so, the result pointer and the first operand have the same
503   /// value, just potentially different types.
504   bool hasAllZeroIndices() const;
505
506   /// hasAllConstantIndices - Return true if all of the indices of this GEP are
507   /// constant integers.  If so, the result pointer and the first operand have
508   /// a constant offset between them.
509   bool hasAllConstantIndices() const;
510
511   /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
512   /// See LangRef.html for the meaning of inbounds on a getelementptr.
513   void setIsInBounds(bool b = true);
514
515   /// isInBounds - Determine whether the GEP has the inbounds flag.
516   bool isInBounds() const;
517
518   // Methods for support type inquiry through isa, cast, and dyn_cast:
519   static inline bool classof(const GetElementPtrInst *) { return true; }
520   static inline bool classof(const Instruction *I) {
521     return (I->getOpcode() == Instruction::GetElementPtr);
522   }
523   static inline bool classof(const Value *V) {
524     return isa<Instruction>(V) && classof(cast<Instruction>(V));
525   }
526 };
527
528 template <>
529 struct OperandTraits<GetElementPtrInst> : public VariadicOperandTraits<1> {
530 };
531
532 template<typename InputIterator>
533 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
534                                      InputIterator IdxBegin,
535                                      InputIterator IdxEnd,
536                                      unsigned Values,
537                                      const Twine &NameStr,
538                                      Instruction *InsertBefore)
539   : Instruction(PointerType::get(checkType(
540                                    getIndexedType(Ptr->getType(),
541                                                   IdxBegin, IdxEnd)),
542                                  cast<PointerType>(Ptr->getType())
543                                    ->getAddressSpace()),
544                 GetElementPtr,
545                 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
546                 Values, InsertBefore) {
547   init(Ptr, IdxBegin, IdxEnd, NameStr,
548        typename std::iterator_traits<InputIterator>::iterator_category());
549 }
550 template<typename InputIterator>
551 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
552                                      InputIterator IdxBegin,
553                                      InputIterator IdxEnd,
554                                      unsigned Values,
555                                      const Twine &NameStr,
556                                      BasicBlock *InsertAtEnd)
557   : Instruction(PointerType::get(checkType(
558                                    getIndexedType(Ptr->getType(),
559                                                   IdxBegin, IdxEnd)),
560                                  cast<PointerType>(Ptr->getType())
561                                    ->getAddressSpace()),
562                 GetElementPtr,
563                 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
564                 Values, InsertAtEnd) {
565   init(Ptr, IdxBegin, IdxEnd, NameStr,
566        typename std::iterator_traits<InputIterator>::iterator_category());
567 }
568
569
570 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
571
572
573 //===----------------------------------------------------------------------===//
574 //                               ICmpInst Class
575 //===----------------------------------------------------------------------===//
576
577 /// This instruction compares its operands according to the predicate given
578 /// to the constructor. It only operates on integers or pointers. The operands
579 /// must be identical types.
580 /// @brief Represent an integer comparison operator.
581 class ICmpInst: public CmpInst {
582 public:
583   /// @brief Constructor with insert-before-instruction semantics.
584   ICmpInst(
585     Instruction *InsertBefore,  ///< Where to insert
586     Predicate pred,  ///< The predicate to use for the comparison
587     Value *LHS,      ///< The left-hand-side of the expression
588     Value *RHS,      ///< The right-hand-side of the expression
589     const Twine &NameStr = ""  ///< Name of the instruction
590   ) : CmpInst(makeCmpResultType(LHS->getType()),
591               Instruction::ICmp, pred, LHS, RHS, NameStr,
592               InsertBefore) {
593     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
594            pred <= CmpInst::LAST_ICMP_PREDICATE &&
595            "Invalid ICmp predicate value");
596     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
597           "Both operands to ICmp instruction are not of the same type!");
598     // Check that the operands are the right type
599     assert((getOperand(0)->getType()->isIntOrIntVector() ||
600             isa<PointerType>(getOperand(0)->getType())) &&
601            "Invalid operand types for ICmp instruction");
602   }
603
604   /// @brief Constructor with insert-at-end semantics.
605   ICmpInst(
606     BasicBlock &InsertAtEnd, ///< Block to insert into.
607     Predicate pred,  ///< The predicate to use for the comparison
608     Value *LHS,      ///< The left-hand-side of the expression
609     Value *RHS,      ///< The right-hand-side of the expression
610     const Twine &NameStr = ""  ///< Name of the instruction
611   ) : CmpInst(makeCmpResultType(LHS->getType()),
612               Instruction::ICmp, pred, LHS, RHS, NameStr,
613               &InsertAtEnd) {
614     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
615           pred <= CmpInst::LAST_ICMP_PREDICATE &&
616           "Invalid ICmp predicate value");
617     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
618           "Both operands to ICmp instruction are not of the same type!");
619     // Check that the operands are the right type
620     assert((getOperand(0)->getType()->isIntOrIntVector() ||
621             isa<PointerType>(getOperand(0)->getType())) &&
622            "Invalid operand types for ICmp instruction");
623   }
624
625   /// @brief Constructor with no-insertion semantics
626   ICmpInst(
627     Predicate pred, ///< The predicate to use for the comparison
628     Value *LHS,     ///< The left-hand-side of the expression
629     Value *RHS,     ///< The right-hand-side of the expression
630     const Twine &NameStr = "" ///< Name of the instruction
631   ) : CmpInst(makeCmpResultType(LHS->getType()),
632               Instruction::ICmp, pred, LHS, RHS, NameStr) {
633     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
634            pred <= CmpInst::LAST_ICMP_PREDICATE &&
635            "Invalid ICmp predicate value");
636     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
637           "Both operands to ICmp instruction are not of the same type!");
638     // Check that the operands are the right type
639     assert((getOperand(0)->getType()->isIntOrIntVector() ||
640             isa<PointerType>(getOperand(0)->getType())) &&
641            "Invalid operand types for ICmp instruction");
642   }
643
644   /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
645   /// @returns the predicate that would be the result if the operand were
646   /// regarded as signed.
647   /// @brief Return the signed version of the predicate
648   Predicate getSignedPredicate() const {
649     return getSignedPredicate(getPredicate());
650   }
651
652   /// This is a static version that you can use without an instruction.
653   /// @brief Return the signed version of the predicate.
654   static Predicate getSignedPredicate(Predicate pred);
655
656   /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
657   /// @returns the predicate that would be the result if the operand were
658   /// regarded as unsigned.
659   /// @brief Return the unsigned version of the predicate
660   Predicate getUnsignedPredicate() const {
661     return getUnsignedPredicate(getPredicate());
662   }
663
664   /// This is a static version that you can use without an instruction.
665   /// @brief Return the unsigned version of the predicate.
666   static Predicate getUnsignedPredicate(Predicate pred);
667
668   /// isEquality - Return true if this predicate is either EQ or NE.  This also
669   /// tests for commutativity.
670   static bool isEquality(Predicate P) {
671     return P == ICMP_EQ || P == ICMP_NE;
672   }
673
674   /// isEquality - Return true if this predicate is either EQ or NE.  This also
675   /// tests for commutativity.
676   bool isEquality() const {
677     return isEquality(getPredicate());
678   }
679
680   /// @returns true if the predicate of this ICmpInst is commutative
681   /// @brief Determine if this relation is commutative.
682   bool isCommutative() const { return isEquality(); }
683
684   /// isRelational - Return true if the predicate is relational (not EQ or NE).
685   ///
686   bool isRelational() const {
687     return !isEquality();
688   }
689
690   /// isRelational - Return true if the predicate is relational (not EQ or NE).
691   ///
692   static bool isRelational(Predicate P) {
693     return !isEquality(P);
694   }
695
696   /// Initialize a set of values that all satisfy the predicate with C.
697   /// @brief Make a ConstantRange for a relation with a constant value.
698   static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
699
700   /// Exchange the two operands to this instruction in such a way that it does
701   /// not modify the semantics of the instruction. The predicate value may be
702   /// changed to retain the same result if the predicate is order dependent
703   /// (e.g. ult).
704   /// @brief Swap operands and adjust predicate.
705   void swapOperands() {
706     SubclassData = getSwappedPredicate();
707     Op<0>().swap(Op<1>());
708   }
709
710   virtual ICmpInst *clone() const;
711
712   // Methods for support type inquiry through isa, cast, and dyn_cast:
713   static inline bool classof(const ICmpInst *) { return true; }
714   static inline bool classof(const Instruction *I) {
715     return I->getOpcode() == Instruction::ICmp;
716   }
717   static inline bool classof(const Value *V) {
718     return isa<Instruction>(V) && classof(cast<Instruction>(V));
719   }
720
721 };
722
723 //===----------------------------------------------------------------------===//
724 //                               FCmpInst Class
725 //===----------------------------------------------------------------------===//
726
727 /// This instruction compares its operands according to the predicate given
728 /// to the constructor. It only operates on floating point values or packed
729 /// vectors of floating point values. The operands must be identical types.
730 /// @brief Represents a floating point comparison operator.
731 class FCmpInst: public CmpInst {
732 public:
733   /// @brief Constructor with insert-before-instruction semantics.
734   FCmpInst(
735     Instruction *InsertBefore, ///< Where to insert
736     Predicate pred,  ///< The predicate to use for the comparison
737     Value *LHS,      ///< The left-hand-side of the expression
738     Value *RHS,      ///< The right-hand-side of the expression
739     const Twine &NameStr = ""  ///< Name of the instruction
740   ) : CmpInst(makeCmpResultType(LHS->getType()),
741               Instruction::FCmp, pred, LHS, RHS, NameStr,
742               InsertBefore) {
743     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
744            "Invalid FCmp predicate value");
745     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
746            "Both operands to FCmp instruction are not of the same type!");
747     // Check that the operands are the right type
748     assert(getOperand(0)->getType()->isFPOrFPVector() &&
749            "Invalid operand types for FCmp instruction");
750   }
751   
752   /// @brief Constructor with insert-at-end semantics.
753   FCmpInst(
754     BasicBlock &InsertAtEnd, ///< Block to insert into.
755     Predicate pred,  ///< The predicate to use for the comparison
756     Value *LHS,      ///< The left-hand-side of the expression
757     Value *RHS,      ///< The right-hand-side of the expression
758     const Twine &NameStr = ""  ///< Name of the instruction
759   ) : CmpInst(makeCmpResultType(LHS->getType()),
760               Instruction::FCmp, pred, LHS, RHS, NameStr,
761               &InsertAtEnd) {
762     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
763            "Invalid FCmp predicate value");
764     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
765            "Both operands to FCmp instruction are not of the same type!");
766     // Check that the operands are the right type
767     assert(getOperand(0)->getType()->isFPOrFPVector() &&
768            "Invalid operand types for FCmp instruction");
769   }
770
771   /// @brief Constructor with no-insertion semantics
772   FCmpInst(
773     Predicate pred, ///< The predicate to use for the comparison
774     Value *LHS,     ///< The left-hand-side of the expression
775     Value *RHS,     ///< The right-hand-side of the expression
776     const Twine &NameStr = "" ///< Name of the instruction
777   ) : CmpInst(makeCmpResultType(LHS->getType()),
778               Instruction::FCmp, pred, LHS, RHS, NameStr) {
779     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
780            "Invalid FCmp predicate value");
781     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
782            "Both operands to FCmp instruction are not of the same type!");
783     // Check that the operands are the right type
784     assert(getOperand(0)->getType()->isFPOrFPVector() &&
785            "Invalid operand types for FCmp instruction");
786   }
787
788   /// @returns true if the predicate of this instruction is EQ or NE.
789   /// @brief Determine if this is an equality predicate.
790   bool isEquality() const {
791     return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
792            SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
793   }
794
795   /// @returns true if the predicate of this instruction is commutative.
796   /// @brief Determine if this is a commutative predicate.
797   bool isCommutative() const {
798     return isEquality() ||
799            SubclassData == FCMP_FALSE ||
800            SubclassData == FCMP_TRUE ||
801            SubclassData == FCMP_ORD ||
802            SubclassData == FCMP_UNO;
803   }
804
805   /// @returns true if the predicate is relational (not EQ or NE).
806   /// @brief Determine if this a relational predicate.
807   bool isRelational() const { return !isEquality(); }
808
809   /// Exchange the two operands to this instruction in such a way that it does
810   /// not modify the semantics of the instruction. The predicate value may be
811   /// changed to retain the same result if the predicate is order dependent
812   /// (e.g. ult).
813   /// @brief Swap operands and adjust predicate.
814   void swapOperands() {
815     SubclassData = getSwappedPredicate();
816     Op<0>().swap(Op<1>());
817   }
818
819   virtual FCmpInst *clone() const;
820
821   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
822   static inline bool classof(const FCmpInst *) { return true; }
823   static inline bool classof(const Instruction *I) {
824     return I->getOpcode() == Instruction::FCmp;
825   }
826   static inline bool classof(const Value *V) {
827     return isa<Instruction>(V) && classof(cast<Instruction>(V));
828   }
829 };
830
831 //===----------------------------------------------------------------------===//
832 //                                 CallInst Class
833 //===----------------------------------------------------------------------===//
834 /// CallInst - This class represents a function call, abstracting a target
835 /// machine's calling convention.  This class uses low bit of the SubClassData
836 /// field to indicate whether or not this is a tail call.  The rest of the bits
837 /// hold the calling convention of the call.
838 ///
839
840 class CallInst : public Instruction {
841   AttrListPtr AttributeList; ///< parameter attributes for call
842   CallInst(const CallInst &CI);
843   void init(Value *Func, Value* const *Params, unsigned NumParams);
844   void init(Value *Func, Value *Actual1, Value *Actual2);
845   void init(Value *Func, Value *Actual);
846   void init(Value *Func);
847
848   template<typename InputIterator>
849   void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
850             const Twine &NameStr,
851             // This argument ensures that we have an iterator we can
852             // do arithmetic on in constant time
853             std::random_access_iterator_tag) {
854     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
855
856     // This requires that the iterator points to contiguous memory.
857     init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
858     setName(NameStr);
859   }
860
861   /// Construct a CallInst given a range of arguments.  InputIterator
862   /// must be a random-access iterator pointing to contiguous storage
863   /// (e.g. a std::vector<>::iterator).  Checks are made for
864   /// random-accessness but not for contiguous storage as that would
865   /// incur runtime overhead.
866   /// @brief Construct a CallInst from a range of arguments
867   template<typename InputIterator>
868   CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
869            const Twine &NameStr, Instruction *InsertBefore);
870
871   /// Construct a CallInst given a range of arguments.  InputIterator
872   /// must be a random-access iterator pointing to contiguous storage
873   /// (e.g. a std::vector<>::iterator).  Checks are made for
874   /// random-accessness but not for contiguous storage as that would
875   /// incur runtime overhead.
876   /// @brief Construct a CallInst from a range of arguments
877   template<typename InputIterator>
878   inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
879                   const Twine &NameStr, BasicBlock *InsertAtEnd);
880
881   CallInst(Value *F, Value *Actual, const Twine &NameStr,
882            Instruction *InsertBefore);
883   CallInst(Value *F, Value *Actual, const Twine &NameStr,
884            BasicBlock *InsertAtEnd);
885   explicit CallInst(Value *F, const Twine &NameStr,
886                     Instruction *InsertBefore);
887   CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
888 public:
889   template<typename InputIterator>
890   static CallInst *Create(Value *Func,
891                           InputIterator ArgBegin, InputIterator ArgEnd,
892                           const Twine &NameStr = "",
893                           Instruction *InsertBefore = 0) {
894     return new((unsigned)(ArgEnd - ArgBegin + 1))
895       CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertBefore);
896   }
897   template<typename InputIterator>
898   static CallInst *Create(Value *Func,
899                           InputIterator ArgBegin, InputIterator ArgEnd,
900                           const Twine &NameStr, BasicBlock *InsertAtEnd) {
901     return new((unsigned)(ArgEnd - ArgBegin + 1))
902       CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertAtEnd);
903   }
904   static CallInst *Create(Value *F, Value *Actual,
905                           const Twine &NameStr = "",
906                           Instruction *InsertBefore = 0) {
907     return new(2) CallInst(F, Actual, NameStr, InsertBefore);
908   }
909   static CallInst *Create(Value *F, Value *Actual, const Twine &NameStr,
910                           BasicBlock *InsertAtEnd) {
911     return new(2) CallInst(F, Actual, NameStr, InsertAtEnd);
912   }
913   static CallInst *Create(Value *F, const Twine &NameStr = "",
914                           Instruction *InsertBefore = 0) {
915     return new(1) CallInst(F, NameStr, InsertBefore);
916   }
917   static CallInst *Create(Value *F, const Twine &NameStr,
918                           BasicBlock *InsertAtEnd) {
919     return new(1) CallInst(F, NameStr, InsertAtEnd);
920   }
921   /// CreateMalloc - Generate the IR for a call to malloc:
922   /// 1. Compute the malloc call's argument as the specified type's size,
923   ///    possibly multiplied by the array size if the array size is not
924   ///    constant 1.
925   /// 2. Call malloc with that argument.
926   /// 3. Bitcast the result of the malloc call to the specified type.
927   static Instruction *CreateMalloc(Instruction *InsertBefore,
928                                    const Type *IntPtrTy, const Type *AllocTy,
929                                    Value *ArraySize = 0,
930                                    const Twine &Name = "");
931   static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
932                                    const Type *IntPtrTy, const Type *AllocTy,
933                                    Value *ArraySize = 0, Function* MallocF = 0,
934                                    const Twine &Name = "");
935   /// CreateFree - Generate the IR for a call to the builtin free function.
936   static void CreateFree(Value* Source, Instruction *InsertBefore);
937   static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
938
939   ~CallInst();
940
941   bool isTailCall() const           { return SubclassData & 1; }
942   void setTailCall(bool isTC = true) {
943     SubclassData = (SubclassData & ~1) | unsigned(isTC);
944   }
945
946   virtual CallInst *clone() const;
947
948   /// Provide fast operand accessors
949   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
950
951   /// getCallingConv/setCallingConv - Get or set the calling convention of this
952   /// function call.
953   CallingConv::ID getCallingConv() const {
954     return static_cast<CallingConv::ID>(SubclassData >> 1);
955   }
956   void setCallingConv(CallingConv::ID CC) {
957     SubclassData = (SubclassData & 1) | (static_cast<unsigned>(CC) << 1);
958   }
959
960   /// getAttributes - Return the parameter attributes for this call.
961   ///
962   const AttrListPtr &getAttributes() const { return AttributeList; }
963
964   /// setAttributes - Set the parameter attributes for this call.
965   ///
966   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
967
968   /// addAttribute - adds the attribute to the list of attributes.
969   void addAttribute(unsigned i, Attributes attr);
970
971   /// removeAttribute - removes the attribute from the list of attributes.
972   void removeAttribute(unsigned i, Attributes attr);
973
974   /// @brief Determine whether the call or the callee has the given attribute.
975   bool paramHasAttr(unsigned i, Attributes attr) const;
976
977   /// @brief Extract the alignment for a call or parameter (0=unknown).
978   unsigned getParamAlignment(unsigned i) const {
979     return AttributeList.getParamAlignment(i);
980   }
981
982   /// @brief Determine if the call does not access memory.
983   bool doesNotAccessMemory() const {
984     return paramHasAttr(~0, Attribute::ReadNone);
985   }
986   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
987     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
988     else removeAttribute(~0, Attribute::ReadNone);
989   }
990
991   /// @brief Determine if the call does not access or only reads memory.
992   bool onlyReadsMemory() const {
993     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
994   }
995   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
996     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
997     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
998   }
999
1000   /// @brief Determine if the call cannot return.
1001   bool doesNotReturn() const {
1002     return paramHasAttr(~0, Attribute::NoReturn);
1003   }
1004   void setDoesNotReturn(bool DoesNotReturn = true) {
1005     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1006     else removeAttribute(~0, Attribute::NoReturn);
1007   }
1008
1009   /// @brief Determine if the call cannot unwind.
1010   bool doesNotThrow() const {
1011     return paramHasAttr(~0, Attribute::NoUnwind);
1012   }
1013   void setDoesNotThrow(bool DoesNotThrow = true) {
1014     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1015     else removeAttribute(~0, Attribute::NoUnwind);
1016   }
1017
1018   /// @brief Determine if the call returns a structure through first
1019   /// pointer argument.
1020   bool hasStructRetAttr() const {
1021     // Be friendly and also check the callee.
1022     return paramHasAttr(1, Attribute::StructRet);
1023   }
1024
1025   /// @brief Determine if any call argument is an aggregate passed by value.
1026   bool hasByValArgument() const {
1027     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1028   }
1029
1030   /// getCalledFunction - Return the function called, or null if this is an
1031   /// indirect function invocation.
1032   ///
1033   Function *getCalledFunction() const {
1034     return dyn_cast<Function>(Op<0>());
1035   }
1036
1037   /// getCalledValue - Get a pointer to the function that is invoked by this
1038   /// instruction.
1039   const Value *getCalledValue() const { return Op<0>(); }
1040         Value *getCalledValue()       { return Op<0>(); }
1041
1042   /// setCalledFunction - Set the function called.
1043   void setCalledFunction(Value* Fn) {
1044     Op<0>() = Fn;
1045   }
1046
1047   // Methods for support type inquiry through isa, cast, and dyn_cast:
1048   static inline bool classof(const CallInst *) { return true; }
1049   static inline bool classof(const Instruction *I) {
1050     return I->getOpcode() == Instruction::Call;
1051   }
1052   static inline bool classof(const Value *V) {
1053     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1054   }
1055 };
1056
1057 template <>
1058 struct OperandTraits<CallInst> : public VariadicOperandTraits<1> {
1059 };
1060
1061 template<typename InputIterator>
1062 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1063                    const Twine &NameStr, BasicBlock *InsertAtEnd)
1064   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1065                                    ->getElementType())->getReturnType(),
1066                 Instruction::Call,
1067                 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1068                 (unsigned)(ArgEnd - ArgBegin + 1), InsertAtEnd) {
1069   init(Func, ArgBegin, ArgEnd, NameStr,
1070        typename std::iterator_traits<InputIterator>::iterator_category());
1071 }
1072
1073 template<typename InputIterator>
1074 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1075                    const Twine &NameStr, Instruction *InsertBefore)
1076   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1077                                    ->getElementType())->getReturnType(),
1078                 Instruction::Call,
1079                 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1080                 (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) {
1081   init(Func, ArgBegin, ArgEnd, NameStr,
1082        typename std::iterator_traits<InputIterator>::iterator_category());
1083 }
1084
1085 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1086
1087 //===----------------------------------------------------------------------===//
1088 //                               SelectInst Class
1089 //===----------------------------------------------------------------------===//
1090
1091 /// SelectInst - This class represents the LLVM 'select' instruction.
1092 ///
1093 class SelectInst : public Instruction {
1094   void init(Value *C, Value *S1, Value *S2) {
1095     assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1096     Op<0>() = C;
1097     Op<1>() = S1;
1098     Op<2>() = S2;
1099   }
1100
1101   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1102              Instruction *InsertBefore)
1103     : Instruction(S1->getType(), Instruction::Select,
1104                   &Op<0>(), 3, InsertBefore) {
1105     init(C, S1, S2);
1106     setName(NameStr);
1107   }
1108   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1109              BasicBlock *InsertAtEnd)
1110     : Instruction(S1->getType(), Instruction::Select,
1111                   &Op<0>(), 3, InsertAtEnd) {
1112     init(C, S1, S2);
1113     setName(NameStr);
1114   }
1115 public:
1116   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1117                             const Twine &NameStr = "",
1118                             Instruction *InsertBefore = 0) {
1119     return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1120   }
1121   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1122                             const Twine &NameStr,
1123                             BasicBlock *InsertAtEnd) {
1124     return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1125   }
1126
1127   const Value *getCondition() const { return Op<0>(); }
1128   const Value *getTrueValue() const { return Op<1>(); }
1129   const Value *getFalseValue() const { return Op<2>(); }
1130   Value *getCondition() { return Op<0>(); }
1131   Value *getTrueValue() { return Op<1>(); }
1132   Value *getFalseValue() { return Op<2>(); }
1133   
1134   /// areInvalidOperands - Return a string if the specified operands are invalid
1135   /// for a select operation, otherwise return null.
1136   static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1137
1138   /// Transparently provide more efficient getOperand methods.
1139   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1140
1141   OtherOps getOpcode() const {
1142     return static_cast<OtherOps>(Instruction::getOpcode());
1143   }
1144
1145   virtual SelectInst *clone() const;
1146
1147   // Methods for support type inquiry through isa, cast, and dyn_cast:
1148   static inline bool classof(const SelectInst *) { return true; }
1149   static inline bool classof(const Instruction *I) {
1150     return I->getOpcode() == Instruction::Select;
1151   }
1152   static inline bool classof(const Value *V) {
1153     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1154   }
1155 };
1156
1157 template <>
1158 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<3> {
1159 };
1160
1161 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1162
1163 //===----------------------------------------------------------------------===//
1164 //                                VAArgInst Class
1165 //===----------------------------------------------------------------------===//
1166
1167 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1168 /// an argument of the specified type given a va_list and increments that list
1169 ///
1170 class VAArgInst : public UnaryInstruction {
1171 public:
1172   VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "",
1173              Instruction *InsertBefore = 0)
1174     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1175     setName(NameStr);
1176   }
1177   VAArgInst(Value *List, const Type *Ty, const Twine &NameStr,
1178             BasicBlock *InsertAtEnd)
1179     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1180     setName(NameStr);
1181   }
1182
1183   virtual VAArgInst *clone() const;
1184
1185   // Methods for support type inquiry through isa, cast, and dyn_cast:
1186   static inline bool classof(const VAArgInst *) { return true; }
1187   static inline bool classof(const Instruction *I) {
1188     return I->getOpcode() == VAArg;
1189   }
1190   static inline bool classof(const Value *V) {
1191     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1192   }
1193 };
1194
1195 //===----------------------------------------------------------------------===//
1196 //                                ExtractElementInst Class
1197 //===----------------------------------------------------------------------===//
1198
1199 /// ExtractElementInst - This instruction extracts a single (scalar)
1200 /// element from a VectorType value
1201 ///
1202 class ExtractElementInst : public Instruction {
1203   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1204                      Instruction *InsertBefore = 0);
1205   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1206                      BasicBlock *InsertAtEnd);
1207 public:
1208   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1209                                    const Twine &NameStr = "",
1210                                    Instruction *InsertBefore = 0) {
1211     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1212   }
1213   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1214                                    const Twine &NameStr,
1215                                    BasicBlock *InsertAtEnd) {
1216     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1217   }
1218
1219   /// isValidOperands - Return true if an extractelement instruction can be
1220   /// formed with the specified operands.
1221   static bool isValidOperands(const Value *Vec, const Value *Idx);
1222
1223   virtual ExtractElementInst *clone() const;
1224
1225   Value *getVectorOperand() { return Op<0>(); }
1226   Value *getIndexOperand() { return Op<1>(); }
1227   const Value *getVectorOperand() const { return Op<0>(); }
1228   const Value *getIndexOperand() const { return Op<1>(); }
1229   
1230   const VectorType *getVectorOperandType() const {
1231     return reinterpret_cast<const VectorType*>(getVectorOperand()->getType());
1232   }
1233   
1234   
1235   /// Transparently provide more efficient getOperand methods.
1236   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1237
1238   // Methods for support type inquiry through isa, cast, and dyn_cast:
1239   static inline bool classof(const ExtractElementInst *) { return true; }
1240   static inline bool classof(const Instruction *I) {
1241     return I->getOpcode() == Instruction::ExtractElement;
1242   }
1243   static inline bool classof(const Value *V) {
1244     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1245   }
1246 };
1247
1248 template <>
1249 struct OperandTraits<ExtractElementInst> : public FixedNumOperandTraits<2> {
1250 };
1251
1252 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1253
1254 //===----------------------------------------------------------------------===//
1255 //                                InsertElementInst Class
1256 //===----------------------------------------------------------------------===//
1257
1258 /// InsertElementInst - This instruction inserts a single (scalar)
1259 /// element into a VectorType value
1260 ///
1261 class InsertElementInst : public Instruction {
1262   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1263                     const Twine &NameStr = "",
1264                     Instruction *InsertBefore = 0);
1265   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1266                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1267 public:
1268   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1269                                    const Twine &NameStr = "",
1270                                    Instruction *InsertBefore = 0) {
1271     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1272   }
1273   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1274                                    const Twine &NameStr,
1275                                    BasicBlock *InsertAtEnd) {
1276     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1277   }
1278
1279   /// isValidOperands - Return true if an insertelement instruction can be
1280   /// formed with the specified operands.
1281   static bool isValidOperands(const Value *Vec, const Value *NewElt,
1282                               const Value *Idx);
1283
1284   virtual InsertElementInst *clone() const;
1285
1286   /// getType - Overload to return most specific vector type.
1287   ///
1288   const VectorType *getType() const {
1289     return reinterpret_cast<const VectorType*>(Instruction::getType());
1290   }
1291
1292   /// Transparently provide more efficient getOperand methods.
1293   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1294
1295   // Methods for support type inquiry through isa, cast, and dyn_cast:
1296   static inline bool classof(const InsertElementInst *) { return true; }
1297   static inline bool classof(const Instruction *I) {
1298     return I->getOpcode() == Instruction::InsertElement;
1299   }
1300   static inline bool classof(const Value *V) {
1301     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1302   }
1303 };
1304
1305 template <>
1306 struct OperandTraits<InsertElementInst> : public FixedNumOperandTraits<3> {
1307 };
1308
1309 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1310
1311 //===----------------------------------------------------------------------===//
1312 //                           ShuffleVectorInst Class
1313 //===----------------------------------------------------------------------===//
1314
1315 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1316 /// input vectors.
1317 ///
1318 class ShuffleVectorInst : public Instruction {
1319 public:
1320   // allocate space for exactly three operands
1321   void *operator new(size_t s) {
1322     return User::operator new(s, 3);
1323   }
1324   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1325                     const Twine &NameStr = "",
1326                     Instruction *InsertBefor = 0);
1327   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1328                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1329
1330   /// isValidOperands - Return true if a shufflevector instruction can be
1331   /// formed with the specified operands.
1332   static bool isValidOperands(const Value *V1, const Value *V2,
1333                               const Value *Mask);
1334
1335   virtual ShuffleVectorInst *clone() const;
1336
1337   /// getType - Overload to return most specific vector type.
1338   ///
1339   const VectorType *getType() const {
1340     return reinterpret_cast<const VectorType*>(Instruction::getType());
1341   }
1342
1343   /// Transparently provide more efficient getOperand methods.
1344   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1345
1346   /// getMaskValue - Return the index from the shuffle mask for the specified
1347   /// output result.  This is either -1 if the element is undef or a number less
1348   /// than 2*numelements.
1349   int getMaskValue(unsigned i) const;
1350
1351   // Methods for support type inquiry through isa, cast, and dyn_cast:
1352   static inline bool classof(const ShuffleVectorInst *) { return true; }
1353   static inline bool classof(const Instruction *I) {
1354     return I->getOpcode() == Instruction::ShuffleVector;
1355   }
1356   static inline bool classof(const Value *V) {
1357     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1358   }
1359 };
1360
1361 template <>
1362 struct OperandTraits<ShuffleVectorInst> : public FixedNumOperandTraits<3> {
1363 };
1364
1365 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1366
1367 //===----------------------------------------------------------------------===//
1368 //                                ExtractValueInst Class
1369 //===----------------------------------------------------------------------===//
1370
1371 /// ExtractValueInst - This instruction extracts a struct member or array
1372 /// element value from an aggregate value.
1373 ///
1374 class ExtractValueInst : public UnaryInstruction {
1375   SmallVector<unsigned, 4> Indices;
1376
1377   ExtractValueInst(const ExtractValueInst &EVI);
1378   void init(const unsigned *Idx, unsigned NumIdx,
1379             const Twine &NameStr);
1380   void init(unsigned Idx, const Twine &NameStr);
1381
1382   template<typename InputIterator>
1383   void init(InputIterator IdxBegin, InputIterator IdxEnd,
1384             const Twine &NameStr,
1385             // This argument ensures that we have an iterator we can
1386             // do arithmetic on in constant time
1387             std::random_access_iterator_tag) {
1388     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1389
1390     // There's no fundamental reason why we require at least one index
1391     // (other than weirdness with &*IdxBegin being invalid; see
1392     // getelementptr's init routine for example). But there's no
1393     // present need to support it.
1394     assert(NumIdx > 0 && "ExtractValueInst must have at least one index");
1395
1396     // This requires that the iterator points to contiguous memory.
1397     init(&*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1398                                          // we have to build an array here
1399   }
1400
1401   /// getIndexedType - Returns the type of the element that would be extracted
1402   /// with an extractvalue instruction with the specified parameters.
1403   ///
1404   /// Null is returned if the indices are invalid for the specified
1405   /// pointer type.
1406   ///
1407   static const Type *getIndexedType(const Type *Agg,
1408                                     const unsigned *Idx, unsigned NumIdx);
1409
1410   template<typename InputIterator>
1411   static const Type *getIndexedType(const Type *Ptr,
1412                                     InputIterator IdxBegin,
1413                                     InputIterator IdxEnd,
1414                                     // This argument ensures that we
1415                                     // have an iterator we can do
1416                                     // arithmetic on in constant time
1417                                     std::random_access_iterator_tag) {
1418     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1419
1420     if (NumIdx > 0)
1421       // This requires that the iterator points to contiguous memory.
1422       return getIndexedType(Ptr, &*IdxBegin, NumIdx);
1423     else
1424       return getIndexedType(Ptr, (const unsigned *)0, NumIdx);
1425   }
1426
1427   /// Constructors - Create a extractvalue instruction with a base aggregate
1428   /// value and a list of indices.  The first ctor can optionally insert before
1429   /// an existing instruction, the second appends the new instruction to the
1430   /// specified BasicBlock.
1431   template<typename InputIterator>
1432   inline ExtractValueInst(Value *Agg, InputIterator IdxBegin,
1433                           InputIterator IdxEnd,
1434                           const Twine &NameStr,
1435                           Instruction *InsertBefore);
1436   template<typename InputIterator>
1437   inline ExtractValueInst(Value *Agg,
1438                           InputIterator IdxBegin, InputIterator IdxEnd,
1439                           const Twine &NameStr, BasicBlock *InsertAtEnd);
1440
1441   // allocate space for exactly one operand
1442   void *operator new(size_t s) {
1443     return User::operator new(s, 1);
1444   }
1445
1446 public:
1447   template<typename InputIterator>
1448   static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin,
1449                                   InputIterator IdxEnd,
1450                                   const Twine &NameStr = "",
1451                                   Instruction *InsertBefore = 0) {
1452     return new
1453       ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore);
1454   }
1455   template<typename InputIterator>
1456   static ExtractValueInst *Create(Value *Agg,
1457                                   InputIterator IdxBegin, InputIterator IdxEnd,
1458                                   const Twine &NameStr,
1459                                   BasicBlock *InsertAtEnd) {
1460     return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd);
1461   }
1462
1463   /// Constructors - These two creators are convenience methods because one
1464   /// index extractvalue instructions are much more common than those with
1465   /// more than one.
1466   static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1467                                   const Twine &NameStr = "",
1468                                   Instruction *InsertBefore = 0) {
1469     unsigned Idxs[1] = { Idx };
1470     return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore);
1471   }
1472   static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1473                                   const Twine &NameStr,
1474                                   BasicBlock *InsertAtEnd) {
1475     unsigned Idxs[1] = { Idx };
1476     return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
1477   }
1478
1479   virtual ExtractValueInst *clone() const;
1480
1481   /// getIndexedType - Returns the type of the element that would be extracted
1482   /// with an extractvalue instruction with the specified parameters.
1483   ///
1484   /// Null is returned if the indices are invalid for the specified
1485   /// pointer type.
1486   ///
1487   template<typename InputIterator>
1488   static const Type *getIndexedType(const Type *Ptr,
1489                                     InputIterator IdxBegin,
1490                                     InputIterator IdxEnd) {
1491     return getIndexedType(Ptr, IdxBegin, IdxEnd,
1492                           typename std::iterator_traits<InputIterator>::
1493                           iterator_category());
1494   }
1495   static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
1496
1497   typedef const unsigned* idx_iterator;
1498   inline idx_iterator idx_begin() const { return Indices.begin(); }
1499   inline idx_iterator idx_end()   const { return Indices.end(); }
1500
1501   Value *getAggregateOperand() {
1502     return getOperand(0);
1503   }
1504   const Value *getAggregateOperand() const {
1505     return getOperand(0);
1506   }
1507   static unsigned getAggregateOperandIndex() {
1508     return 0U;                      // get index for modifying correct operand
1509   }
1510
1511   unsigned getNumIndices() const {  // Note: always non-negative
1512     return (unsigned)Indices.size();
1513   }
1514
1515   bool hasIndices() const {
1516     return true;
1517   }
1518
1519   // Methods for support type inquiry through isa, cast, and dyn_cast:
1520   static inline bool classof(const ExtractValueInst *) { return true; }
1521   static inline bool classof(const Instruction *I) {
1522     return I->getOpcode() == Instruction::ExtractValue;
1523   }
1524   static inline bool classof(const Value *V) {
1525     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1526   }
1527 };
1528
1529 template<typename InputIterator>
1530 ExtractValueInst::ExtractValueInst(Value *Agg,
1531                                    InputIterator IdxBegin,
1532                                    InputIterator IdxEnd,
1533                                    const Twine &NameStr,
1534                                    Instruction *InsertBefore)
1535   : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1536                                               IdxBegin, IdxEnd)),
1537                      ExtractValue, Agg, InsertBefore) {
1538   init(IdxBegin, IdxEnd, NameStr,
1539        typename std::iterator_traits<InputIterator>::iterator_category());
1540 }
1541 template<typename InputIterator>
1542 ExtractValueInst::ExtractValueInst(Value *Agg,
1543                                    InputIterator IdxBegin,
1544                                    InputIterator IdxEnd,
1545                                    const Twine &NameStr,
1546                                    BasicBlock *InsertAtEnd)
1547   : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1548                                               IdxBegin, IdxEnd)),
1549                      ExtractValue, Agg, InsertAtEnd) {
1550   init(IdxBegin, IdxEnd, NameStr,
1551        typename std::iterator_traits<InputIterator>::iterator_category());
1552 }
1553
1554
1555 //===----------------------------------------------------------------------===//
1556 //                                InsertValueInst Class
1557 //===----------------------------------------------------------------------===//
1558
1559 /// InsertValueInst - This instruction inserts a struct field of array element
1560 /// value into an aggregate value.
1561 ///
1562 class InsertValueInst : public Instruction {
1563   SmallVector<unsigned, 4> Indices;
1564
1565   void *operator new(size_t, unsigned); // Do not implement
1566   InsertValueInst(const InsertValueInst &IVI);
1567   void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx,
1568             const Twine &NameStr);
1569   void init(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr);
1570
1571   template<typename InputIterator>
1572   void init(Value *Agg, Value *Val,
1573             InputIterator IdxBegin, InputIterator IdxEnd,
1574             const Twine &NameStr,
1575             // This argument ensures that we have an iterator we can
1576             // do arithmetic on in constant time
1577             std::random_access_iterator_tag) {
1578     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1579
1580     // There's no fundamental reason why we require at least one index
1581     // (other than weirdness with &*IdxBegin being invalid; see
1582     // getelementptr's init routine for example). But there's no
1583     // present need to support it.
1584     assert(NumIdx > 0 && "InsertValueInst must have at least one index");
1585
1586     // This requires that the iterator points to contiguous memory.
1587     init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1588                                               // we have to build an array here
1589   }
1590
1591   /// Constructors - Create a insertvalue instruction with a base aggregate
1592   /// value, a value to insert, and a list of indices.  The first ctor can
1593   /// optionally insert before an existing instruction, the second appends
1594   /// the new instruction to the specified BasicBlock.
1595   template<typename InputIterator>
1596   inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin,
1597                          InputIterator IdxEnd,
1598                          const Twine &NameStr,
1599                          Instruction *InsertBefore);
1600   template<typename InputIterator>
1601   inline InsertValueInst(Value *Agg, Value *Val,
1602                          InputIterator IdxBegin, InputIterator IdxEnd,
1603                          const Twine &NameStr, BasicBlock *InsertAtEnd);
1604
1605   /// Constructors - These two constructors are convenience methods because one
1606   /// and two index insertvalue instructions are so common.
1607   InsertValueInst(Value *Agg, Value *Val,
1608                   unsigned Idx, const Twine &NameStr = "",
1609                   Instruction *InsertBefore = 0);
1610   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1611                   const Twine &NameStr, BasicBlock *InsertAtEnd);
1612 public:
1613   // allocate space for exactly two operands
1614   void *operator new(size_t s) {
1615     return User::operator new(s, 2);
1616   }
1617
1618   template<typename InputIterator>
1619   static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin,
1620                                  InputIterator IdxEnd,
1621                                  const Twine &NameStr = "",
1622                                  Instruction *InsertBefore = 0) {
1623     return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1624                                NameStr, InsertBefore);
1625   }
1626   template<typename InputIterator>
1627   static InsertValueInst *Create(Value *Agg, Value *Val,
1628                                  InputIterator IdxBegin, InputIterator IdxEnd,
1629                                  const Twine &NameStr,
1630                                  BasicBlock *InsertAtEnd) {
1631     return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1632                                NameStr, InsertAtEnd);
1633   }
1634
1635   /// Constructors - These two creators are convenience methods because one
1636   /// index insertvalue instructions are much more common than those with
1637   /// more than one.
1638   static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1639                                  const Twine &NameStr = "",
1640                                  Instruction *InsertBefore = 0) {
1641     return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore);
1642   }
1643   static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1644                                  const Twine &NameStr,
1645                                  BasicBlock *InsertAtEnd) {
1646     return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
1647   }
1648
1649   virtual InsertValueInst *clone() const;
1650
1651   /// Transparently provide more efficient getOperand methods.
1652   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1653
1654   typedef const unsigned* idx_iterator;
1655   inline idx_iterator idx_begin() const { return Indices.begin(); }
1656   inline idx_iterator idx_end()   const { return Indices.end(); }
1657
1658   Value *getAggregateOperand() {
1659     return getOperand(0);
1660   }
1661   const Value *getAggregateOperand() const {
1662     return getOperand(0);
1663   }
1664   static unsigned getAggregateOperandIndex() {
1665     return 0U;                      // get index for modifying correct operand
1666   }
1667
1668   Value *getInsertedValueOperand() {
1669     return getOperand(1);
1670   }
1671   const Value *getInsertedValueOperand() const {
1672     return getOperand(1);
1673   }
1674   static unsigned getInsertedValueOperandIndex() {
1675     return 1U;                      // get index for modifying correct operand
1676   }
1677
1678   unsigned getNumIndices() const {  // Note: always non-negative
1679     return (unsigned)Indices.size();
1680   }
1681
1682   bool hasIndices() const {
1683     return true;
1684   }
1685
1686   // Methods for support type inquiry through isa, cast, and dyn_cast:
1687   static inline bool classof(const InsertValueInst *) { return true; }
1688   static inline bool classof(const Instruction *I) {
1689     return I->getOpcode() == Instruction::InsertValue;
1690   }
1691   static inline bool classof(const Value *V) {
1692     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1693   }
1694 };
1695
1696 template <>
1697 struct OperandTraits<InsertValueInst> : public FixedNumOperandTraits<2> {
1698 };
1699
1700 template<typename InputIterator>
1701 InsertValueInst::InsertValueInst(Value *Agg,
1702                                  Value *Val,
1703                                  InputIterator IdxBegin,
1704                                  InputIterator IdxEnd,
1705                                  const Twine &NameStr,
1706                                  Instruction *InsertBefore)
1707   : Instruction(Agg->getType(), InsertValue,
1708                 OperandTraits<InsertValueInst>::op_begin(this),
1709                 2, InsertBefore) {
1710   init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1711        typename std::iterator_traits<InputIterator>::iterator_category());
1712 }
1713 template<typename InputIterator>
1714 InsertValueInst::InsertValueInst(Value *Agg,
1715                                  Value *Val,
1716                                  InputIterator IdxBegin,
1717                                  InputIterator IdxEnd,
1718                                  const Twine &NameStr,
1719                                  BasicBlock *InsertAtEnd)
1720   : Instruction(Agg->getType(), InsertValue,
1721                 OperandTraits<InsertValueInst>::op_begin(this),
1722                 2, InsertAtEnd) {
1723   init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1724        typename std::iterator_traits<InputIterator>::iterator_category());
1725 }
1726
1727 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1728
1729 //===----------------------------------------------------------------------===//
1730 //                               PHINode Class
1731 //===----------------------------------------------------------------------===//
1732
1733 // PHINode - The PHINode class is used to represent the magical mystical PHI
1734 // node, that can not exist in nature, but can be synthesized in a computer
1735 // scientist's overactive imagination.
1736 //
1737 class PHINode : public Instruction {
1738   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
1739   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1740   /// the number actually in use.
1741   unsigned ReservedSpace;
1742   PHINode(const PHINode &PN);
1743   // allocate space for exactly zero operands
1744   void *operator new(size_t s) {
1745     return User::operator new(s, 0);
1746   }
1747   explicit PHINode(const Type *Ty, const Twine &NameStr = "",
1748                    Instruction *InsertBefore = 0)
1749     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1750       ReservedSpace(0) {
1751     setName(NameStr);
1752   }
1753
1754   PHINode(const Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd)
1755     : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1756       ReservedSpace(0) {
1757     setName(NameStr);
1758   }
1759 public:
1760   static PHINode *Create(const Type *Ty, const Twine &NameStr = "",
1761                          Instruction *InsertBefore = 0) {
1762     return new PHINode(Ty, NameStr, InsertBefore);
1763   }
1764   static PHINode *Create(const Type *Ty, const Twine &NameStr,
1765                          BasicBlock *InsertAtEnd) {
1766     return new PHINode(Ty, NameStr, InsertAtEnd);
1767   }
1768   ~PHINode();
1769
1770   /// reserveOperandSpace - This method can be used to avoid repeated
1771   /// reallocation of PHI operand lists by reserving space for the correct
1772   /// number of operands before adding them.  Unlike normal vector reserves,
1773   /// this method can also be used to trim the operand space.
1774   void reserveOperandSpace(unsigned NumValues) {
1775     resizeOperands(NumValues*2);
1776   }
1777
1778   virtual PHINode *clone() const;
1779
1780   /// Provide fast operand accessors
1781   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1782
1783   /// getNumIncomingValues - Return the number of incoming edges
1784   ///
1785   unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1786
1787   /// getIncomingValue - Return incoming value number x
1788   ///
1789   Value *getIncomingValue(unsigned i) const {
1790     assert(i*2 < getNumOperands() && "Invalid value number!");
1791     return getOperand(i*2);
1792   }
1793   void setIncomingValue(unsigned i, Value *V) {
1794     assert(i*2 < getNumOperands() && "Invalid value number!");
1795     setOperand(i*2, V);
1796   }
1797   static unsigned getOperandNumForIncomingValue(unsigned i) {
1798     return i*2;
1799   }
1800   static unsigned getIncomingValueNumForOperand(unsigned i) {
1801     assert(i % 2 == 0 && "Invalid incoming-value operand index!");
1802     return i/2;
1803   }
1804
1805   /// getIncomingBlock - Return incoming basic block #i.
1806   ///
1807   BasicBlock *getIncomingBlock(unsigned i) const {
1808     return cast<BasicBlock>(getOperand(i*2+1));
1809   }
1810   
1811   /// getIncomingBlock - Return incoming basic block corresponding
1812   /// to an operand of the PHI.
1813   ///
1814   BasicBlock *getIncomingBlock(const Use &U) const {
1815     assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
1816     return cast<BasicBlock>((&U + 1)->get());
1817   }
1818   
1819   /// getIncomingBlock - Return incoming basic block corresponding
1820   /// to value use iterator.
1821   ///
1822   template <typename U>
1823   BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1824     return getIncomingBlock(I.getUse());
1825   }
1826   
1827   
1828   void setIncomingBlock(unsigned i, BasicBlock *BB) {
1829     setOperand(i*2+1, BB);
1830   }
1831   static unsigned getOperandNumForIncomingBlock(unsigned i) {
1832     return i*2+1;
1833   }
1834   static unsigned getIncomingBlockNumForOperand(unsigned i) {
1835     assert(i % 2 == 1 && "Invalid incoming-block operand index!");
1836     return i/2;
1837   }
1838
1839   /// addIncoming - Add an incoming value to the end of the PHI list
1840   ///
1841   void addIncoming(Value *V, BasicBlock *BB) {
1842     assert(V && "PHI node got a null value!");
1843     assert(BB && "PHI node got a null basic block!");
1844     assert(getType() == V->getType() &&
1845            "All operands to PHI node must be the same type as the PHI node!");
1846     unsigned OpNo = NumOperands;
1847     if (OpNo+2 > ReservedSpace)
1848       resizeOperands(0);  // Get more space!
1849     // Initialize some new operands.
1850     NumOperands = OpNo+2;
1851     OperandList[OpNo] = V;
1852     OperandList[OpNo+1] = BB;
1853   }
1854
1855   /// removeIncomingValue - Remove an incoming value.  This is useful if a
1856   /// predecessor basic block is deleted.  The value removed is returned.
1857   ///
1858   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1859   /// is true), the PHI node is destroyed and any uses of it are replaced with
1860   /// dummy values.  The only time there should be zero incoming values to a PHI
1861   /// node is when the block is dead, so this strategy is sound.
1862   ///
1863   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1864
1865   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1866     int Idx = getBasicBlockIndex(BB);
1867     assert(Idx >= 0 && "Invalid basic block argument to remove!");
1868     return removeIncomingValue(Idx, DeletePHIIfEmpty);
1869   }
1870
1871   /// getBasicBlockIndex - Return the first index of the specified basic
1872   /// block in the value list for this PHI.  Returns -1 if no instance.
1873   ///
1874   int getBasicBlockIndex(const BasicBlock *BB) const {
1875     Use *OL = OperandList;
1876     for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1877       if (OL[i+1].get() == BB) return i/2;
1878     return -1;
1879   }
1880
1881   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1882     return getIncomingValue(getBasicBlockIndex(BB));
1883   }
1884
1885   /// hasConstantValue - If the specified PHI node always merges together the
1886   /// same value, return the value, otherwise return null.
1887   ///
1888   /// If the PHI has undef operands, but all the rest of the operands are
1889   /// some unique value, return that value if it can be proved that the
1890   /// value dominates the PHI. If DT is null, use a conservative check,
1891   /// otherwise use DT to test for dominance.
1892   ///
1893   Value *hasConstantValue(DominatorTree *DT = 0) const;
1894
1895   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1896   static inline bool classof(const PHINode *) { return true; }
1897   static inline bool classof(const Instruction *I) {
1898     return I->getOpcode() == Instruction::PHI;
1899   }
1900   static inline bool classof(const Value *V) {
1901     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1902   }
1903  private:
1904   void resizeOperands(unsigned NumOperands);
1905 };
1906
1907 template <>
1908 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
1909 };
1910
1911 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1912
1913
1914 //===----------------------------------------------------------------------===//
1915 //                               ReturnInst Class
1916 //===----------------------------------------------------------------------===//
1917
1918 //===---------------------------------------------------------------------------
1919 /// ReturnInst - Return a value (possibly void), from a function.  Execution
1920 /// does not continue in this function any longer.
1921 ///
1922 class ReturnInst : public TerminatorInst {
1923   ReturnInst(const ReturnInst &RI);
1924
1925 private:
1926   // ReturnInst constructors:
1927   // ReturnInst()                  - 'ret void' instruction
1928   // ReturnInst(    null)          - 'ret void' instruction
1929   // ReturnInst(Value* X)          - 'ret X'    instruction
1930   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
1931   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
1932   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
1933   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
1934   //
1935   // NOTE: If the Value* passed is of type void then the constructor behaves as
1936   // if it was passed NULL.
1937   explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
1938                       Instruction *InsertBefore = 0);
1939   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
1940   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
1941 public:
1942   static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
1943                             Instruction *InsertBefore = 0) {
1944     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
1945   }
1946   static ReturnInst* Create(LLVMContext &C, Value *retVal,
1947                             BasicBlock *InsertAtEnd) {
1948     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
1949   }
1950   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
1951     return new(0) ReturnInst(C, InsertAtEnd);
1952   }
1953   virtual ~ReturnInst();
1954
1955   virtual ReturnInst *clone() const;
1956
1957   /// Provide fast operand accessors
1958   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1959
1960   /// Convenience accessor
1961   Value *getReturnValue(unsigned n = 0) const {
1962     return n < getNumOperands()
1963       ? getOperand(n)
1964       : 0;
1965   }
1966
1967   unsigned getNumSuccessors() const { return 0; }
1968
1969   // Methods for support type inquiry through isa, cast, and dyn_cast:
1970   static inline bool classof(const ReturnInst *) { return true; }
1971   static inline bool classof(const Instruction *I) {
1972     return (I->getOpcode() == Instruction::Ret);
1973   }
1974   static inline bool classof(const Value *V) {
1975     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1976   }
1977  private:
1978   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1979   virtual unsigned getNumSuccessorsV() const;
1980   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1981 };
1982
1983 template <>
1984 struct OperandTraits<ReturnInst> : public OptionalOperandTraits<> {
1985 };
1986
1987 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
1988
1989 //===----------------------------------------------------------------------===//
1990 //                               BranchInst Class
1991 //===----------------------------------------------------------------------===//
1992
1993 //===---------------------------------------------------------------------------
1994 /// BranchInst - Conditional or Unconditional Branch instruction.
1995 ///
1996 class BranchInst : public TerminatorInst {
1997   /// Ops list - Branches are strange.  The operands are ordered:
1998   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
1999   /// they don't have to check for cond/uncond branchness. These are mostly
2000   /// accessed relative from op_end().
2001   BranchInst(const BranchInst &BI);
2002   void AssertOK();
2003   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2004   // BranchInst(BB *B)                           - 'br B'
2005   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
2006   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
2007   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2008   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
2009   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
2010   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2011   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2012              Instruction *InsertBefore = 0);
2013   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2014   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2015              BasicBlock *InsertAtEnd);
2016 public:
2017   static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2018     return new(1, true) BranchInst(IfTrue, InsertBefore);
2019   }
2020   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2021                             Value *Cond, Instruction *InsertBefore = 0) {
2022     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2023   }
2024   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2025     return new(1, true) BranchInst(IfTrue, InsertAtEnd);
2026   }
2027   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2028                             Value *Cond, BasicBlock *InsertAtEnd) {
2029     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2030   }
2031
2032   ~BranchInst();
2033
2034   /// Transparently provide more efficient getOperand methods.
2035   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2036
2037   virtual BranchInst *clone() const;
2038
2039   bool isUnconditional() const { return getNumOperands() == 1; }
2040   bool isConditional()   const { return getNumOperands() == 3; }
2041
2042   Value *getCondition() const {
2043     assert(isConditional() && "Cannot get condition of an uncond branch!");
2044     return Op<-3>();
2045   }
2046
2047   void setCondition(Value *V) {
2048     assert(isConditional() && "Cannot set condition of unconditional branch!");
2049     Op<-3>() = V;
2050   }
2051
2052   // setUnconditionalDest - Change the current branch to an unconditional branch
2053   // targeting the specified block.
2054   // FIXME: Eliminate this ugly method.
2055   void setUnconditionalDest(BasicBlock *Dest) {
2056     Op<-1>() = Dest;
2057     if (isConditional()) {  // Convert this to an uncond branch.
2058       Op<-2>() = 0;
2059       Op<-3>() = 0;
2060       NumOperands = 1;
2061       OperandList = op_begin();
2062     }
2063   }
2064
2065   unsigned getNumSuccessors() const { return 1+isConditional(); }
2066
2067   BasicBlock *getSuccessor(unsigned i) const {
2068     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2069     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2070   }
2071
2072   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2073     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2074     *(&Op<-1>() - idx) = NewSucc;
2075   }
2076
2077   // Methods for support type inquiry through isa, cast, and dyn_cast:
2078   static inline bool classof(const BranchInst *) { return true; }
2079   static inline bool classof(const Instruction *I) {
2080     return (I->getOpcode() == Instruction::Br);
2081   }
2082   static inline bool classof(const Value *V) {
2083     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2084   }
2085 private:
2086   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2087   virtual unsigned getNumSuccessorsV() const;
2088   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2089 };
2090
2091 template <>
2092 struct OperandTraits<BranchInst> : public VariadicOperandTraits<1> {};
2093
2094 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2095
2096 //===----------------------------------------------------------------------===//
2097 //                               SwitchInst Class
2098 //===----------------------------------------------------------------------===//
2099
2100 //===---------------------------------------------------------------------------
2101 /// SwitchInst - Multiway switch
2102 ///
2103 class SwitchInst : public TerminatorInst {
2104   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2105   unsigned ReservedSpace;
2106   // Operand[0]    = Value to switch on
2107   // Operand[1]    = Default basic block destination
2108   // Operand[2n  ] = Value to match
2109   // Operand[2n+1] = BasicBlock to go to on match
2110   SwitchInst(const SwitchInst &RI);
2111   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
2112   void resizeOperands(unsigned No);
2113   // allocate space for exactly zero operands
2114   void *operator new(size_t s) {
2115     return User::operator new(s, 0);
2116   }
2117   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2118   /// switch on and a default destination.  The number of additional cases can
2119   /// be specified here to make memory allocation more efficient.  This
2120   /// constructor can also autoinsert before another instruction.
2121   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2122              Instruction *InsertBefore = 0);
2123
2124   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2125   /// switch on and a default destination.  The number of additional cases can
2126   /// be specified here to make memory allocation more efficient.  This
2127   /// constructor also autoinserts at the end of the specified BasicBlock.
2128   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2129              BasicBlock *InsertAtEnd);
2130 public:
2131   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2132                             unsigned NumCases, Instruction *InsertBefore = 0) {
2133     return new SwitchInst(Value, Default, NumCases, InsertBefore);
2134   }
2135   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2136                             unsigned NumCases, BasicBlock *InsertAtEnd) {
2137     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2138   }
2139   ~SwitchInst();
2140
2141   /// Provide fast operand accessors
2142   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2143
2144   // Accessor Methods for Switch stmt
2145   Value *getCondition() const { return getOperand(0); }
2146   void setCondition(Value *V) { setOperand(0, V); }
2147
2148   BasicBlock *getDefaultDest() const {
2149     return cast<BasicBlock>(getOperand(1));
2150   }
2151
2152   /// getNumCases - return the number of 'cases' in this switch instruction.
2153   /// Note that case #0 is always the default case.
2154   unsigned getNumCases() const {
2155     return getNumOperands()/2;
2156   }
2157
2158   /// getCaseValue - Return the specified case value.  Note that case #0, the
2159   /// default destination, does not have a case value.
2160   ConstantInt *getCaseValue(unsigned i) {
2161     assert(i && i < getNumCases() && "Illegal case value to get!");
2162     return getSuccessorValue(i);
2163   }
2164
2165   /// getCaseValue - Return the specified case value.  Note that case #0, the
2166   /// default destination, does not have a case value.
2167   const ConstantInt *getCaseValue(unsigned i) const {
2168     assert(i && i < getNumCases() && "Illegal case value to get!");
2169     return getSuccessorValue(i);
2170   }
2171
2172   /// findCaseValue - Search all of the case values for the specified constant.
2173   /// If it is explicitly handled, return the case number of it, otherwise
2174   /// return 0 to indicate that it is handled by the default handler.
2175   unsigned findCaseValue(const ConstantInt *C) const {
2176     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2177       if (getCaseValue(i) == C)
2178         return i;
2179     return 0;
2180   }
2181
2182   /// findCaseDest - Finds the unique case value for a given successor. Returns
2183   /// null if the successor is not found, not unique, or is the default case.
2184   ConstantInt *findCaseDest(BasicBlock *BB) {
2185     if (BB == getDefaultDest()) return NULL;
2186
2187     ConstantInt *CI = NULL;
2188     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2189       if (getSuccessor(i) == BB) {
2190         if (CI) return NULL;   // Multiple cases lead to BB.
2191         else CI = getCaseValue(i);
2192       }
2193     }
2194     return CI;
2195   }
2196
2197   /// addCase - Add an entry to the switch instruction...
2198   ///
2199   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2200
2201   /// removeCase - This method removes the specified successor from the switch
2202   /// instruction.  Note that this cannot be used to remove the default
2203   /// destination (successor #0).
2204   ///
2205   void removeCase(unsigned idx);
2206
2207   virtual SwitchInst *clone() const;
2208
2209   unsigned getNumSuccessors() const { return getNumOperands()/2; }
2210   BasicBlock *getSuccessor(unsigned idx) const {
2211     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2212     return cast<BasicBlock>(getOperand(idx*2+1));
2213   }
2214   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2215     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2216     setOperand(idx*2+1, NewSucc);
2217   }
2218
2219   // getSuccessorValue - Return the value associated with the specified
2220   // successor.
2221   ConstantInt *getSuccessorValue(unsigned idx) const {
2222     assert(idx < getNumSuccessors() && "Successor # out of range!");
2223     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2224   }
2225
2226   // Methods for support type inquiry through isa, cast, and dyn_cast:
2227   static inline bool classof(const SwitchInst *) { return true; }
2228   static inline bool classof(const Instruction *I) {
2229     return I->getOpcode() == Instruction::Switch;
2230   }
2231   static inline bool classof(const Value *V) {
2232     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2233   }
2234 private:
2235   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2236   virtual unsigned getNumSuccessorsV() const;
2237   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2238 };
2239
2240 template <>
2241 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2242 };
2243
2244 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2245
2246
2247 //===----------------------------------------------------------------------===//
2248 //                               InvokeInst Class
2249 //===----------------------------------------------------------------------===//
2250
2251 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
2252 /// calling convention of the call.
2253 ///
2254 class InvokeInst : public TerminatorInst {
2255   AttrListPtr AttributeList;
2256   InvokeInst(const InvokeInst &BI);
2257   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
2258             Value* const *Args, unsigned NumArgs);
2259
2260   template<typename InputIterator>
2261   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2262             InputIterator ArgBegin, InputIterator ArgEnd,
2263             const Twine &NameStr,
2264             // This argument ensures that we have an iterator we can
2265             // do arithmetic on in constant time
2266             std::random_access_iterator_tag) {
2267     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
2268
2269     // This requires that the iterator points to contiguous memory.
2270     init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
2271     setName(NameStr);
2272   }
2273
2274   /// Construct an InvokeInst given a range of arguments.
2275   /// InputIterator must be a random-access iterator pointing to
2276   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
2277   /// made for random-accessness but not for contiguous storage as
2278   /// that would incur runtime overhead.
2279   ///
2280   /// @brief Construct an InvokeInst from a range of arguments
2281   template<typename InputIterator>
2282   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2283                     InputIterator ArgBegin, InputIterator ArgEnd,
2284                     unsigned Values,
2285                     const Twine &NameStr, Instruction *InsertBefore);
2286
2287   /// Construct an InvokeInst given a range of arguments.
2288   /// InputIterator must be a random-access iterator pointing to
2289   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
2290   /// made for random-accessness but not for contiguous storage as
2291   /// that would incur runtime overhead.
2292   ///
2293   /// @brief Construct an InvokeInst from a range of arguments
2294   template<typename InputIterator>
2295   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2296                     InputIterator ArgBegin, InputIterator ArgEnd,
2297                     unsigned Values,
2298                     const Twine &NameStr, BasicBlock *InsertAtEnd);
2299 public:
2300   template<typename InputIterator>
2301   static InvokeInst *Create(Value *Func,
2302                             BasicBlock *IfNormal, BasicBlock *IfException,
2303                             InputIterator ArgBegin, InputIterator ArgEnd,
2304                             const Twine &NameStr = "",
2305                             Instruction *InsertBefore = 0) {
2306     unsigned Values(ArgEnd - ArgBegin + 3);
2307     return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2308                                   Values, NameStr, InsertBefore);
2309   }
2310   template<typename InputIterator>
2311   static InvokeInst *Create(Value *Func,
2312                             BasicBlock *IfNormal, BasicBlock *IfException,
2313                             InputIterator ArgBegin, InputIterator ArgEnd,
2314                             const Twine &NameStr,
2315                             BasicBlock *InsertAtEnd) {
2316     unsigned Values(ArgEnd - ArgBegin + 3);
2317     return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2318                                   Values, NameStr, InsertAtEnd);
2319   }
2320
2321   virtual InvokeInst *clone() const;
2322
2323   /// Provide fast operand accessors
2324   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2325
2326   /// getCallingConv/setCallingConv - Get or set the calling convention of this
2327   /// function call.
2328   CallingConv::ID getCallingConv() const {
2329     return static_cast<CallingConv::ID>(SubclassData);
2330   }
2331   void setCallingConv(CallingConv::ID CC) {
2332     SubclassData = static_cast<unsigned>(CC);
2333   }
2334
2335   /// getAttributes - Return the parameter attributes for this invoke.
2336   ///
2337   const AttrListPtr &getAttributes() const { return AttributeList; }
2338
2339   /// setAttributes - Set the parameter attributes for this invoke.
2340   ///
2341   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2342
2343   /// addAttribute - adds the attribute to the list of attributes.
2344   void addAttribute(unsigned i, Attributes attr);
2345
2346   /// removeAttribute - removes the attribute from the list of attributes.
2347   void removeAttribute(unsigned i, Attributes attr);
2348
2349   /// @brief Determine whether the call or the callee has the given attribute.
2350   bool paramHasAttr(unsigned i, Attributes attr) const;
2351
2352   /// @brief Extract the alignment for a call or parameter (0=unknown).
2353   unsigned getParamAlignment(unsigned i) const {
2354     return AttributeList.getParamAlignment(i);
2355   }
2356
2357   /// @brief Determine if the call does not access memory.
2358   bool doesNotAccessMemory() const {
2359     return paramHasAttr(~0, Attribute::ReadNone);
2360   }
2361   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2362     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2363     else removeAttribute(~0, Attribute::ReadNone);
2364   }
2365
2366   /// @brief Determine if the call does not access or only reads memory.
2367   bool onlyReadsMemory() const {
2368     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2369   }
2370   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2371     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2372     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2373   }
2374
2375   /// @brief Determine if the call cannot return.
2376   bool doesNotReturn() const {
2377     return paramHasAttr(~0, Attribute::NoReturn);
2378   }
2379   void setDoesNotReturn(bool DoesNotReturn = true) {
2380     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2381     else removeAttribute(~0, Attribute::NoReturn);
2382   }
2383
2384   /// @brief Determine if the call cannot unwind.
2385   bool doesNotThrow() const {
2386     return paramHasAttr(~0, Attribute::NoUnwind);
2387   }
2388   void setDoesNotThrow(bool DoesNotThrow = true) {
2389     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2390     else removeAttribute(~0, Attribute::NoUnwind);
2391   }
2392
2393   /// @brief Determine if the call returns a structure through first
2394   /// pointer argument.
2395   bool hasStructRetAttr() const {
2396     // Be friendly and also check the callee.
2397     return paramHasAttr(1, Attribute::StructRet);
2398   }
2399
2400   /// @brief Determine if any call argument is an aggregate passed by value.
2401   bool hasByValArgument() const {
2402     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2403   }
2404
2405   /// getCalledFunction - Return the function called, or null if this is an
2406   /// indirect function invocation.
2407   ///
2408   Function *getCalledFunction() const {
2409     return dyn_cast<Function>(getOperand(0));
2410   }
2411
2412   /// getCalledValue - Get a pointer to the function that is invoked by this
2413   /// instruction
2414   const Value *getCalledValue() const { return getOperand(0); }
2415         Value *getCalledValue()       { return getOperand(0); }
2416
2417   // get*Dest - Return the destination basic blocks...
2418   BasicBlock *getNormalDest() const {
2419     return cast<BasicBlock>(getOperand(1));
2420   }
2421   BasicBlock *getUnwindDest() const {
2422     return cast<BasicBlock>(getOperand(2));
2423   }
2424   void setNormalDest(BasicBlock *B) {
2425     setOperand(1, B);
2426   }
2427
2428   void setUnwindDest(BasicBlock *B) {
2429     setOperand(2, B);
2430   }
2431
2432   BasicBlock *getSuccessor(unsigned i) const {
2433     assert(i < 2 && "Successor # out of range for invoke!");
2434     return i == 0 ? getNormalDest() : getUnwindDest();
2435   }
2436
2437   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2438     assert(idx < 2 && "Successor # out of range for invoke!");
2439     setOperand(idx+1, NewSucc);
2440   }
2441
2442   unsigned getNumSuccessors() const { return 2; }
2443
2444   // Methods for support type inquiry through isa, cast, and dyn_cast:
2445   static inline bool classof(const InvokeInst *) { return true; }
2446   static inline bool classof(const Instruction *I) {
2447     return (I->getOpcode() == Instruction::Invoke);
2448   }
2449   static inline bool classof(const Value *V) {
2450     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2451   }
2452 private:
2453   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2454   virtual unsigned getNumSuccessorsV() const;
2455   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2456 };
2457
2458 template <>
2459 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<3> {
2460 };
2461
2462 template<typename InputIterator>
2463 InvokeInst::InvokeInst(Value *Func,
2464                        BasicBlock *IfNormal, BasicBlock *IfException,
2465                        InputIterator ArgBegin, InputIterator ArgEnd,
2466                        unsigned Values,
2467                        const Twine &NameStr, Instruction *InsertBefore)
2468   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2469                                       ->getElementType())->getReturnType(),
2470                    Instruction::Invoke,
2471                    OperandTraits<InvokeInst>::op_end(this) - Values,
2472                    Values, InsertBefore) {
2473   init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2474        typename std::iterator_traits<InputIterator>::iterator_category());
2475 }
2476 template<typename InputIterator>
2477 InvokeInst::InvokeInst(Value *Func,
2478                        BasicBlock *IfNormal, BasicBlock *IfException,
2479                        InputIterator ArgBegin, InputIterator ArgEnd,
2480                        unsigned Values,
2481                        const Twine &NameStr, BasicBlock *InsertAtEnd)
2482   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2483                                       ->getElementType())->getReturnType(),
2484                    Instruction::Invoke,
2485                    OperandTraits<InvokeInst>::op_end(this) - Values,
2486                    Values, InsertAtEnd) {
2487   init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2488        typename std::iterator_traits<InputIterator>::iterator_category());
2489 }
2490
2491 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2492
2493 //===----------------------------------------------------------------------===//
2494 //                              UnwindInst Class
2495 //===----------------------------------------------------------------------===//
2496
2497 //===---------------------------------------------------------------------------
2498 /// UnwindInst - Immediately exit the current function, unwinding the stack
2499 /// until an invoke instruction is found.
2500 ///
2501 class UnwindInst : public TerminatorInst {
2502   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2503 public:
2504   // allocate space for exactly zero operands
2505   void *operator new(size_t s) {
2506     return User::operator new(s, 0);
2507   }
2508   explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2509   explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2510
2511   virtual UnwindInst *clone() const;
2512
2513   unsigned getNumSuccessors() const { return 0; }
2514
2515   // Methods for support type inquiry through isa, cast, and dyn_cast:
2516   static inline bool classof(const UnwindInst *) { return true; }
2517   static inline bool classof(const Instruction *I) {
2518     return I->getOpcode() == Instruction::Unwind;
2519   }
2520   static inline bool classof(const Value *V) {
2521     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2522   }
2523 private:
2524   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2525   virtual unsigned getNumSuccessorsV() const;
2526   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2527 };
2528
2529 //===----------------------------------------------------------------------===//
2530 //                           UnreachableInst Class
2531 //===----------------------------------------------------------------------===//
2532
2533 //===---------------------------------------------------------------------------
2534 /// UnreachableInst - This function has undefined behavior.  In particular, the
2535 /// presence of this instruction indicates some higher level knowledge that the
2536 /// end of the block cannot be reached.
2537 ///
2538 class UnreachableInst : public TerminatorInst {
2539   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2540 public:
2541   // allocate space for exactly zero operands
2542   void *operator new(size_t s) {
2543     return User::operator new(s, 0);
2544   }
2545   explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2546   explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2547
2548   virtual UnreachableInst *clone() const;
2549
2550   unsigned getNumSuccessors() const { return 0; }
2551
2552   // Methods for support type inquiry through isa, cast, and dyn_cast:
2553   static inline bool classof(const UnreachableInst *) { return true; }
2554   static inline bool classof(const Instruction *I) {
2555     return I->getOpcode() == Instruction::Unreachable;
2556   }
2557   static inline bool classof(const Value *V) {
2558     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2559   }
2560 private:
2561   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2562   virtual unsigned getNumSuccessorsV() const;
2563   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2564 };
2565
2566 //===----------------------------------------------------------------------===//
2567 //                                 TruncInst Class
2568 //===----------------------------------------------------------------------===//
2569
2570 /// @brief This class represents a truncation of integer types.
2571 class TruncInst : public CastInst {
2572 public:
2573   /// @brief Constructor with insert-before-instruction semantics
2574   TruncInst(
2575     Value *S,                     ///< The value to be truncated
2576     const Type *Ty,               ///< The (smaller) type to truncate to
2577     const Twine &NameStr = "", ///< A name for the new instruction
2578     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2579   );
2580
2581   /// @brief Constructor with insert-at-end-of-block semantics
2582   TruncInst(
2583     Value *S,                     ///< The value to be truncated
2584     const Type *Ty,               ///< The (smaller) type to truncate to
2585     const Twine &NameStr,   ///< A name for the new instruction
2586     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2587   );
2588
2589   /// @brief Clone an identical TruncInst
2590   virtual TruncInst *clone() const;
2591
2592   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2593   static inline bool classof(const TruncInst *) { return true; }
2594   static inline bool classof(const Instruction *I) {
2595     return I->getOpcode() == Trunc;
2596   }
2597   static inline bool classof(const Value *V) {
2598     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2599   }
2600 };
2601
2602 //===----------------------------------------------------------------------===//
2603 //                                 ZExtInst Class
2604 //===----------------------------------------------------------------------===//
2605
2606 /// @brief This class represents zero extension of integer types.
2607 class ZExtInst : public CastInst {
2608 public:
2609   /// @brief Constructor with insert-before-instruction semantics
2610   ZExtInst(
2611     Value *S,                     ///< The value to be zero extended
2612     const Type *Ty,               ///< The type to zero extend to
2613     const Twine &NameStr = "", ///< A name for the new instruction
2614     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2615   );
2616
2617   /// @brief Constructor with insert-at-end semantics.
2618   ZExtInst(
2619     Value *S,                     ///< The value to be zero extended
2620     const Type *Ty,               ///< The type to zero extend to
2621     const Twine &NameStr,   ///< A name for the new instruction
2622     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2623   );
2624
2625   /// @brief Clone an identical ZExtInst
2626   virtual ZExtInst *clone() const;
2627
2628   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2629   static inline bool classof(const ZExtInst *) { return true; }
2630   static inline bool classof(const Instruction *I) {
2631     return I->getOpcode() == ZExt;
2632   }
2633   static inline bool classof(const Value *V) {
2634     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2635   }
2636 };
2637
2638 //===----------------------------------------------------------------------===//
2639 //                                 SExtInst Class
2640 //===----------------------------------------------------------------------===//
2641
2642 /// @brief This class represents a sign extension of integer types.
2643 class SExtInst : public CastInst {
2644 public:
2645   /// @brief Constructor with insert-before-instruction semantics
2646   SExtInst(
2647     Value *S,                     ///< The value to be sign extended
2648     const Type *Ty,               ///< The type to sign extend to
2649     const Twine &NameStr = "", ///< A name for the new instruction
2650     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2651   );
2652
2653   /// @brief Constructor with insert-at-end-of-block semantics
2654   SExtInst(
2655     Value *S,                     ///< The value to be sign extended
2656     const Type *Ty,               ///< The type to sign extend to
2657     const Twine &NameStr,   ///< A name for the new instruction
2658     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2659   );
2660
2661   /// @brief Clone an identical SExtInst
2662   virtual SExtInst *clone() const;
2663
2664   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2665   static inline bool classof(const SExtInst *) { return true; }
2666   static inline bool classof(const Instruction *I) {
2667     return I->getOpcode() == SExt;
2668   }
2669   static inline bool classof(const Value *V) {
2670     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2671   }
2672 };
2673
2674 //===----------------------------------------------------------------------===//
2675 //                                 FPTruncInst Class
2676 //===----------------------------------------------------------------------===//
2677
2678 /// @brief This class represents a truncation of floating point types.
2679 class FPTruncInst : public CastInst {
2680 public:
2681   /// @brief Constructor with insert-before-instruction semantics
2682   FPTruncInst(
2683     Value *S,                     ///< The value to be truncated
2684     const Type *Ty,               ///< The type to truncate to
2685     const Twine &NameStr = "", ///< A name for the new instruction
2686     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2687   );
2688
2689   /// @brief Constructor with insert-before-instruction semantics
2690   FPTruncInst(
2691     Value *S,                     ///< The value to be truncated
2692     const Type *Ty,               ///< The type to truncate to
2693     const Twine &NameStr,   ///< A name for the new instruction
2694     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2695   );
2696
2697   /// @brief Clone an identical FPTruncInst
2698   virtual FPTruncInst *clone() const;
2699
2700   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2701   static inline bool classof(const FPTruncInst *) { return true; }
2702   static inline bool classof(const Instruction *I) {
2703     return I->getOpcode() == FPTrunc;
2704   }
2705   static inline bool classof(const Value *V) {
2706     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2707   }
2708 };
2709
2710 //===----------------------------------------------------------------------===//
2711 //                                 FPExtInst Class
2712 //===----------------------------------------------------------------------===//
2713
2714 /// @brief This class represents an extension of floating point types.
2715 class FPExtInst : public CastInst {
2716 public:
2717   /// @brief Constructor with insert-before-instruction semantics
2718   FPExtInst(
2719     Value *S,                     ///< The value to be extended
2720     const Type *Ty,               ///< The type to extend to
2721     const Twine &NameStr = "", ///< A name for the new instruction
2722     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2723   );
2724
2725   /// @brief Constructor with insert-at-end-of-block semantics
2726   FPExtInst(
2727     Value *S,                     ///< The value to be extended
2728     const Type *Ty,               ///< The type to extend to
2729     const Twine &NameStr,   ///< A name for the new instruction
2730     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2731   );
2732
2733   /// @brief Clone an identical FPExtInst
2734   virtual FPExtInst *clone() const;
2735
2736   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2737   static inline bool classof(const FPExtInst *) { return true; }
2738   static inline bool classof(const Instruction *I) {
2739     return I->getOpcode() == FPExt;
2740   }
2741   static inline bool classof(const Value *V) {
2742     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2743   }
2744 };
2745
2746 //===----------------------------------------------------------------------===//
2747 //                                 UIToFPInst Class
2748 //===----------------------------------------------------------------------===//
2749
2750 /// @brief This class represents a cast unsigned integer to floating point.
2751 class UIToFPInst : public CastInst {
2752 public:
2753   /// @brief Constructor with insert-before-instruction semantics
2754   UIToFPInst(
2755     Value *S,                     ///< The value to be converted
2756     const Type *Ty,               ///< The type to convert to
2757     const Twine &NameStr = "", ///< A name for the new instruction
2758     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2759   );
2760
2761   /// @brief Constructor with insert-at-end-of-block semantics
2762   UIToFPInst(
2763     Value *S,                     ///< The value to be converted
2764     const Type *Ty,               ///< The type to convert to
2765     const Twine &NameStr,   ///< A name for the new instruction
2766     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2767   );
2768
2769   /// @brief Clone an identical UIToFPInst
2770   virtual UIToFPInst *clone() const;
2771
2772   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2773   static inline bool classof(const UIToFPInst *) { return true; }
2774   static inline bool classof(const Instruction *I) {
2775     return I->getOpcode() == UIToFP;
2776   }
2777   static inline bool classof(const Value *V) {
2778     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2779   }
2780 };
2781
2782 //===----------------------------------------------------------------------===//
2783 //                                 SIToFPInst Class
2784 //===----------------------------------------------------------------------===//
2785
2786 /// @brief This class represents a cast from signed integer to floating point.
2787 class SIToFPInst : public CastInst {
2788 public:
2789   /// @brief Constructor with insert-before-instruction semantics
2790   SIToFPInst(
2791     Value *S,                     ///< The value to be converted
2792     const Type *Ty,               ///< The type to convert to
2793     const Twine &NameStr = "", ///< A name for the new instruction
2794     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2795   );
2796
2797   /// @brief Constructor with insert-at-end-of-block semantics
2798   SIToFPInst(
2799     Value *S,                     ///< The value to be converted
2800     const Type *Ty,               ///< The type to convert to
2801     const Twine &NameStr,   ///< A name for the new instruction
2802     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2803   );
2804
2805   /// @brief Clone an identical SIToFPInst
2806   virtual SIToFPInst *clone() const;
2807
2808   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2809   static inline bool classof(const SIToFPInst *) { return true; }
2810   static inline bool classof(const Instruction *I) {
2811     return I->getOpcode() == SIToFP;
2812   }
2813   static inline bool classof(const Value *V) {
2814     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2815   }
2816 };
2817
2818 //===----------------------------------------------------------------------===//
2819 //                                 FPToUIInst Class
2820 //===----------------------------------------------------------------------===//
2821
2822 /// @brief This class represents a cast from floating point to unsigned integer
2823 class FPToUIInst  : public CastInst {
2824 public:
2825   /// @brief Constructor with insert-before-instruction semantics
2826   FPToUIInst(
2827     Value *S,                     ///< The value to be converted
2828     const Type *Ty,               ///< The type to convert to
2829     const Twine &NameStr = "", ///< A name for the new instruction
2830     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2831   );
2832
2833   /// @brief Constructor with insert-at-end-of-block semantics
2834   FPToUIInst(
2835     Value *S,                     ///< The value to be converted
2836     const Type *Ty,               ///< The type to convert to
2837     const Twine &NameStr,   ///< A name for the new instruction
2838     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
2839   );
2840
2841   /// @brief Clone an identical FPToUIInst
2842   virtual FPToUIInst *clone() const;
2843
2844   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2845   static inline bool classof(const FPToUIInst *) { return true; }
2846   static inline bool classof(const Instruction *I) {
2847     return I->getOpcode() == FPToUI;
2848   }
2849   static inline bool classof(const Value *V) {
2850     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2851   }
2852 };
2853
2854 //===----------------------------------------------------------------------===//
2855 //                                 FPToSIInst Class
2856 //===----------------------------------------------------------------------===//
2857
2858 /// @brief This class represents a cast from floating point to signed integer.
2859 class FPToSIInst  : public CastInst {
2860 public:
2861   /// @brief Constructor with insert-before-instruction semantics
2862   FPToSIInst(
2863     Value *S,                     ///< The value to be converted
2864     const Type *Ty,               ///< The type to convert to
2865     const Twine &NameStr = "", ///< A name for the new instruction
2866     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2867   );
2868
2869   /// @brief Constructor with insert-at-end-of-block semantics
2870   FPToSIInst(
2871     Value *S,                     ///< The value to be converted
2872     const Type *Ty,               ///< The type to convert to
2873     const Twine &NameStr,   ///< A name for the new instruction
2874     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2875   );
2876
2877   /// @brief Clone an identical FPToSIInst
2878   virtual FPToSIInst *clone() const;
2879
2880   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2881   static inline bool classof(const FPToSIInst *) { return true; }
2882   static inline bool classof(const Instruction *I) {
2883     return I->getOpcode() == FPToSI;
2884   }
2885   static inline bool classof(const Value *V) {
2886     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2887   }
2888 };
2889
2890 //===----------------------------------------------------------------------===//
2891 //                                 IntToPtrInst Class
2892 //===----------------------------------------------------------------------===//
2893
2894 /// @brief This class represents a cast from an integer to a pointer.
2895 class IntToPtrInst : public CastInst {
2896 public:
2897   /// @brief Constructor with insert-before-instruction semantics
2898   IntToPtrInst(
2899     Value *S,                     ///< The value to be converted
2900     const Type *Ty,               ///< The type to convert to
2901     const Twine &NameStr = "", ///< A name for the new instruction
2902     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2903   );
2904
2905   /// @brief Constructor with insert-at-end-of-block semantics
2906   IntToPtrInst(
2907     Value *S,                     ///< The value to be converted
2908     const Type *Ty,               ///< The type to convert to
2909     const Twine &NameStr,   ///< A name for the new instruction
2910     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2911   );
2912
2913   /// @brief Clone an identical IntToPtrInst
2914   virtual IntToPtrInst *clone() const;
2915
2916   // Methods for support type inquiry through isa, cast, and dyn_cast:
2917   static inline bool classof(const IntToPtrInst *) { return true; }
2918   static inline bool classof(const Instruction *I) {
2919     return I->getOpcode() == IntToPtr;
2920   }
2921   static inline bool classof(const Value *V) {
2922     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2923   }
2924 };
2925
2926 //===----------------------------------------------------------------------===//
2927 //                                 PtrToIntInst Class
2928 //===----------------------------------------------------------------------===//
2929
2930 /// @brief This class represents a cast from a pointer to an integer
2931 class PtrToIntInst : public CastInst {
2932 public:
2933   /// @brief Constructor with insert-before-instruction semantics
2934   PtrToIntInst(
2935     Value *S,                     ///< The value to be converted
2936     const Type *Ty,               ///< The type to convert to
2937     const Twine &NameStr = "", ///< A name for the new instruction
2938     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2939   );
2940
2941   /// @brief Constructor with insert-at-end-of-block semantics
2942   PtrToIntInst(
2943     Value *S,                     ///< The value to be converted
2944     const Type *Ty,               ///< The type to convert to
2945     const Twine &NameStr,   ///< A name for the new instruction
2946     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2947   );
2948
2949   /// @brief Clone an identical PtrToIntInst
2950   virtual PtrToIntInst *clone() const;
2951
2952   // Methods for support type inquiry through isa, cast, and dyn_cast:
2953   static inline bool classof(const PtrToIntInst *) { return true; }
2954   static inline bool classof(const Instruction *I) {
2955     return I->getOpcode() == PtrToInt;
2956   }
2957   static inline bool classof(const Value *V) {
2958     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2959   }
2960 };
2961
2962 //===----------------------------------------------------------------------===//
2963 //                             BitCastInst Class
2964 //===----------------------------------------------------------------------===//
2965
2966 /// @brief This class represents a no-op cast from one type to another.
2967 class BitCastInst : public CastInst {
2968 public:
2969   /// @brief Constructor with insert-before-instruction semantics
2970   BitCastInst(
2971     Value *S,                     ///< The value to be casted
2972     const Type *Ty,               ///< The type to casted to
2973     const Twine &NameStr = "", ///< A name for the new instruction
2974     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2975   );
2976
2977   /// @brief Constructor with insert-at-end-of-block semantics
2978   BitCastInst(
2979     Value *S,                     ///< The value to be casted
2980     const Type *Ty,               ///< The type to casted to
2981     const Twine &NameStr,      ///< A name for the new instruction
2982     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2983   );
2984
2985   /// @brief Clone an identical BitCastInst
2986   virtual BitCastInst *clone() const;
2987
2988   // Methods for support type inquiry through isa, cast, and dyn_cast:
2989   static inline bool classof(const BitCastInst *) { return true; }
2990   static inline bool classof(const Instruction *I) {
2991     return I->getOpcode() == BitCast;
2992   }
2993   static inline bool classof(const Value *V) {
2994     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2995   }
2996 };
2997
2998 } // End llvm namespace
2999
3000 #endif