[lld] r208818 - [PECOFF] Read files lazily.

Rui Ueyama ruiu at google.com
Wed May 14 15:35:47 PDT 2014


Author: ruiu
Date: Wed May 14 17:35:47 2014
New Revision: 208818

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

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h

Modified: lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h?rev=208818&r1=208817&r2=208818&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h Wed May 14 17:35:47 2014
@@ -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;
 };





More information about the llvm-commits mailing list