From d48f5efa9db174650d87f5dedc03810998f43960 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 25 Apr 2014 18:52:29 +0000 Subject: [PATCH] DwarfUnit: return by reference from createAndAddDIE Since this doesn't return ownership (the DIE has been added to the specified parent already) nor return null, just return by reference. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207259 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 28 ++++++------ lib/CodeGen/AsmPrinter/DwarfDebug.h | 10 ++--- lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 64 +++++++++++++-------------- lib/CodeGen/AsmPrinter/DwarfUnit.h | 4 +- 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index a8936bad2be..321b6c03bac 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -272,7 +272,7 @@ static bool SectionSort(const MCSection *A, const MCSection *B) { // TODO: Determine whether or not we should add names for programs // that do not have a DW_AT_name or DW_AT_linkage_name field - this // is only slightly different than the lookup of non-standard ObjC names. -void DwarfDebug::addSubprogramNames(DISubprogram SP, DIE *Die) { +void DwarfDebug::addSubprogramNames(DISubprogram SP, DIE &Die) { if (!SP.isDefinition()) return; addAccelName(SP.getName(), Die); @@ -322,7 +322,7 @@ DIE *DwarfDebug::updateSubprogramScopeDIE(DwarfCompileUnit &SPCU, // concrete DIE twice. if (DIE *AbsSPDIE = AbstractSPDies.lookup(SP)) { // Pick up abstract subprogram DIE. - SPDie = SPCU.createAndAddDIE(dwarf::DW_TAG_subprogram, SPCU.getUnitDie()); + SPDie = &SPCU.createAndAddDIE(dwarf::DW_TAG_subprogram, SPCU.getUnitDie()); SPCU.addDIEEntry(*SPDie, dwarf::DW_AT_abstract_origin, AbsSPDIE); } else { DISubprogram SPDecl = SP.getFunctionDeclaration(); @@ -345,7 +345,7 @@ DIE *DwarfDebug::updateSubprogramScopeDIE(DwarfCompileUnit &SPCU, SPCU.constructSubprogramArguments(*SPDie, Args); DIE *SPDeclDie = SPDie; SPDie = - SPCU.createAndAddDIE(dwarf::DW_TAG_subprogram, SPCU.getUnitDie()); + &SPCU.createAndAddDIE(dwarf::DW_TAG_subprogram, SPCU.getUnitDie()); SPCU.addDIEEntry(*SPDie, dwarf::DW_AT_specification, SPDeclDie); } } @@ -359,7 +359,7 @@ DIE *DwarfDebug::updateSubprogramScopeDIE(DwarfCompileUnit &SPCU, // Add name to the name table, we do this here because we're guaranteed // to have concrete versions of our DW_TAG_subprogram nodes. - addSubprogramNames(SP, SPDie); + addSubprogramNames(SP, *SPDie); return SPDie; } @@ -501,7 +501,7 @@ DIE *DwarfDebug::constructInlinedScopeDIE(DwarfCompileUnit &TheCU, // Add name to the name table, we do this here because we're guaranteed // to have concrete versions of our DW_TAG_inlined_subprogram nodes. - addSubprogramNames(InlinedSP, ScopeDIE); + addSubprogramNames(InlinedSP, *ScopeDIE); return ScopeDIE; } @@ -734,7 +734,7 @@ void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU, assert(Module.Verify() && "Use one of the MDNode * overloads to handle invalid metadata"); assert(Context && "Should always have a context for an imported_module"); - DIE &IMDie = *TheCU.createAndAddDIE(Module.getTag(), *Context, Module); + DIE &IMDie = TheCU.createAndAddDIE(Module.getTag(), *Context, Module); DIE *EntityDie; DIDescriptor Entity = resolve(Module.getEntity()); if (Entity.isNameSpace()) @@ -2541,30 +2541,30 @@ void DwarfDebug::attachLowHighPC(DwarfCompileUnit &Unit, DIE &D, // DIE to the proper table while ensuring that the name that we're going // to reference is in the string table. We do this since the names we // add may not only be identical to the names in the DIE. -void DwarfDebug::addAccelName(StringRef Name, const DIE *Die) { +void DwarfDebug::addAccelName(StringRef Name, const DIE &Die) { if (!useDwarfAccelTables()) return; InfoHolder.getStringPoolEntry(Name); - AccelNames.AddName(Name, Die); + AccelNames.AddName(Name, &Die); } -void DwarfDebug::addAccelObjC(StringRef Name, const DIE *Die) { +void DwarfDebug::addAccelObjC(StringRef Name, const DIE &Die) { if (!useDwarfAccelTables()) return; InfoHolder.getStringPoolEntry(Name); - AccelObjC.AddName(Name, Die); + AccelObjC.AddName(Name, &Die); } -void DwarfDebug::addAccelNamespace(StringRef Name, const DIE *Die) { +void DwarfDebug::addAccelNamespace(StringRef Name, const DIE &Die) { if (!useDwarfAccelTables()) return; InfoHolder.getStringPoolEntry(Name); - AccelNamespace.AddName(Name, Die); + AccelNamespace.AddName(Name, &Die); } -void DwarfDebug::addAccelType(StringRef Name, const DIE *Die, char Flags) { +void DwarfDebug::addAccelType(StringRef Name, const DIE &Die, char Flags) { if (!useDwarfAccelTables()) return; InfoHolder.getStringPoolEntry(Name); - AccelTypes.AddName(Name, Die, Flags); + AccelTypes.AddName(Name, &Die, Flags); } diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index 69c1b12d09a..325e053029e 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -640,17 +640,17 @@ public: /// or another context nested inside a subprogram. bool isSubprogramContext(const MDNode *Context); - void addSubprogramNames(DISubprogram SP, DIE *Die); + void addSubprogramNames(DISubprogram SP, DIE &Die); AddressPool &getAddressPool() { return AddrPool; } - void addAccelName(StringRef Name, const DIE *Die); + void addAccelName(StringRef Name, const DIE &Die); - void addAccelObjC(StringRef Name, const DIE *Die); + void addAccelObjC(StringRef Name, const DIE &Die); - void addAccelNamespace(StringRef Name, const DIE *Die); + void addAccelNamespace(StringRef Name, const DIE &Die); - void addAccelType(StringRef Name, const DIE *Die, char Flags); + void addAccelType(StringRef Name, const DIE &Die, char Flags); }; } // End of namespace llvm diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 3195126bfae..2952a7023a2 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -380,13 +380,13 @@ void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute, /// Create a DIE with the given Tag, add the DIE to its parent, and /// call insertDIE if MD is not null. -DIE *DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, DIDescriptor N) { +DIE &DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, DIDescriptor N) { assert(Tag != dwarf::DW_TAG_auto_variable && Tag != dwarf::DW_TAG_arg_variable); - DIE *Die = new DIE((dwarf::Tag)Tag); - Parent.addChild(Die); + Parent.addChild(new DIE((dwarf::Tag)Tag)); + DIE &Die = *Parent.getChildren().back(); if (N) - insertDIE(N, Die); + insertDIE(N, &Die); return Die; } @@ -958,17 +958,16 @@ DIE *DwarfUnit::createTypeDIE(DICompositeType Ty) { DIScope Context = resolve(Ty.getContext()); DIE *ContextDIE = getOrCreateContextDIE(Context); - DIE *TyDIE = getDIE(Ty); - if (TyDIE) + if (DIE *TyDIE = getDIE(Ty)) return TyDIE; // Create new type. - TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty); + DIE &TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty); - constructTypeDIE(*TyDIE, Ty); + constructTypeDIE(TyDIE, Ty); updateAcceleratorTables(Context, Ty, TyDIE); - return TyDIE; + return &TyDIE; } /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the @@ -996,9 +995,9 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) { return TyDIE; // Create new type. - DIE &TyDIE = *createAndAddDIE(Ty.getTag(), *ContextDIE, Ty); + DIE &TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty); - updateAcceleratorTables(Context, Ty, &TyDIE); + updateAcceleratorTables(Context, Ty, TyDIE); if (Ty.isBasicType()) constructTypeDIE(TyDIE, DIBasicType(Ty)); @@ -1020,7 +1019,7 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) { } void DwarfUnit::updateAcceleratorTables(DIScope Context, DIType Ty, - const DIE *TyDIE) { + const DIE &TyDIE) { if (!Ty.getName().empty() && !Ty.isForwardDecl()) { bool IsImplementation = 0; if (Ty.isCompositeType()) { @@ -1035,7 +1034,8 @@ void DwarfUnit::updateAcceleratorTables(DIScope Context, DIType Ty, if ((!Context || Context.isCompileUnit() || Context.isFile() || Context.isNameSpace()) && getCUNode().getEmissionKind() != DIBuilder::LineTablesOnly) - GlobalTypes[getParentContextString(Context) + Ty.getName().str()] = TyDIE; + GlobalTypes[getParentContextString(Context) + Ty.getName().str()] = + &TyDIE; } } @@ -1163,10 +1163,10 @@ void DwarfUnit::constructSubprogramArguments(DIE &Buffer, DIArray Args) { assert(i == N-1 && "Unspecified parameter must be the last argument"); createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer); } else { - DIE *Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer); - addType(*Arg, DIType(Ty)); + DIE &Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer); + addType(Arg, DIType(Ty)); if (DIType(Ty).isArtificial()) - addFlag(*Arg, dwarf::DW_AT_artificial); + addFlag(Arg, dwarf::DW_AT_artificial); } } } @@ -1226,7 +1226,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) { else if (Element.isDerivedType()) { DIDerivedType DDTy(Element); if (DDTy.getTag() == dwarf::DW_TAG_friend) { - DIE &ElemDie = *createAndAddDIE(dwarf::DW_TAG_friend, Buffer); + DIE &ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer); addType(ElemDie, resolve(DDTy.getTypeDerivedFrom()), dwarf::DW_AT_friend); } else if (DDTy.isStaticMember()) { @@ -1236,7 +1236,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) { } } else if (Element.isObjCProperty()) { DIObjCProperty Property(Element); - DIE &ElemDie = *createAndAddDIE(Property.getTag(), Buffer); + DIE &ElemDie = createAndAddDIE(Property.getTag(), Buffer); StringRef PropertyName = Property.getObjCPropertyName(); addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName); if (Property.getType()) @@ -1333,7 +1333,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) { void DwarfUnit::constructTemplateTypeParameterDIE(DIE &Buffer, DITemplateTypeParameter TP) { DIE &ParamDIE = - *createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer); + createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer); // Add the type if it exists, it could be void and therefore no type. if (TP.getType()) addType(ParamDIE, resolve(TP.getType())); @@ -1346,7 +1346,7 @@ void DwarfUnit::constructTemplateTypeParameterDIE(DIE &Buffer, void DwarfUnit::constructTemplateValueParameterDIE(DIE &Buffer, DITemplateValueParameter VP) { - DIE &ParamDIE = *createAndAddDIE(VP.getTag(), Buffer); + DIE &ParamDIE = createAndAddDIE(VP.getTag(), Buffer); // Add the type if there is one, template template and template parameter // packs will not have a type. @@ -1387,14 +1387,14 @@ DIE *DwarfUnit::getOrCreateNameSpace(DINameSpace NS) { if (DIE *NDie = getDIE(NS)) return NDie; - DIE &NDie = *createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS); + DIE &NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS); if (!NS.getName().empty()) { addString(NDie, dwarf::DW_AT_name, NS.getName()); - DD->addAccelNamespace(NS.getName(), &NDie); + DD->addAccelNamespace(NS.getName(), NDie); addGlobalName(NS.getName(), NDie, NS.getContext()); } else - DD->addAccelNamespace("(anonymous namespace)", &NDie); + DD->addAccelNamespace("(anonymous namespace)", NDie); addSourceLine(NDie, NS); return &NDie; } @@ -1420,7 +1420,7 @@ DIE *DwarfUnit::getOrCreateSubprogramDIE(DISubprogram SP) { ContextDIE = UnitDie.get(); // DW_TAG_inlined_subroutine may refer to this DIE. - DIE &SPDie = *createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, SP); + DIE &SPDie = createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, SP); DIE *DeclDie = nullptr; if (SPDecl.isSubprogram()) @@ -1585,7 +1585,7 @@ void DwarfCompileUnit::createGlobalVariableDIE(DIGlobalVariable GV) { DIE *ContextDIE = getOrCreateContextDIE(GVContext); // Add to map. - VariableDIE = createAndAddDIE(GV.getTag(), *ContextDIE, GV); + VariableDIE = &createAndAddDIE(GV.getTag(), *ContextDIE, GV); // Add name and type. addString(*VariableDIE, dwarf::DW_AT_name, GV.getDisplayName()); @@ -1637,7 +1637,7 @@ void DwarfCompileUnit::createGlobalVariableDIE(DIGlobalVariable GV) { if (GVContext && GV.isDefinition() && !GVContext.isCompileUnit() && !GVContext.isFile() && !DD->isSubprogramContext(GVContext)) { // Create specification DIE. - VariableSpecDIE = createAndAddDIE(dwarf::DW_TAG_variable, *UnitDie); + VariableSpecDIE = &createAndAddDIE(dwarf::DW_TAG_variable, *UnitDie); addDIEEntry(*VariableSpecDIE, dwarf::DW_AT_specification, VariableDIE); addBlock(*VariableSpecDIE, dwarf::DW_AT_location, Loc); // A static member's declaration is already flagged as such. @@ -1681,7 +1681,7 @@ void DwarfCompileUnit::createGlobalVariableDIE(DIGlobalVariable GV) { } if (addToAccelTable) { - DIE *AddrDIE = VariableSpecDIE ? VariableSpecDIE : VariableDIE; + DIE &AddrDIE = VariableSpecDIE ? *VariableSpecDIE : *VariableDIE; DD->addAccelName(GV.getName(), AddrDIE); // If the linkage name is different than the name, go ahead and output @@ -1698,7 +1698,7 @@ void DwarfCompileUnit::createGlobalVariableDIE(DIGlobalVariable GV) { /// constructSubrangeDIE - Construct subrange DIE from DISubrange. void DwarfUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy) { - DIE &DW_Subrange = *createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer); + DIE &DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer); addDIEEntry(DW_Subrange, dwarf::DW_AT_type, IndexTy); // The LowerBound value defines the lower bounds which is typically zero for @@ -1735,7 +1735,7 @@ void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy) { DIE *IdxTy = getIndexTyDie(); if (!IdxTy) { // Construct an integer type to use for indexes. - IdxTy = createAndAddDIE(dwarf::DW_TAG_base_type, *UnitDie); + IdxTy = &createAndAddDIE(dwarf::DW_TAG_base_type, *UnitDie); addString(*IdxTy, dwarf::DW_AT_name, "sizetype"); addUInt(*IdxTy, dwarf::DW_AT_byte_size, None, sizeof(int64_t)); addUInt(*IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, @@ -1760,7 +1760,7 @@ void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy) { for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { DIEnumerator Enum(Elements.getElement(i)); if (Enum.isEnumerator()) { - DIE &Enumerator = *createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer); + DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer); StringRef Name = Enum.getName(); addString(Enumerator, dwarf::DW_AT_name, Name); int64_t Value = Enum.getEnumValue(); @@ -1868,7 +1868,7 @@ DIE *DwarfUnit::constructVariableDIEImpl(const DbgVariable &DV, /// constructMemberDIE - Construct member DIE from DIDerivedType. void DwarfUnit::constructMemberDIE(DIE &Buffer, DIDerivedType DT) { - DIE &MemberDie = *createAndAddDIE(DT.getTag(), Buffer); + DIE &MemberDie = createAndAddDIE(DT.getTag(), Buffer); StringRef Name = DT.getName(); if (!Name.empty()) addString(MemberDie, dwarf::DW_AT_name, Name); @@ -1969,7 +1969,7 @@ DIE *DwarfUnit::getOrCreateStaticMemberDIE(DIDerivedType DT) { if (DIE *StaticMemberDIE = getDIE(DT)) return StaticMemberDIE; - DIE &StaticMemberDIE = *createAndAddDIE(DT.getTag(), *ContextDIE, DT); + DIE &StaticMemberDIE = createAndAddDIE(DT.getTag(), *ContextDIE, DT); DIType Ty = resolve(DT.getTypeDerivedFrom()); diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.h b/lib/CodeGen/AsmPrinter/DwarfUnit.h index 96ef40d94dd..17be320f209 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -432,7 +432,7 @@ public: /// Create a DIE with the given Tag, add the DIE to its parent, and /// call insertDIE if MD is not null. - DIE *createAndAddDIE(unsigned Tag, DIE &Parent, + DIE &createAndAddDIE(unsigned Tag, DIE &Parent, DIDescriptor N = DIDescriptor()); /// Compute the size of a header for this unit, not including the initial @@ -526,7 +526,7 @@ private: /// If this is a named finished type then include it in the list of types for /// the accelerator tables. - void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE *TyDIE); + void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE &TyDIE); }; class DwarfCompileUnit : public DwarfUnit { -- 2.34.1