Auto merge of #53673 - michaelwoerister:incr-thinlto-2000, r=alexcrichton
Enable ThinLTO with incremental compilation. This is an updated version of #52309. This PR allows `rustc` to use (local) ThinLTO and incremental compilation at the same time. In theory this should allow for getting compile-time improvements for small changes while keeping the runtime performance of the generated code roughly the same as when compiling non-incrementally. The difference to #52309 is that this version also caches the pre-LTO version of LLVM bitcode. This allows for another layer of caching: 1. if the module itself has changed, we have to re-codegen and re-optimize. 2. if the module itself has not changed, but a module it imported from during ThinLTO has, we don't need to re-codegen and don't need to re-run the first optimization phase. Only the second (i.e. ThinLTO-) optimization phase is re-run. 3. if neither the module itself nor any of its imports have changed then we can re-use the final, post-ThinLTO version of the module. (We might have to load its pre-ThinLTO version though so it's available for other modules to import from)
This commit is contained in:
commit
ee73f80dc9
17 changed files with 648 additions and 298 deletions
|
@ -1123,6 +1123,28 @@ LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
|
|||
return true;
|
||||
}
|
||||
|
||||
extern "C" typedef void (*LLVMRustModuleNameCallback)(void*, // payload
|
||||
const char*, // importing module name
|
||||
const char*); // imported module name
|
||||
|
||||
// Calls `module_name_callback` for each module import done by ThinLTO.
|
||||
// The callback is provided with regular null-terminated C strings.
|
||||
extern "C" void
|
||||
LLVMRustGetThinLTOModuleImports(const LLVMRustThinLTOData *data,
|
||||
LLVMRustModuleNameCallback module_name_callback,
|
||||
void* callback_payload) {
|
||||
for (const auto& importing_module : data->ImportLists) {
|
||||
const std::string importing_module_id = importing_module.getKey().str();
|
||||
const auto& imports = importing_module.getValue();
|
||||
for (const auto& imported_module : imports) {
|
||||
const std::string imported_module_id = imported_module.getKey().str();
|
||||
module_name_callback(callback_payload,
|
||||
importing_module_id.c_str(),
|
||||
imported_module_id.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This struct and various functions are sort of a hack right now, but the
|
||||
// problem is that we've got in-memory LLVM modules after we generate and
|
||||
// optimize all codegen-units for one compilation in rustc. To be compatible
|
||||
|
@ -1288,6 +1310,11 @@ LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
|
|||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" LLVMRustThinLTOModuleImports
|
||||
LLVMRustGetLLVMRustThinLTOModuleImports(const LLVMRustThinLTOData *Data) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustFreeThinLTOData(LLVMRustThinLTOData *Data) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue