[llvm] r238114 - AsmPrinter: Emit the DwarfStringPool offset directly when possible
Duncan P. N. Exon Smith
dexonsmith at apple.com
Sun May 24 09:14:59 PDT 2015
Author: dexonsmith
Date: Sun May 24 11:14:59 2015
New Revision: 238114
URL: http://llvm.org/viewvc/llvm-project?rev=238114&view=rev
Log:
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.)
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/trunk/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll
llvm/trunk/test/DebugInfo/X86/stringpool.ll
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp?rev=238114&r1=238113&r2=238114&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp Sun May 24 11:14:59 2015
@@ -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 &A
// 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 &A
// 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);
}
}
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h?rev=238114&r1=238113&r2=238114&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h Sun May 24 11:14:59 2015
@@ -25,8 +25,14 @@ class StringRef;
// A String->Symbol mapping of strings used by indirect
// references.
class DwarfStringPool {
- StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> Pool;
+ struct EntryTy {
+ MCSymbol *Symbol;
+ unsigned Offset;
+ unsigned Index;
+ };
+ StringMap<EntryTy, BumpPtrAllocator &> Pool;
StringRef Prefix;
+ unsigned NumBytes = 0;
public:
DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix)
@@ -38,19 +44,24 @@ public:
/// \brief Returns an entry into the string pool with the given
/// string text.
MCSymbol *getSymbol(AsmPrinter &Asm, StringRef Str) {
- return getEntry(Asm, Str).first;
+ return getEntry(Asm, Str).Symbol;
+ }
+
+ /// Get a byte offset into the string pool with the given text.
+ unsigned getOffset(AsmPrinter &Asm, StringRef Str) {
+ return getEntry(Asm, Str).Offset;
}
/// \brief Returns the index into the string pool with the given
/// string text.
unsigned getIndex(AsmPrinter &Asm, StringRef Str) {
- return getEntry(Asm, Str).second;
+ return getEntry(Asm, Str).Index;
}
bool empty() const { return Pool.empty(); }
private:
- std::pair<MCSymbol *, unsigned> &getEntry(AsmPrinter &Asm, StringRef Str);
+ EntryTy &getEntry(AsmPrinter &Asm, StringRef Str);
};
}
#endif
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=238114&r1=238113&r2=238114&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Sun May 24 11:14:59 2015
@@ -239,14 +239,13 @@ void DwarfUnit::addIndexedString(DIE &Di
void DwarfUnit::addLocalString(DIE &Die, dwarf::Attribute Attribute,
StringRef String) {
- const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
- MCSymbol *Symb = DU->getStringPool().getSymbol(*Asm, String);
DIEValue *Value;
if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
- Value = new (DIEValueAllocator) DIELabel(Symb);
+ Value = new (DIEValueAllocator)
+ DIELabel(DU->getStringPool().getSymbol(*Asm, String));
else
Value = new (DIEValueAllocator)
- DIEDelta(Symb, TLOF.getDwarfStrSection()->getBeginSymbol());
+ DIEInteger(DU->getStringPool().getOffset(*Asm, String));
DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String);
Die.addValue(Attribute, dwarf::DW_FORM_strp, Str);
}
Modified: llvm/trunk/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll?rev=238114&r1=238113&r2=238114&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll (original)
+++ llvm/trunk/test/DebugInfo/2010-06-29-InlinedFnLocalVar.ll Sun May 24 11:14:59 2015
@@ -3,7 +3,7 @@
; CHECK: section_info
; CHECK: DW_TAG_structure_type
-; CHECK-NEXT: info_string
+; CHECK-NEXT: DW_AT_name
@i = common global i32 0 ; <i32*> [#uses=2]
Modified: llvm/trunk/test/DebugInfo/X86/stringpool.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/stringpool.ll?rev=238114&r1=238113&r2=238114&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/stringpool.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/stringpool.ll Sun May 24 11:14:59 2015
@@ -18,7 +18,7 @@
; LINUX: .section .debug_str,"MS", at progbits,1
; LINUX: yyyy
; DARWIN: .section __DWARF,__debug_str,regular,debug
-; DARWIN: yyyy
+; DARWIN: .asciz "yyyy" ## string offset=[[YYYY:[0-9]+]]
; Verify that we refer to 'yyyy' with a relocation.
; LINUX: .long .Linfo_string3 # DW_AT_name
@@ -30,9 +30,8 @@
; LINUX-NEXT: .byte 3
; LINUX-NEXT: .quad yyyy
-; Verify that we refer to 'yyyy' without a relocation.
-; DARWIN: Lset[[ID:[0-9]+]] = Linfo_string3-Linfo_string ## DW_AT_name
-; DARWIN-NEXT: .long Lset[[ID]]
+; Verify that we refer to 'yyyy' with a direct offset.
+; DARWIN: .long [[YYYY]]
; DARWIN-NEXT: .long {{[0-9]+}} ## DW_AT_type
; DARWIN-NEXT: ## DW_AT_external
; DARWIN-NEXT: .byte 1 ## DW_AT_decl_file
More information about the llvm-commits
mailing list