[LLVM 3.6.0] Metadata/Value split and RAUW.

Hello everyone,

If I understand correctly after the Metadata/Value split the Metadata support of RAUW is limited by ValueAsMetadata and MDNodeFwdDecl (i.e. until cycled in MDNode are not resovled).

And my question is. Is where any way to replace an MDNode which is referenced by other MDNodes w\o iterating over all MDNodes in LLMVContext to find and replace those references? Unfortunately I couldn’t find such example in LLVM source code…

There are three ways I can think of.

1. During graph construction, create a temporary MDNode instead of
    a normal one. In 3.6, that's a `MDNodeFwdDecl`; in trunk, that's
    just a temporary. Before the end of graph construction, you need
    to RAUW it with the final node (in trunk, there's a function
    called MDNode::replaceWithPermanent()) that probably does what you
    need). This is the approach the debug info schema uses.
2. Change the schema to add a layer of indirection in the spots where
    you need to change the pointee. In particular, instead of

        !0 = !{!"interesting data"}
        !2 = !{!"points at !0", !0}


        !0 = !{!"interesting data"}
        !1 = !{!0}
        !2 = !{!"points at !0", !1}

    If everyone reference !0 does so indirectly, via !1, then you can
    call `!1->replaceOperandWith(0, NewNode)` to change the effective
3. Use the `ValueMapper` infrastructure to remap the metadata in the
    module to point at the new node instead of the old one (this is
    spiritually similar to your suggested approach).

Duncan, thank you for your answer!

These are interesting alternatives. Unfortunately only the third one is suitable to me since it needs to alternate the graph after the construction and its topology is fixed. IMHO RAUW was a good feature for the metadata from that point of view.

Andrey Lizunov