Skip to content

Commit efc2ccb

Browse files
Merge pull request #8106 from felipepiovezan/felipe/cherry-picks-debugnames2
[Cherry-pick] Patches related to dwarf linker and AccelTable
2 parents 87fe0d0 + c779fe1 commit efc2ccb

File tree

152 files changed

+10835
-2589
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+10835
-2589
lines changed

llvm/include/llvm/CodeGen/AccelTable.h

Lines changed: 89 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "llvm/ADT/ArrayRef.h"
1717
#include "llvm/ADT/MapVector.h"
1818
#include "llvm/ADT/STLFunctionalExtras.h"
19-
#include "llvm/ADT/StringMap.h"
2019
#include "llvm/ADT/StringRef.h"
2120
#include "llvm/BinaryFormat/Dwarf.h"
2221
#include "llvm/CodeGen/DIE.h"
@@ -25,6 +24,7 @@
2524
#include "llvm/Support/DJB.h"
2625
#include "llvm/Support/Debug.h"
2726
#include <cstdint>
27+
#include <variant>
2828
#include <vector>
2929

3030
/// \file
@@ -103,8 +103,9 @@
103103
namespace llvm {
104104

105105
class AsmPrinter;
106-
class DwarfCompileUnit;
106+
class DwarfUnit;
107107
class DwarfDebug;
108+
class DwarfTypeUnit;
108109
class MCSymbol;
109110
class raw_ostream;
110111

@@ -196,6 +197,9 @@ template <typename DataT> class AccelTable : public AccelTableBase {
196197

197198
template <typename... Types>
198199
void addName(DwarfStringPoolEntryRef Name, Types &&... Args);
200+
void clear() { Entries.clear(); }
201+
void addEntries(AccelTable<DataT> &Table);
202+
const StringEntries getEntries() const { return Entries; }
199203
};
200204

201205
template <typename AccelTableDataT>
@@ -249,46 +253,93 @@ class AppleAccelTableData : public AccelTableData {
249253
/// emitDWARF5AccelTable function.
250254
class DWARF5AccelTableData : public AccelTableData {
251255
public:
256+
struct AttributeEncoding {
257+
dwarf::Index Index;
258+
dwarf::Form Form;
259+
};
260+
252261
static uint32_t hash(StringRef Name) { return caseFoldingDjbHash(Name); }
253262

254-
DWARF5AccelTableData(const DIE &Die) : Die(Die) {}
263+
DWARF5AccelTableData(const DIE &Die, const uint32_t UnitID,
264+
const bool IsTU = false);
265+
DWARF5AccelTableData(const uint64_t DieOffset, const unsigned DieTag,
266+
const unsigned UnitID, const bool IsTU = false)
267+
: OffsetVal(DieOffset), DieTag(DieTag), UnitID(UnitID), IsTU(IsTU) {}
255268

256269
#ifndef NDEBUG
257270
void print(raw_ostream &OS) const override;
258271
#endif
259272

260-
const DIE &getDie() const { return Die; }
261-
uint64_t getDieOffset() const { return Die.getOffset(); }
262-
unsigned getDieTag() const { return Die.getTag(); }
273+
uint64_t getDieOffset() const {
274+
assert(isNormalized() && "Accessing DIE Offset before normalizing.");
275+
return std::get<uint64_t>(OffsetVal);
276+
}
277+
unsigned getDieTag() const { return DieTag; }
278+
unsigned getUnitID() const { return UnitID; }
279+
bool isTU() const { return IsTU; }
280+
void normalizeDIEToOffset() {
281+
assert(!isNormalized() && "Accessing offset after normalizing.");
282+
OffsetVal = std::get<const DIE *>(OffsetVal)->getOffset();
283+
}
284+
bool isNormalized() const {
285+
return std::holds_alternative<uint64_t>(OffsetVal);
286+
}
263287

264288
protected:
265-
const DIE &Die;
289+
std::variant<const DIE *, uint64_t> OffsetVal;
290+
uint32_t DieTag : 16;
291+
uint32_t UnitID : 15;
292+
uint32_t IsTU : 1;
266293

267-
uint64_t order() const override { return Die.getOffset(); }
294+
uint64_t order() const override { return getDieOffset(); }
268295
};
269296

270-
class DWARF5AccelTableStaticData : public AccelTableData {
271-
public:
272-
static uint32_t hash(StringRef Name) { return caseFoldingDjbHash(Name); }
273-
274-
DWARF5AccelTableStaticData(uint64_t DieOffset, unsigned DieTag,
275-
unsigned CUIndex)
276-
: DieOffset(DieOffset), DieTag(DieTag), CUIndex(CUIndex) {}
277-
278-
#ifndef NDEBUG
279-
void print(raw_ostream &OS) const override;
280-
#endif
281-
282-
uint64_t getDieOffset() const { return DieOffset; }
283-
unsigned getDieTag() const { return DieTag; }
284-
unsigned getCUIndex() const { return CUIndex; }
297+
struct TypeUnitMetaInfo {
298+
// Symbol for start of the TU section or signature if this is SplitDwarf.
299+
std::variant<MCSymbol *, uint64_t> LabelOrSignature;
300+
// Unique ID of Type Unit.
301+
unsigned UniqueID;
302+
};
303+
using TUVectorTy = SmallVector<TypeUnitMetaInfo, 1>;
304+
class DWARF5AccelTable : public AccelTable<DWARF5AccelTableData> {
305+
// Symbols to start of all the TU sections that were generated.
306+
TUVectorTy TUSymbolsOrHashes;
285307

286-
protected:
287-
uint64_t DieOffset;
288-
unsigned DieTag;
289-
unsigned CUIndex;
308+
public:
309+
struct UnitIndexAndEncoding {
310+
unsigned Index;
311+
DWARF5AccelTableData::AttributeEncoding Encoding;
312+
};
313+
/// Returns type units that were constructed.
314+
const TUVectorTy &getTypeUnitsSymbols() { return TUSymbolsOrHashes; }
315+
/// Add a type unit start symbol.
316+
void addTypeUnitSymbol(DwarfTypeUnit &U);
317+
/// Add a type unit Signature.
318+
void addTypeUnitSignature(DwarfTypeUnit &U);
319+
/// Convert DIE entries to explicit offset.
320+
/// Needs to be called after DIE offsets are computed.
321+
void convertDieToOffset() {
322+
for (auto &Entry : Entries) {
323+
for (AccelTableData *Value : Entry.second.Values) {
324+
DWARF5AccelTableData *Data = static_cast<DWARF5AccelTableData *>(Value);
325+
// For TU we normalize as each Unit is emitted.
326+
// So when this is invoked after CU construction we will be in mixed
327+
// state.
328+
if (!Data->isNormalized())
329+
Data->normalizeDIEToOffset();
330+
}
331+
}
332+
}
290333

291-
uint64_t order() const override { return DieOffset; }
334+
void addTypeEntries(DWARF5AccelTable &Table) {
335+
for (auto &Entry : Table.getEntries()) {
336+
for (AccelTableData *Value : Entry.second.Values) {
337+
DWARF5AccelTableData *Data = static_cast<DWARF5AccelTableData *>(Value);
338+
addName(Entry.second.Name, Data->getDieOffset(), Data->getDieTag(),
339+
Data->getUnitID(), true);
340+
}
341+
}
342+
}
292343
};
293344

294345
void emitAppleAccelTableImpl(AsmPrinter *Asm, AccelTableBase &Contents,
@@ -305,16 +356,20 @@ void emitAppleAccelTable(AsmPrinter *Asm, AccelTable<DataT> &Contents,
305356
emitAppleAccelTableImpl(Asm, Contents, Prefix, SecBegin, DataT::Atoms);
306357
}
307358

308-
void emitDWARF5AccelTable(AsmPrinter *Asm,
309-
AccelTable<DWARF5AccelTableData> &Contents,
359+
void emitDWARF5AccelTable(AsmPrinter *Asm, DWARF5AccelTable &Contents,
310360
const DwarfDebug &DD,
311361
ArrayRef<std::unique_ptr<DwarfCompileUnit>> CUs);
312362

363+
/// Emit a DWARFv5 Accelerator Table consisting of entries in the specified
364+
/// AccelTable. The \p CUs contains either symbols keeping offsets to the
365+
/// start of compilation unit, either offsets to the start of compilation
366+
/// unit themselves.
313367
void emitDWARF5AccelTable(
314-
AsmPrinter *Asm, AccelTable<DWARF5AccelTableStaticData> &Contents,
315-
ArrayRef<MCSymbol *> CUs,
316-
llvm::function_ref<unsigned(const DWARF5AccelTableStaticData &)>
317-
getCUIndexForEntry);
368+
AsmPrinter *Asm, DWARF5AccelTable &Contents,
369+
ArrayRef<std::variant<MCSymbol *, uint64_t>> CUs,
370+
llvm::function_ref<std::optional<DWARF5AccelTable::UnitIndexAndEncoding>(
371+
const DWARF5AccelTableData &)>
372+
getIndexForEntry);
318373

319374
/// Accelerator table data implementation for simple Apple accelerator tables
320375
/// with just a DIE reference.

llvm/include/llvm/DWARFLinker/DWARFLinker.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ class DwarfEmitter {
139139
virtual void emitLineStrings(const NonRelocatableStringpool &Pool) = 0;
140140

141141
/// Emit DWARF debug names.
142-
virtual void
143-
emitDebugNames(AccelTable<DWARF5AccelTableStaticData> &Table) = 0;
142+
virtual void emitDebugNames(DWARF5AccelTable &Table) = 0;
144143

145144
/// Emit Apple namespaces accelerator table.
146145
virtual void
@@ -896,7 +895,7 @@ class DWARFLinker {
896895
uint32_t LastCIEOffset = 0;
897896

898897
/// Apple accelerator tables.
899-
AccelTable<DWARF5AccelTableStaticData> DebugNames;
898+
DWARF5AccelTable DebugNames;
900899
AccelTable<AppleAccelTableStaticOffsetData> AppleNames;
901900
AccelTable<AppleAccelTableStaticOffsetData> AppleNamespaces;
902901
AccelTable<AppleAccelTableStaticOffsetData> AppleObjc;

llvm/include/llvm/DWARFLinker/DWARFStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class DwarfStreamer : public DwarfEmitter {
163163
StringRef Bytes) override;
164164

165165
/// Emit DWARF debug names.
166-
void emitDebugNames(AccelTable<DWARF5AccelTableStaticData> &Table) override;
166+
void emitDebugNames(DWARF5AccelTable &Table) override;
167167

168168
/// Emit Apple namespaces accelerator table.
169169
void emitAppleNamespaces(

llvm/include/llvm/DWARFLinkerParallel/DWARFLinker.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ class ExtraDwarfEmitter {
100100
/// Emit section named SecName with data SecData.
101101
virtual void emitSectionContents(StringRef SecData, StringRef SecName) = 0;
102102

103-
/// Emit temporarily symbol named \p SymName inside section \p SecName.
104-
virtual MCSymbol *emitTempSym(StringRef SecName, StringRef SymName) = 0;
105-
106103
/// Emit the swift_ast section stored in \p Buffer.
107104
virtual void emitSwiftAST(StringRef Buffer) = 0;
108105

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "llvm/ADT/SmallPtrSet.h"
2323
#include "llvm/ADT/SmallSet.h"
2424
#include "llvm/ADT/SmallVector.h"
25-
#include "llvm/ADT/iterator_range.h"
2625
#include "llvm/Analysis/AliasAnalysis.h"
2726
#include "llvm/Analysis/AliasSetTracker.h"
2827
#include "llvm/Analysis/LoopAnalysisManager.h"

llvm/lib/Bitcode/Reader/MetadataLoader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "llvm/ADT/StringRef.h"
2323
#include "llvm/ADT/Twine.h"
2424
#include "llvm/ADT/ilist_iterator.h"
25-
#include "llvm/ADT/iterator_range.h"
2625
#include "llvm/BinaryFormat/Dwarf.h"
2726
#include "llvm/Bitcode/BitcodeReader.h"
2827
#include "llvm/Bitcode/LLVMBitCodes.h"

0 commit comments

Comments
 (0)