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