1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===-- llvm/IntrinsicInst.h - Intrinsic Instruction Wrappers ---*- C++ -*-===// 2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The LLVM Compiler Infrastructure 4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source 6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details. 7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file defines classes that make it really easy to deal with intrinsic 11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// functions with the isa/dyncast family of functions. In particular, this 12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// allows you to do things like: 13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// if (MemCpyInst *MCI = dyn_cast<MemCpyInst>(Inst)) 15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// ... MCI->getDest() ... MCI->getSource() ... 16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// All intrinsic function calls are instances of the call instruction, so these 18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// are all subclasses of the CallInst class. Note that none of these classes 19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// has state or virtual methods, which is an important part of this gross/neat 20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// hack working. 21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LLVM_INTRINSICINST_H 25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LLVM_INTRINSICINST_H 26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Constants.h" 28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Function.h" 29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Instructions.h" 30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Intrinsics.h" 31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm { 33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic 34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// functions. This allows the standard isa/dyncast/cast functionality to 35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// work with calls to intrinsic functions. 36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class IntrinsicInst : public CallInst { 37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman IntrinsicInst(); // DO NOT IMPLEMENT 38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman IntrinsicInst(const IntrinsicInst&); // DO NOT IMPLEMENT 39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void operator=(const IntrinsicInst&); // DO NOT IMPLEMENT 40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman public: 41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getIntrinsicID - Return the intrinsic ID of this intrinsic. 42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Intrinsic::ID getIntrinsicID() const { 44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return (Intrinsic::ID)getCalledFunction()->getIntrinsicID(); 45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Methods for support type inquiry through isa, cast, and dyn_cast: 48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const IntrinsicInst *) { return true; } 49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const CallInst *I) { 50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman if (const Function *CF = I->getCalledFunction()) 51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return CF->getIntrinsicID() != 0; 52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return false; 53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const Value *V) { 55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return isa<CallInst>(V) && classof(cast<CallInst>(V)); 56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 5819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 5919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics 6019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// 6119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman class DbgInfoIntrinsic : public IntrinsicInst { 6219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman public: 6319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 6419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman // Methods for support type inquiry through isa, cast, and dyn_cast: 6519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const DbgInfoIntrinsic *) { return true; } 6619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const IntrinsicInst *I) { 6719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman switch (I->getIntrinsicID()) { 6819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman case Intrinsic::dbg_declare: 6919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman case Intrinsic::dbg_value: 7019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return true; 7119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman default: return false; 7219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 7319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 7419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const Value *V) { 7519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 7619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 7719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 7819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static Value *StripCast(Value *C); 7919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman }; 8019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 8119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// DbgDeclareInst - This represents the llvm.dbg.declare instruction. 8219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// 8319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman class DbgDeclareInst : public DbgInfoIntrinsic { 8419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman public: 8519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Value *getAddress() const; 8619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman MDNode *getVariable() const { return cast<MDNode>(getArgOperand(1)); } 8719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 8819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman // Methods for support type inquiry through isa, cast, and dyn_cast: 8919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const DbgDeclareInst *) { return true; } 9019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const IntrinsicInst *I) { 9119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return I->getIntrinsicID() == Intrinsic::dbg_declare; 9219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 9319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const Value *V) { 9419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 9519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 9619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman }; 9719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 9819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// DbgValueInst - This represents the llvm.dbg.value instruction. 9919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// 10019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman class DbgValueInst : public DbgInfoIntrinsic { 10119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman public: 10219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman const Value *getValue() const; 10319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Value *getValue(); 10419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman uint64_t getOffset() const { 10519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return cast<ConstantInt>( 10619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman const_cast<Value*>(getArgOperand(1)))->getZExtValue(); 10719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 10819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman MDNode *getVariable() const { return cast<MDNode>(getArgOperand(2)); } 10919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 11019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman // Methods for support type inquiry through isa, cast, and dyn_cast: 11119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const DbgValueInst *) { return true; } 11219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const IntrinsicInst *I) { 11319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return I->getIntrinsicID() == Intrinsic::dbg_value; 11419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 11519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const Value *V) { 11619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 11719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 11819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman }; 119894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// MemIntrinsic - This is the common base class for memset/memcpy/memmove. 121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class MemIntrinsic : public IntrinsicInst { 123894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman public: 124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *getRawDest() const { return const_cast<Value*>(getArgOperand(0)); } 125894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *getLength() const { return const_cast<Value*>(getArgOperand(2)); } 127894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman ConstantInt *getAlignmentCst() const { 128894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return cast<ConstantInt>(const_cast<Value*>(getArgOperand(3))); 129894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 130894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 131894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman unsigned getAlignment() const { 132894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return getAlignmentCst()->getZExtValue(); 133894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 134894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman ConstantInt *getVolatileCst() const { 136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return cast<ConstantInt>(const_cast<Value*>(getArgOperand(4))); 137894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 138894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool isVolatile() const { 139894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return !getVolatileCst()->isZero(); 140894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 141894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 14219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman unsigned getDestAddressSpace() const { 14319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return cast<PointerType>(getRawDest()->getType())->getAddressSpace(); 14419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 14519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getDest - This is just like getRawDest, but it strips off any cast 147894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// instructions that feed it, giving the original input. The returned 148894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// value is guaranteed to be a pointer. 149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *getDest() const { return getRawDest()->stripPointerCasts(); } 150894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 151894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// set* - Set the specified arguments of the instruction. 152894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 153894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setDest(Value *Ptr) { 154894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(getRawDest()->getType() == Ptr->getType() && 155894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman "setDest called with pointer of wrong type!"); 156894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman setArgOperand(0, Ptr); 157894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 158894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 159894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setLength(Value *L) { 160894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(getLength()->getType() == L->getType() && 161894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman "setLength called with value of wrong type!"); 162894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman setArgOperand(2, L); 163894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 164894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 165894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setAlignment(Constant* A) { 166894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman setArgOperand(3, A); 167894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 168894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 169894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setVolatile(Constant* V) { 170894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman setArgOperand(4, V); 171894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 172894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 17319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Type *getAlignmentType() const { 174894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return getArgOperand(3)->getType(); 175894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 176894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 177894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Methods for support type inquiry through isa, cast, and dyn_cast: 178894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const MemIntrinsic *) { return true; } 179894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const IntrinsicInst *I) { 180894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman switch (I->getIntrinsicID()) { 181894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman case Intrinsic::memcpy: 182894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman case Intrinsic::memmove: 183894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman case Intrinsic::memset: 184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return true; 185894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman default: return false; 186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 187894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const Value *V) { 189894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 190894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 191894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 192894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 193894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// MemSetInst - This class wraps the llvm.memset intrinsic. 194894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 195894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class MemSetInst : public MemIntrinsic { 196894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman public: 197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// get* - Return the arguments to the instruction. 198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 199894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *getValue() const { return const_cast<Value*>(getArgOperand(1)); } 200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 201894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setValue(Value *Val) { 202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(getValue()->getType() == Val->getType() && 203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman "setValue called with value of wrong type!"); 204894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman setArgOperand(1, Val); 205894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 206894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 207894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Methods for support type inquiry through isa, cast, and dyn_cast: 208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const MemSetInst *) { return true; } 209894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const IntrinsicInst *I) { 210894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return I->getIntrinsicID() == Intrinsic::memset; 211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 212894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const Value *V) { 213894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 217894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// MemTransferInst - This class wraps the llvm.memcpy/memmove intrinsics. 218894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 219894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class MemTransferInst : public MemIntrinsic { 220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman public: 221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// get* - Return the arguments to the instruction. 222894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 223894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *getRawSource() const { return const_cast<Value*>(getArgOperand(1)); } 224894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 225894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getSource - This is just like getRawSource, but it strips off any cast 226894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// instructions that feed it, giving the original input. The returned 227894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// value is guaranteed to be a pointer. 228894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *getSource() const { return getRawSource()->stripPointerCasts(); } 229894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 23019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman unsigned getSourceAddressSpace() const { 23119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return cast<PointerType>(getRawSource()->getType())->getAddressSpace(); 23219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 23319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 234894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setSource(Value *Ptr) { 235894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(getRawSource()->getType() == Ptr->getType() && 236894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman "setSource called with pointer of wrong type!"); 237894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman setArgOperand(1, Ptr); 238894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 239894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 240894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Methods for support type inquiry through isa, cast, and dyn_cast: 241894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const MemTransferInst *) { return true; } 242894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const IntrinsicInst *I) { 243894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return I->getIntrinsicID() == Intrinsic::memcpy || 244894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman I->getIntrinsicID() == Intrinsic::memmove; 245894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 246894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const Value *V) { 247894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 248894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 249894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 250894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 251894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 252894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// MemCpyInst - This class wraps the llvm.memcpy intrinsic. 253894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 254894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class MemCpyInst : public MemTransferInst { 255894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman public: 256894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Methods for support type inquiry through isa, cast, and dyn_cast: 257894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const MemCpyInst *) { return true; } 258894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const IntrinsicInst *I) { 259894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return I->getIntrinsicID() == Intrinsic::memcpy; 260894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 261894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const Value *V) { 262894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 263894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 264894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 265894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 266894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// MemMoveInst - This class wraps the llvm.memmove intrinsic. 267894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 268894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class MemMoveInst : public MemTransferInst { 269894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman public: 270894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Methods for support type inquiry through isa, cast, and dyn_cast: 271894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const MemMoveInst *) { return true; } 272894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const IntrinsicInst *I) { 273894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return I->getIntrinsicID() == Intrinsic::memmove; 274894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 275894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const Value *V) { 276894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 277894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 278894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 279894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 28019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// EHExceptionInst - This represents the llvm.eh.exception instruction. 281894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 28219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman class EHExceptionInst : public IntrinsicInst { 283894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman public: 28419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman // Methods for support type inquiry through isa, cast, and dyn_cast: 28519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const EHExceptionInst *) { return true; } 28619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const IntrinsicInst *I) { 28719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return I->getIntrinsicID() == Intrinsic::eh_exception; 28819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 28919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const Value *V) { 29019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 29119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 29219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman }; 293894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 29419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// EHSelectorInst - This represents the llvm.eh.selector instruction. 29519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// 29619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman class EHSelectorInst : public IntrinsicInst { 29719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman public: 298894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Methods for support type inquiry through isa, cast, and dyn_cast: 29919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static inline bool classof(const EHSelectorInst *) { return true; } 300894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const IntrinsicInst *I) { 30119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return I->getIntrinsicID() == Intrinsic::eh_selector; 302894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 303894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static inline bool classof(const Value *V) { 304894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); 305894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 306894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 307894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 308894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} 309894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 310894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif 311