<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Malhar,<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 27 Dec 2017, at 00:56, Malhar Thakkar via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hello everyone,<div class=""><br class=""></div><div class="">In the file <b class="">lib/CodeGen/AsmPrinter/AsmPrinter.cpp</b>, I would like to obtain an MCInst corresponding to its MachineInstr. Can anyone tell me a way to do that?</div></div></div></blockquote><div><br class=""></div>Usually, it happens in lib/Target/X86/X86MCInstLower.cpp, the X86MCInstLower class is used by the X86AsmPrinter (subclass of the AsmPrinter).</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">If that is not possible, then, I would like to know if a given MachineInstr is an <b class="">lea </b>instruction and I would like to know if the symbol involved with this lea instruction is a jump-table.</div></div></div></blockquote><div><br class=""></div><div>You can identify if a MachineInstr is a lea instruction by using something similar to the function isLEA from lib/Target/X86/X86OptimizeLEAs.cpp.</div><div>You can also identify if any of the operands of a MachineInstruction is a jump-table reference by iterating over all the MachineOperands and checking if it’s a jump-table index using the function isJTI.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">For instance, given a MachineInstr, I would like to know if it is of the following form.</div><div class=""><br class=""></div><div class=""><b class=""><font face="monospace, monospace" class="">leaq<span style="white-space:pre" class="">   </span>LJTI0_0(%rip), %rax</font></b></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><b class=""><font face="monospace, monospace" class=""><br class=""></font></b></div><div class=""><font face="arial, helvetica, sans-serif" class="">Also, say, I want to add custom labels (some string) while generating assembly right before emitting such <b class="">lea </b>instructions, how do I do that given that OutStreamer->EmitLabel() takes MCSymbol as an argument and not a string/StringRef?</font></div></div></div></blockquote><div><br class=""></div><div>You will need to create an MCSymbol from a string. The class MCContext is able to create symbols and manage them, so you should be able to create a symbol and pass it to EmitLabel using getOrCreateSymbol or any of the functions in include/llvm/MC/MCContext.h.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><font face="arial, helvetica, sans-serif" class=""><b class=""><br class=""></b></font></div><div class=""><font face="arial, helvetica, sans-serif" class=""><b class="">My goal: </b>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).</font></div></div></div></blockquote></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, helvetica, sans-serif" class="">I have a workaround for all the problems stated above but I want to write a cleaner solution.</font></div><div class=""><ul class=""><li class=""><font face="arial, helvetica, sans-serif" class="">For finding an <b class="">lea </b>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.</font></li></ul></div></div></div></blockquote><div>How are you planning to consume that DenseMap? If you only want to dump it you can probably keep track of everything in X86AsmPrinter::EmitInstruction (lib/Target/X86/X86MCInstLower.cpp).</div><div><br class=""></div><div>I recommend doing everything in the target-specific code as you are only interested in x86 specifics.</div><div><br class=""></div><div>Cheers,</div><div><br class=""></div><div>— </div><div>Francis Visoiu Mistrih</div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><ul class=""><li class=""><font face="arial, helvetica, sans-serif" class="">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).</font></li></ul><div class=""><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div></div><div class=""><font face="arial, helvetica, sans-serif" class="">Is there a way to do both of the aforementioned bullet points inside AsmPrinter.cpp without having to call a function in MCAsmStreamer?</font></div><div class=""><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, helvetica, sans-serif" class="">Thank you.</font></div><div class=""><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, helvetica, sans-serif" class="">Regards,</font></div><div class=""><font face="arial, helvetica, sans-serif" class="">Malhar</font></div><div class=""><br class=""></div></div><div hspace="streak-pt-mark" style="max-height:1px" class=""><img alt="" style="width:0px;max-height:0px;overflow:hidden" src="https://mailfoogae.appspot.com/t?sender=aY3MxM2IxMDMxQGlpdGguYWMuaW4%3D&type=zerocontent&guid=e025264d-3788-4211-925d-5c4578212119" class=""><font color="#ffffff" size="1" class="">ᐧ</font></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>