Support for ThinLTO function importing and symbol linking.
[oota-llvm.git] / include / llvm / IR / FunctionInfo.h
index 264954757cfcefe661f356d47f969b2c660dc076..e265ad3709637b5a8bd2d1b964cf3bd1153e1060 100644 (file)
@@ -165,8 +165,18 @@ private:
   /// Holds strings for combined index, mapping to the corresponding module ID.
   ModulePathStringTableTy ModulePathStringTable;
 
+  /// The main module being compiled, that we are importing into, if applicable.
+  /// Used to check if any of its functions are in the index and therefore
+  /// potentially exported.
+  const Module *ExportingModule;
+
+  /// Flag indicating whether the exporting module has any functions in the
+  /// index and therefore potentially exported (imported into another module).
+  bool HasExportedFunctions;
+
 public:
-  FunctionInfoIndex() = default;
+  FunctionInfoIndex(const Module *M = nullptr)
+      : ExportingModule(M), HasExportedFunctions(false){};
   ~FunctionInfoIndex() = default;
 
   // Disable the copy constructor and assignment operators, so
@@ -186,6 +196,12 @@ public:
 
   /// Add a function info for a function of the given name.
   void addFunctionInfo(StringRef FuncName, std::unique_ptr<FunctionInfo> Info) {
+    if (ExportingModule) {
+      assert(Info->functionSummary());
+      if (ExportingModule->getModuleIdentifier() ==
+          Info->functionSummary()->modulePath())
+        HasExportedFunctions = true;
+    }
     FunctionMap[FuncName].push_back(std::move(Info));
   }
 
@@ -223,6 +239,14 @@ public:
     return ModulePathStringTable.insert(std::make_pair(ModPath, ModId))
         .first->first();
   }
+
+  /// Check if the given Module has any functions available for exporting
+  /// in the index.
+  bool hasExportedFunctions(const Module *M) {
+    assert(M == ExportingModule &&
+           "Checking for exported functions on unexpected module");
+    return HasExportedFunctions;
+  }
 };
 
 } // End llvm namespace