Remove the unused string section symbol parameter from DwarfFile::emitStrings

And since it /looked/ like the DwarfStrSectionSym was unused, I tried
removing it - but then it turned out that DwarfStringPool was
reconstructing the same label (and expecting it to have already been
emitted) and uses that.

So I kept it around, but wanted to pass it in to users - since it seemed
a bit silly for DwarfStringPool to have it passed in and returned but
itself have no use for it. The only two users don't handle strings in
both .dwo and .o files so they only ever need the one symbol - no need
to keep it (and have an unused symbol) in the DwarfStringPool used for
fission/.dwo.

Refactor a bunch of accelerator table usage to remove duplication so I
didn't have to touch 4-5 callers.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217628 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie 2014-09-11 21:12:48 +00:00
parent 330c819d83
commit 85d436d90a
9 changed files with 43 additions and 61 deletions

View File

@ -174,7 +174,8 @@ void DwarfAccelTable::EmitOffsets(AsmPrinter *Asm, MCSymbol *SecBegin) {
// Walk through the buckets and emit the full data for each element in // Walk through the buckets and emit the full data for each element in
// the bucket. For the string case emit the dies and the various offsets. // the bucket. For the string case emit the dies and the various offsets.
// Terminate each HashData bucket with 0. // Terminate each HashData bucket with 0.
void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfFile *D) { void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfFile *D,
MCSymbol *StrSym) {
uint64_t PrevHash = UINT64_MAX; uint64_t PrevHash = UINT64_MAX;
for (size_t i = 0, e = Buckets.size(); i < e; ++i) { for (size_t i = 0, e = Buckets.size(); i < e; ++i) {
for (HashList::const_iterator HI = Buckets[i].begin(), for (HashList::const_iterator HI = Buckets[i].begin(),
@ -183,8 +184,7 @@ void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfFile *D) {
// Remember to emit the label for our offset. // Remember to emit the label for our offset.
Asm->OutStreamer.EmitLabel((*HI)->Sym); Asm->OutStreamer.EmitLabel((*HI)->Sym);
Asm->OutStreamer.AddComment((*HI)->Str); Asm->OutStreamer.AddComment((*HI)->Str);
Asm->EmitSectionOffset((*HI)->Data.StrSym, Asm->EmitSectionOffset((*HI)->Data.StrSym, StrSym);
D->getStringPool().getSectionSymbol());
Asm->OutStreamer.AddComment("Num DIEs"); Asm->OutStreamer.AddComment("Num DIEs");
Asm->EmitInt32((*HI)->Data.Values.size()); Asm->EmitInt32((*HI)->Data.Values.size());
for (HashDataContents *HD : (*HI)->Data.Values) { for (HashDataContents *HD : (*HI)->Data.Values) {
@ -206,7 +206,8 @@ void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfFile *D) {
} }
// Emit the entire data structure to the output file. // Emit the entire data structure to the output file.
void DwarfAccelTable::Emit(AsmPrinter *Asm, MCSymbol *SecBegin, DwarfFile *D) { void DwarfAccelTable::Emit(AsmPrinter *Asm, MCSymbol *SecBegin, DwarfFile *D,
MCSymbol *StrSym) {
// Emit the header. // Emit the header.
EmitHeader(Asm); EmitHeader(Asm);
@ -220,7 +221,7 @@ void DwarfAccelTable::Emit(AsmPrinter *Asm, MCSymbol *SecBegin, DwarfFile *D) {
EmitOffsets(Asm, SecBegin); EmitOffsets(Asm, SecBegin);
// Emit the hash data. // Emit the hash data.
EmitData(Asm, D); EmitData(Asm, D, StrSym);
} }
#ifndef NDEBUG #ifndef NDEBUG

View File

@ -223,7 +223,7 @@ private:
void EmitBuckets(AsmPrinter *); void EmitBuckets(AsmPrinter *);
void EmitHashes(AsmPrinter *); void EmitHashes(AsmPrinter *);
void EmitOffsets(AsmPrinter *, MCSymbol *); void EmitOffsets(AsmPrinter *, MCSymbol *);
void EmitData(AsmPrinter *, DwarfFile *D); void EmitData(AsmPrinter *, DwarfFile *D, MCSymbol *StrSym);
// Allocator for HashData and HashDataContents. // Allocator for HashData and HashDataContents.
BumpPtrAllocator Allocator; BumpPtrAllocator Allocator;
@ -248,7 +248,7 @@ public:
void AddName(StringRef Name, MCSymbol *StrSym, const DIE *Die, void AddName(StringRef Name, MCSymbol *StrSym, const DIE *Die,
char Flags = 0); char Flags = 0);
void FinalizeTable(AsmPrinter *, StringRef); void FinalizeTable(AsmPrinter *, StringRef);
void Emit(AsmPrinter *, MCSymbol *, DwarfFile *); void Emit(AsmPrinter *, MCSymbol *, DwarfFile *, MCSymbol *StrSym);
#ifndef NDEBUG #ifndef NDEBUG
void print(raw_ostream &O); void print(raw_ostream &O);
void dump() { print(dbgs()); } void dump() { print(dbgs()); }

View File

@ -1880,54 +1880,41 @@ void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) {
Asm->EmitInt8(1); Asm->EmitInt8(1);
} }
// Emit visible names into a hashed accelerator table section. void DwarfDebug::emitAccel(DwarfAccelTable &Accel, const MCSection *Section,
void DwarfDebug::emitAccelNames() { StringRef TableName, StringRef SymName) {
AccelNames.FinalizeTable(Asm, "Names"); Accel.FinalizeTable(Asm, TableName);
Asm->OutStreamer.SwitchSection( Asm->OutStreamer.SwitchSection(Section);
Asm->getObjFileLowering().getDwarfAccelNamesSection()); auto *SectionBegin = Asm->GetTempSymbol(SymName);
MCSymbol *SectionBegin = Asm->GetTempSymbol("names_begin");
Asm->OutStreamer.EmitLabel(SectionBegin); Asm->OutStreamer.EmitLabel(SectionBegin);
// Emit the full data. // Emit the full data.
AccelNames.Emit(Asm, SectionBegin, &InfoHolder); Accel.Emit(Asm, SectionBegin, &InfoHolder, DwarfStrSectionSym);
}
// Emit visible names into a hashed accelerator table section.
void DwarfDebug::emitAccelNames() {
emitAccel(AccelNames, Asm->getObjFileLowering().getDwarfAccelNamesSection(),
"Names", "names_begin");
} }
// Emit objective C classes and categories into a hashed accelerator table // Emit objective C classes and categories into a hashed accelerator table
// section. // section.
void DwarfDebug::emitAccelObjC() { void DwarfDebug::emitAccelObjC() {
AccelObjC.FinalizeTable(Asm, "ObjC"); emitAccel(AccelObjC, Asm->getObjFileLowering().getDwarfAccelObjCSection(),
Asm->OutStreamer.SwitchSection( "ObjC", "objc_begin");
Asm->getObjFileLowering().getDwarfAccelObjCSection());
MCSymbol *SectionBegin = Asm->GetTempSymbol("objc_begin");
Asm->OutStreamer.EmitLabel(SectionBegin);
// Emit the full data.
AccelObjC.Emit(Asm, SectionBegin, &InfoHolder);
} }
// Emit namespace dies into a hashed accelerator table. // Emit namespace dies into a hashed accelerator table.
void DwarfDebug::emitAccelNamespaces() { void DwarfDebug::emitAccelNamespaces() {
AccelNamespace.FinalizeTable(Asm, "namespac"); emitAccel(AccelNamespace,
Asm->OutStreamer.SwitchSection( Asm->getObjFileLowering().getDwarfAccelNamespaceSection(),
Asm->getObjFileLowering().getDwarfAccelNamespaceSection()); "namespac", "namespac_begin");
MCSymbol *SectionBegin = Asm->GetTempSymbol("namespac_begin");
Asm->OutStreamer.EmitLabel(SectionBegin);
// Emit the full data.
AccelNamespace.Emit(Asm, SectionBegin, &InfoHolder);
} }
// Emit type dies into a hashed accelerator table. // Emit type dies into a hashed accelerator table.
void DwarfDebug::emitAccelTypes() { void DwarfDebug::emitAccelTypes() {
emitAccel(AccelTypes, Asm->getObjFileLowering().getDwarfAccelTypesSection(),
AccelTypes.FinalizeTable(Asm, "types"); "types", "types_begin");
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfAccelTypesSection());
MCSymbol *SectionBegin = Asm->GetTempSymbol("types_begin");
Asm->OutStreamer.EmitLabel(SectionBegin);
// Emit the full data.
AccelTypes.Emit(Asm, SectionBegin, &InfoHolder);
} }
// Public name handling. // Public name handling.
@ -2524,9 +2511,8 @@ void DwarfDebug::emitDebugStrDWO() {
assert(useSplitDwarf() && "No split dwarf?"); assert(useSplitDwarf() && "No split dwarf?");
const MCSection *OffSec = const MCSection *OffSec =
Asm->getObjFileLowering().getDwarfStrOffDWOSection(); Asm->getObjFileLowering().getDwarfStrOffDWOSection();
const MCSymbol *StrSym = DwarfStrSectionSym;
InfoHolder.emitStrings(Asm->getObjFileLowering().getDwarfStrDWOSection(), InfoHolder.emitStrings(Asm->getObjFileLowering().getDwarfStrDWOSection(),
OffSec, StrSym); OffSec);
} }
MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) { MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) {

View File

@ -422,6 +422,10 @@ class DwarfDebug : public AsmPrinterHandler {
/// the line matrix. /// the line matrix.
void emitEndOfLineMatrix(unsigned SectionEnd); void emitEndOfLineMatrix(unsigned SectionEnd);
/// \brief Emit a specified accelerator table.
void emitAccel(DwarfAccelTable &Accel, const MCSection *Section,
StringRef TableName, StringRef SymName);
/// \brief Emit visible names into a hashed accelerator table section. /// \brief Emit visible names into a hashed accelerator table section.
void emitAccelNames(); void emitAccelNames();
@ -627,6 +631,9 @@ public:
/// Returns the section symbol for the .debug_loc section. /// Returns the section symbol for the .debug_loc section.
MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; } MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
/// Returns the section symbol for the .debug_str section.
MCSymbol *getDebugStrSym() const { return DwarfStrSectionSym; }
/// Returns the previous CU that was being updated /// Returns the previous CU that was being updated
const DwarfCompileUnit *getPrevCU() const { return PrevCU; } const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; } void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }

View File

@ -149,8 +149,7 @@ void DwarfFile::emitAbbrevs(const MCSection *Section) {
// Emit strings into a string section. // Emit strings into a string section.
void DwarfFile::emitStrings(const MCSection *StrSection, void DwarfFile::emitStrings(const MCSection *StrSection,
const MCSection *OffsetSection, const MCSection *OffsetSection) {
const MCSymbol *StrSecSym) { StrPool.emit(*Asm, StrSection, OffsetSection);
StrPool.emit(*Asm, StrSection, OffsetSection, StrSecSym);
} }
} }

View File

@ -74,8 +74,7 @@ public:
/// \brief Emit all of the strings to the section given. /// \brief Emit all of the strings to the section given.
void emitStrings(const MCSection *StrSection, void emitStrings(const MCSection *StrSection,
const MCSection *OffsetSection = nullptr, const MCSection *OffsetSection = nullptr);
const MCSymbol *StrSecSym = nullptr);
/// \brief Returns the string pool. /// \brief Returns the string pool.
DwarfStringPool &getStringPool() { return StrPool; } DwarfStringPool &getStringPool() { return StrPool; }

View File

@ -12,8 +12,6 @@
using namespace llvm; using namespace llvm;
MCSymbol *DwarfStringPool::getSectionSymbol() { return SectionSymbol; }
static std::pair<MCSymbol *, unsigned> & static std::pair<MCSymbol *, unsigned> &
getEntry(AsmPrinter &Asm, getEntry(AsmPrinter &Asm,
StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> &Pool, StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> &Pool,
@ -36,8 +34,7 @@ unsigned DwarfStringPool::getIndex(AsmPrinter &Asm, StringRef Str) {
} }
void DwarfStringPool::emit(AsmPrinter &Asm, const MCSection *StrSection, void DwarfStringPool::emit(AsmPrinter &Asm, const MCSection *StrSection,
const MCSection *OffsetSection, const MCSection *OffsetSection) {
const MCSymbol *StrSecSym) {
if (Pool.empty()) if (Pool.empty())
return; return;

View File

@ -28,18 +28,13 @@ class StringRef;
class DwarfStringPool { class DwarfStringPool {
StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> Pool; StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> Pool;
StringRef Prefix; StringRef Prefix;
MCSymbol *SectionSymbol;
public: public:
DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix) DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix)
: Pool(A), Prefix(Prefix), SectionSymbol(Asm.GetTempSymbol(Prefix)) {} : Pool(A), Prefix(Prefix) {}
void emit(AsmPrinter &Asm, const MCSection *StrSection, void emit(AsmPrinter &Asm, const MCSection *StrSection,
const MCSection *OffsetSection = nullptr, const MCSection *OffsetSection = nullptr);
const MCSymbol *StrSecSym = nullptr);
/// \brief Returns the entry into the start of the pool.
MCSymbol *getSectionSymbol();
/// \brief Returns an entry into the string pool with the given /// \brief Returns an entry into the string pool with the given
/// string text. /// string text.

View File

@ -225,10 +225,8 @@ void DwarfUnit::addLocalString(DIE &Die, dwarf::Attribute Attribute,
DIEValue *Value; DIEValue *Value;
if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
Value = new (DIEValueAllocator) DIELabel(Symb); Value = new (DIEValueAllocator) DIELabel(Symb);
else { else
MCSymbol *StringPool = DU->getStringPool().getSectionSymbol(); Value = new (DIEValueAllocator) DIEDelta(Symb, DD->getDebugStrSym());
Value = new (DIEValueAllocator) DIEDelta(Symb, StringPool);
}
DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String); DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String);
Die.addValue(Attribute, dwarf::DW_FORM_strp, Str); Die.addValue(Attribute, dwarf::DW_FORM_strp, Str);
} }