llvm.org GIT mirror llvm / 5b5d262
[Support][CachePruning] Disable cache pruning regression fix borked by: rL284966 (see: https://reviews.llvm.org/D25730). Previously, Interval was unsigned (see: CachePruning.h), replacing the type with std::chrono::seconds (which is signed) causes a regression in behaviour because the c-api intends negative values to translate to large positive intervals to *effectively* disable the pruning (see comments on: setCachePruningInterval()). Differential Revision: https://reviews.llvm.org/D41231 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321077 91177308-0d34-0410-b5e6-96231b3b80d8 Ben Dunbobbin 2 years ago
4 changed file(s) with 32 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
150150 /// Cache policy: interval (seconds) between two prune of the cache. Set to a
151151 /// negative value (default) to disable pruning. A value of 0 will be ignored.
152152 void setCachePruningInterval(int Interval) {
153 static_assert(std::is_same
154 std::chrono::seconds>::value,
155 "ensure same types to avoid risk of overflow");
153156 if (Interval)
154 CacheOptions.Policy.Interval = std::chrono::seconds(Interval);
157 CacheOptions.Policy.Interval = Interval > 0 ? std::chrono::seconds(Interval)
158 : std::chrono::seconds::max();
155159 }
156160
157161 /// Cache policy: expiration (in seconds) for an entry.
154154 SmallString<128> TimestampFile(Path);
155155 sys::path::append(TimestampFile, "llvmcache.timestamp");
156156 sys::fs::file_status FileStatus;
157 const auto CurrentTime = system_clock::now();
157 const auto CurrentTime =
158 time_point_cast(system_clock::now());
158159 if (auto EC = sys::fs::status(TimestampFile, FileStatus)) {
159160 if (EC == errc::no_such_file_or_directory) {
160161 // If the timestamp file wasn't there, create one now.
167168 if (Policy.Interval != seconds(0)) {
168169 // Check whether the time stamp is older than our pruning interval.
169170 // If not, do nothing.
170 const auto TimeStampModTime = FileStatus.getLastModificationTime();
171 const auto TimeStampModTime = time_point_cast(
172 FileStatus.getLastModificationTime());
171173 auto TimeStampAge = CurrentTime - TimeStampModTime;
172174 if (TimeStampAge <= Policy.Interval) {
173175 DEBUG(dbgs() << "Timestamp file too recent ("
44
55 ; Verify that enabling caching is ignoring module without hash
66 ; RUN: rm -Rf %t.cache && mkdir %t.cache
7 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache
7 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache
88 ; RUN: ls %t.cache/llvmcache.timestamp
99 ; RUN: ls %t.cache | count 1
1010
2626 ; files matching the pattern "llvmcache-*".
2727 ; RUN: rm -Rf %t.cache && mkdir %t.cache
2828 ; RUN: touch -t 197001011200 %t.cache/llvmcache-foo %t.cache/foo
29 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache
29 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache
3030 ; RUN: ls %t.cache | count 4
3131 ; RUN: ls %t.cache/llvmcache.timestamp
3232 ; RUN: ls %t.cache/foo
3535
3636 ; Verify that enabling caching is working with llvm-lto2
3737 ; RUN: rm -Rf %t.cache
38 ; RUN: llvm-lto2 run -o %t.o %t2.bc %t.bc -cache-dir %t.cache \
38 ; RUN: llvm-lto2 run -o %t.o %t2.bc %t.bc -cache-dir %t.cache \
3939 ; RUN: -r=%t2.bc,_main,plx \
4040 ; RUN: -r=%t2.bc,_globalfunc,lx \
4141 ; RUN: -r=%t.bc,_globalfunc,plx
4242 ; RUN: ls %t.cache | count 2
4343 ; RUN: ls %t.cache/llvmcache-* | count 2
44
45 ; Verify that caches with a timestamp older than the pruning interval
46 ; will be pruned
47 ; RUN: rm -Rf %t.cache && mkdir %t.cache
48 ; RUN: touch -t 197001011200 %t.cache/llvmcache-foo
49 ; RUN: touch -t 197001011200 %t.cache/llvmcache.timestamp
50 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache
51 ; RUN: not ls %t.cache/llvmcache-foo
52
53 ; Verify that specifying a negative number for the pruning interval
54 ; effectively disables the pruning
55 ; RUN: rm -Rf %t.cache && mkdir %t.cache
56 ; RUN: touch -t 197001011200 %t.cache/llvmcache-foo
57 ; RUN: touch -t 197001011200 %t.cache/llvmcache.timestamp
58 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-pruning-interval -1
59 ; RUN: ls %t.cache/llvmcache-foo
4460
4561 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4662 target triple = "x86_64-apple-macosx10.11.0"
155155 static cl::opt
156156 ThinLTOCacheDir("thinlto-cache-dir", cl::desc("Enable ThinLTO caching."));
157157
158 static cl::opt
159 ThinLTOCachePruningInterval("thinlto-cache-pruning-interval", cl::desc("Set ThinLTO cache pruning interval."));
160
158161 static cl::opt ThinLTOSaveTempsPrefix(
159162 "thinlto-save-temps",
160163 cl::desc("Save ThinLTO temp files using filenames created by adding "
469472 ThinGenerator.setCodePICModel(getRelocModel());
470473 ThinGenerator.setTargetOptions(Options);
471474 ThinGenerator.setCacheDir(ThinLTOCacheDir);
475 ThinGenerator.setCachePruningInterval(ThinLTOCachePruningInterval);
472476 ThinGenerator.setFreestanding(EnableFreestanding);
473477
474478 // Add all the exported symbols to the table of symbols to preserve.