Skip to content

Commit

Permalink
Avoid dsymutil calls to getFileNameByIndex.
Browse files Browse the repository at this point in the history
This change adds a hasFileAtIndex method. getChildDeclContext can first call this method, and if it returns true it knows it can then lookup the resolved path cache for the given file index. If we hit that cache then we don't even have to call getFileNameByIndex.

Running dsymutil against the swift executable built from github gives a 20% performance improvement without any change in the binary.

Differential Revision: https://reviews.llvm.org/D22655

Reviewed by friss.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276380 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
cooperp committed Jul 22, 2016
1 parent cb5c574 commit 59023bf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ class DWARFDebugLine {
bool lookupAddressRange(uint64_t address, uint64_t size,
std::vector<uint32_t> &result) const;

bool hasFileAtIndex(uint64_t FileIndex) const;

// Extracts filename by its index in filename table in prologue.
// Returns true on success.
bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir,
Expand Down
17 changes: 11 additions & 6 deletions lib/DebugInfo/DWARF/DWARFDebugLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,17 @@ bool DWARFDebugLine::LineTable::lookupAddressRange(
return true;
}

bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
const char *CompDir,
FileLineInfoKind Kind,
std::string &Result) const {
if (FileIndex == 0 || FileIndex > Prologue.FileNames.size() ||
Kind == FileLineInfoKind::None)
bool
DWARFDebugLine::LineTable::hasFileAtIndex(uint64_t FileIndex) const {
return FileIndex != 0 && FileIndex <= Prologue.FileNames.size();
}

bool
DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
const char *CompDir,
FileLineInfoKind Kind,
std::string &Result) const {
if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
return false;
const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];
const char *FileName = Entry.Name;
Expand Down
13 changes: 8 additions & 5 deletions tools/dsymutil/DwarfLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1633,11 +1633,7 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(
// FIXME: Passing U.getOrigUnit().getCompilationDir()
// instead of "" would allow more uniquing, but for now, do
// it this way to match dsymutil-classic.
std::string File;
if (LT->getFileNameByIndex(
FileNum, "",
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
File)) {
if (LT->hasFileAtIndex(FileNum)) {
Line = DIE->getAttributeValueAsUnsignedConstant(
&U.getOrigUnit(), dwarf::DW_AT_decl_line, 0);
// Cache the resolved paths, because calling realpath is expansive.
Expand All @@ -1646,6 +1642,13 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(
FileRef = ResolvedPath;
} else {
#ifdef HAVE_REALPATH
std::string File;
bool gotFileName =
LT->getFileNameByIndex(FileNum, "",
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
File);
(void)gotFileName;
assert(gotFileName && "Must get file name from line table");
char RealPath[PATH_MAX + 1];
RealPath[PATH_MAX] = 0;
if (::realpath(File.c_str(), RealPath))
Expand Down

0 comments on commit 59023bf

Please sign in to comment.