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