Debug Info: Type Units: Simplify type hashing using IR-provided unique names.

What's good for LTO metadata size problems ought to be good for non-LTO
debug info size too, so let's rely on the same uniqueness in both cases.
If it's insufficient for non-LTO for whatever reason (since we now won't
be uniquing CU-local types or any C types - but these are likely to not
be the most significant contributors to type bloat) we should consider a
frontend solution that'll help both LTO and non-LTO alike, rather than
using DWARF-level DIE-hashing that only helps non-LTO debug info size.

It's also much simpler this way and benefits C++ even more since we can
deduplicate lexically separate definitions of the same C++ type since
they have the same mangled name.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198397 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie
2014-01-03 04:20:26 +00:00
parent 32abfefd9b
commit 5df1dd410e
5 changed files with 50 additions and 124 deletions

View File

@ -58,11 +58,6 @@ static cl::opt<bool> UnknownLocations(
cl::desc("Make an absence of debug location information explicit."),
cl::init(false));
static cl::opt<bool>
GenerateODRHash("generate-odr-hash", cl::Hidden,
cl::desc("Add an ODR hash to external type DIEs."),
cl::init(false));
static cl::opt<bool> GenerateCUHash("generate-cu-hash", cl::Hidden,
cl::desc("Add the CU hash as the dwo_id."),
cl::init(false));
@ -1019,41 +1014,6 @@ void DwarfDebug::collectDeadVariables() {
}
}
// Type Signature [7.27] and ODR Hash code.
/// \brief Grabs the string in whichever attribute is passed in and returns
/// a reference to it. Returns "" if the attribute doesn't exist.
static StringRef getDIEStringAttr(DIE *Die, unsigned Attr) {
DIEValue *V = Die->findAttribute(Attr);
if (DIEString *S = dyn_cast_or_null<DIEString>(V))
return S->getString();
return StringRef("");
}
/// Return true if the current DIE is contained within an anonymous namespace.
static bool isContainedInAnonNamespace(DIE *Die) {
DIE *Parent = Die->getParent();
while (Parent) {
if (Parent->getTag() == dwarf::DW_TAG_namespace &&
getDIEStringAttr(Parent, dwarf::DW_AT_name) == "")
return true;
Parent = Parent->getParent();
}
return false;
}
/// Test if the current CU language is C++ and that we have
/// a named type that is not contained in an anonymous namespace.
static bool shouldAddODRHash(DwarfTypeUnit *CU, DIE *Die) {
return CU->getLanguage() == dwarf::DW_LANG_C_plus_plus &&
getDIEStringAttr(Die, dwarf::DW_AT_name) != "" &&
!isContainedInAnonNamespace(Die);
}
void DwarfDebug::finalizeModuleInfo() {
// Collect info for variables that were optimized out.
collectDeadVariables();
@ -3041,8 +3001,8 @@ void DwarfDebug::emitDebugStrDWO() {
OffSec, StrSym);
}
void DwarfDebug::addDwarfTypeUnitType(uint16_t Language, DIE *RefDie,
DICompositeType CTy) {
void DwarfDebug::addDwarfTypeUnitType(uint16_t Language, StringRef Identifier,
DIE *RefDie, DICompositeType CTy) {
const DwarfTypeUnit *&TU = DwarfTypeUnits[CTy];
if (!TU) {
DIE *UnitDie = new DIE(dwarf::DW_TAG_type_unit);
@ -3057,16 +3017,14 @@ void DwarfDebug::addDwarfTypeUnitType(uint16_t Language, DIE *RefDie,
DIE *Die = NewTU->createTypeDIE(CTy);
if (GenerateODRHash && shouldAddODRHash(NewTU, Die))
NewTU->addUInt(UnitDie, dwarf::DW_AT_GNU_odr_signature,
dwarf::DW_FORM_data8,
DIEHash().computeDIEODRSignature(*Die));
// FIXME: This won't handle circularly referential structures, as the DIE
// may have references to other DIEs still under construction and missing
// their signature. Hashing should walk through the signatures to their
// referenced type, or possibly walk the precomputed hashes of related types
// at the end.
uint64_t Signature = DIEHash().computeTypeSignature(*Die);
MD5 Hash;
Hash.update(Identifier);
// ... take the least significant 8 bytes and return those. Our MD5
// implementation always returns its results in little endian, swap bytes
// appropriately.
MD5::MD5Result Result;
Hash.final(Result);
uint64_t Signature = *reinterpret_cast<uint64_t *>(Result + 8);
NewTU->setTypeSignature(Signature);
NewTU->setType(Die);