LLVM  mainline
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/ADT/STLExtras.h"
00022 #include "llvm/ADT/iterator_range.h"
00023 #include "llvm/IR/Attributes.h"
00024 #include "llvm/IR/CallingConv.h"
00025 #include "llvm/IR/DerivedTypes.h"
00026 #include "llvm/IR/Function.h"
00027 #include "llvm/IR/InstrTypes.h"
00028 #include "llvm/Support/ErrorHandling.h"
00029 #include <iterator>
00030 
00031 namespace llvm {
00032 
00033 class APInt;
00034 class ConstantInt;
00035 class ConstantRange;
00036 class DataLayout;
00037 class LLVMContext;
00038 
00039 enum AtomicOrdering {
00040   NotAtomic = 0,
00041   Unordered = 1,
00042   Monotonic = 2,
00043   // Consume = 3,  // Not specified yet.
00044   Acquire = 4,
00045   Release = 5,
00046   AcquireRelease = 6,
00047   SequentiallyConsistent = 7
00048 };
00049 
00050 enum SynchronizationScope {
00051   SingleThread = 0,
00052   CrossThread = 1
00053 };
00054 
00055 /// Returns true if the ordering is at least as strong as acquire
00056 /// (i.e. acquire, acq_rel or seq_cst)
00057 inline bool isAtLeastAcquire(AtomicOrdering Ord) {
00058    return (Ord == Acquire ||
00059     Ord == AcquireRelease ||
00060     Ord == SequentiallyConsistent);
00061 }
00062 
00063 /// Returns true if the ordering is at least as strong as release
00064 /// (i.e. release, acq_rel or seq_cst)
00065 inline bool isAtLeastRelease(AtomicOrdering Ord) {
00066 return (Ord == Release ||
00067     Ord == AcquireRelease ||
00068     Ord == SequentiallyConsistent);
00069 }
00070 
00071 //===----------------------------------------------------------------------===//
00072 //                                AllocaInst Class
00073 //===----------------------------------------------------------------------===//
00074 
00075 /// AllocaInst - an instruction to allocate memory on the stack
00076 ///
00077 class AllocaInst : public UnaryInstruction {
00078   Type *AllocatedType;
00079 
00080 protected:
00081   // Note: Instruction needs to be a friend here to call cloneImpl.
00082   friend class Instruction;
00083   AllocaInst *cloneImpl() const;
00084 
00085 public:
00086   explicit AllocaInst(Type *Ty, Value *ArraySize = nullptr,
00087                       const Twine &Name = "",
00088                       Instruction *InsertBefore = nullptr);
00089   AllocaInst(Type *Ty, Value *ArraySize,
00090              const Twine &Name, BasicBlock *InsertAtEnd);
00091 
00092   AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = nullptr);
00093   AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
00094 
00095   AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
00096              const Twine &Name = "", Instruction *InsertBefore = nullptr);
00097   AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
00098              const Twine &Name, BasicBlock *InsertAtEnd);
00099 
00100   // Out of line virtual method, so the vtable, etc. has a home.
00101   ~AllocaInst() override;
00102 
00103   /// isArrayAllocation - Return true if there is an allocation size parameter
00104   /// to the allocation instruction that is not 1.
00105   ///
00106   bool isArrayAllocation() const;
00107 
00108   /// getArraySize - Get the number of elements allocated. For a simple
00109   /// allocation of a single element, this will return a constant 1 value.
00110   ///
00111   const Value *getArraySize() const { return getOperand(0); }
00112   Value *getArraySize() { return getOperand(0); }
00113 
00114   /// getType - Overload to return most specific pointer type
00115   ///
00116   PointerType *getType() const {
00117     return cast<PointerType>(Instruction::getType());
00118   }
00119 
00120   /// getAllocatedType - Return the type that is being allocated by the
00121   /// instruction.
00122   ///
00123   Type *getAllocatedType() const { return AllocatedType; }
00124   /// \brief for use only in special circumstances that need to generically
00125   /// transform a whole instruction (eg: IR linking and vectorization).
00126   void setAllocatedType(Type *Ty) { AllocatedType = Ty; }
00127 
00128   /// getAlignment - Return the alignment of the memory that is being allocated
00129   /// by the instruction.
00130   ///
00131   unsigned getAlignment() const {
00132     return (1u << (getSubclassDataFromInstruction() & 31)) >> 1;
00133   }
00134   void setAlignment(unsigned Align);
00135 
00136   /// isStaticAlloca - Return true if this alloca is in the entry block of the
00137   /// function and is a constant size.  If so, the code generator will fold it
00138   /// into the prolog/epilog code, so it is basically free.
00139   bool isStaticAlloca() const;
00140 
00141   /// \brief Return true if this alloca is used as an inalloca argument to a
00142   /// call.  Such allocas are never considered static even if they are in the
00143   /// entry block.
00144   bool isUsedWithInAlloca() const {
00145     return getSubclassDataFromInstruction() & 32;
00146   }
00147 
00148   /// \brief Specify whether this alloca is used to represent the arguments to
00149   /// a call.
00150   void setUsedWithInAlloca(bool V) {
00151     setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) |
00152                                (V ? 32 : 0));
00153   }
00154 
00155   // Methods for support type inquiry through isa, cast, and dyn_cast:
00156   static inline bool classof(const Instruction *I) {
00157     return (I->getOpcode() == Instruction::Alloca);
00158   }
00159   static inline bool classof(const Value *V) {
00160     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00161   }
00162 
00163 private:
00164   // Shadow Instruction::setInstructionSubclassData with a private forwarding
00165   // method so that subclasses cannot accidentally use it.
00166   void setInstructionSubclassData(unsigned short D) {
00167     Instruction::setInstructionSubclassData(D);
00168   }
00169 };
00170 
00171 //===----------------------------------------------------------------------===//
00172 //                                LoadInst Class
00173 //===----------------------------------------------------------------------===//
00174 
00175 /// LoadInst - an instruction for reading from memory.  This uses the
00176 /// SubclassData field in Value to store whether or not the load is volatile.
00177 ///
00178 class LoadInst : public UnaryInstruction {
00179   void AssertOK();
00180 
00181 protected:
00182   // Note: Instruction needs to be a friend here to call cloneImpl.
00183   friend class Instruction;
00184   LoadInst *cloneImpl() const;
00185 
00186 public:
00187   LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
00188   LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
00189   LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile = false,
00190            Instruction *InsertBefore = nullptr);
00191   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
00192            Instruction *InsertBefore = nullptr)
00193       : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
00194                  NameStr, isVolatile, InsertBefore) {}
00195   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
00196            BasicBlock *InsertAtEnd);
00197   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
00198            Instruction *InsertBefore = nullptr)
00199       : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
00200                  NameStr, isVolatile, Align, InsertBefore) {}
00201   LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
00202            unsigned Align, Instruction *InsertBefore = nullptr);
00203   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
00204            unsigned Align, BasicBlock *InsertAtEnd);
00205   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
00206            AtomicOrdering Order, SynchronizationScope SynchScope = CrossThread,
00207            Instruction *InsertBefore = nullptr)
00208       : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
00209                  NameStr, isVolatile, Align, Order, SynchScope, InsertBefore) {}
00210   LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
00211            unsigned Align, AtomicOrdering Order,
00212            SynchronizationScope SynchScope = CrossThread,
00213            Instruction *InsertBefore = nullptr);
00214   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
00215            unsigned Align, AtomicOrdering Order,
00216            SynchronizationScope SynchScope,
00217            BasicBlock *InsertAtEnd);
00218 
00219   LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
00220   LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
00221   LoadInst(Type *Ty, Value *Ptr, const char *NameStr = nullptr,
00222            bool isVolatile = false, Instruction *InsertBefore = nullptr);
00223   explicit LoadInst(Value *Ptr, const char *NameStr = nullptr,
00224                     bool isVolatile = false,
00225                     Instruction *InsertBefore = nullptr)
00226       : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
00227                  NameStr, isVolatile, InsertBefore) {}
00228   LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
00229            BasicBlock *InsertAtEnd);
00230 
00231   /// isVolatile - Return true if this is a load from a volatile memory
00232   /// location.
00233   ///
00234   bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
00235 
00236   /// setVolatile - Specify whether this is a volatile load or not.
00237   ///
00238   void setVolatile(bool V) {
00239     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
00240                                (V ? 1 : 0));
00241   }
00242 
00243   /// getAlignment - Return the alignment of the access that is being performed
00244   ///
00245   unsigned getAlignment() const {
00246     return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
00247   }
00248 
00249   void setAlignment(unsigned Align);
00250 
00251   /// Returns the ordering effect of this fence.
00252   AtomicOrdering getOrdering() const {
00253     return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
00254   }
00255 
00256   /// Set the ordering constraint on this load. May not be Release or
00257   /// AcquireRelease.
00258   void setOrdering(AtomicOrdering Ordering) {
00259     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
00260                                (Ordering << 7));
00261   }
00262 
00263   SynchronizationScope getSynchScope() const {
00264     return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
00265   }
00266 
00267   /// Specify whether this load is ordered with respect to all
00268   /// concurrently executing threads, or only with respect to signal handlers
00269   /// executing in the same thread.
00270   void setSynchScope(SynchronizationScope xthread) {
00271     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
00272                                (xthread << 6));
00273   }
00274 
00275   void setAtomic(AtomicOrdering Ordering,
00276                  SynchronizationScope SynchScope = CrossThread) {
00277     setOrdering(Ordering);
00278     setSynchScope(SynchScope);
00279   }
00280 
00281   bool isSimple() const { return !isAtomic() && !isVolatile(); }
00282   bool isUnordered() const {
00283     return getOrdering() <= Unordered && !isVolatile();
00284   }
00285 
00286   Value *getPointerOperand() { return getOperand(0); }
00287   const Value *getPointerOperand() const { return getOperand(0); }
00288   static unsigned getPointerOperandIndex() { return 0U; }
00289 
00290   /// \brief Returns the address space of the pointer operand.
00291   unsigned getPointerAddressSpace() const {
00292     return getPointerOperand()->getType()->getPointerAddressSpace();
00293   }
00294 
00295   // Methods for support type inquiry through isa, cast, and dyn_cast:
00296   static inline bool classof(const Instruction *I) {
00297     return I->getOpcode() == Instruction::Load;
00298   }
00299   static inline bool classof(const Value *V) {
00300     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00301   }
00302 
00303 private:
00304   // Shadow Instruction::setInstructionSubclassData with a private forwarding
00305   // method so that subclasses cannot accidentally use it.
00306   void setInstructionSubclassData(unsigned short D) {
00307     Instruction::setInstructionSubclassData(D);
00308   }
00309 };
00310 
00311 //===----------------------------------------------------------------------===//
00312 //                                StoreInst Class
00313 //===----------------------------------------------------------------------===//
00314 
00315 /// StoreInst - an instruction for storing to memory
00316 ///
00317 class StoreInst : public Instruction {
00318   void *operator new(size_t, unsigned) = delete;
00319   void AssertOK();
00320 
00321 protected:
00322   // Note: Instruction needs to be a friend here to call cloneImpl.
00323   friend class Instruction;
00324   StoreInst *cloneImpl() const;
00325 
00326 public:
00327   // allocate space for exactly two operands
00328   void *operator new(size_t s) {
00329     return User::operator new(s, 2);
00330   }
00331   StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
00332   StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
00333   StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
00334             Instruction *InsertBefore = nullptr);
00335   StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
00336   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
00337             unsigned Align, Instruction *InsertBefore = nullptr);
00338   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
00339             unsigned Align, BasicBlock *InsertAtEnd);
00340   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
00341             unsigned Align, AtomicOrdering Order,
00342             SynchronizationScope SynchScope = CrossThread,
00343             Instruction *InsertBefore = nullptr);
00344   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
00345             unsigned Align, AtomicOrdering Order,
00346             SynchronizationScope SynchScope,
00347             BasicBlock *InsertAtEnd);
00348 
00349   /// isVolatile - Return true if this is a store to a volatile memory
00350   /// location.
00351   ///
00352   bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
00353 
00354   /// setVolatile - Specify whether this is a volatile store or not.
00355   ///
00356   void setVolatile(bool V) {
00357     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
00358                                (V ? 1 : 0));
00359   }
00360 
00361   /// Transparently provide more efficient getOperand methods.
00362   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00363 
00364   /// getAlignment - Return the alignment of the access that is being performed
00365   ///
00366   unsigned getAlignment() const {
00367     return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
00368   }
00369 
00370   void setAlignment(unsigned Align);
00371 
00372   /// Returns the ordering effect of this store.
00373   AtomicOrdering getOrdering() const {
00374     return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
00375   }
00376 
00377   /// Set the ordering constraint on this store.  May not be Acquire or
00378   /// AcquireRelease.
00379   void setOrdering(AtomicOrdering Ordering) {
00380     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
00381                                (Ordering << 7));
00382   }
00383 
00384   SynchronizationScope getSynchScope() const {
00385     return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
00386   }
00387 
00388   /// Specify whether this store instruction is ordered with respect to all
00389   /// concurrently executing threads, or only with respect to signal handlers
00390   /// executing in the same thread.
00391   void setSynchScope(SynchronizationScope xthread) {
00392     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
00393                                (xthread << 6));
00394   }
00395 
00396   void setAtomic(AtomicOrdering Ordering,
00397                  SynchronizationScope SynchScope = CrossThread) {
00398     setOrdering(Ordering);
00399     setSynchScope(SynchScope);
00400   }
00401 
00402   bool isSimple() const { return !isAtomic() && !isVolatile(); }
00403   bool isUnordered() const {
00404     return getOrdering() <= Unordered && !isVolatile();
00405   }
00406 
00407   Value *getValueOperand() { return getOperand(0); }
00408   const Value *getValueOperand() const { return getOperand(0); }
00409 
00410   Value *getPointerOperand() { return getOperand(1); }
00411   const Value *getPointerOperand() const { return getOperand(1); }
00412   static unsigned getPointerOperandIndex() { return 1U; }
00413 
00414   /// \brief Returns the address space of the pointer operand.
00415   unsigned getPointerAddressSpace() const {
00416     return getPointerOperand()->getType()->getPointerAddressSpace();
00417   }
00418 
00419   // Methods for support type inquiry through isa, cast, and dyn_cast:
00420   static inline bool classof(const Instruction *I) {
00421     return I->getOpcode() == Instruction::Store;
00422   }
00423   static inline bool classof(const Value *V) {
00424     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00425   }
00426 
00427 private:
00428   // Shadow Instruction::setInstructionSubclassData with a private forwarding
00429   // method so that subclasses cannot accidentally use it.
00430   void setInstructionSubclassData(unsigned short D) {
00431     Instruction::setInstructionSubclassData(D);
00432   }
00433 };
00434 
00435 template <>
00436 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
00437 };
00438 
00439 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
00440 
00441 //===----------------------------------------------------------------------===//
00442 //                                FenceInst Class
00443 //===----------------------------------------------------------------------===//
00444 
00445 /// FenceInst - an instruction for ordering other memory operations
00446 ///
00447 class FenceInst : public Instruction {
00448   void *operator new(size_t, unsigned) = delete;
00449   void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
00450 
00451 protected:
00452   // Note: Instruction needs to be a friend here to call cloneImpl.
00453   friend class Instruction;
00454   FenceInst *cloneImpl() const;
00455 
00456 public:
00457   // allocate space for exactly zero operands
00458   void *operator new(size_t s) {
00459     return User::operator new(s, 0);
00460   }
00461 
00462   // Ordering may only be Acquire, Release, AcquireRelease, or
00463   // SequentiallyConsistent.
00464   FenceInst(LLVMContext &C, AtomicOrdering Ordering,
00465             SynchronizationScope SynchScope = CrossThread,
00466             Instruction *InsertBefore = nullptr);
00467   FenceInst(LLVMContext &C, AtomicOrdering Ordering,
00468             SynchronizationScope SynchScope,
00469             BasicBlock *InsertAtEnd);
00470 
00471   /// Returns the ordering effect of this fence.
00472   AtomicOrdering getOrdering() const {
00473     return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
00474   }
00475 
00476   /// Set the ordering constraint on this fence.  May only be Acquire, Release,
00477   /// AcquireRelease, or SequentiallyConsistent.
00478   void setOrdering(AtomicOrdering Ordering) {
00479     setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
00480                                (Ordering << 1));
00481   }
00482 
00483   SynchronizationScope getSynchScope() const {
00484     return SynchronizationScope(getSubclassDataFromInstruction() & 1);
00485   }
00486 
00487   /// Specify whether this fence orders other operations with respect to all
00488   /// concurrently executing threads, or only with respect to signal handlers
00489   /// executing in the same thread.
00490   void setSynchScope(SynchronizationScope xthread) {
00491     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
00492                                xthread);
00493   }
00494 
00495   // Methods for support type inquiry through isa, cast, and dyn_cast:
00496   static inline bool classof(const Instruction *I) {
00497     return I->getOpcode() == Instruction::Fence;
00498   }
00499   static inline bool classof(const Value *V) {
00500     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00501   }
00502 
00503 private:
00504   // Shadow Instruction::setInstructionSubclassData with a private forwarding
00505   // method so that subclasses cannot accidentally use it.
00506   void setInstructionSubclassData(unsigned short D) {
00507     Instruction::setInstructionSubclassData(D);
00508   }
00509 };
00510 
00511 //===----------------------------------------------------------------------===//
00512 //                                AtomicCmpXchgInst Class
00513 //===----------------------------------------------------------------------===//
00514 
00515 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
00516 /// specified value is in a memory location, and, if it is, stores a new value
00517 /// there.  Returns the value that was loaded.
00518 ///
00519 class AtomicCmpXchgInst : public Instruction {
00520   void *operator new(size_t, unsigned) = delete;
00521   void Init(Value *Ptr, Value *Cmp, Value *NewVal,
00522             AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
00523             SynchronizationScope SynchScope);
00524 
00525 protected:
00526   // Note: Instruction needs to be a friend here to call cloneImpl.
00527   friend class Instruction;
00528   AtomicCmpXchgInst *cloneImpl() const;
00529 
00530 public:
00531   // allocate space for exactly three operands
00532   void *operator new(size_t s) {
00533     return User::operator new(s, 3);
00534   }
00535   AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
00536                     AtomicOrdering SuccessOrdering,
00537                     AtomicOrdering FailureOrdering,
00538                     SynchronizationScope SynchScope,
00539                     Instruction *InsertBefore = nullptr);
00540   AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
00541                     AtomicOrdering SuccessOrdering,
00542                     AtomicOrdering FailureOrdering,
00543                     SynchronizationScope SynchScope,
00544                     BasicBlock *InsertAtEnd);
00545 
00546   /// isVolatile - Return true if this is a cmpxchg from a volatile memory
00547   /// location.
00548   ///
00549   bool isVolatile() const {
00550     return getSubclassDataFromInstruction() & 1;
00551   }
00552 
00553   /// setVolatile - Specify whether this is a volatile cmpxchg.
00554   ///
00555   void setVolatile(bool V) {
00556      setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
00557                                 (unsigned)V);
00558   }
00559 
00560   /// Return true if this cmpxchg may spuriously fail.
00561   bool isWeak() const {
00562     return getSubclassDataFromInstruction() & 0x100;
00563   }
00564 
00565   void setWeak(bool IsWeak) {
00566     setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x100) |
00567                                (IsWeak << 8));
00568   }
00569 
00570   /// Transparently provide more efficient getOperand methods.
00571   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00572 
00573   /// Set the ordering constraint on this cmpxchg.
00574   void setSuccessOrdering(AtomicOrdering Ordering) {
00575     assert(Ordering != NotAtomic &&
00576            "CmpXchg instructions can only be atomic.");
00577     setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) |
00578                                (Ordering << 2));
00579   }
00580 
00581   void setFailureOrdering(AtomicOrdering Ordering) {
00582     assert(Ordering != NotAtomic &&
00583            "CmpXchg instructions can only be atomic.");
00584     setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) |
00585                                (Ordering << 5));
00586   }
00587 
00588   /// Specify whether this cmpxchg is atomic and orders other operations with
00589   /// respect to all concurrently executing threads, or only with respect to
00590   /// signal handlers executing in the same thread.
00591   void setSynchScope(SynchronizationScope SynchScope) {
00592     setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
00593                                (SynchScope << 1));
00594   }
00595 
00596   /// Returns the ordering constraint on this cmpxchg.
00597   AtomicOrdering getSuccessOrdering() const {
00598     return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
00599   }
00600 
00601   /// Returns the ordering constraint on this cmpxchg.
00602   AtomicOrdering getFailureOrdering() const {
00603     return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7);
00604   }
00605 
00606   /// Returns whether this cmpxchg is atomic between threads or only within a
00607   /// single thread.
00608   SynchronizationScope getSynchScope() const {
00609     return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
00610   }
00611 
00612   Value *getPointerOperand() { return getOperand(0); }
00613   const Value *getPointerOperand() const { return getOperand(0); }
00614   static unsigned getPointerOperandIndex() { return 0U; }
00615 
00616   Value *getCompareOperand() { return getOperand(1); }
00617   const Value *getCompareOperand() const { return getOperand(1); }
00618 
00619   Value *getNewValOperand() { return getOperand(2); }
00620   const Value *getNewValOperand() const { return getOperand(2); }
00621 
00622   /// \brief Returns the address space of the pointer operand.
00623   unsigned getPointerAddressSpace() const {
00624     return getPointerOperand()->getType()->getPointerAddressSpace();
00625   }
00626 
00627   /// \brief Returns the strongest permitted ordering on failure, given the
00628   /// desired ordering on success.
00629   ///
00630   /// If the comparison in a cmpxchg operation fails, there is no atomic store
00631   /// so release semantics cannot be provided. So this function drops explicit
00632   /// Release requests from the AtomicOrdering. A SequentiallyConsistent
00633   /// operation would remain SequentiallyConsistent.
00634   static AtomicOrdering
00635   getStrongestFailureOrdering(AtomicOrdering SuccessOrdering) {
00636     switch (SuccessOrdering) {
00637     default: llvm_unreachable("invalid cmpxchg success ordering");
00638     case Release:
00639     case Monotonic:
00640       return Monotonic;
00641     case AcquireRelease:
00642     case Acquire:
00643       return Acquire;
00644     case SequentiallyConsistent:
00645       return SequentiallyConsistent;
00646     }
00647   }
00648 
00649   // Methods for support type inquiry through isa, cast, and dyn_cast:
00650   static inline bool classof(const Instruction *I) {
00651     return I->getOpcode() == Instruction::AtomicCmpXchg;
00652   }
00653   static inline bool classof(const Value *V) {
00654     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00655   }
00656 
00657 private:
00658   // Shadow Instruction::setInstructionSubclassData with a private forwarding
00659   // method so that subclasses cannot accidentally use it.
00660   void setInstructionSubclassData(unsigned short D) {
00661     Instruction::setInstructionSubclassData(D);
00662   }
00663 };
00664 
00665 template <>
00666 struct OperandTraits<AtomicCmpXchgInst> :
00667     public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
00668 };
00669 
00670 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
00671 
00672 //===----------------------------------------------------------------------===//
00673 //                                AtomicRMWInst Class
00674 //===----------------------------------------------------------------------===//
00675 
00676 /// AtomicRMWInst - an instruction that atomically reads a memory location,
00677 /// combines it with another value, and then stores the result back.  Returns
00678 /// the old value.
00679 ///
00680 class AtomicRMWInst : public Instruction {
00681   void *operator new(size_t, unsigned) = delete;
00682 
00683 protected:
00684   // Note: Instruction needs to be a friend here to call cloneImpl.
00685   friend class Instruction;
00686   AtomicRMWInst *cloneImpl() const;
00687 
00688 public:
00689   /// This enumeration lists the possible modifications atomicrmw can make.  In
00690   /// the descriptions, 'p' is the pointer to the instruction's memory location,
00691   /// 'old' is the initial value of *p, and 'v' is the other value passed to the
00692   /// instruction.  These instructions always return 'old'.
00693   enum BinOp {
00694     /// *p = v
00695     Xchg,
00696     /// *p = old + v
00697     Add,
00698     /// *p = old - v
00699     Sub,
00700     /// *p = old & v
00701     And,
00702     /// *p = ~(old & v)
00703     Nand,
00704     /// *p = old | v
00705     Or,
00706     /// *p = old ^ v
00707     Xor,
00708     /// *p = old >signed v ? old : v
00709     Max,
00710     /// *p = old <signed v ? old : v
00711     Min,
00712     /// *p = old >unsigned v ? old : v
00713     UMax,
00714     /// *p = old <unsigned v ? old : v
00715     UMin,
00716 
00717     FIRST_BINOP = Xchg,
00718     LAST_BINOP = UMin,
00719     BAD_BINOP
00720   };
00721 
00722   // allocate space for exactly two operands
00723   void *operator new(size_t s) {
00724     return User::operator new(s, 2);
00725   }
00726   AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
00727                 AtomicOrdering Ordering, SynchronizationScope SynchScope,
00728                 Instruction *InsertBefore = nullptr);
00729   AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
00730                 AtomicOrdering Ordering, SynchronizationScope SynchScope,
00731                 BasicBlock *InsertAtEnd);
00732 
00733   BinOp getOperation() const {
00734     return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
00735   }
00736 
00737   void setOperation(BinOp Operation) {
00738     unsigned short SubclassData = getSubclassDataFromInstruction();
00739     setInstructionSubclassData((SubclassData & 31) |
00740                                (Operation << 5));
00741   }
00742 
00743   /// isVolatile - Return true if this is a RMW on a volatile memory location.
00744   ///
00745   bool isVolatile() const {
00746     return getSubclassDataFromInstruction() & 1;
00747   }
00748 
00749   /// setVolatile - Specify whether this is a volatile RMW or not.
00750   ///
00751   void setVolatile(bool V) {
00752      setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
00753                                 (unsigned)V);
00754   }
00755 
00756   /// Transparently provide more efficient getOperand methods.
00757   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00758 
00759   /// Set the ordering constraint on this RMW.
00760   void setOrdering(AtomicOrdering Ordering) {
00761     assert(Ordering != NotAtomic &&
00762            "atomicrmw instructions can only be atomic.");
00763     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
00764                                (Ordering << 2));
00765   }
00766 
00767   /// Specify whether this RMW orders other operations with respect to all
00768   /// concurrently executing threads, or only with respect to signal handlers
00769   /// executing in the same thread.
00770   void setSynchScope(SynchronizationScope SynchScope) {
00771     setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
00772                                (SynchScope << 1));
00773   }
00774 
00775   /// Returns the ordering constraint on this RMW.
00776   AtomicOrdering getOrdering() const {
00777     return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
00778   }
00779 
00780   /// Returns whether this RMW is atomic between threads or only within a
00781   /// single thread.
00782   SynchronizationScope getSynchScope() const {
00783     return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
00784   }
00785 
00786   Value *getPointerOperand() { return getOperand(0); }
00787   const Value *getPointerOperand() const { return getOperand(0); }
00788   static unsigned getPointerOperandIndex() { return 0U; }
00789 
00790   Value *getValOperand() { return getOperand(1); }
00791   const Value *getValOperand() const { return getOperand(1); }
00792 
00793   /// \brief Returns the address space of the pointer operand.
00794   unsigned getPointerAddressSpace() const {
00795     return getPointerOperand()->getType()->getPointerAddressSpace();
00796   }
00797 
00798   // Methods for support type inquiry through isa, cast, and dyn_cast:
00799   static inline bool classof(const Instruction *I) {
00800     return I->getOpcode() == Instruction::AtomicRMW;
00801   }
00802   static inline bool classof(const Value *V) {
00803     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00804   }
00805 
00806 private:
00807   void Init(BinOp Operation, Value *Ptr, Value *Val,
00808             AtomicOrdering Ordering, SynchronizationScope SynchScope);
00809   // Shadow Instruction::setInstructionSubclassData with a private forwarding
00810   // method so that subclasses cannot accidentally use it.
00811   void setInstructionSubclassData(unsigned short D) {
00812     Instruction::setInstructionSubclassData(D);
00813   }
00814 };
00815 
00816 template <>
00817 struct OperandTraits<AtomicRMWInst>
00818     : public FixedNumOperandTraits<AtomicRMWInst,2> {
00819 };
00820 
00821 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
00822 
00823 //===----------------------------------------------------------------------===//
00824 //                             GetElementPtrInst Class
00825 //===----------------------------------------------------------------------===//
00826 
00827 // checkGEPType - Simple wrapper function to give a better assertion failure
00828 // message on bad indexes for a gep instruction.
00829 //
00830 inline Type *checkGEPType(Type *Ty) {
00831   assert(Ty && "Invalid GetElementPtrInst indices for type!");
00832   return Ty;
00833 }
00834 
00835 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
00836 /// access elements of arrays and structs
00837 ///
00838 class GetElementPtrInst : public Instruction {
00839   Type *SourceElementType;
00840   Type *ResultElementType;
00841 
00842   void anchor() override;
00843 
00844   GetElementPtrInst(const GetElementPtrInst &GEPI);
00845   void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
00846 
00847   /// Constructors - Create a getelementptr instruction with a base pointer an
00848   /// list of indices. The first ctor can optionally insert before an existing
00849   /// instruction, the second appends the new instruction to the specified
00850   /// BasicBlock.
00851   inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
00852                            ArrayRef<Value *> IdxList, unsigned Values,
00853                            const Twine &NameStr, Instruction *InsertBefore);
00854   inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
00855                            ArrayRef<Value *> IdxList, unsigned Values,
00856                            const Twine &NameStr, BasicBlock *InsertAtEnd);
00857 
00858 protected:
00859   // Note: Instruction needs to be a friend here to call cloneImpl.
00860   friend class Instruction;
00861   GetElementPtrInst *cloneImpl() const;
00862 
00863 public:
00864   static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
00865                                    ArrayRef<Value *> IdxList,
00866                                    const Twine &NameStr = "",
00867                                    Instruction *InsertBefore = nullptr) {
00868     unsigned Values = 1 + unsigned(IdxList.size());
00869     if (!PointeeType)
00870       PointeeType =
00871           cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
00872     else
00873       assert(
00874           PointeeType ==
00875           cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
00876     return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
00877                                           NameStr, InsertBefore);
00878   }
00879   static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
00880                                    ArrayRef<Value *> IdxList,
00881                                    const Twine &NameStr,
00882                                    BasicBlock *InsertAtEnd) {
00883     unsigned Values = 1 + unsigned(IdxList.size());
00884     if (!PointeeType)
00885       PointeeType =
00886           cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
00887     else
00888       assert(
00889           PointeeType ==
00890           cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
00891     return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
00892                                           NameStr, InsertAtEnd);
00893   }
00894 
00895   /// Create an "inbounds" getelementptr. See the documentation for the
00896   /// "inbounds" flag in LangRef.html for details.
00897   static GetElementPtrInst *CreateInBounds(Value *Ptr,
00898                                            ArrayRef<Value *> IdxList,
00899                                            const Twine &NameStr = "",
00900                                            Instruction *InsertBefore = nullptr){
00901     return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore);
00902   }
00903   static GetElementPtrInst *
00904   CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
00905                  const Twine &NameStr = "",
00906                  Instruction *InsertBefore = nullptr) {
00907     GetElementPtrInst *GEP =
00908         Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
00909     GEP->setIsInBounds(true);
00910     return GEP;
00911   }
00912   static GetElementPtrInst *CreateInBounds(Value *Ptr,
00913                                            ArrayRef<Value *> IdxList,
00914                                            const Twine &NameStr,
00915                                            BasicBlock *InsertAtEnd) {
00916     return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd);
00917   }
00918   static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,
00919                                            ArrayRef<Value *> IdxList,
00920                                            const Twine &NameStr,
00921                                            BasicBlock *InsertAtEnd) {
00922     GetElementPtrInst *GEP =
00923         Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd);
00924     GEP->setIsInBounds(true);
00925     return GEP;
00926   }
00927 
00928   /// Transparently provide more efficient getOperand methods.
00929   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00930 
00931   // getType - Overload to return most specific sequential type.
00932   SequentialType *getType() const {
00933     return cast<SequentialType>(Instruction::getType());
00934   }
00935 
00936   Type *getSourceElementType() const { return SourceElementType; }
00937 
00938   void setSourceElementType(Type *Ty) { SourceElementType = Ty; }
00939   void setResultElementType(Type *Ty) { ResultElementType = Ty; }
00940 
00941   Type *getResultElementType() const {
00942     assert(ResultElementType ==
00943            cast<PointerType>(getType()->getScalarType())->getElementType());
00944     return ResultElementType;
00945   }
00946 
00947   /// \brief Returns the address space of this instruction's pointer type.
00948   unsigned getAddressSpace() const {
00949     // Note that this is always the same as the pointer operand's address space
00950     // and that is cheaper to compute, so cheat here.
00951     return getPointerAddressSpace();
00952   }
00953 
00954   /// getIndexedType - Returns the type of the element that would be loaded with
00955   /// a load instruction with the specified parameters.
00956   ///
00957   /// Null is returned if the indices are invalid for the specified
00958   /// pointer type.
00959   ///
00960   static Type *getIndexedType(Type *Ty, ArrayRef<Value *> IdxList);
00961   static Type *getIndexedType(Type *Ty, ArrayRef<Constant *> IdxList);
00962   static Type *getIndexedType(Type *Ty, ArrayRef<uint64_t> IdxList);
00963 
00964   inline op_iterator       idx_begin()       { return op_begin()+1; }
00965   inline const_op_iterator idx_begin() const { return op_begin()+1; }
00966   inline op_iterator       idx_end()         { return op_end(); }
00967   inline const_op_iterator idx_end()   const { return op_end(); }
00968 
00969   Value *getPointerOperand() {
00970     return getOperand(0);
00971   }
00972   const Value *getPointerOperand() const {
00973     return getOperand(0);
00974   }
00975   static unsigned getPointerOperandIndex() {
00976     return 0U;    // get index for modifying correct operand.
00977   }
00978 
00979   /// getPointerOperandType - Method to return the pointer operand as a
00980   /// PointerType.
00981   Type *getPointerOperandType() const {
00982     return getPointerOperand()->getType();
00983   }
00984 
00985   /// \brief Returns the address space of the pointer operand.
00986   unsigned getPointerAddressSpace() const {
00987     return getPointerOperandType()->getPointerAddressSpace();
00988   }
00989 
00990   /// GetGEPReturnType - Returns the pointer type returned by the GEP
00991   /// instruction, which may be a vector of pointers.
00992   static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
00993     return getGEPReturnType(
00994         cast<PointerType>(Ptr->getType()->getScalarType())->getElementType(),
00995         Ptr, IdxList);
00996   }
00997   static Type *getGEPReturnType(Type *ElTy, Value *Ptr,
00998                                 ArrayRef<Value *> IdxList) {
00999     Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)),
01000                                    Ptr->getType()->getPointerAddressSpace());
01001     // Vector GEP
01002     if (Ptr->getType()->isVectorTy()) {
01003       unsigned NumElem = Ptr->getType()->getVectorNumElements();
01004       return VectorType::get(PtrTy, NumElem);
01005     }
01006     for (Value *Index : IdxList)
01007       if (Index->getType()->isVectorTy()) {
01008         unsigned NumElem = Index->getType()->getVectorNumElements();
01009         return VectorType::get(PtrTy, NumElem);
01010       }
01011     // Scalar GEP
01012     return PtrTy;
01013   }
01014 
01015   unsigned getNumIndices() const {  // Note: always non-negative
01016     return getNumOperands() - 1;
01017   }
01018 
01019   bool hasIndices() const {
01020     return getNumOperands() > 1;
01021   }
01022 
01023   /// hasAllZeroIndices - Return true if all of the indices of this GEP are
01024   /// zeros.  If so, the result pointer and the first operand have the same
01025   /// value, just potentially different types.
01026   bool hasAllZeroIndices() const;
01027 
01028   /// hasAllConstantIndices - Return true if all of the indices of this GEP are
01029   /// constant integers.  If so, the result pointer and the first operand have
01030   /// a constant offset between them.
01031   bool hasAllConstantIndices() const;
01032 
01033   /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
01034   /// See LangRef.html for the meaning of inbounds on a getelementptr.
01035   void setIsInBounds(bool b = true);
01036 
01037   /// isInBounds - Determine whether the GEP has the inbounds flag.
01038   bool isInBounds() const;
01039 
01040   /// \brief Accumulate the constant address offset of this GEP if possible.
01041   ///
01042   /// This routine accepts an APInt into which it will accumulate the constant
01043   /// offset of this GEP if the GEP is in fact constant. If the GEP is not
01044   /// all-constant, it returns false and the value of the offset APInt is
01045   /// undefined (it is *not* preserved!). The APInt passed into this routine
01046   /// must be at least as wide as the IntPtr type for the address space of
01047   /// the base GEP pointer.
01048   bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
01049 
01050   // Methods for support type inquiry through isa, cast, and dyn_cast:
01051   static inline bool classof(const Instruction *I) {
01052     return (I->getOpcode() == Instruction::GetElementPtr);
01053   }
01054   static inline bool classof(const Value *V) {
01055     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01056   }
01057 };
01058 
01059 template <>
01060 struct OperandTraits<GetElementPtrInst> :
01061   public VariadicOperandTraits<GetElementPtrInst, 1> {
01062 };
01063 
01064 GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
01065                                      ArrayRef<Value *> IdxList, unsigned Values,
01066                                      const Twine &NameStr,
01067                                      Instruction *InsertBefore)
01068     : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
01069                   OperandTraits<GetElementPtrInst>::op_end(this) - Values,
01070                   Values, InsertBefore),
01071       SourceElementType(PointeeType),
01072       ResultElementType(getIndexedType(PointeeType, IdxList)) {
01073   assert(ResultElementType ==
01074          cast<PointerType>(getType()->getScalarType())->getElementType());
01075   init(Ptr, IdxList, NameStr);
01076 }
01077 GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
01078                                      ArrayRef<Value *> IdxList, unsigned Values,
01079                                      const Twine &NameStr,
01080                                      BasicBlock *InsertAtEnd)
01081     : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
01082                   OperandTraits<GetElementPtrInst>::op_end(this) - Values,
01083                   Values, InsertAtEnd),
01084       SourceElementType(PointeeType),
01085       ResultElementType(getIndexedType(PointeeType, IdxList)) {
01086   assert(ResultElementType ==
01087          cast<PointerType>(getType()->getScalarType())->getElementType());
01088   init(Ptr, IdxList, NameStr);
01089 }
01090 
01091 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
01092 
01093 //===----------------------------------------------------------------------===//
01094 //                               ICmpInst Class
01095 //===----------------------------------------------------------------------===//
01096 
01097 /// This instruction compares its operands according to the predicate given
01098 /// to the constructor. It only operates on integers or pointers. The operands
01099 /// must be identical types.
01100 /// \brief Represent an integer comparison operator.
01101 class ICmpInst: public CmpInst {
01102   void anchor() override;
01103 
01104   void AssertOK() {
01105     assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE &&
01106            getPredicate() <= CmpInst::LAST_ICMP_PREDICATE &&
01107            "Invalid ICmp predicate value");
01108     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
01109           "Both operands to ICmp instruction are not of the same type!");
01110     // Check that the operands are the right type
01111     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
01112             getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
01113            "Invalid operand types for ICmp instruction");
01114   }
01115 
01116 protected:
01117   // Note: Instruction needs to be a friend here to call cloneImpl.
01118   friend class Instruction;
01119   /// \brief Clone an identical ICmpInst
01120   ICmpInst *cloneImpl() const;
01121 
01122 public:
01123   /// \brief Constructor with insert-before-instruction semantics.
01124   ICmpInst(
01125     Instruction *InsertBefore,  ///< Where to insert
01126     Predicate pred,  ///< The predicate to use for the comparison
01127     Value *LHS,      ///< The left-hand-side of the expression
01128     Value *RHS,      ///< The right-hand-side of the expression
01129     const Twine &NameStr = ""  ///< Name of the instruction
01130   ) : CmpInst(makeCmpResultType(LHS->getType()),
01131               Instruction::ICmp, pred, LHS, RHS, NameStr,
01132               InsertBefore) {
01133 #ifndef NDEBUG
01134   AssertOK();
01135 #endif
01136   }
01137 
01138   /// \brief Constructor with insert-at-end semantics.
01139   ICmpInst(
01140     BasicBlock &InsertAtEnd, ///< Block to insert into.
01141     Predicate pred,  ///< The predicate to use for the comparison
01142     Value *LHS,      ///< The left-hand-side of the expression
01143     Value *RHS,      ///< The right-hand-side of the expression
01144     const Twine &NameStr = ""  ///< Name of the instruction
01145   ) : CmpInst(makeCmpResultType(LHS->getType()),
01146               Instruction::ICmp, pred, LHS, RHS, NameStr,
01147               &InsertAtEnd) {
01148 #ifndef NDEBUG
01149   AssertOK();
01150 #endif
01151   }
01152 
01153   /// \brief Constructor with no-insertion semantics
01154   ICmpInst(
01155     Predicate pred, ///< The predicate to use for the comparison
01156     Value *LHS,     ///< The left-hand-side of the expression
01157     Value *RHS,     ///< The right-hand-side of the expression
01158     const Twine &NameStr = "" ///< Name of the instruction
01159   ) : CmpInst(makeCmpResultType(LHS->getType()),
01160               Instruction::ICmp, pred, LHS, RHS, NameStr) {
01161 #ifndef NDEBUG
01162   AssertOK();
01163 #endif
01164   }
01165 
01166   /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
01167   /// @returns the predicate that would be the result if the operand were
01168   /// regarded as signed.
01169   /// \brief Return the signed version of the predicate
01170   Predicate getSignedPredicate() const {
01171     return getSignedPredicate(getPredicate());
01172   }
01173 
01174   /// This is a static version that you can use without an instruction.
01175   /// \brief Return the signed version of the predicate.
01176   static Predicate getSignedPredicate(Predicate pred);
01177 
01178   /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
01179   /// @returns the predicate that would be the result if the operand were
01180   /// regarded as unsigned.
01181   /// \brief Return the unsigned version of the predicate
01182   Predicate getUnsignedPredicate() const {
01183     return getUnsignedPredicate(getPredicate());
01184   }
01185 
01186   /// This is a static version that you can use without an instruction.
01187   /// \brief Return the unsigned version of the predicate.
01188   static Predicate getUnsignedPredicate(Predicate pred);
01189 
01190   /// isEquality - Return true if this predicate is either EQ or NE.  This also
01191   /// tests for commutativity.
01192   static bool isEquality(Predicate P) {
01193     return P == ICMP_EQ || P == ICMP_NE;
01194   }
01195 
01196   /// isEquality - Return true if this predicate is either EQ or NE.  This also
01197   /// tests for commutativity.
01198   bool isEquality() const {
01199     return isEquality(getPredicate());
01200   }
01201 
01202   /// @returns true if the predicate of this ICmpInst is commutative
01203   /// \brief Determine if this relation is commutative.
01204   bool isCommutative() const { return isEquality(); }
01205 
01206   /// isRelational - Return true if the predicate is relational (not EQ or NE).
01207   ///
01208   bool isRelational() const {
01209     return !isEquality();
01210   }
01211 
01212   /// isRelational - Return true if the predicate is relational (not EQ or NE).
01213   ///
01214   static bool isRelational(Predicate P) {
01215     return !isEquality(P);
01216   }
01217 
01218   /// Initialize a set of values that all satisfy the predicate with C.
01219   /// \brief Make a ConstantRange for a relation with a constant value.
01220   static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
01221 
01222   /// Exchange the two operands to this instruction in such a way that it does
01223   /// not modify the semantics of the instruction. The predicate value may be
01224   /// changed to retain the same result if the predicate is order dependent
01225   /// (e.g. ult).
01226   /// \brief Swap operands and adjust predicate.
01227   void swapOperands() {
01228     setPredicate(getSwappedPredicate());
01229     Op<0>().swap(Op<1>());
01230   }
01231 
01232   // Methods for support type inquiry through isa, cast, and dyn_cast:
01233   static inline bool classof(const Instruction *I) {
01234     return I->getOpcode() == Instruction::ICmp;
01235   }
01236   static inline bool classof(const Value *V) {
01237     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01238   }
01239 };
01240 
01241 //===----------------------------------------------------------------------===//
01242 //                               FCmpInst Class
01243 //===----------------------------------------------------------------------===//
01244 
01245 /// This instruction compares its operands according to the predicate given
01246 /// to the constructor. It only operates on floating point values or packed
01247 /// vectors of floating point values. The operands must be identical types.
01248 /// \brief Represents a floating point comparison operator.
01249 class FCmpInst: public CmpInst {
01250 protected:
01251   // Note: Instruction needs to be a friend here to call cloneImpl.
01252   friend class Instruction;
01253   /// \brief Clone an identical FCmpInst
01254   FCmpInst *cloneImpl() const;
01255 
01256 public:
01257   /// \brief Constructor with insert-before-instruction semantics.
01258   FCmpInst(
01259     Instruction *InsertBefore, ///< Where to insert
01260     Predicate pred,  ///< The predicate to use for the comparison
01261     Value *LHS,      ///< The left-hand-side of the expression
01262     Value *RHS,      ///< The right-hand-side of the expression
01263     const Twine &NameStr = ""  ///< Name of the instruction
01264   ) : CmpInst(makeCmpResultType(LHS->getType()),
01265               Instruction::FCmp, pred, LHS, RHS, NameStr,
01266               InsertBefore) {
01267     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
01268            "Invalid FCmp predicate value");
01269     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
01270            "Both operands to FCmp instruction are not of the same type!");
01271     // Check that the operands are the right type
01272     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
01273            "Invalid operand types for FCmp instruction");
01274   }
01275 
01276   /// \brief Constructor with insert-at-end semantics.
01277   FCmpInst(
01278     BasicBlock &InsertAtEnd, ///< Block to insert into.
01279     Predicate pred,  ///< The predicate to use for the comparison
01280     Value *LHS,      ///< The left-hand-side of the expression
01281     Value *RHS,      ///< The right-hand-side of the expression
01282     const Twine &NameStr = ""  ///< Name of the instruction
01283   ) : CmpInst(makeCmpResultType(LHS->getType()),
01284               Instruction::FCmp, pred, LHS, RHS, NameStr,
01285               &InsertAtEnd) {
01286     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
01287            "Invalid FCmp predicate value");
01288     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
01289            "Both operands to FCmp instruction are not of the same type!");
01290     // Check that the operands are the right type
01291     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
01292            "Invalid operand types for FCmp instruction");
01293   }
01294 
01295   /// \brief Constructor with no-insertion semantics
01296   FCmpInst(
01297     Predicate pred, ///< The predicate to use for the comparison
01298     Value *LHS,     ///< The left-hand-side of the expression
01299     Value *RHS,     ///< The right-hand-side of the expression
01300     const Twine &NameStr = "" ///< Name of the instruction
01301   ) : CmpInst(makeCmpResultType(LHS->getType()),
01302               Instruction::FCmp, pred, LHS, RHS, NameStr) {
01303     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
01304            "Invalid FCmp predicate value");
01305     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
01306            "Both operands to FCmp instruction are not of the same type!");
01307     // Check that the operands are the right type
01308     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
01309            "Invalid operand types for FCmp instruction");
01310   }
01311 
01312   /// @returns true if the predicate of this instruction is EQ or NE.
01313   /// \brief Determine if this is an equality predicate.
01314   static bool isEquality(Predicate Pred) {
01315     return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ ||
01316            Pred == FCMP_UNE;
01317   }
01318 
01319   /// @returns true if the predicate of this instruction is EQ or NE.
01320   /// \brief Determine if this is an equality predicate.
01321   bool isEquality() const { return isEquality(getPredicate()); }
01322 
01323   /// @returns true if the predicate of this instruction is commutative.
01324   /// \brief Determine if this is a commutative predicate.
01325   bool isCommutative() const {
01326     return isEquality() ||
01327            getPredicate() == FCMP_FALSE ||
01328            getPredicate() == FCMP_TRUE ||
01329            getPredicate() == FCMP_ORD ||
01330            getPredicate() == FCMP_UNO;
01331   }
01332 
01333   /// @returns true if the predicate is relational (not EQ or NE).
01334   /// \brief Determine if this a relational predicate.
01335   bool isRelational() const { return !isEquality(); }
01336 
01337   /// Exchange the two operands to this instruction in such a way that it does
01338   /// not modify the semantics of the instruction. The predicate value may be
01339   /// changed to retain the same result if the predicate is order dependent
01340   /// (e.g. ult).
01341   /// \brief Swap operands and adjust predicate.
01342   void swapOperands() {
01343     setPredicate(getSwappedPredicate());
01344     Op<0>().swap(Op<1>());
01345   }
01346 
01347   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
01348   static inline bool classof(const Instruction *I) {
01349     return I->getOpcode() == Instruction::FCmp;
01350   }
01351   static inline bool classof(const Value *V) {
01352     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01353   }
01354 };
01355 
01356 //===----------------------------------------------------------------------===//
01357 /// CallInst - This class represents a function call, abstracting a target
01358 /// machine's calling convention.  This class uses low bit of the SubClassData
01359 /// field to indicate whether or not this is a tail call.  The rest of the bits
01360 /// hold the calling convention of the call.
01361 ///
01362 class CallInst : public Instruction,
01363                  public OperandBundleUser<CallInst, User::op_iterator> {
01364   AttributeSet AttributeList; ///< parameter attributes for call
01365   FunctionType *FTy;
01366   CallInst(const CallInst &CI);
01367   void init(Value *Func, ArrayRef<Value *> Args,
01368             ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr) {
01369     init(cast<FunctionType>(
01370              cast<PointerType>(Func->getType())->getElementType()),
01371          Func, Args, Bundles, NameStr);
01372   }
01373   void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
01374             ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
01375   void init(Value *Func, const Twine &NameStr);
01376 
01377   /// Construct a CallInst given a range of arguments.
01378   /// \brief Construct a CallInst from a range of arguments
01379   inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
01380                   ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
01381                   Instruction *InsertBefore);
01382   inline CallInst(Value *Func, ArrayRef<Value *> Args,
01383                   ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
01384                   Instruction *InsertBefore)
01385       : CallInst(cast<FunctionType>(
01386                      cast<PointerType>(Func->getType())->getElementType()),
01387                  Func, Args, Bundles, NameStr, InsertBefore) {}
01388 
01389   inline CallInst(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr,
01390                   Instruction *InsertBefore)
01391       : CallInst(Func, Args, None, NameStr, InsertBefore) {}
01392 
01393   /// Construct a CallInst given a range of arguments.
01394   /// \brief Construct a CallInst from a range of arguments
01395   inline CallInst(Value *Func, ArrayRef<Value *> Args,
01396                   ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
01397                   BasicBlock *InsertAtEnd);
01398 
01399   explicit CallInst(Value *F, const Twine &NameStr,
01400                     Instruction *InsertBefore);
01401   CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
01402 
01403   friend class OperandBundleUser<CallInst, User::op_iterator>;
01404   bool hasDescriptor() const { return HasDescriptor; }
01405 
01406 protected:
01407   // Note: Instruction needs to be a friend here to call cloneImpl.
01408   friend class Instruction;
01409   CallInst *cloneImpl() const;
01410 
01411 public:
01412   static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
01413                           ArrayRef<OperandBundleDef> Bundles = None,
01414                           const Twine &NameStr = "",
01415                           Instruction *InsertBefore = nullptr) {
01416     return Create(cast<FunctionType>(
01417                       cast<PointerType>(Func->getType())->getElementType()),
01418                   Func, Args, Bundles, NameStr, InsertBefore);
01419   }
01420   static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
01421                           const Twine &NameStr,
01422                           Instruction *InsertBefore = nullptr) {
01423     return Create(cast<FunctionType>(
01424                       cast<PointerType>(Func->getType())->getElementType()),
01425                   Func, Args, None, NameStr, InsertBefore);
01426   }
01427   static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
01428                           const Twine &NameStr,
01429                           Instruction *InsertBefore = nullptr) {
01430     return new (unsigned(Args.size() + 1))
01431         CallInst(Ty, Func, Args, None, NameStr, InsertBefore);
01432   }
01433   static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
01434                           ArrayRef<OperandBundleDef> Bundles = None,
01435                           const Twine &NameStr = "",
01436                           Instruction *InsertBefore = nullptr) {
01437     const unsigned TotalOps =
01438         unsigned(Args.size()) + CountBundleInputs(Bundles) + 1;
01439     const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
01440 
01441     return new (TotalOps, DescriptorBytes)
01442         CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore);
01443   }
01444   static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
01445                           ArrayRef<OperandBundleDef> Bundles,
01446                           const Twine &NameStr, BasicBlock *InsertAtEnd) {
01447     const unsigned TotalOps =
01448         unsigned(Args.size()) + CountBundleInputs(Bundles) + 1;
01449     const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
01450 
01451     return new (TotalOps, DescriptorBytes)
01452         CallInst(Func, Args, Bundles, NameStr, InsertAtEnd);
01453   }
01454   static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
01455                           const Twine &NameStr, BasicBlock *InsertAtEnd) {
01456     return new (unsigned(Args.size() + 1))
01457         CallInst(Func, Args, None, NameStr, InsertAtEnd);
01458   }
01459   static CallInst *Create(Value *F, const Twine &NameStr = "",
01460                           Instruction *InsertBefore = nullptr) {
01461     return new(1) CallInst(F, NameStr, InsertBefore);
01462   }
01463   static CallInst *Create(Value *F, const Twine &NameStr,
01464                           BasicBlock *InsertAtEnd) {
01465     return new(1) CallInst(F, NameStr, InsertAtEnd);
01466   }
01467 
01468   /// \brief Create a clone of \p CI with a different set of operand bundles and
01469   /// insert it before \p InsertPt.
01470   ///
01471   /// The returned call instruction is identical \p CI in every way except that
01472   /// the operand bundles for the new instruction are set to the operand bundles
01473   /// in \p Bundles.
01474   static CallInst *Create(CallInst *CI, ArrayRef<OperandBundleDef> Bundles,
01475                           Instruction *InsertPt = nullptr);
01476 
01477   /// CreateMalloc - Generate the IR for a call to malloc:
01478   /// 1. Compute the malloc call's argument as the specified type's size,
01479   ///    possibly multiplied by the array size if the array size is not
01480   ///    constant 1.
01481   /// 2. Call malloc with that argument.
01482   /// 3. Bitcast the result of the malloc call to the specified type.
01483   static Instruction *CreateMalloc(Instruction *InsertBefore,
01484                                    Type *IntPtrTy, Type *AllocTy,
01485                                    Value *AllocSize, Value *ArraySize = nullptr,
01486                                    Function* MallocF = nullptr,
01487                                    const Twine &Name = "");
01488   static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
01489                                    Type *IntPtrTy, Type *AllocTy,
01490                                    Value *AllocSize, Value *ArraySize = nullptr,
01491                                    Function* MallocF = nullptr,
01492                                    const Twine &Name = "");
01493   /// CreateFree - Generate the IR for a call to the builtin free function.
01494   static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
01495   static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
01496 
01497   ~CallInst() override;
01498 
01499   FunctionType *getFunctionType() const { return FTy; }
01500 
01501   void mutateFunctionType(FunctionType *FTy) {
01502     mutateType(FTy->getReturnType());
01503     this->FTy = FTy;
01504   }
01505 
01506   // Note that 'musttail' implies 'tail'.
01507   enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2,
01508                       TCK_NoTail = 3 };
01509   TailCallKind getTailCallKind() const {
01510     return TailCallKind(getSubclassDataFromInstruction() & 3);
01511   }
01512   bool isTailCall() const {
01513     unsigned Kind = getSubclassDataFromInstruction() & 3;
01514     return Kind == TCK_Tail || Kind == TCK_MustTail;
01515   }
01516   bool isMustTailCall() const {
01517     return (getSubclassDataFromInstruction() & 3) == TCK_MustTail;
01518   }
01519   bool isNoTailCall() const {
01520     return (getSubclassDataFromInstruction() & 3) == TCK_NoTail;
01521   }
01522   void setTailCall(bool isTC = true) {
01523     setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
01524                                unsigned(isTC ? TCK_Tail : TCK_None));
01525   }
01526   void setTailCallKind(TailCallKind TCK) {
01527     setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
01528                                unsigned(TCK));
01529   }
01530 
01531   /// Provide fast operand accessors
01532   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01533 
01534   /// getNumArgOperands - Return the number of call arguments.
01535   ///
01536   unsigned getNumArgOperands() const {
01537     return getNumOperands() - getNumTotalBundleOperands() - 1;
01538   }
01539 
01540   /// getArgOperand/setArgOperand - Return/set the i-th call argument.
01541   ///
01542   Value *getArgOperand(unsigned i) const {
01543     assert(i < getNumArgOperands() && "Out of bounds!");
01544     return getOperand(i);
01545   }
01546   void setArgOperand(unsigned i, Value *v) {
01547     assert(i < getNumArgOperands() && "Out of bounds!");
01548     setOperand(i, v);
01549   }
01550 
01551   /// \brief Return the iterator pointing to the beginning of the argument list.
01552   op_iterator arg_begin() { return op_begin(); }
01553 
01554   /// \brief Return the iterator pointing to the end of the argument list.
01555   op_iterator arg_end() {
01556     // [ call args ], [ operand bundles ], callee
01557     return op_end() - getNumTotalBundleOperands() - 1;
01558   };
01559 
01560   /// \brief Iteration adapter for range-for loops.
01561   iterator_range<op_iterator> arg_operands() {
01562     return make_range(arg_begin(), arg_end());
01563   }
01564 
01565   /// \brief Return the iterator pointing to the beginning of the argument list.
01566   const_op_iterator arg_begin() const { return op_begin(); }
01567 
01568   /// \brief Return the iterator pointing to the end of the argument list.
01569   const_op_iterator arg_end() const {
01570     // [ call args ], [ operand bundles ], callee
01571     return op_end() - getNumTotalBundleOperands() - 1;
01572   };
01573 
01574   /// \brief Iteration adapter for range-for loops.
01575   iterator_range<const_op_iterator> arg_operands() const {
01576     return make_range(arg_begin(), arg_end());
01577   }
01578 
01579   /// \brief Wrappers for getting the \c Use of a call argument.
01580   const Use &getArgOperandUse(unsigned i) const {
01581     assert(i < getNumArgOperands() && "Out of bounds!");
01582     return getOperandUse(i);
01583   }
01584   Use &getArgOperandUse(unsigned i) {
01585     assert(i < getNumArgOperands() && "Out of bounds!");
01586     return getOperandUse(i);
01587   }
01588 
01589   /// getCallingConv/setCallingConv - Get or set the calling convention of this
01590   /// function call.
01591   CallingConv::ID getCallingConv() const {
01592     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
01593   }
01594   void setCallingConv(CallingConv::ID CC) {
01595     auto ID = static_cast<unsigned>(CC);
01596     assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
01597     setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
01598                                (ID << 2));
01599   }
01600 
01601   /// getAttributes - Return the parameter attributes for this call.
01602   ///
01603   const AttributeSet &getAttributes() const { return AttributeList; }
01604 
01605   /// setAttributes - Set the parameter attributes for this call.
01606   ///
01607   void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
01608 
01609   /// addAttribute - adds the attribute to the list of attributes.
01610   void addAttribute(unsigned i, Attribute::AttrKind attr);
01611 
01612   /// addAttribute - adds the attribute to the list of attributes.
01613   void addAttribute(unsigned i, StringRef Kind, StringRef Value);
01614 
01615   /// removeAttribute - removes the attribute from the list of attributes.
01616   void removeAttribute(unsigned i, Attribute attr);
01617 
01618   /// \brief adds the dereferenceable attribute to the list of attributes.
01619   void addDereferenceableAttr(unsigned i, uint64_t Bytes);
01620 
01621   /// \brief adds the dereferenceable_or_null attribute to the list of
01622   /// attributes.
01623   void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
01624 
01625   /// \brief Determine whether this call has the given attribute.
01626   bool hasFnAttr(Attribute::AttrKind A) const {
01627     assert(A != Attribute::NoBuiltin &&
01628            "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
01629     return hasFnAttrImpl(A);
01630   }
01631 
01632   /// \brief Determine whether this call has the given attribute.
01633   bool hasFnAttr(StringRef A) const {
01634     return hasFnAttrImpl(A);
01635   }
01636 
01637   /// \brief Determine whether the call or the callee has the given attributes.
01638   bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
01639 
01640   /// \brief Return true if the data operand at index \p i has the attribute \p
01641   /// A.
01642   ///
01643   /// Data operands include call arguments and values used in operand bundles,
01644   /// but does not include the callee operand.  This routine dispatches to the
01645   /// underlying AttributeList or the OperandBundleUser as appropriate.
01646   ///
01647   /// The index \p i is interpreted as
01648   ///
01649   ///  \p i == Attribute::ReturnIndex  -> the return value
01650   ///  \p i in [1, arg_size + 1)  -> argument number (\p i - 1)
01651   ///  \p i in [arg_size + 1, data_operand_size + 1) -> bundle operand at index
01652   ///     (\p i - 1) in the operand list.
01653   bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind A) const;
01654 
01655   /// \brief Extract the alignment for a call or parameter (0=unknown).
01656   unsigned getParamAlignment(unsigned i) const {
01657     return AttributeList.getParamAlignment(i);
01658   }
01659 
01660   /// \brief Extract the number of dereferenceable bytes for a call or
01661   /// parameter (0=unknown).
01662   uint64_t getDereferenceableBytes(unsigned i) const {
01663     return AttributeList.getDereferenceableBytes(i);
01664   }
01665 
01666   /// \brief Extract the number of dereferenceable_or_null bytes for a call or
01667   /// parameter (0=unknown).
01668   uint64_t getDereferenceableOrNullBytes(unsigned i) const {
01669     return AttributeList.getDereferenceableOrNullBytes(i);
01670   }
01671 
01672   /// @brief Determine if the parameter or return value is marked with NoAlias
01673   /// attribute.
01674   /// @param n The parameter to check. 1 is the first parameter, 0 is the return
01675   bool doesNotAlias(unsigned n) const {
01676     return AttributeList.hasAttribute(n, Attribute::NoAlias);
01677   }
01678 
01679   /// \brief Return true if the call should not be treated as a call to a
01680   /// builtin.
01681   bool isNoBuiltin() const {
01682     return hasFnAttrImpl(Attribute::NoBuiltin) &&
01683       !hasFnAttrImpl(Attribute::Builtin);
01684   }
01685 
01686   /// \brief Return true if the call should not be inlined.
01687   bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
01688   void setIsNoInline() {
01689     addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
01690   }
01691 
01692   /// \brief Return true if the call can return twice
01693   bool canReturnTwice() const {
01694     return hasFnAttr(Attribute::ReturnsTwice);
01695   }
01696   void setCanReturnTwice() {
01697     addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
01698   }
01699 
01700   /// \brief Determine if the call does not access memory.
01701   bool doesNotAccessMemory() const {
01702     return hasFnAttr(Attribute::ReadNone);
01703   }
01704   void setDoesNotAccessMemory() {
01705     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
01706   }
01707 
01708   /// \brief Determine if the call does not access or only reads memory.
01709   bool onlyReadsMemory() const {
01710     return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
01711   }
01712   void setOnlyReadsMemory() {
01713     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
01714   }
01715 
01716   /// @brief Determine if the call can access memmory only using pointers based
01717   /// on its arguments.
01718   bool onlyAccessesArgMemory() const {
01719     return hasFnAttr(Attribute::ArgMemOnly);
01720   }
01721   void setOnlyAccessesArgMemory() {
01722     addAttribute(AttributeSet::FunctionIndex, Attribute::ArgMemOnly);
01723   }
01724 
01725   /// \brief Determine if the call cannot return.
01726   bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
01727   void setDoesNotReturn() {
01728     addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
01729   }
01730 
01731   /// \brief Determine if the call cannot unwind.
01732   bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
01733   void setDoesNotThrow() {
01734     addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
01735   }
01736 
01737   /// \brief Determine if the call cannot be duplicated.
01738   bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
01739   void setCannotDuplicate() {
01740     addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
01741   }
01742 
01743   /// \brief Determine if the call is convergent
01744   bool isConvergent() const { return hasFnAttr(Attribute::Convergent); }
01745   void setConvergent() {
01746     addAttribute(AttributeSet::FunctionIndex, Attribute::Convergent);
01747   }
01748 
01749   /// \brief Determine if the call returns a structure through first
01750   /// pointer argument.
01751   bool hasStructRetAttr() const {
01752     if (getNumArgOperands() == 0)
01753       return false;
01754 
01755     // Be friendly and also check the callee.
01756     return paramHasAttr(1, Attribute::StructRet);
01757   }
01758 
01759   /// \brief Determine if any call argument is an aggregate passed by value.
01760   bool hasByValArgument() const {
01761     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
01762   }
01763 
01764   /// getCalledFunction - Return the function called, or null if this is an
01765   /// indirect function invocation.
01766   ///
01767   Function *getCalledFunction() const {
01768     return dyn_cast<Function>(Op<-1>());
01769   }
01770 
01771   /// getCalledValue - Get a pointer to the function that is invoked by this
01772   /// instruction.
01773   const Value *getCalledValue() const { return Op<-1>(); }
01774         Value *getCalledValue()       { return Op<-1>(); }
01775 
01776   /// setCalledFunction - Set the function called.
01777   void setCalledFunction(Value* Fn) {
01778     setCalledFunction(
01779         cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
01780         Fn);
01781   }
01782   void setCalledFunction(FunctionType *FTy, Value *Fn) {
01783     this->FTy = FTy;
01784     assert(FTy == cast<FunctionType>(
01785                       cast<PointerType>(Fn->getType())->getElementType()));
01786     Op<-1>() = Fn;
01787   }
01788 
01789   /// isInlineAsm - Check if this call is an inline asm statement.
01790   bool isInlineAsm() const {
01791     return isa<InlineAsm>(Op<-1>());
01792   }
01793 
01794   // Methods for support type inquiry through isa, cast, and dyn_cast:
01795   static inline bool classof(const Instruction *I) {
01796     return I->getOpcode() == Instruction::Call;
01797   }
01798   static inline bool classof(const Value *V) {
01799     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01800   }
01801 
01802 private:
01803   template <typename AttrKind> bool hasFnAttrImpl(AttrKind A) const {
01804     if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, A))
01805       return true;
01806 
01807     // Operand bundles override attributes on the called function, but don't
01808     // override attributes directly present on the call instruction.
01809     if (isFnAttrDisallowedByOpBundle(A))
01810       return false;
01811 
01812     if (const Function *F = getCalledFunction())
01813       return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, A);
01814     return false;
01815   }
01816 
01817   // Shadow Instruction::setInstructionSubclassData with a private forwarding
01818   // method so that subclasses cannot accidentally use it.
01819   void setInstructionSubclassData(unsigned short D) {
01820     Instruction::setInstructionSubclassData(D);
01821   }
01822 };
01823 
01824 template <>
01825 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
01826 };
01827 
01828 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
01829                    ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
01830                    BasicBlock *InsertAtEnd)
01831     : Instruction(
01832           cast<FunctionType>(cast<PointerType>(Func->getType())
01833                                  ->getElementType())->getReturnType(),
01834           Instruction::Call, OperandTraits<CallInst>::op_end(this) -
01835                                  (Args.size() + CountBundleInputs(Bundles) + 1),
01836           unsigned(Args.size() + CountBundleInputs(Bundles) + 1), InsertAtEnd) {
01837   init(Func, Args, Bundles, NameStr);
01838 }
01839 
01840 CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
01841                    ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
01842                    Instruction *InsertBefore)
01843     : Instruction(Ty->getReturnType(), Instruction::Call,
01844                   OperandTraits<CallInst>::op_end(this) -
01845                       (Args.size() + CountBundleInputs(Bundles) + 1),
01846                   unsigned(Args.size() + CountBundleInputs(Bundles) + 1),
01847                   InsertBefore) {
01848   init(Ty, Func, Args, Bundles, NameStr);
01849 }
01850 
01851 // Note: if you get compile errors about private methods then
01852 //       please update your code to use the high-level operand
01853 //       interfaces. See line 943 above.
01854 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
01855 
01856 //===----------------------------------------------------------------------===//
01857 //                               SelectInst Class
01858 //===----------------------------------------------------------------------===//
01859 
01860 /// SelectInst - This class represents the LLVM 'select' instruction.
01861 ///
01862 class SelectInst : public Instruction {
01863   void init(Value *C, Value *S1, Value *S2) {
01864     assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
01865     Op<0>() = C;
01866     Op<1>() = S1;
01867     Op<2>() = S2;
01868   }
01869 
01870   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
01871              Instruction *InsertBefore)
01872     : Instruction(S1->getType(), Instruction::Select,
01873                   &Op<0>(), 3, InsertBefore) {
01874     init(C, S1, S2);
01875     setName(NameStr);
01876   }
01877   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
01878              BasicBlock *InsertAtEnd)
01879     : Instruction(S1->getType(), Instruction::Select,
01880                   &Op<0>(), 3, InsertAtEnd) {
01881     init(C, S1, S2);
01882     setName(NameStr);
01883   }
01884 
01885 protected:
01886   // Note: Instruction needs to be a friend here to call cloneImpl.
01887   friend class Instruction;
01888   SelectInst *cloneImpl() const;
01889 
01890 public:
01891   static SelectInst *Create(Value *C, Value *S1, Value *S2,
01892                             const Twine &NameStr = "",
01893                             Instruction *InsertBefore = nullptr) {
01894     return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
01895   }
01896   static SelectInst *Create(Value *C, Value *S1, Value *S2,
01897                             const Twine &NameStr,
01898                             BasicBlock *InsertAtEnd) {
01899     return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
01900   }
01901 
01902   const Value *getCondition() const { return Op<0>(); }
01903   const Value *getTrueValue() const { return Op<1>(); }
01904   const Value *getFalseValue() const { return Op<2>(); }
01905   Value *getCondition() { return Op<0>(); }
01906   Value *getTrueValue() { return Op<1>(); }
01907   Value *getFalseValue() { return Op<2>(); }
01908 
01909   /// areInvalidOperands - Return a string if the specified operands are invalid
01910   /// for a select operation, otherwise return null.
01911   static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
01912 
01913   /// Transparently provide more efficient getOperand methods.
01914   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01915 
01916   OtherOps getOpcode() const {
01917     return static_cast<OtherOps>(Instruction::getOpcode());
01918   }
01919 
01920   // Methods for support type inquiry through isa, cast, and dyn_cast:
01921   static inline bool classof(const Instruction *I) {
01922     return I->getOpcode() == Instruction::Select;
01923   }
01924   static inline bool classof(const Value *V) {
01925     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01926   }
01927 };
01928 
01929 template <>
01930 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
01931 };
01932 
01933 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
01934 
01935 //===----------------------------------------------------------------------===//
01936 //                                VAArgInst Class
01937 //===----------------------------------------------------------------------===//
01938 
01939 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
01940 /// an argument of the specified type given a va_list and increments that list
01941 ///
01942 class VAArgInst : public UnaryInstruction {
01943 protected:
01944   // Note: Instruction needs to be a friend here to call cloneImpl.
01945   friend class Instruction;
01946   VAArgInst *cloneImpl() const;
01947 
01948 public:
01949   VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
01950              Instruction *InsertBefore = nullptr)
01951     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
01952     setName(NameStr);
01953   }
01954   VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
01955             BasicBlock *InsertAtEnd)
01956     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
01957     setName(NameStr);
01958   }
01959 
01960   Value *getPointerOperand() { return getOperand(0); }
01961   const Value *getPointerOperand() const { return getOperand(0); }
01962   static unsigned getPointerOperandIndex() { return 0U; }
01963 
01964   // Methods for support type inquiry through isa, cast, and dyn_cast:
01965   static inline bool classof(const Instruction *I) {
01966     return I->getOpcode() == VAArg;
01967   }
01968   static inline bool classof(const Value *V) {
01969     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01970   }
01971 };
01972 
01973 //===----------------------------------------------------------------------===//
01974 //                                ExtractElementInst Class
01975 //===----------------------------------------------------------------------===//
01976 
01977 /// ExtractElementInst - This instruction extracts a single (scalar)
01978 /// element from a VectorType value
01979 ///
01980 class ExtractElementInst : public Instruction {
01981   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
01982                      Instruction *InsertBefore = nullptr);
01983   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
01984                      BasicBlock *InsertAtEnd);
01985 
01986 protected:
01987   // Note: Instruction needs to be a friend here to call cloneImpl.
01988   friend class Instruction;
01989   ExtractElementInst *cloneImpl() const;
01990 
01991 public:
01992   static ExtractElementInst *Create(Value *Vec, Value *Idx,
01993                                    const Twine &NameStr = "",
01994                                    Instruction *InsertBefore = nullptr) {
01995     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
01996   }
01997   static ExtractElementInst *Create(Value *Vec, Value *Idx,
01998                                    const Twine &NameStr,
01999                                    BasicBlock *InsertAtEnd) {
02000     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
02001   }
02002 
02003   /// isValidOperands - Return true if an extractelement instruction can be
02004   /// formed with the specified operands.
02005   static bool isValidOperands(const Value *Vec, const Value *Idx);
02006 
02007   Value *getVectorOperand() { return Op<0>(); }
02008   Value *getIndexOperand() { return Op<1>(); }
02009   const Value *getVectorOperand() const { return Op<0>(); }
02010   const Value *getIndexOperand() const { return Op<1>(); }
02011 
02012   VectorType *getVectorOperandType() const {
02013     return cast<VectorType>(getVectorOperand()->getType());
02014   }
02015 
02016   /// Transparently provide more efficient getOperand methods.
02017   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02018 
02019   // Methods for support type inquiry through isa, cast, and dyn_cast:
02020   static inline bool classof(const Instruction *I) {
02021     return I->getOpcode() == Instruction::ExtractElement;
02022   }
02023   static inline bool classof(const Value *V) {
02024     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02025   }
02026 };
02027 
02028 template <>
02029 struct OperandTraits<ExtractElementInst> :
02030   public FixedNumOperandTraits<ExtractElementInst, 2> {
02031 };
02032 
02033 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
02034 
02035 //===----------------------------------------------------------------------===//
02036 //                                InsertElementInst Class
02037 //===----------------------------------------------------------------------===//
02038 
02039 /// InsertElementInst - This instruction inserts a single (scalar)
02040 /// element into a VectorType value
02041 ///
02042 class InsertElementInst : public Instruction {
02043   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
02044                     const Twine &NameStr = "",
02045                     Instruction *InsertBefore = nullptr);
02046   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr,
02047                     BasicBlock *InsertAtEnd);
02048 
02049 protected:
02050   // Note: Instruction needs to be a friend here to call cloneImpl.
02051   friend class Instruction;
02052   InsertElementInst *cloneImpl() const;
02053 
02054 public:
02055   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
02056                                    const Twine &NameStr = "",
02057                                    Instruction *InsertBefore = nullptr) {
02058     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
02059   }
02060   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
02061                                    const Twine &NameStr,
02062                                    BasicBlock *InsertAtEnd) {
02063     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
02064   }
02065 
02066   /// isValidOperands - Return true if an insertelement instruction can be
02067   /// formed with the specified operands.
02068   static bool isValidOperands(const Value *Vec, const Value *NewElt,
02069                               const Value *Idx);
02070 
02071   /// getType - Overload to return most specific vector type.
02072   ///
02073   VectorType *getType() const {
02074     return cast<VectorType>(Instruction::getType());
02075   }
02076 
02077   /// Transparently provide more efficient getOperand methods.
02078   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02079 
02080   // Methods for support type inquiry through isa, cast, and dyn_cast:
02081   static inline bool classof(const Instruction *I) {
02082     return I->getOpcode() == Instruction::InsertElement;
02083   }
02084   static inline bool classof(const Value *V) {
02085     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02086   }
02087 };
02088 
02089 template <>
02090 struct OperandTraits<InsertElementInst> :
02091   public FixedNumOperandTraits<InsertElementInst, 3> {
02092 };
02093 
02094 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
02095 
02096 //===----------------------------------------------------------------------===//
02097 //                           ShuffleVectorInst Class
02098 //===----------------------------------------------------------------------===//
02099 
02100 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
02101 /// input vectors.
02102 ///
02103 class ShuffleVectorInst : public Instruction {
02104 protected:
02105   // Note: Instruction needs to be a friend here to call cloneImpl.
02106   friend class Instruction;
02107   ShuffleVectorInst *cloneImpl() const;
02108 
02109 public:
02110   // allocate space for exactly three operands
02111   void *operator new(size_t s) {
02112     return User::operator new(s, 3);
02113   }
02114   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
02115                     const Twine &NameStr = "",
02116                     Instruction *InsertBefor = nullptr);
02117   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
02118                     const Twine &NameStr, BasicBlock *InsertAtEnd);
02119 
02120   /// isValidOperands - Return true if a shufflevector instruction can be
02121   /// formed with the specified operands.
02122   static bool isValidOperands(const Value *V1, const Value *V2,
02123                               const Value *Mask);
02124 
02125   /// getType - Overload to return most specific vector type.
02126   ///
02127   VectorType *getType() const {
02128     return cast<VectorType>(Instruction::getType());
02129   }
02130 
02131   /// Transparently provide more efficient getOperand methods.
02132   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02133 
02134   Constant *getMask() const {
02135     return cast<Constant>(getOperand(2));
02136   }
02137 
02138   /// getMaskValue - Return the index from the shuffle mask for the specified
02139   /// output result.  This is either -1 if the element is undef or a number less
02140   /// than 2*numelements.
02141   static int getMaskValue(Constant *Mask, unsigned i);
02142 
02143   int getMaskValue(unsigned i) const {
02144     return getMaskValue(getMask(), i);
02145   }
02146 
02147   /// getShuffleMask - Return the full mask for this instruction, where each
02148   /// element is the element number and undef's are returned as -1.
02149   static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
02150 
02151   void getShuffleMask(SmallVectorImpl<int> &Result) const {
02152     return getShuffleMask(getMask(), Result);
02153   }
02154 
02155   SmallVector<int, 16> getShuffleMask() const {
02156     SmallVector<int, 16> Mask;
02157     getShuffleMask(Mask);
02158     return Mask;
02159   }
02160 
02161   // Methods for support type inquiry through isa, cast, and dyn_cast:
02162   static inline bool classof(const Instruction *I) {
02163     return I->getOpcode() == Instruction::ShuffleVector;
02164   }
02165   static inline bool classof(const Value *V) {
02166     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02167   }
02168 };
02169 
02170 template <>
02171 struct OperandTraits<ShuffleVectorInst> :
02172   public FixedNumOperandTraits<ShuffleVectorInst, 3> {
02173 };
02174 
02175 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
02176 
02177 //===----------------------------------------------------------------------===//
02178 //                                ExtractValueInst Class
02179 //===----------------------------------------------------------------------===//
02180 
02181 /// ExtractValueInst - This instruction extracts a struct member or array
02182 /// element value from an aggregate value.
02183 ///
02184 class ExtractValueInst : public UnaryInstruction {
02185   SmallVector<unsigned, 4> Indices;
02186 
02187   ExtractValueInst(const ExtractValueInst &EVI);
02188   void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
02189 
02190   /// Constructors - Create a extractvalue instruction with a base aggregate
02191   /// value and a list of indices.  The first ctor can optionally insert before
02192   /// an existing instruction, the second appends the new instruction to the
02193   /// specified BasicBlock.
02194   inline ExtractValueInst(Value *Agg,
02195                           ArrayRef<unsigned> Idxs,
02196                           const Twine &NameStr,
02197                           Instruction *InsertBefore);
02198   inline ExtractValueInst(Value *Agg,
02199                           ArrayRef<unsigned> Idxs,
02200                           const Twine &NameStr, BasicBlock *InsertAtEnd);
02201 
02202   // allocate space for exactly one operand
02203   void *operator new(size_t s) { return User::operator new(s, 1); }
02204 
02205 protected:
02206   // Note: Instruction needs to be a friend here to call cloneImpl.
02207   friend class Instruction;
02208   ExtractValueInst *cloneImpl() const;
02209 
02210 public:
02211   static ExtractValueInst *Create(Value *Agg,
02212                                   ArrayRef<unsigned> Idxs,
02213                                   const Twine &NameStr = "",
02214                                   Instruction *InsertBefore = nullptr) {
02215     return new
02216       ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
02217   }
02218   static ExtractValueInst *Create(Value *Agg,
02219                                   ArrayRef<unsigned> Idxs,
02220                                   const Twine &NameStr,
02221                                   BasicBlock *InsertAtEnd) {
02222     return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
02223   }
02224 
02225   /// getIndexedType - Returns the type of the element that would be extracted
02226   /// with an extractvalue instruction with the specified parameters.
02227   ///
02228   /// Null is returned if the indices are invalid for the specified type.
02229   static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
02230 
02231   typedef const unsigned* idx_iterator;
02232   inline idx_iterator idx_begin() const { return Indices.begin(); }
02233   inline idx_iterator idx_end()   const { return Indices.end(); }
02234   inline iterator_range<idx_iterator> indices() const {
02235     return make_range(idx_begin(), idx_end());
02236   }
02237 
02238   Value *getAggregateOperand() {
02239     return getOperand(0);
02240   }
02241   const Value *getAggregateOperand() const {
02242     return getOperand(0);
02243   }
02244   static unsigned getAggregateOperandIndex() {
02245     return 0U;                      // get index for modifying correct operand
02246   }
02247 
02248   ArrayRef<unsigned> getIndices() const {
02249     return Indices;
02250   }
02251 
02252   unsigned getNumIndices() const {
02253     return (unsigned)Indices.size();
02254   }
02255 
02256   bool hasIndices() const {
02257     return true;
02258   }
02259 
02260   // Methods for support type inquiry through isa, cast, and dyn_cast:
02261   static inline bool classof(const Instruction *I) {
02262     return I->getOpcode() == Instruction::ExtractValue;
02263   }
02264   static inline bool classof(const Value *V) {
02265     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02266   }
02267 };
02268 
02269 ExtractValueInst::ExtractValueInst(Value *Agg,
02270                                    ArrayRef<unsigned> Idxs,
02271                                    const Twine &NameStr,
02272                                    Instruction *InsertBefore)
02273   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
02274                      ExtractValue, Agg, InsertBefore) {
02275   init(Idxs, NameStr);
02276 }
02277 ExtractValueInst::ExtractValueInst(Value *Agg,
02278                                    ArrayRef<unsigned> Idxs,
02279                                    const Twine &NameStr,
02280                                    BasicBlock *InsertAtEnd)
02281   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
02282                      ExtractValue, Agg, InsertAtEnd) {
02283   init(Idxs, NameStr);
02284 }
02285 
02286 //===----------------------------------------------------------------------===//
02287 //                                InsertValueInst Class
02288 //===----------------------------------------------------------------------===//
02289 
02290 /// InsertValueInst - This instruction inserts a struct field of array element
02291 /// value into an aggregate value.
02292 ///
02293 class InsertValueInst : public Instruction {
02294   SmallVector<unsigned, 4> Indices;
02295 
02296   void *operator new(size_t, unsigned) = delete;
02297   InsertValueInst(const InsertValueInst &IVI);
02298   void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
02299             const Twine &NameStr);
02300 
02301   /// Constructors - Create a insertvalue instruction with a base aggregate
02302   /// value, a value to insert, and a list of indices.  The first ctor can
02303   /// optionally insert before an existing instruction, the second appends
02304   /// the new instruction to the specified BasicBlock.
02305   inline InsertValueInst(Value *Agg, Value *Val,
02306                          ArrayRef<unsigned> Idxs,
02307                          const Twine &NameStr,
02308                          Instruction *InsertBefore);
02309   inline InsertValueInst(Value *Agg, Value *Val,
02310                          ArrayRef<unsigned> Idxs,
02311                          const Twine &NameStr, BasicBlock *InsertAtEnd);
02312 
02313   /// Constructors - These two constructors are convenience methods because one
02314   /// and two index insertvalue instructions are so common.
02315   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
02316                   const Twine &NameStr = "",
02317                   Instruction *InsertBefore = nullptr);
02318   InsertValueInst(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr,
02319                   BasicBlock *InsertAtEnd);
02320 
02321 protected:
02322   // Note: Instruction needs to be a friend here to call cloneImpl.
02323   friend class Instruction;
02324   InsertValueInst *cloneImpl() const;
02325 
02326 public:
02327   // allocate space for exactly two operands
02328   void *operator new(size_t s) {
02329     return User::operator new(s, 2);
02330   }
02331 
02332   static InsertValueInst *Create(Value *Agg, Value *Val,
02333                                  ArrayRef<unsigned> Idxs,
02334                                  const Twine &NameStr = "",
02335                                  Instruction *InsertBefore = nullptr) {
02336     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
02337   }
02338   static InsertValueInst *Create(Value *Agg, Value *Val,
02339                                  ArrayRef<unsigned> Idxs,
02340                                  const Twine &NameStr,
02341                                  BasicBlock *InsertAtEnd) {
02342     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
02343   }
02344 
02345   /// Transparently provide more efficient getOperand methods.
02346   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02347 
02348   typedef const unsigned* idx_iterator;
02349   inline idx_iterator idx_begin() const { return Indices.begin(); }
02350   inline idx_iterator idx_end()   const { return Indices.end(); }
02351   inline iterator_range<idx_iterator> indices() const {
02352     return make_range(idx_begin(), idx_end());
02353   }
02354 
02355   Value *getAggregateOperand() {
02356     return getOperand(0);
02357   }
02358   const Value *getAggregateOperand() const {
02359     return getOperand(0);
02360   }
02361   static unsigned getAggregateOperandIndex() {
02362     return 0U;                      // get index for modifying correct operand
02363   }
02364 
02365   Value *getInsertedValueOperand() {
02366     return getOperand(1);
02367   }
02368   const Value *getInsertedValueOperand() const {
02369     return getOperand(1);
02370   }
02371   static unsigned getInsertedValueOperandIndex() {
02372     return 1U;                      // get index for modifying correct operand
02373   }
02374 
02375   ArrayRef<unsigned> getIndices() const {
02376     return Indices;
02377   }
02378 
02379   unsigned getNumIndices() const {
02380     return (unsigned)Indices.size();
02381   }
02382 
02383   bool hasIndices() const {
02384     return true;
02385   }
02386 
02387   // Methods for support type inquiry through isa, cast, and dyn_cast:
02388   static inline bool classof(const Instruction *I) {
02389     return I->getOpcode() == Instruction::InsertValue;
02390   }
02391   static inline bool classof(const Value *V) {
02392     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02393   }
02394 };
02395 
02396 template <>
02397 struct OperandTraits<InsertValueInst> :
02398   public FixedNumOperandTraits<InsertValueInst, 2> {
02399 };
02400 
02401 InsertValueInst::InsertValueInst(Value *Agg,
02402                                  Value *Val,
02403                                  ArrayRef<unsigned> Idxs,
02404                                  const Twine &NameStr,
02405                                  Instruction *InsertBefore)
02406   : Instruction(Agg->getType(), InsertValue,
02407                 OperandTraits<InsertValueInst>::op_begin(this),
02408                 2, InsertBefore) {
02409   init(Agg, Val, Idxs, NameStr);
02410 }
02411 InsertValueInst::InsertValueInst(Value *Agg,
02412                                  Value *Val,
02413                                  ArrayRef<unsigned> Idxs,
02414                                  const Twine &NameStr,
02415                                  BasicBlock *InsertAtEnd)
02416   : Instruction(Agg->getType(), InsertValue,
02417                 OperandTraits<InsertValueInst>::op_begin(this),
02418                 2, InsertAtEnd) {
02419   init(Agg, Val, Idxs, NameStr);
02420 }
02421 
02422 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
02423 
02424 //===----------------------------------------------------------------------===//
02425 //                               PHINode Class
02426 //===----------------------------------------------------------------------===//
02427 
02428 // PHINode - The PHINode class is used to represent the magical mystical PHI
02429 // node, that can not exist in nature, but can be synthesized in a computer
02430 // scientist's overactive imagination.
02431 //
02432 class PHINode : public Instruction {
02433   void anchor() override;
02434 
02435   void *operator new(size_t, unsigned) = delete;
02436   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
02437   /// the number actually in use.
02438   unsigned ReservedSpace;
02439   PHINode(const PHINode &PN);
02440   // allocate space for exactly zero operands
02441   void *operator new(size_t s) {
02442     return User::operator new(s);
02443   }
02444   explicit PHINode(Type *Ty, unsigned NumReservedValues,
02445                    const Twine &NameStr = "",
02446                    Instruction *InsertBefore = nullptr)
02447     : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
02448       ReservedSpace(NumReservedValues) {
02449     setName(NameStr);
02450     allocHungoffUses(ReservedSpace);
02451   }
02452 
02453   PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
02454           BasicBlock *InsertAtEnd)
02455     : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
02456       ReservedSpace(NumReservedValues) {
02457     setName(NameStr);
02458     allocHungoffUses(ReservedSpace);
02459   }
02460 
02461 protected:
02462   // allocHungoffUses - this is more complicated than the generic
02463   // User::allocHungoffUses, because we have to allocate Uses for the incoming
02464   // values and pointers to the incoming blocks, all in one allocation.
02465   void allocHungoffUses(unsigned N) {
02466     User::allocHungoffUses(N, /* IsPhi */ true);
02467   }
02468 
02469   // Note: Instruction needs to be a friend here to call cloneImpl.
02470   friend class Instruction;
02471   PHINode *cloneImpl() const;
02472 
02473 public:
02474   /// Constructors - NumReservedValues is a hint for the number of incoming
02475   /// edges that this phi node will have (use 0 if you really have no idea).
02476   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
02477                          const Twine &NameStr = "",
02478                          Instruction *InsertBefore = nullptr) {
02479     return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
02480   }
02481   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
02482                          const Twine &NameStr, BasicBlock *InsertAtEnd) {
02483     return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
02484   }
02485 
02486   /// Provide fast operand accessors
02487   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02488 
02489   // Block iterator interface. This provides access to the list of incoming
02490   // basic blocks, which parallels the list of incoming values.
02491 
02492   typedef BasicBlock **block_iterator;
02493   typedef BasicBlock * const *const_block_iterator;
02494 
02495   block_iterator block_begin() {
02496     Use::UserRef *ref =
02497       reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
02498     return reinterpret_cast<block_iterator>(ref + 1);
02499   }
02500 
02501   const_block_iterator block_begin() const {
02502     const Use::UserRef *ref =
02503       reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
02504     return reinterpret_cast<const_block_iterator>(ref + 1);
02505   }
02506 
02507   block_iterator block_end() {
02508     return block_begin() + getNumOperands();
02509   }
02510 
02511   const_block_iterator block_end() const {
02512     return block_begin() + getNumOperands();
02513   }
02514 
02515   op_range incoming_values() { return operands(); }
02516 
02517   const_op_range incoming_values() const { return operands(); }
02518 
02519   /// getNumIncomingValues - Return the number of incoming edges
02520   ///
02521   unsigned getNumIncomingValues() const { return getNumOperands(); }
02522 
02523   /// getIncomingValue - Return incoming value number x
02524   ///
02525   Value *getIncomingValue(unsigned i) const {
02526     return getOperand(i);
02527   }
02528   void setIncomingValue(unsigned i, Value *V) {
02529     assert(V && "PHI node got a null value!");
02530     assert(getType() == V->getType() &&
02531            "All operands to PHI node must be the same type as the PHI node!");
02532     setOperand(i, V);
02533   }
02534   static unsigned getOperandNumForIncomingValue(unsigned i) {
02535     return i;
02536   }
02537   static unsigned getIncomingValueNumForOperand(unsigned i) {
02538     return i;
02539   }
02540 
02541   /// getIncomingBlock - Return incoming basic block number @p i.
02542   ///
02543   BasicBlock *getIncomingBlock(unsigned i) const {
02544     return block_begin()[i];
02545   }
02546 
02547   /// getIncomingBlock - Return incoming basic block corresponding
02548   /// to an operand of the PHI.
02549   ///
02550   BasicBlock *getIncomingBlock(const Use &U) const {
02551     assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
02552     return getIncomingBlock(unsigned(&U - op_begin()));
02553   }
02554 
02555   /// getIncomingBlock - Return incoming basic block corresponding
02556   /// to value use iterator.
02557   ///
02558   BasicBlock *getIncomingBlock(Value::const_user_iterator I) const {
02559     return getIncomingBlock(I.getUse());
02560   }
02561 
02562   void setIncomingBlock(unsigned i, BasicBlock *BB) {
02563     assert(BB && "PHI node got a null basic block!");
02564     block_begin()[i] = BB;
02565   }
02566 
02567   /// addIncoming - Add an incoming value to the end of the PHI list
02568   ///
02569   void addIncoming(Value *V, BasicBlock *BB) {
02570     if (getNumOperands() == ReservedSpace)
02571       growOperands();  // Get more space!
02572     // Initialize some new operands.
02573     setNumHungOffUseOperands(getNumOperands() + 1);
02574     setIncomingValue(getNumOperands() - 1, V);
02575     setIncomingBlock(getNumOperands() - 1, BB);
02576   }
02577 
02578   /// removeIncomingValue - Remove an incoming value.  This is useful if a
02579   /// predecessor basic block is deleted.  The value removed is returned.
02580   ///
02581   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
02582   /// is true), the PHI node is destroyed and any uses of it are replaced with
02583   /// dummy values.  The only time there should be zero incoming values to a PHI
02584   /// node is when the block is dead, so this strategy is sound.
02585   ///
02586   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
02587 
02588   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
02589     int Idx = getBasicBlockIndex(BB);
02590     assert(Idx >= 0 && "Invalid basic block argument to remove!");
02591     return removeIncomingValue(Idx, DeletePHIIfEmpty);
02592   }
02593 
02594   /// getBasicBlockIndex - Return the first index of the specified basic
02595   /// block in the value list for this PHI.  Returns -1 if no instance.
02596   ///
02597   int getBasicBlockIndex(const BasicBlock *BB) const {
02598     for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
02599       if (block_begin()[i] == BB)
02600         return i;
02601     return -1;
02602   }
02603 
02604   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
02605     int Idx = getBasicBlockIndex(BB);
02606     assert(Idx >= 0 && "Invalid basic block argument!");
02607     return getIncomingValue(Idx);
02608   }
02609 
02610   /// hasConstantValue - If the specified PHI node always merges together the
02611   /// same value, return the value, otherwise return null.
02612   Value *hasConstantValue() const;
02613 
02614   /// Methods for support type inquiry through isa, cast, and dyn_cast:
02615   static inline bool classof(const Instruction *I) {
02616     return I->getOpcode() == Instruction::PHI;
02617   }
02618   static inline bool classof(const Value *V) {
02619     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02620   }
02621 
02622 private:
02623   void growOperands();
02624 };
02625 
02626 template <>
02627 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
02628 };
02629 
02630 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
02631 
02632 //===----------------------------------------------------------------------===//
02633 //                           LandingPadInst Class
02634 //===----------------------------------------------------------------------===//
02635 
02636 //===---------------------------------------------------------------------------
02637 /// LandingPadInst - The landingpad instruction holds all of the information
02638 /// necessary to generate correct exception handling. The landingpad instruction
02639 /// cannot be moved from the top of a landing pad block, which itself is
02640 /// accessible only from the 'unwind' edge of an invoke. This uses the
02641 /// SubclassData field in Value to store whether or not the landingpad is a
02642 /// cleanup.
02643 ///
02644 class LandingPadInst : public Instruction {
02645   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
02646   /// the number actually in use.
02647   unsigned ReservedSpace;
02648   LandingPadInst(const LandingPadInst &LP);
02649 
02650 public:
02651   enum ClauseType { Catch, Filter };
02652 
02653 private:
02654   void *operator new(size_t, unsigned) = delete;
02655   // Allocate space for exactly zero operands.
02656   void *operator new(size_t s) {
02657     return User::operator new(s);
02658   }
02659   void growOperands(unsigned Size);
02660   void init(unsigned NumReservedValues, const Twine &NameStr);
02661 
02662   explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
02663                           const Twine &NameStr, Instruction *InsertBefore);
02664   explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
02665                           const Twine &NameStr, BasicBlock *InsertAtEnd);
02666 
02667 protected:
02668   // Note: Instruction needs to be a friend here to call cloneImpl.
02669   friend class Instruction;
02670   LandingPadInst *cloneImpl() const;
02671 
02672 public:
02673   /// Constructors - NumReservedClauses is a hint for the number of incoming
02674   /// clauses that this landingpad will have (use 0 if you really have no idea).
02675   static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
02676                                 const Twine &NameStr = "",
02677                                 Instruction *InsertBefore = nullptr);
02678   static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
02679                                 const Twine &NameStr, BasicBlock *InsertAtEnd);
02680 
02681   /// Provide fast operand accessors
02682   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02683 
02684   /// isCleanup - Return 'true' if this landingpad instruction is a
02685   /// cleanup. I.e., it should be run when unwinding even if its landing pad
02686   /// doesn't catch the exception.
02687   bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
02688 
02689   /// setCleanup - Indicate that this landingpad instruction is a cleanup.
02690   void setCleanup(bool V) {
02691     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
02692                                (V ? 1 : 0));
02693   }
02694 
02695   /// Add a catch or filter clause to the landing pad.
02696   void addClause(Constant *ClauseVal);
02697 
02698   /// Get the value of the clause at index Idx. Use isCatch/isFilter to
02699   /// determine what type of clause this is.
02700   Constant *getClause(unsigned Idx) const {
02701     return cast<Constant>(getOperandList()[Idx]);
02702   }
02703 
02704   /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
02705   bool isCatch(unsigned Idx) const {
02706     return !isa<ArrayType>(getOperandList()[Idx]->getType());
02707   }
02708 
02709   /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
02710   bool isFilter(unsigned Idx) const {
02711     return isa<ArrayType>(getOperandList()[Idx]->getType());
02712   }
02713 
02714   /// getNumClauses - Get the number of clauses for this landing pad.
02715   unsigned getNumClauses() const { return getNumOperands(); }
02716 
02717   /// reserveClauses - Grow the size of the operand list to accommodate the new
02718   /// number of clauses.
02719   void reserveClauses(unsigned Size) { growOperands(Size); }
02720 
02721   // Methods for support type inquiry through isa, cast, and dyn_cast:
02722   static inline bool classof(const Instruction *I) {
02723     return I->getOpcode() == Instruction::LandingPad;
02724   }
02725   static inline bool classof(const Value *V) {
02726     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02727   }
02728 };
02729 
02730 template <>
02731 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<1> {
02732 };
02733 
02734 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
02735 
02736 //===----------------------------------------------------------------------===//
02737 //                               ReturnInst Class
02738 //===----------------------------------------------------------------------===//
02739 
02740 //===---------------------------------------------------------------------------
02741 /// ReturnInst - Return a value (possibly void), from a function.  Execution
02742 /// does not continue in this function any longer.
02743 ///
02744 class ReturnInst : public TerminatorInst {
02745   ReturnInst(const ReturnInst &RI);
02746 
02747 private:
02748   // ReturnInst constructors:
02749   // ReturnInst()                  - 'ret void' instruction
02750   // ReturnInst(    null)          - 'ret void' instruction
02751   // ReturnInst(Value* X)          - 'ret X'    instruction
02752   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
02753   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
02754   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
02755   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
02756   //
02757   // NOTE: If the Value* passed is of type void then the constructor behaves as
02758   // if it was passed NULL.
02759   explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
02760                       Instruction *InsertBefore = nullptr);
02761   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
02762   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
02763 
02764 protected:
02765   // Note: Instruction needs to be a friend here to call cloneImpl.
02766   friend class Instruction;
02767   ReturnInst *cloneImpl() const;
02768 
02769 public:
02770   static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
02771                             Instruction *InsertBefore = nullptr) {
02772     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
02773   }
02774   static ReturnInst* Create(LLVMContext &C, Value *retVal,
02775                             BasicBlock *InsertAtEnd) {
02776     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
02777   }
02778   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
02779     return new(0) ReturnInst(C, InsertAtEnd);
02780   }
02781   ~ReturnInst() override;
02782 
02783   /// Provide fast operand accessors
02784   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02785 
02786   /// Convenience accessor. Returns null if there is no return value.
02787   Value *getReturnValue() const {
02788     return getNumOperands() != 0 ? getOperand(0) : nullptr;
02789   }
02790 
02791   unsigned getNumSuccessors() const { return 0; }
02792 
02793   // Methods for support type inquiry through isa, cast, and dyn_cast:
02794   static inline bool classof(const Instruction *I) {
02795     return (I->getOpcode() == Instruction::Ret);
02796   }
02797   static inline bool classof(const Value *V) {
02798     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02799   }
02800 
02801 private:
02802   BasicBlock *getSuccessorV(unsigned idx) const override;
02803   unsigned getNumSuccessorsV() const override;
02804   void setSuccessorV(unsigned idx, BasicBlock *B) override;
02805 };
02806 
02807 template <>
02808 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
02809 };
02810 
02811 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
02812 
02813 //===----------------------------------------------------------------------===//
02814 //                               BranchInst Class
02815 //===----------------------------------------------------------------------===//
02816 
02817 //===---------------------------------------------------------------------------
02818 /// BranchInst - Conditional or Unconditional Branch instruction.
02819 ///
02820 class BranchInst : public TerminatorInst {
02821   /// Ops list - Branches are strange.  The operands are ordered:
02822   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
02823   /// they don't have to check for cond/uncond branchness. These are mostly
02824   /// accessed relative from op_end().
02825   BranchInst(const BranchInst &BI);
02826   void AssertOK();
02827   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
02828   // BranchInst(BB *B)                           - 'br B'
02829   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
02830   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
02831   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
02832   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
02833   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
02834   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
02835   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
02836              Instruction *InsertBefore = nullptr);
02837   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
02838   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
02839              BasicBlock *InsertAtEnd);
02840 
02841 protected:
02842   // Note: Instruction needs to be a friend here to call cloneImpl.
02843   friend class Instruction;
02844   BranchInst *cloneImpl() const;
02845 
02846 public:
02847   static BranchInst *Create(BasicBlock *IfTrue,
02848                             Instruction *InsertBefore = nullptr) {
02849     return new(1) BranchInst(IfTrue, InsertBefore);
02850   }
02851   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
02852                             Value *Cond, Instruction *InsertBefore = nullptr) {
02853     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
02854   }
02855   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
02856     return new(1) BranchInst(IfTrue, InsertAtEnd);
02857   }
02858   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
02859                             Value *Cond, BasicBlock *InsertAtEnd) {
02860     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
02861   }
02862 
02863   /// Transparently provide more efficient getOperand methods.
02864   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02865 
02866   bool isUnconditional() const { return getNumOperands() == 1; }
02867   bool isConditional()   const { return getNumOperands() == 3; }
02868 
02869   Value *getCondition() const {
02870     assert(isConditional() && "Cannot get condition of an uncond branch!");
02871     return Op<-3>();
02872   }
02873 
02874   void setCondition(Value *V) {
02875     assert(isConditional() && "Cannot set condition of unconditional branch!");
02876     Op<-3>() = V;
02877   }
02878 
02879   unsigned getNumSuccessors() const { return 1+isConditional(); }
02880 
02881   BasicBlock *getSuccessor(unsigned i) const {
02882     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
02883     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
02884   }
02885 
02886   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
02887     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
02888     *(&Op<-1>() - idx) = NewSucc;
02889   }
02890 
02891   /// \brief Swap the successors of this branch instruction.
02892   ///
02893   /// Swaps the successors of the branch instruction. This also swaps any
02894   /// branch weight metadata associated with the instruction so that it
02895   /// continues to map correctly to each operand.
02896   void swapSuccessors();
02897 
02898   // Methods for support type inquiry through isa, cast, and dyn_cast:
02899   static inline bool classof(const Instruction *I) {
02900     return (I->getOpcode() == Instruction::Br);
02901   }
02902   static inline bool classof(const Value *V) {
02903     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02904   }
02905 
02906 private:
02907   BasicBlock *getSuccessorV(unsigned idx) const override;
02908   unsigned getNumSuccessorsV() const override;
02909   void setSuccessorV(unsigned idx, BasicBlock *B) override;
02910 };
02911 
02912 template <>
02913 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
02914 };
02915 
02916 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
02917 
02918 //===----------------------------------------------------------------------===//
02919 //                               SwitchInst Class
02920 //===----------------------------------------------------------------------===//
02921 
02922 //===---------------------------------------------------------------------------
02923 /// SwitchInst - Multiway switch
02924 ///
02925 class SwitchInst : public TerminatorInst {
02926   void *operator new(size_t, unsigned) = delete;
02927   unsigned ReservedSpace;
02928   // Operand[0]    = Value to switch on
02929   // Operand[1]    = Default basic block destination
02930   // Operand[2n  ] = Value to match
02931   // Operand[2n+1] = BasicBlock to go to on match
02932   SwitchInst(const SwitchInst &SI);
02933   void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
02934   void growOperands();
02935   // allocate space for exactly zero operands
02936   void *operator new(size_t s) {
02937     return User::operator new(s);
02938   }
02939   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
02940   /// switch on and a default destination.  The number of additional cases can
02941   /// be specified here to make memory allocation more efficient.  This
02942   /// constructor can also autoinsert before another instruction.
02943   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
02944              Instruction *InsertBefore);
02945 
02946   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
02947   /// switch on and a default destination.  The number of additional cases can
02948   /// be specified here to make memory allocation more efficient.  This
02949   /// constructor also autoinserts at the end of the specified BasicBlock.
02950   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
02951              BasicBlock *InsertAtEnd);
02952 
02953 protected:
02954   // Note: Instruction needs to be a friend here to call cloneImpl.
02955   friend class Instruction;
02956   SwitchInst *cloneImpl() const;
02957 
02958 public:
02959   // -2
02960   static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
02961 
02962   template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
02963   class CaseIteratorT {
02964   protected:
02965     SwitchInstTy *SI;
02966     unsigned Index;
02967 
02968   public:
02969     typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self;
02970 
02971     /// Initializes case iterator for given SwitchInst and for given
02972     /// case number.
02973     CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
02974       this->SI = SI;
02975       Index = CaseNum;
02976     }
02977 
02978     /// Initializes case iterator for given SwitchInst and for given
02979     /// TerminatorInst's successor index.
02980     static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
02981       assert(SuccessorIndex < SI->getNumSuccessors() &&
02982              "Successor index # out of range!");
02983       return SuccessorIndex != 0 ?
02984              Self(SI, SuccessorIndex - 1) :
02985              Self(SI, DefaultPseudoIndex);
02986     }
02987 
02988     /// Resolves case value for current case.
02989     ConstantIntTy *getCaseValue() {
02990       assert(Index < SI->getNumCases() && "Index out the number of cases.");
02991       return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
02992     }
02993 
02994     /// Resolves successor for current case.
02995     BasicBlockTy *getCaseSuccessor() {
02996       assert((Index < SI->getNumCases() ||
02997               Index == DefaultPseudoIndex) &&
02998              "Index out the number of cases.");
02999       return SI->getSuccessor(getSuccessorIndex());
03000     }
03001 
03002     /// Returns number of current case.
03003     unsigned getCaseIndex() const { return Index; }
03004 
03005     /// Returns TerminatorInst's successor index for current case successor.
03006     unsigned getSuccessorIndex() const {
03007       assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
03008              "Index out the number of cases.");
03009       return Index != DefaultPseudoIndex ? Index + 1 : 0;
03010     }
03011 
03012     Self operator++() {
03013       // Check index correctness after increment.
03014       // Note: Index == getNumCases() means end().
03015       assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
03016       ++Index;
03017       return *this;
03018     }
03019     Self operator++(int) {
03020       Self tmp = *this;
03021       ++(*this);
03022       return tmp;
03023     }
03024     Self operator--() {
03025       // Check index correctness after decrement.
03026       // Note: Index == getNumCases() means end().
03027       // Also allow "-1" iterator here. That will became valid after ++.
03028       assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
03029              "Index out the number of cases.");
03030       --Index;
03031       return *this;
03032     }
03033     Self operator--(int) {
03034       Self tmp = *this;
03035       --(*this);
03036       return tmp;
03037     }
03038     bool operator==(const Self& RHS) const {
03039       assert(RHS.SI == SI && "Incompatible operators.");
03040       return RHS.Index == Index;
03041     }
03042     bool operator!=(const Self& RHS) const {
03043       assert(RHS.SI == SI && "Incompatible operators.");
03044       return RHS.Index != Index;
03045     }
03046     Self &operator*() {
03047       return *this;
03048     }
03049   };
03050 
03051   typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
03052     ConstCaseIt;
03053 
03054   class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
03055 
03056     typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy;
03057 
03058   public:
03059     CaseIt(const ParentTy &Src) : ParentTy(Src) {}
03060     CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
03061 
03062     /// Sets the new value for current case.
03063     void setValue(ConstantInt *V) {
03064       assert(Index < SI->getNumCases() && "Index out the number of cases.");
03065       SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
03066     }
03067 
03068     /// Sets the new successor for current case.
03069     void setSuccessor(BasicBlock *S) {
03070       SI->setSuccessor(getSuccessorIndex(), S);
03071     }
03072   };
03073 
03074   static SwitchInst *Create(Value *Value, BasicBlock *Default,
03075                             unsigned NumCases,
03076                             Instruction *InsertBefore = nullptr) {
03077     return new SwitchInst(Value, Default, NumCases, InsertBefore);
03078   }
03079   static SwitchInst *Create(Value *Value, BasicBlock *Default,
03080                             unsigned NumCases, BasicBlock *InsertAtEnd) {
03081     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
03082   }
03083 
03084   /// Provide fast operand accessors
03085   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
03086 
03087   // Accessor Methods for Switch stmt
03088   Value *getCondition() const { return getOperand(0); }
03089   void setCondition(Value *V) { setOperand(0, V); }
03090 
03091   BasicBlock *getDefaultDest() const {
03092     return cast<BasicBlock>(getOperand(1));
03093   }
03094 
03095   void setDefaultDest(BasicBlock *DefaultCase) {
03096     setOperand(1, reinterpret_cast<Value*>(DefaultCase));
03097   }
03098 
03099   /// getNumCases - return the number of 'cases' in this switch instruction,
03100   /// except the default case
03101   unsigned getNumCases() const {
03102     return getNumOperands()/2 - 1;
03103   }
03104 
03105   /// Returns a read/write iterator that points to the first
03106   /// case in SwitchInst.
03107   CaseIt case_begin() {
03108     return CaseIt(this, 0);
03109   }
03110   /// Returns a read-only iterator that points to the first
03111   /// case in the SwitchInst.
03112   ConstCaseIt case_begin() const {
03113     return ConstCaseIt(this, 0);
03114   }
03115 
03116   /// Returns a read/write iterator that points one past the last
03117   /// in the SwitchInst.
03118   CaseIt case_end() {
03119     return CaseIt(this, getNumCases());
03120   }
03121   /// Returns a read-only iterator that points one past the last
03122   /// in the SwitchInst.
03123   ConstCaseIt case_end() const {
03124     return ConstCaseIt(this, getNumCases());
03125   }
03126 
03127   /// cases - iteration adapter for range-for loops.
03128   iterator_range<CaseIt> cases() {
03129     return make_range(case_begin(), case_end());
03130   }
03131 
03132   /// cases - iteration adapter for range-for loops.
03133   iterator_range<ConstCaseIt> cases() const {
03134     return make_range(case_begin(), case_end());
03135   }
03136 
03137   /// Returns an iterator that points to the default case.
03138   /// Note: this iterator allows to resolve successor only. Attempt
03139   /// to resolve case value causes an assertion.
03140   /// Also note, that increment and decrement also causes an assertion and
03141   /// makes iterator invalid.
03142   CaseIt case_default() {
03143     return CaseIt(this, DefaultPseudoIndex);
03144   }
03145   ConstCaseIt case_default() const {
03146     return ConstCaseIt(this, DefaultPseudoIndex);
03147   }
03148 
03149   /// findCaseValue - Search all of the case values for the specified constant.
03150   /// If it is explicitly handled, return the case iterator of it, otherwise
03151   /// return default case iterator to indicate
03152   /// that it is handled by the default handler.
03153   CaseIt findCaseValue(const ConstantInt *C) {
03154     for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
03155       if (i.getCaseValue() == C)
03156         return i;
03157     return case_default();
03158   }
03159   ConstCaseIt findCaseValue(const ConstantInt *C) const {
03160     for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
03161       if (i.getCaseValue() == C)
03162         return i;
03163     return case_default();
03164   }
03165 
03166   /// findCaseDest - Finds the unique case value for a given successor. Returns
03167   /// null if the successor is not found, not unique, or is the default case.
03168   ConstantInt *findCaseDest(BasicBlock *BB) {
03169     if (BB == getDefaultDest()) return nullptr;
03170 
03171     ConstantInt *CI = nullptr;
03172     for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
03173       if (i.getCaseSuccessor() == BB) {
03174         if (CI) return nullptr;   // Multiple cases lead to BB.
03175         else CI = i.getCaseValue();
03176       }
03177     }
03178     return CI;
03179   }
03180 
03181   /// addCase - Add an entry to the switch instruction...
03182   /// Note:
03183   /// This action invalidates case_end(). Old case_end() iterator will
03184   /// point to the added case.
03185   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
03186 
03187   /// removeCase - This method removes the specified case and its successor
03188   /// from the switch instruction. Note that this operation may reorder the
03189   /// remaining cases at index idx and above.
03190   /// Note:
03191   /// This action invalidates iterators for all cases following the one removed,
03192   /// including the case_end() iterator.
03193   void removeCase(CaseIt i);
03194 
03195   unsigned getNumSuccessors() const { return getNumOperands()/2; }
03196   BasicBlock *getSuccessor(unsigned idx) const {
03197     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
03198     return cast<BasicBlock>(getOperand(idx*2+1));
03199   }
03200   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
03201     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
03202     setOperand(idx * 2 + 1, NewSucc);
03203   }
03204 
03205   // Methods for support type inquiry through isa, cast, and dyn_cast:
03206   static inline bool classof(const Instruction *I) {
03207     return I->getOpcode() == Instruction::Switch;
03208   }
03209   static inline bool classof(const Value *V) {
03210     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03211   }
03212 
03213 private:
03214   BasicBlock *getSuccessorV(unsigned idx) const override;
03215   unsigned getNumSuccessorsV() const override;
03216   void setSuccessorV(unsigned idx, BasicBlock *B) override;
03217 };
03218 
03219 template <>
03220 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
03221 };
03222 
03223 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
03224 
03225 //===----------------------------------------------------------------------===//
03226 //                             IndirectBrInst Class
03227 //===----------------------------------------------------------------------===//
03228 
03229 //===---------------------------------------------------------------------------
03230 /// IndirectBrInst - Indirect Branch Instruction.
03231 ///
03232 class IndirectBrInst : public TerminatorInst {
03233   void *operator new(size_t, unsigned) = delete;
03234   unsigned ReservedSpace;
03235   // Operand[0]    = Value to switch on
03236   // Operand[1]    = Default basic block destination
03237   // Operand[2n  ] = Value to match
03238   // Operand[2n+1] = BasicBlock to go to on match
03239   IndirectBrInst(const IndirectBrInst &IBI);
03240   void init(Value *Address, unsigned NumDests);
03241   void growOperands();
03242   // allocate space for exactly zero operands
03243   void *operator new(size_t s) {
03244     return User::operator new(s);
03245   }
03246   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
03247   /// Address to jump to.  The number of expected destinations can be specified
03248   /// here to make memory allocation more efficient.  This constructor can also
03249   /// autoinsert before another instruction.
03250   IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
03251 
03252   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
03253   /// Address to jump to.  The number of expected destinations can be specified
03254   /// here to make memory allocation more efficient.  This constructor also
03255   /// autoinserts at the end of the specified BasicBlock.
03256   IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
03257 
03258 protected:
03259   // Note: Instruction needs to be a friend here to call cloneImpl.
03260   friend class Instruction;
03261   IndirectBrInst *cloneImpl() const;
03262 
03263 public:
03264   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
03265                                 Instruction *InsertBefore = nullptr) {
03266     return new IndirectBrInst(Address, NumDests, InsertBefore);
03267   }
03268   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
03269                                 BasicBlock *InsertAtEnd) {
03270     return new IndirectBrInst(Address, NumDests, InsertAtEnd);
03271   }
03272 
03273   /// Provide fast operand accessors.
03274   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
03275 
03276   // Accessor Methods for IndirectBrInst instruction.
03277   Value *getAddress() { return getOperand(0); }
03278   const Value *getAddress() const { return getOperand(0); }
03279   void setAddress(Value *V) { setOperand(0, V); }
03280 
03281   /// getNumDestinations - return the number of possible destinations in this
03282   /// indirectbr instruction.
03283   unsigned getNumDestinations() const { return getNumOperands()-1; }
03284 
03285   /// getDestination - Return the specified destination.
03286   BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
03287   const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
03288 
03289   /// addDestination - Add a destination.
03290   ///
03291   void addDestination(BasicBlock *Dest);
03292 
03293   /// removeDestination - This method removes the specified successor from the
03294   /// indirectbr instruction.
03295   void removeDestination(unsigned i);
03296 
03297   unsigned getNumSuccessors() const { return getNumOperands()-1; }
03298   BasicBlock *getSuccessor(unsigned i) const {
03299     return cast<BasicBlock>(getOperand(i+1));
03300   }
03301   void setSuccessor(unsigned i, BasicBlock *NewSucc) {
03302     setOperand(i + 1, NewSucc);
03303   }
03304 
03305   // Methods for support type inquiry through isa, cast, and dyn_cast:
03306   static inline bool classof(const Instruction *I) {
03307     return I->getOpcode() == Instruction::IndirectBr;
03308   }
03309   static inline bool classof(const Value *V) {
03310     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03311   }
03312 
03313 private:
03314   BasicBlock *getSuccessorV(unsigned idx) const override;
03315   unsigned getNumSuccessorsV() const override;
03316   void setSuccessorV(unsigned idx, BasicBlock *B) override;
03317 };
03318 
03319 template <>
03320 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
03321 };
03322 
03323 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
03324 
03325 //===----------------------------------------------------------------------===//
03326 //                               InvokeInst Class
03327 //===----------------------------------------------------------------------===//
03328 
03329 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
03330 /// calling convention of the call.
03331 ///
03332 class InvokeInst : public TerminatorInst,
03333                    public OperandBundleUser<InvokeInst, User::op_iterator> {
03334   AttributeSet AttributeList;
03335   FunctionType *FTy;
03336   InvokeInst(const InvokeInst &BI);
03337   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
03338             ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
03339             const Twine &NameStr) {
03340     init(cast<FunctionType>(
03341              cast<PointerType>(Func->getType())->getElementType()),
03342          Func, IfNormal, IfException, Args, Bundles, NameStr);
03343   }
03344   void init(FunctionType *FTy, Value *Func, BasicBlock *IfNormal,
03345             BasicBlock *IfException, ArrayRef<Value *> Args,
03346             ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
03347 
03348   /// Construct an InvokeInst given a range of arguments.
03349   ///
03350   /// \brief Construct an InvokeInst from a range of arguments
03351   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
03352                     ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
03353                     unsigned Values, const Twine &NameStr,
03354                     Instruction *InsertBefore)
03355       : InvokeInst(cast<FunctionType>(
03356                        cast<PointerType>(Func->getType())->getElementType()),
03357                    Func, IfNormal, IfException, Args, Bundles, Values, NameStr,
03358                    InsertBefore) {}
03359 
03360   inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
03361                     BasicBlock *IfException, ArrayRef<Value *> Args,
03362                     ArrayRef<OperandBundleDef> Bundles, unsigned Values,
03363                     const Twine &NameStr, Instruction *InsertBefore);
03364   /// Construct an InvokeInst given a range of arguments.
03365   ///
03366   /// \brief Construct an InvokeInst from a range of arguments
03367   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
03368                     ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
03369                     unsigned Values, const Twine &NameStr,
03370                     BasicBlock *InsertAtEnd);
03371 
03372   friend class OperandBundleUser<InvokeInst, User::op_iterator>;
03373   bool hasDescriptor() const { return HasDescriptor; }
03374 
03375 protected:
03376   // Note: Instruction needs to be a friend here to call cloneImpl.
03377   friend class Instruction;
03378   InvokeInst *cloneImpl() const;
03379 
03380 public:
03381   static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
03382                             BasicBlock *IfException, ArrayRef<Value *> Args,
03383                             const Twine &NameStr,
03384                             Instruction *InsertBefore = nullptr) {
03385     return Create(cast<FunctionType>(
03386                       cast<PointerType>(Func->getType())->getElementType()),
03387                   Func, IfNormal, IfException, Args, None, NameStr,
03388                   InsertBefore);
03389   }
03390   static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
03391                             BasicBlock *IfException, ArrayRef<Value *> Args,
03392                             ArrayRef<OperandBundleDef> Bundles = None,
03393                             const Twine &NameStr = "",
03394                             Instruction *InsertBefore = nullptr) {
03395     return Create(cast<FunctionType>(
03396                       cast<PointerType>(Func->getType())->getElementType()),
03397                   Func, IfNormal, IfException, Args, Bundles, NameStr,
03398                   InsertBefore);
03399   }
03400   static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
03401                             BasicBlock *IfException, ArrayRef<Value *> Args,
03402                             const Twine &NameStr,
03403                             Instruction *InsertBefore = nullptr) {
03404     unsigned Values = unsigned(Args.size()) + 3;
03405     return new (Values) InvokeInst(Ty, Func, IfNormal, IfException, Args, None,
03406                                    Values, NameStr, InsertBefore);
03407   }
03408   static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
03409                             BasicBlock *IfException, ArrayRef<Value *> Args,
03410                             ArrayRef<OperandBundleDef> Bundles = None,
03411                             const Twine &NameStr = "",
03412                             Instruction *InsertBefore = nullptr) {
03413     unsigned Values = unsigned(Args.size()) + CountBundleInputs(Bundles) + 3;
03414     unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
03415 
03416     return new (Values, DescriptorBytes)
03417         InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, Values,
03418                    NameStr, InsertBefore);
03419   }
03420   static InvokeInst *Create(Value *Func,
03421                             BasicBlock *IfNormal, BasicBlock *IfException,
03422                             ArrayRef<Value *> Args, const Twine &NameStr,
03423                             BasicBlock *InsertAtEnd) {
03424     unsigned Values = unsigned(Args.size()) + 3;
03425     return new (Values) InvokeInst(Func, IfNormal, IfException, Args, None,
03426                                    Values, NameStr, InsertAtEnd);
03427   }
03428   static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
03429                             BasicBlock *IfException, ArrayRef<Value *> Args,
03430                             ArrayRef<OperandBundleDef> Bundles,
03431                             const Twine &NameStr, BasicBlock *InsertAtEnd) {
03432     unsigned Values = unsigned(Args.size()) + CountBundleInputs(Bundles) + 3;
03433     unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
03434 
03435     return new (Values, DescriptorBytes)
03436         InvokeInst(Func, IfNormal, IfException, Args, Bundles, Values, NameStr,
03437                    InsertAtEnd);
03438   }
03439 
03440   /// \brief Create a clone of \p II with a different set of operand bundles and
03441   /// insert it before \p InsertPt.
03442   ///
03443   /// The returned invoke instruction is identical to \p II in every way except
03444   /// that the operand bundles for the new instruction are set to the operand
03445   /// bundles in \p Bundles.
03446   static InvokeInst *Create(InvokeInst *II, ArrayRef<OperandBundleDef> Bundles,
03447                             Instruction *InsertPt = nullptr);
03448 
03449   /// Provide fast operand accessors
03450   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
03451 
03452   FunctionType *getFunctionType() const { return FTy; }
03453 
03454   void mutateFunctionType(FunctionType *FTy) {
03455     mutateType(FTy->getReturnType());
03456     this->FTy = FTy;
03457   }
03458 
03459   /// getNumArgOperands - Return the number of invoke arguments.
03460   ///
03461   unsigned getNumArgOperands() const {
03462     return getNumOperands() - getNumTotalBundleOperands() - 3;
03463   }
03464 
03465   /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
03466   ///
03467   Value *getArgOperand(unsigned i) const {
03468     assert(i < getNumArgOperands() && "Out of bounds!");
03469     return getOperand(i);
03470   }
03471   void setArgOperand(unsigned i, Value *v) {
03472     assert(i < getNumArgOperands() && "Out of bounds!");
03473     setOperand(i, v);
03474   }
03475 
03476   /// \brief Return the iterator pointing to the beginning of the argument list.
03477   op_iterator arg_begin() { return op_begin(); }
03478 
03479   /// \brief Return the iterator pointing to the end of the argument list.
03480   op_iterator arg_end() {
03481     // [ invoke args ], [ operand bundles ], normal dest, unwind dest, callee
03482     return op_end() - getNumTotalBundleOperands() - 3;
03483   };
03484 
03485   /// \brief Iteration adapter for range-for loops.
03486   iterator_range<op_iterator> arg_operands() {
03487     return make_range(arg_begin(), arg_end());
03488   }
03489 
03490   /// \brief Return the iterator pointing to the beginning of the argument list.
03491   const_op_iterator arg_begin() const { return op_begin(); }
03492 
03493   /// \brief Return the iterator pointing to the end of the argument list.
03494   const_op_iterator arg_end() const {
03495     // [ invoke args ], [ operand bundles ], normal dest, unwind dest, callee
03496     return op_end() - getNumTotalBundleOperands() - 3;
03497   };
03498 
03499   /// \brief Iteration adapter for range-for loops.
03500   iterator_range<const_op_iterator> arg_operands() const {
03501     return make_range(arg_begin(), arg_end());
03502   }
03503 
03504   /// \brief Wrappers for getting the \c Use of a invoke argument.
03505   const Use &getArgOperandUse(unsigned i) const {
03506     assert(i < getNumArgOperands() && "Out of bounds!");
03507     return getOperandUse(i);
03508   }
03509   Use &getArgOperandUse(unsigned i) {
03510     assert(i < getNumArgOperands() && "Out of bounds!");
03511     return getOperandUse(i);
03512   }
03513 
03514   /// getCallingConv/setCallingConv - Get or set the calling convention of this
03515   /// function call.
03516   CallingConv::ID getCallingConv() const {
03517     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
03518   }
03519   void setCallingConv(CallingConv::ID CC) {
03520     auto ID = static_cast<unsigned>(CC);
03521     assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
03522     setInstructionSubclassData(ID);
03523   }
03524 
03525   /// getAttributes - Return the parameter attributes for this invoke.
03526   ///
03527   const AttributeSet &getAttributes() const { return AttributeList; }
03528 
03529   /// setAttributes - Set the parameter attributes for this invoke.
03530   ///
03531   void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
03532 
03533   /// addAttribute - adds the attribute to the list of attributes.
03534   void addAttribute(unsigned i, Attribute::AttrKind attr);
03535 
03536   /// removeAttribute - removes the attribute from the list of attributes.
03537   void removeAttribute(unsigned i, Attribute attr);
03538 
03539   /// \brief adds the dereferenceable attribute to the list of attributes.
03540   void addDereferenceableAttr(unsigned i, uint64_t Bytes);
03541 
03542   /// \brief adds the dereferenceable_or_null attribute to the list of
03543   /// attributes.
03544   void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
03545 
03546   /// \brief Determine whether this call has the given attribute.
03547   bool hasFnAttr(Attribute::AttrKind A) const {
03548     assert(A != Attribute::NoBuiltin &&
03549            "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
03550     return hasFnAttrImpl(A);
03551   }
03552 
03553   /// \brief Determine whether this call has the given attribute.
03554   bool hasFnAttr(StringRef A) const {
03555     return hasFnAttrImpl(A);
03556   }
03557 
03558   /// \brief Determine whether the call or the callee has the given attributes.
03559   bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
03560 
03561   /// \brief Return true if the data operand at index \p i has the attribute \p
03562   /// A.
03563   ///
03564   /// Data operands include invoke arguments and values used in operand bundles,
03565   /// but does not include the invokee operand, or the two successor blocks.
03566   /// This routine dispatches to the underlying AttributeList or the
03567   /// OperandBundleUser as appropriate.
03568   ///
03569   /// The index \p i is interpreted as
03570   ///
03571   ///  \p i == Attribute::ReturnIndex  -> the return value
03572   ///  \p i in [1, arg_size + 1)  -> argument number (\p i - 1)
03573   ///  \p i in [arg_size + 1, data_operand_size + 1) -> bundle operand at index
03574   ///     (\p i - 1) in the operand list.
03575   bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind A) const;
03576 
03577   /// \brief Extract the alignment for a call or parameter (0=unknown).
03578   unsigned getParamAlignment(unsigned i) const {
03579     return AttributeList.getParamAlignment(i);
03580   }
03581 
03582   /// \brief Extract the number of dereferenceable bytes for a call or
03583   /// parameter (0=unknown).
03584   uint64_t getDereferenceableBytes(unsigned i) const {
03585     return AttributeList.getDereferenceableBytes(i);
03586   }
03587 
03588   /// \brief Extract the number of dereferenceable_or_null bytes for a call or
03589   /// parameter (0=unknown).
03590   uint64_t getDereferenceableOrNullBytes(unsigned i) const {
03591     return AttributeList.getDereferenceableOrNullBytes(i);
03592   }
03593 
03594   /// @brief Determine if the parameter or return value is marked with NoAlias
03595   /// attribute.
03596   /// @param n The parameter to check. 1 is the first parameter, 0 is the return
03597   bool doesNotAlias(unsigned n) const {
03598     return AttributeList.hasAttribute(n, Attribute::NoAlias);
03599   }
03600 
03601   /// \brief Return true if the call should not be treated as a call to a
03602   /// builtin.
03603   bool isNoBuiltin() const {
03604     // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have
03605     // to check it by hand.
03606     return hasFnAttrImpl(Attribute::NoBuiltin) &&
03607       !hasFnAttrImpl(Attribute::Builtin);
03608   }
03609 
03610   /// \brief Return true if the call should not be inlined.
03611   bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
03612   void setIsNoInline() {
03613     addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
03614   }
03615 
03616   /// \brief Determine if the call does not access memory.
03617   bool doesNotAccessMemory() const {
03618     return hasFnAttr(Attribute::ReadNone);
03619   }
03620   void setDoesNotAccessMemory() {
03621     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
03622   }
03623 
03624   /// \brief Determine if the call does not access or only reads memory.
03625   bool onlyReadsMemory() const {
03626     return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
03627   }
03628   void setOnlyReadsMemory() {
03629     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
03630   }
03631 
03632   /// @brief Determine if the call access memmory only using it's pointer
03633   /// arguments.
03634   bool onlyAccessesArgMemory() const {
03635     return hasFnAttr(Attribute::ArgMemOnly);
03636   }
03637   void setOnlyAccessesArgMemory() {
03638     addAttribute(AttributeSet::FunctionIndex, Attribute::ArgMemOnly);
03639   }
03640 
03641   /// \brief Determine if the call cannot return.
03642   bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
03643   void setDoesNotReturn() {
03644     addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
03645   }
03646 
03647   /// \brief Determine if the call cannot unwind.
03648   bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
03649   void setDoesNotThrow() {
03650     addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
03651   }
03652 
03653   /// \brief Determine if the invoke cannot be duplicated.
03654   bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
03655   void setCannotDuplicate() {
03656     addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
03657   }
03658 
03659   /// \brief Determine if the call returns a structure through first
03660   /// pointer argument.
03661   bool hasStructRetAttr() const {
03662     if (getNumArgOperands() == 0)
03663       return false;
03664 
03665     // Be friendly and also check the callee.
03666     return paramHasAttr(1, Attribute::StructRet);
03667   }
03668 
03669   /// \brief Determine if any call argument is an aggregate passed by value.
03670   bool hasByValArgument() const {
03671     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
03672   }
03673 
03674   /// getCalledFunction - Return the function called, or null if this is an
03675   /// indirect function invocation.
03676   ///
03677   Function *getCalledFunction() const {
03678     return dyn_cast<Function>(Op<-3>());
03679   }
03680 
03681   /// getCalledValue - Get a pointer to the function that is invoked by this
03682   /// instruction
03683   const Value *getCalledValue() const { return Op<-3>(); }
03684         Value *getCalledValue()       { return Op<-3>(); }
03685 
03686   /// setCalledFunction - Set the function called.
03687   void setCalledFunction(Value* Fn) {
03688     setCalledFunction(
03689         cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
03690         Fn);
03691   }
03692   void setCalledFunction(FunctionType *FTy, Value *Fn) {
03693     this->FTy = FTy;
03694     assert(FTy == cast<FunctionType>(
03695                       cast<PointerType>(Fn->getType())->getElementType()));
03696     Op<-3>() = Fn;
03697   }
03698 
03699   // get*Dest - Return the destination basic blocks...
03700   BasicBlock *getNormalDest() const {
03701     return cast<BasicBlock>(Op<-2>());
03702   }
03703   BasicBlock *getUnwindDest() const {
03704     return cast<BasicBlock>(Op<-1>());
03705   }
03706   void setNormalDest(BasicBlock *B) {
03707     Op<-2>() = reinterpret_cast<Value*>(B);
03708   }
03709   void setUnwindDest(BasicBlock *B) {
03710     Op<-1>() = reinterpret_cast<Value*>(B);
03711   }
03712 
03713   /// getLandingPadInst - Get the landingpad instruction from the landing pad
03714   /// block (the unwind destination).
03715   LandingPadInst *getLandingPadInst() const;
03716 
03717   BasicBlock *getSuccessor(unsigned i) const {
03718     assert(i < 2 && "Successor # out of range for invoke!");
03719     return i == 0 ? getNormalDest() : getUnwindDest();
03720   }
03721 
03722   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
03723     assert(idx < 2 && "Successor # out of range for invoke!");
03724     *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
03725   }
03726 
03727   unsigned getNumSuccessors() const { return 2; }
03728 
03729   // Methods for support type inquiry through isa, cast, and dyn_cast:
03730   static inline bool classof(const Instruction *I) {
03731     return (I->getOpcode() == Instruction::Invoke);
03732   }
03733   static inline bool classof(const Value *V) {
03734     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03735   }
03736 
03737 private:
03738   BasicBlock *getSuccessorV(unsigned idx) const override;
03739   unsigned getNumSuccessorsV() const override;
03740   void setSuccessorV(unsigned idx, BasicBlock *B) override;
03741 
03742   template <typename AttrKind> bool hasFnAttrImpl(AttrKind A) const {
03743     if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, A))
03744       return true;
03745 
03746     // Operand bundles override attributes on the called function, but don't
03747     // override attributes directly present on the invoke instruction.
03748     if (isFnAttrDisallowedByOpBundle(A))
03749       return false;
03750 
03751     if (const Function *F = getCalledFunction())
03752       return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, A);
03753     return false;
03754   }
03755 
03756   // Shadow Instruction::setInstructionSubclassData with a private forwarding
03757   // method so that subclasses cannot accidentally use it.
03758   void setInstructionSubclassData(unsigned short D) {
03759     Instruction::setInstructionSubclassData(D);
03760   }
03761 };
03762 
03763 template <>
03764 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
03765 };
03766 
03767 InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
03768                        BasicBlock *IfException, ArrayRef<Value *> Args,
03769                        ArrayRef<OperandBundleDef> Bundles, unsigned Values,
03770                        const Twine &NameStr, Instruction *InsertBefore)
03771     : TerminatorInst(Ty->getReturnType(), Instruction::Invoke,
03772                      OperandTraits<InvokeInst>::op_end(this) - Values, Values,
03773                      InsertBefore) {
03774   init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
03775 }
03776 InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
03777                        BasicBlock *IfException, ArrayRef<Value *> Args,
03778                        ArrayRef<OperandBundleDef> Bundles, unsigned Values,
03779                        const Twine &NameStr, BasicBlock *InsertAtEnd)
03780     : TerminatorInst(
03781           cast<FunctionType>(cast<PointerType>(Func->getType())
03782                                  ->getElementType())->getReturnType(),
03783           Instruction::Invoke, OperandTraits<InvokeInst>::op_end(this) - Values,
03784           Values, InsertAtEnd) {
03785   init(Func, IfNormal, IfException, Args, Bundles, NameStr);
03786 }
03787 
03788 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
03789 
03790 //===----------------------------------------------------------------------===//
03791 //                              ResumeInst Class
03792 //===----------------------------------------------------------------------===//
03793 
03794 //===---------------------------------------------------------------------------
03795 /// ResumeInst - Resume the propagation of an exception.
03796 ///
03797 class ResumeInst : public TerminatorInst {
03798   ResumeInst(const ResumeInst &RI);
03799 
03800   explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr);
03801   ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
03802 
03803 protected:
03804   // Note: Instruction needs to be a friend here to call cloneImpl.
03805   friend class Instruction;
03806   ResumeInst *cloneImpl() const;
03807 
03808 public:
03809   static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) {
03810     return new(1) ResumeInst(Exn, InsertBefore);
03811   }
03812   static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
03813     return new(1) ResumeInst(Exn, InsertAtEnd);
03814   }
03815 
03816   /// Provide fast operand accessors
03817   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
03818 
03819   /// Convenience accessor.
03820   Value *getValue() const { return Op<0>(); }
03821 
03822   unsigned getNumSuccessors() const { return 0; }
03823 
03824   // Methods for support type inquiry through isa, cast, and dyn_cast:
03825   static inline bool classof(const Instruction *I) {
03826     return I->getOpcode() == Instruction::Resume;
03827   }
03828   static inline bool classof(const Value *V) {
03829     return isa<Instruction>(V) && classof(cast<Instruction>(V));
03830   }
03831 
03832 private:
03833   BasicBlock *getSuccessorV(unsigned idx) const override;
03834   unsigned getNumSuccessorsV() const override;
03835   void setSuccessorV(unsigned idx, BasicBlock *B) override;
03836 };
03837 
03838 template <>
03839 struct OperandTraits<ResumeInst> :
03840     public FixedNumOperandTraits<ResumeInst, 1> {
03841 };
03842 
03843 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
03844 
03845 //===----------------------------------------------------------------------===//
03846 //                         CatchSwitchInst Class
03847 //===----------------------------------------------------------------------===//
03848 class CatchSwitchInst : public TerminatorInst {
03849   void *operator new(size_t, unsigned) = delete;
03850   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
03851   /// the number actually in use.
03852   unsigned ReservedSpace;
03853   // Operand[0] = Outer scope
03854   // Operand[1] = Unwind block destination
03855   // Operand[n] = BasicBlock to go to on match
03856   CatchSwitchInst(const CatchSwitchInst &CSI);
03857   void init(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumReserved);
03858   void growOperands(unsigned Size);
03859   // allocate space for exactly zero operands
03860   void *operator new(size_t s) { return User::operator new(s); }
03861   /// CatchSwitchInst ctor - Create a new switch instruction, specifying a
03862   /// default destination.  The number of additional handlers can be specified
03863   /// here to make memory allocation more efficient.
03864   /// This constructor can also autoinsert before another instruction.
03865   CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
03866                   unsigned NumHandlers, const Twine &NameStr,
03867                   Instruction *InsertBefore);
03868 
03869   /// CatchSwitchInst ctor - Create a new switch instruction, specifying a
03870   /// default destination.  The number of additional handlers can be specified
03871   /// here to make memory allocation more efficient.
03872   /// This constructor also autoinserts at the end of the specified BasicBlock.
03873   CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
03874                   unsigned NumHandlers, const Twine &NameStr,
03875                   BasicBlock *InsertAtEnd);
03876 
03877 protected:
03878   // Note: Instruction needs to be a friend here to call cloneImpl.
03879   friend class Instruction;
03880   CatchSwitchInst *cloneImpl() const;
03881 
03882 public:
03883   static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
03884                                  unsigned NumHandlers,
03885                                  const Twine &NameStr = "",
03886                                  Instruction *InsertBefore = nullptr) {
03887     return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
03888                                InsertBefore);
03889   }
03890   static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
03891                                  unsigned NumHandlers, const Twine &NameStr,
03892                                  BasicBlock *InsertAtEnd) {
03893     return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
03894                                InsertAtEnd);
03895   }
03896 
03897   /// Provide fast operand accessors
03898   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
03899 
03900   // Accessor Methods for CatchSwitch stmt
03901   Value *getParentPad() const { return getOperand(0); }
03902   void setParentPad(Value *ParentPad) { setOperand(0, ParentPad); }
03903 
03904   // Accessor Methods for CatchSwitch stmt
03905   bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
03906   bool unwindsToCaller() const { return !hasUnwindDest(); }
03907   BasicBlock *getUnwindDest() const {
03908     if (hasUnwindDest())
03909       return cast<BasicBlock>(getOperand(1));
03910     return nullptr;
03911   }
03912   void setUnwindDest(BasicBlock *UnwindDest) {
03913     assert(UnwindDest);
03914     assert(hasUnwindDest());
03915     setOperand(1, UnwindDest);
03916   }
03917 
03918   /// getNumHandlers - return the number of 'handlers' in this catchswitch
03919   /// instruction, except the default handler
03920   unsigned getNumHandlers() const {
03921     if (hasUnwindDest())
03922       return getNumOperands() - 2;
03923     return getNumOperands() - 1;
03924   }
03925 
03926 private:
03927   static BasicBlock *handler_helper(Value *V) { return cast<BasicBlock>(V); }
03928   static const BasicBlock *handler_helper(const Value *V) {
03929     return cast<BasicBlock>(V);
03930   }
03931 
03932 public:
03933   typedef std::pointer_to_unary_function<Value *, BasicBlock *> DerefFnTy;
03934   typedef mapped_iterator<op_iterator, DerefFnTy> handler_iterator;
03935   typedef iterator_range<handler_iterator> handler_range;
03936 
03937 
03938   typedef std::pointer_to_unary_function<const Value *, const BasicBlock *>
03939       ConstDerefFnTy;
03940   typedef mapped_iterator<const_op_iterator, ConstDerefFnTy> const_handler_iterator;
03941   typedef iterator_range<const_handler_iterator> const_handler_range;
03942 
03943   /// Returns an iterator that points to the first handler in CatchSwitchInst.
03944   handler_iterator handler_begin() {
03945     op_iterator It = op_begin() + 1;
03946     if (hasUnwindDest())
03947       ++It;
03948     return handler_iterator(It, DerefFnTy(handler_helper));
03949   }
03950   /// Returns an iterator that points to the first handler in the
03951   /// CatchSwitchInst.
03952   const_handler_iterator handler_begin() const {
03953     const_op_iterator It = op_begin() + 1;
03954     if (hasUnwindDest())
03955       ++It;
03956     return const_handler_iterator(It, ConstDerefFnTy(handler_helper));
03957   }
03958 
03959   /// Returns a read-only iterator that points one past the last
03960   /// handler in the CatchSwitchInst.
03961   handler_iterator handler_end() {
03962     return handler_iterator(op_end(), DerefFnTy(handler_helper));
03963   }
03964   /// Returns an iterator that points one past the last handler in the
03965   /// CatchSwitchInst.
03966   const_handler_iterator handler_end() const {
03967     return const_handler_iterator(op_end(), ConstDerefFnTy(handler_helper));
03968   }
03969 
03970   /// handlers - iteration adapter for range-for loops.
03971   handler_range handlers() {
03972     return make_range(handler_begin(), handler_end());
03973   }
03974 
03975   /// handlers - iteration adapter for range-for loops.
03976   const_handler_range handlers() const {
03977     return make_range(handler_begin(), handler_end());
03978   }
03979 
03980   /// addHandler - Add an entry to the switch instruction...
03981   /// Note:
03982   /// This action invalidates handler_end(). Old handler_end() iterator will
03983   /// point to the added handler.
03984   void addHandler(BasicBlock *Dest);
03985 
03986   void removeHandler(handler_iterator HI);
03987 
03988   unsigned getNumSuccessors() const { return getNumOperands() - 1; }
03989   BasicBlock *getSuccessor(unsigned Idx) const {
03990     assert(Idx < getNumSuccessors() &&
03991            "Successor # out of range for catchswitch!");
03992     return cast<BasicBlock>(getOperand(Idx + 1));
03993   }
03994   void setSuccessor(unsigned Idx, BasicBlock *NewSucc) {
03995     assert(Idx < getNumSuccessors() &&
03996            "Successor # out of range for catchswitch!");
03997     setOperand(Idx + 1, NewSucc);
03998   }
03999 
04000   // Methods for support type inquiry through isa, cast, and dyn_cast:
04001   static inline bool classof(const Instruction *I) {
04002     return I->getOpcode() == Instruction::CatchSwitch;
04003   }
04004   static inline bool classof(const Value *V) {
04005     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04006   }
04007 
04008 private:
04009   BasicBlock *getSuccessorV(unsigned Idx) const override;
04010   unsigned getNumSuccessorsV() const override;
04011   void setSuccessorV(unsigned Idx, BasicBlock *B) override;
04012 };
04013 
04014 template <>
04015 struct OperandTraits<CatchSwitchInst> : public HungoffOperandTraits<2> {};
04016 
04017 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchSwitchInst, Value)
04018 
04019 //===----------------------------------------------------------------------===//
04020 //                               CleanupPadInst Class
04021 //===----------------------------------------------------------------------===//
04022 class CleanupPadInst : public FuncletPadInst {
04023 private:
04024   explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args,
04025                           unsigned Values, const Twine &NameStr,
04026                           Instruction *InsertBefore)
04027       : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values,
04028                        NameStr, InsertBefore) {}
04029   explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args,
04030                           unsigned Values, const Twine &NameStr,
04031                           BasicBlock *InsertAtEnd)
04032       : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values,
04033                        NameStr, InsertAtEnd) {}
04034 
04035 public:
04036   static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args = None,
04037                                 const Twine &NameStr = "",
04038                                 Instruction *InsertBefore = nullptr) {
04039     unsigned Values = 1 + Args.size();
04040     return new (Values)
04041         CleanupPadInst(ParentPad, Args, Values, NameStr, InsertBefore);
04042   }
04043   static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args,
04044                                 const Twine &NameStr, BasicBlock *InsertAtEnd) {
04045     unsigned Values = 1 + Args.size();
04046     return new (Values)
04047         CleanupPadInst(ParentPad, Args, Values, NameStr, InsertAtEnd);
04048   }
04049 
04050   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
04051   static inline bool classof(const Instruction *I) {
04052     return I->getOpcode() == Instruction::CleanupPad;
04053   }
04054   static inline bool classof(const Value *V) {
04055     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04056   }
04057 };
04058 
04059 //===----------------------------------------------------------------------===//
04060 //                               CatchPadInst Class
04061 //===----------------------------------------------------------------------===//
04062 class CatchPadInst : public FuncletPadInst {
04063 private:
04064   explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args,
04065                         unsigned Values, const Twine &NameStr,
04066                         Instruction *InsertBefore)
04067       : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values,
04068                        NameStr, InsertBefore) {}
04069   explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args,
04070                         unsigned Values, const Twine &NameStr,
04071                         BasicBlock *InsertAtEnd)
04072       : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values,
04073                        NameStr, InsertAtEnd) {}
04074 
04075 public:
04076   static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args,
04077                               const Twine &NameStr = "",
04078                               Instruction *InsertBefore = nullptr) {
04079     unsigned Values = 1 + Args.size();
04080     return new (Values)
04081         CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertBefore);
04082   }
04083   static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args,
04084                               const Twine &NameStr, BasicBlock *InsertAtEnd) {
04085     unsigned Values = 1 + Args.size();
04086     return new (Values)
04087         CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertAtEnd);
04088   }
04089 
04090   /// Convenience accessors
04091   CatchSwitchInst *getCatchSwitch() const {
04092     return cast<CatchSwitchInst>(Op<-1>());
04093   }
04094   void setCatchSwitch(Value *CatchSwitch) {
04095     assert(CatchSwitch);
04096     Op<-1>() = CatchSwitch;
04097   }
04098 
04099   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
04100   static inline bool classof(const Instruction *I) {
04101     return I->getOpcode() == Instruction::CatchPad;
04102   }
04103   static inline bool classof(const Value *V) {
04104     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04105   }
04106 };
04107 
04108 //===----------------------------------------------------------------------===//
04109 //                               CatchReturnInst Class
04110 //===----------------------------------------------------------------------===//
04111 
04112 class CatchReturnInst : public TerminatorInst {
04113   CatchReturnInst(const CatchReturnInst &RI);
04114 
04115   void init(Value *CatchPad, BasicBlock *BB);
04116   CatchReturnInst(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore);
04117   CatchReturnInst(Value *CatchPad, BasicBlock *BB, BasicBlock *InsertAtEnd);
04118 
04119 protected:
04120   // Note: Instruction needs to be a friend here to call cloneImpl.
04121   friend class Instruction;
04122   CatchReturnInst *cloneImpl() const;
04123 
04124 public:
04125   static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
04126                                  Instruction *InsertBefore = nullptr) {
04127     assert(CatchPad);
04128     assert(BB);
04129     return new (2) CatchReturnInst(CatchPad, BB, InsertBefore);
04130   }
04131   static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
04132                                  BasicBlock *InsertAtEnd) {
04133     assert(CatchPad);
04134     assert(BB);
04135     return new (2) CatchReturnInst(CatchPad, BB, InsertAtEnd);
04136   }
04137 
04138   /// Provide fast operand accessors
04139   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
04140 
04141   /// Convenience accessors.
04142   CatchPadInst *getCatchPad() const { return cast<CatchPadInst>(Op<0>()); }
04143   void setCatchPad(CatchPadInst *CatchPad) {
04144     assert(CatchPad);
04145     Op<0>() = CatchPad;
04146   }
04147 
04148   BasicBlock *getSuccessor() const { return cast<BasicBlock>(Op<1>()); }
04149   void setSuccessor(BasicBlock *NewSucc) {
04150     assert(NewSucc);
04151     Op<1>() = NewSucc;
04152   }
04153   unsigned getNumSuccessors() const { return 1; }
04154 
04155   /// Get the parentPad of this catchret's catchpad's catchswitch.
04156   /// The successor block is implicitly a member of this funclet.
04157   Value *getCatchSwitchParentPad() const {
04158     return getCatchPad()->getCatchSwitch()->getParentPad();
04159   }
04160 
04161   // Methods for support type inquiry through isa, cast, and dyn_cast:
04162   static inline bool classof(const Instruction *I) {
04163     return (I->getOpcode() == Instruction::CatchRet);
04164   }
04165   static inline bool classof(const Value *V) {
04166     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04167   }
04168 
04169 private:
04170   BasicBlock *getSuccessorV(unsigned Idx) const override;
04171   unsigned getNumSuccessorsV() const override;
04172   void setSuccessorV(unsigned Idx, BasicBlock *B) override;
04173 };
04174 
04175 template <>
04176 struct OperandTraits<CatchReturnInst>
04177     : public FixedNumOperandTraits<CatchReturnInst, 2> {};
04178 
04179 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchReturnInst, Value)
04180 
04181 //===----------------------------------------------------------------------===//
04182 //                               CleanupReturnInst Class
04183 //===----------------------------------------------------------------------===//
04184 
04185 class CleanupReturnInst : public TerminatorInst {
04186 private:
04187   CleanupReturnInst(const CleanupReturnInst &RI);
04188 
04189   void init(Value *CleanupPad, BasicBlock *UnwindBB);
04190   CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values,
04191                     Instruction *InsertBefore = nullptr);
04192   CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values,
04193                     BasicBlock *InsertAtEnd);
04194 
04195 protected:
04196   // Note: Instruction needs to be a friend here to call cloneImpl.
04197   friend class Instruction;
04198   CleanupReturnInst *cloneImpl() const;
04199 
04200 public:
04201   static CleanupReturnInst *Create(Value *CleanupPad,
04202                                    BasicBlock *UnwindBB = nullptr,
04203                                    Instruction *InsertBefore = nullptr) {
04204     assert(CleanupPad);
04205     unsigned Values = 1;
04206     if (UnwindBB)
04207       ++Values;
04208     return new (Values)
04209         CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertBefore);
04210   }
04211   static CleanupReturnInst *Create(Value *CleanupPad, BasicBlock *UnwindBB,
04212                                    BasicBlock *InsertAtEnd) {
04213     assert(CleanupPad);
04214     unsigned Values = 1;
04215     if (UnwindBB)
04216       ++Values;
04217     return new (Values)
04218         CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertAtEnd);
04219   }
04220 
04221   /// Provide fast operand accessors
04222   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
04223 
04224   bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
04225   bool unwindsToCaller() const { return !hasUnwindDest(); }
04226 
04227   /// Convenience accessor.
04228   CleanupPadInst *getCleanupPad() const {
04229     return cast<CleanupPadInst>(Op<0>());
04230   }
04231   void setCleanupPad(CleanupPadInst *CleanupPad) {
04232     assert(CleanupPad);
04233     Op<0>() = CleanupPad;
04234   }
04235 
04236   unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
04237 
04238   BasicBlock *getUnwindDest() const {
04239     return hasUnwindDest() ? cast<BasicBlock>(Op<1>()) : nullptr;
04240   }
04241   void setUnwindDest(BasicBlock *NewDest) {
04242     assert(NewDest);
04243     assert(hasUnwindDest());
04244     Op<1>() = NewDest;
04245   }
04246 
04247   // Methods for support type inquiry through isa, cast, and dyn_cast:
04248   static inline bool classof(const Instruction *I) {
04249     return (I->getOpcode() == Instruction::CleanupRet);
04250   }
04251   static inline bool classof(const Value *V) {
04252     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04253   }
04254 
04255 private:
04256   BasicBlock *getSuccessorV(unsigned Idx) const override;
04257   unsigned getNumSuccessorsV() const override;
04258   void setSuccessorV(unsigned Idx, BasicBlock *B) override;
04259 
04260   // Shadow Instruction::setInstructionSubclassData with a private forwarding
04261   // method so that subclasses cannot accidentally use it.
04262   void setInstructionSubclassData(unsigned short D) {
04263     Instruction::setInstructionSubclassData(D);
04264   }
04265 };
04266 
04267 template <>
04268 struct OperandTraits<CleanupReturnInst>
04269     : public VariadicOperandTraits<CleanupReturnInst, /*MINARITY=*/1> {};
04270 
04271 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CleanupReturnInst, Value)
04272 
04273 //===----------------------------------------------------------------------===//
04274 //                           UnreachableInst Class
04275 //===----------------------------------------------------------------------===//
04276 
04277 //===---------------------------------------------------------------------------
04278 /// UnreachableInst - This function has undefined behavior.  In particular, the
04279 /// presence of this instruction indicates some higher level knowledge that the
04280 /// end of the block cannot be reached.
04281 ///
04282 class UnreachableInst : public TerminatorInst {
04283   void *operator new(size_t, unsigned) = delete;
04284 
04285 protected:
04286   // Note: Instruction needs to be a friend here to call cloneImpl.
04287   friend class Instruction;
04288   UnreachableInst *cloneImpl() const;
04289 
04290 public:
04291   // allocate space for exactly zero operands
04292   void *operator new(size_t s) {
04293     return User::operator new(s, 0);
04294   }
04295   explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr);
04296   explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
04297 
04298   unsigned getNumSuccessors() const { return 0; }
04299 
04300   // Methods for support type inquiry through isa, cast, and dyn_cast:
04301   static inline bool classof(const Instruction *I) {
04302     return I->getOpcode() == Instruction::Unreachable;
04303   }
04304   static inline bool classof(const Value *V) {
04305     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04306   }
04307 
04308 private:
04309   BasicBlock *getSuccessorV(unsigned idx) const override;
04310   unsigned getNumSuccessorsV() const override;
04311   void setSuccessorV(unsigned idx, BasicBlock *B) override;
04312 };
04313 
04314 //===----------------------------------------------------------------------===//
04315 //                                 TruncInst Class
04316 //===----------------------------------------------------------------------===//
04317 
04318 /// \brief This class represents a truncation of integer types.
04319 class TruncInst : public CastInst {
04320 protected:
04321   // Note: Instruction needs to be a friend here to call cloneImpl.
04322   friend class Instruction;
04323   /// \brief Clone an identical TruncInst
04324   TruncInst *cloneImpl() const;
04325 
04326 public:
04327   /// \brief Constructor with insert-before-instruction semantics
04328   TruncInst(
04329     Value *S,                           ///< The value to be truncated
04330     Type *Ty,                           ///< The (smaller) type to truncate to
04331     const Twine &NameStr = "",          ///< A name for the new instruction
04332     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04333   );
04334 
04335   /// \brief Constructor with insert-at-end-of-block semantics
04336   TruncInst(
04337     Value *S,                     ///< The value to be truncated
04338     Type *Ty,                     ///< The (smaller) type to truncate to
04339     const Twine &NameStr,         ///< A name for the new instruction
04340     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
04341   );
04342 
04343   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
04344   static inline bool classof(const Instruction *I) {
04345     return I->getOpcode() == Trunc;
04346   }
04347   static inline bool classof(const Value *V) {
04348     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04349   }
04350 };
04351 
04352 //===----------------------------------------------------------------------===//
04353 //                                 ZExtInst Class
04354 //===----------------------------------------------------------------------===//
04355 
04356 /// \brief This class represents zero extension of integer types.
04357 class ZExtInst : public CastInst {
04358 protected:
04359   // Note: Instruction needs to be a friend here to call cloneImpl.
04360   friend class Instruction;
04361   /// \brief Clone an identical ZExtInst
04362   ZExtInst *cloneImpl() const;
04363 
04364 public:
04365   /// \brief Constructor with insert-before-instruction semantics
04366   ZExtInst(
04367     Value *S,                           ///< The value to be zero extended
04368     Type *Ty,                           ///< The type to zero extend to
04369     const Twine &NameStr = "",          ///< A name for the new instruction
04370     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04371   );
04372 
04373   /// \brief Constructor with insert-at-end semantics.
04374   ZExtInst(
04375     Value *S,                     ///< The value to be zero extended
04376     Type *Ty,                     ///< The type to zero extend to
04377     const Twine &NameStr,         ///< A name for the new instruction
04378     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
04379   );
04380 
04381   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
04382   static inline bool classof(const Instruction *I) {
04383     return I->getOpcode() == ZExt;
04384   }
04385   static inline bool classof(const Value *V) {
04386     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04387   }
04388 };
04389 
04390 //===----------------------------------------------------------------------===//
04391 //                                 SExtInst Class
04392 //===----------------------------------------------------------------------===//
04393 
04394 /// \brief This class represents a sign extension of integer types.
04395 class SExtInst : public CastInst {
04396 protected:
04397   // Note: Instruction needs to be a friend here to call cloneImpl.
04398   friend class Instruction;
04399   /// \brief Clone an identical SExtInst
04400   SExtInst *cloneImpl() const;
04401 
04402 public:
04403   /// \brief Constructor with insert-before-instruction semantics
04404   SExtInst(
04405     Value *S,                           ///< The value to be sign extended
04406     Type *Ty,                           ///< The type to sign extend to
04407     const Twine &NameStr = "",          ///< A name for the new instruction
04408     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04409   );
04410 
04411   /// \brief Constructor with insert-at-end-of-block semantics
04412   SExtInst(
04413     Value *S,                     ///< The value to be sign extended
04414     Type *Ty,                     ///< The type to sign extend to
04415     const Twine &NameStr,         ///< A name for the new instruction
04416     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
04417   );
04418 
04419   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
04420   static inline bool classof(const Instruction *I) {
04421     return I->getOpcode() == SExt;
04422   }
04423   static inline bool classof(const Value *V) {
04424     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04425   }
04426 };
04427 
04428 //===----------------------------------------------------------------------===//
04429 //                                 FPTruncInst Class
04430 //===----------------------------------------------------------------------===//
04431 
04432 /// \brief This class represents a truncation of floating point types.
04433 class FPTruncInst : public CastInst {
04434 protected:
04435   // Note: Instruction needs to be a friend here to call cloneImpl.
04436   friend class Instruction;
04437   /// \brief Clone an identical FPTruncInst
04438   FPTruncInst *cloneImpl() const;
04439 
04440 public:
04441   /// \brief Constructor with insert-before-instruction semantics
04442   FPTruncInst(
04443     Value *S,                           ///< The value to be truncated
04444     Type *Ty,                           ///< The type to truncate to
04445     const Twine &NameStr = "",          ///< A name for the new instruction
04446     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04447   );
04448 
04449   /// \brief Constructor with insert-before-instruction semantics
04450   FPTruncInst(
04451     Value *S,                     ///< The value to be truncated
04452     Type *Ty,                     ///< The type to truncate to
04453     const Twine &NameStr,         ///< A name for the new instruction
04454     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
04455   );
04456 
04457   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
04458   static inline bool classof(const Instruction *I) {
04459     return I->getOpcode() == FPTrunc;
04460   }
04461   static inline bool classof(const Value *V) {
04462     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04463   }
04464 };
04465 
04466 //===----------------------------------------------------------------------===//
04467 //                                 FPExtInst Class
04468 //===----------------------------------------------------------------------===//
04469 
04470 /// \brief This class represents an extension of floating point types.
04471 class FPExtInst : public CastInst {
04472 protected:
04473   // Note: Instruction needs to be a friend here to call cloneImpl.
04474   friend class Instruction;
04475   /// \brief Clone an identical FPExtInst
04476   FPExtInst *cloneImpl() const;
04477 
04478 public:
04479   /// \brief Constructor with insert-before-instruction semantics
04480   FPExtInst(
04481     Value *S,                           ///< The value to be extended
04482     Type *Ty,                           ///< The type to extend to
04483     const Twine &NameStr = "",          ///< A name for the new instruction
04484     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04485   );
04486 
04487   /// \brief Constructor with insert-at-end-of-block semantics
04488   FPExtInst(
04489     Value *S,                     ///< The value to be extended
04490     Type *Ty,                     ///< The type to extend to
04491     const Twine &NameStr,         ///< A name for the new instruction
04492     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
04493   );
04494 
04495   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
04496   static inline bool classof(const Instruction *I) {
04497     return I->getOpcode() == FPExt;
04498   }
04499   static inline bool classof(const Value *V) {
04500     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04501   }
04502 };
04503 
04504 //===----------------------------------------------------------------------===//
04505 //                                 UIToFPInst Class
04506 //===----------------------------------------------------------------------===//
04507 
04508 /// \brief This class represents a cast unsigned integer to floating point.
04509 class UIToFPInst : public CastInst {
04510 protected:
04511   // Note: Instruction needs to be a friend here to call cloneImpl.
04512   friend class Instruction;
04513   /// \brief Clone an identical UIToFPInst
04514   UIToFPInst *cloneImpl() const;
04515 
04516 public:
04517   /// \brief Constructor with insert-before-instruction semantics
04518   UIToFPInst(
04519     Value *S,                           ///< The value to be converted
04520     Type *Ty,                           ///< The type to convert to
04521     const Twine &NameStr = "",          ///< A name for the new instruction
04522     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04523   );
04524 
04525   /// \brief Constructor with insert-at-end-of-block semantics
04526   UIToFPInst(
04527     Value *S,                     ///< The value to be converted
04528     Type *Ty,                     ///< The type to convert to
04529     const Twine &NameStr,         ///< A name for the new instruction
04530     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
04531   );
04532 
04533   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
04534   static inline bool classof(const Instruction *I) {
04535     return I->getOpcode() == UIToFP;
04536   }
04537   static inline bool classof(const Value *V) {
04538     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04539   }
04540 };
04541 
04542 //===----------------------------------------------------------------------===//
04543 //                                 SIToFPInst Class
04544 //===----------------------------------------------------------------------===//
04545 
04546 /// \brief This class represents a cast from signed integer to floating point.
04547 class SIToFPInst : public CastInst {
04548 protected:
04549   // Note: Instruction needs to be a friend here to call cloneImpl.
04550   friend class Instruction;
04551   /// \brief Clone an identical SIToFPInst
04552   SIToFPInst *cloneImpl() const;
04553 
04554 public:
04555   /// \brief Constructor with insert-before-instruction semantics
04556   SIToFPInst(
04557     Value *S,                           ///< The value to be converted
04558     Type *Ty,                           ///< The type to convert to
04559     const Twine &NameStr = "",          ///< A name for the new instruction
04560     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04561   );
04562 
04563   /// \brief Constructor with insert-at-end-of-block semantics
04564   SIToFPInst(
04565     Value *S,                     ///< The value to be converted
04566     Type *Ty,                     ///< The type to convert to
04567     const Twine &NameStr,         ///< A name for the new instruction
04568     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
04569   );
04570 
04571   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
04572   static inline bool classof(const Instruction *I) {
04573     return I->getOpcode() == SIToFP;
04574   }
04575   static inline bool classof(const Value *V) {
04576     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04577   }
04578 };
04579 
04580 //===----------------------------------------------------------------------===//
04581 //                                 FPToUIInst Class
04582 //===----------------------------------------------------------------------===//
04583 
04584 /// \brief This class represents a cast from floating point to unsigned integer
04585 class FPToUIInst  : public CastInst {
04586 protected:
04587   // Note: Instruction needs to be a friend here to call cloneImpl.
04588   friend class Instruction;
04589   /// \brief Clone an identical FPToUIInst
04590   FPToUIInst *cloneImpl() const;
04591 
04592 public:
04593   /// \brief Constructor with insert-before-instruction semantics
04594   FPToUIInst(
04595     Value *S,                           ///< The value to be converted
04596     Type *Ty,                           ///< The type to convert to
04597     const Twine &NameStr = "",          ///< A name for the new instruction
04598     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04599   );
04600 
04601   /// \brief Constructor with insert-at-end-of-block semantics
04602   FPToUIInst(
04603     Value *S,                     ///< The value to be converted
04604     Type *Ty,                     ///< The type to convert to
04605     const Twine &NameStr,         ///< A name for the new instruction
04606     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
04607   );
04608 
04609   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
04610   static inline bool classof(const Instruction *I) {
04611     return I->getOpcode() == FPToUI;
04612   }
04613   static inline bool classof(const Value *V) {
04614     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04615   }
04616 };
04617 
04618 //===----------------------------------------------------------------------===//
04619 //                                 FPToSIInst Class
04620 //===----------------------------------------------------------------------===//
04621 
04622 /// \brief This class represents a cast from floating point to signed integer.
04623 class FPToSIInst  : public CastInst {
04624 protected:
04625   // Note: Instruction needs to be a friend here to call cloneImpl.
04626   friend class Instruction;
04627   /// \brief Clone an identical FPToSIInst
04628   FPToSIInst *cloneImpl() const;
04629 
04630 public:
04631   /// \brief Constructor with insert-before-instruction semantics
04632   FPToSIInst(
04633     Value *S,                           ///< The value to be converted
04634     Type *Ty,                           ///< The type to convert to
04635     const Twine &NameStr = "",          ///< A name for the new instruction
04636     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04637   );
04638 
04639   /// \brief Constructor with insert-at-end-of-block semantics
04640   FPToSIInst(
04641     Value *S,                     ///< The value to be converted
04642     Type *Ty,                     ///< The type to convert to
04643     const Twine &NameStr,         ///< A name for the new instruction
04644     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
04645   );
04646 
04647   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
04648   static inline bool classof(const Instruction *I) {
04649     return I->getOpcode() == FPToSI;
04650   }
04651   static inline bool classof(const Value *V) {
04652     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04653   }
04654 };
04655 
04656 //===----------------------------------------------------------------------===//
04657 //                                 IntToPtrInst Class
04658 //===----------------------------------------------------------------------===//
04659 
04660 /// \brief This class represents a cast from an integer to a pointer.
04661 class IntToPtrInst : public CastInst {
04662 public:
04663   /// \brief Constructor with insert-before-instruction semantics
04664   IntToPtrInst(
04665     Value *S,                           ///< The value to be converted
04666     Type *Ty,                           ///< The type to convert to
04667     const Twine &NameStr = "",          ///< A name for the new instruction
04668     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04669   );
04670 
04671   /// \brief Constructor with insert-at-end-of-block semantics
04672   IntToPtrInst(
04673     Value *S,                     ///< The value to be converted
04674     Type *Ty,                     ///< The type to convert to
04675     const Twine &NameStr,         ///< A name for the new instruction
04676     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
04677   );
04678 
04679   // Note: Instruction needs to be a friend here to call cloneImpl.
04680   friend class Instruction;
04681   /// \brief Clone an identical IntToPtrInst
04682   IntToPtrInst *cloneImpl() const;
04683 
04684   /// \brief Returns the address space of this instruction's pointer type.
04685   unsigned getAddressSpace() const {
04686     return getType()->getPointerAddressSpace();
04687   }
04688 
04689   // Methods for support type inquiry through isa, cast, and dyn_cast:
04690   static inline bool classof(const Instruction *I) {
04691     return I->getOpcode() == IntToPtr;
04692   }
04693   static inline bool classof(const Value *V) {
04694     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04695   }
04696 };
04697 
04698 //===----------------------------------------------------------------------===//
04699 //                                 PtrToIntInst Class
04700 //===----------------------------------------------------------------------===//
04701 
04702 /// \brief This class represents a cast from a pointer to an integer
04703 class PtrToIntInst : public CastInst {
04704 protected:
04705   // Note: Instruction needs to be a friend here to call cloneImpl.
04706   friend class Instruction;
04707   /// \brief Clone an identical PtrToIntInst
04708   PtrToIntInst *cloneImpl() const;
04709 
04710 public:
04711   /// \brief Constructor with insert-before-instruction semantics
04712   PtrToIntInst(
04713     Value *S,                           ///< The value to be converted
04714     Type *Ty,                           ///< The type to convert to
04715     const Twine &NameStr = "",          ///< A name for the new instruction
04716     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04717   );
04718 
04719   /// \brief Constructor with insert-at-end-of-block semantics
04720   PtrToIntInst(
04721     Value *S,                     ///< The value to be converted
04722     Type *Ty,                     ///< The type to convert to
04723     const Twine &NameStr,         ///< A name for the new instruction
04724     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
04725   );
04726 
04727   /// \brief Gets the pointer operand.
04728   Value *getPointerOperand() { return getOperand(0); }
04729   /// \brief Gets the pointer operand.
04730   const Value *getPointerOperand() const { return getOperand(0); }
04731   /// \brief Gets the operand index of the pointer operand.
04732   static unsigned getPointerOperandIndex() { return 0U; }
04733 
04734   /// \brief Returns the address space of the pointer operand.
04735   unsigned getPointerAddressSpace() const {
04736     return getPointerOperand()->getType()->getPointerAddressSpace();
04737   }
04738 
04739   // Methods for support type inquiry through isa, cast, and dyn_cast:
04740   static inline bool classof(const Instruction *I) {
04741     return I->getOpcode() == PtrToInt;
04742   }
04743   static inline bool classof(const Value *V) {
04744     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04745   }
04746 };
04747 
04748 //===----------------------------------------------------------------------===//
04749 //                             BitCastInst Class
04750 //===----------------------------------------------------------------------===//
04751 
04752 /// \brief This class represents a no-op cast from one type to another.
04753 class BitCastInst : public CastInst {
04754 protected:
04755   // Note: Instruction needs to be a friend here to call cloneImpl.
04756   friend class Instruction;
04757   /// \brief Clone an identical BitCastInst
04758   BitCastInst *cloneImpl() const;
04759 
04760 public:
04761   /// \brief Constructor with insert-before-instruction semantics
04762   BitCastInst(
04763     Value *S,                           ///< The value to be casted
04764     Type *Ty,                           ///< The type to casted to
04765     const Twine &NameStr = "",          ///< A name for the new instruction
04766     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04767   );
04768 
04769   /// \brief Constructor with insert-at-end-of-block semantics
04770   BitCastInst(
04771     Value *S,                     ///< The value to be casted
04772     Type *Ty,                     ///< The type to casted to
04773     const Twine &NameStr,         ///< A name for the new instruction
04774     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
04775   );
04776 
04777   // Methods for support type inquiry through isa, cast, and dyn_cast:
04778   static inline bool classof(const Instruction *I) {
04779     return I->getOpcode() == BitCast;
04780   }
04781   static inline bool classof(const Value *V) {
04782     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04783   }
04784 };
04785 
04786 //===----------------------------------------------------------------------===//
04787 //                          AddrSpaceCastInst Class
04788 //===----------------------------------------------------------------------===//
04789 
04790 /// \brief This class represents a conversion between pointers from
04791 /// one address space to another.
04792 class AddrSpaceCastInst : public CastInst {
04793 protected:
04794   // Note: Instruction needs to be a friend here to call cloneImpl.
04795   friend class Instruction;
04796   /// \brief Clone an identical AddrSpaceCastInst
04797   AddrSpaceCastInst *cloneImpl() const;
04798 
04799 public:
04800   /// \brief Constructor with insert-before-instruction semantics
04801   AddrSpaceCastInst(
04802     Value *S,                           ///< The value to be casted
04803     Type *Ty,                           ///< The type to casted to
04804     const Twine &NameStr = "",          ///< A name for the new instruction
04805     Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
04806   );
04807 
04808   /// \brief Constructor with insert-at-end-of-block semantics
04809   AddrSpaceCastInst(
04810     Value *S,                     ///< The value to be casted
04811     Type *Ty,                     ///< The type to casted to
04812     const Twine &NameStr,         ///< A name for the new instruction
04813     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
04814   );
04815 
04816   // Methods for support type inquiry through isa, cast, and dyn_cast:
04817   static inline bool classof(const Instruction *I) {
04818     return I->getOpcode() == AddrSpaceCast;
04819   }
04820   static inline bool classof(const Value *V) {
04821     return isa<Instruction>(V) && classof(cast<Instruction>(V));
04822   }
04823 };
04824 
04825 } // End llvm namespace
04826 
04827 #endif