@@ -322,43 +322,6 @@ void DWARF5AcceleratorTable::finalize() {
322
322
TUIndexEncodingSize = *dwarf::getFixedFormByteSize (TUIndexForm, FormParams);
323
323
}
324
324
325
- DWARF5AcceleratorTable::TagIndex DWARF5AcceleratorTable::getAbbrevIndex (
326
- const unsigned DieTag,
327
- const std::optional<DWARF5AccelTable::UnitIndexAndEncoding> &EntryRet,
328
- const std::optional<DWARF5AccelTable::UnitIndexAndEncoding>
329
- &SecondEntryRet) {
330
- AbbrevDescriptor AbbrvDesc;
331
- auto setFields =
332
- [&](const std::optional<DWARF5AccelTable::UnitIndexAndEncoding> &Entry)
333
- -> void {
334
- if (!Entry)
335
- return ;
336
- switch (Entry->Encoding .Index ) {
337
- case dwarf::DW_IDX_compile_unit:
338
- AbbrvDesc.Bits .CompUnit = true ;
339
- break ;
340
- case dwarf::DW_IDX_type_unit:
341
- AbbrvDesc.Bits .TypeUnit = true ;
342
- break ;
343
- case dwarf::DW_IDX_parent:
344
- AbbrvDesc.Bits .Parent = 0 ;
345
- break ;
346
- case dwarf::DW_IDX_type_hash:
347
- AbbrvDesc.Bits .TypeHash = true ;
348
- break ;
349
- default :
350
- return ;
351
- }
352
- };
353
- setFields (EntryRet);
354
- setFields (SecondEntryRet);
355
- AbbrvDesc.Bits .DieOffset = true ;
356
- AbbrvDesc.Bits .Tag = DieTag;
357
- auto Iter = AbbrevTagToIndexMap.insert (
358
- {AbbrvDesc.Value , static_cast <uint32_t >(AbbrevTagToIndexMap.size () + 1 )});
359
- return {DieTag, Iter.first ->second };
360
- }
361
-
362
325
std::optional<DWARF5AccelTable::UnitIndexAndEncoding>
363
326
DWARF5AcceleratorTable::getIndexForEntry (
364
327
const BOLTDWARF5AccelTableData &Value) const {
@@ -388,17 +351,26 @@ void DWARF5AcceleratorTable::populateAbbrevsMap() {
388
351
// the CU.
389
352
const std::optional<DWARF5AccelTable::UnitIndexAndEncoding>
390
353
SecondEntryRet = getSecondIndexForEntry (*Value);
391
- const unsigned Tag = Value->getDieTag ();
392
- const TagIndex AbbrvTag = getAbbrevIndex (Tag, EntryRet, SecondEntryRet);
393
- if (Abbreviations.count (AbbrvTag) == 0 ) {
394
- SmallVector<DWARF5AccelTableData::AttributeEncoding, 2 > UA;
395
- if (EntryRet)
396
- UA.push_back (EntryRet->Encoding );
397
- if (SecondEntryRet)
398
- UA.push_back (SecondEntryRet->Encoding );
399
- UA.push_back ({dwarf::DW_IDX_die_offset, dwarf::DW_FORM_ref4});
400
- Abbreviations.try_emplace (AbbrvTag, UA);
354
+ DebugNamesAbbrev Abbrev (Value->getDieTag ());
355
+ if (EntryRet)
356
+ Abbrev.addAttribute (EntryRet->Encoding );
357
+ if (SecondEntryRet)
358
+ Abbrev.addAttribute (SecondEntryRet->Encoding );
359
+ Abbrev.addAttribute ({dwarf::DW_IDX_die_offset, dwarf::DW_FORM_ref4});
360
+ FoldingSetNodeID ID;
361
+ Abbrev.Profile (ID);
362
+ void *InsertPos;
363
+ if (DebugNamesAbbrev *Existing =
364
+ AbbreviationsSet.FindNodeOrInsertPos (ID, InsertPos)) {
365
+ Value->setAbbrevNumber (Existing->getNumber ());
366
+ continue ;
401
367
}
368
+ DebugNamesAbbrev *NewAbbrev =
369
+ new (Alloc) DebugNamesAbbrev (std::move (Abbrev));
370
+ AbbreviationsVector.push_back (NewAbbrev);
371
+ NewAbbrev->setNumber (AbbreviationsVector.size ());
372
+ AbbreviationsSet.InsertNode (NewAbbrev, InsertPos);
373
+ Value->setAbbrevNumber (NewAbbrev->getNumber ());
402
374
}
403
375
}
404
376
}
@@ -410,12 +382,11 @@ void DWARF5AcceleratorTable::writeEntry(const BOLTDWARF5AccelTableData &Entry) {
410
382
// For forgeign type (FTU) units that need to refer to the FTU and to the CU.
411
383
const std::optional<DWARF5AccelTable::UnitIndexAndEncoding> SecondEntryRet =
412
384
getSecondIndexForEntry (Entry);
413
- const TagIndex TagIndexVal =
414
- getAbbrevIndex (Entry.getDieTag (), EntryRet, SecondEntryRet);
415
- auto AbbrevIt = Abbreviations.find (TagIndexVal);
416
- assert (AbbrevIt != Abbreviations.end () &&
417
- " Abbrev tag was not found in the abbreviation map!" );
418
- encodeULEB128 (TagIndexVal.Index , *Entriestream);
385
+ const unsigned AbbrevIndex = Entry.getAbbrevNumber () - 1 ;
386
+ assert (AbbrevIndex < AbbreviationsVector.size () &&
387
+ " Entry abbrev index is outside of abbreviations vector range." );
388
+ const DebugNamesAbbrev *Abbrev = AbbreviationsVector[AbbrevIndex];
389
+ encodeULEB128 (Entry.getAbbrevNumber (), *Entriestream);
419
390
auto writeIndex = [&](uint32_t Index, uint32_t IndexSize) -> void {
420
391
switch (IndexSize) {
421
392
default :
@@ -436,8 +407,8 @@ void DWARF5AcceleratorTable::writeEntry(const BOLTDWARF5AccelTableData &Entry) {
436
407
};
437
408
};
438
409
439
- for (const DWARF5AccelTableData ::AttributeEncoding &AttrEnc :
440
- AbbrevIt-> second ) {
410
+ for (const DebugNamesAbbrev ::AttributeEncoding &AttrEnc :
411
+ Abbrev-> getAttributes () ) {
441
412
switch (AttrEnc.Index ) {
442
413
default : {
443
414
llvm_unreachable (" Unexpected index attribute!" );
@@ -602,10 +573,10 @@ void DWARF5AcceleratorTable::emitOffsets() const {
602
573
}
603
574
void DWARF5AcceleratorTable::emitAbbrevs () {
604
575
const uint32_t AbbrevTableStart = StrBuffer->size ();
605
- for (const auto & Abbrev : Abbreviations ) {
606
- encodeULEB128 (Abbrev. first . Index , *StrStream);
607
- encodeULEB128 (Abbrev. first . DieTag , *StrStream);
608
- for (const auto &AttrEnc : Abbrev. second ) {
576
+ for (const auto * Abbrev : AbbreviationsVector ) {
577
+ encodeULEB128 (Abbrev-> getNumber () , *StrStream);
578
+ encodeULEB128 (Abbrev-> getDieTag () , *StrStream);
579
+ for (const auto &AttrEnc : Abbrev-> getAttributes () ) {
609
580
encodeULEB128 (AttrEnc.Index , *StrStream);
610
581
encodeULEB128 (AttrEnc.Form , *StrStream);
611
582
}
0 commit comments