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)
58 std::stable_sort(
E.second.Values.begin(),
E.second.Values.end(),
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);
84 std::stable_sort(Bucket.begin(), Bucket.end(),
93 class AccelTableWriter {
101 const bool SkipIdenticalHashes;
103 void emitHashes()
const;
111 bool SkipIdenticalHashes)
112 :
Asm(Asm), Contents(Contents), SkipIdenticalHashes(SkipIdenticalHashes) {
116 class AppleAccelTableWriter :
public AccelTableWriter {
129 static const uint32_t MagicHash = 0x48415348;
132 :
BucketCount(BucketCount), HashCount(UniqueHashCount),
133 HeaderDataLength(DataLength) {}
152 : DieOffsetBase(
Offset), Atoms(AtomList.
begin(), AtomList.
end()) {}
162 HeaderData HeaderData;
165 void emitBuckets()
const;
166 void emitData()
const;
171 : AccelTableWriter(Asm, Contents,
true),
173 8 + (Atoms.
size() * 4)),
174 HeaderData(Atoms), SecBegin(SecBegin) {}
191 template <
typename DataT>
192 class Dwarf5AccelTableWriter :
public AccelTableWriter {
196 uint16_t Padding = 0;
203 uint32_t AugmentationStringSize =
sizeof(AugmentationString);
204 char AugmentationString[8] = {
'L',
'L',
'V',
'M',
'0',
'7',
'0',
'0'};
207 : CompUnitCount(CompUnitCount),
BucketCount(BucketCount),
208 NameCount(NameCount) {}
210 void emit(
const Dwarf5AccelTableWriter &Ctx)
const;
212 struct AttributeEncoding {
221 MCSymbol *ContributionStart =
Asm->createTempSymbol(
"names_start");
222 MCSymbol *ContributionEnd =
Asm->createTempSymbol(
"names_end");
223 MCSymbol *AbbrevStart =
Asm->createTempSymbol(
"names_abbrev_start");
224 MCSymbol *AbbrevEnd =
Asm->createTempSymbol(
"names_abbrev_end");
225 MCSymbol *EntryPool =
Asm->createTempSymbol(
"names_entries");
232 void emitCUList()
const;
233 void emitBuckets()
const;
234 void emitStringOffsets()
const;
235 void emitAbbrevs()
const;
236 void emitEntry(
const DataT &Entry)
const;
237 void emitData()
const;
240 Dwarf5AccelTableWriter(
249 void AccelTableWriter::emitHashes()
const {
251 unsigned BucketIdx = 0;
252 for (
auto &Bucket : Contents.getBuckets()) {
253 for (
auto &
Hash : Bucket) {
255 if (SkipIdenticalHashes && PrevHash == HashValue)
257 Asm->OutStreamer->AddComment(
"Hash in Bucket " +
Twine(BucketIdx));
258 Asm->emitInt32(HashValue);
259 PrevHash = HashValue;
265 void AccelTableWriter::emitOffsets(
const MCSymbol *
Base)
const {
266 const auto &
Buckets = Contents.getBuckets();
268 for (
size_t i = 0, e =
Buckets.size(); i < e; ++i) {
271 if (SkipIdenticalHashes && PrevHash == HashValue)
273 PrevHash = HashValue;
274 Asm->OutStreamer->AddComment(
"Offset in Bucket " +
Twine(i));
280 void AppleAccelTableWriter::Header::emit(
AsmPrinter *
Asm)
const {
285 Asm->
OutStreamer->AddComment(
"Header Hash Function");
287 Asm->
OutStreamer->AddComment(
"Header Bucket Count");
291 Asm->
OutStreamer->AddComment(
"Header Data Length");
295 void AppleAccelTableWriter::HeaderData::emit(
AsmPrinter *Asm)
const {
296 Asm->
OutStreamer->AddComment(
"HeaderData Die Offset Base");
298 Asm->
OutStreamer->AddComment(
"HeaderData Atom Count");
301 for (
const Atom &A : Atoms) {
309 void AppleAccelTableWriter::emitBuckets()
const {
310 const auto &
Buckets = Contents.getBuckets();
312 for (
size_t i = 0, e =
Buckets.size(); i < e; ++i) {
323 if (PrevHash != HashValue)
325 PrevHash = HashValue;
330 void AppleAccelTableWriter::emitData()
const {
331 const auto &
Buckets = Contents.getBuckets();
332 for (
size_t i = 0, e =
Buckets.size(); i < e; ++i) {
338 PrevHash !=
Hash->HashValue)
346 for (
const auto *V :
Hash->Values)
348 PrevHash =
Hash->HashValue;
356 void AppleAccelTableWriter::emit()
const {
358 HeaderData.emit(Asm);
361 emitOffsets(SecBegin);
365 template <
typename DataT>
366 void Dwarf5AccelTableWriter<DataT>::Header::emit(
367 const Dwarf5AccelTableWriter &Ctx)
const {
368 assert(CompUnitCount > 0 &&
"Index must have at least one CU.");
371 Asm->
OutStreamer->AddComment(
"Header: unit length");
374 Asm->
OutStreamer->EmitLabel(Ctx.ContributionStart);
379 Asm->
OutStreamer->AddComment(
"Header: compilation unit count");
381 Asm->
OutStreamer->AddComment(
"Header: local type unit count");
383 Asm->
OutStreamer->AddComment(
"Header: foreign type unit count");
385 Asm->
OutStreamer->AddComment(
"Header: bucket count");
387 Asm->
OutStreamer->AddComment(
"Header: name count");
389 Asm->
OutStreamer->AddComment(
"Header: abbreviation table size");
391 Asm->
OutStreamer->AddComment(
"Header: augmentation string size");
392 assert(AugmentationStringSize % 4 == 0);
394 Asm->
OutStreamer->AddComment(
"Header: augmentation string");
395 Asm->
OutStreamer->EmitBytes({AugmentationString, AugmentationStringSize});
398 template <
typename DataT>
401 for (
auto &Bucket : Contents.getBuckets()) {
402 for (
auto *
Hash : Bucket) {
404 unsigned Tag =
static_cast<const DataT *
>(
Value)->getDieTag();
412 template <
typename DataT>
414 Dwarf5AccelTableWriter<DataT>::getUniformAttributes()
const {
416 if (CompUnits.size() > 1) {
417 size_t LargestCUIndex = CompUnits.
size() - 1;
419 UA.
push_back({dwarf::DW_IDX_compile_unit, Form});
421 UA.
push_back({dwarf::DW_IDX_die_offset, dwarf::DW_FORM_ref4});
425 template <
typename DataT>
426 void Dwarf5AccelTableWriter<DataT>::emitCUList()
const {
433 template <
typename DataT>
434 void Dwarf5AccelTableWriter<DataT>::emitBuckets()
const {
436 for (
const auto &Bucket :
enumerate(Contents.getBuckets())) {
439 Index += Bucket.value().size();
443 template <
typename DataT>
444 void Dwarf5AccelTableWriter<DataT>::emitStringOffsets()
const {
445 for (
const auto &Bucket :
enumerate(Contents.getBuckets())) {
446 for (
auto *
Hash : Bucket.value()) {
455 template <
typename DataT>
456 void Dwarf5AccelTableWriter<DataT>::emitAbbrevs()
const {
458 for (
const auto &Abbrev : Abbreviations) {
460 assert(Abbrev.first != 0);
464 for (
const auto &AttrEnc : Abbrev.second) {
476 template <
typename DataT>
477 void Dwarf5AccelTableWriter<DataT>::emitEntry(
const DataT &Entry)
const {
478 auto AbbrevIt = Abbreviations.find(Entry.getDieTag());
479 assert(AbbrevIt != Abbreviations.end() &&
480 "Why wasn't this abbrev generated?");
482 Asm->
EmitULEB128(AbbrevIt->first,
"Abbreviation code");
483 for (
const auto &AttrEnc : AbbrevIt->second) {
485 switch (AttrEnc.Index) {
486 case dwarf::DW_IDX_compile_unit: {
491 case dwarf::DW_IDX_die_offset:
492 assert(AttrEnc.Form == dwarf::DW_FORM_ref4);
501 template <
typename DataT>
void Dwarf5AccelTableWriter<DataT>::emitData()
const {
503 for (
auto &Bucket : Contents.getBuckets()) {
504 for (
auto *
Hash : Bucket) {
508 emitEntry(*static_cast<const DataT *>(
Value));
509 Asm->
OutStreamer->AddComment(
"End of list: " +
Hash->Name.getString());
515 template <
typename DataT>
516 Dwarf5AccelTableWriter<DataT>::Dwarf5AccelTableWriter(
520 : AccelTableWriter(Asm, Contents,
false),
523 CompUnits(CompUnits), getCUIndexForEntry(std::move(getCUIndexForEntry)) {
527 Abbreviations.reserve(UniqueTags.
size());
529 Abbreviations.try_emplace(
Tag, UniformAttributes);
532 template <
typename DataT>
void Dwarf5AccelTableWriter<DataT>::emit()
const {
538 emitOffsets(EntryPool);
549 AppleAccelTableWriter(Asm, Contents, Atoms, SecBegin).emit();
555 std::vector<MCSymbol *> CompUnits;
557 assert(
CU.index() ==
CU.value()->getUniqueID());
560 CompUnits.push_back(MainCU->getLabelBegin());
564 Dwarf5AccelTableWriter<DWARF5AccelTableData>(
565 Asm, Contents, CompUnits,
577 getCUIndexForEntry) {
579 Dwarf5AccelTableWriter<DWARF5AccelTableStaticData>(
Asm, Contents, CUs,
585 Asm->
emitInt32(Die.getDebugSectionOffset());
589 Asm->
emitInt32(Die.getDebugSectionOffset());
615 AppleAccelTableOffsetData::Atoms = {
622 AppleAccelTableStaticOffsetData::Atoms = {
625 AppleAccelTableStaticTypeData::Atoms = {
628 Atom(5, dwarf::DW_FORM_data1),
Atom(6, dwarf::DW_FORM_data4)};
634 <<
"Version: " <<
Version <<
"\n" 635 <<
"Hash Function: " << HashFunction <<
"\n" 637 <<
"Header Data Length: " << HeaderDataLength <<
"\n";
646 OS <<
"DIE Offset Base: " << DieOffsetBase <<
"\n";
647 for (
auto Atom : Atoms)
653 HeaderData.print(OS);
655 SecBegin->print(OS,
nullptr);
659 OS <<
"Name: " <<
Name.getString() <<
"\n";
660 OS <<
" Hash Value: " <<
format(
"0x%x", HashValue) <<
"\n";
667 for (
auto *
Value : Values)
674 for (
const auto &Entry :
Entries) {
675 OS <<
"Name: " << Entry.first() <<
"\n";
676 for (
auto *V : Entry.second.Values)
680 OS <<
"Buckets and Hashes: \n";
682 for (
auto &
Hash : Bucket)
686 for (
auto &
E : Entries)
691 OS <<
" Offset: " << getDieOffset() <<
"\n";
696 OS <<
" Offset: " << getDieOffset() <<
"\n";
701 OS <<
" Offset: " << Die.getOffset() <<
"\n";
705 OS <<
" Offset: " << Die.getOffset() <<
"\n";
710 OS <<
" Static Offset: " <<
Offset <<
"\n";
714 OS <<
" Static Offset: " <<
Offset <<
"\n";
715 OS <<
" QualifiedNameHash: " <<
format(
"%x\n", QualifiedNameHash) <<
"\n";
717 OS <<
" ObjCClassIsImplementation: " 718 << (ObjCClassIsImplementation ?
"true" :
"false");
static constexpr Atom Atoms[]
void push_back(const T &Elt)
void print(raw_ostream &OS) const override
StringRef IndexString(unsigned Idx)
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Compute iterated dominance frontiers using a linear time algorithm.
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 ...
void print(raw_ostream &OS) const override
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.
StringRef getString() const
void print(raw_ostream &OS) const override
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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...
const DIE * getUnitDie() const
Climb up the parent chain to get the compile unit or type unit DIE that this DIE belongs to...
StringRef FormEncodingString(unsigned Encoding)
String pool entry reference.
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...
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
Interface which the different types of accelerator table data have to conform.
void print(raw_ostream &OS) const
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.
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
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...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void emitInt8(int Value) const
Emit a byte directive and value.
LLVM Value Representation.
void EmitULEB128(uint64_t Value, const char *Desc=nullptr) const
Emit the specified unsigned leb128 value.
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.
Marker as the end of a list of atoms.
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 ...