[llvm] [DWARF] Speedup .gdb_index dumping (PR #151806)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 2 01:26:28 PDT 2025
https://github.com/itrofimow created https://github.com/llvm/llvm-project/pull/151806
This patch drastically speed ups dumping .gdb_index for large indexes
>From 0d22a6fa2dca2f452b350de9d5a5425911db98e2 Mon Sep 17 00:00:00 2001
From: Ivan Trofimov <i.trofimow at yandex.ru>
Date: Sat, 2 Aug 2025 11:24:21 +0300
Subject: [PATCH] [DWARF] Speedup .gdb_index dumping
---
llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp | 25 +++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp b/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp
index 987e63963a068..c0ad2a38df373 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp
@@ -17,6 +17,7 @@
#include <cinttypes>
#include <cstdint>
#include <set>
+#include <unordered_map>
#include <utility>
using namespace llvm;
@@ -60,6 +61,24 @@ void DWARFGdbIndex::dumpSymbolTable(raw_ostream &OS) const {
", filled slots:",
SymbolTableOffset, (uint64_t)SymbolTable.size())
<< '\n';
+
+ std::unordered_map<uint32_t, decltype(ConstantPoolVectors)::const_iterator>
+ CuVectorMap{};
+ CuVectorMap.reserve(ConstantPoolVectors.size());
+ const auto FindCuVector =
+ [&CuVectorMap, notFound = ConstantPoolVectors.end()](uint32_t vecOffset) {
+ const auto it = CuVectorMap.find(vecOffset);
+ if (it != CuVectorMap.end()) {
+ return it->second;
+ }
+
+ return notFound;
+ };
+ for (auto it = ConstantPoolVectors.begin(); it != ConstantPoolVectors.end();
+ ++it) {
+ CuVectorMap.emplace(it->first, it);
+ }
+
uint32_t I = -1;
for (const SymTableEntry &E : SymbolTable) {
++I;
@@ -72,11 +91,7 @@ void DWARFGdbIndex::dumpSymbolTable(raw_ostream &OS) const {
StringRef Name = ConstantPoolStrings.substr(
ConstantPoolOffset - StringPoolOffset + E.NameOffset);
- auto CuVector = llvm::find_if(
- ConstantPoolVectors,
- [&](const std::pair<uint32_t, SmallVector<uint32_t, 0>> &V) {
- return V.first == E.VecOffset;
- });
+ auto CuVector = FindCuVector(E.VecOffset);
assert(CuVector != ConstantPoolVectors.end() && "Invalid symbol table");
uint32_t CuVectorId = CuVector - ConstantPoolVectors.begin();
OS << format(" String name: %s, CU vector index: %d\n", Name.data(),
More information about the llvm-commits
mailing list