<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 15, 2016 at 4:09 PM, Reid Kleckner via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rnk<br>
Date: Fri Jan 15 18:09:09 2016<br>
New Revision: 257966<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=257966&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=257966&view=rev</a><br>
Log:<br>
[codeview] Remove custom line info struct in favor of DebugLoc<br>
<br>
The only functional change would be that we might emit multiple filename<br>
segments on code like this:<br>
<br>
  void f() {<br>
  #include "p1/../t.h"<br>
  #include "p2/../t.h"<br>
  }<br>
<br>
I believe these get separate DIFile metadata nodes, but will have the<br>
same canonicalized absolute path. Previously by computing the path up<br>
front and comparing it we would merge the line info segments.<br></blockquote><div><br></div><div>If I recall correctly, I think we probably want to do some kind of file canonicalization on paths like this to help LTO... but maybe I'm misremembering and/or there may be no good answer (when you do two compilations from two different directories (so different relative paths) & then LTO those together, etc - well, I suppose the compile unit should have the path that these are relative to, so might be able to do it)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=257966&r1=257965&r2=257966&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=257966&r1=257965&r2=257966&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Fri Jan 15 18:09:09 2016<br>
@@ -22,20 +22,13 @@ using namespace llvm::codeview;<br>
<br>
 namespace llvm {<br>
<br>
-StringRef CodeViewDebug::getFullFilepath(const MDNode *S) {<br>
-  assert(S);<br>
-  assert((isa<DICompileUnit>(S) || isa<DIFile>(S) || isa<DISubprogram>(S) ||<br>
-          isa<DILexicalBlockBase>(S)) &&<br>
-         "Unexpected scope info");<br>
-<br>
-  auto *Scope = cast<DIScope>(S);<br>
-  StringRef Dir = Scope->getDirectory(),<br>
-            Filename = Scope->getFilename();<br>
-  std::string &Filepath =<br>
-      DirAndFilenameToFilepathMap[std::make_pair(Dir, Filename)];<br>
+StringRef CodeViewDebug::getFullFilepath(const DIFile *File) {<br>
+  std::string &Filepath = FileToFilepathMap[File];<br>
   if (!Filepath.empty())<br>
     return Filepath;<br>
<br>
+  StringRef Dir = File->getDirectory(), Filename = File->getFilename();<br>
+<br>
   // Clang emits directory and relative filename info into the IR, but CodeView<br>
   // operates on full paths.  We could change Clang to emit full paths too, but<br>
   // that would increase the IR size and probably not needed for other users.<br>
@@ -82,36 +75,25 @@ StringRef CodeViewDebug::getFullFilepath<br>
 }<br>
<br>
 void CodeViewDebug::maybeRecordLocation(DebugLoc DL,<br>
-                                                const MachineFunction *MF) {<br>
-  const MDNode *Scope = DL.getScope();<br>
+                                        const MachineFunction *MF) {<br>
+  // Skip this instruction if it has the same location as the previous one.<br>
+  if (DL == CurFn->LastLoc)<br>
+    return;<br>
+<br>
+  const DIScope *Scope = DL.get()->getScope();<br>
   if (!Scope)<br>
     return;<br>
-  unsigned LineNumber = DL.getLine();<br>
+<br>
   // Skip this line if it is longer than the maximum we can record.<br>
-  if (LineNumber > COFF::CVL_MaxLineNumber)<br>
+  if (DL.getLine() > COFF::CVL_MaxLineNumber)<br>
     return;<br>
<br>
-  unsigned ColumnNumber = DL.getCol();<br>
-  // Truncate the column number if it is longer than the maximum we can record.<br>
-  if (ColumnNumber > COFF::CVL_MaxColumnNumber)<br>
-    ColumnNumber = 0;<br>
-<br>
-  StringRef Filename = getFullFilepath(Scope);<br>
-<br>
-  // Skip this instruction if it has the same file:line as the previous one.<br>
-  assert(CurFn);<br>
-  if (!CurFn->Instrs.empty()) {<br>
-    const InstrInfoTy &LastInstr = InstrInfo[CurFn->Instrs.back()];<br>
-    if (LastInstr.Filename == Filename && LastInstr.LineNumber == LineNumber &&<br>
-        LastInstr.ColumnNumber == ColumnNumber)<br>
-      return;<br>
-  }<br>
-  FileNameRegistry.add(Filename);<br>
+  CurFn->LastLoc = DL;<br>
<br>
   MCSymbol *MCL = Asm->MMI->getContext().createTempSymbol();<br>
   Asm->OutStreamer->EmitLabel(MCL);<br>
   CurFn->Instrs.push_back(MCL);<br>
-  InstrInfo[MCL] = InstrInfoTy(Filename, LineNumber, ColumnNumber);<br>
+  LabelsAndLocs[MCL] = DL;<br>
 }<br>
<br>
 CodeViewDebug::CodeViewDebug(AsmPrinter *AP)<br>
@@ -195,6 +177,10 @@ static void EmitLabelDiff(MCStreamer &St<br>
   Streamer.EmitValue(AddrDelta, Size);<br>
 }<br>
<br>
+static const DIFile *getFileFromLoc(DebugLoc DL) {<br>
+  return DL.get()->getScope()->getFile();<br>
+}<br>
+<br>
 void CodeViewDebug::emitDebugInfoForFunction(const Function *GV) {<br>
   // For each function there is a separate subsection<br>
   // which holds the PC to file:line table.<br>
@@ -258,13 +244,14 @@ void CodeViewDebug::emitDebugInfoForFunc<br>
   // number of the respective instruction that starts a new segment.<br>
   DenseMap<size_t, size_t> FilenameSegmentLengths;<br>
   size_t LastSegmentEnd = 0;<br>
-  StringRef PrevFilename = InstrInfo[FI.Instrs[0]].Filename;<br>
+  const DIFile *PrevFile = getFileFromLoc(LabelsAndLocs[FI.Instrs[0]]);<br>
   for (size_t J = 1, F = FI.Instrs.size(); J != F; ++J) {<br>
-    if (PrevFilename == InstrInfo[FI.Instrs[J]].Filename)<br>
+    const DIFile *CurFile = getFileFromLoc(LabelsAndLocs[FI.Instrs[J]]);<br>
+    if (PrevFile == CurFile)<br>
       continue;<br>
     FilenameSegmentLengths[LastSegmentEnd] = J - LastSegmentEnd;<br>
     LastSegmentEnd = J;<br>
-    PrevFilename = InstrInfo[FI.Instrs[J]].Filename;<br>
+    PrevFile = CurFile;<br>
   }<br>
   FilenameSegmentLengths[LastSegmentEnd] = FI.Instrs.size() - LastSegmentEnd;<br>
<br>
@@ -297,8 +284,11 @@ void CodeViewDebug::emitDebugInfoForFunc<br>
     for (size_t ColSegI = LastSegmentStart,<br>
                 ColSegEnd = ColSegI + FilenameSegmentLengths[LastSegmentStart];<br>
          ColSegI != ColSegEnd; ++ColSegI) {<br>
-      unsigned ColumnNumber = InstrInfo[FI.Instrs[ColSegI]].ColumnNumber;<br>
-      assert(ColumnNumber <= COFF::CVL_MaxColumnNumber);<br>
+      unsigned ColumnNumber = LabelsAndLocs[FI.Instrs[ColSegI]].getCol();<br>
+      // Truncate the column number if it is longer than the maximum we can<br>
+      // record.<br>
+      if (ColumnNumber > COFF::CVL_MaxColumnNumber)<br>
+        ColumnNumber = 0;<br>
       Asm->EmitInt16(ColumnNumber); // Start column<br>
       Asm->EmitInt16(0);            // End column<br>
     }<br>
@@ -307,22 +297,21 @@ void CodeViewDebug::emitDebugInfoForFunc<br>
<br>
   for (size_t J = 0, F = FI.Instrs.size(); J != F; ++J) {<br>
     MCSymbol *Instr = FI.Instrs[J];<br>
-    assert(InstrInfo.count(Instr));<br>
+    assert(LabelsAndLocs.count(Instr));<br>
<br>
     if (FilenameSegmentLengths.count(J)) {<br>
       // We came to a beginning of a new filename segment.<br>
       FinishPreviousChunk();<br>
-      StringRef CurFilename = InstrInfo[FI.Instrs[J]].Filename;<br>
-      assert(FileNameRegistry.Infos.count(CurFilename));<br>
-      size_t IndexInStringTable =<br>
-          FileNameRegistry.Infos[CurFilename].FilenameID;<br>
+      const DIFile *File = getFileFromLoc(LabelsAndLocs[FI.Instrs[J]]);<br>
+      StringRef CurFilename = getFullFilepath(File);<br>
+      size_t IndexInFileTable = FileNameRegistry.add(CurFilename);<br>
       // Each segment starts with the offset of the filename<br>
       // in the string table.<br>
       Asm->OutStreamer->AddComment(<br>
           "Segment for file '" + Twine(CurFilename) + "' begins");<br>
       MCSymbol *FileSegmentBegin = Asm->MMI->getContext().createTempSymbol();<br>
       Asm->OutStreamer->EmitLabel(FileSegmentBegin);<br>
-      Asm->EmitInt32(8 * IndexInStringTable);<br>
+      Asm->EmitInt32(8 * IndexInFileTable);<br>
<br>
       // Number of PC records in the lookup table.<br>
       size_t SegmentLength = FilenameSegmentLengths[J];<br>
@@ -337,7 +326,7 @@ void CodeViewDebug::emitDebugInfoForFunc<br>
<br>
     // The first PC with the given linenumber and the linenumber itself.<br>
     EmitLabelDiff(*Asm->OutStreamer, Fn, Instr);<br>
-    uint32_t LineNumber = InstrInfo[Instr].LineNumber;<br>
+    uint32_t LineNumber = LabelsAndLocs[Instr].getLine();<br>
     assert(LineNumber <= COFF::CVL_MaxLineNumber);<br>
     uint32_t LineData = LineNumber | COFF::CVL_IsStatement;<br>
     Asm->EmitInt32(LineData);<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=257966&r1=257965&r2=257966&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h?rev=257966&r1=257965&r2=257966&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h Fri Jan 15 18:09:09 2016<br>
@@ -36,10 +36,12 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDe<br>
   // For each function, store a vector of labels to its instructions, as well as<br>
   // to the end of the function.<br>
   struct FunctionInfo {<br>
+    DebugLoc LastLoc;<br>
     SmallVector<MCSymbol *, 10> Instrs;<br>
     MCSymbol *End;<br>
     FunctionInfo() : End(nullptr) {}<br>
-  } *CurFn;<br>
+  };<br>
+  FunctionInfo *CurFn;<br>
<br>
   typedef DenseMap<const Function *, FunctionInfo> FnDebugInfoTy;<br>
   FnDebugInfoTy FnDebugInfo;<br>
@@ -47,20 +49,7 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDe<br>
   // order while emitting subsections.<br>
   SmallVector<const Function *, 10> VisitedFunctions;<br>
<br>
-  // InstrInfoTy - Holds the Filename:LineNumber information for every<br>
-  // instruction with a unique debug location.<br>
-  struct InstrInfoTy {<br>
-    StringRef Filename;<br>
-    unsigned LineNumber;<br>
-    unsigned ColumnNumber;<br>
-<br>
-    InstrInfoTy() : LineNumber(0), ColumnNumber(0) {}<br>
-<br>
-    InstrInfoTy(StringRef Filename, unsigned LineNumber, unsigned ColumnNumber)<br>
-        : Filename(Filename), LineNumber(LineNumber),<br>
-          ColumnNumber(ColumnNumber) {}<br>
-  };<br>
-  DenseMap<MCSymbol *, InstrInfoTy> InstrInfo;<br>
+  DenseMap<MCSymbol *, DebugLoc> LabelsAndLocs;<br>
<br>
   // FileNameRegistry - Manages filenames observed while generating debug info<br>
   // by filtering out duplicates and bookkeeping the offsets in the string<br>
@@ -81,14 +70,17 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDe<br>
     }<br>
<br>
     // Add Filename to the registry, if it was not observed before.<br>
-    void add(StringRef Filename) {<br>
-      if (Infos.count(Filename))<br>
-        return;<br>
+    size_t add(StringRef Filename) {<br>
       size_t OldSize = Infos.size();<br>
-      Infos[Filename].FilenameID = OldSize;<br>
-      Infos[Filename].StartOffset = LastOffset;<br>
-      LastOffset += Filename.size() + 1;<br>
-      Filenames.push_back(Filename);<br>
+      bool Inserted;<br>
+      StringMap<PerFileInfo>::iterator It;<br>
+      std::tie(It, Inserted) = Infos.insert(<br>
+          std::make_pair(Filename, PerFileInfo{OldSize, LastOffset}));<br>
+      if (Inserted) {<br>
+        LastOffset += Filename.size() + 1;<br>
+        Filenames.push_back(Filename);<br>
+      }<br>
+      return It->second.FilenameID;<br>
     }<br>
<br>
     void clear() {<br>
@@ -98,17 +90,16 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDe<br>
     }<br>
   } FileNameRegistry;<br>
<br>
-  typedef std::map<std::pair<StringRef, StringRef>, std::string><br>
-      DirAndFilenameToFilepathMapTy;<br>
-  DirAndFilenameToFilepathMapTy DirAndFilenameToFilepathMap;<br>
-  StringRef getFullFilepath(const MDNode *S);<br>
+  typedef std::map<const DIFile *, std::string> FileToFilepathMapTy;<br>
+  FileToFilepathMapTy FileToFilepathMap;<br>
+  StringRef getFullFilepath(const DIFile *S);<br>
<br>
   void maybeRecordLocation(DebugLoc DL, const MachineFunction *MF);<br>
<br>
   void clear() {<br>
     assert(CurFn == nullptr);<br>
     FileNameRegistry.clear();<br>
-    InstrInfo.clear();<br>
+    LabelsAndLocs.clear();<br>
   }<br>
<br>
   void emitDebugInfoForFunction(const Function *GV);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>