How to pass custom metadata from IR module pass to backend MF pass?

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)



Christopher Jelesnianski
Virginia Tech Research Assistant

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: and
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?