[llvm] r206925 - Push memory ownership of DwarfUnits into clients of DwarfFile.
David Blaikie
dblaikie at gmail.com
Tue Apr 22 15:57:15 PDT 2014
On Tue, Apr 22, 2014 at 3:50 PM, Eric Christopher <echristo at gmail.com> wrote:
> On Tue, Apr 22, 2014 at 3:39 PM, David Blaikie <dblaikie at gmail.com> wrote:
>> Author: dblaikie
>> Date: Tue Apr 22 17:39:41 2014
>> New Revision: 206925
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=206925&view=rev
>> Log:
>> Push memory ownership of DwarfUnits into clients of DwarfFile.
>>
>> This prompted me to push references through most of DwarfDebug. Sorry
>> for the churn.
>>
>> Honestly it's a bit silly that we're passing around units all over the
>> place like that anyway and I think it's mostly due to the DIE attribute
>> adding utility functions being utilities in DwarfUnit. I should have
>> another go at moving them out of DwarfUnit...
>
> Yup. I think the only problems are the caches for things that are
> already used in the unit. Moving those out and using DD to add
> attributes would solve the uses.
Yep, but then you get all the DwarfUnit functions needing to use
DD->addFoo, which didn't seem like a great improvement. But at least
in DwarfUnit there's a DwarfDebug member so we wouldn't be passing an
extra parameter around all over the place like we are in DwarfDebug at
the moment.
Many of them don't need... well, I was going to say many of them don't
even need any extra state, but it just happened that the one random
add* function I looked at was addFlag, which uses DIEIntegerOne (which
is extra state... ) and it's one of the only ones that doesn't
directly use the DIEValueAllocator, of course.
So, yeah, a bunch of these functions need some extra state and are
going to need an extra parameter one way or another.
> You know this already though :)
Yep - good to write it down/discuss/remind myself/us/others, though.
This stuff oozes out my ears after a few days/weeks/months.
- David
>
> -eric
>
>>
>> Modified:
>> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
>> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=206925&r1=206924&r2=206925&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Apr 22 17:39:41 2014
>> @@ -280,8 +280,8 @@ void DwarfFile::assignAbbrevNumber(DIEAb
>> }
>> }
>>
>> -void DwarfFile::addUnit(DwarfUnit *CU) {
>> - CUs.push_back(std::unique_ptr<DwarfUnit>(CU));
>> +void DwarfFile::addUnit(std::unique_ptr<DwarfUnit> U) {
>> + CUs.push_back(std::move(U));
>> }
>>
>> static bool isObjCClass(StringRef Name) {
>> @@ -323,26 +323,26 @@ static bool SectionSort(const MCSection
>> // 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.
>> -static void addSubprogramNames(DwarfUnit *TheU, DISubprogram SP, DIE *Die) {
>> +static void addSubprogramNames(DwarfUnit &TheU, DISubprogram SP, DIE *Die) {
>> if (!SP.isDefinition())
>> return;
>> - TheU->addAccelName(SP.getName(), Die);
>> + TheU.addAccelName(SP.getName(), Die);
>>
>> // If the linkage name is different than the name, go ahead and output
>> // that as well into the name table.
>> if (SP.getLinkageName() != "" && SP.getName() != SP.getLinkageName())
>> - TheU->addAccelName(SP.getLinkageName(), Die);
>> + TheU.addAccelName(SP.getLinkageName(), Die);
>>
>> // If this is an Objective-C selector name add it to the ObjC accelerator
>> // too.
>> if (isObjCClass(SP.getName())) {
>> StringRef Class, Category;
>> getObjCClassCategory(SP.getName(), Class, Category);
>> - TheU->addAccelObjC(Class, Die);
>> + TheU.addAccelObjC(Class, Die);
>> if (Category != "")
>> - TheU->addAccelObjC(Category, Die);
>> + TheU.addAccelObjC(Category, Die);
>> // Also add the base method name to the name table.
>> - TheU->addAccelName(getObjCMethodName(SP.getName()), Die);
>> + TheU.addAccelName(getObjCMethodName(SP.getName()), Die);
>> }
>> }
>>
>> @@ -362,9 +362,9 @@ bool DwarfDebug::isSubprogramContext(con
>> // Find DIE for the given subprogram and attach appropriate DW_AT_low_pc
>> // and DW_AT_high_pc attributes. If there are global variables in this
>> // scope then create and insert DIEs for these variables.
>> -DIE *DwarfDebug::updateSubprogramScopeDIE(DwarfCompileUnit *SPCU,
>> +DIE *DwarfDebug::updateSubprogramScopeDIE(DwarfCompileUnit &SPCU,
>> DISubprogram SP) {
>> - DIE *SPDie = SPCU->getDIE(SP);
>> + DIE *SPDie = SPCU.getDIE(SP);
>>
>> assert(SPDie && "Unable to find subprogram DIE!");
>>
>> @@ -374,8 +374,8 @@ DIE *DwarfDebug::updateSubprogramScopeDI
>> if (DIE *AbsSPDIE = AbstractSPDies.lookup(SP)) {
>> // Pick up abstract subprogram DIE.
>> SPDie =
>> - SPCU->createAndAddDIE(dwarf::DW_TAG_subprogram, *SPCU->getUnitDie());
>> - SPCU->addDIEEntry(SPDie, dwarf::DW_AT_abstract_origin, AbsSPDIE);
>> + SPCU.createAndAddDIE(dwarf::DW_TAG_subprogram, *SPCU.getUnitDie());
>> + SPCU.addDIEEntry(SPDie, dwarf::DW_AT_abstract_origin, AbsSPDIE);
>> } else {
>> DISubprogram SPDecl = SP.getFunctionDeclaration();
>> if (!SPDecl.isSubprogram()) {
>> @@ -387,18 +387,18 @@ DIE *DwarfDebug::updateSubprogramScopeDI
>> DIScope SPContext = resolve(SP.getContext());
>> if (SP.isDefinition() && !SPContext.isCompileUnit() &&
>> !SPContext.isFile() && !isSubprogramContext(SPContext)) {
>> - SPCU->addFlag(SPDie, dwarf::DW_AT_declaration);
>> + SPCU.addFlag(SPDie, dwarf::DW_AT_declaration);
>>
>> // Add arguments.
>> DICompositeType SPTy = SP.getType();
>> DIArray Args = SPTy.getTypeArray();
>> uint16_t SPTag = SPTy.getTag();
>> if (SPTag == dwarf::DW_TAG_subroutine_type)
>> - SPCU->constructSubprogramArguments(*SPDie, Args);
>> + SPCU.constructSubprogramArguments(*SPDie, Args);
>> DIE *SPDeclDie = SPDie;
>> - SPDie = SPCU->createAndAddDIE(dwarf::DW_TAG_subprogram,
>> - *SPCU->getUnitDie());
>> - SPCU->addDIEEntry(SPDie, dwarf::DW_AT_specification, SPDeclDie);
>> + SPDie = SPCU.createAndAddDIE(dwarf::DW_TAG_subprogram,
>> + *SPCU.getUnitDie());
>> + SPCU.addDIEEntry(SPDie, dwarf::DW_AT_specification, SPDeclDie);
>> }
>> }
>> }
>> @@ -407,7 +407,7 @@ DIE *DwarfDebug::updateSubprogramScopeDI
>>
>> const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
>> MachineLocation Location(RI->getFrameRegister(*Asm->MF));
>> - SPCU->addAddress(SPDie, dwarf::DW_AT_frame_base, Location);
>> + SPCU.addAddress(SPDie, dwarf::DW_AT_frame_base, Location);
>>
>> // Add name to the name table, we do this here because we're guaranteed
>> // to have concrete versions of our DW_TAG_subprogram nodes.
>> @@ -437,16 +437,16 @@ bool DwarfDebug::isLexicalScopeDIENull(L
>> return !End;
>> }
>>
>> -static void addSectionLabel(AsmPrinter *Asm, DwarfUnit *U, DIE *D,
>> +static void addSectionLabel(AsmPrinter &Asm, DwarfUnit &U, DIE *D,
>> dwarf::Attribute A, const MCSymbol *L,
>> const MCSymbol *Sec) {
>> - if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
>> - U->addSectionLabel(D, A, L);
>> + if (Asm.MAI->doesDwarfUseRelocationsAcrossSections())
>> + U.addSectionLabel(D, A, L);
>> else
>> - U->addSectionDelta(D, A, L, Sec);
>> + U.addSectionDelta(D, A, L, Sec);
>> }
>>
>> -void DwarfDebug::addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE,
>> +void DwarfDebug::addScopeRangeList(DwarfCompileUnit &TheCU, DIE *ScopeDIE,
>> const SmallVectorImpl<InsnRange> &Range) {
>> // Emit offset in .debug_range as a relocatable label. emitDIE will handle
>> // emitting it appropriately.
>> @@ -455,10 +455,10 @@ void DwarfDebug::addScopeRangeList(Dwarf
>> // Under fission, ranges are specified by constant offsets relative to the
>> // CU's DW_AT_GNU_ranges_base.
>> if (useSplitDwarf())
>> - TheCU->addSectionDelta(ScopeDIE, dwarf::DW_AT_ranges, RangeSym,
>> + TheCU.addSectionDelta(ScopeDIE, dwarf::DW_AT_ranges, RangeSym,
>> DwarfDebugRangeSectionSym);
>> else
>> - addSectionLabel(Asm, TheCU, ScopeDIE, dwarf::DW_AT_ranges, RangeSym,
>> + addSectionLabel(*Asm, TheCU, ScopeDIE, dwarf::DW_AT_ranges, RangeSym,
>> DwarfDebugRangeSectionSym);
>>
>> RangeSpanList List(RangeSym);
>> @@ -468,12 +468,12 @@ void DwarfDebug::addScopeRangeList(Dwarf
>> }
>>
>> // Add the range list to the set of ranges to be emitted.
>> - TheCU->addRangeList(std::move(List));
>> + TheCU.addRangeList(std::move(List));
>> }
>>
>> // Construct new DW_TAG_lexical_block for this scope and attach
>> // DW_AT_low_pc/DW_AT_high_pc labels.
>> -DIE *DwarfDebug::constructLexicalScopeDIE(DwarfCompileUnit *TheCU,
>> +DIE *DwarfDebug::constructLexicalScopeDIE(DwarfCompileUnit &TheCU,
>> LexicalScope *Scope) {
>> if (isLexicalScopeDIENull(Scope))
>> return 0;
>> @@ -506,7 +506,7 @@ DIE *DwarfDebug::constructLexicalScopeDI
>>
>> // This scope represents inlined body of a function. Construct DIE to
>> // represent this concrete inlined copy of the function.
>> -DIE *DwarfDebug::constructInlinedScopeDIE(DwarfCompileUnit *TheCU,
>> +DIE *DwarfDebug::constructInlinedScopeDIE(DwarfCompileUnit &TheCU,
>> LexicalScope *Scope) {
>> const SmallVectorImpl<InsnRange> &ScopeRanges = Scope->getRanges();
>> assert(!ScopeRanges.empty() &&
>> @@ -516,14 +516,14 @@ DIE *DwarfDebug::constructInlinedScopeDI
>> return NULL;
>> DIScope DS(Scope->getScopeNode());
>> DISubprogram InlinedSP = getDISubprogram(DS);
>> - DIE *OriginDIE = TheCU->getDIE(InlinedSP);
>> + DIE *OriginDIE = TheCU.getDIE(InlinedSP);
>> if (!OriginDIE) {
>> DEBUG(dbgs() << "Unable to find original DIE for an inlined subprogram.");
>> return NULL;
>> }
>>
>> DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine);
>> - TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin, OriginDIE);
>> + TheCU.addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin, OriginDIE);
>>
>> // If we have multiple ranges, emit them into the range section.
>> if (ScopeRanges.size() > 1)
>> @@ -547,10 +547,10 @@ DIE *DwarfDebug::constructInlinedScopeDI
>>
>> // Add the call site information to the DIE.
>> DILocation DL(Scope->getInlinedAt());
>> - TheCU->addUInt(
>> + TheCU.addUInt(
>> ScopeDIE, dwarf::DW_AT_call_file, None,
>> - TheCU->getOrCreateSourceID(DL.getFilename(), DL.getDirectory()));
>> - TheCU->addUInt(ScopeDIE, dwarf::DW_AT_call_line, None, DL.getLineNumber());
>> + TheCU.getOrCreateSourceID(DL.getFilename(), DL.getDirectory()));
>> + TheCU.addUInt(ScopeDIE, dwarf::DW_AT_call_line, None, DL.getLineNumber());
>>
>> // 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.
>> @@ -559,7 +559,7 @@ DIE *DwarfDebug::constructInlinedScopeDI
>> return ScopeDIE;
>> }
>>
>> -DIE *DwarfDebug::createScopeChildrenDIE(DwarfCompileUnit *TheCU,
>> +DIE *DwarfDebug::createScopeChildrenDIE(DwarfCompileUnit &TheCU,
>> LexicalScope *Scope,
>> SmallVectorImpl<DIE *> &Children) {
>> DIE *ObjectPointer = NULL;
>> @@ -569,7 +569,7 @@ DIE *DwarfDebug::createScopeChildrenDIE(
>> for (DbgVariable *ArgDV : CurrentFnArguments)
>> if (ArgDV)
>> if (DIE *Arg =
>> - TheCU->constructVariableDIE(*ArgDV, Scope->isAbstractScope())) {
>> + TheCU.constructVariableDIE(*ArgDV, Scope->isAbstractScope())) {
>> Children.push_back(Arg);
>> if (ArgDV->isObjectPointer())
>> ObjectPointer = Arg;
>> @@ -587,7 +587,7 @@ DIE *DwarfDebug::createScopeChildrenDIE(
>>
>> // Collect lexical scope children first.
>> for (DbgVariable *DV : ScopeVariables.lookup(Scope))
>> - if (DIE *Variable = TheCU->constructVariableDIE(*DV,
>> + if (DIE *Variable = TheCU.constructVariableDIE(*DV,
>> Scope->isAbstractScope())) {
>> Children.push_back(Variable);
>> if (DV->isObjectPointer())
>> @@ -600,7 +600,7 @@ DIE *DwarfDebug::createScopeChildrenDIE(
>> }
>>
>> // Construct a DIE for this scope.
>> -DIE *DwarfDebug::constructScopeDIE(DwarfCompileUnit *TheCU,
>> +DIE *DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU,
>> LexicalScope *Scope) {
>> if (!Scope || !Scope->getScopeNode())
>> return NULL;
>> @@ -620,7 +620,7 @@ DIE *DwarfDebug::constructScopeDIE(Dwarf
>> else if (DS.isSubprogram()) {
>> ProcessedSPNodes.insert(DS);
>> if (Scope->isAbstractScope()) {
>> - ScopeDIE = TheCU->getDIE(DS);
>> + ScopeDIE = TheCU.getDIE(DS);
>> // Note down abstract DIE.
>> if (ScopeDIE)
>> AbstractSPDies.insert(std::make_pair(DS, ScopeDIE));
>> @@ -667,28 +667,30 @@ DIE *DwarfDebug::constructScopeDIE(Dwarf
>> ScopeDIE->addChild(I);
>>
>> if (DS.isSubprogram() && ObjectPointer != NULL)
>> - TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, ObjectPointer);
>> + TheCU.addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, ObjectPointer);
>>
>> return ScopeDIE;
>> }
>>
>> -void DwarfDebug::addGnuPubAttributes(DwarfUnit *U, DIE *D) const {
>> +void DwarfDebug::addGnuPubAttributes(DwarfUnit &U, DIE *D) const {
>> if (!GenerateGnuPubSections)
>> return;
>>
>> - U->addFlag(D, dwarf::DW_AT_GNU_pubnames);
>> + U.addFlag(D, dwarf::DW_AT_GNU_pubnames);
>> }
>>
>> // Create new DwarfCompileUnit for the given metadata node with tag
>> // DW_TAG_compile_unit.
>> -DwarfCompileUnit *DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
>> +DwarfCompileUnit &DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
>> StringRef FN = DIUnit.getFilename();
>> CompilationDir = DIUnit.getDirectory();
>>
>> DIE *Die = new DIE(dwarf::DW_TAG_compile_unit);
>> - DwarfCompileUnit *NewCU = new DwarfCompileUnit(
>> + auto OwnedUnit = make_unique<DwarfCompileUnit>(
>> InfoHolder.getUnits().size(), Die, DIUnit, Asm, this, &InfoHolder);
>> - InfoHolder.addUnit(NewCU);
>> + DwarfCompileUnit &NewCU = *OwnedUnit;
>> + InfoHolder.addUnit(std::move(OwnedUnit));
>> +
>>
>> // LTO with assembly output shares a single line table amongst multiple CUs.
>> // To avoid the compilation directory being ambiguous, let the line table
>> @@ -696,53 +698,53 @@ DwarfCompileUnit *DwarfDebug::constructD
>> // compilation directory.
>> if (!Asm->OutStreamer.hasRawTextSupport() || SingleCU)
>> Asm->OutStreamer.getContext().setMCLineTableCompilationDir(
>> - NewCU->getUniqueID(), CompilationDir);
>> + NewCU.getUniqueID(), CompilationDir);
>>
>> - NewCU->addString(Die, dwarf::DW_AT_producer, DIUnit.getProducer());
>> - NewCU->addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
>> + NewCU.addString(Die, dwarf::DW_AT_producer, DIUnit.getProducer());
>> + NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
>> DIUnit.getLanguage());
>> - NewCU->addString(Die, dwarf::DW_AT_name, FN);
>> + NewCU.addString(Die, dwarf::DW_AT_name, FN);
>>
>> if (!useSplitDwarf()) {
>> - NewCU->initStmtList(DwarfLineSectionSym);
>> + NewCU.initStmtList(DwarfLineSectionSym);
>>
>> // If we're using split dwarf the compilation dir is going to be in the
>> // skeleton CU and so we don't need to duplicate it here.
>> if (!CompilationDir.empty())
>> - NewCU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
>> + NewCU.addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
>>
>> addGnuPubAttributes(NewCU, Die);
>> }
>>
>> if (DIUnit.isOptimized())
>> - NewCU->addFlag(Die, dwarf::DW_AT_APPLE_optimized);
>> + NewCU.addFlag(Die, dwarf::DW_AT_APPLE_optimized);
>>
>> StringRef Flags = DIUnit.getFlags();
>> if (!Flags.empty())
>> - NewCU->addString(Die, dwarf::DW_AT_APPLE_flags, Flags);
>> + NewCU.addString(Die, dwarf::DW_AT_APPLE_flags, Flags);
>>
>> if (unsigned RVer = DIUnit.getRunTimeVersion())
>> - NewCU->addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
>> + NewCU.addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
>> dwarf::DW_FORM_data1, RVer);
>>
>> if (!FirstCU)
>> - FirstCU = NewCU;
>> + FirstCU = &NewCU;
>>
>> if (useSplitDwarf()) {
>> - NewCU->initSection(Asm->getObjFileLowering().getDwarfInfoDWOSection(),
>> + NewCU.initSection(Asm->getObjFileLowering().getDwarfInfoDWOSection(),
>> DwarfInfoDWOSectionSym);
>> - NewCU->setSkeleton(constructSkeletonCU(NewCU));
>> + NewCU.setSkeleton(constructSkeletonCU(NewCU));
>> } else
>> - NewCU->initSection(Asm->getObjFileLowering().getDwarfInfoSection(),
>> + NewCU.initSection(Asm->getObjFileLowering().getDwarfInfoSection(),
>> DwarfInfoSectionSym);
>>
>> - CUMap.insert(std::make_pair(DIUnit, NewCU));
>> - CUDieMap.insert(std::make_pair(Die, NewCU));
>> + CUMap.insert(std::make_pair(DIUnit, &NewCU));
>> + CUDieMap.insert(std::make_pair(Die, &NewCU));
>> return NewCU;
>> }
>>
>> // Construct subprogram DIE.
>> -void DwarfDebug::constructSubprogramDIE(DwarfCompileUnit *TheCU,
>> +void DwarfDebug::constructSubprogramDIE(DwarfCompileUnit &TheCU,
>> const MDNode *N) {
>> // FIXME: We should only call this routine once, however, during LTO if a
>> // program is defined in multiple CUs we could end up calling it out of
>> @@ -751,7 +753,7 @@ void DwarfDebug::constructSubprogramDIE(
>> DwarfCompileUnit *&CURef = SPMap[N];
>> if (CURef)
>> return;
>> - CURef = TheCU;
>> + CURef = &TheCU;
>>
>> DISubprogram SP(N);
>> if (!SP.isDefinition())
>> @@ -759,51 +761,51 @@ void DwarfDebug::constructSubprogramDIE(
>> // class type.
>> return;
>>
>> - DIE *SubprogramDie = TheCU->getOrCreateSubprogramDIE(SP);
>> + DIE *SubprogramDie = TheCU.getOrCreateSubprogramDIE(SP);
>>
>> // Expose as a global name.
>> - TheCU->addGlobalName(SP.getName(), SubprogramDie, resolve(SP.getContext()));
>> + TheCU.addGlobalName(SP.getName(), SubprogramDie, resolve(SP.getContext()));
>> }
>>
>> -void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit *TheCU,
>> +void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU,
>> const MDNode *N) {
>> DIImportedEntity Module(N);
>> assert(Module.Verify());
>> - if (DIE *D = TheCU->getOrCreateContextDIE(Module.getContext()))
>> + if (DIE *D = TheCU.getOrCreateContextDIE(Module.getContext()))
>> constructImportedEntityDIE(TheCU, Module, D);
>> }
>>
>> -void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit *TheCU,
>> +void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU,
>> const MDNode *N, DIE *Context) {
>> DIImportedEntity Module(N);
>> assert(Module.Verify());
>> return constructImportedEntityDIE(TheCU, Module, Context);
>> }
>>
>> -void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit *TheCU,
>> +void DwarfDebug::constructImportedEntityDIE(DwarfCompileUnit &TheCU,
>> const DIImportedEntity &Module,
>> DIE *Context) {
>> 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())
>> - EntityDie = TheCU->getOrCreateNameSpace(DINameSpace(Entity));
>> + EntityDie = TheCU.getOrCreateNameSpace(DINameSpace(Entity));
>> else if (Entity.isSubprogram())
>> - EntityDie = TheCU->getOrCreateSubprogramDIE(DISubprogram(Entity));
>> + EntityDie = TheCU.getOrCreateSubprogramDIE(DISubprogram(Entity));
>> else if (Entity.isType())
>> - EntityDie = TheCU->getOrCreateTypeDIE(DIType(Entity));
>> + EntityDie = TheCU.getOrCreateTypeDIE(DIType(Entity));
>> else
>> - EntityDie = TheCU->getDIE(Entity);
>> - TheCU->addSourceLine(IMDie, Module.getLineNumber(),
>> + EntityDie = TheCU.getDIE(Entity);
>> + TheCU.addSourceLine(IMDie, Module.getLineNumber(),
>> Module.getContext().getFilename(),
>> Module.getContext().getDirectory());
>> - TheCU->addDIEEntry(IMDie, dwarf::DW_AT_import, EntityDie);
>> + TheCU.addDIEEntry(IMDie, dwarf::DW_AT_import, EntityDie);
>> StringRef Name = Module.getName();
>> if (!Name.empty())
>> - TheCU->addString(IMDie, dwarf::DW_AT_name, Name);
>> + TheCU.addString(IMDie, dwarf::DW_AT_name, Name);
>> }
>>
>> // Emit all Dwarf sections that should come prior to the content. Create
>> @@ -829,7 +831,7 @@ void DwarfDebug::beginModule() {
>>
>> for (MDNode *N : CU_Nodes->operands()) {
>> DICompileUnit CUNode(N);
>> - DwarfCompileUnit *CU = constructDwarfCompileUnit(CUNode);
>> + DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
>> DIArray ImportedEntities = CUNode.getImportedEntities();
>> for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i)
>> ScopesWithImportedEntities.push_back(std::make_pair(
>> @@ -839,20 +841,20 @@ void DwarfDebug::beginModule() {
>> ScopesWithImportedEntities.end(), less_first());
>> DIArray GVs = CUNode.getGlobalVariables();
>> for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i)
>> - CU->createGlobalVariableDIE(DIGlobalVariable(GVs.getElement(i)));
>> + CU.createGlobalVariableDIE(DIGlobalVariable(GVs.getElement(i)));
>> DIArray SPs = CUNode.getSubprograms();
>> for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
>> constructSubprogramDIE(CU, SPs.getElement(i));
>> DIArray EnumTypes = CUNode.getEnumTypes();
>> for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i)
>> - CU->getOrCreateTypeDIE(EnumTypes.getElement(i));
>> + CU.getOrCreateTypeDIE(EnumTypes.getElement(i));
>> DIArray RetainedTypes = CUNode.getRetainedTypes();
>> for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i) {
>> DIType Ty(RetainedTypes.getElement(i));
>> // The retained types array by design contains pointers to
>> // MDNodes rather than DIRefs. Unique them here.
>> DIType UniqueTy(resolve(Ty.getRef()));
>> - CU->getOrCreateTypeDIE(UniqueTy);
>> + CU.getOrCreateTypeDIE(UniqueTy);
>> }
>> // Emit imported_modules last so that the relevant context is already
>> // available.
>> @@ -907,7 +909,7 @@ void DwarfDebug::collectDeadVariables()
>> assert(SPCU && "Unable to find Compile Unit!");
>> // FIXME: See the comment in constructSubprogramDIE about duplicate
>> // subprogram DIEs.
>> - constructSubprogramDIE(SPCU, SP);
>> + constructSubprogramDIE(*SPCU, SP);
>> DIE *SPDIE = SPCU->getDIE(SP);
>> for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) {
>> DIVariable DV(Variables.getElement(vi));
>> @@ -953,11 +955,11 @@ void DwarfDebug::finalizeModuleInfo() {
>> // We don't keep track of which addresses are used in which CU so this
>> // is a bit pessimistic under LTO.
>> if (!InfoHolder.getAddrPool()->empty())
>> - addSectionLabel(Asm, SkCU, SkCU->getUnitDie(),
>> + addSectionLabel(*Asm, *SkCU, SkCU->getUnitDie(),
>> dwarf::DW_AT_GNU_addr_base, DwarfAddrSectionSym,
>> DwarfAddrSectionSym);
>> if (!TheU->getRangeLists().empty())
>> - addSectionLabel(Asm, SkCU, SkCU->getUnitDie(),
>> + addSectionLabel(*Asm, *SkCU, SkCU->getUnitDie(),
>> dwarf::DW_AT_GNU_ranges_base,
>> DwarfDebugRangeSectionSym, DwarfDebugRangeSectionSym);
>> }
>> @@ -973,7 +975,7 @@ void DwarfDebug::finalizeModuleInfo() {
>> unsigned NumRanges = TheU->getRanges().size();
>> if (NumRanges) {
>> if (NumRanges > 1) {
>> - addSectionLabel(Asm, &U, U.getUnitDie(), dwarf::DW_AT_ranges,
>> + addSectionLabel(*Asm, U, U.getUnitDie(), dwarf::DW_AT_ranges,
>> Asm->GetTempSymbol("cu_ranges", U.getUniqueID()),
>> DwarfDebugRangeSectionSym);
>>
>> @@ -1694,8 +1696,7 @@ void DwarfDebug::endFunction(const Machi
>> collectVariableInfo(ProcessedVars);
>>
>> LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
>> - DwarfCompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
>> - assert(TheCU && "Unable to find compile unit!");
>> + DwarfCompileUnit &TheCU = *SPMap.lookup(FnScope->getScopeNode());
>>
>> // Construct abstract scopes.
>> for (LexicalScope *AScope : LScopes.getAbstractScopesList()) {
>> @@ -1723,13 +1724,13 @@ void DwarfDebug::endFunction(const Machi
>>
>> DIE *CurFnDIE = constructScopeDIE(TheCU, FnScope);
>> if (!CurFn->getTarget().Options.DisableFramePointerElim(*CurFn))
>> - TheCU->addFlag(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr);
>> + TheCU.addFlag(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr);
>>
>> // Add the range of this function to the list of ranges for the CU.
>> RangeSpan Span(FunctionBeginSym, FunctionEndSym);
>> - TheCU->addRange(std::move(Span));
>> + TheCU.addRange(std::move(Span));
>> PrevSection = Asm->getCurrentSection();
>> - PrevCU = TheCU;
>> + PrevCU = &TheCU;
>>
>> // Clear debug info
>> for (auto &I : ScopeVariables)
>> @@ -2649,52 +2650,54 @@ void DwarfDebug::emitDebugRanges() {
>>
>> // DWARF5 Experimental Separate Dwarf emitters.
>>
>> -void DwarfDebug::initSkeletonUnit(const DwarfUnit *U, DIE *Die,
>> - DwarfUnit *NewU) {
>> +void DwarfDebug::initSkeletonUnit(const DwarfUnit &U, DIE *Die,
>> + std::unique_ptr<DwarfUnit> NewU) {
>> NewU->addLocalString(Die, dwarf::DW_AT_GNU_dwo_name,
>> - U->getCUNode().getSplitDebugFilename());
>> + U.getCUNode().getSplitDebugFilename());
>>
>> if (!CompilationDir.empty())
>> NewU->addLocalString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
>>
>> - addGnuPubAttributes(NewU, Die);
>> + addGnuPubAttributes(*NewU, Die);
>>
>> - SkeletonHolder.addUnit(NewU);
>> + SkeletonHolder.addUnit(std::move(NewU));
>> }
>>
>> // This DIE has the following attributes: DW_AT_comp_dir, DW_AT_stmt_list,
>> // DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_dwo_name, DW_AT_dwo_id,
>> // DW_AT_addr_base, DW_AT_ranges_base.
>> -DwarfCompileUnit *DwarfDebug::constructSkeletonCU(const DwarfCompileUnit *CU) {
>> +DwarfCompileUnit &DwarfDebug::constructSkeletonCU(const DwarfCompileUnit &CU) {
>>
>> DIE *Die = new DIE(dwarf::DW_TAG_compile_unit);
>> - DwarfCompileUnit *NewCU = new DwarfCompileUnit(
>> - CU->getUniqueID(), Die, CU->getCUNode(), Asm, this, &SkeletonHolder);
>> - NewCU->initSection(Asm->getObjFileLowering().getDwarfInfoSection(),
>> + auto OwnedUnit = make_unique<DwarfCompileUnit>(
>> + CU.getUniqueID(), Die, CU.getCUNode(), Asm, this, &SkeletonHolder);
>> + DwarfCompileUnit &NewCU = *OwnedUnit;
>> + NewCU.initSection(Asm->getObjFileLowering().getDwarfInfoSection(),
>> DwarfInfoSectionSym);
>>
>> - NewCU->initStmtList(DwarfLineSectionSym);
>> + NewCU.initStmtList(DwarfLineSectionSym);
>>
>> - initSkeletonUnit(CU, Die, NewCU);
>> + initSkeletonUnit(CU, Die, std::move(OwnedUnit));
>>
>> return NewCU;
>> }
>>
>> // This DIE has the following attributes: DW_AT_comp_dir, DW_AT_dwo_name,
>> // DW_AT_addr_base.
>> -DwarfTypeUnit *DwarfDebug::constructSkeletonTU(DwarfTypeUnit *TU) {
>> +DwarfTypeUnit &DwarfDebug::constructSkeletonTU(DwarfTypeUnit &TU) {
>> DwarfCompileUnit &CU = static_cast<DwarfCompileUnit &>(
>> - *SkeletonHolder.getUnits()[TU->getCU().getUniqueID()]);
>> + *SkeletonHolder.getUnits()[TU.getCU().getUniqueID()]);
>>
>> DIE *Die = new DIE(dwarf::DW_TAG_type_unit);
>> - DwarfTypeUnit *NewTU =
>> - new DwarfTypeUnit(TU->getUniqueID(), Die, CU, Asm, this, &SkeletonHolder);
>> - NewTU->setTypeSignature(TU->getTypeSignature());
>> - NewTU->setType(NULL);
>> - NewTU->initSection(
>> - Asm->getObjFileLowering().getDwarfTypesSection(TU->getTypeSignature()));
>> + auto OwnedUnit = make_unique<DwarfTypeUnit>(TU.getUniqueID(), Die, CU, Asm,
>> + this, &SkeletonHolder);
>> + DwarfTypeUnit &NewTU = *OwnedUnit;
>> + NewTU.setTypeSignature(TU.getTypeSignature());
>> + NewTU.setType(NULL);
>> + NewTU.initSection(
>> + Asm->getObjFileLowering().getDwarfTypesSection(TU.getTypeSignature()));
>>
>> - initSkeletonUnit(TU, Die, NewTU);
>> + initSkeletonUnit(TU, Die, std::move(OwnedUnit));
>> return NewTU;
>> }
>>
>> @@ -2757,13 +2760,14 @@ void DwarfDebug::addDwarfTypeUnitType(Dw
>> }
>>
>> DIE *UnitDie = new DIE(dwarf::DW_TAG_type_unit);
>> - DwarfTypeUnit *NewTU =
>> - new DwarfTypeUnit(InfoHolder.getUnits().size(), UnitDie, CU, Asm, this,
>> - &InfoHolder, getDwoLineTable(CU));
>> - TU = NewTU;
>> - InfoHolder.addUnit(NewTU);
>> + auto OwnedUnit =
>> + make_unique<DwarfTypeUnit>(InfoHolder.getUnits().size(), UnitDie, CU, Asm,
>> + this, &InfoHolder, getDwoLineTable(CU));
>> + DwarfTypeUnit &NewTU = *OwnedUnit;
>> + TU = &NewTU;
>> + InfoHolder.addUnit(std::move(OwnedUnit));
>>
>> - NewTU->addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
>> + NewTU.addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
>> CU.getLanguage());
>>
>> MD5 Hash;
>> @@ -2774,27 +2778,27 @@ void DwarfDebug::addDwarfTypeUnitType(Dw
>> MD5::MD5Result Result;
>> Hash.final(Result);
>> uint64_t Signature = *reinterpret_cast<support::ulittle64_t *>(Result + 8);
>> - NewTU->setTypeSignature(Signature);
>> + NewTU.setTypeSignature(Signature);
>> if (useSplitDwarf())
>> - NewTU->setSkeleton(constructSkeletonTU(NewTU));
>> + NewTU.setSkeleton(constructSkeletonTU(NewTU));
>> else
>> CU.applyStmtList(*UnitDie);
>>
>> - NewTU->setType(NewTU->createTypeDIE(CTy));
>> + NewTU.setType(NewTU.createTypeDIE(CTy));
>>
>> - NewTU->initSection(
>> + NewTU.initSection(
>> useSplitDwarf()
>> ? Asm->getObjFileLowering().getDwarfTypesDWOSection(Signature)
>> : Asm->getObjFileLowering().getDwarfTypesSection(Signature));
>>
>> - CU.addDIETypeSignature(RefDie, *NewTU);
>> + CU.addDIETypeSignature(RefDie, NewTU);
>> }
>>
>> -void DwarfDebug::attachLowHighPC(DwarfCompileUnit *Unit, DIE *D,
>> +void DwarfDebug::attachLowHighPC(DwarfCompileUnit &Unit, DIE *D,
>> MCSymbol *Begin, MCSymbol *End) {
>> - Unit->addLabelAddress(D, dwarf::DW_AT_low_pc, Begin);
>> + Unit.addLabelAddress(D, dwarf::DW_AT_low_pc, Begin);
>> if (DwarfVersion < 4)
>> - Unit->addLabelAddress(D, dwarf::DW_AT_high_pc, End);
>> + Unit.addLabelAddress(D, dwarf::DW_AT_high_pc, End);
>> else
>> - Unit->addLabelDelta(D, dwarf::DW_AT_high_pc, End, Begin);
>> + Unit.addLabelDelta(D, dwarf::DW_AT_high_pc, End, Begin);
>> }
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=206925&r1=206924&r2=206925&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Tue Apr 22 17:39:41 2014
>> @@ -30,6 +30,8 @@
>> #include "llvm/MC/MCDwarf.h"
>> #include "llvm/Support/Allocator.h"
>>
>> +#include <memory>
>> +
>> namespace llvm {
>>
>> class AsmPrinter;
>> @@ -184,7 +186,7 @@ public:
>> void assignAbbrevNumber(DIEAbbrev &Abbrev);
>>
>> /// \brief Add a unit to the list of CUs.
>> - void addUnit(DwarfUnit *CU);
>> + void addUnit(std::unique_ptr<DwarfUnit> U);
>>
>> /// \brief Emit all of the units to the section listed with the given
>> /// abbreviation section.
>> @@ -423,7 +425,7 @@ class DwarfDebug : public AsmPrinterHand
>> /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
>> /// variables in this scope then create and insert DIEs for these
>> /// variables.
>> - DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP);
>> + DIE *updateSubprogramScopeDIE(DwarfCompileUnit &SPCU, DISubprogram SP);
>>
>> /// \brief A helper function to check whether the DIE for a given Scope is
>> /// going to be null.
>> @@ -431,21 +433,21 @@ class DwarfDebug : public AsmPrinterHand
>>
>> /// \brief A helper function to construct a RangeSpanList for a given
>> /// lexical scope.
>> - void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE,
>> + void addScopeRangeList(DwarfCompileUnit &TheCU, DIE *ScopeDIE,
>> const SmallVectorImpl<InsnRange> &Range);
>>
>> /// \brief Construct new DW_TAG_lexical_block for this scope and
>> /// attach DW_AT_low_pc/DW_AT_high_pc labels.
>> - DIE *constructLexicalScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
>> + DIE *constructLexicalScopeDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope);
>>
>> /// \brief This scope represents inlined body of a function. Construct
>> /// DIE to represent this concrete inlined copy of the function.
>> - DIE *constructInlinedScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
>> + DIE *constructInlinedScopeDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope);
>>
>> /// \brief Construct a DIE for this scope.
>> - DIE *constructScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
>> + DIE *constructScopeDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope);
>> /// A helper function to create children of a Scope DIE.
>> - DIE *createScopeChildrenDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope,
>> + DIE *createScopeChildrenDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope,
>> SmallVectorImpl<DIE *> &Children);
>>
>> /// \brief Emit initial Dwarf sections with a label at the start of each one.
>> @@ -532,15 +534,16 @@ class DwarfDebug : public AsmPrinterHand
>> /// DWARF 5 Experimental Split Dwarf Emitters
>>
>> /// \brief Initialize common features of skeleton units.
>> - void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU);
>> + void initSkeletonUnit(const DwarfUnit &U, DIE *Die,
>> + std::unique_ptr<DwarfUnit> NewU);
>>
>> /// \brief Construct the split debug info compile unit for the debug info
>> /// section.
>> - DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU);
>> + DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
>>
>> /// \brief Construct the split debug info compile unit for the debug info
>> /// section.
>> - DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU);
>> + DwarfTypeUnit &constructSkeletonTU(DwarfTypeUnit &TU);
>>
>> /// \brief Emit the debug info dwo section.
>> void emitDebugInfoDWO();
>> @@ -556,24 +559,24 @@ class DwarfDebug : public AsmPrinterHand
>>
>> /// Flags to let the linker know we have emitted new style pubnames. Only
>> /// emit it here if we don't have a skeleton CU for split dwarf.
>> - void addGnuPubAttributes(DwarfUnit *U, DIE *D) const;
>> + void addGnuPubAttributes(DwarfUnit &U, DIE *D) const;
>>
>> /// \brief Create new DwarfCompileUnit for the given metadata node with tag
>> /// DW_TAG_compile_unit.
>> - DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit);
>> + DwarfCompileUnit &constructDwarfCompileUnit(DICompileUnit DIUnit);
>>
>> /// \brief Construct subprogram DIE.
>> - void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
>> + void constructSubprogramDIE(DwarfCompileUnit &TheCU, const MDNode *N);
>>
>> /// \brief Construct imported_module or imported_declaration DIE.
>> - void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N);
>> + void constructImportedEntityDIE(DwarfCompileUnit &TheCU, const MDNode *N);
>>
>> /// \brief Construct import_module DIE.
>> - void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N,
>> + void constructImportedEntityDIE(DwarfCompileUnit &TheCU, const MDNode *N,
>> DIE *Context);
>>
>> /// \brief Construct import_module DIE.
>> - void constructImportedEntityDIE(DwarfCompileUnit *TheCU,
>> + void constructImportedEntityDIE(DwarfCompileUnit &TheCU,
>> const DIImportedEntity &Module, DIE *Context);
>>
>> /// \brief Register a source line with debug info. Returns the unique
>> @@ -613,7 +616,7 @@ class DwarfDebug : public AsmPrinterHand
>> /// \brief Return Label immediately following the instruction.
>> MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
>>
>> - void attachLowHighPC(DwarfCompileUnit *Unit, DIE *D, MCSymbol *Begin,
>> + void attachLowHighPC(DwarfCompileUnit &Unit, DIE *D, MCSymbol *Begin,
>> MCSymbol *End);
>>
>> public:
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h?rev=206925&r1=206924&r2=206925&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h Tue Apr 22 17:39:41 2014
>> @@ -163,7 +163,7 @@ public:
>> virtual ~DwarfUnit();
>>
>> /// Set the skeleton unit associated with this unit.
>> - void setSkeleton(DwarfUnit *Skel) { Skeleton = Skel; }
>> + void setSkeleton(DwarfUnit &Skel) { Skeleton = &Skel; }
>>
>> /// Get the skeleton unit associated with this unit.
>> DwarfUnit *getSkeleton() const { return Skeleton; }
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list