llvm.org GIT mirror llvm / d4c7e11
Remove "ExportingModule" from ThinLTO Index (NFC) There is no real reason the index has to have the concept of an exporting Module. We should be able to have one single unique instance of the Index, and it should be read-only after creation for the whole ThinLTO processing. The linker plugin should be able to process multiple modules (in parallel or in sequence) with the same index. The only reason the ExportingModule was present seems to be to implement hasExportedFunctions() that is used by the Module linker to decide what to do with the current Module. For now I replaced it with a query to the map of Modules path to see if this module was declared in the Index and consider that if it is the case then it is probably exporting function. On the long term the Linker interface needs to evolve and this call should not be needed anymore. From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254581 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 4 years ago
7 changed file(s) with 16 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
7070 DiagnosticHandlerFunction DiagnosticHandler);
7171
7272 /// Parse the specified bitcode buffer, returning the function info index.
73 /// If ExportingModule is true, check for functions in the index from this
74 /// module when the combined index is built during parsing and set flag.
7573 /// If IsLazy is true, parse the entire function summary into
7674 /// the index. Otherwise skip the function summary section, and only create
7775 /// an index object with a map from function name to function summary offset.
7876 /// The index is used to perform lazy function summary reading later.
7977 ErrorOr> getFunctionInfoIndex(
8078 MemoryBufferRef Buffer, DiagnosticHandlerFunction DiagnosticHandler,
81 const Module *ExportingModule = nullptr, bool IsLazy = false);
79 bool IsLazy = false);
8280
8381 /// This method supports lazy reading of function summary data from the
8482 /// combined index during function importing. When reading the combined index
164164 /// Holds strings for combined index, mapping to the corresponding module ID.
165165 ModulePathStringTableTy ModulePathStringTable;
166166
167 /// The main module being compiled, that we are importing into, if applicable.
168 /// Used to check if any of its functions are in the index and therefore
169 /// potentially exported.
170 const Module *ExportingModule;
171
172 /// Flag indicating whether the exporting module has any functions in the
173 /// index and therefore potentially exported (imported into another module).
174 bool HasExportedFunctions;
175
176167 public:
177 FunctionInfoIndex(const Module *M = nullptr)
178 : ExportingModule(M), HasExportedFunctions(false){};
179 ~FunctionInfoIndex() = default;
168 FunctionInfoIndex() = default;
180169
181170 // Disable the copy constructor and assignment operators, so
182171 // no unexpected copying/moving occurs.
200189
201190 /// Add a function info for a function of the given name.
202191 void addFunctionInfo(StringRef FuncName, std::unique_ptr Info) {
203 // Update the HasExportedFunctions flag, but only if we had a function
204 // summary (i.e. we aren't parsing them lazily or have a bitcode file
205 // without a function summary section).
206 if (ExportingModule && Info->functionSummary()) {
207 if (ExportingModule->getModuleIdentifier() ==
208 Info->functionSummary()->modulePath())
209 HasExportedFunctions = true;
210 }
211192 FunctionMap[FuncName].push_back(std::move(Info));
212193 }
213194
247228 }
248229
249230 /// Check if the given Module has any functions available for exporting
250 /// in the index.
251 bool hasExportedFunctions(const Module *M) const {
252 assert(M == ExportingModule &&
253 "Checking for exported functions on unexpected module");
254 return HasExportedFunctions;
231 /// in the index. We consider any module present in the ModulePathStringTable
232 /// to have exported functions.
233 bool hasExportedFunctions(const Module &M) const {
234 return ModulePathStringTable.count(M.getModuleIdentifier());
255235 }
256236 };
257237
8787 /// summary/index.
8888 static ErrorOr>
8989 create(MemoryBufferRef Object, DiagnosticHandlerFunction DiagnosticHandler,
90 const Module *ExportingModule = nullptr, bool IsLazy = false);
90 bool IsLazy = false);
9191
9292 /// \brief Parse the function summary information for function with the
9393 /// given name out of the given buffer. Parsed information is
103103 /// index object if found, or nullptr if not.
104104 ErrorOr>
105105 getFunctionIndexForFile(StringRef Path,
106 DiagnosticHandlerFunction DiagnosticHandler,
107 const Module *ExportingModule = nullptr);
106 DiagnosticHandlerFunction DiagnosticHandler);
108107 }
109108
110109 #endif
59905990 ErrorOr>
59915991 llvm::getFunctionInfoIndex(MemoryBufferRef Buffer,
59925992 DiagnosticHandlerFunction DiagnosticHandler,
5993 const Module *ExportingModule, bool IsLazy) {
5993 bool IsLazy) {
59945994 std::unique_ptr Buf = MemoryBuffer::getMemBuffer(Buffer, false);
59955995 FunctionIndexBitcodeReader R(Buf.get(), DiagnosticHandler, IsLazy);
59965996
5997 std::unique_ptr Index =
5998 llvm::make_unique(ExportingModule);
5997 auto Index = llvm::make_unique();
59995998
60005999 auto cleanupOnError = [&](std::error_code EC) {
60016000 R.releaseBuffer(); // Never take ownership on error.
434434 // backend compilation, and we need to see if it has functions that
435435 // may be exported to another backend compilation.
436436 if (ImportIndex && !ImportFunction)
437 HasExportedFunctions = ImportIndex->hasExportedFunctions(&SrcM);
437 HasExportedFunctions = ImportIndex->hasExportedFunctions(SrcM);
438438 }
439439
440440 bool run();
8585 ErrorOr>
8686 FunctionIndexObjectFile::create(MemoryBufferRef Object,
8787 DiagnosticHandlerFunction DiagnosticHandler,
88 const Module *ExportingModule, bool IsLazy) {
88 bool IsLazy) {
8989 std::unique_ptr Index;
9090
9191 ErrorOr BCOrErr = findBitcodeInMemBuffer(Object);
9393 return BCOrErr.getError();
9494
9595 ErrorOr> IOrErr = getFunctionInfoIndex(
96 BCOrErr.get(), DiagnosticHandler, ExportingModule, IsLazy);
96 BCOrErr.get(), DiagnosticHandler, IsLazy);
9797
9898 if (std::error_code EC = IOrErr.getError())
9999 return EC;
124124 // index object if found, or nullptr if not.
125125 ErrorOr>
126126 llvm::getFunctionIndexForFile(StringRef Path,
127 DiagnosticHandlerFunction DiagnosticHandler,
128 const Module *ExportingModule) {
127 DiagnosticHandlerFunction DiagnosticHandler) {
129128 ErrorOr> FileOrErr =
130129 MemoryBuffer::getFileOrSTDIN(Path);
131130 std::error_code EC = FileOrErr.getError();
133132 return EC;
134133 MemoryBufferRef BufferRef = (FileOrErr.get())->getMemBufferRef();
135134 ErrorOr> ObjOrErr =
136 object::FunctionIndexObjectFile::create(BufferRef, DiagnosticHandler,
137 ExportingModule);
135 object::FunctionIndexObjectFile::create(BufferRef, DiagnosticHandler);
138136 EC = ObjOrErr.getError();
139137 if (EC)
140138 return EC;
228228 std::unique_ptr Index;
229229 if (!FunctionIndex.empty()) {
230230 ErrorOr> IndexOrErr =
231 llvm::getFunctionIndexForFile(FunctionIndex, diagnosticHandler, &*M);
231 llvm::getFunctionIndexForFile(FunctionIndex, diagnosticHandler);
232232 std::error_code EC = IndexOrErr.getError();
233233 if (EC) {
234234 errs() << EC.message() << '\n';