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