summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-04-22 21:27:37 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-04-22 21:27:37 +0000
commit0eb05e272ae10bc8c5530740914e1fb9e9052db1 (patch)
tree5b650bf6eae1d8acba00c19ce11244d2a1ea7856
parent44fa7c35ee64fbfb655825be613eaf125d3323e5 (diff)
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) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206921 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfDebug.cpp45
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfDebug.h11
2 files changed, 30 insertions, 26 deletions
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 7f1bebaf124..0638f31e112 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -225,9 +225,9 @@ static MCSymbol *emitSectionSym(AsmPrinter *Asm, const MCSection *Section,
return TmpSym;
}
+DwarfFile::DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
+ : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref) {}
DwarfFile::~DwarfFile() {
- for (DwarfUnit *DU : CUs)
- delete DU;
}
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) {
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
// all other generation.
- for (DwarfUnit *TheU : getUnits()) {
+ for (const auto &TheU : getUnits()) {
// Emit DW_AT_containing_type attribute to connect types with their
// vtable holding type.
TheU->constructContainingTypeDIEs();
@@ -964,26 +968,27 @@ void DwarfDebug::finalizeModuleInfo() {
// FIXME: We should use ranges allow reordering of code ala
// .subsections_via_symbols in mach-o. This would mean turning on
// 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();
if (NumRanges) {
if (NumRanges > 1) {
- addSectionLabel(Asm, U, U->getUnitDie(), dwarf::DW_AT_ranges,
- Asm->GetTempSymbol("cu_ranges", U->getUniqueID()),
+ addSectionLabel(Asm, &U, U.getUnitDie(), dwarf::DW_AT_ranges,
+ Asm->GetTempSymbol("cu_ranges", U.getUniqueID()),
DwarfDebugRangeSectionSym);
// 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
// location lists (see Section 2.6.2) and range lists (see Section
// 2.17.3).
- U->addUInt(U->getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
- 0);
+ U.addUInt(U.getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
+ 0);
} else {
RangeSpan &Range = TheU->getRanges().back();
- U->addLocalLabelAddress(U->getUnitDie(), dwarf::DW_AT_low_pc,
- Range.getStart());
- U->addLabelDelta(U->getUnitDie(), dwarf::DW_AT_high_pc,
- Range.getEnd(), Range.getStart());
+ U.addLocalLabelAddress(U.getUnitDie(), dwarf::DW_AT_low_pc,
+ Range.getStart());
+ U.addLabelDelta(U.getUnitDie(), dwarf::DW_AT_high_pc, Range.getEnd(),
+ Range.getStart());
}
}
}
@@ -1776,8 +1781,8 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
llvm_unreachable("Unexpected scope info");
unsigned CUID = Asm->OutStreamer.getContext().getDwarfCompileUnitID();
- Src = static_cast<DwarfCompileUnit *>(InfoHolder.getUnits()[CUID])
- ->getOrCreateSourceID(Fn, Dir);
+ Src = static_cast<DwarfCompileUnit &>(*InfoHolder.getUnits()[CUID])
+ .getOrCreateSourceID(Fn, Dir);
}
Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, Flags, 0,
Discriminator, Fn);
@@ -1835,7 +1840,7 @@ void DwarfFile::computeSizeAndOffsets() {
// Iterate over each compile unit and set the size and offsets for each
// DIE within each compile unit. All offsets are CU relative.
- for (DwarfUnit *TheU : CUs) {
+ for (const auto &TheU : CUs) {
TheU->setDebugInfoOffset(SecOffset);
// 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
// the abbreviations going into ASection.
void DwarfFile::emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym) {
- for (DwarfUnit *TheU : CUs) {
+ for (const auto &TheU : CUs) {
DIE *Die = TheU->getUnitDie();
const MCSection *USection = TheU->getSection();
Asm->OutStreamer.SwitchSection(USection);
@@ -2022,7 +2027,7 @@ void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) {
void DwarfDebug::emitAccelNames() {
DwarfAccelTable AT(
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()) {
StringRef Name = GI.getKey();
for (const DIE *D : GI.second)
@@ -2045,7 +2050,7 @@ void DwarfDebug::emitAccelNames() {
void DwarfDebug::emitAccelObjC() {
DwarfAccelTable AT(
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()) {
StringRef Name = GI.getKey();
for (const DIE *D : GI.second)
@@ -2067,7 +2072,7 @@ void DwarfDebug::emitAccelObjC() {
void DwarfDebug::emitAccelNamespaces() {
DwarfAccelTable AT(
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()) {
StringRef Name = GI.getKey();
for (const DIE *D : GI.second)
@@ -2095,7 +2100,7 @@ void DwarfDebug::emitAccelTypes() {
Atoms.push_back(
DwarfAccelTable::Atom(dwarf::DW_ATOM_type_flags, dwarf::DW_FORM_data1));
DwarfAccelTable AT(Atoms);
- for (DwarfUnit *TheU : getUnits()) {
+ for (const auto &TheU : getUnits()) {
for (const auto &GI : TheU->getAccelTypes()) {
StringRef Name = GI.getKey();
for (const auto &DI : GI.second)
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h
index 363d7650e0b..521a62310ae 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -145,7 +145,7 @@ class DwarfFile {
std::vector<DIEAbbrev *> Abbreviations;
// 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.
// A String->Symbol mapping of strings used by indirect
@@ -168,12 +168,11 @@ class DwarfFile {
AddrPool AddressPool;
public:
- DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
- : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref) {}
+ DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA);
~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.
unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
@@ -185,7 +184,7 @@ public:
void assignAbbrevNumber(DIEAbbrev &Abbrev);
/// \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
/// abbreviation section.
@@ -413,7 +412,7 @@ class DwarfDebug : public AsmPrinterHandler {
void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
- const SmallVectorImpl<DwarfUnit *> &getUnits() {
+ const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() {
return InfoHolder.getUnits();
}