Skip to content

Commit e29e408

Browse files
committed
Reland r342233: [ThinLTO] Allow setting of maximum cache size with 64-bit number
The original was reverted due to an apparent build-bot test failure, but it looks like this is just a flaky test. Also added a C-interface function for large values, and updated llvm-lto's --thinlto-cache-max-size-bytes switch to take a type larger than int. The maximum cache size in terms of bytes is a 64-bit number. However, the methods to set it only took unsigned previously, which meant that the maximum cache size could not be specified above 4GB. That's quite small compared to the output of some projects, so it makes sense to provide the ability to set larger values in that field. We also needed a C-interface function that provides a greater range than the existing thinlto_codegen_set_cache_size_bytes, which also only takes an unsigned, so this change also adds hinlto_codegen_set_cache_size_megabytes. Reviewed by: mehdi_amini, tejohnson, steven_wu Differential Revision: https://reviews.llvm.org/D52023 llvm-svn: 342366
1 parent c704f4d commit e29e408

File tree

6 files changed

+34
-3
lines changed

6 files changed

+34
-3
lines changed

llvm/include/llvm-c/lto.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef bool lto_bool_t;
4444
* @{
4545
*/
4646

47-
#define LTO_API_VERSION 22
47+
#define LTO_API_VERSION 23
4848

4949
/**
5050
* \since prior to LTO_API_VERSION=3
@@ -827,6 +827,16 @@ extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg,
827827
extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg,
828828
unsigned max_size_bytes);
829829

830+
/**
831+
* Same as thinlto_codegen_set_cache_size_bytes, except the maximum size is in
832+
* megabytes (2^20 bytes).
833+
*
834+
* \since LTO_API_VERSION=23
835+
*/
836+
extern void
837+
thinlto_codegen_set_cache_size_megabytes(thinlto_code_gen_t cg,
838+
unsigned max_size_megabytes);
839+
830840
/**
831841
* Sets the maximum number of files in the cache directory. An unspecified
832842
* default value will be applied. A value of 0 will be ignored.

llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class ThinLTOCodeGenerator {
187187
/// Cache policy: the maximum size for the cache directory in bytes. A value
188188
/// over the amount of available space on the disk will be reduced to the
189189
/// amount of available space. A value of 0 will be ignored.
190-
void setCacheMaxSizeBytes(unsigned MaxSizeBytes) {
190+
void setCacheMaxSizeBytes(uint64_t MaxSizeBytes) {
191191
if (MaxSizeBytes)
192192
CacheOptions.Policy.MaxSizeBytes = MaxSizeBytes;
193193
}

llvm/test/ThinLTO/X86/cache.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@
121121
; RUN: not ls %t.cache/llvmcache-foo-100k
122122
; RUN: not ls %t.cache/llvmcache-foo-77k
123123

124+
; Verify that specifying a max size > 4GB for the cache directory does not
125+
; prematurely prune, due to an integer overflow.
126+
; RUN: rm -Rf %t.cache && mkdir %t.cache
127+
; RUN: %python -c "with open(r'%t.cache/llvmcache-foo-10', 'w') as file: file.truncate(10)"
128+
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-max-size-bytes 4294967297
129+
; RUN: ls %t.cache/llvmcache-foo-10
130+
131+
; Verify that negative numbers aren't accepted for the
132+
; --thinlto-cache-max-size-bytes switch
133+
; RUN: rm -Rf %t.cache && mkdir %t.cache
134+
; RUN: not llvm-lto %t.bc --thinlto-cache-max-size-bytes -1 2>&1 | FileCheck %s
135+
; CHECK: -thinlto-cache-max-size-bytes option: '-1' value invalid
136+
124137
; Verify that specifying max number of files in the cache directory prunes
125138
; it to this amount, removing the oldest files first.
126139
; RUN: rm -Rf %t.cache && mkdir %t.cache

llvm/tools/llvm-lto/llvm-lto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static cl::opt<int>
158158
ThinLTOCachePruningInterval("thinlto-cache-pruning-interval",
159159
cl::init(1200), cl::desc("Set ThinLTO cache pruning interval."));
160160

161-
static cl::opt<int>
161+
static cl::opt<unsigned long long>
162162
ThinLTOCacheMaxSizeBytes("thinlto-cache-max-size-bytes",
163163
cl::desc("Set ThinLTO cache pruning directory maximum size in bytes."));
164164

llvm/tools/lto/lto.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,13 @@ void thinlto_codegen_set_cache_size_bytes(
591591
return unwrap(cg)->setCacheMaxSizeBytes(MaxSizeBytes);
592592
}
593593

594+
void thinlto_codegen_set_cache_size_megabytes(
595+
thinlto_code_gen_t cg, unsigned MaxSizeMegabytes) {
596+
uint64_t MaxSizeBytes = MaxSizeMegabytes;
597+
MaxSizeBytes *= 1024 * 1024;
598+
return unwrap(cg)->setCacheMaxSizeBytes(MaxSizeBytes);
599+
}
600+
594601
void thinlto_codegen_set_cache_size_files(
595602
thinlto_code_gen_t cg, unsigned MaxSizeFiles) {
596603
return unwrap(cg)->setCacheMaxSizeFiles(MaxSizeFiles);

llvm/tools/lto/lto.exports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ thinlto_codegen_set_cache_pruning_interval
5858
thinlto_codegen_set_cache_entry_expiration
5959
thinlto_codegen_set_final_cache_size_relative_to_available_space
6060
thinlto_codegen_set_cache_size_bytes
61+
thinlto_codegen_set_cache_size_megabytes
6162
thinlto_codegen_set_cache_size_files
6263
thinlto_codegen_set_savetemps_dir
6364
thinlto_codegen_set_cpu

0 commit comments

Comments
 (0)