[PATCH] D45045: [DebugInfo] Generate DILabel metadata for labels.

Hsiangkai Wang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 30 07:21:48 PDT 2018


HsiangKai updated this revision to Diff 140423.
HsiangKai retitled this revision from "[DebugInfo] Generate debug information about labels" to "[DebugInfo] Generate DILabel metadata for labels.".
HsiangKai edited the summary of this revision.
HsiangKai added a comment.

1. No generating llvm.dbg.label intrinsic.
2. Modify commits according to chenwj's comments.


Repository:
  rC Clang

https://reviews.llvm.org/D45045

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CGStmt.cpp


Index: lib/CodeGen/CGStmt.cpp
===================================================================
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -531,6 +531,19 @@
   }
 
   EmitBlock(Dest.getBlock());
+
+  // Emit debug info for the label only if it's reachable.
+  if (HaveInsertPoint()) {
+    if (CGDebugInfo *DI = getDebugInfo()) {
+      if (CGM.getCodeGenOpts().getDebugInfo() >=
+          codegenoptions::LimitedDebugInfo) {
+        DI->setLocation(D->getLocation());
+        auto BB = Dest.getBlock();
+        DI->EmitLabel(D, BB, Builder);
+      }
+    }
+  }
+
   incrementProfileCounter(D->getStmt());
 }
 
Index: lib/CodeGen/CGDebugInfo.h
===================================================================
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -395,6 +395,9 @@
                                                    llvm::Value *AI,
                                                    CGBuilderTy &Builder);
 
+  /// Emit call to \c llvm.dbg.label for an label.
+  void EmitLabel(const LabelDecl *D, llvm::BasicBlock *BB, CGBuilderTy &Builder);
+
   /// Emit call to \c llvm.dbg.declare for an imported variable
   /// declaration in a block.
   void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable,
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3640,6 +3640,24 @@
   return EmitDeclare(VD, Storage, llvm::None, Builder);
 }
 
+void CGDebugInfo::EmitLabel(const LabelDecl *D, llvm::BasicBlock *BB,
+                            CGBuilderTy &Builder) {
+  assert(DebugKind >= codegenoptions::LimitedDebugInfo);
+  assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
+
+  if (D->hasAttr<NoDebugAttr>())
+    return;
+
+  auto *Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
+  StringRef Name = D->getName();
+  llvm::DIFile *Unit = getOrCreateFile(D->getLocation());
+  unsigned Line = getLineNumber(D->getLocation());
+
+  // Create the descriptor for the label.
+  auto *L = DBuilder.createLabel(Scope, Name, Unit, Line);
+  BB->setLabel(L);
+}
+
 llvm::DIType *CGDebugInfo::CreateSelfType(const QualType &QualTy,
                                           llvm::DIType *Ty) {
   llvm::DIType *CachedTy = getTypeOrNull(QualTy);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45045.140423.patch
Type: text/x-patch
Size: 2345 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180330/55b8ebfc/attachment-0001.bin>


More information about the cfe-commits mailing list