llvmllvm-3.0

Is there a struct type isomorphism check in LLVM 3.0?


In LLVM-3.0, named structs are always unique and pointer equality with other structurally same structs does not work. From their blog entry on LLVM-3.0 types, the highlights are mine:

Identified structures are the kind we are talking about: they can have a name, and can have their body specified after the type is created. The identified structure is not uniqued with other structure types, which is why they are produced with StructType::create(...). Because identified types are potentially recursive, the asmprinter always prints them by their name (or a number like %42 if the identified struct has no name).

This breaks type equality checking by type pointer checking. For example, the haskell package llvm depends on llvm type pointers being equal for compile time type checks and type casts.

Is there any way to check for two structs being isomorphic(same structure)? Preferably in the llvm-c api?


Solution

  • In the C++ API, the StructType class has

    bool StructType::isLayoutIdentical(StructType *Other) const
    

    This function iterates through the elements of the StructTypes to see if they're equal.