[llvm] r238122 - AsmPrinter: Avoid creating symbols in DwarfStringPool

Duncan P. N. Exon Smith dexonsmith at apple.com
Sun May 24 09:58:59 PDT 2015


Author: dexonsmith
Date: Sun May 24 11:58:59 2015
New Revision: 238122

URL: http://llvm.org/viewvc/llvm-project?rev=238122&view=rev
Log:
AsmPrinter: Avoid creating symbols in DwarfStringPool

Stop creating symbols we don't need in `DwarfStringPool`.  The consumers
only call `DwarfStringPoolEntryRef::getSymbol()` when DWARF is
relocatable, so this just stops creating the unused symbols when it's
not.  This drops memory usage from 851 MB to 845 MB, around 0.7%.

(I'm looking at `llc` memory usage on `verify-uselistorder.lto.opt.bc`;
see r236629 for details.)

Modified:
    llvm/trunk/include/llvm/CodeGen/DwarfStringPoolEntry.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h

Modified: llvm/trunk/include/llvm/CodeGen/DwarfStringPoolEntry.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DwarfStringPoolEntry.h?rev=238122&r1=238121&r2=238122&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/DwarfStringPoolEntry.h (original)
+++ llvm/trunk/include/llvm/CodeGen/DwarfStringPoolEntry.h Sun May 24 11:58:59 2015
@@ -34,7 +34,10 @@ public:
       : I(&I) {}
 
   explicit operator bool() const { return I; }
-  MCSymbol *getSymbol() const { return I->second.Symbol; }
+  MCSymbol *getSymbol() const {
+    assert(I->second.Symbol && "No symbol available!");
+    return I->second.Symbol;
+  }
   unsigned getOffset() const { return I->second.Offset; }
   unsigned getIndex() const { return I->second.Index; }
   StringRef getString() const { return I->first(); }

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp?rev=238122&r1=238121&r2=238122&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp Sun May 24 11:58:59 2015
@@ -9,10 +9,16 @@
 
 #include "DwarfStringPool.h"
 #include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCStreamer.h"
 
 using namespace llvm;
 
+DwarfStringPool::DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm,
+                                 StringRef Prefix)
+    : Pool(A), Prefix(Prefix),
+      ShouldCreateSymbols(Asm.MAI->doesDwarfUseRelocationsAcrossSections()) {}
+
 DwarfStringPool::EntryRef DwarfStringPool::getEntry(AsmPrinter &Asm,
                                                     StringRef Str) {
   auto I = Pool.insert(std::make_pair(Str, EntryTy()));
@@ -20,7 +26,7 @@ DwarfStringPool::EntryRef DwarfStringPoo
     auto &Entry = I.first->second;
     Entry.Index = Pool.size() - 1;
     Entry.Offset = NumBytes;
-    Entry.Symbol = Asm.createTempSymbol(Prefix);
+    Entry.Symbol = ShouldCreateSymbols ? Asm.createTempSymbol(Prefix) : nullptr;
 
     NumBytes += Str.size() + 1;
     assert(NumBytes > Entry.Offset && "Unexpected overflow");
@@ -44,8 +50,12 @@ void DwarfStringPool::emit(AsmPrinter &A
     Entries[E.getValue().Index] = &E;
 
   for (const auto &Entry : Entries) {
+    assert(ShouldCreateSymbols == static_cast<bool>(Entry->getValue().Symbol) &&
+           "Mismatch between setting and entry");
+
     // Emit a label for reference from debug information entries.
-    Asm.OutStreamer->EmitLabel(Entry->getValue().Symbol);
+    if (ShouldCreateSymbols)
+      Asm.OutStreamer->EmitLabel(Entry->getValue().Symbol);
 
     // Emit the string itself with a terminating null byte.
     Asm.OutStreamer->AddComment("string offset=" +

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h?rev=238122&r1=238121&r2=238122&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h Sun May 24 11:58:59 2015
@@ -30,12 +30,12 @@ class DwarfStringPool {
   StringMap<EntryTy, BumpPtrAllocator &> Pool;
   StringRef Prefix;
   unsigned NumBytes = 0;
+  bool ShouldCreateSymbols;
 
 public:
   typedef DwarfStringPoolEntryRef EntryRef;
 
-  DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix)
-      : Pool(A), Prefix(Prefix) {}
+  DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix);
 
   void emit(AsmPrinter &Asm, MCSection *StrSection,
             MCSection *OffsetSection = nullptr);





More information about the llvm-commits mailing list