Pekka Nikander
2010-Sep-29 19:13 UTC
[LLVMdev] Associating types directly with debug metadata?
>> 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
Pekka Nikander
2010-Sep-30 08:30 UTC
[LLVMdev] Associating types directly with debug metadata?
>>> 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...I thought about that more, and I think the "right" way would be to have a syntax like !21 = metadata !{ type %struct.T, metadata !11 } or perhaps !21 = metadata !{ typeval %struct.T, metadata !11 } to avoid the problem with the keyword 'type'. But to be able to do that, should apparently be possible to represent types as first class values. That in turn would apparently require a new Type::TypeID? Would that be worth doing? Apparently we can fake with our need, and use a null pointer instead. Technically, that would be wrong, but would work with the current code without any modifications: !21 = metadata !{ %struct.T *null, metadata !11 } Any opinions? (I guess I'll just try the number of changes needed for a 'typeval' and report back.) --Pekka
Devang Patel
2010-Sep-30 17:13 UTC
[LLVMdev] Associating types directly with debug metadata?
On Sep 30, 2010, at 1:30 AM, Pekka Nikander wrote:>>>> 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... > > I thought about that more, and I think the "right" way would be to have a syntax like > > !21 = metadata !{ type %struct.T, metadata !11 } > > or perhaps > > !21 = metadata !{ typeval %struct.T, metadata !11 } > > to avoid the problem with the keyword 'type'. > > But to be able to do that, should apparently be possible to represent types as first class values. That in turn would apparently require a new Type::TypeID? > > Would that be worth doing? Apparently we can fake with our need, and use a null pointer instead. Technically, that would be wrong, but would work with the current code without any modifications: > > !21 = metadata !{ %struct.T *null, metadata !11 }I would recommend this approach. - Devang> > Any opinions? (I guess I'll just try the number of changes needed for a 'typeval' and report back.) > > --Pekka >
Devang Patel
2010-Sep-30 17:15 UTC
[LLVMdev] Associating types directly with debug metadata?
On Sep 29, 2010, at 12:13 PM, Pekka Nikander wrote:>>> 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?There are not any strict conventions. We generally use llvm.dbg.<blah> for debug info needs. "llvm." prefix should be reserved for uses that are actually in mainline llvm sources. - Devang
Apparently Analagous Threads
- [LLVMdev] Associating types directly with debug metadata?
- [LLVMdev] Associating types directly with debug metadata?
- [LLVMdev] Associating types directly with debug metadata?
- [LLVMdev] Associating types directly with debug metadata?
- [LLVMdev] Associating types directly with debug metadata?