[llvm] r265233 - Linker: Split mapUnneededSubprograms into two; almost NFC

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 2 10:54:01 PDT 2016


Author: dexonsmith
Date: Sat Apr  2 12:54:01 2016
New Revision: 265233

URL: http://llvm.org/viewvc/llvm-project?rev=265233&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Linker/IRMover.cpp

Modified: llvm/trunk/lib/Linker/IRMover.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/IRMover.cpp?rev=265233&r1=265232&r2=265233&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/IRMover.cpp (original)
+++ llvm/trunk/lib/Linker/IRMover.cpp Sat Apr  2 12:54:01 2016
@@ -1040,22 +1040,26 @@ void IRLinker::mapUnneededSubprograms()
   NamedMDNode *CompileUnits = SrcM->getNamedMetadata("llvm.dbg.cu");
   if (!CompileUnits)
     return;
-  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())
+  // 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) {
+    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;
   }




More information about the llvm-commits mailing list