Skip to content

Commit d345f73

Browse files
author
Ekaterina Romanova
committed
Allow 0 to be a valid value pruning interval in C LTO API. Value 0 will cause garbage collector to run. This matches the behavior in C++ LTO API.
llvm-svn: 325303
1 parent 17daedf commit d345f73

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

llvm/include/llvm-c/lto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg,
784784
/**
785785
* Sets the cache pruning interval (in seconds). A negative value disables the
786786
* pruning. An unspecified default value will be applied, and a value of 0 will
787-
* be ignored.
787+
* force prunning to occur.
788788
*
789789
* \since LTO_API_VERSION=18
790790
*/

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ class ThinLTOCodeGenerator {
131131
* To avoid filling the disk space, a few knobs are provided:
132132
* - The pruning interval limit the frequency at which the garbage collector
133133
* will try to scan the cache directory to prune it from expired entries.
134-
* Setting to -1 disable the pruning (default).
134+
* Setting to -1 disable the pruning (default). Setting to 0 will force
135+
* pruning to occur.
135136
* - The pruning expiration time indicates to the garbage collector how old
136137
* an entry needs to be to be removed.
137138
* - Finally, the garbage collector can be instructed to prune the cache till
@@ -149,10 +150,9 @@ class ThinLTOCodeGenerator {
149150
void setCacheDir(std::string Path) { CacheOptions.Path = std::move(Path); }
150151

151152
/// Cache policy: interval (seconds) between two prunes of the cache. Set to a
152-
/// negative value to disable pruning. A value of 0 will be ignored.
153+
/// negative value to disable pruning. A value of 0 will force pruning to
154+
/// occur.
153155
void setCachePruningInterval(int Interval) {
154-
if (Interval == 0)
155-
return;
156156
if(Interval < 0)
157157
CacheOptions.Policy.Interval.reset();
158158
else

llvm/test/ThinLTO/X86/cache.ll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@
5959
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-pruning-interval -1
6060
; RUN: ls %t.cache/llvmcache-foo
6161

62+
; Verify that the pruner doesn't run and a cache file is not deleted when:
63+
; default values for pruning interval and cache expiration are used,
64+
; llvmcache.timestamp is current,
65+
; cache file is older than default cache expiration value.
66+
; RUN: rm -Rf %t.cache && mkdir %t.cache
67+
; RUN: touch -t 197001011200 %t.cache/llvmcache-foo
68+
; RUN: touch %t.cache/llvmcache.timestamp
69+
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache
70+
; RUN: ls %t.cache/llvmcache-foo
71+
72+
; Verify that the pruner runs and a cache file is deleted when:
73+
; pruning interval has value 0 (i.e. run garbage collector now)
74+
; default value for cache expiration is used,
75+
; llvmcache.timestamp is current,
76+
; cache file is older than default cache expiration value.
77+
; RUN: rm -Rf %t.cache && mkdir %t.cache
78+
; RUN: touch -t 197001011200 %t.cache/llvmcache-foo
79+
; RUN: touch %t.cache/llvmcache.timestamp
80+
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-pruning-interval 0
81+
; RUN: not ls %t.cache/llvmcache-foo
82+
6283
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
6384
target triple = "x86_64-apple-macosx10.11.0"
6485

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ static cl::opt<std::string>
157157
ThinLTOCacheDir("thinlto-cache-dir", cl::desc("Enable ThinLTO caching."));
158158

159159
static cl::opt<int>
160-
ThinLTOCachePruningInterval("thinlto-cache-pruning-interval", cl::desc("Set ThinLTO cache pruning interval."));
160+
ThinLTOCachePruningInterval("thinlto-cache-pruning-interval",
161+
cl::init(1200), cl::desc("Set ThinLTO cache pruning interval."));
161162

162163
static cl::opt<std::string> ThinLTOSaveTempsPrefix(
163164
"thinlto-save-temps",

0 commit comments

Comments
 (0)