Keep track of all modules crated using a name to module map.
authorDevang Patel <dpatel@apple.com>
Wed, 6 Sep 2006 18:50:26 +0000 (18:50 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 6 Sep 2006 18:50:26 +0000 (18:50 +0000)
Add private member function getMoudle().

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30130 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/LinkTimeOptimizer.h
tools/lto/lto.cpp

index d20d21e4c025adbf3a86aa5ec2c887bb128d8fd0..76a7af66da0c583ff5ab487923b82ab969ed0932 100644 (file)
@@ -83,6 +83,8 @@ namespace llvm {
   public:
     typedef hash_map<const char*, LLVMSymbol*, hash<const char*>, 
                      string_compare> NameToSymbolMap;
+    typedef hash_map<const char*, Module*, hash<const char*>, 
+                     string_compare> NameToModuleMap;
 
     enum LTOStatus readLLVMObjectFile(const std::string &InputFilename,
                                       NameToSymbolMap &symbols,
@@ -91,9 +93,13 @@ namespace llvm {
                                    std::vector<const char*> &exportList,
                                    std::string &targetTriple);
 
+  private:
+    Module *getModule (const std::string &InputFilename);
+
   private:
     std::vector<Module *> modules;
     NameToSymbolMap allSymbols;
+    NameToModuleMap allModules;
   };
 
 } // End llvm namespace
index e49364e6320f82d767d281d4c682c62806cb858a..96b449e28c80cc297e00ca2b97abebd613213e15 100644 (file)
@@ -99,6 +99,23 @@ findExternalRefs(Value *value, std::set<std::string> &references,
       findExternalRefs(c->getOperand(i), references, mangler);
 }
 
+/// InputFilename is a LLVM bytecode file. If Module with InputFilename is
+/// available then return it. Otherwise parseInputFilename.
+Module *
+LinkTimeOptimizer::getModule(const std::string &InputFilename)
+{
+  Module *m = NULL;
+
+  NameToModuleMap::iterator pos = allModules.find(InputFilename.c_str());
+  if (pos != allModules.end())
+    m = allModules[InputFilename.c_str()];
+  else {
+    m = ParseBytecodeFile(InputFilename);
+    allModules[InputFilename.c_str()] = m;
+  }
+  return m;
+}
+
 /// InputFilename is a LLVM bytecode file. Read it using bytecode reader.
 /// Collect global functions and symbol names in symbols vector.
 /// Collect external references in references vector.
@@ -108,7 +125,7 @@ LinkTimeOptimizer::readLLVMObjectFile(const std::string &InputFilename,
                                       NameToSymbolMap &symbols,
                                       std::set<std::string> &references)
 {
-  Module *m = ParseBytecodeFile(InputFilename);
+  Module *m = getModule(InputFilename);
   if (!m)
     return LTO_READ_FAILURE;