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   Type *ResultElementType;
00814 
00815   GetElementPtrInst(const GetElementPtrInst &GEPI);
00816   void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
00817 
00818   /// Constructors - Create a getelementptr instruction with a base pointer an
00819   /// list of indices. The first ctor can optionally insert before an existing
00820   /// instruction, the second appends the new instruction to the specified
00821   /// BasicBlock.
00822   inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
00823                            ArrayRef<Value *> IdxList, unsigned Values,
00824                            const Twine &NameStr, Instruction *InsertBefore);
00825   inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
00826                            ArrayRef<Value *> IdxList, unsigned Values,
00827                            const Twine &NameStr, BasicBlock *InsertAtEnd);
00828 
00829 protected:
00830   GetElementPtrInst *clone_impl() const override;
00831 public:
00832   static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
00833                                    ArrayRef<Value *> IdxList,
00834                                    const Twine &NameStr = "",
00835                                    Instruction *InsertBefore = nullptr) {
00836     unsigned Values = 1 + unsigned(IdxList.size());
00837     if (!PointeeType)
00838       PointeeType =
00839           cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
00840     else
00841       assert(
00842           PointeeType ==
00843           cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
00844     return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
00845                                           NameStr, InsertBefore);
00846   }
00847   static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
00848                                    ArrayRef<Value *> IdxList,
00849                                    const Twine &NameStr,
00850                                    BasicBlock *InsertAtEnd) {
00851     unsigned Values = 1 + unsigned(IdxList.size());
00852     if (!PointeeType)
00853       PointeeType =
00854           cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
00855     else
00856       assert(
00857           PointeeType ==
00858           cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
00859     return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
00860                                           NameStr, InsertAtEnd);
00861   }
00862 
00863   /// Create an "inbounds" getelementptr. See the documentation for the
00864   /// "inbounds" flag in LangRef.html for details.
00865   static GetElementPtrInst *CreateInBounds(Value *Ptr,
00866                                            ArrayRef<Value *> IdxList,
00867                                            const Twine &NameStr = "",
00868                                            Instruction *InsertBefore = nullptr){
00869     return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore);
00870   }
00871   static GetElementPtrInst *
00872   CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
00873                  const Twine &NameStr = "",
00874                  Instruction *InsertBefore = nullptr) {
00875     GetElementPtrInst *GEP =
00876         Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
00877     GEP->setIsInBounds(true);
00878     return GEP;
00879   }
00880   static GetElementPtrInst *CreateInBounds(Value *Ptr,
00881                                            ArrayRef<Value *> IdxList,
00882                                            const Twine &NameStr,
00883                                            BasicBlock *InsertAtEnd) {
00884     return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd);
00885   }
00886   static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,
00887                                            ArrayRef<Value *> IdxList,
00888                                            const Twine &NameStr,
00889                                            BasicBlock *InsertAtEnd) {
00890     GetElementPtrInst *GEP =
00891         Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd);
00892     GEP->setIsInBounds(true);
00893     return GEP;
00894   }
00895 
00896   /// Transparently provide more efficient getOperand methods.
00897   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00898 
00899   // getType - Overload to return most specific sequential type.
00900   SequentialType *getType() const {
00901     return cast<SequentialType>(Instruction::getType());
00902   }
00903 
00904   Type *getSourceElementType() const { return SourceElementType; }
00905 
00906   void setSourceElementType(Type *Ty) { SourceElementType = Ty; }
00907   void setResultElementType(Type *Ty) { ResultElementType = Ty; }
00908 
00909   Type *getResultElementType() const {
00910     assert(ResultElementType ==
00911            cast<PointerType>(getType()->getScalarType())->getElementType());
00912     return ResultElementType;
00913   }
00914 
00915   /// \brief Returns the address space of this instruction's pointer type.
00916   unsigned getAddressSpace() const {
00917     // Note that this is always the same as the pointer operand's address space
00918     // and that is cheaper to compute, so cheat here.
00919     return getPointerAddressSpace();
00920   }
00921 
00922   /// getIndexedType - Returns the type of the element that would be loaded with
00923   /// a load instruction with the specified parameters.
00924   ///
00925   /// Null is returned if the indices are invalid for the specified
00926   /// pointer type.
00927   ///
00928   static Type *getIndexedType(Type *Ty, ArrayRef<Value *> IdxList);
00929   static Type *getIndexedType(Type *Ty, ArrayRef<Constant *> IdxList);
00930   static Type *getIndexedType(Type *Ty, ArrayRef<uint64_t> IdxList);
00931 
00932   inline op_iterator       idx_begin()       { return op_begin()+1; }
00933   inline const_op_iterator idx_begin() const { return op_begin()+1; }
00934   inline op_iterator       idx_end()         { return op_end(); }
00935   inline const_op_iterator idx_end()   const { return op_end(); }
00936 
00937   Value *getPointerOperand() {
00938     return getOperand(0);
00939   }
00940   const Value *getPointerOperand() const {
00941     return getOperand(0);
00942   }
00943   static unsigned getPointerOperandIndex() {
00944     return 0U;    // get index for modifying correct operand.
00945   }
00946 
00947   /// getPointerOperandType - Method to return the pointer operand as a
00948   /// PointerType.
00949   Type *getPointerOperandType() const {
00950     return getPointerOperand()->getType();
00951   }
00952 
00953   /// \brief Returns the address space of the pointer operand.
00954   unsigned getPointerAddressSpace() const {
00955     return getPointerOperandType()->getPointerAddressSpace();
00956   }
00957 
00958   /// GetGEPReturnType - Returns the pointer type returned by the GEP
00959   /// instruction, which may be a vector of pointers.
00960   static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
00961     return getGEPReturnType(
00962         cast<PointerType>(Ptr->getType()->getScalarType())->getElementType(),
00963         Ptr, IdxList);
00964   }
00965   static Type *getGEPReturnType(Type *ElTy, Value *Ptr,
00966                                 ArrayRef<Value *> IdxList) {
00967     Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)),
00968                                    Ptr->getType()->getPointerAddressSpace());
00969     // Vector GEP
00970     if (Ptr->getType()->isVectorTy()) {
00971       unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements();
00972       return VectorType::get(PtrTy, NumElem);
00973     }
00974 
00975     // Scalar GEP
00976     return PtrTy;
00977   }
00978 
00979   unsigned getNumIndices() const {  // Note: always non-negative
00980     return getNumOperands() - 1;
00981   }
00982 
00983   bool hasIndices() const {
00984     return getNumOperands() > 1;
00985   }
00986 
00987   /// hasAllZeroIndices - Return true if all of the indices of this GEP are
00988   /// zeros.  If so, the result pointer and the first operand have the same
00989   /// value, just potentially different types.
00990   bool hasAllZeroIndices() const;
00991 
00992   /// hasAllConstantIndices - Return true if all of the indices of this GEP are
00993   /// constant integers.  If so, the result pointer and the first operand have
00994   /// a constant offset between them.
00995   bool hasAllConstantIndices() const;
00996 
00997   /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
00998   /// See LangRef.html for the meaning of inbounds on a getelementptr.
00999   void setIsInBounds(bool b = true);
01000 
01001   /// isInBounds - Determine whether the GEP has the inbounds flag.
01002   bool isInBounds() const;
01003 
01004   /// \brief Accumulate the constant address offset of this GEP if possible.
01005   ///
01006   /// This routine accepts an APInt into which it will accumulate the constant
01007   /// offset of this GEP if the GEP is in fact constant. If the GEP is not
01008   /// all-constant, it returns false and the value of the offset APInt is
01009   /// undefined (it is *not* preserved!). The APInt passed into this routine
01010   /// must be at least as wide as the IntPtr type for the address space of
01011   /// the base GEP pointer.
01012   bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
01013 
01014   // Methods for support type inquiry through isa, cast, and dyn_cast:
01015   static inline bool classof(const Instruction *I) {
01016     return (I->getOpcode() == Instruction::GetElementPtr);
01017   }
01018   static inline bool classof(const Value *V) {
01019     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01020   }
01021 };
01022 
01023 template <>
01024 struct OperandTraits<GetElementPtrInst> :
01025   public VariadicOperandTraits<GetElementPtrInst, 1> {
01026 };
01027 
01028 GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
01029                                      ArrayRef<Value *> IdxList, unsigned Values,
01030                                      const Twine &NameStr,
01031                                      Instruction *InsertBefore)
01032     : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
01033                   OperandTraits<GetElementPtrInst>::op_end(this) - Values,
01034                   Values, InsertBefore),
01035       SourceElementType(PointeeType),
01036       ResultElementType(getIndexedType(PointeeType, IdxList)) {
01037   assert(ResultElementType ==
01038          cast<PointerType>(getType()->getScalarType())->getElementType());
01039   init(Ptr, IdxList, NameStr);
01040 }
01041 GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
01042                                      ArrayRef<Value *> IdxList, unsigned Values,
01043                                      const Twine &NameStr,
01044                                      BasicBlock *InsertAtEnd)
01045     : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
01046                   OperandTraits<GetElementPtrInst>::op_end(this) - Values,
01047                   Values, InsertAtEnd),
01048       SourceElementType(PointeeType),
01049       ResultElementType(getIndexedType(PointeeType, IdxList)) {
01050   assert(ResultElementType ==
01051          cast<PointerType>(getType()->getScalarType())->getElementType());
01052   init(Ptr, IdxList, NameStr);
01053 }
01054 
01055 
01056 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
01057 
01058 
01059 //===----------------------------------------------------------------------===//
01060 //                               ICmpInst Class
01061 //===----------------------------------------------------------------------===//
01062 
01063 /// This instruction compares its operands according to the predicate given
01064 /// to the constructor. It only operates on integers or pointers. The operands
01065 /// must be identical types.
01066 /// \brief Represent an integer comparison operator.
01067 class ICmpInst: public CmpInst {
01068   void AssertOK() {
01069     assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE &&
01070            getPredicate() <= CmpInst::LAST_ICMP_PREDICATE &&
01071            "Invalid ICmp predicate value");
01072     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
01073           "Both operands to ICmp instruction are not of the same type!");
01074     // Check that the operands are the right type
01075     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
01076             getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
01077            "Invalid operand types for ICmp instruction");
01078   }
01079 
01080 protected:
01081   /// \brief Clone an identical ICmpInst
01082   ICmpInst *clone_impl() const override;
01083 public:
01084   /// \brief Constructor with insert-before-instruction semantics.
01085   ICmpInst(
01086     Instruction *InsertBefore,  ///< Where to insert
01087     Predicate pred,  ///< The predicate to use for the comparison
01088     Value *LHS,      ///< The left-hand-side of the expression
01089     Value *RHS,      ///< The right-hand-side of the expression
01090     const Twine &NameStr = ""  ///< Name of the instruction
01091   ) : CmpInst(makeCmpResultType(LHS->getType()),
01092               Instruction::ICmp, pred, LHS, RHS, NameStr,
01093               InsertBefore) {
01094 #ifndef NDEBUG
01095   AssertOK();
01096 #endif
01097   }
01098 
01099   /// \brief Constructor with insert-at-end semantics.
01100   ICmpInst(
01101     BasicBlock &InsertAtEnd, ///< Block to insert into.
01102     Predicate pred,  ///< The predicate to use for the comparison
01103     Value *LHS,      ///< The left-hand-side of the expression
01104     Value *RHS,      ///< The right-hand-side of the expression
01105     const Twine &NameStr = ""  ///< Name of the instruction
01106   ) : CmpInst(makeCmpResultType(LHS->getType()),
01107               Instruction::ICmp, pred, LHS, RHS, NameStr,
01108               &InsertAtEnd) {
01109 #ifndef NDEBUG
01110   AssertOK();
01111 #endif
01112   }
01113 
01114   /// \brief Constructor with no-insertion semantics
01115   ICmpInst(
01116     Predicate pred, ///< The predicate to use for the comparison
01117     Value *LHS,     ///< The left-hand-side of the expression
01118     Value *RHS,     ///< The right-hand-side of the expression
01119     const Twine &NameStr = "" ///< Name of the instruction
01120   ) : CmpInst(makeCmpResultType(LHS->getType()),
01121               Instruction::ICmp, pred, LHS, RHS, NameStr) {
01122 #ifndef NDEBUG
01123   AssertOK();
01124 #endif
01125   }
01126 
01127   /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
01128   /// @returns the predicate that would be the result if the operand were
01129   /// regarded as signed.
01130   /// \brief Return the signed version of the predicate
01131   Predicate getSignedPredicate() const {
01132     return getSignedPredicate(getPredicate());
01133   }
01134 
01135   /// This is a static version that you can use without an instruction.
01136   /// \brief Return the signed version of the predicate.
01137   static Predicate getSignedPredicate(Predicate pred);
01138 
01139   /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
01140   /// @returns the predicate that would be the result if the operand were
01141   /// regarded as unsigned.
01142   /// \brief Return the unsigned version of the predicate
01143   Predicate getUnsignedPredicate() const {
01144     return getUnsignedPredicate(getPredicate());
01145   }
01146 
01147   /// This is a static version that you can use without an instruction.
01148   /// \brief Return the unsigned version of the predicate.
01149   static Predicate getUnsignedPredicate(Predicate pred);
01150 
01151   /// isEquality - Return true if this predicate is either EQ or NE.  This also
01152   /// tests for commutativity.
01153   static bool isEquality(Predicate P) {
01154     return P == ICMP_EQ || P == ICMP_NE;
01155   }
01156 
01157   /// isEquality - Return true if this predicate is either EQ or NE.  This also
01158   /// tests for commutativity.
01159   bool isEquality() const {
01160     return isEquality(getPredicate());
01161   }
01162 
01163   /// @returns true if the predicate of this ICmpInst is commutative
01164   /// \brief Determine if this relation is commutative.
01165   bool isCommutative() const { return isEquality(); }
01166 
01167   /// isRelational - Return true if the predicate is relational (not EQ or NE).
01168   ///
01169   bool isRelational() const {
01170     return !isEquality();
01171   }
01172 
01173   /// isRelational - Return true if the predicate is relational (not EQ or NE).
01174   ///
01175   static bool isRelational(Predicate P) {
01176     return !isEquality(P);
01177   }
01178 
01179   /// Initialize a set of values that all satisfy the predicate with C.
01180   /// \brief Make a ConstantRange for a relation with a constant value.
01181   static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
01182 
01183   /// Exchange the two operands to this instruction in such a way that it does
01184   /// not modify the semantics of the instruction. The predicate value may be
01185   /// changed to retain the same result if the predicate is order dependent
01186   /// (e.g. ult).
01187   /// \brief Swap operands and adjust predicate.
01188   void swapOperands() {
01189     setPredicate(getSwappedPredicate());
01190     Op<0>().swap(Op<1>());
01191   }
01192 
01193   // Methods for support type inquiry through isa, cast, and dyn_cast:
01194   static inline bool classof(const Instruction *I) {
01195     return I->getOpcode() == Instruction::ICmp;
01196   }
01197   static inline bool classof(const Value *V) {
01198     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01199   }
01200 
01201 };
01202 
01203 //===----------------------------------------------------------------------===//
01204 //                               FCmpInst Class
01205 //===----------------------------------------------------------------------===//
01206 
01207 /// This instruction compares its operands according to the predicate given
01208 /// to the constructor. It only operates on floating point values or packed
01209 /// vectors of floating point values. The operands must be identical types.
01210 /// \brief Represents a floating point comparison operator.
01211 class FCmpInst: public CmpInst {
01212 protected:
01213   /// \brief Clone an identical FCmpInst
01214   FCmpInst *clone_impl() const override;
01215 public:
01216   /// \brief Constructor with insert-before-instruction semantics.
01217   FCmpInst(
01218     Instruction *InsertBefore, ///< Where to insert
01219     Predicate pred,  ///< The predicate to use for the comparison
01220     Value *LHS,      ///< The left-hand-side of the expression
01221     Value *RHS,      ///< The right-hand-side of the expression
01222     const Twine &NameStr = ""  ///< Name of the instruction
01223   ) : CmpInst(makeCmpResultType(LHS->getType()),
01224               Instruction::FCmp, pred, LHS, RHS, NameStr,
01225               InsertBefore) {
01226     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
01227            "Invalid FCmp predicate value");
01228     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
01229            "Both operands to FCmp instruction are not of the same type!");
01230     // Check that the operands are the right type
01231     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
01232            "Invalid operand types for FCmp instruction");
01233   }
01234 
01235   /// \brief Constructor with insert-at-end semantics.
01236   FCmpInst(
01237     BasicBlock &InsertAtEnd, ///< Block to insert into.
01238     Predicate pred,  ///< The predicate to use for the comparison
01239     Value *LHS,      ///< The left-hand-side of the expression
01240     Value *RHS,      ///< The right-hand-side of the expression
01241     const Twine &NameStr = ""  ///< Name of the instruction
01242   ) : CmpInst(makeCmpResultType(LHS->getType()),
01243               Instruction::FCmp, pred, LHS, RHS, NameStr,
01244               &InsertAtEnd) {
01245     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
01246            "Invalid FCmp predicate value");
01247     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
01248            "Both operands to FCmp instruction are not of the same type!");
01249     // Check that the operands are the right type
01250     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
01251            "Invalid operand types for FCmp instruction");
01252   }
01253 
01254   /// \brief Constructor with no-insertion semantics
01255   FCmpInst(
01256     Predicate pred, ///< The predicate to use for the comparison
01257     Value *LHS,     ///< The left-hand-side of the expression
01258     Value *RHS,     ///< The right-hand-side of the expression
01259     const Twine &NameStr = "" ///< Name of the instruction
01260   ) : CmpInst(makeCmpResultType(LHS->getType()),
01261               Instruction::FCmp, pred, LHS, RHS, NameStr) {
01262     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
01263            "Invalid FCmp predicate value");
01264     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
01265            "Both operands to FCmp instruction are not of the same type!");
01266     // Check that the operands are the right type
01267     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
01268            "Invalid operand types for FCmp instruction");
01269   }
01270 
01271   /// @returns true if the predicate of this instruction is EQ or NE.
01272   /// \brief Determine if this is an equality predicate.
01273   static bool isEquality(Predicate Pred) {
01274     return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ ||
01275            Pred == FCMP_UNE;
01276   }
01277 
01278   /// @returns true if the predicate of this instruction is EQ or NE.
01279   /// \brief Determine if this is an equality predicate.
01280   bool isEquality() const { return isEquality(getPredicate()); }
01281 
01282   /// @returns true if the predicate of this instruction is commutative.
01283   /// \brief Determine if this is a commutative predicate.
01284   bool isCommutative() const {
01285     return isEquality() ||
01286            getPredicate() == FCMP_FALSE ||
01287            getPredicate() == FCMP_TRUE ||
01288            getPredicate() == FCMP_ORD ||
01289            getPredicate() == FCMP_UNO;
01290   }
01291 
01292   /// @returns true if the predicate is relational (not EQ or NE).
01293   /// \brief Determine if this a relational predicate.
01294   bool isRelational() const { return !isEquality(); }
01295 
01296   /// Exchange the two operands to this instruction in such a way that it does
01297   /// not modify the semantics of the instruction. The predicate value may be
01298   /// changed to retain the same result if the predicate is order dependent
01299   /// (e.g. ult).
01300   /// \brief Swap operands and adjust predicate.
01301   void swapOperands() {
01302     setPredicate(getSwappedPredicate());
01303     Op<0>().swap(Op<1>());
01304   }
01305 
01306   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
01307   static inline bool classof(const Instruction *I) {
01308     return I->getOpcode() == Instruction::FCmp;
01309   }
01310   static inline bool classof(const Value *V) {
01311     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01312   }
01313 };
01314 
01315 //===----------------------------------------------------------------------===//
01316 /// CallInst - This class represents a function call, abstracting a target
01317 /// machine's calling convention.  This class uses low bit of the SubClassData
01318 /// field to indicate whether or not this is a tail call.  The rest of the bits
01319 /// hold the calling convention of the call.
01320 ///
01321 class CallInst : public Instruction {
01322   AttributeSet AttributeList; ///< parameter attributes for call
01323   FunctionType *FTy;
01324   CallInst(const CallInst &CI);
01325   void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr) {
01326     init(cast<FunctionType>(
01327              cast<PointerType>(Func->getType())->getElementType()),
01328          Func, Args, NameStr);
01329   }
01330   void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
01331             const Twine &NameStr);
01332   void init(Value *Func, const Twine &NameStr);
01333 
01334   /// Construct a CallInst given a range of arguments.
01335   /// \brief Construct a CallInst from a range of arguments
01336   inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
01337                   const Twine &NameStr, Instruction *InsertBefore);
01338   inline CallInst(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr,
01339                   Instruction *InsertBefore)
01340       : CallInst(cast<FunctionType>(
01341                      cast<PointerType>(Func->getType())->getElementType()),
01342                  Func, Args, NameStr, InsertBefore) {}
01343 
01344   /// Construct a CallInst given a range of arguments.
01345   /// \brief Construct a CallInst from a range of arguments
01346   inline CallInst(Value *Func, ArrayRef<Value *> Args,
01347                   const Twine &NameStr, BasicBlock *InsertAtEnd);
01348 
01349   explicit CallInst(Value *F, const Twine &NameStr,
01350                     Instruction *InsertBefore);
01351   CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
01352 protected:
01353   CallInst *clone_impl() const override;
01354 public:
01355   static CallInst *Create(Value *Func,
01356                           ArrayRef<Value *> Args,
01357                           const Twine &NameStr = "",
01358                           Instruction *InsertBefore = nullptr) {
01359     return Create(cast<FunctionType>(
01360                       cast<PointerType>(Func->getType())->getElementType()),
01361                   Func, Args, NameStr, InsertBefore);
01362   }
01363   static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
01364                           const Twine &NameStr = "",
01365                           Instruction *InsertBefore = nullptr) {
01366     return new (unsigned(Args.size() + 1))
01367         CallInst(Ty, Func, Args, NameStr, InsertBefore);
01368   }
01369   static CallInst *Create(Value *Func,
01370                           ArrayRef<Value *> Args,
01371                           const Twine &NameStr, BasicBlock *InsertAtEnd) {
01372     return new(unsigned(Args.size() + 1))
01373       CallInst(Func, Args, NameStr, InsertAtEnd);
01374   }
01375   static CallInst *Create(Value *F, const Twine &NameStr = "",
01376                           Instruction *InsertBefore = nullptr) {
01377     return new(1) CallInst(F, NameStr, InsertBefore);
01378   }
01379   static CallInst *Create(Value *F, const Twine &NameStr,
01380                           BasicBlock *InsertAtEnd) {
01381     return new(1) CallInst(F, NameStr, InsertAtEnd);
01382   }
01383   /// CreateMalloc - Generate the IR for a call to malloc:
01384   /// 1. Compute the malloc call's argument as the specified type's size,
01385   ///    possibly multiplied by the array size if the array size is not
01386   ///    constant 1.
01387   /// 2. Call malloc with that argument.
01388   /// 3. Bitcast the result of the malloc call to the specified type.
01389   static Instruction *CreateMalloc(Instruction *InsertBefore,
01390                                    Type *IntPtrTy, Type *AllocTy,
01391                                    Value *AllocSize, Value *ArraySize = nullptr,
01392                                    Function* MallocF = nullptr,
01393                                    const Twine &Name = "");
01394   static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
01395                                    Type *IntPtrTy, Type *AllocTy,
01396                                    Value *AllocSize, Value *ArraySize = nullptr,
01397                                    Function* MallocF = nullptr,
01398                                    const Twine &Name = "");
01399   /// CreateFree - Generate the IR for a call to the builtin free function.
01400   static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
01401   static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
01402 
01403   ~CallInst() override;
01404 
01405   FunctionType *getFunctionType() const { return FTy; }
01406 
01407   void mutateFunctionType(FunctionType *FTy) {
01408     mutateType(FTy->getReturnType());
01409     this->FTy = FTy;
01410   }
01411 
01412   // Note that 'musttail' implies 'tail'.
01413   enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2 };
01414   TailCallKind getTailCallKind() const {
01415     return TailCallKind(getSubclassDataFromInstruction() & 3);
01416   }
01417   bool isTailCall() const {
01418     return (getSubclassDataFromInstruction() & 3) != TCK_None;
01419   }
01420   bool isMustTailCall() const {
01421     return (getSubclassDataFromInstruction() & 3) == TCK_MustTail;
01422   }
01423   void setTailCall(bool isTC = true) {
01424     setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
01425                                unsigned(isTC ? TCK_Tail : TCK_None));
01426   }
01427   void setTailCallKind(TailCallKind TCK) {
01428     setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
01429                                unsigned(TCK));
01430   }
01431 
01432   /// Provide fast operand accessors
01433   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01434 
01435   /// getNumArgOperands - Return the number of call arguments.
01436   ///
01437   unsigned getNumArgOperands() const { return getNumOperands() - 1; }
01438 
01439   /// getArgOperand/setArgOperand - Return/set the i-th call argument.
01440   ///
01441   Value *getArgOperand(unsigned i) const { return getOperand(i); }
01442   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
01443 
01444   /// arg_operands - iteration adapter for range-for loops.
01445   iterator_range<op_iterator> arg_operands() {
01446     // The last operand in the op list is the callee - it's not one of the args
01447     // so we don't want to iterate over it.
01448     return iterator_range<op_iterator>(op_begin(), op_end() - 1);
01449   }
01450 
01451   /// arg_operands - iteration adapter for range-for loops.
01452   iterator_range<const_op_iterator> arg_operands() const {
01453     return iterator_range<const_op_iterator>(op_begin(), op_end() - 1);
01454   }
01455 
01456   /// \brief Wrappers for getting the \c Use of a call argument.
01457   const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
01458   Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
01459 
01460   /// getCallingConv/setCallingConv - Get or set the calling convention of this
01461   /// function call.
01462   CallingConv::ID getCallingConv() const {
01463     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
01464   }
01465   void setCallingConv(CallingConv::ID CC) {
01466     setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
01467                                (static_cast<unsigned>(CC) << 2));
01468   }
01469 
01470   /// getAttributes - Return the parameter attributes for this call.
01471   ///
01472   const AttributeSet &getAttributes() const { return AttributeList; }
01473 
01474   /// setAttributes - Set the parameter attributes for this call.
01475   ///
01476   void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
01477 
01478   /// addAttribute - adds the attribute to the list of attributes.
01479   void addAttribute(unsigned i, Attribute::AttrKind attr);
01480 
01481   /// removeAttribute - removes the attribute from the list of attributes.
01482   void removeAttribute(unsigned i, Attribute attr);
01483 
01484   /// \brief adds the dereferenceable attribute to the list of attributes.
01485   void addDereferenceableAttr(unsigned i, uint64_t Bytes);
01486 
01487   /// \brief adds the dereferenceable_or_null attribute to the list of
01488   /// attributes.
01489   void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
01490 
01491   /// \brief Determine whether this call has the given attribute.
01492   bool hasFnAttr(Attribute::AttrKind A) const {
01493     assert(A != Attribute::NoBuiltin &&
01494            "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
01495     return hasFnAttrImpl(A);
01496   }
01497 
01498   /// \brief Determine whether the call or the callee has the given attributes.
01499   bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
01500 
01501   /// \brief Extract the alignment for a call or parameter (0=unknown).
01502   unsigned getParamAlignment(unsigned i) const {
01503     return AttributeList.getParamAlignment(i);
01504   }
01505 
01506   /// \brief Extract the number of dereferenceable bytes for a call or
01507   /// parameter (0=unknown).
01508   uint64_t getDereferenceableBytes(unsigned i) const {
01509     return AttributeList.getDereferenceableBytes(i);
01510   }
01511 
01512   /// \brief Extract the number of dereferenceable_or_null bytes for a call or
01513   /// parameter (0=unknown).
01514   uint64_t getDereferenceableOrNullBytes(unsigned i) const {
01515     return AttributeList.getDereferenceableOrNullBytes(i);
01516   }
01517   
01518   /// \brief Return true if the call should not be treated as a call to a
01519   /// builtin.
01520   bool isNoBuiltin() const {
01521     return hasFnAttrImpl(Attribute::NoBuiltin) &&
01522       !hasFnAttrImpl(Attribute::Builtin);
01523   }
01524 
01525   /// \brief Return true if the call should not be inlined.
01526   bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
01527   void setIsNoInline() {
01528     addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
01529   }
01530 
01531   /// \brief Return true if the call can return twice
01532   bool canReturnTwice() const {
01533     return hasFnAttr(Attribute::ReturnsTwice);
01534   }
01535   void setCanReturnTwice() {
01536     addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
01537   }
01538 
01539   /// \brief Determine if the call does not access memory.
01540   bool doesNotAccessMemory() const {
01541     return hasFnAttr(Attribute::ReadNone);
01542   }
01543   void setDoesNotAccessMemory() {
01544     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
01545   }
01546 
01547   /// \brief Determine if the call does not access or only reads memory.
01548   bool onlyReadsMemory() const {
01549     return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
01550   }
01551   void setOnlyReadsMemory() {
01552     addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
01553   }
01554 
01555   /// \brief Determine if the call cannot return.
01556   bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
01557   void setDoesNotReturn() {
01558     addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
01559   }
01560 
01561   /// \brief Determine if the call cannot unwind.
01562   bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
01563   void setDoesNotThrow() {
01564     addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
01565   }
01566 
01567   /// \brief Determine if the call cannot be duplicated.
01568   bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
01569   void setCannotDuplicate() {
01570     addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
01571   }
01572 
01573   /// \brief Determine if the call returns a structure through first
01574   /// pointer argument.
01575   bool hasStructRetAttr() const {
01576     // Be friendly and also check the callee.
01577     return paramHasAttr(1, Attribute::StructRet);
01578   }
01579 
01580   /// \brief Determine if any call argument is an aggregate passed by value.
01581   bool hasByValArgument() const {
01582     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
01583   }
01584 
01585   /// getCalledFunction - Return the function called, or null if this is an
01586   /// indirect function invocation.
01587   ///
01588   Function *getCalledFunction() const {
01589     return dyn_cast<Function>(Op<-1>());
01590   }
01591 
01592   /// getCalledValue - Get a pointer to the function that is invoked by this
01593   /// instruction.
01594   const Value *getCalledValue() const { return Op<-1>(); }
01595         Value *getCalledValue()       { return Op<-1>(); }
01596 
01597   /// setCalledFunction - Set the function called.
01598   void setCalledFunction(Value* Fn) {
01599     setCalledFunction(
01600         cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
01601         Fn);
01602   }
01603   void setCalledFunction(FunctionType *FTy, Value *Fn) {
01604     this->FTy = FTy;
01605     assert(FTy == cast<FunctionType>(
01606                       cast<PointerType>(Fn->getType())->getElementType()));
01607     Op<-1>() = Fn;
01608   }
01609 
01610   /// isInlineAsm - Check if this call is an inline asm statement.
01611   bool isInlineAsm() const {
01612     return isa<InlineAsm>(Op<-1>());
01613   }
01614 
01615   // Methods for support type inquiry through isa, cast, and dyn_cast:
01616   static inline bool classof(const Instruction *I) {
01617     return I->getOpcode() == Instruction::Call;
01618   }
01619   static inline bool classof(const Value *V) {
01620     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01621   }
01622 private:
01623 
01624   bool hasFnAttrImpl(Attribute::AttrKind A) const;
01625 
01626   // Shadow Instruction::setInstructionSubclassData with a private forwarding
01627   // method so that subclasses cannot accidentally use it.
01628   void setInstructionSubclassData(unsigned short D) {
01629     Instruction::setInstructionSubclassData(D);
01630   }
01631 };
01632 
01633 template <>
01634 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
01635 };
01636 
01637 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
01638                    const Twine &NameStr, BasicBlock *InsertAtEnd)
01639   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
01640                                    ->getElementType())->getReturnType(),
01641                 Instruction::Call,
01642                 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
01643                 unsigned(Args.size() + 1), InsertAtEnd) {
01644   init(Func, Args, NameStr);
01645 }
01646 
01647 CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
01648                    const Twine &NameStr, Instruction *InsertBefore)
01649     : Instruction(Ty->getReturnType(), Instruction::Call,
01650                   OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
01651                   unsigned(Args.size() + 1), InsertBefore) {
01652   init(Ty, Func, Args, NameStr);
01653 }
01654 
01655 
01656 // Note: if you get compile errors about private methods then
01657 //       please update your code to use the high-level operand
01658 //       interfaces. See line 943 above.
01659 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
01660 
01661 //===----------------------------------------------------------------------===//
01662 //                               SelectInst Class
01663 //===----------------------------------------------------------------------===//
01664 
01665 /// SelectInst - This class represents the LLVM 'select' instruction.
01666 ///
01667 class SelectInst : public Instruction {
01668   void init(Value *C, Value *S1, Value *S2) {
01669     assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
01670     Op<0>() = C;
01671     Op<1>() = S1;
01672     Op<2>() = S2;
01673   }
01674 
01675   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
01676              Instruction *InsertBefore)
01677     : Instruction(S1->getType(), Instruction::Select,
01678                   &Op<0>(), 3, InsertBefore) {
01679     init(C, S1, S2);
01680     setName(NameStr);
01681   }
01682   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
01683              BasicBlock *InsertAtEnd)
01684     : Instruction(S1->getType(), Instruction::Select,
01685                   &Op<0>(), 3, InsertAtEnd) {
01686     init(C, S1, S2);
01687     setName(NameStr);
01688   }
01689 protected:
01690   SelectInst *clone_impl() const override;
01691 public:
01692   static SelectInst *Create(Value *C, Value *S1, Value *S2,
01693                             const Twine &NameStr = "",
01694                             Instruction *InsertBefore = nullptr) {
01695     return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
01696   }
01697   static SelectInst *Create(Value *C, Value *S1, Value *S2,
01698                             const Twine &NameStr,
01699                             BasicBlock *InsertAtEnd) {
01700     return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
01701   }
01702 
01703   const Value *getCondition() const { return Op<0>(); }
01704   const Value *getTrueValue() const { return Op<1>(); }
01705   const Value *getFalseValue() const { return Op<2>(); }
01706   Value *getCondition() { return Op<0>(); }
01707   Value *getTrueValue() { return Op<1>(); }
01708   Value *getFalseValue() { return Op<2>(); }
01709 
01710   /// areInvalidOperands - Return a string if the specified operands are invalid
01711   /// for a select operation, otherwise return null.
01712   static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
01713 
01714   /// Transparently provide more efficient getOperand methods.
01715   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01716 
01717   OtherOps getOpcode() const {
01718     return static_cast<OtherOps>(Instruction::getOpcode());
01719   }
01720 
01721   // Methods for support type inquiry through isa, cast, and dyn_cast:
01722   static inline bool classof(const Instruction *I) {
01723     return I->getOpcode() == Instruction::Select;
01724   }
01725   static inline bool classof(const Value *V) {
01726     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01727   }
01728 };
01729 
01730 template <>
01731 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
01732 };
01733 
01734 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
01735 
01736 //===----------------------------------------------------------------------===//
01737 //                                VAArgInst Class
01738 //===----------------------------------------------------------------------===//
01739 
01740 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
01741 /// an argument of the specified type given a va_list and increments that list
01742 ///
01743 class VAArgInst : public UnaryInstruction {
01744 protected:
01745   VAArgInst *clone_impl() const override;
01746 
01747 public:
01748   VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
01749              Instruction *InsertBefore = nullptr)
01750     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
01751     setName(NameStr);
01752   }
01753   VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
01754             BasicBlock *InsertAtEnd)
01755     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
01756     setName(NameStr);
01757   }
01758 
01759   Value *getPointerOperand() { return getOperand(0); }
01760   const Value *getPointerOperand() const { return getOperand(0); }
01761   static unsigned getPointerOperandIndex() { return 0U; }
01762 
01763   // Methods for support type inquiry through isa, cast, and dyn_cast:
01764   static inline bool classof(const Instruction *I) {
01765     return I->getOpcode() == VAArg;
01766   }
01767   static inline bool classof(const Value *V) {
01768     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01769   }
01770 };
01771 
01772 //===----------------------------------------------------------------------===//
01773 //                                ExtractElementInst Class
01774 //===----------------------------------------------------------------------===//
01775 
01776 /// ExtractElementInst - This instruction extracts a single (scalar)
01777 /// element from a VectorType value
01778 ///
01779 class ExtractElementInst : public Instruction {
01780   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
01781                      Instruction *InsertBefore = nullptr);
01782   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
01783                      BasicBlock *InsertAtEnd);
01784 protected:
01785   ExtractElementInst *clone_impl() const override;
01786 
01787 public:
01788   static ExtractElementInst *Create(Value *Vec, Value *Idx,
01789                                    const Twine &NameStr = "",
01790                                    Instruction *InsertBefore = nullptr) {
01791     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
01792   }
01793   static ExtractElementInst *Create(Value *Vec, Value *Idx,
01794                                    const Twine &NameStr,
01795                                    BasicBlock *InsertAtEnd) {
01796     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
01797   }
01798 
01799   /// isValidOperands - Return true if an extractelement instruction can be
01800   /// formed with the specified operands.
01801   static bool isValidOperands(const Value *Vec, const Value *Idx);
01802 
01803   Value *getVectorOperand() { return Op<0>(); }
01804   Value *getIndexOperand() { return Op<1>(); }
01805   const Value *getVectorOperand() const { return Op<0>(); }
01806   const Value *getIndexOperand() const { return Op<1>(); }
01807 
01808   VectorType *getVectorOperandType() const {
01809     return cast<VectorType>(getVectorOperand()->getType());
01810   }
01811 
01812 
01813   /// Transparently provide more efficient getOperand methods.
01814   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01815 
01816   // Methods for support type inquiry through isa, cast, and dyn_cast:
01817   static inline bool classof(const Instruction *I) {
01818     return I->getOpcode() == Instruction::ExtractElement;
01819   }
01820   static inline bool classof(const Value *V) {
01821     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01822   }
01823 };
01824 
01825 template <>
01826 struct OperandTraits<ExtractElementInst> :
01827   public FixedNumOperandTraits<ExtractElementInst, 2> {
01828 };
01829 
01830 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
01831 
01832 //===----------------------------------------------------------------------===//
01833 //                                InsertElementInst Class
01834 //===----------------------------------------------------------------------===//
01835 
01836 /// InsertElementInst - This instruction inserts a single (scalar)
01837 /// element into a VectorType value
01838 ///
01839 class InsertElementInst : public Instruction {
01840   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
01841                     const Twine &NameStr = "",
01842                     Instruction *InsertBefore = nullptr);
01843   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
01844                     const Twine &NameStr, BasicBlock *InsertAtEnd);
01845 protected:
01846   InsertElementInst *clone_impl() const override;
01847 
01848 public:
01849   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
01850                                    const Twine &NameStr = "",
01851                                    Instruction *InsertBefore = nullptr) {
01852     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
01853   }
01854   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
01855                                    const Twine &NameStr,
01856                                    BasicBlock *InsertAtEnd) {
01857     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
01858   }
01859 
01860   /// isValidOperands - Return true if an insertelement instruction can be
01861   /// formed with the specified operands.
01862   static bool isValidOperands(const Value *Vec, const Value *NewElt,
01863                               const Value *Idx);
01864 
01865   /// getType - Overload to return most specific vector type.
01866   ///
01867   VectorType *getType() const {
01868     return cast<VectorType>(Instruction::getType());
01869   }
01870 
01871   /// Transparently provide more efficient getOperand methods.
01872   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01873 
01874   // Methods for support type inquiry through isa, cast, and dyn_cast:
01875   static inline bool classof(const Instruction *I) {
01876     return I->getOpcode() == Instruction::InsertElement;
01877   }
01878   static inline bool classof(const Value *V) {
01879     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01880   }
01881 };
01882 
01883 template <>
01884 struct OperandTraits<InsertElementInst> :
01885   public FixedNumOperandTraits<InsertElementInst, 3> {
01886 };
01887 
01888 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
01889 
01890 //===----------------------------------------------------------------------===//
01891 //                           ShuffleVectorInst Class
01892 //===----------------------------------------------------------------------===//
01893 
01894 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
01895 /// input vectors.
01896 ///
01897 class ShuffleVectorInst : public Instruction {
01898 protected:
01899   ShuffleVectorInst *clone_impl() const override;
01900 
01901 public:
01902   // allocate space for exactly three operands
01903   void *operator new(size_t s) {
01904     return User::operator new(s, 3);
01905   }
01906   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
01907                     const Twine &NameStr = "",
01908                     Instruction *InsertBefor = nullptr);
01909   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
01910                     const Twine &NameStr, BasicBlock *InsertAtEnd);
01911 
01912   /// isValidOperands - Return true if a shufflevector instruction can be
01913   /// formed with the specified operands.
01914   static bool isValidOperands(const Value *V1, const Value *V2,
01915                               const Value *Mask);
01916 
01917   /// getType - Overload to return most specific vector type.
01918   ///
01919   VectorType *getType() const {
01920     return cast<VectorType>(Instruction::getType());
01921   }
01922 
01923   /// Transparently provide more efficient getOperand methods.
01924   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
01925 
01926   Constant *getMask() const {
01927     return cast<Constant>(getOperand(2));
01928   }
01929 
01930   /// getMaskValue - Return the index from the shuffle mask for the specified
01931   /// output result.  This is either -1 if the element is undef or a number less
01932   /// than 2*numelements.
01933   static int getMaskValue(Constant *Mask, unsigned i);
01934 
01935   int getMaskValue(unsigned i) const {
01936     return getMaskValue(getMask(), i);
01937   }
01938 
01939   /// getShuffleMask - Return the full mask for this instruction, where each
01940   /// element is the element number and undef's are returned as -1.
01941   static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
01942 
01943   void getShuffleMask(SmallVectorImpl<int> &Result) const {
01944     return getShuffleMask(getMask(), Result);
01945   }
01946 
01947   SmallVector<int, 16> getShuffleMask() const {
01948     SmallVector<int, 16> Mask;
01949     getShuffleMask(Mask);
01950     return Mask;
01951   }
01952 
01953 
01954   // Methods for support type inquiry through isa, cast, and dyn_cast:
01955   static inline bool classof(const Instruction *I) {
01956     return I->getOpcode() == Instruction::ShuffleVector;
01957   }
01958   static inline bool classof(const Value *V) {
01959     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01960   }
01961 };
01962 
01963 template <>
01964 struct OperandTraits<ShuffleVectorInst> :
01965   public FixedNumOperandTraits<ShuffleVectorInst, 3> {
01966 };
01967 
01968 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
01969 
01970 //===----------------------------------------------------------------------===//
01971 //                                ExtractValueInst Class
01972 //===----------------------------------------------------------------------===//
01973 
01974 /// ExtractValueInst - This instruction extracts a struct member or array
01975 /// element value from an aggregate value.
01976 ///
01977 class ExtractValueInst : public UnaryInstruction {
01978   SmallVector<unsigned, 4> Indices;
01979 
01980   ExtractValueInst(const ExtractValueInst &EVI);
01981   void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
01982 
01983   /// Constructors - Create a extractvalue instruction with a base aggregate
01984   /// value and a list of indices.  The first ctor can optionally insert before
01985   /// an existing instruction, the second appends the new instruction to the
01986   /// specified BasicBlock.
01987   inline ExtractValueInst(Value *Agg,
01988                           ArrayRef<unsigned> Idxs,
01989                           const Twine &NameStr,
01990                           Instruction *InsertBefore);
01991   inline ExtractValueInst(Value *Agg,
01992                           ArrayRef<unsigned> Idxs,
01993                           const Twine &NameStr, BasicBlock *InsertAtEnd);
01994 
01995   // allocate space for exactly one operand
01996   void *operator new(size_t s) {
01997     return User::operator new(s, 1);
01998   }
01999 protected:
02000   ExtractValueInst *clone_impl() const override;
02001 
02002 public:
02003   static ExtractValueInst *Create(Value *Agg,
02004                                   ArrayRef<unsigned> Idxs,
02005                                   const Twine &NameStr = "",
02006                                   Instruction *InsertBefore = nullptr) {
02007     return new
02008       ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
02009   }
02010   static ExtractValueInst *Create(Value *Agg,
02011                                   ArrayRef<unsigned> Idxs,
02012                                   const Twine &NameStr,
02013                                   BasicBlock *InsertAtEnd) {
02014     return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
02015   }
02016 
02017   /// getIndexedType - Returns the type of the element that would be extracted
02018   /// with an extractvalue instruction with the specified parameters.
02019   ///
02020   /// Null is returned if the indices are invalid for the specified type.
02021   static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
02022 
02023   typedef const unsigned* idx_iterator;
02024   inline idx_iterator idx_begin() const { return Indices.begin(); }
02025   inline idx_iterator idx_end()   const { return Indices.end(); }
02026   inline iterator_range<idx_iterator> indices() const {
02027     return iterator_range<idx_iterator>(idx_begin(), idx_end());
02028   }
02029 
02030   Value *getAggregateOperand() {
02031     return getOperand(0);
02032   }
02033   const Value *getAggregateOperand() const {
02034     return getOperand(0);
02035   }
02036   static unsigned getAggregateOperandIndex() {
02037     return 0U;                      // get index for modifying correct operand
02038   }
02039 
02040   ArrayRef<unsigned> getIndices() const {
02041     return Indices;
02042   }
02043 
02044   unsigned getNumIndices() const {
02045     return (unsigned)Indices.size();
02046   }
02047 
02048   bool hasIndices() const {
02049     return true;
02050   }
02051 
02052   // Methods for support type inquiry through isa, cast, and dyn_cast:
02053   static inline bool classof(const Instruction *I) {
02054     return I->getOpcode() == Instruction::ExtractValue;
02055   }
02056   static inline bool classof(const Value *V) {
02057     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02058   }
02059 };
02060 
02061 ExtractValueInst::ExtractValueInst(Value *Agg,
02062                                    ArrayRef<unsigned> Idxs,
02063                                    const Twine &NameStr,
02064                                    Instruction *InsertBefore)
02065   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
02066                      ExtractValue, Agg, InsertBefore) {
02067   init(Idxs, NameStr);
02068 }
02069 ExtractValueInst::ExtractValueInst(Value *Agg,
02070                                    ArrayRef<unsigned> Idxs,
02071                                    const Twine &NameStr,
02072                                    BasicBlock *InsertAtEnd)
02073   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
02074                      ExtractValue, Agg, InsertAtEnd) {
02075   init(Idxs, NameStr);
02076 }
02077 
02078 
02079 //===----------------------------------------------------------------------===//
02080 //                                InsertValueInst Class
02081 //===----------------------------------------------------------------------===//
02082 
02083 /// InsertValueInst - This instruction inserts a struct field of array element
02084 /// value into an aggregate value.
02085 ///
02086 class InsertValueInst : public Instruction {
02087   SmallVector<unsigned, 4> Indices;
02088 
02089   void *operator new(size_t, unsigned) = delete;
02090   InsertValueInst(const InsertValueInst &IVI);
02091   void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
02092             const Twine &NameStr);
02093 
02094   /// Constructors - Create a insertvalue instruction with a base aggregate
02095   /// value, a value to insert, and a list of indices.  The first ctor can
02096   /// optionally insert before an existing instruction, the second appends
02097   /// the new instruction to the specified BasicBlock.
02098   inline InsertValueInst(Value *Agg, Value *Val,
02099                          ArrayRef<unsigned> Idxs,
02100                          const Twine &NameStr,
02101                          Instruction *InsertBefore);
02102   inline InsertValueInst(Value *Agg, Value *Val,
02103                          ArrayRef<unsigned> Idxs,
02104                          const Twine &NameStr, BasicBlock *InsertAtEnd);
02105 
02106   /// Constructors - These two constructors are convenience methods because one
02107   /// and two index insertvalue instructions are so common.
02108   InsertValueInst(Value *Agg, Value *Val,
02109                   unsigned Idx, const Twine &NameStr = "",
02110                   Instruction *InsertBefore = nullptr);
02111   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
02112                   const Twine &NameStr, BasicBlock *InsertAtEnd);
02113 protected:
02114   InsertValueInst *clone_impl() const override;
02115 public:
02116   // allocate space for exactly two operands
02117   void *operator new(size_t s) {
02118     return User::operator new(s, 2);
02119   }
02120 
02121   static InsertValueInst *Create(Value *Agg, Value *Val,
02122                                  ArrayRef<unsigned> Idxs,
02123                                  const Twine &NameStr = "",
02124                                  Instruction *InsertBefore = nullptr) {
02125     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
02126   }
02127   static InsertValueInst *Create(Value *Agg, Value *Val,
02128                                  ArrayRef<unsigned> Idxs,
02129                                  const Twine &NameStr,
02130                                  BasicBlock *InsertAtEnd) {
02131     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
02132   }
02133 
02134   /// Transparently provide more efficient getOperand methods.
02135   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02136 
02137   typedef const unsigned* idx_iterator;
02138   inline idx_iterator idx_begin() const { return Indices.begin(); }
02139   inline idx_iterator idx_end()   const { return Indices.end(); }
02140   inline iterator_range<idx_iterator> indices() const {
02141     return iterator_range<idx_iterator>(idx_begin(), idx_end());
02142   }
02143 
02144   Value *getAggregateOperand() {
02145     return getOperand(0);
02146   }
02147   const Value *getAggregateOperand() const {
02148     return getOperand(0);
02149   }
02150   static unsigned getAggregateOperandIndex() {
02151     return 0U;                      // get index for modifying correct operand
02152   }
02153 
02154   Value *getInsertedValueOperand() {
02155     return getOperand(1);
02156   }
02157   const Value *getInsertedValueOperand() const {
02158     return getOperand(1);
02159   }
02160   static unsigned getInsertedValueOperandIndex() {
02161     return 1U;                      // get index for modifying correct operand
02162   }
02163 
02164   ArrayRef<unsigned> getIndices() const {
02165     return Indices;
02166   }
02167 
02168   unsigned getNumIndices() const {
02169     return (unsigned)Indices.size();
02170   }
02171 
02172   bool hasIndices() const {
02173     return true;
02174   }
02175 
02176   // Methods for support type inquiry through isa, cast, and dyn_cast:
02177   static inline bool classof(const Instruction *I) {
02178     return I->getOpcode() == Instruction::InsertValue;
02179   }
02180   static inline bool classof(const Value *V) {
02181     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02182   }
02183 };
02184 
02185 template <>
02186 struct OperandTraits<InsertValueInst> :
02187   public FixedNumOperandTraits<InsertValueInst, 2> {
02188 };
02189 
02190 InsertValueInst::InsertValueInst(Value *Agg,
02191                                  Value *Val,
02192                                  ArrayRef<unsigned> Idxs,
02193                                  const Twine &NameStr,
02194                                  Instruction *InsertBefore)
02195   : Instruction(Agg->getType(), InsertValue,
02196                 OperandTraits<InsertValueInst>::op_begin(this),
02197                 2, InsertBefore) {
02198   init(Agg, Val, Idxs, NameStr);
02199 }
02200 InsertValueInst::InsertValueInst(Value *Agg,
02201                                  Value *Val,
02202                                  ArrayRef<unsigned> Idxs,
02203                                  const Twine &NameStr,
02204                                  BasicBlock *InsertAtEnd)
02205   : Instruction(Agg->getType(), InsertValue,
02206                 OperandTraits<InsertValueInst>::op_begin(this),
02207                 2, InsertAtEnd) {
02208   init(Agg, Val, Idxs, NameStr);
02209 }
02210 
02211 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
02212 
02213 //===----------------------------------------------------------------------===//
02214 //                               PHINode Class
02215 //===----------------------------------------------------------------------===//
02216 
02217 // PHINode - The PHINode class is used to represent the magical mystical PHI
02218 // node, that can not exist in nature, but can be synthesized in a computer
02219 // scientist's overactive imagination.
02220 //
02221 class PHINode : public Instruction {
02222   void *operator new(size_t, unsigned) = delete;
02223   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
02224   /// the number actually in use.
02225   unsigned ReservedSpace;
02226   PHINode(const PHINode &PN);
02227   // allocate space for exactly zero operands
02228   void *operator new(size_t s) {
02229     return User::operator new(s);
02230   }
02231   explicit PHINode(Type *Ty, unsigned NumReservedValues,
02232                    const Twine &NameStr = "",
02233                    Instruction *InsertBefore = nullptr)
02234     : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
02235       ReservedSpace(NumReservedValues) {
02236     setName(NameStr);
02237     allocHungoffUses(ReservedSpace);
02238   }
02239 
02240   PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
02241           BasicBlock *InsertAtEnd)
02242     : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
02243       ReservedSpace(NumReservedValues) {
02244     setName(NameStr);
02245     allocHungoffUses(ReservedSpace);
02246   }
02247 protected:
02248   // allocHungoffUses - this is more complicated than the generic
02249   // User::allocHungoffUses, because we have to allocate Uses for the incoming
02250   // values and pointers to the incoming blocks, all in one allocation.
02251   void allocHungoffUses(unsigned N) {
02252     User::allocHungoffUses(N, /* IsPhi */ true);
02253   }
02254 
02255   PHINode *clone_impl() const override;
02256 public:
02257   /// Constructors - NumReservedValues is a hint for the number of incoming
02258   /// edges that this phi node will have (use 0 if you really have no idea).
02259   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
02260                          const Twine &NameStr = "",
02261                          Instruction *InsertBefore = nullptr) {
02262     return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
02263   }
02264   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
02265                          const Twine &NameStr, BasicBlock *InsertAtEnd) {
02266     return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
02267   }
02268 
02269   /// Provide fast operand accessors
02270   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02271 
02272   // Block iterator interface. This provides access to the list of incoming
02273   // basic blocks, which parallels the list of incoming values.
02274 
02275   typedef BasicBlock **block_iterator;
02276   typedef BasicBlock * const *const_block_iterator;
02277 
02278   block_iterator block_begin() {
02279     Use::UserRef *ref =
02280       reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
02281     return reinterpret_cast<block_iterator>(ref + 1);
02282   }
02283 
02284   const_block_iterator block_begin() const {
02285     const Use::UserRef *ref =
02286       reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
02287     return reinterpret_cast<const_block_iterator>(ref + 1);
02288   }
02289 
02290   block_iterator block_end() {
02291     return block_begin() + getNumOperands();
02292   }
02293 
02294   const_block_iterator block_end() const {
02295     return block_begin() + getNumOperands();
02296   }
02297 
02298   op_range incoming_values() { return operands(); }
02299 
02300   const_op_range incoming_values() const { return operands(); }
02301 
02302   /// getNumIncomingValues - Return the number of incoming edges
02303   ///
02304   unsigned getNumIncomingValues() const { return getNumOperands(); }
02305 
02306   /// getIncomingValue - Return incoming value number x
02307   ///
02308   Value *getIncomingValue(unsigned i) const {
02309     return getOperand(i);
02310   }
02311   void setIncomingValue(unsigned i, Value *V) {
02312     setOperand(i, V);
02313   }
02314   static unsigned getOperandNumForIncomingValue(unsigned i) {
02315     return i;
02316   }
02317   static unsigned getIncomingValueNumForOperand(unsigned i) {
02318     return i;
02319   }
02320 
02321   /// getIncomingBlock - Return incoming basic block number @p i.
02322   ///
02323   BasicBlock *getIncomingBlock(unsigned i) const {
02324     return block_begin()[i];
02325   }
02326 
02327   /// getIncomingBlock - Return incoming basic block corresponding
02328   /// to an operand of the PHI.
02329   ///
02330   BasicBlock *getIncomingBlock(const Use &U) const {
02331     assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
02332     return getIncomingBlock(unsigned(&U - op_begin()));
02333   }
02334 
02335   /// getIncomingBlock - Return incoming basic block corresponding
02336   /// to value use iterator.
02337   ///
02338   BasicBlock *getIncomingBlock(Value::const_user_iterator I) const {
02339     return getIncomingBlock(I.getUse());
02340   }
02341 
02342   void setIncomingBlock(unsigned i, BasicBlock *BB) {
02343     block_begin()[i] = BB;
02344   }
02345 
02346   /// addIncoming - Add an incoming value to the end of the PHI list
02347   ///
02348   void addIncoming(Value *V, BasicBlock *BB) {
02349     assert(V && "PHI node got a null value!");
02350     assert(BB && "PHI node got a null basic block!");
02351     assert(getType() == V->getType() &&
02352            "All operands to PHI node must be the same type as the PHI node!");
02353     if (getNumOperands() == ReservedSpace)
02354       growOperands();  // Get more space!
02355     // Initialize some new operands.
02356     setNumHungOffUseOperands(getNumOperands() + 1);
02357     setIncomingValue(getNumOperands() - 1, V);
02358     setIncomingBlock(getNumOperands() - 1, BB);
02359   }
02360 
02361   /// removeIncomingValue - Remove an incoming value.  This is useful if a
02362   /// predecessor basic block is deleted.  The value removed is returned.
02363   ///
02364   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
02365   /// is true), the PHI node is destroyed and any uses of it are replaced with
02366   /// dummy values.  The only time there should be zero incoming values to a PHI
02367   /// node is when the block is dead, so this strategy is sound.
02368   ///
02369   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
02370 
02371   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
02372     int Idx = getBasicBlockIndex(BB);
02373     assert(Idx >= 0 && "Invalid basic block argument to remove!");
02374     return removeIncomingValue(Idx, DeletePHIIfEmpty);
02375   }
02376 
02377   /// getBasicBlockIndex - Return the first index of the specified basic
02378   /// block in the value list for this PHI.  Returns -1 if no instance.
02379   ///
02380   int getBasicBlockIndex(const BasicBlock *BB) const {
02381     for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
02382       if (block_begin()[i] == BB)
02383         return i;
02384     return -1;
02385   }
02386 
02387   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
02388     int Idx = getBasicBlockIndex(BB);
02389     assert(Idx >= 0 && "Invalid basic block argument!");
02390     return getIncomingValue(Idx);
02391   }
02392 
02393   /// hasConstantValue - If the specified PHI node always merges together the
02394   /// same value, return the value, otherwise return null.
02395   Value *hasConstantValue() const;
02396 
02397   /// Methods for support type inquiry through isa, cast, and dyn_cast:
02398   static inline bool classof(const Instruction *I) {
02399     return I->getOpcode() == Instruction::PHI;
02400   }
02401   static inline bool classof(const Value *V) {
02402     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02403   }
02404  private:
02405   void growOperands();
02406 };
02407 
02408 template <>
02409 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
02410 };
02411 
02412 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
02413 
02414 //===----------------------------------------------------------------------===//
02415 //                           LandingPadInst Class
02416 //===----------------------------------------------------------------------===//
02417 
02418 //===---------------------------------------------------------------------------
02419 /// LandingPadInst - The landingpad instruction holds all of the information
02420 /// necessary to generate correct exception handling. The landingpad instruction
02421 /// cannot be moved from the top of a landing pad block, which itself is
02422 /// accessible only from the 'unwind' edge of an invoke. This uses the
02423 /// SubclassData field in Value to store whether or not the landingpad is a
02424 /// cleanup.
02425 ///
02426 class LandingPadInst : public Instruction {
02427   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
02428   /// the number actually in use.
02429   unsigned ReservedSpace;
02430   LandingPadInst(const LandingPadInst &LP);
02431 public:
02432   enum ClauseType { Catch, Filter };
02433 private:
02434   void *operator new(size_t, unsigned) = delete;
02435   // Allocate space for exactly zero operands.
02436   void *operator new(size_t s) {
02437     return User::operator new(s);
02438   }
02439   void growOperands(unsigned Size);
02440   void init(unsigned NumReservedValues, const Twine &NameStr);
02441 
02442   explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
02443                           const Twine &NameStr, Instruction *InsertBefore);
02444   explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
02445                           const Twine &NameStr, BasicBlock *InsertAtEnd);
02446 
02447 protected:
02448   LandingPadInst *clone_impl() const override;
02449 public:
02450   /// Constructors - NumReservedClauses is a hint for the number of incoming
02451   /// clauses that this landingpad will have (use 0 if you really have no idea).
02452   static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
02453                                 const Twine &NameStr = "",
02454                                 Instruction *InsertBefore = nullptr);
02455   static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
02456                                 const Twine &NameStr, BasicBlock *InsertAtEnd);
02457 
02458   /// Provide fast operand accessors
02459   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02460 
02461   /// isCleanup - Return 'true' if this landingpad instruction is a
02462   /// cleanup. I.e., it should be run when unwinding even if its landing pad
02463   /// doesn't catch the exception.
02464   bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
02465 
02466   /// setCleanup - Indicate that this landingpad instruction is a cleanup.
02467   void setCleanup(bool V) {
02468     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
02469                                (V ? 1 : 0));
02470   }
02471 
02472   /// Add a catch or filter clause to the landing pad.
02473   void addClause(Constant *ClauseVal);
02474 
02475   /// Get the value of the clause at index Idx. Use isCatch/isFilter to
02476   /// determine what type of clause this is.
02477   Constant *getClause(unsigned Idx) const {
02478     return cast<Constant>(getOperandList()[Idx]);
02479   }
02480 
02481   /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
02482   bool isCatch(unsigned Idx) const {
02483     return !isa<ArrayType>(getOperandList()[Idx]->getType());
02484   }
02485 
02486   /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
02487   bool isFilter(unsigned Idx) const {
02488     return isa<ArrayType>(getOperandList()[Idx]->getType());
02489   }
02490 
02491   /// getNumClauses - Get the number of clauses for this landing pad.
02492   unsigned getNumClauses() const { return getNumOperands(); }
02493 
02494   /// reserveClauses - Grow the size of the operand list to accommodate the new
02495   /// number of clauses.
02496   void reserveClauses(unsigned Size) { growOperands(Size); }
02497 
02498   // Methods for support type inquiry through isa, cast, and dyn_cast:
02499   static inline bool classof(const Instruction *I) {
02500     return I->getOpcode() == Instruction::LandingPad;
02501   }
02502   static inline bool classof(const Value *V) {
02503     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02504   }
02505 };
02506 
02507 template <>
02508 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<1> {
02509 };
02510 
02511 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
02512 
02513 //===----------------------------------------------------------------------===//
02514 //                               ReturnInst Class
02515 //===----------------------------------------------------------------------===//
02516 
02517 //===---------------------------------------------------------------------------
02518 /// ReturnInst - Return a value (possibly void), from a function.  Execution
02519 /// does not continue in this function any longer.
02520 ///
02521 class ReturnInst : public TerminatorInst {
02522   ReturnInst(const ReturnInst &RI);
02523 
02524 private:
02525   // ReturnInst constructors:
02526   // ReturnInst()                  - 'ret void' instruction
02527   // ReturnInst(    null)          - 'ret void' instruction
02528   // ReturnInst(Value* X)          - 'ret X'    instruction
02529   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
02530   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
02531   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
02532   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
02533   //
02534   // NOTE: If the Value* passed is of type void then the constructor behaves as
02535   // if it was passed NULL.
02536   explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
02537                       Instruction *InsertBefore = nullptr);
02538   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
02539   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
02540 protected:
02541   ReturnInst *clone_impl() const override;
02542 public:
02543   static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
02544                             Instruction *InsertBefore = nullptr) {
02545     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
02546   }
02547   static ReturnInst* Create(LLVMContext &C, Value *retVal,
02548                             BasicBlock *InsertAtEnd) {
02549     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
02550   }
02551   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
02552     return new(0) ReturnInst(C, InsertAtEnd);
02553   }
02554   ~ReturnInst() override;
02555 
02556   /// Provide fast operand accessors
02557   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02558 
02559   /// Convenience accessor. Returns null if there is no return value.
02560   Value *getReturnValue() const {
02561     return getNumOperands() != 0 ? getOperand(0) : nullptr;
02562   }
02563 
02564   unsigned getNumSuccessors() const { return 0; }
02565 
02566   // Methods for support type inquiry through isa, cast, and dyn_cast:
02567   static inline bool classof(const Instruction *I) {
02568     return (I->getOpcode() == Instruction::Ret);
02569   }
02570   static inline bool classof(const Value *V) {
02571     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02572   }
02573  private:
02574   BasicBlock *getSuccessorV(unsigned idx) const override;
02575   unsigned getNumSuccessorsV() const override;
02576   void setSuccessorV(unsigned idx, BasicBlock *B) override;
02577 };
02578 
02579 template <>
02580 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
02581 };
02582 
02583 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
02584 
02585 //===----------------------------------------------------------------------===//
02586 //                               BranchInst Class
02587 //===----------------------------------------------------------------------===//
02588 
02589 //===---------------------------------------------------------------------------
02590 /// BranchInst - Conditional or Unconditional Branch instruction.
02591 ///
02592 class BranchInst : public TerminatorInst {
02593   /// Ops list - Branches are strange.  The operands are ordered:
02594   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
02595   /// they don't have to check for cond/uncond branchness. These are mostly
02596   /// accessed relative from op_end().
02597   BranchInst(const BranchInst &BI);
02598   void AssertOK();
02599   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
02600   // BranchInst(BB *B)                           - 'br B'
02601   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
02602   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
02603   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
02604   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
02605   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
02606   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
02607   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
02608              Instruction *InsertBefore = nullptr);
02609   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
02610   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
02611              BasicBlock *InsertAtEnd);
02612 protected:
02613   BranchInst *clone_impl() const override;
02614 public:
02615   static BranchInst *Create(BasicBlock *IfTrue,
02616                             Instruction *InsertBefore = nullptr) {
02617     return new(1) BranchInst(IfTrue, InsertBefore);
02618   }
02619   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
02620                             Value *Cond, Instruction *InsertBefore = nullptr) {
02621     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
02622   }
02623   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
02624     return new(1) BranchInst(IfTrue, InsertAtEnd);
02625   }
02626   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
02627                             Value *Cond, BasicBlock *InsertAtEnd) {
02628     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
02629   }
02630 
02631   /// Transparently provide more efficient getOperand methods.
02632   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02633 
02634   bool isUnconditional() const { return getNumOperands() == 1; }
02635   bool isConditional()   const { return getNumOperands() == 3; }
02636 
02637   Value *getCondition() const {
02638     assert(isConditional() && "Cannot get condition of an uncond branch!");
02639     return Op<-3>();
02640   }
02641 
02642   void setCondition(Value *V) {
02643     assert(isConditional() && "Cannot set condition of unconditional branch!");
02644     Op<-3>() = V;
02645   }
02646 
02647   unsigned getNumSuccessors() const { return 1+isConditional(); }
02648 
02649   BasicBlock *getSuccessor(unsigned i) const {
02650     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
02651     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
02652   }
02653 
02654   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
02655     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
02656     *(&Op<-1>() - idx) = (Value*)NewSucc;
02657   }
02658 
02659   /// \brief Swap the successors of this branch instruction.
02660   ///
02661   /// Swaps the successors of the branch instruction. This also swaps any
02662   /// branch weight metadata associated with the instruction so that it
02663   /// continues to map correctly to each operand.
02664   void swapSuccessors();
02665 
02666   // Methods for support type inquiry through isa, cast, and dyn_cast:
02667   static inline bool classof(const Instruction *I) {
02668     return (I->getOpcode() == Instruction::Br);
02669   }
02670   static inline bool classof(const Value *V) {
02671     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02672   }
02673 private:
02674   BasicBlock *getSuccessorV(unsigned idx) const override;
02675   unsigned getNumSuccessorsV() const override;
02676   void setSuccessorV(unsigned idx, BasicBlock *B) override;
02677 };
02678 
02679 template <>
02680 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
02681 };
02682 
02683 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
02684 
02685 //===----------------------------------------------------------------------===//
02686 //                               SwitchInst Class
02687 //===----------------------------------------------------------------------===//
02688 
02689 //===---------------------------------------------------------------------------
02690 /// SwitchInst - Multiway switch
02691 ///
02692 class SwitchInst : public TerminatorInst {
02693   void *operator new(size_t, unsigned) = delete;
02694   unsigned ReservedSpace;
02695   // Operand[0]    = Value to switch on
02696   // Operand[1]    = Default basic block destination
02697   // Operand[2n  ] = Value to match
02698   // Operand[2n+1] = BasicBlock to go to on match
02699   SwitchInst(const SwitchInst &SI);
02700   void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
02701   void growOperands();
02702   // allocate space for exactly zero operands
02703   void *operator new(size_t s) {
02704     return User::operator new(s);
02705   }
02706   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
02707   /// switch on and a default destination.  The number of additional cases can
02708   /// be specified here to make memory allocation more efficient.  This
02709   /// constructor can also autoinsert before another instruction.
02710   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
02711              Instruction *InsertBefore);
02712 
02713   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
02714   /// switch on and a default destination.  The number of additional cases can
02715   /// be specified here to make memory allocation more efficient.  This
02716   /// constructor also autoinserts at the end of the specified BasicBlock.
02717   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
02718              BasicBlock *InsertAtEnd);
02719 protected:
02720   SwitchInst *clone_impl() const override;
02721 public:
02722 
02723   // -2
02724   static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
02725 
02726   template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
02727   class CaseIteratorT {
02728   protected:
02729 
02730     SwitchInstTy *SI;
02731     unsigned Index;
02732 
02733   public:
02734 
02735     typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self;
02736 
02737     /// Initializes case iterator for given SwitchInst and for given
02738     /// case number.
02739     CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
02740       this->SI = SI;
02741       Index = CaseNum;
02742     }
02743 
02744     /// Initializes case iterator for given SwitchInst and for given
02745     /// TerminatorInst's successor index.
02746     static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
02747       assert(SuccessorIndex < SI->getNumSuccessors() &&
02748              "Successor index # out of range!");
02749       return SuccessorIndex != 0 ?
02750              Self(SI, SuccessorIndex - 1) :
02751              Self(SI, DefaultPseudoIndex);
02752     }
02753 
02754     /// Resolves case value for current case.
02755     ConstantIntTy *getCaseValue() {
02756       assert(Index < SI->getNumCases() && "Index out the number of cases.");
02757       return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
02758     }
02759 
02760     /// Resolves successor for current case.
02761     BasicBlockTy *getCaseSuccessor() {
02762       assert((Index < SI->getNumCases() ||
02763               Index == DefaultPseudoIndex) &&
02764              "Index out the number of cases.");
02765       return SI->getSuccessor(getSuccessorIndex());
02766     }
02767 
02768     /// Returns number of current case.
02769     unsigned getCaseIndex() const { return Index; }
02770 
02771     /// Returns TerminatorInst's successor index for current case successor.
02772     unsigned getSuccessorIndex() const {
02773       assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
02774              "Index out the number of cases.");
02775       return Index != DefaultPseudoIndex ? Index + 1 : 0;
02776     }
02777 
02778     Self operator++() {
02779       // Check index correctness after increment.
02780       // Note: Index == getNumCases() means end().
02781       assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
02782       ++Index;
02783       return *this;
02784     }
02785     Self operator++(int) {
02786       Self tmp = *this;
02787       ++(*this);
02788       return tmp;
02789     }
02790     Self operator--() {
02791       // Check index correctness after decrement.
02792       // Note: Index == getNumCases() means end().
02793       // Also allow "-1" iterator here. That will became valid after ++.
02794       assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
02795              "Index out the number of cases.");
02796       --Index;
02797       return *this;
02798     }
02799     Self operator--(int) {
02800       Self tmp = *this;
02801       --(*this);
02802       return tmp;
02803     }
02804     bool operator==(const Self& RHS) const {
02805       assert(RHS.SI == SI && "Incompatible operators.");
02806       return RHS.Index == Index;
02807     }
02808     bool operator!=(const Self& RHS) const {
02809       assert(RHS.SI == SI && "Incompatible operators.");
02810       return RHS.Index != Index;
02811     }
02812     Self &operator*() {
02813       return *this;
02814     }
02815   };
02816 
02817   typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
02818     ConstCaseIt;
02819 
02820   class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
02821 
02822     typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy;
02823 
02824   public:
02825 
02826     CaseIt(const ParentTy& Src) : ParentTy(Src) {}
02827     CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
02828 
02829     /// Sets the new value for current case.
02830     void setValue(ConstantInt *V) {
02831       assert(Index < SI->getNumCases() && "Index out the number of cases.");
02832       SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
02833     }
02834 
02835     /// Sets the new successor for current case.
02836     void setSuccessor(BasicBlock *S) {
02837       SI->setSuccessor(getSuccessorIndex(), S);
02838     }
02839   };
02840 
02841   static SwitchInst *Create(Value *Value, BasicBlock *Default,
02842                             unsigned NumCases,
02843                             Instruction *InsertBefore = nullptr) {
02844     return new SwitchInst(Value, Default, NumCases, InsertBefore);
02845   }
02846   static SwitchInst *Create(Value *Value, BasicBlock *Default,
02847                             unsigned NumCases, BasicBlock *InsertAtEnd) {
02848     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
02849   }
02850 
02851   /// Provide fast operand accessors
02852   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
02853 
02854   // Accessor Methods for Switch stmt
02855   Value *getCondition() const { return getOperand(0); }
02856   void setCondition(Value *V) { setOperand(0, V); }
02857 
02858   BasicBlock *getDefaultDest() const {
02859     return cast<BasicBlock>(getOperand(1));
02860   }
02861 
02862   void setDefaultDest(BasicBlock *DefaultCase) {
02863     setOperand(1, reinterpret_cast<Value*>(DefaultCase));
02864   }
02865 
02866   /// getNumCases - return the number of 'cases' in this switch instruction,
02867   /// except the default case
02868   unsigned getNumCases() const {
02869     return getNumOperands()/2 - 1;
02870   }
02871 
02872   /// Returns a read/write iterator that points to the first
02873   /// case in SwitchInst.
02874   CaseIt case_begin() {
02875     return CaseIt(this, 0);
02876   }
02877   /// Returns a read-only iterator that points to the first
02878   /// case in the SwitchInst.
02879   ConstCaseIt case_begin() const {
02880     return ConstCaseIt(this, 0);
02881   }
02882 
02883   /// Returns a read/write iterator that points one past the last
02884   /// in the SwitchInst.
02885   CaseIt case_end() {
02886     return CaseIt(this, getNumCases());
02887   }
02888   /// Returns a read-only iterator that points one past the last
02889   /// in the SwitchInst.
02890   ConstCaseIt case_end() const {
02891     return ConstCaseIt(this, getNumCases());
02892   }
02893 
02894   /// cases - iteration adapter for range-for loops.
02895   iterator_range<CaseIt> cases() {
02896     return iterator_range<CaseIt>(case_begin(), case_end());
02897   }
02898 
02899   /// cases - iteration adapter for range-for loops.
02900   iterator_range<ConstCaseIt> cases() const {
02901     return iterator_range<ConstCaseIt>(case_begin(), case_end());
02902   }
02903 
02904   /// Returns an iterator that points to the default case.
02905   /// Note: this iterator allows to resolve successor only. Attempt
02906   /// to resolve case value causes an assertion.
02907   /// Also note, that increment and decrement also causes an assertion and
02908   /// makes iterator invalid.
02909   CaseIt case_default() {
02910     return CaseIt(this, DefaultPseudoIndex);
02911   }
02912   ConstCaseIt case_default() const {
02913     return ConstCaseIt(this, DefaultPseudoIndex);
02914   }
02915 
02916   /// findCaseValue - Search all of the case values for the specified constant.
02917   /// If it is explicitly handled, return the case iterator of it, otherwise
02918   /// return default case iterator to indicate
02919   /// that it is handled by the default handler.
02920   CaseIt findCaseValue(const ConstantInt *C) {
02921     for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
02922       if (i.getCaseValue() == C)
02923         return i;
02924     return case_default();
02925   }
02926   ConstCaseIt findCaseValue(const ConstantInt *C) const {
02927     for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
02928       if (i.getCaseValue() == C)
02929         return i;
02930     return case_default();
02931   }
02932 
02933   /// findCaseDest - Finds the unique case value for a given successor. Returns
02934   /// null if the successor is not found, not unique, or is the default case.
02935   ConstantInt *findCaseDest(BasicBlock *BB) {
02936     if (BB == getDefaultDest()) return nullptr;
02937 
02938     ConstantInt *CI = nullptr;
02939     for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
02940       if (i.getCaseSuccessor() == BB) {
02941         if (CI) return nullptr;   // Multiple cases lead to BB.
02942         else CI = i.getCaseValue();
02943       }
02944     }
02945     return CI;
02946   }
02947 
02948   /// addCase - Add an entry to the switch instruction...
02949   /// Note:
02950   /// This action invalidates case_end(). Old case_end() iterator will
02951   /// point to the added case.
02952   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
02953 
02954   /// removeCase - This method removes the specified case and its successor
02955   /// from the switch instruction. Note that this operation may reorder the
02956   /// remaining cases at index idx and above.
02957   /// Note:
02958   /// This action invalidates iterators for all cases following the one removed,
02959   /// including the case_end() iterator.
02960   void removeCase(CaseIt i);
02961 
02962   unsigned getNumSuccessors() const { return getNumOperands()/2; }
02963   BasicBlock *getSuccessor(unsigned idx) const {
02964     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
02965     return cast<BasicBlock>(getOperand(idx*2+1));
02966   }
02967   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
02968     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
02969     setOperand(idx*2+1, (Value*)NewSucc);
02970   }
02971 
02972   // Methods for support type inquiry through isa, cast, and dyn_cast:
02973   static inline bool classof(const Instruction *I) {
02974     return I->getOpcode() == Instruction::Switch;
02975   }
02976   static inline bool classof(const Value *V) {
02977     return isa<Instruction>(V) && classof(cast<Instruction>(V));
02978   }
02979 private:
02980   BasicBlock *getSuccessorV(unsigned idx) const override;
02981   unsigned getNumSuccessorsV() const override;
02982   void setSuccessorV(unsigned idx, BasicBlock *B) override;
02983 };
02984 
02985 template <>
02986 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
02987 };
02988 
02989 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
02990 
02991 
02992 //===----------------------------------------------------------------------===//
02993 //                             IndirectBrInst Class
02994 //===----------------------------------------------------------------------===//
02995 
02996 //===---------------------------------------------------------------------------
02997 /// IndirectBrInst - Indirect Branch Instruction.
02998 ///
02999 class IndirectBrInst : public TerminatorInst {
03000   void *operator new(size_t, unsigned) = delete;
03001   unsigned ReservedSpace;
03002   // Operand[0]    = Value to switch on
03003   // Operand[1]    = Default basic block destination
03004   // Operand[2n  ] = Value to match
03005   // Operand[2n+1] = BasicBlock to go to on match
03006   IndirectBrInst(const IndirectBrInst &IBI);
03007   void init(Value *Address, unsigned NumDests);
03008   void growOperands();
03009   // allocate space for exactly zero operands
03010   void *operator new(size_t s) {
03011     return User::operator new(s);
03012   }
03013   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
03014   /// Address to jump to.  The number of expected destinations can be specified
03015   /// here to make memory allocation more efficient.  This constructor can also
03016   /// autoinsert before another instruction.
03017   IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
03018 
03019   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
03020   /// Address to jump to.  The number of expected destinations can be specified
03021   /// here to make memory allocation more efficient.  This constructor also
03022   /// autoinserts at the end of the specified BasicBlock.
03023   IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
03024 protected:
03025   IndirectBrInst *clone_impl() const override;
03026 public:
03027   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
03028                                 Instruction *InsertBefore = nullptr) {
03029     return new IndirectBrInst(Address, NumDests, InsertBefore);
03030   }
03031   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
03032                                 BasicBlock *InsertAtEnd) {
03033     return new IndirectBrInst(Address, NumDests, InsertAtEnd);
03034   }
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