[LLVMdev] [LLVM 3.6.0] Metadata/Value split and RAUW.

Duncan P. N. Exon Smith dexonsmith at apple.com
Tue Jun 2 14:17:54 PDT 2015


> On 2015-May-21, at 00:18, Lizunov, Andrey E <andrey.e.lizunov at intel.com> wrote:
> 
> 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}

    use:

        !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
    pointee.
 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).



More information about the llvm-dev mailing list