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