Skip to content

Commit 421d4b6

Browse files
committed
[llvm-dwarf] Make --verify for .debug_names multithreaded.
This PR makes verification of .debug_names acceleration table multithreaded. In local testing it improves verification of clang .debug_names from four minutes to under a minute. This PR relies on a current mechanism of extracting DIEs into a vector. Future improvements can include creating API to extract DIE at a time, or grouping Entires into buckets by CUs and extracting before parallel step. Single Thread 4:12.37 real, 246.88 user, 3.54 sys, 0 amem, 10232004 mmem 0:49.40 real, 612.84 user, 515.73 sys, 0 amem, 11226292 mmem
1 parent 32c8754 commit 421d4b6

File tree

10 files changed

+194
-171
lines changed

10 files changed

+194
-171
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,12 @@ class DWARFDebugNames : public DWARFAcceleratorTable {
770770
}
771771

772772
public:
773+
using size_type = size_t;
773774
using iterator_category = std::input_iterator_tag;
774775
using value_type = NameTableEntry;
775776
using difference_type = uint32_t;
776777
using pointer = NameTableEntry *;
777-
using reference = NameTableEntry; // We return entries by value.
778+
using reference = NameTableEntry;
778779

779780
/// Creates an iterator whose initial position is name CurrentName in
780781
/// CurrentIndex.
@@ -793,6 +794,14 @@ class DWARFDebugNames : public DWARFAcceleratorTable {
793794
next();
794795
return I;
795796
}
797+
reference operator[](size_type idx) {
798+
return CurrentIndex->getNameTableEntry(idx + 1);
799+
}
800+
801+
difference_type operator-(const NameIterator &other) const {
802+
assert(CurrentIndex == other.CurrentIndex);
803+
return this->CurrentName - other.CurrentName;
804+
}
796805

797806
friend bool operator==(const NameIterator &A, const NameIterator &B) {
798807
return A.CurrentIndex == B.CurrentIndex && A.CurrentName == B.CurrentName;

llvm/include/llvm/DebugInfo/DWARF/DWARFVerifier.h

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
1717
#include <cstdint>
1818
#include <map>
19+
#include <mutex>
1920
#include <set>
2021

2122
namespace llvm {
@@ -32,7 +33,9 @@ struct DWARFSection;
3233

3334
class OutputCategoryAggregator {
3435
private:
36+
std::mutex WriteMutex;
3537
std::map<std::string, unsigned> Aggregation;
38+
unsigned NumErrors = 0;
3639
bool IncludeDetail;
3740

3841
public:
@@ -42,6 +45,8 @@ class OutputCategoryAggregator {
4245
size_t GetNumCategories() const { return Aggregation.size(); }
4346
void Report(StringRef s, std::function<void()> detailCallback);
4447
void EnumerateResults(std::function<void(StringRef, unsigned)> handleCounts);
48+
/// Return the number of errors that have been reported.
49+
unsigned GetNumErrors() const { return NumErrors; }
4550
};
4651

4752
/// A class that verifies DWARF debug information given a DWARF Context.
@@ -104,6 +109,7 @@ class DWARFVerifier {
104109
bool IsObjectFile;
105110
bool IsMachOObject;
106111
using ReferenceMap = std::map<uint64_t, std::set<uint64_t>>;
112+
std::mutex AccessMutex;
107113

108114
raw_ostream &error() const;
109115
raw_ostream &warn() const;
@@ -264,21 +270,22 @@ class DWARFVerifier {
264270
/// \param SectionName the name of the table we're verifying
265271
///
266272
/// \returns The number of errors occurred during verification
267-
unsigned verifyAppleAccelTable(const DWARFSection *AccelSection,
268-
DataExtractor *StrData,
269-
const char *SectionName);
270-
271-
unsigned verifyDebugNamesCULists(const DWARFDebugNames &AccelTable);
272-
unsigned verifyNameIndexBuckets(const DWARFDebugNames::NameIndex &NI,
273-
const DataExtractor &StrData);
274-
unsigned verifyNameIndexAbbrevs(const DWARFDebugNames::NameIndex &NI);
275-
unsigned verifyNameIndexAttribute(const DWARFDebugNames::NameIndex &NI,
276-
const DWARFDebugNames::Abbrev &Abbr,
277-
DWARFDebugNames::AttributeEncoding AttrEnc);
278-
unsigned verifyNameIndexEntries(const DWARFDebugNames::NameIndex &NI,
279-
const DWARFDebugNames::NameTableEntry &NTE);
280-
unsigned verifyNameIndexCompleteness(const DWARFDie &Die,
281-
const DWARFDebugNames::NameIndex &NI);
273+
void verifyAppleAccelTable(const DWARFSection *AccelSection,
274+
DataExtractor *StrData, const char *SectionName);
275+
276+
void verifyDebugNamesCULists(const DWARFDebugNames &AccelTable);
277+
void verifyNameIndexBuckets(const DWARFDebugNames::NameIndex &NI,
278+
const DataExtractor &StrData);
279+
void verifyNameIndexAbbrevs(const DWARFDebugNames::NameIndex &NI);
280+
void verifyNameIndexAttribute(const DWARFDebugNames::NameIndex &NI,
281+
const DWARFDebugNames::Abbrev &Abbr,
282+
DWARFDebugNames::AttributeEncoding AttrEnc);
283+
void verifyNameIndexEntries(
284+
const DWARFDebugNames::NameIndex &NI,
285+
const DWARFDebugNames::NameTableEntry &NTE,
286+
const DenseMap<uint64_t, DWARFUnit *> &CUOffsetsToDUMap);
287+
void verifyNameIndexCompleteness(const DWARFDie &Die,
288+
const DWARFDebugNames::NameIndex &NI);
282289

283290
/// Verify that the DWARF v5 accelerator table is valid.
284291
///
@@ -297,8 +304,8 @@ class DWARFVerifier {
297304
/// \param StrData string section
298305
///
299306
/// \returns The number of errors occurred during verification
300-
unsigned verifyDebugNames(const DWARFSection &AccelSection,
301-
const DataExtractor &StrData);
307+
void verifyDebugNames(const DWARFSection &AccelSection,
308+
const DataExtractor &StrData);
302309

303310
public:
304311
DWARFVerifier(raw_ostream &S, DWARFContext &D,

0 commit comments

Comments
 (0)