将Value *转换为llvm中的PointerType时出错
问题描述:
我尝试在LLVM IR中加载/存储指令并跟踪其存储器地址,因此我需要插入检测函数来记录加载/存储指令的地址。将Value *转换为llvm中的PointerType时出错
我有一个类型转换问题,当我尝试创建recordLoad /存储功能:
首先,我创建的指针型,“VoidPtrType”
Type Int64Type = IntegerType::getInt64Ty(M.getContext());
Type* VoidPtrType = PointerType::getUnqual(Int64Type);
然后,我创建论据仪表功能:
// ldstInst is a load/store instruction
Value* Args[] = {
ConstantInt::get(Int64Type, uint64_t(lsIDpass->getlsID(inst))),
ConstantInt::get(VoidPtrType, uint64_t(ldstInst->getPointerOperand())),
ConstantInt::get(Int64Type, uint64_t(DL->getTypeStoreSize(VTy)))
};
但是,当我运行我的程序时,我无法通过“ConstantIn T ::得到(VoidPtrType,uint64_t中(ldstInst-> getPointerOperand()))”,提供如下错误信息:
Assertion failed: isa<X>(Val) && "cast<Ty>() argument of incompatible type!"
任何人都可以向我提供任何提示?
感谢, 亨利
答
的问题是,VoidPtrType
是不是IntegerType
(相反,它是PointerType
)。我相信你需要使用inttoptr
强制转换来创建一个常量指针。
虽然,我不确定你的设计。你真的想在编译的程序中使用指向只在编译时存在的LLVM操作数吗?
谢谢。我的设计用于在运行时跟踪内存访问加载/存储指令。因此,我需要将一些自定义函数插入到llvm ir中来记录地址。它就像一个自定义的llvm-gprof。 – henry 2014-10-27 10:10:37