llvm.org GIT mirror llvm / 76899c6
[ThinLTO] Added a couple of C LTO API interfaces to control the cache policy. - thinlto_codegen_set_cache_size_bytes to control the absolute size of cache directory. - thinlto_codegen_set_cache_size_files the size and amount of files in cache directory. These functions have been supported in C++ LTO API for a long time, but were absent in C LTO API. Differential Revision: https://reviews.llvm.org/D42446 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326537 91177308-0d34-0410-b5e6-96231b3b80d8 Ekaterina Romanova 2 years ago
6 changed file(s) with 96 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
183183 CacheOptions.Policy.MaxSizePercentageOfAvailableSpace = Percentage;
184184 }
185185
186 /// Cache policy: the maximum size for the cache directory in bytes. A value
187 /// over the amount of available space on the disk will be reduced to the
188 /// amount of available space. A value of 0 will be ignored.
189 void setCacheMaxSizeBytes(unsigned MaxSizeBytes) {
190 if (MaxSizeBytes)
191 CacheOptions.Policy.MaxSizeBytes = MaxSizeBytes;
192 }
193
194 /// Cache policy: the maximum number of files in the cache directory. A value
195 /// of 0 will be ignored.
196 void setCacheMaxSizeFiles(unsigned MaxSizeFiles) {
197 if (MaxSizeFiles)
198 CacheOptions.Policy.MaxSizeFiles = MaxSizeFiles;
199 }
200
186201 /**@}*/
187202
188203 /// Set the path to a directory where to save temporaries at various stages of
4343 * @{
4444 */
4545
46 #define LTO_API_VERSION 21
46 #define LTO_API_VERSION 22
4747
4848 /**
4949 * \since prior to LTO_API_VERSION=3
816816 unsigned expiration);
817817
818818 /**
819 * Sets the maximum size of the cache directory (in bytes). A value over the
820 * amount of available space on the disk will be reduced to the amount of
821 * available space. An unspecified default value will be applied. A value of 0
822 * will be ignored.
823 *
824 * \since LTO_API_VERSION=22
825 */
826 extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg,
827 unsigned max_size_bytes);
828
829 /**
830 * Sets the maximum number of files in the cache directory. An unspecified
831 * default value will be applied. A value of 0 will be ignored.
832 *
833 * \since LTO_API_VERSION=22
834 */
835 extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg,
836 unsigned max_size_files);
837
838
839
840 /**
819841 * @} // endgroup LLVMCTLTO_CACHING
820842 */
821843
7979 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-pruning-interval 0
8080 ; RUN: not ls %t.cache/llvmcache-foo
8181
82 ; Verify that specifying max size for the cache directory prunes it to this
83 ; size, removing the largest files first.
84 ; RUN: rm -Rf %t.cache && mkdir %t.cache
85 ; Create cache files with different sizes.
86 ; Only 8B, 16B and 76B files should stay after pruning.
87 ; RUN: %python -c "print(' ' * 1023)" > %t.cache/llvmcache-foo-1024
88 ; RUN: %python -c "print(' ' * 15)" > %t.cache/llvmcache-foo-16
89 ; RUN: %python -c "print(' ' * 7)" > %t.cache/llvmcache-foo-8
90 ; RUN: %python -c "print(' ' * 75)" > %t.cache/llvmcache-foo-76
91 ; RUN: %python -c "print(' ' * 76)" > %t.cache/llvmcache-foo-77
92 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-max-size-bytes 100
93 ; RUN: ls %t.cache/llvmcache-foo-16
94 ; RUN: ls %t.cache/llvmcache-foo-8
95 ; RUN: ls %t.cache/llvmcache-foo-76
96 ; RUN: not ls %t.cache/llvmcache-foo-1024
97 ; RUN: not ls %t.cache/llvmcache-foo-77
98
99 ; Verify that specifying max number of files in the cache directory prunes
100 ; it to this amount, removing the largest files first.
101 ; RUN: rm -Rf %t.cache && mkdir %t.cache
102 ; Create cache files with different sizes.
103 ; Only 8B and 16B files should stay after pruning.
104 ; RUN: %python -c "print(' ' * 1023)" > %t.cache/llvmcache-foo-1024
105 ; RUN: %python -c "print(' ' * 15)" > %t.cache/llvmcache-foo-16
106 ; RUN: %python -c "print(' ' * 7)" > %t.cache/llvmcache-foo-8
107 ; RUN: %python -c "print(' ' * 75)" > %t.cache/llvmcache-foo-76
108 ; RUN: %python -c "print(' ' * 76)" > %t.cache/llvmcache-foo-77
109 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-max-size-files 2
110 ; RUN: ls %t.cache/llvmcache-foo-16
111 ; RUN: ls %t.cache/llvmcache-foo-8
112 ; RUN: not ls %t.cache/llvmcache-foo-76
113 ; RUN: not ls %t.cache/llvmcache-foo-1024
114 ; RUN: not ls %t.cache/llvmcache-foo-77
115
82116 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
83117 target triple = "x86_64-apple-macosx10.11.0"
84118
159159 ThinLTOCachePruningInterval("thinlto-cache-pruning-interval",
160160 cl::init(1200), cl::desc("Set ThinLTO cache pruning interval."));
161161
162 static cl::opt
163 ThinLTOCacheMaxSizeBytes("thinlto-cache-max-size-bytes",
164 cl::desc("Set ThinLTO cache pruning directory maximum size in bytes."));
165
166 static cl::opt
167 ThinLTOCacheMaxSizeFiles("thinlto-cache-max-size-files", cl::init(1000000),
168 cl::desc("Set ThinLTO cache pruning directory maximum number of files."));
169
162170 static cl::opt ThinLTOSaveTempsPrefix(
163171 "thinlto-save-temps",
164172 cl::desc("Save ThinLTO temp files using filenames created by adding "
474482 ThinGenerator.setTargetOptions(Options);
475483 ThinGenerator.setCacheDir(ThinLTOCacheDir);
476484 ThinGenerator.setCachePruningInterval(ThinLTOCachePruningInterval);
485 ThinGenerator.setCacheMaxSizeFiles(ThinLTOCacheMaxSizeFiles);
486 ThinGenerator.setCacheMaxSizeBytes(ThinLTOCacheMaxSizeBytes);
477487 ThinGenerator.setFreestanding(EnableFreestanding);
478488
479489 // Add all the exported symbols to the table of symbols to preserve.
585585 return unwrap(cg)->setMaxCacheSizeRelativeToAvailableSpace(Percentage);
586586 }
587587
588 void thinlto_codegen_set_cache_size_bytes(
589 thinlto_code_gen_t cg, unsigned MaxSizeBytes) {
590 return unwrap(cg)->setCacheMaxSizeBytes(MaxSizeBytes);
591 }
592
593 void thinlto_codegen_set_cache_size_files(
594 thinlto_code_gen_t cg, unsigned MaxSizeFiles) {
595 return unwrap(cg)->setCacheMaxSizeFiles(MaxSizeFiles);
596 }
597
588598 void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg,
589599 const char *save_temps_dir) {
590600 return unwrap(cg)->setSaveTempsDir(save_temps_dir);
5555 thinlto_codegen_set_cache_dir
5656 thinlto_codegen_set_cache_pruning_interval
5757 thinlto_codegen_set_cache_entry_expiration
58 thinlto_codegen_set_final_cache_size_relative_to_available_space
59 thinlto_codegen_set_cache_size_bytes
60 thinlto_codegen_set_cache_size_files
5861 thinlto_codegen_set_savetemps_dir
5962 thinlto_codegen_set_cpu
6063 thinlto_debug_options
6164 lto_module_is_thinlto
6265 thinlto_codegen_add_must_preserve_symbol
6366 thinlto_codegen_add_cross_referenced_symbol
64 thinlto_codegen_set_final_cache_size_relative_to_available_space
6567 thinlto_codegen_set_codegen_only
6668 thinlto_codegen_disable_codegen
6769 thinlto_module_get_num_object_files
6870 thinlto_module_get_object_file
69 thinlto_set_generated_objects_dir
71 thinlto_set_generated_objects_dir