[LLVMdev] [PATCH] Support asm comment output

David Greene dag at cray.com
Mon Jul 13 11:29:58 PDT 2009

On Monday 13 July 2009 13:13, Chris Lattner wrote:

> > We're not going to submit our line number stuff anyway (it's too
> > much of a
> > hack) but we would like the comment infrastructure to be there.
> DebugLoc is there.  The transition isn't complete at the LLVM IR
> level, but it is at the MachineInstr level AFAIK.

Well, the IR level is pretty important to us since we convert our
code into LLVM IR and add source line comments at the same time.

> Vector vs scalar should also be pretty simple, just look at the reg
> class and the VT's involved.  It should all be target independent,
> probably less than a dozen lines.  After the conversion to
> formatted_raw_ostream, we can discuss the best way to do this.  It
> would be helpful if you gave an example of the output you wanted.

Ok, this might work.

> I don't know what you mean by "pattern information".  We can obviously
> enhance tblgen to include any information that we need, but I don't
> see how the asmprinter wouldn't know something that an earlier pass
> would.  Again, it would be helpful if you included example output to
> show what you're going for.

Ok, here's an example:

        movl    (%rsi), %ecx                                # LLVM 
Instruction:         volatile store i32* %ksize, i32** %ksize3       ; 
[oox.4 : sln.5]

                                                            # [result] Pattern 

I then hacked tblgen to output this in the generated isel file:

    // Pattern 1367: (ld:i32 addr:iPTR:$src)<<P:Predicate_load>>
    // Emits: (MOV32rm:i32 addr:iPTR:$src)
    PatternID = 1367;
    // Pattern complexity = 19  cost = 1  size = 3
    SDValue CPTmp01;
    SDValue CPTmp11;
    SDValue CPTmp21;
    SDValue CPTmp31;
    if (SelectAddr(N, N1, CPTmp01, CPTmp11, CPTmp21, CPTmp31)) {
      CurDAG->setSubgraphColor(N.getNode(), "red");
      SDNode *Result = Emit_125(N, X86::MOV32rm, MVT::i32, CPTmp01, CPTmp11, 
CPTmp21, CPTmp31, PatternID);
      if(Result) {
        CurDAG->setSubgraphColor(Result, "yellow");
        CurDAG->setSubgraphColor(Result, "black");
      return Result;

So it's really easy to set a breakpoint in Emit_125 to look for the pattern 
number in question.

I forgot about the LLVM instruction information.  That's something that can't 
be synthesized by the asmprinter.  Again, we only emit some of this with 
special debug flags so we don't carry the original IR around in comments all
the time.  :)

> > What's the plan for meta-information?  Could comments go there when
> > it's
> > ready?  Would it be ok to add these for now and remove them as other
> > mechanisms (DebugLoc, meta-information) come on-line?
> Which meta-information, MDNode and friends?  

I don't know, I've just heard the term from time to time.  Sounds like it's
not appropriate for this, though.


More information about the llvm-dev mailing list