[PATCH] D45039: [DebugInfo] Prepare debug information of labels in DebugHandlerBase.

Hsiangkai Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 29 07:15:57 PDT 2018


HsiangKai created this revision.
HsiangKai added reviewers: rnk, chenwj.
Herald added subscribers: JDevlieghere, aprantl.

DebugHandlerBase is a child class of AsmPrinterHandler. It is the parent
class of DwarfDebug and CodeViewDebug, it depends on which debug format
you want to generate. DwarfDebug will generate DWARF format debug info
through AsmPrinter.

Before DwarfDebug generate DWARF format finally, DebugHandlerBase need to
collect label information from MI listing first. This patch collects
mappings of DILabel to (DILocation, MachineInstr) from DBG_LABEL MI.
We record DBG_LABEL MI in the mapping due to the MCSymbol is not ready as
collecting the mappings in DebugHandlerBase::beginFunction().


Repository:
  rL LLVM

https://reviews.llvm.org/D45039

Files:
  lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
  lib/CodeGen/AsmPrinter/DebugHandlerBase.h


Index: lib/CodeGen/AsmPrinter/DebugHandlerBase.h
===================================================================
--- lib/CodeGen/AsmPrinter/DebugHandlerBase.h
+++ lib/CodeGen/AsmPrinter/DebugHandlerBase.h
@@ -49,6 +49,10 @@
   extractFromMachineInstruction(const MachineInstr &Instruction);
 };
 
+typedef std::pair<const DILocation *, const MachineInstr *> LabelInfo;
+typedef std::pair<const DILabel *, LabelInfo> InlinedLabel;
+typedef SmallVector<InlinedLabel, 4> DbgLabelList;
+
 /// Base class for debug information backends. Common functionality related to
 /// tracking which variables and scopes are alive at a given PC live here.
 class DebugHandlerBase : public AsmPrinterHandler {
@@ -82,6 +86,9 @@
   /// variable.  Variables are listed in order of appearance.
   DbgValueHistoryMap DbgValues;
 
+  /// Labels are listed in order of appearance.
+  DbgLabelList DbgLabels;
+
   /// Maps instruction with label emitted before instruction.
   /// FIXME: Make this private from DwarfDebug, we have the necessary accessors
   /// for it.
@@ -104,6 +111,8 @@
     LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
   }
 
+  void collectDbgLabel(const MachineFunction *MF, DbgLabelList &Result);
+
   virtual void beginFunctionImpl(const MachineFunction *MF) = 0;
   virtual void endFunctionImpl(const MachineFunction *MF) = 0;
   virtual void skippedNonDebugFunction() {}
Index: lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
+++ lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
@@ -167,6 +167,24 @@
   return true;
 }
 
+void DebugHandlerBase::collectDbgLabel(const MachineFunction *MF,
+                                       DbgLabelList &Result) {
+  for (const auto &MBB : *MF) {
+    for (const auto &MI : MBB) {
+      if (MI.isDebugLabel()) {
+        assert(MI.getNumOperands() == 1 && "Invalid DBG_LABEL instruction!");
+        const DILabel *RawLabel = MI.getDebugLabel();
+        assert(RawLabel->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
+               "Expected inlined-at fields to agree");
+        requestLabelBeforeInsn(&MI);
+        Result.push_back(std::make_pair(RawLabel,
+                           std::make_pair(MI.getDebugLoc()->getInlinedAt(),
+			                  &MI)));
+      }
+    }
+  }
+}
+
 void DebugHandlerBase::beginFunction(const MachineFunction *MF) {
   PrevInstBB = nullptr;
 
@@ -191,6 +209,9 @@
   calculateDbgValueHistory(MF, Asm->MF->getSubtarget().getRegisterInfo(),
                            DbgValues);
 
+  // Collect local labels.
+  collectDbgLabel(MF, DbgLabels);
+
   // Request labels for the full history.
   for (const auto &I : DbgValues) {
     const auto &Ranges = I.second;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45039.140241.patch
Type: text/x-patch
Size: 2772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180329/81bdbda3/attachment.bin>


More information about the llvm-commits mailing list