diff options
| author | Rui Ueyama <ruiu@google.com> | 2014-05-14 22:35:47 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2014-05-14 22:35:47 +0000 |
| commit | 5def41ee40bdfb7930a86d5ca599d948f5b86f98 (patch) | |
| tree | a5f1601fe09ac44dcb428ab79f35f88d1649369e | |
| parent | 9ba72546880f5cc21a5f9f17a2e71774912520d8 (diff) | |
| download | bcm5719-llvm-5def41ee40bdfb7930a86d5ca599d948f5b86f98.tar.gz bcm5719-llvm-5def41ee40bdfb7930a86d5ca599d948f5b86f98.zip | |
[PECOFF] Read files lazily.
ExportedSymbolRenameFile is not always used. In most cases we don't
need to read given files at all. So lazy load would help. This doesn't
change the meaining of the program.
llvm-svn: 208818
| -rw-r--r-- | lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h index a6f69392b98..2a309e774b2 100644 --- a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h +++ b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h @@ -202,19 +202,13 @@ public: if (_seen.count(file) > 0) return; _seen.insert(file); - if (auto *archive = dyn_cast<ArchiveLibraryFile>(file)) { - for (const std::string &sym : archive->getDefinedSymbols()) - _defined.insert(sym); - return; - } - for (const DefinedAtom *atom : file->defined()) - if (!atom->name().empty()) - _defined.insert(atom->name()); + _queue.insert(file); } const File *find(StringRef sym, bool dataSymbolOnly) const override { if (_exportedSyms.count(sym) == 0) return nullptr; + readAllSymbols(); std::string replace; if (!findSymbolWithAtsignSuffix(sym.str(), replace)) return nullptr; @@ -222,6 +216,22 @@ public: } private: + // Files are read lazily, so that it has no runtime overhead if + // there's no dllexported stdcall functions. + void readAllSymbols() const { + for (File *file : _queue) { + if (auto *archive = dyn_cast<ArchiveLibraryFile>(file)) { + for (const std::string &sym : archive->getDefinedSymbols()) + _defined.insert(sym); + continue; + } + for (const DefinedAtom *atom : file->defined()) + if (!atom->name().empty()) + _defined.insert(atom->name()); + } + _queue.clear(); + } + // Find a symbol that starts with a given symbol name followed // by @number suffix. bool findSymbolWithAtsignSuffix(std::string sym, std::string &res) const { @@ -242,8 +252,9 @@ private: } std::set<std::string> _exportedSyms; - std::set<std::string> _defined; std::set<File *> _seen; + mutable std::set<std::string> _defined; + mutable std::set<File *> _queue; mutable std::mutex _mutex; mutable llvm::BumpPtrAllocator _alloc; }; |

