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