aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Support/CachePruning.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/CachePruning.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Support/CachePruning.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/CachePruning.cpp b/contrib/llvm-project/llvm/lib/Support/CachePruning.cpp
index 5c5759ffbaca..a56d8356d838 100644
--- a/contrib/llvm-project/llvm/lib/Support/CachePruning.cpp
+++ b/contrib/llvm-project/llvm/lib/Support/CachePruning.cpp
@@ -17,6 +17,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#define DEBUG_TYPE "cache-pruning"
@@ -141,7 +142,8 @@ llvm::parseCachePruningPolicy(StringRef PolicyStr) {
}
/// Prune the cache of files that haven't been accessed in a long time.
-bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy) {
+bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy,
+ const std::vector<std::unique_ptr<MemoryBuffer>> &Files) {
using namespace std::chrono;
if (Path.empty())
@@ -258,6 +260,17 @@ bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy) {
++FileInfo;
};
+ // files.size() is greater the number of inputs by one. However, a timestamp
+ // file is created and stored in the cache directory if --thinlto-cache-policy
+ // option is used. Therefore, files.size() is used as ActualNums.
+ const size_t ActualNums = Files.size();
+ if (Policy.MaxSizeFiles && ActualNums > Policy.MaxSizeFiles)
+ WithColor::warning()
+ << "ThinLTO cache pruning happens since the number of created files ("
+ << ActualNums << ") exceeds the maximum number of files ("
+ << Policy.MaxSizeFiles
+ << "); consider adjusting --thinlto-cache-policy\n";
+
// Prune for number of files.
if (Policy.MaxSizeFiles)
while (NumFiles > Policy.MaxSizeFiles)
@@ -285,6 +298,19 @@ bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy) {
<< Policy.MaxSizePercentageOfAvailableSpace << "%, "
<< Policy.MaxSizeBytes << " bytes\n");
+ size_t ActualSizes = 0;
+ for (const auto &File : Files)
+ if (File)
+ ActualSizes += File->getBufferSize();
+
+ if (ActualSizes > TotalSizeTarget)
+ WithColor::warning()
+ << "ThinLTO cache pruning happens since the total size of the cache "
+ "files consumed by the current link job ("
+ << ActualSizes << " bytes) exceeds maximum cache size ("
+ << TotalSizeTarget
+ << " bytes); consider adjusting --thinlto-cache-policy\n";
+
// Remove the oldest accessed files first, till we get below the threshold.
while (TotalSize > TotalSizeTarget && FileInfo != FileInfos.end())
RemoveCacheFile();