[LLVMdev] Associating types directly with debug metadata?

Pekka Nikander pekka.nikander at nomadiclab.com
Wed Sep 29 12:13:25 PDT 2010


>> We would need to access the LLVM debug metadata type information directly from LLVM types.  It looks like the current clang and llvm-gcc don't support such an association, nor appears the LLVM itself do.
> 
> True. I am curious how do you want to use this association ? 

Thanks for you advice below, Devang.

We are using LLVM type definitions + debug metadata to interpret binary data, read from memory, and dump it out as LLVM IR constants.  A similar kind of thing to what GNU Emacs does when it dumps its memory image when bootstrapping, or what some OSes do to speed up their boot times on a known hardware configuration.  However, our approach is different in that we want to have an LLVM IR dump, not a binary dump as emacs and the OSes do.

In our case, the data structures we are dumping are ones that are configured when the original program is initialised, and then not changed afterwards; we are essentially producing frozen configurations.  Then we optimize the performance critical part of the original program with a frozen configuration (instead of using a dynamically assembled configuration).  The results from our prototyping so far are pretty good; in some cases we are able to repeatedly perform loop peeling and constant propagation so that the original loop disappears altogether.  (We didn't get constant propagation to go through the PHIs our loops initially have.  Peeling the loop helped.)

Using @llvm.invariant.start doesn't give as good results, since from our dump we know the exact value of the data fields, in addition to that they don't change.  Hence, that allows us to optimise the code much more aggressively.

And yes, (to Chris in the other e-mail), we are aware that the IR type names are "meaningless".  That's the main reason why we want to use the debug metadata, under the assumption that it would have better coherence with the source code.  

>> Then the type would probably need to be added to a new named metadata tag as well, maybe !llvm.dbg.ty?
> 
> This is a preferred way to do. BTW, I used llvm.dbg.ty name so it is a good idea to pick up some name that also conveys your use of this association.

Would !llvm.dbg.types be appropriate?  Are there naming conventions here?

>> Would the right starting point be to simply add an MDNode pointer to the Type class?  That should be then convertible to a DIType?  
> 
> We want to avoid any Type class modification. Instead you can use pair in named metadata to match metadata with type.
> 
> !11 = metadata !{i32 524307, metadata !1, metadata !"T", metadata !1, i32 2, i64 32, i64 32, i64 0, i32 0, null, metadata !12, i32 0, null} ; [ DW_TAG_structure_type ]
> 
> !21 = metadata !{ metadata !11,  %struct.T %z}
> 
> !llvm.my_special_type_info = !{!21}

Ok, that approach should work.  Though we want to associate the type, not some variable with the type, i.e. something like

!21 = metadata !{ %struct.T, metadata !11 }

But I don't know if that would be valid syntax...  

> Yes. BTW, Dan Gohman is working on TBAA. He is also working on necessary support to associate Type with a metadata.

Thanks for the hint.  Our goal seems to be orthogonal, though, I think.

--Pekka





More information about the llvm-dev mailing list