llvm.org GIT mirror llvm / b981f4f
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342366 91177308-0d34-0410-b5e6-96231b3b80d8 James Henderson 2 years ago
6 changed file(s) with 34 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
186186 /// Cache policy: the maximum size for the cache directory in bytes. A value
187187 /// over the amount of available space on the disk will be reduced to the
188188 /// amount of available space. A value of 0 will be ignored.
189 void setCacheMaxSizeBytes(unsigned MaxSizeBytes) {
189 void setCacheMaxSizeBytes(uint64_t MaxSizeBytes) {
190190 if (MaxSizeBytes)
191191 CacheOptions.Policy.MaxSizeBytes = MaxSizeBytes;
192192 }
4343 * @{
4444 */
4545
46 #define LTO_API_VERSION 22
46 #define LTO_API_VERSION 23
4747
4848 /**
4949 * \since prior to LTO_API_VERSION=3
827827 unsigned max_size_bytes);
828828
829829 /**
830 * Same as thinlto_codegen_set_cache_size_bytes, except the maximum size is in
831 * megabytes (2^20 bytes).
832 *
833 * \since LTO_API_VERSION=23
834 */
835 extern void
836 thinlto_codegen_set_cache_size_megabytes(thinlto_code_gen_t cg,
837 unsigned max_size_megabytes);
838
839 /**
830840 * Sets the maximum number of files in the cache directory. An unspecified
831841 * default value will be applied. A value of 0 will be ignored.
832842 *
120120 ; RUN: not ls %t.cache/llvmcache-foo-100k
121121 ; RUN: not ls %t.cache/llvmcache-foo-77k
122122
123 ; Verify that specifying a max size > 4GB for the cache directory does not
124 ; prematurely prune, due to an integer overflow.
125 ; RUN: rm -Rf %t.cache && mkdir %t.cache
126 ; RUN: %python -c "with open(r'%t.cache/llvmcache-foo-10', 'w') as file: file.truncate(10)"
127 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-max-size-bytes 4294967297
128 ; RUN: ls %t.cache/llvmcache-foo-10
129
130 ; Verify that negative numbers aren't accepted for the
131 ; --thinlto-cache-max-size-bytes switch
132 ; RUN: rm -Rf %t.cache && mkdir %t.cache
133 ; RUN: not llvm-lto %t.bc --thinlto-cache-max-size-bytes -1 2>&1 | FileCheck %s
134 ; CHECK: -thinlto-cache-max-size-bytes option: '-1' value invalid
135
123136 ; Verify that specifying max number of files in the cache directory prunes
124137 ; it to this amount, removing the oldest files first.
125138 ; RUN: rm -Rf %t.cache && mkdir %t.cache
157157 ThinLTOCachePruningInterval("thinlto-cache-pruning-interval",
158158 cl::init(1200), cl::desc("Set ThinLTO cache pruning interval."));
159159
160 static cl::opt<int>
160 static cl::opt<unsigned long long>
161161 ThinLTOCacheMaxSizeBytes("thinlto-cache-max-size-bytes",
162162 cl::desc("Set ThinLTO cache pruning directory maximum size in bytes."));
163163
590590 return unwrap(cg)->setCacheMaxSizeBytes(MaxSizeBytes);
591591 }
592592
593 void thinlto_codegen_set_cache_size_megabytes(
594 thinlto_code_gen_t cg, unsigned MaxSizeMegabytes) {
595 uint64_t MaxSizeBytes = MaxSizeMegabytes;
596 MaxSizeBytes *= 1024 * 1024;
597 return unwrap(cg)->setCacheMaxSizeBytes(MaxSizeBytes);
598 }
599
593600 void thinlto_codegen_set_cache_size_files(
594601 thinlto_code_gen_t cg, unsigned MaxSizeFiles) {
595602 return unwrap(cg)->setCacheMaxSizeFiles(MaxSizeFiles);
5757 thinlto_codegen_set_cache_entry_expiration
5858 thinlto_codegen_set_final_cache_size_relative_to_available_space
5959 thinlto_codegen_set_cache_size_bytes
60 thinlto_codegen_set_cache_size_megabytes
6061 thinlto_codegen_set_cache_size_files
6162 thinlto_codegen_set_savetemps_dir
6263 thinlto_codegen_set_cpu