From 2e5d870b384f7cc20ba040e827d54fa473f60800 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Thu, 20 Dec 2012 21:58:36 +0000 Subject: [PATCH] Start splitting out the debug string section handling by moving it into the DwarfUnits class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170770 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp | 6 +-- lib/CodeGen/AsmPrinter/DwarfAccelTable.h | 6 +-- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 9 +++-- lib/CodeGen/AsmPrinter/DwarfCompileUnit.h | 6 ++- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 41 ++++++++++++--------- lib/CodeGen/AsmPrinter/DwarfDebug.h | 35 ++++++++++++------ 6 files changed, 63 insertions(+), 40 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp b/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp index 6a172b981dc..3f87bd23d56 100644 --- a/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp @@ -181,7 +181,7 @@ void DwarfAccelTable::EmitOffsets(AsmPrinter *Asm, MCSymbol *SecBegin) { // 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. // Terminate each HashData bucket with 0. -void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfDebug *D) { +void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfUnits *D) { uint64_t PrevHash = UINT64_MAX; for (size_t i = 0, e = Buckets.size(); i < e; ++i) { for (HashList::const_iterator HI = Buckets[i].begin(), @@ -190,7 +190,7 @@ void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfDebug *D) { Asm->OutStreamer.EmitLabel((*HI)->Sym); Asm->OutStreamer.AddComment((*HI)->Str); Asm->EmitSectionOffset(D->getStringPoolEntry((*HI)->Str), - D->getStringPool()); + D->getStringPoolSym()); Asm->OutStreamer.AddComment("Num DIEs"); Asm->EmitInt32((*HI)->Data.size()); for (ArrayRef::const_iterator @@ -215,7 +215,7 @@ void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfDebug *D) { // Emit the entire data structure to the output file. void DwarfAccelTable::Emit(AsmPrinter *Asm, MCSymbol *SecBegin, - DwarfDebug *D) { + DwarfUnits *D) { // Emit the header. EmitHeader(Asm); diff --git a/lib/CodeGen/AsmPrinter/DwarfAccelTable.h b/lib/CodeGen/AsmPrinter/DwarfAccelTable.h index daca0cb5dd8..7304f8537fe 100644 --- a/lib/CodeGen/AsmPrinter/DwarfAccelTable.h +++ b/lib/CodeGen/AsmPrinter/DwarfAccelTable.h @@ -63,7 +63,7 @@ namespace llvm { class AsmPrinter; class DIE; -class DwarfDebug; +class DwarfUnits; class DwarfAccelTable { @@ -245,7 +245,7 @@ private: void EmitBuckets(AsmPrinter *); void EmitHashes(AsmPrinter *); void EmitOffsets(AsmPrinter *, MCSymbol *); - void EmitData(AsmPrinter *, DwarfDebug *D); + void EmitData(AsmPrinter *, DwarfUnits *D); // Allocator for HashData and HashDataContents. BumpPtrAllocator Allocator; @@ -272,7 +272,7 @@ private: ~DwarfAccelTable(); void AddName(StringRef, DIE*, char = 0); void FinalizeTable(AsmPrinter *, const char *); - void Emit(AsmPrinter *, MCSymbol *, DwarfDebug *); + void Emit(AsmPrinter *, MCSymbol *, DwarfUnits *); #ifndef NDEBUG void print(raw_ostream &O); void dump() { print(dbgs()); } diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index 83dfa54da59..c7aefc35c45 100644 --- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -33,8 +33,9 @@ using namespace llvm; /// CompileUnit - Compile unit constructor. CompileUnit::CompileUnit(unsigned UID, unsigned L, DIE *D, AsmPrinter *A, - DwarfDebug *DW) - : UniqueID(UID), Language(L), CUDie(D), Asm(A), DD(DW), IndexTyDie(0) { + DwarfDebug *DW, DwarfUnits *DWU) + : UniqueID(UID), Language(L), CUDie(D), Asm(A), DD(DW), DU(DWU), + IndexTyDie(0) { DIEIntegerOne = new (DIEValueAllocator) DIEInteger(1); } @@ -127,12 +128,12 @@ void CompileUnit::addSInt(DIE *Die, unsigned Attribute, /// reference to the string pool instead of immediate strings so that DIEs have /// more predictable sizes. void CompileUnit::addString(DIE *Die, unsigned Attribute, StringRef String) { - MCSymbol *Symb = DD->getStringPoolEntry(String); + MCSymbol *Symb = DU->getStringPoolEntry(String); DIEValue *Value; if (Asm->needsRelocationsForDwarfStringPool()) Value = new (DIEValueAllocator) DIELabel(Symb); else { - MCSymbol *StringPool = DD->getStringPool(); + MCSymbol *StringPool = DU->getStringPoolSym(); Value = new (DIEValueAllocator) DIEDelta(Symb, StringPool); } Die->addValue(Attribute, dwarf::DW_FORM_strp, Value); diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h index bd63ff5f9b1..2a61efb13eb 100644 --- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h +++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h @@ -23,6 +23,7 @@ namespace llvm { class DwarfDebug; +class DwarfUnits; class MachineLocation; class MachineOperand; class ConstantInt; @@ -47,7 +48,9 @@ class CompileUnit { /// Asm - Target of Dwarf emission. AsmPrinter *Asm; + // Holders for some common dwarf information. DwarfDebug *DD; + DwarfUnits *DU; /// IndexTyDie - An anonymous type for index type. Owned by CUDie. DIE *IndexTyDie; @@ -84,7 +87,8 @@ class CompileUnit { int64_t getDefaultLowerBound() const; public: - CompileUnit(unsigned UID, unsigned L, DIE *D, AsmPrinter *A, DwarfDebug *DW); + CompileUnit(unsigned UID, unsigned L, DIE *D, AsmPrinter *A, DwarfDebug *DW, + DwarfUnits *); ~CompileUnit(); // Accessors. diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index f05802070e5..2a9c2ff2328 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -155,13 +155,12 @@ DIType DbgVariable::getType() const { DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M) : Asm(A), MMI(Asm->MMI), FirstCU(0), AbbreviationsSet(InitAbbreviationsSetSize), - SourceIdMap(DIEValueAllocator), StringPool(DIEValueAllocator), + SourceIdMap(DIEValueAllocator), InfoStringPool(DIEValueAllocator), PrevLabel(NULL), GlobalCUIndexCount(0), - InfoHolder(A, &AbbreviationsSet, &Abbreviations), + InfoHolder(A, &AbbreviationsSet, &Abbreviations, &InfoStringPool), SkeletonCU(0), SkeletonAbbrevSet(InitAbbreviationsSetSize), - SkeletonHolder(A, &SkeletonAbbrevSet, &SkeletonAbbrevs) { - NextStringPoolNumber = 0; + SkeletonHolder(A, &SkeletonAbbrevSet, &SkeletonAbbrevs, &InfoStringPool) { DwarfInfoSectionSym = DwarfAbbrevSectionSym = 0; DwarfStrSectionSym = TextSectionSym = 0; @@ -213,12 +212,13 @@ static MCSymbol *emitSectionSym(AsmPrinter *Asm, const MCSection *Section, return TmpSym; } -MCSymbol *DwarfDebug::getStringPool() { +MCSymbol *DwarfUnits::getStringPoolSym() { return Asm->GetTempSymbol("section_str"); } -MCSymbol *DwarfDebug::getStringPoolEntry(StringRef Str) { - std::pair &Entry = StringPool[Str]; +MCSymbol *DwarfUnits::getStringPoolEntry(StringRef Str) { + std::pair &Entry = + StringPool->GetOrCreateValue(Str).getValue(); if (Entry.first) return Entry.first; Entry.second = NextStringPoolNumber++; @@ -626,7 +626,8 @@ CompileUnit *DwarfDebug::constructCompileUnit(const MDNode *N) { DIE *Die = new DIE(dwarf::DW_TAG_compile_unit); CompileUnit *NewCU = new CompileUnit(GlobalCUIndexCount++, - DIUnit.getLanguage(), Die, Asm, this); + DIUnit.getLanguage(), Die, Asm, + this, &InfoHolder); NewCU->addString(Die, dwarf::DW_AT_producer, DIUnit.getProducer()); NewCU->addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2, DIUnit.getLanguage()); @@ -1958,7 +1959,7 @@ void DwarfDebug::emitAccelNames() { Asm->OutStreamer.EmitLabel(SectionBegin); // Emit the full data. - AT.Emit(Asm, SectionBegin, this); + AT.Emit(Asm, SectionBegin, &InfoHolder); } // Emit objective C classes and categories into a hashed accelerator table section. @@ -1986,7 +1987,7 @@ void DwarfDebug::emitAccelObjC() { Asm->OutStreamer.EmitLabel(SectionBegin); // Emit the full data. - AT.Emit(Asm, SectionBegin, this); + AT.Emit(Asm, SectionBegin, &InfoHolder); } // Emit namespace dies into a hashed accelerator table. @@ -2014,7 +2015,7 @@ void DwarfDebug::emitAccelNamespaces() { Asm->OutStreamer.EmitLabel(SectionBegin); // Emit the full data. - AT.Emit(Asm, SectionBegin, this); + AT.Emit(Asm, SectionBegin, &InfoHolder); } // Emit type dies into a hashed accelerator table. @@ -2049,7 +2050,7 @@ void DwarfDebug::emitAccelTypes() { Asm->OutStreamer.EmitLabel(SectionBegin); // Emit the full data. - AT.Emit(Asm, SectionBegin, this); + AT.Emit(Asm, SectionBegin, &InfoHolder); } void DwarfDebug::emitDebugPubTypes() { @@ -2107,7 +2108,7 @@ void DwarfDebug::emitDebugPubTypes() { // Emit visible names into a debug str section. void DwarfDebug::emitDebugStr() { // Check to see if it is worth the effort. - if (StringPool.empty()) return; + if (InfoHolder.getStringPool()->empty()) return; // Start the dwarf str section. Asm->OutStreamer.SwitchSection( @@ -2119,7 +2120,7 @@ void DwarfDebug::emitDebugStr() { StringMapEntry >*>, 64> Entries; for (StringMap >::iterator - I = StringPool.begin(), E = StringPool.end(); I != E; ++I) + I = InfoHolder.getStringPool()->begin(), E = InfoHolder.getStringPool()->end(); I != E; ++I) Entries.push_back(std::make_pair(I->second.second, &*I)); array_pod_sort(Entries.begin(), Entries.end()); @@ -2318,13 +2319,16 @@ void DwarfDebug::emitDebugInlineInfo() { Asm->OutStreamer.AddComment("MIPS linkage name"); if (LName.empty()) - Asm->EmitSectionOffset(getStringPoolEntry(Name), DwarfStrSectionSym); + Asm->EmitSectionOffset(InfoHolder.getStringPoolEntry(Name), + DwarfStrSectionSym); else - Asm->EmitSectionOffset(getStringPoolEntry(getRealLinkageName(LName)), + Asm->EmitSectionOffset(InfoHolder + .getStringPoolEntry(getRealLinkageName(LName)), DwarfStrSectionSym); Asm->OutStreamer.AddComment("Function name"); - Asm->EmitSectionOffset(getStringPoolEntry(Name), DwarfStrSectionSym); + Asm->EmitSectionOffset(InfoHolder.getStringPoolEntry(Name), + DwarfStrSectionSym); Asm->EmitULEB128(Labels.size(), "Inline count"); for (SmallVector::iterator LI = Labels.begin(), @@ -2354,7 +2358,8 @@ CompileUnit *DwarfDebug::constructSkeletonCU(const MDNode *N) { DIE *Die = new DIE(dwarf::DW_TAG_compile_unit); CompileUnit *NewCU = new CompileUnit(GlobalCUIndexCount++, - DIUnit.getLanguage(), Die, Asm, this); + DIUnit.getLanguage(), Die, Asm, + this, &InfoHolder); // FIXME: This should be the .dwo file. NewCU->addString(Die, dwarf::DW_AT_GNU_dwo_name, FN); diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index 58ae3d68d14..71e78c22117 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -189,6 +189,12 @@ public: DIType getType() const; }; + +// A String->Symbol mapping of strings used by indirect +// references. +typedef StringMap, + BumpPtrAllocator&> StrPool; + /// \brief Collects and handles information specific to a particular /// collection of units. class DwarfUnits { @@ -204,10 +210,15 @@ class DwarfUnits { // A pointer to all units in the section. SmallVector CUs; + // Collection of strings for this unit. + StrPool *StringPool; + unsigned NextStringPoolNumber; + public: DwarfUnits(AsmPrinter *AP, FoldingSet *AS, - std::vector *A) : - Asm(AP), AbbreviationsSet(AS), Abbreviations(A) {} + std::vector *A, StrPool *SP) : + Asm(AP), AbbreviationsSet(AS), Abbreviations(A), + StringPool(SP), NextStringPoolNumber(0) {} /// \brief Compute the size and offset of a DIE given an incoming Offset. unsigned computeSizeAndOffset(DIE *Die, unsigned Offset); @@ -225,6 +236,16 @@ public: /// abbreviation section. void emitUnits(DwarfDebug *, const MCSection *, const MCSection *, const MCSymbol *); + + /// \brief Returns the entry into the start of the pool. + MCSymbol *getStringPoolSym(); + + /// \brief Returns an entry into the string pool with the given + /// string text. + MCSymbol *getStringPoolEntry(StringRef Str); + + /// \brief Returns the string pool. + StrPool *getStringPool() { return StringPool; } }; /// \brief Collects and handles dwarf debug information. @@ -262,8 +283,7 @@ class DwarfDebug { // A String->Symbol mapping of strings used by indirect // references. - StringMap, BumpPtrAllocator&> StringPool; - unsigned NextStringPoolNumber; + StrPool InfoStringPool; // Provides a unique id per text section. SetVector SectionMap; @@ -579,13 +599,6 @@ public: /// SourceIds map. unsigned getOrCreateSourceID(StringRef DirName, StringRef FullName); - /// \brief Returns the entry into the start of the pool. - MCSymbol *getStringPool(); - - /// \brief Returns an entry into the string pool with the given - /// string text. - MCSymbol *getStringPoolEntry(StringRef Str); - /// \brief Recursively Emits a debug information entry. void emitDIE(DIE *Die, std::vector *Abbrevs); -- 2.34.1