[Lldb-commits] [lldb] r113032 - in /lldb/trunk: include/lldb/Core/ConstString.h lldb.xcodeproj/project.pbxproj source/Core/ConstString.cpp source/Core/Mangled.cpp source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp

Greg Clayton gclayton at apple.com
Fri Sep 3 16:26:12 PDT 2010


Author: gclayton
Date: Fri Sep  3 18:26:12 2010
New Revision: 113032

URL: http://llvm.org/viewvc/llvm-project?rev=113032&view=rev
Log:
Improved name demangling performance by 20% on darwin.


Modified:
    lldb/trunk/include/lldb/Core/ConstString.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Core/ConstString.cpp
    lldb/trunk/source/Core/Mangled.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp

Modified: lldb/trunk/include/lldb/Core/ConstString.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ConstString.h?rev=113032&r1=113031&r2=113032&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ConstString.h (original)
+++ lldb/trunk/include/lldb/Core/ConstString.h Fri Sep  3 18:26:12 2010
@@ -290,7 +290,11 @@
     ///     @li \b false if the contained string is not empty.
     //------------------------------------------------------------------
     bool
-    IsEmpty () const;
+    IsEmpty () const
+    {
+        return m_string == NULL || m_string[0] == '\0';
+    }
+
 
     //------------------------------------------------------------------
     /// Set the C string value.

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=113032&r1=113031&r2=113032&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Fri Sep  3 18:26:12 2010
@@ -2295,6 +2295,7 @@
 			isa = PBXProject;
 			buildConfigurationList = 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "lldb" */;
 			compatibilityVersion = "Xcode 3.1";
+			developmentRegion = English;
 			hasScannedForEncodings = 1;
 			knownRegions = (
 				en,

Modified: lldb/trunk/source/Core/ConstString.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ConstString.cpp?rev=113032&r1=113031&r2=113032&view=diff
==============================================================================
--- lldb/trunk/source/Core/ConstString.cpp (original)
+++ lldb/trunk/source/Core/ConstString.cpp Fri Sep  3 18:26:12 2010
@@ -391,15 +391,6 @@
 }
 
 //----------------------------------------------------------------------
-// Returns true if the contained string is empty.
-//----------------------------------------------------------------------
-bool
-ConstString::IsEmpty() const
-{
-    return m_string == NULL || m_string[0] == '\0';
-}
-
-//----------------------------------------------------------------------
 // Set the string value in the object by uniquing the "cstr" string
 // value in our global string pool.
 //

Modified: lldb/trunk/source/Core/Mangled.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Mangled.cpp?rev=113032&r1=113031&r2=113032&view=diff
==============================================================================
--- lldb/trunk/source/Core/Mangled.cpp (original)
+++ lldb/trunk/source/Core/Mangled.cpp Fri Sep  3 18:26:12 2010
@@ -9,6 +9,8 @@
 
 #include <cxxabi.h>
 
+#include "llvm/ADT/DenseMap.h"
+
 #include "lldb/Core/ConstString.h"
 #include "lldb/Core/Mangled.h"
 #include "lldb/Core/Stream.h"
@@ -142,18 +144,47 @@
         const char * mangled = m_mangled.AsCString();
         if (mangled[0])
         {
-            char *demangled_name = abi::__cxa_demangle (mangled, NULL, NULL, NULL);
-
-            if (demangled_name)
+            // Since demangling can be a costly, and since all names that go 
+            // into a ConstString (like our m_mangled and m_demangled members)
+            // end up being unique "const char *" values, we can use a DenseMap
+            // to speed up our lookup. We do this because often our symbol table
+            // and our debug information both have the mangled names which they
+            // would each need to demangle. Also, with GCC we end up with the one
+            // definition rule where a lot of STL code produces symbols that are
+            // in multiple compile units and the mangled names end up being in
+            // the same binary multiple times. The performance win isn't huge, 
+            // but we showed a 20% improvement on darwin.
+            typedef llvm::DenseMap<const char *, const char *> MangledToDemangledMap;
+            static MangledToDemangledMap g_mangled_to_demangled;
+
+            // Check our mangled string pointer to demangled string pointer map first
+            MangledToDemangledMap::const_iterator pos = g_mangled_to_demangled.find (mangled);
+            if (pos != g_mangled_to_demangled.end())
             {
-                m_demangled.SetCString (demangled_name);
-                free (demangled_name);
+                // We have already demangled this string, we can just use our saved result!
+                m_demangled.SetCString(pos->second);
             }
             else
             {
-                // Set the demangled string to the empty string to indicate we
-                // tried to parse it once and failed.
-                m_demangled.SetCString("");
+                // We didn't already mangle this name, demangle it and if all goes well
+                // add it to our map.
+                char *demangled_name = abi::__cxa_demangle (mangled, NULL, NULL, NULL);
+
+                if (demangled_name)
+                {
+                    m_demangled.SetCString (demangled_name);
+                    // Now that the name has been uniqued, add the uniqued C string
+                    // pointer from m_mangled as the key to the uniqued C string
+                    // pointer in m_demangled.
+                    g_mangled_to_demangled.insert (std::make_pair (mangled, m_demangled.GetCString()));
+                    free (demangled_name);
+                }
+                else
+                {
+                    // Set the demangled string to the empty string to indicate we
+                    // tried to parse it once and failed.
+                    m_demangled.SetCString("");
+                }
             }
         }
     }

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp?rev=113032&r1=113031&r2=113032&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Fri Sep  3 18:26:12 2010
@@ -9,6 +9,7 @@
 
 #include "DWARFCompileUnit.h"
 
+#include "lldb/Core/Mangled.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Core/Timer.h"
 
@@ -591,7 +592,7 @@
 
         DWARFDebugInfoEntry::Attributes attributes;
         const char *name = NULL;
-        const char *mangled = NULL;
+        Mangled mangled;
         bool is_variable = false;
         bool is_declaration = false;
         bool is_artificial = false;
@@ -629,7 +630,7 @@
 
                 case DW_AT_MIPS_linkage_name:
                     if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value))
-                        mangled = form_value.AsCString(debug_str);
+                        mangled.GetMangledName().SetCString(form_value.AsCString(debug_str));
                     break;
 
                 case DW_AT_low_pc:
@@ -761,8 +762,10 @@
                     else
                         base_name_to_function_die.Append(ConstString(name).AsCString(), die.GetOffset());
                 }
-                if (mangled)
-                    full_name_to_function_die.Append(ConstString(mangled).AsCString(), die.GetOffset());
+                if (mangled.GetMangledName())
+                    full_name_to_function_die.Append(mangled.GetMangledName().AsCString(), die.GetOffset());
+                if (mangled.GetDemangledName())
+                    full_name_to_function_die.Append(mangled.GetDemangledName().AsCString(), die.GetOffset());
             }
             break;
 
@@ -771,8 +774,10 @@
             {
                 if (name)
                     base_name_to_function_die.Append(ConstString(name).AsCString(), die.GetOffset());
-                if (mangled)
-                    full_name_to_function_die.Append(ConstString(mangled).AsCString(), die.GetOffset());
+                if (mangled.GetMangledName())
+                    full_name_to_function_die.Append(mangled.GetMangledName().AsCString(), die.GetOffset());
+                if (mangled.GetDemangledName())
+                    full_name_to_function_die.Append(mangled.GetDemangledName().AsCString(), die.GetOffset());
             }
             break;
         





More information about the lldb-commits mailing list