[llvm] r207277 - Encapsulate the DWARF string pool in a separate type.
David Blaikie
dblaikie at gmail.com
Fri Apr 25 14:34:35 PDT 2014
Author: dblaikie
Date: Fri Apr 25 16:34:35 2014
New Revision: 207277
URL: http://llvm.org/viewvc/llvm-project?rev=207277&view=rev
Log:
Encapsulate the DWARF string pool in a separate type.
Pulls out some more code from some of the rather monolithic DWARF
classes. Unlike the address table, the string table won't move up into
DwarfDebug - each DWARF file has its own string table (but there can be
only one address table).
Added:
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt?rev=207277&r1=207276&r2=207277&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CMakeLists.txt Fri Apr 25 16:34:35 2014
@@ -11,6 +11,7 @@ add_llvm_library(LLVMAsmPrinter
DwarfDebug.cpp
DwarfException.cpp
DwarfFile.cpp
+ DwarfStringPool.cpp
DwarfUnit.cpp
ErlangGCPrinter.cpp
OcamlGCPrinter.cpp
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp?rev=207277&r1=207276&r2=207277&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp Fri Apr 25 16:34:35 2014
@@ -179,8 +179,8 @@ 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->getStringPoolEntry((*HI)->Str),
- D->getStringPoolSym());
+ Asm->EmitSectionOffset(D->getStringPool().getSymbol(*Asm, (*HI)->Str),
+ D->getStringPool().getSectionSymbol());
Asm->OutStreamer.AddComment("Num DIEs");
Asm->EmitInt32((*HI)->Data.size());
for (ArrayRef<HashDataContents *>::const_iterator
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=207277&r1=207276&r2=207277&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Fri Apr 25 16:34:35 2014
@@ -2545,27 +2545,27 @@ void DwarfDebug::attachLowHighPC(DwarfCo
void DwarfDebug::addAccelName(StringRef Name, const DIE &Die) {
if (!useDwarfAccelTables())
return;
- InfoHolder.getStringPoolEntry(Name);
+ InfoHolder.getStringPool().getSymbol(*Asm, Name);
AccelNames.AddName(Name, &Die);
}
void DwarfDebug::addAccelObjC(StringRef Name, const DIE &Die) {
if (!useDwarfAccelTables())
return;
- InfoHolder.getStringPoolEntry(Name);
+ InfoHolder.getStringPool().getSymbol(*Asm, Name);
AccelObjC.AddName(Name, &Die);
}
void DwarfDebug::addAccelNamespace(StringRef Name, const DIE &Die) {
if (!useDwarfAccelTables())
return;
- InfoHolder.getStringPoolEntry(Name);
+ InfoHolder.getStringPool().getSymbol(*Asm, Name);
AccelNamespace.AddName(Name, &Die);
}
void DwarfDebug::addAccelType(StringRef Name, const DIE &Die, char Flags) {
if (!useDwarfAccelTables())
return;
- InfoHolder.getStringPoolEntry(Name);
+ InfoHolder.getStringPool().getSymbol(*Asm, Name);
AccelTypes.AddName(Name, &Die, Flags);
}
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp?rev=207277&r1=207276&r2=207277&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp Fri Apr 25 16:34:35 2014
@@ -18,36 +18,11 @@
#include "llvm/Target/TargetLoweringObjectFile.h"
namespace llvm {
-DwarfFile::DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
- : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref) {}
+DwarfFile::DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA)
+ : Asm(AP), StrPool(DA, *Asm, Pref) {}
DwarfFile::~DwarfFile() {}
-MCSymbol *DwarfFile::getStringPoolSym() {
- return Asm->GetTempSymbol(StringPref);
-}
-
-MCSymbol *DwarfFile::getStringPoolEntry(StringRef Str) {
- std::pair<MCSymbol *, unsigned> &Entry =
- StringPool.GetOrCreateValue(Str).getValue();
- if (Entry.first)
- return Entry.first;
-
- Entry.second = NextStringPoolNumber++;
- return Entry.first = Asm->GetTempSymbol(StringPref, Entry.second);
-}
-
-unsigned DwarfFile::getStringPoolIndex(StringRef Str) {
- std::pair<MCSymbol *, unsigned> &Entry =
- StringPool.GetOrCreateValue(Str).getValue();
- if (Entry.first)
- return Entry.second;
-
- Entry.second = NextStringPoolNumber++;
- Entry.first = Asm->GetTempSymbol(StringPref, Entry.second);
- return Entry.second;
-}
-
// Define a unique number for the abbreviation.
//
void DwarfFile::assignAbbrevNumber(DIEAbbrev &Abbrev) {
@@ -176,40 +151,6 @@ void DwarfFile::emitAbbrevs(const MCSect
void DwarfFile::emitStrings(const MCSection *StrSection,
const MCSection *OffsetSection,
const MCSymbol *StrSecSym) {
-
- if (StringPool.empty())
- return;
-
- // Start the dwarf str section.
- Asm->OutStreamer.SwitchSection(StrSection);
-
- // Get all of the string pool entries and put them in an array by their ID so
- // we can sort them.
- SmallVector<std::pair<unsigned, const StrPool::value_type *>, 64> Entries;
-
- for (const auto &I : StringPool)
- Entries.push_back(std::make_pair(I.second.second, &I));
-
- array_pod_sort(Entries.begin(), Entries.end());
-
- for (const auto &Entry : Entries) {
- // Emit a label for reference from debug information entries.
- Asm->OutStreamer.EmitLabel(Entry.second->getValue().first);
-
- // Emit the string itself with a terminating null byte.
- Asm->OutStreamer.EmitBytes(StringRef(Entry.second->getKeyData(),
- Entry.second->getKeyLength() + 1));
- }
-
- // If we've got an offset section go ahead and emit that now as well.
- if (OffsetSection) {
- Asm->OutStreamer.SwitchSection(OffsetSection);
- unsigned offset = 0;
- unsigned size = 4; // FIXME: DWARF64 is 8.
- for (const auto &Entry : Entries) {
- Asm->OutStreamer.EmitIntValue(offset, size);
- offset += Entry.second->getKeyLength() + 1;
- }
- }
+ StrPool.emit(*Asm, StrSection, OffsetSection, StrSecSym);
}
}
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h?rev=207277&r1=207276&r2=207277&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h Fri Apr 25 16:34:35 2014
@@ -16,6 +16,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Allocator.h"
#include "AddressPool.h"
+#include "DwarfStringPool.h"
#include <vector>
#include <string>
@@ -43,17 +44,10 @@ class DwarfFile {
// A pointer to all units in the section.
SmallVector<std::unique_ptr<DwarfUnit>, 1> CUs;
- // Collection of strings for this unit and assorted symbols.
- // A String->Symbol mapping of strings used by indirect
- // references.
- typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
- StrPool;
- StrPool StringPool;
- unsigned NextStringPoolNumber;
- std::string StringPref;
+ DwarfStringPool StrPool;
public:
- DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA);
+ DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA);
~DwarfFile();
@@ -83,19 +77,8 @@ public:
const MCSection *OffsetSection = nullptr,
const MCSymbol *StrSecSym = nullptr);
- /// \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 index into the string pool with the given
- /// string text.
- unsigned getStringPoolIndex(StringRef Str);
-
/// \brief Returns the string pool.
- StrPool *getStringPool() { return &StringPool; }
+ DwarfStringPool &getStringPool() { return StrPool; }
};
}
#endif
Added: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp?rev=207277&view=auto
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp (added)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp Fri Apr 25 16:34:35 2014
@@ -0,0 +1,74 @@
+//===-- llvm/CodeGen/DwarfStringPool.cpp - Dwarf Debug Framework ----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "DwarfStringPool.h"
+#include "llvm/MC/MCStreamer.h"
+
+using namespace llvm;
+
+MCSymbol *DwarfStringPool::getSectionSymbol() { return SectionSymbol; }
+
+std::pair<MCSymbol *, unsigned> &
+getEntry(AsmPrinter &Asm,
+ StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> &Pool,
+ StringRef Prefix, StringRef Str) {
+ std::pair<MCSymbol *, unsigned> &Entry =
+ Pool.GetOrCreateValue(Str).getValue();
+ if (!Entry.first) {
+ Entry.second = Pool.size() - 1;
+ Entry.first = Asm.GetTempSymbol(Prefix, Entry.second);
+ }
+ return Entry;
+}
+
+MCSymbol *DwarfStringPool::getSymbol(AsmPrinter &Asm, StringRef Str) {
+ return getEntry(Asm, Pool, Prefix, Str).first;
+}
+
+unsigned DwarfStringPool::getIndex(AsmPrinter &Asm, StringRef Str) {
+ return getEntry(Asm, Pool, Prefix, Str).second;
+}
+
+void DwarfStringPool::emit(AsmPrinter &Asm, const MCSection *StrSection,
+ const MCSection *OffsetSection,
+ const MCSymbol *StrSecSym) {
+ if (Pool.empty())
+ return;
+
+ // Start the dwarf str section.
+ Asm.OutStreamer.SwitchSection(StrSection);
+
+ // Get all of the string pool entries and put them in an array by their ID so
+ // we can sort them.
+ SmallVector<const StringMapEntry<std::pair<MCSymbol *, unsigned>> *, 64>
+ Entries(Pool.size());
+
+ for (const auto &E : Pool)
+ Entries[E.getValue().second] = &E;
+
+ for (const auto &Entry : Entries) {
+ // Emit a label for reference from debug information entries.
+ Asm.OutStreamer.EmitLabel(Entry->getValue().first);
+
+ // Emit the string itself with a terminating null byte.
+ Asm.OutStreamer.EmitBytes(
+ StringRef(Entry->getKeyData(), Entry->getKeyLength() + 1));
+ }
+
+ // If we've got an offset section go ahead and emit that now as well.
+ if (OffsetSection) {
+ Asm.OutStreamer.SwitchSection(OffsetSection);
+ unsigned offset = 0;
+ unsigned size = 4; // FIXME: DWARF64 is 8.
+ for (const auto &Entry : Entries) {
+ Asm.OutStreamer.EmitIntValue(offset, size);
+ offset += Entry->getKeyLength() + 1;
+ }
+ }
+}
Added: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h?rev=207277&view=auto
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h (added)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h Fri Apr 25 16:34:35 2014
@@ -0,0 +1,55 @@
+//===-- llvm/CodeGen/DwarfStringPool.h - Dwarf Debug Framework -*- C++ -*--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CODEGEN_ASMPRINTER_STRINGPOOL_H__
+#define CODEGEN_ASMPRINTER_STRINGPOOL_H__
+
+#include "llvm/ADT/StringMap.h"
+#include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/Support/Allocator.h"
+
+#include <utility>
+
+namespace llvm {
+
+class MCSymbol;
+class MCSection;
+class StringRef;
+
+// Collection of strings for this unit and assorted symbols.
+// A String->Symbol mapping of strings used by indirect
+// references.
+class DwarfStringPool {
+ StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> Pool;
+ StringRef Prefix;
+ MCSymbol *SectionSymbol;
+
+public:
+ DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix)
+ : Pool(A), Prefix(Prefix), SectionSymbol(Asm.GetTempSymbol(Prefix)) {}
+
+ void emit(AsmPrinter &Asm, const MCSection *StrSection,
+ 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
+ /// string text.
+ MCSymbol *getSymbol(AsmPrinter &Asm, StringRef Str);
+
+ /// \brief Returns the index into the string pool with the given
+ /// string text.
+ unsigned getIndex(AsmPrinter &Asm, StringRef Str);
+
+ bool empty() const { return Pool.empty(); }
+};
+}
+#endif
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=207277&r1=207276&r2=207277&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Fri Apr 25 16:34:35 2014
@@ -208,7 +208,7 @@ void DwarfUnit::addString(DIE &Die, dwar
if (!DD->useSplitDwarf())
return addLocalString(Die, Attribute, String);
- unsigned idx = DU->getStringPoolIndex(String);
+ unsigned idx = DU->getStringPool().getIndex(*Asm, String);
DIEValue *Value = new (DIEValueAllocator) DIEInteger(idx);
DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String);
Die.addValue(Attribute, dwarf::DW_FORM_GNU_str_index, Str);
@@ -218,12 +218,12 @@ void DwarfUnit::addString(DIE &Die, dwar
/// to be in the local string pool instead of indirected.
void DwarfUnit::addLocalString(DIE &Die, dwarf::Attribute Attribute,
StringRef String) {
- MCSymbol *Symb = DU->getStringPoolEntry(String);
+ MCSymbol *Symb = DU->getStringPool().getSymbol(*Asm, String);
DIEValue *Value;
if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
Value = new (DIEValueAllocator) DIELabel(Symb);
else {
- MCSymbol *StringPool = DU->getStringPoolSym();
+ MCSymbol *StringPool = DU->getStringPool().getSectionSymbol();
Value = new (DIEValueAllocator) DIEDelta(Symb, StringPool);
}
DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String);
More information about the llvm-commits
mailing list