[lld] [llvm] [DTLTO] Refactor the DTLTO code. (PR #192629)
Konstantin Belochapka via llvm-commits
llvm-commits at lists.llvm.org
Fri May 1 02:03:43 PDT 2026
================
@@ -223,43 +206,416 @@ lto::DTLTO::addInput(std::unique_ptr<InputFile> InputPtr) {
}
// Save the contents of ThinLTO-enabled input files that must be serialized for
-// distribution, such as archive members and FatLTO objects, to individual
-// bitcode files named after the module ID.
-//
-// Must be called after all input files are added but before optimization
-// begins. If a file with that name already exists, it is likely a leftover from
-// a previously terminated linker process and can be safely overwritten.
-llvm::Error lto::DTLTO::serializeInputsForDistribution() {
+// distribution.
+Error lto::DTLTO::handleArchiveInputs() {
for (auto &Input : InputFiles) {
if (!Input->isThinLTO() || !Input->getSerializeForDistribution())
continue;
// Save the content of the input file to a file named after the module ID.
StringRef ModuleId = Input->getName();
TimeTraceScope TimeScope("Serialize bitcode input for DTLTO", ModuleId);
+ MemoryBufferRef Buf = Input->getFileBuffer();
+ if (Error Err = save(Buf.getBuffer(), ModuleId))
+ return Err;
// Cleanup this file on abnormal process exit.
if (!SaveTemps)
- llvm::sys::RemoveFileOnSignal(ModuleId);
- if (Error EC = save(Input.get(), ModuleId))
- return EC;
+ addToCleanup(ModuleId);
}
-
return Error::success();
}
-// Remove serialized inputs created to enable distribution.
+// Remove temporary files created to enable distribution.
void lto::DTLTO::cleanup() {
if (!SaveTemps) {
- TimeTraceScope TimeScope("Remove temporary inputs for DTLTO");
- for (auto &Input : InputFiles) {
- if (!Input->getSerializeForDistribution())
- continue;
- std::error_code EC =
- sys::fs::remove(Input->getName(), /*IgnoreNonExisting=*/true);
+ // Remove one file, report error if any.
+ auto removeFile = [](StringRef FileName) -> void {
+ std::error_code EC = sys::fs::remove(FileName, true);
if (EC &&
EC != std::make_error_code(std::errc::no_such_file_or_directory))
- errs() << "warning: could not remove temporary DTLTO input file '"
- << Input->getName() << "': " << EC.message() << "\n";
+ errs() << "warning: could not remove the file '" << FileName
+ << "': " << EC.message() << "\n";
+ };
+
+ TimeTraceScope JobScope("Remove DTLTO temporary files");
+ for (const auto &Name : CleanupList) {
----------------
kbelochapka wrote:
Removes unnecessary braces.
https://github.com/llvm/llvm-project/pull/192629
More information about the llvm-commits
mailing list