@@ -208,7 +208,9 @@ class Dwarf5AccelTableWriter : public AccelTableWriter {
208
208
};
209
209
210
210
Header Header;
211
- DenseMap<uint32_t , SmallVector<DWARF5AccelTableData::AttributeEncoding, 3 >>
211
+ std::map<DWARF5AccelTable::TagIndex,
212
+ SmallVector<DWARF5AccelTableData::AttributeEncoding, 3 >,
213
+ DWARF5AccelTable::cmpByTagIndex>
212
214
Abbreviations;
213
215
ArrayRef<std::variant<MCSymbol *, uint64_t >> CompUnits;
214
216
ArrayRef<std::variant<MCSymbol *, uint64_t >> TypeUnits;
@@ -223,6 +225,15 @@ class Dwarf5AccelTableWriter : public AccelTableWriter {
223
225
bool IsSplitDwarf = false ;
224
226
// / Stores the DIE offsets which are indexed by this table.
225
227
DenseSet<OffsetAndUnitID> IndexedOffsets;
228
+ // / Mapping between AbbrevTag and Index.
229
+ std::unordered_map<uint32_t , uint32_t > AbbrevTagToIndexMap;
230
+
231
+ // / Constructs and returns a unique AbbrevTag that captures what a DIE
232
+ // / accesses.
233
+ DWARF5AccelTable::TagIndex getAbbrevIndex (
234
+ const unsigned DieTag,
235
+ const std::optional<DWARF5AccelTable::UnitIndexAndEncoding> &EntryRet,
236
+ const std::optional<dwarf::Form> &MaybeParentForm);
226
237
227
238
void populateAbbrevsMap ();
228
239
@@ -234,7 +245,7 @@ class Dwarf5AccelTableWriter : public AccelTableWriter {
234
245
void emitEntry (
235
246
const DWARF5AccelTableData &Entry,
236
247
const DenseMap<OffsetAndUnitID, MCSymbol *> &DIEOffsetToAccelEntryLabel,
237
- DenseSet<MCSymbol *> &EmittedAccelEntrySymbols) const ;
248
+ DenseSet<MCSymbol *> &EmittedAccelEntrySymbols);
238
249
void emitData ();
239
250
240
251
public:
@@ -409,49 +420,30 @@ DWARF5AccelTableData::getDefiningParentDieOffset(const DIE &Die) {
409
420
return {};
410
421
}
411
422
412
- enum IdxParentEncoding : uint8_t {
413
- NoIndexedParent = 0 , // / Parent information present but parent isn't indexed.
414
- Ref4 = 1 , // / Parent information present and parent is indexed.
415
- NoParent = 2 , // / Parent information missing.
416
- };
417
-
418
- static uint32_t constexpr NumBitsIdxParent = 2 ;
419
-
420
- uint8_t encodeIdxParent (const std::optional<dwarf::Form> MaybeParentForm) {
421
- if (!MaybeParentForm)
422
- return NoParent;
423
- switch (*MaybeParentForm) {
424
- case dwarf::Form::DW_FORM_flag_present:
425
- return NoIndexedParent;
426
- case dwarf::Form::DW_FORM_ref4:
427
- return Ref4;
428
- default :
429
- // This is not crashing on bad input: we should only reach this if the
430
- // internal compiler logic is faulty; see getFormForIdxParent.
431
- llvm_unreachable (" Bad form for IDX_parent" );
432
- }
433
- }
434
-
435
- static uint32_t constexpr ParentBitOffset = dwarf::DW_IDX_type_hash;
436
- static uint32_t constexpr TagBitOffset = ParentBitOffset + NumBitsIdxParent;
437
- static uint32_t getTagFromAbbreviationTag (const uint32_t AbbrvTag) {
438
- return AbbrvTag >> TagBitOffset;
439
- }
440
-
441
- // / Constructs a unique AbbrevTag that captures what a DIE accesses.
442
- // / Using this tag we can emit a unique abbreviation for each DIE.
443
- static uint32_t constructAbbreviationTag (
444
- const unsigned Tag,
423
+ DWARF5AccelTable::TagIndex Dwarf5AccelTableWriter::getAbbrevIndex (
424
+ const unsigned DieTag,
445
425
const std::optional<DWARF5AccelTable::UnitIndexAndEncoding> &EntryRet,
446
- std::optional<dwarf::Form> MaybeParentForm) {
447
- uint32_t AbbrvTag = 0 ;
448
- if (EntryRet)
449
- AbbrvTag |= 1 << EntryRet->Encoding .Index ;
450
- AbbrvTag |= 1 << dwarf::DW_IDX_die_offset;
451
- AbbrvTag |= 1 << dwarf::DW_IDX_parent;
452
- AbbrvTag |= encodeIdxParent (MaybeParentForm) << ParentBitOffset;
453
- AbbrvTag |= Tag << TagBitOffset;
454
- return AbbrvTag;
426
+ const std::optional<dwarf::Form> &MaybeParentForm) {
427
+ DWARF5AccelTable::AbbrevDescriptor AbbrvDesc;
428
+ if (EntryRet) {
429
+ switch (EntryRet->Encoding .Index ) {
430
+ case dwarf::DW_IDX_compile_unit:
431
+ AbbrvDesc.Bits .CompUnit = true ;
432
+ break ;
433
+ case dwarf::DW_IDX_type_unit:
434
+ AbbrvDesc.Bits .TypeUnit = true ;
435
+ break ;
436
+ default :
437
+ llvm_unreachable (" Invalid encoding index" );
438
+ break ;
439
+ }
440
+ }
441
+ AbbrvDesc.Bits .Parent = DWARF5AccelTable::encodeIdxParent (MaybeParentForm);
442
+ AbbrvDesc.Bits .DieOffset = true ;
443
+ AbbrvDesc.Bits .Tag = DieTag;
444
+ auto Iter = AbbrevTagToIndexMap.insert (
445
+ {AbbrvDesc.Value , static_cast <uint32_t >(AbbrevTagToIndexMap.size () + 1 )});
446
+ return {DieTag, Iter.first ->second };
455
447
}
456
448
457
449
static std::optional<dwarf::Form>
@@ -476,8 +468,8 @@ void Dwarf5AccelTableWriter::populateAbbrevsMap() {
476
468
unsigned Tag = Value->getDieTag ();
477
469
std::optional<dwarf::Form> MaybeParentForm = getFormForIdxParent (
478
470
IndexedOffsets, Value->getParentDieOffsetAndUnitID ());
479
- uint32_t AbbrvTag =
480
- constructAbbreviationTag (Tag, EntryRet, MaybeParentForm);
471
+ const DWARF5AccelTable::TagIndex AbbrvTag =
472
+ getAbbrevIndex (Tag, EntryRet, MaybeParentForm);
481
473
if (Abbreviations.count (AbbrvTag) == 0 ) {
482
474
SmallVector<DWARF5AccelTableData::AttributeEncoding, 3 > UA;
483
475
if (EntryRet)
@@ -538,11 +530,9 @@ void Dwarf5AccelTableWriter::emitAbbrevs() const {
538
530
Asm->OutStreamer ->emitLabel (AbbrevStart);
539
531
for (const auto &Abbrev : Abbreviations) {
540
532
Asm->OutStreamer ->AddComment (" Abbrev code" );
541
- uint32_t Tag = getTagFromAbbreviationTag (Abbrev.first );
542
- assert (Tag != 0 );
543
- Asm->emitULEB128 (Abbrev.first );
544
- Asm->OutStreamer ->AddComment (dwarf::TagString (Tag));
545
- Asm->emitULEB128 (Tag);
533
+ Asm->emitULEB128 (Abbrev.first .Index );
534
+ Asm->OutStreamer ->AddComment (dwarf::TagString (Abbrev.first .DieTag ));
535
+ Asm->emitULEB128 (Abbrev.first .DieTag );
546
536
for (const auto &AttrEnc : Abbrev.second ) {
547
537
Asm->emitULEB128 (AttrEnc.Index , dwarf::IndexString (AttrEnc.Index ).data ());
548
538
Asm->emitULEB128 (AttrEnc.Form ,
@@ -558,20 +548,18 @@ void Dwarf5AccelTableWriter::emitAbbrevs() const {
558
548
void Dwarf5AccelTableWriter::emitEntry (
559
549
const DWARF5AccelTableData &Entry,
560
550
const DenseMap<OffsetAndUnitID, MCSymbol *> &DIEOffsetToAccelEntryLabel,
561
- DenseSet<MCSymbol *> &EmittedAccelEntrySymbols) const {
551
+ DenseSet<MCSymbol *> &EmittedAccelEntrySymbols) {
562
552
std::optional<DWARF5AccelTable::UnitIndexAndEncoding> EntryRet =
563
553
getIndexForEntry (Entry);
564
554
std::optional<OffsetAndUnitID> MaybeParentOffset =
565
555
Entry.getParentDieOffsetAndUnitID ();
566
556
std::optional<dwarf::Form> MaybeParentForm =
567
557
getFormForIdxParent (IndexedOffsets, MaybeParentOffset);
568
- uint32_t AbbrvTag =
569
- constructAbbreviationTag (Entry.getDieTag (), EntryRet, MaybeParentForm);
570
- auto AbbrevIt = Abbreviations.find (AbbrvTag );
558
+ const DWARF5AccelTable::TagIndex TagIndexVal =
559
+ getAbbrevIndex (Entry.getDieTag (), EntryRet, MaybeParentForm);
560
+ auto AbbrevIt = Abbreviations.find (TagIndexVal );
571
561
assert (AbbrevIt != Abbreviations.end () &&
572
562
" Why wasn't this abbrev generated?" );
573
- assert (getTagFromAbbreviationTag (AbbrevIt->first ) == Entry.getDieTag () &&
574
- " Invalid Tag" );
575
563
576
564
auto EntrySymbolIt =
577
565
DIEOffsetToAccelEntryLabel.find (Entry.getDieOffsetAndUnitID ());
@@ -584,7 +572,7 @@ void Dwarf5AccelTableWriter::emitEntry(
584
572
if (EmittedAccelEntrySymbols.insert (EntrySymbol).second )
585
573
Asm->OutStreamer ->emitLabel (EntrySymbol);
586
574
587
- Asm->emitULEB128 (AbbrevIt-> first , " Abbreviation code" );
575
+ Asm->emitULEB128 (TagIndexVal. Index , " Abbreviation code" );
588
576
589
577
for (const auto &AttrEnc : AbbrevIt->second ) {
590
578
Asm->OutStreamer ->AddComment (dwarf::IndexString (AttrEnc.Index ));
0 commit comments