[Lldb-commits] [lldb] r363528 - DWARF: Avoid storing DIERefs in long-lived containers

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 17 00:32:57 PDT 2019


Author: labath
Date: Mon Jun 17 00:32:56 2019
New Revision: 363528

URL: http://llvm.org/viewvc/llvm-project?rev=363528&view=rev
Log:
DWARF: Avoid storing DIERefs in long-lived containers

Summary:
A user_id_t carries the same information as a DIERef, but it takes up
less space.

Furthermore, DIERef::operator<'s implementation is very
questionable, as it does not take the cu_offset and section fields into
account. Using just the die offset was correct in the days when all
debug info lived in a single section, but since we started supporting
DWO debug info, this was no longer true. The comparison operator could
be fixed, but it seems like using the user_id_t for these purposes is a
better idea overall.

I think this did not cause any bugs, because the only place the
comparison operator was used is in m_function_scope_qualified_name_map,
and this one is local to a dwo file, but I am not 100% sure of that.

Reviewers: clayborg, JDevlieghere

Subscribers: aprantl, lldb-commits

Differential Revision: https://reviews.llvm.org/D63322

Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h?rev=363528&r1=363527&r2=363528&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h Mon Jun 17 00:32:56 2019
@@ -25,10 +25,6 @@ struct DIERef {
 
   explicit DIERef(const DWARFFormValue &form_value);
 
-  bool operator<(const DIERef &ref) const {
-    return die_offset < ref.die_offset;
-  }
-
   explicit operator bool() const {
     return cu_offset != DW_INVALID_OFFSET || die_offset != DW_INVALID_OFFSET;
   }

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp?rev=363528&r1=363527&r2=363528&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Mon Jun 17 00:32:56 2019
@@ -998,7 +998,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
             clang_type.GetOpaqueQualType();
         dwarf->GetForwardDeclClangTypeToDie()
             [ClangUtil::RemoveFastQualifiers(clang_type).GetOpaqueQualType()] =
-            die.GetDIERef();
+            die.GetID();
         m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true);
       }
     }

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=363528&r1=363527&r2=363528&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Mon Jun 17 00:32:56 2019
@@ -2327,15 +2327,9 @@ void SymbolFileDWARF::GetMangledNamesFor
       dwo->GetMangledNamesForFunction(scope_qualified_name, mangled_names);
   }
 
-  NameToOffsetMap::iterator iter =
-      m_function_scope_qualified_name_map.find(scope_qualified_name);
-  if (iter == m_function_scope_qualified_name_map.end())
-    return;
-
-  DIERefSetSP set_sp = (*iter).second;
-  std::set<DIERef>::iterator set_iter;
-  for (set_iter = set_sp->begin(); set_iter != set_sp->end(); set_iter++) {
-    DWARFDIE die = DebugInfo()->GetDIE(*set_iter);
+  for (lldb::user_id_t uid :
+       m_function_scope_qualified_name_map.lookup(scope_qualified_name)) {
+    DWARFDIE die = GetDIE(uid);
     mangled_names.push_back(ConstString(die.GetMangledName()));
   }
 }
@@ -2952,42 +2946,32 @@ TypeSP SymbolFileDWARF::FindDefinitionTy
 
 TypeSP SymbolFileDWARF::ParseType(const SymbolContext &sc, const DWARFDIE &die,
                                   bool *type_is_new_ptr) {
-  TypeSP type_sp;
-
-  if (die) {
-    TypeSystem *type_system =
-        GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
+  if (!die)
+    return {};
 
-    if (type_system) {
-      DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-      if (dwarf_ast) {
-        Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
-        type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, log, type_is_new_ptr);
-        if (type_sp) {
-          TypeList *type_list = GetTypeList();
-          if (type_list)
-            type_list->Insert(type_sp);
-
-          if (die.Tag() == DW_TAG_subprogram) {
-            DIERef die_ref = die.GetDIERef();
-            std::string scope_qualified_name(GetDeclContextForUID(die.GetID())
-                                                 .GetScopeQualifiedName()
-                                                 .AsCString(""));
-            if (scope_qualified_name.size()) {
-              NameToOffsetMap::iterator iter =
-                  m_function_scope_qualified_name_map.find(
-                      scope_qualified_name);
-              if (iter != m_function_scope_qualified_name_map.end())
-                (*iter).second->insert(die_ref);
-              else {
-                DIERefSetSP new_set(new std::set<DIERef>);
-                new_set->insert(die_ref);
-                m_function_scope_qualified_name_map.emplace(
-                    std::make_pair(scope_qualified_name, new_set));
-              }
-            }
-          }
-        }
+  TypeSystem *type_system =
+      GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
+  if (!type_system)
+    return {};
+
+  DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
+  if (!dwarf_ast)
+    return {};
+
+  Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
+  TypeSP type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, log, type_is_new_ptr);
+  if (type_sp) {
+    TypeList *type_list = GetTypeList();
+    if (type_list)
+      type_list->Insert(type_sp);
+
+    if (die.Tag() == DW_TAG_subprogram) {
+      std::string scope_qualified_name(GetDeclContextForUID(die.GetID())
+                                           .GetScopeQualifiedName()
+                                           .AsCString(""));
+      if (scope_qualified_name.size()) {
+        m_function_scope_qualified_name_map[scope_qualified_name].insert(
+            die.GetID());
       }
     }
   }

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=363528&r1=363527&r2=363528&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Mon Jun 17 00:32:56 2019
@@ -309,7 +309,8 @@ protected:
   typedef llvm::DenseMap<const DWARFDebugInfoEntry *,
                          lldb::opaque_compiler_type_t>
       DIEToClangType;
-  typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> ClangTypeToDIE;
+  typedef llvm::DenseMap<lldb::opaque_compiler_type_t, lldb::user_id_t>
+      ClangTypeToDIE;
 
   struct DWARFDataSegment {
     llvm::once_flag m_flag;
@@ -471,8 +472,8 @@ protected:
   bool m_fetched_external_modules : 1;
   lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
 
-  typedef std::shared_ptr<std::set<DIERef>> DIERefSetSP;
-  typedef std::unordered_map<std::string, DIERefSetSP> NameToOffsetMap;
+  typedef std::set<lldb::user_id_t> DIERefSet;
+  typedef llvm::StringMap<DIERefSet> NameToOffsetMap;
   NameToOffsetMap m_function_scope_qualified_name_map;
   std::unique_ptr<DWARFDebugRangesBase> m_ranges;
   std::unique_ptr<DWARFDebugRangesBase> m_rnglists;




More information about the lldb-commits mailing list