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