[llvm-commits] [llvm] r130409 - /llvm/trunk/lib/VMCore/AsmWriter.cpp

Chris Lattner clattner at apple.com
Sat May 21 11:31:37 PDT 2011


On Apr 28, 2011, at 10:41 AM, Devang Patel wrote:

> Author: dpatel
> Date: Thu Apr 28 12:41:38 2011
> New Revision: 130409
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=130409&view=rev
> Log:
> Add command line option to print debug info in human readable form as comment in llvm IR output. This, i.e -enable-debug-info-comment,  is very useful if you want to easily find out which optimization pass is losing line number information.

Hi Devang, why don't you implement this as an AssemblyAnnotationWriter?  That's the entire point of having that API. :)

-Chris

> 
> Modified:
>    llvm/trunk/lib/VMCore/AsmWriter.cpp
> 
> Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=130409&r1=130408&r2=130409&view=diff
> ==============================================================================
> --- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
> +++ llvm/trunk/lib/VMCore/AsmWriter.cpp Thu Apr 28 12:41:38 2011
> @@ -32,6 +32,7 @@
> #include "llvm/ADT/StringExtras.h"
> #include "llvm/ADT/STLExtras.h"
> #include "llvm/Support/CFG.h"
> +#include "llvm/Support/CommandLine.h"
> #include "llvm/Support/Debug.h"
> #include "llvm/Support/Dwarf.h"
> #include "llvm/Support/ErrorHandling.h"
> @@ -41,6 +42,11 @@
> #include <cctype>
> using namespace llvm;
> 
> +static cl::opt<bool>
> +EnableDebugInfoComment("enable-debug-info-comment", cl::Hidden,
> +                       cl::desc("Enable debug info comments"));
> +
> +
> // Make virtual table appear in this compilation unit.
> AssemblyAnnotationWriter::~AssemblyAnnotationWriter() {}
> 
> @@ -1729,6 +1735,18 @@
>   if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
> }
> 
> +/// printDebugLoc - Print DebugLoc.
> +static void printDebugLoc(const DebugLoc &DL, formatted_raw_ostream &OS) {
> +  OS << DL.getLine() << ":" << DL.getCol();
> +  if (MDNode *N = DL.getInlinedAt(getGlobalContext())) {
> +    DebugLoc IDL = DebugLoc::getFromDILocation(N);
> +    if (!IDL.isUnknown()) {
> +      OS << "@";
> +      printDebugLoc(IDL,OS);
> +    }
> +  }
> +}
> +
> /// printInfoComment - Print a little comment after the instruction indicating
> /// which slot it occupies.
> ///
> @@ -1736,6 +1754,43 @@
>   if (AnnotationWriter) {
>     AnnotationWriter->printInfoComment(V, Out);
>     return;
> +  } else if (EnableDebugInfoComment) {
> +    bool Padded = false;
> +    if (const Instruction *I = dyn_cast<Instruction>(&V)) {
> +      const DebugLoc &DL = I->getDebugLoc();
> +      if (!DL.isUnknown()) {
> +        if (!Padded) {
> +          Out.PadToColumn(50);
> +          Padded = true;
> +          Out << ";";
> +        }
> +        Out << " [debug line = ";
> +        printDebugLoc(DL,Out);
> +        Out << "]";
> +      }
> +      if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(I)) {
> +        const MDNode *Var = DDI->getVariable();
> +        if (!Padded) {
> +          Out.PadToColumn(50);
> +          Padded = true;
> +          Out << ";";
> +        }
> +        if (Var && Var->getNumOperands() >= 2)
> +          if (MDString *MDS = dyn_cast_or_null<MDString>(Var->getOperand(2)))
> +            Out << " [debug variable = " << MDS->getString() << "]";
> +      }
> +      else if (const DbgValueInst *DVI = dyn_cast<DbgValueInst>(I)) {
> +        const MDNode *Var = DVI->getVariable();
> +        if (!Padded) {
> +          Out.PadToColumn(50);
> +          Padded = true;
> +          Out << ";";
> +        }
> +        if (Var && Var->getNumOperands() >= 2)
> +          if (MDString *MDS = dyn_cast_or_null<MDString>(Var->getOperand(2)))
> +            Out << " [debug variable = " << MDS->getString() << "]";
> +      }
> +    }
>   }
> }
> 
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list