简体   繁体   English

比较 LLVM 值的类型

[英]Compare Types of LLVM values

I'm trying to compare a llvm Type and a Type* .我正在尝试比较 llvm Type 和 Type* I'm using the LLVM C APIs.我正在使用 LLVM C API。 Is there any possible method to do this?有没有可能的方法来做到这一点?

I have Type* because I did LLVMTypeOf api to get the type from an LLVM Value.我有Type*因为我做了 LLVMTypeOf api 从 LLVM 值中获取类型。 So if I can get the Type from a Value , it would also fix the issue.因此,如果我可以从 Value 中获取 Type ,它也可以解决问题。

Types are unique in LLVM world, so you could compare their addresses.类型在 LLVM 世界中是独一无二的,因此您可以比较它们的地址。

To make it clear, and extend prior answers with a proper llvm-c code example, you just compare two LLVMTypeRef like you would compare any two pointers to check if they are equal.为了清楚起见,并使用适当的llvm-c代码示例扩展先前的答案,您只需比较两个LLVMTypeRef ,就像比较任何两个指针以检查它们是否相等。

LLVMTypeRef type1 = whatever1();  // e.g. LLVMTypeOf(...)
LLVMTypeRef type2 = whatever2();  // e.g. LLVMDoubleType()
if (type1 == type2)
{
    // the two types are equal
}

You can directly compare LLVM types of two values.您可以直接比较两个值的 LLVM 类型。 eg see:例如见:

llvm/lib/Analysis/BasicAliasAnalysis.cpp:967 llvm/lib/Analysis/BasicAliasAnalysis.cpp:967

          GEP1->getPointerOperandType() == GEP2->getPointerOperandType() &&

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM