[llvm] r276380 - Avoid dsymutil calls to getFileNameByIndex.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 21 18:41:32 PDT 2016


Author: pete
Date: Thu Jul 21 20:41:32 2016
New Revision: 276380

URL: http://llvm.org/viewvc/llvm-project?rev=276380&view=rev
Log:
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.

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

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h?rev=276380&r1=276379&r2=276380&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h Thu Jul 21 20:41:32 2016
@@ -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,

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp?rev=276380&r1=276379&r2=276380&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp Thu Jul 21 20:41:32 2016
@@ -624,12 +624,17 @@ bool DWARFDebugLine::LineTable::lookupAd
   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;

Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=276380&r1=276379&r2=276380&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Thu Jul 21 20:41:32 2016
@@ -1633,11 +1633,7 @@ PointerIntPair<DeclContext *, 1> DeclCon
           // 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> DeclCon
               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))




More information about the llvm-commits mailing list