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