Destructor
Destructor

Reputation: 523

Compare Types of LLVM values

I'm trying to compare a llvm Type and a Type*. I'm using the LLVM C APIs. Is there any possible method to do this?

I have Type* because I did LLVMTypeOf api to get the type from an LLVM Value. So if I can get the Type from a Value, it would also fix the issue.

Upvotes: 4

Views: 2913

Answers (3)

Frederic
Frederic

Reputation: 1820

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.

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

Upvotes: 2

A. K.
A. K.

Reputation: 38264

You can directly compare LLVM types of two values. e.g. see:

llvm/lib/Analysis/BasicAliasAnalysis.cpp:967

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

Upvotes: 0

Anton Korobeynikov
Anton Korobeynikov

Reputation: 9324

Types are unique in LLVM world, so you could compare their addresses.

Upvotes: 4

Related Questions