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
diff --git a/llvm/tools/dsymutil/DwarfLinker.cpp b/llvm/tools/dsymutil/DwarfLinker.cpp
index bea30de..0421040 100644
--- a/llvm/tools/dsymutil/DwarfLinker.cpp
+++ b/llvm/tools/dsymutil/DwarfLinker.cpp
@@ -1633,11 +1633,7 @@
// 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 @@
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))