#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));
}
};
struct DbgInfoIntrinsic : public IntrinsicInst {
static inline bool classof(const DbgInfoIntrinsic *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
switch (I->getIntrinsicID()) {
case Intrinsic::dbg_stoppoint:
case Intrinsic::dbg_func_start:
case Intrinsic::dbg_region_start:
case Intrinsic::dbg_region_end:
case Intrinsic::dbg_declare:
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);
};
struct DbgStopPointInst : public DbgInfoIntrinsic {
Value *getLineValue() const { return const_cast<Value*>(getOperand(1)); }
Value *getColumnValue() const { return const_cast<Value*>(getOperand(2)); }
Value *getContext() const {
return StripCast(getOperand(3));
}
unsigned getLine() const {
return unsigned(cast<ConstantInt>(getOperand(1))->getZExtValue());
}
unsigned getColumn() const {
return unsigned(cast<ConstantInt>(getOperand(2))->getZExtValue());
}
Value* getFileName() const;
Value* getDirectory() const;
static inline bool classof(const DbgStopPointInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::dbg_stoppoint;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
struct DbgFuncStartInst : public DbgInfoIntrinsic {
Value *getSubprogram() const { return StripCast(getOperand(1)); }
static inline bool classof(const DbgFuncStartInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::dbg_func_start;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
struct DbgRegionStartInst : public DbgInfoIntrinsic {
Value *getContext() const { return StripCast(getOperand(1)); }
static inline bool classof(const DbgRegionStartInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::dbg_region_start;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
struct DbgRegionEndInst : public DbgInfoIntrinsic {
Value *getContext() const { return StripCast(getOperand(1)); }
static inline bool classof(const DbgRegionEndInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::dbg_region_end;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
struct DbgDeclareInst : public DbgInfoIntrinsic {
Value *getAddress() const { return getOperand(1); }
Value *getVariable() const { return StripCast(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));
}
};
struct MemIntrinsic : public IntrinsicInst {
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();
}
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(unsigned A) {
const Type *Int32Ty = getOperand(4)->getType();
setOperand(4, ConstantInt::get(Int32Ty, A));
}
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:
case Intrinsic::memcpyany:
return true;
default: return false;
}
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
struct MemSetInst : public MemIntrinsic {
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));
}
};
struct MemTransferInst : public MemIntrinsic {
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::memcpyany ||
I->getIntrinsicID() == Intrinsic::memmove;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
struct MemCpyInst : public MemTransferInst {
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));
}
};
struct MemMoveInst : public MemTransferInst {
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));
}
};
struct EHSelectorInst : public IntrinsicInst {
static inline bool classof(const EHSelectorInst *) { return true; }
static inline bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::eh_selector_i32 ||
I->getIntrinsicID() == Intrinsic::eh_selector_i64;
}
static inline bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};
}
#endif