<div dir="ltr">This change is causing LSan failures on the ASan sanitizer bot, for <a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/21688/steps/check-llvm%20asan/logs/stdio">example</a>:<div><div>FAIL: LLVM :: DebugInfo/X86/fi-piece.ll (16281 of 26964)</div><div>******************** TEST 'LLVM :: DebugInfo/X86/fi-piece.ll' FAILED ********************</div><div>Script:</div><div>--</div><div>: 'RUN: at line 1';   /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/llc /b/sanitizer-x86_64-linux-fast/build/llvm/test/DebugInfo/X86/fi-piece.ll -filetype=obj -o - | /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/llvm-dwarfdump -v - | /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/FileCheck /b/sanitizer-x86_64-linux-fast/build/llvm/test/DebugInfo/X86/fi-piece.ll</div><div>--</div><div>Exit Code: 1</div><div><br></div><div>Command Output (stderr):</div><div>--</div><div><br></div><div>=================================================================</div><div>==16262==ERROR: LeakSanitizer: detected memory leaks</div><div><br></div><div>Direct leak of 48 byte(s) in 1 object(s) allocated from:</div><div>    #0 0x9b4b48 in malloc /b/sanitizer-x86_64-linux-fast/build/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:88</div><div>    #1 0x5813cb2 in safe_malloc /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Support/MemAlloc.h:27:18</div><div>    #2 0x5813cb2 in llvm::SmallVectorBase::grow_pod(void*, unsigned long, unsigned long) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/Support/SmallVector.cpp:55</div><div>    #3 0x37bf8b4 in grow_pod /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/ADT/SmallVector.h:99:22</div><div>    #4 0x37bf8b4 in grow /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/ADT/SmallVector.h:307</div><div>    #5 0x37bf8b4 in push_back /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/ADT/SmallVector.h:312</div><div>    #6 0x37bf8b4 in llvm::DbgVariable::addMMIEntry(llvm::DbgVariable const&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:282</div><div>    #7 0x37d71d6 in llvm::DwarfDebug::collectVariableInfoFromMFTable(llvm::DwarfCompileUnit&, llvm::DenseSet<std::__1::pair<llvm::DILocalVariable const*, llvm::DILocation const*>, llvm::DenseMapInfo<std::__1::pair<llvm::DILocalVariable const*, llvm::DILocation const*> > >&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:959:15</div><div>    #8 0x37dbef3 in llvm::DwarfDebug::collectEntityInfo(llvm::DwarfCompileUnit&, llvm::DISubprogram const*, llvm::DenseSet<std::__1::pair<llvm::DILocalVariable const*, llvm::DILocation const*>, llvm::DenseMapInfo<std::__1::pair<llvm::DILocalVariable const*, llvm::DILocation const*> > >&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1212:3</div><div>    #9 0x37e156a in llvm::DwarfDebug::endFunctionImpl(llvm::MachineFunction const*) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1463:3</div><div>    #10 0x38e98dc in llvm::DebugHandlerBase::endFunction(llvm::MachineFunction const*) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp:304:5</div><div>    #11 0x37779a0 in llvm::AsmPrinter::EmitFunctionBody() /b/sanitizer-x86_64-linux-fast/build/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1208:17</div><div>    #12 0x2ad4203 in llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/Target/X86/X86AsmPrinter.cpp:78:3</div><div>    #13 0x3c6f6d5 in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/CodeGen/MachineFunctionPass.cpp:61:13</div><div>    #14 0x46bc25d in llvm::FPPassManager::runOnFunction(llvm::Function&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IR/LegacyPassManager.cpp:1586:27</div><div>    #15 0x46bc872 in llvm::FPPassManager::runOnModule(llvm::Module&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IR/LegacyPassManager.cpp:1609:16</div><div>    #16 0x46bd5e8 in runOnModule /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IR/LegacyPassManager.cpp:1669:27</div><div>    #17 0x46bd5e8 in llvm::legacy::PassManagerImpl::run(llvm::Module&) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/IR/LegacyPassManager.cpp:1774</div><div>    #18 0x9f2e4f in compileModule(char**, llvm::LLVMContext&) /b/sanitizer-x86_64-linux-fast/build/llvm/tools/llc/llc.cpp:597:8</div><div>    #19 0x9ec3c0 in main /b/sanitizer-x86_64-linux-fast/build/llvm/tools/llc/llc.cpp:351:22</div><div>    #20 0x7fdde9ea92e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)</div><div><br></div><div>SUMMARY: AddressSanitizer: 48 byte(s) leaked in 1 allocation(s).</div></div><div><br></div><div>I've reverted it in r338408</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 31, 2018 at 7:48 AM Hsiangkai Wang via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: hsiangkai<br>
Date: Tue Jul 31 07:48:32 2018<br>
New Revision: 338390<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=338390&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=338390&view=rev</a><br>
Log:<br>
[DebugInfo] Generate DWARF debug information for labels.<br>
<br>
There are two forms for label debug information in DWARF format.<br>
<br>
1. Labels in a non-inlined function:<br>
<br>
DW_TAG_label<br>
  DW_AT_name<br>
  DW_AT_decl_file<br>
  DW_AT_decl_line<br>
  DW_AT_low_pc<br>
<br>
2. Labels in an inlined function:<br>
<br>
DW_TAG_label<br>
  DW_AT_abstract_origin<br>
  DW_AT_low_pc<br>
<br>
We will collect label information from DBG_LABEL. Before every DBG_LABEL,<br>
we will generate a temporary symbol to denote the location of the label.<br>
The symbol could be used to get DW_AT_low_pc afterwards. So, we create a<br>
mapping between 'inlined label' and DBG_LABEL MachineInstr in DebugHandlerBase.<br>
The DBG_LABEL in the mapping is used to query the symbol before it.<br>
<br>
The AbstractLabels in DwarfCompileUnit is used to process labels in inlined<br>
functions.<br>
<br>
We also keep a mapping between scope and labels in DwarfFile to help to<br>
generate correct tree structure of DIEs.<br>
<br>
It also generates label debug information under global isel.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D45556" rel="noreferrer" target="_blank">https://reviews.llvm.org/D45556</a><br>
<br>
Added:<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp<br>
      - copied, changed from r338388, llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h<br>
      - copied, changed from r338388, llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h<br>
    llvm/trunk/test/DebugInfo/Generic/debug-label-inline.ll<br>
    llvm/trunk/test/DebugInfo/Generic/debug-label.ll<br>
Removed:<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h<br>
Modified:<br>
    llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h<br>
    llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp<br>
    llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h?rev=338390&r1=338389&r2=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h (original)<br>
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h Tue Jul 31 07:48:32 2018<br>
@@ -208,6 +208,10 @@ public:<br>
                                          const MDNode *Variable,<br>
                                          const MDNode *Expr);<br>
<br>
+  /// Build and insert a DBG_LABEL instructions specifying that \p Label is<br>
+  /// given. Convert "llvm.dbg.label Label" to "DBG_LABEL Label".<br>
+  MachineInstrBuilder buildDbgLabel(const MDNode *Label);<br>
+<br>
   /// Build and insert \p Res = G_FRAME_INDEX \p Idx<br>
   ///<br>
   /// G_FRAME_INDEX materializes the address of an alloca value or other<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt?rev=338390&r1=338389&r2=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt Tue Jul 31 07:48:32 2018<br>
@@ -5,7 +5,7 @@ add_llvm_library(LLVMAsmPrinter<br>
   AsmPrinter.cpp<br>
   AsmPrinterDwarf.cpp<br>
   AsmPrinterInlineAsm.cpp<br>
-  DbgValueHistoryCalculator.cpp<br>
+  DbgEntityHistoryCalculator.cpp<br>
   DebugHandlerBase.cpp<br>
   DebugLocStream.cpp<br>
   DIE.cpp<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h?rev=338390&r1=338389&r2=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h Tue Jul 31 07:48:32 2018<br>
@@ -14,7 +14,7 @@<br>
 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H<br>
 #define LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H<br>
<br>
-#include "DbgValueHistoryCalculator.h"<br>
+#include "DbgEntityHistoryCalculator.h"<br>
 #include "DebugHandlerBase.h"<br>
 #include "llvm/ADT/ArrayRef.h"<br>
 #include "llvm/ADT/DenseMap.h"<br>
<br>
Copied: llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp (from r338388, llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp)<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp?p2=llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp&p1=llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp&r1=338388&r2=338390&rev=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp?p2=llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp&p1=llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp&r1=338388&r2=338390&rev=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp Tue Jul 31 07:48:32 2018<br>
@@ -1,4 +1,4 @@<br>
-//===- llvm/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp --------------===//<br>
+//===- llvm/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp -------------===//<br>
 //<br>
 //                     The LLVM Compiler Infrastructure<br>
 //<br>
@@ -7,7 +7,7 @@<br>
 //<br>
 //===----------------------------------------------------------------------===//<br>
<br>
-#include "DbgValueHistoryCalculator.h"<br>
+#include "DbgEntityHistoryCalculator.h"<br>
 #include "llvm/ADT/BitVector.h"<br>
 #include "llvm/ADT/STLExtras.h"<br>
 #include "llvm/ADT/SmallVector.h"<br>
@@ -78,11 +78,17 @@ unsigned DbgValueHistoryMap::getRegister<br>
   return isDescribedByReg(*Ranges.back().first);<br>
 }<br>
<br>
+void DbgLabelInstrMap::addInstr(InlinedLabel Label, const MachineInstr &MI) {<br>
+  assert(MI.isDebugLabel() && "not a DBG_LABEL");<br>
+  LabelInstr[Label] = &MI;<br>
+}<br>
+<br>
 namespace {<br>
<br>
 // Maps physreg numbers to the variables they describe.<br>
 using InlinedVariable = DbgValueHistoryMap::InlinedVariable;<br>
 using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedVariable, 1>>;<br>
+using InlinedLabel = DbgLabelInstrMap::InlinedLabel;<br>
<br>
 } // end anonymous namespace<br>
<br>
@@ -187,9 +193,10 @@ static void collectChangingRegs(const Ma<br>
   }<br>
 }<br>
<br>
-void llvm::calculateDbgValueHistory(const MachineFunction *MF,<br>
-                                    const TargetRegisterInfo *TRI,<br>
-                                    DbgValueHistoryMap &Result) {<br>
+void llvm::calculateDbgEntityHistory(const MachineFunction *MF,<br>
+                                     const TargetRegisterInfo *TRI,<br>
+                                     DbgValueHistoryMap &DbgValues,<br>
+                                     DbgLabelInstrMap &DbgLabels) {<br>
   BitVector ChangingRegs(TRI->getNumRegs());<br>
   collectChangingRegs(MF, TRI, ChangingRegs);<br>
<br>
@@ -210,14 +217,14 @@ void llvm::calculateDbgValueHistory(cons<br>
             // If this is a virtual register, only clobber it since it doesn't<br>
             // have aliases.<br>
             if (TRI->isVirtualRegister(MO.getReg()))<br>
-              clobberRegisterUses(RegVars, MO.getReg(), Result, MI);<br>
+              clobberRegisterUses(RegVars, MO.getReg(), DbgValues, MI);<br>
             // If this is a register def operand, it may end a debug value<br>
             // range.<br>
             else {<br>
               for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid();<br>
                    ++AI)<br>
                 if (ChangingRegs.test(*AI))<br>
-                  clobberRegisterUses(RegVars, *AI, Result, MI);<br>
+                  clobberRegisterUses(RegVars, *AI, DbgValues, MI);<br>
             }<br>
           } else if (MO.isRegMask()) {<br>
             // If this is a register mask operand, clobber all debug values in<br>
@@ -226,7 +233,7 @@ void llvm::calculateDbgValueHistory(cons<br>
               // Don't consider SP to be clobbered by register masks.<br>
               if (unsigned(I) != SP && TRI->isPhysicalRegister(I) &&<br>
                   MO.clobbersPhysReg(I)) {<br>
-                clobberRegisterUses(RegVars, I, Result, MI);<br>
+                clobberRegisterUses(RegVars, I, DbgValues, MI);<br>
               }<br>
             }<br>
           }<br>
@@ -234,26 +241,34 @@ void llvm::calculateDbgValueHistory(cons<br>
         continue;<br>
       }<br>
<br>
-      // Skip DBG_LABEL instructions.<br>
-      if (MI.isDebugLabel())<br>
-        continue;<br>
-<br>
-      assert(MI.getNumOperands() > 1 && "Invalid DBG_VALUE instruction!");<br>
-      // Use the base variable (without any DW_OP_piece expressions)<br>
-      // as index into History. The full variables including the<br>
-      // piece expressions are attached to the MI.<br>
-      const DILocalVariable *RawVar = MI.getDebugVariable();<br>
-      assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) &&<br>
-             "Expected inlined-at fields to agree");<br>
-      InlinedVariable Var(RawVar, MI.getDebugLoc()->getInlinedAt());<br>
-<br>
-      if (unsigned PrevReg = Result.getRegisterForVar(Var))<br>
-        dropRegDescribedVar(RegVars, PrevReg, Var);<br>
-<br>
-      Result.startInstrRange(Var, MI);<br>
-<br>
-      if (unsigned NewReg = isDescribedByReg(MI))<br>
-        addRegDescribedVar(RegVars, NewReg, Var);<br>
+      if (MI.isDebugValue()) {<br>
+        assert(MI.getNumOperands() > 1 && "Invalid DBG_VALUE instruction!");<br>
+        // Use the base variable (without any DW_OP_piece expressions)<br>
+        // as index into History. The full variables including the<br>
+        // piece expressions are attached to the MI.<br>
+        const DILocalVariable *RawVar = MI.getDebugVariable();<br>
+        assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) &&<br>
+               "Expected inlined-at fields to agree");<br>
+        InlinedVariable Var(RawVar, MI.getDebugLoc()->getInlinedAt());<br>
+<br>
+        if (unsigned PrevReg = DbgValues.getRegisterForVar(Var))<br>
+          dropRegDescribedVar(RegVars, PrevReg, Var);<br>
+<br>
+        DbgValues.startInstrRange(Var, MI);<br>
+<br>
+        if (unsigned NewReg = isDescribedByReg(MI))<br>
+          addRegDescribedVar(RegVars, NewReg, Var);<br>
+      } else if (MI.isDebugLabel()) {<br>
+        assert(MI.getNumOperands() == 1 && "Invalid DBG_LABEL instruction!");<br>
+        const DILabel *RawLabel = MI.getDebugLabel();<br>
+        assert(RawLabel->isValidLocationForIntrinsic(MI.getDebugLoc()) &&<br>
+            "Expected inlined-at fields to agree");<br>
+        // When collecting debug information for labels, there is no MCSymbol<br>
+        // generated for it. So, we keep MachineInstr in DbgLabels in order<br>
+        // to query MCSymbol afterward.<br>
+        InlinedLabel L(RawLabel, MI.getDebugLoc()->getInlinedAt());<br>
+        DbgLabels.addInstr(L, MI);<br>
+      }<br>
     }<br>
<br>
     // Make sure locations for register-described variables are valid only<br>
@@ -264,7 +279,7 @@ void llvm::calculateDbgValueHistory(cons<br>
         auto CurElem = I++; // CurElem can be erased below.<br>
         if (TRI->isVirtualRegister(CurElem->first) ||<br>
             ChangingRegs.test(CurElem->first))<br>
-          clobberRegisterUses(RegVars, CurElem, Result, MBB.back());<br>
+          clobberRegisterUses(RegVars, CurElem, DbgValues, MBB.back());<br>
       }<br>
     }<br>
   }<br>
<br>
Copied: llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h (from r338388, llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h)<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h?p2=llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h&p1=llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h&r1=338388&r2=338390&rev=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h?p2=llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h&p1=llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h&r1=338388&r2=338390&rev=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h Tue Jul 31 07:48:32 2018<br>
@@ -1,4 +1,4 @@<br>
-//===- llvm/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h ------*- C++ -*-===//<br>
+//===- llvm/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h -----*- C++ -*-===//<br>
 //<br>
 //                     The LLVM Compiler Infrastructure<br>
 //<br>
@@ -58,9 +58,30 @@ public:<br>
 #endif<br>
 };<br>
<br>
-void calculateDbgValueHistory(const MachineFunction *MF,<br>
-                              const TargetRegisterInfo *TRI,<br>
-                              DbgValueHistoryMap &Result);<br>
+/// For each inlined instance of a source-level label, keep the corresponding<br>
+/// DBG_LABEL instruction. The DBG_LABEL instruction could be used to generate<br>
+/// a temporary (assembler) label before it.<br>
+class DbgLabelInstrMap {<br>
+public:<br>
+  using InlinedLabel = std::pair<const DILabel *, const DILocation *>;<br>
+  using InstrMap = MapVector<InlinedLabel, const MachineInstr *>;<br>
+<br>
+private:<br>
+  InstrMap LabelInstr;<br>
+<br>
+public:<br>
+  void  addInstr(InlinedLabel Label, const MachineInstr &MI);<br>
+<br>
+  bool empty() const { return LabelInstr.empty(); }<br>
+  void clear() { LabelInstr.clear(); }<br>
+  InstrMap::const_iterator begin() const { return LabelInstr.begin(); }<br>
+  InstrMap::const_iterator end() const { return LabelInstr.end(); }<br>
+};<br>
+<br>
+void calculateDbgEntityHistory(const MachineFunction *MF,<br>
+                               const TargetRegisterInfo *TRI,<br>
+                               DbgValueHistoryMap &DbgValues,<br>
+                               DbgLabelInstrMap &DbgLabels);<br>
<br>
 } // end namespace llvm<br>
<br>
<br>
Removed: llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp?rev=338389&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp?rev=338389&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp (removed)<br>
@@ -1,301 +0,0 @@<br>
-//===- llvm/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp --------------===//<br>
-//<br>
-//                     The LLVM Compiler Infrastructure<br>
-//<br>
-// This file is distributed under the University of Illinois Open Source<br>
-// License. See LICENSE.TXT for details.<br>
-//<br>
-//===----------------------------------------------------------------------===//<br>
-<br>
-#include "DbgValueHistoryCalculator.h"<br>
-#include "llvm/ADT/BitVector.h"<br>
-#include "llvm/ADT/STLExtras.h"<br>
-#include "llvm/ADT/SmallVector.h"<br>
-#include "llvm/CodeGen/MachineBasicBlock.h"<br>
-#include "llvm/CodeGen/MachineFunction.h"<br>
-#include "llvm/CodeGen/MachineInstr.h"<br>
-#include "llvm/CodeGen/MachineOperand.h"<br>
-#include "llvm/CodeGen/TargetLowering.h"<br>
-#include "llvm/CodeGen/TargetRegisterInfo.h"<br>
-#include "llvm/CodeGen/TargetSubtargetInfo.h"<br>
-#include "llvm/IR/DebugInfoMetadata.h"<br>
-#include "llvm/IR/DebugLoc.h"<br>
-#include "llvm/MC/MCRegisterInfo.h"<br>
-#include "llvm/Support/Debug.h"<br>
-#include "llvm/Support/raw_ostream.h"<br>
-#include <cassert><br>
-#include <map><br>
-#include <utility><br>
-<br>
-using namespace llvm;<br>
-<br>
-#define DEBUG_TYPE "dwarfdebug"<br>
-<br>
-// If @MI is a DBG_VALUE with debug value described by a<br>
-// defined register, returns the number of this register.<br>
-// In the other case, returns 0.<br>
-static unsigned isDescribedByReg(const MachineInstr &MI) {<br>
-  assert(MI.isDebugValue());<br>
-  assert(MI.getNumOperands() == 4);<br>
-  // If location of variable is described using a register (directly or<br>
-  // indirectly), this register is always a first operand.<br>
-  return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0;<br>
-}<br>
-<br>
-void DbgValueHistoryMap::startInstrRange(InlinedVariable Var,<br>
-                                         const MachineInstr &MI) {<br>
-  // Instruction range should start with a DBG_VALUE instruction for the<br>
-  // variable.<br>
-  assert(MI.isDebugValue() && "not a DBG_VALUE");<br>
-  auto &Ranges = VarInstrRanges[Var];<br>
-  if (!Ranges.empty() && Ranges.back().second == nullptr &&<br>
-      Ranges.back().first->isIdenticalTo(MI)) {<br>
-    LLVM_DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n"<br>
-                      << "\t" << Ranges.back().first << "\t" << MI << "\n");<br>
-    return;<br>
-  }<br>
-  Ranges.push_back(std::make_pair(&MI, nullptr));<br>
-}<br>
-<br>
-void DbgValueHistoryMap::endInstrRange(InlinedVariable Var,<br>
-                                       const MachineInstr &MI) {<br>
-  auto &Ranges = VarInstrRanges[Var];<br>
-  // Verify that the current instruction range is not yet closed.<br>
-  assert(!Ranges.empty() && Ranges.back().second == nullptr);<br>
-  // For now, instruction ranges are not allowed to cross basic block<br>
-  // boundaries.<br>
-  assert(Ranges.back().first->getParent() == MI.getParent());<br>
-  Ranges.back().second = &MI;<br>
-}<br>
-<br>
-unsigned DbgValueHistoryMap::getRegisterForVar(InlinedVariable Var) const {<br>
-  const auto &I = VarInstrRanges.find(Var);<br>
-  if (I == VarInstrRanges.end())<br>
-    return 0;<br>
-  const auto &Ranges = I->second;<br>
-  if (Ranges.empty() || Ranges.back().second != nullptr)<br>
-    return 0;<br>
-  return isDescribedByReg(*Ranges.back().first);<br>
-}<br>
-<br>
-namespace {<br>
-<br>
-// Maps physreg numbers to the variables they describe.<br>
-using InlinedVariable = DbgValueHistoryMap::InlinedVariable;<br>
-using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedVariable, 1>>;<br>
-<br>
-} // end anonymous namespace<br>
-<br>
-// Claim that @Var is not described by @RegNo anymore.<br>
-static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,<br>
-                                InlinedVariable Var) {<br>
-  const auto &I = RegVars.find(RegNo);<br>
-  assert(RegNo != 0U && I != RegVars.end());<br>
-  auto &VarSet = I->second;<br>
-  const auto &VarPos = llvm::find(VarSet, Var);<br>
-  assert(VarPos != VarSet.end());<br>
-  VarSet.erase(VarPos);<br>
-  // Don't keep empty sets in a map to keep it as small as possible.<br>
-  if (VarSet.empty())<br>
-    RegVars.erase(I);<br>
-}<br>
-<br>
-// Claim that @Var is now described by @RegNo.<br>
-static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,<br>
-                               InlinedVariable Var) {<br>
-  assert(RegNo != 0U);<br>
-  auto &VarSet = RegVars[RegNo];<br>
-  assert(!is_contained(VarSet, Var));<br>
-  VarSet.push_back(Var);<br>
-}<br>
-<br>
-// Terminate the location range for variables described by register at<br>
-// @I by inserting @ClobberingInstr to their history.<br>
-static void clobberRegisterUses(RegDescribedVarsMap &RegVars,<br>
-                                RegDescribedVarsMap::iterator I,<br>
-                                DbgValueHistoryMap &HistMap,<br>
-                                const MachineInstr &ClobberingInstr) {<br>
-  // Iterate over all variables described by this register and add this<br>
-  // instruction to their history, clobbering it.<br>
-  for (const auto &Var : I->second)<br>
-    HistMap.endInstrRange(Var, ClobberingInstr);<br>
-  RegVars.erase(I);<br>
-}<br>
-<br>
-// Terminate the location range for variables described by register<br>
-// @RegNo by inserting @ClobberingInstr to their history.<br>
-static void clobberRegisterUses(RegDescribedVarsMap &RegVars, unsigned RegNo,<br>
-                                DbgValueHistoryMap &HistMap,<br>
-                                const MachineInstr &ClobberingInstr) {<br>
-  const auto &I = RegVars.find(RegNo);<br>
-  if (I == RegVars.end())<br>
-    return;<br>
-  clobberRegisterUses(RegVars, I, HistMap, ClobberingInstr);<br>
-}<br>
-<br>
-// Returns the first instruction in @MBB which corresponds to<br>
-// the function epilogue, or nullptr if @MBB doesn't contain an epilogue.<br>
-static const MachineInstr *getFirstEpilogueInst(const MachineBasicBlock &MBB) {<br>
-  auto LastMI = MBB.getLastNonDebugInstr();<br>
-  if (LastMI == MBB.end() || !LastMI->isReturn())<br>
-    return nullptr;<br>
-  // Assume that epilogue starts with instruction having the same debug location<br>
-  // as the return instruction.<br>
-  DebugLoc LastLoc = LastMI->getDebugLoc();<br>
-  auto Res = LastMI;<br>
-  for (MachineBasicBlock::const_reverse_iterator I = LastMI.getReverse(),<br>
-                                                 E = MBB.rend();<br>
-       I != E; ++I) {<br>
-    if (I->getDebugLoc() != LastLoc)<br>
-      return &*Res;<br>
-    Res = &*I;<br>
-  }<br>
-  // If all instructions have the same debug location, assume whole MBB is<br>
-  // an epilogue.<br>
-  return &*MBB.begin();<br>
-}<br>
-<br>
-// Collect registers that are modified in the function body (their<br>
-// contents is changed outside of the prologue and epilogue).<br>
-static void collectChangingRegs(const MachineFunction *MF,<br>
-                                const TargetRegisterInfo *TRI,<br>
-                                BitVector &Regs) {<br>
-  for (const auto &MBB : *MF) {<br>
-    auto FirstEpilogueInst = getFirstEpilogueInst(MBB);<br>
-<br>
-    for (const auto &MI : MBB) {<br>
-      // Avoid looking at prologue or epilogue instructions.<br>
-      if (&MI == FirstEpilogueInst)<br>
-        break;<br>
-      if (MI.getFlag(MachineInstr::FrameSetup))<br>
-        continue;<br>
-<br>
-      // Look for register defs and register masks. Register masks are<br>
-      // typically on calls and they clobber everything not in the mask.<br>
-      for (const MachineOperand &MO : MI.operands()) {<br>
-        // Skip virtual registers since they are handled by the parent.<br>
-        if (MO.isReg() && MO.isDef() && MO.getReg() &&<br>
-            !TRI->isVirtualRegister(MO.getReg())) {<br>
-          for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid();<br>
-               ++AI)<br>
-            Regs.set(*AI);<br>
-        } else if (MO.isRegMask()) {<br>
-          Regs.setBitsNotInMask(MO.getRegMask());<br>
-        }<br>
-      }<br>
-    }<br>
-  }<br>
-}<br>
-<br>
-void llvm::calculateDbgValueHistory(const MachineFunction *MF,<br>
-                                    const TargetRegisterInfo *TRI,<br>
-                                    DbgValueHistoryMap &Result) {<br>
-  BitVector ChangingRegs(TRI->getNumRegs());<br>
-  collectChangingRegs(MF, TRI, ChangingRegs);<br>
-<br>
-  const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();<br>
-  unsigned SP = TLI->getStackPointerRegisterToSaveRestore();<br>
-  RegDescribedVarsMap RegVars;<br>
-  for (const auto &MBB : *MF) {<br>
-    for (const auto &MI : MBB) {<br>
-      if (!MI.isDebugInstr()) {<br>
-        // Not a DBG_VALUE instruction. It may clobber registers which describe<br>
-        // some variables.<br>
-        for (const MachineOperand &MO : MI.operands()) {<br>
-          if (MO.isReg() && MO.isDef() && MO.getReg()) {<br>
-            // Ignore call instructions that claim to clobber SP. The AArch64<br>
-            // backend does this for aggregate function arguments.<br>
-            if (MI.isCall() && MO.getReg() == SP)<br>
-              continue;<br>
-            // If this is a virtual register, only clobber it since it doesn't<br>
-            // have aliases.<br>
-            if (TRI->isVirtualRegister(MO.getReg()))<br>
-              clobberRegisterUses(RegVars, MO.getReg(), Result, MI);<br>
-            // If this is a register def operand, it may end a debug value<br>
-            // range.<br>
-            else {<br>
-              for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid();<br>
-                   ++AI)<br>
-                if (ChangingRegs.test(*AI))<br>
-                  clobberRegisterUses(RegVars, *AI, Result, MI);<br>
-            }<br>
-          } else if (MO.isRegMask()) {<br>
-            // If this is a register mask operand, clobber all debug values in<br>
-            // non-CSRs.<br>
-            for (unsigned I : ChangingRegs.set_bits()) {<br>
-              // Don't consider SP to be clobbered by register masks.<br>
-              if (unsigned(I) != SP && TRI->isPhysicalRegister(I) &&<br>
-                  MO.clobbersPhysReg(I)) {<br>
-                clobberRegisterUses(RegVars, I, Result, MI);<br>
-              }<br>
-            }<br>
-          }<br>
-        }<br>
-        continue;<br>
-      }<br>
-<br>
-      // Skip DBG_LABEL instructions.<br>
-      if (MI.isDebugLabel())<br>
-        continue;<br>
-<br>
-      assert(MI.getNumOperands() > 1 && "Invalid DBG_VALUE instruction!");<br>
-      // Use the base variable (without any DW_OP_piece expressions)<br>
-      // as index into History. The full variables including the<br>
-      // piece expressions are attached to the MI.<br>
-      const DILocalVariable *RawVar = MI.getDebugVariable();<br>
-      assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) &&<br>
-             "Expected inlined-at fields to agree");<br>
-      InlinedVariable Var(RawVar, MI.getDebugLoc()->getInlinedAt());<br>
-<br>
-      if (unsigned PrevReg = Result.getRegisterForVar(Var))<br>
-        dropRegDescribedVar(RegVars, PrevReg, Var);<br>
-<br>
-      Result.startInstrRange(Var, MI);<br>
-<br>
-      if (unsigned NewReg = isDescribedByReg(MI))<br>
-        addRegDescribedVar(RegVars, NewReg, Var);<br>
-    }<br>
-<br>
-    // Make sure locations for register-described variables are valid only<br>
-    // until the end of the basic block (unless it's the last basic block, in<br>
-    // which case let their liveness run off to the end of the function).<br>
-    if (!MBB.empty() && &MBB != &MF->back()) {<br>
-      for (auto I = RegVars.begin(), E = RegVars.end(); I != E;) {<br>
-        auto CurElem = I++; // CurElem can be erased below.<br>
-        if (TRI->isVirtualRegister(CurElem->first) ||<br>
-            ChangingRegs.test(CurElem->first))<br>
-          clobberRegisterUses(RegVars, CurElem, Result, MBB.back());<br>
-      }<br>
-    }<br>
-  }<br>
-}<br>
-<br>
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)<br>
-LLVM_DUMP_METHOD void DbgValueHistoryMap::dump() const {<br>
-  dbgs() << "DbgValueHistoryMap:\n";<br>
-  for (const auto &VarRangePair : *this) {<br>
-    const InlinedVariable &Var = VarRangePair.first;<br>
-    const InstrRanges &Ranges = VarRangePair.second;<br>
-<br>
-    const DILocalVariable *LocalVar = Var.first;<br>
-    const DILocation *Location = Var.second;<br>
-<br>
-    dbgs() << " - " << LocalVar->getName() << " at ";<br>
-<br>
-    if (Location)<br>
-      dbgs() << Location->getFilename() << ":" << Location->getLine() << ":"<br>
-             << Location->getColumn();<br>
-    else<br>
-      dbgs() << "<unknown location>";<br>
-<br>
-    dbgs() << " --\n";<br>
-<br>
-    for (const InstrRange &Range : Ranges) {<br>
-      dbgs() << "   Begin: " << *Range.first;<br>
-      if (Range.second)<br>
-        dbgs() << "   End  : " << *Range.second;<br>
-      dbgs() << "\n";<br>
-    }<br>
-  }<br>
-}<br>
-#endif<br>
<br>
Removed: llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h?rev=338389&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h?rev=338389&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h (removed)<br>
@@ -1,67 +0,0 @@<br>
-//===- llvm/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h ------*- C++ -*-===//<br>
-//<br>
-//                     The LLVM Compiler Infrastructure<br>
-//<br>
-// This file is distributed under the University of Illinois Open Source<br>
-// License. See LICENSE.TXT for details.<br>
-//<br>
-//===----------------------------------------------------------------------===//<br>
-<br>
-#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DBGVALUEHISTORYCALCULATOR_H<br>
-#define LLVM_LIB_CODEGEN_ASMPRINTER_DBGVALUEHISTORYCALCULATOR_H<br>
-<br>
-#include "llvm/ADT/MapVector.h"<br>
-#include "llvm/ADT/SmallVector.h"<br>
-#include "llvm/IR/DebugInfoMetadata.h"<br>
-#include <utility><br>
-<br>
-namespace llvm {<br>
-<br>
-class DILocalVariable;<br>
-class MachineFunction;<br>
-class MachineInstr;<br>
-class TargetRegisterInfo;<br>
-<br>
-// For each user variable, keep a list of instruction ranges where this variable<br>
-// is accessible. The variables are listed in order of appearance.<br>
-class DbgValueHistoryMap {<br>
-  // Each instruction range starts with a DBG_VALUE instruction, specifying the<br>
-  // location of a variable, which is assumed to be valid until the end of the<br>
-  // range. If end is not specified, location is valid until the start<br>
-  // instruction of the next instruction range, or until the end of the<br>
-  // function.<br>
-public:<br>
-  using InstrRange = std::pair<const MachineInstr *, const MachineInstr *>;<br>
-  using InstrRanges = SmallVector<InstrRange, 4>;<br>
-  using InlinedVariable =<br>
-      std::pair<const DILocalVariable *, const DILocation *>;<br>
-  using InstrRangesMap = MapVector<InlinedVariable, InstrRanges>;<br>
-<br>
-private:<br>
-  InstrRangesMap VarInstrRanges;<br>
-<br>
-public:<br>
-  void startInstrRange(InlinedVariable Var, const MachineInstr &MI);<br>
-  void endInstrRange(InlinedVariable Var, const MachineInstr &MI);<br>
-<br>
-  // Returns register currently describing @Var. If @Var is currently<br>
-  // unaccessible or is not described by a register, returns 0.<br>
-  unsigned getRegisterForVar(InlinedVariable Var) const;<br>
-<br>
-  bool empty() const { return VarInstrRanges.empty(); }<br>
-  void clear() { VarInstrRanges.clear(); }<br>
-  InstrRangesMap::const_iterator begin() const { return VarInstrRanges.begin(); }<br>
-  InstrRangesMap::const_iterator end() const { return VarInstrRanges.end(); }<br>
-<br>
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)<br>
-  LLVM_DUMP_METHOD void dump() const;<br>
-#endif<br>
-};<br>
-<br>
-void calculateDbgValueHistory(const MachineFunction *MF,<br>
-                              const TargetRegisterInfo *TRI,<br>
-                              DbgValueHistoryMap &Result);<br>
-<br>
-} // end namespace llvm<br>
-<br>
-#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DBGVALUEHISTORYCALCULATOR_H<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp?rev=338390&r1=338389&r2=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp Tue Jul 31 07:48:32 2018<br>
@@ -190,8 +190,9 @@ void DebugHandlerBase::beginFunction(con<br>
<br>
   // Calculate history for local variables.<br>
   assert(DbgValues.empty() && "DbgValues map wasn't cleaned!");<br>
-  calculateDbgValueHistory(MF, Asm->MF->getSubtarget().getRegisterInfo(),<br>
-                           DbgValues);<br>
+  assert(DbgLabels.empty() && "DbgLabels map wasn't cleaned!");<br>
+  calculateDbgEntityHistory(MF, Asm->MF->getSubtarget().getRegisterInfo(),<br>
+                            DbgValues, DbgLabels);<br>
   LLVM_DEBUG(DbgValues.dump());<br>
<br>
   // Request labels for the full history.<br>
@@ -229,6 +230,12 @@ void DebugHandlerBase::beginFunction(con<br>
     }<br>
   }<br>
<br>
+  // Ensure there is a symbol before DBG_LABEL.<br>
+  for (const auto &I : DbgLabels) {<br>
+    const MachineInstr *MI = I.second;<br>
+    requestLabelBeforeInsn(MI);<br>
+  }<br>
+<br>
   PrevInstLoc = DebugLoc();<br>
   PrevLabel = Asm->getFunctionBegin();<br>
   beginFunctionImpl(MF);<br>
@@ -296,6 +303,7 @@ void DebugHandlerBase::endFunction(const<br>
   if (hasDebugInfo(MMI, MF))<br>
     endFunctionImpl(MF);<br>
   DbgValues.clear();<br>
+  DbgLabels.clear();<br>
   LabelsBeforeInsn.clear();<br>
   LabelsAfterInsn.clear();<br>
 }<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h?rev=338390&r1=338389&r2=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h Tue Jul 31 07:48:32 2018<br>
@@ -16,7 +16,7 @@<br>
 #define LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGHANDLERBASE_H<br>
<br>
 #include "AsmPrinterHandler.h"<br>
-#include "DbgValueHistoryCalculator.h"<br>
+#include "DbgEntityHistoryCalculator.h"<br>
 #include "llvm/ADT/Optional.h"<br>
 #include "llvm/CodeGen/LexicalScopes.h"<br>
 #include "llvm/CodeGen/MachineInstr.h"<br>
@@ -82,6 +82,9 @@ protected:<br>
   /// variable.  Variables are listed in order of appearance.<br>
   DbgValueHistoryMap DbgValues;<br>
<br>
+  /// Mapping of inlined labels and DBG_LABEL machine instruction.<br>
+  DbgLabelInstrMap DbgLabels;<br>
+<br>
   /// Maps instruction with label emitted before instruction.<br>
   /// FIXME: Make this private from DwarfDebug, we have the necessary accessors<br>
   /// for it.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=338390&r1=338389&r2=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Tue Jul 31 07:48:32 2018<br>
@@ -506,6 +506,18 @@ DIE *DwarfCompileUnit::constructVariable<br>
   return D;<br>
 }<br>
<br>
+DIE *DwarfCompileUnit::constructLabelDIE(DbgLabel &DL,<br>
+                                         const LexicalScope &Scope) {<br>
+  auto LabelDie = DIE::get(DIEValueAllocator, DL.getTag());<br>
+  insertDIE(DL.getLabel(), LabelDie);<br>
+  DL.setDIE(*LabelDie);<br>
+<br>
+  if (Scope.isAbstractScope())<br>
+    applyLabelAttributes(DL, *LabelDie);<br>
+<br>
+  return LabelDie;<br>
+}<br>
+<br>
 DIE *DwarfCompileUnit::constructVariableDIEImpl(const DbgVariable &DV,<br>
                                                 bool Abstract) {<br>
   // Define variable debug information entry.<br>
@@ -699,6 +711,9 @@ DIE *DwarfCompileUnit::createScopeChildr<br>
   if (HasNonScopeChildren)<br>
     *HasNonScopeChildren = !Children.empty();<br>
<br>
+  for (DbgLabel *DL : DU->getScopeLabels().lookup(Scope))<br>
+    Children.push_back(constructLabelDIE(*DL, *Scope));<br>
+<br>
   for (LexicalScope *LS : Scope->getChildren())<br>
     constructScopeDIE(LS, Children);<br>
<br>
@@ -824,40 +839,52 @@ void DwarfCompileUnit::finishSubprogramD<br>
   }<br>
 }<br>
<br>
-void DwarfCompileUnit::finishVariableDefinition(const DbgVariable &Var) {<br>
-  DbgVariable *AbsVar = getExistingAbstractVariable(<br>
-      InlinedVariable(Var.getVariable(), Var.getInlinedAt()));<br>
-  auto *VariableDie = Var.getDIE();<br>
-  if (AbsVar && AbsVar->getDIE()) {<br>
-    addDIEEntry(*VariableDie, dwarf::DW_AT_abstract_origin,<br>
-                      *AbsVar->getDIE());<br>
-  } else<br>
-    applyVariableAttributes(Var, *VariableDie);<br>
-}<br>
-<br>
-DbgVariable *DwarfCompileUnit::getExistingAbstractVariable(InlinedVariable IV) {<br>
-  const DILocalVariable *Cleansed;<br>
-  return getExistingAbstractVariable(IV, Cleansed);<br>
-}<br>
-<br>
-// Find abstract variable, if any, associated with Var.<br>
-DbgVariable *DwarfCompileUnit::getExistingAbstractVariable(<br>
-    InlinedVariable IV, const DILocalVariable *&Cleansed) {<br>
-  // More then one inlined variable corresponds to one abstract variable.<br>
-  Cleansed = IV.first;<br>
-  auto &AbstractVariables = getAbstractVariables();<br>
-  auto I = AbstractVariables.find(Cleansed);<br>
-  if (I != AbstractVariables.end())<br>
+void DwarfCompileUnit::finishEntityDefinition(const DbgEntity *Entity) {<br>
+  DbgEntity *AbsEntity = getExistingAbstractEntity(Entity->getEntity());<br>
+<br>
+  auto *Die = Entity->getDIE();<br>
+  /// Label may be used to generate DW_AT_low_pc, so put it outside<br>
+  /// if/else block.<br>
+  const DbgLabel *Label = nullptr;<br>
+  if (AbsEntity && AbsEntity->getDIE()) {<br>
+    addDIEEntry(*Die, dwarf::DW_AT_abstract_origin, *AbsEntity->getDIE());<br>
+    Label = dyn_cast<const DbgLabel>(Entity);<br>
+  } else {<br>
+    if (const DbgVariable *Var = dyn_cast<const DbgVariable>(Entity))<br>
+      applyVariableAttributes(*Var, *Die);<br>
+    else if ((Label = dyn_cast<const DbgLabel>(Entity)))<br>
+      applyLabelAttributes(*Label, *Die);<br>
+    else<br>
+      llvm_unreachable("DbgEntity must be DbgVariable or DbgLabel.");<br>
+  }<br>
+<br>
+  if (Label) {<br>
+    const MCSymbol *Sym = Label->getSymbol();<br>
+    addLabelAddress(*Die, dwarf::DW_AT_low_pc, Sym);<br>
+  }<br>
+}<br>
+<br>
+DbgEntity *DwarfCompileUnit::getExistingAbstractEntity(const DINode *Node) {<br>
+  auto &AbstractEntities = getAbstractEntities();<br>
+  auto I = AbstractEntities.find(Node);<br>
+  if (I != AbstractEntities.end())<br>
     return I->second.get();<br>
   return nullptr;<br>
 }<br>
<br>
-void DwarfCompileUnit::createAbstractVariable(const DILocalVariable *Var,<br>
-                                        LexicalScope *Scope) {<br>
+void DwarfCompileUnit::createAbstractEntity(const DINode *Node,<br>
+                                            LexicalScope *Scope) {<br>
   assert(Scope && Scope->isAbstractScope());<br>
-  auto AbsDbgVariable = llvm::make_unique<DbgVariable>(Var, /* IA */ nullptr);<br>
-  DU->addScopeVariable(Scope, AbsDbgVariable.get());<br>
-  getAbstractVariables()[Var] = std::move(AbsDbgVariable);<br>
+  auto &Entity = getAbstractEntities()[Node];<br>
+  if (isa<const DILocalVariable>(Node)) {<br>
+    Entity = llvm::make_unique<DbgVariable>(<br>
+                        cast<const DILocalVariable>(Node), nullptr /* IA */);;<br>
+    DU->addScopeVariable(Scope, cast<DbgVariable>(Entity.get()));<br>
+  } else if (isa<const DILabel>(Node)) {<br>
+    Entity = llvm::make_unique<DbgLabel>(<br>
+                        cast<const DILabel>(Node), nullptr /* IA */);<br>
+    DU->addScopeLabel(Scope, cast<DbgLabel>(Entity.get()));<br>
+  }<br>
 }<br>
<br>
 void DwarfCompileUnit::emitHeader(bool UseOffsets) {<br>
@@ -1012,6 +1039,15 @@ void DwarfCompileUnit::applyVariableAttr<br>
     addFlag(VariableDie, dwarf::DW_AT_artificial);<br>
 }<br>
<br>
+void DwarfCompileUnit::applyLabelAttributes(const DbgLabel &Label,<br>
+                                            DIE &LabelDie) {<br>
+  StringRef Name = Label.getName();<br>
+  if (!Name.empty())<br>
+    addString(LabelDie, dwarf::DW_AT_name, Name);<br>
+  const auto *DILabel = Label.getLabel();<br>
+  addSourceLine(LabelDie, DILabel);<br>
+}<br>
+<br>
 /// Add a Dwarf expression attribute data and value.<br>
 void DwarfCompileUnit::addExpr(DIELoc &Die, dwarf::Form Form,<br>
                                const MCExpr *Expr) {<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h?rev=338390&r1=338389&r2=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h Tue Jul 31 07:48:32 2018<br>
@@ -14,7 +14,7 @@<br>
 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H<br>
 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H<br>
<br>
-#include "DbgValueHistoryCalculator.h"<br>
+#include "DbgEntityHistoryCalculator.h"<br>
 #include "DwarfDebug.h"<br>
 #include "DwarfUnit.h"<br>
 #include "llvm/ADT/ArrayRef.h"<br>
@@ -81,7 +81,7 @@ class DwarfCompileUnit final : public Dw<br>
   const MCSymbol *BaseAddress = nullptr;<br>
<br>
   DenseMap<const MDNode *, DIE *> AbstractSPDies;<br>
-  DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;<br>
+  DenseMap<const DINode *, std::unique_ptr<DbgEntity>> AbstractEntities;<br>
<br>
   /// DWO ID for correlating skeleton and split units.<br>
   uint64_t DWOId = 0;<br>
@@ -98,10 +98,10 @@ class DwarfCompileUnit final : public Dw<br>
     return DU->getAbstractSPDies();<br>
   }<br>
<br>
-  DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> &getAbstractVariables() {<br>
+  DenseMap<const DINode *, std::unique_ptr<DbgEntity>> &getAbstractEntities() {<br>
     if (isDwoUnit() && !DD->shareAcrossDWOCUs())<br>
-      return AbstractVariables;<br>
-    return DU->getAbstractVariables();<br>
+      return AbstractEntities;<br>
+    return DU->getAbstractEntities();<br>
   }<br>
<br>
 public:<br>
@@ -194,6 +194,9 @@ public:<br>
   DIE *constructVariableDIE(DbgVariable &DV, const LexicalScope &Scope,<br>
                             DIE *&ObjectPointer);<br>
<br>
+  /// Construct a DIE for the given DbgLabel.<br>
+  DIE *constructLabelDIE(DbgLabel &DL, const LexicalScope &Scope);<br>
+<br>
   /// A helper function to create children of a Scope DIE.<br>
   DIE *createScopeChildrenDIE(LexicalScope *Scope,<br>
                               SmallVectorImpl<DIE *> &Children,<br>
@@ -210,14 +213,12 @@ public:<br>
   DIE *constructImportedEntityDIE(const DIImportedEntity *Module);<br>
<br>
   void finishSubprogramDefinition(const DISubprogram *SP);<br>
-  void finishVariableDefinition(const DbgVariable &Var);<br>
+  void finishEntityDefinition(const DbgEntity *Entity);<br>
<br>
   /// Find abstract variable associated with Var.<br>
   using InlinedVariable = DbgValueHistoryMap::InlinedVariable;<br>
-  DbgVariable *getExistingAbstractVariable(InlinedVariable IV,<br>
-                                           const DILocalVariable *&Cleansed);<br>
-  DbgVariable *getExistingAbstractVariable(InlinedVariable IV);<br>
-  void createAbstractVariable(const DILocalVariable *Var, LexicalScope *Scope);<br>
+  DbgEntity *getExistingAbstractEntity(const DINode *Node);<br>
+  void createAbstractEntity(const DINode *Node, LexicalScope *Scope);<br>
<br>
   /// Set the skeleton unit associated with this unit.<br>
   void setSkeleton(DwarfCompileUnit &Skel) { Skeleton = &Skel; }<br>
@@ -288,6 +289,8 @@ public:<br>
   void applySubprogramAttributesToDefinition(const DISubprogram *SP,<br>
                                              DIE &SPDie);<br>
<br>
+  void applyLabelAttributes(const DbgLabel &Label, DIE &LabelDie);<br>
+<br>
   /// getRangeLists - Get the vector of range lists.<br>
   const SmallVectorImpl<RangeSpanList> &getRangeLists() const {<br>
     return (Skeleton ? Skeleton : this)->CURangeLists;<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=338390&r1=338389&r2=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Jul 31 07:48:32 2018<br>
@@ -188,12 +188,12 @@ bool DebugLocDwarfExpression::isFrameReg<br>
 }<br>
<br>
 bool DbgVariable::isBlockByrefVariable() const {<br>
-  assert(Var && "Invalid complex DbgVariable!");<br>
-  return Var->getType().resolve()->isBlockByrefStruct();<br>
+  assert(getVariable() && "Invalid complex DbgVariable!");<br>
+  return getVariable()->getType().resolve()->isBlockByrefStruct();<br>
 }<br>
<br>
 const DIType *DbgVariable::getType() const {<br>
-  DIType *Ty = Var->getType().resolve();<br>
+  DIType *Ty = getVariable()->getType().resolve();<br>
   // FIXME: isBlockByrefVariable should be reformulated in terms of complex<br>
   // addresses instead.<br>
   if (Ty->isBlockByrefStruct()) {<br>
@@ -258,8 +258,8 @@ ArrayRef<DbgVariable::FrameIndexExpr> Db<br>
 void DbgVariable::addMMIEntry(const DbgVariable &V) {<br>
   assert(DebugLocListIndex == ~0U && !MInsn && "not an MMI entry");<br>
   assert(V.DebugLocListIndex == ~0U && !V.MInsn && "not an MMI entry");<br>
-  assert(V.Var == Var && "conflicting variable");<br>
-  assert(V.IA == IA && "conflicting inlined-at location");<br>
+  assert(V.getVariable() == getVariable() && "conflicting variable");<br>
+  assert(V.getInlinedAt() == getInlinedAt() && "conflicting inlined-at location");<br>
<br>
   assert(!FrameIndexExprs.empty() && "Expected an MMI entry");<br>
   assert(!V.FrameIndexExprs.empty() && "Expected an MMI entry");<br>
@@ -726,16 +726,16 @@ void DwarfDebug::beginModule() {<br>
   }<br>
 }<br>
<br>
-void DwarfDebug::finishVariableDefinitions() {<br>
-  for (const auto &Var : ConcreteVariables) {<br>
-    DIE *VariableDie = Var->getDIE();<br>
-    assert(VariableDie);<br>
+void DwarfDebug::finishEntityDefinitions() {<br>
+  for (const auto &Entity : ConcreteEntities) {<br>
+    DIE *Die = Entity->getDIE();<br>
+    assert(Die);<br>
     // FIXME: Consider the time-space tradeoff of just storing the unit pointer<br>
-    // in the ConcreteVariables list, rather than looking it up again here.<br>
+    // in the ConcreteEntities list, rather than looking it up again here.<br>
     // DIE::getUnit isn't simple - it walks parent pointers, etc.<br>
-    DwarfCompileUnit *Unit = CUDieMap.lookup(VariableDie->getUnitDie());<br>
+    DwarfCompileUnit *Unit = CUDieMap.lookup(Die->getUnitDie());<br>
     assert(Unit);<br>
-    Unit->finishVariableDefinition(*Var);<br>
+    Unit->finishEntityDefinition(Entity.get());<br>
   }<br>
 }<br>
<br>
@@ -753,7 +753,7 @@ void DwarfDebug::finalizeModuleInfo() {<br>
<br>
   finishSubprogramDefinitions();<br>
<br>
-  finishVariableDefinitions();<br>
+  finishEntityDefinitions();<br>
<br>
   // Include the DWO file name in the hash if there's more than one CU.<br>
   // This handles ThinLTO's situation where imported CUs may very easily be<br>
@@ -914,25 +914,24 @@ void DwarfDebug::endModule() {<br>
   // FIXME: AbstractVariables.clear();<br>
 }<br>
<br>
-void DwarfDebug::ensureAbstractVariableIsCreated(DwarfCompileUnit &CU, InlinedVariable IV,<br>
-                                                 const MDNode *ScopeNode) {<br>
-  const DILocalVariable *Cleansed = nullptr;<br>
-  if (CU.getExistingAbstractVariable(IV, Cleansed))<br>
+void DwarfDebug::ensureAbstractEntityIsCreated(DwarfCompileUnit &CU,<br>
+                                               const DINode *Node,<br>
+                                               const MDNode *ScopeNode) {<br>
+  if (CU.getExistingAbstractEntity(Node))<br>
     return;<br>
<br>
-  CU.createAbstractVariable(Cleansed, LScopes.getOrCreateAbstractScope(<br>
+  CU.createAbstractEntity(Node, LScopes.getOrCreateAbstractScope(<br>
                                        cast<DILocalScope>(ScopeNode)));<br>
 }<br>
<br>
-void DwarfDebug::ensureAbstractVariableIsCreatedIfScoped(DwarfCompileUnit &CU,<br>
-    InlinedVariable IV, const MDNode *ScopeNode) {<br>
-  const DILocalVariable *Cleansed = nullptr;<br>
-  if (CU.getExistingAbstractVariable(IV, Cleansed))<br>
+void DwarfDebug::ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU,<br>
+    const DINode *Node, const MDNode *ScopeNode) {<br>
+  if (CU.getExistingAbstractEntity(Node))<br>
     return;<br>
<br>
   if (LexicalScope *Scope =<br>
           LScopes.findAbstractScope(cast_or_null<DILocalScope>(ScopeNode)))<br>
-    CU.createAbstractVariable(Cleansed, Scope);<br>
+    CU.createAbstractEntity(Node, Scope);<br>
 }<br>
<br>
 // Collect variable information from side table maintained by MF.<br>
@@ -953,14 +952,14 @@ void DwarfDebug::collectVariableInfoFrom<br>
     if (!Scope)<br>
       continue;<br>
<br>
-    ensureAbstractVariableIsCreatedIfScoped(TheCU, Var, Scope->getScopeNode());<br>
+    ensureAbstractEntityIsCreatedIfScoped(TheCU, Var.first, Scope->getScopeNode());<br>
     auto RegVar = llvm::make_unique<DbgVariable>(Var.first, Var.second);<br>
     RegVar->initializeMMI(VI.Expr, VI.Slot);<br>
     if (DbgVariable *DbgVar = MFVars.lookup(Var))<br>
       DbgVar->addMMIEntry(*RegVar);<br>
     else if (InfoHolder.addScopeVariable(Scope, RegVar.get())) {<br>
       MFVars.insert({Var, RegVar.get()});<br>
-      ConcreteVariables.push_back(std::move(RegVar));<br>
+      ConcreteEntities.push_back(std::move(RegVar));<br>
     }<br>
   }<br>
 }<br>
@@ -1125,14 +1124,26 @@ DwarfDebug::buildLocationList(SmallVecto<br>
   }<br>
 }<br>
<br>
-DbgVariable *DwarfDebug::createConcreteVariable(DwarfCompileUnit &TheCU,<br>
-                                                LexicalScope &Scope,<br>
-                                                InlinedVariable IV) {<br>
-  ensureAbstractVariableIsCreatedIfScoped(TheCU, IV, Scope.getScopeNode());<br>
-  ConcreteVariables.push_back(<br>
-      llvm::make_unique<DbgVariable>(IV.first, IV.second));<br>
-  InfoHolder.addScopeVariable(&Scope, ConcreteVariables.back().get());<br>
-  return ConcreteVariables.back().get();<br>
+DbgEntity *DwarfDebug::createConcreteEntity(DwarfCompileUnit &TheCU,<br>
+                                            LexicalScope &Scope,<br>
+                                            const DINode *Node,<br>
+                                            const DILocation *Location,<br>
+                                            const MCSymbol *Sym) {<br>
+  ensureAbstractEntityIsCreatedIfScoped(TheCU, Node, Scope.getScopeNode());<br>
+  if (isa<const DILocalVariable>(Node)) {<br>
+    ConcreteEntities.push_back(<br>
+        llvm::make_unique<DbgVariable>(cast<const DILocalVariable>(Node),<br>
+                                       Location));<br>
+    InfoHolder.addScopeVariable(&Scope,<br>
+        cast<DbgVariable>(ConcreteEntities.back().get()));<br>
+  } else if (isa<const DILabel>(Node)) {<br>
+    ConcreteEntities.push_back(<br>
+        llvm::make_unique<DbgLabel>(cast<const DILabel>(Node),<br>
+                                    Location, Sym));<br>
+    InfoHolder.addScopeLabel(&Scope,<br>
+        cast<DbgLabel>(ConcreteEntities.back().get()));<br>
+  }<br>
+  return ConcreteEntities.back().get();<br>
 }<br>
<br>
 /// Determine whether a *singular* DBG_VALUE is valid for the entirety of its<br>
@@ -1194,9 +1205,9 @@ static bool validThroughout(LexicalScope<br>
 }<br>
<br>
 // Find variables for each lexical scope.<br>
-void DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU,<br>
-                                     const DISubprogram *SP,<br>
-                                     DenseSet<InlinedVariable> &Processed) {<br>
+void DwarfDebug::collectEntityInfo(DwarfCompileUnit &TheCU,<br>
+                                   const DISubprogram *SP,<br>
+                                   DenseSet<InlinedVariable> &Processed) {<br>
   // Grab the variable info that was squirreled away in the MMI side-table.<br>
   collectVariableInfoFromMFTable(TheCU, Processed);<br>
<br>
@@ -1220,7 +1231,8 @@ void DwarfDebug::collectVariableInfo(Dwa<br>
       continue;<br>
<br>
     Processed.insert(IV);<br>
-    DbgVariable *RegVar = createConcreteVariable(TheCU, *Scope, IV);<br>
+    DbgVariable *RegVar = cast<DbgVariable>(createConcreteEntity(TheCU,<br>
+                                            *Scope, IV.first, IV.second));<br>
<br>
     const MachineInstr *MInsn = Ranges.front().first;<br>
     assert(MInsn->isDebugValue() && "History must begin with debug value");<br>
@@ -1253,13 +1265,44 @@ void DwarfDebug::collectVariableInfo(Dwa<br>
       Entry.finalize(*Asm, List, BT);<br>
   }<br>
<br>
-  // Collect info for variables that were optimized out.<br>
+  // For each InlinedLabel collected from DBG_LABEL instructions, convert to<br>
+  // DWARF-related DbgLabel.<br>
+  for (const auto &I : DbgLabels) {<br>
+    InlinedLabel IL = I.first;<br>
+    const MachineInstr *MI = I.second;<br>
+    if (MI == nullptr)<br>
+      continue;<br>
+<br>
+    LexicalScope *Scope = nullptr;<br>
+    // Get inlined DILocation if it is inlined label.<br>
+    if (const DILocation *IA = IL.second)<br>
+      Scope = LScopes.findInlinedScope(IL.first->getScope(), IA);<br>
+    else<br>
+      Scope = LScopes.findLexicalScope(IL.first->getScope());<br>
+    // If label scope is not found then skip this label.<br>
+    if (!Scope)<br>
+      continue;<br>
+<br>
+    /// At this point, the temporary label is created.<br>
+    /// Save the temporary label to DbgLabel entity to get the<br>
+    /// actually address when generating Dwarf DIE.<br>
+    MCSymbol *Sym = getLabelBeforeInsn(MI);<br>
+    createConcreteEntity(TheCU, *Scope, IL.first, IL.second, Sym);<br>
+  }<br>
+<br>
+  // Collect info for variables/labels that were optimized out.<br>
   for (const DINode *DN : SP->getRetainedNodes()) {<br>
+    LexicalScope *Scope = nullptr;<br>
     if (auto *DV = dyn_cast<DILocalVariable>(DN)) {<br>
-      if (Processed.insert(InlinedVariable(DV, nullptr)).second)<br>
-        if (LexicalScope *Scope = LScopes.findLexicalScope(DV->getScope()))<br>
-          createConcreteVariable(TheCU, *Scope, InlinedVariable(DV, nullptr));<br>
+      if (!Processed.insert(InlinedVariable(DV, nullptr)).second)<br>
+        continue;<br>
+      Scope = LScopes.findLexicalScope(DV->getScope());<br>
+    } else if (auto *DL = dyn_cast<DILabel>(DN)) {<br>
+      Scope = LScopes.findLexicalScope(DL->getScope());<br>
     }<br>
+<br>
+    if (Scope)<br>
+      createConcreteEntity(TheCU, *Scope, DN, nullptr);<br>
   }<br>
 }<br>
<br>
@@ -1417,7 +1460,7 @@ void DwarfDebug::endFunctionImpl(const M<br>
   DwarfCompileUnit &TheCU = *CUMap.lookup(SP->getUnit());<br>
<br>
   DenseSet<InlinedVariable> ProcessedVars;<br>
-  collectVariableInfo(TheCU, SP, ProcessedVars);<br>
+  collectEntityInfo(TheCU, SP, ProcessedVars);<br>
<br>
   // Add the range of this function to the list of ranges for the CU.<br>
   TheCU.addRange(RangeSpan(Asm->getFunctionBegin(), Asm->getFunctionEnd()));<br>
@@ -1445,10 +1488,11 @@ void DwarfDebug::endFunctionImpl(const M<br>
         // Collect info for variables that were optimized out.<br>
         if (!ProcessedVars.insert(InlinedVariable(DV, nullptr)).second)<br>
           continue;<br>
-        ensureAbstractVariableIsCreated(TheCU, InlinedVariable(DV, nullptr),<br>
-                                        DV->getScope());<br>
+        ensureAbstractEntityIsCreated(TheCU, DV, DV->getScope());<br>
         assert(LScopes.getAbstractScopesList().size() == NumAbstractScopes<br>
-               && "ensureAbstractVariableIsCreated inserted abstract scopes");<br>
+               && "ensureAbstractEntityIsCreated inserted abstract scopes");<br>
+      } else if (auto *DL = dyn_cast<DILabel>(DN)) {<br>
+        ensureAbstractEntityIsCreated(TheCU, DL, DL->getScope());<br>
       }<br>
     }<br>
     constructAbstractSubprogramScopeDIE(TheCU, AScope);<br>
@@ -1466,6 +1510,7 @@ void DwarfDebug::endFunctionImpl(const M<br>
   // DbgVariables except those that are also in AbstractVariables (since they<br>
   // can be used cross-function)<br>
   InfoHolder.getScopeVariables().clear();<br>
+  InfoHolder.getScopeLabels().clear();<br>
   PrevLabel = nullptr;<br>
   CurFn = nullptr;<br>
 }<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=338390&r1=338389&r2=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Tue Jul 31 07:48:32 2018<br>
@@ -15,7 +15,7 @@<br>
 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H<br>
<br>
 #include "AddressPool.h"<br>
-#include "DbgValueHistoryCalculator.h"<br>
+#include "DbgEntityHistoryCalculator.h"<br>
 #include "DebugHandlerBase.h"<br>
 #include "DebugLocStream.h"<br>
 #include "DwarfFile.h"<br>
@@ -62,6 +62,46 @@ class MDNode;<br>
 class Module;<br>
<br>
 //===----------------------------------------------------------------------===//<br>
+/// This class is defined as the common parent of DbgVariable and DbgLabel<br>
+/// such that it could levarage polymorphism to extract common code for<br>
+/// DbgVariable and DbgLabel.<br>
+class DbgEntity {<br>
+  const DINode *Entity;<br>
+  const DILocation *InlinedAt;<br>
+  DIE *TheDIE = nullptr;<br>
+  unsigned SubclassID;<br>
+<br>
+public:<br>
+  enum DbgEntityKind {<br>
+    DbgVariableKind,<br>
+    DbgLabelKind<br>
+  };<br>
+<br>
+  DbgEntity(const DINode *N, const DILocation *IA, unsigned ID)<br>
+    : Entity(N), InlinedAt(IA), SubclassID(ID) {}<br>
+<br>
+  /// Accessors.<br>
+  /// @{<br>
+  const DINode *getEntity() const { return Entity; }<br>
+  const DILocation *getInlinedAt() const { return InlinedAt; }<br>
+  DIE *getDIE() const { return TheDIE; }<br>
+  unsigned getDbgEntityID() const { return SubclassID; }<br>
+  /// @}<br>
+<br>
+  void setDIE(DIE &D) { TheDIE = &D; }<br>
+<br>
+  static bool classof(const DbgEntity *N) {<br>
+    switch (N->getDbgEntityID()) {<br>
+    default:<br>
+      return false;<br>
+    case DbgVariableKind:<br>
+    case DbgLabelKind:<br>
+      return true;<br>
+    }<br>
+  }<br>
+};<br>
+<br>
+//===----------------------------------------------------------------------===//<br>
 /// This class is used to track local variable information.<br>
 ///<br>
 /// Variables can be created from allocas, in which case they're generated from<br>
@@ -73,10 +113,7 @@ class Module;<br>
 /// single instruction use \a MInsn and (optionally) a single entry of \a Expr.<br>
 ///<br>
 /// Variables that have been optimized out use none of these fields.<br>
-class DbgVariable {<br>
-  const DILocalVariable *Var;                /// Variable Descriptor.<br>
-  const DILocation *IA;                      /// Inlined at location.<br>
-  DIE *TheDIE = nullptr;                     /// Variable DIE.<br>
+class DbgVariable : public DbgEntity {<br>
   unsigned DebugLocListIndex = ~0u;          /// Offset in DebugLocs.<br>
   const MachineInstr *MInsn = nullptr;       /// DBG_VALUE instruction.<br>
<br>
@@ -93,7 +130,7 @@ public:<br>
   /// Creates a variable without any DW_AT_location.  Call \a initializeMMI()<br>
   /// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions.<br>
   DbgVariable(const DILocalVariable *V, const DILocation *IA)<br>
-      : Var(V), IA(IA) {}<br>
+      : DbgEntity(V, IA, DbgVariableKind) {}<br>
<br>
   /// Initialize from the MMI table.<br>
   void initializeMMI(const DIExpression *E, int FI) {<br>
@@ -111,8 +148,9 @@ public:<br>
     assert(FrameIndexExprs.empty() && "Already initialized?");<br>
     assert(!MInsn && "Already initialized?");<br>
<br>
-    assert(Var == DbgValue->getDebugVariable() && "Wrong variable");<br>
-    assert(IA == DbgValue->getDebugLoc()->getInlinedAt() && "Wrong inlined-at");<br>
+    assert(getVariable() == DbgValue->getDebugVariable() && "Wrong variable");<br>
+    assert(getInlinedAt() == DbgValue->getDebugLoc()->getInlinedAt() &&<br>
+           "Wrong inlined-at");<br>
<br>
     MInsn = DbgValue;<br>
     if (auto *E = DbgValue->getDebugExpression())<br>
@@ -121,19 +159,18 @@ public:<br>
   }<br>
<br>
   // Accessors.<br>
-  const DILocalVariable *getVariable() const { return Var; }<br>
-  const DILocation *getInlinedAt() const { return IA; }<br>
+  const DILocalVariable *getVariable() const {<br>
+    return cast<DILocalVariable>(getEntity());<br>
+  }<br>
<br>
   const DIExpression *getSingleExpression() const {<br>
     assert(MInsn && FrameIndexExprs.size() <= 1);<br>
     return FrameIndexExprs.size() ? FrameIndexExprs[0].Expr : nullptr;<br>
   }<br>
<br>
-  void setDIE(DIE &D) { TheDIE = &D; }<br>
-  DIE *getDIE() const { return TheDIE; }<br>
   void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; }<br>
   unsigned getDebugLocListIndex() const { return DebugLocListIndex; }<br>
-  StringRef getName() const { return Var->getName(); }<br>
+  StringRef getName() const { return getVariable()->getName(); }<br>
   const MachineInstr *getMInsn() const { return MInsn; }<br>
   /// Get the FI entries, sorted by fragment offset.<br>
   ArrayRef<FrameIndexExpr> getFrameIndexExprs() const;<br>
@@ -143,7 +180,7 @@ public:<br>
   // Translate tag to proper Dwarf tag.<br>
   dwarf::Tag getTag() const {<br>
     // FIXME: Why don't we just infer this tag and store it all along?<br>
-    if (Var->isParameter())<br>
+    if (getVariable()->isParameter())<br>
       return dwarf::DW_TAG_formal_parameter;<br>
<br>
     return dwarf::DW_TAG_variable;<br>
@@ -151,7 +188,7 @@ public:<br>
<br>
   /// Return true if DbgVariable is artificial.<br>
   bool isArtificial() const {<br>
-    if (Var->isArtificial())<br>
+    if (getVariable()->isArtificial())<br>
       return true;<br>
     if (getType()->isArtificial())<br>
       return true;<br>
@@ -159,7 +196,7 @@ public:<br>
   }<br>
<br>
   bool isObjectPointer() const {<br>
-    if (Var->isObjectPointer())<br>
+    if (getVariable()->isObjectPointer())<br>
       return true;<br>
     if (getType()->isObjectPointer())<br>
       return true;<br>
@@ -178,6 +215,45 @@ public:<br>
   bool isBlockByrefVariable() const;<br>
   const DIType *getType() const;<br>
<br>
+  static bool classof(const DbgEntity *N) {<br>
+    return N->getDbgEntityID() == DbgVariableKind;<br>
+  }<br>
+<br>
+private:<br>
+  template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {<br>
+    return Ref.resolve();<br>
+  }<br>
+};<br>
+<br>
+//===----------------------------------------------------------------------===//<br>
+/// This class is used to track label information.<br>
+///<br>
+/// Labels are collected from \c DBG_LABEL instructions.<br>
+class DbgLabel : public DbgEntity {<br>
+  const MCSymbol *Sym;                  /// Symbol before DBG_LABEL instruction.<br>
+<br>
+public:<br>
+  /// We need MCSymbol information to generate DW_AT_low_pc.<br>
+  DbgLabel(const DILabel *L, const DILocation *IA, const MCSymbol *Sym = nullptr)<br>
+      : DbgEntity(L, IA, DbgLabelKind), Sym(Sym) {}<br>
+<br>
+  /// Accessors.<br>
+  /// @{<br>
+  const DILabel *getLabel() const { return cast<DILabel>(getEntity()); }<br>
+  const MCSymbol *getSymbol() const { return Sym; }<br>
+<br>
+  StringRef getName() const { return getLabel()->getName(); }<br>
+  /// @}<br>
+<br>
+  /// Translate tag to proper Dwarf tag.<br>
+  dwarf::Tag getTag() const {<br>
+    return dwarf::DW_TAG_label;<br>
+  }<br>
+<br>
+  static bool classof(const DbgEntity *N) {<br>
+    return N->getDbgEntityID() == DbgLabelKind;<br>
+  }<br>
+<br>
 private:<br>
   template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {<br>
     return Ref.resolve();<br>
@@ -217,8 +293,8 @@ class DwarfDebug : public DebugHandlerBa<br>
   /// Size of each symbol emitted (for those symbols that have a specific size).<br>
   DenseMap<const MCSymbol *, uint64_t> SymSize;<br>
<br>
-  /// Collection of abstract variables.<br>
-  SmallVector<std::unique_ptr<DbgVariable>, 64> ConcreteVariables;<br>
+  /// Collection of abstract variables/labels.<br>
+  SmallVector<std::unique_ptr<DbgEntity>, 64> ConcreteEntities;<br>
<br>
   /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists<br>
   /// can refer to them in spite of insertions into this list.<br>
@@ -333,14 +409,20 @@ class DwarfDebug : public DebugHandlerBa<br>
   }<br>
<br>
   using InlinedVariable = DbgValueHistoryMap::InlinedVariable;<br>
+  using InlinedLabel = DbgLabelInstrMap::InlinedLabel;<br>
<br>
-  void ensureAbstractVariableIsCreated(DwarfCompileUnit &CU, InlinedVariable IV,<br>
-                                       const MDNode *Scope);<br>
-  void ensureAbstractVariableIsCreatedIfScoped(DwarfCompileUnit &CU, InlinedVariable IV,<br>
-                                               const MDNode *Scope);<br>
-<br>
-  DbgVariable *createConcreteVariable(DwarfCompileUnit &TheCU,<br>
-                                      LexicalScope &Scope, InlinedVariable IV);<br>
+  void ensureAbstractEntityIsCreated(DwarfCompileUnit &CU,<br>
+                                     const DINode *Node,<br>
+                                     const MDNode *Scope);<br>
+  void ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU,<br>
+                                             const DINode *Node,<br>
+                                             const MDNode *Scope);<br>
+<br>
+  DbgEntity *createConcreteEntity(DwarfCompileUnit &TheCU,<br>
+                                  LexicalScope &Scope,<br>
+                                  const DINode *Node,<br>
+                                  const DILocation *Location,<br>
+                                  const MCSymbol *Sym = nullptr);<br>
<br>
   /// Construct a DIE for this abstract scope.<br>
   void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);<br>
@@ -349,7 +431,7 @@ class DwarfDebug : public DebugHandlerBa<br>
   void addAccelNameImpl(AccelTable<DataT> &AppleAccel, StringRef Name,<br>
                         const DIE &Die);<br>
<br>
-  void finishVariableDefinitions();<br>
+  void finishEntityDefinitions();<br>
<br>
   void finishSubprogramDefinitions();<br>
<br>
@@ -466,8 +548,8 @@ class DwarfDebug : public DebugHandlerBa<br>
                         unsigned Flags);<br>
<br>
   /// Populate LexicalScope entries with variables' info.<br>
-  void collectVariableInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,<br>
-                           DenseSet<InlinedVariable> &ProcessedVars);<br>
+  void collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,<br>
+                         DenseSet<InlinedVariable> &ProcessedVars);<br>
<br>
   /// Build the location list for all DBG_VALUEs in the<br>
   /// function that describe the same variable.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp?rev=338390&r1=338389&r2=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp Tue Jul 31 07:48:32 2018<br>
@@ -98,3 +98,8 @@ bool DwarfFile::addScopeVariable(Lexical<br>
   }<br>
   return true;<br>
 }<br>
+<br>
+void DwarfFile::addScopeLabel(LexicalScope *LS, DbgLabel *Label) {<br>
+  SmallVectorImpl<DbgLabel *> &Labels = ScopeLabels[LS];<br>
+  Labels.push_back(Label);<br>
+}<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h?rev=338390&r1=338389&r2=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h Tue Jul 31 07:48:32 2018<br>
@@ -24,7 +24,9 @@<br>
 namespace llvm {<br>
<br>
 class AsmPrinter;<br>
+class DbgEntity;<br>
 class DbgVariable;<br>
+class DbgLabel;<br>
 class DwarfCompileUnit;<br>
 class DwarfUnit;<br>
 class LexicalScope;<br>
@@ -62,9 +64,13 @@ class DwarfFile {<br>
   /// Collection of DbgVariables of each lexical scope.<br>
   DenseMap<LexicalScope *, ScopeVars> ScopeVariables;<br>
<br>
+  /// Collection of DbgLabels of each lexical scope.<br>
+  using LabelList = SmallVector<DbgLabel *, 4>;<br>
+  DenseMap<LexicalScope *, LabelList> ScopeLabels;<br>
+<br>
   // Collection of abstract subprogram DIEs.<br>
   DenseMap<const MDNode *, DIE *> AbstractSPDies;<br>
-  DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;<br>
+  DenseMap<const DINode *, std::unique_ptr<DbgEntity>> AbstractEntities;<br>
<br>
   /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can<br>
   /// be shared across CUs, that is why we keep the map here instead<br>
@@ -122,16 +128,22 @@ public:<br>
   /// \returns false if the variable was merged with a previous one.<br>
   bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);<br>
<br>
+  void addScopeLabel(LexicalScope *LS, DbgLabel *Label);<br>
+<br>
   DenseMap<LexicalScope *, ScopeVars> &getScopeVariables() {<br>
     return ScopeVariables;<br>
   }<br>
<br>
+  DenseMap<LexicalScope *, LabelList> &getScopeLabels() {<br>
+    return ScopeLabels;<br>
+  }<br>
+<br>
   DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {<br>
     return AbstractSPDies;<br>
   }<br>
<br>
-  DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> &getAbstractVariables() {<br>
-    return AbstractVariables;<br>
+  DenseMap<const DINode *, std::unique_ptr<DbgEntity>> &getAbstractEntities() {<br>
+    return AbstractEntities;<br>
   }<br>
<br>
   void insertDIE(const MDNode *TypeMD, DIE *Die) {<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=338390&r1=338389&r2=338390&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Tue Jul 31 07:48:32 2018<br>
@@ -401,6 +401,12 @@ void DwarfUnit::addSourceLine(DIE &Die,<br>
   addSourceLine(Die, SP->getLine(), SP->getFile());<br>
 }<br>
<br>
+void DwarfUnit::addSourceLine(DIE &Die, const DILabel *L) {<br>
+  assert(L);<br>
+<br>
+  addSourceLine(Die, L->getLine(), L->getFile());<br>
+}<br>
+<br>
 void DwarfUnit::addSourceLine(DIE &Die, const DIType *Ty) {<br>
   assert(Ty);<br>
<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h?rev=338390&r1=338389&r2=338390&view=diff" rel="noreferrer" target="_blank"></a></blockquote></div>