Adding comments in Assembly

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.

/Jonas

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?

We have the setup which Jonas describes in the target that I am working on. It works most of the time but has some problems.

If we add a comment on an MI and then a later optimization/expansion replaces this instruction, the comment will be lost.

Also, such "lost" comments can show up on other instructions which just happen to get the same value of the pointer (MachineInstr *).

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.

I think metadata is probably be a good idea. It feels like a good fit, but I do not have any experience with using it for this purpose.