[llvm-dev] Adding comments in Assembly

Jonas Paulsson via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 16 04:05:32 PST 2015

Hi Kumail,

It's the AsmPrinter that by itself checks if the block is in a loop. See
lib/CodeGen/AsmPrinter/AsmPrinter.cpp - emitBasicBlockLoopComments().

I think comments are useful, and find this to be a missing feature. I have experience
with adding asm comment strings based on a map from MachineInstr* to std::string. This
worked quite well, but was not ideal. Mattias - do you have any comment?

An alternative might be to have a global asm-comment string map and make each MI that
carries a comment have an index for the comment. This would be better than using the
address while cloning / expanding instructions, I think.

I am not sure about metadata, as it is not guaranteed to be preserved.

Feel free to give it a try if you want to implement this Kumail! Otherwise, unfortunately
the answer is today that it can't be done, unless you are happy with hacking into
the AsmPrinter on your end.


>Which file should I edit, if i want to add comments to an assembly instruction.
>For example,
>   mov r1, 0    #r1 is variable a
>Should I add it as a metadata? Secondly, how are comments inserted at
>the beginning of loops?
>Best Regards,

More information about the llvm-dev mailing list