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