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