diff options
Diffstat (limited to 'lib/CodeGen/AsmPrinter/DwarfAccelTable.h')
-rw-r--r-- | lib/CodeGen/AsmPrinter/DwarfAccelTable.h | 130 |
1 files changed, 68 insertions, 62 deletions
diff --git a/lib/CodeGen/AsmPrinter/DwarfAccelTable.h b/lib/CodeGen/AsmPrinter/DwarfAccelTable.h index b1ef8cfe989d..f56199dc8e72 100644 --- a/lib/CodeGen/AsmPrinter/DwarfAccelTable.h +++ b/lib/CodeGen/AsmPrinter/DwarfAccelTable.h @@ -1,4 +1,4 @@ -//==-- llvm/CodeGen/DwarfAccelTable.h - Dwarf Accelerator Tables -*- C++ -*-==// +//==- llvm/CodeGen/DwarfAccelTable.h - Dwarf Accelerator Tables --*- C++ -*-==// // // The LLVM Compiler Infrastructure // @@ -15,16 +15,19 @@ #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFACCELTABLE_H #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/CodeGen/DIE.h" +#include "llvm/CodeGen/DwarfStringPoolEntry.h" #include "llvm/MC/MCSymbol.h" -#include "llvm/Support/Compiler.h" -#include "llvm/Support/DataTypes.h" +#include "llvm/Support/Allocator.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" -#include "llvm/Support/FormattedStream.h" +#include "llvm/Support/raw_ostream.h" +#include <cstddef> +#include <cstdint> #include <vector> // The dwarf accelerator tables are an indirect hash table optimized @@ -65,44 +68,35 @@ class AsmPrinter; class DwarfDebug; class DwarfAccelTable { - - static uint32_t HashDJB(StringRef Str) { - uint32_t h = 5381; - for (unsigned i = 0, e = Str.size(); i != e; ++i) - h = ((h << 5) + h) + Str[i]; - return h; - } - // Helper function to compute the number of buckets needed based on // the number of unique hashes. - void ComputeBucketCount(void); + void ComputeBucketCount(); struct TableHeader { - uint32_t magic; // 'HASH' magic value to allow endian detection - uint16_t version; // Version number. - uint16_t hash_function; // The hash function enumeration that was used. - uint32_t bucket_count; // The number of buckets in this hash table. - uint32_t hashes_count; // The total number of unique hash values - // and hash data offsets in this table. - uint32_t header_data_len; // The bytes to skip to get to the hash - // indexes (buckets) for correct alignment. + uint32_t magic = MagicHash; // 'HASH' magic value to allow endian detection + uint16_t version = 1; // Version number. + uint16_t hash_function = dwarf::DW_hash_function_djb; + // The hash function enumeration that was used. + uint32_t bucket_count = 0; // The number of buckets in this hash table. + uint32_t hashes_count = 0; // The total number of unique hash values + // and hash data offsets in this table. + uint32_t header_data_len; // The bytes to skip to get to the hash + // indexes (buckets) for correct alignment. // Also written to disk is the implementation specific header data. static const uint32_t MagicHash = 0x48415348; - TableHeader(uint32_t data_len) - : magic(MagicHash), version(1), - hash_function(dwarf::DW_hash_function_djb), bucket_count(0), - hashes_count(0), header_data_len(data_len) {} + TableHeader(uint32_t data_len) : header_data_len(data_len) {} #ifndef NDEBUG - void print(raw_ostream &O) { - O << "Magic: " << format("0x%x", magic) << "\n" - << "Version: " << version << "\n" - << "Hash Function: " << hash_function << "\n" - << "Bucket Count: " << bucket_count << "\n" - << "Header Data Length: " << header_data_len << "\n"; + void print(raw_ostream &OS) { + OS << "Magic: " << format("0x%x", magic) << "\n" + << "Version: " << version << "\n" + << "Hash Function: " << hash_function << "\n" + << "Bucket Count: " << bucket_count << "\n" + << "Header Data Length: " << header_data_len << "\n"; } + void dump() { print(dbgs()); } #endif }; @@ -127,11 +121,13 @@ public: uint16_t form; // DWARF DW_FORM_ defines constexpr Atom(uint16_t type, uint16_t form) : type(type), form(form) {} + #ifndef NDEBUG - void print(raw_ostream &O) { - O << "Type: " << dwarf::AtomTypeString(type) << "\n" - << "Form: " << dwarf::FormEncodingString(form) << "\n"; + void print(raw_ostream &OS) { + OS << "Type: " << dwarf::AtomTypeString(type) << "\n" + << "Form: " << dwarf::FormEncodingString(form) << "\n"; } + void dump() { print(dbgs()); } #endif }; @@ -145,11 +141,12 @@ private: : die_offset_base(offset), Atoms(AtomList.begin(), AtomList.end()) {} #ifndef NDEBUG - void print(raw_ostream &O) { - O << "die_offset_base: " << die_offset_base << "\n"; + void print(raw_ostream &OS) { + OS << "die_offset_base: " << die_offset_base << "\n"; for (size_t i = 0; i < Atoms.size(); i++) - Atoms[i].print(O); + Atoms[i].print(OS); } + void dump() { print(dbgs()); } #endif }; @@ -168,11 +165,12 @@ public: char Flags; // Specific flags to output HashDataContents(const DIE *D, char Flags) : Die(D), Flags(Flags) {} + #ifndef NDEBUG - void print(raw_ostream &O) const { - O << " Offset: " << Die->getOffset() << "\n"; - O << " Tag: " << dwarf::TagString(Die->getTag()) << "\n"; - O << " Flags: " << Flags << "\n"; + void print(raw_ostream &OS) const { + OS << " Offset: " << Die->getOffset() << "\n" + << " Tag: " << dwarf::TagString(Die->getTag()) << "\n" + << " Flags: " << Flags << "\n"; } #endif }; @@ -183,39 +181,41 @@ private: DwarfStringPoolEntryRef Name; std::vector<HashDataContents *> Values; }; + friend struct HashData; + struct HashData { StringRef Str; uint32_t HashValue; MCSymbol *Sym; DwarfAccelTable::DataArray &Data; // offsets + HashData(StringRef S, DwarfAccelTable::DataArray &Data) : Str(S), Data(Data) { - HashValue = DwarfAccelTable::HashDJB(S); + HashValue = dwarf::djbHash(S); } + #ifndef NDEBUG - void print(raw_ostream &O) { - O << "Name: " << Str << "\n"; - O << " Hash Value: " << format("0x%x", HashValue) << "\n"; - O << " Symbol: "; + void print(raw_ostream &OS) { + OS << "Name: " << Str << "\n"; + OS << " Hash Value: " << format("0x%x", HashValue) << "\n"; + OS << " Symbol: "; if (Sym) - O << *Sym; + OS << *Sym; else - O << "<none>"; - O << "\n"; + OS << "<none>"; + OS << "\n"; for (HashDataContents *C : Data.Values) { - O << " Offset: " << C->Die->getOffset() << "\n"; - O << " Tag: " << dwarf::TagString(C->Die->getTag()) << "\n"; - O << " Flags: " << C->Flags << "\n"; + OS << " Offset: " << C->Die->getOffset() << "\n"; + OS << " Tag: " << dwarf::TagString(C->Die->getTag()) << "\n"; + OS << " Flags: " << C->Flags << "\n"; } } + void dump() { print(dbgs()); } #endif }; - DwarfAccelTable(const DwarfAccelTable &) = delete; - void operator=(const DwarfAccelTable &) = delete; - // Internal Functions void EmitHeader(AsmPrinter *); void EmitBuckets(AsmPrinter *); @@ -231,25 +231,31 @@ private: TableHeaderData HeaderData; std::vector<HashData *> Data; - typedef StringMap<DataArray, BumpPtrAllocator &> StringEntries; + using StringEntries = StringMap<DataArray, BumpPtrAllocator &>; + StringEntries Entries; // Buckets/Hashes/Offsets - typedef std::vector<HashData *> HashList; - typedef std::vector<HashList> BucketList; + using HashList = std::vector<HashData *>; + using BucketList = std::vector<HashList>; BucketList Buckets; HashList Hashes; // Public Implementation public: DwarfAccelTable(ArrayRef<DwarfAccelTable::Atom>); + DwarfAccelTable(const DwarfAccelTable &) = delete; + DwarfAccelTable &operator=(const DwarfAccelTable &) = delete; + void AddName(DwarfStringPoolEntryRef Name, const DIE *Die, char Flags = 0); void FinalizeTable(AsmPrinter *, StringRef); void emit(AsmPrinter *, const MCSymbol *, DwarfDebug *); #ifndef NDEBUG - void print(raw_ostream &O); + void print(raw_ostream &OS); void dump() { print(dbgs()); } #endif }; -} -#endif + +} // end namespace llvm + +#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFACCELTABLE_H |