From e3b557809604d036af6e00c60f012c2025b59a5e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 11 Feb 2023 13:38:04 +0100 Subject: Vendor import of llvm-project main llvmorg-16-init-18548-gb0daacf58f41, the last commit before the upstream release/17.x branch was created. --- llvm/lib/Support/Caching.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'llvm/lib/Support/Caching.cpp') diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp index d6902f660e39..f20f08a865c7 100644 --- a/llvm/lib/Support/Caching.cpp +++ b/llvm/lib/Support/Caching.cpp @@ -26,9 +26,9 @@ using namespace llvm; -Expected llvm::localCache(Twine CacheNameRef, - Twine TempFilePrefixRef, - Twine CacheDirectoryPathRef, +Expected llvm::localCache(const Twine &CacheNameRef, + const Twine &TempFilePrefixRef, + const Twine &CacheDirectoryPathRef, AddBufferFn AddBuffer) { // Create local copies which are safely captured-by-copy in lambdas @@ -37,7 +37,8 @@ Expected llvm::localCache(Twine CacheNameRef, TempFilePrefixRef.toVector(TempFilePrefix); CacheDirectoryPathRef.toVector(CacheDirectoryPath); - return [=](unsigned Task, StringRef Key) -> Expected { + return [=](unsigned Task, StringRef Key, + const Twine &ModuleName) -> Expected { // This choice of file name allows the cache to be pruned (see pruneCache() // in include/llvm/Support/CachePruning.h). SmallString<64> EntryPath; @@ -54,7 +55,7 @@ Expected llvm::localCache(Twine CacheNameRef, /*RequiresNullTerminator=*/false); sys::fs::closeFile(*FDOrErr); if (MBOrErr) { - AddBuffer(Task, std::move(*MBOrErr)); + AddBuffer(Task, ModuleName, std::move(*MBOrErr)); return AddStreamFn(); } EC = MBOrErr.getError(); @@ -77,14 +78,15 @@ Expected llvm::localCache(Twine CacheNameRef, struct CacheStream : CachedFileStream { AddBufferFn AddBuffer; sys::fs::TempFile TempFile; + std::string ModuleName; unsigned Task; CacheStream(std::unique_ptr OS, AddBufferFn AddBuffer, sys::fs::TempFile TempFile, std::string EntryPath, - unsigned Task) + std::string ModuleName, unsigned Task) : CachedFileStream(std::move(OS), std::move(EntryPath)), AddBuffer(std::move(AddBuffer)), TempFile(std::move(TempFile)), - Task(Task) {} + ModuleName(ModuleName), Task(Task) {} ~CacheStream() { // TODO: Manually commit rather than using non-trivial destructor, @@ -133,11 +135,12 @@ Expected llvm::localCache(Twine CacheNameRef, TempFile.TmpName + " to " + ObjectPathName + ": " + toString(std::move(E)) + "\n"); - AddBuffer(Task, std::move(*MBOrErr)); + AddBuffer(Task, ModuleName, std::move(*MBOrErr)); } }; - return [=](size_t Task) -> Expected> { + return [=](size_t Task, const Twine &ModuleName) + -> Expected> { // Create the cache directory if not already done. Doing this lazily // ensures the filesystem isn't mutated until the cache is. if (std::error_code EC = sys::fs::create_directories( @@ -158,7 +161,8 @@ Expected llvm::localCache(Twine CacheNameRef, // This CacheStream will move the temporary file into the cache when done. return std::make_unique( std::make_unique(Temp->FD, /* ShouldClose */ false), - AddBuffer, std::move(*Temp), std::string(EntryPath.str()), Task); + AddBuffer, std::move(*Temp), std::string(EntryPath.str()), + ModuleName.str(), Task); }; }; } -- cgit v1.2.3