aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-05-24 16:14:59 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-05-24 16:14:59 +0000
commit1a65e4ade4e77ad56a57502dcb0cb21b2850df7a (patch)
treebf8347914756152c8d7abb2f14be13e0b89173ee /llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
parent004e73420d1d8ffdc75ff7d9c88911f33c6c6278 (diff)
downloadllvm-1a65e4ade4e77ad56a57502dcb0cb21b2850df7a.zip
llvm-1a65e4ade4e77ad56a57502dcb0cb21b2850df7a.tar.gz
llvm-1a65e4ade4e77ad56a57502dcb0cb21b2850df7a.tar.bz2
AsmPrinter: Emit the DwarfStringPool offset directly when possible
Change `DwarfStringPool` to calculate byte offsets on-the-fly, and update `DwarfUnit::getLocalString()` to use a `DIEInteger` instead of a `DIEDelta` when Dwarf doesn't use relocations (i.e., Mach-O). This eliminates another call to `EmitLabelDifference()`, and drops memory usage from 865 MB down to 861 MB, around 0.5%. (I'm looking at `llc` memory usage on `verify-uselistorder.lto.opt.bc`; see r236629 for details.) llvm-svn: 238114
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
index fc98ed4..a599126 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
@@ -12,12 +12,16 @@
using namespace llvm;
-std::pair<MCSymbol *, unsigned> &DwarfStringPool::getEntry(AsmPrinter &Asm,
- StringRef Str) {
- std::pair<MCSymbol *, unsigned> &Entry = Pool[Str];
- if (!Entry.first) {
- Entry.second = Pool.size() - 1;
- Entry.first = Asm.createTempSymbol(Prefix);
+DwarfStringPool::EntryTy &DwarfStringPool::getEntry(AsmPrinter &Asm,
+ StringRef Str) {
+ auto &Entry = Pool[Str];
+ if (!Entry.Symbol) {
+ Entry.Index = Pool.size() - 1;
+ Entry.Offset = NumBytes;
+ Entry.Symbol = Asm.createTempSymbol(Prefix);
+
+ NumBytes += Str.size() + 1;
+ assert(NumBytes > Entry.Offset && "Unexpected overflow");
}
return Entry;
}
@@ -32,17 +36,18 @@ void DwarfStringPool::emit(AsmPrinter &Asm, MCSection *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());
+ SmallVector<const StringMapEntry<EntryTy> *, 64> Entries(Pool.size());
for (const auto &E : Pool)
- Entries[E.getValue().second] = &E;
+ Entries[E.getValue().Index] = &E;
for (const auto &Entry : Entries) {
// Emit a label for reference from debug information entries.
- Asm.OutStreamer->EmitLabel(Entry->getValue().first);
+ Asm.OutStreamer->EmitLabel(Entry->getValue().Symbol);
// Emit the string itself with a terminating null byte.
+ Asm.OutStreamer->AddComment("string offset=" +
+ Twine(Entry->getValue().Offset));
Asm.OutStreamer->EmitBytes(
StringRef(Entry->getKeyData(), Entry->getKeyLength() + 1));
}
@@ -50,11 +55,8 @@ void DwarfStringPool::emit(AsmPrinter &Asm, MCSection *StrSection,
// 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;
- }
+ for (const auto &Entry : Entries)
+ Asm.OutStreamer->EmitIntValue(Entry->getValue().Offset, size);
}
}