guiandrade updated this revision to Diff 218564.
guiandrade marked 6 inline comments as done.
guiandrade retitled this revision from "Skip getting declarations for repeated 
DIEs (WIP)" to "Cache expanded CompilerDeclContext's to avoid parsing them 
multiple times".
guiandrade edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67022/new/

https://reviews.llvm.org/D67022

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
===================================================================
--- lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
@@ -39,9 +39,12 @@
   ast_parser.LinkDeclContextToDIE((clang::DeclContext *)2LL, die3);
   ast_parser.LinkDeclContextToDIE((clang::DeclContext *)3LL, die4);
 
-  auto die_list = ast_parser.GetDIEForDeclContext(
-      CompilerDeclContext(nullptr, (clang::DeclContext *)2LL));
+  std::vector<DWARFDIE> die_list;
+  ast_parser.ForEachDIEInDeclContext(
+      CompilerDeclContext(nullptr, (clang::DeclContext *)2LL),
+      [&die_list](DWARFDIE die) { die_list.push_back(die); });
+
   ASSERT_EQ(2u, die_list.size());
-  ASSERT_EQ(die2, die_list[0]);
-  ASSERT_EQ(die3, die_list[1]);
+  ASSERT_NE(die_list.end(), std::find(die_list.begin(), die_list.end(), die2));
+  ASSERT_NE(die_list.end(), std::find(die_list.begin(), die_list.end(), die3));
 }
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -489,6 +489,8 @@
   llvm::DenseMap<dw_offset_t, lldb_private::FileSpecList>
       m_type_unit_support_files;
   std::vector<uint32_t> m_lldb_cu_to_dwarf_unit;
+
+  std::set<lldb_private::CompilerDeclContext> m_parsed_decls_for_decl_ctx;
 };
 
 #endif // SymbolFileDWARF_SymbolFileDWARF_h_
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1206,14 +1206,14 @@
   auto *type_system = decl_ctx.GetTypeSystem();
   if (!type_system)
     return;
-  DWARFASTParser *ast_parser = type_system->GetDWARFParser();
-  std::vector<DWARFDIE> decl_ctx_die_list =
-      ast_parser->GetDIEForDeclContext(decl_ctx);
+  if (!m_parsed_decls_for_decl_ctx.insert(decl_ctx).second)
+    return;
 
-  for (DWARFDIE decl_ctx_die : decl_ctx_die_list)
-    for (DWARFDIE decl = decl_ctx_die.GetFirstChild(); decl;
-         decl = decl.GetSibling())
+  DWARFASTParser *ast_parser = type_system->GetDWARFParser();
+  ast_parser->ForEachDIEInDeclContext(decl_ctx, [ast_parser](DWARFDIE die) {
+    for (DWARFDIE decl = die.GetFirstChild(); decl; decl = decl.GetSibling())
       ast_parser->GetDeclForUIDFromDWARF(decl);
+  });
 }
 
 user_id_t SymbolFileDWARF::GetUID(DIERef ref) {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -51,8 +51,9 @@
   lldb_private::CompilerDecl
   GetDeclForUIDFromDWARF(const DWARFDIE &die) override;
 
-  std::vector<DWARFDIE>
-  GetDIEForDeclContext(lldb_private::CompilerDeclContext decl_context) override;
+  void ForEachDIEInDeclContext(
+      lldb_private::CompilerDeclContext decl_context,
+      std::function<void(DWARFDIE die)> const &callback) override;
 
   lldb_private::CompilerDeclContext
   GetDeclContextForUIDFromDWARF(const DWARFDIE &die) override;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2183,15 +2183,14 @@
   return false;
 }
 
-std::vector<DWARFDIE> DWARFASTParserClang::GetDIEForDeclContext(
-    lldb_private::CompilerDeclContext decl_context) {
-  std::vector<DWARFDIE> result;
+void DWARFASTParserClang::ForEachDIEInDeclContext(
+    lldb_private::CompilerDeclContext decl_context,
+    std::function<void(DWARFDIE die)> const &callback) {
   auto opaque_decl_ctx =
       (clang::DeclContext *)decl_context.GetOpaqueDeclContext();
   for (auto it = m_decl_ctx_to_die.find(opaque_decl_ctx);
        it != m_decl_ctx_to_die.end() && it->first == opaque_decl_ctx; it++)
-    result.push_back(it->second);
-  return result;
+    callback(it->second);
 }
 
 CompilerDecl DWARFASTParserClang::GetDeclForUIDFromDWARF(const DWARFDIE &die) {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -48,8 +48,9 @@
   virtual lldb_private::CompilerDeclContext
   GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) = 0;
 
-  virtual std::vector<DWARFDIE>
-  GetDIEForDeclContext(lldb_private::CompilerDeclContext decl_context) = 0;
+  virtual void ForEachDIEInDeclContext(
+      lldb_private::CompilerDeclContext decl_context,
+      std::function<void(DWARFDIE die)> const &callback) = 0;
 
   static llvm::Optional<lldb_private::SymbolFile::ArrayInfo>
   ParseChildArrayInfo(const DWARFDIE &parent_die,
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to