[LLVMdev] [PATCH] Support asm comment output

Chris Lattner clattner at apple.com
Sun Jul 12 16:56:17 PDT 2009

On Jul 10, 2009, at 3:05 PM, David Greene wrote:

> Here's the first of several patches to get comments into asm  
> output.  This one
> adds comment information to MachineInstructions and outputs it in the
> generated AsmPrinters.  This includes TableGen work to trigger the  
> comment
> output in the right places.

A couple of things are important to discuss:

+    dynamic_cast<formatted_raw_ostream &>(O) << Comment(*c);

We're trying to eliminate rtti, please don't add new uses of it.   
Switching all of the asmprinter to statically use  
formatted_raw_ostream would be appropriate.

+++ include/llvm/CodeGen/MachineInstr.h	(working copy)
@@ -46,6 +46,9 @@
    MachineBasicBlock *Parent;            // Pointer to the owning  
basic block.
    DebugLoc debugLoc;                    // Source line information.

+  typedef std::vector<std::string> CommentList;
+  CommentList Comments;                 // asm file comments

This is a very heavy-weight representation, growing each MachineInstr  
by 3 words.  Once .o file writing comes on-line, the performance of  
the .s file writer will matter much less, but this growth will still  
affect it.

Before we settle on whether this is the right thing to do or not, can  
you talk about what comments you plan to add to these instructions?   
Comments indicating what a memoperand are (for example) don't need to  
be explicitly store in the machineinstr, they can be synthesized from  
the MachineOperand directly.

Minor stuff:

+  /// commentsBegin - Get an iterator to the start of the comment list
+  ///
+  const_comment_iterator commentsBegin(void) const {
+    return(Comments.begin());
+  }

no need for the (void), no need for the redundant parens, please  
punctuate comments properly.


More information about the llvm-dev mailing list