diff options
author | Teresa Johnson <tejohnson@google.com> | 2016-01-28 15:08:09 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2016-01-28 15:08:09 +0000 |
commit | beb43ba7e5b5524ad0296a4d1f1271e0212ddd33 (patch) | |
tree | f51173fca2837c2f6ffaaa2128dbf4ae2553e97e /llvm/lib/Linker | |
parent | ea59b9d91f072bf7f6fccf2c1c566c9e0f060369 (diff) | |
download | bcm5719-llvm-beb43ba7e5b5524ad0296a4d1f1271e0212ddd33.tar.gz bcm5719-llvm-beb43ba7e5b5524ad0296a4d1f1271e0212ddd33.zip |
Improve efficiency of handling unmapped subprogram metadata
The stripNullSubprograms function is very inefficient because
it walks all subprograms in all compile units in the dest module
any time a new module is linked in. For LTO in particular this will
get increasingly expensive as more modules are linked.
This patch improves the efficiency in several ways. The first is that
no scanning is necessary when there were no unneeded subprograms
identified in the first place. The second is that only the newly-linked
module's compile unit metadata should be examined.
Fixes PR26346.
llvm-svn: 259049
Diffstat (limited to 'llvm/lib/Linker')
-rw-r--r-- | llvm/lib/Linker/IRMover.cpp | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index 6dbc183f782..bc2cc66541f 100644 --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -507,8 +507,9 @@ class IRLinker { SmallPtrSet<const MDNode *, 16> &Visited); /// The value mapper leaves nulls in the list of subprograms for any - /// in the UnneededSubprograms map. Strip those out after metadata linking. - void stripNullSubprograms(); + /// in the UnneededSubprograms map. Strip those out of the mapped + /// compile unit. + void stripNullSubprograms(DICompileUnit *CU); public: IRLinker(Module &DstM, IRMover::IdentifiedStructTypeSet &Set, Module &SrcM, @@ -1266,28 +1267,24 @@ void IRLinker::findNeededSubprograms() { } } -// Squash null subprograms from compile unit subprogram lists. -void IRLinker::stripNullSubprograms() { - NamedMDNode *CompileUnits = DstM.getNamedMetadata("llvm.dbg.cu"); - if (!CompileUnits) +// Squash null subprograms from the given compile unit's subprogram list. +void IRLinker::stripNullSubprograms(DICompileUnit *CU) { + // There won't be any nulls if we didn't have any subprograms marked + // as unneeded. + if (UnneededSubprograms.empty()) return; - for (unsigned I = 0, E = CompileUnits->getNumOperands(); I != E; ++I) { - auto *CU = cast<DICompileUnit>(CompileUnits->getOperand(I)); - assert(CU && "Expected valid compile unit"); - - SmallVector<Metadata *, 16> NewSPs; - NewSPs.reserve(CU->getSubprograms().size()); - bool FoundNull = false; - for (DISubprogram *SP : CU->getSubprograms()) { - if (!SP) { - FoundNull = true; - continue; - } - NewSPs.push_back(SP); + SmallVector<Metadata *, 16> NewSPs; + NewSPs.reserve(CU->getSubprograms().size()); + bool FoundNull = false; + for (DISubprogram *SP : CU->getSubprograms()) { + if (!SP) { + FoundNull = true; + continue; } - if (FoundNull) - CU->replaceSubprograms(MDTuple::get(CU->getContext(), NewSPs)); + NewSPs.push_back(SP); } + if (FoundNull) + CU->replaceSubprograms(MDTuple::get(CU->getContext(), NewSPs)); } /// Insert all of the named MDNodes in Src into the Dest module. @@ -1300,12 +1297,18 @@ void IRLinker::linkNamedMDNodes() { continue; NamedMDNode *DestNMD = DstM.getOrInsertNamedMetadata(NMD.getName()); // Add Src elements into Dest node. - for (const MDNode *op : NMD.operands()) - DestNMD->addOperand(MapMetadata( + for (const MDNode *op : NMD.operands()) { + MDNode *DestMD = MapMetadata( op, ValueMap, ValueMapperFlags | RF_NullMapMissingGlobalValues, - &TypeMap, &GValMaterializer)); + &TypeMap, &GValMaterializer); + // For each newly mapped compile unit remove any null subprograms, + // which occur when findNeededSubprograms identified any as unneeded + // in the dest module. + if (auto *CU = dyn_cast<DICompileUnit>(DestMD)) + stripNullSubprograms(CU); + DestNMD->addOperand(DestMD); + } } - stripNullSubprograms(); } /// Merge the linker flags in Src into the Dest module. |