[CodeGen] Optimize AccelTable

Summary:
The class contained arrays of two structures (DataArray and HashData).
These structures were in 1:1 correspondence, and one of them contained
pointers to the other (and *both* contained a "Name" field). By merging
these two structures into one, we can save a bit of space without
negatively impacting much of anything.

Reviewers: JDevlieghere, aprantl

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D43073

llvm-svn: 324724
diff --git a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
index 0320b54..3ecef5d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
@@ -138,11 +138,11 @@
         Asm->EmitInt32(0);
       // Remember to emit the label for our offset.
       Asm->OutStreamer->EmitLabel(Hash->Sym);
-      Asm->OutStreamer->AddComment(Hash->Str);
-      Asm->emitDwarfStringOffset(Hash->Data.Name);
+      Asm->OutStreamer->AddComment(Hash->Name.getString());
+      Asm->emitDwarfStringOffset(Hash->Name);
       Asm->OutStreamer->AddComment("Num DIEs");
-      Asm->EmitInt32(Hash->Data.Values.size());
-      for (const auto *V : Hash->Data.Values) {
+      Asm->EmitInt32(Hash->Values.size());
+      for (const auto *V : Hash->Values) {
         V->emit(Asm);
       }
       PrevHash = Hash->HashValue;
@@ -155,9 +155,10 @@
 
 void AppleAccelTableBase::computeBucketCount() {
   // First get the number of unique hashes.
-  std::vector<uint32_t> uniques(Data.size());
-  for (size_t i = 0, e = Data.size(); i < e; ++i)
-    uniques[i] = Data[i]->HashValue;
+  std::vector<uint32_t> uniques;
+  uniques.reserve(Entries.size());
+  for (const auto &E : Entries)
+    uniques.push_back(E.second.HashValue);
   array_pod_sort(uniques.begin(), uniques.end());
   std::vector<uint32_t>::iterator p =
       std::unique(uniques.begin(), uniques.end());
@@ -169,7 +170,6 @@
 
 void AppleAccelTableBase::finalizeTable(AsmPrinter *Asm, StringRef Prefix) {
   // Create the individual hash data outputs.
-  Data.reserve(Entries.size());
   for (auto &E : Entries) {
     // Unique the entries.
     std::stable_sort(E.second.Values.begin(), E.second.Values.end(),
@@ -178,9 +178,6 @@
     E.second.Values.erase(
         std::unique(E.second.Values.begin(), E.second.Values.end()),
         E.second.Values.end());
-
-    HashData *Entry = new (Allocator) HashData(E.first(), E.second);
-    Data.push_back(Entry);
   }
 
   // Figure out how many buckets we need, then compute the bucket contents and
@@ -192,10 +189,10 @@
 
   // Compute bucket contents and final ordering.
   Buckets.resize(Header.getBucketCount());
-  for (auto &D : Data) {
-    uint32_t bucket = D->HashValue % Header.getBucketCount();
-    Buckets[bucket].push_back(D);
-    D->Sym = Asm->createTempSymbol(Prefix);
+  for (auto &E : Entries) {
+    uint32_t bucket = E.second.HashValue % Header.getBucketCount();
+    Buckets[bucket].push_back(&E.second);
+    E.second.Sym = Asm->createTempSymbol(Prefix);
   }
 
   // Sort the contents of the buckets by hash value so that hash collisions end
@@ -286,8 +283,8 @@
   HeaderData.print(OS);
 }
 
-void AppleAccelTableBase::HashData::print(raw_ostream &OS) {
-  OS << "Name: " << Str << "\n";
+void AppleAccelTableBase::HashData::print(raw_ostream &OS) const {
+  OS << "Name: " << Name.getString() << "\n";
   OS << "  Hash Value: " << format("0x%x", HashValue) << "\n";
   OS << "  Symbol: ";
   if (Sym)
@@ -295,7 +292,7 @@
   else
     OS << "<none>";
   OS << "\n";
-  for (auto *Value : Data.Values)
+  for (auto *Value : Values)
     Value->print(OS);
 }
 
@@ -317,8 +314,8 @@
       Hash->print(OS);
 
   OS << "Data: \n";
-  for (auto &D : Data)
-    D->print(OS);
+  for (auto &E : Entries)
+    E.second.print(OS);
 }
 
 void AppleAccelTableOffsetData::print(raw_ostream &OS) const {