llvm.org GIT mirror llvm / cc5ba44
LTO: When creating a local cache, create the cache directory if it does not already exist. Differential Revision: https://reviews.llvm.org/D30519 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296726 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 2 years ago
8 changed file(s) with 18 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
2727 typedef std::function AddFileFn;
2828
2929 /// Create a local file system cache which uses the given cache directory and
30 /// file callback.
31 NativeObjectCache localCache(StringRef CacheDirectoryPath, AddFileFn AddFile);
30 /// file callback. This function also creates the cache directory if it does not
31 /// already exist.
32 Expected localCache(StringRef CacheDirectoryPath,
33 AddFileFn AddFile);
3234
3335 } // namespace lto
3436 } // namespace llvm
4545 }
4646 }
4747
48 NativeObjectCache lto::localCache(StringRef CacheDirectoryPath,
49 AddFileFn AddFile) {
48 Expected lto::localCache(StringRef CacheDirectoryPath,
49 AddFileFn AddFile) {
50 if (std::error_code EC = sys::fs::create_directories(CacheDirectoryPath))
51 return errorCodeToError(EC);
52
5053 return [=](unsigned Task, StringRef Key) -> AddStreamFn {
5154 // First, see if we have a cache hit.
5255 SmallString<64> EntryPath;
None ; RUN: rm -rf %t.cache && mkdir %t.cache
0 ; RUN: rm -rf %t.cache
11 ; RUN: opt -module-hash -module-summary %s -o %t.bc
22
33 ; RUN: llvm-lto2 -o %t.o %t.bc -cache-dir %t.cache -r=%t.bc,globalfunc,plx
99 ; RUN: ls %t.cache | count 1
1010
1111 ; Verify that enabling caching is ignoring module without hash with llvm-lto2
12 ; RUN: rm -Rf %t.cache && mkdir %t.cache
12 ; RUN: rm -Rf %t.cache
1313 ; RUN: llvm-lto2 -o %t.o %t2.bc %t.bc -cache-dir %t.cache \
1414 ; RUN: -r=%t2.bc,_main,plx \
1515 ; RUN: -r=%t2.bc,_globalfunc,lx \
2929 ; RUN: ls %t.cache | count 3
3030
3131 ; Verify that enabling caching is working with llvm-lto2
32 ; RUN: rm -Rf %t.cache && mkdir %t.cache
32 ; RUN: rm -Rf %t.cache
3333 ; RUN: llvm-lto2 -o %t.o %t2.bc %t.bc -cache-dir %t.cache \
3434 ; RUN: -r=%t2.bc,_main,plx \
3535 ; RUN: -r=%t2.bc,_globalfunc,lx \
77 ; RUN: ls %t.cache | count 3
88
99 ; Verify that enabling caching is working with llvm-lto2
10 ; RUN: rm -Rf %t.cache && mkdir %t.cache
10 ; RUN: rm -Rf %t.cache
1111 ; RUN: llvm-lto2 -o %t.o %t2.bc %t.bc -cache-dir %t.cache \
1212 ; RUN: -r=%t2.bc,_main,plx
1313 ; RUN: ls %t.cache | count 2
2424 ; RUN: ls %t.cache | count 1
2525
2626 ; Verify that caching is disabled for module without hash, with llvm-lto2
27 ; RUN: rm -Rf %t.cache && mkdir %t.cache
27 ; RUN: rm -Rf %t.cache
2828 ; RUN: llvm-lto2 -o %t.o %t2.bc %t.bc -cache-dir %t.cache \
2929 ; RUN: -r=%t2.bc,_main,plx
3030 ; RUN: ls %t.cache | count 0
11 ; RUN: opt -module-summary %s -o %t.o
22 ; RUN: opt -module-summary %p/Inputs/cache.ll -o %t2.o
33
4 ; RUN: rm -Rf %t.cache && mkdir %t.cache
4 ; RUN: rm -Rf %t.cache
55 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
66 ; RUN: --plugin-opt=thinlto \
77 ; RUN: --plugin-opt=cache-dir=%t.cache \
1515 ; RUN: opt -module-hash -module-summary %s -o %t.o
1616 ; RUN: opt -module-hash -module-summary %p/Inputs/cache.ll -o %t2.o
1717
18 ; RUN: rm -Rf %t.cache && mkdir %t.cache
18 ; RUN: rm -Rf %t.cache
1919 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
2020 ; RUN: --plugin-opt=thinlto \
2121 ; RUN: --plugin-opt=cache-dir=%t.cache \
834834
835835 NativeObjectCache Cache;
836836 if (!options::cache_dir.empty())
837 Cache = localCache(options::cache_dir, AddFile);
837 Cache = check(localCache(options::cache_dir, AddFile));
838838
839839 check(Lto->run(AddStream, Cache));
840840
283283
284284 NativeObjectCache Cache;
285285 if (!CacheDir.empty())
286 Cache = localCache(CacheDir, AddFile);
286 Cache = check(localCache(CacheDir, AddFile), "failed to create cache");
287287
288288 check(Lto.run(AddStream, Cache), "LTO::run failed");
289289 }