<div dir="ltr">I'm still vaguely thinking we should be doing this in the frontend instead.<br><br>Could you remind me what problems happen if there are duplicates? And why it was hard to detect duplicates in the frontend? (why we even ever visited the same using decl more than once?)<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 24, 2016 at 6:47 AM, Amjad Aboud via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">aaboud created this revision.<br>
aaboud added reviewers: dexonsmith, dblaikie, aprantl.<br>
aaboud added a subscriber: llvm-commits.<br>
<br>
Following Duncan suggestion of improving code to disallow duplication of imported entities from commit: <a href="http://reviews.llvm.org/rL263379" rel="noreferrer" target="_blank">http://reviews.llvm.org/rL263379</a><br>
By simply filter the AllImportedModules list at DIBuilder::finalize function.<br>
<br>
Note: LIT test was committed in revision 263379.<br>
<br>
<a href="http://reviews.llvm.org/D19468" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19468</a><br>
<br>
Files:<br>
lib/IR/DIBuilder.cpp<br>
<br>
Index: lib/IR/DIBuilder.cpp<br>
===================================================================<br>
--- lib/IR/DIBuilder.cpp<br>
+++ lib/IR/DIBuilder.cpp<br>
@@ -119,10 +119,16 @@<br>
if (!AllGVs.empty())<br>
CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));<br>
<br>
- if (!AllImportedModules.empty())<br>
- CUNode->replaceImportedEntities(MDTuple::get(<br>
- VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(),<br>
- AllImportedModules.end())));<br>
+ // Create imported entities list without duplications.<br>
+ SmallVector<Metadata *, 16> ImportedModules;<br>
+ SmallPtrSet<Metadata *, 16> AlreadyImported;<br>
+ std::remove_copy_if(AllImportedModules.begin(), AllImportedModules.end(),<br>
+ std::back_inserter(ImportedModules),<br>
+ [&AlreadyImported](TrackingMDNodeRef &Ref) {<br>
+ return !AlreadyImported.insert(Ref.get()).second;<br>
+ });<br>
+ if (!ImportedModules.empty())<br>
+ CUNode->replaceImportedEntities(MDTuple::get(VMContext, ImportedModules));<br>
<br>
// Now that all temp nodes have been replaced or deleted, resolve remaining<br>
// cycles.<br>
@@ -170,12 +176,8 @@<br>
createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context,<br>
Metadata *NS, unsigned Line, StringRef Name,<br>
SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {<br>
- unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size();<br>
auto *M = DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), Line, Name);<br>
- if (EntitiesCount < C.pImpl->DIImportedEntitys.size())<br>
- // A new Imported Entity was just added to the context.<br>
- // Add it to the Imported Modules list.<br>
- AllImportedModules.emplace_back(M);<br>
+ AllImportedModules.emplace_back(M);<br>
return M;<br>
}<br>
<br>
<br>
<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>