LLVM API Documentation

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