[llvm-dev] Get the Metadata User of a Value

Jeremy Morse via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 2 01:48:57 PST 2020


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


More information about the llvm-dev mailing list