Dear all,<div><br></div><div>I am looking to output assembly comments in my emitPrologue() function, just for my own readability. Searching for a way to do this found me this thread - <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/043722.html">http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/043722.html</a>, which says that the best way to output comments from somewhere like emitPrologue() is to:</div>
<div><ol><li>Create an MDString for the comment.</li><li>Attach it to an LLVM instruction using setMetadata().</li><li>Add a new member to MachineInstr to hold the metadata, and attach it when converting LLVM instructions.</li>
<li>Update AsmPrinter to read off the metadata and output it as an assembly comment.</li></ol><div>Is this the only (and correct) way to do this?</div></div><div><br></div><div><br></div><div><br></div><div><br></div><div>
If so, I am having trouble attaching the MDString to an instruction. I am using BuildMI to create my instruction, which only seems to have an "addMetadata()" function rather than "setMetadata()", and which takes an MDNode instead of an MDString. I attempted to do this as follows:</div>
<div><br></div><div>void XXXFrameLowering::emitPrologue(MachineFunction &MF) const {</div><div>...</div><div><div>  Value* end_prologue_comment = MDString::get(getGlobalContext(), "end of prologue");</div></div>
<div><div>  BuildMI(MBB, MBBI, dl, TII.get(Target::AnInstr), Target::R1).addMetadata(cast<MDNode>(end_prologue_comment));</div></div><div>}</div><div><br></div><div>However, it seems an MDString cannot be case to an MDNode this way. How do I go about turning that MDString into an MDNode, and once done how do I add the new member to MachineInstr and attach the metadata to it?</div>
<div><br></div><div>Thanks,</div><div>Stephen</div>