1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[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

llvm-svn: 326537
This commit is contained in:
Ekaterina Romanova 2018-03-02 03:51:27 +00:00
parent 60ce171e6f
commit 26e5ff8165
6 changed files with 96 additions and 3 deletions

View File

@ -44,7 +44,7 @@ typedef bool lto_bool_t;
* @{ * @{
*/ */
#define LTO_API_VERSION 21 #define LTO_API_VERSION 22
/** /**
* \since prior to LTO_API_VERSION=3 * \since prior to LTO_API_VERSION=3
@ -816,6 +816,28 @@ extern void thinlto_codegen_set_final_cache_size_relative_to_available_space(
extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg, extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg,
unsigned expiration); unsigned expiration);
/**
* Sets the maximum size of the cache directory (in bytes). A value over the
* amount of available space on the disk will be reduced to the amount of
* available space. An unspecified default value will be applied. A value of 0
* will be ignored.
*
* \since LTO_API_VERSION=22
*/
extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg,
unsigned max_size_bytes);
/**
* Sets the maximum number of files in the cache directory. An unspecified
* default value will be applied. A value of 0 will be ignored.
*
* \since LTO_API_VERSION=22
*/
extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg,
unsigned max_size_files);
/** /**
* @} // endgroup LLVMCTLTO_CACHING * @} // endgroup LLVMCTLTO_CACHING
*/ */

View File

@ -184,6 +184,21 @@ public:
CacheOptions.Policy.MaxSizePercentageOfAvailableSpace = Percentage; CacheOptions.Policy.MaxSizePercentageOfAvailableSpace = Percentage;
} }
/// Cache policy: the maximum size for the cache directory in bytes. A value
/// over the amount of available space on the disk will be reduced to the
/// amount of available space. A value of 0 will be ignored.
void setCacheMaxSizeBytes(unsigned MaxSizeBytes) {
if (MaxSizeBytes)
CacheOptions.Policy.MaxSizeBytes = MaxSizeBytes;
}
/// Cache policy: the maximum number of files in the cache directory. A value
/// of 0 will be ignored.
void setCacheMaxSizeFiles(unsigned MaxSizeFiles) {
if (MaxSizeFiles)
CacheOptions.Policy.MaxSizeFiles = MaxSizeFiles;
}
/**@}*/ /**@}*/
/// Set the path to a directory where to save temporaries at various stages of /// Set the path to a directory where to save temporaries at various stages of

View File

@ -80,6 +80,40 @@
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-pruning-interval 0 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-pruning-interval 0
; RUN: not ls %t.cache/llvmcache-foo ; RUN: not ls %t.cache/llvmcache-foo
; Verify that specifying max size for the cache directory prunes it to this
; size, removing the largest files first.
; RUN: rm -Rf %t.cache && mkdir %t.cache
; Create cache files with different sizes.
; Only 8B, 16B and 76B files should stay after pruning.
; RUN: %python -c "print(' ' * 1023)" > %t.cache/llvmcache-foo-1024
; RUN: %python -c "print(' ' * 15)" > %t.cache/llvmcache-foo-16
; RUN: %python -c "print(' ' * 7)" > %t.cache/llvmcache-foo-8
; RUN: %python -c "print(' ' * 75)" > %t.cache/llvmcache-foo-76
; RUN: %python -c "print(' ' * 76)" > %t.cache/llvmcache-foo-77
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-max-size-bytes 100
; RUN: ls %t.cache/llvmcache-foo-16
; RUN: ls %t.cache/llvmcache-foo-8
; RUN: ls %t.cache/llvmcache-foo-76
; RUN: not ls %t.cache/llvmcache-foo-1024
; RUN: not ls %t.cache/llvmcache-foo-77
; Verify that specifying max number of files in the cache directory prunes
; it to this amount, removing the largest files first.
; RUN: rm -Rf %t.cache && mkdir %t.cache
; Create cache files with different sizes.
; Only 8B and 16B files should stay after pruning.
; RUN: %python -c "print(' ' * 1023)" > %t.cache/llvmcache-foo-1024
; RUN: %python -c "print(' ' * 15)" > %t.cache/llvmcache-foo-16
; RUN: %python -c "print(' ' * 7)" > %t.cache/llvmcache-foo-8
; RUN: %python -c "print(' ' * 75)" > %t.cache/llvmcache-foo-76
; RUN: %python -c "print(' ' * 76)" > %t.cache/llvmcache-foo-77
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-max-size-files 2
; RUN: ls %t.cache/llvmcache-foo-16
; RUN: ls %t.cache/llvmcache-foo-8
; RUN: not ls %t.cache/llvmcache-foo-76
; RUN: not ls %t.cache/llvmcache-foo-1024
; RUN: not ls %t.cache/llvmcache-foo-77
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.11.0" target triple = "x86_64-apple-macosx10.11.0"

View File

@ -160,6 +160,14 @@ static cl::opt<int>
ThinLTOCachePruningInterval("thinlto-cache-pruning-interval", ThinLTOCachePruningInterval("thinlto-cache-pruning-interval",
cl::init(1200), cl::desc("Set ThinLTO cache pruning interval.")); cl::init(1200), cl::desc("Set ThinLTO cache pruning interval."));
static cl::opt<int>
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<std::string> ThinLTOSaveTempsPrefix( static cl::opt<std::string> ThinLTOSaveTempsPrefix(
"thinlto-save-temps", "thinlto-save-temps",
cl::desc("Save ThinLTO temp files using filenames created by adding " cl::desc("Save ThinLTO temp files using filenames created by adding "
@ -475,6 +483,8 @@ public:
ThinGenerator.setTargetOptions(Options); ThinGenerator.setTargetOptions(Options);
ThinGenerator.setCacheDir(ThinLTOCacheDir); ThinGenerator.setCacheDir(ThinLTOCacheDir);
ThinGenerator.setCachePruningInterval(ThinLTOCachePruningInterval); ThinGenerator.setCachePruningInterval(ThinLTOCachePruningInterval);
ThinGenerator.setCacheMaxSizeFiles(ThinLTOCacheMaxSizeFiles);
ThinGenerator.setCacheMaxSizeBytes(ThinLTOCacheMaxSizeBytes);
ThinGenerator.setFreestanding(EnableFreestanding); ThinGenerator.setFreestanding(EnableFreestanding);
// Add all the exported symbols to the table of symbols to preserve. // Add all the exported symbols to the table of symbols to preserve.

View File

@ -586,6 +586,16 @@ void thinlto_codegen_set_final_cache_size_relative_to_available_space(
return unwrap(cg)->setMaxCacheSizeRelativeToAvailableSpace(Percentage); return unwrap(cg)->setMaxCacheSizeRelativeToAvailableSpace(Percentage);
} }
void thinlto_codegen_set_cache_size_bytes(
thinlto_code_gen_t cg, unsigned MaxSizeBytes) {
return unwrap(cg)->setCacheMaxSizeBytes(MaxSizeBytes);
}
void thinlto_codegen_set_cache_size_files(
thinlto_code_gen_t cg, unsigned MaxSizeFiles) {
return unwrap(cg)->setCacheMaxSizeFiles(MaxSizeFiles);
}
void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg, void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg,
const char *save_temps_dir) { const char *save_temps_dir) {
return unwrap(cg)->setSaveTempsDir(save_temps_dir); return unwrap(cg)->setSaveTempsDir(save_temps_dir);

View File

@ -56,15 +56,17 @@ thinlto_codegen_set_pic_model
thinlto_codegen_set_cache_dir thinlto_codegen_set_cache_dir
thinlto_codegen_set_cache_pruning_interval thinlto_codegen_set_cache_pruning_interval
thinlto_codegen_set_cache_entry_expiration thinlto_codegen_set_cache_entry_expiration
thinlto_codegen_set_final_cache_size_relative_to_available_space
thinlto_codegen_set_cache_size_bytes
thinlto_codegen_set_cache_size_files
thinlto_codegen_set_savetemps_dir thinlto_codegen_set_savetemps_dir
thinlto_codegen_set_cpu thinlto_codegen_set_cpu
thinlto_debug_options thinlto_debug_options
lto_module_is_thinlto lto_module_is_thinlto
thinlto_codegen_add_must_preserve_symbol thinlto_codegen_add_must_preserve_symbol
thinlto_codegen_add_cross_referenced_symbol thinlto_codegen_add_cross_referenced_symbol
thinlto_codegen_set_final_cache_size_relative_to_available_space
thinlto_codegen_set_codegen_only thinlto_codegen_set_codegen_only
thinlto_codegen_disable_codegen thinlto_codegen_disable_codegen
thinlto_module_get_num_object_files thinlto_module_get_num_object_files
thinlto_module_get_object_file thinlto_module_get_object_file
thinlto_set_generated_objects_dir thinlto_set_generated_objects_dir