[llvm-dev] Preserving the type of structure

Kaylor, Andrew via llvm-dev llvm-dev at lists.llvm.org
Mon Mar 2 13:06:14 PST 2020


What you’ll observe depends on the front end you’re using. If you’re using clang, you may need to get in very early to see the TBAA metadata. Like all metadata, it can be dropped whenever the IR is transformed.

For example: https://godbolt.org/z/zCJaT4

In this case, the front end itself transforms the structure to a single i32 for the purposes of argument passing. This may vary, depending on the target ABI, but for x86-64 on Linux this is the way small structures are passed by value. The function body still shows the TBAA information when the IR is generated by clang, but SROA will optimize that away very early in the pipeline. Disabling SROA is a bad idea for anything other than experimentation, but if you did that some other optimization might do the same thing.

In general, LLVM IR operates on values (which have semantically significant type information) and memory locations (which do not). Although LLVM IR has a type system that represents composite data types such as structs, there is no guarantee that these have any correspondence to the source language data types. If you need source type information, that needs to be generated by the front end in some way (such as TBAA), but the front end uses metadata to represent this information it may not be preserved. Any method that is guaranteed to be preserved would most likely block some optimizations.

I’ve run into this problem in a couple of different contexts, so I’d be curious to hear more about why you want this information if you are able to share.

Thanks,
Andy

P.S. If you look at the IR above, you can probably figure out the TBAA metadata. It’s described here: http://llvm.org/docs/LangRef.html#tbaa-metadata

From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of sangeeta chowdhary via llvm-dev
Sent: Monday, March 02, 2020 9:55 AM
To: David Blaikie <dblaikie at gmail.com>
Cc: LLVM Developers Mailing List <llvm-dev at lists.llvm.org>
Subject: Re: [llvm-dev] Preserving the type of structure

Hi David,

Thanks for the response. I was wondering if you have any concrete steps to get this information from TBAA data?
If you can point me towards some source or example then it would be really helpful.

Regards,
Sangeeta

On Sat, Feb 29, 2020 at 5:30 PM David Blaikie <dblaikie at gmail.com<mailto:dblaikie at gmail.com>> wrote:
No - if you really want this sort of information you'd likely find it in the debug info https://llvm.org/docs/SourceLevelDebugging.html or maybe TBAA data.

On Fri, Feb 28, 2020 at 7:30 PM sangeeta chowdhary via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote:
Hello,

LLVM IR flattens out the structure with one integer element to i32. Is there any way to disable this? I want to preserve the type information of the structure. I tried compiling the program with O0, it maintains the type for most of the instructions but for all.

Regards,
Sangeeta
_______________________________________________
LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200302/7819bb56/attachment.html>


More information about the llvm-dev mailing list