[lld] [llvm] [DTLTO] Overlap temporary file removal (PR #209423)

Ben Dunbobbin via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 17 02:53:02 PDT 2026


================
@@ -27,27 +27,59 @@
 #include "llvm/Support/raw_ostream.h"
 
 #include <string>
+#include <system_error>
+#include <utility>
+#include <vector>
 
 using namespace llvm;
 
+// Experimentation showed that serial deletion is most efficient, hence
+// a single thread.
+lto::DTLTO::BackgroundDeletion::BackgroundDeletion()
+    : DefaultThreadPool(hardware_concurrency(1)) {}
+
+lto::DTLTO::BackgroundDeletion::~BackgroundDeletion() {
+  wait();
+  for (const std::string &Warning : Warnings)
+    errs() << "warning: could not remove the file " << Warning << "\n";
+}
+
+void lto::DTLTO::BackgroundDeletion::remove(std::vector<std::string> &&Files,
+                                            const Config &Conf) {
+  if (Files.empty())
+    return;
+
+  async([this, Files = std::move(Files), TTE = Conf.TimeTraceEnabled,
+         TTG = Conf.TimeTraceGranularity] {
+    if (LLVM_ENABLE_THREADS && TTE)
+      timeTraceProfilerInitialize(TTG, "Remove DTLTO temporary files");
+    {
+      TimeTraceScope TimeScope("Remove DTLTO temporary files");
+      for (const std::string &Path : Files) {
+        if (Path.empty())
----------------
bd1976bris wrote:

Good point, this is needlessly defensive. It should not be empty: every entry in CleanupList comes through addToCleanup(), and those call sites all pass concrete temp paths. Removed now, thanks.

https://github.com/llvm/llvm-project/pull/209423


More information about the llvm-commits mailing list