diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-04-02 17:54:01 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-04-02 17:54:01 +0000 |
commit | 6d72d166dc0b67418bd334886e29a0a2bf541a92 (patch) | |
tree | 358376de90d65097acb52202e8ca8135827619f7 /llvm/lib/Linker | |
parent | 751114b39d434bdd2b6f95330bed7fdcc7a0d580 (diff) | |
download | bcm5719-llvm-6d72d166dc0b67418bd334886e29a0a2bf541a92.tar.gz bcm5719-llvm-6d72d166dc0b67418bd334886e29a0a2bf541a92.zip |
Linker: Split mapUnneededSubprograms into two; almost NFC
Split the loop through compile units in mapUnneededSubprograms in two.
First, visit imported entities to ensure that we've visited all need
subprograms. Second, visit subprograms, and drop the ones we don't
need.
Hypothetically this protects against a subprogram from one compile unit
being referenced from an imported entity in a different compile unit. I
don't think that's valid IR (a debug info expert could confirm), but I
think the refactor makes the code more clear.
llvm-svn: 265233
Diffstat (limited to 'llvm/lib/Linker')
-rw-r--r-- | llvm/lib/Linker/IRMover.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index b7058f433bc..57a5401f6c7 100644 --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -1040,22 +1040,26 @@ void IRLinker::mapUnneededSubprograms() { NamedMDNode *CompileUnits = SrcM->getNamedMetadata("llvm.dbg.cu"); if (!CompileUnits) return; + + // Seed the ValueMap with the imported entities, in case they reference new + // subprograms. + // FIXME: The DISubprogram for functions not linked in but kept due to + // being referenced by a DIImportedEntity should also get their + // IsDefinition flag is unset. for (unsigned I = 0, E = CompileUnits->getNumOperands(); I != E; ++I) { - auto *CU = cast<DICompileUnit>(CompileUnits->getOperand(I)); - - // Seed the ValueMap with the imported entities, in case they reference new - // subprograms. - // FIXME: The DISubprogram for functions not linked in but kept due to - // being referenced by a DIImportedEntity should also get their - // IsDefinition flag is unset. - if (MDTuple *IEs = CU->getImportedEntities().get()) + if (MDTuple *IEs = cast<DICompileUnit>(CompileUnits->getOperand(I)) + ->getImportedEntities() + .get()) (void)MapMetadata(IEs, ValueMap, ValueMapperFlags | RF_NullMapMissingGlobalValues, &TypeMap, &GValMaterializer); + } - // Try to insert nullptr into the map for any SP not already mapped. If - // the insertion succeeds, we don't need this subprogram. - for (auto *Op : CU->getSubprograms()) + // Try to insert nullptr into the map for any SP not already mapped. If + // the insertion succeeds, we don't need this subprogram. + for (unsigned I = 0, E = CompileUnits->getNumOperands(); I != E; ++I) { + for (auto *Op : + cast<DICompileUnit>(CompileUnits->getOperand(I))->getSubprograms()) if (ValueMap.MD().insert(std::make_pair(Op, TrackingMDRef())).second) HasUnneededSPs = true; } |