36 std::vector<uint32_t> Uniques;
39 Uniques.push_back(
E.second.HashValue);
41 std::vector<uint32_t>::iterator
P =
42 std::unique(Uniques.begin(), Uniques.end());
46 if (UniqueHashCount > 1024)
48 else if (UniqueHashCount > 16)
62 E.second.Values.erase(
63 std::unique(
E.second.Values.begin(),
E.second.Values.end()),
64 E.second.Values.end());
75 for (
auto &
E : Entries) {
77 Buckets[Bucket].push_back(&
E.second);
92 class AccelTableWriter {
100 const bool SkipIdenticalHashes;
102 void emitHashes()
const;
110 bool SkipIdenticalHashes)
111 :
Asm(Asm), Contents(Contents), SkipIdenticalHashes(SkipIdenticalHashes) {
115 class AppleAccelTableWriter :
public AccelTableWriter {
128 static const uint32_t MagicHash = 0x48415348;
131 :
BucketCount(BucketCount), HashCount(UniqueHashCount),
132 HeaderDataLength(DataLength) {}
151 : DieOffsetBase(
Offset), Atoms(AtomList.
begin(), AtomList.
end()) {}
161 HeaderData HeaderData;
164 void emitBuckets()
const;
165 void emitData()
const;
170 : AccelTableWriter(Asm, Contents,
true),
172 8 + (Atoms.
size() * 4)),
173 HeaderData(Atoms), SecBegin(SecBegin) {}
190 template <
typename DataT>
191 class Dwarf5AccelTableWriter :
public AccelTableWriter {
202 uint32_t AugmentationStringSize =
sizeof(AugmentationString);
203 char AugmentationString[8] = {
'L',
'L',
'V',
'M',
'0',
'7',
'0',
'0'};
206 : CompUnitCount(CompUnitCount),
BucketCount(BucketCount),
207 NameCount(NameCount) {}
209 void emit(
const Dwarf5AccelTableWriter &Ctx)
const;
211 struct AttributeEncoding {
220 MCSymbol *ContributionStart =
Asm->createTempSymbol(
"names_start");
221 MCSymbol *ContributionEnd =
Asm->createTempSymbol(
"names_end");
222 MCSymbol *AbbrevStart =
Asm->createTempSymbol(
"names_abbrev_start");
223 MCSymbol *AbbrevEnd =
Asm->createTempSymbol(
"names_abbrev_end");
224 MCSymbol *EntryPool =
Asm->createTempSymbol(
"names_entries");
231 void emitCUList()
const;
232 void emitBuckets()
const;
233 void emitStringOffsets()
const;
234 void emitAbbrevs()
const;
235 void emitEntry(
const DataT &
Entry)
const;
236 void emitData()
const;
239 Dwarf5AccelTableWriter(
248 void AccelTableWriter::emitHashes()
const {
250 unsigned BucketIdx = 0;
251 for (
auto &Bucket : Contents.getBuckets()) {
252 for (
auto &
Hash : Bucket) {
254 if (SkipIdenticalHashes && PrevHash == HashValue)
256 Asm->OutStreamer->AddComment(
"Hash in Bucket " +
Twine(BucketIdx));
257 Asm->emitInt32(HashValue);
258 PrevHash = HashValue;
264 void AccelTableWriter::emitOffsets(
const MCSymbol *
Base)
const {
265 const auto &
Buckets = Contents.getBuckets();
267 for (
size_t i = 0,
e =
Buckets.size(); i <
e; ++i) {
270 if (SkipIdenticalHashes && PrevHash == HashValue)
272 PrevHash = HashValue;
273 Asm->OutStreamer->AddComment(
"Offset in Bucket " +
Twine(i));
279 void AppleAccelTableWriter::Header::emit(
AsmPrinter *
Asm)
const {
284 Asm->
OutStreamer->AddComment(
"Header Hash Function");
286 Asm->
OutStreamer->AddComment(
"Header Bucket Count");
290 Asm->
OutStreamer->AddComment(
"Header Data Length");
294 void AppleAccelTableWriter::HeaderData::emit(
AsmPrinter *Asm)
const {
295 Asm->
OutStreamer->AddComment(
"HeaderData Die Offset Base");
297 Asm->
OutStreamer->AddComment(
"HeaderData Atom Count");
300 for (
const Atom &A : Atoms) {
308 void AppleAccelTableWriter::emitBuckets()
const {
309 const auto &
Buckets = Contents.getBuckets();
311 for (
size_t i = 0,
e =
Buckets.size(); i <
e; ++i) {
322 if (PrevHash != HashValue)
324 PrevHash = HashValue;
329 void AppleAccelTableWriter::emitData()
const {
330 const auto &
Buckets = Contents.getBuckets();
331 for (
size_t i = 0,
e =
Buckets.size(); i <
e; ++i) {
337 PrevHash !=
Hash->HashValue)
345 for (
const auto *V :
Hash->Values)
347 PrevHash =
Hash->HashValue;
355 void AppleAccelTableWriter::emit()
const {
357 HeaderData.emit(Asm);
360 emitOffsets(SecBegin);
364 template <
typename DataT>
365 void Dwarf5AccelTableWriter<DataT>::Header::emit(
366 const Dwarf5AccelTableWriter &Ctx)
const {
367 assert(CompUnitCount > 0 &&
"Index must have at least one CU.");
370 Asm->
OutStreamer->AddComment(
"Header: unit length");
373 Asm->
OutStreamer->EmitLabel(Ctx.ContributionStart);
378 Asm->
OutStreamer->AddComment(
"Header: compilation unit count");
380 Asm->
OutStreamer->AddComment(
"Header: local type unit count");
382 Asm->
OutStreamer->AddComment(
"Header: foreign type unit count");
384 Asm->
OutStreamer->AddComment(
"Header: bucket count");
386 Asm->
OutStreamer->AddComment(
"Header: name count");
388 Asm->
OutStreamer->AddComment(
"Header: abbreviation table size");
390 Asm->
OutStreamer->AddComment(
"Header: augmentation string size");
391 assert(AugmentationStringSize % 4 == 0);
393 Asm->
OutStreamer->AddComment(
"Header: augmentation string");
394 Asm->
OutStreamer->EmitBytes({AugmentationString, AugmentationStringSize});
397 template <
typename DataT>
400 for (
auto &Bucket : Contents.getBuckets()) {
401 for (
auto *
Hash : Bucket) {
403 unsigned Tag =
static_cast<const DataT *
>(
Value)->getDieTag();
411 template <
typename DataT>
413 Dwarf5AccelTableWriter<DataT>::getUniformAttributes()
const {
415 if (CompUnits.size() > 1) {
416 size_t LargestCUIndex = CompUnits.
size() - 1;
418 UA.
push_back({dwarf::DW_IDX_compile_unit, Form});
420 UA.
push_back({dwarf::DW_IDX_die_offset, dwarf::DW_FORM_ref4});
424 template <
typename DataT>
425 void Dwarf5AccelTableWriter<DataT>::emitCUList()
const {
432 template <
typename DataT>
433 void Dwarf5AccelTableWriter<DataT>::emitBuckets()
const {
435 for (
const auto &Bucket :
enumerate(Contents.getBuckets())) {
438 Index += Bucket.value().size();
442 template <
typename DataT>
443 void Dwarf5AccelTableWriter<DataT>::emitStringOffsets()
const {
444 for (
const auto &Bucket :
enumerate(Contents.getBuckets())) {
445 for (
auto *
Hash : Bucket.value()) {
454 template <
typename DataT>
455 void Dwarf5AccelTableWriter<DataT>::emitAbbrevs()
const {
457 for (
const auto &Abbrev : Abbreviations) {
459 assert(Abbrev.first != 0);
463 for (
const auto &AttrEnc : Abbrev.second) {
475 template <
typename DataT>
476 void Dwarf5AccelTableWriter<DataT>::emitEntry(
const DataT &
Entry)
const {
477 auto AbbrevIt = Abbreviations.find(Entry.getDieTag());
478 assert(AbbrevIt != Abbreviations.end() &&
479 "Why wasn't this abbrev generated?");
481 Asm->
EmitULEB128(AbbrevIt->first,
"Abbreviation code");
482 for (
const auto &AttrEnc : AbbrevIt->second) {
484 switch (AttrEnc.Index) {
485 case dwarf::DW_IDX_compile_unit: {
490 case dwarf::DW_IDX_die_offset:
491 assert(AttrEnc.Form == dwarf::DW_FORM_ref4);
500 template <
typename DataT>
void Dwarf5AccelTableWriter<DataT>::emitData()
const {
502 for (
auto &Bucket : Contents.getBuckets()) {
503 for (
auto *
Hash : Bucket) {
507 emitEntry(*static_cast<const DataT *>(
Value));
508 Asm->
OutStreamer->AddComment(
"End of list: " +
Hash->Name.getString());
514 template <
typename DataT>
515 Dwarf5AccelTableWriter<DataT>::Dwarf5AccelTableWriter(
519 : AccelTableWriter(Asm, Contents,
false),
522 CompUnits(CompUnits), getCUIndexForEntry(std::move(getCUIndexForEntry)) {
526 Abbreviations.reserve(UniqueTags.
size());
528 Abbreviations.try_emplace(
Tag, UniformAttributes);
531 template <
typename DataT>
void Dwarf5AccelTableWriter<DataT>::emit()
const {
537 emitOffsets(EntryPool);
548 AppleAccelTableWriter(Asm, Contents, Atoms, SecBegin).emit();
554 std::vector<MCSymbol *> CompUnits;
558 if (
CU.value()->getCUNode()->getNameTableKind() !=
561 CUIndex[
CU.index()] = Count++;
562 assert(
CU.index() ==
CU.value()->getUniqueID());
565 CompUnits.push_back(MainCU->getLabelBegin());
568 if (CompUnits.empty())
575 Dwarf5AccelTableWriter<DWARF5AccelTableData>(
576 Asm, Contents, CompUnits,
578 const DIE *CUDie =
Entry.getDie().getUnitDie();
588 getCUIndexForEntry) {
590 Dwarf5AccelTableWriter<DWARF5AccelTableStaticData>(
Asm, Contents, CUs,
596 Asm->
emitInt32(Die.getDebugSectionOffset());
600 Asm->
emitInt32(Die.getDebugSectionOffset());
625 <<
"Version: " <<
Version <<
"\n" 626 <<
"Hash Function: " << HashFunction <<
"\n" 628 <<
"Header Data Length: " << HeaderDataLength <<
"\n";
637 OS <<
"DIE Offset Base: " << DieOffsetBase <<
"\n";
638 for (
auto Atom : Atoms)
644 HeaderData.print(OS);
646 SecBegin->print(OS,
nullptr);
650 OS <<
"Name: " <<
Name.getString() <<
"\n";
651 OS <<
" Hash Value: " <<
format(
"0x%x", HashValue) <<
"\n";
658 for (
auto *
Value : Values)
666 OS <<
"Name: " <<
Entry.first() <<
"\n";
667 for (
auto *V :
Entry.second.Values)
671 OS <<
"Buckets and Hashes: \n";
673 for (
auto &
Hash : Bucket)
677 for (
auto &
E : Entries)
682 OS <<
" Offset: " << getDieOffset() <<
"\n";
687 OS <<
" Offset: " << getDieOffset() <<
"\n";
692 OS <<
" Offset: " << Die.getOffset() <<
"\n";
696 OS <<
" Offset: " << Die.getOffset() <<
"\n";
701 OS <<
" Static Offset: " <<
Offset <<
"\n";
705 OS <<
" Static Offset: " <<
Offset <<
"\n";
706 OS <<
" QualifiedNameHash: " <<
format(
"%x\n", QualifiedNameHash) <<
"\n";
708 OS <<
" ObjCClassIsImplementation: " 709 << (ObjCClassIsImplementation ?
"true" :
"false");
StringRef getString() const
static constexpr Atom Atoms[]
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
void print(raw_ostream &OS) const override
StringRef IndexString(unsigned Idx)
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
This class represents lattice values for constants.
StringRef AtomTypeString(unsigned Atom)
An Atom defines the form of the data in an Apple accelerator table.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void print(raw_ostream &OS) const override
void push_back(const T &Elt)
static constexpr Atom Atoms[]
Collects and handles dwarf debug information.
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
An efficient, type-erasing, non-owning reference to a callable.
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
void print(raw_ostream &OS) const override
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support...
void print(raw_ostream &OS) const override
uint32_t getUniqueHashCount() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StringRef FormEncodingString(unsigned Encoding)
void emit(AsmPrinter *Asm) const override
void emitAppleAccelTableImpl(AsmPrinter *Asm, AccelTableBase &Contents, StringRef Prefix, const MCSymbol *SecBegin, ArrayRef< AppleAccelTableData::Atom > Atoms)
void computeBucketCount()
unsigned getUniqueID() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void emit(AsmPrinter *Asm) const override
static constexpr Atom Atoms[]
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
uint32_t getUniqueNameCount() const
The instances of the Type class are immutable: once they are created, they are never changed...
void EmitULEB128(uint64_t Value, const char *Desc=nullptr, unsigned PadTo=0) const
Emit the specified unsigned leb128 value.
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
A structured debug information entry.
std::pair< iterator, bool > insert(const ValueT &V)
static dwarf::Form BestForm(bool IsSigned, uint64_t Int)
Choose the best form for integer.
This class is intended to be used as a driving class for all asm writers.
void emit(AsmPrinter *Asm) const override
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
void emitDWARF5AccelTable(AsmPrinter *Asm, AccelTable< DWARF5AccelTableData > &Contents, const DwarfDebug &DD, ArrayRef< std::unique_ptr< DwarfCompileUnit >> CUs)
A base class for different implementations of Data classes for Apple Accelerator Tables.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void print(raw_ostream &OS) const override
void finalize(AsmPrinter *Asm, StringRef Prefix)
static const char *const Magic
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Interface which the different types of accelerator table data have to conform.
void print(raw_ostream &OS) const
Align max(MaybeAlign Lhs, Align Rhs)
void emitDwarfStringOffset(DwarfStringPoolEntry S) const
Emit the 4-byte offset of a string from the start of its section.
DwarfCompileUnit * lookupCU(const DIE *Die)
Find the matching DwarfCompileUnit for the given CU DIE.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
void print(raw_ostream &OS) const
void emitInt32(int Value) const
Emit a long directive and value.
MCSection * getDwarfDebugNamesSection() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
A base class holding non-template-dependant functionality of the AccelTable class.
This file contains constants used for implementing Dwarf debug support.
void print(raw_ostream &OS) const
void emit(AsmPrinter *Asm) const override
String pool entry reference.
Represents a group of entries with identical name (and hence, hash value).
StringRef TagString(unsigned Tag)
The Data class implementation for DWARF v5 accelerator table.
static constexpr Atom Atoms[]
void print(raw_ostream &OS) const override
void EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) const
Emit something like ".long Hi-Lo" where the size in bytes of the directive is specified by Size and H...
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void stable_sort(R &&Range)
void emitInt8(int Value) const
Emit a byte directive and value.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
void EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit integer of appropriate size.
MCSymbol * createTempSymbol(const Twine &Name) const
uint32_t getBucketCount() const
void emitInt16(int Value) const
Emit a short directive and value.
detail::enumerator< R > enumerate(R &&TheRange)
Given an input range, returns a new range whose values are are pair (A,B) such that A is the 0-based ...