16
16
#include " llvm/ADT/ArrayRef.h"
17
17
#include " llvm/ADT/MapVector.h"
18
18
#include " llvm/ADT/STLFunctionalExtras.h"
19
- #include " llvm/ADT/StringMap.h"
20
19
#include " llvm/ADT/StringRef.h"
21
20
#include " llvm/BinaryFormat/Dwarf.h"
22
21
#include " llvm/CodeGen/DIE.h"
104
103
namespace llvm {
105
104
106
105
class AsmPrinter ;
107
- class DwarfCompileUnit ;
106
+ class DwarfUnit ;
108
107
class DwarfDebug ;
108
+ class DwarfTypeUnit ;
109
109
class MCSymbol ;
110
110
class raw_ostream ;
111
111
@@ -197,6 +197,9 @@ template <typename DataT> class AccelTable : public AccelTableBase {
197
197
198
198
template <typename ... Types>
199
199
void addName (DwarfStringPoolEntryRef Name, Types &&... Args);
200
+ void clear () { Entries.clear (); }
201
+ void addEntries (AccelTable<DataT> &Table);
202
+ const StringEntries getEntries () const { return Entries; }
200
203
};
201
204
202
205
template <typename AccelTableDataT>
@@ -250,11 +253,18 @@ class AppleAccelTableData : public AccelTableData {
250
253
// / emitDWARF5AccelTable function.
251
254
class DWARF5AccelTableData : public AccelTableData {
252
255
public:
256
+ struct AttributeEncoding {
257
+ dwarf::Index Index;
258
+ dwarf::Form Form;
259
+ };
260
+
253
261
static uint32_t hash (StringRef Name) { return caseFoldingDjbHash (Name); }
254
262
255
- DWARF5AccelTableData (const DIE &Die, const DwarfCompileUnit &CU);
256
- DWARF5AccelTableData (uint64_t DieOffset, unsigned DieTag, unsigned CUIndex)
257
- : OffsetVal(DieOffset), DieTag(DieTag), UnitID(CUIndex) {}
263
+ DWARF5AccelTableData (const DIE &Die, const uint32_t UnitID,
264
+ const bool IsTU = false );
265
+ DWARF5AccelTableData (const uint64_t DieOffset, const unsigned DieTag,
266
+ const unsigned UnitID, const bool IsTU = false )
267
+ : OffsetVal(DieOffset), DieTag(DieTag), UnitID(UnitID), IsTU(IsTU) {}
258
268
259
269
#ifndef NDEBUG
260
270
void print (raw_ostream &OS) const override ;
@@ -267,28 +277,66 @@ class DWARF5AccelTableData : public AccelTableData {
267
277
}
268
278
unsigned getDieTag () const { return DieTag; }
269
279
unsigned getUnitID () const { return UnitID; }
280
+ bool isTU () const { return IsTU; }
270
281
void normalizeDIEToOffset () {
271
282
assert (std::holds_alternative<const DIE *>(OffsetVal) &&
272
283
" Accessing offset after normalizing." );
273
284
OffsetVal = std::get<const DIE *>(OffsetVal)->getOffset ();
274
285
}
286
+ bool isNormalized () const {
287
+ return std::holds_alternative<uint64_t >(OffsetVal);
288
+ }
275
289
276
290
protected:
277
291
std::variant<const DIE *, uint64_t > OffsetVal;
278
- unsigned DieTag;
279
- unsigned UnitID;
292
+ uint32_t DieTag : 16 ;
293
+ uint32_t UnitID : 15 ;
294
+ uint32_t IsTU : 1 ;
280
295
281
296
uint64_t order () const override { return getDieOffset (); }
282
297
};
283
298
299
+ struct TypeUnitMetaInfo {
300
+ // Symbol for start of the TU section.
301
+ MCSymbol *Label;
302
+ // Unique ID of Type Unit.
303
+ unsigned UniqueID;
304
+ };
305
+ using TUVectorTy = SmallVector<TypeUnitMetaInfo, 1 >;
284
306
class DWARF5AccelTable : public AccelTable <DWARF5AccelTableData> {
307
+ // Symbols to start of all the TU sections that were generated.
308
+ TUVectorTy TUSymbols;
309
+
285
310
public:
311
+ struct UnitIndexAndEncoding {
312
+ unsigned Index;
313
+ DWARF5AccelTableData::AttributeEncoding Endoding;
314
+ };
315
+ // / Returns type units that were constructed.
316
+ const TUVectorTy &getTypeUnitsSymbols () { return TUSymbols; }
317
+ // / Add a type unit start symbol.
318
+ void addTypeUnitSymbol (DwarfTypeUnit &U);
286
319
// / Convert DIE entries to explicit offset.
287
320
// / Needs to be called after DIE offsets are computed.
288
321
void convertDieToOffset () {
289
322
for (auto &Entry : Entries) {
290
323
for (AccelTableData *Value : Entry.second .Values ) {
291
- static_cast <DWARF5AccelTableData *>(Value)->normalizeDIEToOffset ();
324
+ DWARF5AccelTableData *Data = static_cast <DWARF5AccelTableData *>(Value);
325
+ // For TU we normalize as each Unit is emitted.
326
+ // So when this is invoked after CU construction we will be in mixed
327
+ // state.
328
+ if (!Data->isNormalized ())
329
+ Data->normalizeDIEToOffset ();
330
+ }
331
+ }
332
+ }
333
+
334
+ void addTypeEntries (DWARF5AccelTable &Table) {
335
+ for (auto &Entry : Table.getEntries ()) {
336
+ for (AccelTableData *Value : Entry.second .Values ) {
337
+ DWARF5AccelTableData *Data = static_cast <DWARF5AccelTableData *>(Value);
338
+ addName (Entry.second .Name , Data->getDieOffset (), Data->getDieTag (),
339
+ Data->getUnitID (), true );
292
340
}
293
341
}
294
342
}
@@ -319,8 +367,9 @@ void emitDWARF5AccelTable(AsmPrinter *Asm, DWARF5AccelTable &Contents,
319
367
void emitDWARF5AccelTable (
320
368
AsmPrinter *Asm, DWARF5AccelTable &Contents,
321
369
ArrayRef<std::variant<MCSymbol *, uint64_t >> CUs,
322
- llvm::function_ref<unsigned (const DWARF5AccelTableData &)>
323
- getCUIndexForEntry);
370
+ llvm::function_ref<std::optional<DWARF5AccelTable::UnitIndexAndEncoding>(
371
+ const DWARF5AccelTableData &)>
372
+ getIndexForEntry);
324
373
325
374
// / Accelerator table data implementation for simple Apple accelerator tables
326
375
// / with just a DIE reference.
0 commit comments