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