[llvm-dev] Convert MachineInstr to MCInst in AsmPrinter.cpp

Malhar Thakkar via llvm-dev llvm-dev at lists.llvm.org
Tue Dec 26 16:56:11 PST 2017


Hello everyone,

In the file *lib/CodeGen/AsmPrinter/AsmPrinter.cpp*, I would like to obtain
an MCInst corresponding to its MachineInstr. Can anyone tell me a way to do
that?

If that is not possible, then, I would like to know if a given MachineInstr
is an *lea *instruction and I would like to know if the symbol involved
with this lea instruction is a jump-table.
For instance, given a MachineInstr, I would like to know if it is of the
following form.

*leaq LJTI0_0(%rip), %rax*

Also, say, I want to add custom labels (some string) while generating
assembly right before emitting such *lea *instructions, how do I do that
given that OutStreamer->EmitLabel() takes MCSymbol as an argument and not a
string/StringRef?

*My goal: *To find lea instructions corresponding to jump-tables and emit a
custom label before such instructions and also maintain a count of how many
such lea instructions are there for each jump-table (using a DenseMap).

I have a workaround for all the problems stated above but I want to write a
cleaner solution.

   - For finding an *lea *instruction and emitting a label before actually
   emitting it, I have modified the EmitInstruction() function in
   MCAsmStreamer.cpp wherein I keep track of how many lea instructions are
   there for each jump-table using a DenseMap.
   - As I require the number of lea instructions per jump-table in
   AsmPrinter.cpp, I have created a function in MCAsmStreamer.cpp which
   returns the DenseMap (added a declaration of this function in MCStreamer.h).


Is there a way to do both of the aforementioned bullet points inside
AsmPrinter.cpp without having to call a function in MCAsmStreamer?

Thank you.

Regards,
Malhar

ᐧ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171226/0a58c0f5/attachment.html>


More information about the llvm-dev mailing list