LLVM API Documentation

Instructions.h

Go to the documentation of this file.
00001 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file exposes the class definitions of all of the subclasses of the
00011 // Instruction class.  This is meant to be an easy way to get access to all
00012 // instruction subclasses.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_INSTRUCTIONS_H
00017 #define LLVM_INSTRUCTIONS_H
00018 
00019 #include "llvm/InstrTypes.h"
00020 #include "llvm/DerivedTypes.h"
00021 #include "llvm/Attributes.h"
00022 #include "llvm/BasicBlock.h"
00023 #include "llvm/ADT/SmallVector.h"
00024 #include <iterator>
00025 
00026 namespace llvm {
00027 
00028 class ConstantInt;
00029 class ConstantRange;
00030 class APInt;
00031 
00032 //===----------------------------------------------------------------------===//
00033 //                             AllocationInst Class
00034 //===----------------------------------------------------------------------===//
00035 
00036 /// AllocationInst - This class is the common base class of MallocInst and
00037 /// AllocaInst.
00038 ///
00039 class AllocationInst : public UnaryInstruction {
00040 protected:
00041   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
00042                  const std::string &Name = "", Instruction *InsertBefore = 0);
00043   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
00044                  const std::string &Name, BasicBlock *InsertAtEnd);
00045 public:
00046   // Out of line virtual method, so the vtable, etc. has a home.
00047   virtual ~AllocationInst();
00048 
00049   /// isArrayAllocation - Return true if there is an allocation size parameter
00050   /// to the allocation instruction that is not 1.
00051   ///
00052   bool isArrayAllocation() const;
00053 
00054   /// getArraySize - Get the number of element allocated, for a simple
00055   /// allocation of a single element, this will return a constant 1 value.
00056   ///
00057   const Value *getArraySize() const { return getOperand(0); }
00058   Value *getArraySize() { return getOperand(0); }
00059 
00060   /// getType - Overload to return most specific pointer type
00061   ///
00062   const PointerType *getType() const {
00063     return reinterpret_cast<const PointerType*>(Instruction::getType());
00064   }
00065 
00066   /// getAllocatedType - Return the type that is being allocated by the
00067   /// instruction.
00068   ///
00069   const Type *getAllocatedType() const;
00070 
00071   /// getAlignment - Return the alignment of the memory that is being allocated
00072   /// by the instruction.
00073   ///
00074   unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
00075   void setAlignment(unsigned Align);
00076 
00077   virtual Instruction *clone() const = 0;
00078 
00079   // Methods for support type inquiry through isa, cast, and dyn_cast:
00080   static inline bool classof(const AllocationInst *) { return true; }
00081   static inline bool classof(const Instruction *I) {
00082     return I->getOpcode() == Instruction::Alloca ||
00083            I->getOpcode() == Instruction::Malloc;
00084   }
00085   static inline bool classof(const Value *V) {
00086     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00087   }
00088 };
00089 
00090 
00091 //===----------------------------------------------------------------------===//
00092 //                                MallocInst Class
00093 //===----------------------------------------------------------------------===//
00094 
00095 /// MallocInst - an instruction to allocated memory on the heap
00096 ///
00097 class MallocInst : public AllocationInst {
00098   MallocInst(const MallocInst &MI);
00099 public:
00100   explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
00101                       const std::string &NameStr = "",
00102                       Instruction *InsertBefore = 0)
00103     : AllocationInst(Ty, ArraySize, Malloc, 0, NameStr, InsertBefore) {}
00104   MallocInst(const Type *Ty, Value *ArraySize, const std::string &NameStr,
00105              BasicBlock *InsertAtEnd)
00106     : AllocationInst(Ty, ArraySize, Malloc, 0, NameStr, InsertAtEnd) {}
00107 
00108   MallocInst(const Type *Ty, const std::string &NameStr,
00109              Instruction *InsertBefore = 0)
00110     : AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertBefore) {}
00111   MallocInst(const Type *Ty, const std::string &NameStr, BasicBlock *InsertAtEnd)
00112     : AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertAtEnd) {}
00113 
00114   MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
00115              const std::string &NameStr, BasicBlock *InsertAtEnd)
00116     : AllocationInst(Ty, ArraySize, Malloc, Align, NameStr, InsertAtEnd) {}
00117   MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
00118                       const std::string &NameStr = "",
00119                       Instruction *InsertBefore = 0)
00120     : AllocationInst(Ty, ArraySize, Malloc, Align, NameStr, InsertBefore) {}
00121 
00122   virtual MallocInst *clone() const;
00123 
00124   // Methods for support type inquiry through isa, cast, and dyn_cast:
00125   static inline bool classof(const MallocInst *) { return true; }
00126   static inline bool classof(const Instruction *I) {
00127     return (I->getOpcode() == Instruction::Malloc);
00128   }
00129   static inline bool classof(const Value *V) {
00130     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00131   }
00132 };
00133 
00134 
00135 //===----------------------------------------------------------------------===//
00136 //                                AllocaInst Class
00137 //===----------------------------------------------------------------------===//
00138 
00139 /// AllocaInst - an instruction to allocate memory on the stack
00140 ///
00141 class AllocaInst : public AllocationInst {
00142   AllocaInst(const AllocaInst &);
00143 public:
00144   explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
00145                       const std::string &NameStr = "",
00146                       Instruction *InsertBefore = 0)
00147     : AllocationInst(Ty, ArraySize, Alloca, 0, NameStr, InsertBefore) {}
00148   AllocaInst(const Type *Ty, Value *ArraySize, const std::string &NameStr,
00149              BasicBlock *InsertAtEnd)
00150     : AllocationInst(Ty, ArraySize, Alloca, 0, NameStr, InsertAtEnd) {}
00151 
00152   AllocaInst(const Type *Ty, const std::string &NameStr,
00153              Instruction *InsertBefore = 0)
00154     : AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertBefore) {}
00155   AllocaInst(const Type *Ty, const std::string &NameStr,
00156              BasicBlock *InsertAtEnd)
00157     : AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertAtEnd) {}
00158 
00159   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
00160              const std::string &NameStr = "", Instruction *InsertBefore = 0)
00161     : AllocationInst(Ty, ArraySize, Alloca, Align, NameStr, InsertBefore) {}
00162   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
00163              const std::string &NameStr, BasicBlock *InsertAtEnd)
00164     : AllocationInst(Ty, ArraySize, Alloca, Align, NameStr, InsertAtEnd) {}
00165 
00166   virtual AllocaInst *clone() const;
00167   
00168   /// isStaticAlloca - Return true if this alloca is in the entry block of the
00169   /// function and is a constant size.  If so, the code generator will fold it
00170   /// into the prolog/epilog code, so it is basically free.
00171   bool isStaticAlloca() const;
00172 
00173   // Methods for support type inquiry through isa, cast, and dyn_cast:
00174   static inline bool classof(const AllocaInst *) { return true; }
00175   static inline bool classof(const Instruction *I) {
00176     return (I->getOpcode() == Instruction::Alloca);
00177   }
00178   static inline bool classof(const Value *V) {
00179     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00180   }
00181 };
00182 
00183 
00184 //===----------------------------------------------------------------------===//
00185 //                                 FreeInst Class
00186 //===----------------------------------------------------------------------===//
00187 
00188 /// FreeInst - an instruction to deallocate memory
00189 ///
00190 class FreeInst : public UnaryInstruction {
00191   void AssertOK();
00192 public:
00193   explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
00194   FreeInst(Value *Ptr, BasicBlock *InsertAfter);
00195 
00196   virtual FreeInst *clone() const;
00197   
00198   // Accessor methods for consistency with other memory operations
00199   Value *getPointerOperand() { return getOperand(0); }
00200   const Value *getPointerOperand() const { return getOperand(0); }
00201 
00202   // Methods for support type inquiry through isa, cast, and dyn_cast:
00203   static inline bool classof(const FreeInst *) { return true; }
00204   static inline bool classof(const Instruction *I) {
00205     return (I->getOpcode() == Instruction::Free);
00206   }
00207   static inline bool classof(const Value *V) {
00208     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00209   }
00210 };
00211 
00212 
00213 //===----------------------------------------------------------------------===//
00214 //                                LoadInst Class
00215 //===----------------------------------------------------------------------===//
00216 
00217 /// LoadInst - an instruction for reading from memory.  This uses the
00218 /// SubclassData field in Value to store whether or not the load is volatile.
00219 ///
00220 class LoadInst : public UnaryInstruction {
00221 
00222   LoadInst(const LoadInst &LI)
00223     : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
00224     setVolatile(LI.isVolatile());
00225     setAlignment(LI.getAlignment());
00226 
00227 #ifndef NDEBUG
00228     AssertOK();
00229 #endif
00230   }
00231   void AssertOK();
00232 public:
00233   LoadInst(Value *Ptr, const std::string &NameStr, Instruction *InsertBefore);
00234   LoadInst(Value *Ptr, const std::string &NameStr, BasicBlock *InsertAtEnd);
00235   LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile = false, 
00236            Instruction *InsertBefore = 0);
00237   LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile,
00238            unsigned Align, Instruction *InsertBefore = 0);
00239   LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile,
00240            BasicBlock *InsertAtEnd);
00241   LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile,
00242            unsigned Align, BasicBlock *InsertAtEnd);
00243 
00244   LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
00245   LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
00246   explicit LoadInst(Value *Ptr, const char *NameStr = 0,
00247                     bool isVolatile = false,  Instruction *InsertBefore = 0);
00248   LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
00249            BasicBlock *InsertAtEnd);
00250   
00251   /// isVolatile - Return true if this is a load from a volatile memory
00252   /// location.
00253   ///
00254   bool isVolatile() const { return SubclassData & 1; }
00255 
00256   /// setVolatile - Specify whether this is a volatile load or not.
00257   ///
00258   void setVolatile(bool V) { 
00259     SubclassData = (SubclassData & ~1) | (V ? 1 : 0); 
00260   }
00261 
00262   virtual LoadInst *clone() const;
00263 
00264   /// getAlignment - Return the alignment of the access that is being performed
00265   ///
00266   unsigned getAlignment() const {
00267     return (1 << (SubclassData>>1)) >> 1;
00268   }
00269   
00270   void setAlignment(unsigned Align);
00271 
00272   Value *getPointerOperand() { return getOperand(0); }
00273   const Value *getPointerOperand() const { return getOperand(0); }
00274   static unsigned getPointerOperandIndex() { return 0U; }
00275 
00276   // Methods for support type inquiry through isa, cast, and dyn_cast:
00277   static inline bool classof(const LoadInst *) { return true; }
00278   static inline bool classof(const Instruction *I) {
00279     return I->getOpcode() == Instruction::Load;
00280   }
00281   static inline bool classof(const Value *V) {
00282     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00283   }
00284 };
00285 
00286 
00287 //===----------------------------------------------------------------------===//
00288 //                                StoreInst Class
00289 //===----------------------------------------------------------------------===//
00290 
00291 /// StoreInst - an instruction for storing to memory
00292 ///
00293 class StoreInst : public Instruction {
00294   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
00295   
00296   StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store,
00297                                                &Op<0>(), 2) {
00298     Op<0>() = SI.Op<0>();
00299     Op<1>() = SI.Op<1>();
00300     setVolatile(SI.isVolatile());
00301     setAlignment(SI.getAlignment());
00302     
00303 #ifndef NDEBUG
00304     AssertOK();
00305 #endif
00306   }
00307   void AssertOK();
00308 public:
00309   // allocate space for exactly two operands
00310   void *operator new(size_t s) {
00311     return User::operator new(s, 2);
00312   }
00313   StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
00314   StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
00315   StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
00316             Instruction *InsertBefore = 0);
00317   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
00318             unsigned Align, Instruction *InsertBefore = 0);
00319   StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
00320   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
00321             unsigned Align, BasicBlock *InsertAtEnd);
00322 
00323 
00324   /// isVolatile - Return true if this is a load from a volatile memory
00325   /// location.
00326   ///
00327   bool isVolatile() const { return SubclassData & 1; }
00328 
00329   /// setVolatile - Specify whether this is a volatile load or not.
00330   ///
00331   void setVolatile(bool V) { 
00332     SubclassData = (SubclassData & ~1) | (V ? 1 : 0); 
00333   }
00334 
00335   /// Transparently provide more efficient getOperand methods.
00336   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00337 
00338   /// getAlignment - Return the alignment of the access that is being performed
00339   ///
00340   unsigned getAlignment() const {
00341     return (1 << (SubclassData>>1)) >> 1;
00342   }
00343   
00344   void setAlignment(unsigned Align);
00345   
00346   virtual StoreInst *clone() const;
00347 
00348   Value *getPointerOperand() { return getOperand(1); }
00349   const Value *getPointerOperand() const { return getOperand(1); }
00350   static unsigned getPointerOperandIndex() { return 1U; }
00351 
00352   // Methods for support type inquiry through isa, cast, and dyn_cast:
00353   static inline bool classof(const StoreInst *) { return true; }
00354   static inline bool classof(const Instruction *I) {
00355     return I->getOpcode() == Instruction::Store;
00356   }
00357   static inline bool classof(const Value *V) {
00358     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00359   }
00360 };
00361 
00362 template <>
00363 struct OperandTraits<StoreInst> : FixedNumOperandTraits<2> {
00364 };
00365 
00366 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
00367 
00368 //===----------------------------------------------------------------------===//
00369 //                             GetElementPtrInst Class
00370 //===----------------------------------------------------------------------===//
00371 
00372 // checkType - Simple wrapper function to give a better assertion failure
00373 // message on bad indexes for a gep instruction.
00374 //
00375 static inline const Type *checkType(const Type *Ty) {
00376   assert(Ty && "Invalid GetElementPtrInst indices for type!");
00377   return Ty;
00378 }
00379 
00380 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
00381 /// access elements of arrays and structs
00382 ///
00383 class GetElementPtrInst : public Instruction {
00384   GetElementPtrInst(const GetElementPtrInst &GEPI);
00385   void init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
00386             const std::string &NameStr);
00387   void init(Value *Ptr, Value *Idx, const std::string &NameStr);
00388 
00389   template<typename InputIterator>
00390   void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
00391             const std::string &NameStr,
00392             // This argument ensures that we have an iterator we can
00393             // do arithmetic on in constant time
00394             std::random_access_iterator_tag) {
00395     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
00396     
00397     if (NumIdx > 0) {
00398       // This requires that the iterator points to contiguous memory.
00399       init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
00400                                      // we have to build an array here
00401     }
00402     else {
00403       init(Ptr, 0, NumIdx, NameStr);
00404     }
00405   }
00406 
00407   /// getIndexedType - Returns the type of the element that would be loaded with
00408   /// a load instruction with the specified parameters.
00409   ///
00410   /// Null is returned if the indices are invalid for the specified
00411   /// pointer type.
00412   ///
00413   template<typename InputIterator>
00414   static const Type *getIndexedType(const Type *Ptr,
00415                                     InputIterator IdxBegin, 
00416                                     InputIterator IdxEnd,
00417                                     // This argument ensures that we
00418                                     // have an iterator we can do
00419                                     // arithmetic on in constant time
00420                                     std::random_access_iterator_tag) {
00421     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
00422 
00423     if (NumIdx > 0)
00424       // This requires that the iterator points to contiguous memory.
00425       return getIndexedType(Ptr, &*IdxBegin, NumIdx);
00426     else
00427       return getIndexedType(Ptr, (Value *const*)0, NumIdx);
00428   }
00429 
00430   /// Constructors - Create a getelementptr instruction with a base pointer an
00431   /// list of indices.  The first ctor can optionally insert before an existing
00432   /// instruction, the second appends the new instruction to the specified
00433   /// BasicBlock.
00434   template<typename InputIterator>
00435   inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, 
00436                            InputIterator IdxEnd,
00437                            unsigned Values,
00438                            const std::string &NameStr,
00439                            Instruction *InsertBefore);
00440   template<typename InputIterator>
00441   inline GetElementPtrInst(Value *Ptr,
00442                            InputIterator IdxBegin, InputIterator IdxEnd,
00443                            unsigned Values,
00444                            const std::string &NameStr, BasicBlock *InsertAtEnd);
00445 
00446   /// Constructors - These two constructors are convenience methods because one
00447   /// and two index getelementptr instructions are so common.
00448   GetElementPtrInst(Value *Ptr, Value *Idx, const std::string &NameStr = "",
00449                     Instruction *InsertBefore = 0);
00450   GetElementPtrInst(Value *Ptr, Value *Idx,
00451                     const std::string &NameStr, BasicBlock *InsertAtEnd);
00452 public:
00453   template<typename InputIterator>
00454   static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, 
00455                                    InputIterator IdxEnd,
00456                                    const std::string &NameStr = "",
00457                                    Instruction *InsertBefore = 0) {
00458     typename std::iterator_traits<InputIterator>::difference_type Values = 
00459       1 + std::distance(IdxBegin, IdxEnd);
00460     return new(Values)
00461       GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
00462   }
00463   template<typename InputIterator>
00464   static GetElementPtrInst *Create(Value *Ptr,
00465                                    InputIterator IdxBegin, InputIterator IdxEnd,
00466                                    const std::string &NameStr,
00467                                    BasicBlock *InsertAtEnd) {
00468     typename std::iterator_traits<InputIterator>::difference_type Values = 
00469       1 + std::distance(IdxBegin, IdxEnd);
00470     return new(Values)
00471       GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
00472   }
00473 
00474   /// Constructors - These two creators are convenience methods because one
00475   /// index getelementptr instructions are so common.
00476   static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
00477                                    const std::string &NameStr = "",
00478                                    Instruction *InsertBefore = 0) {
00479     return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore);
00480   }
00481   static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
00482                                    const std::string &NameStr,
00483                                    BasicBlock *InsertAtEnd) {
00484     return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
00485   }
00486 
00487   virtual GetElementPtrInst *clone() const;
00488 
00489   /// Transparently provide more efficient getOperand methods.
00490   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00491 
00492   // getType - Overload to return most specific pointer type...
00493   const PointerType *getType() const {
00494     return reinterpret_cast<const PointerType*>(Instruction::getType());
00495   }
00496 
00497   /// getIndexedType - Returns the type of the element that would be loaded with
00498   /// a load instruction with the specified parameters.
00499   ///
00500   /// Null is returned if the indices are invalid for the specified
00501   /// pointer type.
00502   ///
00503   template<typename InputIterator>
00504   static const Type *getIndexedType(const Type *Ptr,
00505                                     InputIterator IdxBegin,
00506                                     InputIterator IdxEnd) {
00507     return getIndexedType(Ptr, IdxBegin, IdxEnd,
00508                           typename std::iterator_traits<InputIterator>::
00509                           iterator_category());
00510   }  
00511 
00512   static const Type *getIndexedType(const Type *Ptr,
00513                                     Value* const *Idx, unsigned NumIdx);
00514 
00515   static const Type *getIndexedType(const Type *Ptr,
00516                                     uint64_t const *Idx, unsigned NumIdx);
00517 
00518   static const Type *getIndexedType(const Type *Ptr, Value *Idx);
00519 
00520   inline op_iterator       idx_begin()       { return op_begin()+1; }
00521   inline const_op_iterator idx_begin() const { return op_begin()+1; }
00522   inline op_iterator       idx_end()         { return op_end(); }
00523   inline const_op_iterator idx_end()   const { return op_end(); }
00524 
00525   Value *getPointerOperand() {
00526     return getOperand(0);
00527   }
00528   const Value *getPointerOperand() const {
00529     return getOperand(0);
00530   }
00531   static unsigned getPointerOperandIndex() {
00532     return 0U;                      // get index for modifying correct operand
00533   }
00534   
00535   /// getPointerOperandType - Method to return the pointer operand as a
00536   /// PointerType.
00537   const PointerType *getPointerOperandType() const {
00538     return reinterpret_cast<const PointerType*>(getPointerOperand()->getType());
00539   }
00540   
00541 
00542   unsigned getNumIndices() const {  // Note: always non-negative
00543     return getNumOperands() - 1;
00544   }
00545 
00546   bool hasIndices() const {
00547     return getNumOperands() > 1;
00548   }
00549   
00550   /// hasAllZeroIndices - Return true if all of the indices of this GEP are
00551   /// zeros.  If so, the result pointer and the first operand have the same
00552   /// value, just potentially different types.
00553   bool hasAllZeroIndices() const;
00554   
00555   /// hasAllConstantIndices - Return true if all of the indices of this GEP are
00556   /// constant integers.  If so, the result pointer and the first operand have
00557   /// a constant offset between them.
00558   bool hasAllConstantIndices() const;
00559   
00560 
00561   // Methods for support type inquiry through isa, cast, and dyn_cast:
00562   static inline bool classof(const GetElementPtrInst *) { return true; }
00563   static inline bool classof(const Instruction *I) {
00564     return (I->getOpcode() == Instruction::GetElementPtr);
00565   }
00566   static inline bool classof(const Value *V) {
00567     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00568   }
00569 };
00570 
00571 template <>
00572 struct OperandTraits<GetElementPtrInst> : VariadicOperandTraits<1> {
00573 };
00574 
00575 template<typename InputIterator>
00576 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
00577                                      InputIterator IdxBegin, 
00578                                      InputIterator IdxEnd,
00579                                      unsigned Values,
00580                                      const std::string &NameStr,
00581                                      Instruction *InsertBefore)
00582   : Instruction(PointerType::get(checkType(
00583                                    getIndexedType(Ptr->getType(),
00584                                                   IdxBegin, IdxEnd)),
00585                                  cast<PointerType>(Ptr->getType())
00586                                    ->getAddressSpace()),
00587                 GetElementPtr,
00588                 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
00589                 Values, InsertBefore) {
00590   init(Ptr, IdxBegin, IdxEnd, NameStr,
00591        typename std::iterator_traits<InputIterator>::iterator_category());
00592 }
00593 template<typename InputIterator>
00594 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
00595                                      InputIterator IdxBegin,
00596                                      InputIterator IdxEnd,
00597                                      unsigned Values,
00598                                      const std::string &NameStr,
00599                                      BasicBlock *InsertAtEnd)
00600   : Instruction(PointerType::get(checkType(
00601                                    getIndexedType(Ptr->getType(),
00602                                                   IdxBegin, IdxEnd)),
00603                                  cast<PointerType>(Ptr->getType())
00604                                    ->getAddressSpace()),
00605                 GetElementPtr,
00606                 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
00607                 Values, InsertAtEnd) {
00608   init(Ptr, IdxBegin, IdxEnd, NameStr,
00609        typename std::iterator_traits<InputIterator>::iterator_category());
00610 }
00611 
00612 
00613 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
00614 
00615 
00616 //===----------------------------------------------------------------------===//
00617 //                               ICmpInst Class
00618 //===----------------------------------------------------------------------===//
00619 
00620 /// This instruction compares its operands according to the predicate given
00621 /// to the constructor. It only operates on integers or pointers. The operands
00622 /// must be identical types.
00623 /// @brief Represent an integer comparison operator.
00624 class ICmpInst: public CmpInst {
00625 public:
00626   /// @brief Constructor with insert-before-instruction semantics.
00627   ICmpInst(
00628     Predicate pred,  ///< The predicate to use for the comparison
00629     Value *LHS,      ///< The left-hand-side of the expression
00630     Value *RHS,      ///< The right-hand-side of the expression
00631     const std::string &NameStr = "",  ///< Name of the instruction
00632     Instruction *InsertBefore = 0  ///< Where to insert
00633   ) : CmpInst(makeCmpResultType(LHS->getType()),
00634               Instruction::ICmp, pred, LHS, RHS, NameStr,
00635               InsertBefore) {
00636     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
00637            pred <= CmpInst::LAST_ICMP_PREDICATE &&
00638            "Invalid ICmp predicate value");
00639     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
00640           "Both operands to ICmp instruction are not of the same type!");
00641     // Check that the operands are the right type
00642     assert((getOperand(0)->getType()->isIntOrIntVector() || 
00643             isa<PointerType>(getOperand(0)->getType())) &&
00644            "Invalid operand types for ICmp instruction");
00645   }
00646 
00647   /// @brief Constructor with insert-at-block-end semantics.
00648   ICmpInst(
00649     Predicate pred, ///< The predicate to use for the comparison
00650     Value *LHS,     ///< The left-hand-side of the expression
00651     Value *RHS,     ///< The right-hand-side of the expression
00652     const std::string &NameStr,  ///< Name of the instruction
00653     BasicBlock *InsertAtEnd   ///< Block to insert into.
00654   ) : CmpInst(makeCmpResultType(LHS->getType()),
00655               Instruction::ICmp, pred, LHS, RHS, NameStr,
00656               InsertAtEnd) {
00657     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
00658            pred <= CmpInst::LAST_ICMP_PREDICATE &&
00659            "Invalid ICmp predicate value");
00660     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
00661           "Both operands to ICmp instruction are not of the same type!");
00662     // Check that the operands are the right type
00663     assert((getOperand(0)->getType()->isIntOrIntVector() || 
00664             isa<PointerType>(getOperand(0)->getType())) &&
00665            "Invalid operand types for ICmp instruction");
00666   }
00667 
00668   /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
00669   /// @returns the predicate that would be the result if the operand were
00670   /// regarded as signed.
00671   /// @brief Return the signed version of the predicate
00672   Predicate getSignedPredicate() const {
00673     return getSignedPredicate(getPredicate());
00674   }
00675 
00676   /// This is a static version that you can use without an instruction.
00677   /// @brief Return the signed version of the predicate.
00678   static Predicate getSignedPredicate(Predicate pred);
00679 
00680   /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
00681   /// @returns the predicate that would be the result if the operand were
00682   /// regarded as unsigned.
00683   /// @brief Return the unsigned version of the predicate
00684   Predicate getUnsignedPredicate() const {
00685     return getUnsignedPredicate(getPredicate());
00686   }
00687 
00688   /// This is a static version that you can use without an instruction.
00689   /// @brief Return the unsigned version of the predicate.
00690   static Predicate getUnsignedPredicate(Predicate pred);
00691 
00692   /// isEquality - Return true if this predicate is either EQ or NE.  This also
00693   /// tests for commutativity.
00694   static bool isEquality(Predicate P) {
00695     return P == ICMP_EQ || P == ICMP_NE;
00696   }
00697   
00698   /// isEquality - Return true if this predicate is either EQ or NE.  This also
00699   /// tests for commutativity.
00700   bool isEquality() const {
00701     return isEquality(getPredicate());
00702   }
00703 
00704   /// @returns true if the predicate of this ICmpInst is commutative
00705   /// @brief Determine if this relation is commutative.
00706   bool isCommutative() const { return isEquality(); }
00707 
00708   /// isRelational - Return true if the predicate is relational (not EQ or NE). 
00709   ///
00710   bool isRelational() const {
00711     return !isEquality();
00712   }
00713 
00714   /// isRelational - Return true if the predicate is relational (not EQ or NE). 
00715   ///
00716   static bool isRelational(Predicate P) {
00717     return !isEquality(P);
00718   }
00719   
00720   /// @returns true if the predicate of this ICmpInst is signed, false otherwise
00721   /// @brief Determine if this instruction's predicate is signed.
00722   bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
00723 
00724   /// @returns true if the predicate provided is signed, false otherwise
00725   /// @brief Determine if the predicate is signed.
00726   static bool isSignedPredicate(Predicate pred);
00727 
00728   /// @returns true if the specified compare predicate is
00729   /// true when both operands are equal...
00730   /// @brief Determine if the icmp is true when both operands are equal
00731   static bool isTrueWhenEqual(ICmpInst::Predicate pred) {
00732     return pred == ICmpInst::ICMP_EQ  || pred == ICmpInst::ICMP_UGE ||
00733            pred == ICmpInst::ICMP_SGE || pred == ICmpInst::ICMP_ULE ||
00734            pred == ICmpInst::ICMP_SLE;
00735   }
00736 
00737   /// @returns true if the specified compare instruction is
00738   /// true when both operands are equal...
00739   /// @brief Determine if the ICmpInst returns true when both operands are equal
00740   bool isTrueWhenEqual() {
00741     return isTrueWhenEqual(getPredicate());
00742   }
00743 
00744   /// Initialize a set of values that all satisfy the predicate with C. 
00745   /// @brief Make a ConstantRange for a relation with a constant value.
00746   static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
00747 
00748   /// Exchange the two operands to this instruction in such a way that it does
00749   /// not modify the semantics of the instruction. The predicate value may be
00750   /// changed to retain the same result if the predicate is order dependent
00751   /// (e.g. ult). 
00752   /// @brief Swap operands and adjust predicate.
00753   void swapOperands() {
00754     SubclassData = getSwappedPredicate();
00755     Op<0>().swap(Op<1>());
00756   }
00757 
00758   virtual ICmpInst *clone() const;
00759 
00760   // Methods for support type inquiry through isa, cast, and dyn_cast:
00761   static inline bool classof(const ICmpInst *) { return true; }
00762   static inline bool classof(const Instruction *I) {
00763     return I->getOpcode() == Instruction::ICmp;
00764   }
00765   static inline bool classof(const Value *V) {
00766     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00767   }
00768 
00769 };
00770 
00771 //===----------------------------------------------------------------------===//
00772 //                               FCmpInst Class
00773 //===----------------------------------------------------------------------===//
00774 
00775 /// This instruction compares its operands according to the predicate given
00776 /// to the constructor. It only operates on floating point values or packed     
00777 /// vectors of floating point values. The operands must be identical types.
00778 /// @brief Represents a floating point comparison operator.
00779 class FCmpInst: public CmpInst {
00780 public:
00781   /// @brief Constructor with insert-before-instruction semantics.
00782   FCmpInst(
00783     Predicate pred,  ///< The predicate to use for the comparison
00784     Value *LHS,      ///< The left-hand-side of the expression
00785     Value *RHS,      ///< The right-hand-side of the expression
00786     const std::string &NameStr = "",  ///< Name of the instruction
00787     Instruction *InsertBefore = 0  ///< Where to insert
00788   ) : CmpInst(makeCmpResultType(LHS->getType()),
00789               Instruction::FCmp, pred, LHS, RHS, NameStr,
00790               InsertBefore) {
00791     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
00792            "Invalid FCmp predicate value");
00793     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
00794            "Both operands to FCmp instruction are not of the same type!");
00795     // Check that the operands are the right type
00796     assert(getOperand(0)->getType()->isFPOrFPVector() &&
00797            "Invalid operand types for FCmp instruction");
00798   }
00799 
00800   /// @brief Constructor with insert-at-block-end semantics.
00801   FCmpInst(
00802     Predicate pred, ///< The predicate to use for the comparison
00803     Value *LHS,     ///< The left-hand-side of the expression
00804     Value *RHS,     ///< The right-hand-side of the expression
00805     const std::string &NameStr,  ///< Name of the instruction
00806     BasicBlock *InsertAtEnd   ///< Block to insert into.
00807   ) : CmpInst(makeCmpResultType(LHS->getType()),
00808               Instruction::FCmp, pred, LHS, RHS, NameStr,
00809               InsertAtEnd) {
00810     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
00811            "Invalid FCmp predicate value");
00812     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
00813            "Both operands to FCmp instruction are not of the same type!");
00814     // Check that the operands are the right type
00815     assert(getOperand(0)->getType()->isFPOrFPVector() &&
00816            "Invalid operand types for FCmp instruction");
00817   }
00818 
00819   /// @returns true if the predicate of this instruction is EQ or NE.
00820   /// @brief Determine if this is an equality predicate.
00821   bool isEquality() const {
00822     return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
00823            SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
00824   }
00825 
00826   /// @returns true if the predicate of this instruction is commutative.
00827   /// @brief Determine if this is a commutative predicate.
00828   bool isCommutative() const {
00829     return isEquality() ||
00830            SubclassData == FCMP_FALSE ||
00831            SubclassData == FCMP_TRUE ||
00832            SubclassData == FCMP_ORD ||
00833            SubclassData == FCMP_UNO;
00834   }
00835 
00836   /// @returns true if the predicate is relational (not EQ or NE). 
00837   /// @brief Determine if this a relational predicate.
00838   bool isRelational() const { return !isEquality(); }
00839 
00840   /// Exchange the two operands to this instruction in such a way that it does
00841   /// not modify the semantics of the instruction. The predicate value may be
00842   /// changed to retain the same result if the predicate is order dependent
00843   /// (e.g. ult). 
00844   /// @brief Swap operands and adjust predicate.
00845   void swapOperands() {
00846     SubclassData = getSwappedPredicate();
00847     Op<0>().swap(Op<1>());
00848   }
00849 
00850   virtual FCmpInst *clone() const;
00851 
00852   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
00853   static inline bool classof(const FCmpInst *) { return true; }
00854   static inline bool classof(const Instruction *I) {
00855     return I->getOpcode() == Instruction::FCmp;
00856   }
00857   static inline bool classof(const Value *V) {
00858     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00859   }
00860   
00861 };
00862 
00863 //===----------------------------------------------------------------------===//
00864 //                               VICmpInst Class
00865 //===----------------------------------------------------------------------===//
00866 
00867 /// This instruction compares its operands according to the predicate given
00868 /// to the constructor. It only operates on vectors of integers.
00869 /// The operands must be identical types.
00870 /// @brief Represents a vector integer comparison operator.
00871 class VICmpInst: public CmpInst {
00872 public:
00873   /// @brief Constructor with insert-before-instruction semantics.
00874   VICmpInst(
00875     Predicate pred,  ///< The predicate to use for the comparison
00876     Value *LHS,      ///< The left-hand-side of the expression
00877     Value *RHS,      ///< The right-hand-side of the expression
00878     const std::string &NameStr = "",  ///< Name of the instruction
00879     Instruction *InsertBefore = 0  ///< Where to insert
00880   ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, NameStr,
00881               InsertBefore) {
00882     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
00883            pred <= CmpInst::LAST_ICMP_PREDICATE &&
00884            "Invalid VICmp predicate value");
00885     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
00886           "Both operands to VICmp instruction are not of the same type!");
00887   }
00888 
00889   /// @brief Constructor with insert-at-block-end semantics.
00890   VICmpInst(
00891     Predicate pred, ///< The predicate to use for the comparison
00892     Value *LHS,     ///< The left-hand-side of the expression
00893     Value *RHS,     ///< The right-hand-side of the expression
00894     const std::string &NameStr,  ///< Name of the instruction
00895     BasicBlock *InsertAtEnd   ///< Block to insert into.
00896   ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, NameStr,
00897               InsertAtEnd) {
00898     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
00899            pred <= CmpInst::LAST_ICMP_PREDICATE &&
00900            "Invalid VICmp predicate value");
00901     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
00902           "Both operands to VICmp instruction are not of the same type!");
00903   }
00904   
00905   /// @brief Return the predicate for this instruction.
00906   Predicate getPredicate() const { return Predicate(SubclassData); }
00907 
00908   virtual VICmpInst *clone() const;
00909 
00910   // Methods for support type inquiry through isa, cast, and dyn_cast:
00911   static inline bool classof(const VICmpInst *) { return true; }
00912   static inline bool classof(const Instruction *I) {
00913     return I->getOpcode() == Instruction::VICmp;
00914   }
00915   static inline bool classof(const Value *V) {
00916     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00917   }
00918 };
00919 
00920 //===----------------------------------------------------------------------===//
00921 //                               VFCmpInst Class
00922 //===----------------------------------------------------------------------===//
00923 
00924 /// This instruction compares its operands according to the predicate given
00925 /// to the constructor. It only operates on vectors of floating point values.
00926 /// The operands must be identical types.
00927 /// @brief Represents a vector floating point comparison operator.
00928 class VFCmpInst: public CmpInst {
00929 public:
00930   /// @brief Constructor with insert-before-instruction semantics.
00931   VFCmpInst(
00932     Predicate pred,  ///< The predicate to use for the comparison
00933     Value *LHS,      ///< The left-hand-side of the expression
00934     Value *RHS,      ///< The right-hand-side of the expression
00935     const std::string &NameStr = "",  ///< Name of the instruction
00936     Instruction *InsertBefore = 0  ///< Where to insert
00937   ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
00938               Instruction::VFCmp, pred, LHS, RHS, NameStr, InsertBefore) {
00939     assert(pred <= CmpInst::LAST_FCMP_PREDICATE &&
00940            "Invalid VFCmp predicate value");
00941     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
00942            "Both operands to VFCmp instruction are not of the same type!");
00943   }
00944 
00945   /// @brief Constructor with insert-at-block-end semantics.
00946   VFCmpInst(
00947     Predicate pred, ///< The predicate to use for the comparison
00948     Value *LHS,     ///< The left-hand-side of the expression
00949     Value *RHS,     ///< The right-hand-side of the expression
00950     const std::string &NameStr,  ///< Name of the instruction
00951     BasicBlock *InsertAtEnd   ///< Block to insert into.
00952   ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
00953               Instruction::VFCmp, pred, LHS, RHS, NameStr, InsertAtEnd) {
00954     assert(pred <= CmpInst::LAST_FCMP_PREDICATE &&
00955            "Invalid VFCmp predicate value");
00956     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
00957            "Both operands to VFCmp instruction are not of the same type!");
00958   }
00959 
00960   /// @brief Return the predicate for this instruction.
00961   Predicate getPredicate() const { return Predicate(SubclassData); }
00962 
00963   virtual VFCmpInst *clone() const;
00964 
00965   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
00966   static inline bool classof(const VFCmpInst *) { return true; }
00967   static inline bool classof(const Instruction *I) {
00968     return I->getOpcode() == Instruction::VFCmp;
00969   }
00970   static inline bool classof(const Value *V) {
00971     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00972   }
00973 };
00974 
00975 //===----------------------------------------------------------------------===//
00976 //                                 CallInst Class
00977 //===----------------------------------------------------------------------===//
00978 /// CallInst - This class represents a function call, abstracting a target
00979 /// machine's calling convention.  This class uses low bit of the SubClassData
00980 /// field to indicate whether or not this is a tail call.  The rest of the bits
00981 /// hold the calling convention of the call.
00982 ///
00983 
00984 class CallInst : public Instruction {
00985   AttrListPtr AttributeList; ///< parameter attributes for call
00986   CallInst(const CallInst &CI);
00987   void init(Value *Func, Value* const *Params, unsigned NumParams);
00988   void init(Value *Func, Value *Actual1, Value *Actual2);
00989   void init(Value *Func, Value *Actual);
00990   void init(Value *Func);
00991 
00992   template<typename InputIterator>
00993   void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
00994             const std::string &NameStr,
00995             // This argument ensures that we have an iterator we can
00996             // do arithmetic on in constant time
00997             std::random_access_iterator_tag) {
00998     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
00999     
01000     // This requires that the iterator points to contiguous memory.
01001     init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
01002     setName(NameStr);
01003   }
01004 
01005   /// Construct a CallInst given a range of arguments.  InputIterator
01006   /// must be a random-access iterator pointing to contiguous storage
01007   /// (e.g. a std::vector<>::iterator).  Checks are made for
01008   /// random-accessness but not for contiguous storage as that would
01009   /// incur runtime overhead.
01010   /// @brief Construct a CallInst from a range of arguments
01011   template<typename InputIterator>
01012   CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
01013            const std::string &NameStr, Instruction *InsertBefore);
01014 
01015   /// Construct a CallInst given a range of arguments.  InputIterator
01016   /// must be a random-access iterator pointing to contiguous storage
01017   /// (e.g. a std::vector<>::iterator).  Checks are made for
01018   /// random-accessness but not for contiguous storage as that would
01019   /// incur runtime overhead.
01020   /// @brief Construct a CallInst from a range of arguments
01021   template<typename InputIterator>
01022   inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
01023                   const std::string &NameStr, BasicBlock *InsertAtEnd);
01024 
01025   CallInst(Value *F, Value *Actual, const std::string& NameStr,
01026            Instruction *InsertBefore);
01027   CallInst(Value *F, Value *Actual, const std::string& NameStr,
01028            BasicBlock *InsertAtEnd);
01029   explicit CallInst(Value *F, const std::string &NameStr,
01030                     Instruction *InsertBefore);
01031   CallInst(Value *F, const std::string &NameStr, BasicBlock *InsertAtEnd);
01032 public:
01033   template<typename InputIterator>
01034   static CallInst *Create(Value *Func,
01035                           InputIterator ArgBegin, InputIterator ArgEnd,
01036                           const std::string &NameStr = "",
01037                           Instruction *InsertBefore = 0) {
01038     return new((unsigned)(ArgEnd - ArgBegin + 1))
01039       CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertBefore);
01040   }
01041   template<typename InputIterator>
01042   static CallInst *Create(Value *Func,
01043                           InputIterator ArgBegin, InputIterator ArgEnd,
01044                           const std::string &NameStr, BasicBlock *InsertAtEnd) {
01045     return new((unsigned)(ArgEnd - ArgBegin + 1))
01046       CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertAtEnd);
01047   }
01048   static CallInst *Create(Value *F, Value *Actual,
01049                           const std::string& NameStr = "",
01050                           Instruction *InsertBefore = 0) {
01051     return new(2) CallInst(F, Actual, NameStr, InsertBefore);
01052   }
01053   static CallInst *Create(Value *F, Value *Actual, const std::string& NameStr,
01054                           BasicBlock *InsertAtEnd) {
01055     return new(2) CallInst(F, Actual, NameStr, InsertAtEnd);
01056   }
01057   static CallInst *Create(Value *F, const std::string &NameStr = "",
01058                           Instruction *InsertBefore = 0) {
01059     return new(1) CallInst(F, NameStr, InsertBefore);
01060   }
01061   static CallInst *Create(Value *F, const std::string &NameStr,
01062                           BasicBlock *InsertAtEnd) {
01063     return new(1) CallInst(F, NameStr, InsertAtEnd);
01064   }
01065 
01066   ~CallInst();
01067 
01068   bool isTailCall() const           { return SubclassData & 1; }
01069   void setTailCall(bool isTC = true) {
01070     SubclassData = (SubclassData & ~1) | unsigned(isTC);
01071   }
01072 
01073   virtual CallInst *clone() const;
01074 
01075   /// Provide fast operand accessors
01076   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01077   
01078   /// getCallingConv/setCallingConv - Get or set the calling convention of this
01079   /// function call.
01080   unsigned getCallingConv() const { return SubclassData >> 1; }
01081   void setCallingConv(unsigned CC) {
01082     SubclassData = (SubclassData & 1) | (CC << 1);
01083   }
01084 
01085   /// getAttributes - Return the parameter attributes for this call.
01086   ///
01087   const AttrListPtr &getAttributes() const { return AttributeList; }
01088 
01089   /// setAttributes - Set the parameter attributes for this call.
01090   ///
01091   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
01092   
01093   /// addAttribute - adds the attribute to the list of attributes.
01094   void addAttribute(unsigned i, Attributes attr);
01095 
01096   /// removeAttribute - removes the attribute from the list of attributes.
01097   void removeAttribute(unsigned i, Attributes attr);
01098 
01099   /// @brief Determine whether the call or the callee has the given attribute.
01100   bool paramHasAttr(unsigned i, Attributes attr) const;
01101 
01102   /// @brief Extract the alignment for a call or parameter (0=unknown).
01103   unsigned getParamAlignment(unsigned i) const {
01104     return AttributeList.getParamAlignment(i);
01105   }
01106 
01107   /// @brief Determine if the call does not access memory.
01108   bool doesNotAccessMemory() const {
01109     return paramHasAttr(~0, Attribute::ReadNone);
01110   }
01111   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
01112     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
01113     else removeAttribute(~0, Attribute::ReadNone);
01114   }
01115 
01116   /// @brief Determine if the call does not access or only reads memory.
01117   bool onlyReadsMemory() const {
01118     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
01119   }
01120   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
01121     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
01122     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
01123   }
01124 
01125   /// @brief Determine if the call cannot return.
01126   bool doesNotReturn() const {
01127     return paramHasAttr(~0, Attribute::NoReturn);
01128   }
01129   void setDoesNotReturn(bool DoesNotReturn = true) {
01130     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
01131     else removeAttribute(~0, Attribute::NoReturn);
01132   }
01133 
01134   /// @brief Determine if the call cannot unwind.
01135   bool doesNotThrow() const {
01136     return paramHasAttr(~0, Attribute::NoUnwind);
01137   }
01138   void setDoesNotThrow(bool DoesNotThrow = true) {
01139     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
01140     else removeAttribute(~0, Attribute::NoUnwind);
01141   }
01142 
01143   /// @brief Determine if the call returns a structure through first 
01144   /// pointer argument.
01145   bool hasStructRetAttr() const {
01146     // Be friendly and also check the callee.
01147     return paramHasAttr(1, Attribute::StructRet);
01148   }
01149 
01150   /// @brief Determine if any call argument is an aggregate passed by value.
01151   bool hasByValArgument() const {
01152     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
01153   }
01154 
01155   /// getCalledFunction - Return the function called, or null if this is an
01156   /// indirect function invocation.
01157   ///
01158   Function *getCalledFunction() const {
01159     return dyn_cast<Function>(getOperand(0));
01160   }
01161 
01162   /// getCalledValue - Get a pointer to the function that is invoked by this 
01163   /// instruction
01164   const Value *getCalledValue() const { return getOperand(0); }
01165         Value *getCalledValue()       { return getOperand(0); }
01166 
01167   // Methods for support type inquiry through isa, cast, and dyn_cast:
01168   static inline bool classof(const CallInst *) { return true; }
01169   static inline bool classof(const Instruction *I) {
01170     return I->getOpcode() == Instruction::Call;
01171   }
01172   static inline bool classof(const Value *V) {
01173     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01174   }
01175 };
01176 
01177 template <>
01178 struct OperandTraits<CallInst> : VariadicOperandTraits<1> {
01179 };
01180 
01181 template<typename InputIterator>
01182 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
01183                    const std::string &NameStr, BasicBlock *InsertAtEnd)
01184   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
01185                                    ->getElementType())->getReturnType(),
01186                 Instruction::Call,
01187                 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
01188                 (unsigned)(ArgEnd - ArgBegin + 1), InsertAtEnd) {
01189   init(Func, ArgBegin, ArgEnd, NameStr,
01190        typename std::iterator_traits<InputIterator>::iterator_category());
01191 }
01192 
01193 template<typename InputIterator>
01194 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
01195                    const std::string &NameStr, Instruction *InsertBefore)
01196   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
01197                                    ->getElementType())->getReturnType(),
01198                 Instruction::Call,
01199                 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
01200                 (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) {
01201   init(Func, ArgBegin, ArgEnd, NameStr, 
01202        typename std::iterator_traits<InputIterator>::iterator_category());
01203 }
01204 
01205 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
01206 
01207 //===----------------------------------------------------------------------===//
01208 //                               SelectInst Class
01209 //===----------------------------------------------------------------------===//
01210 
01211 /// SelectInst - This class represents the LLVM 'select' instruction.
01212 ///
01213 class SelectInst : public Instruction {
01214   void init(Value *C, Value *S1, Value *S2) {
01215     assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
01216     Op<0>() = C;
01217     Op<1>() = S1;
01218     Op<2>() = S2;
01219   }
01220 
01221   SelectInst(const SelectInst &SI)
01222     : Instruction(SI.getType(), SI.getOpcode(), &Op<0>(), 3) {
01223     init(SI.Op<0>(), SI.Op<1>(), SI.Op<2>());
01224   }
01225   SelectInst(Value *C, Value *S1, Value *S2, const std::string &NameStr,
01226              Instruction *InsertBefore)
01227     : Instruction(S1->getType(), Instruction::Select,
01228                   &Op<0>(), 3, InsertBefore) {
01229     init(C, S1, S2);
01230     setName(NameStr);
01231   }
01232   SelectInst(Value *C, Value *S1, Value *S2, const std::string &NameStr,
01233              BasicBlock *InsertAtEnd)
01234     : Instruction(S1->getType(), Instruction::Select,
01235                   &Op<0>(), 3, InsertAtEnd) {
01236     init(C, S1, S2);
01237     setName(NameStr);
01238   }
01239 public:
01240   static SelectInst *Create(Value *C, Value *S1, Value *S2,
01241                             const std::string &NameStr = "",
01242                             Instruction *InsertBefore = 0) {
01243     return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
01244   }
01245   static SelectInst *Create(Value *C, Value *S1, Value *S2,
01246                             const std::string &NameStr,
01247                             BasicBlock *InsertAtEnd) {
01248     return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
01249   }
01250 
01251   Value *getCondition() const { return Op<0>(); }
01252   Value *getTrueValue() const { return Op<1>(); }
01253   Value *getFalseValue() const { return Op<2>(); }
01254   
01255   /// areInvalidOperands - Return a string if the specified operands are invalid
01256   /// for a select operation, otherwise return null.
01257   static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
01258 
01259   /// Transparently provide more efficient getOperand methods.
01260   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01261 
01262   OtherOps getOpcode() const {
01263     return static_cast<OtherOps>(Instruction::getOpcode());
01264   }
01265 
01266   virtual SelectInst *clone() const;
01267 
01268   // Methods for support type inquiry through isa, cast, and dyn_cast:
01269   static inline bool classof(const SelectInst *) { return true; }
01270   static inline bool classof(const Instruction *I) {
01271     return I->getOpcode() == Instruction::Select;
01272   }
01273   static inline bool classof(const Value *V) {
01274     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01275   }
01276 };
01277 
01278 template <>
01279 struct OperandTraits<SelectInst> : FixedNumOperandTraits<3> {
01280 };
01281 
01282 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
01283 
01284 //===----------------------------------------------------------------------===//
01285 //                                VAArgInst Class
01286 //===----------------------------------------------------------------------===//
01287 
01288 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
01289 /// an argument of the specified type given a va_list and increments that list
01290 ///
01291 class VAArgInst : public UnaryInstruction {
01292   VAArgInst(const VAArgInst &VAA)
01293     : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
01294 public:
01295   VAArgInst(Value *List, const Type *Ty, const std::string &NameStr = "",
01296              Instruction *InsertBefore = 0)
01297     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
01298     setName(NameStr);
01299   }
01300   VAArgInst(Value *List, const Type *Ty, const std::string &NameStr,
01301             BasicBlock *InsertAtEnd)
01302     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
01303     setName(NameStr);
01304   }
01305 
01306   virtual VAArgInst *clone() const;
01307 
01308   // Methods for support type inquiry through isa, cast, and dyn_cast:
01309   static inline bool classof(const VAArgInst *) { return true; }
01310   static inline bool classof(const Instruction *I) {
01311     return I->getOpcode() == VAArg;
01312   }
01313   static inline bool classof(const Value *V) {
01314     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01315   }
01316 };
01317 
01318 //===----------------------------------------------------------------------===//
01319 //                                ExtractElementInst Class
01320 //===----------------------------------------------------------------------===//
01321 
01322 /// ExtractElementInst - This instruction extracts a single (scalar)
01323 /// element from a VectorType value
01324 ///
01325 class ExtractElementInst : public Instruction {
01326   ExtractElementInst(const ExtractElementInst &EE) :
01327     Instruction(EE.getType(), ExtractElement, &Op<0>(), 2) {
01328     Op<0>() = EE.Op<0>();
01329     Op<1>() = EE.Op<1>();
01330   }
01331 
01332 public:
01333   // allocate space for exactly two operands
01334   void *operator new(size_t s) {
01335     return User::operator new(s, 2); // FIXME: "unsigned Idx" forms of ctor?
01336   }
01337   ExtractElementInst(Value *Vec, Value *Idx, const std::string &NameStr = "",
01338                      Instruction *InsertBefore = 0);
01339   ExtractElementInst(Value *Vec, unsigned Idx, const std::string &NameStr = "",
01340                      Instruction *InsertBefore = 0);
01341   ExtractElementInst(Value *Vec, Value *Idx, const std::string &NameStr,
01342                      BasicBlock *InsertAtEnd);
01343   ExtractElementInst(Value *Vec, unsigned Idx, const std::string &NameStr,
01344                      BasicBlock *InsertAtEnd);
01345 
01346   /// isValidOperands - Return true if an extractelement instruction can be
01347   /// formed with the specified operands.
01348   static bool isValidOperands(const Value *Vec, const Value *Idx);
01349 
01350   virtual ExtractElementInst *clone() const;
01351 
01352   /// Transparently provide more efficient getOperand methods.
01353   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01354 
01355   // Methods for support type inquiry through isa, cast, and dyn_cast:
01356   static inline bool classof(const ExtractElementInst *) { return true; }
01357   static inline bool classof(const Instruction *I) {
01358     return I->getOpcode() == Instruction::ExtractElement;
01359   }
01360   static inline bool classof(const Value *V) {
01361     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01362   }
01363 };
01364 
01365 template <>
01366 struct OperandTraits<ExtractElementInst> : FixedNumOperandTraits<2> {
01367 };
01368 
01369 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
01370 
01371 //===----------------------------------------------------------------------===//
01372 //                                InsertElementInst Class
01373 //===----------------------------------------------------------------------===//
01374 
01375 /// InsertElementInst - This instruction inserts a single (scalar)
01376 /// element into a VectorType value
01377 ///
01378 class InsertElementInst : public Instruction {
01379   InsertElementInst(const InsertElementInst &IE);
01380   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
01381                     const std::string &NameStr = "",Instruction *InsertBefore = 0);
01382   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
01383                     const std::string &NameStr = "",Instruction *InsertBefore = 0);
01384   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
01385                     const std::string &NameStr, BasicBlock *InsertAtEnd);
01386   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
01387                     const std::string &NameStr, BasicBlock *InsertAtEnd);
01388 public:
01389   static InsertElementInst *Create(const InsertElementInst &IE) {
01390     return new(IE.getNumOperands()) InsertElementInst(IE);
01391   }
01392   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
01393                                    const std::string &NameStr = "",
01394                                    Instruction *InsertBefore = 0) {
01395     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
01396   }
01397   static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
01398                                    const std::string &NameStr = "",
01399                                    Instruction *InsertBefore = 0) {
01400     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
01401   }
01402   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
01403                                    const std::string &NameStr,
01404                                    BasicBlock *InsertAtEnd) {
01405     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
01406   }
01407   static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
01408                                    const std::string &NameStr,
01409                                    BasicBlock *InsertAtEnd) {
01410     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
01411   }
01412 
01413   /// isValidOperands - Return true if an insertelement instruction can be
01414   /// formed with the specified operands.
01415   static bool isValidOperands(const Value *Vec, const Value *NewElt,
01416                               const Value *Idx);
01417 
01418   virtual InsertElementInst *clone() const;
01419 
01420   /// getType - Overload to return most specific vector type.
01421   ///
01422   const VectorType *getType() const {
01423     return reinterpret_cast<const VectorType*>(Instruction::getType());
01424   }
01425 
01426   /// Transparently provide more efficient getOperand methods.
01427   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01428 
01429   // Methods for support type inquiry through isa, cast, and dyn_cast:
01430   static inline bool classof(const InsertElementInst *) { return true; }
01431   static inline bool classof(const Instruction *I) {
01432     return I->getOpcode() == Instruction::InsertElement;
01433   }
01434   static inline bool classof(const Value *V) {
01435     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01436   }
01437 };
01438 
01439 template <>
01440 struct OperandTraits<InsertElementInst> : FixedNumOperandTraits<3> {
01441 };
01442 
01443 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
01444 
01445 //===----------------------------------------------------------------------===//
01446 //                           ShuffleVectorInst Class
01447 //===----------------------------------------------------------------------===//
01448 
01449 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
01450 /// input vectors.
01451 ///
01452 class ShuffleVectorInst : public Instruction {
01453   ShuffleVectorInst(const ShuffleVectorInst &IE);
01454 public:
01455   // allocate space for exactly three operands
01456   void *operator new(size_t s) {
01457     return User::operator new(s, 3);
01458   }
01459   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
01460                     const std::string &NameStr = "",
01461                     Instruction *InsertBefor = 0);
01462   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
01463                     const std::string &NameStr, BasicBlock *InsertAtEnd);
01464 
01465   /// isValidOperands - Return true if a shufflevector instruction can be
01466   /// formed with the specified operands.
01467   static bool isValidOperands(const Value *V1, const Value *V2,
01468                               const Value *Mask);
01469 
01470   virtual ShuffleVectorInst *clone() const;
01471 
01472   /// getType - Overload to return most specific vector type.
01473   ///
01474   const VectorType *getType() const {
01475     return reinterpret_cast<const VectorType*>(Instruction::getType());
01476   }
01477 
01478   /// Transparently provide more efficient getOperand methods.
01479   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01480   
01481   /// getMaskValue - Return the index from the shuffle mask for the specified
01482   /// output result.  This is either -1 if the element is undef or a number less
01483   /// than 2*numelements.
01484   int getMaskValue(unsigned i) const;
01485 
01486   // Methods for support type inquiry through isa, cast, and dyn_cast:
01487   static inline bool classof(const ShuffleVectorInst *) { return true; }
01488   static inline bool classof(const Instruction *I) {
01489     return I->getOpcode() == Instruction::ShuffleVector;
01490   }
01491   static inline bool classof(const Value *V) {
01492     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01493   }
01494 };
01495 
01496 template <>
01497 struct OperandTraits<ShuffleVectorInst> : FixedNumOperandTraits<3> {
01498 };
01499 
01500 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
01501 
01502 //===----------------------------------------------------------------------===//
01503 //                                ExtractValueInst Class
01504 //===----------------------------------------------------------------------===//
01505 
01506 /// ExtractValueInst - This instruction extracts a struct member or array
01507 /// element value from an aggregate value.
01508 ///
01509 class ExtractValueInst : public UnaryInstruction {
01510   SmallVector<unsigned, 4> Indices;
01511 
01512   ExtractValueInst(const ExtractValueInst &EVI);
01513   void init(const unsigned *Idx, unsigned NumIdx,
01514             const std::string &NameStr);
01515   void init(unsigned Idx, const std::string &NameStr);
01516 
01517   template<typename InputIterator>
01518   void init(InputIterator IdxBegin, InputIterator IdxEnd,
01519             const std::string &NameStr,
01520             // This argument ensures that we have an iterator we can
01521             // do arithmetic on in constant time
01522             std::random_access_iterator_tag) {
01523     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
01524     
01525     // There's no fundamental reason why we require at least one index
01526     // (other than weirdness with &*IdxBegin being invalid; see
01527     // getelementptr's init routine for example). But there's no
01528     // present need to support it.
01529     assert(NumIdx > 0 && "ExtractValueInst must have at least one index");
01530 
01531     // This requires that the iterator points to contiguous memory.
01532     init(&*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
01533                                          // we have to build an array here
01534   }
01535 
01536   /// getIndexedType - Returns the type of the element that would be extracted
01537   /// with an extractvalue instruction with the specified parameters.
01538   ///
01539   /// Null is returned if the indices are invalid for the specified
01540   /// pointer type.
01541   ///
01542   static const Type *getIndexedType(const Type *Agg,
01543                                     const unsigned *Idx, unsigned NumIdx);
01544 
01545   template<typename InputIterator>
01546   static const Type *getIndexedType(const Type *Ptr,
01547                                     InputIterator IdxBegin, 
01548                                     InputIterator IdxEnd,
01549                                     // This argument ensures that we
01550                                     // have an iterator we can do
01551                                     // arithmetic on in constant time
01552                                     std::random_access_iterator_tag) {
01553     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
01554 
01555     if (NumIdx > 0)
01556       // This requires that the iterator points to contiguous memory.
01557       return getIndexedType(Ptr, &*IdxBegin, NumIdx);
01558     else
01559       return getIndexedType(Ptr, (const unsigned *)0, NumIdx);
01560   }
01561 
01562   /// Constructors - Create a extractvalue instruction with a base aggregate
01563   /// value and a list of indices.  The first ctor can optionally insert before
01564   /// an existing instruction, the second appends the new instruction to the
01565   /// specified BasicBlock.
01566   template<typename InputIterator>
01567   inline ExtractValueInst(Value *Agg, InputIterator IdxBegin, 
01568                           InputIterator IdxEnd,
01569                           const std::string &NameStr,
01570                           Instruction *InsertBefore);
01571   template<typename InputIterator>
01572   inline ExtractValueInst(Value *Agg,
01573                           InputIterator IdxBegin, InputIterator IdxEnd,
01574                           const std::string &NameStr, BasicBlock *InsertAtEnd);
01575 
01576   // allocate space for exactly one operand
01577   void *operator new(size_t s) {
01578     return User::operator new(s, 1);
01579   }
01580 
01581 public:
01582   template<typename InputIterator>
01583   static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin, 
01584                                   InputIterator IdxEnd,
01585                                   const std::string &NameStr = "",
01586                                   Instruction *InsertBefore = 0) {
01587     return new
01588       ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore);
01589   }
01590   template<typename InputIterator>
01591   static ExtractValueInst *Create(Value *Agg,
01592                                   InputIterator IdxBegin, InputIterator IdxEnd,
01593                                   const std::string &NameStr,
01594                                   BasicBlock *InsertAtEnd) {
01595     return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd);
01596   }
01597 
01598   /// Constructors - These two creators are convenience methods because one
01599   /// index extractvalue instructions are much more common than those with
01600   /// more than one.
01601   static ExtractValueInst *Create(Value *Agg, unsigned Idx,
01602                                   const std::string &NameStr = "",
01603                                   Instruction *InsertBefore = 0) {
01604     unsigned Idxs[1] = { Idx };
01605     return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore);
01606   }
01607   static ExtractValueInst *Create(Value *Agg, unsigned Idx,
01608                                   const std::string &NameStr,
01609                                   BasicBlock *InsertAtEnd) {
01610     unsigned Idxs[1] = { Idx };
01611     return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
01612   }
01613 
01614   virtual ExtractValueInst *clone() const;
01615 
01616   // getType - Overload to return most specific pointer type...
01617   const PointerType *getType() const {
01618     return reinterpret_cast<const PointerType*>(Instruction::getType());
01619   }
01620 
01621   /// getIndexedType - Returns the type of the element that would be extracted
01622   /// with an extractvalue instruction with the specified parameters.
01623   ///
01624   /// Null is returned if the indices are invalid for the specified
01625   /// pointer type.
01626   ///
01627   template<typename InputIterator>
01628   static const Type *getIndexedType(const Type *Ptr,
01629                                     InputIterator IdxBegin,
01630                                     InputIterator IdxEnd) {
01631     return getIndexedType(Ptr, IdxBegin, IdxEnd,
01632                           typename std::iterator_traits<InputIterator>::
01633                           iterator_category());
01634   }  
01635   static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
01636 
01637   typedef const unsigned* idx_iterator;
01638   inline idx_iterator idx_begin() const { return Indices.begin(); }
01639   inline idx_iterator idx_end()   const { return Indices.end(); }
01640 
01641   Value *getAggregateOperand() {
01642     return getOperand(0);
01643   }
01644   const Value *getAggregateOperand() const {
01645     return getOperand(0);
01646   }
01647   static unsigned getAggregateOperandIndex() {
01648     return 0U;                      // get index for modifying correct operand
01649   }
01650 
01651   unsigned getNumIndices() const {  // Note: always non-negative
01652     return (unsigned)Indices.size();
01653   }
01654 
01655   bool hasIndices() const {
01656     return true;
01657   }
01658   
01659   // Methods for support type inquiry through isa, cast, and dyn_cast:
01660   static inline bool classof(const ExtractValueInst *) { return true; }
01661   static inline bool classof(const Instruction *I) {
01662     return I->getOpcode() == Instruction::ExtractValue;
01663   }
01664   static inline bool classof(const Value *V) {
01665     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01666   }
01667 };
01668 
01669 template<typename InputIterator>
01670 ExtractValueInst::ExtractValueInst(Value *Agg,
01671                                    InputIterator IdxBegin, 
01672                                    InputIterator IdxEnd,
01673                                    const std::string &NameStr,
01674                                    Instruction *InsertBefore)
01675   : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
01676                                               IdxBegin, IdxEnd)),
01677                      ExtractValue, Agg, InsertBefore) {
01678   init(IdxBegin, IdxEnd, NameStr,
01679        typename std::iterator_traits<InputIterator>::iterator_category());
01680 }
01681 template<typename InputIterator>
01682 ExtractValueInst::ExtractValueInst(Value *Agg,
01683                                    InputIterator IdxBegin,
01684                                    InputIterator IdxEnd,
01685                                    const std::string &NameStr,
01686                                    BasicBlock *InsertAtEnd)
01687   : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
01688                                               IdxBegin, IdxEnd)),
01689                      ExtractValue, Agg, InsertAtEnd) {
01690   init(IdxBegin, IdxEnd, NameStr,
01691        typename std::iterator_traits<InputIterator>::iterator_category());
01692 }
01693 
01694 
01695 //===----------------------------------------------------------------------===//
01696 //                                InsertValueInst Class
01697 //===----------------------------------------------------------------------===//
01698 
01699 /// InsertValueInst - This instruction inserts a struct field of array element
01700 /// value into an aggregate value.
01701 ///
01702 class InsertValueInst : public Instruction {
01703   SmallVector<unsigned, 4> Indices;
01704 
01705   void *operator new(size_t, unsigned); // Do not implement
01706   InsertValueInst(const InsertValueInst &IVI);
01707   void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx,
01708             const std::string &NameStr);
01709   void init(Value *Agg, Value *Val, unsigned Idx, const std::string &NameStr);
01710 
01711   template<typename InputIterator>
01712   void init(Value *Agg, Value *Val,
01713             InputIterator IdxBegin, InputIterator IdxEnd,
01714             const std::string &NameStr,
01715             // This argument ensures that we have an iterator we can
01716             // do arithmetic on in constant time
01717             std::random_access_iterator_tag) {
01718     unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
01719     
01720     // There's no fundamental reason why we require at least one index
01721     // (other than weirdness with &*IdxBegin being invalid; see
01722     // getelementptr's init routine for example). But there's no
01723     // present need to support it.
01724     assert(NumIdx > 0 && "InsertValueInst must have at least one index");
01725 
01726     // This requires that the iterator points to contiguous memory.
01727     init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
01728                                               // we have to build an array here
01729   }
01730 
01731   /// Constructors - Create a insertvalue instruction with a base aggregate
01732   /// value, a value to insert, and a list of indices.  The first ctor can
01733   /// optionally insert before an existing instruction, the second appends
01734   /// the new instruction to the specified BasicBlock.
01735   template<typename InputIterator>
01736   inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin, 
01737                          InputIterator IdxEnd,
01738                          const std::string &NameStr,
01739                          Instruction *InsertBefore);
01740   template<typename InputIterator>
01741   inline InsertValueInst(Value *Agg, Value *Val,
01742                          InputIterator IdxBegin, InputIterator IdxEnd,
01743                          const std::string &NameStr, BasicBlock *InsertAtEnd);
01744 
01745   /// Constructors - These two constructors are convenience methods because one
01746   /// and two index insertvalue instructions are so common.
01747   InsertValueInst(Value *Agg, Value *Val,
01748                   unsigned Idx, const std::string &NameStr = "",
01749                   Instruction *InsertBefore = 0);
01750   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
01751                   const std::string &NameStr, BasicBlock *InsertAtEnd);
01752 public:
01753   // allocate space for exactly two operands
01754   void *operator new(size_t s) {
01755     return User::operator new(s, 2);
01756   }
01757 
01758   template<typename InputIterator>
01759   static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin,
01760                                  InputIterator IdxEnd,
01761                                  const std::string &NameStr = "",
01762                                  Instruction *InsertBefore = 0) {
01763     return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
01764                                NameStr, InsertBefore);
01765   }
01766   template<typename InputIterator>
01767   static InsertValueInst *Create(Value *Agg, Value *Val,
01768                                  InputIterator IdxBegin, InputIterator IdxEnd,
01769                                  const std::string &NameStr,
01770                                  BasicBlock *InsertAtEnd) {
01771     return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
01772                                NameStr, InsertAtEnd);
01773   }
01774 
01775   /// Constructors - These two creators are convenience methods because one
01776   /// index insertvalue instructions are much more common than those with
01777   /// more than one.
01778   static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
01779                                  const std::string &NameStr = "",
01780                                  Instruction *InsertBefore = 0) {
01781     return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore);
01782   }
01783   static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
01784                                  const std::string &NameStr,
01785                                  BasicBlock *InsertAtEnd) {
01786     return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
01787   }
01788 
01789   virtual InsertValueInst *clone() const;
01790 
01791   /// Transparently provide more efficient getOperand methods.
01792   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01793 
01794   // getType - Overload to return most specific pointer type...
01795   const PointerType *getType() const {
01796     return reinterpret_cast<const PointerType*>(Instruction::getType());
01797   }
01798 
01799   typedef const unsigned* idx_iterator;
01800   inline idx_iterator idx_begin() const { return Indices.begin(); }
01801   inline idx_iterator idx_end()   const { return Indices.end(); }
01802 
01803   Value *getAggregateOperand() {
01804     return getOperand(0);
01805   }
01806   const Value *getAggregateOperand() const {
01807     return getOperand(0);
01808   }
01809   static unsigned getAggregateOperandIndex() {
01810     return 0U;                      // get index for modifying correct operand
01811   }
01812 
01813   Value *getInsertedValueOperand() {
01814     return getOperand(1);
01815   }
01816   const Value *getInsertedValueOperand() const {
01817     return getOperand(1);
01818   }
01819   static unsigned getInsertedValueOperandIndex() {
01820     return 1U;                      // get index for modifying correct operand
01821   }
01822 
01823   unsigned getNumIndices() const {  // Note: always non-negative
01824     return (unsigned)Indices.size();
01825   }
01826 
01827   bool hasIndices() const {
01828     return true;
01829   }
01830   
01831   // Methods for support type inquiry through isa, cast, and dyn_cast:
01832   static inline bool classof(const InsertValueInst *) { return true; }
01833   static inline bool classof(const Instruction *I) {
01834     return I->getOpcode() == Instruction::InsertValue;
01835   }
01836   static inline bool classof(const Value *V) {
01837     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01838   }
01839 };
01840 
01841 template <>
01842 struct OperandTraits<InsertValueInst> : FixedNumOperandTraits<2> {
01843 };
01844 
01845 template<typename InputIterator>
01846 InsertValueInst::InsertValueInst(Value *Agg,
01847                                  Value *Val,
01848                                  InputIterator IdxBegin, 
01849                                  InputIterator IdxEnd,
01850                                  const std::string &NameStr,
01851                                  Instruction *InsertBefore)
01852   : Instruction(Agg->getType(), InsertValue,
01853                 OperandTraits<InsertValueInst>::op_begin(this),
01854                 2, InsertBefore) {
01855   init(Agg, Val, IdxBegin, IdxEnd, NameStr,
01856        typename std::iterator_traits<InputIterator>::iterator_category());
01857 }
01858 template<typename InputIterator>
01859 InsertValueInst::InsertValueInst(Value *Agg,
01860                                  Value *Val,
01861                                  InputIterator IdxBegin,
01862                                  InputIterator IdxEnd,
01863                                  const std::string &NameStr,
01864                                  BasicBlock *InsertAtEnd)
01865   : Instruction(Agg->getType(), InsertValue,
01866                 OperandTraits<InsertValueInst>::op_begin(this),
01867                 2, InsertAtEnd) {
01868   init(Agg, Val, IdxBegin, IdxEnd, NameStr,
01869        typename std::iterator_traits<InputIterator>::iterator_category());
01870 }
01871 
01872 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
01873 
01874 //===----------------------------------------------------------------------===//
01875 //                               PHINode Class
01876 //===----------------------------------------------------------------------===//
01877 
01878 // PHINode - The PHINode class is used to represent the magical mystical PHI
01879 // node, that can not exist in nature, but can be synthesized in a computer
01880 // scientist's overactive imagination.
01881 //
01882 class PHINode : public Instruction {
01883   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
01884   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
01885   /// the number actually in use.
01886   unsigned ReservedSpace;
01887   PHINode(const PHINode &PN);
01888   // allocate space for exactly zero operands
01889   void *operator new(size_t s) {
01890     return User::operator new(s, 0);
01891   }
01892   explicit PHINode(const Type *Ty, const std::string &NameStr = "",
01893                    Instruction *InsertBefore = 0)
01894     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
01895       ReservedSpace(0) {
01896     setName(NameStr);
01897   }
01898 
01899   PHINode(const Type *Ty, const std::string &NameStr, BasicBlock *InsertAtEnd)
01900     : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
01901       ReservedSpace(0) {
01902     setName(NameStr);
01903   }
01904 public:
01905   static PHINode *Create(const Type *Ty, const std::string &NameStr = "",
01906                          Instruction *InsertBefore = 0) {
01907     return new PHINode(Ty, NameStr, InsertBefore);
01908   }
01909   static PHINode *Create(const Type *Ty, const std::string &NameStr,
01910                          BasicBlock *InsertAtEnd) {
01911     return new PHINode(Ty, NameStr, InsertAtEnd);
01912   }
01913   ~PHINode();
01914 
01915   /// reserveOperandSpace - This method can be used to avoid repeated
01916   /// reallocation of PHI operand lists by reserving space for the correct
01917   /// number of operands before adding them.  Unlike normal vector reserves,
01918   /// this method can also be used to trim the operand space.
01919   void reserveOperandSpace(unsigned NumValues) {
01920     resizeOperands(NumValues*2);
01921   }
01922 
01923   virtual PHINode *clone() const;
01924 
01925   /// Provide fast operand accessors
01926   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01927 
01928   /// getNumIncomingValues - Return the number of incoming edges
01929   ///
01930   unsigned getNumIncomingValues() const { return getNumOperands()/2; }
01931 
01932   /// getIncomingValue - Return incoming value number x
01933   ///
01934   Value *getIncomingValue(unsigned i) const {
01935     assert(i*2 < getNumOperands() && "Invalid value number!");
01936     return getOperand(i*2);
01937   }
01938   void setIncomingValue(unsigned i, Value *V) {
01939     assert(i*2 < getNumOperands() && "Invalid value number!");
01940     setOperand(i*2, V);
01941   }
01942   unsigned getOperandNumForIncomingValue(unsigned i) {
01943     return i*2;
01944   }
01945 
01946   /// getIncomingBlock - Return incoming basic block corresponding
01947   /// to value use iterator
01948   ///
01949   template <typename U>
01950   BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
01951     assert(this == *I && "Iterator doesn't point to PHI's Uses?");
01952     return static_cast<BasicBlock*>((&I.getUse() + 1)->get());
01953   }
01954   /// getIncomingBlock - Return incoming basic block number x
01955   ///
01956   BasicBlock *getIncomingBlock(unsigned i) const {
01957     return static_cast<BasicBlock*>(getOperand(i*2+1));
01958   }
01959   void setIncomingBlock(unsigned i, BasicBlock *BB) {
01960     setOperand(i*2+1, BB);
01961   }
01962   unsigned getOperandNumForIncomingBlock(unsigned i) {
01963     return i*2+1;
01964   }
01965 
01966   /// addIncoming - Add an incoming value to the end of the PHI list
01967   ///
01968   void addIncoming(Value *V, BasicBlock *BB) {
01969     assert(V && "PHI node got a null value!");
01970     assert(BB && "PHI node got a null basic block!");
01971     assert(getType() == V->getType() &&
01972            "All operands to PHI node must be the same type as the PHI node!");
01973     unsigned OpNo = NumOperands;
01974     if (OpNo+2 > ReservedSpace)
01975       resizeOperands(0);  // Get more space!
01976     // Initialize some new operands.
01977     NumOperands = OpNo+2;
01978     OperandList[OpNo] = V;
01979     OperandList[OpNo+1] = BB;
01980   }
01981 
01982   /// removeIncomingValue - Remove an incoming value.  This is useful if a
01983   /// predecessor basic block is deleted.  The value removed is returned.
01984   ///
01985   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
01986   /// is true), the PHI node is destroyed and any uses of it are replaced with
01987   /// dummy values.  The only time there should be zero incoming values to a PHI
01988   /// node is when the block is dead, so this strategy is sound.
01989   ///
01990   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
01991 
01992   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
01993     int Idx = getBasicBlockIndex(BB);
01994     assert(Idx >= 0 && "Invalid basic block argument to remove!");
01995     return removeIncomingValue(Idx, DeletePHIIfEmpty);
01996   }
01997 
01998   /// getBasicBlockIndex - Return the first index of the specified basic
01999   /// block in the value list for this PHI.  Returns -1 if no instance.
02000   ///
02001   int getBasicBlockIndex(const BasicBlock *BB) const {
02002     Use *OL = OperandList;
02003     for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
02004       if (OL[i+1].get() == BB) return i/2;
02005     return -1;
02006   }
02007 
02008   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
02009     return getIncomingValue(getBasicBlockIndex(BB));
02010   }
02011 
02012   /// hasConstantValue - If the specified PHI node always merges together the
02013   /// same value, return the value, otherwise return null.
02014   ///
02015   Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
02016 
02017   /// Methods for support type inquiry through isa, cast, and dyn_cast:
02018   static inline bool classof(const PHINode *) { return true; }
02019   static inline bool classof(const Instruction *I) {
02020     return I->getOpcode() == Instruction::PHI;
02021   }
02022   static inline bool classof(const Value *V) {
02023     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02024   }
02025  private:
02026   void resizeOperands(unsigned NumOperands);
02027 };
02028 
02029 template <>
02030 struct OperandTraits<PHINode> : HungoffOperandTraits<2> {
02031 };
02032 
02033 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)  
02034 
02035 
02036 //===----------------------------------------------------------------------===//
02037 //                               ReturnInst Class
02038 //===----------------------------------------------------------------------===//
02039 
02040 //===---------------------------------------------------------------------------
02041 /// ReturnInst - Return a value (possibly void), from a function.  Execution
02042 /// does not continue in this function any longer.
02043 ///
02044 class ReturnInst : public TerminatorInst {
02045   ReturnInst(const ReturnInst &RI);
02046 
02047 private:
02048   // ReturnInst constructors:
02049   // ReturnInst()                  - 'ret void' instruction
02050   // ReturnInst(    null)          - 'ret void' instruction
02051   // ReturnInst(Value* X)          - 'ret X'    instruction
02052   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
02053   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
02054   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
02055   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
02056   //
02057   // NOTE: If the Value* passed is of type void then the constructor behaves as
02058   // if it was passed NULL.
02059   explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
02060   ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
02061   explicit ReturnInst(BasicBlock *InsertAtEnd);
02062 public:
02063   static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
02064     return new(!!retVal) ReturnInst(retVal, InsertBefore);
02065   }
02066   static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
02067     return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
02068   }
02069   static ReturnInst* Create(BasicBlock *InsertAtEnd) {
02070     return new(0) ReturnInst(InsertAtEnd);
02071   }
02072   virtual ~ReturnInst();
02073 
02074   virtual ReturnInst *clone() const;
02075 
02076   /// Provide fast operand accessors
02077   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02078 
02079   /// Convenience accessor
02080   Value *getReturnValue(unsigned n = 0) const {
02081     return n < getNumOperands()
02082       ? getOperand(n)
02083       : 0;
02084   }
02085 
02086   unsigned getNumSuccessors() const { return 0; }
02087 
02088   // Methods for support type inquiry through isa, cast, and dyn_cast:
02089   static inline bool classof(const ReturnInst *) { return true; }
02090   static inline bool classof(const Instruction *I) {
02091     return (I->getOpcode() == Instruction::Ret);
02092   }
02093   static inline bool classof(const Value *V) {
02094     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02095   }
02096  private:
02097   virtual BasicBlock *getSuccessorV(unsigned idx) const;
02098   virtual unsigned getNumSuccessorsV() const;
02099   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
02100 };
02101 
02102 template <>
02103 struct OperandTraits<ReturnInst> : OptionalOperandTraits<> {
02104 };
02105 
02106 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
02107 
02108 //===----------------------------------------------------------------------===//
02109 //                               BranchInst Class
02110 //===----------------------------------------------------------------------===//
02111 
02112 //===---------------------------------------------------------------------------
02113 /// BranchInst - Conditional or Unconditional Branch instruction.
02114 ///
02115 class BranchInst : public TerminatorInst {
02116   /// Ops list - Branches are strange.  The operands are ordered:
02117   ///  TrueDest, FalseDest, Cond.  This makes some accessors faster because
02118   /// they don't have to check for cond/uncond branchness.
02119   BranchInst(const BranchInst &BI);
02120   void AssertOK();
02121   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
02122   // BranchInst(BB *B)                           - 'br B'
02123   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
02124   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
02125   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
02126   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
02127   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
02128   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
02129   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
02130              Instruction *InsertBefore = 0);
02131   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
02132   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
02133              BasicBlock *InsertAtEnd);
02134 public:
02135   static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
02136     return new(1) BranchInst(IfTrue, InsertBefore);
02137   }
02138   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
02139                             Value *Cond, Instruction *InsertBefore = 0) {
02140     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
02141   }
02142   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
02143     return new(1) BranchInst(IfTrue, InsertAtEnd);
02144   }
02145   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
02146                             Value *Cond, BasicBlock *InsertAtEnd) {
02147     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
02148   }
02149 
02150   ~BranchInst() {
02151     if (NumOperands == 1)
02152       NumOperands = (unsigned)((Use*)this - OperandList);
02153   }
02154 
02155   /// Transparently provide more efficient getOperand methods.
02156   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02157 
02158   virtual BranchInst *clone() const;
02159 
02160   bool isUnconditional() const { return getNumOperands() == 1; }
02161   bool isConditional()   const { return getNumOperands() == 3; }
02162 
02163   Value *getCondition() const {
02164     assert(isConditional() && "Cannot get condition of an uncond branch!");
02165     return getOperand(2);
02166   }
02167 
02168   void setCondition(Value *V) {
02169     assert(isConditional() && "Cannot set condition of unconditional branch!");
02170     setOperand(2, V);
02171   }
02172 
02173   // setUnconditionalDest - Change the current branch to an unconditional branch
02174   // targeting the specified block.
02175   // FIXME: Eliminate this ugly method.
02176   void setUnconditionalDest(BasicBlock *Dest) {
02177     Op<0>() = Dest;
02178     if (isConditional()) {  // Convert this to an uncond branch.
02179       Op<1>().set(0);
02180       Op<2>().set(0);
02181       NumOperands = 1;
02182     }
02183   }
02184 
02185   unsigned getNumSuccessors() const { return 1+isConditional(); }
02186 
02187   BasicBlock *getSuccessor(unsigned i) const {
02188     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
02189     return cast<BasicBlock>(getOperand(i));
02190   }
02191 
02192   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
02193     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
02194     setOperand(idx, NewSucc);
02195   }
02196 
02197   // Methods for support type inquiry through isa, cast, and dyn_cast:
02198   static inline bool classof(const BranchInst *) { return true; }
02199   static inline bool classof(const Instruction *I) {
02200     return (I->getOpcode() == Instruction::Br);
02201   }
02202   static inline bool classof(const Value *V) {
02203     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02204   }
02205 private:
02206   virtual BasicBlock *getSuccessorV(unsigned idx) const;
02207   virtual unsigned getNumSuccessorsV() const;
02208   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
02209 };
02210 
02211 template <>
02212 struct OperandTraits<BranchInst> : HungoffOperandTraits<> {
02213   // we need to access operands via OperandList, since
02214   // the NumOperands may change from 3 to 1
02215   static inline void *allocate(unsigned); // FIXME
02216 };
02217 
02218 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
02219 
02220 //===----------------------------------------------------------------------===//
02221 //                               SwitchInst Class
02222 //===----------------------------------------------------------------------===//
02223 
02224 //===---------------------------------------------------------------------------
02225 /// SwitchInst - Multiway switch
02226 ///
02227 class SwitchInst : public TerminatorInst {
02228   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
02229   unsigned ReservedSpace;
02230   // Operand[0]    = Value to switch on
02231   // Operand[1]    = Default basic block destination
02232   // Operand[2n  ] = Value to match
02233   // Operand[2n+1] = BasicBlock to go to on match
02234   SwitchInst(const SwitchInst &RI);
02235   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
02236   void resizeOperands(unsigned No);
02237   // allocate space for exactly zero operands
02238   void *operator new(size_t s) {
02239     return User::operator new(s, 0);
02240   }
02241   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
02242   /// switch on and a default destination.  The number of additional cases can
02243   /// be specified here to make memory allocation more efficient.  This
02244   /// constructor can also autoinsert before another instruction.
02245   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
02246              Instruction *InsertBefore = 0);
02247   
02248   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
02249   /// switch on and a default destination.  The number of additional cases can
02250   /// be specified here to make memory allocation more efficient.  This
02251   /// constructor also autoinserts at the end of the specified BasicBlock.
02252   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
02253              BasicBlock *InsertAtEnd);
02254 public:
02255   static SwitchInst *Create(Value *Value, BasicBlock *Default,
02256                             unsigned NumCases, Instruction *InsertBefore = 0) {
02257     return new SwitchInst(Value, Default, NumCases, InsertBefore);
02258   }
02259   static SwitchInst *Create(Value *Value, BasicBlock *Default,
02260                             unsigned NumCases, BasicBlock *InsertAtEnd) {
02261     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
02262   }
02263   ~SwitchInst();
02264 
02265   /// Provide fast operand accessors
02266   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02267 
02268   // Accessor Methods for Switch stmt
02269   Value *getCondition() const { return getOperand(0); }
02270   void setCondition(Value *V) { setOperand(0, V); }
02271 
02272   BasicBlock *getDefaultDest() const {
02273     return cast<BasicBlock>(getOperand(1));
02274   }
02275 
02276   /// getNumCases - return the number of 'cases' in this switch instruction.
02277   /// Note that case #0 is always the default case.
02278   unsigned getNumCases() const {
02279     return getNumOperands()/2;
02280   }
02281 
02282   /// getCaseValue - Return the specified case value.  Note that case #0, the
02283   /// default destination, does not have a case value.
02284   ConstantInt *getCaseValue(unsigned i) {
02285     assert(i && i < getNumCases() && "Illegal case value to get!");
02286     return getSuccessorValue(i);
02287   }
02288 
02289   /// getCaseValue - Return the specified case value.  Note that case #0, the
02290   /// default destination, does not have a case value.
02291   const ConstantInt *getCaseValue(unsigned i) const {
02292     assert(i && i < getNumCases() && "Illegal case value to get!");
02293     return getSuccessorValue(i);
02294   }
02295 
02296   /// findCaseValue - Search all of the case values for the specified constant.
02297   /// If it is explicitly handled, return the case number of it, otherwise
02298   /// return 0 to indicate that it is handled by the default handler.
02299   unsigned findCaseValue(const ConstantInt *C) const {
02300     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
02301       if (getCaseValue(i) == C)
02302         return i;
02303     return 0;
02304   }
02305 
02306   /// findCaseDest - Finds the unique case value for a given successor. Returns
02307   /// null if the successor is not found, not unique, or is the default case.
02308   ConstantInt *findCaseDest(BasicBlock *BB) {
02309     if (BB == getDefaultDest()) return NULL;
02310 
02311     ConstantInt *CI = NULL;
02312     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
02313       if (getSuccessor(i) == BB) {
02314         if (CI) return NULL;   // Multiple cases lead to BB.
02315         else CI = getCaseValue(i);
02316       }
02317     }
02318     return CI;
02319   }
02320 
02321   /// addCase - Add an entry to the switch instruction...
02322   ///
02323   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
02324 
02325   /// removeCase - This method removes the specified successor from the switch
02326   /// instruction.  Note that this cannot be used to remove the default
02327   /// destination (successor #0).
02328   ///
02329   void removeCase(unsigned idx);
02330 
02331   virtual SwitchInst *clone() const;
02332 
02333   unsigned getNumSuccessors() const { return getNumOperands()/2; }
02334   BasicBlock *getSuccessor(unsigned idx) const {
02335     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
02336     return cast<BasicBlock>(getOperand(idx*2+1));
02337   }
02338   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
02339     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
02340     setOperand(idx*2+1, NewSucc);
02341   }
02342 
02343   // getSuccessorValue - Return the value associated with the specified
02344   // successor.
02345   ConstantInt *getSuccessorValue(unsigned idx) const {
02346     assert(idx < getNumSuccessors() && "Successor # out of range!");
02347     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
02348   }
02349 
02350   // Methods for support type inquiry through isa, cast, and dyn_cast:
02351   static inline bool classof(const SwitchInst *) { return true; }
02352   static inline bool classof(const Instruction *I) {
02353     return I->getOpcode() == Instruction::Switch;
02354   }
02355   static inline bool classof(const Value *V) {
02356     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02357   }
02358 private:
02359   virtual BasicBlock *getSuccessorV(unsigned idx) const;
02360   virtual unsigned getNumSuccessorsV() const;
02361   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
02362 };
02363 
02364 template <>
02365 struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> {
02366 };
02367 
02368 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)  
02369 
02370 
02371 //===----------------------------------------------------------------------===//
02372 //                               InvokeInst Class
02373 //===----------------------------------------------------------------------===//
02374 
02375 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
02376 /// calling convention of the call.
02377 ///
02378 class InvokeInst : public TerminatorInst {
02379   AttrListPtr AttributeList;
02380   InvokeInst(const InvokeInst &BI);
02381   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
02382             Value* const *Args, unsigned NumArgs);
02383 
02384   template<typename InputIterator>
02385   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
02386             InputIterator ArgBegin, InputIterator ArgEnd,
02387             const std::string &NameStr,
02388             // This argument ensures that we have an iterator we can
02389             // do arithmetic on in constant time
02390             std::random_access_iterator_tag) {
02391     unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
02392     
02393     // This requires that the iterator points to contiguous memory.
02394     init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
02395     setName(NameStr);
02396   }
02397 
02398   /// Construct an InvokeInst given a range of arguments.
02399   /// InputIterator must be a random-access iterator pointing to
02400   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
02401   /// made for random-accessness but not for contiguous storage as
02402   /// that would incur runtime overhead.
02403   ///
02404   /// @brief Construct an InvokeInst from a range of arguments
02405   template<typename InputIterator>
02406   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
02407                     InputIterator ArgBegin, InputIterator ArgEnd,
02408                     unsigned Values,
02409                     const std::string &NameStr, Instruction *InsertBefore);
02410 
02411   /// Construct an InvokeInst given a range of arguments.
02412   /// InputIterator must be a random-access iterator pointing to
02413   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
02414   /// made for random-accessness but not for contiguous storage as
02415   /// that would incur runtime overhead.
02416   ///
02417   /// @brief Construct an InvokeInst from a range of arguments
02418   template<typename InputIterator>
02419   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
02420                     InputIterator ArgBegin, InputIterator ArgEnd,
02421                     unsigned Values,
02422                     const std::string &NameStr, BasicBlock *InsertAtEnd);
02423 public:
02424   template<typename InputIterator>
02425   static InvokeInst *Create(Value *Func,
02426                             BasicBlock *IfNormal, BasicBlock *IfException,
02427                             InputIterator ArgBegin, InputIterator ArgEnd,
02428                             const std::string &NameStr = "",
02429                             Instruction *InsertBefore = 0) {
02430     unsigned Values(ArgEnd - ArgBegin + 3);
02431     return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
02432                                   Values, NameStr, InsertBefore);
02433   }
02434   template<typename InputIterator>
02435   static InvokeInst *Create(Value *Func,
02436                             BasicBlock *IfNormal, BasicBlock *IfException,
02437                             InputIterator ArgBegin, InputIterator ArgEnd,
02438                             const std::string &NameStr,
02439                             BasicBlock *InsertAtEnd) {
02440     unsigned Values(ArgEnd - ArgBegin + 3);
02441     return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
02442                                   Values, NameStr, InsertAtEnd);
02443   }
02444 
02445   virtual InvokeInst *clone() const;
02446 
02447   /// Provide fast operand accessors
02448   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02449   
02450   /// getCallingConv/setCallingConv - Get or set the calling convention of this
02451   /// function call.
02452   unsigned getCallingConv() const { return SubclassData; }
02453   void setCallingConv(unsigned CC) {
02454     SubclassData = CC;
02455   }
02456 
02457   /// getAttributes - Return the parameter attributes for this invoke.
02458   ///
02459   const AttrListPtr &getAttributes() const { return AttributeList; }
02460 
02461   /// setAttributes - Set the parameter attributes for this invoke.
02462   ///
02463   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
02464 
02465   /// addAttribute - adds the attribute to the list of attributes.
02466   void addAttribute(unsigned i, Attributes attr);
02467 
02468   /// removeAttribute - removes the attribute from the list of attributes.
02469   void removeAttribute(unsigned i, Attributes attr);
02470 
02471   /// @brief Determine whether the call or the callee has the given attribute.
02472   bool paramHasAttr(unsigned i, Attributes attr) const;
02473   
02474   /// @brief Extract the alignment for a call or parameter (0=unknown).
02475   unsigned getParamAlignment(unsigned i) const {
02476     return AttributeList.getParamAlignment(i);
02477   }
02478 
02479   /// @brief Determine if the call does not access memory.
02480   bool doesNotAccessMemory() const {
02481     return paramHasAttr(0, Attribute::ReadNone);
02482   }
02483   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
02484     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
02485     else removeAttribute(~0, Attribute::ReadNone);
02486   }
02487 
02488   /// @brief Determine if the call does not access or only reads memory.
02489   bool onlyReadsMemory() const {
02490     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
02491   }
02492   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
02493     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
02494     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
02495   }
02496 
02497   /// @brief Determine if the call cannot return.
02498   bool doesNotReturn() const {
02499     return paramHasAttr(~0, Attribute::NoReturn);
02500   }
02501   void setDoesNotReturn(bool DoesNotReturn = true) {
02502     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
02503     else removeAttribute(~0, Attribute::NoReturn);
02504   }
02505 
02506   /// @brief Determine if the call cannot unwind.
02507   bool doesNotThrow() const {
02508     return paramHasAttr(~0, Attribute::NoUnwind);
02509   }
02510   void setDoesNotThrow(bool DoesNotThrow = true) {
02511     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
02512     else removeAttribute(~0, Attribute::NoUnwind);
02513   }
02514 
02515   /// @brief Determine if the call returns a structure through first 
02516   /// pointer argument.
02517   bool hasStructRetAttr() const {
02518     // Be friendly and also check the callee.
02519     return paramHasAttr(1, Attribute::StructRet);
02520   }
02521 
02522   /// @brief Determine if any call argument is an aggregate passed by value.
02523   bool hasByValArgument() const {
02524     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
02525   }
02526 
02527   /// getCalledFunction - Return the function called, or null if this is an
02528   /// indirect function invocation.
02529   ///
02530   Function *getCalledFunction() const {
02531     return dyn_cast<Function>(getOperand(0));
02532   }
02533 
02534   /// getCalledValue - Get a pointer to the function that is invoked by this 
02535   /// instruction
02536   const Value *getCalledValue() const { return getOperand(0); }
02537         Value *getCalledValue()       { return getOperand(0); }
02538 
02539   // get*Dest - Return the destination basic blocks...
02540   BasicBlock *getNormalDest() const {
02541     return cast<BasicBlock>(getOperand(1));
02542   }
02543   BasicBlock *getUnwindDest() const {
02544     return cast<BasicBlock>(getOperand(2));
02545   }
02546   void setNormalDest(BasicBlock *B) {
02547     setOperand(1, B);
02548   }
02549 
02550   void setUnwindDest(BasicBlock *B) {
02551     setOperand(2, B);
02552   }
02553 
02554   BasicBlock *getSuccessor(unsigned i) const {
02555     assert(i < 2 && "Successor # out of range for invoke!");
02556     return i == 0 ? getNormalDest() : getUnwindDest();
02557   }
02558 
02559   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
02560     assert(idx < 2 && "Successor # out of range for invoke!");
02561     setOperand(idx+1, NewSucc);
02562   }
02563 
02564   unsigned getNumSuccessors() const { return 2; }
02565 
02566   // Methods for support type inquiry through isa, cast, and dyn_cast:
02567   static inline bool classof(const InvokeInst *) { return true; }
02568   static inline bool classof(const Instruction *I) {
02569     return (I->getOpcode() == Instruction::Invoke);
02570   }
02571   static inline bool classof(const Value *V) {
02572     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02573   }
02574 private:
02575   virtual BasicBlock *getSuccessorV(unsigned idx) const;
02576   virtual unsigned getNumSuccessorsV() const;
02577   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
02578 };
02579 
02580 template <>
02581 struct OperandTraits<InvokeInst> : VariadicOperandTraits<3> {
02582 };
02583 
02584 template<typename InputIterator>
02585 InvokeInst::InvokeInst(Value *Func,
02586                        BasicBlock *IfNormal, BasicBlock *IfException,
02587                        InputIterator ArgBegin, InputIterator ArgEnd,
02588                        unsigned Values,
02589                        const std::string &NameStr, Instruction *InsertBefore)
02590   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
02591                                       ->getElementType())->getReturnType(),
02592                    Instruction::Invoke,
02593                    OperandTraits<InvokeInst>::op_end(this) - Values,
02594                    Values, InsertBefore) {
02595   init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
02596        typename std::iterator_traits<InputIterator>::iterator_category());
02597 }
02598 template<typename InputIterator>
02599 InvokeInst::InvokeInst(Value *Func,
02600                        BasicBlock *IfNormal, BasicBlock *IfException,
02601                        InputIterator ArgBegin, InputIterator ArgEnd,
02602                        unsigned Values,
02603                        const std::string &NameStr, BasicBlock *InsertAtEnd)
02604   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
02605                                       ->getElementType())->getReturnType(),
02606                    Instruction::Invoke,
02607                    OperandTraits<InvokeInst>::op_end(this) - Values,
02608                    Values, InsertAtEnd) {
02609   init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr,
02610        typename std::iterator_traits<InputIterator>::iterator_category());
02611 }
02612 
02613 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
02614 
02615 //===----------------------------------------------------------------------===//
02616 //                              UnwindInst Class
02617 //===----------------------------------------------------------------------===//
02618 
02619 //===---------------------------------------------------------------------------
02620 /// UnwindInst - Immediately exit the current function, unwinding the stack
02621 /// until an invoke instruction is found.
02622 ///
02623 class UnwindInst : public TerminatorInst {
02624   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
02625 public:
02626   // allocate space for exactly zero operands
02627   void *operator new(size_t s) {
02628     return User::operator new(s, 0);
02629   }
02630   explicit UnwindInst(Instruction *InsertBefore = 0);
02631   explicit UnwindInst(BasicBlock *InsertAtEnd);
02632 
02633   virtual UnwindInst *clone() const;
02634 
02635   unsigned getNumSuccessors() const { return 0; }
02636 
02637   // Methods for support type inquiry through isa, cast, and dyn_cast:
02638   static inline bool classof(const UnwindInst *) { return true; }
02639   static inline bool classof(const Instruction *I) {
02640     return I->getOpcode() == Instruction::Unwind;
02641   }
02642   static inline bool classof(const Value *V) {
02643     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02644   }
02645 private:
02646   virtual BasicBlock *getSuccessorV(unsigned idx) const;
02647   virtual unsigned getNumSuccessorsV() const;
02648   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
02649 };
02650 
02651 //===----------------------------------------------------------------------===//
02652 //                           UnreachableInst Class
02653 //===----------------------------------------------------------------------===//
02654 
02655 //===---------------------------------------------------------------------------
02656 /// UnreachableInst - This function has undefined behavior.  In particular, the
02657 /// presence of this instruction indicates some higher level knowledge that the
02658 /// end of the block cannot be reached.
02659 ///
02660 class UnreachableInst : public TerminatorInst {
02661   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
02662 public:
02663   // allocate space for exactly zero operands
02664   void *operator new(size_t s) {
02665     return User::operator new(s, 0);
02666   }
02667   explicit UnreachableInst(Instruction *InsertBefore = 0);
02668   explicit UnreachableInst(BasicBlock *InsertAtEnd);
02669 
02670   virtual UnreachableInst *clone() const;
02671 
02672   unsigned getNumSuccessors() const { return 0; }
02673 
02674   // Methods for support type inquiry through isa, cast, and dyn_cast:
02675   static inline bool classof(const UnreachableInst *) { return true; }
02676   static inline bool classof(const Instruction *I) {
02677     return I->getOpcode() == Instruction::Unreachable;
02678   }
02679   static inline bool classof(const Value *V) {
02680     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02681   }
02682 private:
02683   virtual BasicBlock *getSuccessorV(unsigned idx) const;
02684   virtual unsigned getNumSuccessorsV() const;
02685   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
02686 };
02687 
02688 //===----------------------------------------------------------------------===//
02689 //                                 TruncInst Class
02690 //===----------------------------------------------------------------------===//
02691 
02692 /// @brief This class represents a truncation of integer types.
02693 class TruncInst : public CastInst {
02694   /// Private copy constructor
02695   TruncInst(const TruncInst &CI)
02696     : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
02697   }
02698 public:
02699   /// @brief Constructor with insert-before-instruction semantics
02700   TruncInst(
02701     Value *S,                     ///< The value to be truncated
02702     const Type *Ty,               ///< The (smaller) type to truncate to
02703     const std::string &NameStr = "", ///< A name for the new instruction
02704     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
02705   );
02706 
02707   /// @brief Constructor with insert-at-end-of-block semantics
02708   TruncInst(
02709     Value *S,                     ///< The value to be truncated
02710     const Type *Ty,               ///< The (smaller) type to truncate to
02711     const std::string &NameStr,   ///< A name for the new instruction
02712     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
02713   );
02714 
02715   /// @brief Clone an identical TruncInst
02716   virtual CastInst *clone() const;
02717 
02718   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
02719   static inline bool classof(const TruncInst *) { return true; }
02720   static inline bool classof(const Instruction *I) {
02721     return I->getOpcode() == Trunc;
02722   }
02723   static inline bool classof(const Value *V) {
02724     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02725   }
02726 };
02727 
02728 //===----------------------------------------------------------------------===//
02729 //                                 ZExtInst Class
02730 //===----------------------------------------------------------------------===//
02731 
02732 /// @brief This class represents zero extension of integer types.
02733 class ZExtInst : public CastInst {
02734   /// @brief Private copy constructor
02735   ZExtInst(const ZExtInst &CI)
02736     : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
02737   }
02738 public:
02739   /// @brief Constructor with insert-before-instruction semantics
02740   ZExtInst(
02741     Value *S,                     ///< The value to be zero extended
02742     const Type *Ty,               ///< The type to zero extend to
02743     const std::string &NameStr = "", ///< A name for the new instruction
02744     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
02745   );
02746 
02747   /// @brief Constructor with insert-at-end semantics.
02748   ZExtInst(
02749     Value *S,                     ///< The value to be zero extended
02750     const Type *Ty,               ///< The type to zero extend to
02751     const std::string &NameStr,   ///< A name for the new instruction
02752     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
02753   );
02754 
02755   /// @brief Clone an identical ZExtInst
02756   virtual CastInst *clone() const;
02757 
02758   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
02759   static inline bool classof(const ZExtInst *) { return true; }
02760   static inline bool classof(const Instruction *I) {
02761     return I->getOpcode() == ZExt;
02762   }
02763   static inline bool classof(const Value *V) {
02764     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02765   }
02766 };
02767 
02768 //===----------------------------------------------------------------------===//
02769 //                                 SExtInst Class
02770 //===----------------------------------------------------------------------===//
02771 
02772 /// @brief This class represents a sign extension of integer types.
02773 class SExtInst : public CastInst {
02774   /// @brief Private copy constructor
02775   SExtInst(const SExtInst &CI)
02776     : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
02777   }
02778 public:
02779   /// @brief Constructor with insert-before-instruction semantics
02780   SExtInst(
02781     Value *S,                     ///< The value to be sign extended
02782     const Type *Ty,               ///< The type to sign extend to
02783     const std::string &NameStr = "", ///< A name for the new instruction
02784     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
02785   );
02786 
02787   /// @brief Constructor with insert-at-end-of-block semantics
02788   SExtInst(
02789     Value *S,                     ///< The value to be sign extended
02790     const Type *Ty,               ///< The type to sign extend to
02791     const std::string &NameStr,   ///< A name for the new instruction
02792     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
02793   );
02794 
02795   /// @brief Clone an identical SExtInst
02796   virtual CastInst *clone() const;
02797 
02798   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
02799   static inline bool classof(const SExtInst *) { return true; }
02800   static inline bool classof(const Instruction *I) {
02801     return I->getOpcode() == SExt;
02802   }
02803   static inline bool classof(const Value *V) {
02804     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02805   }
02806 };
02807 
02808 //===----------------------------------------------------------------------===//
02809 //                                 FPTruncInst Class
02810 //===----------------------------------------------------------------------===//
02811 
02812 /// @brief This class represents a truncation of floating point types.
02813 class FPTruncInst : public CastInst {
02814   FPTruncInst(const FPTruncInst &CI)
02815     : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
02816   }
02817 public:
02818   /// @brief Constructor with insert-before-instruction semantics
02819   FPTruncInst(
02820     Value *S,                     ///< The value to be truncated
02821     const Type *Ty,               ///< The type to truncate to
02822     const std::string &NameStr = "", ///< A name for the new instruction
02823     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
02824   );
02825 
02826   /// @brief Constructor with insert-before-instruction semantics
02827   FPTruncInst(
02828     Value *S,                     ///< The value to be truncated
02829     const Type *Ty,               ///< The type to truncate to
02830     const std::string &NameStr,   ///< A name for the new instruction
02831     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
02832   );
02833 
02834   /// @brief Clone an identical FPTruncInst
02835   virtual CastInst *clone() const;
02836 
02837   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
02838   static inline bool classof(const FPTruncInst *) { return true; }
02839   static inline bool classof(const Instruction *I) {
02840     return I->getOpcode() == FPTrunc;
02841   }
02842   static inline bool classof(const Value *V) {
02843     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02844   }
02845 };
02846 
02847 //===----------------------------------------------------------------------===//
02848 //                                 FPExtInst Class
02849 //===----------------------------------------------------------------------===//
02850 
02851 /// @brief This class represents an extension of floating point types.
02852 class FPExtInst : public CastInst {
02853   FPExtInst(const FPExtInst &CI)
02854     : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
02855   }
02856 public:
02857   /// @brief Constructor with insert-before-instruction semantics
02858   FPExtInst(
02859     Value *S,                     ///< The value to be extended
02860     const Type *Ty,               ///< The type to extend to
02861     const std::string &NameStr = "", ///< A name for the new instruction
02862     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
02863   );
02864 
02865   /// @brief Constructor with insert-at-end-of-block semantics
02866   FPExtInst(
02867     Value *S,                     ///< The value to be extended
02868     const Type *Ty,               ///< The type to extend to
02869     const std::string &NameStr,   ///< A name for the new instruction
02870     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
02871   );
02872 
02873   /// @brief Clone an identical FPExtInst
02874   virtual CastInst *clone() const;
02875 
02876   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
02877   static inline bool classof(const FPExtInst *) { return true; }
02878   static inline bool classof(const Instruction *I) {
02879     return I->getOpcode() == FPExt;
02880   }
02881   static inline bool classof(const Value *V) {
02882     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02883   }
02884 };
02885 
02886 //===----------------------------------------------------------------------===//
02887 //                                 UIToFPInst Class
02888 //===----------------------------------------------------------------------===//
02889 
02890 /// @brief This class represents a cast unsigned integer to floating point.
02891 class UIToFPInst : public CastInst {
02892   UIToFPInst(const UIToFPInst &CI)
02893     : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
02894   }
02895 public:
02896   /// @brief Constructor with insert-before-instruction semantics
02897   UIToFPInst(
02898     Value *S,                     ///< The value to be converted
02899     const Type *Ty,               ///< The type to convert to
02900     const std::string &NameStr = "", ///< A name for the new instruction
02901     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
02902   );
02903 
02904   /// @brief Constructor with insert-at-end-of-block semantics
02905   UIToFPInst(
02906     Value *S,                     ///< The value to be converted
02907     const Type *Ty,               ///< The type to convert to
02908     const std::string &NameStr,   ///< A name for the new instruction
02909     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
02910   );
02911 
02912   /// @brief Clone an identical UIToFPInst
02913   virtual CastInst *clone() const;
02914 
02915   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
02916   static inline bool classof(const UIToFPInst *) { return true; }
02917   static inline bool classof(const Instruction *I) {
02918     return I->getOpcode() == UIToFP;
02919   }
02920   static inline bool classof(const Value *V) {
02921     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02922   }
02923 };
02924 
02925 //===----------------------------------------------------------------------===//
02926 //                                 SIToFPInst Class
02927 //===----------------------------------------------------------------------===//
02928 
02929 /// @brief This class represents a cast from signed integer to floating point.
02930 class SIToFPInst : public CastInst {
02931   SIToFPInst(const SIToFPInst &CI)
02932     : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
02933   }
02934 public:
02935   /// @brief Constructor with insert-before-instruction semantics
02936   SIToFPInst(
02937     Value *S,                     ///< The value to be converted
02938     const Type *Ty,               ///< The type to convert to
02939     const std::string &NameStr = "", ///< A name for the new instruction
02940     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
02941   );
02942 
02943   /// @brief Constructor with insert-at-end-of-block semantics
02944   SIToFPInst(
02945     Value *S,                     ///< The value to be converted
02946     const Type *Ty,               ///< The type to convert to
02947     const std::string &NameStr,   ///< A name for the new instruction
02948     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
02949   );
02950 
02951   /// @brief Clone an identical SIToFPInst
02952   virtual CastInst *clone() const;
02953 
02954   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
02955   static inline bool classof(const SIToFPInst *) { return true; }
02956   static inline bool classof(const Instruction *I) {
02957     return I->getOpcode() == SIToFP;
02958   }
02959   static inline bool classof(const Value *V) {
02960     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02961   }
02962 };
02963 
02964 //===----------------------------------------------------------------------===//
02965 //                                 FPToUIInst Class
02966 //===----------------------------------------------------------------------===//
02967 
02968 /// @brief This class represents a cast from floating point to unsigned integer
02969 class FPToUIInst  : public CastInst {
02970   FPToUIInst(const FPToUIInst &CI)
02971     : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
02972   }
02973 public:
02974   /// @brief Constructor with insert-before-instruction semantics
02975   FPToUIInst(
02976     Value *S,                     ///< The value to be converted
02977     const Type *Ty,               ///< The type to convert to
02978     const std::string &NameStr = "", ///< A name for the new instruction
02979     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
02980   );
02981 
02982   /// @brief Constructor with insert-at-end-of-block semantics
02983   FPToUIInst(
02984     Value *S,                     ///< The value to be converted
02985     const Type *Ty,               ///< The type to convert to
02986     const std::string &NameStr,   ///< A name for the new instruction
02987     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
02988   );
02989 
02990   /// @brief Clone an identical FPToUIInst
02991   virtual CastInst *clone() const;
02992 
02993   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
02994   static inline bool classof(const FPToUIInst *) { return true; }
02995   static inline bool classof(const Instruction *I) {
02996     return I->getOpcode() == FPToUI;
02997   }
02998   static inline bool classof(const Value *V) {
02999     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03000   }
03001 };
03002 
03003 //===----------------------------------------------------------------------===//
03004 //                                 FPToSIInst Class
03005 //===----------------------------------------------------------------------===//
03006 
03007 /// @brief This class represents a cast from floating point to signed integer.
03008 class FPToSIInst  : public CastInst {
03009   FPToSIInst(const FPToSIInst &CI)
03010     : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
03011   }
03012 public:
03013   /// @brief Constructor with insert-before-instruction semantics
03014   FPToSIInst(
03015     Value *S,                     ///< The value to be converted
03016     const Type *Ty,               ///< The type to convert to
03017     const std::string &NameStr = "", ///< A name for the new instruction
03018     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03019   );
03020 
03021   /// @brief Constructor with insert-at-end-of-block semantics
03022   FPToSIInst(
03023     Value *S,                     ///< The value to be converted
03024     const Type *Ty,               ///< The type to convert to
03025     const std::string &NameStr,   ///< A name for the new instruction
03026     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03027   );
03028 
03029   /// @brief Clone an identical FPToSIInst
03030   virtual CastInst *clone() const;
03031 
03032   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
03033   static inline bool classof(const FPToSIInst *) { return true; }
03034   static inline bool classof(const Instruction *I) {
03035     return I->getOpcode() == FPToSI;
03036   }
03037   static inline bool classof(const Value *V) {
03038     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03039   }
03040 };
03041 
03042 //===----------------------------------------------------------------------===//
03043 //                                 IntToPtrInst Class
03044 //===----------------------------------------------------------------------===//
03045 
03046 /// @brief This class represents a cast from an integer to a pointer.
03047 class IntToPtrInst : public CastInst {
03048   IntToPtrInst(const IntToPtrInst &CI)
03049     : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
03050   }
03051 public:
03052   /// @brief Constructor with insert-before-instruction semantics
03053   IntToPtrInst(
03054     Value *S,                     ///< The value to be converted
03055     const Type *Ty,               ///< The type to convert to
03056     const std::string &NameStr = "", ///< A name for the new instruction
03057     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03058   );
03059 
03060   /// @brief Constructor with insert-at-end-of-block semantics
03061   IntToPtrInst(
03062     Value *S,                     ///< The value to be converted
03063     const Type *Ty,               ///< The type to convert to
03064     const std::string &NameStr,   ///< A name for the new instruction
03065     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03066   );
03067 
03068   /// @brief Clone an identical IntToPtrInst
03069   virtual CastInst *clone() const;
03070 
03071   // Methods for support type inquiry through isa, cast, and dyn_cast:
03072   static inline bool classof(const IntToPtrInst *) { return true; }
03073   static inline bool classof(const Instruction *I) {
03074     return I->getOpcode() == IntToPtr;
03075   }
03076   static inline bool classof(const Value *V) {
03077     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03078   }
03079 };
03080 
03081 //===----------------------------------------------------------------------===//
03082 //                                 PtrToIntInst Class
03083 //===----------------------------------------------------------------------===//
03084 
03085 /// @brief This class represents a cast from a pointer to an integer
03086 class PtrToIntInst : public CastInst {
03087   PtrToIntInst(const PtrToIntInst &CI)
03088     : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
03089   }
03090 public:
03091   /// @brief Constructor with insert-before-instruction semantics
03092   PtrToIntInst(
03093     Value *S,                     ///< The value to be converted
03094     const Type *Ty,               ///< The type to convert to
03095     const std::string &NameStr = "", ///< A name for the new instruction
03096     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03097   );
03098 
03099   /// @brief Constructor with insert-at-end-of-block semantics
03100   PtrToIntInst(
03101     Value *S,                     ///< The value to be converted
03102     const Type *Ty,               ///< The type to convert to
03103     const std::string &NameStr,   ///< A name for the new instruction
03104     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03105   );
03106 
03107   /// @brief Clone an identical PtrToIntInst
03108   virtual CastInst *clone() const;
03109 
03110   // Methods for support type inquiry through isa, cast, and dyn_cast:
03111   static inline bool classof(const PtrToIntInst *) { return true; }
03112   static inline bool classof(const Instruction *I) {
03113     return I->getOpcode() == PtrToInt;
03114   }
03115   static inline bool classof(const Value *V) {
03116     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03117   }
03118 };
03119 
03120 //===----------------------------------------------------------------------===//
03121 //                             BitCastInst Class
03122 //===----------------------------------------------------------------------===//
03123 
03124 /// @brief This class represents a no-op cast from one type to another.
03125 class BitCastInst : public CastInst {
03126   BitCastInst(const BitCastInst &CI)
03127     : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
03128   }
03129 public:
03130   /// @brief Constructor with insert-before-instruction semantics
03131   BitCastInst(
03132     Value *S,                     ///< The value to be casted
03133     const Type *Ty,               ///< The type to casted to
03134     const std::string &NameStr = "", ///< A name for the new instruction
03135     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03136   );
03137 
03138   /// @brief Constructor with insert-at-end-of-block semantics
03139   BitCastInst(
03140     Value *S,                     ///< The value to be casted
03141     const Type *Ty,               ///< The type to casted to
03142     const std::string &NameStr,      ///< A name for the new instruction
03143     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03144   );
03145 
03146   /// @brief Clone an identical BitCastInst
03147   virtual CastInst *clone() const;
03148 
03149   // Methods for support type inquiry through isa, cast, and dyn_cast:
03150   static inline bool classof(const BitCastInst *) { return true; }
03151   static inline bool classof(const Instruction *I) {
03152     return I->getOpcode() == BitCast;
03153   }
03154   static inline bool classof(const Value *V) {
03155     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03156   }
03157 };
03158 
03159 } // End llvm namespace
03160 
03161 #endif