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