[llvm] 3493540 - [DebugInfo][NFC] Erase capacity in DWARFUnit::clearDIEs().
Alexey Lapshin via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 10 00:07:41 PDT 2021
Author: Alexey Lapshin
Date: 2021-09-10T10:07:28+03:00
New Revision: 349354083059bd908bd982fc5e9f298ffdb20cd2
URL: https://github.com/llvm/llvm-project/commit/349354083059bd908bd982fc5e9f298ffdb20cd2
DIFF: https://github.com/llvm/llvm-project/commit/349354083059bd908bd982fc5e9f298ffdb20cd2.diff
LOG: [DebugInfo][NFC] Erase capacity in DWARFUnit::clearDIEs().
DWARFUnit::clearDIEs() uses std::vector::shrink_to_fit() to make
capacity of DieArray matched with its size(). The shrink_to_fit()
is not binding request to make capacity match with size().
Thus the memory could still be reserved after DWARFUnit::clearDIEs()
is called. This patch erases capacity when DWARFUnit::clearDIEs() is requested.
So the memory occupied by dies would be freed.
Differential Revision: https://reviews.llvm.org/D109499
Added:
Modified:
llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
Removed:
################################################################################
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
index f6bad56f6bfa..2faa9f9ddf75 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -577,10 +577,14 @@ bool DWARFUnit::parseDWO() {
}
void DWARFUnit::clearDIEs(bool KeepCUDie) {
- if (DieArray.size() > (unsigned)KeepCUDie) {
- DieArray.resize((unsigned)KeepCUDie);
- DieArray.shrink_to_fit();
- }
+ // Do not use resize() + shrink_to_fit() to free memory occupied by dies.
+ // shrink_to_fit() is a *non-binding* request to reduce capacity() to size().
+ // It depends on the implementation whether the request is fulfilled.
+ // Create a new vector with a small capacity and assign it to the DieArray to
+ // have previous contents freed.
+ DieArray = (KeepCUDie && !DieArray.empty())
+ ? std::vector<DWARFDebugInfoEntry>({DieArray[0]})
+ : std::vector<DWARFDebugInfoEntry>();
}
Expected<DWARFAddressRangesVector>
More information about the llvm-commits
mailing list