[llvm] r204027 - DebugInfo: Improve reuse of file table entries in asm debug info
David Blaikie
dblaikie at gmail.com
Sun Mar 16 19:03:23 PDT 2014
On Mar 16, 2014 7:00 PM, "David Blaikie" <dblaikie at gmail.com> wrote:
>
> Author: dblaikie
> Date: Sun Mar 16 20:52:11 2014
> New Revision: 204027
Test case accidentally committed separately in r204026.
>
> URL: http://llvm.org/viewvc/llvm-project?rev=204027&view=rev
> Log:
> DebugInfo: Improve reuse of file table entries in asm debug info
>
> The previous deduping strategy was woefully inadequate - it only
> considered the most recent file used and avoided emitting a duplicate in
> that case - never considering the a/b/a scenario.
>
> It was also lacking when it came to directory paths as the previous
> filename would never match the current if the filename had been split
> into file and directory components.
>
> This change builds caching functionality into the line table at the
> lowest level in an optional form (a file number of 0 indicates that one
> should be chosen and returned) and will eventually be reused by the
> normal source level debugging DWARF emission.
>
> Modified:
> llvm/trunk/include/llvm/MC/MCContext.h
> llvm/trunk/include/llvm/MC/MCDwarf.h
> llvm/trunk/include/llvm/MC/MCStreamer.h
> llvm/trunk/lib/MC/MCAsmStreamer.cpp
> llvm/trunk/lib/MC/MCDwarf.cpp
> llvm/trunk/lib/MC/MCNullStreamer.cpp
> llvm/trunk/lib/MC/MCParser/AsmParser.cpp
> llvm/trunk/lib/MC/MCStreamer.cpp
> llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s
>
> Modified: llvm/trunk/include/llvm/MC/MCContext.h
> URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=204027&r1=204026&r2=204027&view=diff
>
==============================================================================
> --- llvm/trunk/include/llvm/MC/MCContext.h (original)
> +++ llvm/trunk/include/llvm/MC/MCContext.h Sun Mar 16 20:52:11 2014
> @@ -371,7 +371,9 @@ namespace llvm {
> bool getGenDwarfForAssembly() { return GenDwarfForAssembly; }
> void setGenDwarfForAssembly(bool Value) { GenDwarfForAssembly =
Value; }
> unsigned getGenDwarfFileNumber() { return GenDwarfFileNumber; }
> - unsigned nextGenDwarfFileNumber() { return ++GenDwarfFileNumber; }
> + void setGenDwarfFileNumber(unsigned FileNumber) {
> + GenDwarfFileNumber = FileNumber;
> + }
> const MCSection *getGenDwarfSection() { return GenDwarfSection; }
> void setGenDwarfSection(const MCSection *Sec) { GenDwarfSection =
Sec; }
> MCSymbol *getGenDwarfSectionStartSym() { return
GenDwarfSectionStartSym; }
>
> Modified: llvm/trunk/include/llvm/MC/MCDwarf.h
> URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=204027&r1=204026&r2=204027&view=diff
>
==============================================================================
> --- llvm/trunk/include/llvm/MC/MCDwarf.h (original)
> +++ llvm/trunk/include/llvm/MC/MCDwarf.h Sun Mar 16 20:52:11 2014
> @@ -16,6 +16,7 @@
> #define LLVM_MC_MCDWARF_H
>
> #include "llvm/ADT/StringRef.h"
> +#include "llvm/ADT/StringMap.h"
> #include "llvm/ADT/MapVector.h"
> #include "llvm/Support/Compiler.h"
> #include "llvm/Support/Dwarf.h"
> @@ -179,8 +180,9 @@ struct MCDwarfLineTableHeader {
> MCSymbol *Label;
> SmallVector<std::string, 3> MCDwarfDirs;
> SmallVector<MCDwarfFile, 3> MCDwarfFiles;
> + StringMap<unsigned> SourceIdMap;
> MCDwarfLineTableHeader() : Label(nullptr) {}
> - unsigned getFile(StringRef Directory, StringRef FileName, unsigned
FileNumber);
> + unsigned getFile(StringRef Directory, StringRef FileName, unsigned
FileNumber = 0);
> std::pair<MCSymbol *, MCSymbol *> Emit(MCStreamer *MCOS) const;
> };
>
> @@ -195,7 +197,7 @@ public:
> // This emits the Dwarf file and the line tables for a given Compile
Unit.
> const MCSymbol *EmitCU(MCStreamer *MCOS) const;
>
> - unsigned getFile(StringRef Directory, StringRef FileName, unsigned
FileNumber);
> + unsigned getFile(StringRef Directory, StringRef FileName, unsigned
FileNumber = 0);
>
> MCSymbol *getLabel() const {
> return Header.Label;
>
> Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
> URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=204027&r1=204026&r2=204027&view=diff
>
==============================================================================
> --- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
> +++ llvm/trunk/include/llvm/MC/MCStreamer.h Sun Mar 16 20:52:11 2014
> @@ -628,8 +628,9 @@ public:
> /// EmitDwarfFileDirective - Associate a filename with a specified
logical
> /// file number. This implements the DWARF2 '.file 4 "foo.c"'
assembler
> /// directive.
> - virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef
Directory,
> - StringRef Filename, unsigned CUID
= 0);
> + virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef
Directory,
> + StringRef Filename,
> + unsigned CUID = 0);
>
> /// EmitDwarfLocDirective - This implements the DWARF2
> // '.loc fileno lineno ...' assembler directive.
>
> Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
> URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=204027&r1=204026&r2=204027&view=diff
>
==============================================================================
> --- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Sun Mar 16 20:52:11 2014
> @@ -197,8 +197,9 @@ public:
> unsigned char Value = 0) override;
>
> void EmitFileDirective(StringRef Filename) override;
> - bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
> - StringRef Filename, unsigned CUID = 0)
override;
> + unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
> + StringRef Filename,
> + unsigned CUID = 0) override;
> void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
> unsigned Column, unsigned Flags,
> unsigned Isa, unsigned Discriminator,
> @@ -843,8 +844,10 @@ void MCAsmStreamer::EmitFileDirective(St
> EmitEOL();
> }
>
> -bool MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo, StringRef
Directory,
> - StringRef Filename, unsigned
CUID) {
> +unsigned MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo,
> + StringRef Directory,
> + StringRef Filename,
> + unsigned CUID) {
> if (!UseDwarfDirectory && !Directory.empty()) {
> if (sys::path::is_absolute(Filename))
> return EmitDwarfFileDirective(FileNo, "", Filename, CUID);
>
> Modified: llvm/trunk/lib/MC/MCDwarf.cpp
> URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=204027&r1=204026&r2=204027&view=diff
>
==============================================================================
> --- llvm/trunk/lib/MC/MCDwarf.cpp (original)
> +++ llvm/trunk/lib/MC/MCDwarf.cpp Sun Mar 16 20:52:11 2014
> @@ -336,7 +336,18 @@ unsigned MCDwarfLineTable::getFile(Strin
> return Header.getFile(Directory, FileName, FileNumber);
> }
>
> -unsigned MCDwarfLineTableHeader::getFile(StringRef Directory, StringRef
FileName, unsigned FileNumber) {
> +unsigned MCDwarfLineTableHeader::getFile(StringRef Directory,
> + StringRef FileName,
> + unsigned FileNumber) {
> + if (FileNumber == 0) {
> + FileNumber = SourceIdMap.size() + 1;
> + assert((MCDwarfFiles.empty() || FileNumber == MCDwarfFiles.size()) &&
> + "Don't mix autonumbered and explicit numbered line table
usage");
> + StringMapEntry<unsigned> &Ent = SourceIdMap.GetOrCreateValue(
> + (Directory + Twine('\0') + FileName).str(), FileNumber);
> + if (Ent.getValue() != FileNumber)
> + return Ent.getValue();
> + }
> // Make space for this FileNumber in the MCDwarfFiles vector if needed.
> MCDwarfFiles.resize(FileNumber + 1);
>
>
> Modified: llvm/trunk/lib/MC/MCNullStreamer.cpp
> URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCNullStreamer.cpp?rev=204027&r1=204026&r2=204027&view=diff
>
==============================================================================
> --- llvm/trunk/lib/MC/MCNullStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCNullStreamer.cpp Sun Mar 16 20:52:11 2014
> @@ -85,10 +85,10 @@ namespace {
> unsigned char Value = 0) override { return
false; }
>
> void EmitFileDirective(StringRef Filename) override {}
> - bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
> - StringRef Filename,
> - unsigned CUID = 0) override {
> - return false;
> + unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
> + StringRef Filename,
> + unsigned CUID = 0) override {
> + return 0;
> }
> void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
> unsigned Column, unsigned Flags,
>
> Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
> URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=204027&r1=204026&r2=204027&view=diff
>
==============================================================================
> --- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
> +++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Sun Mar 16 20:52:11 2014
> @@ -640,9 +640,8 @@ bool AsmParser::Run(bool NoInitialTextSe
> MCSymbol *SectionStartSym = getContext().CreateTempSymbol();
> getStreamer().EmitLabel(SectionStartSym);
> getContext().setGenDwarfSectionStartSym(SectionStartSym);
> -
getStreamer().EmitDwarfFileDirective(getContext().nextGenDwarfFileNumber(),
> - StringRef(),
> - getContext().getMainFileName());
> +
getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
> + 0, StringRef(), getContext().getMainFileName()));
> }
>
> // While we have input, parse each statement.
> @@ -1589,14 +1588,10 @@ bool AsmParser::parseStatement(ParseStat
> // If we previously parsed a cpp hash file line comment then make
sure the
> // current Dwarf File is for the CppHashFilename if not then emit the
> // Dwarf File table for it and adjust the line number for the .loc.
> - const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles =
> - getContext().getMCDwarfFiles();
> if (CppHashFilename.size() != 0) {
> - if (MCDwarfFiles[getContext().getGenDwarfFileNumber()].Name !=
> - CppHashFilename)
> - getStreamer().EmitDwarfFileDirective(
> - getContext().nextGenDwarfFileNumber(), StringRef(),
> - CppHashFilename);
> + unsigned FileNumber = getStreamer().EmitDwarfFileDirective(
> + 0, StringRef(), CppHashFilename);
> + getContext().setGenDwarfFileNumber(FileNumber);
>
> // Since SrcMgr.FindLineNumber() is slow and messes up the
SourceMgr's
> // cache with the different Loc from the call above we save the
last
> @@ -2762,7 +2757,8 @@ bool AsmParser::parseDirectiveFile(SMLoc
> "input can't have .file dwarf directives when -g is "
> "used to generate dwarf debug info for assembly code");
>
> - if (getStreamer().EmitDwarfFileDirective(FileNumber, Directory,
Filename))
> + if (getStreamer().EmitDwarfFileDirective(FileNumber, Directory,
Filename) ==
> + 0)
> Error(FileNumberLoc, "file number already allocated");
> }
>
>
> Modified: llvm/trunk/lib/MC/MCStreamer.cpp
> URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=204027&r1=204026&r2=204027&view=diff
>
==============================================================================
> --- llvm/trunk/lib/MC/MCStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCStreamer.cpp Sun Mar 16 20:52:11 2014
> @@ -174,10 +174,10 @@ void MCStreamer::EmitZeros(uint64_t NumB
> EmitFill(NumBytes, 0);
> }
>
> -bool MCStreamer::EmitDwarfFileDirective(unsigned FileNo,
> - StringRef Directory,
> - StringRef Filename, unsigned
CUID) {
> - return getContext().GetDwarfFile(Directory, Filename, FileNo, CUID) ==
0;
> +unsigned MCStreamer::EmitDwarfFileDirective(unsigned FileNo,
> + StringRef Directory,
> + StringRef Filename, unsigned
CUID) {
> + return getContext().GetDwarfFile(Directory, Filename, FileNo, CUID);
> }
>
> void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
>
> Modified: llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s
> URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s?rev=204027&r1=204026&r2=204027&view=diff
>
==============================================================================
> --- llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s (original)
> +++ llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s Sun Mar 16 20:52:11 2014
> @@ -4,6 +4,7 @@
> # 100 "t.s" 1
> .globl _bar
> _bar:
> + movl $0, %eax
> # 3 "inc/g.s"
> movl $0, %eax
> L1: leave
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140316/41a7da43/attachment.html>
More information about the llvm-commits
mailing list