diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-01-03 04:49:04 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-01-03 04:49:04 +0000 |
commit | ab0ba249835992e07310a7664f7f4763bfb0a767 (patch) | |
tree | 62fd8b11dd03653b9d48a6080816a28d7cd08c1a /llvm/lib/CodeGen | |
parent | ddb66281cd881b674f86c2798b9c99cac0adc202 (diff) | |
download | bcm5719-llvm-ab0ba249835992e07310a7664f7f4763bfb0a767.tar.gz bcm5719-llvm-ab0ba249835992e07310a7664f7f4763bfb0a767.zip |
Revert "Debug Info: Type Units: Simplify type hashing using IR-provided unique names."
Reverting due to bot failure I won't have time to investigate until
tomorrow.
This reverts commit r198397.
llvm-svn: 198398
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 62 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 47 |
3 files changed, 93 insertions, 19 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index e8e1e50c9b9..a0052f605d7 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -58,6 +58,11 @@ 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)); @@ -1014,6 +1019,41 @@ 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(); @@ -3001,8 +3041,8 @@ void DwarfDebug::emitDebugStrDWO() { OffSec, StrSym); } -void DwarfDebug::addDwarfTypeUnitType(uint16_t Language, StringRef Identifier, - DIE *RefDie, DICompositeType CTy) { +void DwarfDebug::addDwarfTypeUnitType(uint16_t Language, DIE *RefDie, + DICompositeType CTy) { const DwarfTypeUnit *&TU = DwarfTypeUnits[CTy]; if (!TU) { DIE *UnitDie = new DIE(dwarf::DW_TAG_type_unit); @@ -3017,14 +3057,16 @@ void DwarfDebug::addDwarfTypeUnitType(uint16_t Language, StringRef Identifier, DIE *Die = NewTU->createTypeDIE(CTy); - 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); + 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); NewTU->setTypeSignature(Signature); NewTU->setType(Die); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h index 84d9cae7a1d..b81688ea3f0 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -695,8 +695,7 @@ public: /// \brief Add a DIE to the set of types that we're going to pull into /// type units. - void addDwarfTypeUnitType(uint16_t Language, StringRef Identifier, DIE *Die, - DICompositeType CTy); + void addDwarfTypeUnitType(uint16_t Language, DIE *Die, DICompositeType CTy); /// \brief Add a label so that arange data can be generated for it. void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 7de4b1e1875..0e3db3c5085 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -928,6 +928,41 @@ DIE *DwarfUnit::createTypeDIE(DICompositeType Ty) { return TyDIE; } +/// Return true if the type is appropriately scoped to be contained inside +/// its own type unit. +static bool isDwarfTypeUnitScoped(DIType Ty, const DwarfDebug *DD) { + DIScope Parent = DD->resolve(Ty.getContext()); + while (Parent) { + // Don't generate a hash for anything scoped inside a function. + if (Parent.isSubprogram()) + return false; + Parent = DD->resolve(Parent.getContext()); + } + return true; +} + +/// Return true if the type should be split out into a type unit. +static bool shouldCreateDwarfTypeUnit(DICompositeType CTy, + const DwarfDebug *DD) { + if (!GenerateDwarfTypeUnits) + return false; + + uint16_t Tag = CTy.getTag(); + + switch (Tag) { + case dwarf::DW_TAG_structure_type: + case dwarf::DW_TAG_union_type: + case dwarf::DW_TAG_enumeration_type: + case dwarf::DW_TAG_class_type: + // If this is a class, structure, union, or enumeration type + // that is a definition (not a declaration), and not scoped + // inside a function then separate this out as a type unit. + return !CTy.isForwardDecl() && isDwarfTypeUnitScoped(CTy, DD); + default: + return false; + } +} + /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the /// given DIType. DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) { @@ -954,13 +989,11 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) { constructTypeDIE(*TyDIE, DIBasicType(Ty)); else if (Ty.isCompositeType()) { DICompositeType CTy(Ty); - if (GenerateDwarfTypeUnits && !Ty.isForwardDecl()) - if (MDString *TypeId = CTy.getIdentifier()) { - DD->addDwarfTypeUnitType(getLanguage(), TypeId->getString(), TyDIE, - CTy); - // Skip updating the accellerator tables since this is not the full type - return TyDIE; - } + if (shouldCreateDwarfTypeUnit(CTy, DD)) { + DD->addDwarfTypeUnitType(getLanguage(), TyDIE, CTy); + // Skip updating the accellerator tables since this is not the full type + return TyDIE; + } constructTypeDIE(*TyDIE, CTy); } else { assert(Ty.isDerivedType() && "Unknown kind of DIType"); |