Home | History | Annotate | Download | only in IR
      1 //===-- llvm/IntrinsicInst.h - Intrinsic Instruction Wrappers ---*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file defines classes that make it really easy to deal with intrinsic
     11 // functions with the isa/dyncast family of functions.  In particular, this
     12 // allows you to do things like:
     13 //
     14 //     if (MemCpyInst *MCI = dyn_cast<MemCpyInst>(Inst))
     15 //        ... MCI->getDest() ... MCI->getSource() ...
     16 //
     17 // All intrinsic function calls are instances of the call instruction, so these
     18 // are all subclasses of the CallInst class.  Note that none of these classes
     19 // has state or virtual methods, which is an important part of this gross/neat
     20 // hack working.
     21 //
     22 //===----------------------------------------------------------------------===//
     23 
     24 #ifndef LLVM_IR_INTRINSICINST_H
     25 #define LLVM_IR_INTRINSICINST_H
     26 
     27 #include "llvm/IR/Constants.h"
     28 #include "llvm/IR/DerivedTypes.h"
     29 #include "llvm/IR/Function.h"
     30 #include "llvm/IR/GlobalVariable.h"
     31 #include "llvm/IR/Instructions.h"
     32 #include "llvm/IR/Intrinsics.h"
     33 #include "llvm/IR/Metadata.h"
     34 #include "llvm/IR/Value.h"
     35 #include "llvm/Support/Casting.h"
     36 #include <cassert>
     37 #include <cstdint>
     38 
     39 namespace llvm {
     40 
     41   /// A wrapper class for inspecting calls to intrinsic functions.
     42   /// This allows the standard isa/dyncast/cast functionality to work with calls
     43   /// to intrinsic functions.
     44   class IntrinsicInst : public CallInst {
     45   public:
     46     IntrinsicInst() = delete;
     47     IntrinsicInst(const IntrinsicInst &) = delete;
     48     IntrinsicInst &operator=(const IntrinsicInst &) = delete;
     49 
     50     /// Return the intrinsic ID of this intrinsic.
     51     Intrinsic::ID getIntrinsicID() const {
     52       return getCalledFunction()->getIntrinsicID();
     53     }
     54 
     55     // Methods for support type inquiry through isa, cast, and dyn_cast:
     56     static bool classof(const CallInst *I) {
     57       if (const Function *CF = I->getCalledFunction())
     58         return CF->isIntrinsic();
     59       return false;
     60     }
     61     static bool classof(const Value *V) {
     62       return isa<CallInst>(V) && classof(cast<CallInst>(V));
     63     }
     64   };
     65 
     66   /// This is the common base class for debug info intrinsics.
     67   class DbgInfoIntrinsic : public IntrinsicInst {
     68   public:
     69     /// Get the location corresponding to the variable referenced by the debug
     70     /// info intrinsic.  Depending on the intrinsic, this could be the
     71     /// variable's value or its address.
     72     Value *getVariableLocation(bool AllowNullOp = true) const;
     73 
     74     /// Does this describe the address of a local variable. True for dbg.addr
     75     /// and dbg.declare, but not dbg.value, which describes its value.
     76     bool isAddressOfVariable() const {
     77       return getIntrinsicID() != Intrinsic::dbg_value;
     78     }
     79 
     80     DILocalVariable *getVariable() const {
     81       return cast<DILocalVariable>(getRawVariable());
     82     }
     83 
     84     DIExpression *getExpression() const {
     85       return cast<DIExpression>(getRawExpression());
     86     }
     87 
     88     Metadata *getRawVariable() const {
     89       return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
     90     }
     91 
     92     Metadata *getRawExpression() const {
     93       return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
     94     }
     95 
     96     /// \name Casting methods
     97     /// @{
     98     static bool classof(const IntrinsicInst *I) {
     99       switch (I->getIntrinsicID()) {
    100       case Intrinsic::dbg_declare:
    101       case Intrinsic::dbg_value:
    102       case Intrinsic::dbg_addr:
    103         return true;
    104       default: return false;
    105       }
    106     }
    107     static bool classof(const Value *V) {
    108       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    109     }
    110     /// @}
    111   };
    112 
    113   /// This represents the llvm.dbg.declare instruction.
    114   class DbgDeclareInst : public DbgInfoIntrinsic {
    115   public:
    116     Value *getAddress() const { return getVariableLocation(); }
    117 
    118     /// \name Casting methods
    119     /// @{
    120     static bool classof(const IntrinsicInst *I) {
    121       return I->getIntrinsicID() == Intrinsic::dbg_declare;
    122     }
    123     static bool classof(const Value *V) {
    124       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    125     }
    126     /// @}
    127   };
    128 
    129   /// This represents the llvm.dbg.addr instruction.
    130   class DbgAddrIntrinsic : public DbgInfoIntrinsic {
    131   public:
    132     Value *getAddress() const { return getVariableLocation(); }
    133 
    134     /// \name Casting methods
    135     /// @{
    136     static bool classof(const IntrinsicInst *I) {
    137       return I->getIntrinsicID() == Intrinsic::dbg_addr;
    138     }
    139     static bool classof(const Value *V) {
    140       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    141     }
    142   };
    143 
    144   /// This represents the llvm.dbg.value instruction.
    145   class DbgValueInst : public DbgInfoIntrinsic {
    146   public:
    147     Value *getValue() const {
    148       return getVariableLocation(/* AllowNullOp = */ false);
    149     }
    150 
    151     /// \name Casting methods
    152     /// @{
    153     static bool classof(const IntrinsicInst *I) {
    154       return I->getIntrinsicID() == Intrinsic::dbg_value;
    155     }
    156     static bool classof(const Value *V) {
    157       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    158     }
    159     /// @}
    160   };
    161 
    162   /// This is the common base class for constrained floating point intrinsics.
    163   class ConstrainedFPIntrinsic : public IntrinsicInst {
    164   public:
    165     enum RoundingMode {
    166       rmInvalid,
    167       rmDynamic,
    168       rmToNearest,
    169       rmDownward,
    170       rmUpward,
    171       rmTowardZero
    172     };
    173 
    174     enum ExceptionBehavior {
    175       ebInvalid,
    176       ebIgnore,
    177       ebMayTrap,
    178       ebStrict
    179     };
    180 
    181     bool isUnaryOp() const;
    182     bool isTernaryOp() const;
    183     RoundingMode getRoundingMode() const;
    184     ExceptionBehavior getExceptionBehavior() const;
    185 
    186     // Methods for support type inquiry through isa, cast, and dyn_cast:
    187     static bool classof(const IntrinsicInst *I) {
    188       switch (I->getIntrinsicID()) {
    189       case Intrinsic::experimental_constrained_fadd:
    190       case Intrinsic::experimental_constrained_fsub:
    191       case Intrinsic::experimental_constrained_fmul:
    192       case Intrinsic::experimental_constrained_fdiv:
    193       case Intrinsic::experimental_constrained_frem:
    194       case Intrinsic::experimental_constrained_fma:
    195       case Intrinsic::experimental_constrained_sqrt:
    196       case Intrinsic::experimental_constrained_pow:
    197       case Intrinsic::experimental_constrained_powi:
    198       case Intrinsic::experimental_constrained_sin:
    199       case Intrinsic::experimental_constrained_cos:
    200       case Intrinsic::experimental_constrained_exp:
    201       case Intrinsic::experimental_constrained_exp2:
    202       case Intrinsic::experimental_constrained_log:
    203       case Intrinsic::experimental_constrained_log10:
    204       case Intrinsic::experimental_constrained_log2:
    205       case Intrinsic::experimental_constrained_rint:
    206       case Intrinsic::experimental_constrained_nearbyint:
    207         return true;
    208       default: return false;
    209       }
    210     }
    211     static bool classof(const Value *V) {
    212       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    213     }
    214   };
    215 
    216   /// This class represents atomic memcpy intrinsic
    217   /// TODO: Integrate this class into MemIntrinsic hierarchy; for now this is
    218   /// C&P of all methods from that hierarchy
    219   class ElementUnorderedAtomicMemCpyInst : public IntrinsicInst {
    220   private:
    221     enum { ARG_DEST = 0, ARG_SOURCE = 1, ARG_LENGTH = 2, ARG_ELEMENTSIZE = 3 };
    222 
    223   public:
    224     Value *getRawDest() const {
    225       return const_cast<Value *>(getArgOperand(ARG_DEST));
    226     }
    227     const Use &getRawDestUse() const { return getArgOperandUse(ARG_DEST); }
    228     Use &getRawDestUse() { return getArgOperandUse(ARG_DEST); }
    229 
    230     /// Return the arguments to the instruction.
    231     Value *getRawSource() const {
    232       return const_cast<Value *>(getArgOperand(ARG_SOURCE));
    233     }
    234     const Use &getRawSourceUse() const { return getArgOperandUse(ARG_SOURCE); }
    235     Use &getRawSourceUse() { return getArgOperandUse(ARG_SOURCE); }
    236 
    237     Value *getLength() const {
    238       return const_cast<Value *>(getArgOperand(ARG_LENGTH));
    239     }
    240     const Use &getLengthUse() const { return getArgOperandUse(ARG_LENGTH); }
    241     Use &getLengthUse() { return getArgOperandUse(ARG_LENGTH); }
    242 
    243     bool isVolatile() const { return false; }
    244 
    245     Value *getRawElementSizeInBytes() const {
    246       return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE));
    247     }
    248 
    249     ConstantInt *getElementSizeInBytesCst() const {
    250       return cast<ConstantInt>(getRawElementSizeInBytes());
    251     }
    252 
    253     uint32_t getElementSizeInBytes() const {
    254       return getElementSizeInBytesCst()->getZExtValue();
    255     }
    256 
    257     /// This is just like getRawDest, but it strips off any cast
    258     /// instructions that feed it, giving the original input.  The returned
    259     /// value is guaranteed to be a pointer.
    260     Value *getDest() const { return getRawDest()->stripPointerCasts(); }
    261 
    262     /// This is just like getRawSource, but it strips off any cast
    263     /// instructions that feed it, giving the original input.  The returned
    264     /// value is guaranteed to be a pointer.
    265     Value *getSource() const { return getRawSource()->stripPointerCasts(); }
    266 
    267     unsigned getDestAddressSpace() const {
    268       return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
    269     }
    270 
    271     unsigned getSourceAddressSpace() const {
    272       return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
    273     }
    274 
    275     /// Set the specified arguments of the instruction.
    276     void setDest(Value *Ptr) {
    277       assert(getRawDest()->getType() == Ptr->getType() &&
    278              "setDest called with pointer of wrong type!");
    279       setArgOperand(ARG_DEST, Ptr);
    280     }
    281 
    282     void setSource(Value *Ptr) {
    283       assert(getRawSource()->getType() == Ptr->getType() &&
    284              "setSource called with pointer of wrong type!");
    285       setArgOperand(ARG_SOURCE, Ptr);
    286     }
    287 
    288     void setLength(Value *L) {
    289       assert(getLength()->getType() == L->getType() &&
    290              "setLength called with value of wrong type!");
    291       setArgOperand(ARG_LENGTH, L);
    292     }
    293 
    294     void setElementSizeInBytes(Constant *V) {
    295       assert(V->getType() == Type::getInt8Ty(getContext()) &&
    296              "setElementSizeInBytes called with value of wrong type!");
    297       setArgOperand(ARG_ELEMENTSIZE, V);
    298     }
    299 
    300     static bool classof(const IntrinsicInst *I) {
    301       return I->getIntrinsicID() == Intrinsic::memcpy_element_unordered_atomic;
    302     }
    303     static bool classof(const Value *V) {
    304       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    305     }
    306   };
    307 
    308   class ElementUnorderedAtomicMemMoveInst : public IntrinsicInst {
    309   private:
    310     enum { ARG_DEST = 0, ARG_SOURCE = 1, ARG_LENGTH = 2, ARG_ELEMENTSIZE = 3 };
    311 
    312   public:
    313     Value *getRawDest() const {
    314       return const_cast<Value *>(getArgOperand(ARG_DEST));
    315     }
    316     const Use &getRawDestUse() const { return getArgOperandUse(ARG_DEST); }
    317     Use &getRawDestUse() { return getArgOperandUse(ARG_DEST); }
    318 
    319     /// Return the arguments to the instruction.
    320     Value *getRawSource() const {
    321       return const_cast<Value *>(getArgOperand(ARG_SOURCE));
    322     }
    323     const Use &getRawSourceUse() const { return getArgOperandUse(ARG_SOURCE); }
    324     Use &getRawSourceUse() { return getArgOperandUse(ARG_SOURCE); }
    325 
    326     Value *getLength() const {
    327       return const_cast<Value *>(getArgOperand(ARG_LENGTH));
    328     }
    329     const Use &getLengthUse() const { return getArgOperandUse(ARG_LENGTH); }
    330     Use &getLengthUse() { return getArgOperandUse(ARG_LENGTH); }
    331 
    332     bool isVolatile() const { return false; }
    333 
    334     Value *getRawElementSizeInBytes() const {
    335       return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE));
    336     }
    337 
    338     ConstantInt *getElementSizeInBytesCst() const {
    339       return cast<ConstantInt>(getRawElementSizeInBytes());
    340     }
    341 
    342     uint32_t getElementSizeInBytes() const {
    343       return getElementSizeInBytesCst()->getZExtValue();
    344     }
    345 
    346     /// This is just like getRawDest, but it strips off any cast
    347     /// instructions that feed it, giving the original input.  The returned
    348     /// value is guaranteed to be a pointer.
    349     Value *getDest() const { return getRawDest()->stripPointerCasts(); }
    350 
    351     /// This is just like getRawSource, but it strips off any cast
    352     /// instructions that feed it, giving the original input.  The returned
    353     /// value is guaranteed to be a pointer.
    354     Value *getSource() const { return getRawSource()->stripPointerCasts(); }
    355 
    356     unsigned getDestAddressSpace() const {
    357       return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
    358     }
    359 
    360     unsigned getSourceAddressSpace() const {
    361       return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
    362     }
    363 
    364     /// Set the specified arguments of the instruction.
    365     void setDest(Value *Ptr) {
    366       assert(getRawDest()->getType() == Ptr->getType() &&
    367              "setDest called with pointer of wrong type!");
    368       setArgOperand(ARG_DEST, Ptr);
    369     }
    370 
    371     void setSource(Value *Ptr) {
    372       assert(getRawSource()->getType() == Ptr->getType() &&
    373              "setSource called with pointer of wrong type!");
    374       setArgOperand(ARG_SOURCE, Ptr);
    375     }
    376 
    377     void setLength(Value *L) {
    378       assert(getLength()->getType() == L->getType() &&
    379              "setLength called with value of wrong type!");
    380       setArgOperand(ARG_LENGTH, L);
    381     }
    382 
    383     void setElementSizeInBytes(Constant *V) {
    384       assert(V->getType() == Type::getInt8Ty(getContext()) &&
    385              "setElementSizeInBytes called with value of wrong type!");
    386       setArgOperand(ARG_ELEMENTSIZE, V);
    387     }
    388 
    389     static inline bool classof(const IntrinsicInst *I) {
    390       return I->getIntrinsicID() == Intrinsic::memmove_element_unordered_atomic;
    391     }
    392     static inline bool classof(const Value *V) {
    393       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    394     }
    395   };
    396 
    397   /// This class represents atomic memset intrinsic
    398   /// TODO: Integrate this class into MemIntrinsic hierarchy; for now this is
    399   /// C&P of all methods from that hierarchy
    400   class ElementUnorderedAtomicMemSetInst : public IntrinsicInst {
    401   private:
    402     enum { ARG_DEST = 0, ARG_VALUE = 1, ARG_LENGTH = 2, ARG_ELEMENTSIZE = 3 };
    403 
    404   public:
    405     Value *getRawDest() const {
    406       return const_cast<Value *>(getArgOperand(ARG_DEST));
    407     }
    408     const Use &getRawDestUse() const { return getArgOperandUse(ARG_DEST); }
    409     Use &getRawDestUse() { return getArgOperandUse(ARG_DEST); }
    410 
    411     Value *getValue() const { return const_cast<Value*>(getArgOperand(ARG_VALUE)); }
    412     const Use &getValueUse() const { return getArgOperandUse(ARG_VALUE); }
    413     Use &getValueUse() { return getArgOperandUse(ARG_VALUE); }
    414 
    415     Value *getLength() const {
    416       return const_cast<Value *>(getArgOperand(ARG_LENGTH));
    417     }
    418     const Use &getLengthUse() const { return getArgOperandUse(ARG_LENGTH); }
    419     Use &getLengthUse() { return getArgOperandUse(ARG_LENGTH); }
    420 
    421     bool isVolatile() const { return false; }
    422 
    423     Value *getRawElementSizeInBytes() const {
    424       return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE));
    425     }
    426 
    427     ConstantInt *getElementSizeInBytesCst() const {
    428       return cast<ConstantInt>(getRawElementSizeInBytes());
    429     }
    430 
    431     uint32_t getElementSizeInBytes() const {
    432       return getElementSizeInBytesCst()->getZExtValue();
    433     }
    434 
    435     /// This is just like getRawDest, but it strips off any cast
    436     /// instructions that feed it, giving the original input.  The returned
    437     /// value is guaranteed to be a pointer.
    438     Value *getDest() const { return getRawDest()->stripPointerCasts(); }
    439 
    440     unsigned getDestAddressSpace() const {
    441       return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
    442     }
    443 
    444     /// Set the specified arguments of the instruction.
    445     void setDest(Value *Ptr) {
    446       assert(getRawDest()->getType() == Ptr->getType() &&
    447              "setDest called with pointer of wrong type!");
    448       setArgOperand(ARG_DEST, Ptr);
    449     }
    450 
    451     void setValue(Value *Val) {
    452       assert(getValue()->getType() == Val->getType() &&
    453              "setValue called with value of wrong type!");
    454       setArgOperand(ARG_VALUE, Val);
    455     }
    456 
    457     void setLength(Value *L) {
    458       assert(getLength()->getType() == L->getType() &&
    459              "setLength called with value of wrong type!");
    460       setArgOperand(ARG_LENGTH, L);
    461     }
    462 
    463     void setElementSizeInBytes(Constant *V) {
    464       assert(V->getType() == Type::getInt8Ty(getContext()) &&
    465              "setElementSizeInBytes called with value of wrong type!");
    466       setArgOperand(ARG_ELEMENTSIZE, V);
    467     }
    468 
    469     static inline bool classof(const IntrinsicInst *I) {
    470       return I->getIntrinsicID() == Intrinsic::memset_element_unordered_atomic;
    471     }
    472     static inline bool classof(const Value *V) {
    473       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    474     }
    475   };
    476 
    477   /// This is the common base class for memset/memcpy/memmove.
    478   class MemIntrinsic : public IntrinsicInst {
    479   public:
    480     Value *getRawDest() const { return const_cast<Value*>(getArgOperand(0)); }
    481     const Use &getRawDestUse() const { return getArgOperandUse(0); }
    482     Use &getRawDestUse() { return getArgOperandUse(0); }
    483 
    484     Value *getLength() const { return const_cast<Value*>(getArgOperand(2)); }
    485     const Use &getLengthUse() const { return getArgOperandUse(2); }
    486     Use &getLengthUse() { return getArgOperandUse(2); }
    487 
    488     ConstantInt *getAlignmentCst() const {
    489       return cast<ConstantInt>(const_cast<Value*>(getArgOperand(3)));
    490     }
    491 
    492     unsigned getAlignment() const {
    493       return getAlignmentCst()->getZExtValue();
    494     }
    495 
    496     ConstantInt *getVolatileCst() const {
    497       return cast<ConstantInt>(const_cast<Value*>(getArgOperand(4)));
    498     }
    499 
    500     bool isVolatile() const {
    501       return !getVolatileCst()->isZero();
    502     }
    503 
    504     unsigned getDestAddressSpace() const {
    505       return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
    506     }
    507 
    508     /// This is just like getRawDest, but it strips off any cast
    509     /// instructions that feed it, giving the original input.  The returned
    510     /// value is guaranteed to be a pointer.
    511     Value *getDest() const { return getRawDest()->stripPointerCasts(); }
    512 
    513     /// Set the specified arguments of the instruction.
    514     void setDest(Value *Ptr) {
    515       assert(getRawDest()->getType() == Ptr->getType() &&
    516              "setDest called with pointer of wrong type!");
    517       setArgOperand(0, Ptr);
    518     }
    519 
    520     void setLength(Value *L) {
    521       assert(getLength()->getType() == L->getType() &&
    522              "setLength called with value of wrong type!");
    523       setArgOperand(2, L);
    524     }
    525 
    526     void setAlignment(Constant* A) {
    527       setArgOperand(3, A);
    528     }
    529 
    530     void setVolatile(Constant* V) {
    531       setArgOperand(4, V);
    532     }
    533 
    534     Type *getAlignmentType() const {
    535       return getArgOperand(3)->getType();
    536     }
    537 
    538     // Methods for support type inquiry through isa, cast, and dyn_cast:
    539     static bool classof(const IntrinsicInst *I) {
    540       switch (I->getIntrinsicID()) {
    541       case Intrinsic::memcpy:
    542       case Intrinsic::memmove:
    543       case Intrinsic::memset:
    544         return true;
    545       default: return false;
    546       }
    547     }
    548     static bool classof(const Value *V) {
    549       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    550     }
    551   };
    552 
    553   /// This class wraps the llvm.memset intrinsic.
    554   class MemSetInst : public MemIntrinsic {
    555   public:
    556     /// Return the arguments to the instruction.
    557     Value *getValue() const { return const_cast<Value*>(getArgOperand(1)); }
    558     const Use &getValueUse() const { return getArgOperandUse(1); }
    559     Use &getValueUse() { return getArgOperandUse(1); }
    560 
    561     void setValue(Value *Val) {
    562       assert(getValue()->getType() == Val->getType() &&
    563              "setValue called with value of wrong type!");
    564       setArgOperand(1, Val);
    565     }
    566 
    567     // Methods for support type inquiry through isa, cast, and dyn_cast:
    568     static bool classof(const IntrinsicInst *I) {
    569       return I->getIntrinsicID() == Intrinsic::memset;
    570     }
    571     static bool classof(const Value *V) {
    572       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    573     }
    574   };
    575 
    576   /// This class wraps the llvm.memcpy/memmove intrinsics.
    577   class MemTransferInst : public MemIntrinsic {
    578   public:
    579     /// Return the arguments to the instruction.
    580     Value *getRawSource() const { return const_cast<Value*>(getArgOperand(1)); }
    581     const Use &getRawSourceUse() const { return getArgOperandUse(1); }
    582     Use &getRawSourceUse() { return getArgOperandUse(1); }
    583 
    584     /// This is just like getRawSource, but it strips off any cast
    585     /// instructions that feed it, giving the original input.  The returned
    586     /// value is guaranteed to be a pointer.
    587     Value *getSource() const { return getRawSource()->stripPointerCasts(); }
    588 
    589     unsigned getSourceAddressSpace() const {
    590       return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
    591     }
    592 
    593     void setSource(Value *Ptr) {
    594       assert(getRawSource()->getType() == Ptr->getType() &&
    595              "setSource called with pointer of wrong type!");
    596       setArgOperand(1, Ptr);
    597     }
    598 
    599     // Methods for support type inquiry through isa, cast, and dyn_cast:
    600     static bool classof(const IntrinsicInst *I) {
    601       return I->getIntrinsicID() == Intrinsic::memcpy ||
    602              I->getIntrinsicID() == Intrinsic::memmove;
    603     }
    604     static bool classof(const Value *V) {
    605       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    606     }
    607   };
    608 
    609   /// This class wraps the llvm.memcpy intrinsic.
    610   class MemCpyInst : public MemTransferInst {
    611   public:
    612     // Methods for support type inquiry through isa, cast, and dyn_cast:
    613     static bool classof(const IntrinsicInst *I) {
    614       return I->getIntrinsicID() == Intrinsic::memcpy;
    615     }
    616     static bool classof(const Value *V) {
    617       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    618     }
    619   };
    620 
    621   /// This class wraps the llvm.memmove intrinsic.
    622   class MemMoveInst : public MemTransferInst {
    623   public:
    624     // Methods for support type inquiry through isa, cast, and dyn_cast:
    625     static bool classof(const IntrinsicInst *I) {
    626       return I->getIntrinsicID() == Intrinsic::memmove;
    627     }
    628     static bool classof(const Value *V) {
    629       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    630     }
    631   };
    632 
    633   /// This represents the llvm.va_start intrinsic.
    634   class VAStartInst : public IntrinsicInst {
    635   public:
    636     static bool classof(const IntrinsicInst *I) {
    637       return I->getIntrinsicID() == Intrinsic::vastart;
    638     }
    639     static bool classof(const Value *V) {
    640       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    641     }
    642 
    643     Value *getArgList() const { return const_cast<Value*>(getArgOperand(0)); }
    644   };
    645 
    646   /// This represents the llvm.va_end intrinsic.
    647   class VAEndInst : public IntrinsicInst {
    648   public:
    649     static bool classof(const IntrinsicInst *I) {
    650       return I->getIntrinsicID() == Intrinsic::vaend;
    651     }
    652     static bool classof(const Value *V) {
    653       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    654     }
    655 
    656     Value *getArgList() const { return const_cast<Value*>(getArgOperand(0)); }
    657   };
    658 
    659   /// This represents the llvm.va_copy intrinsic.
    660   class VACopyInst : public IntrinsicInst {
    661   public:
    662     static bool classof(const IntrinsicInst *I) {
    663       return I->getIntrinsicID() == Intrinsic::vacopy;
    664     }
    665     static bool classof(const Value *V) {
    666       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    667     }
    668 
    669     Value *getDest() const { return const_cast<Value*>(getArgOperand(0)); }
    670     Value *getSrc() const { return const_cast<Value*>(getArgOperand(1)); }
    671   };
    672 
    673   /// This represents the llvm.instrprof_increment intrinsic.
    674   class InstrProfIncrementInst : public IntrinsicInst {
    675   public:
    676     static bool classof(const IntrinsicInst *I) {
    677       return I->getIntrinsicID() == Intrinsic::instrprof_increment;
    678     }
    679     static bool classof(const Value *V) {
    680       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    681     }
    682 
    683     GlobalVariable *getName() const {
    684       return cast<GlobalVariable>(
    685           const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
    686     }
    687 
    688     ConstantInt *getHash() const {
    689       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
    690     }
    691 
    692     ConstantInt *getNumCounters() const {
    693       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
    694     }
    695 
    696     ConstantInt *getIndex() const {
    697       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
    698     }
    699 
    700     Value *getStep() const;
    701   };
    702 
    703   class InstrProfIncrementInstStep : public InstrProfIncrementInst {
    704   public:
    705     static bool classof(const IntrinsicInst *I) {
    706       return I->getIntrinsicID() == Intrinsic::instrprof_increment_step;
    707     }
    708     static bool classof(const Value *V) {
    709       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    710     }
    711   };
    712 
    713   /// This represents the llvm.instrprof_value_profile intrinsic.
    714   class InstrProfValueProfileInst : public IntrinsicInst {
    715   public:
    716     static bool classof(const IntrinsicInst *I) {
    717       return I->getIntrinsicID() == Intrinsic::instrprof_value_profile;
    718     }
    719     static bool classof(const Value *V) {
    720       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
    721     }
    722 
    723     GlobalVariable *getName() const {
    724       return cast<GlobalVariable>(
    725           const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
    726     }
    727 
    728     ConstantInt *getHash() const {
    729       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
    730     }
    731 
    732     Value *getTargetValue() const {
    733       return cast<Value>(const_cast<Value *>(getArgOperand(2)));
    734     }
    735 
    736     ConstantInt *getValueKind() const {
    737       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
    738     }
    739 
    740     // Returns the value site index.
    741     ConstantInt *getIndex() const {
    742       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(4)));
    743     }
    744   };
    745 
    746 } // end namespace llvm
    747 
    748 #endif // LLVM_IR_INTRINSICINST_H
    749