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