Skip to content

Commit 47f615e

Browse files
committed
DebugInfo: Introduce new DIValue, DIETypeSignature to encode references to type units via their signatures
This simplifies type unit and type unit reference creation as well as setting the stage for inter-type hashing across type unit boundaries. llvm-svn: 197539
1 parent c2e60f5 commit 47f615e

File tree

6 files changed

+61
-36
lines changed

6 files changed

+61
-36
lines changed

llvm/lib/CodeGen/AsmPrinter/DIE.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "DIE.h"
1515
#include "DwarfDebug.h"
16+
#include "DwarfUnit.h"
1617
#include "llvm/ADT/Twine.h"
1718
#include "llvm/CodeGen/AsmPrinter.h"
1819
#include "llvm/IR/DataLayout.h"
@@ -403,6 +404,22 @@ void DIEEntry::print(raw_ostream &O) const {
403404
}
404405
#endif
405406

407+
//===----------------------------------------------------------------------===//
408+
// DIETypeSignature Implementation
409+
//===----------------------------------------------------------------------===//
410+
void DIETypeSignature::EmitValue(AsmPrinter *Asm, dwarf::Form Form) const {
411+
assert(Form == dwarf::DW_FORM_ref_sig8);
412+
Asm->OutStreamer.EmitIntValue(Unit.getTypeSignature(), 8);
413+
}
414+
415+
#ifndef NDEBUG
416+
void DIETypeSignature::print(raw_ostream &O) const {
417+
O << format("Type Unit: 0x%lx", Unit.getTypeSignature());
418+
}
419+
420+
void DIETypeSignature::dump() const { print(dbgs()); }
421+
#endif
422+
406423
//===----------------------------------------------------------------------===//
407424
// DIEBlock Implementation
408425
//===----------------------------------------------------------------------===//

llvm/lib/CodeGen/AsmPrinter/DIE.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace llvm {
2626
class MCSymbol;
2727
class MCSymbolRefExpr;
2828
class raw_ostream;
29+
class DwarfTypeUnit;
2930

3031
//===--------------------------------------------------------------------===//
3132
/// DIEAbbrevData - Dwarf abbreviation data, describes one attribute of a
@@ -195,6 +196,7 @@ namespace llvm {
195196
isLabel,
196197
isDelta,
197198
isEntry,
199+
isTypeSignature,
198200
isBlock
199201
};
200202
protected:
@@ -411,6 +413,33 @@ namespace llvm {
411413
#endif
412414
};
413415

416+
//===--------------------------------------------------------------------===//
417+
/// \brief A signature reference to a type unit.
418+
class DIETypeSignature : public DIEValue {
419+
const DwarfTypeUnit &Unit;
420+
public:
421+
explicit DIETypeSignature(const DwarfTypeUnit &Unit)
422+
: DIEValue(isTypeSignature), Unit(Unit) {}
423+
424+
/// \brief Emit type unit signature.
425+
virtual void EmitValue(AsmPrinter *Asm, dwarf::Form Form) const;
426+
427+
/// Returns size of a ref_sig8 entry.
428+
virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
429+
assert(Form == dwarf::DW_FORM_ref_sig8);
430+
return 8;
431+
}
432+
433+
// \brief Implement isa/cast/dyncast.
434+
static bool classof(const DIEValue *E) {
435+
return E->getType() == isTypeSignature;
436+
}
437+
#ifndef NDEBUG
438+
virtual void print(raw_ostream &O) const;
439+
void dump() const;
440+
#endif
441+
};
442+
414443
//===--------------------------------------------------------------------===//
415444
/// DIEBlock - A block of values. Primarily used for location expressions.
416445
//

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,35 +3015,18 @@ void DwarfDebug::emitDebugStrDWO() {
30153015

30163016
void DwarfDebug::addDwarfTypeUnitType(uint16_t Language, DIE *RefDie,
30173017
DICompositeType CTy) {
3018-
DenseMap<const MDNode *,
3019-
std::pair<uint64_t, SmallVectorImpl<DIE *> *> >::iterator I =
3020-
DwarfTypeUnits.find(CTy);
3021-
SmallVector<DIE *, 8> References;
3022-
References.push_back(RefDie);
3023-
if (I != DwarfTypeUnits.end()) {
3024-
if (I->second.second) {
3025-
I->second.second->push_back(RefDie);
3026-
return;
3027-
}
3028-
} else {
3018+
const DwarfTypeUnit *&TU = DwarfTypeUnits[CTy];
3019+
if (!TU) {
30293020
DIE *UnitDie = new DIE(dwarf::DW_TAG_type_unit);
30303021
DwarfTypeUnit *NewTU =
30313022
new DwarfTypeUnit(InfoHolder.getUnits().size(), UnitDie, Language, Asm,
30323023
this, &InfoHolder);
3024+
TU = NewTU;
30333025
InfoHolder.addUnit(NewTU);
30343026

30353027
NewTU->addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
30363028
Language);
30373029

3038-
// Register the type in the DwarfTypeUnits map with a vector of references
3039-
// to be
3040-
// populated whenever a reference is required.
3041-
I = DwarfTypeUnits.insert(std::make_pair(
3042-
CTy, std::make_pair(0, &References))).first;
3043-
3044-
// Construct the type, this may, recursively, require more type units that
3045-
// may in turn require this type again - in which case they will add DIEs to
3046-
// the References vector.
30473030
DIE *Die = NewTU->createTypeDIE(CTy);
30483031

30493032
if (GenerateODRHash && shouldAddODRHash(NewTU, Die))
@@ -3059,19 +3042,11 @@ void DwarfDebug::addDwarfTypeUnitType(uint16_t Language, DIE *RefDie,
30593042
NewTU->setTypeSignature(Signature);
30603043
NewTU->setType(Die);
30613044

3062-
// Remove the References vector and add the type hash.
3063-
I->second.first = Signature;
3064-
I->second.second = NULL;
3065-
30663045
NewTU->initSection(
30673046
useSplitDwarf()
30683047
? Asm->getObjFileLowering().getDwarfTypesDWOSection(Signature)
30693048
: Asm->getObjFileLowering().getDwarfTypesSection(Signature));
30703049
}
30713050

3072-
// Populate all the signatures.
3073-
for (unsigned i = 0, e = References.size(); i != e; ++i) {
3074-
CUMap.begin()->second->addUInt(References[i], dwarf::DW_AT_signature,
3075-
dwarf::DW_FORM_ref_sig8, I->second.first);
3076-
}
3051+
CUMap.begin()->second->addDIETypeSignature(RefDie, *TU);
30773052
}

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,9 @@ class DwarfDebug : public AsmPrinterHandler {
450450
ImportedEntityMap;
451451
ImportedEntityMap ScopesWithImportedEntities;
452452

453-
// Map from type MDNodes to a pair used as a union. If the pointer is
454-
// non-null, proxy DIEs in CUs meant to reference this type should be stored
455-
// in the vector. The hash will be added to these DIEs once it is computed. If
456-
// the pointer is null, the hash is immediately available in the uint64_t and
457-
// should be directly used for proxy DIEs.
458-
DenseMap<const MDNode *, std::pair<uint64_t, SmallVectorImpl<DIE *> *> >
459-
DwarfTypeUnits;
453+
// Map from MDNodes for user-defined types to the type units that describe
454+
// them.
455+
DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
460456

461457
// Whether to emit the pubnames/pubtypes sections.
462458
bool HasDwarfPubSections;

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ void DwarfUnit::addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIE *Entry) {
322322
addDIEEntry(Die, Attribute, createDIEEntry(Entry));
323323
}
324324

325+
void DwarfUnit::addDIETypeSignature(DIE *Die, const DwarfTypeUnit &Type) {
326+
Die->addValue(dwarf::DW_AT_signature, dwarf::DW_FORM_ref_sig8,
327+
new (DIEValueAllocator) DIETypeSignature(Type));
328+
}
329+
325330
void DwarfUnit::addDIEEntry(DIE *Die, dwarf::Attribute Attribute,
326331
DIEEntry *Entry) {
327332
const DIE *DieCU = Die->getUnitOrNull();

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ class DwarfUnit {
319319
/// addDIEEntry - Add a DIE attribute data and value.
320320
void addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIEEntry *Entry);
321321

322+
void addDIETypeSignature(DIE *Die, const DwarfTypeUnit &Type);
323+
322324
/// addBlock - Add block data.
323325
void addBlock(DIE *Die, dwarf::Attribute Attribute, DIEBlock *Block);
324326

@@ -524,6 +526,7 @@ class DwarfTypeUnit : public DwarfUnit {
524526
virtual ~DwarfTypeUnit() LLVM_OVERRIDE;
525527

526528
void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; }
529+
uint64_t getTypeSignature() const { return TypeSignature; }
527530
void setType(const DIE *Ty) { this->Ty = Ty; }
528531

529532
uint16_t getLanguage() const LLVM_OVERRIDE { return Language; }

0 commit comments

Comments
 (0)