[PATCH] D22655: Avoid dsymutil calls to getFileNameByIndex

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 21 15:45:19 PDT 2016


pete created this revision.
pete added a reviewer: friss.
pete added a subscriber: llvm-commits.
pete set the repository for this revision to rL LLVM.

Hi Fred

getFileNameByIndex calls sys::path::append and (transitively) malloc a large number of times.

The call site in getChildDeclContext already caches resolved paths for a given FileNum if we have the file name by its index.

This patch adds a hasFileNameByIndex 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  on the swift executable generated from the GitHub sources, before this change took 100s on my iMac.  Afterwards took 80s.  So a nice 20% speedup.  I ran a few times on each configuration to make sure the numbers are quite stable.  I also diffed the dSYM produced before and after this patch and they are binary identical.

Thanks,
Pete

Repository:
  rL LLVM

https://reviews.llvm.org/D22655

Files:
  include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
  lib/DebugInfo/DWARF/DWARFDebugLine.cpp
  tools/dsymutil/DwarfLinker.cpp

Index: tools/dsymutil/DwarfLinker.cpp
===================================================================
--- tools/dsymutil/DwarfLinker.cpp
+++ tools/dsymutil/DwarfLinker.cpp
@@ -1633,19 +1633,23 @@
           // 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->hasFileNameByIndex(FileNum,
+                    DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath)) {
             Line = DIE->getAttributeValueAsUnsignedConstant(
                 &U.getOrigUnit(), dwarf::DW_AT_decl_line, 0);
             // Cache the resolved paths, because calling realpath is expansive.
             StringRef ResolvedPath = U.getResolvedPath(FileNum);
             if (!ResolvedPath.empty()) {
               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))
Index: lib/DebugInfo/DWARF/DWARFDebugLine.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -624,13 +624,22 @@
   return true;
 }
 
-bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
-                                                   const char *CompDir,
-                                                   FileLineInfoKind Kind,
-                                                   std::string &Result) const {
+bool
+DWARFDebugLine::LineTable::hasFileNameByIndex(uint64_t FileIndex,
+                                              FileLineInfoKind Kind) const {
   if (FileIndex == 0 || FileIndex > Prologue.FileNames.size() ||
       Kind == FileLineInfoKind::None)
     return false;
+  return true;
+}
+
+bool
+DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
+                                              const char *CompDir,
+                                              FileLineInfoKind Kind,
+                                              std::string &Result) const {
+  if (!hasFileNameByIndex(FileIndex, Kind))
+    return false;
   const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];
   const char *FileName = Entry.Name;
   if (Kind != FileLineInfoKind::AbsoluteFilePath ||
Index: include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
===================================================================
--- include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
+++ include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
@@ -188,6 +188,9 @@
     bool lookupAddressRange(uint64_t address, uint64_t size,
                             std::vector<uint32_t> &result) const;
 
+    bool hasFileNameByIndex(uint64_t FileIndex,
+                            DILineInfoSpecifier::FileLineInfoKind Kind) const;
+
     // Extracts filename by its index in filename table in prologue.
     // Returns true on success.
     bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22655.64980.patch
Type: text/x-patch
Size: 3625 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160721/ce1742bb/attachment-0001.bin>


More information about the llvm-commits mailing list