[PATCH] D19468: Disallow duplication of imported entities (improved implementation)

Amjad Aboud via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 24 06:47:20 PDT 2016


aaboud created this revision.
aaboud added reviewers: dexonsmith, dblaikie, aprantl.
aaboud added a subscriber: llvm-commits.

Following Duncan suggestion of improving code to disallow duplication of imported entities from commit: http://reviews.llvm.org/rL263379
By simply filter the AllImportedModules list at DIBuilder::finalize function.

Note: LIT test was committed in revision 263379.

http://reviews.llvm.org/D19468

Files:
  lib/IR/DIBuilder.cpp

Index: lib/IR/DIBuilder.cpp
===================================================================
--- lib/IR/DIBuilder.cpp
+++ lib/IR/DIBuilder.cpp
@@ -119,10 +119,16 @@
   if (!AllGVs.empty())
     CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));
 
-  if (!AllImportedModules.empty())
-    CUNode->replaceImportedEntities(MDTuple::get(
-        VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(),
-                                               AllImportedModules.end())));
+  // Create imported entities list without duplications.
+  SmallVector<Metadata *, 16> ImportedModules;
+  SmallPtrSet<Metadata *, 16> AlreadyImported;
+  std::remove_copy_if(AllImportedModules.begin(), AllImportedModules.end(),
+    std::back_inserter(ImportedModules),
+    [&AlreadyImported](TrackingMDNodeRef &Ref) {
+    return !AlreadyImported.insert(Ref.get()).second;
+  });
+  if (!ImportedModules.empty())
+    CUNode->replaceImportedEntities(MDTuple::get(VMContext, ImportedModules));
 
   // Now that all temp nodes have been replaced or deleted, resolve remaining
   // cycles.
@@ -170,12 +176,8 @@
 createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context,
                      Metadata *NS, unsigned Line, StringRef Name,
                      SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
-  unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size();
   auto *M = DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), Line, Name);
-  if (EntitiesCount < C.pImpl->DIImportedEntitys.size())
-    // A new Imported Entity was just added to the context.
-    // Add it to the Imported Modules list.
-    AllImportedModules.emplace_back(M);
+  AllImportedModules.emplace_back(M);
   return M;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19468.54802.patch
Type: text/x-patch
Size: 1775 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160424/980164d3/attachment.bin>


More information about the llvm-commits mailing list