#ifndef LLVM_INTRINSICINST_H
#define LLVM_INTRINSICINST_H
#include "llvm/Constants.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/Intrinsics.h"
namespace llvm {
class IntrinsicInst : public CallInst {
IntrinsicInst(); IntrinsicInst(const IntrinsicInst&); void operator=(const IntrinsicInst&); public:
Intrinsic::ID getIntrinsicID() const {
return (Intrinsic::ID)getCalledFunction()->getIntrinsicID();
}
static inline bool classof(const IntrinsicInst *) { return true; }
static inline bool classof(const CallInst *I) {
if (const Function *CF = I->getCalledFunction())
return CF->getIntrinsicID() != 0;
return false;
}
static inline bool classof(const Value *V) {
return isa<CallInst>(V) && classof(cast<CallInst>(V));
}
};
class DbgInfoIntrinsic : public IntrinsicInst {
public:
static inline bool classof(const DbgInfoIntrinsic *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::dbg_declare:
case Intrinsic::dbg_value:
return true;
default: return false;
}
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
static Value *StripCast(Value *C);
};
class DbgDeclareInst : public DbgInfoIntrinsic {
public:
Value *getAddress() const;
MDNode *getVariable() const { return cast<MDNode>(getOperand(2)); }
static inline bool classof(const DbgDeclareInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::dbg_declare;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class DbgValueInst : public DbgInfoIntrinsic {
public:
const Value *getValue() const;
Value *getValue();
uint64_t getOffset() const {
return cast<ConstantInt>(
const_cast<Value*>(getOperand(2)))->getZExtValue();
}
const MDNode *getVariable() const { return cast<MDNode>(getOperand(3)); }
MDNode *getVariable() { return cast<MDNode>(getOperand(3)); }
static inline bool classof(const DbgValueInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::dbg_value;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemIntrinsic : public IntrinsicInst {
public:
Value *getRawDest() const { return const_cast<Value*>(getOperand(1)); }
Value *getLength() const { return const_cast<Value*>(getOperand(3)); }
ConstantInt *getAlignmentCst() const {
return cast<ConstantInt>(const_cast<Value*>(getOperand(4)));
}
unsigned getAlignment() const {
return getAlignmentCst()->getZExtValue();
}
ConstantInt *getVolatileCst() const {
return cast<ConstantInt>(const_cast<Value*>(getOperand(5)));
}
bool isVolatile() const {
return getVolatileCst()->getZExtValue() != 0;
}
Value *getDest() const { return getRawDest()->stripPointerCasts(); }
void setDest(Value *Ptr) {
assert(getRawDest()->getType() == Ptr->getType() &&
"setDest called with pointer of wrong type!");
setOperand(1, Ptr);
}
void setLength(Value *L) {
assert(getLength()->getType() == L->getType() &&
"setLength called with value of wrong type!");
setOperand(3, L);
}
void setAlignment(Constant* A) {
setOperand(4, A);
}
void setVolatile(Constant* V) {
setOperand(5, V);
}
const Type *getAlignmentType() const {
return getOperand(4)->getType();
}
static inline bool classof(const MemIntrinsic *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::memcpy:
case Intrinsic::memmove:
case Intrinsic::memset:
return true;
default: return false;
}
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemSetInst : public MemIntrinsic {
public:
Value *getValue() const { return const_cast<Value*>(getOperand(2)); }
void setValue(Value *Val) {
assert(getValue()->getType() == Val->getType() &&
"setSource called with pointer of wrong type!");
setOperand(2, Val);
}
static inline bool classof(const MemSetInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memset;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemTransferInst : public MemIntrinsic {
public:
Value *getRawSource() const { return const_cast<Value*>(getOperand(2)); }
Value *getSource() const { return getRawSource()->stripPointerCasts(); }
void setSource(Value *Ptr) {
assert(getRawSource()->getType() == Ptr->getType() &&
"setSource called with pointer of wrong type!");
setOperand(2, Ptr);
}
static inline bool classof(const MemTransferInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memcpy ||
I->getIntrinsicID() == Intrinsic::memmove;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemCpyInst : public MemTransferInst {
public:
static inline bool classof(const MemCpyInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memcpy;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemMoveInst : public MemTransferInst {
public:
static inline bool classof(const MemMoveInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::memmove;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class EHSelectorInst : public IntrinsicInst {
public:
static inline bool classof(const EHSelectorInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::eh_selector;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
class MemoryUseIntrinsic : public IntrinsicInst {
public:
static inline bool classof(const MemoryUseIntrinsic *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::lifetime_start:
case Intrinsic::lifetime_end:
case Intrinsic::invariant_start:
case Intrinsic::invariant_end:
return true;
default: return false;
}
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
}
#endif