[llvm] [libLTO] add thinlto caching flags to libLTO (PR #168567)
Wael Yehia via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 19 03:32:54 PST 2025
https://github.com/w2yehia updated https://github.com/llvm/llvm-project/pull/168567
>From 0eafb2b3aedda9a5ea7c54e036e6b85aa8027454 Mon Sep 17 00:00:00 2001
From: Wael Yehia <wyehia at ca.ibm.com>
Date: Tue, 7 Oct 2025 09:07:30 -0400
Subject: [PATCH 1/2] [libLTO] add thinlto caching flags to libLTO
---
llvm/tools/lto/lto.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index 467a4da27dcd8..6efefc7977e4a 100644
--- a/llvm/tools/lto/lto.cpp
+++ b/llvm/tools/lto/lto.cpp
@@ -24,6 +24,7 @@
#include "llvm/LTO/legacy/LTOCodeGenerator.h"
#include "llvm/LTO/legacy/LTOModule.h"
#include "llvm/LTO/legacy/ThinLTOCodeGenerator.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
@@ -44,6 +45,29 @@ static cl::opt<bool> EnableFreestanding(
"lto-freestanding", cl::init(false),
cl::desc("Enable Freestanding (disable builtins / TLI) during LTO"));
+static cl::opt<std::string> ThinLTOCacheDir(
+ "thinlto-cache-dir",
+ cl::desc("Experimental option, enable ThinLTO caching. Note: the cache "
+ "currently does not take the mcmodel setting into account, so you "
+ "might get false hits if different mcmodels are used in different "
+ "builds using the same cache directory."));
+
+static cl::opt<int> ThinLTOCachePruningInterval(
+ "thinlto-cache-pruning-interval", cl::init(1200),
+ cl::desc("Set ThinLTO cache pruning interval (seconds)."));
+
+static cl::opt<uint64_t> ThinLTOCacheMaxSizeBytes(
+ "thinlto-cache-max-size-bytes",
+ cl::desc("Set ThinLTO cache pruning directory maximum size in bytes."));
+
+static cl::opt<int> ThinLTOCacheMaxSizeFiles(
+ "thinlto-cache-max-size-files", cl::init(1000000),
+ cl::desc("Set ThinLTO cache pruning directory maximum number of files."));
+
+static cl::opt<unsigned> ThinLTOCacheEntryExpiration(
+ "thinlto-cache-entry-expiration", cl::init(604800) /* 1w */,
+ cl::desc("Set ThinLTO cache entry expiration time (seconds)."));
+
#ifdef NDEBUG
static bool VerifyByDefault = false;
#else
@@ -543,6 +567,24 @@ thinlto_code_gen_t thinlto_create_codegen(void) {
assert(CGOptLevelOrNone);
CodeGen->setCodeGenOptLevel(*CGOptLevelOrNone);
}
+ if (!ThinLTOCacheDir.empty()) {
+ auto Err = llvm::sys::fs::create_directories(ThinLTOCacheDir.getValue());
+ if (Err)
+ report_fatal_error(Twine("Unable to create thinLTO cache directory: ") +
+ Err.message());
+ bool result;
+ Err = llvm::sys::fs::is_directory(ThinLTOCacheDir.getValue(), result);
+ if (Err || !result)
+ report_fatal_error(Twine("Unable to get status of thinLTO cache path or "
+ "path is not a directory: ") +
+ Err.message());
+ CodeGen->setCacheDir(ThinLTOCacheDir);
+ }
+ CodeGen->setCachePruningInterval(ThinLTOCachePruningInterval);
+ CodeGen->setCacheEntryExpiration(ThinLTOCacheEntryExpiration);
+ CodeGen->setCacheMaxSizeFiles(ThinLTOCacheMaxSizeFiles);
+ CodeGen->setCacheMaxSizeBytes(ThinLTOCacheMaxSizeBytes);
+
return wrap(CodeGen);
}
>From c3b7a83efd522400e60dd93cc46302bb3d149c24 Mon Sep 17 00:00:00 2001
From: Wael Yehia <wyehia at ca.ibm.com>
Date: Wed, 19 Nov 2025 11:40:17 +0000
Subject: [PATCH 2/2] address review comments
---
llvm/tools/lto/lto.cpp | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index 6efefc7977e4a..513d0578af24a 100644
--- a/llvm/tools/lto/lto.cpp
+++ b/llvm/tools/lto/lto.cpp
@@ -46,26 +46,26 @@ static cl::opt<bool> EnableFreestanding(
cl::desc("Enable Freestanding (disable builtins / TLI) during LTO"));
static cl::opt<std::string> ThinLTOCacheDir(
- "thinlto-cache-dir",
+ "legacy-thinlto-cache-dir",
cl::desc("Experimental option, enable ThinLTO caching. Note: the cache "
"currently does not take the mcmodel setting into account, so you "
"might get false hits if different mcmodels are used in different "
"builds using the same cache directory."));
static cl::opt<int> ThinLTOCachePruningInterval(
- "thinlto-cache-pruning-interval", cl::init(1200),
+ "legacy-thinlto-cache-pruning-interval", cl::init(1200),
cl::desc("Set ThinLTO cache pruning interval (seconds)."));
static cl::opt<uint64_t> ThinLTOCacheMaxSizeBytes(
- "thinlto-cache-max-size-bytes",
+ "legacy-thinlto-cache-max-size-bytes",
cl::desc("Set ThinLTO cache pruning directory maximum size in bytes."));
static cl::opt<int> ThinLTOCacheMaxSizeFiles(
- "thinlto-cache-max-size-files", cl::init(1000000),
+ "legacy-thinlto-cache-max-size-files", cl::init(1000000),
cl::desc("Set ThinLTO cache pruning directory maximum number of files."));
static cl::opt<unsigned> ThinLTOCacheEntryExpiration(
- "thinlto-cache-entry-expiration", cl::init(604800) /* 1w */,
+ "legacy-thinlto-cache-entry-expiration", cl::init(604800) /* 1w */,
cl::desc("Set ThinLTO cache entry expiration time (seconds)."));
#ifdef NDEBUG
@@ -568,22 +568,23 @@ thinlto_code_gen_t thinlto_create_codegen(void) {
CodeGen->setCodeGenOptLevel(*CGOptLevelOrNone);
}
if (!ThinLTOCacheDir.empty()) {
- auto Err = llvm::sys::fs::create_directories(ThinLTOCacheDir.getValue());
+ auto Err = llvm::sys::fs::create_directories(ThinLTOCacheDir);
if (Err)
report_fatal_error(Twine("Unable to create thinLTO cache directory: ") +
Err.message());
bool result;
- Err = llvm::sys::fs::is_directory(ThinLTOCacheDir.getValue(), result);
+ Err = llvm::sys::fs::is_directory(ThinLTOCacheDir, result);
if (Err || !result)
report_fatal_error(Twine("Unable to get status of thinLTO cache path or "
"path is not a directory: ") +
Err.message());
CodeGen->setCacheDir(ThinLTOCacheDir);
+
+ CodeGen->setCachePruningInterval(ThinLTOCachePruningInterval);
+ CodeGen->setCacheEntryExpiration(ThinLTOCacheEntryExpiration);
+ CodeGen->setCacheMaxSizeFiles(ThinLTOCacheMaxSizeFiles);
+ CodeGen->setCacheMaxSizeBytes(ThinLTOCacheMaxSizeBytes);
}
- CodeGen->setCachePruningInterval(ThinLTOCachePruningInterval);
- CodeGen->setCacheEntryExpiration(ThinLTOCacheEntryExpiration);
- CodeGen->setCacheMaxSizeFiles(ThinLTOCacheMaxSizeFiles);
- CodeGen->setCacheMaxSizeBytes(ThinLTOCacheMaxSizeBytes);
return wrap(CodeGen);
}
More information about the llvm-commits
mailing list