José Wesley Magalhães via llvm-dev
2020-Oct-29 14:41 UTC
[llvm-dev] Get the Metadata User of a Value
Dear LLVM devs, I'm working on a project in which I need to associate some Values with LLVM Debug Info. LLVM provides methods to easily iterate over both def-use and use-def chains of a Value, but I'm having a problem when some of these Users is a debug intrisic. I have the following situation 92 %call.i = tail call noalias dereferenceable_or_null(16) i8* @malloc(i64 16) #3, !dbg !90 93 %2 = bitcast i8* %call.i to %struct.Node*, !dbg !86 94 call void @llvm.dbg.value(metadata %struct.Node* %2, metadata !24, metadata !DIExpression()) #3, !dbg !89 If I iterate over the users of the value %2 (line 92), I cannot get the debug instruction at line 94. Knowing that the value is used by metadata, (method isUsedByMetadata returns true), is it possible to get the debug intrinsic that uses value %2? Or this does not configure a Use of %2? Any help would be appreciated. Best regards, José Wesley de Souza Magalhães MSc Student in Computer Science Federal University of Minas Gerais - Brazil -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201029/ad15efa4/attachment.html>
Jeremy Morse via llvm-dev
2020-Nov-02 09:48 UTC
[llvm-dev] Get the Metadata User of a Value
Hi José, On Thu, Oct 29, 2020 at 2:41 PM José Wesley Magalhães via llvm-dev <llvm-dev at lists.llvm.org> wrote:> If I iterate over the users of the value %2 (line 92), I cannot get the > debug instruction at line 94. Knowing that the value is used by metadata, > (method isUsedByMetadata returns true), is it possible to get the debug intrinsic > that uses value %2? Or this does not configure a Use of %2?There's a helper function "findDbgValues" in llvm/lib/Transforms/Utils/Local.cpp which should do exactly what you want, producing a collection of dbg.value intrinsics for a given Value. If you need to do something more complicated: as that function shows the extra step you're missing is calling MetadataAsValue::getIfExists. As far as I understand it, by design there's no mapping back from one metadata node to its users: debug info metadata hangs everything off a unique MetadataAsValue and tries to look it up directly. Value users of MetadataAsValue can then be looked up in the usual way. -- Thanks, Jeremy
José Wesley Magalhães via llvm-dev
2020-Nov-03 14:52 UTC
[llvm-dev] Get the Metadata User of a Value
Hi Jeremy,>There's a helper function "findDbgValues" in >llvm/lib/Transforms/Utils/Local.cpp which should do exactly what you >want, producing a collection of dbg.value intrinsics for a given >Value.Thanks a lot! This function does exactly what I need. Best regards, José Wesley de Souza Magalhães Mestrando em Ciência da Computação Belo Horizonte/MG - Brasil Em seg., 2 de nov. de 2020 às 06:49, Jeremy Morse < jeremy.morse.llvm at gmail.com> escreveu:> Hi José, > > On Thu, Oct 29, 2020 at 2:41 PM José Wesley Magalhães via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > > If I iterate over the users of the value %2 (line 92), I cannot get the > > debug instruction at line 94. Knowing that the value is used by metadata, > > (method isUsedByMetadata returns true), is it possible to get the debug > intrinsic > > that uses value %2? Or this does not configure a Use of %2? > > There's a helper function "findDbgValues" in > llvm/lib/Transforms/Utils/Local.cpp which should do exactly what you > want, producing a collection of dbg.value intrinsics for a given > Value. > > If you need to do something more complicated: as that function shows > the extra step you're missing is calling MetadataAsValue::getIfExists. > As far as I understand it, by design there's no mapping back from one > metadata node to its users: debug info metadata hangs everything off a > unique MetadataAsValue and tries to look it up directly. Value users > of MetadataAsValue can then be looked up in the usual way. > > -- > Thanks, > Jeremy >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201103/663bc291/attachment.html>