[llvm] r260432 - [codeview] Describe int local variables using .cv_def_range

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 10 12:55:50 PST 2016


Author: rnk
Date: Wed Feb 10 14:55:49 2016
New Revision: 260432

URL: http://llvm.org/viewvc/llvm-project?rev=260432&view=rev
Log:
[codeview] Describe int local variables using .cv_def_range

Summary:
Refactor common value, scope, and label tracking logic out of DwarfDebug
into a common base class called DebugHandlerBase.

Update an old LLVM IR test case to avoid an assertion in LexicalScopes.

Reviewers: dblaikie, majnemer

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D16931

Added:
    llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h
    llvm/trunk/test/DebugInfo/COFF/local-variables.ll
Modified:
    llvm/trunk/include/llvm/MC/MCRegisterInfo.h
    llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
    llvm/trunk/lib/MC/MCRegisterInfo.cpp
    llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
    llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h
    llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp
    llvm/trunk/test/DebugInfo/COFF/asm.ll
    llvm/trunk/test/DebugInfo/COFF/inlining.ll
    llvm/trunk/test/DebugInfo/COFF/multifile.ll
    llvm/trunk/test/DebugInfo/COFF/multifunction.ll
    llvm/trunk/test/DebugInfo/COFF/simple.ll
    llvm/trunk/test/DebugInfo/COFF/tail-call-without-lexical-scopes.ll

Modified: llvm/trunk/include/llvm/MC/MCRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCRegisterInfo.h?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCRegisterInfo.h (original)
+++ llvm/trunk/include/llvm/MC/MCRegisterInfo.h Wed Feb 10 14:55:49 2016
@@ -182,6 +182,7 @@ private:
   const DwarfLLVMRegPair *Dwarf2LRegs;        // Dwarf to LLVM regs mapping
   const DwarfLLVMRegPair *EHDwarf2LRegs;      // Dwarf to LLVM regs mapping EH
   DenseMap<unsigned, int> L2SEHRegs;          // LLVM to SEH regs mapping
+  DenseMap<unsigned, int> L2CVRegs;           // LLVM to CV regs mapping
 
 public:
   /// DiffListIterator - Base iterator class that can traverse the
@@ -309,6 +310,10 @@ public:
     L2SEHRegs[LLVMReg] = SEHReg;
   }
 
+  void mapLLVMRegToCVReg(unsigned LLVMReg, int CVReg) {
+    L2CVRegs[LLVMReg] = CVReg;
+  }
+
   /// \brief This method should return the register where the return
   /// address can be found.
   unsigned getRARegister() const {
@@ -396,6 +401,10 @@ public:
   /// number.  Returns LLVM register number if there is no equivalent value.
   int getSEHRegNum(unsigned RegNum) const;
 
+  /// \brief Map a target register to an equivalent CodeView register
+  /// number.
+  int getCodeViewRegNum(unsigned RegNum) const;
+
   regclass_iterator regclass_begin() const { return Classes; }
   regclass_iterator regclass_end() const { return Classes+NumClasses; }
 

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt Wed Feb 10 14:55:49 2016
@@ -5,6 +5,7 @@ add_llvm_library(LLVMAsmPrinter
   AsmPrinterDwarf.cpp
   AsmPrinterInlineAsm.cpp
   DbgValueHistoryCalculator.cpp
+  DebugHandlerBase.cpp
   DebugLocStream.cpp
   DIE.cpp
   DIEHash.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Wed Feb 10 14:55:49 2016
@@ -20,10 +20,26 @@
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCSymbol.h"
 #include "llvm/Support/COFF.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
+#include "llvm/Target/TargetRegisterInfo.h"
+#include "llvm/Target/TargetFrameLowering.h"
 
+using namespace llvm;
 using namespace llvm::codeview;
 
-namespace llvm {
+CodeViewDebug::CodeViewDebug(AsmPrinter *AP)
+    : DebugHandlerBase(AP), OS(*Asm->OutStreamer), CurFn(nullptr) {
+  // If module doesn't have named metadata anchors or COFF debug section
+  // is not available, skip any debug info related stuff.
+  if (!MMI->getModule()->getNamedMetadata("llvm.dbg.cu") ||
+      !AP->getObjFileLowering().getCOFFDebugSymbolsSection()) {
+    Asm = nullptr;
+    return;
+  }
+
+  // Tell MMI that we have debug info.
+  MMI->setDebugInfoAvailability(true);
+}
 
 StringRef CodeViewDebug::getFullFilepath(const DIFile *File) {
   std::string &Filepath = FileToFilepathMap[File];
@@ -92,13 +108,13 @@ unsigned CodeViewDebug::maybeRecordFile(
 CodeViewDebug::InlineSite &CodeViewDebug::getInlineSite(const DILocation *Loc) {
   const DILocation *InlinedAt = Loc->getInlinedAt();
   auto Insertion = CurFn->InlineSites.insert({InlinedAt, InlineSite()});
+  InlineSite *Site = &Insertion.first->second;
   if (Insertion.second) {
-    InlineSite &Site = Insertion.first->second;
-    Site.SiteFuncId = NextFuncId++;
-    Site.Inlinee = Loc->getScope()->getSubprogram();
+    Site->SiteFuncId = NextFuncId++;
+    Site->Inlinee = Loc->getScope()->getSubprogram();
     InlinedSubprograms.insert(Loc->getScope()->getSubprogram());
   }
-  return Insertion.first->second;
+  return *Site;
 }
 
 void CodeViewDebug::maybeRecordLocation(DebugLoc DL,
@@ -135,6 +151,7 @@ void CodeViewDebug::maybeRecordLocation(
     // If this location was actually inlined from somewhere else, give it the ID
     // of the inline call site.
     FuncId = getInlineSite(DL.get()).SiteFuncId;
+    CurFn->ChildSites.push_back(Loc);
     // Ensure we have links in the tree of inline call sites.
     const DILocation *ChildLoc = nullptr;
     while (Loc->getInlinedAt()) {
@@ -155,22 +172,6 @@ void CodeViewDebug::maybeRecordLocation(
                         /*IsStmt=*/false, DL->getFilename());
 }
 
-CodeViewDebug::CodeViewDebug(AsmPrinter *AP)
-    : Asm(AP), OS(*Asm->OutStreamer), CurFn(nullptr) {
-  MachineModuleInfo *MMI = AP->MMI;
-
-  // If module doesn't have named metadata anchors or COFF debug section
-  // is not available, skip any debug info related stuff.
-  if (!MMI->getModule()->getNamedMetadata("llvm.dbg.cu") ||
-      !AP->getObjFileLowering().getCOFFDebugSymbolsSection()) {
-    Asm = nullptr;
-    return;
-  }
-
-  // Tell MMI that we have debug info.
-  MMI->setDebugInfoAvailability(true);
-}
-
 void CodeViewDebug::endModule() {
   if (FnDebugInfo.empty())
     return;
@@ -215,7 +216,7 @@ void CodeViewDebug::emitTypeInformation(
   OS.EmitIntValue(COFF::DEBUG_SECTION_MAGIC, 4);
 
   NamedMDNode *CU_Nodes =
-      Asm->MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
+      MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
   if (!CU_Nodes)
     return;
 
@@ -277,8 +278,8 @@ void CodeViewDebug::emitInlineeLinesSubs
   if (InlinedSubprograms.empty())
     return;
 
-  MCSymbol *InlineBegin = Asm->MMI->getContext().createTempSymbol(),
-           *InlineEnd = Asm->MMI->getContext().createTempSymbol();
+  MCSymbol *InlineBegin = MMI->getContext().createTempSymbol(),
+           *InlineEnd = MMI->getContext().createTempSymbol();
 
   OS.AddComment("Inlinee lines subsection");
   OS.EmitIntValue(unsigned(ModuleSubstreamKind::InlineeLines), 4);
@@ -317,7 +318,6 @@ void CodeViewDebug::collectInlineSiteChi
     const InlineSite &Site) {
   for (const DILocation *ChildSiteLoc : Site.ChildSites) {
     auto I = FI.InlineSites.find(ChildSiteLoc);
-    assert(I != FI.InlineSites.end());
     const InlineSite &ChildSite = I->second;
     Children.push_back(ChildSite.SiteFuncId);
     collectInlineSiteChildren(Children, FI, ChildSite);
@@ -327,8 +327,8 @@ void CodeViewDebug::collectInlineSiteChi
 void CodeViewDebug::emitInlinedCallSite(const FunctionInfo &FI,
                                         const DILocation *InlinedAt,
                                         const InlineSite &Site) {
-  MCSymbol *InlineBegin = Asm->MMI->getContext().createTempSymbol(),
-           *InlineEnd = Asm->MMI->getContext().createTempSymbol();
+  MCSymbol *InlineBegin = MMI->getContext().createTempSymbol(),
+           *InlineEnd = MMI->getContext().createTempSymbol();
 
   assert(SubprogramToFuncId.count(Site.Inlinee));
   TypeIndex InlineeIdx = SubprogramToFuncId[Site.Inlinee];
@@ -357,6 +357,9 @@ void CodeViewDebug::emitInlinedCallSite(
 
   OS.EmitLabel(InlineEnd);
 
+  for (const LocalVariable &Var : Site.InlinedLocals)
+    emitLocalVariable(Var);
+
   // Recurse on child inlined call sites before closing the scope.
   for (const DILocation *ChildSite : Site.ChildSites) {
     auto I = FI.InlineSites.find(ChildSite);
@@ -372,6 +375,13 @@ void CodeViewDebug::emitInlinedCallSite(
   OS.EmitIntValue(SymbolRecordKind::S_INLINESITE_END, 2); // RecordKind
 }
 
+static void emitNullTerminatedString(MCStreamer &OS, StringRef S) {
+  SmallString<32> NullTerminatedString(S);
+  if (NullTerminatedString.empty() || NullTerminatedString.back() != '\0')
+    NullTerminatedString.push_back('\0');
+  OS.EmitBytes(NullTerminatedString);
+}
+
 void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
                                              FunctionInfo &FI) {
   // For each function there is a separate subsection
@@ -388,16 +398,16 @@ void CodeViewDebug::emitDebugInfoForFunc
     FuncName = GlobalValue::getRealLinkageName(GV->getName());
 
   // Emit a symbol subsection, required by VS2012+ to find function boundaries.
-  MCSymbol *SymbolsBegin = Asm->MMI->getContext().createTempSymbol(),
-           *SymbolsEnd = Asm->MMI->getContext().createTempSymbol();
+  MCSymbol *SymbolsBegin = MMI->getContext().createTempSymbol(),
+           *SymbolsEnd = MMI->getContext().createTempSymbol();
   OS.AddComment("Symbol subsection for " + Twine(FuncName));
   OS.EmitIntValue(unsigned(ModuleSubstreamKind::Symbols), 4);
   OS.AddComment("Subsection size");
   OS.emitAbsoluteSymbolDiff(SymbolsEnd, SymbolsBegin, 4);
   OS.EmitLabel(SymbolsBegin);
   {
-    MCSymbol *ProcRecordBegin = Asm->MMI->getContext().createTempSymbol(),
-             *ProcRecordEnd = Asm->MMI->getContext().createTempSymbol();
+    MCSymbol *ProcRecordBegin = MMI->getContext().createTempSymbol(),
+             *ProcRecordEnd = MMI->getContext().createTempSymbol();
     OS.AddComment("Record length");
     OS.emitAbsoluteSymbolDiff(ProcRecordEnd, ProcRecordBegin, 2);
     OS.EmitLabel(ProcRecordBegin);
@@ -430,21 +440,20 @@ void CodeViewDebug::emitDebugInfoForFunc
     OS.EmitIntValue(0, 1);
     // Emit the function display name as a null-terminated string.
     OS.AddComment("Function name");
-    {
-      SmallString<32> NullTerminatedString(FuncName);
-      if (NullTerminatedString.empty() || NullTerminatedString.back() != '\0')
-        NullTerminatedString.push_back('\0');
-      OS.EmitBytes(NullTerminatedString);
-    }
+    emitNullTerminatedString(OS, FuncName);
     OS.EmitLabel(ProcRecordEnd);
 
+    for (const LocalVariable &Var : FI.Locals)
+      emitLocalVariable(Var);
+
     // Emit inlined call site information. Only emit functions inlined directly
     // into the parent function. We'll emit the other sites recursively as part
     // of their parent inline site.
-    for (auto &KV : FI.InlineSites) {
-      const DILocation *InlinedAt = KV.first;
-      if (!InlinedAt->getInlinedAt())
-        emitInlinedCallSite(FI, InlinedAt, KV.second);
+    for (const DILocation *InlinedAt : FI.ChildSites) {
+      auto I = FI.InlineSites.find(InlinedAt);
+      assert(I != FI.InlineSites.end() &&
+             "child site not in function inline site map");
+      emitInlinedCallSite(FI, InlinedAt, I->second);
     }
 
     // We're done with this function.
@@ -461,40 +470,80 @@ void CodeViewDebug::emitDebugInfoForFunc
   OS.EmitCVLinetableDirective(FI.FuncId, Fn, FI.End);
 }
 
+void CodeViewDebug::collectVariableInfoFromMMITable() {
+  for (const auto &VI : MMI->getVariableDbgInfo()) {
+    if (!VI.Var)
+      continue;
+    assert(VI.Var->isValidLocationForIntrinsic(VI.Loc) &&
+           "Expected inlined-at fields to agree");
+
+    LexicalScope *Scope = LScopes.findLexicalScope(VI.Loc);
+
+    // If variable scope is not found then skip this variable.
+    if (!Scope)
+      continue;
+
+    LocalVariable Var;
+    Var.DIVar = VI.Var;
+
+    // Get the frame register used and the offset.
+    unsigned FrameReg = 0;
+    const TargetSubtargetInfo &TSI = Asm->MF->getSubtarget();
+    const TargetFrameLowering *TFI = TSI.getFrameLowering();
+    const TargetRegisterInfo *TRI = TSI.getRegisterInfo();
+    Var.RegisterOffset = TFI->getFrameIndexReference(*Asm->MF, VI.Slot, FrameReg);
+    Var.CVRegister = TRI->getCodeViewRegNum(FrameReg);
+
+    // Calculate the label ranges.
+    for (const InsnRange &Range : Scope->getRanges()) {
+      const MCSymbol *Begin = getLabelBeforeInsn(Range.first);
+      const MCSymbol *End = getLabelAfterInsn(Range.second);
+      Var.Ranges.push_back({Begin, End});
+    }
+
+    if (VI.Loc->getInlinedAt()) {
+      // This variable was inlined. Associate it with the InlineSite.
+      InlineSite &Site = getInlineSite(VI.Loc);
+      Site.InlinedLocals.emplace_back(std::move(Var));
+    } else {
+      // This variable goes in the main ProcSym.
+      CurFn->Locals.emplace_back(std::move(Var));
+    }
+  }
+}
+
 void CodeViewDebug::beginFunction(const MachineFunction *MF) {
   assert(!CurFn && "Can't process two functions at once!");
 
-  if (!Asm || !Asm->MMI->hasDebugInfo())
+  if (!Asm || !MMI->hasDebugInfo())
     return;
 
+  DebugHandlerBase::beginFunction(MF);
+
   const Function *GV = MF->getFunction();
   assert(FnDebugInfo.count(GV) == false);
   CurFn = &FnDebugInfo[GV];
   CurFn->FuncId = NextFuncId++;
   CurFn->Begin = Asm->getFunctionBegin();
 
-  // Find the end of the function prolog.
+  // Find the end of the function prolog.  First known non-DBG_VALUE and
+  // non-frame setup location marks the beginning of the function body.
   // FIXME: is there a simpler a way to do this? Can we just search
   // for the first instruction of the function, not the last of the prolog?
   DebugLoc PrologEndLoc;
   bool EmptyPrologue = true;
   for (const auto &MBB : *MF) {
-    if (PrologEndLoc)
-      break;
     for (const auto &MI : MBB) {
-      if (MI.isDebugValue())
-        continue;
-
-      // First known non-DBG_VALUE and non-frame setup location marks
-      // the beginning of the function body.
-      // FIXME: do we need the first subcondition?
-      if (!MI.getFlag(MachineInstr::FrameSetup) && MI.getDebugLoc()) {
+      if (!MI.isDebugValue() && !MI.getFlag(MachineInstr::FrameSetup) &&
+          MI.getDebugLoc()) {
         PrologEndLoc = MI.getDebugLoc();
         break;
+      } else if (!MI.isDebugValue()) {
+        EmptyPrologue = false;
       }
-      EmptyPrologue = false;
     }
   }
+
   // Record beginning of function if we have a non-empty prologue.
   if (PrologEndLoc && !EmptyPrologue) {
     DebugLoc FnStartDL = PrologEndLoc.getFnDebugLoc();
@@ -502,7 +551,50 @@ void CodeViewDebug::beginFunction(const
   }
 }
 
+void CodeViewDebug::emitLocalVariable(const LocalVariable &Var) {
+  // LocalSym record, see SymbolRecord.h for more info.
+  MCSymbol *LocalBegin = MMI->getContext().createTempSymbol(),
+           *LocalEnd = MMI->getContext().createTempSymbol();
+  OS.AddComment("Record length");
+  OS.emitAbsoluteSymbolDiff(LocalEnd, LocalBegin, 2);
+  OS.EmitLabel(LocalBegin);
+
+  OS.AddComment("Record kind: S_LOCAL");
+  OS.EmitIntValue(unsigned(SymbolRecordKind::S_LOCAL), 2);
+
+  uint16_t Flags = 0;
+  if (Var.DIVar->isParameter())
+    Flags |= LocalSym::IsParameter;
+
+  OS.AddComment("TypeIndex");
+  OS.EmitIntValue(TypeIndex::Int32().getIndex(), 4);
+  OS.AddComment("Flags");
+  OS.EmitIntValue(Flags, 2);
+  emitNullTerminatedString(OS, Var.DIVar->getName());
+  OS.EmitLabel(LocalEnd);
+
+  // DefRangeRegisterRelSym record, see SymbolRecord.h for more info.  Omit the
+  // LocalVariableAddrRange field from the record. The directive will emit that.
+  DefRangeRegisterRelSym Sym{};
+  ulittle16_t SymKind = ulittle16_t(S_DEFRANGE_REGISTER_REL);
+  Sym.BaseRegister = Var.CVRegister;
+  Sym.Flags = 0; // Unclear what matters here.
+  Sym.BasePointerOffset = Var.RegisterOffset;
+  SmallString<sizeof(Sym) + sizeof(SymKind) - sizeof(LocalVariableAddrRange)>
+      BytePrefix;
+  BytePrefix += StringRef(reinterpret_cast<const char *>(&SymKind),
+                          sizeof(SymKind));
+  BytePrefix += StringRef(reinterpret_cast<const char *>(&Sym),
+                          sizeof(Sym) - sizeof(LocalVariableAddrRange));
+
+  OS.EmitCVDefRangeDirective(Var.Ranges, BytePrefix);
+}
+
 void CodeViewDebug::endFunction(const MachineFunction *MF) {
+  collectVariableInfoFromMMITable();
+
+  DebugHandlerBase::endFunction(MF);
+
   if (!Asm || !CurFn)  // We haven't created any debug info for this function.
     return;
 
@@ -513,13 +605,18 @@ void CodeViewDebug::endFunction(const Ma
   // Don't emit anything if we don't have any line tables.
   if (!CurFn->HaveLineInfo) {
     FnDebugInfo.erase(GV);
-  } else {
-    CurFn->End = Asm->getFunctionEnd();
+    CurFn = nullptr;
+    return;
   }
+
+  CurFn->End = Asm->getFunctionEnd();
+
   CurFn = nullptr;
 }
 
 void CodeViewDebug::beginInstruction(const MachineInstr *MI) {
+  DebugHandlerBase::beginInstruction(MI);
+
   // Ignore DBG_VALUE locations and function prologue.
   if (!Asm || MI->isDebugValue() || MI->getFlag(MachineInstr::FrameSetup))
     return;
@@ -528,4 +625,3 @@ void CodeViewDebug::beginInstruction(con
     return;
   maybeRecordLocation(DL, Asm->MF);
 }
-}

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h Wed Feb 10 14:55:49 2016
@@ -14,12 +14,11 @@
 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H
 #define LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H
 
-#include "AsmPrinterHandler.h"
+#include "DebugHandlerBase.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/CodeGen/AsmPrinter.h"
-#include "llvm/CodeGen/LexicalScopes.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineModuleInfo.h"
 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
@@ -29,14 +28,25 @@
 #include "llvm/Target/TargetLoweringObjectFile.h"
 
 namespace llvm {
+
+class LexicalScope;
+
 /// \brief Collects and handles line tables information in a CodeView format.
-class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public AsmPrinterHandler {
-  AsmPrinter *Asm;
+class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
   MCStreamer &OS;
-  DebugLoc PrevInstLoc;
+
+  /// Similar to DbgVariable in DwarfDebug, but not dwarf-specific.
+  struct LocalVariable {
+    const DILocalVariable *DIVar = nullptr;
+    SmallVector<std::pair<const MCSymbol *, const MCSymbol *>, 1> Ranges;
+    unsigned CVRegister = 0;
+    int RegisterOffset = 0;
+    // FIXME: Add support for DIExpressions.
+  };
 
   struct InlineSite {
-    TinyPtrVector<const DILocation *> ChildSites;
+    SmallVector<LocalVariable, 1> InlinedLocals;
+    SmallVector<const DILocation *, 1> ChildSites;
     const DISubprogram *Inlinee = nullptr;
     unsigned SiteFuncId = 0;
   };
@@ -46,7 +56,12 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDe
   struct FunctionInfo {
     /// Map from inlined call site to inlined instructions and child inlined
     /// call sites. Listed in program order.
-    MapVector<const DILocation *, InlineSite> InlineSites;
+    std::unordered_map<const DILocation *, InlineSite> InlineSites;
+
+    /// Ordered list of top-level inlined call sites.
+    SmallVector<const DILocation *, 1> ChildSites;
+
+    SmallVector<LocalVariable, 1> Locals;
 
     DebugLoc LastLoc;
     const MCSymbol *Begin = nullptr;
@@ -108,6 +123,10 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDe
   void emitInlinedCallSite(const FunctionInfo &FI, const DILocation *InlinedAt,
                            const InlineSite &Site);
 
+  void collectVariableInfoFromMMITable();
+
+  void emitLocalVariable(const LocalVariable &Var);
+
 public:
   CodeViewDebug(AsmPrinter *Asm);
 
@@ -124,9 +143,6 @@ public:
 
   /// \brief Process beginning of an instruction.
   void beginInstruction(const MachineInstr *MI) override;
-
-  /// \brief Process end of an instruction.
-  void endInstruction() override {}
 };
 } // End of namespace llvm
 

Added: llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp?rev=260432&view=auto
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp (added)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp Wed Feb 10 14:55:49 2016
@@ -0,0 +1,200 @@
+//===-- llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp -------*- C++ -*--===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Common functionality for different debug information format backends.
+// LLVM currently supports DWARF and CodeView.
+//
+//===----------------------------------------------------------------------===//
+
+#include "DebugHandlerBase.h"
+#include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
+
+using namespace llvm;
+
+DebugHandlerBase::DebugHandlerBase(AsmPrinter *A) : Asm(A), MMI(Asm->MMI) {}
+
+// Each LexicalScope has first instruction and last instruction to mark
+// beginning and end of a scope respectively. Create an inverse map that list
+// scopes starts (and ends) with an instruction. One instruction may start (or
+// end) multiple scopes. Ignore scopes that are not reachable.
+void DebugHandlerBase::identifyScopeMarkers() {
+  SmallVector<LexicalScope *, 4> WorkList;
+  WorkList.push_back(LScopes.getCurrentFunctionScope());
+  while (!WorkList.empty()) {
+    LexicalScope *S = WorkList.pop_back_val();
+
+    const SmallVectorImpl<LexicalScope *> &Children = S->getChildren();
+    if (!Children.empty())
+      WorkList.append(Children.begin(), Children.end());
+
+    if (S->isAbstractScope())
+      continue;
+
+    for (const InsnRange &R : S->getRanges()) {
+      assert(R.first && "InsnRange does not have first instruction!");
+      assert(R.second && "InsnRange does not have second instruction!");
+      requestLabelBeforeInsn(R.first);
+      requestLabelAfterInsn(R.second);
+    }
+  }
+}
+
+// Return Label preceding the instruction.
+MCSymbol *DebugHandlerBase::getLabelBeforeInsn(const MachineInstr *MI) {
+  MCSymbol *Label = LabelsBeforeInsn.lookup(MI);
+  assert(Label && "Didn't insert label before instruction");
+  return Label;
+}
+
+// Return Label immediately following the instruction.
+MCSymbol *DebugHandlerBase::getLabelAfterInsn(const MachineInstr *MI) {
+  return LabelsAfterInsn.lookup(MI);
+}
+
+// Determine the relative position of the pieces described by P1 and P2.
+// Returns  -1 if P1 is entirely before P2, 0 if P1 and P2 overlap,
+// 1 if P1 is entirely after P2.
+int DebugHandlerBase::pieceCmp(const DIExpression *P1, const DIExpression *P2) {
+  unsigned l1 = P1->getBitPieceOffset();
+  unsigned l2 = P2->getBitPieceOffset();
+  unsigned r1 = l1 + P1->getBitPieceSize();
+  unsigned r2 = l2 + P2->getBitPieceSize();
+  if (r1 <= l2)
+    return -1;
+  else if (r2 <= l1)
+    return 1;
+  else
+    return 0;
+}
+
+/// Determine whether two variable pieces overlap.
+bool DebugHandlerBase::piecesOverlap(const DIExpression *P1, const DIExpression *P2) {
+  if (!P1->isBitPiece() || !P2->isBitPiece())
+    return true;
+  return pieceCmp(P1, P2) == 0;
+}
+
+void DebugHandlerBase::beginFunction(const MachineFunction *MF) {
+  // Grab the lexical scopes for the function, if we don't have any of those
+  // then we're not going to be able to do anything.
+  LScopes.initialize(*MF);
+  if (LScopes.empty())
+    return;
+
+  // Make sure that each lexical scope will have a begin/end label.
+  identifyScopeMarkers();
+
+  // Calculate history for local variables.
+  assert(DbgValues.empty() && "DbgValues map wasn't cleaned!");
+  calculateDbgValueHistory(MF, Asm->MF->getSubtarget().getRegisterInfo(),
+                           DbgValues);
+
+  // Request labels for the full history.
+  for (const auto &I : DbgValues) {
+    const auto &Ranges = I.second;
+    if (Ranges.empty())
+      continue;
+
+    // The first mention of a function argument gets the CurrentFnBegin
+    // label, so arguments are visible when breaking at function entry.
+    const DILocalVariable *DIVar = Ranges.front().first->getDebugVariable();
+    if (DIVar->isParameter() &&
+        getDISubprogram(DIVar->getScope())->describes(MF->getFunction())) {
+      LabelsBeforeInsn[Ranges.front().first] = Asm->getFunctionBegin();
+      if (Ranges.front().first->getDebugExpression()->isBitPiece()) {
+        // Mark all non-overlapping initial pieces.
+        for (auto I = Ranges.begin(); I != Ranges.end(); ++I) {
+          const DIExpression *Piece = I->first->getDebugExpression();
+          if (std::all_of(Ranges.begin(), I,
+                          [&](DbgValueHistoryMap::InstrRange Pred) {
+                return !piecesOverlap(Piece, Pred.first->getDebugExpression());
+              }))
+            LabelsBeforeInsn[I->first] = Asm->getFunctionBegin();
+          else
+            break;
+        }
+      }
+    }
+
+    for (const auto &Range : Ranges) {
+      requestLabelBeforeInsn(Range.first);
+      if (Range.second)
+        requestLabelAfterInsn(Range.second);
+    }
+  }
+
+  PrevInstLoc = DebugLoc();
+  PrevLabel = Asm->getFunctionBegin();
+}
+
+void DebugHandlerBase::beginInstruction(const MachineInstr *MI) {
+  if (!MMI->hasDebugInfo())
+    return;
+
+  assert(CurMI == nullptr);
+  CurMI = MI;
+
+  // Insert labels where requested.
+  DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
+      LabelsBeforeInsn.find(MI);
+
+  // No label needed.
+  if (I == LabelsBeforeInsn.end())
+    return;
+
+  // Label already assigned.
+  if (I->second)
+    return;
+
+  if (!PrevLabel) {
+    PrevLabel = MMI->getContext().createTempSymbol();
+    Asm->OutStreamer->EmitLabel(PrevLabel);
+  }
+  I->second = PrevLabel;
+}
+
+void DebugHandlerBase::endInstruction() {
+  if (!MMI->hasDebugInfo())
+    return;
+
+  assert(CurMI != nullptr);
+  // Don't create a new label after DBG_VALUE instructions.
+  // They don't generate code.
+  if (!CurMI->isDebugValue())
+    PrevLabel = nullptr;
+
+  DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
+      LabelsAfterInsn.find(CurMI);
+  CurMI = nullptr;
+
+  // No label needed.
+  if (I == LabelsAfterInsn.end())
+    return;
+
+  // Label already assigned.
+  if (I->second)
+    return;
+
+  // We need a label after this instruction.
+  if (!PrevLabel) {
+    PrevLabel = MMI->getContext().createTempSymbol();
+    Asm->OutStreamer->EmitLabel(PrevLabel);
+  }
+  I->second = PrevLabel;
+}
+
+void DebugHandlerBase::endFunction(const MachineFunction *MF) {
+  DbgValues.clear();
+  LabelsBeforeInsn.clear();
+  LabelsAfterInsn.clear();
+}

Added: llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h?rev=260432&view=auto
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h (added)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h Wed Feb 10 14:55:49 2016
@@ -0,0 +1,105 @@
+//===-- llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.h --------*- C++ -*--===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Common functionality for different debug information format backends.
+// LLVM currently supports DWARF and CodeView.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGHANDLERBASE_H
+#define LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGHANDLERBASE_H
+
+#include "AsmPrinterHandler.h"
+#include "DbgValueHistoryCalculator.h"
+#include "llvm/CodeGen/LexicalScopes.h"
+
+namespace llvm {
+
+class AsmPrinter;
+class MachineModuleInfo;
+
+/// Base class for debug information backends. Common functionality related to
+/// tracking which variables and scopes are alive at a given PC live here.
+class LLVM_LIBRARY_VISIBILITY DebugHandlerBase : public AsmPrinterHandler {
+protected:
+  DebugHandlerBase(AsmPrinter *A);
+
+  /// Target of debug info emission.
+  AsmPrinter *Asm;
+
+  /// Collected machine module information.
+  MachineModuleInfo *MMI;
+
+  /// Previous instruction's location information. This is used to
+  /// determine label location to indicate scope boundries in dwarf
+  /// debug info.
+  DebugLoc PrevInstLoc;
+  MCSymbol *PrevLabel = nullptr;
+
+  /// This location indicates end of function prologue and beginning of
+  /// function body.
+  DebugLoc PrologEndLoc;
+
+  /// If nonnull, stores the current machine instruction we're processing.
+  const MachineInstr *CurMI = nullptr;
+
+  LexicalScopes LScopes;
+
+  /// History of DBG_VALUE and clobber instructions for each user
+  /// variable.  Variables are listed in order of appearance.
+  DbgValueHistoryMap DbgValues;
+
+  /// Maps instruction with label emitted before instruction.
+  /// FIXME: Make this private from DwarfDebug, we have the necessary accessors
+  /// for it.
+  DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
+
+  /// Maps instruction with label emitted after instruction.
+  DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
+
+  /// Indentify instructions that are marking the beginning of or
+  /// ending of a scope.
+  void identifyScopeMarkers();
+
+  /// Ensure that a label will be emitted before MI.
+  void requestLabelBeforeInsn(const MachineInstr *MI) {
+    LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
+  }
+
+  /// Ensure that a label will be emitted after MI.
+  void requestLabelAfterInsn(const MachineInstr *MI) {
+    LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
+  }
+
+  // AsmPrinterHandler overrides.
+public:
+  void beginInstruction(const MachineInstr *MI) override;
+  void endInstruction() override;
+
+  void beginFunction(const MachineFunction *MF) override;
+  void endFunction(const MachineFunction *MF) override;
+
+  /// Return Label preceding the instruction.
+  MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
+
+  /// Return Label immediately following the instruction.
+  MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
+
+  /// Determine the relative position of the pieces described by P1 and P2.
+  /// Returns  -1 if P1 is entirely before P2, 0 if P1 and P2 overlap,
+  /// 1 if P1 is entirely after P2.
+  static int pieceCmp(const DIExpression *P1, const DIExpression *P2);
+
+  /// Determine whether two variable pieces overlap.
+  static bool piecesOverlap(const DIExpression *P1, const DIExpression *P2);
+};
+
+}
+
+#endif

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Wed Feb 10 14:55:49 2016
@@ -202,8 +202,8 @@ static LLVM_CONSTEXPR DwarfAccelTable::A
     DwarfAccelTable::Atom(dwarf::DW_ATOM_type_flags, dwarf::DW_FORM_data1)};
 
 DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
-    : Asm(A), MMI(Asm->MMI), DebugLocs(A->OutStreamer->isVerboseAsm()),
-      PrevLabel(nullptr), InfoHolder(A, "info_string", DIEValueAllocator),
+    : DebugHandlerBase(A), DebugLocs(A->OutStreamer->isVerboseAsm()),
+      InfoHolder(A, "info_string", DIEValueAllocator),
       SkeletonHolder(A, "skel_string", DIEValueAllocator),
       IsDarwin(Triple(A->getTargetTriple()).isOSDarwin()),
       AccelNames(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset,
@@ -215,7 +215,6 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Mo
       AccelTypes(TypeAtoms), DebuggerTuning(DebuggerKind::Default) {
 
   CurFn = nullptr;
-  CurMI = nullptr;
   Triple TT(Asm->getTargetTriple());
 
   // Make sure we know our "debugger tuning."  The target option takes
@@ -788,29 +787,6 @@ static DebugLocEntry::Value getDebugLocV
   llvm_unreachable("Unexpected 4-operand DBG_VALUE instruction!");
 }
 
-// Determine the relative position of the pieces described by P1 and P2.
-// Returns  -1 if P1 is entirely before P2, 0 if P1 and P2 overlap,
-// 1 if P1 is entirely after P2.
-static int pieceCmp(const DIExpression *P1, const DIExpression *P2) {
-  unsigned l1 = P1->getBitPieceOffset();
-  unsigned l2 = P2->getBitPieceOffset();
-  unsigned r1 = l1 + P1->getBitPieceSize();
-  unsigned r2 = l2 + P2->getBitPieceSize();
-  if (r1 <= l2)
-    return -1;
-  else if (r2 <= l1)
-    return 1;
-  else
-    return 0;
-}
-
-/// Determine whether two variable pieces overlap.
-static bool piecesOverlap(const DIExpression *P1, const DIExpression *P2) {
-  if (!P1->isBitPiece() || !P2->isBitPiece())
-    return true;
-  return pieceCmp(P1, P2) == 0;
-}
-
 /// \brief If this and Next are describing different pieces of the same
 /// variable, merge them by appending Next's values to the current
 /// list of values.
@@ -827,8 +803,9 @@ bool DebugLocEntry::MergeValues(const De
     // sorted.
     for (unsigned i = 0, j = 0; i < Values.size(); ++i) {
       for (; j < Next.Values.size(); ++j) {
-        int res = pieceCmp(cast<DIExpression>(Values[i].Expression),
-                           cast<DIExpression>(Next.Values[j].Expression));
+        int res = DebugHandlerBase::pieceCmp(
+            cast<DIExpression>(Values[i].Expression),
+            cast<DIExpression>(Next.Values[j].Expression));
         if (res == 0) // The two expressions overlap, we can't merge.
           return false;
         // Values[i] is entirely before Next.Values[j],
@@ -1022,22 +999,11 @@ void DwarfDebug::collectVariableInfo(Dwa
   }
 }
 
-// Return Label preceding the instruction.
-MCSymbol *DwarfDebug::getLabelBeforeInsn(const MachineInstr *MI) {
-  MCSymbol *Label = LabelsBeforeInsn.lookup(MI);
-  assert(Label && "Didn't insert label before instruction");
-  return Label;
-}
-
-// Return Label immediately following the instruction.
-MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) {
-  return LabelsAfterInsn.lookup(MI);
-}
-
 // Process beginning of an instruction.
 void DwarfDebug::beginInstruction(const MachineInstr *MI) {
-  assert(CurMI == nullptr);
-  CurMI = MI;
+  DebugHandlerBase::beginInstruction(MI);
+  assert(CurMI);
+
   // Check if source location changes, but ignore DBG_VALUE locations.
   if (!MI->isDebugValue()) {
     DebugLoc DL = MI->getDebugLoc();
@@ -1062,78 +1028,6 @@ void DwarfDebug::beginInstruction(const
       }
     }
   }
-
-  // Insert labels where requested.
-  DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
-      LabelsBeforeInsn.find(MI);
-
-  // No label needed.
-  if (I == LabelsBeforeInsn.end())
-    return;
-
-  // Label already assigned.
-  if (I->second)
-    return;
-
-  if (!PrevLabel) {
-    PrevLabel = MMI->getContext().createTempSymbol();
-    Asm->OutStreamer->EmitLabel(PrevLabel);
-  }
-  I->second = PrevLabel;
-}
-
-// Process end of an instruction.
-void DwarfDebug::endInstruction() {
-  assert(CurMI != nullptr);
-  // Don't create a new label after DBG_VALUE instructions.
-  // They don't generate code.
-  if (!CurMI->isDebugValue())
-    PrevLabel = nullptr;
-
-  DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
-      LabelsAfterInsn.find(CurMI);
-  CurMI = nullptr;
-
-  // No label needed.
-  if (I == LabelsAfterInsn.end())
-    return;
-
-  // Label already assigned.
-  if (I->second)
-    return;
-
-  // We need a label after this instruction.
-  if (!PrevLabel) {
-    PrevLabel = MMI->getContext().createTempSymbol();
-    Asm->OutStreamer->EmitLabel(PrevLabel);
-  }
-  I->second = PrevLabel;
-}
-
-// Each LexicalScope has first instruction and last instruction to mark
-// beginning and end of a scope respectively. Create an inverse map that list
-// scopes starts (and ends) with an instruction. One instruction may start (or
-// end) multiple scopes. Ignore scopes that are not reachable.
-void DwarfDebug::identifyScopeMarkers() {
-  SmallVector<LexicalScope *, 4> WorkList;
-  WorkList.push_back(LScopes.getCurrentFunctionScope());
-  while (!WorkList.empty()) {
-    LexicalScope *S = WorkList.pop_back_val();
-
-    const SmallVectorImpl<LexicalScope *> &Children = S->getChildren();
-    if (!Children.empty())
-      WorkList.append(Children.begin(), Children.end());
-
-    if (S->isAbstractScope())
-      continue;
-
-    for (const InsnRange &R : S->getRanges()) {
-      assert(R.first && "InsnRange does not have first instruction!");
-      assert(R.second && "InsnRange does not have second instruction!");
-      requestLabelBeforeInsn(R.first);
-      requestLabelAfterInsn(R.second);
-    }
-  }
 }
 
 static DebugLoc findPrologueEndLoc(const MachineFunction *MF) {
@@ -1162,15 +1056,10 @@ void DwarfDebug::beginFunction(const Mac
 
   // Grab the lexical scopes for the function, if we don't have any of those
   // then we're not going to be able to do anything.
-  LScopes.initialize(*MF);
+  DebugHandlerBase::beginFunction(MF);
   if (LScopes.empty())
     return;
 
-  assert(DbgValues.empty() && "DbgValues map wasn't cleaned!");
-
-  // Make sure that each lexical scope will have a begin/end label.
-  identifyScopeMarkers();
-
   // Set DwarfDwarfCompileUnitID in MCContext to the Compile Unit this function
   // belongs to so that we add to the correct per-cu line table in the
   // non-asm case.
@@ -1191,47 +1080,6 @@ void DwarfDebug::beginFunction(const Mac
   else
     Asm->OutStreamer->getContext().setDwarfCompileUnitID(TheCU->getUniqueID());
 
-  // Calculate history for local variables.
-  calculateDbgValueHistory(MF, Asm->MF->getSubtarget().getRegisterInfo(),
-                           DbgValues);
-
-  // Request labels for the full history.
-  for (const auto &I : DbgValues) {
-    const auto &Ranges = I.second;
-    if (Ranges.empty())
-      continue;
-
-    // The first mention of a function argument gets the CurrentFnBegin
-    // label, so arguments are visible when breaking at function entry.
-    const DILocalVariable *DIVar = Ranges.front().first->getDebugVariable();
-    if (DIVar->isParameter() &&
-        getDISubprogram(DIVar->getScope())->describes(MF->getFunction())) {
-      LabelsBeforeInsn[Ranges.front().first] = Asm->getFunctionBegin();
-      if (Ranges.front().first->getDebugExpression()->isBitPiece()) {
-        // Mark all non-overlapping initial pieces.
-        for (auto I = Ranges.begin(); I != Ranges.end(); ++I) {
-          const DIExpression *Piece = I->first->getDebugExpression();
-          if (std::all_of(Ranges.begin(), I,
-                          [&](DbgValueHistoryMap::InstrRange Pred) {
-                return !piecesOverlap(Piece, Pred.first->getDebugExpression());
-              }))
-            LabelsBeforeInsn[I->first] = Asm->getFunctionBegin();
-          else
-            break;
-        }
-      }
-    }
-
-    for (const auto &Range : Ranges) {
-      requestLabelBeforeInsn(Range.first);
-      if (Range.second)
-        requestLabelAfterInsn(Range.second);
-    }
-  }
-
-  PrevInstLoc = DebugLoc();
-  PrevLabel = Asm->getFunctionBegin();
-
   // Record beginning of function.
   PrologEndLoc = findPrologueEndLoc(MF);
   if (DILocation *L = PrologEndLoc) {
@@ -1254,6 +1102,7 @@ void DwarfDebug::endFunction(const Machi
     // previously used section to nullptr.
     PrevCU = nullptr;
     CurFn = nullptr;
+    DebugHandlerBase::endFunction(MF);
     return;
   }
 
@@ -1279,10 +1128,9 @@ void DwarfDebug::endFunction(const Machi
     // FIXME: This wouldn't be true in LTO with a -g (with inlining) CU followed
     // by a -gmlt CU. Add a test and remove this assertion.
     assert(AbstractVariables.empty());
-    LabelsBeforeInsn.clear();
-    LabelsAfterInsn.clear();
     PrevLabel = nullptr;
     CurFn = nullptr;
+    DebugHandlerBase::endFunction(MF);
     return;
   }
 
@@ -1314,11 +1162,9 @@ void DwarfDebug::endFunction(const Machi
   // DbgVariables except those that are also in AbstractVariables (since they
   // can be used cross-function)
   InfoHolder.getScopeVariables().clear();
-  DbgValues.clear();
-  LabelsBeforeInsn.clear();
-  LabelsAfterInsn.clear();
   PrevLabel = nullptr;
   CurFn = nullptr;
+  DebugHandlerBase::endFunction(MF);
 }
 
 // Register a source line with debug info. Returns the  unique label that was

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Wed Feb 10 14:55:49 2016
@@ -14,8 +14,8 @@
 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
 
-#include "AsmPrinterHandler.h"
 #include "DbgValueHistoryCalculator.h"
+#include "DebugHandlerBase.h"
 #include "DebugLocStream.h"
 #include "DwarfAccelTable.h"
 #include "DwarfFile.h"
@@ -188,13 +188,7 @@ struct SymbolCU {
 };
 
 /// Collects and handles dwarf debug information.
-class DwarfDebug : public AsmPrinterHandler {
-  /// Target of Dwarf emission.
-  AsmPrinter *Asm;
-
-  /// Collected machine module information.
-  MachineModuleInfo *MMI;
-
+class DwarfDebug : public DebugHandlerBase {
   /// All DIEValues are allocated through this allocator.
   BumpPtrAllocator DIEValueAllocator;
 
@@ -213,8 +207,6 @@ class DwarfDebug : public AsmPrinterHand
   /// Size of each symbol emitted (for those symbols that have a specific size).
   DenseMap<const MCSymbol *, uint64_t> SymSize;
 
-  LexicalScopes LScopes;
-
   /// Collection of abstract variables.
   DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;
   SmallVector<std::unique_ptr<DbgVariable>, 64> ConcreteVariables;
@@ -227,32 +219,9 @@ class DwarfDebug : public AsmPrinterHand
   /// create DIEs.
   SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
 
-  /// Maps instruction with label emitted before instruction.
-  DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
-
-  /// Maps instruction with label emitted after instruction.
-  DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
-
-  /// History of DBG_VALUE and clobber instructions for each user
-  /// variable.  Variables are listed in order of appearance.
-  DbgValueHistoryMap DbgValues;
-
-  /// Previous instruction's location information. This is used to
-  /// determine label location to indicate scope boundries in dwarf
-  /// debug info.
-  DebugLoc PrevInstLoc;
-  MCSymbol *PrevLabel;
-
-  /// This location indicates end of function prologue and beginning of
-  /// function body.
-  DebugLoc PrologEndLoc;
-
   /// If nonnull, stores the current machine function we're processing.
   const MachineFunction *CurFn;
 
-  /// If nonnull, stores the current machine instruction we're processing.
-  const MachineInstr *CurMI;
-
   /// If nonnull, stores the CU in which the previous subprogram was contained.
   const DwarfCompileUnit *PrevCU;
 
@@ -458,10 +427,6 @@ class DwarfDebug : public AsmPrinterHand
   void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
                         unsigned Flags);
 
-  /// Indentify instructions that are marking the beginning of or
-  /// ending of a scope.
-  void identifyScopeMarkers();
-
   /// Populate LexicalScope entries with variables' info.
   void collectVariableInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
                            DenseSet<InlinedVariable> &ProcessedVars);
@@ -475,16 +440,6 @@ class DwarfDebug : public AsmPrinterHand
   /// by MMI.
   void collectVariableInfoFromMMITable(DenseSet<InlinedVariable> &P);
 
-  /// Ensure that a label will be emitted before MI.
-  void requestLabelBeforeInsn(const MachineInstr *MI) {
-    LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
-  }
-
-  /// Ensure that a label will be emitted after MI.
-  void requestLabelAfterInsn(const MachineInstr *MI) {
-    LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
-  }
-
 public:
   //===--------------------------------------------------------------------===//
   // Main entry points.
@@ -509,9 +464,6 @@ public:
   /// Process beginning of an instruction.
   void beginInstruction(const MachineInstr *MI) override;
 
-  /// Process end of an instruction.
-  void endInstruction() override;
-
   /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits.
   static uint64_t makeTypeSignature(StringRef Identifier);
 
@@ -606,12 +558,6 @@ public:
   /// going to be null.
   bool isLexicalScopeDIENull(LexicalScope *Scope);
 
-  /// Return Label preceding the instruction.
-  MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
-
-  /// Return Label immediately following the instruction.
-  MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
-
   // FIXME: Sink these functions down into DwarfFile/Dwarf*Unit.
 
   SmallPtrSet<const MDNode *, 16> &getProcessedSPNodes() {

Modified: llvm/trunk/lib/MC/MCRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCRegisterInfo.cpp?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCRegisterInfo.cpp (original)
+++ llvm/trunk/lib/MC/MCRegisterInfo.cpp Wed Feb 10 14:55:49 2016
@@ -84,3 +84,10 @@ int MCRegisterInfo::getSEHRegNum(unsigne
   if (I == L2SEHRegs.end()) return (int)RegNum;
   return I->second;
 }
+
+int MCRegisterInfo::getCodeViewRegNum(unsigned RegNum) const {
+  const DenseMap<unsigned, int>::const_iterator I = L2CVRegs.find(RegNum);
+  if (I == L2CVRegs.end())
+    report_fatal_error("target does not implement codeview register mapping");
+  return I->second;
+}

Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp Wed Feb 10 14:55:49 2016
@@ -66,12 +66,52 @@ unsigned X86_MC::getDwarfRegFlavour(cons
   return DWARFFlavour::X86_32_Generic;
 }
 
-void X86_MC::InitLLVM2SEHRegisterMapping(MCRegisterInfo *MRI) {
+void X86_MC::initLLVMToSEHAndCVRegMapping(MCRegisterInfo *MRI) {
   // FIXME: TableGen these.
-  for (unsigned Reg = X86::NoRegister+1; Reg < X86::NUM_TARGET_REGS; ++Reg) {
+  for (unsigned Reg = X86::NoRegister + 1; Reg < X86::NUM_TARGET_REGS; ++Reg) {
     unsigned SEH = MRI->getEncodingValue(Reg);
     MRI->mapLLVMRegToSEHReg(Reg, SEH);
   }
+
+  // These CodeView registers are numbered sequentially starting at value 1.
+  unsigned LowCVRegs[] = {
+      X86::AL,  X86::CL,  X86::DL,  X86::BL,  X86::AH,  X86::CH,
+      X86::DH,  X86::BH,  X86::AX,  X86::CX,  X86::DX,  X86::BX,
+      X86::SP,  X86::BP,  X86::SI,  X86::DI,  X86::EAX, X86::ECX,
+      X86::EDX, X86::EBX, X86::ESP, X86::EBP, X86::ESI, X86::EDI,
+  };
+  unsigned CVLowRegStart = 1;
+  for (unsigned I = 0; I < array_lengthof(LowCVRegs); ++I)
+    MRI->mapLLVMRegToCVReg(LowCVRegs[I], I + CVLowRegStart);
+
+  // The low 8 XMM registers start at 154 and are numbered sequentially.
+  unsigned CVXMM0Start = 154;
+  for (unsigned I = 0; I < 8; ++I)
+    MRI->mapLLVMRegToCVReg(X86::XMM0 + I, CVXMM0Start + I);
+
+  // The high 8 XMM registers start at 252 and are numbered sequentially.
+  unsigned CVXMM8Start = 252;
+  for (unsigned I = 0; I < 8; ++I)
+    MRI->mapLLVMRegToCVReg(X86::XMM8 + I, CVXMM8Start + I);
+
+  // FIXME: XMM16 and above from AVX512 not yet documented.
+
+  // AMD64 registers start at 324 and count up.
+  unsigned CVX64RegStart = 324;
+  unsigned CVX64Regs[] = {
+      X86::SIL,   X86::DIL,   X86::BPL,   X86::SPL,   X86::RAX,   X86::RBX,
+      X86::RCX,   X86::RDX,   X86::RSI,   X86::RDI,   X86::RBP,   X86::RSP,
+      X86::R8,    X86::R9,    X86::R10,   X86::R11,   X86::R12,   X86::R13,
+      X86::R14,   X86::R15,   X86::R8B,   X86::R9B,   X86::R10B,  X86::R11B,
+      X86::R12B,  X86::R13B,  X86::R14B,  X86::R15B,  X86::R8W,   X86::R9W,
+      X86::R10W,  X86::R11W,  X86::R12W,  X86::R13W,  X86::R14W,  X86::R15W,
+      X86::R8D,   X86::R9D,   X86::R10D,  X86::R11D,  X86::R12D,  X86::R13D,
+      X86::R14D,  X86::R15D,  X86::YMM0,  X86::YMM1,  X86::YMM2,  X86::YMM3,
+      X86::YMM4,  X86::YMM5,  X86::YMM6,  X86::YMM7,  X86::YMM8,  X86::YMM9,
+      X86::YMM10, X86::YMM11, X86::YMM12, X86::YMM13, X86::YMM14, X86::YMM15,
+  };
+  for (unsigned I = 0; I < array_lengthof(CVX64Regs); ++I)
+    MRI->mapLLVMRegToCVReg(CVX64Regs[I], CVX64RegStart + I);
 }
 
 MCSubtargetInfo *X86_MC::createX86MCSubtargetInfo(const Triple &TT,
@@ -105,7 +145,7 @@ static MCRegisterInfo *createX86MCRegist
   MCRegisterInfo *X = new MCRegisterInfo();
   InitX86MCRegisterInfo(X, RA, X86_MC::getDwarfRegFlavour(TT, false),
                         X86_MC::getDwarfRegFlavour(TT, true), RA);
-  X86_MC::InitLLVM2SEHRegisterMapping(X);
+  X86_MC::initLLVMToSEHAndCVRegMapping(X);
   return X;
 }
 

Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h Wed Feb 10 14:55:49 2016
@@ -56,7 +56,7 @@ std::string ParseX86Triple(const Triple
 
 unsigned getDwarfRegFlavour(const Triple &TT, bool isEH);
 
-void InitLLVM2SEHRegisterMapping(MCRegisterInfo *MRI);
+void initLLVMToSEHAndCVRegMapping(MCRegisterInfo *MRI);
 
 /// Create a X86 MCSubtargetInfo instance. This is exposed so Asm parser, etc.
 /// do not need to go through TargetRegistry.

Modified: llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp Wed Feb 10 14:55:49 2016
@@ -52,7 +52,7 @@ X86RegisterInfo::X86RegisterInfo(const T
                          X86_MC::getDwarfRegFlavour(TT, false),
                          X86_MC::getDwarfRegFlavour(TT, true),
                          (TT.isArch64Bit() ? X86::RIP : X86::EIP)) {
-  X86_MC::InitLLVM2SEHRegisterMapping(this);
+  X86_MC::initLLVMToSEHAndCVRegMapping(this);
 
   // Cache some information.
   Is64Bit = TT.isArch64Bit();

Modified: llvm/trunk/test/DebugInfo/COFF/asm.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/asm.ll?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/asm.ll (original)
+++ llvm/trunk/test/DebugInfo/COFF/asm.ll Wed Feb 10 14:55:49 2016
@@ -19,7 +19,7 @@
 ; X86:      calll   _g
 ; X86:      .cv_loc 0 1 6 0
 ; X86:      ret
-; X86-NEXT: [[END_OF_F:^L.*]]:
+; X86:      [[END_OF_F:.?Lfunc_end.*]]:
 ;
 ; X86-LABEL: .section        .debug$S,"dr"
 ; X86-NEXT: .long   4
@@ -110,7 +110,7 @@
 ; X64:      .cv_loc 0 1 6 0
 ; X64:      addq    $40, %rsp
 ; X64-NEXT: ret
-; X64-NEXT: [[END_OF_F:.*]]:
+; X64:      [[END_OF_F:.?Lfunc_end.*]]:
 ;
 ; X64-LABEL: .section        .debug$S,"dr"
 ; X64-NEXT: .long   4

Modified: llvm/trunk/test/DebugInfo/COFF/inlining.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/inlining.ll?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/inlining.ll (original)
+++ llvm/trunk/test/DebugInfo/COFF/inlining.ll Wed Feb 10 14:55:49 2016
@@ -55,7 +55,7 @@
 ; ASM: [[inline_end]]:
 
 ; ASM: .long   241                     # Symbol subsection for baz
-; ASM: .long   Ltmp3-Ltmp2
+; ASM: .long   {{.*}} # Subsection size
 ; ASM: .short 4429
 ; ASM: .long
 ; ASM: .long

Added: llvm/trunk/test/DebugInfo/COFF/local-variables.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/local-variables.ll?rev=260432&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/local-variables.ll (added)
+++ llvm/trunk/test/DebugInfo/COFF/local-variables.ll Wed Feb 10 14:55:49 2016
@@ -0,0 +1,316 @@
+; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s --check-prefix=ASM
+; RUN: llc -mtriple=x86_64-windows-msvc < %s -filetype=obj | llvm-readobj -codeview - | FileCheck %s --check-prefix=OBJ
+
+; This LL file was generated by running 'clang -g -gcodeview' on the
+; following code:
+;  1: extern "C" volatile int x;
+;  2: extern "C" void capture(int *p);
+;  3: static __forceinline inline void will_be_inlined() {
+;  4:   int v = 3;
+;  5:   capture(&v);
+;  6: }
+;  7: extern "C" void f(int param) {
+;  8:   if (param) {
+;  9:     int a = 42;
+; 10:     will_be_inlined();
+; 11:     capture(&a);
+; 12:   } else {
+; 13:     int b = 42;
+; 14:     will_be_inlined();
+; 15:     capture(&b);
+; 16:   }
+; 17: }
+
+; ASM: f:                                      # @f
+; ASM:         .cv_file        1 "D:\\src\\llvm\\build\\t.cpp"
+; ASM:         .cv_loc 0 1 7 0 is_stmt 0       # t.cpp:7:0
+; ASM: .seh_proc f
+; ASM: # BB#0:                                 # %entry
+; ASM:         subq    $56, %rsp
+; ASM:         #DEBUG_VALUE: f:param <- [%RSP+44]
+; ASM:         movl    %ecx, 44(%rsp)
+; ASM: [[prologue_end:\.Ltmp.*]]:
+; ASM:         .cv_loc 0 1 8 7                 # t.cpp:8:7
+; ASM:         testl   %ecx, %ecx
+; ASM:         je      .LBB0_2
+; ASM: [[if_start:\.Ltmp.*]]:
+; ASM: # BB#1:                                 # %if.then
+; ASM:         #DEBUG_VALUE: f:param <- [%RSP+44]
+; ASM:         #DEBUG_VALUE: a <- [%RSP+40]
+; ASM:         .cv_loc 0 1 9 9                 # t.cpp:9:9
+; ASM:         movl    $42, 40(%rsp)
+; ASM: [[inline_site1:\.Ltmp.*]]:
+; ASM:         .cv_loc 1 1 4 7                 # t.cpp:4:7
+; ASM:         movl    $3, 48(%rsp)
+; ASM:         leaq    48(%rsp), %rcx
+; ASM:         .cv_loc 1 1 5 3                 # t.cpp:5:3
+; ASM:         callq   capture
+; ASM:         leaq    40(%rsp), %rcx
+; ASM:         jmp     .LBB0_3
+; ASM: [[else_start:\.Ltmp.*]]:
+; ASM: .LBB0_2:                                # %if.else
+; ASM:         #DEBUG_VALUE: f:param <- [%RSP+44]
+; ASM:         #DEBUG_VALUE: b <- [%RSP+36]
+; ASM:         .cv_loc 0 1 13 9                # t.cpp:13:9
+; ASM:         movl    $42, 36(%rsp)
+; ASM: [[inline_site2:\.Ltmp.*]]:
+; ASM:         .cv_loc 2 1 4 7                 # t.cpp:4:7
+; ASM:         movl    $3, 52(%rsp)
+; ASM:         leaq    52(%rsp), %rcx
+; ASM:         .cv_loc 2 1 5 3                 # t.cpp:5:3
+; ASM:         callq   capture
+; ASM:         leaq    36(%rsp), %rcx
+; ASM: [[inline_site2_end:\.Ltmp.*]]:
+; ASM: .LBB0_3:                                # %if.end
+; ASM:         .cv_loc 0 1 15 5                # t.cpp:15:5
+; ASM:         callq   capture
+; ASM: [[else_end:\.Ltmp.*]]:
+; ASM:         .cv_loc 0 1 17 1                # t.cpp:17:1
+; ASM:         nop
+; ASM:         addq    $56, %rsp
+; ASM:         retq
+; ASM: [[param_end:\.Ltmp.*]]:
+
+; ASM: .short  4414                    # Record kind: S_LOCAL
+; ASM: .long   116                     # TypeIndex
+; ASM: .short  1                       # Flags
+; ASM: .asciz  "param"
+; ASM: .cv_def_range    [[prologue_end]] [[param_end]], "E\021O\001\000\000,\000\000\000"
+; ASM: .short  4414                    # Record kind: S_LOCAL
+; ASM: .long   116                     # TypeIndex
+; ASM: .short  0                       # Flags
+; ASM: .asciz  "a"
+; ASM: .cv_def_range    [[if_start]] [[else_start]], "E\021O\001\000\000(\000\000\000"
+; ASM: .short  4414                    # Record kind: S_LOCAL
+; ASM: .long   116                     # TypeIndex
+; ASM: .short  0                       # Flags
+; ASM: .asciz  "b"
+; ASM: .cv_def_range    [[else_start]] [[else_end]], "E\021O\001\000\000$\000\000\000"
+; ASM: .short  4429                    # Record kind: S_INLINESITE
+; ASM: .short  4414                    # Record kind: S_LOCAL
+; ASM: .long   116                     # TypeIndex
+; ASM: .short  0                       # Flags
+; ASM: .asciz  "v"
+; ASM: .cv_def_range    [[inline_site1]] [[else_start]], "E\021O\001\000\0000\000\000\000"
+; ASM: .short  4430                    # Record kind: S_INLINESITE_END
+; ASM: .short  4429                    # Record kind: S_INLINESITE
+; ASM: .short  4414                    # Record kind: S_LOCAL
+; ASM: .long   116                     # TypeIndex
+; ASM: .short  0                       # Flags
+; ASM: .asciz  "v"
+; ASM: .cv_def_range    [[inline_site2]] [[inline_site2_end]], "E\021O\001\000\0004\000\000\000"
+; ASM: .short  4430                    # Record kind: S_INLINESITE_END
+
+; OBJ:  Subsection [
+; OBJ:    SubSectionType: Symbols (0xF1)
+; OBJ:    ProcStart {
+; OBJ:      DisplayName: f
+; OBJ:      LinkageName: f
+; OBJ:    }
+; OBJ:    Local {
+; OBJ:      Type: int (0x74)
+; OBJ:      Flags [ (0x1)
+; OBJ:        IsParameter (0x1)
+; OBJ:      ]
+; OBJ:      VarName: param
+; OBJ:    }
+; OBJ:    DefRangeRegisterRel {
+; OBJ:      BaseRegister: 335
+; OBJ:      HasSpilledUDTMember: No
+; OBJ:      OffsetInParent: 0
+; OBJ:      BasePointerOffset: 44
+; OBJ:      LocalVariableAddrRange {
+; OBJ:        OffsetStart: .text+0x8
+; OBJ:        ISectStart: 0x0
+; OBJ:        Range: 79
+; OBJ:      }
+; OBJ:    }
+; OBJ:    Local {
+; OBJ:      Type: int (0x74)
+; OBJ:      Flags [ (0x0)
+; OBJ:      ]
+; OBJ:      VarName: a
+; OBJ:    }
+; OBJ:    DefRangeRegisterRel {
+; OBJ:      BaseRegister: 335
+; OBJ:      HasSpilledUDTMember: No
+; OBJ:      OffsetInParent: 0
+; OBJ:      BasePointerOffset: 40
+; OBJ:      LocalVariableAddrRange {
+; OBJ:        OffsetStart: .text+0xC
+; OBJ:        ISectStart: 0x0
+; OBJ:        Range: 33
+; OBJ:      }
+; OBJ:    }
+; OBJ:    Local {
+; OBJ:      Type: int (0x74)
+; OBJ:      Flags [ (0x0)
+; OBJ:      ]
+; OBJ:      VarName: b
+; OBJ:    }
+; OBJ:    DefRangeRegisterRel {
+; OBJ:      BaseRegister: 335
+; OBJ:      HasSpilledUDTMember: No
+; OBJ:      OffsetInParent: 0
+; OBJ:      BasePointerOffset: 36
+; OBJ:      LocalVariableAddrRange {
+; OBJ:        OffsetStart: .text+0x2D
+; OBJ:        ISectStart: 0x0
+; OBJ:        Range: 36
+; OBJ:      }
+; OBJ:    }
+; OBJ:    InlineSite {
+; OBJ:      PtrParent: 0x0
+; OBJ:      PtrEnd: 0x0
+; OBJ:      Inlinee: will_be_inlined (0x1003)
+; OBJ:      BinaryAnnotations [
+; OBJ:        ChangeLineOffset: 1
+; OBJ:        ChangeCodeOffset: 0x14
+; OBJ:        ChangeCodeOffsetAndLineOffset: {CodeOffset: 0xD, LineOffset: 1}
+; OBJ:        ChangeCodeLength: 0xC
+; OBJ:      ]
+; OBJ:    }
+; OBJ:    Local {
+; OBJ:      Type: int (0x74)
+; OBJ:      Flags [ (0x0)
+; OBJ:      ]
+; OBJ:      VarName: v
+; OBJ:    }
+; OBJ:    DefRangeRegisterRel {
+; OBJ:      BaseRegister: 335
+; OBJ:      HasSpilledUDTMember: No
+; OBJ:      OffsetInParent: 0
+; OBJ:      BasePointerOffset: 48
+; OBJ:      LocalVariableAddrRange {
+; OBJ:        OffsetStart: .text+0x14
+; OBJ:        ISectStart: 0x0
+; OBJ:        Range: 25
+; OBJ:      }
+; OBJ:    }
+; OBJ:    InlineSiteEnd {
+; OBJ:    }
+; OBJ:    InlineSite {
+; OBJ:      PtrParent: 0x0
+; OBJ:      PtrEnd: 0x0
+; OBJ:      Inlinee: will_be_inlined (0x1003)
+; OBJ:      BinaryAnnotations [
+; OBJ:        ChangeLineOffset: 1
+; OBJ:        ChangeCodeOffset: 0x35
+; OBJ:        ChangeCodeOffsetAndLineOffset: {CodeOffset: 0xD, LineOffset: 1}
+; OBJ:        ChangeCodeLength: 0xA
+; OBJ:      ]
+; OBJ:    }
+; OBJ:    Local {
+; OBJ:      Type: int (0x74)
+; OBJ:      Flags [ (0x0)
+; OBJ:      ]
+; OBJ:      VarName: v
+; OBJ:    }
+; OBJ:    DefRangeRegisterRel {
+; OBJ:      BaseRegister: 335
+; OBJ:      HasSpilledUDTMember: No
+; OBJ:      OffsetInParent: 0
+; OBJ:      BasePointerOffset: 52
+; OBJ:      LocalVariableAddrRange {
+; OBJ:        OffsetStart: .text+0x35
+; OBJ:        ISectStart: 0x0
+; OBJ:        Range: 23
+; OBJ:      }
+; OBJ:    }
+; OBJ:    InlineSiteEnd {
+; OBJ:    }
+; OBJ:    ProcEnd
+; OBJ:  ]
+
+; ModuleID = 't.cpp'
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc18.0.0"
+
+; Function Attrs: nounwind uwtable
+define void @f(i32 %param) #0 !dbg !4 {
+entry:
+  %v.i1 = alloca i32, align 4
+  call void @llvm.dbg.declare(metadata i32* %v.i1, metadata !15, metadata !16), !dbg !17
+  %v.i = alloca i32, align 4
+  call void @llvm.dbg.declare(metadata i32* %v.i, metadata !15, metadata !16), !dbg !21
+  %param.addr = alloca i32, align 4
+  %a = alloca i32, align 4
+  %b = alloca i32, align 4
+  store i32 %param, i32* %param.addr, align 4
+  call void @llvm.dbg.declare(metadata i32* %param.addr, metadata !24, metadata !16), !dbg !25
+  %0 = load i32, i32* %param.addr, align 4, !dbg !26
+  %tobool = icmp ne i32 %0, 0, !dbg !26
+  br i1 %tobool, label %if.then, label %if.else, !dbg !27
+
+if.then:                                          ; preds = %entry
+  call void @llvm.dbg.declare(metadata i32* %a, metadata !28, metadata !16), !dbg !29
+  store i32 42, i32* %a, align 4, !dbg !29
+  store i32 3, i32* %v.i, align 4, !dbg !21
+  call void @capture(i32* %v.i) #3, !dbg !30
+  call void @capture(i32* %a), !dbg !31
+  br label %if.end, !dbg !32
+
+if.else:                                          ; preds = %entry
+  call void @llvm.dbg.declare(metadata i32* %b, metadata !33, metadata !16), !dbg !34
+  store i32 42, i32* %b, align 4, !dbg !34
+  store i32 3, i32* %v.i1, align 4, !dbg !17
+  call void @capture(i32* %v.i1) #3, !dbg !35
+  call void @capture(i32* %b), !dbg !36
+  br label %if.end
+
+if.end:                                           ; preds = %if.else, %if.then
+  ret void, !dbg !37
+}
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+declare void @capture(i32*) #2
+
+attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone }
+attributes #2 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #3 = { nounwind }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!11, !12, !13}
+!llvm.ident = !{!14}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3)
+!1 = !DIFile(filename: "t.cpp", directory: "D:\5Csrc\5Cllvm\5Cbuild")
+!2 = !{}
+!3 = !{!4, !8}
+!4 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 7, type: !5, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, variables: !2)
+!5 = !DISubroutineType(types: !6)
+!6 = !{null, !7}
+!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!8 = distinct !DISubprogram(name: "will_be_inlined", linkageName: "\01?will_be_inlined@@YAXXZ", scope: !1, file: !1, line: 3, type: !9, isLocal: true, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, variables: !2)
+!9 = !DISubroutineType(types: !10)
+!10 = !{null}
+!11 = !{i32 2, !"CodeView", i32 1}
+!12 = !{i32 2, !"Debug Info Version", i32 3}
+!13 = !{i32 1, !"PIC Level", i32 2}
+!14 = !{!"clang version 3.9.0 "}
+!15 = !DILocalVariable(name: "v", scope: !8, file: !1, line: 4, type: !7)
+!16 = !DIExpression()
+!17 = !DILocation(line: 4, column: 7, scope: !8, inlinedAt: !18)
+!18 = distinct !DILocation(line: 14, column: 5, scope: !19)
+!19 = distinct !DILexicalBlock(scope: !20, file: !1, line: 12, column: 10)
+!20 = distinct !DILexicalBlock(scope: !4, file: !1, line: 8, column: 7)
+!21 = !DILocation(line: 4, column: 7, scope: !8, inlinedAt: !22)
+!22 = distinct !DILocation(line: 10, column: 5, scope: !23)
+!23 = distinct !DILexicalBlock(scope: !20, file: !1, line: 8, column: 14)
+!24 = !DILocalVariable(name: "param", arg: 1, scope: !4, file: !1, line: 7, type: !7)
+!25 = !DILocation(line: 7, column: 23, scope: !4)
+!26 = !DILocation(line: 8, column: 7, scope: !20)
+!27 = !DILocation(line: 8, column: 7, scope: !4)
+!28 = !DILocalVariable(name: "a", scope: !23, file: !1, line: 9, type: !7)
+!29 = !DILocation(line: 9, column: 9, scope: !23)
+!30 = !DILocation(line: 5, column: 3, scope: !8, inlinedAt: !22)
+!31 = !DILocation(line: 11, column: 5, scope: !23)
+!32 = !DILocation(line: 12, column: 3, scope: !23)
+!33 = !DILocalVariable(name: "b", scope: !19, file: !1, line: 13, type: !7)
+!34 = !DILocation(line: 13, column: 9, scope: !19)
+!35 = !DILocation(line: 5, column: 3, scope: !8, inlinedAt: !18)
+!36 = !DILocation(line: 15, column: 5, scope: !19)
+!37 = !DILocation(line: 17, column: 1, scope: !4)

Modified: llvm/trunk/test/DebugInfo/COFF/multifile.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/multifile.ll?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/multifile.ll (original)
+++ llvm/trunk/test/DebugInfo/COFF/multifile.ll Wed Feb 10 14:55:49 2016
@@ -28,7 +28,7 @@
 ; X86:      calll   _g
 ; X86:      .cv_loc 0 1 8 0 # one.c:8:0
 ; X86:      ret
-; X86-NEXT: [[END_OF_F:.*]]:
+; X86:      [[END_OF_F:.?Lfunc_end.*]]:
 ;
 ; X86-LABEL: .section        .debug$S,"dr"
 ; X86-NEXT: .long   4
@@ -134,7 +134,7 @@
 ; X64:      .cv_loc 0 2 8 0 # one.c:8:0
 ; X64:      addq    $40, %rsp
 ; X64-NEXT: ret
-; X64-NEXT: [[END_OF_F:.*]]:
+; X64:      [[END_OF_F:.?Lfunc_end.*]]:
 ;
 ; X64-LABEL: .section        .debug$S,"dr"
 ; X64-NEXT: .long   4

Modified: llvm/trunk/test/DebugInfo/COFF/multifunction.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/multifunction.ll?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/multifunction.ll (original)
+++ llvm/trunk/test/DebugInfo/COFF/multifunction.ll Wed Feb 10 14:55:49 2016
@@ -29,7 +29,7 @@
 ; X86:      calll   _z
 ; X86:      .cv_loc 0 1 5 43 # source.c:5:43
 ; X86:      ret
-; X86-NEXT: [[END_OF_X:.*]]:
+; X86:      [[END_OF_X:.?Lfunc_end.*]]:
 ;
 ; X86-LABEL: _y:
 ; X86:      # BB
@@ -37,7 +37,7 @@
 ; X86:      calll   _z
 ; X86:      .cv_loc 1 1 9 53 # source.c:9:53
 ; X86:      ret
-; X86-NEXT: [[END_OF_Y:.*]]:
+; X86:      [[END_OF_Y:.?Lfunc_end.*]]:
 ;
 ; X86-LABEL: _f:
 ; X86:      # BB
@@ -49,7 +49,7 @@
 ; X86:      calll   _z
 ; X86:      .cv_loc 2 1 15 73 # source.c:15:73
 ; X86:      ret
-; X86-NEXT: [[END_OF_F:.*]]:
+; X86:      [[END_OF_F:.?Lfunc_end.*]]:
 ;
 ; X86-LABEL: .section        .debug$S,"dr"
 ; X86-NEXT: .long   4
@@ -281,7 +281,7 @@
 ; X64:      .cv_loc 0 1 5 43 # source.c:5:43
 ; X64:      addq    $40, %rsp
 ; X64-NEXT: ret
-; X64-NEXT: [[END_OF_X:.*]]:
+; X64:      [[END_OF_X:.?Lfunc_end.*]]:
 ;
 ; X64-LABEL: y:
 ; X64-NEXT: .L{{.*}}:
@@ -293,7 +293,7 @@
 ; X64:      .cv_loc 1 1 9 53 # source.c:9:53
 ; X64:      addq    $40, %rsp
 ; X64-NEXT: ret
-; X64-NEXT: [[END_OF_Y:.*]]:
+; X64:      [[END_OF_Y:.?Lfunc_end.*]]:
 ;
 ; X64-LABEL: f:
 ; X64-NEXT: .L{{.*}}:
@@ -309,7 +309,7 @@
 ; X64:      .cv_loc 2 1 15 73 # source.c:15:73
 ; X64:      addq    $40, %rsp
 ; X64-NEXT: ret
-; X64-NEXT: [[END_OF_F:.*]]:
+; X64:      [[END_OF_F:.?Lfunc_end.*]]:
 ;
 ; X64-LABEL: .section        .debug$S,"dr"
 ; X64-NEXT: .long   4

Modified: llvm/trunk/test/DebugInfo/COFF/simple.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/simple.ll?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/simple.ll (original)
+++ llvm/trunk/test/DebugInfo/COFF/simple.ll Wed Feb 10 14:55:49 2016
@@ -18,7 +18,7 @@
 ; X86:      calll   _g
 ; X86:      .cv_loc 0 1 5 0 # test.c:5:0
 ; X86:      ret
-; X86-NEXT: [[END_OF_F:.*]]:
+; X86:      [[END_OF_F:Lfunc_end.*]]:
 ;
 ; X86-LABEL: .section        .debug$S,"dr"
 ; X86-NEXT: .long   4
@@ -106,7 +106,7 @@
 ; X64:      .cv_loc 0 1 5 0 # test.c:5:0
 ; X64:      addq    $40, %rsp
 ; X64-NEXT: ret
-; X64-NEXT: [[END_OF_F:.*]]:
+; X64:      [[END_OF_F:.?Lfunc_end.*]]:
 ;
 ; X64-LABEL: .section        .debug$S,"dr"
 ; X64-NEXT: .long   4

Modified: llvm/trunk/test/DebugInfo/COFF/tail-call-without-lexical-scopes.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/tail-call-without-lexical-scopes.ll?rev=260432&r1=260431&r2=260432&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/tail-call-without-lexical-scopes.ll (original)
+++ llvm/trunk/test/DebugInfo/COFF/tail-call-without-lexical-scopes.ll Wed Feb 10 14:55:49 2016
@@ -20,7 +20,7 @@
 ; X86-LABEL: {{^}}"?bar@@YAXHZZ":
 ; X86:      .cv_loc  1 1 4 0
 ; X86:      jmp "?foo@@YAXXZ"
-; X86-NEXT: [[END_OF_BAR:^L.*]]:{{$}}
+; X86:      [[END_OF_BAR:.?Lfunc_end.*]]:{{$}}
 ; X86-NOT:  ret
 
 ; X86-LABEL: .section        .debug$S,"dr"
@@ -35,14 +35,14 @@ target datalayout = "e-m:w-p:32:32-i64:6
 target triple = "i686-pc-win32"
 
 ; Function Attrs: nounwind
-define void @"\01?spam@@YAXXZ"() #0 {
+define void @"\01?spam@@YAXXZ"() #0 !dbg !4 {
 entry:
   tail call void @"\01?bar@@YAXHZZ"(), !dbg !11
   ret void, !dbg !12
 }
 
 ; Function Attrs: nounwind
-define internal void @"\01?bar@@YAXHZZ"() #0 {
+define internal void @"\01?bar@@YAXHZZ"() #0 !dbg !7 {
 entry:
   tail call void @"\01?foo@@YAXXZ"() #2, !dbg !13
   ret void, !dbg !14




More information about the llvm-commits mailing list