Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 1 | //=-- llvm/CodeGen/DwarfAccelTable.cpp - Dwarf Accelerator Tables -*- C++ -*-=// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains support for writing dwarf accelerator tables. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Craig Topper | 6e80c28 | 2012-03-26 06:58:25 +0000 | [diff] [blame] | 14 | #include "DwarfAccelTable.h" |
Frederic Riss | 3a6b354 | 2014-11-12 23:48:14 +0000 | [diff] [blame] | 15 | #include "DwarfCompileUnit.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "DwarfDebug.h" |
Benjamin Kramer | 3e6719c | 2012-03-26 14:17:26 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/Twine.h" |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/AsmPrinter.h" |
Frederic Riss | e541e0b | 2015-01-05 21:29:41 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/DIE.h" |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCExpr.h" |
| 22 | #include "llvm/MC/MCStreamer.h" |
| 23 | #include "llvm/MC/MCSymbol.h" |
| 24 | #include "llvm/Support/Debug.h" |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 25 | |
| 26 | using namespace llvm; |
| 27 | |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 28 | // The length of the header data is always going to be 4 + 4 + 4*NumAtoms. |
Eric Christopher | b4e2cc4 | 2013-09-05 16:46:43 +0000 | [diff] [blame] | 29 | DwarfAccelTable::DwarfAccelTable(ArrayRef<DwarfAccelTable::Atom> atomList) |
| 30 | : Header(8 + (atomList.size() * 4)), HeaderData(atomList), |
| 31 | Entries(Allocator) {} |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 32 | |
Duncan P. N. Exon Smith | f459994 | 2015-05-24 16:44:32 +0000 | [diff] [blame] | 33 | void DwarfAccelTable::AddName(DwarfStringPoolEntryRef Name, const DIE *die, |
David Blaikie | 772ab8a | 2014-04-25 22:21:35 +0000 | [diff] [blame] | 34 | char Flags) { |
Benjamin Kramer | 330970d | 2012-04-13 20:06:17 +0000 | [diff] [blame] | 35 | assert(Data.empty() && "Already finalized!"); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 36 | // If the string is in the list already then add this die to the list |
| 37 | // otherwise add a new one. |
Duncan P. N. Exon Smith | f459994 | 2015-05-24 16:44:32 +0000 | [diff] [blame] | 38 | DataArray &DIEs = Entries[Name.getString()]; |
| 39 | assert(!DIEs.Name || DIEs.Name == Name); |
| 40 | DIEs.Name = Name; |
David Blaikie | 772ab8a | 2014-04-25 22:21:35 +0000 | [diff] [blame] | 41 | DIEs.Values.push_back(new (Allocator) HashDataContents(die, Flags)); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Eugene Zelenko | ffec81c | 2015-11-04 22:32:32 +0000 | [diff] [blame] | 44 | void DwarfAccelTable::ComputeBucketCount() { |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 45 | // First get the number of unique hashes. |
Benjamin Kramer | 3e6719c | 2012-03-26 14:17:26 +0000 | [diff] [blame] | 46 | std::vector<uint32_t> uniques(Data.size()); |
Eric Christopher | 54ce295d | 2011-11-08 18:38:40 +0000 | [diff] [blame] | 47 | for (size_t i = 0, e = Data.size(); i < e; ++i) |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 48 | uniques[i] = Data[i]->HashValue; |
Benjamin Kramer | 3e6719c | 2012-03-26 14:17:26 +0000 | [diff] [blame] | 49 | array_pod_sort(uniques.begin(), uniques.end()); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 50 | std::vector<uint32_t>::iterator p = |
Eric Christopher | b4e2cc4 | 2013-09-05 16:46:43 +0000 | [diff] [blame] | 51 | std::unique(uniques.begin(), uniques.end()); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 52 | uint32_t num = std::distance(uniques.begin(), p); |
| 53 | |
| 54 | // Then compute the bucket size, minimum of 1 bucket. |
Eric Christopher | b4e2cc4 | 2013-09-05 16:46:43 +0000 | [diff] [blame] | 55 | if (num > 1024) |
| 56 | Header.bucket_count = num / 4; |
Frederic Riss | 2ad5188 | 2015-03-09 21:09:50 +0000 | [diff] [blame] | 57 | else if (num > 16) |
Eric Christopher | b4e2cc4 | 2013-09-05 16:46:43 +0000 | [diff] [blame] | 58 | Header.bucket_count = num / 2; |
| 59 | else |
| 60 | Header.bucket_count = num > 0 ? num : 1; |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 61 | |
| 62 | Header.hashes_count = num; |
| 63 | } |
| 64 | |
Benjamin Kramer | 330970d | 2012-04-13 20:06:17 +0000 | [diff] [blame] | 65 | // compareDIEs - comparison predicate that sorts DIEs by their offset. |
| 66 | static bool compareDIEs(const DwarfAccelTable::HashDataContents *A, |
| 67 | const DwarfAccelTable::HashDataContents *B) { |
| 68 | return A->Die->getOffset() < B->Die->getOffset(); |
Eric Christopher | 0abbd0e | 2011-11-15 23:37:17 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Benjamin Kramer | 63e39eb | 2013-05-11 18:24:28 +0000 | [diff] [blame] | 71 | void DwarfAccelTable::FinalizeTable(AsmPrinter *Asm, StringRef Prefix) { |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 72 | // Create the individual hash data outputs. |
Benjamin Kramer | 49a1132 | 2015-02-28 20:15:00 +0000 | [diff] [blame] | 73 | Data.reserve(Entries.size()); |
Eric Christopher | b4e2cc4 | 2013-09-05 16:46:43 +0000 | [diff] [blame] | 74 | for (StringMap<DataArray>::iterator EI = Entries.begin(), EE = Entries.end(); |
| 75 | EI != EE; ++EI) { |
Eric Christopher | d9843b3 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 76 | |
| 77 | // Unique the entries. |
David Blaikie | 772ab8a | 2014-04-25 22:21:35 +0000 | [diff] [blame] | 78 | std::stable_sort(EI->second.Values.begin(), EI->second.Values.end(), compareDIEs); |
| 79 | EI->second.Values.erase( |
| 80 | std::unique(EI->second.Values.begin(), EI->second.Values.end()), |
| 81 | EI->second.Values.end()); |
Eric Christopher | d9843b3 | 2011-11-10 19:25:34 +0000 | [diff] [blame] | 82 | |
Benjamin Kramer | 330970d | 2012-04-13 20:06:17 +0000 | [diff] [blame] | 83 | HashData *Entry = new (Allocator) HashData(EI->getKey(), EI->second); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 84 | Data.push_back(Entry); |
| 85 | } |
| 86 | |
| 87 | // Figure out how many buckets we need, then compute the bucket |
| 88 | // contents and the final ordering. We'll emit the hashes and offsets |
| 89 | // by doing a walk during the emission phase. We add temporary |
| 90 | // symbols to the data so that we can reference them during the offset |
| 91 | // later, we'll emit them when we emit the data. |
| 92 | ComputeBucketCount(); |
| 93 | |
| 94 | // Compute bucket contents and final ordering. |
| 95 | Buckets.resize(Header.bucket_count); |
Eric Christopher | 54ce295d | 2011-11-08 18:38:40 +0000 | [diff] [blame] | 96 | for (size_t i = 0, e = Data.size(); i < e; ++i) { |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 97 | uint32_t bucket = Data[i]->HashValue % Header.bucket_count; |
| 98 | Buckets[bucket].push_back(Data[i]); |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 99 | Data[i]->Sym = Asm->createTempSymbol(Prefix); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 100 | } |
Frederic Riss | 0e9a50f | 2015-03-10 00:46:31 +0000 | [diff] [blame] | 101 | |
| 102 | // Sort the contents of the buckets by hash value so that hash |
| 103 | // collisions end up together. Stable sort makes testing easier and |
| 104 | // doesn't cost much more. |
| 105 | for (size_t i = 0; i < Buckets.size(); ++i) |
| 106 | std::stable_sort(Buckets[i].begin(), Buckets[i].end(), |
| 107 | [] (HashData *LHS, HashData *RHS) { |
| 108 | return LHS->HashValue < RHS->HashValue; |
| 109 | }); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | // Emits the header for the table via the AsmPrinter. |
| 113 | void DwarfAccelTable::EmitHeader(AsmPrinter *Asm) { |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 114 | Asm->OutStreamer->AddComment("Header Magic"); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 115 | Asm->EmitInt32(Header.magic); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 116 | Asm->OutStreamer->AddComment("Header Version"); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 117 | Asm->EmitInt16(Header.version); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 118 | Asm->OutStreamer->AddComment("Header Hash Function"); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 119 | Asm->EmitInt16(Header.hash_function); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 120 | Asm->OutStreamer->AddComment("Header Bucket Count"); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 121 | Asm->EmitInt32(Header.bucket_count); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 122 | Asm->OutStreamer->AddComment("Header Hash Count"); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 123 | Asm->EmitInt32(Header.hashes_count); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 124 | Asm->OutStreamer->AddComment("Header Data Length"); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 125 | Asm->EmitInt32(Header.header_data_len); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 126 | Asm->OutStreamer->AddComment("HeaderData Die Offset Base"); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 127 | Asm->EmitInt32(HeaderData.die_offset_base); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 128 | Asm->OutStreamer->AddComment("HeaderData Atom Count"); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 129 | Asm->EmitInt32(HeaderData.Atoms.size()); |
| 130 | for (size_t i = 0; i < HeaderData.Atoms.size(); i++) { |
| 131 | Atom A = HeaderData.Atoms[i]; |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 132 | Asm->OutStreamer->AddComment(dwarf::AtomTypeString(A.type)); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 133 | Asm->EmitInt16(A.type); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 134 | Asm->OutStreamer->AddComment(dwarf::FormEncodingString(A.form)); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 135 | Asm->EmitInt16(A.form); |
| 136 | } |
| 137 | } |
| 138 | |
Eric Christopher | 2861136 | 2012-10-08 23:53:45 +0000 | [diff] [blame] | 139 | // Walk through and emit the buckets for the table. Each index is |
| 140 | // an offset into the list of hashes. |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 141 | void DwarfAccelTable::EmitBuckets(AsmPrinter *Asm) { |
| 142 | unsigned index = 0; |
Eric Christopher | 54ce295d | 2011-11-08 18:38:40 +0000 | [diff] [blame] | 143 | for (size_t i = 0, e = Buckets.size(); i < e; ++i) { |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 144 | Asm->OutStreamer->AddComment("Bucket " + Twine(i)); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 145 | if (Buckets[i].size() != 0) |
| 146 | Asm->EmitInt32(index); |
| 147 | else |
| 148 | Asm->EmitInt32(UINT32_MAX); |
Frederic Riss | 0e9a50f | 2015-03-10 00:46:31 +0000 | [diff] [blame] | 149 | // Buckets point in the list of hashes, not to the data. Do not |
| 150 | // increment the index multiple times in case of hash collisions. |
| 151 | uint64_t PrevHash = UINT64_MAX; |
| 152 | for (auto *HD : Buckets[i]) { |
| 153 | uint32_t HashValue = HD->HashValue; |
| 154 | if (PrevHash != HashValue) |
| 155 | ++index; |
| 156 | PrevHash = HashValue; |
| 157 | } |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
| 161 | // Walk through the buckets and emit the individual hashes for each |
| 162 | // bucket. |
| 163 | void DwarfAccelTable::EmitHashes(AsmPrinter *Asm) { |
Frederic Riss | 0e9a50f | 2015-03-10 00:46:31 +0000 | [diff] [blame] | 164 | uint64_t PrevHash = UINT64_MAX; |
Eric Christopher | 54ce295d | 2011-11-08 18:38:40 +0000 | [diff] [blame] | 165 | for (size_t i = 0, e = Buckets.size(); i < e; ++i) { |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 166 | for (HashList::const_iterator HI = Buckets[i].begin(), |
Eric Christopher | b4e2cc4 | 2013-09-05 16:46:43 +0000 | [diff] [blame] | 167 | HE = Buckets[i].end(); |
| 168 | HI != HE; ++HI) { |
Frederic Riss | 0e9a50f | 2015-03-10 00:46:31 +0000 | [diff] [blame] | 169 | uint32_t HashValue = (*HI)->HashValue; |
| 170 | if (PrevHash == HashValue) |
| 171 | continue; |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 172 | Asm->OutStreamer->AddComment("Hash in Bucket " + Twine(i)); |
Frederic Riss | 0e9a50f | 2015-03-10 00:46:31 +0000 | [diff] [blame] | 173 | Asm->EmitInt32(HashValue); |
| 174 | PrevHash = HashValue; |
Eric Christopher | 48fef59 | 2012-12-20 21:58:40 +0000 | [diff] [blame] | 175 | } |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | // Walk through the buckets and emit the individual offsets for each |
| 180 | // element in each bucket. This is done via a symbol subtraction from the |
| 181 | // beginning of the section. The non-section symbol will be output later |
| 182 | // when we emit the actual data. |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 183 | void DwarfAccelTable::emitOffsets(AsmPrinter *Asm, const MCSymbol *SecBegin) { |
Frederic Riss | 0e9a50f | 2015-03-10 00:46:31 +0000 | [diff] [blame] | 184 | uint64_t PrevHash = UINT64_MAX; |
Eric Christopher | 54ce295d | 2011-11-08 18:38:40 +0000 | [diff] [blame] | 185 | for (size_t i = 0, e = Buckets.size(); i < e; ++i) { |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 186 | for (HashList::const_iterator HI = Buckets[i].begin(), |
Eric Christopher | b4e2cc4 | 2013-09-05 16:46:43 +0000 | [diff] [blame] | 187 | HE = Buckets[i].end(); |
| 188 | HI != HE; ++HI) { |
Frederic Riss | 0e9a50f | 2015-03-10 00:46:31 +0000 | [diff] [blame] | 189 | uint32_t HashValue = (*HI)->HashValue; |
| 190 | if (PrevHash == HashValue) |
| 191 | continue; |
| 192 | PrevHash = HashValue; |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 193 | Asm->OutStreamer->AddComment("Offset in Bucket " + Twine(i)); |
| 194 | MCContext &Context = Asm->OutStreamer->getContext(); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 195 | const MCExpr *Sub = MCBinaryExpr::createSub( |
| 196 | MCSymbolRefExpr::create((*HI)->Sym, Context), |
| 197 | MCSymbolRefExpr::create(SecBegin, Context), Context); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 198 | Asm->OutStreamer->EmitValue(Sub, sizeof(uint32_t)); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | // Walk through the buckets and emit the full data for each element in |
| 204 | // the bucket. For the string case emit the dies and the various offsets. |
| 205 | // Terminate each HashData bucket with 0. |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 206 | void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfDebug *D) { |
Eric Christopher | 54ce295d | 2011-11-08 18:38:40 +0000 | [diff] [blame] | 207 | for (size_t i = 0, e = Buckets.size(); i < e; ++i) { |
Frederic Riss | 44a219f | 2015-03-10 03:47:55 +0000 | [diff] [blame] | 208 | uint64_t PrevHash = UINT64_MAX; |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 209 | for (HashList::const_iterator HI = Buckets[i].begin(), |
Eric Christopher | b4e2cc4 | 2013-09-05 16:46:43 +0000 | [diff] [blame] | 210 | HE = Buckets[i].end(); |
| 211 | HI != HE; ++HI) { |
Frederic Riss | 0e9a50f | 2015-03-10 00:46:31 +0000 | [diff] [blame] | 212 | // Terminate the previous entry if there is no hash collision |
| 213 | // with the current one. |
| 214 | if (PrevHash != UINT64_MAX && PrevHash != (*HI)->HashValue) |
| 215 | Asm->EmitInt32(0); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 216 | // Remember to emit the label for our offset. |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 217 | Asm->OutStreamer->EmitLabel((*HI)->Sym); |
| 218 | Asm->OutStreamer->AddComment((*HI)->Str); |
Duncan P. N. Exon Smith | 1e0d94e | 2015-05-24 16:48:54 +0000 | [diff] [blame] | 219 | Asm->emitDwarfStringOffset((*HI)->Data.Name); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 220 | Asm->OutStreamer->AddComment("Num DIEs"); |
David Blaikie | 772ab8a | 2014-04-25 22:21:35 +0000 | [diff] [blame] | 221 | Asm->EmitInt32((*HI)->Data.Values.size()); |
| 222 | for (HashDataContents *HD : (*HI)->Data.Values) { |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 223 | // Emit the DIE offset |
Frederic Riss | 3a6b354 | 2014-11-12 23:48:14 +0000 | [diff] [blame] | 224 | DwarfCompileUnit *CU = D->lookupUnit(HD->Die->getUnit()); |
| 225 | assert(CU && "Accelerated DIE should belong to a CU."); |
| 226 | Asm->EmitInt32(HD->Die->getOffset() + CU->getDebugInfoOffset()); |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 227 | // If we have multiple Atoms emit that info too. |
| 228 | // FIXME: A bit of a hack, we either emit only one atom or all info. |
| 229 | if (HeaderData.Atoms.size() > 1) { |
David Blaikie | 772ab8a | 2014-04-25 22:21:35 +0000 | [diff] [blame] | 230 | Asm->EmitInt16(HD->Die->getTag()); |
| 231 | Asm->EmitInt8(HD->Flags); |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 232 | } |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 233 | } |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 234 | PrevHash = (*HI)->HashValue; |
| 235 | } |
Frederic Riss | 0e9a50f | 2015-03-10 00:46:31 +0000 | [diff] [blame] | 236 | // Emit the final end marker for the bucket. |
Frederic Riss | 44a219f | 2015-03-10 03:47:55 +0000 | [diff] [blame] | 237 | if (!Buckets[i].empty()) |
| 238 | Asm->EmitInt32(0); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
| 242 | // Emit the entire data structure to the output file. |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 243 | void DwarfAccelTable::emit(AsmPrinter *Asm, const MCSymbol *SecBegin, |
| 244 | DwarfDebug *D) { |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 245 | // Emit the header. |
| 246 | EmitHeader(Asm); |
| 247 | |
| 248 | // Emit the buckets. |
| 249 | EmitBuckets(Asm); |
| 250 | |
| 251 | // Emit the hashes. |
| 252 | EmitHashes(Asm); |
| 253 | |
| 254 | // Emit the offsets. |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 255 | emitOffsets(Asm, SecBegin); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 256 | |
| 257 | // Emit the hash data. |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 258 | EmitData(Asm, D); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | #ifndef NDEBUG |
| 262 | void DwarfAccelTable::print(raw_ostream &O) { |
| 263 | |
| 264 | Header.print(O); |
| 265 | HeaderData.print(O); |
| 266 | |
| 267 | O << "Entries: \n"; |
Eric Christopher | b4e2cc4 | 2013-09-05 16:46:43 +0000 | [diff] [blame] | 268 | for (StringMap<DataArray>::const_iterator EI = Entries.begin(), |
| 269 | EE = Entries.end(); |
| 270 | EI != EE; ++EI) { |
Eric Christopher | 5a28a6e | 2012-01-06 23:03:27 +0000 | [diff] [blame] | 271 | O << "Name: " << EI->getKeyData() << "\n"; |
David Blaikie | 772ab8a | 2014-04-25 22:21:35 +0000 | [diff] [blame] | 272 | for (HashDataContents *HD : EI->second.Values) |
| 273 | HD->print(O); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | O << "Buckets and Hashes: \n"; |
Eric Christopher | 54ce295d | 2011-11-08 18:38:40 +0000 | [diff] [blame] | 277 | for (size_t i = 0, e = Buckets.size(); i < e; ++i) |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 278 | for (HashList::const_iterator HI = Buckets[i].begin(), |
Eric Christopher | b4e2cc4 | 2013-09-05 16:46:43 +0000 | [diff] [blame] | 279 | HE = Buckets[i].end(); |
| 280 | HI != HE; ++HI) |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 281 | (*HI)->print(O); |
| 282 | |
| 283 | O << "Data: \n"; |
Eric Christopher | b4e2cc4 | 2013-09-05 16:46:43 +0000 | [diff] [blame] | 284 | for (std::vector<HashData *>::const_iterator DI = Data.begin(), |
| 285 | DE = Data.end(); |
| 286 | DI != DE; ++DI) |
| 287 | (*DI)->print(O); |
Eric Christopher | 6e47204 | 2011-11-07 09:18:42 +0000 | [diff] [blame] | 288 | } |
| 289 | #endif |