Index: llvm/trunk/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h =================================================================== --- llvm/trunk/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h +++ llvm/trunk/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h @@ -151,8 +151,12 @@ /// 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. void setCachePruningInterval(int Interval) { + static_assert(std::is_same::value, + "ensure same types to avoid risk of overflow"); 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. Index: llvm/trunk/lib/Support/CachePruning.cpp =================================================================== --- llvm/trunk/lib/Support/CachePruning.cpp +++ llvm/trunk/lib/Support/CachePruning.cpp @@ -155,7 +155,8 @@ SmallString<128> TimestampFile(Path); sys::path::append(TimestampFile, "llvmcache.timestamp"); sys::fs::file_status FileStatus; - const auto CurrentTime = system_clock::now(); + const auto CurrentTime = + time_point_cast(system_clock::now()); if (auto EC = sys::fs::status(TimestampFile, FileStatus)) { if (EC == errc::no_such_file_or_directory) { // If the timestamp file wasn't there, create one now. @@ -168,7 +169,8 @@ if (Policy.Interval != seconds(0)) { // Check whether the time stamp is older than our pruning interval. // If not, do nothing. - const auto TimeStampModTime = FileStatus.getLastModificationTime(); + const auto TimeStampModTime = time_point_cast( + FileStatus.getLastModificationTime()); auto TimeStampAge = CurrentTime - TimeStampModTime; if (TimeStampAge <= Policy.Interval) { DEBUG(dbgs() << "Timestamp file too recent (" Index: llvm/trunk/test/ThinLTO/X86/cache.ll =================================================================== --- llvm/trunk/test/ThinLTO/X86/cache.ll +++ llvm/trunk/test/ThinLTO/X86/cache.ll @@ -5,7 +5,7 @@ ; Verify that enabling caching is ignoring module without hash ; 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 | count 1 @@ -27,7 +27,7 @@ ; files matching the pattern "llvmcache-*". ; RUN: rm -Rf %t.cache && mkdir %t.cache ; 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/llvmcache.timestamp ; RUN: ls %t.cache/foo @@ -36,13 +36,29 @@ ; Verify that enabling caching is working with llvm-lto2 ; 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,_globalfunc,lx \ ; RUN: -r=%t.bc,_globalfunc,plx ; RUN: ls %t.cache | 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 triple = "x86_64-apple-macosx10.11.0" Index: llvm/trunk/tools/llvm-lto/llvm-lto.cpp =================================================================== --- llvm/trunk/tools/llvm-lto/llvm-lto.cpp +++ llvm/trunk/tools/llvm-lto/llvm-lto.cpp @@ -156,6 +156,9 @@ static cl::opt ThinLTOCacheDir("thinlto-cache-dir", cl::desc("Enable ThinLTO caching.")); +static cl::opt + ThinLTOCachePruningInterval("thinlto-cache-pruning-interval", cl::desc("Set ThinLTO cache pruning interval.")); + static cl::opt ThinLTOSaveTempsPrefix( "thinlto-save-temps", cl::desc("Save ThinLTO temp files using filenames created by adding " @@ -470,6 +473,7 @@ ThinGenerator.setCodePICModel(getRelocModel()); ThinGenerator.setTargetOptions(Options); ThinGenerator.setCacheDir(ThinLTOCacheDir); + ThinGenerator.setCachePruningInterval(ThinLTOCachePruningInterval); ThinGenerator.setFreestanding(EnableFreestanding); // Add all the exported symbols to the table of symbols to preserve.