use ArgOffset constant to prepare for operand rotation
[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                                    const Twine &Name = "");
926   static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
927                                    const Type *IntPtrTy, const Type *AllocTy,
928                                    Value *AllocSize, Value *ArraySize = 0,
929                                    Function* MallocF = 0,
930                                    const Twine &Name = "");
931   /// CreateFree - Generate the IR for a call to the builtin free function.
932   static void CreateFree(Value* Source, Instruction *InsertBefore);
933   static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
934
935   ~CallInst();
936
937   bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
938   void setTailCall(bool isTC = true) {
939     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
940                                unsigned(isTC));
941   }
942
943   /// Provide fast operand accessors
944   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
945
946   enum { ArgOffset = 1 }; ///< temporary, do not use for new code!
947   unsigned getNumArgOperands() const { return getNumOperands() - 1; }
948   Value *getArgOperand(unsigned i) const { return getOperand(i + ArgOffset); }
949   void setArgOperand(unsigned i, Value *v) { setOperand(i + ArgOffset, v); }
950
951   /// getCallingConv/setCallingConv - Get or set the calling convention of this
952   /// function call.
953   CallingConv::ID getCallingConv() const {
954     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
955   }
956   void setCallingConv(CallingConv::ID CC) {
957     setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
958                                (static_cast<unsigned>(CC) << 1));
959   }
960
961   /// getAttributes - Return the parameter attributes for this call.
962   ///
963   const AttrListPtr &getAttributes() const { return AttributeList; }
964
965   /// setAttributes - Set the parameter attributes for this call.
966   ///
967   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
968
969   /// addAttribute - adds the attribute to the list of attributes.
970   void addAttribute(unsigned i, Attributes attr);
971
972   /// removeAttribute - removes the attribute from the list of attributes.
973   void removeAttribute(unsigned i, Attributes attr);
974
975   /// @brief Determine whether the call or the callee has the given attribute.
976   bool paramHasAttr(unsigned i, Attributes attr) const;
977
978   /// @brief Extract the alignment for a call or parameter (0=unknown).
979   unsigned getParamAlignment(unsigned i) const {
980     return AttributeList.getParamAlignment(i);
981   }
982   
983   /// @brief Return true if the call should not be inlined.
984   bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
985   void setIsNoInline(bool Value) {
986     if (Value) addAttribute(~0, Attribute::NoInline);
987     else removeAttribute(~0, Attribute::NoInline);
988   }
989
990   /// @brief Determine if the call does not access memory.
991   bool doesNotAccessMemory() const {
992     return paramHasAttr(~0, Attribute::ReadNone);
993   }
994   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
995     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
996     else removeAttribute(~0, Attribute::ReadNone);
997   }
998
999   /// @brief Determine if the call does not access or only reads memory.
1000   bool onlyReadsMemory() const {
1001     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
1002   }
1003   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
1004     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
1005     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
1006   }
1007
1008   /// @brief Determine if the call cannot return.
1009   bool doesNotReturn() const {
1010     return paramHasAttr(~0, Attribute::NoReturn);
1011   }
1012   void setDoesNotReturn(bool DoesNotReturn = true) {
1013     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1014     else removeAttribute(~0, Attribute::NoReturn);
1015   }
1016
1017   /// @brief Determine if the call cannot unwind.
1018   bool doesNotThrow() const {
1019     return paramHasAttr(~0, Attribute::NoUnwind);
1020   }
1021   void setDoesNotThrow(bool DoesNotThrow = true) {
1022     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1023     else removeAttribute(~0, Attribute::NoUnwind);
1024   }
1025
1026   /// @brief Determine if the call returns a structure through first
1027   /// pointer argument.
1028   bool hasStructRetAttr() const {
1029     // Be friendly and also check the callee.
1030     return paramHasAttr(1, Attribute::StructRet);
1031   }
1032
1033   /// @brief Determine if any call argument is an aggregate passed by value.
1034   bool hasByValArgument() const {
1035     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1036   }
1037
1038   /// getCalledFunction - Return the function called, or null if this is an
1039   /// indirect function invocation.
1040   ///
1041   Function *getCalledFunction() const {
1042     return dyn_cast<Function>(Op<ArgOffset -1>());
1043   }
1044
1045   /// getCalledValue - Get a pointer to the function that is invoked by this
1046   /// instruction.
1047   const Value *getCalledValue() const { return Op<ArgOffset -1>(); }
1048         Value *getCalledValue()       { return Op<ArgOffset -1>(); }
1049
1050   /// setCalledFunction - Set the function called.
1051   void setCalledFunction(Value* Fn) {
1052     Op<ArgOffset -1>() = Fn;
1053   }
1054
1055   // Methods for support type inquiry through isa, cast, and dyn_cast:
1056   static inline bool classof(const CallInst *) { return true; }
1057   static inline bool classof(const Instruction *I) {
1058     return I->getOpcode() == Instruction::Call;
1059   }
1060   static inline bool classof(const Value *V) {
1061     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1062   }
1063 private:
1064   // Shadow Instruction::setInstructionSubclassData with a private forwarding
1065   // method so that subclasses cannot accidentally use it.
1066   void setInstructionSubclassData(unsigned short D) {
1067     Instruction::setInstructionSubclassData(D);
1068   }
1069 };
1070
1071 template <>
1072 struct OperandTraits<CallInst> : public VariadicOperandTraits<1> {
1073 };
1074
1075 template<typename InputIterator>
1076 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1077                    const Twine &NameStr, BasicBlock *InsertAtEnd)
1078   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1079                                    ->getElementType())->getReturnType(),
1080                 Instruction::Call,
1081                 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1082                 (unsigned)(ArgEnd - ArgBegin + 1), InsertAtEnd) {
1083   init(Func, ArgBegin, ArgEnd, NameStr,
1084        typename std::iterator_traits<InputIterator>::iterator_category());
1085 }
1086
1087 template<typename InputIterator>
1088 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1089                    const Twine &NameStr, Instruction *InsertBefore)
1090   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1091                                    ->getElementType())->getReturnType(),
1092                 Instruction::Call,
1093                 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1094                 (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) {
1095   init(Func, ArgBegin, ArgEnd, NameStr,
1096        typename std::iterator_traits<InputIterator>::iterator_category());
1097 }
1098
1099 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1100
1101 //===----------------------------------------------------------------------===//
1102 //                               SelectInst Class
1103 //===----------------------------------------------------------------------===//
1104
1105 /// SelectInst - This class represents the LLVM 'select' instruction.
1106 ///
1107 class SelectInst : public Instruction {
1108   void init(Value *C, Value *S1, Value *S2) {
1109     assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1110     Op<0>() = C;
1111     Op<1>() = S1;
1112     Op<2>() = S2;
1113   }
1114
1115   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1116              Instruction *InsertBefore)
1117     : Instruction(S1->getType(), Instruction::Select,
1118                   &Op<0>(), 3, InsertBefore) {
1119     init(C, S1, S2);
1120     setName(NameStr);
1121   }
1122   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1123              BasicBlock *InsertAtEnd)
1124     : Instruction(S1->getType(), Instruction::Select,
1125                   &Op<0>(), 3, InsertAtEnd) {
1126     init(C, S1, S2);
1127     setName(NameStr);
1128   }
1129 protected:
1130   virtual SelectInst *clone_impl() const;
1131 public:
1132   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1133                             const Twine &NameStr = "",
1134                             Instruction *InsertBefore = 0) {
1135     return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1136   }
1137   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1138                             const Twine &NameStr,
1139                             BasicBlock *InsertAtEnd) {
1140     return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1141   }
1142
1143   const Value *getCondition() const { return Op<0>(); }
1144   const Value *getTrueValue() const { return Op<1>(); }
1145   const Value *getFalseValue() const { return Op<2>(); }
1146   Value *getCondition() { return Op<0>(); }
1147   Value *getTrueValue() { return Op<1>(); }
1148   Value *getFalseValue() { return Op<2>(); }
1149   
1150   /// areInvalidOperands - Return a string if the specified operands are invalid
1151   /// for a select operation, otherwise return null.
1152   static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1153
1154   /// Transparently provide more efficient getOperand methods.
1155   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1156
1157   OtherOps getOpcode() const {
1158     return static_cast<OtherOps>(Instruction::getOpcode());
1159   }
1160
1161   // Methods for support type inquiry through isa, cast, and dyn_cast:
1162   static inline bool classof(const SelectInst *) { return true; }
1163   static inline bool classof(const Instruction *I) {
1164     return I->getOpcode() == Instruction::Select;
1165   }
1166   static inline bool classof(const Value *V) {
1167     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1168   }
1169 };
1170
1171 template <>
1172 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<3> {
1173 };
1174
1175 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1176
1177 //===----------------------------------------------------------------------===//
1178 //                                VAArgInst Class
1179 //===----------------------------------------------------------------------===//
1180
1181 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1182 /// an argument of the specified type given a va_list and increments that list
1183 ///
1184 class VAArgInst : public UnaryInstruction {
1185 protected:
1186   virtual VAArgInst *clone_impl() const;
1187
1188 public:
1189   VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "",
1190              Instruction *InsertBefore = 0)
1191     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1192     setName(NameStr);
1193   }
1194   VAArgInst(Value *List, const Type *Ty, const Twine &NameStr,
1195             BasicBlock *InsertAtEnd)
1196     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1197     setName(NameStr);
1198   }
1199
1200   // Methods for support type inquiry through isa, cast, and dyn_cast:
1201   static inline bool classof(const VAArgInst *) { return true; }
1202   static inline bool classof(const Instruction *I) {
1203     return I->getOpcode() == VAArg;
1204   }
1205   static inline bool classof(const Value *V) {
1206     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1207   }
1208 };
1209
1210 //===----------------------------------------------------------------------===//
1211 //                                ExtractElementInst Class
1212 //===----------------------------------------------------------------------===//
1213
1214 /// ExtractElementInst - This instruction extracts a single (scalar)
1215 /// element from a VectorType value
1216 ///
1217 class ExtractElementInst : public Instruction {
1218   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1219                      Instruction *InsertBefore = 0);
1220   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1221                      BasicBlock *InsertAtEnd);
1222 protected:
1223   virtual ExtractElementInst *clone_impl() const;
1224
1225 public:
1226   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1227                                    const Twine &NameStr = "",
1228                                    Instruction *InsertBefore = 0) {
1229     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1230   }
1231   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1232                                    const Twine &NameStr,
1233                                    BasicBlock *InsertAtEnd) {
1234     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1235   }
1236
1237   /// isValidOperands - Return true if an extractelement instruction can be
1238   /// formed with the specified operands.
1239   static bool isValidOperands(const Value *Vec, const Value *Idx);
1240
1241   Value *getVectorOperand() { return Op<0>(); }
1242   Value *getIndexOperand() { return Op<1>(); }
1243   const Value *getVectorOperand() const { return Op<0>(); }
1244   const Value *getIndexOperand() const { return Op<1>(); }
1245   
1246   const VectorType *getVectorOperandType() const {
1247     return reinterpret_cast<const VectorType*>(getVectorOperand()->getType());
1248   }
1249   
1250   
1251   /// Transparently provide more efficient getOperand methods.
1252   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1253
1254   // Methods for support type inquiry through isa, cast, and dyn_cast:
1255   static inline bool classof(const ExtractElementInst *) { return true; }
1256   static inline bool classof(const Instruction *I) {
1257     return I->getOpcode() == Instruction::ExtractElement;
1258   }
1259   static inline bool classof(const Value *V) {
1260     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1261   }
1262 };
1263
1264 template <>
1265 struct OperandTraits<ExtractElementInst> : public FixedNumOperandTraits<2> {
1266 };
1267
1268 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1269
1270 //===----------------------------------------------------------------------===//
1271 //                                InsertElementInst Class
1272 //===----------------------------------------------------------------------===//
1273
1274 /// InsertElementInst - This instruction inserts a single (scalar)
1275 /// element into a VectorType value
1276 ///
1277 class InsertElementInst : public Instruction {
1278   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1279                     const Twine &NameStr = "",
1280                     Instruction *InsertBefore = 0);
1281   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1282                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1283 protected:
1284   virtual InsertElementInst *clone_impl() const;
1285
1286 public:
1287   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1288                                    const Twine &NameStr = "",
1289                                    Instruction *InsertBefore = 0) {
1290     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1291   }
1292   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1293                                    const Twine &NameStr,
1294                                    BasicBlock *InsertAtEnd) {
1295     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1296   }
1297
1298   /// isValidOperands - Return true if an insertelement instruction can be
1299   /// formed with the specified operands.
1300   static bool isValidOperands(const Value *Vec, const Value *NewElt,
1301                               const Value *Idx);
1302
1303   /// getType - Overload to return most specific vector type.
1304   ///
1305   const VectorType *getType() const {
1306     return reinterpret_cast<const VectorType*>(Instruction::getType());
1307   }
1308
1309   /// Transparently provide more efficient getOperand methods.
1310   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1311
1312   // Methods for support type inquiry through isa, cast, and dyn_cast:
1313   static inline bool classof(const InsertElementInst *) { return true; }
1314   static inline bool classof(const Instruction *I) {
1315     return I->getOpcode() == Instruction::InsertElement;
1316   }
1317   static inline bool classof(const Value *V) {
1318     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1319   }
1320 };
1321
1322 template <>
1323 struct OperandTraits<InsertElementInst> : public FixedNumOperandTraits<3> {
1324 };
1325
1326 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1327
1328 //===----------------------------------------------------------------------===//
1329 //                           ShuffleVectorInst Class
1330 //===----------------------------------------------------------------------===//
1331
1332 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1333 /// input vectors.
1334 ///
1335 class ShuffleVectorInst : public Instruction {
1336 protected:
1337   virtual ShuffleVectorInst *clone_impl() const;
1338
1339 public:
1340   // allocate space for exactly three operands
1341   void *operator new(size_t s) {
1342     return User::operator new(s, 3);
1343   }
1344   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1345                     const Twine &NameStr = "",
1346                     Instruction *InsertBefor = 0);
1347   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1348                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1349
1350   /// isValidOperands - Return true if a shufflevector instruction can be
1351   /// formed with the specified operands.
1352   static bool isValidOperands(const Value *V1, const Value *V2,
1353                               const Value *Mask);
1354
1355   /// getType - Overload to return most specific vector type.
1356   ///
1357   const VectorType *getType() const {
1358     return reinterpret_cast<const VectorType*>(Instruction::getType());
1359   }
1360
1361   /// Transparently provide more efficient getOperand methods.
1362   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1363
1364   /// getMaskValue - Return the index from the shuffle mask for the specified
1365   /// output result.  This is either -1 if the element is undef or a number less
1366   /// than 2*numelements.
1367   int getMaskValue(unsigned i) const;
1368
1369   // Methods for support type inquiry through isa, cast, and dyn_cast:
1370   static inline bool classof(const ShuffleVectorInst *) { return true; }
1371   static inline bool classof(const Instruction *I) {
1372     return I->getOpcode() == Instruction::ShuffleVector;
1373   }
1374   static inline bool classof(const Value *V) {
1375     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1376   }
1377 };
1378
1379 template <>
1380 struct OperandTraits<ShuffleVectorInst> : public FixedNumOperandTraits<3> {
1381 };
1382
1383 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1384
1385 //===----------------------------------------------------------------------===//
1386 //                                ExtractValueInst Class
1387 //===----------------------------------------------------------------------===//
1388
1389 /// ExtractValueInst - This instruction extracts a struct member or array
1390 /// element value from an aggregate value.
1391 ///
1392 class ExtractValueInst : public UnaryInstruction {
1393   SmallVector<unsigned, 4> Indices;
1394
1395   ExtractValueInst(const ExtractValueInst &EVI);
1396   void init(const unsigned *Idx, unsigned NumIdx,
1397             const Twine &NameStr);
1398   void init(unsigned Idx, const Twine &NameStr);
1399
1400   template<typename InputIterator>
1401   void init(InputIterator IdxBegin, InputIterator IdxEnd,
1402             const Twine &NameStr,
1403             // This argument ensures that we have an iterator we can
1404             // do arithmetic on in constant time
1405             std::random_access_iterator_tag) {
1406     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1407
1408     // There's no fundamental reason why we require at least one index
1409     // (other than weirdness with &*IdxBegin being invalid; see
1410     // getelementptr's init routine for example). But there's no
1411     // present need to support it.
1412     assert(NumIdx > 0 && "ExtractValueInst must have at least one index");
1413
1414     // This requires that the iterator points to contiguous memory.
1415     init(&*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1416                                          // we have to build an array here
1417   }
1418
1419   /// getIndexedType - Returns the type of the element that would be extracted
1420   /// with an extractvalue instruction with the specified parameters.
1421   ///
1422   /// Null is returned if the indices are invalid for the specified
1423   /// pointer type.
1424   ///
1425   static const Type *getIndexedType(const Type *Agg,
1426                                     const unsigned *Idx, unsigned NumIdx);
1427
1428   template<typename InputIterator>
1429   static const Type *getIndexedType(const Type *Ptr,
1430                                     InputIterator IdxBegin,
1431                                     InputIterator IdxEnd,
1432                                     // This argument ensures that we
1433                                     // have an iterator we can do
1434                                     // arithmetic on in constant time
1435                                     std::random_access_iterator_tag) {
1436     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1437
1438     if (NumIdx > 0)
1439       // This requires that the iterator points to contiguous memory.
1440       return getIndexedType(Ptr, &*IdxBegin, NumIdx);
1441     else
1442       return getIndexedType(Ptr, (const unsigned *)0, NumIdx);
1443   }
1444
1445   /// Constructors - Create a extractvalue instruction with a base aggregate
1446   /// value and a list of indices.  The first ctor can optionally insert before
1447   /// an existing instruction, the second appends the new instruction to the
1448   /// specified BasicBlock.
1449   template<typename InputIterator>
1450   inline ExtractValueInst(Value *Agg, InputIterator IdxBegin,
1451                           InputIterator IdxEnd,
1452                           const Twine &NameStr,
1453                           Instruction *InsertBefore);
1454   template<typename InputIterator>
1455   inline ExtractValueInst(Value *Agg,
1456                           InputIterator IdxBegin, InputIterator IdxEnd,
1457                           const Twine &NameStr, BasicBlock *InsertAtEnd);
1458
1459   // allocate space for exactly one operand
1460   void *operator new(size_t s) {
1461     return User::operator new(s, 1);
1462   }
1463 protected:
1464   virtual ExtractValueInst *clone_impl() const;
1465
1466 public:
1467   template<typename InputIterator>
1468   static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin,
1469                                   InputIterator IdxEnd,
1470                                   const Twine &NameStr = "",
1471                                   Instruction *InsertBefore = 0) {
1472     return new
1473       ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore);
1474   }
1475   template<typename InputIterator>
1476   static ExtractValueInst *Create(Value *Agg,
1477                                   InputIterator IdxBegin, InputIterator IdxEnd,
1478                                   const Twine &NameStr,
1479                                   BasicBlock *InsertAtEnd) {
1480     return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd);
1481   }
1482
1483   /// Constructors - These two creators are convenience methods because one
1484   /// index extractvalue instructions are much more common than those with
1485   /// more than one.
1486   static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1487                                   const Twine &NameStr = "",
1488                                   Instruction *InsertBefore = 0) {
1489     unsigned Idxs[1] = { Idx };
1490     return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore);
1491   }
1492   static ExtractValueInst *Create(Value *Agg, unsigned Idx,
1493                                   const Twine &NameStr,
1494                                   BasicBlock *InsertAtEnd) {
1495     unsigned Idxs[1] = { Idx };
1496     return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
1497   }
1498
1499   /// getIndexedType - Returns the type of the element that would be extracted
1500   /// with an extractvalue instruction with the specified parameters.
1501   ///
1502   /// Null is returned if the indices are invalid for the specified
1503   /// pointer type.
1504   ///
1505   template<typename InputIterator>
1506   static const Type *getIndexedType(const Type *Ptr,
1507                                     InputIterator IdxBegin,
1508                                     InputIterator IdxEnd) {
1509     return getIndexedType(Ptr, IdxBegin, IdxEnd,
1510                           typename std::iterator_traits<InputIterator>::
1511                           iterator_category());
1512   }
1513   static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
1514
1515   typedef const unsigned* idx_iterator;
1516   inline idx_iterator idx_begin() const { return Indices.begin(); }
1517   inline idx_iterator idx_end()   const { return Indices.end(); }
1518
1519   Value *getAggregateOperand() {
1520     return getOperand(0);
1521   }
1522   const Value *getAggregateOperand() const {
1523     return getOperand(0);
1524   }
1525   static unsigned getAggregateOperandIndex() {
1526     return 0U;                      // get index for modifying correct operand
1527   }
1528
1529   unsigned getNumIndices() const {  // Note: always non-negative
1530     return (unsigned)Indices.size();
1531   }
1532
1533   bool hasIndices() const {
1534     return true;
1535   }
1536
1537   // Methods for support type inquiry through isa, cast, and dyn_cast:
1538   static inline bool classof(const ExtractValueInst *) { return true; }
1539   static inline bool classof(const Instruction *I) {
1540     return I->getOpcode() == Instruction::ExtractValue;
1541   }
1542   static inline bool classof(const Value *V) {
1543     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1544   }
1545 };
1546
1547 template<typename InputIterator>
1548 ExtractValueInst::ExtractValueInst(Value *Agg,
1549                                    InputIterator IdxBegin,
1550                                    InputIterator IdxEnd,
1551                                    const Twine &NameStr,
1552                                    Instruction *InsertBefore)
1553   : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1554                                               IdxBegin, IdxEnd)),
1555                      ExtractValue, Agg, InsertBefore) {
1556   init(IdxBegin, IdxEnd, NameStr,
1557        typename std::iterator_traits<InputIterator>::iterator_category());
1558 }
1559 template<typename InputIterator>
1560 ExtractValueInst::ExtractValueInst(Value *Agg,
1561                                    InputIterator IdxBegin,
1562                                    InputIterator IdxEnd,
1563                                    const Twine &NameStr,
1564                                    BasicBlock *InsertAtEnd)
1565   : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1566                                               IdxBegin, IdxEnd)),
1567                      ExtractValue, Agg, InsertAtEnd) {
1568   init(IdxBegin, IdxEnd, NameStr,
1569        typename std::iterator_traits<InputIterator>::iterator_category());
1570 }
1571
1572
1573 //===----------------------------------------------------------------------===//
1574 //                                InsertValueInst Class
1575 //===----------------------------------------------------------------------===//
1576
1577 /// InsertValueInst - This instruction inserts a struct field of array element
1578 /// value into an aggregate value.
1579 ///
1580 class InsertValueInst : public Instruction {
1581   SmallVector<unsigned, 4> Indices;
1582
1583   void *operator new(size_t, unsigned); // Do not implement
1584   InsertValueInst(const InsertValueInst &IVI);
1585   void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx,
1586             const Twine &NameStr);
1587   void init(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr);
1588
1589   template<typename InputIterator>
1590   void init(Value *Agg, Value *Val,
1591             InputIterator IdxBegin, InputIterator IdxEnd,
1592             const Twine &NameStr,
1593             // This argument ensures that we have an iterator we can
1594             // do arithmetic on in constant time
1595             std::random_access_iterator_tag) {
1596     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1597
1598     // There's no fundamental reason why we require at least one index
1599     // (other than weirdness with &*IdxBegin being invalid; see
1600     // getelementptr's init routine for example). But there's no
1601     // present need to support it.
1602     assert(NumIdx > 0 && "InsertValueInst must have at least one index");
1603
1604     // This requires that the iterator points to contiguous memory.
1605     init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
1606                                               // we have to build an array here
1607   }
1608
1609   /// Constructors - Create a insertvalue instruction with a base aggregate
1610   /// value, a value to insert, and a list of indices.  The first ctor can
1611   /// optionally insert before an existing instruction, the second appends
1612   /// the new instruction to the specified BasicBlock.
1613   template<typename InputIterator>
1614   inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin,
1615                          InputIterator IdxEnd,
1616                          const Twine &NameStr,
1617                          Instruction *InsertBefore);
1618   template<typename InputIterator>
1619   inline InsertValueInst(Value *Agg, Value *Val,
1620                          InputIterator IdxBegin, InputIterator IdxEnd,
1621                          const Twine &NameStr, BasicBlock *InsertAtEnd);
1622
1623   /// Constructors - These two constructors are convenience methods because one
1624   /// and two index insertvalue instructions are so common.
1625   InsertValueInst(Value *Agg, Value *Val,
1626                   unsigned Idx, const Twine &NameStr = "",
1627                   Instruction *InsertBefore = 0);
1628   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1629                   const Twine &NameStr, BasicBlock *InsertAtEnd);
1630 protected:
1631   virtual InsertValueInst *clone_impl() const;
1632 public:
1633   // allocate space for exactly two operands
1634   void *operator new(size_t s) {
1635     return User::operator new(s, 2);
1636   }
1637
1638   template<typename InputIterator>
1639   static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin,
1640                                  InputIterator IdxEnd,
1641                                  const Twine &NameStr = "",
1642                                  Instruction *InsertBefore = 0) {
1643     return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1644                                NameStr, InsertBefore);
1645   }
1646   template<typename InputIterator>
1647   static InsertValueInst *Create(Value *Agg, Value *Val,
1648                                  InputIterator IdxBegin, InputIterator IdxEnd,
1649                                  const Twine &NameStr,
1650                                  BasicBlock *InsertAtEnd) {
1651     return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1652                                NameStr, InsertAtEnd);
1653   }
1654
1655   /// Constructors - These two creators are convenience methods because one
1656   /// index insertvalue instructions are much more common than those with
1657   /// more than one.
1658   static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1659                                  const Twine &NameStr = "",
1660                                  Instruction *InsertBefore = 0) {
1661     return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore);
1662   }
1663   static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
1664                                  const Twine &NameStr,
1665                                  BasicBlock *InsertAtEnd) {
1666     return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
1667   }
1668
1669   /// Transparently provide more efficient getOperand methods.
1670   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1671
1672   typedef const unsigned* idx_iterator;
1673   inline idx_iterator idx_begin() const { return Indices.begin(); }
1674   inline idx_iterator idx_end()   const { return Indices.end(); }
1675
1676   Value *getAggregateOperand() {
1677     return getOperand(0);
1678   }
1679   const Value *getAggregateOperand() const {
1680     return getOperand(0);
1681   }
1682   static unsigned getAggregateOperandIndex() {
1683     return 0U;                      // get index for modifying correct operand
1684   }
1685
1686   Value *getInsertedValueOperand() {
1687     return getOperand(1);
1688   }
1689   const Value *getInsertedValueOperand() const {
1690     return getOperand(1);
1691   }
1692   static unsigned getInsertedValueOperandIndex() {
1693     return 1U;                      // get index for modifying correct operand
1694   }
1695
1696   unsigned getNumIndices() const {  // Note: always non-negative
1697     return (unsigned)Indices.size();
1698   }
1699
1700   bool hasIndices() const {
1701     return true;
1702   }
1703
1704   // Methods for support type inquiry through isa, cast, and dyn_cast:
1705   static inline bool classof(const InsertValueInst *) { return true; }
1706   static inline bool classof(const Instruction *I) {
1707     return I->getOpcode() == Instruction::InsertValue;
1708   }
1709   static inline bool classof(const Value *V) {
1710     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1711   }
1712 };
1713
1714 template <>
1715 struct OperandTraits<InsertValueInst> : public FixedNumOperandTraits<2> {
1716 };
1717
1718 template<typename InputIterator>
1719 InsertValueInst::InsertValueInst(Value *Agg,
1720                                  Value *Val,
1721                                  InputIterator IdxBegin,
1722                                  InputIterator IdxEnd,
1723                                  const Twine &NameStr,
1724                                  Instruction *InsertBefore)
1725   : Instruction(Agg->getType(), InsertValue,
1726                 OperandTraits<InsertValueInst>::op_begin(this),
1727                 2, InsertBefore) {
1728   init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1729        typename std::iterator_traits<InputIterator>::iterator_category());
1730 }
1731 template<typename InputIterator>
1732 InsertValueInst::InsertValueInst(Value *Agg,
1733                                  Value *Val,
1734                                  InputIterator IdxBegin,
1735                                  InputIterator IdxEnd,
1736                                  const Twine &NameStr,
1737                                  BasicBlock *InsertAtEnd)
1738   : Instruction(Agg->getType(), InsertValue,
1739                 OperandTraits<InsertValueInst>::op_begin(this),
1740                 2, InsertAtEnd) {
1741   init(Agg, Val, IdxBegin, IdxEnd, NameStr,
1742        typename std::iterator_traits<InputIterator>::iterator_category());
1743 }
1744
1745 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1746
1747 //===----------------------------------------------------------------------===//
1748 //                               PHINode Class
1749 //===----------------------------------------------------------------------===//
1750
1751 // PHINode - The PHINode class is used to represent the magical mystical PHI
1752 // node, that can not exist in nature, but can be synthesized in a computer
1753 // scientist's overactive imagination.
1754 //
1755 class PHINode : public Instruction {
1756   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
1757   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1758   /// the number actually in use.
1759   unsigned ReservedSpace;
1760   PHINode(const PHINode &PN);
1761   // allocate space for exactly zero operands
1762   void *operator new(size_t s) {
1763     return User::operator new(s, 0);
1764   }
1765   explicit PHINode(const Type *Ty, const Twine &NameStr = "",
1766                    Instruction *InsertBefore = 0)
1767     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1768       ReservedSpace(0) {
1769     setName(NameStr);
1770   }
1771
1772   PHINode(const Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd)
1773     : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1774       ReservedSpace(0) {
1775     setName(NameStr);
1776   }
1777 protected:
1778   virtual PHINode *clone_impl() const;
1779 public:
1780   static PHINode *Create(const Type *Ty, const Twine &NameStr = "",
1781                          Instruction *InsertBefore = 0) {
1782     return new PHINode(Ty, NameStr, InsertBefore);
1783   }
1784   static PHINode *Create(const Type *Ty, const Twine &NameStr,
1785                          BasicBlock *InsertAtEnd) {
1786     return new PHINode(Ty, NameStr, InsertAtEnd);
1787   }
1788   ~PHINode();
1789
1790   /// reserveOperandSpace - This method can be used to avoid repeated
1791   /// reallocation of PHI operand lists by reserving space for the correct
1792   /// number of operands before adding them.  Unlike normal vector reserves,
1793   /// this method can also be used to trim the operand space.
1794   void reserveOperandSpace(unsigned NumValues) {
1795     resizeOperands(NumValues*2);
1796   }
1797
1798   /// Provide fast operand accessors
1799   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1800
1801   /// getNumIncomingValues - Return the number of incoming edges
1802   ///
1803   unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1804
1805   /// getIncomingValue - Return incoming value number x
1806   ///
1807   Value *getIncomingValue(unsigned i) const {
1808     assert(i*2 < getNumOperands() && "Invalid value number!");
1809     return getOperand(i*2);
1810   }
1811   void setIncomingValue(unsigned i, Value *V) {
1812     assert(i*2 < getNumOperands() && "Invalid value number!");
1813     setOperand(i*2, V);
1814   }
1815   static unsigned getOperandNumForIncomingValue(unsigned i) {
1816     return i*2;
1817   }
1818   static unsigned getIncomingValueNumForOperand(unsigned i) {
1819     assert(i % 2 == 0 && "Invalid incoming-value operand index!");
1820     return i/2;
1821   }
1822
1823   /// getIncomingBlock - Return incoming basic block number @p i.
1824   ///
1825   BasicBlock *getIncomingBlock(unsigned i) const {
1826     return cast<BasicBlock>(getOperand(i*2+1));
1827   }
1828   
1829   /// getIncomingBlock - Return incoming basic block corresponding
1830   /// to an operand of the PHI.
1831   ///
1832   BasicBlock *getIncomingBlock(const Use &U) const {
1833     assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
1834     return cast<BasicBlock>((&U + 1)->get());
1835   }
1836   
1837   /// getIncomingBlock - Return incoming basic block corresponding
1838   /// to value use iterator.
1839   ///
1840   template <typename U>
1841   BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1842     return getIncomingBlock(I.getUse());
1843   }
1844   
1845   
1846   void setIncomingBlock(unsigned i, BasicBlock *BB) {
1847     setOperand(i*2+1, (Value*)BB);
1848   }
1849   static unsigned getOperandNumForIncomingBlock(unsigned i) {
1850     return i*2+1;
1851   }
1852   static unsigned getIncomingBlockNumForOperand(unsigned i) {
1853     assert(i % 2 == 1 && "Invalid incoming-block operand index!");
1854     return i/2;
1855   }
1856
1857   /// addIncoming - Add an incoming value to the end of the PHI list
1858   ///
1859   void addIncoming(Value *V, BasicBlock *BB) {
1860     assert(V && "PHI node got a null value!");
1861     assert(BB && "PHI node got a null basic block!");
1862     assert(getType() == V->getType() &&
1863            "All operands to PHI node must be the same type as the PHI node!");
1864     unsigned OpNo = NumOperands;
1865     if (OpNo+2 > ReservedSpace)
1866       resizeOperands(0);  // Get more space!
1867     // Initialize some new operands.
1868     NumOperands = OpNo+2;
1869     OperandList[OpNo] = V;
1870     OperandList[OpNo+1] = (Value*)BB;
1871   }
1872
1873   /// removeIncomingValue - Remove an incoming value.  This is useful if a
1874   /// predecessor basic block is deleted.  The value removed is returned.
1875   ///
1876   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1877   /// is true), the PHI node is destroyed and any uses of it are replaced with
1878   /// dummy values.  The only time there should be zero incoming values to a PHI
1879   /// node is when the block is dead, so this strategy is sound.
1880   ///
1881   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1882
1883   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1884     int Idx = getBasicBlockIndex(BB);
1885     assert(Idx >= 0 && "Invalid basic block argument to remove!");
1886     return removeIncomingValue(Idx, DeletePHIIfEmpty);
1887   }
1888
1889   /// getBasicBlockIndex - Return the first index of the specified basic
1890   /// block in the value list for this PHI.  Returns -1 if no instance.
1891   ///
1892   int getBasicBlockIndex(const BasicBlock *BB) const {
1893     Use *OL = OperandList;
1894     for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1895       if (OL[i+1].get() == (const Value*)BB) return i/2;
1896     return -1;
1897   }
1898
1899   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1900     return getIncomingValue(getBasicBlockIndex(BB));
1901   }
1902
1903   /// hasConstantValue - If the specified PHI node always merges together the
1904   /// same value, return the value, otherwise return null.
1905   ///
1906   /// If the PHI has undef operands, but all the rest of the operands are
1907   /// some unique value, return that value if it can be proved that the
1908   /// value dominates the PHI. If DT is null, use a conservative check,
1909   /// otherwise use DT to test for dominance.
1910   ///
1911   Value *hasConstantValue(DominatorTree *DT = 0) const;
1912
1913   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1914   static inline bool classof(const PHINode *) { return true; }
1915   static inline bool classof(const Instruction *I) {
1916     return I->getOpcode() == Instruction::PHI;
1917   }
1918   static inline bool classof(const Value *V) {
1919     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1920   }
1921  private:
1922   void resizeOperands(unsigned NumOperands);
1923 };
1924
1925 template <>
1926 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
1927 };
1928
1929 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1930
1931
1932 //===----------------------------------------------------------------------===//
1933 //                               ReturnInst Class
1934 //===----------------------------------------------------------------------===//
1935
1936 //===---------------------------------------------------------------------------
1937 /// ReturnInst - Return a value (possibly void), from a function.  Execution
1938 /// does not continue in this function any longer.
1939 ///
1940 class ReturnInst : public TerminatorInst {
1941   ReturnInst(const ReturnInst &RI);
1942
1943 private:
1944   // ReturnInst constructors:
1945   // ReturnInst()                  - 'ret void' instruction
1946   // ReturnInst(    null)          - 'ret void' instruction
1947   // ReturnInst(Value* X)          - 'ret X'    instruction
1948   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
1949   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
1950   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
1951   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
1952   //
1953   // NOTE: If the Value* passed is of type void then the constructor behaves as
1954   // if it was passed NULL.
1955   explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
1956                       Instruction *InsertBefore = 0);
1957   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
1958   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
1959 protected:
1960   virtual ReturnInst *clone_impl() const;
1961 public:
1962   static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
1963                             Instruction *InsertBefore = 0) {
1964     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
1965   }
1966   static ReturnInst* Create(LLVMContext &C, Value *retVal,
1967                             BasicBlock *InsertAtEnd) {
1968     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
1969   }
1970   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
1971     return new(0) ReturnInst(C, InsertAtEnd);
1972   }
1973   virtual ~ReturnInst();
1974
1975   /// Provide fast operand accessors
1976   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1977
1978   /// Convenience accessor
1979   Value *getReturnValue(unsigned n = 0) const {
1980     return n < getNumOperands()
1981       ? getOperand(n)
1982       : 0;
1983   }
1984
1985   unsigned getNumSuccessors() const { return 0; }
1986
1987   // Methods for support type inquiry through isa, cast, and dyn_cast:
1988   static inline bool classof(const ReturnInst *) { return true; }
1989   static inline bool classof(const Instruction *I) {
1990     return (I->getOpcode() == Instruction::Ret);
1991   }
1992   static inline bool classof(const Value *V) {
1993     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1994   }
1995  private:
1996   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1997   virtual unsigned getNumSuccessorsV() const;
1998   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1999 };
2000
2001 template <>
2002 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<> {
2003 };
2004
2005 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2006
2007 //===----------------------------------------------------------------------===//
2008 //                               BranchInst Class
2009 //===----------------------------------------------------------------------===//
2010
2011 //===---------------------------------------------------------------------------
2012 /// BranchInst - Conditional or Unconditional Branch instruction.
2013 ///
2014 class BranchInst : public TerminatorInst {
2015   /// Ops list - Branches are strange.  The operands are ordered:
2016   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
2017   /// they don't have to check for cond/uncond branchness. These are mostly
2018   /// accessed relative from op_end().
2019   BranchInst(const BranchInst &BI);
2020   void AssertOK();
2021   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2022   // BranchInst(BB *B)                           - 'br B'
2023   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
2024   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
2025   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2026   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
2027   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
2028   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2029   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2030              Instruction *InsertBefore = 0);
2031   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2032   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2033              BasicBlock *InsertAtEnd);
2034 protected:
2035   virtual BranchInst *clone_impl() const;
2036 public:
2037   static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2038     return new(1, true) BranchInst(IfTrue, InsertBefore);
2039   }
2040   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2041                             Value *Cond, Instruction *InsertBefore = 0) {
2042     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2043   }
2044   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2045     return new(1, true) BranchInst(IfTrue, InsertAtEnd);
2046   }
2047   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2048                             Value *Cond, BasicBlock *InsertAtEnd) {
2049     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2050   }
2051
2052   ~BranchInst();
2053
2054   /// Transparently provide more efficient getOperand methods.
2055   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2056
2057   bool isUnconditional() const { return getNumOperands() == 1; }
2058   bool isConditional()   const { return getNumOperands() == 3; }
2059
2060   Value *getCondition() const {
2061     assert(isConditional() && "Cannot get condition of an uncond branch!");
2062     return Op<-3>();
2063   }
2064
2065   void setCondition(Value *V) {
2066     assert(isConditional() && "Cannot set condition of unconditional branch!");
2067     Op<-3>() = V;
2068   }
2069
2070   // setUnconditionalDest - Change the current branch to an unconditional branch
2071   // targeting the specified block.
2072   // FIXME: Eliminate this ugly method.
2073   void setUnconditionalDest(BasicBlock *Dest) {
2074     Op<-1>() = (Value*)Dest;
2075     if (isConditional()) {  // Convert this to an uncond branch.
2076       Op<-2>() = 0;
2077       Op<-3>() = 0;
2078       NumOperands = 1;
2079       OperandList = op_begin();
2080     }
2081   }
2082
2083   unsigned getNumSuccessors() const { return 1+isConditional(); }
2084
2085   BasicBlock *getSuccessor(unsigned i) const {
2086     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2087     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2088   }
2089
2090   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2091     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2092     *(&Op<-1>() - idx) = (Value*)NewSucc;
2093   }
2094
2095   // Methods for support type inquiry through isa, cast, and dyn_cast:
2096   static inline bool classof(const BranchInst *) { return true; }
2097   static inline bool classof(const Instruction *I) {
2098     return (I->getOpcode() == Instruction::Br);
2099   }
2100   static inline bool classof(const Value *V) {
2101     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2102   }
2103 private:
2104   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2105   virtual unsigned getNumSuccessorsV() const;
2106   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2107 };
2108
2109 template <>
2110 struct OperandTraits<BranchInst> : public VariadicOperandTraits<1> {};
2111
2112 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2113
2114 //===----------------------------------------------------------------------===//
2115 //                               SwitchInst Class
2116 //===----------------------------------------------------------------------===//
2117
2118 //===---------------------------------------------------------------------------
2119 /// SwitchInst - Multiway switch
2120 ///
2121 class SwitchInst : public TerminatorInst {
2122   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2123   unsigned ReservedSpace;
2124   // Operand[0]    = Value to switch on
2125   // Operand[1]    = Default basic block destination
2126   // Operand[2n  ] = Value to match
2127   // Operand[2n+1] = BasicBlock to go to on match
2128   SwitchInst(const SwitchInst &SI);
2129   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
2130   void resizeOperands(unsigned No);
2131   // allocate space for exactly zero operands
2132   void *operator new(size_t s) {
2133     return User::operator new(s, 0);
2134   }
2135   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2136   /// switch on and a default destination.  The number of additional cases can
2137   /// be specified here to make memory allocation more efficient.  This
2138   /// constructor can also autoinsert before another instruction.
2139   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2140              Instruction *InsertBefore);
2141
2142   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2143   /// switch on and a default destination.  The number of additional cases can
2144   /// be specified here to make memory allocation more efficient.  This
2145   /// constructor also autoinserts at the end of the specified BasicBlock.
2146   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2147              BasicBlock *InsertAtEnd);
2148 protected:
2149   virtual SwitchInst *clone_impl() const;
2150 public:
2151   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2152                             unsigned NumCases, Instruction *InsertBefore = 0) {
2153     return new SwitchInst(Value, Default, NumCases, InsertBefore);
2154   }
2155   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2156                             unsigned NumCases, BasicBlock *InsertAtEnd) {
2157     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2158   }
2159   ~SwitchInst();
2160
2161   /// Provide fast operand accessors
2162   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2163
2164   // Accessor Methods for Switch stmt
2165   Value *getCondition() const { return getOperand(0); }
2166   void setCondition(Value *V) { setOperand(0, V); }
2167
2168   BasicBlock *getDefaultDest() const {
2169     return cast<BasicBlock>(getOperand(1));
2170   }
2171
2172   /// getNumCases - return the number of 'cases' in this switch instruction.
2173   /// Note that case #0 is always the default case.
2174   unsigned getNumCases() const {
2175     return getNumOperands()/2;
2176   }
2177
2178   /// getCaseValue - Return the specified case value.  Note that case #0, the
2179   /// default destination, does not have a case value.
2180   ConstantInt *getCaseValue(unsigned i) {
2181     assert(i && i < getNumCases() && "Illegal case value to get!");
2182     return getSuccessorValue(i);
2183   }
2184
2185   /// getCaseValue - Return the specified case value.  Note that case #0, the
2186   /// default destination, does not have a case value.
2187   const ConstantInt *getCaseValue(unsigned i) const {
2188     assert(i && i < getNumCases() && "Illegal case value to get!");
2189     return getSuccessorValue(i);
2190   }
2191
2192   /// findCaseValue - Search all of the case values for the specified constant.
2193   /// If it is explicitly handled, return the case number of it, otherwise
2194   /// return 0 to indicate that it is handled by the default handler.
2195   unsigned findCaseValue(const ConstantInt *C) const {
2196     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2197       if (getCaseValue(i) == C)
2198         return i;
2199     return 0;
2200   }
2201
2202   /// findCaseDest - Finds the unique case value for a given successor. Returns
2203   /// null if the successor is not found, not unique, or is the default case.
2204   ConstantInt *findCaseDest(BasicBlock *BB) {
2205     if (BB == getDefaultDest()) return NULL;
2206
2207     ConstantInt *CI = NULL;
2208     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2209       if (getSuccessor(i) == BB) {
2210         if (CI) return NULL;   // Multiple cases lead to BB.
2211         else CI = getCaseValue(i);
2212       }
2213     }
2214     return CI;
2215   }
2216
2217   /// addCase - Add an entry to the switch instruction...
2218   ///
2219   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2220
2221   /// removeCase - This method removes the specified successor from the switch
2222   /// instruction.  Note that this cannot be used to remove the default
2223   /// destination (successor #0).
2224   ///
2225   void removeCase(unsigned idx);
2226
2227   unsigned getNumSuccessors() const { return getNumOperands()/2; }
2228   BasicBlock *getSuccessor(unsigned idx) const {
2229     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2230     return cast<BasicBlock>(getOperand(idx*2+1));
2231   }
2232   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2233     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2234     setOperand(idx*2+1, (Value*)NewSucc);
2235   }
2236
2237   // getSuccessorValue - Return the value associated with the specified
2238   // successor.
2239   ConstantInt *getSuccessorValue(unsigned idx) const {
2240     assert(idx < getNumSuccessors() && "Successor # out of range!");
2241     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2242   }
2243
2244   // Methods for support type inquiry through isa, cast, and dyn_cast:
2245   static inline bool classof(const SwitchInst *) { return true; }
2246   static inline bool classof(const Instruction *I) {
2247     return I->getOpcode() == Instruction::Switch;
2248   }
2249   static inline bool classof(const Value *V) {
2250     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2251   }
2252 private:
2253   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2254   virtual unsigned getNumSuccessorsV() const;
2255   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2256 };
2257
2258 template <>
2259 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2260 };
2261
2262 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2263
2264
2265 //===----------------------------------------------------------------------===//
2266 //                             IndirectBrInst Class
2267 //===----------------------------------------------------------------------===//
2268
2269 //===---------------------------------------------------------------------------
2270 /// IndirectBrInst - Indirect Branch Instruction.
2271 ///
2272 class IndirectBrInst : public TerminatorInst {
2273   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2274   unsigned ReservedSpace;
2275   // Operand[0]    = Value to switch on
2276   // Operand[1]    = Default basic block destination
2277   // Operand[2n  ] = Value to match
2278   // Operand[2n+1] = BasicBlock to go to on match
2279   IndirectBrInst(const IndirectBrInst &IBI);
2280   void init(Value *Address, unsigned NumDests);
2281   void resizeOperands(unsigned No);
2282   // allocate space for exactly zero operands
2283   void *operator new(size_t s) {
2284     return User::operator new(s, 0);
2285   }
2286   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2287   /// Address to jump to.  The number of expected destinations can be specified
2288   /// here to make memory allocation more efficient.  This constructor can also
2289   /// autoinsert before another instruction.
2290   IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2291   
2292   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2293   /// Address to jump to.  The number of expected destinations can be specified
2294   /// here to make memory allocation more efficient.  This constructor also
2295   /// autoinserts at the end of the specified BasicBlock.
2296   IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2297 protected:
2298   virtual IndirectBrInst *clone_impl() const;
2299 public:
2300   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2301                                 Instruction *InsertBefore = 0) {
2302     return new IndirectBrInst(Address, NumDests, InsertBefore);
2303   }
2304   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2305                                 BasicBlock *InsertAtEnd) {
2306     return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2307   }
2308   ~IndirectBrInst();
2309   
2310   /// Provide fast operand accessors.
2311   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2312   
2313   // Accessor Methods for IndirectBrInst instruction.
2314   Value *getAddress() { return getOperand(0); }
2315   const Value *getAddress() const { return getOperand(0); }
2316   void setAddress(Value *V) { setOperand(0, V); }
2317   
2318   
2319   /// getNumDestinations - return the number of possible destinations in this
2320   /// indirectbr instruction.
2321   unsigned getNumDestinations() const { return getNumOperands()-1; }
2322   
2323   /// getDestination - Return the specified destination.
2324   BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2325   const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2326   
2327   /// addDestination - Add a destination.
2328   ///
2329   void addDestination(BasicBlock *Dest);
2330   
2331   /// removeDestination - This method removes the specified successor from the
2332   /// indirectbr instruction.
2333   void removeDestination(unsigned i);
2334   
2335   unsigned getNumSuccessors() const { return getNumOperands()-1; }
2336   BasicBlock *getSuccessor(unsigned i) const {
2337     return cast<BasicBlock>(getOperand(i+1));
2338   }
2339   void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2340     setOperand(i+1, (Value*)NewSucc);
2341   }
2342   
2343   // Methods for support type inquiry through isa, cast, and dyn_cast:
2344   static inline bool classof(const IndirectBrInst *) { return true; }
2345   static inline bool classof(const Instruction *I) {
2346     return I->getOpcode() == Instruction::IndirectBr;
2347   }
2348   static inline bool classof(const Value *V) {
2349     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2350   }
2351 private:
2352   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2353   virtual unsigned getNumSuccessorsV() const;
2354   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2355 };
2356
2357 template <>
2358 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2359 };
2360
2361 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2362   
2363   
2364 //===----------------------------------------------------------------------===//
2365 //                               InvokeInst Class
2366 //===----------------------------------------------------------------------===//
2367
2368 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
2369 /// calling convention of the call.
2370 ///
2371 class InvokeInst : public TerminatorInst {
2372   AttrListPtr AttributeList;
2373   InvokeInst(const InvokeInst &BI);
2374   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
2375             Value* const *Args, unsigned NumArgs);
2376
2377   template<typename InputIterator>
2378   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2379             InputIterator ArgBegin, InputIterator ArgEnd,
2380             const Twine &NameStr,
2381             // This argument ensures that we have an iterator we can
2382             // do arithmetic on in constant time
2383             std::random_access_iterator_tag) {
2384     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
2385
2386     // This requires that the iterator points to contiguous memory.
2387     init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
2388     setName(NameStr);
2389   }
2390
2391   /// Construct an InvokeInst given a range of arguments.
2392   /// InputIterator must be a random-access iterator pointing to
2393   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
2394   /// made for random-accessness but not for contiguous storage as
2395   /// that would incur runtime overhead.
2396   ///
2397   /// @brief Construct an InvokeInst from a range of arguments
2398   template<typename InputIterator>
2399   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2400                     InputIterator ArgBegin, InputIterator ArgEnd,
2401                     unsigned Values,
2402                     const Twine &NameStr, Instruction *InsertBefore);
2403
2404   /// Construct an InvokeInst given a range of arguments.
2405   /// InputIterator must be a random-access iterator pointing to
2406   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
2407   /// made for random-accessness but not for contiguous storage as
2408   /// that would incur runtime overhead.
2409   ///
2410   /// @brief Construct an InvokeInst from a range of arguments
2411   template<typename InputIterator>
2412   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2413                     InputIterator ArgBegin, InputIterator ArgEnd,
2414                     unsigned Values,
2415                     const Twine &NameStr, BasicBlock *InsertAtEnd);
2416 protected:
2417   virtual InvokeInst *clone_impl() const;
2418 public:
2419   template<typename InputIterator>
2420   static InvokeInst *Create(Value *Func,
2421                             BasicBlock *IfNormal, BasicBlock *IfException,
2422                             InputIterator ArgBegin, InputIterator ArgEnd,
2423                             const Twine &NameStr = "",
2424                             Instruction *InsertBefore = 0) {
2425     unsigned Values(ArgEnd - ArgBegin + 3);
2426     return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2427                                   Values, NameStr, InsertBefore);
2428   }
2429   template<typename InputIterator>
2430   static InvokeInst *Create(Value *Func,
2431                             BasicBlock *IfNormal, BasicBlock *IfException,
2432                             InputIterator ArgBegin, InputIterator ArgEnd,
2433                             const Twine &NameStr,
2434                             BasicBlock *InsertAtEnd) {
2435     unsigned Values(ArgEnd - ArgBegin + 3);
2436     return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2437                                   Values, NameStr, InsertAtEnd);
2438   }
2439
2440   /// Provide fast operand accessors
2441   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2442
2443   unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2444   Value *getArgOperand(unsigned i) const { return getOperand(i); }
2445   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2446
2447   /// getCallingConv/setCallingConv - Get or set the calling convention of this
2448   /// function call.
2449   CallingConv::ID getCallingConv() const {
2450     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2451   }
2452   void setCallingConv(CallingConv::ID CC) {
2453     setInstructionSubclassData(static_cast<unsigned>(CC));
2454   }
2455
2456   /// getAttributes - Return the parameter attributes for this invoke.
2457   ///
2458   const AttrListPtr &getAttributes() const { return AttributeList; }
2459
2460   /// setAttributes - Set the parameter attributes for this invoke.
2461   ///
2462   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2463
2464   /// addAttribute - adds the attribute to the list of attributes.
2465   void addAttribute(unsigned i, Attributes attr);
2466
2467   /// removeAttribute - removes the attribute from the list of attributes.
2468   void removeAttribute(unsigned i, Attributes attr);
2469
2470   /// @brief Determine whether the call or the callee has the given attribute.
2471   bool paramHasAttr(unsigned i, Attributes attr) const;
2472
2473   /// @brief Extract the alignment for a call or parameter (0=unknown).
2474   unsigned getParamAlignment(unsigned i) const {
2475     return AttributeList.getParamAlignment(i);
2476   }
2477
2478   /// @brief Return true if the call should not be inlined.
2479   bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2480   void setIsNoInline(bool Value) {
2481     if (Value) addAttribute(~0, Attribute::NoInline);
2482     else removeAttribute(~0, Attribute::NoInline);
2483   }
2484   
2485   /// @brief Determine if the call does not access memory.
2486   bool doesNotAccessMemory() const {
2487     return paramHasAttr(~0, Attribute::ReadNone);
2488   }
2489   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2490     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2491     else removeAttribute(~0, Attribute::ReadNone);
2492   }
2493
2494   /// @brief Determine if the call does not access or only reads memory.
2495   bool onlyReadsMemory() const {
2496     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2497   }
2498   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2499     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2500     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2501   }
2502
2503   /// @brief Determine if the call cannot return.
2504   bool doesNotReturn() const {
2505     return paramHasAttr(~0, Attribute::NoReturn);
2506   }
2507   void setDoesNotReturn(bool DoesNotReturn = true) {
2508     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2509     else removeAttribute(~0, Attribute::NoReturn);
2510   }
2511
2512   /// @brief Determine if the call cannot unwind.
2513   bool doesNotThrow() const {
2514     return paramHasAttr(~0, Attribute::NoUnwind);
2515   }
2516   void setDoesNotThrow(bool DoesNotThrow = true) {
2517     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2518     else removeAttribute(~0, Attribute::NoUnwind);
2519   }
2520
2521   /// @brief Determine if the call returns a structure through first
2522   /// pointer argument.
2523   bool hasStructRetAttr() const {
2524     // Be friendly and also check the callee.
2525     return paramHasAttr(1, Attribute::StructRet);
2526   }
2527
2528   /// @brief Determine if any call argument is an aggregate passed by value.
2529   bool hasByValArgument() const {
2530     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2531   }
2532
2533   /// getCalledFunction - Return the function called, or null if this is an
2534   /// indirect function invocation.
2535   ///
2536   Function *getCalledFunction() const {
2537     return dyn_cast<Function>(Op<-3>());
2538   }
2539
2540   /// getCalledValue - Get a pointer to the function that is invoked by this
2541   /// instruction
2542   const Value *getCalledValue() const { return Op<-3>(); }
2543         Value *getCalledValue()       { return Op<-3>(); }
2544
2545   /// setCalledFunction - Set the function called.
2546   void setCalledFunction(Value* Fn) {
2547     Op<-3>() = Fn;
2548   }
2549
2550   // get*Dest - Return the destination basic blocks...
2551   BasicBlock *getNormalDest() const {
2552     return cast<BasicBlock>(Op<-2>());
2553   }
2554   BasicBlock *getUnwindDest() const {
2555     return cast<BasicBlock>(Op<-1>());
2556   }
2557   void setNormalDest(BasicBlock *B) {
2558     Op<-2>() = reinterpret_cast<Value*>(B);
2559   }
2560   void setUnwindDest(BasicBlock *B) {
2561     Op<-1>() = reinterpret_cast<Value*>(B);
2562   }
2563
2564   BasicBlock *getSuccessor(unsigned i) const {
2565     assert(i < 2 && "Successor # out of range for invoke!");
2566     return i == 0 ? getNormalDest() : getUnwindDest();
2567   }
2568
2569   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2570     assert(idx < 2 && "Successor # out of range for invoke!");
2571     *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2572   }
2573
2574   unsigned getNumSuccessors() const { return 2; }
2575
2576   // Methods for support type inquiry through isa, cast, and dyn_cast:
2577   static inline bool classof(const InvokeInst *) { return true; }
2578   static inline bool classof(const Instruction *I) {
2579     return (I->getOpcode() == Instruction::Invoke);
2580   }
2581   static inline bool classof(const Value *V) {
2582     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2583   }
2584
2585 private:
2586   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2587   virtual unsigned getNumSuccessorsV() const;
2588   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2589
2590   // Shadow Instruction::setInstructionSubclassData with a private forwarding
2591   // method so that subclasses cannot accidentally use it.
2592   void setInstructionSubclassData(unsigned short D) {
2593     Instruction::setInstructionSubclassData(D);
2594   }
2595 };
2596
2597 template <>
2598 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<3> {
2599 };
2600
2601 template<typename InputIterator>
2602 InvokeInst::InvokeInst(Value *Func,
2603                        BasicBlock *IfNormal, BasicBlock *IfException,
2604                        InputIterator ArgBegin, InputIterator ArgEnd,
2605                        unsigned Values,
2606                        const Twine &NameStr, Instruction *InsertBefore)
2607   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2608                                       ->getElementType())->getReturnType(),
2609                    Instruction::Invoke,
2610                    OperandTraits<InvokeInst>::op_end(this) - Values,
2611                    Values, InsertBefore) {
2612   init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2613        typename std::iterator_traits<InputIterator>::iterator_category());
2614 }
2615 template<typename InputIterator>
2616 InvokeInst::InvokeInst(Value *Func,
2617                        BasicBlock *IfNormal, BasicBlock *IfException,
2618                        InputIterator ArgBegin, InputIterator ArgEnd,
2619                        unsigned Values,
2620                        const Twine &NameStr, BasicBlock *InsertAtEnd)
2621   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2622                                       ->getElementType())->getReturnType(),
2623                    Instruction::Invoke,
2624                    OperandTraits<InvokeInst>::op_end(this) - Values,
2625                    Values, InsertAtEnd) {
2626   init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
2627        typename std::iterator_traits<InputIterator>::iterator_category());
2628 }
2629
2630 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2631
2632 //===----------------------------------------------------------------------===//
2633 //                              UnwindInst Class
2634 //===----------------------------------------------------------------------===//
2635
2636 //===---------------------------------------------------------------------------
2637 /// UnwindInst - Immediately exit the current function, unwinding the stack
2638 /// until an invoke instruction is found.
2639 ///
2640 class UnwindInst : public TerminatorInst {
2641   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2642 protected:
2643   virtual UnwindInst *clone_impl() const;
2644 public:
2645   // allocate space for exactly zero operands
2646   void *operator new(size_t s) {
2647     return User::operator new(s, 0);
2648   }
2649   explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2650   explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2651
2652   unsigned getNumSuccessors() const { return 0; }
2653
2654   // Methods for support type inquiry through isa, cast, and dyn_cast:
2655   static inline bool classof(const UnwindInst *) { return true; }
2656   static inline bool classof(const Instruction *I) {
2657     return I->getOpcode() == Instruction::Unwind;
2658   }
2659   static inline bool classof(const Value *V) {
2660     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2661   }
2662 private:
2663   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2664   virtual unsigned getNumSuccessorsV() const;
2665   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2666 };
2667
2668 //===----------------------------------------------------------------------===//
2669 //                           UnreachableInst Class
2670 //===----------------------------------------------------------------------===//
2671
2672 //===---------------------------------------------------------------------------
2673 /// UnreachableInst - This function has undefined behavior.  In particular, the
2674 /// presence of this instruction indicates some higher level knowledge that the
2675 /// end of the block cannot be reached.
2676 ///
2677 class UnreachableInst : public TerminatorInst {
2678   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2679 protected:
2680   virtual UnreachableInst *clone_impl() const;
2681
2682 public:
2683   // allocate space for exactly zero operands
2684   void *operator new(size_t s) {
2685     return User::operator new(s, 0);
2686   }
2687   explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2688   explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2689
2690   unsigned getNumSuccessors() const { return 0; }
2691
2692   // Methods for support type inquiry through isa, cast, and dyn_cast:
2693   static inline bool classof(const UnreachableInst *) { return true; }
2694   static inline bool classof(const Instruction *I) {
2695     return I->getOpcode() == Instruction::Unreachable;
2696   }
2697   static inline bool classof(const Value *V) {
2698     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2699   }
2700 private:
2701   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2702   virtual unsigned getNumSuccessorsV() const;
2703   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2704 };
2705
2706 //===----------------------------------------------------------------------===//
2707 //                                 TruncInst Class
2708 //===----------------------------------------------------------------------===//
2709
2710 /// @brief This class represents a truncation of integer types.
2711 class TruncInst : public CastInst {
2712 protected:
2713   /// @brief Clone an identical TruncInst
2714   virtual TruncInst *clone_impl() const;
2715
2716 public:
2717   /// @brief Constructor with insert-before-instruction semantics
2718   TruncInst(
2719     Value *S,                     ///< The value to be truncated
2720     const Type *Ty,               ///< The (smaller) type to truncate to
2721     const Twine &NameStr = "", ///< A name for the new instruction
2722     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2723   );
2724
2725   /// @brief Constructor with insert-at-end-of-block semantics
2726   TruncInst(
2727     Value *S,                     ///< The value to be truncated
2728     const Type *Ty,               ///< The (smaller) type to truncate to
2729     const Twine &NameStr,   ///< A name for the new instruction
2730     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2731   );
2732
2733   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2734   static inline bool classof(const TruncInst *) { return true; }
2735   static inline bool classof(const Instruction *I) {
2736     return I->getOpcode() == Trunc;
2737   }
2738   static inline bool classof(const Value *V) {
2739     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2740   }
2741 };
2742
2743 //===----------------------------------------------------------------------===//
2744 //                                 ZExtInst Class
2745 //===----------------------------------------------------------------------===//
2746
2747 /// @brief This class represents zero extension of integer types.
2748 class ZExtInst : public CastInst {
2749 protected:
2750   /// @brief Clone an identical ZExtInst
2751   virtual ZExtInst *clone_impl() const;
2752
2753 public:
2754   /// @brief Constructor with insert-before-instruction semantics
2755   ZExtInst(
2756     Value *S,                     ///< The value to be zero extended
2757     const Type *Ty,               ///< The type to zero extend to
2758     const Twine &NameStr = "", ///< A name for the new instruction
2759     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2760   );
2761
2762   /// @brief Constructor with insert-at-end semantics.
2763   ZExtInst(
2764     Value *S,                     ///< The value to be zero extended
2765     const Type *Ty,               ///< The type to zero extend to
2766     const Twine &NameStr,   ///< A name for the new instruction
2767     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2768   );
2769
2770   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2771   static inline bool classof(const ZExtInst *) { return true; }
2772   static inline bool classof(const Instruction *I) {
2773     return I->getOpcode() == ZExt;
2774   }
2775   static inline bool classof(const Value *V) {
2776     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2777   }
2778 };
2779
2780 //===----------------------------------------------------------------------===//
2781 //                                 SExtInst Class
2782 //===----------------------------------------------------------------------===//
2783
2784 /// @brief This class represents a sign extension of integer types.
2785 class SExtInst : public CastInst {
2786 protected:
2787   /// @brief Clone an identical SExtInst
2788   virtual SExtInst *clone_impl() const;
2789
2790 public:
2791   /// @brief Constructor with insert-before-instruction semantics
2792   SExtInst(
2793     Value *S,                     ///< The value to be sign extended
2794     const Type *Ty,               ///< The type to sign extend to
2795     const Twine &NameStr = "", ///< A name for the new instruction
2796     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2797   );
2798
2799   /// @brief Constructor with insert-at-end-of-block semantics
2800   SExtInst(
2801     Value *S,                     ///< The value to be sign extended
2802     const Type *Ty,               ///< The type to sign extend to
2803     const Twine &NameStr,   ///< A name for the new instruction
2804     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2805   );
2806
2807   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2808   static inline bool classof(const SExtInst *) { return true; }
2809   static inline bool classof(const Instruction *I) {
2810     return I->getOpcode() == SExt;
2811   }
2812   static inline bool classof(const Value *V) {
2813     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2814   }
2815 };
2816
2817 //===----------------------------------------------------------------------===//
2818 //                                 FPTruncInst Class
2819 //===----------------------------------------------------------------------===//
2820
2821 /// @brief This class represents a truncation of floating point types.
2822 class FPTruncInst : public CastInst {
2823 protected:
2824   /// @brief Clone an identical FPTruncInst
2825   virtual FPTruncInst *clone_impl() const;
2826
2827 public:
2828   /// @brief Constructor with insert-before-instruction semantics
2829   FPTruncInst(
2830     Value *S,                     ///< The value to be truncated
2831     const Type *Ty,               ///< The type to truncate to
2832     const Twine &NameStr = "", ///< A name for the new instruction
2833     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2834   );
2835
2836   /// @brief Constructor with insert-before-instruction semantics
2837   FPTruncInst(
2838     Value *S,                     ///< The value to be truncated
2839     const Type *Ty,               ///< The type to truncate to
2840     const Twine &NameStr,   ///< A name for the new instruction
2841     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2842   );
2843
2844   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2845   static inline bool classof(const FPTruncInst *) { return true; }
2846   static inline bool classof(const Instruction *I) {
2847     return I->getOpcode() == FPTrunc;
2848   }
2849   static inline bool classof(const Value *V) {
2850     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2851   }
2852 };
2853
2854 //===----------------------------------------------------------------------===//
2855 //                                 FPExtInst Class
2856 //===----------------------------------------------------------------------===//
2857
2858 /// @brief This class represents an extension of floating point types.
2859 class FPExtInst : public CastInst {
2860 protected:
2861   /// @brief Clone an identical FPExtInst
2862   virtual FPExtInst *clone_impl() const;
2863
2864 public:
2865   /// @brief Constructor with insert-before-instruction semantics
2866   FPExtInst(
2867     Value *S,                     ///< The value to be extended
2868     const Type *Ty,               ///< The type to extend to
2869     const Twine &NameStr = "", ///< A name for the new instruction
2870     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2871   );
2872
2873   /// @brief Constructor with insert-at-end-of-block semantics
2874   FPExtInst(
2875     Value *S,                     ///< The value to be extended
2876     const Type *Ty,               ///< The type to extend to
2877     const Twine &NameStr,   ///< A name for the new instruction
2878     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2879   );
2880
2881   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2882   static inline bool classof(const FPExtInst *) { return true; }
2883   static inline bool classof(const Instruction *I) {
2884     return I->getOpcode() == FPExt;
2885   }
2886   static inline bool classof(const Value *V) {
2887     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2888   }
2889 };
2890
2891 //===----------------------------------------------------------------------===//
2892 //                                 UIToFPInst Class
2893 //===----------------------------------------------------------------------===//
2894
2895 /// @brief This class represents a cast unsigned integer to floating point.
2896 class UIToFPInst : public CastInst {
2897 protected:
2898   /// @brief Clone an identical UIToFPInst
2899   virtual UIToFPInst *clone_impl() const;
2900
2901 public:
2902   /// @brief Constructor with insert-before-instruction semantics
2903   UIToFPInst(
2904     Value *S,                     ///< The value to be converted
2905     const Type *Ty,               ///< The type to convert to
2906     const Twine &NameStr = "", ///< A name for the new instruction
2907     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2908   );
2909
2910   /// @brief Constructor with insert-at-end-of-block semantics
2911   UIToFPInst(
2912     Value *S,                     ///< The value to be converted
2913     const Type *Ty,               ///< The type to convert to
2914     const Twine &NameStr,   ///< A name for the new instruction
2915     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2916   );
2917
2918   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2919   static inline bool classof(const UIToFPInst *) { return true; }
2920   static inline bool classof(const Instruction *I) {
2921     return I->getOpcode() == UIToFP;
2922   }
2923   static inline bool classof(const Value *V) {
2924     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2925   }
2926 };
2927
2928 //===----------------------------------------------------------------------===//
2929 //                                 SIToFPInst Class
2930 //===----------------------------------------------------------------------===//
2931
2932 /// @brief This class represents a cast from signed integer to floating point.
2933 class SIToFPInst : public CastInst {
2934 protected:
2935   /// @brief Clone an identical SIToFPInst
2936   virtual SIToFPInst *clone_impl() const;
2937
2938 public:
2939   /// @brief Constructor with insert-before-instruction semantics
2940   SIToFPInst(
2941     Value *S,                     ///< The value to be converted
2942     const Type *Ty,               ///< The type to convert to
2943     const Twine &NameStr = "", ///< A name for the new instruction
2944     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2945   );
2946
2947   /// @brief Constructor with insert-at-end-of-block semantics
2948   SIToFPInst(
2949     Value *S,                     ///< The value to be converted
2950     const Type *Ty,               ///< The type to convert to
2951     const Twine &NameStr,   ///< A name for the new instruction
2952     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2953   );
2954
2955   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2956   static inline bool classof(const SIToFPInst *) { return true; }
2957   static inline bool classof(const Instruction *I) {
2958     return I->getOpcode() == SIToFP;
2959   }
2960   static inline bool classof(const Value *V) {
2961     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2962   }
2963 };
2964
2965 //===----------------------------------------------------------------------===//
2966 //                                 FPToUIInst Class
2967 //===----------------------------------------------------------------------===//
2968
2969 /// @brief This class represents a cast from floating point to unsigned integer
2970 class FPToUIInst  : public CastInst {
2971 protected:
2972   /// @brief Clone an identical FPToUIInst
2973   virtual FPToUIInst *clone_impl() const;
2974
2975 public:
2976   /// @brief Constructor with insert-before-instruction semantics
2977   FPToUIInst(
2978     Value *S,                     ///< The value to be converted
2979     const Type *Ty,               ///< The type to convert to
2980     const Twine &NameStr = "", ///< A name for the new instruction
2981     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2982   );
2983
2984   /// @brief Constructor with insert-at-end-of-block semantics
2985   FPToUIInst(
2986     Value *S,                     ///< The value to be converted
2987     const Type *Ty,               ///< The type to convert to
2988     const Twine &NameStr,   ///< A name for the new instruction
2989     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
2990   );
2991
2992   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2993   static inline bool classof(const FPToUIInst *) { return true; }
2994   static inline bool classof(const Instruction *I) {
2995     return I->getOpcode() == FPToUI;
2996   }
2997   static inline bool classof(const Value *V) {
2998     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2999   }
3000 };
3001
3002 //===----------------------------------------------------------------------===//
3003 //                                 FPToSIInst Class
3004 //===----------------------------------------------------------------------===//
3005
3006 /// @brief This class represents a cast from floating point to signed integer.
3007 class FPToSIInst  : public CastInst {
3008 protected:
3009   /// @brief Clone an identical FPToSIInst
3010   virtual FPToSIInst *clone_impl() const;
3011
3012 public:
3013   /// @brief Constructor with insert-before-instruction semantics
3014   FPToSIInst(
3015     Value *S,                     ///< The value to be converted
3016     const Type *Ty,               ///< The type to convert to
3017     const Twine &NameStr = "", ///< A name for the new instruction
3018     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3019   );
3020
3021   /// @brief Constructor with insert-at-end-of-block semantics
3022   FPToSIInst(
3023     Value *S,                     ///< The value to be converted
3024     const Type *Ty,               ///< The type to convert to
3025     const Twine &NameStr,   ///< A name for the new instruction
3026     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3027   );
3028
3029   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3030   static inline bool classof(const FPToSIInst *) { return true; }
3031   static inline bool classof(const Instruction *I) {
3032     return I->getOpcode() == FPToSI;
3033   }
3034   static inline bool classof(const Value *V) {
3035     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3036   }
3037 };
3038
3039 //===----------------------------------------------------------------------===//
3040 //                                 IntToPtrInst Class
3041 //===----------------------------------------------------------------------===//
3042
3043 /// @brief This class represents a cast from an integer to a pointer.
3044 class IntToPtrInst : public CastInst {
3045 public:
3046   /// @brief Constructor with insert-before-instruction semantics
3047   IntToPtrInst(
3048     Value *S,                     ///< The value to be converted
3049     const Type *Ty,               ///< The type to convert to
3050     const Twine &NameStr = "", ///< A name for the new instruction
3051     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3052   );
3053
3054   /// @brief Constructor with insert-at-end-of-block semantics
3055   IntToPtrInst(
3056     Value *S,                     ///< The value to be converted
3057     const Type *Ty,               ///< The type to convert to
3058     const Twine &NameStr,   ///< A name for the new instruction
3059     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3060   );
3061
3062   /// @brief Clone an identical IntToPtrInst
3063   virtual IntToPtrInst *clone_impl() const;
3064
3065   // Methods for support type inquiry through isa, cast, and dyn_cast:
3066   static inline bool classof(const IntToPtrInst *) { return true; }
3067   static inline bool classof(const Instruction *I) {
3068     return I->getOpcode() == IntToPtr;
3069   }
3070   static inline bool classof(const Value *V) {
3071     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3072   }
3073 };
3074
3075 //===----------------------------------------------------------------------===//
3076 //                                 PtrToIntInst Class
3077 //===----------------------------------------------------------------------===//
3078
3079 /// @brief This class represents a cast from a pointer to an integer
3080 class PtrToIntInst : public CastInst {
3081 protected:
3082   /// @brief Clone an identical PtrToIntInst
3083   virtual PtrToIntInst *clone_impl() const;
3084
3085 public:
3086   /// @brief Constructor with insert-before-instruction semantics
3087   PtrToIntInst(
3088     Value *S,                     ///< The value to be converted
3089     const Type *Ty,               ///< The type to convert to
3090     const Twine &NameStr = "", ///< A name for the new instruction
3091     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3092   );
3093
3094   /// @brief Constructor with insert-at-end-of-block semantics
3095   PtrToIntInst(
3096     Value *S,                     ///< The value to be converted
3097     const Type *Ty,               ///< The type to convert to
3098     const Twine &NameStr,   ///< A name for the new instruction
3099     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3100   );
3101
3102   // Methods for support type inquiry through isa, cast, and dyn_cast:
3103   static inline bool classof(const PtrToIntInst *) { return true; }
3104   static inline bool classof(const Instruction *I) {
3105     return I->getOpcode() == PtrToInt;
3106   }
3107   static inline bool classof(const Value *V) {
3108     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3109   }
3110 };
3111
3112 //===----------------------------------------------------------------------===//
3113 //                             BitCastInst Class
3114 //===----------------------------------------------------------------------===//
3115
3116 /// @brief This class represents a no-op cast from one type to another.
3117 class BitCastInst : public CastInst {
3118 protected:
3119   /// @brief Clone an identical BitCastInst
3120   virtual BitCastInst *clone_impl() const;
3121
3122 public:
3123   /// @brief Constructor with insert-before-instruction semantics
3124   BitCastInst(
3125     Value *S,                     ///< The value to be casted
3126     const Type *Ty,               ///< The type to casted to
3127     const Twine &NameStr = "", ///< A name for the new instruction
3128     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3129   );
3130
3131   /// @brief Constructor with insert-at-end-of-block semantics
3132   BitCastInst(
3133     Value *S,                     ///< The value to be casted
3134     const Type *Ty,               ///< The type to casted to
3135     const Twine &NameStr,      ///< A name for the new instruction
3136     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3137   );
3138
3139   // Methods for support type inquiry through isa, cast, and dyn_cast:
3140   static inline bool classof(const BitCastInst *) { return true; }
3141   static inline bool classof(const Instruction *I) {
3142     return I->getOpcode() == BitCast;
3143   }
3144   static inline bool classof(const Value *V) {
3145     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3146   }
3147 };
3148
3149 } // End llvm namespace
3150
3151 #endif