有没有办法在llvm ir中区分指针类型?

有没有办法在llvm ir中区分指针类型?,llvm,Llvm,我试图在llvm ir中优化代码,意识到类型-isPointerTy并不区分*i8、*i16、*i32、*i64。打印出它们的类型值显然会给出不同的值。下面是我用来检测问题的代码 在C中: 将输出显示为 使用ptr return调用func=malloc8 0x1c56e90 使用ptr return调用func=malloc16 0x1c56e20 使用ptr return调用func=malloc32 0x1c56db0 使用ptr return调用func=malloc64 0x1c56d

我试图在llvm ir中优化代码,意识到类型-isPointerTy并不区分*i8、*i16、*i32、*i64。打印出它们的类型值显然会给出不同的值。下面是我用来检测问题的代码

在C中:

将输出显示为

使用ptr return调用func=malloc8
0x1c56e90
使用ptr return调用func=malloc16
0x1c56e20
使用ptr return调用func=malloc32
0x1c56db0
使用ptr return调用func=malloc64
0x1c56d40


我试着检查了许多llvm文档,但遗漏了一些内容。任何关于如何检查准确指针类型的建议都将不胜感激

isPointerTy方法不区分不同的类型,它只告诉
true
false
类型是否是指针

解决问题的一种方法是查看它的底层指针对象类型(指针指向的类型)

这就是你可以做到的:

Type *returnType = CI->getCalledFunction()->getReturnType();
if (PointerType *pointerType = dyn_cast<PointerType>(returnType)) {
  llvm::Type *pointeeType = pointerType->getElementType();
  /// the pointee type now holds one of i8, i16, i32, or i64
  if (IntegerType *intType = dyn_cast<IntegerType>(pointeeType)) {
    outs() << intType->getBitWidth() << "\n";
  }
}
Type*returnType=CI->getCalledFunction()->getReturnType();
if(PointerType*PointerType=dyn_cast(returnType)){
llvm::Type*pointeeType=pointerType->getElementType();
///指针对象类型现在保存i8、i16、i32或i64中的一种
if(IntegerType*intType=dyn_cast(pointeeType)){
outs()getBitWidth()
...
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)
Type *returnType = CI->getCalledFunction()->getReturnType();
if (PointerType *pointerType = dyn_cast<PointerType>(returnType)) {
  llvm::Type *pointeeType = pointerType->getElementType();
  /// the pointee type now holds one of i8, i16, i32, or i64
  if (IntegerType *intType = dyn_cast<IntegerType>(pointeeType)) {
    outs() << intType->getBitWidth() << "\n";
  }
}