From 0d22a6fa2dca2f452b350de9d5a5425911db98e2 Mon Sep 17 00:00:00 2001 From: Ivan Trofimov Date: Sat, 2 Aug 2025 11:24:21 +0300 Subject: [PATCH 1/5] [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 #include #include +#include #include 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 + 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> &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(), From 4d30a5c5785f0c4c0e26e1e532079cfdb244f598 Mon Sep 17 00:00:00 2001 From: Ivan Trofimov Date: Wed, 6 Aug 2025 14:38:00 +0300 Subject: [PATCH 2/5] cr fixes --- llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp | 27 ++++++++-------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp b/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp index c0ad2a38df373..c076c4547be7f 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/DWARF/DWARFGdbIndex.h" +#include #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/DataExtractor.h" @@ -17,7 +18,6 @@ #include #include #include -#include #include using namespace llvm; @@ -62,22 +62,15 @@ void DWARFGdbIndex::dumpSymbolTable(raw_ostream &OS) const { SymbolTableOffset, (uint64_t)SymbolTable.size()) << '\n'; - std::unordered_map - 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; + llvm::DenseMap + CuVectorMap(ConstantPoolVectors.size()); + for (const auto& [Offset, CUVector] : ConstantPoolVectors) + CuVectorMap.try_emplace(Offset, &CUVector); + + const auto FindCuVector =[&](uint32_t VecOffset) { + const auto It = CuVectorMap.find(VecOffset); + return It != CuVectorMap.end() ? It->second : ConstantPoolVectors.end(); }; - for (auto it = ConstantPoolVectors.begin(); it != ConstantPoolVectors.end(); - ++it) { - CuVectorMap.emplace(it->first, it); - } uint32_t I = -1; for (const SymTableEntry &E : SymbolTable) { @@ -91,7 +84,7 @@ void DWARFGdbIndex::dumpSymbolTable(raw_ostream &OS) const { StringRef Name = ConstantPoolStrings.substr( ConstantPoolOffset - StringPoolOffset + E.NameOffset); - auto CuVector = FindCuVector(E.VecOffset); + const 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(), From 72ff5d8714b3e03da05773e921b7eaa717e5d7a5 Mon Sep 17 00:00:00 2001 From: Ivan Trofimov Date: Wed, 6 Aug 2025 14:59:39 +0300 Subject: [PATCH 3/5] cleanup --- llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp b/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp index c076c4547be7f..da771c7f93415 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp @@ -62,15 +62,15 @@ void DWARFGdbIndex::dumpSymbolTable(raw_ostream &OS) const { SymbolTableOffset, (uint64_t)SymbolTable.size()) << '\n'; - llvm::DenseMap - CuVectorMap(ConstantPoolVectors.size()); - for (const auto& [Offset, CUVector] : ConstantPoolVectors) - CuVectorMap.try_emplace(Offset, &CUVector); + llvm::DenseMap OffsetToIdMap(ConstantPoolVectors.size()); + for (uint32_t Id = 0; Id < ConstantPoolVectors.size(); ++Id) + OffsetToIdMap[ConstantPoolVectors[Id].first] = Id; - const auto FindCuVector =[&](uint32_t VecOffset) { - const auto It = CuVectorMap.find(VecOffset); - return It != CuVectorMap.end() ? It->second : ConstantPoolVectors.end(); - }; + const auto FindCuVectorId = [&](uint32_t VecOffset) { + const auto It = OffsetToIdMap.find(VecOffset); + assert(It != OffsetToIdMap.end() && "Invalid symbol table"); + return It->second; + }; uint32_t I = -1; for (const SymTableEntry &E : SymbolTable) { @@ -84,9 +84,7 @@ void DWARFGdbIndex::dumpSymbolTable(raw_ostream &OS) const { StringRef Name = ConstantPoolStrings.substr( ConstantPoolOffset - StringPoolOffset + E.NameOffset); - const auto* CuVector = FindCuVector(E.VecOffset); - assert(CuVector != ConstantPoolVectors.end() && "Invalid symbol table"); - uint32_t CuVectorId = CuVector - ConstantPoolVectors.begin(); + const uint32_t CuVectorId = FindCuVectorId(E.VecOffset); OS << format(" String name: %s, CU vector index: %d\n", Name.data(), CuVectorId); } From 9601b2f790b282aa8a7ad9060fd2cc7e90f1680a Mon Sep 17 00:00:00 2001 From: Ivan Trofimov Date: Wed, 6 Aug 2025 15:12:20 +0300 Subject: [PATCH 4/5] clang-format fixes --- llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp b/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp index da771c7f93415..3b51ea08a1d5a 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp @@ -14,6 +14,7 @@ #include "llvm/Support/Format.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/raw_ostream.h" + #include #include #include From b51c2235c1dfcaca709fd0b2540c5e8eb71d23d1 Mon Sep 17 00:00:00 2001 From: Ivan Trofimov Date: Wed, 6 Aug 2025 15:18:43 +0300 Subject: [PATCH 5/5] clang-format fixes --- llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp b/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp index 3b51ea08a1d5a..750db94a2f848 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp @@ -7,14 +7,13 @@ //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/DWARF/DWARFGdbIndex.h" -#include +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/DataExtractor.h" #include "llvm/Support/Format.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/raw_ostream.h" - #include #include #include