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