[llvm] r296726 - LTO: When creating a local cache, create the cache directory if it does not already exist.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 1 18:02:39 PST 2017
Author: pcc
Date: Wed Mar 1 20:02:38 2017
New Revision: 296726
URL: http://llvm.org/viewvc/llvm-project?rev=296726&view=rev
Log:
LTO: When creating a local cache, create the cache directory if it does not already exist.
Differential Revision: https://reviews.llvm.org/D30519
Modified:
llvm/trunk/include/llvm/LTO/Caching.h
llvm/trunk/lib/LTO/Caching.cpp
llvm/trunk/test/ThinLTO/X86/cache-config.ll
llvm/trunk/test/ThinLTO/X86/cache.ll
llvm/trunk/test/ThinLTO/X86/empty_module_with_cache.ll
llvm/trunk/test/tools/gold/X86/cache.ll
llvm/trunk/tools/gold/gold-plugin.cpp
llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp
Modified: llvm/trunk/include/llvm/LTO/Caching.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/Caching.h?rev=296726&r1=296725&r2=296726&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/Caching.h (original)
+++ llvm/trunk/include/llvm/LTO/Caching.h Wed Mar 1 20:02:38 2017
@@ -28,8 +28,10 @@ namespace lto {
typedef std::function<void(unsigned Task, StringRef Path)> AddFileFn;
/// Create a local file system cache which uses the given cache directory and
-/// file callback.
-NativeObjectCache localCache(StringRef CacheDirectoryPath, AddFileFn AddFile);
+/// file callback. This function also creates the cache directory if it does not
+/// already exist.
+Expected<NativeObjectCache> localCache(StringRef CacheDirectoryPath,
+ AddFileFn AddFile);
} // namespace lto
} // namespace llvm
Modified: llvm/trunk/lib/LTO/Caching.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/Caching.cpp?rev=296726&r1=296725&r2=296726&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/Caching.cpp (original)
+++ llvm/trunk/lib/LTO/Caching.cpp Wed Mar 1 20:02:38 2017
@@ -46,8 +46,11 @@ static void commitEntry(StringRef TempFi
}
}
-NativeObjectCache lto::localCache(StringRef CacheDirectoryPath,
- AddFileFn AddFile) {
+Expected<NativeObjectCache> lto::localCache(StringRef CacheDirectoryPath,
+ AddFileFn AddFile) {
+ if (std::error_code EC = sys::fs::create_directories(CacheDirectoryPath))
+ return errorCodeToError(EC);
+
return [=](unsigned Task, StringRef Key) -> AddStreamFn {
// First, see if we have a cache hit.
SmallString<64> EntryPath;
Modified: llvm/trunk/test/ThinLTO/X86/cache-config.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/cache-config.ll?rev=296726&r1=296725&r2=296726&view=diff
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/cache-config.ll (original)
+++ llvm/trunk/test/ThinLTO/X86/cache-config.ll Wed Mar 1 20:02:38 2017
@@ -1,4 +1,4 @@
-; RUN: rm -rf %t.cache && mkdir %t.cache
+; RUN: rm -rf %t.cache
; RUN: opt -module-hash -module-summary %s -o %t.bc
; RUN: llvm-lto2 -o %t.o %t.bc -cache-dir %t.cache -r=%t.bc,globalfunc,plx
Modified: llvm/trunk/test/ThinLTO/X86/cache.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/cache.ll?rev=296726&r1=296725&r2=296726&view=diff
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/cache.ll (original)
+++ llvm/trunk/test/ThinLTO/X86/cache.ll Wed Mar 1 20:02:38 2017
@@ -10,7 +10,7 @@
; RUN: ls %t.cache | count 1
; Verify that enabling caching is ignoring module without hash with llvm-lto2
-; RUN: rm -Rf %t.cache && mkdir %t.cache
+; RUN: rm -Rf %t.cache
; RUN: llvm-lto2 -o %t.o %t2.bc %t.bc -cache-dir %t.cache \
; RUN: -r=%t2.bc,_main,plx \
; RUN: -r=%t2.bc,_globalfunc,lx \
@@ -30,7 +30,7 @@
; RUN: ls %t.cache | count 3
; Verify that enabling caching is working with llvm-lto2
-; RUN: rm -Rf %t.cache && mkdir %t.cache
+; RUN: rm -Rf %t.cache
; RUN: llvm-lto2 -o %t.o %t2.bc %t.bc -cache-dir %t.cache \
; RUN: -r=%t2.bc,_main,plx \
; RUN: -r=%t2.bc,_globalfunc,lx \
Modified: llvm/trunk/test/ThinLTO/X86/empty_module_with_cache.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/empty_module_with_cache.ll?rev=296726&r1=296725&r2=296726&view=diff
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/empty_module_with_cache.ll (original)
+++ llvm/trunk/test/ThinLTO/X86/empty_module_with_cache.ll Wed Mar 1 20:02:38 2017
@@ -8,7 +8,7 @@
; RUN: ls %t.cache | count 3
; Verify that enabling caching is working with llvm-lto2
-; RUN: rm -Rf %t.cache && mkdir %t.cache
+; RUN: rm -Rf %t.cache
; RUN: llvm-lto2 -o %t.o %t2.bc %t.bc -cache-dir %t.cache \
; RUN: -r=%t2.bc,_main,plx
; RUN: ls %t.cache | count 2
@@ -25,7 +25,7 @@
; RUN: ls %t.cache | count 1
; Verify that caching is disabled for module without hash, with llvm-lto2
-; RUN: rm -Rf %t.cache && mkdir %t.cache
+; RUN: rm -Rf %t.cache
; RUN: llvm-lto2 -o %t.o %t2.bc %t.bc -cache-dir %t.cache \
; RUN: -r=%t2.bc,_main,plx
; RUN: ls %t.cache | count 0
Modified: llvm/trunk/test/tools/gold/X86/cache.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/cache.ll?rev=296726&r1=296725&r2=296726&view=diff
==============================================================================
--- llvm/trunk/test/tools/gold/X86/cache.ll (original)
+++ llvm/trunk/test/tools/gold/X86/cache.ll Wed Mar 1 20:02:38 2017
@@ -2,7 +2,7 @@
; RUN: opt -module-summary %s -o %t.o
; RUN: opt -module-summary %p/Inputs/cache.ll -o %t2.o
-; RUN: rm -Rf %t.cache && mkdir %t.cache
+; RUN: rm -Rf %t.cache
; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
; RUN: --plugin-opt=thinlto \
; RUN: --plugin-opt=cache-dir=%t.cache \
@@ -16,7 +16,7 @@
; RUN: opt -module-hash -module-summary %s -o %t.o
; RUN: opt -module-hash -module-summary %p/Inputs/cache.ll -o %t2.o
-; RUN: rm -Rf %t.cache && mkdir %t.cache
+; RUN: rm -Rf %t.cache
; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
; RUN: --plugin-opt=thinlto \
; RUN: --plugin-opt=cache-dir=%t.cache \
Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=296726&r1=296725&r2=296726&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Wed Mar 1 20:02:38 2017
@@ -835,7 +835,7 @@ static ld_plugin_status allSymbolsReadHo
NativeObjectCache Cache;
if (!options::cache_dir.empty())
- Cache = localCache(options::cache_dir, AddFile);
+ Cache = check(localCache(options::cache_dir, AddFile));
check(Lto->run(AddStream, Cache));
Modified: llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp?rev=296726&r1=296725&r2=296726&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp (original)
+++ llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp Wed Mar 1 20:02:38 2017
@@ -284,7 +284,7 @@ int main(int argc, char **argv) {
NativeObjectCache Cache;
if (!CacheDir.empty())
- Cache = localCache(CacheDir, AddFile);
+ Cache = check(localCache(CacheDir, AddFile), "failed to create cache");
check(Lto.run(AddStream, Cache), "LTO::run failed");
}
More information about the llvm-commits
mailing list