【发布时间】:2020-05-27 18:49:07
【问题描述】:
我正在尝试优化 llvm ir 中的代码,意识到 Types - isPointerTy 不区分 *i8、*i16、*i32、*i64。打印出它们的类型值显然会给出不同的值。下面是我用来检测问题的代码。
在 C 中:
...
if (CallInst *CI = dyn_cast<CallInst>(UsrI)) {
if (CI->getCalledFunction()->getReturnType() ->isPointerTy()){
outs() << "Calling func with ptr return = " << CI->getCalledFunction()->getName() << "\n";
outs() << CI->getCalledFunction()->getReturnType() << "\n";
}
}
...
在 llvm 中:
...
if.end:
%test3 = call i64* @malloc64(i64 %mul)
%call = call i32* @malloc32(i64 %mul) #4
%test = call i16* @malloc16(i64 %mul)
%test2 = call i8* @malloc8(i64 %mul)
...
declare i8* @malloc8(i64)
declare i16* @malloc16(i64)
declare i16* @malloc16(i64)
declare i16* @malloc16(i64)
显示输出为
使用 ptr return = malloc8 调用 func
0x1c56e90
使用 ptr return = malloc16 调用 func
0x1c56e20
使用 ptr return = malloc32 调用 func
0x1c56db0
使用 ptr return = malloc64 调用 func
0x1c56d40
我尝试检查了许多 llvm 文档,但我错过了一些东西。任何关于我如何检查确切指针类型的建议都将不胜感激。
【问题讨论】:
标签: llvm