如何判断一个llvm:Type是否是i8*类型?
How to determine if a llvm:Type is of type i8*?
如何判断一个llvm:Type是否是i8*
类型?我遍历函数 F
的参数并想确定参数是否属于 i8*
.
类型
for(auto& arg : F.getArgumentList()) {
arg.getType()->???
}
您可以使用 llvm::isa 或使用高级转换,例如 llvm::cast。
否则,你可以只制作普通的旧 C++:[未测试]
void Test(llvm::Function* f) {
for (auto& arg : f->getArgumentList()) {
llvm::Type* t = arg.getType();
if (t->isPointerTy()) {
llvm::Type* inner = t->getPointerElementType();
if (inner->isIntegerTy()) {
llvm::IntegerType* it = (llvm::IntegerType*) inner;
if (it->getBitWidth() == 8) {
// i8* --> do something
}
// another int pointer (int32* for example)
}
// another pointer type
}
// not pointer type
}
}
一种紧凑的方法是执行 llvm::dyn_cast
:
... // using namespace llvm
if (PointerType *PT = dyn_cast<PointerType>(arg.getType()))
if (IntegerType *IT = dyn_cast<IntegerType>(PT->getPointerElementType()))
if (IT->getBitWidth() == 8)
// do stuff
...
。请注意,未识别结构的类型在 LLVM IR 中在结构上是唯一的。如果你有 LLVMContext
的句柄,你可以将参数类型的指针与 built-in 8 位 int 指针进行比较:
... //using namespace llvm
if (PointerType *PT = dyn_cast<PointerType>(arg.getType()))
if (PT == Type::getInt8PtrTy(ctx, PT->getPointerAddressSpace()))
// do stuff
...
.
如何判断一个llvm:Type是否是i8*
类型?我遍历函数 F
的参数并想确定参数是否属于 i8*
.
for(auto& arg : F.getArgumentList()) {
arg.getType()->???
}
您可以使用 llvm::isa 或使用高级转换,例如 llvm::cast。
否则,你可以只制作普通的旧 C++:[未测试]
void Test(llvm::Function* f) {
for (auto& arg : f->getArgumentList()) {
llvm::Type* t = arg.getType();
if (t->isPointerTy()) {
llvm::Type* inner = t->getPointerElementType();
if (inner->isIntegerTy()) {
llvm::IntegerType* it = (llvm::IntegerType*) inner;
if (it->getBitWidth() == 8) {
// i8* --> do something
}
// another int pointer (int32* for example)
}
// another pointer type
}
// not pointer type
}
}
一种紧凑的方法是执行 llvm::dyn_cast
:
... // using namespace llvm
if (PointerType *PT = dyn_cast<PointerType>(arg.getType()))
if (IntegerType *IT = dyn_cast<IntegerType>(PT->getPointerElementType()))
if (IT->getBitWidth() == 8)
// do stuff
...
。请注意,未识别结构的类型在 LLVM IR 中在结构上是唯一的。如果你有 LLVMContext
的句柄,你可以将参数类型的指针与 built-in 8 位 int 指针进行比较:
... //using namespace llvm
if (PointerType *PT = dyn_cast<PointerType>(arg.getType()))
if (PT == Type::getInt8PtrTy(ctx, PT->getPointerAddressSpace()))
// do stuff
...
.