[llvm] r207281 - DwarfAccelTable: Store the string symbol in the accelerator table to avoid duplicate lookup.
David Blaikie
dblaikie at gmail.com
Sun Apr 27 07:47:38 PDT 2014
On Sun, Apr 27, 2014 at 5:11 AM, NAKAMURA Takumi <geek4civic at gmail.com> wrote:
> 2014-04-26 7:21 GMT+09:00 David Blaikie <dblaikie at gmail.com>:
>> Author: dblaikie
>> Date: Fri Apr 25 17:21:35 2014
>> New Revision: 207281
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=207281&view=rev
>> Log:
>> DwarfAccelTable: Store the string symbol in the accelerator table to avoid duplicate lookup.
>>
>> This also avoids the need for subtly side-effecting calls to manifest
>> strings in the string table at the point where items are added to the
>> accelerator tables.
>>
>> Modified:
>> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp
>> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.h
>> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp?rev=207281&r1=207280&r2=207281&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp Fri Apr 25 17:21:35 2014
>> @@ -29,12 +29,15 @@ DwarfAccelTable::DwarfAccelTable(ArrayRe
>> : Header(8 + (atomList.size() * 4)), HeaderData(atomList),
>> Entries(Allocator) {}
>>
>> -void DwarfAccelTable::AddName(StringRef Name, const DIE *die, char Flags) {
>> +void DwarfAccelTable::AddName(StringRef Name, MCSymbol *StrSym, const DIE *die,
>> + char Flags) {
>> assert(Data.empty() && "Already finalized!");
>> // If the string is in the list already then add this die to the list
>> // otherwise add a new one.
>> DataArray &DIEs = Entries[Name];
>> - DIEs.push_back(new (Allocator) HashDataContents(die, Flags));
>> + assert(!DIEs.StrSym || DIEs.StrSym == StrSym);
> .
> DIEs.StrSym might not be zero-initialized, at least on msvc. Fixed in r207356
Thanks for the catch - sorry about that.
- David
>
>> + DIEs.StrSym = StrSym;
>> + DIEs.Values.push_back(new (Allocator) HashDataContents(die, Flags));
>> }
>>
>> void DwarfAccelTable::ComputeBucketCount(void) {
>> @@ -70,9 +73,10 @@ void DwarfAccelTable::FinalizeTable(AsmP
>> EI != EE; ++EI) {
>>
>> // Unique the entries.
>> - std::stable_sort(EI->second.begin(), EI->second.end(), compareDIEs);
>> - EI->second.erase(std::unique(EI->second.begin(), EI->second.end()),
>> - EI->second.end());
>> + std::stable_sort(EI->second.Values.begin(), EI->second.Values.end(), compareDIEs);
>> + EI->second.Values.erase(
>> + std::unique(EI->second.Values.begin(), EI->second.Values.end()),
>> + EI->second.Values.end());
>>
>> HashData *Entry = new (Allocator) HashData(EI->getKey(), EI->second);
>> Data.push_back(Entry);
>> @@ -179,21 +183,18 @@ void DwarfAccelTable::EmitData(AsmPrinte
>> // Remember to emit the label for our offset.
>> Asm->OutStreamer.EmitLabel((*HI)->Sym);
>> Asm->OutStreamer.AddComment((*HI)->Str);
>> - Asm->EmitSectionOffset(D->getStringPool().getSymbol(*Asm, (*HI)->Str),
>> + Asm->EmitSectionOffset((*HI)->Data.StrSym,
>> D->getStringPool().getSectionSymbol());
>> Asm->OutStreamer.AddComment("Num DIEs");
>> - Asm->EmitInt32((*HI)->Data.size());
>> - for (ArrayRef<HashDataContents *>::const_iterator
>> - DI = (*HI)->Data.begin(),
>> - DE = (*HI)->Data.end();
>> - DI != DE; ++DI) {
>> + Asm->EmitInt32((*HI)->Data.Values.size());
>> + for (HashDataContents *HD : (*HI)->Data.Values) {
>> // Emit the DIE offset
>> - Asm->EmitInt32((*DI)->Die->getOffset());
>> + Asm->EmitInt32(HD->Die->getOffset());
>> // If we have multiple Atoms emit that info too.
>> // FIXME: A bit of a hack, we either emit only one atom or all info.
>> if (HeaderData.Atoms.size() > 1) {
>> - Asm->EmitInt16((*DI)->Die->getTag());
>> - Asm->EmitInt8((*DI)->Flags);
>> + Asm->EmitInt16(HD->Die->getTag());
>> + Asm->EmitInt8(HD->Flags);
>> }
>> }
>> // Emit a 0 to terminate the data unless we have a hash collision.
>> @@ -233,10 +234,8 @@ void DwarfAccelTable::print(raw_ostream
>> EE = Entries.end();
>> EI != EE; ++EI) {
>> O << "Name: " << EI->getKeyData() << "\n";
>> - for (DataArray::const_iterator DI = EI->second.begin(),
>> - DE = EI->second.end();
>> - DI != DE; ++DI)
>> - (*DI)->print(O);
>> + for (HashDataContents *HD : EI->second.Values)
>> + HD->print(O);
>> }
>>
>> O << "Buckets and Hashes: \n";
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.h?rev=207281&r1=207280&r2=207281&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.h (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.h Fri Apr 25 17:21:35 2014
>> @@ -179,12 +179,18 @@ public:
>> };
>>
>> private:
>> + // String Data
>> + struct DataArray {
>> + MCSymbol *StrSym;
>> + std::vector<HashDataContents *> Values;
>> + };
>> + friend struct HashData;
>> struct HashData {
>> StringRef Str;
>> uint32_t HashValue;
>> MCSymbol *Sym;
>> - ArrayRef<HashDataContents *> Data; // offsets
>> - HashData(StringRef S, ArrayRef<HashDataContents *> Data)
>> + DwarfAccelTable::DataArray &Data; // offsets
>> + HashData(StringRef S, DwarfAccelTable::DataArray &Data)
>> : Str(S), Data(Data) {
>> HashValue = DwarfAccelTable::HashDJB(S);
>> }
>> @@ -198,10 +204,10 @@ private:
>> else
>> O << "<none>";
>> O << "\n";
>> - for (size_t i = 0; i < Data.size(); i++) {
>> - O << " Offset: " << Data[i]->Die->getOffset() << "\n";
>> - O << " Tag: " << dwarf::TagString(Data[i]->Die->getTag()) << "\n";
>> - O << " Flags: " << Data[i]->Flags << "\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";
>> }
>> }
>> void dump() { print(dbgs()); }
>> @@ -226,8 +232,6 @@ private:
>> TableHeaderData HeaderData;
>> std::vector<HashData *> Data;
>>
>> - // String Data
>> - typedef std::vector<HashDataContents *> DataArray;
>> typedef StringMap<DataArray, BumpPtrAllocator &> StringEntries;
>> StringEntries Entries;
>>
>> @@ -240,7 +244,8 @@ private:
>> // Public Implementation
>> public:
>> DwarfAccelTable(ArrayRef<DwarfAccelTable::Atom>);
>> - void AddName(StringRef, const DIE *, char = 0);
>> + void AddName(StringRef Name, MCSymbol *StrSym, const DIE *Die,
>> + char Flags = 0);
>> void FinalizeTable(AsmPrinter *, StringRef);
>> void Emit(AsmPrinter *, MCSymbol *, DwarfFile *);
>> #ifndef NDEBUG
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=207281&r1=207280&r2=207281&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Fri Apr 25 17:21:35 2014
>> @@ -2545,27 +2545,27 @@ void DwarfDebug::attachLowHighPC(DwarfCo
>> void DwarfDebug::addAccelName(StringRef Name, const DIE &Die) {
>> if (!useDwarfAccelTables())
>> return;
>> - InfoHolder.getStringPool().getSymbol(*Asm, Name);
>> - AccelNames.AddName(Name, &Die);
>> + AccelNames.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
>> + &Die);
>> }
>>
>> void DwarfDebug::addAccelObjC(StringRef Name, const DIE &Die) {
>> if (!useDwarfAccelTables())
>> return;
>> - InfoHolder.getStringPool().getSymbol(*Asm, Name);
>> - AccelObjC.AddName(Name, &Die);
>> + AccelObjC.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
>> + &Die);
>> }
>>
>> void DwarfDebug::addAccelNamespace(StringRef Name, const DIE &Die) {
>> if (!useDwarfAccelTables())
>> return;
>> - InfoHolder.getStringPool().getSymbol(*Asm, Name);
>> - AccelNamespace.AddName(Name, &Die);
>> + AccelNamespace.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
>> + &Die);
>> }
>>
>> void DwarfDebug::addAccelType(StringRef Name, const DIE &Die, char Flags) {
>> if (!useDwarfAccelTables())
>> return;
>> - InfoHolder.getStringPool().getSymbol(*Asm, Name);
>> - AccelTypes.AddName(Name, &Die, Flags);
>> + AccelTypes.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
>> + &Die);
>> }
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list