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