[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 llvm-svn: 321077
This commit is contained in:
parent
3feaf2a207
commit
9ecb8b548c
|
@ -151,8 +151,12 @@ public:
|
||||||
/// Cache policy: interval (seconds) between two prune of the cache. Set to a
|
/// Cache policy: interval (seconds) between two prune of the cache. Set to a
|
||||||
/// negative value (default) to disable pruning. A value of 0 will be ignored.
|
/// negative value (default) to disable pruning. A value of 0 will be ignored.
|
||||||
void setCachePruningInterval(int Interval) {
|
void setCachePruningInterval(int Interval) {
|
||||||
|
static_assert(std::is_same<decltype(CacheOptions.Policy.Interval),
|
||||||
|
std::chrono::seconds>::value,
|
||||||
|
"ensure same types to avoid risk of overflow");
|
||||||
if (Interval)
|
if (Interval)
|
||||||
CacheOptions.Policy.Interval = std::chrono::seconds(Interval);
|
CacheOptions.Policy.Interval = Interval > 0 ? std::chrono::seconds(Interval)
|
||||||
|
: std::chrono::seconds::max();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cache policy: expiration (in seconds) for an entry.
|
/// Cache policy: expiration (in seconds) for an entry.
|
||||||
|
|
|
@ -155,7 +155,8 @@ bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy) {
|
||||||
SmallString<128> TimestampFile(Path);
|
SmallString<128> TimestampFile(Path);
|
||||||
sys::path::append(TimestampFile, "llvmcache.timestamp");
|
sys::path::append(TimestampFile, "llvmcache.timestamp");
|
||||||
sys::fs::file_status FileStatus;
|
sys::fs::file_status FileStatus;
|
||||||
const auto CurrentTime = system_clock::now();
|
const auto CurrentTime =
|
||||||
|
time_point_cast<decltype(Policy.Interval)>(system_clock::now());
|
||||||
if (auto EC = sys::fs::status(TimestampFile, FileStatus)) {
|
if (auto EC = sys::fs::status(TimestampFile, FileStatus)) {
|
||||||
if (EC == errc::no_such_file_or_directory) {
|
if (EC == errc::no_such_file_or_directory) {
|
||||||
// If the timestamp file wasn't there, create one now.
|
// If the timestamp file wasn't there, create one now.
|
||||||
|
@ -168,7 +169,8 @@ bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy) {
|
||||||
if (Policy.Interval != seconds(0)) {
|
if (Policy.Interval != seconds(0)) {
|
||||||
// Check whether the time stamp is older than our pruning interval.
|
// Check whether the time stamp is older than our pruning interval.
|
||||||
// If not, do nothing.
|
// If not, do nothing.
|
||||||
const auto TimeStampModTime = FileStatus.getLastModificationTime();
|
const auto TimeStampModTime = time_point_cast<decltype(Policy.Interval)>(
|
||||||
|
FileStatus.getLastModificationTime());
|
||||||
auto TimeStampAge = CurrentTime - TimeStampModTime;
|
auto TimeStampAge = CurrentTime - TimeStampModTime;
|
||||||
if (TimeStampAge <= Policy.Interval) {
|
if (TimeStampAge <= Policy.Interval) {
|
||||||
DEBUG(dbgs() << "Timestamp file too recent ("
|
DEBUG(dbgs() << "Timestamp file too recent ("
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
; Verify that enabling caching is ignoring module without hash
|
; Verify that enabling caching is ignoring module without hash
|
||||||
; RUN: rm -Rf %t.cache && mkdir %t.cache
|
; RUN: rm -Rf %t.cache && mkdir %t.cache
|
||||||
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache
|
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache
|
||||||
; RUN: ls %t.cache/llvmcache.timestamp
|
; RUN: ls %t.cache/llvmcache.timestamp
|
||||||
; RUN: ls %t.cache | count 1
|
; RUN: ls %t.cache | count 1
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
; files matching the pattern "llvmcache-*".
|
; files matching the pattern "llvmcache-*".
|
||||||
; RUN: rm -Rf %t.cache && mkdir %t.cache
|
; RUN: rm -Rf %t.cache && mkdir %t.cache
|
||||||
; RUN: touch -t 197001011200 %t.cache/llvmcache-foo %t.cache/foo
|
; RUN: touch -t 197001011200 %t.cache/llvmcache-foo %t.cache/foo
|
||||||
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache
|
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache
|
||||||
; RUN: ls %t.cache | count 4
|
; RUN: ls %t.cache | count 4
|
||||||
; RUN: ls %t.cache/llvmcache.timestamp
|
; RUN: ls %t.cache/llvmcache.timestamp
|
||||||
; RUN: ls %t.cache/foo
|
; RUN: ls %t.cache/foo
|
||||||
|
@ -36,13 +36,29 @@
|
||||||
|
|
||||||
; Verify that enabling caching is working with llvm-lto2
|
; Verify that enabling caching is working with llvm-lto2
|
||||||
; RUN: rm -Rf %t.cache
|
; RUN: rm -Rf %t.cache
|
||||||
; RUN: llvm-lto2 run -o %t.o %t2.bc %t.bc -cache-dir %t.cache \
|
; RUN: llvm-lto2 run -o %t.o %t2.bc %t.bc -cache-dir %t.cache \
|
||||||
; RUN: -r=%t2.bc,_main,plx \
|
; RUN: -r=%t2.bc,_main,plx \
|
||||||
; RUN: -r=%t2.bc,_globalfunc,lx \
|
; RUN: -r=%t2.bc,_globalfunc,lx \
|
||||||
; RUN: -r=%t.bc,_globalfunc,plx
|
; RUN: -r=%t.bc,_globalfunc,plx
|
||||||
; RUN: ls %t.cache | count 2
|
; RUN: ls %t.cache | count 2
|
||||||
; RUN: ls %t.cache/llvmcache-* | count 2
|
; RUN: ls %t.cache/llvmcache-* | count 2
|
||||||
|
|
||||||
|
; Verify that caches with a timestamp older than the pruning interval
|
||||||
|
; will be pruned
|
||||||
|
; RUN: rm -Rf %t.cache && mkdir %t.cache
|
||||||
|
; RUN: touch -t 197001011200 %t.cache/llvmcache-foo
|
||||||
|
; RUN: touch -t 197001011200 %t.cache/llvmcache.timestamp
|
||||||
|
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache
|
||||||
|
; RUN: not ls %t.cache/llvmcache-foo
|
||||||
|
|
||||||
|
; Verify that specifying a negative number for the pruning interval
|
||||||
|
; effectively disables the pruning
|
||||||
|
; RUN: rm -Rf %t.cache && mkdir %t.cache
|
||||||
|
; RUN: touch -t 197001011200 %t.cache/llvmcache-foo
|
||||||
|
; RUN: touch -t 197001011200 %t.cache/llvmcache.timestamp
|
||||||
|
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-pruning-interval -1
|
||||||
|
; RUN: ls %t.cache/llvmcache-foo
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
|
|
|
@ -156,6 +156,9 @@ static cl::opt<std::string> ThinLTOModuleId(
|
||||||
static cl::opt<std::string>
|
static cl::opt<std::string>
|
||||||
ThinLTOCacheDir("thinlto-cache-dir", cl::desc("Enable ThinLTO caching."));
|
ThinLTOCacheDir("thinlto-cache-dir", cl::desc("Enable ThinLTO caching."));
|
||||||
|
|
||||||
|
static cl::opt<int>
|
||||||
|
ThinLTOCachePruningInterval("thinlto-cache-pruning-interval", cl::desc("Set ThinLTO cache pruning interval."));
|
||||||
|
|
||||||
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 "
|
||||||
|
@ -470,6 +473,7 @@ public:
|
||||||
ThinGenerator.setCodePICModel(getRelocModel());
|
ThinGenerator.setCodePICModel(getRelocModel());
|
||||||
ThinGenerator.setTargetOptions(Options);
|
ThinGenerator.setTargetOptions(Options);
|
||||||
ThinGenerator.setCacheDir(ThinLTOCacheDir);
|
ThinGenerator.setCacheDir(ThinLTOCacheDir);
|
||||||
|
ThinGenerator.setCachePruningInterval(ThinLTOCachePruningInterval);
|
||||||
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.
|
||||||
|
|
Loading…
Reference in New Issue