Refactor out the abbreviation handling into a separate class that

controls each of the abbreviation sets (only a single one at the
moment) and computes offsets separately as well for each set
of DIEs.

No real function change, ordering of abbreviations for the skeleton
CU changed but only because we're computing in a separate order. Fix
the testcase not to care.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169793 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Christopher 2012-12-10 23:34:43 +00:00
parent 376642ed62
commit 0e3e9b79f6
3 changed files with 58 additions and 25 deletions

View File

@ -156,7 +156,9 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
: Asm(A), MMI(Asm->MMI), FirstCU(0), : Asm(A), MMI(Asm->MMI), FirstCU(0),
AbbreviationsSet(InitAbbreviationsSetSize), AbbreviationsSet(InitAbbreviationsSetSize),
SourceIdMap(DIEValueAllocator), StringPool(DIEValueAllocator), SourceIdMap(DIEValueAllocator), StringPool(DIEValueAllocator),
PrevLabel(NULL), GlobalCUIndexCount(0), SkeletonCU(0) { PrevLabel(NULL), GlobalCUIndexCount(0),
InfoHolder(A, &AbbreviationsSet, &Abbreviations),
SkeletonCU(0), SkeletonHolder(A, &AbbreviationsSet, &Abbreviations) {
NextStringPoolNumber = 0; NextStringPoolNumber = 0;
DwarfInfoSectionSym = DwarfAbbrevSectionSym = 0; DwarfInfoSectionSym = DwarfAbbrevSectionSym = 0;
@ -222,21 +224,21 @@ MCSymbol *DwarfDebug::getStringPoolEntry(StringRef Str) {
// Define a unique number for the abbreviation. // Define a unique number for the abbreviation.
// //
void DwarfDebug::assignAbbrevNumber(DIEAbbrev &Abbrev) { void DwarfUnits::assignAbbrevNumber(DIEAbbrev &Abbrev) {
// Profile the node so that we can make it unique. // Profile the node so that we can make it unique.
FoldingSetNodeID ID; FoldingSetNodeID ID;
Abbrev.Profile(ID); Abbrev.Profile(ID);
// Check the set for priors. // Check the set for priors.
DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev); DIEAbbrev *InSet = AbbreviationsSet->GetOrInsertNode(&Abbrev);
// If it's newly added. // If it's newly added.
if (InSet == &Abbrev) { if (InSet == &Abbrev) {
// Add to abbreviation list. // Add to abbreviation list.
Abbreviations.push_back(&Abbrev); Abbreviations->push_back(&Abbrev);
// Assign the vector position + 1 as its number. // Assign the vector position + 1 as its number.
Abbrev.setNumber(Abbreviations.size()); Abbrev.setNumber(Abbreviations->size());
} else { } else {
// Assign existing abbreviation number. // Assign existing abbreviation number.
Abbrev.setNumber(InSet->getNumber()); Abbrev.setNumber(InSet->getNumber());
@ -655,6 +657,8 @@ CompileUnit *DwarfDebug::constructCompileUnit(const MDNode *N) {
if (useSplitDwarf() && !SkeletonCU) if (useSplitDwarf() && !SkeletonCU)
SkeletonCU = constructSkeletonCU(N); SkeletonCU = constructSkeletonCU(N);
InfoHolder.addUnit(NewCU);
CUMap.insert(std::make_pair(N, NewCU)); CUMap.insert(std::make_pair(N, NewCU));
return NewCU; return NewCU;
} }
@ -871,7 +875,9 @@ void DwarfDebug::finalizeModuleInfo() {
} }
// Compute DIE offsets and sizes. // Compute DIE offsets and sizes.
computeSizeAndOffsets(); InfoHolder.computeSizeAndOffsets();
if (useSplitDwarf())
SkeletonHolder.computeSizeAndOffsets();
} }
void DwarfDebug::endSections() { void DwarfDebug::endSections() {
@ -1635,7 +1641,7 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
// Compute the size and offset of a DIE. // Compute the size and offset of a DIE.
unsigned unsigned
DwarfDebug::computeSizeAndOffset(DIE *Die, unsigned Offset) { DwarfUnits::computeSizeAndOffset(DIE *Die, unsigned Offset) {
// Get the children. // Get the children.
const std::vector<DIE *> &Children = Die->getChildren(); const std::vector<DIE *> &Children = Die->getChildren();
@ -1644,7 +1650,7 @@ DwarfDebug::computeSizeAndOffset(DIE *Die, unsigned Offset) {
// Get the abbreviation for this DIE. // Get the abbreviation for this DIE.
unsigned AbbrevNumber = Die->getAbbrevNumber(); unsigned AbbrevNumber = Die->getAbbrevNumber();
const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; const DIEAbbrev *Abbrev = Abbreviations->at(AbbrevNumber - 1);
// Set DIE offset // Set DIE offset
Die->setOffset(Offset); Die->setOffset(Offset);
@ -1677,25 +1683,16 @@ DwarfDebug::computeSizeAndOffset(DIE *Die, unsigned Offset) {
} }
// Compute the size and offset of all the DIEs. // Compute the size and offset of all the DIEs.
void DwarfDebug::computeSizeAndOffsets() { void DwarfUnits::computeSizeAndOffsets() {
if (SkeletonCU) { for (SmallVector<CompileUnit *, 1>::iterator I = CUs.begin(),
E = CUs.end(); I != E; ++I) {
unsigned Offset = unsigned Offset =
sizeof(int32_t) + // Length of Compilation Unit Info sizeof(int32_t) + // Length of Compilation Unit Info
sizeof(int16_t) + // DWARF version number sizeof(int16_t) + // DWARF version number
sizeof(int32_t) + // Offset Into Abbrev. Section sizeof(int32_t) + // Offset Into Abbrev. Section
sizeof(int8_t); // Pointer Size (in bytes) sizeof(int8_t); // Pointer Size (in bytes)
computeSizeAndOffset(SkeletonCU->getCUDie(), Offset); computeSizeAndOffset((*I)->getCUDie(), Offset);
}
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
E = CUMap.end(); I != E; ++I) {
// Compute size of compile unit header.
unsigned Offset =
sizeof(int32_t) + // Length of Compilation Unit Info
sizeof(int16_t) + // DWARF version number
sizeof(int32_t) + // Offset Into Abbrev. Section
sizeof(int8_t); // Pointer Size (in bytes)
computeSizeAndOffset(I->second->getCUDie(), Offset);
} }
} }
@ -2351,6 +2348,8 @@ CompileUnit *DwarfDebug::constructSkeletonCU(const MDNode *N) {
if (!CompilationDir.empty()) if (!CompilationDir.empty())
NewCU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir); NewCU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
SkeletonHolder.addUnit(NewCU);
return NewCU; return NewCU;
} }

View File

@ -188,6 +188,39 @@ public:
DIType getType() const; DIType getType() const;
}; };
/// \brief Collects and handles information specific to a particular
/// collection of units.
class DwarfUnits {
// Target of Dwarf emission, used for sizing of abbreviations.
AsmPrinter *Asm;
// Used to uniquely define abbreviations.
FoldingSet<DIEAbbrev> *AbbreviationsSet;
// A list of all the unique abbreviations in use.
std::vector<DIEAbbrev *> *Abbreviations;
// A pointer to all units in the section.
SmallVector<CompileUnit *, 1> CUs;
public:
DwarfUnits(AsmPrinter *AP, FoldingSet<DIEAbbrev> *AS,
std::vector<DIEAbbrev *> *A) :
Asm(AP), AbbreviationsSet(AS), Abbreviations(A) {}
/// \brief Compute the size and offset of a DIE given an incoming Offset.
unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
/// \brief Compute the size and offset of all the DIEs.
void computeSizeAndOffsets();
/// \brief Define a unique number for the abbreviation.
void assignAbbrevNumber(DIEAbbrev &Abbrev);
/// \brief Add a unit to the list of CUs.
void addUnit(CompileUnit *CU) { CUs.push_back(CU); }
};
/// \brief Collects and handles dwarf debug information. /// \brief Collects and handles dwarf debug information.
class DwarfDebug { class DwarfDebug {
// Target of Dwarf emission. // Target of Dwarf emission.
@ -312,6 +345,9 @@ class DwarfDebug {
// Counter for assigning globally unique IDs for CUs. // Counter for assigning globally unique IDs for CUs.
unsigned GlobalCUIndexCount; unsigned GlobalCUIndexCount;
// Holder for the file specific debug information.
DwarfUnits InfoHolder;
// Holders for the various debug information flags that we might need to // Holders for the various debug information flags that we might need to
// have exposed. See accessor functions below for description. // have exposed. See accessor functions below for description.
@ -329,12 +365,10 @@ class DwarfDebug {
// The CU left in the original object file for Fission debug info. // The CU left in the original object file for Fission debug info.
CompileUnit *SkeletonCU; CompileUnit *SkeletonCU;
DwarfUnits SkeletonHolder;
private: private:
/// \brief Define a unique number for the abbreviation.
void assignAbbrevNumber(DIEAbbrev &Abbrev);
void addScopeVariable(LexicalScope *LS, DbgVariable *Var); void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
/// \brief Find abstract variable associated with Var. /// \brief Find abstract variable associated with Var.

View File

@ -19,7 +19,7 @@
; DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_dwo_name, DW_AT_dwo_id, ; DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_dwo_name, DW_AT_dwo_id,
; DW_AT_ranges_base, DW_AT_addr_base. ; DW_AT_ranges_base, DW_AT_addr_base.
; CHECK: DW_TAG_compile_unit [1] ; CHECK: DW_TAG_compile_unit
; CHECK: DW_AT_GNU_dwo_name [DW_FORM_strp] ( .debug_str[0x00000035] = "baz.c") ; CHECK: DW_AT_GNU_dwo_name [DW_FORM_strp] ( .debug_str[0x00000035] = "baz.c")
; CHECK: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000) ; CHECK: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
; CHECK: DW_AT_stmt_list [DW_FORM_data4] (0x00000000) ; CHECK: DW_AT_stmt_list [DW_FORM_data4] (0x00000000)