[Lldb-commits] [lldb] [lldb/DWARF] Cache negative results of variable parsing (PR #108810)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 16 02:51:50 PDT 2024
https://github.com/labath created https://github.com/llvm/llvm-project/pull/108810
Use a `nullptr` map entry to mean "variable parse was attempted and it failed" an the absence of an entry to mean "parsing hasn't been attempted yet".
I ran into this because parsing of function-static variables was generating a lot of errors (see #108806), but this seems like a good idea in general.
In theory this should be NFC, except for possibly reducing some amount of work.
>From fddb89e718e3bc96ce5e051ce9a8e63f37ce5a25 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Mon, 16 Sep 2024 11:46:05 +0200
Subject: [PATCH] [lldb/DWARF] Cache negative results of variable parsing
Use a `nullptr` map entry to mean "variable parse was attempted and it
failed" an the absence of an entry to mean "parsing hasn't been
attempted yet".
I ran into this because parsing of function-static variables was
generating a lot of errors (see #108806), but this seems like a good
idea in general.
In theory this should be NFC, except for possibly reducing some amount
of work.
---
.../SymbolFile/DWARF/SymbolFileDWARF.cpp | 26 +++++++++----------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index f721ca00fd3559..bacea848988467 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3377,16 +3377,13 @@ VariableSP SymbolFileDWARF::ParseVariableDIECached(const SymbolContext &sc,
DIEToVariableSP &die_to_variable = die.GetDWARF()->GetDIEToVariable();
- VariableSP var_sp = die_to_variable[die.GetDIE()];
- if (var_sp)
- return var_sp;
-
- var_sp = ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS);
- if (var_sp) {
- die_to_variable[die.GetDIE()] = var_sp;
- if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification))
- die_to_variable[spec_die.GetDIE()] = var_sp;
- }
+ if (auto it = die_to_variable.find(die.GetDIE()); it != die_to_variable.end())
+ return it->second;
+
+ VariableSP var_sp = ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS);
+ die_to_variable.insert_or_assign(die.GetDIE(), var_sp);
+ if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification))
+ die_to_variable.insert_or_assign(spec_die.GetDIE(), var_sp);
return var_sp;
}
@@ -3799,9 +3796,10 @@ void SymbolFileDWARF::ParseAndAppendGlobalVariable(
return;
// Check to see if we have already parsed this variable or constant?
- VariableSP var_sp = GetDIEToVariable()[die.GetDIE()];
- if (var_sp) {
- cc_variable_list.AddVariableIfUnique(var_sp);
+ DIEToVariableSP &die_to_variable = GetDIEToVariable();
+ if (auto it = die_to_variable.find(die.GetDIE());
+ it != die_to_variable.end()) {
+ cc_variable_list.AddVariableIfUnique(it->second);
return;
}
@@ -3835,7 +3833,7 @@ void SymbolFileDWARF::ParseAndAppendGlobalVariable(
return;
}
- var_sp = ParseVariableDIECached(sc, die);
+ VariableSP var_sp = ParseVariableDIECached(sc, die);
if (!var_sp)
return;
More information about the lldb-commits
mailing list