summaryrefslogtreecommitdiffstats
path: root/llvm/lib/LTO/Caching.cpp
diff options
context:
space:
mode:
authorAndrew Ng <anng.sw@gmail.com>2018-07-04 14:17:10 +0000
committerAndrew Ng <anng.sw@gmail.com>2018-07-04 14:17:10 +0000
commit089303d8ffeda0426de8c134fc40f0c2bd772abe (patch)
tree52cea07ddf68eb151714396f2847111f9341e1e5 /llvm/lib/LTO/Caching.cpp
parent67676e9c9913e30690f8f01eba1c9bb2b354c860 (diff)
downloadbcm5719-llvm-089303d8ffeda0426de8c134fc40f0c2bd772abe.tar.gz
bcm5719-llvm-089303d8ffeda0426de8c134fc40f0c2bd772abe.zip
[ThinLTO] Update ThinLTO cache file atimes when on Windows
ThinLTO cache file access times are used for expiration based pruning and since Vista, file access times are not updated by Windows by default: https://blogs.technet.microsoft.com/filecab/2006/11/07/disabling-last-access-time-in-windows-vista-to-improve-ntfs-performance This means on Windows, cache files are currently being pruned from creation time. This change manually updates cache files that are accessed by ThinLTO, when on Windows. Patch by Owen Reynolds. Differential Revision: https://reviews.llvm.org/D47266 llvm-svn: 336276
Diffstat (limited to 'llvm/lib/LTO/Caching.cpp')
-rw-r--r--llvm/lib/LTO/Caching.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/llvm/lib/LTO/Caching.cpp b/llvm/lib/LTO/Caching.cpp
index bd6190d9961..089e77e742e 100644
--- a/llvm/lib/LTO/Caching.cpp
+++ b/llvm/lib/LTO/Caching.cpp
@@ -19,6 +19,12 @@
#include "llvm/Support/Process.h"
#include "llvm/Support/raw_ostream.h"
+#if !defined(_MSC_VER) && !defined(__MINGW32__)
+#include <unistd.h>
+#else
+#include <io.h>
+#endif
+
using namespace llvm;
using namespace llvm::lto;
@@ -33,11 +39,21 @@ Expected<NativeObjectCache> lto::localCache(StringRef CacheDirectoryPath,
SmallString<64> EntryPath;
sys::path::append(EntryPath, CacheDirectoryPath, "llvmcache-" + Key);
// First, see if we have a cache hit.
- ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
- MemoryBuffer::getFile(EntryPath);
- if (MBOrErr) {
- AddBuffer(Task, std::move(*MBOrErr));
- return AddStreamFn();
+ int FD;
+ SmallString<64> ResultPath;
+ std::error_code EC = sys::fs::openFileForRead(
+ Twine(EntryPath), FD, sys::fs::OF_UpdateAtime, &ResultPath);
+ if (!EC) {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
+ MemoryBuffer::getOpenFile(FD, EntryPath,
+ /*FileSize*/ -1,
+ /*RequiresNullTerminator*/ false);
+ close(FD);
+ if (MBOrErr) {
+ AddBuffer(Task, std::move(*MBOrErr));
+ return AddStreamFn();
+ }
+ EC = MBOrErr.getError();
}
// On Windows we can fail to open a cache file with a permission denied
@@ -46,10 +62,9 @@ Expected<NativeObjectCache> lto::localCache(StringRef CacheDirectoryPath,
// process has opened the file without the sharing permissions we need.
// Since the file is probably being deleted we handle it in the same way as
// if the file did not exist at all.
- if (MBOrErr.getError() != errc::no_such_file_or_directory &&
- MBOrErr.getError() != errc::permission_denied)
+ if (EC != errc::no_such_file_or_directory && EC != errc::permission_denied)
report_fatal_error(Twine("Failed to open cache file ") + EntryPath +
- ": " + MBOrErr.getError().message() + "\n");
+ ": " + EC.message() + "\n");
// This native object stream is responsible for commiting the resulting
// file to the cache and calling AddBuffer to add it to the link.
OpenPOWER on IntegriCloud