Avoid dsymutil calls to getFileNameByIndex.

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.

llvm-svn: 276380
This commit is contained in:
Pete Cooper 2016-07-22 01:41:32 +00:00
parent 8258686922
commit b2ba776aed
3 changed files with 21 additions and 11 deletions

View File

@ -188,6 +188,8 @@ public:
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,

View File

@ -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;

View File

@ -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.
@ -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))