[lld] r231395 - Resolver: Update preload map after File::beforeLink().
Rui Ueyama
ruiu at google.com
Thu Mar 5 12:25:42 PST 2015
This has really visible effect other than speed up. As long as existing
tests are okay, it should be okay.
On Thu, Mar 5, 2015 at 12:23 PM, Shankar Easwaran <shankare at codeaurora.org>
wrote:
> No test ?
>
>
> On 3/5/2015 1:25 PM, Rui Ueyama wrote:
>
>> Author: ruiu
>> Date: Thu Mar 5 13:25:58 2015
>> New Revision: 231395
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=231395&view=rev
>> Log:
>> Resolver: Update preload map after File::beforeLink().
>>
>> We maintain a map from symbols to archive files for the archive file
>> pre-loading. That map is created at the beginning of the resolve()
>> and is never updated. However, the input file list may be updated by
>> File::beforeLink(). This is a patch to update the map after beforeLink.
>>
>> Modified:
>> lld/trunk/include/lld/Core/Resolver.h
>> lld/trunk/lib/Core/Resolver.cpp
>>
>> Modified: lld/trunk/include/lld/Core/Resolver.h
>> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/
>> Core/Resolver.h?rev=231395&r1=231394&r2=231395&view=diff
>> ============================================================
>> ==================
>> --- lld/trunk/include/lld/Core/Resolver.h (original)
>> +++ lld/trunk/include/lld/Core/Resolver.h Thu Mar 5 13:25:58 2015
>> @@ -18,6 +18,7 @@
>> #include "llvm/ADT/DenseMap.h"
>> #include "llvm/ADT/DenseSet.h"
>> #include <set>
>> +#include <unordered_set>
>> #include <vector>
>> namespace lld {
>> @@ -64,7 +65,7 @@ private:
>> void maybeAddSectionGroupOrGnuLinkOnce(const DefinedAtom &atom);
>> /// \brief The main function that iterates over the files to resolve
>> - void makePreloadArchiveMap();
>> + void updatePreloadArchiveMap();
>> bool resolveUndefines();
>> void updateReferences();
>> void deadStripOptimize();
>> @@ -99,6 +100,7 @@ private:
>> // Preloading
>> std::map<StringRef, ArchiveLibraryFile *> _archiveMap;
>> + std::unordered_set<ArchiveLibraryFile *> _archiveSeen;
>> };
>> } // namespace lld
>>
>> Modified: lld/trunk/lib/Core/Resolver.cpp
>> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/
>> Resolver.cpp?rev=231395&r1=231394&r2=231395&view=diff
>> ============================================================
>> ==================
>> --- lld/trunk/lib/Core/Resolver.cpp (original)
>> +++ lld/trunk/lib/Core/Resolver.cpp Thu Mar 5 13:25:58 2015
>> @@ -83,6 +83,7 @@ bool Resolver::handleArchiveFile(File &f
>> if (File *member = archiveFile->find(undefName, dataSymbolOnly)) {
>> member->setOrdinal(_ctx.getNextOrdinalAndIncrement());
>> member->beforeLink();
>> + updatePreloadArchiveMap();
>> undefAdded = handleFile(*member) || undefAdded;
>> }
>> });
>> @@ -274,14 +275,21 @@ File *Resolver::getFile(int &index) {
>> return cast<FileNode>(inputs[index++].get())->getFile();
>> }
>> -// Make a map of Symbol -> ArchiveFile.
>> -void Resolver::makePreloadArchiveMap() {
>> +// Update a map of Symbol -> ArchiveFile. The map is used for speculative
>> +// file loading.
>> +void Resolver::updatePreloadArchiveMap() {
>> std::vector<std::unique_ptr<Node>> &nodes = _ctx.getNodes();
>> - for (int i = nodes.size() - 1; i >= 0; --i)
>> - if (auto *fnode = dyn_cast<FileNode>(nodes[i].get()))
>> - if (auto *archive = dyn_cast<ArchiveLibraryFile>(
>> fnode->getFile()))
>> - for (StringRef sym : archive->getDefinedSymbols())
>> - _archiveMap[sym] = archive;
>> + for (int i = nodes.size() - 1; i >= 0; --i) {
>> + auto *fnode = dyn_cast<FileNode>(nodes[i].get());
>> + if (!fnode)
>> + continue;
>> + auto *archive = dyn_cast<ArchiveLibraryFile>(fnode->getFile());
>> + if (!archive || _archiveSeen.count(archive))
>> + continue;
>> + _archiveSeen.insert(archive);
>> + for (StringRef sym : archive->getDefinedSymbols())
>> + _archiveMap[sym] = archive;
>> + }
>> }
>> // Keep adding atoms until _ctx.getNextFile() returns an error. This
>> @@ -301,6 +309,7 @@ bool Resolver::resolveUndefines() {
>> return false;
>> }
>> file->beforeLink();
>> + updatePreloadArchiveMap();
>> switch (file->kind()) {
>> case File::kindObject:
>> // The same file may be visited more than once if the file is
>> @@ -477,7 +486,7 @@ void Resolver::removeCoalescedAwayAtoms(
>> }
>> bool Resolver::resolve() {
>> - makePreloadArchiveMap();
>> + updatePreloadArchiveMap();
>> if (!resolveUndefines())
>> return false;
>> updateReferences();
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>>
>>
>
> --
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted
> by the Linux Foundation
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150305/518c123c/attachment.html>
More information about the llvm-commits
mailing list