[llvm] [llvm-c] Provide LLVMGetGEPResultElementType (PR #95693)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 16 09:16:02 PDT 2024


nikic wrote:

> > Why do you need this? Use of getResultElementType() is something of a red flag, and I do not want to expose it to the C API unless there is a strong need.
> 
> Is there any other way to get a GEP's result element type using the C API? Since the instruction's type itself is just an opaque pointer type, I couldn't find any other way to get this.
> 
> I'm trying to build my own internal representation of LLVM-IR, so I'd need this for a complete translation.

The result element type is redundant information implied by the source element type and the GEP arguments. GEPs currently explicitly store it, but this is largely for historical reasons -- prior to opaque pointers, it was commonly used. Nowadays we could probably remove it. I think the only half-way legitimate use-case for it is to check type compatibility when merging two GEPs into one.

Your internal IR representation shouldn't care about the result element type, only the source element type.

https://github.com/llvm/llvm-project/pull/95693


More information about the llvm-commits mailing list