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