LLVM API Documentation

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