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