[lld] [llvm] DTLTO Cache optimization - rebased (PR #203971)

Katya Romanova via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 5 14:27:49 PDT 2026


https://github.com/romanova-ekaterina updated https://github.com/llvm/llvm-project/pull/203971

>From 476f86f3661b30a9b27062c3f3043aa8880c0a0e Mon Sep 17 00:00:00 2001
From: Romanova <katya.romanova at sony.com>
Date: Mon, 15 Jun 2026 11:45:15 -0700
Subject: [PATCH 1/8] DTLTO Cache optimization - rebased

---
 lld/COFF/LTO.cpp                              |  3 +-
 lld/ELF/LTO.cpp                               |  3 +-
 llvm/include/llvm/Support/Caching.h           | 15 ++--
 llvm/lib/DTLTO/DTLTO.cpp                      | 13 +++-
 llvm/lib/Support/Caching.cpp                  | 40 +++++++++-
 .../dtlto/dtlto-cache-rename-optimization.ll  | 73 +++++++++++++++++++
 llvm/tools/llvm-lto2/llvm-lto2.cpp            |  3 +-
 7 files changed, 137 insertions(+), 13 deletions(-)
 create mode 100644 llvm/test/ThinLTO/X86/dtlto/dtlto-cache-rename-optimization.ll

diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp
index 0329f6c2e9cea..4bfd62e7f7e2f 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -206,7 +206,8 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
   FileCache cache;
   if (!ctx.config.ltoCache.empty())
     cache = check(localCache("ThinLTO", "Thin", ctx.config.ltoCache,
-                             createAddBufferFn(files, file_names)));
+                             createAddBufferFn(files, file_names),
+                             !ctx.config.dtltoDistributor.empty()));
 
   checkError(ltoObj->run(
       [&](size_t task, const Twine &moduleName) {
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index e40575bffec62..4ec301890c7c8 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -336,7 +336,8 @@ SmallVector<std::unique_ptr<InputFile>, 0> BitcodeCompiler::compile() {
   FileCache cache;
   if (!ctx.arg.thinLTOCacheDir.empty())
     cache = check(localCache("ThinLTO", "Thin", ctx.arg.thinLTOCacheDir,
-                             createAddBufferFn(files, filenames)));
+                             createAddBufferFn(files, filenames),
+                             !ctx.arg.dtltoDistributor.empty()));
 
   if (!ctx.bitcodeFiles.empty())
     checkError(ctx.e, ltoObj->run(
diff --git a/llvm/include/llvm/Support/Caching.h b/llvm/include/llvm/Support/Caching.h
index cebf071b0188f..4f3852bd310f7 100644
--- a/llvm/include/llvm/Support/Caching.h
+++ b/llvm/include/llvm/Support/Caching.h
@@ -20,6 +20,11 @@
 #include "llvm/Support/MemoryBuffer.h"
 
 namespace llvm {
+/// This type defines the callback to add a pre-existing file (e.g. in a cache).
+///
+/// Buffer callbacks must be thread safe.
+using AddBufferFn = std::function<void(unsigned Task, const Twine &ModuleName,
+                                       std::unique_ptr<MemoryBuffer> MB)>;
 
 /// This class wraps an output stream for a file. Most clients should just be
 /// able to return an instance of this base class from the stream callback, but
@@ -50,6 +55,7 @@ class CachedFileStream {
     if (!Committed)
       report_fatal_error("CachedFileStream was not committed.\n");
   }
+  virtual AddBufferFn GetAddBuffer() { return AddBufferFn(); }
 };
 
 /// This type defines the callback to add a file that is generated on the fly.
@@ -101,12 +107,6 @@ struct FileCache {
   std::string CacheDirectoryPath;
 };
 
-/// This type defines the callback to add a pre-existing file (e.g. in a cache).
-///
-/// Buffer callbacks must be thread safe.
-using AddBufferFn = std::function<void(unsigned Task, const Twine &ModuleName,
-                                       std::unique_ptr<MemoryBuffer> MB)>;
-
 /// Create a local file system cache which uses the given cache name, temporary
 /// file prefix, cache directory and file callback.  This function does not
 /// immediately create the cache directory if it does not yet exist; this is
@@ -117,7 +117,8 @@ LLVM_ABI Expected<FileCache> localCache(
     const Twine &CacheNameRef, const Twine &TempFilePrefixRef,
     const Twine &CacheDirectoryPathRef,
     AddBufferFn AddBuffer = [](size_t Task, const Twine &ModuleName,
-                               std::unique_ptr<MemoryBuffer> MB) {});
+                               std::unique_ptr<MemoryBuffer> MB) {},
+    bool CacheFileRename = false);
 } // namespace llvm
 
 #endif
diff --git a/llvm/lib/DTLTO/DTLTO.cpp b/llvm/lib/DTLTO/DTLTO.cpp
index 6805746f64978..2c7ddc4449942 100644
--- a/llvm/lib/DTLTO/DTLTO.cpp
+++ b/llvm/lib/DTLTO/DTLTO.cpp
@@ -292,9 +292,18 @@ Error lto::DTLTO::addObjectFilesToLink() {
             createStringError(inconvertibleErrorCode(),
                               "Cannot get a cache file stream: %s",
                               Job.NativeObjectPath.data()));
-      // Store a file buffer into the cache stream.
+
       auto &CacheStream = *(CachedFileStreamOrErr->get());
-      *(CacheStream.OS) << ObjFileMbRef.getBuffer();
+
+      // Store a file path into the cache stream. This file later will be
+      // renamed into cache file.
+      *(CacheStream.OS) << Job.NativeObjectPath;
+      if (Error Err = CacheStream.commit())
+        return Err;
+
+      AddBufferFn AddBuffer = CacheStream.GetAddBuffer();
+      AddBuffer(Job.Task, Job.ModuleID, std::move(ObjFileMbOrErr.get()));
+
       if (Error Err = CacheStream.commit())
         return Err;
     } else {
diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index 40a5c44771b65..a3eb6ecc0077c 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -21,6 +21,7 @@
 #if !defined(_MSC_VER) && !defined(__MINGW32__)
 #include <unistd.h>
 #else
+#include "llvm/Support/Windows/WindowsSupport.h"
 #include <io.h>
 #endif
 
@@ -29,7 +30,7 @@ using namespace llvm;
 Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
                                      const Twine &TempFilePrefixRef,
                                      const Twine &CacheDirectoryPathRef,
-                                     AddBufferFn AddBuffer) {
+                                     AddBufferFn AddBuffer, bool CacheRename) {
 
   // Create local copies which are safely captured-by-copy in lambdas
   SmallString<64> CacheName, TempFilePrefix, CacheDirectoryPath;
@@ -142,6 +143,37 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
         AddBuffer(Task, ModuleName, std::move(*MBOrErr));
         return Error::success();
       }
+      virtual AddBufferFn GetAddBuffer() override { return AddBuffer; }
+    };
+
+    // This class is responsible for renaming/moving existing file into a
+    // cache directory. The path for an input file is passed through a string
+    // stream.
+    struct MoveFileToCache : CachedFileStream {
+      AddBufferFn AddBuffer;
+      size_t Task;
+      SmallString<0> FilePath;
+      MoveFileToCache(AddBufferFn AddBuffer, std::string EntryPath, size_t Task)
+          : CachedFileStream(std::make_unique<raw_svector_ostream>(FilePath),
+                             std::move(EntryPath)),
+            AddBuffer(std::move(AddBuffer)), Task(Task) {}
+      ~MoveFileToCache() {
+        // Rename/move native object file into cache directory, if they are
+        // located the same device/logical drive, otherwise we use a copy.
+        std::error_code EC = sys::fs::rename(FilePath, ObjectPathName);
+#ifdef _WIN32
+        if (EC ==
+            std::error_code(ERROR_NOT_SAME_DEVICE, std::system_category()))
+#else
+        if (EC == std::make_error_code(std::errc::cross_device_link))
+#endif
+          EC = sys::fs::copy_file(FilePath, ObjectPathName);
+        if (EC)
+          report_fatal_error(Twine("Failed to rename or copy file ") +
+                             FilePath + " to " + ObjectPathName + ": " +
+                             EC.message() + "\n");
+      }
+      virtual AddBufferFn GetAddBuffer() override { return AddBuffer; }
     };
 
     return [=](size_t Task, const Twine &ModuleName)
@@ -153,6 +185,12 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
         return createStringError(EC, Twine("can't create cache directory ") +
                                          CacheDirectoryPath + ": " +
                                          EC.message());
+      // MoveFileToChache class will rename/move the file into the cache on
+      // destruction.
+      if (CacheRename) {
+        return std::make_unique<MoveFileToCache>(
+            AddBuffer, std::string(EntryPath.str()), Task);
+      }
 
       // Write to a temporary to avoid race condition
       SmallString<64> TempFilenameModel;
diff --git a/llvm/test/ThinLTO/X86/dtlto/dtlto-cache-rename-optimization.ll b/llvm/test/ThinLTO/X86/dtlto/dtlto-cache-rename-optimization.ll
new file mode 100644
index 0000000000000..932770a5a0909
--- /dev/null
+++ b/llvm/test/ThinLTO/X86/dtlto/dtlto-cache-rename-optimization.ll
@@ -0,0 +1,73 @@
+; DTLTO with llvm-lto2 and -cache-dir, using --save-temps
+; to leave distributor artifacts saved on the disk (except native object files).
+; native object files shouldn't be saved, because they are renamed into
+; cache entries. 
+; The test also checks that the cache is populated
+RUN: rm -rf %t && split-file %s %t && cd %t
+
+; Generate bitcode files with summary.
+RUN: opt -thinlto-bc t1.ll -o t1.bc
+RUN: opt -thinlto-bc t2.ll -o t2.bc
+
+; Generate fake object files for mock.py to return.
+RUN: touch t1.o t2.o
+
+; Create an empty subdirectory to avoid having to account for the input files.
+RUN: mkdir %t/out && cd %t/out
+
+DEFINE: %{command} = llvm-lto2 run ../t1.bc ../t2.bc -o t.o -cache-dir cache-dir \
+DEFINE:   --save-temps \
+DEFINE:   -dtlto-distributor=%python \
+DEFINE:   -dtlto-distributor-arg=%llvm_src_root/utils/dtlto/mock.py,../t1.o,../t2.o \
+DEFINE:   -r=../t1.bc,t1,px \
+DEFINE:   -r=../t2.bc,t2,px
+
+RUN: %{command}
+
+; 12 save-temps outputs plus the cache directory.
+RUN: ls | count 11
+RUN: ls | FileCheck %s --check-prefixes=THINLTO,SAVETEMPS,NOT-NATIVE
+RUN: ls cache-dir/* | count 2
+RUN: ls cache-dir/llvmcache-* | count 2
+
+; llvm-lto2 ThinLTO output files.
+THINLTO-DAG: {{^}}t.o.1{{$}}
+THINLTO-DAG: {{^}}t.o.2{{$}}
+
+; Common -save-temps files from llvm-lto2.
+SAVETEMPS-DAG: {{^}}t.o.resolution.txt{{$}}
+SAVETEMPS-DAG: {{^}}t.o.index.bc{{$}}
+SAVETEMPS-DAG: {{^}}t.o.index.dot{{$}}
+
+; -save-temps incremental files.
+SAVETEMPS-DAG: {{^}}t.o.0.0.preopt.bc{{$}}
+SAVETEMPS-DAG: {{^}}t.o.0.2.internalize.bc{{$}}
+
+; A jobs description JSON.
+SAVETEMPS-DAG: {{^}}t.[[#]].dist-file.json{{$}}
+
+; Summary shards emitted for DTLTO.
+SAVETEMPS-DAG: {{^}}t1.1.[[#]].native.o.thinlto.bc{{$}}
+SAVETEMPS-DAG: {{^}}t2.2.[[#]].native.o.thinlto.bc{{$}}
+
+; DTLTO native output files (the results of the external backend compilations)
+; should not be saved, because these files are renamed into cache entries
+NOT-NATIVE-NOT: native.o{{$}}
+
+;--- t1.ll
+
+target triple = "x86_64-unknown-linux-gnu"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @t1() {
+  ret void
+}
+
+;--- t2.ll
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @t2() {
+  ret void
+}
\ No newline at end of file
diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp
index 4bcf04df89ac9..848ba0a5c3289 100644
--- a/llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -537,7 +537,8 @@ static int run(int argc, char **argv) {
 
   FileCache Cache;
   if (!CacheDir.empty())
-    Cache = check(localCache("ThinLTO", "Thin", CacheDir, AddBuffer),
+    Cache = check(localCache("ThinLTO", "Thin", CacheDir, AddBuffer,
+                             !DTLTODistributor.empty()),
                   "failed to create cache");
 
   check(Lto->run(AddStream, Cache), "LTO::run failed");

>From 072e83aec103b8dae4f2755979e74fba60c402c2 Mon Sep 17 00:00:00 2001
From: Romanova <katya.romanova at sony.com>
Date: Wed, 17 Jun 2026 03:43:08 -0700
Subject: [PATCH 2/8] added virtual commit() function for MoveFileToCache class

---
 llvm/lib/Support/Caching.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index a3eb6ecc0077c..92720dc23a598 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -173,6 +173,7 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
                              FilePath + " to " + ObjectPathName + ": " +
                              EC.message() + "\n");
       }
+      virtual Error commit() override { return Error::success(); }
       virtual AddBufferFn GetAddBuffer() override { return AddBuffer; }
     };
 

>From 8e2c4b1e0eec5221a51e93b6c83d824f756efd1d Mon Sep 17 00:00:00 2001
From: Romanova <katya.romanova at sony.com>
Date: Tue, 23 Jun 2026 05:08:39 -0700
Subject: [PATCH 3/8] DTLTO Cache optimization -resolved test failures

---
 llvm/lib/DTLTO/DTLTO.cpp     |  2 --
 llvm/lib/Support/Caching.cpp | 18 +++++++++++++-----
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/DTLTO/DTLTO.cpp b/llvm/lib/DTLTO/DTLTO.cpp
index 2c7ddc4449942..43a6fd1726b50 100644
--- a/llvm/lib/DTLTO/DTLTO.cpp
+++ b/llvm/lib/DTLTO/DTLTO.cpp
@@ -304,8 +304,6 @@ Error lto::DTLTO::addObjectFilesToLink() {
       AddBufferFn AddBuffer = CacheStream.GetAddBuffer();
       AddBuffer(Job.Task, Job.ModuleID, std::move(ObjFileMbOrErr.get()));
 
-      if (Error Err = CacheStream.commit())
-        return Err;
     } else {
       if (AddBuffer) {
         AddBuffer(Job.Task, Job.ModuleID, std::move(ObjFileMbOrErr.get()));
diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index 92720dc23a598..9576ac2c2ffa9 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -157,7 +157,13 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
           : CachedFileStream(std::make_unique<raw_svector_ostream>(FilePath),
                              std::move(EntryPath)),
             AddBuffer(std::move(AddBuffer)), Task(Task) {}
-      ~MoveFileToCache() {
+      virtual ~MoveFileToCache() = default;
+
+      virtual Error commit() override {
+        if (Committed)
+          return createStringError(make_error_code(std::errc::invalid_argument),
+                                   Twine("MoveFileToCache already committed."));
+
         // Rename/move native object file into cache directory, if they are
         // located the same device/logical drive, otherwise we use a copy.
         std::error_code EC = sys::fs::rename(FilePath, ObjectPathName);
@@ -169,11 +175,13 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
 #endif
           EC = sys::fs::copy_file(FilePath, ObjectPathName);
         if (EC)
-          report_fatal_error(Twine("Failed to rename or copy file ") +
-                             FilePath + " to " + ObjectPathName + ": " +
-                             EC.message() + "\n");
+          return createStringError(EC, Twine("Failed to rename or copy file ") +
+                                           FilePath + " to " + ObjectPathName +
+                                           ": " + EC.message() + "\n");
+
+        Committed = true;
+        return Error::success();
       }
-      virtual Error commit() override { return Error::success(); }
       virtual AddBufferFn GetAddBuffer() override { return AddBuffer; }
     };
 

>From cdd9b4c8f8da12bf76ff47fb1b0af853edd0b624 Mon Sep 17 00:00:00 2001
From: Romanova <katya.romanova at sony.com>
Date: Mon, 29 Jun 2026 12:35:35 -0700
Subject: [PATCH 4/8] DTLTO Cache optimization - addressed code review comments

---
 llvm/include/llvm/Support/Caching.h |  6 ++++++
 llvm/lib/DTLTO/DTLTO.cpp            | 11 +++--------
 llvm/lib/Support/Caching.cpp        | 21 ++++++++++++++-------
 3 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/llvm/include/llvm/Support/Caching.h b/llvm/include/llvm/Support/Caching.h
index 4f3852bd310f7..ae6a541bdac7b 100644
--- a/llvm/include/llvm/Support/Caching.h
+++ b/llvm/include/llvm/Support/Caching.h
@@ -48,6 +48,10 @@ class CachedFileStream {
     return Error::success();
   }
 
+  virtual Error commit(std::unique_ptr<MemoryBuffer> MemBuf) {
+      return Error::success();
+  }
+
   bool Committed = false;
   std::unique_ptr<raw_pwrite_stream> OS;
   std::string ObjectPathName;
@@ -113,6 +117,8 @@ struct FileCache {
 /// done lazily the first time a file is added.  The cache name appears in error
 /// messages for errors during caching. The temporary file prefix is used in the
 /// temporary file naming scheme used when writing files atomically.
+/// If \p CacheFileRename is true, move or rename an existing file into the
+/// cache instead of writing via a temporary stream.
 LLVM_ABI Expected<FileCache> localCache(
     const Twine &CacheNameRef, const Twine &TempFilePrefixRef,
     const Twine &CacheDirectoryPathRef,
diff --git a/llvm/lib/DTLTO/DTLTO.cpp b/llvm/lib/DTLTO/DTLTO.cpp
index 43a6fd1726b50..7455ebee775f4 100644
--- a/llvm/lib/DTLTO/DTLTO.cpp
+++ b/llvm/lib/DTLTO/DTLTO.cpp
@@ -295,15 +295,10 @@ Error lto::DTLTO::addObjectFilesToLink() {
 
       auto &CacheStream = *(CachedFileStreamOrErr->get());
 
-      // Store a file path into the cache stream. This file later will be
-      // renamed into cache file.
-      *(CacheStream.OS) << Job.NativeObjectPath;
-      if (Error Err = CacheStream.commit())
+      // This object file will be renamed into cache entry file. The file
+      // memory buffer will be added to lld list of object files.
+      if (Error Err = CacheStream.commit(std::move(ObjFileMbOrErr.get())))
         return Err;
-
-      AddBufferFn AddBuffer = CacheStream.GetAddBuffer();
-      AddBuffer(Job.Task, Job.ModuleID, std::move(ObjFileMbOrErr.get()));
-
     } else {
       if (AddBuffer) {
         AddBuffer(Job.Task, Job.ModuleID, std::move(ObjFileMbOrErr.get()));
diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index 9576ac2c2ffa9..7f97b14801e2f 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -151,19 +151,24 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
     // stream.
     struct MoveFileToCache : CachedFileStream {
       AddBufferFn AddBuffer;
+      std::string ModuleName;
       size_t Task;
-      SmallString<0> FilePath;
-      MoveFileToCache(AddBufferFn AddBuffer, std::string EntryPath, size_t Task)
-          : CachedFileStream(std::make_unique<raw_svector_ostream>(FilePath),
-                             std::move(EntryPath)),
-            AddBuffer(std::move(AddBuffer)), Task(Task) {}
+      StringRef FilePath;
+
+      MoveFileToCache(AddBufferFn AddBuffer, std::string EntryPath,
+                      std::string ModuleID, size_t Task)
+          : CachedFileStream({}, std::move(EntryPath)),
+            AddBuffer(std::move(AddBuffer)), ModuleName(ModuleID), Task(Task) {}
       virtual ~MoveFileToCache() = default;
 
-      virtual Error commit() override {
+      virtual Error commit(std::unique_ptr<MemoryBuffer> MemBuf) override {
         if (Committed)
           return createStringError(make_error_code(std::errc::invalid_argument),
                                    Twine("MoveFileToCache already committed."));
 
+        FilePath = MemBuf->getBufferIdentifier();
+        assert(!FilePath.empty() && "File path is empty.");
+
         // Rename/move native object file into cache directory, if they are
         // located the same device/logical drive, otherwise we use a copy.
         std::error_code EC = sys::fs::rename(FilePath, ObjectPathName);
@@ -179,6 +184,8 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
                                            FilePath + " to " + ObjectPathName +
                                            ": " + EC.message() + "\n");
 
+        AddBuffer(Task, ModuleName, std::move(MemBuf));
+
         Committed = true;
         return Error::success();
       }
@@ -198,7 +205,7 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
       // destruction.
       if (CacheRename) {
         return std::make_unique<MoveFileToCache>(
-            AddBuffer, std::string(EntryPath.str()), Task);
+            AddBuffer, std::string(EntryPath.str()), ModuleName.str(), Task);
       }
 
       // Write to a temporary to avoid race condition

>From c1fe789d714511fb9f23d7e16aee14f8739bb924 Mon Sep 17 00:00:00 2001
From: Romanova <katya.romanova at sony.com>
Date: Mon, 29 Jun 2026 12:42:55 -0700
Subject: [PATCH 5/8] DTLTO Cache optimization - addressed formatting issues

---
 llvm/include/llvm/Support/Caching.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/Support/Caching.h b/llvm/include/llvm/Support/Caching.h
index ae6a541bdac7b..4f49ad941e9fa 100644
--- a/llvm/include/llvm/Support/Caching.h
+++ b/llvm/include/llvm/Support/Caching.h
@@ -49,7 +49,7 @@ class CachedFileStream {
   }
 
   virtual Error commit(std::unique_ptr<MemoryBuffer> MemBuf) {
-      return Error::success();
+    return Error::success();
   }
 
   bool Committed = false;

>From 5509cd402d122ce339b475097922517849268a03 Mon Sep 17 00:00:00 2001
From: Katya Romanova <Katya.Romanova at sony.com>
Date: Sun, 5 Jul 2026 13:16:37 -0700
Subject: [PATCH 6/8] DTLTO Cache optimization - modified newly added test that
 started to fail after my commit

---
 cross-project-tests/dtlto/cache-serialization.test | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/cross-project-tests/dtlto/cache-serialization.test b/cross-project-tests/dtlto/cache-serialization.test
index 9be19a4b9495c..fbc50577503e5 100644
--- a/cross-project-tests/dtlto/cache-serialization.test
+++ b/cross-project-tests/dtlto/cache-serialization.test
@@ -35,18 +35,17 @@ DEFINE:     -Wl,--save-temps
 #
 # Both f1.o and f2.o require backend compilation, so both should be serialized.
 # Each backend compilation should produce:
-#   * a native object
 #   * a thinlto.bc file
 #   * a serialized temporary bitcode file (an extracted archive member)
+# Native objects are moved into the ThinLTO cache and should not remain here.
 RUN: mkdir none
 RUN: %{link} -Wl,--whole-archive f1.a f2.a -o none/out.elf
 RUN: ls none | sort | FileCheck %s --check-prefix=NONE
 NONE-NOT:  {{^f[1-3]}}
-NONE:      {{^}}f1.a(f1.o at [[#F1_OFFSET:]]).1.[[#%X,HEXPID:]].1.[[#PID:]].native.o{{$}}
-NONE-NEXT: {{^}}f1.a(f1.o at [[#F1_OFFSET]]).1.[[#%X,HEXPID]].1.[[#PID]].native.o.thinlto.bc{{$}}
+NONE-NOT:  {{^}}.*\.native\.o{{$}}
+NONE:      {{^}}f1.a(f1.o at [[#F1_OFFSET:]]).1.[[#%X,HEXPID:]].1.[[#PID:]].native.o.thinlto.bc{{$}}
 NONE-NEXT: {{^}}f1.a(f1.o at [[#F1_OFFSET]]).1.[[#%X,HEXPID]].o{{$}}
-NONE-NEXT: {{^}}f2.a(f2.o at [[#F2_OFFSET:]]).2.[[#%X,HEXPID]].2.[[#PID]].native.o{{$}}
-NONE-NEXT: {{^}}f2.a(f2.o at [[#F2_OFFSET]]).2.[[#%X,HEXPID]].2.[[#PID]].native.o.thinlto.bc{{$}}
+NONE-NEXT: {{^}}f2.a(f2.o at [[#F2_OFFSET:]]).2.[[#%X,HEXPID]].2.[[#PID]].native.o.thinlto.bc{{$}}
 NONE-NEXT: {{^}}f2.a(f2.o at [[#F2_OFFSET]]).2.[[#%X,HEXPID]].o{{$}}
 NONE-NOT:  {{^f[1-3]}}
 
@@ -59,6 +58,7 @@ RUN: mkdir all
 RUN: %{link} -Wl,--whole-archive f1.a f2.a -o all/out.elf
 RUN: ls all | sort | FileCheck %s --check-prefix=ALL
 ALL-NOT: {{^f[1-3]}}
+ALL-NOT: {{^}}.*\.native\.o{{$}}
 
 # 3. Some backend compilations hit in the ThinLTO cache and some miss.
 #
@@ -73,9 +73,9 @@ RUN: mkdir some
 RUN: %{link} -Wl,--whole-archive f1.a f2.a f3.a -o some/out.elf
 RUN: ls some | sort | FileCheck %s --check-prefix=SOME
 SOME-NOT:  {{^f[1-3]}}
+SOME-NOT:  {{^}}.*\.native\.o{{$}}
 SOME:      {{^}}f1.a(f1.o at [[#F1_OFFSET:]]).1.[[#%X,HEXPID:]].o{{$}}
-SOME-NEXT: {{^}}f3.a(f3.o at [[#F3_OFFSET:]]).3.[[#%X,HEXPID]].3.[[#PID:]].native.o{{$}}
-SOME-NEXT: {{^}}f3.a(f3.o at [[#F3_OFFSET]]).3.[[#%X,HEXPID]].3.[[#PID]].native.o.thinlto.bc{{$}}
+SOME-NEXT: {{^}}f3.a(f3.o at [[#F3_OFFSET:]]).3.[[#%X,HEXPID]].3.[[#PID:]].native.o.thinlto.bc{{$}}
 SOME-NEXT: {{^}}f3.a(f3.o at [[#F3_OFFSET]]).3.[[#%X,HEXPID]].o{{$}}
 SOME-NOT:  {{^f[1-3]}}
 

>From eb2378c7034a28fec8c5070800e4c942a045815e Mon Sep 17 00:00:00 2001
From: Romanova <katya.romanova at sony.com>
Date: Wed, 17 Jun 2026 03:43:08 -0700
Subject: [PATCH 7/8] added virtual commit() function for MoveFileToCache class

---
 llvm/lib/Support/Caching.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index 7f97b14801e2f..4da56b1776ce7 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -189,6 +189,7 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
         Committed = true;
         return Error::success();
       }
+      virtual Error commit() override { return Error::success(); }
       virtual AddBufferFn GetAddBuffer() override { return AddBuffer; }
     };
 

>From 470c1f71ceca94b202a677194944137e177f0c70 Mon Sep 17 00:00:00 2001
From: Romanova <katya.romanova at sony.com>
Date: Tue, 23 Jun 2026 05:08:39 -0700
Subject: [PATCH 8/8] DTLTO Cache optimization -resolved merge conflicts

---
 llvm/lib/Support/Caching.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index 4da56b1776ce7..7f97b14801e2f 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -189,7 +189,6 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
         Committed = true;
         return Error::success();
       }
-      virtual Error commit() override { return Error::success(); }
       virtual AddBufferFn GetAddBuffer() override { return AddBuffer; }
     };
 



More information about the llvm-commits mailing list