Oak
Oak

Reputation: 26878

Find all the uses of a metadata node

I have an MDNode* (found using DebugInfoFinder). I want to find out all the other MDNodes in the module that use it, but its use list appears to be empty. How do I find that?

For example, I have something like:

...
!5 = metadata !{i32 100}
...
!8 = metadata !{i32 101, metadata !5}
...

If I have metadata !{i32 100}, how do I get a reference to metadata !{i32 101, metadata !5}?

Upvotes: 0

Views: 159

Answers (1)

Eli Bendersky
Eli Bendersky

Reputation: 273686

Since the "use" of !5 is !8, another MDNode, this is intentional.

A MDNode is not considered to be a "user"; note that while Instruction is-a User, MDNode is not. Metadata cannot affect code generation, by design. Had MDNode been a "user" of values, dead values whose only use is in metadata could not be killed, which goes against the design.

Pragmatically, this means that to perform interesting analyses on metadata you will need to construct this usage graph on your own from the module. If this sounds expensive, worry not because DebugInfoFinder already kind-of does this. So you can replace it with your own analysis (same cost) that collects more useful information.

Upvotes: 1

Related Questions