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_IR_INSTRUCTIONS_H
00017 #define LLVM_IR_INSTRUCTIONS_H
00018 
00019 #include "llvm/ADT/ArrayRef.h"
00020 #include "llvm/ADT/SmallVector.h"
00021 #include "llvm/IR/Attributes.h"
00022 #include "llvm/IR/CallingConv.h"
00023 #include "llvm/IR/DerivedTypes.h"
00024 #include "llvm/IR/InstrTypes.h"
00025 #include "llvm/Support/ErrorHandling.h"
00026 #include "llvm/Support/IntegersSubset.h"
00027 #include "llvm/Support/IntegersSubsetMapping.h"
00028 #include <iterator>
00029 
00030 namespace llvm {
00031 
00032 class APInt;
00033 class ConstantInt;
00034 class ConstantRange;
00035 class DataLayout;
00036 class LLVMContext;
00037 
00038 enum AtomicOrdering {
00039   NotAtomic = 0,
00040   Unordered = 1,
00041   Monotonic = 2,
00042   // Consume = 3,  // Not specified yet.
00043   Acquire = 4,
00044   Release = 5,
00045   AcquireRelease = 6,
00046   SequentiallyConsistent = 7
00047 };
00048 
00049 enum SynchronizationScope {
00050   SingleThread = 0,
00051   CrossThread = 1
00052 };
00053 
00054 //===----------------------------------------------------------------------===//
00055 //                                AllocaInst Class
00056 //===----------------------------------------------------------------------===//
00057 
00058 /// AllocaInst - an instruction to allocate memory on the stack
00059 ///
00060 class AllocaInst : public UnaryInstruction {
00061 protected:
00062   virtual AllocaInst *clone_impl() const;
00063 public:
00064   explicit AllocaInst(Type *Ty, Value *ArraySize = 0,
00065                       const Twine &Name = "", Instruction *InsertBefore = 0);
00066   AllocaInst(Type *Ty, Value *ArraySize,
00067              const Twine &Name, BasicBlock *InsertAtEnd);
00068 
00069   AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
00070   AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
00071 
00072   AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
00073              const Twine &Name = "", Instruction *InsertBefore = 0);
00074   AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
00075              const Twine &Name, BasicBlock *InsertAtEnd);
00076 
00077   // Out of line virtual method, so the vtable, etc. has a home.
00078   virtual ~AllocaInst();
00079 
00080   /// isArrayAllocation - Return true if there is an allocation size parameter
00081   /// to the allocation instruction that is not 1.
00082   ///
00083   bool isArrayAllocation() const;
00084 
00085   /// getArraySize - Get the number of elements allocated. For a simple
00086   /// allocation of a single element, this will return a constant 1 value.
00087   ///
00088   const Value *getArraySize() const { return getOperand(0); }
00089   Value *getArraySize() { return getOperand(0); }
00090 
00091   /// getType - Overload to return most specific pointer type
00092   ///
00093   PointerType *getType() const {
00094     return cast<PointerType>(Instruction::getType());
00095   }
00096 
00097   /// getAllocatedType - Return the type that is being allocated by the
00098   /// instruction.
00099   ///
00100   Type *getAllocatedType() const;
00101 
00102   /// getAlignment - Return the alignment of the memory that is being allocated
00103   /// by the instruction.
00104   ///
00105   unsigned getAlignment() const {
00106     return (1u << getSubclassDataFromInstruction()) >> 1;
00107   }
00108   void setAlignment(unsigned Align);
00109 
00110   /// isStaticAlloca - Return true if this alloca is in the entry block of the
00111   /// function and is a constant size.  If so, the code generator will fold it
00112   /// into the prolog/epilog code, so it is basically free.
00113   bool isStaticAlloca() const;
00114 
00115   // Methods for support type inquiry through isa, cast, and dyn_cast:
00116   static inline bool classof(const Instruction *I) {
00117     return (I->getOpcode() == Instruction::Alloca);
00118   }
00119   static inline bool classof(const Value *V) {
00120     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00121   }
00122 private:
00123   // Shadow Instruction::setInstructionSubclassData with a private forwarding
00124   // method so that subclasses cannot accidentally use it.
00125   void setInstructionSubclassData(unsigned short D) {
00126     Instruction::setInstructionSubclassData(D);
00127   }
00128 };
00129 
00130 
00131 //===----------------------------------------------------------------------===//
00132 //                                LoadInst Class
00133 //===----------------------------------------------------------------------===//
00134 
00135 /// LoadInst - an instruction for reading from memory.  This uses the
00136 /// SubclassData field in Value to store whether or not the load is volatile.
00137 ///
00138 class LoadInst : public UnaryInstruction {
00139   void AssertOK();
00140 protected:
00141   virtual LoadInst *clone_impl() const;
00142 public:
00143   LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
00144   LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
00145   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
00146            Instruction *InsertBefore = 0);
00147   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
00148            BasicBlock *InsertAtEnd);
00149   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
00150            unsigned Align, Instruction *InsertBefore = 0);
00151   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
00152            unsigned Align, BasicBlock *InsertAtEnd);
00153   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
00154            unsigned Align, AtomicOrdering Order,
00155            SynchronizationScope SynchScope = CrossThread,
00156            Instruction *InsertBefore = 0);
00157   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
00158            unsigned Align, AtomicOrdering Order,
00159            SynchronizationScope SynchScope,
00160            BasicBlock *InsertAtEnd);
00161 
00162   LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
00163   LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
00164   explicit LoadInst(Value *Ptr, const char *NameStr = 0,
00165                     bool isVolatile = false,  Instruction *InsertBefore = 0);
00166   LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
00167            BasicBlock *InsertAtEnd);
00168 
00169   /// isVolatile - Return true if this is a load from a volatile memory
00170   /// location.
00171   ///
00172   bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
00173 
00174   /// setVolatile - Specify whether this is a volatile load or not.
00175   ///
00176   void setVolatile(bool V) {
00177     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
00178                                (V ? 1 : 0));
00179   }
00180 
00181   /// getAlignment - Return the alignment of the access that is being performed
00182   ///
00183   unsigned getAlignment() const {
00184     return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
00185   }
00186 
00187   void setAlignment(unsigned Align);
00188 
00189   /// Returns the ordering effect of this fence.
00190   AtomicOrdering getOrdering() const {
00191     return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
00192   }
00193 
00194   /// Set the ordering constraint on this load. May not be Release or
00195   /// AcquireRelease.
00196   void setOrdering(AtomicOrdering Ordering) {
00197     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
00198                                (Ordering << 7));
00199   }
00200 
00201   SynchronizationScope getSynchScope() const {
00202     return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
00203   }
00204 
00205   /// Specify whether this load is ordered with respect to all
00206   /// concurrently executing threads, or only with respect to signal handlers
00207   /// executing in the same thread.
00208   void setSynchScope(SynchronizationScope xthread) {
00209     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
00210                                (xthread << 6));
00211   }
00212 
00213   bool isAtomic() const { return getOrdering() != NotAtomic; }
00214   void setAtomic(AtomicOrdering Ordering,
00215                  SynchronizationScope SynchScope = CrossThread) {
00216     setOrdering(Ordering);
00217     setSynchScope(SynchScope);
00218   }
00219 
00220   bool isSimple() const { return !isAtomic() && !isVolatile(); }
00221   bool isUnordered() const {
00222     return getOrdering() <= Unordered && !isVolatile();
00223   }
00224 
00225   Value *getPointerOperand() { return getOperand(0); }
00226   const Value *getPointerOperand() const { return getOperand(0); }
00227   static unsigned getPointerOperandIndex() { return 0U; }
00228 
00229   /// \brief Returns the address space of the pointer operand.
00230   unsigned getPointerAddressSpace() const {
00231     return getPointerOperand()->getType()->getPointerAddressSpace();
00232   }
00233 
00234 
00235   // Methods for support type inquiry through isa, cast, and dyn_cast:
00236   static inline bool classof(const Instruction *I) {
00237     return I->getOpcode() == Instruction::Load;
00238   }
00239   static inline bool classof(const Value *V) {
00240     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00241   }
00242 private:
00243   // Shadow Instruction::setInstructionSubclassData with a private forwarding
00244   // method so that subclasses cannot accidentally use it.
00245   void setInstructionSubclassData(unsigned short D) {
00246     Instruction::setInstructionSubclassData(D);
00247   }
00248 };
00249 
00250 
00251 //===----------------------------------------------------------------------===//
00252 //                                StoreInst Class
00253 //===----------------------------------------------------------------------===//
00254 
00255 /// StoreInst - an instruction for storing to memory
00256 ///
00257 class StoreInst : public Instruction {
00258   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
00259   void AssertOK();
00260 protected:
00261   virtual StoreInst *clone_impl() const;
00262 public:
00263   // allocate space for exactly two operands
00264   void *operator new(size_t s) {
00265     return User::operator new(s, 2);
00266   }
00267   StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
00268   StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
00269   StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
00270             Instruction *InsertBefore = 0);
00271   StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
00272   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
00273             unsigned Align, Instruction *InsertBefore = 0);
00274   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
00275             unsigned Align, BasicBlock *InsertAtEnd);
00276   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
00277             unsigned Align, AtomicOrdering Order,
00278             SynchronizationScope SynchScope = CrossThread,
00279             Instruction *InsertBefore = 0);
00280   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
00281             unsigned Align, AtomicOrdering Order,
00282             SynchronizationScope SynchScope,
00283             BasicBlock *InsertAtEnd);
00284 
00285 
00286   /// isVolatile - Return true if this is a store to a volatile memory
00287   /// location.
00288   ///
00289   bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
00290 
00291   /// setVolatile - Specify whether this is a volatile store or not.
00292   ///
00293   void setVolatile(bool V) {
00294     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
00295                                (V ? 1 : 0));
00296   }
00297 
00298   /// Transparently provide more efficient getOperand methods.
00299   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00300 
00301   /// getAlignment - Return the alignment of the access that is being performed
00302   ///
00303   unsigned getAlignment() const {
00304     return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
00305   }
00306 
00307   void setAlignment(unsigned Align);
00308 
00309   /// Returns the ordering effect of this store.
00310   AtomicOrdering getOrdering() const {
00311     return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
00312   }
00313 
00314   /// Set the ordering constraint on this store.  May not be Acquire or
00315   /// AcquireRelease.
00316   void setOrdering(AtomicOrdering Ordering) {
00317     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
00318                                (Ordering << 7));
00319   }
00320 
00321   SynchronizationScope getSynchScope() const {
00322     return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
00323   }
00324 
00325   /// Specify whether this store instruction is ordered with respect to all
00326   /// concurrently executing threads, or only with respect to signal handlers
00327   /// executing in the same thread.
00328   void setSynchScope(SynchronizationScope xthread) {
00329     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
00330                                (xthread << 6));
00331   }
00332 
00333   bool isAtomic() const { return getOrdering() != NotAtomic; }
00334   void setAtomic(AtomicOrdering Ordering,
00335                  SynchronizationScope SynchScope = CrossThread) {
00336     setOrdering(Ordering);
00337     setSynchScope(SynchScope);
00338   }
00339 
00340   bool isSimple() const { return !isAtomic() && !isVolatile(); }
00341   bool isUnordered() const {
00342     return getOrdering() <= Unordered && !isVolatile();
00343   }
00344 
00345   Value *getValueOperand() { return getOperand(0); }
00346   const Value *getValueOperand() const { return getOperand(0); }
00347 
00348   Value *getPointerOperand() { return getOperand(1); }
00349   const Value *getPointerOperand() const { return getOperand(1); }
00350   static unsigned getPointerOperandIndex() { return 1U; }
00351 
00352   /// \brief Returns the address space of the pointer operand.
00353   unsigned getPointerAddressSpace() const {
00354     return getPointerOperand()->getType()->getPointerAddressSpace();
00355   }
00356 
00357   // Methods for support type inquiry through isa, cast, and dyn_cast:
00358   static inline bool classof(const Instruction *I) {
00359     return I->getOpcode() == Instruction::Store;
00360   }
00361   static inline bool classof(const Value *V) {
00362     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00363   }
00364 private:
00365   // Shadow Instruction::setInstructionSubclassData with a private forwarding
00366   // method so that subclasses cannot accidentally use it.
00367   void setInstructionSubclassData(unsigned short D) {
00368     Instruction::setInstructionSubclassData(D);
00369   }
00370 };
00371 
00372 template <>
00373 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
00374 };
00375 
00376 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
00377 
00378 //===----------------------------------------------------------------------===//
00379 //                                FenceInst Class
00380 //===----------------------------------------------------------------------===//
00381 
00382 /// FenceInst - an instruction for ordering other memory operations
00383 ///
00384 class FenceInst : public Instruction {
00385   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
00386   void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
00387 protected:
00388   virtual FenceInst *clone_impl() const;
00389 public:
00390   // allocate space for exactly zero operands
00391   void *operator new(size_t s) {
00392     return User::operator new(s, 0);
00393   }
00394 
00395   // Ordering may only be Acquire, Release, AcquireRelease, or
00396   // SequentiallyConsistent.
00397   FenceInst(LLVMContext &C, AtomicOrdering Ordering,
00398             SynchronizationScope SynchScope = CrossThread,
00399             Instruction *InsertBefore = 0);
00400   FenceInst(LLVMContext &C, AtomicOrdering Ordering,
00401             SynchronizationScope SynchScope,
00402             BasicBlock *InsertAtEnd);
00403 
00404   /// Returns the ordering effect of this fence.
00405   AtomicOrdering getOrdering() const {
00406     return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
00407   }
00408 
00409   /// Set the ordering constraint on this fence.  May only be Acquire, Release,
00410   /// AcquireRelease, or SequentiallyConsistent.
00411   void setOrdering(AtomicOrdering Ordering) {
00412     setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
00413                                (Ordering << 1));
00414   }
00415 
00416   SynchronizationScope getSynchScope() const {
00417     return SynchronizationScope(getSubclassDataFromInstruction() & 1);
00418   }
00419 
00420   /// Specify whether this fence orders other operations with respect to all
00421   /// concurrently executing threads, or only with respect to signal handlers
00422   /// executing in the same thread.
00423   void setSynchScope(SynchronizationScope xthread) {
00424     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
00425                                xthread);
00426   }
00427 
00428   // Methods for support type inquiry through isa, cast, and dyn_cast:
00429   static inline bool classof(const Instruction *I) {
00430     return I->getOpcode() == Instruction::Fence;
00431   }
00432   static inline bool classof(const Value *V) {
00433     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00434   }
00435 private:
00436   // Shadow Instruction::setInstructionSubclassData with a private forwarding
00437   // method so that subclasses cannot accidentally use it.
00438   void setInstructionSubclassData(unsigned short D) {
00439     Instruction::setInstructionSubclassData(D);
00440   }
00441 };
00442 
00443 //===----------------------------------------------------------------------===//
00444 //                                AtomicCmpXchgInst Class
00445 //===----------------------------------------------------------------------===//
00446 
00447 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
00448 /// specified value is in a memory location, and, if it is, stores a new value
00449 /// there.  Returns the value that was loaded.
00450 ///
00451 class AtomicCmpXchgInst : public Instruction {
00452   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
00453   void Init(Value *Ptr, Value *Cmp, Value *NewVal,
00454             AtomicOrdering Ordering, SynchronizationScope SynchScope);
00455 protected:
00456   virtual AtomicCmpXchgInst *clone_impl() const;
00457 public:
00458   // allocate space for exactly three operands
00459   void *operator new(size_t s) {
00460     return User::operator new(s, 3);
00461   }
00462   AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
00463                     AtomicOrdering Ordering, SynchronizationScope SynchScope,
00464                     Instruction *InsertBefore = 0);
00465   AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
00466                     AtomicOrdering Ordering, SynchronizationScope SynchScope,
00467                     BasicBlock *InsertAtEnd);
00468 
00469   /// isVolatile - Return true if this is a cmpxchg from a volatile memory
00470   /// location.
00471   ///
00472   bool isVolatile() const {
00473     return getSubclassDataFromInstruction() & 1;
00474   }
00475 
00476   /// setVolatile - Specify whether this is a volatile cmpxchg.
00477   ///
00478   void setVolatile(bool V) {
00479      setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
00480                                 (unsigned)V);
00481   }
00482 
00483   /// Transparently provide more efficient getOperand methods.
00484   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00485 
00486   /// Set the ordering constraint on this cmpxchg.
00487   void setOrdering(AtomicOrdering Ordering) {
00488     assert(Ordering != NotAtomic &&
00489            "CmpXchg instructions can only be atomic.");
00490     setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
00491                                (Ordering << 2));
00492   }
00493 
00494   /// Specify whether this cmpxchg is atomic and orders other operations with
00495   /// respect to all concurrently executing threads, or only with respect to
00496   /// signal handlers executing in the same thread.
00497   void setSynchScope(SynchronizationScope SynchScope) {
00498     setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
00499                                (SynchScope << 1));
00500   }
00501 
00502   /// Returns the ordering constraint on this cmpxchg.
00503   AtomicOrdering getOrdering() const {
00504     return AtomicOrdering(getSubclassDataFromInstruction() >> 2);
00505   }
00506 
00507   /// Returns whether this cmpxchg is atomic between threads or only within a
00508   /// single thread.
00509   SynchronizationScope getSynchScope() const {
00510     return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
00511   }
00512 
00513   Value *getPointerOperand() { return getOperand(0); }
00514   const Value *getPointerOperand() const { return getOperand(0); }
00515   static unsigned getPointerOperandIndex() { return 0U; }
00516 
00517   Value *getCompareOperand() { return getOperand(1); }
00518   const Value *getCompareOperand() const { return getOperand(1); }
00519 
00520   Value *getNewValOperand() { return getOperand(2); }
00521   const Value *getNewValOperand() const { return getOperand(2); }
00522 
00523   /// \brief Returns the address space of the pointer operand.
00524   unsigned getPointerAddressSpace() const {
00525     return getPointerOperand()->getType()->getPointerAddressSpace();
00526   }
00527 
00528   // Methods for support type inquiry through isa, cast, and dyn_cast:
00529   static inline bool classof(const Instruction *I) {
00530     return I->getOpcode() == Instruction::AtomicCmpXchg;
00531   }
00532   static inline bool classof(const Value *V) {
00533     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00534   }
00535 private:
00536   // Shadow Instruction::setInstructionSubclassData with a private forwarding
00537   // method so that subclasses cannot accidentally use it.
00538   void setInstructionSubclassData(unsigned short D) {
00539     Instruction::setInstructionSubclassData(D);
00540   }
00541 };
00542 
00543 template <>
00544 struct OperandTraits<AtomicCmpXchgInst> :
00545     public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
00546 };
00547 
00548 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
00549 
00550 //===----------------------------------------------------------------------===//
00551 //                                AtomicRMWInst Class
00552 //===----------------------------------------------------------------------===//
00553 
00554 /// AtomicRMWInst - an instruction that atomically reads a memory location,
00555 /// combines it with another value, and then stores the result back.  Returns
00556 /// the old value.
00557 ///
00558 class AtomicRMWInst : public Instruction {
00559   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
00560 protected:
00561   virtual AtomicRMWInst *clone_impl() const;
00562 public:
00563   /// This enumeration lists the possible modifications atomicrmw can make.  In
00564   /// the descriptions, 'p' is the pointer to the instruction's memory location,
00565   /// 'old' is the initial value of *p, and 'v' is the other value passed to the
00566   /// instruction.  These instructions always return 'old'.
00567   enum BinOp {
00568     /// *p = v
00569     Xchg,
00570     /// *p = old + v
00571     Add,
00572     /// *p = old - v
00573     Sub,
00574     /// *p = old & v
00575     And,
00576     /// *p = ~old & v
00577     Nand,
00578     /// *p = old | v
00579     Or,
00580     /// *p = old ^ v
00581     Xor,
00582     /// *p = old >signed v ? old : v
00583     Max,
00584     /// *p = old <signed v ? old : v
00585     Min,
00586     /// *p = old >unsigned v ? old : v
00587     UMax,
00588     /// *p = old <unsigned v ? old : v
00589     UMin,
00590 
00591     FIRST_BINOP = Xchg,
00592     LAST_BINOP = UMin,
00593     BAD_BINOP
00594   };
00595 
00596   // allocate space for exactly two operands
00597   void *operator new(size_t s) {
00598     return User::operator new(s, 2);
00599   }
00600   AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
00601                 AtomicOrdering Ordering, SynchronizationScope SynchScope,
00602                 Instruction *InsertBefore = 0);
00603   AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
00604                 AtomicOrdering Ordering, SynchronizationScope SynchScope,
00605                 BasicBlock *InsertAtEnd);
00606 
00607   BinOp getOperation() const {
00608     return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
00609   }
00610 
00611   void setOperation(BinOp Operation) {
00612     unsigned short SubclassData = getSubclassDataFromInstruction();
00613     setInstructionSubclassData((SubclassData & 31) |
00614                                (Operation << 5));
00615   }
00616 
00617   /// isVolatile - Return true if this is a RMW on a volatile memory location.
00618   ///
00619   bool isVolatile() const {
00620     return getSubclassDataFromInstruction() & 1;
00621   }
00622 
00623   /// setVolatile - Specify whether this is a volatile RMW or not.
00624   ///
00625   void setVolatile(bool V) {
00626      setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
00627                                 (unsigned)V);
00628   }
00629 
00630   /// Transparently provide more efficient getOperand methods.
00631   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00632 
00633   /// Set the ordering constraint on this RMW.
00634   void setOrdering(AtomicOrdering Ordering) {
00635     assert(Ordering != NotAtomic &&
00636            "atomicrmw instructions can only be atomic.");
00637     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
00638                                (Ordering << 2));
00639   }
00640 
00641   /// Specify whether this RMW orders other operations with respect to all
00642   /// concurrently executing threads, or only with respect to signal handlers
00643   /// executing in the same thread.
00644   void setSynchScope(SynchronizationScope SynchScope) {
00645     setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
00646                                (SynchScope << 1));
00647   }
00648 
00649   /// Returns the ordering constraint on this RMW.
00650   AtomicOrdering getOrdering() const {
00651     return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
00652   }
00653 
00654   /// Returns whether this RMW is atomic between threads or only within a
00655   /// single thread.
00656   SynchronizationScope getSynchScope() const {
00657     return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
00658   }
00659 
00660   Value *getPointerOperand() { return getOperand(0); }
00661   const Value *getPointerOperand() const { return getOperand(0); }
00662   static unsigned getPointerOperandIndex() { return 0U; }
00663 
00664   Value *getValOperand() { return getOperand(1); }
00665   const Value *getValOperand() const { return getOperand(1); }
00666 
00667   /// \brief Returns the address space of the pointer operand.
00668   unsigned getPointerAddressSpace() const {
00669     return getPointerOperand()->getType()->getPointerAddressSpace();
00670   }
00671 
00672   // Methods for support type inquiry through isa, cast, and dyn_cast:
00673   static inline bool classof(const Instruction *I) {
00674     return I->getOpcode() == Instruction::AtomicRMW;
00675   }
00676   static inline bool classof(const Value *V) {
00677     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00678   }
00679 private:
00680   void Init(BinOp Operation, Value *Ptr, Value *Val,
00681             AtomicOrdering Ordering, SynchronizationScope SynchScope);
00682   // Shadow Instruction::setInstructionSubclassData with a private forwarding
00683   // method so that subclasses cannot accidentally use it.
00684   void setInstructionSubclassData(unsigned short D) {
00685     Instruction::setInstructionSubclassData(D);
00686   }
00687 };
00688 
00689 template <>
00690 struct OperandTraits<AtomicRMWInst>
00691     : public FixedNumOperandTraits<AtomicRMWInst,2> {
00692 };
00693 
00694 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
00695 
00696 //===----------------------------------------------------------------------===//
00697 //                             GetElementPtrInst Class
00698 //===----------------------------------------------------------------------===//
00699 
00700 // checkGEPType - Simple wrapper function to give a better assertion failure
00701 // message on bad indexes for a gep instruction.
00702 //
00703 inline Type *checkGEPType(Type *Ty) {
00704   assert(Ty && "Invalid GetElementPtrInst indices for type!");
00705   return Ty;
00706 }
00707 
00708 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
00709 /// access elements of arrays and structs
00710 ///
00711 class GetElementPtrInst : public Instruction {
00712   GetElementPtrInst(const GetElementPtrInst &GEPI);
00713   void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
00714 
00715   /// Constructors - Create a getelementptr instruction with a base pointer an
00716   /// list of indices. The first ctor can optionally insert before an existing
00717   /// instruction, the second appends the new instruction to the specified
00718   /// BasicBlock.
00719   inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
00720                            unsigned Values, const Twine &NameStr,
00721                            Instruction *InsertBefore);
00722   inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
00723                            unsigned Values, const Twine &NameStr,
00724                            BasicBlock *InsertAtEnd);
00725 protected:
00726   virtual GetElementPtrInst *clone_impl() const;
00727 public:
00728   static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
00729                                    const Twine &NameStr = "",
00730                                    Instruction *InsertBefore = 0) {
00731     unsigned Values = 1 + unsigned(IdxList.size());
00732     return new(Values)
00733       GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
00734   }
00735   static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
00736                                    const Twine &NameStr,
00737                                    BasicBlock *InsertAtEnd) {
00738     unsigned Values = 1 + unsigned(IdxList.size());
00739     return new(Values)
00740       GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
00741   }
00742 
00743   /// Create an "inbounds" getelementptr. See the documentation for the
00744   /// "inbounds" flag in LangRef.html for details.
00745   static GetElementPtrInst *CreateInBounds(Value *Ptr,
00746                                            ArrayRef<Value *> IdxList,
00747                                            const Twine &NameStr = "",
00748                                            Instruction *InsertBefore = 0) {
00749     GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
00750     GEP->setIsInBounds(true);
00751     return GEP;
00752   }
00753   static GetElementPtrInst *CreateInBounds(Value *Ptr,
00754                                            ArrayRef<Value *> IdxList,
00755                                            const Twine &NameStr,
00756                                            BasicBlock *InsertAtEnd) {
00757     GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
00758     GEP->setIsInBounds(true);
00759     return GEP;
00760   }
00761 
00762   /// Transparently provide more efficient getOperand methods.
00763   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00764 
00765   // getType - Overload to return most specific sequential type.
00766   SequentialType *getType() const {
00767     return cast<SequentialType>(Instruction::getType());
00768   }
00769 
00770   /// \brief Returns the address space of this instruction's pointer type.
00771   unsigned getAddressSpace() const {
00772     // Note that this is always the same as the pointer operand's address space
00773     // and that is cheaper to compute, so cheat here.
00774     return getPointerAddressSpace();
00775   }
00776 
00777   /// getIndexedType - Returns the type of the element that would be loaded with
00778   /// a load instruction with the specified parameters.
00779   ///
00780   /// Null is returned if the indices are invalid for the specified
00781   /// pointer type.
00782   ///
00783   static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
00784   static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
00785   static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
00786 
00787   inline op_iterator       idx_begin()       { return op_begin()+1; }
00788   inline const_op_iterator idx_begin() const { return op_begin()+1; }
00789   inline op_iterator       idx_end()         { return op_end(); }
00790   inline const_op_iterator idx_end()   const { return op_end(); }
00791 
00792   Value *getPointerOperand() {
00793     return getOperand(0);
00794   }
00795   const Value *getPointerOperand() const {
00796     return getOperand(0);
00797   }
00798   static unsigned getPointerOperandIndex() {
00799     return 0U;    // get index for modifying correct operand.
00800   }
00801 
00802   /// getPointerOperandType - Method to return the pointer operand as a
00803   /// PointerType.
00804   Type *getPointerOperandType() const {
00805     return getPointerOperand()->getType();
00806   }
00807 
00808   /// \brief Returns the address space of the pointer operand.
00809   unsigned getPointerAddressSpace() const {
00810     return getPointerOperandType()->getPointerAddressSpace();
00811   }
00812 
00813   /// GetGEPReturnType - Returns the pointer type returned by the GEP
00814   /// instruction, which may be a vector of pointers.
00815   static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
00816     Type *PtrTy = PointerType::get(checkGEPType(
00817                                    getIndexedType(Ptr->getType(), IdxList)),
00818                                    Ptr->getType()->getPointerAddressSpace());
00819     // Vector GEP
00820     if (Ptr->getType()->isVectorTy()) {
00821       unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements();
00822       return VectorType::get(PtrTy, NumElem);
00823     }
00824 
00825     // Scalar GEP
00826     return PtrTy;
00827   }
00828 
00829   unsigned getNumIndices() const {  // Note: always non-negative
00830     return getNumOperands() - 1;
00831   }
00832 
00833   bool hasIndices() const {
00834     return getNumOperands() > 1;
00835   }
00836 
00837   /// hasAllZeroIndices - Return true if all of the indices of this GEP are
00838   /// zeros.  If so, the result pointer and the first operand have the same
00839   /// value, just potentially different types.
00840   bool hasAllZeroIndices() const;
00841 
00842   /// hasAllConstantIndices - Return true if all of the indices of this GEP are
00843   /// constant integers.  If so, the result pointer and the first operand have
00844   /// a constant offset between them.
00845   bool hasAllConstantIndices() const;
00846 
00847   /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
00848   /// See LangRef.html for the meaning of inbounds on a getelementptr.
00849   void setIsInBounds(bool b = true);
00850 
00851   /// isInBounds - Determine whether the GEP has the inbounds flag.
00852   bool isInBounds() const;
00853 
00854   /// \brief Accumulate the constant address offset of this GEP if possible.
00855   ///
00856   /// This routine accepts an APInt into which it will accumulate the constant
00857   /// offset of this GEP if the GEP is in fact constant. If the GEP is not
00858   /// all-constant, it returns false and the value of the offset APInt is
00859   /// undefined (it is *not* preserved!). The APInt passed into this routine
00860   /// must be at least as wide as the IntPtr type for the address space of
00861   /// the base GEP pointer.
00862   bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
00863 
00864   // Methods for support type inquiry through isa, cast, and dyn_cast:
00865   static inline bool classof(const Instruction *I) {
00866     return (I->getOpcode() == Instruction::GetElementPtr);
00867   }
00868   static inline bool classof(const Value *V) {
00869     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00870   }
00871 };
00872 
00873 template <>
00874 struct OperandTraits<GetElementPtrInst> :
00875   public VariadicOperandTraits<GetElementPtrInst, 1> {
00876 };
00877 
00878 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
00879                                      ArrayRef<Value *> IdxList,
00880                                      unsigned Values,
00881                                      const Twine &NameStr,
00882                                      Instruction *InsertBefore)
00883   : Instruction(getGEPReturnType(Ptr, IdxList),
00884                 GetElementPtr,
00885                 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
00886                 Values, InsertBefore) {
00887   init(Ptr, IdxList, NameStr);
00888 }
00889 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
00890                                      ArrayRef<Value *> IdxList,
00891                                      unsigned Values,
00892                                      const Twine &NameStr,
00893                                      BasicBlock *InsertAtEnd)
00894   : Instruction(getGEPReturnType(Ptr, IdxList),
00895                 GetElementPtr,
00896                 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
00897                 Values, InsertAtEnd) {
00898   init(Ptr, IdxList, NameStr);
00899 }
00900 
00901 
00902 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
00903 
00904 
00905 //===----------------------------------------------------------------------===//
00906 //                               ICmpInst Class
00907 //===----------------------------------------------------------------------===//
00908 
00909 /// This instruction compares its operands according to the predicate given
00910 /// to the constructor. It only operates on integers or pointers. The operands
00911 /// must be identical types.
00912 /// \brief Represent an integer comparison operator.
00913 class ICmpInst: public CmpInst {
00914 protected:
00915   /// \brief Clone an identical ICmpInst
00916   virtual ICmpInst *clone_impl() const;
00917 public:
00918   /// \brief Constructor with insert-before-instruction semantics.
00919   ICmpInst(
00920     Instruction *InsertBefore,  ///< Where to insert
00921     Predicate pred,  ///< The predicate to use for the comparison
00922     Value *LHS,      ///< The left-hand-side of the expression
00923     Value *RHS,      ///< The right-hand-side of the expression
00924     const Twine &NameStr = ""  ///< Name of the instruction
00925   ) : CmpInst(makeCmpResultType(LHS->getType()),
00926               Instruction::ICmp, pred, LHS, RHS, NameStr,
00927               InsertBefore) {
00928     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
00929            pred <= CmpInst::LAST_ICMP_PREDICATE &&
00930            "Invalid ICmp predicate value");
00931     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
00932           "Both operands to ICmp instruction are not of the same type!");
00933     // Check that the operands are the right type
00934     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
00935             getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
00936            "Invalid operand types for ICmp instruction");
00937   }
00938 
00939   /// \brief Constructor with insert-at-end semantics.
00940   ICmpInst(
00941     BasicBlock &InsertAtEnd, ///< Block to insert into.
00942     Predicate pred,  ///< The predicate to use for the comparison
00943     Value *LHS,      ///< The left-hand-side of the expression
00944     Value *RHS,      ///< The right-hand-side of the expression
00945     const Twine &NameStr = ""  ///< Name of the instruction
00946   ) : CmpInst(makeCmpResultType(LHS->getType()),
00947               Instruction::ICmp, pred, LHS, RHS, NameStr,
00948               &InsertAtEnd) {
00949     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
00950           pred <= CmpInst::LAST_ICMP_PREDICATE &&
00951           "Invalid ICmp predicate value");
00952     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
00953           "Both operands to ICmp instruction are not of the same type!");
00954     // Check that the operands are the right type
00955     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
00956             getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
00957            "Invalid operand types for ICmp instruction");
00958   }
00959 
00960   /// \brief Constructor with no-insertion semantics
00961   ICmpInst(
00962     Predicate pred, ///< The predicate to use for the comparison
00963     Value *LHS,     ///< The left-hand-side of the expression
00964     Value *RHS,     ///< The right-hand-side of the expression
00965     const Twine &NameStr = "" ///< Name of the instruction
00966   ) : CmpInst(makeCmpResultType(LHS->getType()),
00967               Instruction::ICmp, pred, LHS, RHS, NameStr) {
00968     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
00969            pred <= CmpInst::LAST_ICMP_PREDICATE &&
00970            "Invalid ICmp predicate value");
00971     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
00972           "Both operands to ICmp instruction are not of the same type!");
00973     // Check that the operands are the right type
00974     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
00975             getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
00976            "Invalid operand types for ICmp instruction");
00977   }
00978 
00979   /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
00980   /// @returns the predicate that would be the result if the operand were
00981   /// regarded as signed.
00982   /// \brief Return the signed version of the predicate
00983   Predicate getSignedPredicate() const {
00984     return getSignedPredicate(getPredicate());
00985   }
00986 
00987   /// This is a static version that you can use without an instruction.
00988   /// \brief Return the signed version of the predicate.
00989   static Predicate getSignedPredicate(Predicate pred);
00990 
00991   /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
00992   /// @returns the predicate that would be the result if the operand were
00993   /// regarded as unsigned.
00994   /// \brief Return the unsigned version of the predicate
00995   Predicate getUnsignedPredicate() const {
00996     return getUnsignedPredicate(getPredicate());
00997   }
00998 
00999   /// This is a static version that you can use without an instruction.
01000   /// \brief Return the unsigned version of the predicate.
01001   static Predicate getUnsignedPredicate(Predicate pred);
01002 
01003   /// isEquality - Return true if this predicate is either EQ or NE.  This also
01004   /// tests for commutativity.
01005   static bool isEquality(Predicate P) {
01006     return P == ICMP_EQ || P == ICMP_NE;
01007   }
01008 
01009   /// isEquality - Return true if this predicate is either EQ or NE.  This also
01010   /// tests for commutativity.
01011   bool isEquality() const {
01012     return isEquality(getPredicate());
01013   }
01014 
01015   /// @returns true if the predicate of this ICmpInst is commutative
01016   /// \brief Determine if this relation is commutative.
01017   bool isCommutative() const { return isEquality(); }
01018 
01019   /// isRelational - Return true if the predicate is relational (not EQ or NE).
01020   ///
01021   bool isRelational() const {
01022     return !isEquality();
01023   }
01024 
01025   /// isRelational - Return true if the predicate is relational (not EQ or NE).
01026   ///
01027   static bool isRelational(Predicate P) {
01028     return !isEquality(P);
01029   }
01030 
01031   /// Initialize a set of values that all satisfy the predicate with C.
01032   /// \brief Make a ConstantRange for a relation with a constant value.
01033   static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
01034 
01035   /// Exchange the two operands to this instruction in such a way that it does
01036   /// not modify the semantics of the instruction. The predicate value may be
01037   /// changed to retain the same result if the predicate is order dependent
01038   /// (e.g. ult).
01039   /// \brief Swap operands and adjust predicate.
01040   void swapOperands() {
01041     setPredicate(getSwappedPredicate());
01042     Op<0>().swap(Op<1>());
01043   }
01044 
01045   // Methods for support type inquiry through isa, cast, and dyn_cast:
01046   static inline bool classof(const Instruction *I) {
01047     return I->getOpcode() == Instruction::ICmp;
01048   }
01049   static inline bool classof(const Value *V) {
01050     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01051   }
01052 
01053 };
01054 
01055 //===----------------------------------------------------------------------===//
01056 //                               FCmpInst Class
01057 //===----------------------------------------------------------------------===//
01058 
01059 /// This instruction compares its operands according to the predicate given
01060 /// to the constructor. It only operates on floating point values or packed
01061 /// vectors of floating point values. The operands must be identical types.
01062 /// \brief Represents a floating point comparison operator.
01063 class FCmpInst: public CmpInst {
01064 protected:
01065   /// \brief Clone an identical FCmpInst
01066   virtual FCmpInst *clone_impl() const;
01067 public:
01068   /// \brief Constructor with insert-before-instruction semantics.
01069   FCmpInst(
01070     Instruction *InsertBefore, ///< Where to insert
01071     Predicate pred,  ///< The predicate to use for the comparison
01072     Value *LHS,      ///< The left-hand-side of the expression
01073     Value *RHS,      ///< The right-hand-side of the expression
01074     const Twine &NameStr = ""  ///< Name of the instruction
01075   ) : CmpInst(makeCmpResultType(LHS->getType()),
01076               Instruction::FCmp, pred, LHS, RHS, NameStr,
01077               InsertBefore) {
01078     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
01079            "Invalid FCmp predicate value");
01080     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
01081            "Both operands to FCmp instruction are not of the same type!");
01082     // Check that the operands are the right type
01083     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
01084            "Invalid operand types for FCmp instruction");
01085   }
01086 
01087   /// \brief Constructor with insert-at-end semantics.
01088   FCmpInst(
01089     BasicBlock &InsertAtEnd, ///< Block to insert into.
01090     Predicate pred,  ///< The predicate to use for the comparison
01091     Value *LHS,      ///< The left-hand-side of the expression
01092     Value *RHS,      ///< The right-hand-side of the expression
01093     const Twine &NameStr = ""  ///< Name of the instruction
01094   ) : CmpInst(makeCmpResultType(LHS->getType()),
01095               Instruction::FCmp, pred, LHS, RHS, NameStr,
01096               &InsertAtEnd) {
01097     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
01098            "Invalid FCmp predicate value");
01099     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
01100            "Both operands to FCmp instruction are not of the same type!");
01101     // Check that the operands are the right type
01102     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
01103            "Invalid operand types for FCmp instruction");
01104   }
01105 
01106   /// \brief Constructor with no-insertion semantics
01107   FCmpInst(
01108     Predicate pred, ///< The predicate to use for the comparison
01109     Value *LHS,     ///< The left-hand-side of the expression
01110     Value *RHS,     ///< The right-hand-side of the expression
01111     const Twine &NameStr = "" ///< Name of the instruction
01112   ) : CmpInst(makeCmpResultType(LHS->getType()),
01113               Instruction::FCmp, pred, LHS, RHS, NameStr) {
01114     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
01115            "Invalid FCmp predicate value");
01116     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
01117            "Both operands to FCmp instruction are not of the same type!");
01118     // Check that the operands are the right type
01119     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
01120            "Invalid operand types for FCmp instruction");
01121   }
01122 
01123   /// @returns true if the predicate of this instruction is EQ or NE.
01124   /// \brief Determine if this is an equality predicate.
01125   bool isEquality() const {
01126     return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
01127            getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
01128   }
01129 
01130   /// @returns true if the predicate of this instruction is commutative.
01131   /// \brief Determine if this is a commutative predicate.
01132   bool isCommutative() const {
01133     return isEquality() ||
01134            getPredicate() == FCMP_FALSE ||
01135            getPredicate() == FCMP_TRUE ||
01136            getPredicate() == FCMP_ORD ||
01137            getPredicate() == FCMP_UNO;
01138   }
01139 
01140   /// @returns true if the predicate is relational (not EQ or NE).
01141   /// \brief Determine if this a relational predicate.
01142   bool isRelational() const { return !isEquality(); }
01143 
01144   /// Exchange the two operands to this instruction in such a way that it does
01145   /// not modify the semantics of the instruction. The predicate value may be
01146   /// changed to retain the same result if the predicate is order dependent
01147   /// (e.g. ult).
01148   /// \brief Swap operands and adjust predicate.
01149   void swapOperands() {
01150     setPredicate(getSwappedPredicate());
01151     Op<0>().swap(Op<1>());
01152   }
01153 
01154   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
01155   static inline bool classof(const Instruction *I) {
01156     return I->getOpcode() == Instruction::FCmp;
01157   }
01158   static inline bool classof(const Value *V) {
01159     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01160   }
01161 };
01162 
01163 //===----------------------------------------------------------------------===//
01164 /// CallInst - This class represents a function call, abstracting a target
01165 /// machine's calling convention.  This class uses low bit of the SubClassData
01166 /// field to indicate whether or not this is a tail call.  The rest of the bits
01167 /// hold the calling convention of the call.
01168 ///
01169 class CallInst : public Instruction {
01170   AttributeSet AttributeList; ///< parameter attributes for call
01171   CallInst(const CallInst &CI);
01172   void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
01173   void init(Value *Func, const Twine &NameStr);
01174 
01175   /// Construct a CallInst given a range of arguments.
01176   /// \brief Construct a CallInst from a range of arguments
01177   inline CallInst(Value *Func, ArrayRef<Value *> Args,
01178                   const Twine &NameStr, Instruction *InsertBefore);
01179 
01180   /// Construct a CallInst given a range of arguments.
01181   /// \brief Construct a CallInst from a range of arguments
01182   inline CallInst(Value *Func, ArrayRef<Value *> Args,
01183                   const Twine &NameStr, BasicBlock *InsertAtEnd);
01184 
01185   CallInst(Value *F, Value *Actual, const Twine &NameStr,
01186            Instruction *InsertBefore);
01187   CallInst(Value *F, Value *Actual, const Twine &NameStr,
01188            BasicBlock *InsertAtEnd);
01189   explicit CallInst(Value *F, const Twine &NameStr,
01190                     Instruction *InsertBefore);
01191   CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
01192 protected:
01193   virtual CallInst *clone_impl() const;
01194 public:
01195   static CallInst *Create(Value *Func,
01196                           ArrayRef<Value *> Args,
01197                           const Twine &NameStr = "",
01198                           Instruction *InsertBefore = 0) {
01199     return new(unsigned(Args.size() + 1))
01200       CallInst(Func, Args, NameStr, InsertBefore);
01201   }
01202   static CallInst *Create(Value *Func,
01203                           ArrayRef<Value *> Args,
01204                           const Twine &NameStr, BasicBlock *InsertAtEnd) {
01205     return new(unsigned(Args.size() + 1))
01206       CallInst(Func, Args, NameStr, InsertAtEnd);
01207   }
01208   static CallInst *Create(Value *F, const Twine &NameStr = "",
01209                           Instruction *InsertBefore = 0) {
01210     return new(1) CallInst(F, NameStr, InsertBefore);
01211   }
01212   static CallInst *Create(Value *F, const Twine &NameStr,
01213                           BasicBlock *InsertAtEnd) {
01214     return new(1) CallInst(F, NameStr, InsertAtEnd);
01215   }
01216   /// CreateMalloc - Generate the IR for a call to malloc:
01217   /// 1. Compute the malloc call's argument as the specified type's size,
01218   ///    possibly multiplied by the array size if the array size is not
01219   ///    constant 1.
01220   /// 2. Call malloc with that argument.
01221   /// 3. Bitcast the result of the malloc call to the specified type.
01222   static Instruction *CreateMalloc(Instruction *InsertBefore,
01223                                    Type *IntPtrTy, Type *AllocTy,
01224                                    Value *AllocSize, Value *ArraySize = 0,
01225                                    Function* MallocF = 0,
01226                                    const Twine &Name = "");
01227   static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
01228                                    Type *IntPtrTy, Type *AllocTy,
01229                                    Value *AllocSize, Value *ArraySize = 0,
01230                                    Function* MallocF = 0,
01231                                    const Twine &Name = "");
01232   /// CreateFree - Generate the IR for a call to the builtin free function.
01233   static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
01234   static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
01235 
01236   ~CallInst();
01237 
01238   bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
01239   void setTailCall(bool isTC = true) {
01240     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
01241                                unsigned(isTC));
01242   }
01243 
01244   /// Provide fast operand accessors
01245   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01246 
01247   /// getNumArgOperands - Return the number of call arguments.
01248   ///
01249   unsigned getNumArgOperands() const { return getNumOperands() - 1; }
01250 
01251   /// getArgOperand/setArgOperand - Return/set the i-th call argument.
01252   ///
01253   Value *getArgOperand(unsigned i) const { return getOperand(i); }
01254   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
01255 
01256   /// getCallingConv/setCallingConv - Get or set the calling convention of this
01257   /// function call.
01258   CallingConv::ID getCallingConv() const {
01259     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
01260   }
01261   void setCallingConv(CallingConv::ID CC) {
01262     setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
01263                                (static_cast<unsigned>(CC) << 1));
01264   }
01265 
01266   /// getAttributes - Return the parameter attributes for this call.
01267   ///
01268   const AttributeSet &getAttributes() const { return AttributeList; }
01269 
01270   /// setAttributes - Set the parameter attributes for this call.
01271   ///
01272   void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
01273 
01274   /// addAttribute - adds the attribute to the list of attributes.
01275   void addAttribute(unsigned i, Attribute::AttrKind attr);
01276 
01277   /// removeAttribute - removes the attribute from the list of attributes.
01278   void removeAttribute(unsigned i, Attribute attr);
01279 
01280   /// \brief Determine whether this call has the given attribute.
01281   bool hasFnAttr(Attribute::AttrKind A) const;
01282 
01283   /// \brief Determine whether the call or the callee has the given attributes.
01284   bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
01285 
01286   /// \brief Extract the alignment for a call or parameter (0=unknown).
01287   unsigned getParamAlignment(unsigned i) const {
01288     return AttributeList.getParamAlignment(i);
01289   }
01290 
01291   /// \brief Return true if the call should not be inlined.
01292   bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
01293   void setIsNoInline() {
01294     addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
01295   }
01296 
01297   /// \brief Return true if the call can return twice
01298   bool canReturnTwice() const {
01299     return hasFnAttr(Attribute::ReturnsTwice);
01300   }
01301   void setCanReturnTwice() {
01302     addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
01303   }
01304 
01305   /// \brief Determine if the call does not access memory.
01306   bool doesNotAccessMemory() const {
01307     return hasFnAttr(Attribute::ReadNone);
01308   }
01309   void setDoesNotAccessMemory() {
01310     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
01311   }
01312 
01313   /// \brief Determine if the call does not access or only reads memory.
01314   bool onlyReadsMemory() const {
01315     return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
01316   }
01317   void setOnlyReadsMemory() {
01318     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
01319   }
01320 
01321   /// \brief Determine if the call cannot return.
01322   bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
01323   void setDoesNotReturn() {
01324     addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
01325   }
01326 
01327   /// \brief Determine if the call cannot unwind.
01328   bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
01329   void setDoesNotThrow() {
01330     addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
01331   }
01332 
01333   /// \brief Determine if the call cannot be duplicated.
01334   bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
01335   void setCannotDuplicate() {
01336     addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
01337   }
01338 
01339   /// \brief Determine if the call returns a structure through first
01340   /// pointer argument.
01341   bool hasStructRetAttr() const {
01342     // Be friendly and also check the callee.
01343     return paramHasAttr(1, Attribute::StructRet);
01344   }
01345 
01346   /// \brief Determine if any call argument is an aggregate passed by value.
01347   bool hasByValArgument() const {
01348     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
01349   }
01350 
01351   /// getCalledFunction - Return the function called, or null if this is an
01352   /// indirect function invocation.
01353   ///
01354   Function *getCalledFunction() const {
01355     return dyn_cast<Function>(Op<-1>());
01356   }
01357 
01358   /// getCalledValue - Get a pointer to the function that is invoked by this
01359   /// instruction.
01360   const Value *getCalledValue() const { return Op<-1>(); }
01361         Value *getCalledValue()       { return Op<-1>(); }
01362 
01363   /// setCalledFunction - Set the function called.
01364   void setCalledFunction(Value* Fn) {
01365     Op<-1>() = Fn;
01366   }
01367 
01368   /// isInlineAsm - Check if this call is an inline asm statement.
01369   bool isInlineAsm() const {
01370     return isa<InlineAsm>(Op<-1>());
01371   }
01372 
01373   // Methods for support type inquiry through isa, cast, and dyn_cast:
01374   static inline bool classof(const Instruction *I) {
01375     return I->getOpcode() == Instruction::Call;
01376   }
01377   static inline bool classof(const Value *V) {
01378     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01379   }
01380 private:
01381   // Shadow Instruction::setInstructionSubclassData with a private forwarding
01382   // method so that subclasses cannot accidentally use it.
01383   void setInstructionSubclassData(unsigned short D) {
01384     Instruction::setInstructionSubclassData(D);
01385   }
01386 };
01387 
01388 template <>
01389 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
01390 };
01391 
01392 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
01393                    const Twine &NameStr, BasicBlock *InsertAtEnd)
01394   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
01395                                    ->getElementType())->getReturnType(),
01396                 Instruction::Call,
01397                 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
01398                 unsigned(Args.size() + 1), InsertAtEnd) {
01399   init(Func, Args, NameStr);
01400 }
01401 
01402 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
01403                    const Twine &NameStr, Instruction *InsertBefore)
01404   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
01405                                    ->getElementType())->getReturnType(),
01406                 Instruction::Call,
01407                 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
01408                 unsigned(Args.size() + 1), InsertBefore) {
01409   init(Func, Args, NameStr);
01410 }
01411 
01412 
01413 // Note: if you get compile errors about private methods then
01414 //       please update your code to use the high-level operand
01415 //       interfaces. See line 943 above.
01416 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
01417 
01418 //===----------------------------------------------------------------------===//
01419 //                               SelectInst Class
01420 //===----------------------------------------------------------------------===//
01421 
01422 /// SelectInst - This class represents the LLVM 'select' instruction.
01423 ///
01424 class SelectInst : public Instruction {
01425   void init(Value *C, Value *S1, Value *S2) {
01426     assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
01427     Op<0>() = C;
01428     Op<1>() = S1;
01429     Op<2>() = S2;
01430   }
01431 
01432   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
01433              Instruction *InsertBefore)
01434     : Instruction(S1->getType(), Instruction::Select,
01435                   &Op<0>(), 3, InsertBefore) {
01436     init(C, S1, S2);
01437     setName(NameStr);
01438   }
01439   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
01440              BasicBlock *InsertAtEnd)
01441     : Instruction(S1->getType(), Instruction::Select,
01442                   &Op<0>(), 3, InsertAtEnd) {
01443     init(C, S1, S2);
01444     setName(NameStr);
01445   }
01446 protected:
01447   virtual SelectInst *clone_impl() const;
01448 public:
01449   static SelectInst *Create(Value *C, Value *S1, Value *S2,
01450                             const Twine &NameStr = "",
01451                             Instruction *InsertBefore = 0) {
01452     return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
01453   }
01454   static SelectInst *Create(Value *C, Value *S1, Value *S2,
01455                             const Twine &NameStr,
01456                             BasicBlock *InsertAtEnd) {
01457     return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
01458   }
01459 
01460   const Value *getCondition() const { return Op<0>(); }
01461   const Value *getTrueValue() const { return Op<1>(); }
01462   const Value *getFalseValue() const { return Op<2>(); }
01463   Value *getCondition() { return Op<0>(); }
01464   Value *getTrueValue() { return Op<1>(); }
01465   Value *getFalseValue() { return Op<2>(); }
01466 
01467   /// areInvalidOperands - Return a string if the specified operands are invalid
01468   /// for a select operation, otherwise return null.
01469   static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
01470 
01471   /// Transparently provide more efficient getOperand methods.
01472   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01473 
01474   OtherOps getOpcode() const {
01475     return static_cast<OtherOps>(Instruction::getOpcode());
01476   }
01477 
01478   // Methods for support type inquiry through isa, cast, and dyn_cast:
01479   static inline bool classof(const Instruction *I) {
01480     return I->getOpcode() == Instruction::Select;
01481   }
01482   static inline bool classof(const Value *V) {
01483     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01484   }
01485 };
01486 
01487 template <>
01488 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
01489 };
01490 
01491 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
01492 
01493 //===----------------------------------------------------------------------===//
01494 //                                VAArgInst Class
01495 //===----------------------------------------------------------------------===//
01496 
01497 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
01498 /// an argument of the specified type given a va_list and increments that list
01499 ///
01500 class VAArgInst : public UnaryInstruction {
01501 protected:
01502   virtual VAArgInst *clone_impl() const;
01503 
01504 public:
01505   VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
01506              Instruction *InsertBefore = 0)
01507     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
01508     setName(NameStr);
01509   }
01510   VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
01511             BasicBlock *InsertAtEnd)
01512     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
01513     setName(NameStr);
01514   }
01515 
01516   Value *getPointerOperand() { return getOperand(0); }
01517   const Value *getPointerOperand() const { return getOperand(0); }
01518   static unsigned getPointerOperandIndex() { return 0U; }
01519 
01520   // Methods for support type inquiry through isa, cast, and dyn_cast:
01521   static inline bool classof(const Instruction *I) {
01522     return I->getOpcode() == VAArg;
01523   }
01524   static inline bool classof(const Value *V) {
01525     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01526   }
01527 };
01528 
01529 //===----------------------------------------------------------------------===//
01530 //                                ExtractElementInst Class
01531 //===----------------------------------------------------------------------===//
01532 
01533 /// ExtractElementInst - This instruction extracts a single (scalar)
01534 /// element from a VectorType value
01535 ///
01536 class ExtractElementInst : public Instruction {
01537   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
01538                      Instruction *InsertBefore = 0);
01539   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
01540                      BasicBlock *InsertAtEnd);
01541 protected:
01542   virtual ExtractElementInst *clone_impl() const;
01543 
01544 public:
01545   static ExtractElementInst *Create(Value *Vec, Value *Idx,
01546                                    const Twine &NameStr = "",
01547                                    Instruction *InsertBefore = 0) {
01548     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
01549   }
01550   static ExtractElementInst *Create(Value *Vec, Value *Idx,
01551                                    const Twine &NameStr,
01552                                    BasicBlock *InsertAtEnd) {
01553     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
01554   }
01555 
01556   /// isValidOperands - Return true if an extractelement instruction can be
01557   /// formed with the specified operands.
01558   static bool isValidOperands(const Value *Vec, const Value *Idx);
01559 
01560   Value *getVectorOperand() { return Op<0>(); }
01561   Value *getIndexOperand() { return Op<1>(); }
01562   const Value *getVectorOperand() const { return Op<0>(); }
01563   const Value *getIndexOperand() const { return Op<1>(); }
01564 
01565   VectorType *getVectorOperandType() const {
01566     return cast<VectorType>(getVectorOperand()->getType());
01567   }
01568 
01569 
01570   /// Transparently provide more efficient getOperand methods.
01571   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01572 
01573   // Methods for support type inquiry through isa, cast, and dyn_cast:
01574   static inline bool classof(const Instruction *I) {
01575     return I->getOpcode() == Instruction::ExtractElement;
01576   }
01577   static inline bool classof(const Value *V) {
01578     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01579   }
01580 };
01581 
01582 template <>
01583 struct OperandTraits<ExtractElementInst> :
01584   public FixedNumOperandTraits<ExtractElementInst, 2> {
01585 };
01586 
01587 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
01588 
01589 //===----------------------------------------------------------------------===//
01590 //                                InsertElementInst Class
01591 //===----------------------------------------------------------------------===//
01592 
01593 /// InsertElementInst - This instruction inserts a single (scalar)
01594 /// element into a VectorType value
01595 ///
01596 class InsertElementInst : public Instruction {
01597   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
01598                     const Twine &NameStr = "",
01599                     Instruction *InsertBefore = 0);
01600   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
01601                     const Twine &NameStr, BasicBlock *InsertAtEnd);
01602 protected:
01603   virtual InsertElementInst *clone_impl() const;
01604 
01605 public:
01606   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
01607                                    const Twine &NameStr = "",
01608                                    Instruction *InsertBefore = 0) {
01609     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
01610   }
01611   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
01612                                    const Twine &NameStr,
01613                                    BasicBlock *InsertAtEnd) {
01614     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
01615   }
01616 
01617   /// isValidOperands - Return true if an insertelement instruction can be
01618   /// formed with the specified operands.
01619   static bool isValidOperands(const Value *Vec, const Value *NewElt,
01620                               const Value *Idx);
01621 
01622   /// getType - Overload to return most specific vector type.
01623   ///
01624   VectorType *getType() const {
01625     return cast<VectorType>(Instruction::getType());
01626   }
01627 
01628   /// Transparently provide more efficient getOperand methods.
01629   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01630 
01631   // Methods for support type inquiry through isa, cast, and dyn_cast:
01632   static inline bool classof(const Instruction *I) {
01633     return I->getOpcode() == Instruction::InsertElement;
01634   }
01635   static inline bool classof(const Value *V) {
01636     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01637   }
01638 };
01639 
01640 template <>
01641 struct OperandTraits<InsertElementInst> :
01642   public FixedNumOperandTraits<InsertElementInst, 3> {
01643 };
01644 
01645 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
01646 
01647 //===----------------------------------------------------------------------===//
01648 //                           ShuffleVectorInst Class
01649 //===----------------------------------------------------------------------===//
01650 
01651 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
01652 /// input vectors.
01653 ///
01654 class ShuffleVectorInst : public Instruction {
01655 protected:
01656   virtual ShuffleVectorInst *clone_impl() const;
01657 
01658 public:
01659   // allocate space for exactly three operands
01660   void *operator new(size_t s) {
01661     return User::operator new(s, 3);
01662   }
01663   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
01664                     const Twine &NameStr = "",
01665                     Instruction *InsertBefor = 0);
01666   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
01667                     const Twine &NameStr, BasicBlock *InsertAtEnd);
01668 
01669   /// isValidOperands - Return true if a shufflevector instruction can be
01670   /// formed with the specified operands.
01671   static bool isValidOperands(const Value *V1, const Value *V2,
01672                               const Value *Mask);
01673 
01674   /// getType - Overload to return most specific vector type.
01675   ///
01676   VectorType *getType() const {
01677     return cast<VectorType>(Instruction::getType());
01678   }
01679 
01680   /// Transparently provide more efficient getOperand methods.
01681   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01682 
01683   Constant *getMask() const {
01684     return cast<Constant>(getOperand(2));
01685   }
01686 
01687   /// getMaskValue - Return the index from the shuffle mask for the specified
01688   /// output result.  This is either -1 if the element is undef or a number less
01689   /// than 2*numelements.
01690   static int getMaskValue(Constant *Mask, unsigned i);
01691 
01692   int getMaskValue(unsigned i) const {
01693     return getMaskValue(getMask(), i);
01694   }
01695 
01696   /// getShuffleMask - Return the full mask for this instruction, where each
01697   /// element is the element number and undef's are returned as -1.
01698   static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
01699 
01700   void getShuffleMask(SmallVectorImpl<int> &Result) const {
01701     return getShuffleMask(getMask(), Result);
01702   }
01703 
01704   SmallVector<int, 16> getShuffleMask() const {
01705     SmallVector<int, 16> Mask;
01706     getShuffleMask(Mask);
01707     return Mask;
01708   }
01709 
01710 
01711   // Methods for support type inquiry through isa, cast, and dyn_cast:
01712   static inline bool classof(const Instruction *I) {
01713     return I->getOpcode() == Instruction::ShuffleVector;
01714   }
01715   static inline bool classof(const Value *V) {
01716     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01717   }
01718 };
01719 
01720 template <>
01721 struct OperandTraits<ShuffleVectorInst> :
01722   public FixedNumOperandTraits<ShuffleVectorInst, 3> {
01723 };
01724 
01725 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
01726 
01727 //===----------------------------------------------------------------------===//
01728 //                                ExtractValueInst Class
01729 //===----------------------------------------------------------------------===//
01730 
01731 /// ExtractValueInst - This instruction extracts a struct member or array
01732 /// element value from an aggregate value.
01733 ///
01734 class ExtractValueInst : public UnaryInstruction {
01735   SmallVector<unsigned, 4> Indices;
01736 
01737   ExtractValueInst(const ExtractValueInst &EVI);
01738   void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
01739 
01740   /// Constructors - Create a extractvalue instruction with a base aggregate
01741   /// value and a list of indices.  The first ctor can optionally insert before
01742   /// an existing instruction, the second appends the new instruction to the
01743   /// specified BasicBlock.
01744   inline ExtractValueInst(Value *Agg,
01745                           ArrayRef<unsigned> Idxs,
01746                           const Twine &NameStr,
01747                           Instruction *InsertBefore);
01748   inline ExtractValueInst(Value *Agg,
01749                           ArrayRef<unsigned> Idxs,
01750                           const Twine &NameStr, BasicBlock *InsertAtEnd);
01751 
01752   // allocate space for exactly one operand
01753   void *operator new(size_t s) {
01754     return User::operator new(s, 1);
01755   }
01756 protected:
01757   virtual ExtractValueInst *clone_impl() const;
01758 
01759 public:
01760   static ExtractValueInst *Create(Value *Agg,
01761                                   ArrayRef<unsigned> Idxs,
01762                                   const Twine &NameStr = "",
01763                                   Instruction *InsertBefore = 0) {
01764     return new
01765       ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
01766   }
01767   static ExtractValueInst *Create(Value *Agg,
01768                                   ArrayRef<unsigned> Idxs,
01769                                   const Twine &NameStr,
01770                                   BasicBlock *InsertAtEnd) {
01771     return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
01772   }
01773 
01774   /// getIndexedType - Returns the type of the element that would be extracted
01775   /// with an extractvalue instruction with the specified parameters.
01776   ///
01777   /// Null is returned if the indices are invalid for the specified type.
01778   static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
01779 
01780   typedef const unsigned* idx_iterator;
01781   inline idx_iterator idx_begin() const { return Indices.begin(); }
01782   inline idx_iterator idx_end()   const { return Indices.end(); }
01783 
01784   Value *getAggregateOperand() {
01785     return getOperand(0);
01786   }
01787   const Value *getAggregateOperand() const {
01788     return getOperand(0);
01789   }
01790   static unsigned getAggregateOperandIndex() {
01791     return 0U;                      // get index for modifying correct operand
01792   }
01793 
01794   ArrayRef<unsigned> getIndices() const {
01795     return Indices;
01796   }
01797 
01798   unsigned getNumIndices() const {
01799     return (unsigned)Indices.size();
01800   }
01801 
01802   bool hasIndices() const {
01803     return true;
01804   }
01805 
01806   // Methods for support type inquiry through isa, cast, and dyn_cast:
01807   static inline bool classof(const Instruction *I) {
01808     return I->getOpcode() == Instruction::ExtractValue;
01809   }
01810   static inline bool classof(const Value *V) {
01811     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01812   }
01813 };
01814 
01815 ExtractValueInst::ExtractValueInst(Value *Agg,
01816                                    ArrayRef<unsigned> Idxs,
01817                                    const Twine &NameStr,
01818                                    Instruction *InsertBefore)
01819   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
01820                      ExtractValue, Agg, InsertBefore) {
01821   init(Idxs, NameStr);
01822 }
01823 ExtractValueInst::ExtractValueInst(Value *Agg,
01824                                    ArrayRef<unsigned> Idxs,
01825                                    const Twine &NameStr,
01826                                    BasicBlock *InsertAtEnd)
01827   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
01828                      ExtractValue, Agg, InsertAtEnd) {
01829   init(Idxs, NameStr);
01830 }
01831 
01832 
01833 //===----------------------------------------------------------------------===//
01834 //                                InsertValueInst Class
01835 //===----------------------------------------------------------------------===//
01836 
01837 /// InsertValueInst - This instruction inserts a struct field of array element
01838 /// value into an aggregate value.
01839 ///
01840 class InsertValueInst : public Instruction {
01841   SmallVector<unsigned, 4> Indices;
01842 
01843   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
01844   InsertValueInst(const InsertValueInst &IVI);
01845   void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
01846             const Twine &NameStr);
01847 
01848   /// Constructors - Create a insertvalue instruction with a base aggregate
01849   /// value, a value to insert, and a list of indices.  The first ctor can
01850   /// optionally insert before an existing instruction, the second appends
01851   /// the new instruction to the specified BasicBlock.
01852   inline InsertValueInst(Value *Agg, Value *Val,
01853                          ArrayRef<unsigned> Idxs,
01854                          const Twine &NameStr,
01855                          Instruction *InsertBefore);
01856   inline InsertValueInst(Value *Agg, Value *Val,
01857                          ArrayRef<unsigned> Idxs,
01858                          const Twine &NameStr, BasicBlock *InsertAtEnd);
01859 
01860   /// Constructors - These two constructors are convenience methods because one
01861   /// and two index insertvalue instructions are so common.
01862   InsertValueInst(Value *Agg, Value *Val,
01863                   unsigned Idx, const Twine &NameStr = "",
01864                   Instruction *InsertBefore = 0);
01865   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
01866                   const Twine &NameStr, BasicBlock *InsertAtEnd);
01867 protected:
01868   virtual InsertValueInst *clone_impl() const;
01869 public:
01870   // allocate space for exactly two operands
01871   void *operator new(size_t s) {
01872     return User::operator new(s, 2);
01873   }
01874 
01875   static InsertValueInst *Create(Value *Agg, Value *Val,
01876                                  ArrayRef<unsigned> Idxs,
01877                                  const Twine &NameStr = "",
01878                                  Instruction *InsertBefore = 0) {
01879     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
01880   }
01881   static InsertValueInst *Create(Value *Agg, Value *Val,
01882                                  ArrayRef<unsigned> Idxs,
01883                                  const Twine &NameStr,
01884                                  BasicBlock *InsertAtEnd) {
01885     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
01886   }
01887 
01888   /// Transparently provide more efficient getOperand methods.
01889   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01890 
01891   typedef const unsigned* idx_iterator;
01892   inline idx_iterator idx_begin() const { return Indices.begin(); }
01893   inline idx_iterator idx_end()   const { return Indices.end(); }
01894 
01895   Value *getAggregateOperand() {
01896     return getOperand(0);
01897   }
01898   const Value *getAggregateOperand() const {
01899     return getOperand(0);
01900   }
01901   static unsigned getAggregateOperandIndex() {
01902     return 0U;                      // get index for modifying correct operand
01903   }
01904 
01905   Value *getInsertedValueOperand() {
01906     return getOperand(1);
01907   }
01908   const Value *getInsertedValueOperand() const {
01909     return getOperand(1);
01910   }
01911   static unsigned getInsertedValueOperandIndex() {
01912     return 1U;                      // get index for modifying correct operand
01913   }
01914 
01915   ArrayRef<unsigned> getIndices() const {
01916     return Indices;
01917   }
01918 
01919   unsigned getNumIndices() const {
01920     return (unsigned)Indices.size();
01921   }
01922 
01923   bool hasIndices() const {
01924     return true;
01925   }
01926 
01927   // Methods for support type inquiry through isa, cast, and dyn_cast:
01928   static inline bool classof(const Instruction *I) {
01929     return I->getOpcode() == Instruction::InsertValue;
01930   }
01931   static inline bool classof(const Value *V) {
01932     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01933   }
01934 };
01935 
01936 template <>
01937 struct OperandTraits<InsertValueInst> :
01938   public FixedNumOperandTraits<InsertValueInst, 2> {
01939 };
01940 
01941 InsertValueInst::InsertValueInst(Value *Agg,
01942                                  Value *Val,
01943                                  ArrayRef<unsigned> Idxs,
01944                                  const Twine &NameStr,
01945                                  Instruction *InsertBefore)
01946   : Instruction(Agg->getType(), InsertValue,
01947                 OperandTraits<InsertValueInst>::op_begin(this),
01948                 2, InsertBefore) {
01949   init(Agg, Val, Idxs, NameStr);
01950 }
01951 InsertValueInst::InsertValueInst(Value *Agg,
01952                                  Value *Val,
01953                                  ArrayRef<unsigned> Idxs,
01954                                  const Twine &NameStr,
01955                                  BasicBlock *InsertAtEnd)
01956   : Instruction(Agg->getType(), InsertValue,
01957                 OperandTraits<InsertValueInst>::op_begin(this),
01958                 2, InsertAtEnd) {
01959   init(Agg, Val, Idxs, NameStr);
01960 }
01961 
01962 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
01963 
01964 //===----------------------------------------------------------------------===//
01965 //                               PHINode Class
01966 //===----------------------------------------------------------------------===//
01967 
01968 // PHINode - The PHINode class is used to represent the magical mystical PHI
01969 // node, that can not exist in nature, but can be synthesized in a computer
01970 // scientist's overactive imagination.
01971 //
01972 class PHINode : public Instruction {
01973   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
01974   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
01975   /// the number actually in use.
01976   unsigned ReservedSpace;
01977   PHINode(const PHINode &PN);
01978   // allocate space for exactly zero operands
01979   void *operator new(size_t s) {
01980     return User::operator new(s, 0);
01981   }
01982   explicit PHINode(Type *Ty, unsigned NumReservedValues,
01983                    const Twine &NameStr = "", Instruction *InsertBefore = 0)
01984     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
01985       ReservedSpace(NumReservedValues) {
01986     setName(NameStr);
01987     OperandList = allocHungoffUses(ReservedSpace);
01988   }
01989 
01990   PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
01991           BasicBlock *InsertAtEnd)
01992     : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
01993       ReservedSpace(NumReservedValues) {
01994     setName(NameStr);
01995     OperandList = allocHungoffUses(ReservedSpace);
01996   }
01997 protected:
01998   // allocHungoffUses - this is more complicated than the generic
01999   // User::allocHungoffUses, because we have to allocate Uses for the incoming
02000   // values and pointers to the incoming blocks, all in one allocation.
02001   Use *allocHungoffUses(unsigned) const;
02002 
02003   virtual PHINode *clone_impl() const;
02004 public:
02005   /// Constructors - NumReservedValues is a hint for the number of incoming
02006   /// edges that this phi node will have (use 0 if you really have no idea).
02007   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
02008                          const Twine &NameStr = "",
02009                          Instruction *InsertBefore = 0) {
02010     return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
02011   }
02012   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
02013                          const Twine &NameStr, BasicBlock *InsertAtEnd) {
02014     return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
02015   }
02016   ~PHINode();
02017 
02018   /// Provide fast operand accessors
02019   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02020 
02021   // Block iterator interface. This provides access to the list of incoming
02022   // basic blocks, which parallels the list of incoming values.
02023 
02024   typedef BasicBlock **block_iterator;
02025   typedef BasicBlock * const *const_block_iterator;
02026 
02027   block_iterator block_begin() {
02028     Use::UserRef *ref =
02029       reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
02030     return reinterpret_cast<block_iterator>(ref + 1);
02031   }
02032 
02033   const_block_iterator block_begin() const {
02034     const Use::UserRef *ref =
02035       reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
02036     return reinterpret_cast<const_block_iterator>(ref + 1);
02037   }
02038 
02039   block_iterator block_end() {
02040     return block_begin() + getNumOperands();
02041   }
02042 
02043   const_block_iterator block_end() const {
02044     return block_begin() + getNumOperands();
02045   }
02046 
02047   /// getNumIncomingValues - Return the number of incoming edges
02048   ///
02049   unsigned getNumIncomingValues() const { return getNumOperands(); }
02050 
02051   /// getIncomingValue - Return incoming value number x
02052   ///
02053   Value *getIncomingValue(unsigned i) const {
02054     return getOperand(i);
02055   }
02056   void setIncomingValue(unsigned i, Value *V) {
02057     setOperand(i, V);
02058   }
02059   static unsigned getOperandNumForIncomingValue(unsigned i) {
02060     return i;
02061   }
02062   static unsigned getIncomingValueNumForOperand(unsigned i) {
02063     return i;
02064   }
02065 
02066   /// getIncomingBlock - Return incoming basic block number @p i.
02067   ///
02068   BasicBlock *getIncomingBlock(unsigned i) const {
02069     return block_begin()[i];
02070   }
02071 
02072   /// getIncomingBlock - Return incoming basic block corresponding
02073   /// to an operand of the PHI.
02074   ///
02075   BasicBlock *getIncomingBlock(const Use &U) const {
02076     assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
02077     return getIncomingBlock(unsigned(&U - op_begin()));
02078   }
02079 
02080   /// getIncomingBlock - Return incoming basic block corresponding
02081   /// to value use iterator.
02082   ///
02083   template <typename U>
02084   BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
02085     return getIncomingBlock(I.getUse());
02086   }
02087 
02088   void setIncomingBlock(unsigned i, BasicBlock *BB) {
02089     block_begin()[i] = BB;
02090   }
02091 
02092   /// addIncoming - Add an incoming value to the end of the PHI list
02093   ///
02094   void addIncoming(Value *V, BasicBlock *BB) {
02095     assert(V && "PHI node got a null value!");
02096     assert(BB && "PHI node got a null basic block!");
02097     assert(getType() == V->getType() &&
02098            "All operands to PHI node must be the same type as the PHI node!");
02099     if (NumOperands == ReservedSpace)
02100       growOperands();  // Get more space!
02101     // Initialize some new operands.
02102     ++NumOperands;
02103     setIncomingValue(NumOperands - 1, V);
02104     setIncomingBlock(NumOperands - 1, BB);
02105   }
02106 
02107   /// removeIncomingValue - Remove an incoming value.  This is useful if a
02108   /// predecessor basic block is deleted.  The value removed is returned.
02109   ///
02110   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
02111   /// is true), the PHI node is destroyed and any uses of it are replaced with
02112   /// dummy values.  The only time there should be zero incoming values to a PHI
02113   /// node is when the block is dead, so this strategy is sound.
02114   ///
02115   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
02116 
02117   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
02118     int Idx = getBasicBlockIndex(BB);
02119     assert(Idx >= 0 && "Invalid basic block argument to remove!");
02120     return removeIncomingValue(Idx, DeletePHIIfEmpty);
02121   }
02122 
02123   /// getBasicBlockIndex - Return the first index of the specified basic
02124   /// block in the value list for this PHI.  Returns -1 if no instance.
02125   ///
02126   int getBasicBlockIndex(const BasicBlock *BB) const {
02127     for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
02128       if (block_begin()[i] == BB)
02129         return i;
02130     return -1;
02131   }
02132 
02133   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
02134     int Idx = getBasicBlockIndex(BB);
02135     assert(Idx >= 0 && "Invalid basic block argument!");
02136     return getIncomingValue(Idx);
02137   }
02138 
02139   /// hasConstantValue - If the specified PHI node always merges together the
02140   /// same value, return the value, otherwise return null.
02141   Value *hasConstantValue() const;
02142 
02143   /// Methods for support type inquiry through isa, cast, and dyn_cast:
02144   static inline bool classof(const Instruction *I) {
02145     return I->getOpcode() == Instruction::PHI;
02146   }
02147   static inline bool classof(const Value *V) {
02148     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02149   }
02150  private:
02151   void growOperands();
02152 };
02153 
02154 template <>
02155 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
02156 };
02157 
02158 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
02159 
02160 //===----------------------------------------------------------------------===//
02161 //                           LandingPadInst Class
02162 //===----------------------------------------------------------------------===//
02163 
02164 //===---------------------------------------------------------------------------
02165 /// LandingPadInst - The landingpad instruction holds all of the information
02166 /// necessary to generate correct exception handling. The landingpad instruction
02167 /// cannot be moved from the top of a landing pad block, which itself is
02168 /// accessible only from the 'unwind' edge of an invoke. This uses the
02169 /// SubclassData field in Value to store whether or not the landingpad is a
02170 /// cleanup.
02171 ///
02172 class LandingPadInst : public Instruction {
02173   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
02174   /// the number actually in use.
02175   unsigned ReservedSpace;
02176   LandingPadInst(const LandingPadInst &LP);
02177 public:
02178   enum ClauseType { Catch, Filter };
02179 private:
02180   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
02181   // Allocate space for exactly zero operands.
02182   void *operator new(size_t s) {
02183     return User::operator new(s, 0);
02184   }
02185   void growOperands(unsigned Size);
02186   void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
02187 
02188   explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
02189                           unsigned NumReservedValues, const Twine &NameStr,
02190                           Instruction *InsertBefore);
02191   explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
02192                           unsigned NumReservedValues, const Twine &NameStr,
02193                           BasicBlock *InsertAtEnd);
02194 protected:
02195   virtual LandingPadInst *clone_impl() const;
02196 public:
02197   /// Constructors - NumReservedClauses is a hint for the number of incoming
02198   /// clauses that this landingpad will have (use 0 if you really have no idea).
02199   static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
02200                                 unsigned NumReservedClauses,
02201                                 const Twine &NameStr = "",
02202                                 Instruction *InsertBefore = 0);
02203   static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
02204                                 unsigned NumReservedClauses,
02205                                 const Twine &NameStr, BasicBlock *InsertAtEnd);
02206   ~LandingPadInst();
02207 
02208   /// Provide fast operand accessors
02209   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02210 
02211   /// getPersonalityFn - Get the personality function associated with this
02212   /// landing pad.
02213   Value *getPersonalityFn() const { return getOperand(0); }
02214 
02215   /// isCleanup - Return 'true' if this landingpad instruction is a
02216   /// cleanup. I.e., it should be run when unwinding even if its landing pad
02217   /// doesn't catch the exception.
02218   bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
02219 
02220   /// setCleanup - Indicate that this landingpad instruction is a cleanup.
02221   void setCleanup(bool V) {
02222     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
02223                                (V ? 1 : 0));
02224   }
02225 
02226   /// addClause - Add a catch or filter clause to the landing pad.
02227   void addClause(Value *ClauseVal);
02228 
02229   /// getClause - Get the value of the clause at index Idx. Use isCatch/isFilter
02230   /// to determine what type of clause this is.
02231   Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; }
02232 
02233   /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
02234   bool isCatch(unsigned Idx) const {
02235     return !isa<ArrayType>(OperandList[Idx + 1]->getType());
02236   }
02237 
02238   /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
02239   bool isFilter(unsigned Idx) const {
02240     return isa<ArrayType>(OperandList[Idx + 1]->getType());
02241   }
02242 
02243   /// getNumClauses - Get the number of clauses for this landing pad.
02244   unsigned getNumClauses() const { return getNumOperands() - 1; }
02245 
02246   /// reserveClauses - Grow the size of the operand list to accommodate the new
02247   /// number of clauses.
02248   void reserveClauses(unsigned Size) { growOperands(Size); }
02249 
02250   // Methods for support type inquiry through isa, cast, and dyn_cast:
02251   static inline bool classof(const Instruction *I) {
02252     return I->getOpcode() == Instruction::LandingPad;
02253   }
02254   static inline bool classof(const Value *V) {
02255     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02256   }
02257 };
02258 
02259 template <>
02260 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
02261 };
02262 
02263 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
02264 
02265 //===----------------------------------------------------------------------===//
02266 //                               ReturnInst Class
02267 //===----------------------------------------------------------------------===//
02268 
02269 //===---------------------------------------------------------------------------
02270 /// ReturnInst - Return a value (possibly void), from a function.  Execution
02271 /// does not continue in this function any longer.
02272 ///
02273 class ReturnInst : public TerminatorInst {
02274   ReturnInst(const ReturnInst &RI);
02275 
02276 private:
02277   // ReturnInst constructors:
02278   // ReturnInst()                  - 'ret void' instruction
02279   // ReturnInst(    null)          - 'ret void' instruction
02280   // ReturnInst(Value* X)          - 'ret X'    instruction
02281   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
02282   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
02283   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
02284   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
02285   //
02286   // NOTE: If the Value* passed is of type void then the constructor behaves as
02287   // if it was passed NULL.
02288   explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
02289                       Instruction *InsertBefore = 0);
02290   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
02291   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
02292 protected:
02293   virtual ReturnInst *clone_impl() const;
02294 public:
02295   static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
02296                             Instruction *InsertBefore = 0) {
02297     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
02298   }
02299   static ReturnInst* Create(LLVMContext &C, Value *retVal,
02300                             BasicBlock *InsertAtEnd) {
02301     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
02302   }
02303   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
02304     return new(0) ReturnInst(C, InsertAtEnd);
02305   }
02306   virtual ~ReturnInst();
02307 
02308   /// Provide fast operand accessors
02309   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02310 
02311   /// Convenience accessor. Returns null if there is no return value.
02312   Value *getReturnValue() const {
02313     return getNumOperands() != 0 ? getOperand(0) : 0;
02314   }
02315 
02316   unsigned getNumSuccessors() const { return 0; }
02317 
02318   // Methods for support type inquiry through isa, cast, and dyn_cast:
02319   static inline bool classof(const Instruction *I) {
02320     return (I->getOpcode() == Instruction::Ret);
02321   }
02322   static inline bool classof(const Value *V) {
02323     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02324   }
02325  private:
02326   virtual BasicBlock *getSuccessorV(unsigned idx) const;
02327   virtual unsigned getNumSuccessorsV() const;
02328   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
02329 };
02330 
02331 template <>
02332 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
02333 };
02334 
02335 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
02336 
02337 //===----------------------------------------------------------------------===//
02338 //                               BranchInst Class
02339 //===----------------------------------------------------------------------===//
02340 
02341 //===---------------------------------------------------------------------------
02342 /// BranchInst - Conditional or Unconditional Branch instruction.
02343 ///
02344 class BranchInst : public TerminatorInst {
02345   /// Ops list - Branches are strange.  The operands are ordered:
02346   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
02347   /// they don't have to check for cond/uncond branchness. These are mostly
02348   /// accessed relative from op_end().
02349   BranchInst(const BranchInst &BI);
02350   void AssertOK();
02351   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
02352   // BranchInst(BB *B)                           - 'br B'
02353   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
02354   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
02355   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
02356   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
02357   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
02358   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
02359   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
02360              Instruction *InsertBefore = 0);
02361   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
02362   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
02363              BasicBlock *InsertAtEnd);
02364 protected:
02365   virtual BranchInst *clone_impl() const;
02366 public:
02367   static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
02368     return new(1) BranchInst(IfTrue, InsertBefore);
02369   }
02370   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
02371                             Value *Cond, Instruction *InsertBefore = 0) {
02372     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
02373   }
02374   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
02375     return new(1) BranchInst(IfTrue, InsertAtEnd);
02376   }
02377   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
02378                             Value *Cond, BasicBlock *InsertAtEnd) {
02379     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
02380   }
02381 
02382   /// Transparently provide more efficient getOperand methods.
02383   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02384 
02385   bool isUnconditional() const { return getNumOperands() == 1; }
02386   bool isConditional()   const { return getNumOperands() == 3; }
02387 
02388   Value *getCondition() const {
02389     assert(isConditional() && "Cannot get condition of an uncond branch!");
02390     return Op<-3>();
02391   }
02392 
02393   void setCondition(Value *V) {
02394     assert(isConditional() && "Cannot set condition of unconditional branch!");
02395     Op<-3>() = V;
02396   }
02397 
02398   unsigned getNumSuccessors() const { return 1+isConditional(); }
02399 
02400   BasicBlock *getSuccessor(unsigned i) const {
02401     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
02402     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
02403   }
02404 
02405   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
02406     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
02407     *(&Op<-1>() - idx) = (Value*)NewSucc;
02408   }
02409 
02410   /// \brief Swap the successors of this branch instruction.
02411   ///
02412   /// Swaps the successors of the branch instruction. This also swaps any
02413   /// branch weight metadata associated with the instruction so that it
02414   /// continues to map correctly to each operand.
02415   void swapSuccessors();
02416 
02417   // Methods for support type inquiry through isa, cast, and dyn_cast:
02418   static inline bool classof(const Instruction *I) {
02419     return (I->getOpcode() == Instruction::Br);
02420   }
02421   static inline bool classof(const Value *V) {
02422     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02423   }
02424 private:
02425   virtual BasicBlock *getSuccessorV(unsigned idx) const;
02426   virtual unsigned getNumSuccessorsV() const;
02427   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
02428 };
02429 
02430 template <>
02431 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
02432 };
02433 
02434 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
02435 
02436 //===----------------------------------------------------------------------===//
02437 //                               SwitchInst Class
02438 //===----------------------------------------------------------------------===//
02439 
02440 //===---------------------------------------------------------------------------
02441 /// SwitchInst - Multiway switch
02442 ///
02443 class SwitchInst : public TerminatorInst {
02444   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
02445   unsigned ReservedSpace;
02446   // Operands format:
02447   // Operand[0]    = Value to switch on
02448   // Operand[1]    = Default basic block destination
02449   // Operand[2n  ] = Value to match
02450   // Operand[2n+1] = BasicBlock to go to on match
02451 
02452   // Store case values separately from operands list. We needn't User-Use
02453   // concept here, since it is just a case value, it will always constant,
02454   // and case value couldn't reused with another instructions/values.
02455   // Additionally:
02456   // It allows us to use custom type for case values that is not inherited
02457   // from Value. Since case value is a complex type that implements
02458   // the subset of integers, we needn't extract sub-constants within
02459   // slow getAggregateElement method.
02460   // For case values we will use std::list to by two reasons:
02461   // 1. It allows to add/remove cases without whole collection reallocation.
02462   // 2. In most of cases we needn't random access.
02463   // Currently case values are also stored in Operands List, but it will moved
02464   // out in future commits.
02465   typedef std::list<IntegersSubset> Subsets;
02466   typedef Subsets::iterator SubsetsIt;
02467   typedef Subsets::const_iterator SubsetsConstIt;
02468 
02469   Subsets TheSubsets;
02470 
02471   SwitchInst(const SwitchInst &SI);
02472   void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
02473   void growOperands();
02474   // allocate space for exactly zero operands
02475   void *operator new(size_t s) {
02476     return User::operator new(s, 0);
02477   }
02478   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
02479   /// switch on and a default destination.  The number of additional cases can
02480   /// be specified here to make memory allocation more efficient.  This
02481   /// constructor can also autoinsert before another instruction.
02482   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
02483              Instruction *InsertBefore);
02484 
02485   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
02486   /// switch on and a default destination.  The number of additional cases can
02487   /// be specified here to make memory allocation more efficient.  This
02488   /// constructor also autoinserts at the end of the specified BasicBlock.
02489   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
02490              BasicBlock *InsertAtEnd);
02491 protected:
02492   virtual SwitchInst *clone_impl() const;
02493 public:
02494 
02495   // FIXME: Currently there are a lot of unclean template parameters,
02496   // we need to make refactoring in future.
02497   // All these parameters are used to implement both iterator and const_iterator
02498   // without code duplication.
02499   // SwitchInstTy may be "const SwitchInst" or "SwitchInst"
02500   // ConstantIntTy may be "const ConstantInt" or "ConstantInt"
02501   // SubsetsItTy may be SubsetsConstIt or SubsetsIt
02502   // BasicBlockTy may be "const BasicBlock" or "BasicBlock"
02503   template <class SwitchInstTy, class ConstantIntTy,
02504             class SubsetsItTy, class BasicBlockTy>
02505     class CaseIteratorT;
02506 
02507   typedef CaseIteratorT<const SwitchInst, const ConstantInt,
02508                         SubsetsConstIt, const BasicBlock> ConstCaseIt;
02509   class CaseIt;
02510 
02511   // -2
02512   static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
02513 
02514   static SwitchInst *Create(Value *Value, BasicBlock *Default,
02515                             unsigned NumCases, Instruction *InsertBefore = 0) {
02516     return new SwitchInst(Value, Default, NumCases, InsertBefore);
02517   }
02518   static SwitchInst *Create(Value *Value, BasicBlock *Default,
02519                             unsigned NumCases, BasicBlock *InsertAtEnd) {
02520     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
02521   }
02522 
02523   ~SwitchInst();
02524 
02525   /// Provide fast operand accessors
02526   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02527 
02528   // Accessor Methods for Switch stmt
02529   Value *getCondition() const { return getOperand(0); }
02530   void setCondition(Value *V) { setOperand(0, V); }
02531 
02532   BasicBlock *getDefaultDest() const {
02533     return cast<BasicBlock>(getOperand(1));
02534   }
02535 
02536   void setDefaultDest(BasicBlock *DefaultCase) {
02537     setOperand(1, reinterpret_cast<Value*>(DefaultCase));
02538   }
02539 
02540   /// getNumCases - return the number of 'cases' in this switch instruction,
02541   /// except the default case
02542   unsigned getNumCases() const {
02543     return getNumOperands()/2 - 1;
02544   }
02545 
02546   /// Returns a read/write iterator that points to the first
02547   /// case in SwitchInst.
02548   CaseIt case_begin() {
02549     return CaseIt(this, 0, TheSubsets.begin());
02550   }
02551   /// Returns a read-only iterator that points to the first
02552   /// case in the SwitchInst.
02553   ConstCaseIt case_begin() const {
02554     return ConstCaseIt(this, 0, TheSubsets.begin());
02555   }
02556 
02557   /// Returns a read/write iterator that points one past the last
02558   /// in the SwitchInst.
02559   CaseIt case_end() {
02560     return CaseIt(this, getNumCases(), TheSubsets.end());
02561   }
02562   /// Returns a read-only iterator that points one past the last
02563   /// in the SwitchInst.
02564   ConstCaseIt case_end() const {
02565     return ConstCaseIt(this, getNumCases(), TheSubsets.end());
02566   }
02567   /// Returns an iterator that points to the default case.
02568   /// Note: this iterator allows to resolve successor only. Attempt
02569   /// to resolve case value causes an assertion.
02570   /// Also note, that increment and decrement also causes an assertion and
02571   /// makes iterator invalid.
02572   CaseIt case_default() {
02573     return CaseIt(this, DefaultPseudoIndex, TheSubsets.end());
02574   }
02575   ConstCaseIt case_default() const {
02576     return ConstCaseIt(this, DefaultPseudoIndex, TheSubsets.end());
02577   }
02578 
02579   /// findCaseValue - Search all of the case values for the specified constant.
02580   /// If it is explicitly handled, return the case iterator of it, otherwise
02581   /// return default case iterator to indicate
02582   /// that it is handled by the default handler.
02583   CaseIt findCaseValue(const ConstantInt *C) {
02584     for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
02585       if (i.getCaseValueEx().isSatisfies(IntItem::fromConstantInt(C)))
02586         return i;
02587     return case_default();
02588   }
02589   ConstCaseIt findCaseValue(const ConstantInt *C) const {
02590     for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
02591       if (i.getCaseValueEx().isSatisfies(IntItem::fromConstantInt(C)))
02592         return i;
02593     return case_default();
02594   }
02595 
02596   /// findCaseDest - Finds the unique case value for a given successor. Returns
02597   /// null if the successor is not found, not unique, or is the default case.
02598   ConstantInt *findCaseDest(BasicBlock *BB) {
02599     if (BB == getDefaultDest()) return NULL;
02600 
02601     ConstantInt *CI = NULL;
02602     for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
02603       if (i.getCaseSuccessor() == BB) {
02604         if (CI) return NULL;   // Multiple cases lead to BB.
02605         else CI = i.getCaseValue();
02606       }
02607     }
02608     return CI;
02609   }
02610 
02611   /// addCase - Add an entry to the switch instruction...
02612   /// Note:
02613   /// This action invalidates case_end(). Old case_end() iterator will
02614   /// point to the added case.
02615   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
02616 
02617   /// addCase - Add an entry to the switch instruction.
02618   /// Note:
02619   /// This action invalidates case_end(). Old case_end() iterator will
02620   /// point to the added case.
02621   void addCase(IntegersSubset& OnVal, BasicBlock *Dest);
02622 
02623   /// removeCase - This method removes the specified case and its successor
02624   /// from the switch instruction. Note that this operation may reorder the
02625   /// remaining cases at index idx and above.
02626   /// Note:
02627   /// This action invalidates iterators for all cases following the one removed,
02628   /// including the case_end() iterator.
02629   void removeCase(CaseIt& i);
02630 
02631   unsigned getNumSuccessors() const { return getNumOperands()/2; }
02632   BasicBlock *getSuccessor(unsigned idx) const {
02633     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
02634     return cast<BasicBlock>(getOperand(idx*2+1));
02635   }
02636   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
02637     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
02638     setOperand(idx*2+1, (Value*)NewSucc);
02639   }
02640 
02641   uint16_t hash() const {
02642     uint32_t NumberOfCases = (uint32_t)getNumCases();
02643     uint16_t Hash = (0xFFFF & NumberOfCases) ^ (NumberOfCases >> 16);
02644     for (ConstCaseIt i = case_begin(), e = case_end();
02645          i != e; ++i) {
02646       uint32_t NumItems = (uint32_t)i.getCaseValueEx().getNumItems();
02647       Hash = (Hash << 1) ^ (0xFFFF & NumItems) ^ (NumItems >> 16);
02648     }
02649     return Hash;
02650   }
02651 
02652   // Case iterators definition.
02653 
02654   template <class SwitchInstTy, class ConstantIntTy,
02655             class SubsetsItTy, class BasicBlockTy>
02656   class CaseIteratorT {
02657   protected:
02658 
02659     SwitchInstTy *SI;
02660     unsigned Index;
02661     SubsetsItTy SubsetIt;
02662 
02663     /// Initializes case iterator for given SwitchInst and for given
02664     /// case number.
02665     friend class SwitchInst;
02666     CaseIteratorT(SwitchInstTy *SI, unsigned SuccessorIndex,
02667                   SubsetsItTy CaseValueIt) {
02668       this->SI = SI;
02669       Index = SuccessorIndex;
02670       this->SubsetIt = CaseValueIt;
02671     }
02672 
02673   public:
02674     typedef typename SubsetsItTy::reference IntegersSubsetRef;
02675     typedef CaseIteratorT<SwitchInstTy, ConstantIntTy,
02676                           SubsetsItTy, BasicBlockTy> Self;
02677 
02678     CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
02679           this->SI = SI;
02680           Index = CaseNum;
02681           SubsetIt = SI->TheSubsets.begin();
02682           std::advance(SubsetIt, CaseNum);
02683         }
02684 
02685 
02686     /// Initializes case iterator for given SwitchInst and for given
02687     /// TerminatorInst's successor index.
02688     static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
02689       assert(SuccessorIndex < SI->getNumSuccessors() &&
02690              "Successor index # out of range!");
02691       return SuccessorIndex != 0 ?
02692              Self(SI, SuccessorIndex - 1) :
02693              Self(SI, DefaultPseudoIndex);
02694     }
02695 
02696     /// Resolves case value for current case.
02697     ConstantIntTy *getCaseValue() {
02698       assert(Index < SI->getNumCases() && "Index out the number of cases.");
02699       IntegersSubsetRef CaseRanges = *SubsetIt;
02700 
02701       // FIXME: Currently we work with ConstantInt based cases.
02702       // So return CaseValue as ConstantInt.
02703       return CaseRanges.getSingleNumber(0).toConstantInt();
02704     }
02705 
02706     /// Resolves case value for current case.
02707     IntegersSubsetRef getCaseValueEx() {
02708       assert(Index < SI->getNumCases() && "Index out the number of cases.");
02709       return *SubsetIt;
02710     }
02711 
02712     /// Resolves successor for current case.
02713     BasicBlockTy *getCaseSuccessor() {
02714       assert((Index < SI->getNumCases() ||
02715               Index == DefaultPseudoIndex) &&
02716              "Index out the number of cases.");
02717       return SI->getSuccessor(getSuccessorIndex());
02718     }
02719 
02720     /// Returns number of current case.
02721     unsigned getCaseIndex() const { return Index; }
02722 
02723     /// Returns TerminatorInst's successor index for current case successor.
02724     unsigned getSuccessorIndex() const {
02725       assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
02726              "Index out the number of cases.");
02727       return Index != DefaultPseudoIndex ? Index + 1 : 0;
02728     }
02729 
02730     Self operator++() {
02731       // Check index correctness after increment.
02732       // Note: Index == getNumCases() means end().
02733       assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
02734       ++Index;
02735       if (Index == 0)
02736         SubsetIt = SI->TheSubsets.begin();
02737       else
02738         ++SubsetIt;
02739       return *this;
02740     }
02741     Self operator++(int) {
02742       Self tmp = *this;
02743       ++(*this);
02744       return tmp;
02745     }
02746     Self operator--() {
02747       // Check index correctness after decrement.
02748       // Note: Index == getNumCases() means end().
02749       // Also allow "-1" iterator here. That will became valid after ++.
02750       unsigned NumCases = SI->getNumCases();
02751       assert((Index == 0 || Index-1 <= NumCases) &&
02752              "Index out the number of cases.");
02753       --Index;
02754       if (Index == NumCases) {
02755         SubsetIt = SI->TheSubsets.end();
02756         return *this;
02757       }
02758 
02759       if (Index != -1U)
02760         --SubsetIt;
02761 
02762       return *this;
02763     }
02764     Self operator--(int) {
02765       Self tmp = *this;
02766       --(*this);
02767       return tmp;
02768     }
02769     bool operator==(const Self& RHS) const {
02770       assert(RHS.SI == SI && "Incompatible operators.");
02771       return RHS.Index == Index;
02772     }
02773     bool operator!=(const Self& RHS) const {
02774       assert(RHS.SI == SI && "Incompatible operators.");
02775       return RHS.Index != Index;
02776     }
02777   };
02778 
02779   class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt,
02780                                       SubsetsIt, BasicBlock> {
02781     typedef CaseIteratorT<SwitchInst, ConstantInt, SubsetsIt, BasicBlock>
02782       ParentTy;
02783 
02784   protected:
02785     friend class SwitchInst;
02786     CaseIt(SwitchInst *SI, unsigned CaseNum, SubsetsIt SubsetIt) :
02787       ParentTy(SI, CaseNum, SubsetIt) {}
02788 
02789     void updateCaseValueOperand(IntegersSubset& V) {
02790       SI->setOperand(2 + Index*2, reinterpret_cast<Value*>((Constant*)V));
02791     }
02792 
02793   public:
02794 
02795     CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
02796 
02797     CaseIt(const ParentTy& Src) : ParentTy(Src) {}
02798 
02799     /// Sets the new value for current case.
02800     void setValue(ConstantInt *V) {
02801       assert(Index < SI->getNumCases() && "Index out the number of cases.");
02802       IntegersSubsetToBB Mapping;
02803       // FIXME: Currently we work with ConstantInt based cases.
02804       // So inititalize IntItem container directly from ConstantInt.
02805       Mapping.add(IntItem::fromConstantInt(V));
02806       *SubsetIt = Mapping.getCase();
02807       updateCaseValueOperand(*SubsetIt);
02808     }
02809 
02810     /// Sets the new value for current case.
02811     void setValueEx(IntegersSubset& V) {
02812       assert(Index < SI->getNumCases() && "Index out the number of cases.");
02813       *SubsetIt = V;
02814       updateCaseValueOperand(*SubsetIt);
02815     }
02816 
02817     /// Sets the new successor for current case.
02818     void setSuccessor(BasicBlock *S) {
02819       SI->setSuccessor(getSuccessorIndex(), S);
02820     }
02821   };
02822 
02823   // Methods for support type inquiry through isa, cast, and dyn_cast:
02824 
02825   static inline bool classof(const Instruction *I) {
02826     return I->getOpcode() == Instruction::Switch;
02827   }
02828   static inline bool classof(const Value *V) {
02829     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02830   }
02831 private:
02832   virtual BasicBlock *getSuccessorV(unsigned idx) const;
02833   virtual unsigned getNumSuccessorsV() const;
02834   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
02835 };
02836 
02837 template <>
02838 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
02839 };
02840 
02841 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
02842 
02843 
02844 //===----------------------------------------------------------------------===//
02845 //                             IndirectBrInst Class
02846 //===----------------------------------------------------------------------===//
02847 
02848 //===---------------------------------------------------------------------------
02849 /// IndirectBrInst - Indirect Branch Instruction.
02850 ///
02851 class IndirectBrInst : public TerminatorInst {
02852   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
02853   unsigned ReservedSpace;
02854   // Operand[0]    = Value to switch on
02855   // Operand[1]    = Default basic block destination
02856   // Operand[2n  ] = Value to match
02857   // Operand[2n+1] = BasicBlock to go to on match
02858   IndirectBrInst(const IndirectBrInst &IBI);
02859   void init(Value *Address, unsigned NumDests);
02860   void growOperands();
02861   // allocate space for exactly zero operands
02862   void *operator new(size_t s) {
02863     return User::operator new(s, 0);
02864   }
02865   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
02866   /// Address to jump to.  The number of expected destinations can be specified
02867   /// here to make memory allocation more efficient.  This constructor can also
02868   /// autoinsert before another instruction.
02869   IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
02870 
02871   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
02872   /// Address to jump to.  The number of expected destinations can be specified
02873   /// here to make memory allocation more efficient.  This constructor also
02874   /// autoinserts at the end of the specified BasicBlock.
02875   IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
02876 protected:
02877   virtual IndirectBrInst *clone_impl() const;
02878 public:
02879   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
02880                                 Instruction *InsertBefore = 0) {
02881     return new IndirectBrInst(Address, NumDests, InsertBefore);
02882   }
02883   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
02884                                 BasicBlock *InsertAtEnd) {
02885     return new IndirectBrInst(Address, NumDests, InsertAtEnd);
02886   }
02887   ~IndirectBrInst();
02888 
02889   /// Provide fast operand accessors.
02890   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02891 
02892   // Accessor Methods for IndirectBrInst instruction.
02893   Value *getAddress() { return getOperand(0); }
02894   const Value *getAddress() const { return getOperand(0); }
02895   void setAddress(Value *V) { setOperand(0, V); }
02896 
02897 
02898   /// getNumDestinations - return the number of possible destinations in this
02899   /// indirectbr instruction.
02900   unsigned getNumDestinations() const { return getNumOperands()-1; }
02901 
02902   /// getDestination - Return the specified destination.
02903   BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
02904   const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
02905 
02906   /// addDestination - Add a destination.
02907   ///
02908   void addDestination(BasicBlock *Dest);
02909 
02910   /// removeDestination - This method removes the specified successor from the
02911   /// indirectbr instruction.
02912   void removeDestination(unsigned i);
02913 
02914   unsigned getNumSuccessors() const { return getNumOperands()-1; }
02915   BasicBlock *getSuccessor(unsigned i) const {
02916     return cast<BasicBlock>(getOperand(i+1));
02917   }
02918   void setSuccessor(unsigned i, BasicBlock *NewSucc) {
02919     setOperand(i+1, (Value*)NewSucc);
02920   }
02921 
02922   // Methods for support type inquiry through isa, cast, and dyn_cast:
02923   static inline bool classof(const Instruction *I) {
02924     return I->getOpcode() == Instruction::IndirectBr;
02925   }
02926   static inline bool classof(const Value *V) {
02927     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02928   }
02929 private:
02930   virtual BasicBlock *getSuccessorV(unsigned idx) const;
02931   virtual unsigned getNumSuccessorsV() const;
02932   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
02933 };
02934 
02935 template <>
02936 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
02937 };
02938 
02939 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
02940 
02941 
02942 //===----------------------------------------------------------------------===//
02943 //                               InvokeInst Class
02944 //===----------------------------------------------------------------------===//
02945 
02946 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
02947 /// calling convention of the call.
02948 ///
02949 class InvokeInst : public TerminatorInst {
02950   AttributeSet AttributeList;
02951   InvokeInst(const InvokeInst &BI);
02952   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
02953             ArrayRef<Value *> Args, const Twine &NameStr);
02954 
02955   /// Construct an InvokeInst given a range of arguments.
02956   ///
02957   /// \brief Construct an InvokeInst from a range of arguments
02958   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
02959                     ArrayRef<Value *> Args, unsigned Values,
02960                     const Twine &NameStr, Instruction *InsertBefore);
02961 
02962   /// Construct an InvokeInst given a range of arguments.
02963   ///
02964   /// \brief Construct an InvokeInst from a range of arguments
02965   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
02966                     ArrayRef<Value *> Args, unsigned Values,
02967                     const Twine &NameStr, BasicBlock *InsertAtEnd);
02968 protected:
02969   virtual InvokeInst *clone_impl() const;
02970 public:
02971   static InvokeInst *Create(Value *Func,
02972                             BasicBlock *IfNormal, BasicBlock *IfException,
02973                             ArrayRef<Value *> Args, const Twine &NameStr = "",
02974                             Instruction *InsertBefore = 0) {
02975     unsigned Values = unsigned(Args.size()) + 3;
02976     return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
02977                                   Values, NameStr, InsertBefore);
02978   }
02979   static InvokeInst *Create(Value *Func,
02980                             BasicBlock *IfNormal, BasicBlock *IfException,
02981                             ArrayRef<Value *> Args, const Twine &NameStr,
02982                             BasicBlock *InsertAtEnd) {
02983     unsigned Values = unsigned(Args.size()) + 3;
02984     return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
02985                                   Values, NameStr, InsertAtEnd);
02986   }
02987 
02988   /// Provide fast operand accessors
02989   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02990 
02991   /// getNumArgOperands - Return the number of invoke arguments.
02992   ///
02993   unsigned getNumArgOperands() const { return getNumOperands() - 3; }
02994 
02995   /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
02996   ///
02997   Value *getArgOperand(unsigned i) const { return getOperand(i); }
02998   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
02999 
03000   /// getCallingConv/setCallingConv - Get or set the calling convention of this
03001   /// function call.
03002   CallingConv::ID getCallingConv() const {
03003     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
03004   }
03005   void setCallingConv(CallingConv::ID CC) {
03006     setInstructionSubclassData(static_cast<unsigned>(CC));
03007   }
03008 
03009   /// getAttributes - Return the parameter attributes for this invoke.
03010   ///
03011   const AttributeSet &getAttributes() const { return AttributeList; }
03012 
03013   /// setAttributes - Set the parameter attributes for this invoke.
03014   ///
03015   void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
03016 
03017   /// addAttribute - adds the attribute to the list of attributes.
03018   void addAttribute(unsigned i, Attribute::AttrKind attr);
03019 
03020   /// removeAttribute - removes the attribute from the list of attributes.
03021   void removeAttribute(unsigned i, Attribute attr);
03022 
03023   /// \brief Determine whether this call has the NoAlias attribute.
03024   bool hasFnAttr(Attribute::AttrKind A) const;
03025 
03026   /// \brief Determine whether the call or the callee has the given attributes.
03027   bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
03028 
03029   /// \brief Extract the alignment for a call or parameter (0=unknown).
03030   unsigned getParamAlignment(unsigned i) const {
03031     return AttributeList.getParamAlignment(i);
03032   }
03033 
03034   /// \brief Return true if the call should not be inlined.
03035   bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
03036   void setIsNoInline() {
03037     addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
03038   }
03039 
03040   /// \brief Determine if the call does not access memory.
03041   bool doesNotAccessMemory() const {
03042     return hasFnAttr(Attribute::ReadNone);
03043   }
03044   void setDoesNotAccessMemory() {
03045     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
03046   }
03047 
03048   /// \brief Determine if the call does not access or only reads memory.
03049   bool onlyReadsMemory() const {
03050     return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
03051   }
03052   void setOnlyReadsMemory() {
03053     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
03054   }
03055 
03056   /// \brief Determine if the call cannot return.
03057   bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
03058   void setDoesNotReturn() {
03059     addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
03060   }
03061 
03062   /// \brief Determine if the call cannot unwind.
03063   bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
03064   void setDoesNotThrow() {
03065     addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
03066   }
03067 
03068   /// \brief Determine if the call returns a structure through first
03069   /// pointer argument.
03070   bool hasStructRetAttr() const {
03071     // Be friendly and also check the callee.
03072     return paramHasAttr(1, Attribute::StructRet);
03073   }
03074 
03075   /// \brief Determine if any call argument is an aggregate passed by value.
03076   bool hasByValArgument() const {
03077     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
03078   }
03079 
03080   /// getCalledFunction - Return the function called, or null if this is an
03081   /// indirect function invocation.
03082   ///
03083   Function *getCalledFunction() const {
03084     return dyn_cast<Function>(Op<-3>());
03085   }
03086 
03087   /// getCalledValue - Get a pointer to the function that is invoked by this
03088   /// instruction
03089   const Value *getCalledValue() const { return Op<-3>(); }
03090         Value *getCalledValue()       { return Op<-3>(); }
03091 
03092   /// setCalledFunction - Set the function called.
03093   void setCalledFunction(Value* Fn) {
03094     Op<-3>() = Fn;
03095   }
03096 
03097   // get*Dest - Return the destination basic blocks...
03098   BasicBlock *getNormalDest() const {
03099     return cast<BasicBlock>(Op<-2>());
03100   }
03101   BasicBlock *getUnwindDest() const {
03102     return cast<BasicBlock>(Op<-1>());
03103   }
03104   void setNormalDest(BasicBlock *B) {
03105     Op<-2>() = reinterpret_cast<Value*>(B);
03106   }
03107   void setUnwindDest(BasicBlock *B) {
03108     Op<-1>() = reinterpret_cast<Value*>(B);
03109   }
03110 
03111   /// getLandingPadInst - Get the landingpad instruction from the landing pad
03112   /// block (the unwind destination).
03113   LandingPadInst *getLandingPadInst() const;
03114 
03115   BasicBlock *getSuccessor(unsigned i) const {
03116     assert(i < 2 && "Successor # out of range for invoke!");
03117     return i == 0 ? getNormalDest() : getUnwindDest();
03118   }
03119 
03120   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
03121     assert(idx < 2 && "Successor # out of range for invoke!");
03122     *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
03123   }
03124 
03125   unsigned getNumSuccessors() const { return 2; }
03126 
03127   // Methods for support type inquiry through isa, cast, and dyn_cast:
03128   static inline bool classof(const Instruction *I) {
03129     return (I->getOpcode() == Instruction::Invoke);
03130   }
03131   static inline bool classof(const Value *V) {
03132     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03133   }
03134 
03135 private:
03136   virtual BasicBlock *getSuccessorV(unsigned idx) const;
03137   virtual unsigned getNumSuccessorsV() const;
03138   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
03139 
03140   // Shadow Instruction::setInstructionSubclassData with a private forwarding
03141   // method so that subclasses cannot accidentally use it.
03142   void setInstructionSubclassData(unsigned short D) {
03143     Instruction::setInstructionSubclassData(D);
03144   }
03145 };
03146 
03147 template <>
03148 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
03149 };
03150 
03151 InvokeInst::InvokeInst(Value *Func,
03152                        BasicBlock *IfNormal, BasicBlock *IfException,
03153                        ArrayRef<Value *> Args, unsigned Values,
03154                        const Twine &NameStr, Instruction *InsertBefore)
03155   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
03156                                       ->getElementType())->getReturnType(),
03157                    Instruction::Invoke,
03158                    OperandTraits<InvokeInst>::op_end(this) - Values,
03159                    Values, InsertBefore) {
03160   init(Func, IfNormal, IfException, Args, NameStr);
03161 }
03162 InvokeInst::InvokeInst(Value *Func,
03163                        BasicBlock *IfNormal, BasicBlock *IfException,
03164                        ArrayRef<Value *> Args, unsigned Values,
03165                        const Twine &NameStr, BasicBlock *InsertAtEnd)
03166   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
03167                                       ->getElementType())->getReturnType(),
03168                    Instruction::Invoke,
03169                    OperandTraits<InvokeInst>::op_end(this) - Values,
03170                    Values, InsertAtEnd) {
03171   init(Func, IfNormal, IfException, Args, NameStr);
03172 }
03173 
03174 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
03175 
03176 //===----------------------------------------------------------------------===//
03177 //                              ResumeInst Class
03178 //===----------------------------------------------------------------------===//
03179 
03180 //===---------------------------------------------------------------------------
03181 /// ResumeInst - Resume the propagation of an exception.
03182 ///
03183 class ResumeInst : public TerminatorInst {
03184   ResumeInst(const ResumeInst &RI);
03185 
03186   explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0);
03187   ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
03188 protected:
03189   virtual ResumeInst *clone_impl() const;
03190 public:
03191   static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) {
03192     return new(1) ResumeInst(Exn, InsertBefore);
03193   }
03194   static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
03195     return new(1) ResumeInst(Exn, InsertAtEnd);
03196   }
03197 
03198   /// Provide fast operand accessors
03199   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
03200 
03201   /// Convenience accessor.
03202   Value *getValue() const { return Op<0>(); }
03203 
03204   unsigned getNumSuccessors() const { return 0; }
03205 
03206   // Methods for support type inquiry through isa, cast, and dyn_cast:
03207   static inline bool classof(const Instruction *I) {
03208     return I->getOpcode() == Instruction::Resume;
03209   }
03210   static inline bool classof(const Value *V) {
03211     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03212   }
03213 private:
03214   virtual BasicBlock *getSuccessorV(unsigned idx) const;
03215   virtual unsigned getNumSuccessorsV() const;
03216   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
03217 };
03218 
03219 template <>
03220 struct OperandTraits<ResumeInst> :
03221     public FixedNumOperandTraits<ResumeInst, 1> {
03222 };
03223 
03224 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
03225 
03226 //===----------------------------------------------------------------------===//
03227 //                           UnreachableInst Class
03228 //===----------------------------------------------------------------------===//
03229 
03230 //===---------------------------------------------------------------------------
03231 /// UnreachableInst - This function has undefined behavior.  In particular, the
03232 /// presence of this instruction indicates some higher level knowledge that the
03233 /// end of the block cannot be reached.
03234 ///
03235 class UnreachableInst : public TerminatorInst {
03236   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
03237 protected:
03238   virtual UnreachableInst *clone_impl() const;
03239 
03240 public:
03241   // allocate space for exactly zero operands
03242   void *operator new(size_t s) {
03243     return User::operator new(s, 0);
03244   }
03245   explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
03246   explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
03247 
03248   unsigned getNumSuccessors() const { return 0; }
03249 
03250   // Methods for support type inquiry through isa, cast, and dyn_cast:
03251   static inline bool classof(const Instruction *I) {
03252     return I->getOpcode() == Instruction::Unreachable;
03253   }
03254   static inline bool classof(const Value *V) {
03255     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03256   }
03257 private:
03258   virtual BasicBlock *getSuccessorV(unsigned idx) const;
03259   virtual unsigned getNumSuccessorsV() const;
03260   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
03261 };
03262 
03263 //===----------------------------------------------------------------------===//
03264 //                                 TruncInst Class
03265 //===----------------------------------------------------------------------===//
03266 
03267 /// \brief This class represents a truncation of integer types.
03268 class TruncInst : public CastInst {
03269 protected:
03270   /// \brief Clone an identical TruncInst
03271   virtual TruncInst *clone_impl() const;
03272 
03273 public:
03274   /// \brief Constructor with insert-before-instruction semantics
03275   TruncInst(
03276     Value *S,                     ///< The value to be truncated
03277     Type *Ty,               ///< The (smaller) type to truncate to
03278     const Twine &NameStr = "",    ///< A name for the new instruction
03279     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03280   );
03281 
03282   /// \brief Constructor with insert-at-end-of-block semantics
03283   TruncInst(
03284     Value *S,                     ///< The value to be truncated
03285     Type *Ty,               ///< The (smaller) type to truncate to
03286     const Twine &NameStr,         ///< A name for the new instruction
03287     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03288   );
03289 
03290   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
03291   static inline bool classof(const Instruction *I) {
03292     return I->getOpcode() == Trunc;
03293   }
03294   static inline bool classof(const Value *V) {
03295     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03296   }
03297 };
03298 
03299 //===----------------------------------------------------------------------===//
03300 //                                 ZExtInst Class
03301 //===----------------------------------------------------------------------===//
03302 
03303 /// \brief This class represents zero extension of integer types.
03304 class ZExtInst : public CastInst {
03305 protected:
03306   /// \brief Clone an identical ZExtInst
03307   virtual ZExtInst *clone_impl() const;
03308 
03309 public:
03310   /// \brief Constructor with insert-before-instruction semantics
03311   ZExtInst(
03312     Value *S,                     ///< The value to be zero extended
03313     Type *Ty,               ///< The type to zero extend to
03314     const Twine &NameStr = "",    ///< A name for the new instruction
03315     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03316   );
03317 
03318   /// \brief Constructor with insert-at-end semantics.
03319   ZExtInst(
03320     Value *S,                     ///< The value to be zero extended
03321     Type *Ty,               ///< The type to zero extend to
03322     const Twine &NameStr,         ///< A name for the new instruction
03323     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03324   );
03325 
03326   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
03327   static inline bool classof(const Instruction *I) {
03328     return I->getOpcode() == ZExt;
03329   }
03330   static inline bool classof(const Value *V) {
03331     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03332   }
03333 };
03334 
03335 //===----------------------------------------------------------------------===//
03336 //                                 SExtInst Class
03337 //===----------------------------------------------------------------------===//
03338 
03339 /// \brief This class represents a sign extension of integer types.
03340 class SExtInst : public CastInst {
03341 protected:
03342   /// \brief Clone an identical SExtInst
03343   virtual SExtInst *clone_impl() const;
03344 
03345 public:
03346   /// \brief Constructor with insert-before-instruction semantics
03347   SExtInst(
03348     Value *S,                     ///< The value to be sign extended
03349     Type *Ty,               ///< The type to sign extend to
03350     const Twine &NameStr = "",    ///< A name for the new instruction
03351     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03352   );
03353 
03354   /// \brief Constructor with insert-at-end-of-block semantics
03355   SExtInst(
03356     Value *S,                     ///< The value to be sign extended
03357     Type *Ty,               ///< The type to sign extend to
03358     const Twine &NameStr,         ///< A name for the new instruction
03359     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03360   );
03361 
03362   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
03363   static inline bool classof(const Instruction *I) {
03364     return I->getOpcode() == SExt;
03365   }
03366   static inline bool classof(const Value *V) {
03367     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03368   }
03369 };
03370 
03371 //===----------------------------------------------------------------------===//
03372 //                                 FPTruncInst Class
03373 //===----------------------------------------------------------------------===//
03374 
03375 /// \brief This class represents a truncation of floating point types.
03376 class FPTruncInst : public CastInst {
03377 protected:
03378   /// \brief Clone an identical FPTruncInst
03379   virtual FPTruncInst *clone_impl() const;
03380 
03381 public:
03382   /// \brief Constructor with insert-before-instruction semantics
03383   FPTruncInst(
03384     Value *S,                     ///< The value to be truncated
03385     Type *Ty,               ///< The type to truncate to
03386     const Twine &NameStr = "",    ///< A name for the new instruction
03387     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03388   );
03389 
03390   /// \brief Constructor with insert-before-instruction semantics
03391   FPTruncInst(
03392     Value *S,                     ///< The value to be truncated
03393     Type *Ty,               ///< The type to truncate to
03394     const Twine &NameStr,         ///< A name for the new instruction
03395     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03396   );
03397 
03398   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
03399   static inline bool classof(const Instruction *I) {
03400     return I->getOpcode() == FPTrunc;
03401   }
03402   static inline bool classof(const Value *V) {
03403     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03404   }
03405 };
03406 
03407 //===----------------------------------------------------------------------===//
03408 //                                 FPExtInst Class
03409 //===----------------------------------------------------------------------===//
03410 
03411 /// \brief This class represents an extension of floating point types.
03412 class FPExtInst : public CastInst {
03413 protected:
03414   /// \brief Clone an identical FPExtInst
03415   virtual FPExtInst *clone_impl() const;
03416 
03417 public:
03418   /// \brief Constructor with insert-before-instruction semantics
03419   FPExtInst(
03420     Value *S,                     ///< The value to be extended
03421     Type *Ty,               ///< The type to extend to
03422     const Twine &NameStr = "",    ///< A name for the new instruction
03423     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03424   );
03425 
03426   /// \brief Constructor with insert-at-end-of-block semantics
03427   FPExtInst(
03428     Value *S,                     ///< The value to be extended
03429     Type *Ty,               ///< The type to extend to
03430     const Twine &NameStr,         ///< A name for the new instruction
03431     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03432   );
03433 
03434   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
03435   static inline bool classof(const Instruction *I) {
03436     return I->getOpcode() == FPExt;
03437   }
03438   static inline bool classof(const Value *V) {
03439     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03440   }
03441 };
03442 
03443 //===----------------------------------------------------------------------===//
03444 //                                 UIToFPInst Class
03445 //===----------------------------------------------------------------------===//
03446 
03447 /// \brief This class represents a cast unsigned integer to floating point.
03448 class UIToFPInst : public CastInst {
03449 protected:
03450   /// \brief Clone an identical UIToFPInst
03451   virtual UIToFPInst *clone_impl() const;
03452 
03453 public:
03454   /// \brief Constructor with insert-before-instruction semantics
03455   UIToFPInst(
03456     Value *S,                     ///< The value to be converted
03457     Type *Ty,               ///< The type to convert to
03458     const Twine &NameStr = "",    ///< A name for the new instruction
03459     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03460   );
03461 
03462   /// \brief Constructor with insert-at-end-of-block semantics
03463   UIToFPInst(
03464     Value *S,                     ///< The value to be converted
03465     Type *Ty,               ///< The type to convert to
03466     const Twine &NameStr,         ///< A name for the new instruction
03467     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03468   );
03469 
03470   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
03471   static inline bool classof(const Instruction *I) {
03472     return I->getOpcode() == UIToFP;
03473   }
03474   static inline bool classof(const Value *V) {
03475     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03476   }
03477 };
03478 
03479 //===----------------------------------------------------------------------===//
03480 //                                 SIToFPInst Class
03481 //===----------------------------------------------------------------------===//
03482 
03483 /// \brief This class represents a cast from signed integer to floating point.
03484 class SIToFPInst : public CastInst {
03485 protected:
03486   /// \brief Clone an identical SIToFPInst
03487   virtual SIToFPInst *clone_impl() const;
03488 
03489 public:
03490   /// \brief Constructor with insert-before-instruction semantics
03491   SIToFPInst(
03492     Value *S,                     ///< The value to be converted
03493     Type *Ty,               ///< The type to convert to
03494     const Twine &NameStr = "",    ///< A name for the new instruction
03495     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03496   );
03497 
03498   /// \brief Constructor with insert-at-end-of-block semantics
03499   SIToFPInst(
03500     Value *S,                     ///< The value to be converted
03501     Type *Ty,               ///< The type to convert to
03502     const Twine &NameStr,         ///< A name for the new instruction
03503     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03504   );
03505 
03506   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
03507   static inline bool classof(const Instruction *I) {
03508     return I->getOpcode() == SIToFP;
03509   }
03510   static inline bool classof(const Value *V) {
03511     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03512   }
03513 };
03514 
03515 //===----------------------------------------------------------------------===//
03516 //                                 FPToUIInst Class
03517 //===----------------------------------------------------------------------===//
03518 
03519 /// \brief This class represents a cast from floating point to unsigned integer
03520 class FPToUIInst  : public CastInst {
03521 protected:
03522   /// \brief Clone an identical FPToUIInst
03523   virtual FPToUIInst *clone_impl() const;
03524 
03525 public:
03526   /// \brief Constructor with insert-before-instruction semantics
03527   FPToUIInst(
03528     Value *S,                     ///< The value to be converted
03529     Type *Ty,               ///< The type to convert to
03530     const Twine &NameStr = "",    ///< A name for the new instruction
03531     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03532   );
03533 
03534   /// \brief Constructor with insert-at-end-of-block semantics
03535   FPToUIInst(
03536     Value *S,                     ///< The value to be converted
03537     Type *Ty,               ///< The type to convert to
03538     const Twine &NameStr,         ///< A name for the new instruction
03539     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
03540   );
03541 
03542   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
03543   static inline bool classof(const Instruction *I) {
03544     return I->getOpcode() == FPToUI;
03545   }
03546   static inline bool classof(const Value *V) {
03547     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03548   }
03549 };
03550 
03551 //===----------------------------------------------------------------------===//
03552 //                                 FPToSIInst Class
03553 //===----------------------------------------------------------------------===//
03554 
03555 /// \brief This class represents a cast from floating point to signed integer.
03556 class FPToSIInst  : public CastInst {
03557 protected:
03558   /// \brief Clone an identical FPToSIInst
03559   virtual FPToSIInst *clone_impl() const;
03560 
03561 public:
03562   /// \brief Constructor with insert-before-instruction semantics
03563   FPToSIInst(
03564     Value *S,                     ///< The value to be converted
03565     Type *Ty,               ///< The type to convert to
03566     const Twine &NameStr = "",    ///< A name for the new instruction
03567     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03568   );
03569 
03570   /// \brief Constructor with insert-at-end-of-block semantics
03571   FPToSIInst(
03572     Value *S,                     ///< The value to be converted
03573     Type *Ty,               ///< The type to convert to
03574     const Twine &NameStr,         ///< A name for the new instruction
03575     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03576   );
03577 
03578   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
03579   static inline bool classof(const Instruction *I) {
03580     return I->getOpcode() == FPToSI;
03581   }
03582   static inline bool classof(const Value *V) {
03583     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03584   }
03585 };
03586 
03587 //===----------------------------------------------------------------------===//
03588 //                                 IntToPtrInst Class
03589 //===----------------------------------------------------------------------===//
03590 
03591 /// \brief This class represents a cast from an integer to a pointer.
03592 class IntToPtrInst : public CastInst {
03593 public:
03594   /// \brief Constructor with insert-before-instruction semantics
03595   IntToPtrInst(
03596     Value *S,                     ///< The value to be converted
03597     Type *Ty,               ///< The type to convert to
03598     const Twine &NameStr = "",    ///< A name for the new instruction
03599     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03600   );
03601 
03602   /// \brief Constructor with insert-at-end-of-block semantics
03603   IntToPtrInst(
03604     Value *S,                     ///< The value to be converted
03605     Type *Ty,               ///< The type to convert to
03606     const Twine &NameStr,         ///< A name for the new instruction
03607     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03608   );
03609 
03610   /// \brief Clone an identical IntToPtrInst
03611   virtual IntToPtrInst *clone_impl() const;
03612 
03613   /// \brief Returns the address space of this instruction's pointer type.
03614   unsigned getAddressSpace() const {
03615     return getType()->getPointerAddressSpace();
03616   }
03617 
03618   // Methods for support type inquiry through isa, cast, and dyn_cast:
03619   static inline bool classof(const Instruction *I) {
03620     return I->getOpcode() == IntToPtr;
03621   }
03622   static inline bool classof(const Value *V) {
03623     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03624   }
03625 };
03626 
03627 //===----------------------------------------------------------------------===//
03628 //                                 PtrToIntInst Class
03629 //===----------------------------------------------------------------------===//
03630 
03631 /// \brief This class represents a cast from a pointer to an integer
03632 class PtrToIntInst : public CastInst {
03633 protected:
03634   /// \brief Clone an identical PtrToIntInst
03635   virtual PtrToIntInst *clone_impl() const;
03636 
03637 public:
03638   /// \brief Constructor with insert-before-instruction semantics
03639   PtrToIntInst(
03640     Value *S,                     ///< The value to be converted
03641     Type *Ty,               ///< The type to convert to
03642     const Twine &NameStr = "",    ///< A name for the new instruction
03643     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03644   );
03645 
03646   /// \brief Constructor with insert-at-end-of-block semantics
03647   PtrToIntInst(
03648     Value *S,                     ///< The value to be converted
03649     Type *Ty,               ///< The type to convert to
03650     const Twine &NameStr,         ///< A name for the new instruction
03651     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03652   );
03653 
03654   /// \brief Gets the pointer operand.
03655   Value *getPointerOperand() { return getOperand(0); }
03656   /// \brief Gets the pointer operand.
03657   const Value *getPointerOperand() const { return getOperand(0); }
03658   /// \brief Gets the operand index of the pointer operand.
03659   static unsigned getPointerOperandIndex() { return 0U; }
03660 
03661   /// \brief Returns the address space of the pointer operand.
03662   unsigned getPointerAddressSpace() const {
03663     return getPointerOperand()->getType()->getPointerAddressSpace();
03664   }
03665 
03666   // Methods for support type inquiry through isa, cast, and dyn_cast:
03667   static inline bool classof(const Instruction *I) {
03668     return I->getOpcode() == PtrToInt;
03669   }
03670   static inline bool classof(const Value *V) {
03671     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03672   }
03673 };
03674 
03675 //===----------------------------------------------------------------------===//
03676 //                             BitCastInst Class
03677 //===----------------------------------------------------------------------===//
03678 
03679 /// \brief This class represents a no-op cast from one type to another.
03680 class BitCastInst : public CastInst {
03681 protected:
03682   /// \brief Clone an identical BitCastInst
03683   virtual BitCastInst *clone_impl() const;
03684 
03685 public:
03686   /// \brief Constructor with insert-before-instruction semantics
03687   BitCastInst(
03688     Value *S,                     ///< The value to be casted
03689     Type *Ty,               ///< The type to casted to
03690     const Twine &NameStr = "",    ///< A name for the new instruction
03691     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
03692   );
03693 
03694   /// \brief Constructor with insert-at-end-of-block semantics
03695   BitCastInst(
03696     Value *S,                     ///< The value to be casted
03697     Type *Ty,               ///< The type to casted to
03698     const Twine &NameStr,         ///< A name for the new instruction
03699     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
03700   );
03701 
03702   // Methods for support type inquiry through isa, cast, and dyn_cast:
03703   static inline bool classof(const Instruction *I) {
03704     return I->getOpcode() == BitCast;
03705   }
03706   static inline bool classof(const Value *V) {
03707     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03708   }
03709 };
03710 
03711 } // End llvm namespace
03712 
03713 #endif