<p dir="ltr"><br>
On Mar 16, 2014 7:00 PM, "David Blaikie" <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
><br>
> Author: dblaikie<br>
> Date: Sun Mar 16 20:52:11 2014<br>
> New Revision: 204027</p>
<p dir="ltr">Test case accidentally committed separately in r204026. </p>
<p dir="ltr">><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=204027&view=rev">http://llvm.org/viewvc/llvm-project?rev=204027&view=rev</a><br>
> Log:<br>
> DebugInfo: Improve reuse of file table entries in asm debug info<br>
><br>
> The previous deduping strategy was woefully inadequate - it only<br>
> considered the most recent file used and avoided emitting a duplicate in<br>
> that case - never considering the a/b/a scenario.<br>
><br>
> It was also lacking when it came to directory paths as the previous<br>
> filename would never match the current if the filename had been split<br>
> into file and directory components.<br>
><br>
> This change builds caching functionality into the line table at the<br>
> lowest level in an optional form (a file number of 0 indicates that one<br>
> should be chosen and returned) and will eventually be reused by the<br>
> normal source level debugging DWARF emission.<br>
><br>
> Modified:<br>
>     llvm/trunk/include/llvm/MC/MCContext.h<br>
>     llvm/trunk/include/llvm/MC/MCDwarf.h<br>
>     llvm/trunk/include/llvm/MC/MCStreamer.h<br>
>     llvm/trunk/lib/MC/MCAsmStreamer.cpp<br>
>     llvm/trunk/lib/MC/MCDwarf.cpp<br>
>     llvm/trunk/lib/MC/MCNullStreamer.cpp<br>
>     llvm/trunk/lib/MC/MCParser/AsmParser.cpp<br>
>     llvm/trunk/lib/MC/MCStreamer.cpp<br>
>     llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s<br>
><br>
> Modified: llvm/trunk/include/llvm/MC/MCContext.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=204027&r1=204026&r2=204027&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=204027&r1=204026&r2=204027&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/include/llvm/MC/MCContext.h (original)<br>
> +++ llvm/trunk/include/llvm/MC/MCContext.h Sun Mar 16 20:52:11 2014<br>
> @@ -371,7 +371,9 @@ namespace llvm {<br>
>      bool getGenDwarfForAssembly() { return GenDwarfForAssembly; }<br>
>      void setGenDwarfForAssembly(bool Value) { GenDwarfForAssembly = Value; }<br>
>      unsigned getGenDwarfFileNumber() { return GenDwarfFileNumber; }<br>
> -    unsigned nextGenDwarfFileNumber() { return ++GenDwarfFileNumber; }<br>
> +    void setGenDwarfFileNumber(unsigned FileNumber) {<br>
> +      GenDwarfFileNumber = FileNumber;<br>
> +    }<br>
>      const MCSection *getGenDwarfSection() { return GenDwarfSection; }<br>
>      void setGenDwarfSection(const MCSection *Sec) { GenDwarfSection = Sec; }<br>
>      MCSymbol *getGenDwarfSectionStartSym() { return GenDwarfSectionStartSym; }<br>
><br>
> Modified: llvm/trunk/include/llvm/MC/MCDwarf.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=204027&r1=204026&r2=204027&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=204027&r1=204026&r2=204027&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/include/llvm/MC/MCDwarf.h (original)<br>
> +++ llvm/trunk/include/llvm/MC/MCDwarf.h Sun Mar 16 20:52:11 2014<br>
> @@ -16,6 +16,7 @@<br>
>  #define LLVM_MC_MCDWARF_H<br>
><br>
>  #include "llvm/ADT/StringRef.h"<br>
> +#include "llvm/ADT/StringMap.h"<br>
>  #include "llvm/ADT/MapVector.h"<br>
>  #include "llvm/Support/Compiler.h"<br>
>  #include "llvm/Support/Dwarf.h"<br>
> @@ -179,8 +180,9 @@ struct MCDwarfLineTableHeader {<br>
>    MCSymbol *Label;<br>
>    SmallVector<std::string, 3> MCDwarfDirs;<br>
>    SmallVector<MCDwarfFile, 3> MCDwarfFiles;<br>
> +  StringMap<unsigned> SourceIdMap;<br>
>    MCDwarfLineTableHeader() : Label(nullptr) {}<br>
> -  unsigned getFile(StringRef Directory, StringRef FileName, unsigned FileNumber);<br>
> +  unsigned getFile(StringRef Directory, StringRef FileName, unsigned FileNumber = 0);<br>
>    std::pair<MCSymbol *, MCSymbol *> Emit(MCStreamer *MCOS) const;<br>
>  };<br>
><br>
> @@ -195,7 +197,7 @@ public:<br>
>    // This emits the Dwarf file and the line tables for a given Compile Unit.<br>
>    const MCSymbol *EmitCU(MCStreamer *MCOS) const;<br>
><br>
> -  unsigned getFile(StringRef Directory, StringRef FileName, unsigned FileNumber);<br>
> +  unsigned getFile(StringRef Directory, StringRef FileName, unsigned FileNumber = 0);<br>
><br>
>    MCSymbol *getLabel() const {<br>
>      return Header.Label;<br>
><br>
> Modified: llvm/trunk/include/llvm/MC/MCStreamer.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=204027&r1=204026&r2=204027&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=204027&r1=204026&r2=204027&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/include/llvm/MC/MCStreamer.h (original)<br>
> +++ llvm/trunk/include/llvm/MC/MCStreamer.h Sun Mar 16 20:52:11 2014<br>
> @@ -628,8 +628,9 @@ public:<br>
>    /// EmitDwarfFileDirective - Associate a filename with a specified logical<br>
>    /// file number.  This implements the DWARF2 '.file 4 "foo.c"' assembler<br>
>    /// directive.<br>
> -  virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,<br>
> -                                      StringRef Filename, unsigned CUID = 0);<br>
> +  virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,<br>
> +                                          StringRef Filename,<br>
> +                                          unsigned CUID = 0);<br>
><br>
>    /// EmitDwarfLocDirective - This implements the DWARF2<br>
>    // '.loc fileno lineno ...' assembler directive.<br>
><br>
> Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=204027&r1=204026&r2=204027&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=204027&r1=204026&r2=204027&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)<br>
> +++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Sun Mar 16 20:52:11 2014<br>
> @@ -197,8 +197,9 @@ public:<br>
>                           unsigned char Value = 0) override;<br>
><br>
>    void EmitFileDirective(StringRef Filename) override;<br>
> -  bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,<br>
> -                              StringRef Filename, unsigned CUID = 0) override;<br>
> +  unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,<br>
> +                                  StringRef Filename,<br>
> +                                  unsigned CUID = 0) override;<br>
>    void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,<br>
>                               unsigned Column, unsigned Flags,<br>
>                               unsigned Isa, unsigned Discriminator,<br>
> @@ -843,8 +844,10 @@ void MCAsmStreamer::EmitFileDirective(St<br>
>    EmitEOL();<br>
>  }<br>
><br>
> -bool MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,<br>
> -                                           StringRef Filename, unsigned CUID) {<br>
> +unsigned MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo,<br>
> +                                               StringRef Directory,<br>
> +                                               StringRef Filename,<br>
> +                                               unsigned CUID) {<br>
>    if (!UseDwarfDirectory && !Directory.empty()) {<br>
>      if (sys::path::is_absolute(Filename))<br>
>        return EmitDwarfFileDirective(FileNo, "", Filename, CUID);<br>
><br>
> Modified: llvm/trunk/lib/MC/MCDwarf.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=204027&r1=204026&r2=204027&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=204027&r1=204026&r2=204027&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/lib/MC/MCDwarf.cpp (original)<br>
> +++ llvm/trunk/lib/MC/MCDwarf.cpp Sun Mar 16 20:52:11 2014<br>
> @@ -336,7 +336,18 @@ unsigned MCDwarfLineTable::getFile(Strin<br>
>    return Header.getFile(Directory, FileName, FileNumber);<br>
>  }<br>
><br>
> -unsigned MCDwarfLineTableHeader::getFile(StringRef Directory, StringRef FileName, unsigned FileNumber) {<br>
> +unsigned MCDwarfLineTableHeader::getFile(StringRef Directory,<br>
> +                                         StringRef FileName,<br>
> +                                         unsigned FileNumber) {<br>
> +  if (FileNumber == 0) {<br>
> +    FileNumber = SourceIdMap.size() + 1;<br>
> +    assert((MCDwarfFiles.empty() || FileNumber == MCDwarfFiles.size()) &&<br>
> +           "Don't mix autonumbered and explicit numbered line table usage");<br>
> +    StringMapEntry<unsigned> &Ent = SourceIdMap.GetOrCreateValue(<br>
> +        (Directory + Twine('\0') + FileName).str(), FileNumber);<br>
> +    if (Ent.getValue() != FileNumber)<br>
> +      return Ent.getValue();<br>
> +  }<br>
>    // Make space for this FileNumber in the MCDwarfFiles vector if needed.<br>
>    MCDwarfFiles.resize(FileNumber + 1);<br>
><br>
><br>
> Modified: llvm/trunk/lib/MC/MCNullStreamer.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCNullStreamer.cpp?rev=204027&r1=204026&r2=204027&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCNullStreamer.cpp?rev=204027&r1=204026&r2=204027&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/lib/MC/MCNullStreamer.cpp (original)<br>
> +++ llvm/trunk/lib/MC/MCNullStreamer.cpp Sun Mar 16 20:52:11 2014<br>
> @@ -85,10 +85,10 @@ namespace {<br>
>                             unsigned char Value = 0) override { return false; }<br>
><br>
>      void EmitFileDirective(StringRef Filename) override {}<br>
> -    bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,<br>
> -                                StringRef Filename,<br>
> -                                unsigned CUID = 0) override {<br>
> -      return false;<br>
> +    unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,<br>
> +                                    StringRef Filename,<br>
> +                                    unsigned CUID = 0) override {<br>
> +      return 0;<br>
>      }<br>
>      void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,<br>
>                                 unsigned Column, unsigned Flags,<br>
><br>
> Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=204027&r1=204026&r2=204027&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=204027&r1=204026&r2=204027&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)<br>
> +++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Sun Mar 16 20:52:11 2014<br>
> @@ -640,9 +640,8 @@ bool AsmParser::Run(bool NoInitialTextSe<br>
>      MCSymbol *SectionStartSym = getContext().CreateTempSymbol();<br>
>      getStreamer().EmitLabel(SectionStartSym);<br>
>      getContext().setGenDwarfSectionStartSym(SectionStartSym);<br>
> -    getStreamer().EmitDwarfFileDirective(getContext().nextGenDwarfFileNumber(),<br>
> -                                         StringRef(),<br>
> -                                         getContext().getMainFileName());<br>
> +    getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(<br>
> +        0, StringRef(), getContext().getMainFileName()));<br>
>    }<br>
><br>
>    // While we have input, parse each statement.<br>
> @@ -1589,14 +1588,10 @@ bool AsmParser::parseStatement(ParseStat<br>
>      // If we previously parsed a cpp hash file line comment then make sure the<br>
>      // current Dwarf File is for the CppHashFilename if not then emit the<br>
>      // Dwarf File table for it and adjust the line number for the .loc.<br>
> -    const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles =<br>
> -        getContext().getMCDwarfFiles();<br>
>      if (CppHashFilename.size() != 0) {<br>
> -      if (MCDwarfFiles[getContext().getGenDwarfFileNumber()].Name !=<br>
> -          CppHashFilename)<br>
> -        getStreamer().EmitDwarfFileDirective(<br>
> -            getContext().nextGenDwarfFileNumber(), StringRef(),<br>
> -            CppHashFilename);<br>
> +      unsigned FileNumber = getStreamer().EmitDwarfFileDirective(<br>
> +          0, StringRef(), CppHashFilename);<br>
> +      getContext().setGenDwarfFileNumber(FileNumber);<br>
><br>
>        // Since SrcMgr.FindLineNumber() is slow and messes up the SourceMgr's<br>
>        // cache with the different Loc from the call above we save the last<br>
> @@ -2762,7 +2757,8 @@ bool AsmParser::parseDirectiveFile(SMLoc<br>
>              "input can't have .file dwarf directives when -g is "<br>
>              "used to generate dwarf debug info for assembly code");<br>
><br>
> -    if (getStreamer().EmitDwarfFileDirective(FileNumber, Directory, Filename))<br>
> +    if (getStreamer().EmitDwarfFileDirective(FileNumber, Directory, Filename) ==<br>
> +        0)<br>
>        Error(FileNumberLoc, "file number already allocated");<br>
>    }<br>
><br>
><br>
> Modified: llvm/trunk/lib/MC/MCStreamer.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=204027&r1=204026&r2=204027&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=204027&r1=204026&r2=204027&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/lib/MC/MCStreamer.cpp (original)<br>
> +++ llvm/trunk/lib/MC/MCStreamer.cpp Sun Mar 16 20:52:11 2014<br>
> @@ -174,10 +174,10 @@ void MCStreamer::EmitZeros(uint64_t NumB<br>
>    EmitFill(NumBytes, 0);<br>
>  }<br>
><br>
> -bool MCStreamer::EmitDwarfFileDirective(unsigned FileNo,<br>
> -                                        StringRef Directory,<br>
> -                                        StringRef Filename, unsigned CUID) {<br>
> -  return getContext().GetDwarfFile(Directory, Filename, FileNo, CUID) == 0;<br>
> +unsigned MCStreamer::EmitDwarfFileDirective(unsigned FileNo,<br>
> +                                            StringRef Directory,<br>
> +                                            StringRef Filename, unsigned CUID) {<br>
> +  return getContext().GetDwarfFile(Directory, Filename, FileNo, CUID);<br>
>  }<br>
><br>
>  void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,<br>
><br>
> Modified: llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s?rev=204027&r1=204026&r2=204027&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s?rev=204027&r1=204026&r2=204027&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s (original)<br>
> +++ llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s Sun Mar 16 20:52:11 2014<br>
> @@ -4,6 +4,7 @@<br>
>  # 100 "t.s" 1<br>
>  .globl _bar<br>
>  _bar:<br>
> +       movl    $0, %eax<br>
>  # 3 "inc/g.s"<br>
>         movl    $0, %eax<br>
>  L1:    leave<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</p>