Use std::unique_ptr to handle ownership of DwarfUnits in DwarfFile.

So Chandler - how about those range algorithms? (would really love a
dereferencing range adapter for this sort of stuff)

llvm-svn: 206921
This commit is contained in:
David Blaikie 2014-04-22 21:27:37 +00:00
parent 2962a8cf09
commit ef0c701473
2 changed files with 30 additions and 26 deletions

View File

@ -225,9 +225,9 @@ static MCSymbol *emitSectionSym(AsmPrinter *Asm, const MCSection *Section,
return TmpSym; return TmpSym;
} }
DwarfFile::DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
: Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref) {}
DwarfFile::~DwarfFile() { DwarfFile::~DwarfFile() {
for (DwarfUnit *DU : CUs)
delete DU;
} }
MCSymbol *DwarfFile::getStringPoolSym() { MCSymbol *DwarfFile::getStringPoolSym() {
@ -280,6 +280,10 @@ void DwarfFile::assignAbbrevNumber(DIEAbbrev &Abbrev) {
} }
} }
void DwarfFile::addUnit(DwarfUnit *CU) {
CUs.push_back(std::unique_ptr<DwarfUnit>(CU));
}
static bool isObjCClass(StringRef Name) { static bool isObjCClass(StringRef Name) {
return Name.startswith("+") || Name.startswith("-"); return Name.startswith("+") || Name.startswith("-");
} }
@ -927,7 +931,7 @@ void DwarfDebug::finalizeModuleInfo() {
// Handle anything that needs to be done on a per-unit basis after // Handle anything that needs to be done on a per-unit basis after
// all other generation. // all other generation.
for (DwarfUnit *TheU : getUnits()) { for (const auto &TheU : getUnits()) {
// Emit DW_AT_containing_type attribute to connect types with their // Emit DW_AT_containing_type attribute to connect types with their
// vtable holding type. // vtable holding type.
TheU->constructContainingTypeDIEs(); TheU->constructContainingTypeDIEs();
@ -964,26 +968,27 @@ void DwarfDebug::finalizeModuleInfo() {
// FIXME: We should use ranges allow reordering of code ala // FIXME: We should use ranges allow reordering of code ala
// .subsections_via_symbols in mach-o. This would mean turning on // .subsections_via_symbols in mach-o. This would mean turning on
// ranges for all subprogram DIEs for mach-o. // ranges for all subprogram DIEs for mach-o.
DwarfCompileUnit *U = SkCU ? SkCU : static_cast<DwarfCompileUnit *>(TheU); DwarfCompileUnit &U =
SkCU ? *SkCU : static_cast<DwarfCompileUnit &>(*TheU);
unsigned NumRanges = TheU->getRanges().size(); unsigned NumRanges = TheU->getRanges().size();
if (NumRanges) { if (NumRanges) {
if (NumRanges > 1) { if (NumRanges > 1) {
addSectionLabel(Asm, U, U->getUnitDie(), dwarf::DW_AT_ranges, addSectionLabel(Asm, &U, U.getUnitDie(), dwarf::DW_AT_ranges,
Asm->GetTempSymbol("cu_ranges", U->getUniqueID()), Asm->GetTempSymbol("cu_ranges", U.getUniqueID()),
DwarfDebugRangeSectionSym); DwarfDebugRangeSectionSym);
// A DW_AT_low_pc attribute may also be specified in combination with // A DW_AT_low_pc attribute may also be specified in combination with
// DW_AT_ranges to specify the default base address for use in // DW_AT_ranges to specify the default base address for use in
// location lists (see Section 2.6.2) and range lists (see Section // location lists (see Section 2.6.2) and range lists (see Section
// 2.17.3). // 2.17.3).
U->addUInt(U->getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, U.addUInt(U.getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
0); 0);
} else { } else {
RangeSpan &Range = TheU->getRanges().back(); RangeSpan &Range = TheU->getRanges().back();
U->addLocalLabelAddress(U->getUnitDie(), dwarf::DW_AT_low_pc, U.addLocalLabelAddress(U.getUnitDie(), dwarf::DW_AT_low_pc,
Range.getStart()); Range.getStart());
U->addLabelDelta(U->getUnitDie(), dwarf::DW_AT_high_pc, U.addLabelDelta(U.getUnitDie(), dwarf::DW_AT_high_pc, Range.getEnd(),
Range.getEnd(), Range.getStart()); Range.getStart());
} }
} }
} }
@ -1776,8 +1781,8 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
llvm_unreachable("Unexpected scope info"); llvm_unreachable("Unexpected scope info");
unsigned CUID = Asm->OutStreamer.getContext().getDwarfCompileUnitID(); unsigned CUID = Asm->OutStreamer.getContext().getDwarfCompileUnitID();
Src = static_cast<DwarfCompileUnit *>(InfoHolder.getUnits()[CUID]) Src = static_cast<DwarfCompileUnit &>(*InfoHolder.getUnits()[CUID])
->getOrCreateSourceID(Fn, Dir); .getOrCreateSourceID(Fn, Dir);
} }
Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, Flags, 0, Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, Flags, 0,
Discriminator, Fn); Discriminator, Fn);
@ -1835,7 +1840,7 @@ void DwarfFile::computeSizeAndOffsets() {
// Iterate over each compile unit and set the size and offsets for each // Iterate over each compile unit and set the size and offsets for each
// DIE within each compile unit. All offsets are CU relative. // DIE within each compile unit. All offsets are CU relative.
for (DwarfUnit *TheU : CUs) { for (const auto &TheU : CUs) {
TheU->setDebugInfoOffset(SecOffset); TheU->setDebugInfoOffset(SecOffset);
// CU-relative offset is reset to 0 here. // CU-relative offset is reset to 0 here.
@ -1941,7 +1946,7 @@ void DwarfDebug::emitDIE(DIE &Die) {
// Emit the various dwarf units to the unit section USection with // Emit the various dwarf units to the unit section USection with
// the abbreviations going into ASection. // the abbreviations going into ASection.
void DwarfFile::emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym) { void DwarfFile::emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym) {
for (DwarfUnit *TheU : CUs) { for (const auto &TheU : CUs) {
DIE *Die = TheU->getUnitDie(); DIE *Die = TheU->getUnitDie();
const MCSection *USection = TheU->getSection(); const MCSection *USection = TheU->getSection();
Asm->OutStreamer.SwitchSection(USection); Asm->OutStreamer.SwitchSection(USection);
@ -2022,7 +2027,7 @@ void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) {
void DwarfDebug::emitAccelNames() { void DwarfDebug::emitAccelNames() {
DwarfAccelTable AT( DwarfAccelTable AT(
DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4)); DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4));
for (DwarfUnit *TheU : getUnits()) { for (const auto &TheU : getUnits()) {
for (const auto &GI : TheU->getAccelNames()) { for (const auto &GI : TheU->getAccelNames()) {
StringRef Name = GI.getKey(); StringRef Name = GI.getKey();
for (const DIE *D : GI.second) for (const DIE *D : GI.second)
@ -2045,7 +2050,7 @@ void DwarfDebug::emitAccelNames() {
void DwarfDebug::emitAccelObjC() { void DwarfDebug::emitAccelObjC() {
DwarfAccelTable AT( DwarfAccelTable AT(
DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4)); DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4));
for (DwarfUnit *TheU : getUnits()) { for (const auto &TheU : getUnits()) {
for (const auto &GI : TheU->getAccelObjC()) { for (const auto &GI : TheU->getAccelObjC()) {
StringRef Name = GI.getKey(); StringRef Name = GI.getKey();
for (const DIE *D : GI.second) for (const DIE *D : GI.second)
@ -2067,7 +2072,7 @@ void DwarfDebug::emitAccelObjC() {
void DwarfDebug::emitAccelNamespaces() { void DwarfDebug::emitAccelNamespaces() {
DwarfAccelTable AT( DwarfAccelTable AT(
DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4)); DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4));
for (DwarfUnit *TheU : getUnits()) { for (const auto &TheU : getUnits()) {
for (const auto &GI : TheU->getAccelNamespace()) { for (const auto &GI : TheU->getAccelNamespace()) {
StringRef Name = GI.getKey(); StringRef Name = GI.getKey();
for (const DIE *D : GI.second) for (const DIE *D : GI.second)
@ -2095,7 +2100,7 @@ void DwarfDebug::emitAccelTypes() {
Atoms.push_back( Atoms.push_back(
DwarfAccelTable::Atom(dwarf::DW_ATOM_type_flags, dwarf::DW_FORM_data1)); DwarfAccelTable::Atom(dwarf::DW_ATOM_type_flags, dwarf::DW_FORM_data1));
DwarfAccelTable AT(Atoms); DwarfAccelTable AT(Atoms);
for (DwarfUnit *TheU : getUnits()) { for (const auto &TheU : getUnits()) {
for (const auto &GI : TheU->getAccelTypes()) { for (const auto &GI : TheU->getAccelTypes()) {
StringRef Name = GI.getKey(); StringRef Name = GI.getKey();
for (const auto &DI : GI.second) for (const auto &DI : GI.second)

View File

@ -145,7 +145,7 @@ class DwarfFile {
std::vector<DIEAbbrev *> Abbreviations; std::vector<DIEAbbrev *> Abbreviations;
// A pointer to all units in the section. // A pointer to all units in the section.
SmallVector<DwarfUnit *, 1> CUs; SmallVector<std::unique_ptr<DwarfUnit>, 1> CUs;
// Collection of strings for this unit and assorted symbols. // Collection of strings for this unit and assorted symbols.
// A String->Symbol mapping of strings used by indirect // A String->Symbol mapping of strings used by indirect
@ -168,12 +168,11 @@ class DwarfFile {
AddrPool AddressPool; AddrPool AddressPool;
public: public:
DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA) DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA);
: Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref) {}
~DwarfFile(); ~DwarfFile();
const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; } const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; }
/// \brief Compute the size and offset of a DIE given an incoming Offset. /// \brief Compute the size and offset of a DIE given an incoming Offset.
unsigned computeSizeAndOffset(DIE &Die, unsigned Offset); unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
@ -185,7 +184,7 @@ public:
void assignAbbrevNumber(DIEAbbrev &Abbrev); void assignAbbrevNumber(DIEAbbrev &Abbrev);
/// \brief Add a unit to the list of CUs. /// \brief Add a unit to the list of CUs.
void addUnit(DwarfUnit *CU) { CUs.push_back(CU); } void addUnit(DwarfUnit *CU);
/// \brief Emit all of the units to the section listed with the given /// \brief Emit all of the units to the section listed with the given
/// abbreviation section. /// abbreviation section.
@ -413,7 +412,7 @@ class DwarfDebug : public AsmPrinterHandler {
void addScopeVariable(LexicalScope *LS, DbgVariable *Var); void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
const SmallVectorImpl<DwarfUnit *> &getUnits() { const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() {
return InfoHolder.getUnits(); return InfoHolder.getUnits();
} }