LLVM API Documentation

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