Index: include/llvm/Bitcode/ReaderWriter.h =================================================================== --- include/llvm/Bitcode/ReaderWriter.h +++ include/llvm/Bitcode/ReaderWriter.h @@ -71,15 +71,13 @@ DiagnosticHandlerFunction DiagnosticHandler); /// Parse the specified bitcode buffer, returning the function info index. - /// If ExportingModule is true, check for functions in the index from this - /// module when the combined index is built during parsing and set flag. /// If IsLazy is true, parse the entire function summary into /// the index. Otherwise skip the function summary section, and only create /// an index object with a map from function name to function summary offset. /// The index is used to perform lazy function summary reading later. ErrorOr> getFunctionInfoIndex( MemoryBufferRef Buffer, DiagnosticHandlerFunction DiagnosticHandler, - const Module *ExportingModule = nullptr, bool IsLazy = false); + bool IsLazy = false); /// This method supports lazy reading of function summary data from the /// combined index during function importing. When reading the combined index Index: include/llvm/IR/FunctionInfo.h =================================================================== --- include/llvm/IR/FunctionInfo.h +++ include/llvm/IR/FunctionInfo.h @@ -165,19 +165,8 @@ /// 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(const Module *M = nullptr) - : ExportingModule(M), HasExportedFunctions(false){}; - ~FunctionInfoIndex() = default; + FunctionInfoIndex() = default; // Disable the copy constructor and assignment operators, so // no unexpected copying/moving occurs. @@ -201,14 +190,6 @@ /// Add a function info for a function of the given name. void addFunctionInfo(StringRef FuncName, std::unique_ptr Info) { - // Update the HasExportedFunctions flag, but only if we had a function - // summary (i.e. we aren't parsing them lazily or have a bitcode file - // without a function summary section). - if (ExportingModule && Info->functionSummary()) { - if (ExportingModule->getModuleIdentifier() == - Info->functionSummary()->modulePath()) - HasExportedFunctions = true; - } FunctionMap[FuncName].push_back(std::move(Info)); } @@ -248,11 +229,10 @@ } /// Check if the given Module has any functions available for exporting - /// in the index. - bool hasExportedFunctions(const Module *M) const { - assert(M == ExportingModule && - "Checking for exported functions on unexpected module"); - return HasExportedFunctions; + /// in the index. We consider any module present in the ModulePathStringTable + /// to have exported functions. + bool hasExportedFunctions(const Module &M) const { + return ModulePathStringTable.count(M.getModuleIdentifier()); } }; Index: include/llvm/Object/FunctionIndexObjectFile.h =================================================================== --- include/llvm/Object/FunctionIndexObjectFile.h +++ include/llvm/Object/FunctionIndexObjectFile.h @@ -88,7 +88,7 @@ /// summary/index. static ErrorOr> create(MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler, - const Module *ExportingModule = nullptr, bool IsLazy = false); + bool IsLazy = false); /// \brief Parse the function summary information for function with the /// given name out of the given buffer. Parsed information is @@ -104,8 +104,7 @@ /// index object if found, or nullptr if not. ErrorOr> getFunctionIndexForFile(StringRef Path, - DiagnosticHandlerFunction DiagnosticHandler, - const Module *ExportingModule = nullptr); + DiagnosticHandlerFunction DiagnosticHandler); } #endif Index: lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- lib/Bitcode/Reader/BitcodeReader.cpp +++ lib/Bitcode/Reader/BitcodeReader.cpp @@ -5991,12 +5991,11 @@ ErrorOr> llvm::getFunctionInfoIndex(MemoryBufferRef Buffer, DiagnosticHandlerFunction DiagnosticHandler, - const Module *ExportingModule, bool IsLazy) { + bool IsLazy) { std::unique_ptr Buf = MemoryBuffer::getMemBuffer(Buffer, false); FunctionIndexBitcodeReader R(Buf.get(), DiagnosticHandler, IsLazy); - std::unique_ptr Index = - llvm::make_unique(ExportingModule); + auto Index = llvm::make_unique(); auto cleanupOnError = [&](std::error_code EC) { R.releaseBuffer(); // Never take ownership on error. Index: lib/Linker/LinkModules.cpp =================================================================== --- lib/Linker/LinkModules.cpp +++ lib/Linker/LinkModules.cpp @@ -454,7 +454,7 @@ // backend compilation, and we need to see if it has functions that // may be exported to another backend compilation. if (ImportIndex && !ImportFunction) - HasExportedFunctions = ImportIndex->hasExportedFunctions(SrcM); + HasExportedFunctions = ImportIndex->hasExportedFunctions(*SrcM); } bool run(); Index: lib/Object/FunctionIndexObjectFile.cpp =================================================================== --- lib/Object/FunctionIndexObjectFile.cpp +++ lib/Object/FunctionIndexObjectFile.cpp @@ -86,7 +86,7 @@ ErrorOr> FunctionIndexObjectFile::create(MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler, - const Module *ExportingModule, bool IsLazy) { + bool IsLazy) { std::unique_ptr Index; ErrorOr BCOrErr = findBitcodeInMemBuffer(Object); @@ -94,7 +94,7 @@ return BCOrErr.getError(); ErrorOr> IOrErr = getFunctionInfoIndex( - BCOrErr.get(), DiagnosticHandler, ExportingModule, IsLazy); + BCOrErr.get(), DiagnosticHandler, IsLazy); if (std::error_code EC = IOrErr.getError()) return EC; @@ -125,8 +125,7 @@ // index object if found, or nullptr if not. ErrorOr> llvm::getFunctionIndexForFile(StringRef Path, - DiagnosticHandlerFunction DiagnosticHandler, - const Module *ExportingModule) { + DiagnosticHandlerFunction DiagnosticHandler) { ErrorOr> FileOrErr = MemoryBuffer::getFileOrSTDIN(Path); std::error_code EC = FileOrErr.getError(); @@ -134,8 +133,7 @@ return EC; MemoryBufferRef BufferRef = (FileOrErr.get())->getMemBufferRef(); ErrorOr> ObjOrErr = - object::FunctionIndexObjectFile::create(BufferRef, DiagnosticHandler, - ExportingModule); + object::FunctionIndexObjectFile::create(BufferRef, DiagnosticHandler); EC = ObjOrErr.getError(); if (EC) return EC; Index: tools/llvm-link/llvm-link.cpp =================================================================== --- tools/llvm-link/llvm-link.cpp +++ tools/llvm-link/llvm-link.cpp @@ -229,7 +229,7 @@ std::unique_ptr Index; if (!FunctionIndex.empty()) { ErrorOr> IndexOrErr = - llvm::getFunctionIndexForFile(FunctionIndex, diagnosticHandler, &*M); + llvm::getFunctionIndexForFile(FunctionIndex, diagnosticHandler); std::error_code EC = IndexOrErr.getError(); if (EC) { errs() << EC.message() << '\n';