[PATCH] Add new debug kind LocTrackingOnly.

Diego Novillo dnovillo at google.com
Fri Jun 20 11:48:44 PDT 2014


Hi echristo, dblaikie,

This new debug emission kind supports emitting line location
information in all instructions, but stops code generation
from emitting debug info to the final output.

This mode is useful when the backend wants to track source
locations during code generation, but it does not want to
produce debug info. This is currently used by optimization
remarks (-pass-remarks, -pass-remarks-missed and
-pass-remarks-analysis).

To prevent debug info emission, DIBuilder never inserts the
annotation 'llvm.dbg.cu' when LocTrackingOnly is enabled.

http://reviews.llvm.org/D4234

Files:
  include/llvm/IR/DIBuilder.h
  lib/IR/DIBuilder.cpp

Index: include/llvm/IR/DIBuilder.h
===================================================================
--- include/llvm/IR/DIBuilder.h
+++ include/llvm/IR/DIBuilder.h
@@ -87,7 +87,7 @@
     public:
     explicit DIBuilder(Module &M);
     enum ComplexAddrKind { OpPlus=1, OpDeref };
-    enum DebugEmissionKind { FullDebug=1, LineTablesOnly };
+    enum DebugEmissionKind { FullDebug=1, LineTablesOnly, LocTrackingOnly };
 
     /// finalize - Construct any deferred debug info descriptors.
     void finalize();
@@ -108,6 +108,7 @@
     ///                 Objective-C.
     /// @param SplitName The name of the file that we'll split debug info out
     ///                  into.
+    /// @param Kind     The kind of debug information to generate.
     DICompileUnit createCompileUnit(unsigned Lang, StringRef File,
                                     StringRef Dir, StringRef Producer,
                                     bool isOptimized, StringRef Flags,
Index: lib/IR/DIBuilder.cpp
===================================================================
--- lib/IR/DIBuilder.cpp
+++ lib/IR/DIBuilder.cpp
@@ -140,8 +140,14 @@
   MDNode *CUNode = MDNode::get(VMContext, Elts);
 
   // Create a named metadata so that it is easier to find cu in a module.
-  NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
-  NMD->addOperand(CUNode);
+  // Note that we only generate this when the caller wants to actually
+  // emit debug information. When we are only interested in tracking
+  // source line locations throughout the backend, we prevent codegen from
+  // emitting debug info in the final output by not generating llvm.dbg.cu.
+  if (Kind != LocTrackingOnly) {
+    NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
+    NMD->addOperand(CUNode);
+  }
 
   return DICompileUnit(CUNode);
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4234.10699.patch
Type: text/x-patch
Size: 1818 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140620/27620c10/attachment.bin>


More information about the llvm-commits mailing list