Rename Instruction::isIdenticalTo to Instruction::isIdenticalToWhenDefined,
[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 Instruction *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(const ExtractElementInst &EE) {
1280     return Create(EE.getOperand(0), EE.getOperand(1));
1281   }
1282
1283   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1284                                    const Twine &NameStr = "",
1285                                    Instruction *InsertBefore = 0) {
1286     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1287   }
1288   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1289                                    const Twine &NameStr,
1290                                    BasicBlock *InsertAtEnd) {
1291     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1292   }
1293
1294   /// isValidOperands - Return true if an extractelement instruction can be
1295   /// formed with the specified operands.
1296   static bool isValidOperands(const Value *Vec, const Value *Idx);
1297
1298   virtual ExtractElementInst *clone(LLVMContext &Context) const;
1299
1300   /// Transparently provide more efficient getOperand methods.
1301   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1302
1303   // Methods for support type inquiry through isa, cast, and dyn_cast:
1304   static inline bool classof(const ExtractElementInst *) { return true; }
1305   static inline bool classof(const Instruction *I) {
1306     return I->getOpcode() == Instruction::ExtractElement;
1307   }
1308   static inline bool classof(const Value *V) {
1309     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1310   }
1311 };
1312
1313 template <>
1314 struct OperandTraits<ExtractElementInst> : FixedNumOperandTraits<2> {
1315 };
1316
1317 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1318
1319 //===----------------------------------------------------------------------===//
1320 //                                InsertElementInst Class
1321 //===----------------------------------------------------------------------===//
1322
1323 /// InsertElementInst - This instruction inserts a single (scalar)
1324 /// element into a VectorType value
1325 ///
1326 class InsertElementInst : public Instruction {
1327   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1328                     const Twine &NameStr = "",
1329                     Instruction *InsertBefore = 0);
1330   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1331                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1332 public:
1333   static InsertElementInst *Create(const InsertElementInst &IE) {
1334     return Create(IE.getOperand(0), IE.getOperand(1), IE.getOperand(2));
1335   }
1336   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1337                                    const Twine &NameStr = "",
1338                                    Instruction *InsertBefore = 0) {
1339     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1340   }
1341   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1342                                    const Twine &NameStr,
1343                                    BasicBlock *InsertAtEnd) {
1344     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1345   }
1346
1347   /// isValidOperands - Return true if an insertelement instruction can be
1348   /// formed with the specified operands.
1349   static bool isValidOperands(const Value *Vec, const Value *NewElt,
1350                               const Value *Idx);
1351
1352   virtual InsertElementInst *clone(LLVMContext &Context) const;
1353
1354   /// getType - Overload to return most specific vector type.
1355   ///
1356   const VectorType *getType() const {
1357     return reinterpret_cast<const VectorType*>(Instruction::getType());
1358   }
1359
1360   /// Transparently provide more efficient getOperand methods.
1361   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1362
1363   // Methods for support type inquiry through isa, cast, and dyn_cast:
1364   static inline bool classof(const InsertElementInst *) { return true; }
1365   static inline bool classof(const Instruction *I) {
1366     return I->getOpcode() == Instruction::InsertElement;
1367   }
1368   static inline bool classof(const Value *V) {
1369     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1370   }
1371 };
1372
1373 template <>
1374 struct OperandTraits<InsertElementInst> : FixedNumOperandTraits<3> {
1375 };
1376
1377 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1378
1379 //===----------------------------------------------------------------------===//
1380 //                           ShuffleVectorInst Class
1381 //===----------------------------------------------------------------------===//
1382
1383 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1384 /// input vectors.
1385 ///
1386 class ShuffleVectorInst : public Instruction {
1387 public:
1388   // allocate space for exactly three operands
1389   void *operator new(size_t s) {
1390     return User::operator new(s, 3);
1391   }
1392   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1393                     const Twine &NameStr = "",
1394                     Instruction *InsertBefor = 0);
1395   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1396                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1397
1398   /// isValidOperands - Return true if a shufflevector instruction can be
1399   /// formed with the specified operands.
1400   static bool isValidOperands(const Value *V1, const Value *V2,
1401                               const Value *Mask);
1402
1403   virtual ShuffleVectorInst *clone(LLVMContext &Context) const;
1404
1405   /// getType - Overload to return most specific vector type.
1406   ///
1407   const VectorType *getType() const {
1408     return reinterpret_cast<const VectorType*>(Instruction::getType());
1409   }
1410
1411   /// Transparently provide more efficient getOperand methods.
1412   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1413
1414   /// getMaskValue - Return the index from the shuffle mask for the specified
1415   /// output result.  This is either -1 if the element is undef or a number less
1416   /// than 2*numelements.
1417   int getMaskValue(unsigned i) const;
1418
1419   // Methods for support type inquiry through isa, cast, and dyn_cast:
1420   static inline bool classof(const ShuffleVectorInst *) { return true; }
1421   static inline bool classof(const Instruction *I) {
1422     return I->getOpcode() == Instruction::ShuffleVector;
1423   }
1424   static inline bool classof(const Value *V) {
1425     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1426   }
1427 };
1428
1429 template <>
1430 struct OperandTraits<ShuffleVectorInst> : FixedNumOperandTraits<3> {
1431 };
1432
1433 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1434
1435 //===----------------------------------------------------------------------===//
1436 //                                ExtractValueInst Class
1437 //===----------------------------------------------------------------------===//
1438
1439 /// ExtractValueInst - This instruction extracts a struct member or array
1440 /// element value from an aggregate value.
1441 ///
1442 class ExtractValueInst : public UnaryInstruction {
1443   SmallVector<unsigned, 4> Indices;
1444
1445   ExtractValueInst(const ExtractValueInst &EVI);
1446   void init(const unsigned *Idx, unsigned NumIdx,
1447             const Twine &NameStr);
1448   void init(unsigned Idx, const Twine &NameStr);
1449
1450   template<typename InputIterator>
1451   void init(InputIterator IdxBegin, InputIterator IdxEnd,
1452             const Twine &NameStr,
1453             // This argument ensures that we have an iterator we can
1454             // do arithmetic on in constant time
1455             std::random_access_iterator_tag) {
1456     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1457
1458     // There's no fundamental reason why we require at least one index
1459     // (other than weirdness with &*IdxBegin being invalid; see
1460     // getelementptr's init routine for example). But there's no
1461     // present need to support it.
1462     assert(NumIdx > 0 && "ExtractValueInst must have at least one index");
1463
1464     // This requires that the iterator points to contiguous memory.
1465     init(&*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1466                                          // we have to build an array here
1467   }
1468
1469   /// getIndexedType - Returns the type of the element that would be extracted
1470   /// with an extractvalue instruction with the specified parameters.
1471   ///
1472   /// Null is returned if the indices are invalid for the specified
1473   /// pointer type.
1474   ///
1475   static const Type *getIndexedType(const Type *Agg,
1476                                     const unsigned *Idx, unsigned NumIdx);
1477
1478   template<typename InputIterator>
1479   static const Type *getIndexedType(const Type *Ptr,
1480                                     InputIterator IdxBegin,
1481                                     InputIterator IdxEnd,
1482                                     // This argument ensures that we
1483                                     // have an iterator we can do
1484                                     // arithmetic on in constant time
1485                                     std::random_access_iterator_tag) {
1486     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1487
1488     if (NumIdx > 0)
1489       // This requires that the iterator points to contiguous memory.
1490       return getIndexedType(Ptr, &*IdxBegin, NumIdx);
1491     else
1492       return getIndexedType(Ptr, (const unsigned *)0, NumIdx);
1493   }
1494
1495   /// Constructors - Create a extractvalue instruction with a base aggregate
1496   /// value and a list of indices.  The first ctor can optionally insert before
1497   /// an existing instruction, the second appends the new instruction to the
1498   /// specified BasicBlock.
1499   template<typename InputIterator>
1500   inline ExtractValueInst(Value *Agg, InputIterator IdxBegin,
1501                           InputIterator IdxEnd,
1502                           const Twine &NameStr,
1503                           Instruction *InsertBefore);
1504   template<typename InputIterator>
1505   inline ExtractValueInst(Value *Agg,
1506                           InputIterator IdxBegin, InputIterator IdxEnd,
1507                           const Twine &NameStr, BasicBlock *InsertAtEnd);
1508
1509   // allocate space for exactly one operand
1510   void *operator new(size_t s) {
1511     return User::operator new(s, 1);
1512   }
1513
1514 public:
1515   template<typename InputIterator>
1516   static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin,
1517                                   InputIterator IdxEnd,
1518                                   const Twine &NameStr = "",
1519                                   Instruction *InsertBefore = 0) {
1520     return new
1521       ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore);
1522   }
1523   template<typename InputIterator>
1524   static ExtractValueInst *Create(Value *Agg,
1525                                   InputIterator IdxBegin, InputIterator IdxEnd,
1526                                   const Twine &NameStr,
1527                                   BasicBlock *InsertAtEnd) {
1528     return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd);
1529   }
1530
1531   /// Constructors - These two creators are convenience methods because one
1532   /// index extractvalue instructions are much more common than those with
1533   /// more than one.
1534   static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1535                                   const Twine &NameStr = "",
1536                                   Instruction *InsertBefore = 0) {
1537     unsigned Idxs[1] = { Idx };
1538     return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore);
1539   }
1540   static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1541                                   const Twine &NameStr,
1542                                   BasicBlock *InsertAtEnd) {
1543     unsigned Idxs[1] = { Idx };
1544     return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
1545   }
1546
1547   virtual ExtractValueInst *clone(LLVMContext &Context) const;
1548
1549   /// getIndexedType - Returns the type of the element that would be extracted
1550   /// with an extractvalue instruction with the specified parameters.
1551   ///
1552   /// Null is returned if the indices are invalid for the specified
1553   /// pointer type.
1554   ///
1555   template<typename InputIterator>
1556   static const Type *getIndexedType(const Type *Ptr,
1557                                     InputIterator IdxBegin,
1558                                     InputIterator IdxEnd) {
1559     return getIndexedType(Ptr, IdxBegin, IdxEnd,
1560                           typename std::iterator_traits<InputIterator>::
1561                           iterator_category());
1562   }
1563   static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
1564
1565   typedef const unsigned* idx_iterator;
1566   inline idx_iterator idx_begin() const { return Indices.begin(); }
1567   inline idx_iterator idx_end()   const { return Indices.end(); }
1568
1569   Value *getAggregateOperand() {
1570     return getOperand(0);
1571   }
1572   const Value *getAggregateOperand() const {
1573     return getOperand(0);
1574   }
1575   static unsigned getAggregateOperandIndex() {
1576     return 0U;                      // get index for modifying correct operand
1577   }
1578
1579   unsigned getNumIndices() const {  // Note: always non-negative
1580     return (unsigned)Indices.size();
1581   }
1582
1583   bool hasIndices() const {
1584     return true;
1585   }
1586
1587   // Methods for support type inquiry through isa, cast, and dyn_cast:
1588   static inline bool classof(const ExtractValueInst *) { return true; }
1589   static inline bool classof(const Instruction *I) {
1590     return I->getOpcode() == Instruction::ExtractValue;
1591   }
1592   static inline bool classof(const Value *V) {
1593     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1594   }
1595 };
1596
1597 template<typename InputIterator>
1598 ExtractValueInst::ExtractValueInst(Value *Agg,
1599                                    InputIterator IdxBegin,
1600                                    InputIterator IdxEnd,
1601                                    const Twine &NameStr,
1602                                    Instruction *InsertBefore)
1603   : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1604                                               IdxBegin, IdxEnd)),
1605                      ExtractValue, Agg, InsertBefore) {
1606   init(IdxBegin, IdxEnd, NameStr,
1607        typename std::iterator_traits<InputIterator>::iterator_category());
1608 }
1609 template<typename InputIterator>
1610 ExtractValueInst::ExtractValueInst(Value *Agg,
1611                                    InputIterator IdxBegin,
1612                                    InputIterator IdxEnd,
1613                                    const Twine &NameStr,
1614                                    BasicBlock *InsertAtEnd)
1615   : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1616                                               IdxBegin, IdxEnd)),
1617                      ExtractValue, Agg, InsertAtEnd) {
1618   init(IdxBegin, IdxEnd, NameStr,
1619        typename std::iterator_traits<InputIterator>::iterator_category());
1620 }
1621
1622
1623 //===----------------------------------------------------------------------===//
1624 //                                InsertValueInst Class
1625 //===----------------------------------------------------------------------===//
1626
1627 /// InsertValueInst - This instruction inserts a struct field of array element
1628 /// value into an aggregate value.
1629 ///
1630 class InsertValueInst : public Instruction {
1631   SmallVector<unsigned, 4> Indices;
1632
1633   void *operator new(size_t, unsigned); // Do not implement
1634   InsertValueInst(const InsertValueInst &IVI);
1635   void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx,
1636             const Twine &NameStr);
1637   void init(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr);
1638
1639   template<typename InputIterator>
1640   void init(Value *Agg, Value *Val,
1641             InputIterator IdxBegin, InputIterator IdxEnd,
1642             const Twine &NameStr,
1643             // This argument ensures that we have an iterator we can
1644             // do arithmetic on in constant time
1645             std::random_access_iterator_tag) {
1646     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1647
1648     // There's no fundamental reason why we require at least one index
1649     // (other than weirdness with &*IdxBegin being invalid; see
1650     // getelementptr's init routine for example). But there's no
1651     // present need to support it.
1652     assert(NumIdx > 0 && "InsertValueInst must have at least one index");
1653
1654     // This requires that the iterator points to contiguous memory.
1655     init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1656                                               // we have to build an array here
1657   }
1658
1659   /// Constructors - Create a insertvalue instruction with a base aggregate
1660   /// value, a value to insert, and a list of indices.  The first ctor can
1661   /// optionally insert before an existing instruction, the second appends
1662   /// the new instruction to the specified BasicBlock.
1663   template<typename InputIterator>
1664   inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin,
1665                          InputIterator IdxEnd,
1666                          const Twine &NameStr,
1667                          Instruction *InsertBefore);
1668   template<typename InputIterator>
1669   inline InsertValueInst(Value *Agg, Value *Val,
1670                          InputIterator IdxBegin, InputIterator IdxEnd,
1671                          const Twine &NameStr, BasicBlock *InsertAtEnd);
1672
1673   /// Constructors - These two constructors are convenience methods because one
1674   /// and two index insertvalue instructions are so common.
1675   InsertValueInst(Value *Agg, Value *Val,
1676                   unsigned Idx, const Twine &NameStr = "",
1677                   Instruction *InsertBefore = 0);
1678   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1679                   const Twine &NameStr, BasicBlock *InsertAtEnd);
1680 public:
1681   // allocate space for exactly two operands
1682   void *operator new(size_t s) {
1683     return User::operator new(s, 2);
1684   }
1685
1686   template<typename InputIterator>
1687   static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin,
1688                                  InputIterator IdxEnd,
1689                                  const Twine &NameStr = "",
1690                                  Instruction *InsertBefore = 0) {
1691     return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1692                                NameStr, InsertBefore);
1693   }
1694   template<typename InputIterator>
1695   static InsertValueInst *Create(Value *Agg, Value *Val,
1696                                  InputIterator IdxBegin, InputIterator IdxEnd,
1697                                  const Twine &NameStr,
1698                                  BasicBlock *InsertAtEnd) {
1699     return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1700                                NameStr, InsertAtEnd);
1701   }
1702
1703   /// Constructors - These two creators are convenience methods because one
1704   /// index insertvalue instructions are much more common than those with
1705   /// more than one.
1706   static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1707                                  const Twine &NameStr = "",
1708                                  Instruction *InsertBefore = 0) {
1709     return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore);
1710   }
1711   static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1712                                  const Twine &NameStr,
1713                                  BasicBlock *InsertAtEnd) {
1714     return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
1715   }
1716
1717   virtual InsertValueInst *clone(LLVMContext &Context) const;
1718
1719   /// Transparently provide more efficient getOperand methods.
1720   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1721
1722   typedef const unsigned* idx_iterator;
1723   inline idx_iterator idx_begin() const { return Indices.begin(); }
1724   inline idx_iterator idx_end()   const { return Indices.end(); }
1725
1726   Value *getAggregateOperand() {
1727     return getOperand(0);
1728   }
1729   const Value *getAggregateOperand() const {
1730     return getOperand(0);
1731   }
1732   static unsigned getAggregateOperandIndex() {
1733     return 0U;                      // get index for modifying correct operand
1734   }
1735
1736   Value *getInsertedValueOperand() {
1737     return getOperand(1);
1738   }
1739   const Value *getInsertedValueOperand() const {
1740     return getOperand(1);
1741   }
1742   static unsigned getInsertedValueOperandIndex() {
1743     return 1U;                      // get index for modifying correct operand
1744   }
1745
1746   unsigned getNumIndices() const {  // Note: always non-negative
1747     return (unsigned)Indices.size();
1748   }
1749
1750   bool hasIndices() const {
1751     return true;
1752   }
1753
1754   // Methods for support type inquiry through isa, cast, and dyn_cast:
1755   static inline bool classof(const InsertValueInst *) { return true; }
1756   static inline bool classof(const Instruction *I) {
1757     return I->getOpcode() == Instruction::InsertValue;
1758   }
1759   static inline bool classof(const Value *V) {
1760     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1761   }
1762 };
1763
1764 template <>
1765 struct OperandTraits<InsertValueInst> : FixedNumOperandTraits<2> {
1766 };
1767
1768 template<typename InputIterator>
1769 InsertValueInst::InsertValueInst(Value *Agg,
1770                                  Value *Val,
1771                                  InputIterator IdxBegin,
1772                                  InputIterator IdxEnd,
1773                                  const Twine &NameStr,
1774                                  Instruction *InsertBefore)
1775   : Instruction(Agg->getType(), InsertValue,
1776                 OperandTraits<InsertValueInst>::op_begin(this),
1777                 2, InsertBefore) {
1778   init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1779        typename std::iterator_traits<InputIterator>::iterator_category());
1780 }
1781 template<typename InputIterator>
1782 InsertValueInst::InsertValueInst(Value *Agg,
1783                                  Value *Val,
1784                                  InputIterator IdxBegin,
1785                                  InputIterator IdxEnd,
1786                                  const Twine &NameStr,
1787                                  BasicBlock *InsertAtEnd)
1788   : Instruction(Agg->getType(), InsertValue,
1789                 OperandTraits<InsertValueInst>::op_begin(this),
1790                 2, InsertAtEnd) {
1791   init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1792        typename std::iterator_traits<InputIterator>::iterator_category());
1793 }
1794
1795 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1796
1797 //===----------------------------------------------------------------------===//
1798 //                               PHINode Class
1799 //===----------------------------------------------------------------------===//
1800
1801 // PHINode - The PHINode class is used to represent the magical mystical PHI
1802 // node, that can not exist in nature, but can be synthesized in a computer
1803 // scientist's overactive imagination.
1804 //
1805 class PHINode : public Instruction {
1806   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
1807   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1808   /// the number actually in use.
1809   unsigned ReservedSpace;
1810   PHINode(const PHINode &PN);
1811   // allocate space for exactly zero operands
1812   void *operator new(size_t s) {
1813     return User::operator new(s, 0);
1814   }
1815   explicit PHINode(const Type *Ty, const Twine &NameStr = "",
1816                    Instruction *InsertBefore = 0)
1817     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1818       ReservedSpace(0) {
1819     setName(NameStr);
1820   }
1821
1822   PHINode(const Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd)
1823     : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1824       ReservedSpace(0) {
1825     setName(NameStr);
1826   }
1827 public:
1828   static PHINode *Create(const Type *Ty, const Twine &NameStr = "",
1829                          Instruction *InsertBefore = 0) {
1830     return new PHINode(Ty, NameStr, InsertBefore);
1831   }
1832   static PHINode *Create(const Type *Ty, const Twine &NameStr,
1833                          BasicBlock *InsertAtEnd) {
1834     return new PHINode(Ty, NameStr, InsertAtEnd);
1835   }
1836   ~PHINode();
1837
1838   /// reserveOperandSpace - This method can be used to avoid repeated
1839   /// reallocation of PHI operand lists by reserving space for the correct
1840   /// number of operands before adding them.  Unlike normal vector reserves,
1841   /// this method can also be used to trim the operand space.
1842   void reserveOperandSpace(unsigned NumValues) {
1843     resizeOperands(NumValues*2);
1844   }
1845
1846   virtual PHINode *clone(LLVMContext &Context) const;
1847
1848   /// Provide fast operand accessors
1849   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1850
1851   /// getNumIncomingValues - Return the number of incoming edges
1852   ///
1853   unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1854
1855   /// getIncomingValue - Return incoming value number x
1856   ///
1857   Value *getIncomingValue(unsigned i) const {
1858     assert(i*2 < getNumOperands() && "Invalid value number!");
1859     return getOperand(i*2);
1860   }
1861   void setIncomingValue(unsigned i, Value *V) {
1862     assert(i*2 < getNumOperands() && "Invalid value number!");
1863     setOperand(i*2, V);
1864   }
1865   static unsigned getOperandNumForIncomingValue(unsigned i) {
1866     return i*2;
1867   }
1868   static unsigned getIncomingValueNumForOperand(unsigned i) {
1869     assert(i % 2 == 0 && "Invalid incoming-value operand index!");
1870     return i/2;
1871   }
1872
1873   /// getIncomingBlock - Return incoming basic block corresponding
1874   /// to value use iterator
1875   ///
1876   template <typename U>
1877   BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1878     assert(this == *I && "Iterator doesn't point to PHI's Uses?");
1879     return static_cast<BasicBlock*>((&I.getUse() + 1)->get());
1880   }
1881   /// getIncomingBlock - Return incoming basic block number x
1882   ///
1883   BasicBlock *getIncomingBlock(unsigned i) const {
1884     return static_cast<BasicBlock*>(getOperand(i*2+1));
1885   }
1886   void setIncomingBlock(unsigned i, BasicBlock *BB) {
1887     setOperand(i*2+1, BB);
1888   }
1889   static unsigned getOperandNumForIncomingBlock(unsigned i) {
1890     return i*2+1;
1891   }
1892   static unsigned getIncomingBlockNumForOperand(unsigned i) {
1893     assert(i % 2 == 1 && "Invalid incoming-block operand index!");
1894     return i/2;
1895   }
1896
1897   /// addIncoming - Add an incoming value to the end of the PHI list
1898   ///
1899   void addIncoming(Value *V, BasicBlock *BB) {
1900     assert(V && "PHI node got a null value!");
1901     assert(BB && "PHI node got a null basic block!");
1902     assert(getType() == V->getType() &&
1903            "All operands to PHI node must be the same type as the PHI node!");
1904     unsigned OpNo = NumOperands;
1905     if (OpNo+2 > ReservedSpace)
1906       resizeOperands(0);  // Get more space!
1907     // Initialize some new operands.
1908     NumOperands = OpNo+2;
1909     OperandList[OpNo] = V;
1910     OperandList[OpNo+1] = BB;
1911   }
1912
1913   /// removeIncomingValue - Remove an incoming value.  This is useful if a
1914   /// predecessor basic block is deleted.  The value removed is returned.
1915   ///
1916   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1917   /// is true), the PHI node is destroyed and any uses of it are replaced with
1918   /// dummy values.  The only time there should be zero incoming values to a PHI
1919   /// node is when the block is dead, so this strategy is sound.
1920   ///
1921   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1922
1923   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1924     int Idx = getBasicBlockIndex(BB);
1925     assert(Idx >= 0 && "Invalid basic block argument to remove!");
1926     return removeIncomingValue(Idx, DeletePHIIfEmpty);
1927   }
1928
1929   /// getBasicBlockIndex - Return the first index of the specified basic
1930   /// block in the value list for this PHI.  Returns -1 if no instance.
1931   ///
1932   int getBasicBlockIndex(const BasicBlock *BB) const {
1933     Use *OL = OperandList;
1934     for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1935       if (OL[i+1].get() == BB) return i/2;
1936     return -1;
1937   }
1938
1939   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1940     return getIncomingValue(getBasicBlockIndex(BB));
1941   }
1942
1943   /// hasConstantValue - If the specified PHI node always merges together the
1944   /// same value, return the value, otherwise return null.
1945   ///
1946   Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1947
1948   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1949   static inline bool classof(const PHINode *) { return true; }
1950   static inline bool classof(const Instruction *I) {
1951     return I->getOpcode() == Instruction::PHI;
1952   }
1953   static inline bool classof(const Value *V) {
1954     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1955   }
1956  private:
1957   void resizeOperands(unsigned NumOperands);
1958 };
1959
1960 template <>
1961 struct OperandTraits<PHINode> : HungoffOperandTraits<2> {
1962 };
1963
1964 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1965
1966
1967 //===----------------------------------------------------------------------===//
1968 //                               ReturnInst Class
1969 //===----------------------------------------------------------------------===//
1970
1971 //===---------------------------------------------------------------------------
1972 /// ReturnInst - Return a value (possibly void), from a function.  Execution
1973 /// does not continue in this function any longer.
1974 ///
1975 class ReturnInst : public TerminatorInst {
1976   ReturnInst(const ReturnInst &RI);
1977
1978 private:
1979   // ReturnInst constructors:
1980   // ReturnInst()                  - 'ret void' instruction
1981   // ReturnInst(    null)          - 'ret void' instruction
1982   // ReturnInst(Value* X)          - 'ret X'    instruction
1983   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
1984   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
1985   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
1986   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
1987   //
1988   // NOTE: If the Value* passed is of type void then the constructor behaves as
1989   // if it was passed NULL.
1990   explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
1991                       Instruction *InsertBefore = 0);
1992   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
1993   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
1994 public:
1995   static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
1996                             Instruction *InsertBefore = 0) {
1997     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
1998   }
1999   static ReturnInst* Create(LLVMContext &C, Value *retVal,
2000                             BasicBlock *InsertAtEnd) {
2001     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2002   }
2003   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2004     return new(0) ReturnInst(C, InsertAtEnd);
2005   }
2006   virtual ~ReturnInst();
2007
2008   virtual ReturnInst *clone(LLVMContext &Context) const;
2009
2010   /// Provide fast operand accessors
2011   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2012
2013   /// Convenience accessor
2014   Value *getReturnValue(unsigned n = 0) const {
2015     return n < getNumOperands()
2016       ? getOperand(n)
2017       : 0;
2018   }
2019
2020   unsigned getNumSuccessors() const { return 0; }
2021
2022   // Methods for support type inquiry through isa, cast, and dyn_cast:
2023   static inline bool classof(const ReturnInst *) { return true; }
2024   static inline bool classof(const Instruction *I) {
2025     return (I->getOpcode() == Instruction::Ret);
2026   }
2027   static inline bool classof(const Value *V) {
2028     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2029   }
2030  private:
2031   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2032   virtual unsigned getNumSuccessorsV() const;
2033   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2034 };
2035
2036 template <>
2037 struct OperandTraits<ReturnInst> : OptionalOperandTraits<> {
2038 };
2039
2040 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2041
2042 //===----------------------------------------------------------------------===//
2043 //                               BranchInst Class
2044 //===----------------------------------------------------------------------===//
2045
2046 //===---------------------------------------------------------------------------
2047 /// BranchInst - Conditional or Unconditional Branch instruction.
2048 ///
2049 class BranchInst : public TerminatorInst {
2050   /// Ops list - Branches are strange.  The operands are ordered:
2051   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
2052   /// they don't have to check for cond/uncond branchness. These are mostly
2053   /// accessed relative from op_end().
2054   BranchInst(const BranchInst &BI);
2055   void AssertOK();
2056   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2057   // BranchInst(BB *B)                           - 'br B'
2058   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
2059   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
2060   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2061   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
2062   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
2063   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2064   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2065              Instruction *InsertBefore = 0);
2066   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2067   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2068              BasicBlock *InsertAtEnd);
2069 public:
2070   static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2071     return new(1, true) BranchInst(IfTrue, InsertBefore);
2072   }
2073   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2074                             Value *Cond, Instruction *InsertBefore = 0) {
2075     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2076   }
2077   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2078     return new(1, true) BranchInst(IfTrue, InsertAtEnd);
2079   }
2080   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2081                             Value *Cond, BasicBlock *InsertAtEnd) {
2082     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2083   }
2084
2085   ~BranchInst();
2086
2087   /// Transparently provide more efficient getOperand methods.
2088   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2089
2090   virtual BranchInst *clone(LLVMContext &Context) const;
2091
2092   bool isUnconditional() const { return getNumOperands() == 1; }
2093   bool isConditional()   const { return getNumOperands() == 3; }
2094
2095   Value *getCondition() const {
2096     assert(isConditional() && "Cannot get condition of an uncond branch!");
2097     return Op<-3>();
2098   }
2099
2100   void setCondition(Value *V) {
2101     assert(isConditional() && "Cannot set condition of unconditional branch!");
2102     Op<-3>() = V;
2103   }
2104
2105   // setUnconditionalDest - Change the current branch to an unconditional branch
2106   // targeting the specified block.
2107   // FIXME: Eliminate this ugly method.
2108   void setUnconditionalDest(BasicBlock *Dest) {
2109     Op<-1>() = Dest;
2110     if (isConditional()) {  // Convert this to an uncond branch.
2111       Op<-2>() = 0;
2112       Op<-3>() = 0;
2113       NumOperands = 1;
2114       OperandList = op_begin();
2115     }
2116   }
2117
2118   unsigned getNumSuccessors() const { return 1+isConditional(); }
2119
2120   BasicBlock *getSuccessor(unsigned i) const {
2121     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2122     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2123   }
2124
2125   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2126     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2127     *(&Op<-1>() - idx) = NewSucc;
2128   }
2129
2130   // Methods for support type inquiry through isa, cast, and dyn_cast:
2131   static inline bool classof(const BranchInst *) { return true; }
2132   static inline bool classof(const Instruction *I) {
2133     return (I->getOpcode() == Instruction::Br);
2134   }
2135   static inline bool classof(const Value *V) {
2136     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2137   }
2138 private:
2139   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2140   virtual unsigned getNumSuccessorsV() const;
2141   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2142 };
2143
2144 template <>
2145 struct OperandTraits<BranchInst> : VariadicOperandTraits<1> {};
2146
2147 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2148
2149 //===----------------------------------------------------------------------===//
2150 //                               SwitchInst Class
2151 //===----------------------------------------------------------------------===//
2152
2153 //===---------------------------------------------------------------------------
2154 /// SwitchInst - Multiway switch
2155 ///
2156 class SwitchInst : public TerminatorInst {
2157   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2158   unsigned ReservedSpace;
2159   // Operand[0]    = Value to switch on
2160   // Operand[1]    = Default basic block destination
2161   // Operand[2n  ] = Value to match
2162   // Operand[2n+1] = BasicBlock to go to on match
2163   SwitchInst(const SwitchInst &RI);
2164   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
2165   void resizeOperands(unsigned No);
2166   // allocate space for exactly zero operands
2167   void *operator new(size_t s) {
2168     return User::operator new(s, 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 can also autoinsert before another instruction.
2174   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2175              Instruction *InsertBefore = 0);
2176
2177   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2178   /// switch on and a default destination.  The number of additional cases can
2179   /// be specified here to make memory allocation more efficient.  This
2180   /// constructor also autoinserts at the end of the specified BasicBlock.
2181   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2182              BasicBlock *InsertAtEnd);
2183 public:
2184   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2185                             unsigned NumCases, Instruction *InsertBefore = 0) {
2186     return new SwitchInst(Value, Default, NumCases, InsertBefore);
2187   }
2188   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2189                             unsigned NumCases, BasicBlock *InsertAtEnd) {
2190     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2191   }
2192   ~SwitchInst();
2193
2194   /// Provide fast operand accessors
2195   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2196
2197   // Accessor Methods for Switch stmt
2198   Value *getCondition() const { return getOperand(0); }
2199   void setCondition(Value *V) { setOperand(0, V); }
2200
2201   BasicBlock *getDefaultDest() const {
2202     return cast<BasicBlock>(getOperand(1));
2203   }
2204
2205   /// getNumCases - return the number of 'cases' in this switch instruction.
2206   /// Note that case #0 is always the default case.
2207   unsigned getNumCases() const {
2208     return getNumOperands()/2;
2209   }
2210
2211   /// getCaseValue - Return the specified case value.  Note that case #0, the
2212   /// default destination, does not have a case value.
2213   ConstantInt *getCaseValue(unsigned i) {
2214     assert(i && i < getNumCases() && "Illegal case value to get!");
2215     return getSuccessorValue(i);
2216   }
2217
2218   /// getCaseValue - Return the specified case value.  Note that case #0, the
2219   /// default destination, does not have a case value.
2220   const ConstantInt *getCaseValue(unsigned i) const {
2221     assert(i && i < getNumCases() && "Illegal case value to get!");
2222     return getSuccessorValue(i);
2223   }
2224
2225   /// findCaseValue - Search all of the case values for the specified constant.
2226   /// If it is explicitly handled, return the case number of it, otherwise
2227   /// return 0 to indicate that it is handled by the default handler.
2228   unsigned findCaseValue(const ConstantInt *C) const {
2229     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2230       if (getCaseValue(i) == C)
2231         return i;
2232     return 0;
2233   }
2234
2235   /// findCaseDest - Finds the unique case value for a given successor. Returns
2236   /// null if the successor is not found, not unique, or is the default case.
2237   ConstantInt *findCaseDest(BasicBlock *BB) {
2238     if (BB == getDefaultDest()) return NULL;
2239
2240     ConstantInt *CI = NULL;
2241     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2242       if (getSuccessor(i) == BB) {
2243         if (CI) return NULL;   // Multiple cases lead to BB.
2244         else CI = getCaseValue(i);
2245       }
2246     }
2247     return CI;
2248   }
2249
2250   /// addCase - Add an entry to the switch instruction...
2251   ///
2252   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2253
2254   /// removeCase - This method removes the specified successor from the switch
2255   /// instruction.  Note that this cannot be used to remove the default
2256   /// destination (successor #0).
2257   ///
2258   void removeCase(unsigned idx);
2259
2260   virtual SwitchInst *clone(LLVMContext &Context) const;
2261
2262   unsigned getNumSuccessors() const { return getNumOperands()/2; }
2263   BasicBlock *getSuccessor(unsigned idx) const {
2264     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2265     return cast<BasicBlock>(getOperand(idx*2+1));
2266   }
2267   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2268     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2269     setOperand(idx*2+1, NewSucc);
2270   }
2271
2272   // getSuccessorValue - Return the value associated with the specified
2273   // successor.
2274   ConstantInt *getSuccessorValue(unsigned idx) const {
2275     assert(idx < getNumSuccessors() && "Successor # out of range!");
2276     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2277   }
2278
2279   // Methods for support type inquiry through isa, cast, and dyn_cast:
2280   static inline bool classof(const SwitchInst *) { return true; }
2281   static inline bool classof(const Instruction *I) {
2282     return I->getOpcode() == Instruction::Switch;
2283   }
2284   static inline bool classof(const Value *V) {
2285     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2286   }
2287 private:
2288   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2289   virtual unsigned getNumSuccessorsV() const;
2290   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2291 };
2292
2293 template <>
2294 struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> {
2295 };
2296
2297 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2298
2299
2300 //===----------------------------------------------------------------------===//
2301 //                               InvokeInst Class
2302 //===----------------------------------------------------------------------===//
2303
2304 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
2305 /// calling convention of the call.
2306 ///
2307 class InvokeInst : public TerminatorInst {
2308   AttrListPtr AttributeList;
2309   InvokeInst(const InvokeInst &BI);
2310   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
2311             Value* const *Args, unsigned NumArgs);
2312
2313   template<typename InputIterator>
2314   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2315             InputIterator ArgBegin, InputIterator ArgEnd,
2316             const Twine &NameStr,
2317             // This argument ensures that we have an iterator we can
2318             // do arithmetic on in constant time
2319             std::random_access_iterator_tag) {
2320     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
2321
2322     // This requires that the iterator points to contiguous memory.
2323     init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
2324     setName(NameStr);
2325   }
2326
2327   /// Construct an InvokeInst given a range of arguments.
2328   /// InputIterator must be a random-access iterator pointing to
2329   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
2330   /// made for random-accessness but not for contiguous storage as
2331   /// that would incur runtime overhead.
2332   ///
2333   /// @brief Construct an InvokeInst from a range of arguments
2334   template<typename InputIterator>
2335   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2336                     InputIterator ArgBegin, InputIterator ArgEnd,
2337                     unsigned Values,
2338                     const Twine &NameStr, Instruction *InsertBefore);
2339
2340   /// Construct an InvokeInst given a range of arguments.
2341   /// InputIterator must be a random-access iterator pointing to
2342   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
2343   /// made for random-accessness but not for contiguous storage as
2344   /// that would incur runtime overhead.
2345   ///
2346   /// @brief Construct an InvokeInst from a range of arguments
2347   template<typename InputIterator>
2348   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2349                     InputIterator ArgBegin, InputIterator ArgEnd,
2350                     unsigned Values,
2351                     const Twine &NameStr, BasicBlock *InsertAtEnd);
2352 public:
2353   template<typename InputIterator>
2354   static InvokeInst *Create(Value *Func,
2355                             BasicBlock *IfNormal, BasicBlock *IfException,
2356                             InputIterator ArgBegin, InputIterator ArgEnd,
2357                             const Twine &NameStr = "",
2358                             Instruction *InsertBefore = 0) {
2359     unsigned Values(ArgEnd - ArgBegin + 3);
2360     return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2361                                   Values, NameStr, InsertBefore);
2362   }
2363   template<typename InputIterator>
2364   static InvokeInst *Create(Value *Func,
2365                             BasicBlock *IfNormal, BasicBlock *IfException,
2366                             InputIterator ArgBegin, InputIterator ArgEnd,
2367                             const Twine &NameStr,
2368                             BasicBlock *InsertAtEnd) {
2369     unsigned Values(ArgEnd - ArgBegin + 3);
2370     return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2371                                   Values, NameStr, InsertAtEnd);
2372   }
2373
2374   virtual InvokeInst *clone(LLVMContext &Context) const;
2375
2376   /// Provide fast operand accessors
2377   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2378
2379   /// getCallingConv/setCallingConv - Get or set the calling convention of this
2380   /// function call.
2381   unsigned getCallingConv() const { return SubclassData; }
2382   void setCallingConv(unsigned CC) {
2383     SubclassData = CC;
2384   }
2385
2386   /// getAttributes - Return the parameter attributes for this invoke.
2387   ///
2388   const AttrListPtr &getAttributes() const { return AttributeList; }
2389
2390   /// setAttributes - Set the parameter attributes for this invoke.
2391   ///
2392   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2393
2394   /// addAttribute - adds the attribute to the list of attributes.
2395   void addAttribute(unsigned i, Attributes attr);
2396
2397   /// removeAttribute - removes the attribute from the list of attributes.
2398   void removeAttribute(unsigned i, Attributes attr);
2399
2400   /// @brief Determine whether the call or the callee has the given attribute.
2401   bool paramHasAttr(unsigned i, Attributes attr) const;
2402
2403   /// @brief Extract the alignment for a call or parameter (0=unknown).
2404   unsigned getParamAlignment(unsigned i) const {
2405     return AttributeList.getParamAlignment(i);
2406   }
2407
2408   /// @brief Determine if the call does not access memory.
2409   bool doesNotAccessMemory() const {
2410     return paramHasAttr(~0, Attribute::ReadNone);
2411   }
2412   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2413     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2414     else removeAttribute(~0, Attribute::ReadNone);
2415   }
2416
2417   /// @brief Determine if the call does not access or only reads memory.
2418   bool onlyReadsMemory() const {
2419     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2420   }
2421   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2422     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2423     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2424   }
2425
2426   /// @brief Determine if the call cannot return.
2427   bool doesNotReturn() const {
2428     return paramHasAttr(~0, Attribute::NoReturn);
2429   }
2430   void setDoesNotReturn(bool DoesNotReturn = true) {
2431     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2432     else removeAttribute(~0, Attribute::NoReturn);
2433   }
2434
2435   /// @brief Determine if the call cannot unwind.
2436   bool doesNotThrow() const {
2437     return paramHasAttr(~0, Attribute::NoUnwind);
2438   }
2439   void setDoesNotThrow(bool DoesNotThrow = true) {
2440     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2441     else removeAttribute(~0, Attribute::NoUnwind);
2442   }
2443
2444   /// @brief Determine if the call returns a structure through first
2445   /// pointer argument.
2446   bool hasStructRetAttr() const {
2447     // Be friendly and also check the callee.
2448     return paramHasAttr(1, Attribute::StructRet);
2449   }
2450
2451   /// @brief Determine if any call argument is an aggregate passed by value.
2452   bool hasByValArgument() const {
2453     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2454   }
2455
2456   /// getCalledFunction - Return the function called, or null if this is an
2457   /// indirect function invocation.
2458   ///
2459   Function *getCalledFunction() const {
2460     return dyn_cast<Function>(getOperand(0));
2461   }
2462
2463   /// getCalledValue - Get a pointer to the function that is invoked by this
2464   /// instruction
2465   const Value *getCalledValue() const { return getOperand(0); }
2466         Value *getCalledValue()       { return getOperand(0); }
2467
2468   // get*Dest - Return the destination basic blocks...
2469   BasicBlock *getNormalDest() const {
2470     return cast<BasicBlock>(getOperand(1));
2471   }
2472   BasicBlock *getUnwindDest() const {
2473     return cast<BasicBlock>(getOperand(2));
2474   }
2475   void setNormalDest(BasicBlock *B) {
2476     setOperand(1, B);
2477   }
2478
2479   void setUnwindDest(BasicBlock *B) {
2480     setOperand(2, B);
2481   }
2482
2483   BasicBlock *getSuccessor(unsigned i) const {
2484     assert(i < 2 && "Successor # out of range for invoke!");
2485     return i == 0 ? getNormalDest() : getUnwindDest();
2486   }
2487
2488   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2489     assert(idx < 2 && "Successor # out of range for invoke!");
2490     setOperand(idx+1, NewSucc);
2491   }
2492
2493   unsigned getNumSuccessors() const { return 2; }
2494
2495   // Methods for support type inquiry through isa, cast, and dyn_cast:
2496   static inline bool classof(const InvokeInst *) { return true; }
2497   static inline bool classof(const Instruction *I) {
2498     return (I->getOpcode() == Instruction::Invoke);
2499   }
2500   static inline bool classof(const Value *V) {
2501     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2502   }
2503 private:
2504   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2505   virtual unsigned getNumSuccessorsV() const;
2506   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2507 };
2508
2509 template <>
2510 struct OperandTraits<InvokeInst> : VariadicOperandTraits<3> {
2511 };
2512
2513 template<typename InputIterator>
2514 InvokeInst::InvokeInst(Value *Func,
2515                        BasicBlock *IfNormal, BasicBlock *IfException,
2516                        InputIterator ArgBegin, InputIterator ArgEnd,
2517                        unsigned Values,
2518                        const Twine &NameStr, Instruction *InsertBefore)
2519   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2520                                       ->getElementType())->getReturnType(),
2521                    Instruction::Invoke,
2522                    OperandTraits<InvokeInst>::op_end(this) - Values,
2523                    Values, InsertBefore) {
2524   init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2525        typename std::iterator_traits<InputIterator>::iterator_category());
2526 }
2527 template<typename InputIterator>
2528 InvokeInst::InvokeInst(Value *Func,
2529                        BasicBlock *IfNormal, BasicBlock *IfException,
2530                        InputIterator ArgBegin, InputIterator ArgEnd,
2531                        unsigned Values,
2532                        const Twine &NameStr, BasicBlock *InsertAtEnd)
2533   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2534                                       ->getElementType())->getReturnType(),
2535                    Instruction::Invoke,
2536                    OperandTraits<InvokeInst>::op_end(this) - Values,
2537                    Values, InsertAtEnd) {
2538   init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2539        typename std::iterator_traits<InputIterator>::iterator_category());
2540 }
2541
2542 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2543
2544 //===----------------------------------------------------------------------===//
2545 //                              UnwindInst Class
2546 //===----------------------------------------------------------------------===//
2547
2548 //===---------------------------------------------------------------------------
2549 /// UnwindInst - Immediately exit the current function, unwinding the stack
2550 /// until an invoke instruction is found.
2551 ///
2552 class UnwindInst : public TerminatorInst {
2553   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2554 public:
2555   // allocate space for exactly zero operands
2556   void *operator new(size_t s) {
2557     return User::operator new(s, 0);
2558   }
2559   explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2560   explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2561
2562   virtual UnwindInst *clone(LLVMContext &Context) const;
2563
2564   unsigned getNumSuccessors() const { return 0; }
2565
2566   // Methods for support type inquiry through isa, cast, and dyn_cast:
2567   static inline bool classof(const UnwindInst *) { return true; }
2568   static inline bool classof(const Instruction *I) {
2569     return I->getOpcode() == Instruction::Unwind;
2570   }
2571   static inline bool classof(const Value *V) {
2572     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2573   }
2574 private:
2575   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2576   virtual unsigned getNumSuccessorsV() const;
2577   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2578 };
2579
2580 //===----------------------------------------------------------------------===//
2581 //                           UnreachableInst Class
2582 //===----------------------------------------------------------------------===//
2583
2584 //===---------------------------------------------------------------------------
2585 /// UnreachableInst - This function has undefined behavior.  In particular, the
2586 /// presence of this instruction indicates some higher level knowledge that the
2587 /// end of the block cannot be reached.
2588 ///
2589 class UnreachableInst : public TerminatorInst {
2590   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2591 public:
2592   // allocate space for exactly zero operands
2593   void *operator new(size_t s) {
2594     return User::operator new(s, 0);
2595   }
2596   explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2597   explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2598
2599   virtual UnreachableInst *clone(LLVMContext &Context) const;
2600
2601   unsigned getNumSuccessors() const { return 0; }
2602
2603   // Methods for support type inquiry through isa, cast, and dyn_cast:
2604   static inline bool classof(const UnreachableInst *) { return true; }
2605   static inline bool classof(const Instruction *I) {
2606     return I->getOpcode() == Instruction::Unreachable;
2607   }
2608   static inline bool classof(const Value *V) {
2609     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2610   }
2611 private:
2612   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2613   virtual unsigned getNumSuccessorsV() const;
2614   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2615 };
2616
2617 //===----------------------------------------------------------------------===//
2618 //                                 TruncInst Class
2619 //===----------------------------------------------------------------------===//
2620
2621 /// @brief This class represents a truncation of integer types.
2622 class TruncInst : public CastInst {
2623 public:
2624   /// @brief Constructor with insert-before-instruction semantics
2625   TruncInst(
2626     Value *S,                     ///< The value to be truncated
2627     const Type *Ty,               ///< The (smaller) type to truncate to
2628     const Twine &NameStr = "", ///< A name for the new instruction
2629     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2630   );
2631
2632   /// @brief Constructor with insert-at-end-of-block semantics
2633   TruncInst(
2634     Value *S,                     ///< The value to be truncated
2635     const Type *Ty,               ///< The (smaller) type to truncate to
2636     const Twine &NameStr,   ///< A name for the new instruction
2637     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2638   );
2639
2640   /// @brief Clone an identical TruncInst
2641   virtual CastInst *clone(LLVMContext &Context) const;
2642
2643   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2644   static inline bool classof(const TruncInst *) { return true; }
2645   static inline bool classof(const Instruction *I) {
2646     return I->getOpcode() == Trunc;
2647   }
2648   static inline bool classof(const Value *V) {
2649     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2650   }
2651 };
2652
2653 //===----------------------------------------------------------------------===//
2654 //                                 ZExtInst Class
2655 //===----------------------------------------------------------------------===//
2656
2657 /// @brief This class represents zero extension of integer types.
2658 class ZExtInst : public CastInst {
2659 public:
2660   /// @brief Constructor with insert-before-instruction semantics
2661   ZExtInst(
2662     Value *S,                     ///< The value to be zero extended
2663     const Type *Ty,               ///< The type to zero extend to
2664     const Twine &NameStr = "", ///< A name for the new instruction
2665     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2666   );
2667
2668   /// @brief Constructor with insert-at-end semantics.
2669   ZExtInst(
2670     Value *S,                     ///< The value to be zero extended
2671     const Type *Ty,               ///< The type to zero extend to
2672     const Twine &NameStr,   ///< A name for the new instruction
2673     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2674   );
2675
2676   /// @brief Clone an identical ZExtInst
2677   virtual CastInst *clone(LLVMContext &Context) const;
2678
2679   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2680   static inline bool classof(const ZExtInst *) { return true; }
2681   static inline bool classof(const Instruction *I) {
2682     return I->getOpcode() == ZExt;
2683   }
2684   static inline bool classof(const Value *V) {
2685     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2686   }
2687 };
2688
2689 //===----------------------------------------------------------------------===//
2690 //                                 SExtInst Class
2691 //===----------------------------------------------------------------------===//
2692
2693 /// @brief This class represents a sign extension of integer types.
2694 class SExtInst : public CastInst {
2695 public:
2696   /// @brief Constructor with insert-before-instruction semantics
2697   SExtInst(
2698     Value *S,                     ///< The value to be sign extended
2699     const Type *Ty,               ///< The type to sign extend to
2700     const Twine &NameStr = "", ///< A name for the new instruction
2701     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2702   );
2703
2704   /// @brief Constructor with insert-at-end-of-block semantics
2705   SExtInst(
2706     Value *S,                     ///< The value to be sign extended
2707     const Type *Ty,               ///< The type to sign extend to
2708     const Twine &NameStr,   ///< A name for the new instruction
2709     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2710   );
2711
2712   /// @brief Clone an identical SExtInst
2713   virtual CastInst *clone(LLVMContext &Context) const;
2714
2715   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2716   static inline bool classof(const SExtInst *) { return true; }
2717   static inline bool classof(const Instruction *I) {
2718     return I->getOpcode() == SExt;
2719   }
2720   static inline bool classof(const Value *V) {
2721     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2722   }
2723 };
2724
2725 //===----------------------------------------------------------------------===//
2726 //                                 FPTruncInst Class
2727 //===----------------------------------------------------------------------===//
2728
2729 /// @brief This class represents a truncation of floating point types.
2730 class FPTruncInst : public CastInst {
2731 public:
2732   /// @brief Constructor with insert-before-instruction semantics
2733   FPTruncInst(
2734     Value *S,                     ///< The value to be truncated
2735     const Type *Ty,               ///< The type to truncate to
2736     const Twine &NameStr = "", ///< A name for the new instruction
2737     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2738   );
2739
2740   /// @brief Constructor with insert-before-instruction semantics
2741   FPTruncInst(
2742     Value *S,                     ///< The value to be truncated
2743     const Type *Ty,               ///< The type to truncate to
2744     const Twine &NameStr,   ///< A name for the new instruction
2745     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2746   );
2747
2748   /// @brief Clone an identical FPTruncInst
2749   virtual CastInst *clone(LLVMContext &Context) const;
2750
2751   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2752   static inline bool classof(const FPTruncInst *) { return true; }
2753   static inline bool classof(const Instruction *I) {
2754     return I->getOpcode() == FPTrunc;
2755   }
2756   static inline bool classof(const Value *V) {
2757     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2758   }
2759 };
2760
2761 //===----------------------------------------------------------------------===//
2762 //                                 FPExtInst Class
2763 //===----------------------------------------------------------------------===//
2764
2765 /// @brief This class represents an extension of floating point types.
2766 class FPExtInst : public CastInst {
2767 public:
2768   /// @brief Constructor with insert-before-instruction semantics
2769   FPExtInst(
2770     Value *S,                     ///< The value to be extended
2771     const Type *Ty,               ///< The type to extend to
2772     const Twine &NameStr = "", ///< A name for the new instruction
2773     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2774   );
2775
2776   /// @brief Constructor with insert-at-end-of-block semantics
2777   FPExtInst(
2778     Value *S,                     ///< The value to be extended
2779     const Type *Ty,               ///< The type to extend to
2780     const Twine &NameStr,   ///< A name for the new instruction
2781     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2782   );
2783
2784   /// @brief Clone an identical FPExtInst
2785   virtual CastInst *clone(LLVMContext &Context) const;
2786
2787   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2788   static inline bool classof(const FPExtInst *) { return true; }
2789   static inline bool classof(const Instruction *I) {
2790     return I->getOpcode() == FPExt;
2791   }
2792   static inline bool classof(const Value *V) {
2793     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2794   }
2795 };
2796
2797 //===----------------------------------------------------------------------===//
2798 //                                 UIToFPInst Class
2799 //===----------------------------------------------------------------------===//
2800
2801 /// @brief This class represents a cast unsigned integer to floating point.
2802 class UIToFPInst : public CastInst {
2803 public:
2804   /// @brief Constructor with insert-before-instruction semantics
2805   UIToFPInst(
2806     Value *S,                     ///< The value to be converted
2807     const Type *Ty,               ///< The type to convert to
2808     const Twine &NameStr = "", ///< A name for the new instruction
2809     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2810   );
2811
2812   /// @brief Constructor with insert-at-end-of-block semantics
2813   UIToFPInst(
2814     Value *S,                     ///< The value to be converted
2815     const Type *Ty,               ///< The type to convert to
2816     const Twine &NameStr,   ///< A name for the new instruction
2817     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2818   );
2819
2820   /// @brief Clone an identical UIToFPInst
2821   virtual CastInst *clone(LLVMContext &Context) const;
2822
2823   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2824   static inline bool classof(const UIToFPInst *) { return true; }
2825   static inline bool classof(const Instruction *I) {
2826     return I->getOpcode() == UIToFP;
2827   }
2828   static inline bool classof(const Value *V) {
2829     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2830   }
2831 };
2832
2833 //===----------------------------------------------------------------------===//
2834 //                                 SIToFPInst Class
2835 //===----------------------------------------------------------------------===//
2836
2837 /// @brief This class represents a cast from signed integer to floating point.
2838 class SIToFPInst : public CastInst {
2839 public:
2840   /// @brief Constructor with insert-before-instruction semantics
2841   SIToFPInst(
2842     Value *S,                     ///< The value to be converted
2843     const Type *Ty,               ///< The type to convert to
2844     const Twine &NameStr = "", ///< A name for the new instruction
2845     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2846   );
2847
2848   /// @brief Constructor with insert-at-end-of-block semantics
2849   SIToFPInst(
2850     Value *S,                     ///< The value to be converted
2851     const Type *Ty,               ///< The type to convert to
2852     const Twine &NameStr,   ///< A name for the new instruction
2853     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2854   );
2855
2856   /// @brief Clone an identical SIToFPInst
2857   virtual CastInst *clone(LLVMContext &Context) const;
2858
2859   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2860   static inline bool classof(const SIToFPInst *) { return true; }
2861   static inline bool classof(const Instruction *I) {
2862     return I->getOpcode() == SIToFP;
2863   }
2864   static inline bool classof(const Value *V) {
2865     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2866   }
2867 };
2868
2869 //===----------------------------------------------------------------------===//
2870 //                                 FPToUIInst Class
2871 //===----------------------------------------------------------------------===//
2872
2873 /// @brief This class represents a cast from floating point to unsigned integer
2874 class FPToUIInst  : public CastInst {
2875 public:
2876   /// @brief Constructor with insert-before-instruction semantics
2877   FPToUIInst(
2878     Value *S,                     ///< The value to be converted
2879     const Type *Ty,               ///< The type to convert to
2880     const Twine &NameStr = "", ///< A name for the new instruction
2881     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2882   );
2883
2884   /// @brief Constructor with insert-at-end-of-block semantics
2885   FPToUIInst(
2886     Value *S,                     ///< The value to be converted
2887     const Type *Ty,               ///< The type to convert to
2888     const Twine &NameStr,   ///< A name for the new instruction
2889     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
2890   );
2891
2892   /// @brief Clone an identical FPToUIInst
2893   virtual CastInst *clone(LLVMContext &Context) const;
2894
2895   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2896   static inline bool classof(const FPToUIInst *) { return true; }
2897   static inline bool classof(const Instruction *I) {
2898     return I->getOpcode() == FPToUI;
2899   }
2900   static inline bool classof(const Value *V) {
2901     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2902   }
2903 };
2904
2905 //===----------------------------------------------------------------------===//
2906 //                                 FPToSIInst Class
2907 //===----------------------------------------------------------------------===//
2908
2909 /// @brief This class represents a cast from floating point to signed integer.
2910 class FPToSIInst  : public CastInst {
2911 public:
2912   /// @brief Constructor with insert-before-instruction semantics
2913   FPToSIInst(
2914     Value *S,                     ///< The value to be converted
2915     const Type *Ty,               ///< The type to convert to
2916     const Twine &NameStr = "", ///< A name for the new instruction
2917     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2918   );
2919
2920   /// @brief Constructor with insert-at-end-of-block semantics
2921   FPToSIInst(
2922     Value *S,                     ///< The value to be converted
2923     const Type *Ty,               ///< The type to convert to
2924     const Twine &NameStr,   ///< A name for the new instruction
2925     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2926   );
2927
2928   /// @brief Clone an identical FPToSIInst
2929   virtual CastInst *clone(LLVMContext &Context) const;
2930
2931   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2932   static inline bool classof(const FPToSIInst *) { return true; }
2933   static inline bool classof(const Instruction *I) {
2934     return I->getOpcode() == FPToSI;
2935   }
2936   static inline bool classof(const Value *V) {
2937     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2938   }
2939 };
2940
2941 //===----------------------------------------------------------------------===//
2942 //                                 IntToPtrInst Class
2943 //===----------------------------------------------------------------------===//
2944
2945 /// @brief This class represents a cast from an integer to a pointer.
2946 class IntToPtrInst : public CastInst {
2947 public:
2948   /// @brief Constructor with insert-before-instruction semantics
2949   IntToPtrInst(
2950     Value *S,                     ///< The value to be converted
2951     const Type *Ty,               ///< The type to convert to
2952     const Twine &NameStr = "", ///< A name for the new instruction
2953     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2954   );
2955
2956   /// @brief Constructor with insert-at-end-of-block semantics
2957   IntToPtrInst(
2958     Value *S,                     ///< The value to be converted
2959     const Type *Ty,               ///< The type to convert to
2960     const Twine &NameStr,   ///< A name for the new instruction
2961     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2962   );
2963
2964   /// @brief Clone an identical IntToPtrInst
2965   virtual CastInst *clone(LLVMContext &Context) const;
2966
2967   // Methods for support type inquiry through isa, cast, and dyn_cast:
2968   static inline bool classof(const IntToPtrInst *) { return true; }
2969   static inline bool classof(const Instruction *I) {
2970     return I->getOpcode() == IntToPtr;
2971   }
2972   static inline bool classof(const Value *V) {
2973     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2974   }
2975 };
2976
2977 //===----------------------------------------------------------------------===//
2978 //                                 PtrToIntInst Class
2979 //===----------------------------------------------------------------------===//
2980
2981 /// @brief This class represents a cast from a pointer to an integer
2982 class PtrToIntInst : public CastInst {
2983 public:
2984   /// @brief Constructor with insert-before-instruction semantics
2985   PtrToIntInst(
2986     Value *S,                     ///< The value to be converted
2987     const Type *Ty,               ///< The type to convert to
2988     const Twine &NameStr = "", ///< A name for the new instruction
2989     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2990   );
2991
2992   /// @brief Constructor with insert-at-end-of-block semantics
2993   PtrToIntInst(
2994     Value *S,                     ///< The value to be converted
2995     const Type *Ty,               ///< The type to convert to
2996     const Twine &NameStr,   ///< A name for the new instruction
2997     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2998   );
2999
3000   /// @brief Clone an identical PtrToIntInst
3001   virtual CastInst *clone(LLVMContext &Context) const;
3002
3003   // Methods for support type inquiry through isa, cast, and dyn_cast:
3004   static inline bool classof(const PtrToIntInst *) { return true; }
3005   static inline bool classof(const Instruction *I) {
3006     return I->getOpcode() == PtrToInt;
3007   }
3008   static inline bool classof(const Value *V) {
3009     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3010   }
3011 };
3012
3013 //===----------------------------------------------------------------------===//
3014 //                             BitCastInst Class
3015 //===----------------------------------------------------------------------===//
3016
3017 /// @brief This class represents a no-op cast from one type to another.
3018 class BitCastInst : public CastInst {
3019 public:
3020   /// @brief Constructor with insert-before-instruction semantics
3021   BitCastInst(
3022     Value *S,                     ///< The value to be casted
3023     const Type *Ty,               ///< The type to casted to
3024     const Twine &NameStr = "", ///< A name for the new instruction
3025     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3026   );
3027
3028   /// @brief Constructor with insert-at-end-of-block semantics
3029   BitCastInst(
3030     Value *S,                     ///< The value to be casted
3031     const Type *Ty,               ///< The type to casted to
3032     const Twine &NameStr,      ///< A name for the new instruction
3033     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3034   );
3035
3036   /// @brief Clone an identical BitCastInst
3037   virtual CastInst *clone(LLVMContext &Context) const;
3038
3039   // Methods for support type inquiry through isa, cast, and dyn_cast:
3040   static inline bool classof(const BitCastInst *) { return true; }
3041   static inline bool classof(const Instruction *I) {
3042     return I->getOpcode() == BitCast;
3043   }
3044   static inline bool classof(const Value *V) {
3045     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3046   }
3047 };
3048
3049 } // End llvm namespace
3050
3051 #endif