[llvm-dev] How to pass custom metadata from IR module pass to backend MF pass?

Son Tuan VU via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 9 03:58:25 PST 2020


Hi Christopher,

We just started a discussion about introducing the metadata mechanism to
the MIR, just as the IR does, i.e. attaching metadata to a MachineInstr:
http://lists.llvm.org/pipermail/llvm-dev/2020-July/143639.html and
http://lists.llvm.org/pipermail/llvm-dev/2020-September/144886.html
However, there is currently a special metadata that survives DAG lowering:
debug info.
In the IR, llvm.dbg.value intrinsics maps an SSA value to the metadata
describing a given source-level variable.
In the MIR, DBG_VALUE pseudo-instructions map a register to the metadata
describing a given source-level variable.
In fact, there is a 1:1 mapping between llvm.dbg.value and DBG_VALUE, and
the same variable metadata is used for a given pair of (llvm.dbg.value,
DBG_VALUE). This metadata is kept aside in SelectionDAG, and is inserted in
the DBG_VALUE during instruction emitting phase.
Maybe you can mimic this process for lowering your metadata?

HTH,

Son Tuan Vu


On Thu, Nov 5, 2020 at 7:57 PM K Jelesnianski via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Dear All,
>
> I am performing some analysis on a traditional IR Module Pass in LLVM,
> with that analysis I want to tag the places I will need to extract
> file offsets from as custom symbols.
>
> Ideally I would want to attach some metadata to a IR instruction, and
> have it be accessible when I perform a backend MF pass.
>
> Essentially I want to pass the information I collected and generated
> in the IR pass, to the backend machineFunction pass and ASMPrinter
> that will be able to write out custom symbols with my metadata.
>
> The problem I'm running into is two-fold:
> 1) IR Instructions are being expanded to multiple x86 assembly,
> machine instructions. (No surprise about that, but if I tag at the
> BasicBlock level, the tag will be in the wrong place)
> 2) I do not know know how to tag an IR instruction with metadata, so
> that that metadata survives the DAG lowering to x86 machine
> instructions. Has anyone done this before?
>
> Options I have in my head is to write out my metadata into a output
> text file (gathered from the IR pass) and have the MF pass read that
> output text file in again to do the tagging I need. (Another issue
> here is how to code opt to take in a text file as pass data and NOT a
> file to be compiled/opted)
>
> Thanks!
>
> Sincerely,
>
> Christopher Jelesnianski
> Virginia Tech Research Assistant
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201109/88930794/attachment.html>


More information about the llvm-dev mailing list