Skip to content

Commit cfd6add

Browse files
committed
[CAS] Adopt UnifiedOnDiskCache for the on-disk CAS for clang
Notable changes: * Having a separate flag for on-disk path for `ActionCache` becomes redundant (only one on-disk path for CAS/cache configuration is sufficient), so `-faction-cache-path` and related flags of testing tools are removed. * To accomodate testing, other testing tools adopt `UnifiedOnDiskCache` as well. * `llvm-cas` gets new functionality to accomodate testing: * `-import`: import objects from another CAS * `-put-cache-key`: set a value for a cache key Note that clang opens a `UnifiedOnDiskCache` without imposing any size limit, it is assumed that a higher level service, e.g. the build system or the clang daemon, is going to be responsible for managing growth of the CAS databases during a build.
1 parent 14ee8b9 commit cfd6add

File tree

55 files changed

+390
-248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+390
-248
lines changed

clang/include/clang/Basic/DiagnosticCASKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def err_builtin_cas_cannot_be_initialized : Error<
1212
"CAS cannot be initialized from '%0' on disk (check -fcas-path)">,
1313
DefaultFatal;
1414
def err_builtin_actioncache_cannot_be_initialized : Error<
15-
"ActionCache cannot be initialized from '%0' on disk (check -faction-cache-path)">,
15+
"ActionCache cannot be initialized from '%0' on disk (check -fcas-path)">,
1616
DefaultFatal;
1717
def err_cas_cannot_parse_root_id : Error<
1818
"CAS cannot parse root-id '%0' specified by -fcas-fs">, DefaultFatal;

clang/include/clang/CAS/CASOptions.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ class CASConfiguration {
5454
/// - "auto" is an alias for an automatically chosen location in the user's
5555
/// system cache.
5656
std::string CASPath;
57-
std::string CachePath;
5857

5958
friend bool operator==(const CASConfiguration &LHS,
6059
const CASConfiguration &RHS) {
61-
return LHS.CASPath == RHS.CASPath && LHS.CachePath == RHS.CachePath;
60+
return LHS.CASPath == RHS.CASPath;
6261
}
6362
friend bool operator!=(const CASConfiguration &LHS,
6463
const CASConfiguration &RHS) {

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6591,12 +6591,6 @@ def fcas_path : Separate<["-"], "fcas-path">,
65916591
" '-fcas-path=auto' chooses a path in the user's system cache.">,
65926592
MarshallingInfoString<CASOpts<"CASPath">>;
65936593

6594-
def faction_cache_path : Separate<["-"], "faction-cache-path">,
6595-
Group<f_Group>, MetaVarName<"<dir>|auto">,
6596-
HelpText<"Path to a persistent on-disk backing store for the builtin Cache."
6597-
" '-faction-cache-path=auto' chooses a path in the user's system cache.">,
6598-
MarshallingInfoString<CASOpts<"CachePath">>;
6599-
66006594
// FIXME: Add to driver once it's supported by -fdepscan.
66016595
def fcas_fs : Separate<["-"], "fcas-fs">,
66026596
Group<f_Group>, MetaVarName<"<tree>">,

clang/lib/CAS/CASOptions.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ using namespace clang;
1717
using namespace llvm::cas;
1818

1919
static std::shared_ptr<llvm::cas::ObjectStore>
20-
createObjectStore(const CASConfiguration &Config, DiagnosticsEngine &Diags) {
20+
createObjectStoreWithoutPath(const CASConfiguration &Config,
21+
DiagnosticsEngine &Diags) {
2122
if (Config.CASPath.empty())
2223
return llvm::cas::createInMemoryCAS();
2324

25+
assert(Config.CASPath == "auto");
2426
// Compute the path.
2527
SmallString<128> Storage;
26-
StringRef Path = Config.CASPath;
27-
if (Path == "auto") {
28-
llvm::cas::getDefaultOnDiskCASPath(Storage);
29-
Path = Storage;
30-
}
28+
llvm::cas::getDefaultOnDiskCASPath(Storage);
29+
StringRef Path = Storage;
3130

3231
// FIXME: Pass on the actual error from the CAS.
3332
if (auto MaybeCAS =
@@ -73,20 +72,17 @@ void CASOptions::freezeConfig(DiagnosticsEngine &Diags) {
7372
CurrentConfig.CASPath =
7473
Cache.CAS->getContext().getHashSchemaIdentifier().str();
7574
}
76-
if (Cache.AC)
77-
CurrentConfig.CachePath = "";
7875
}
7976

8077
static std::shared_ptr<llvm::cas::ActionCache>
81-
createCache(ObjectStore &CAS, const CASConfiguration &Config,
82-
DiagnosticsEngine &Diags) {
83-
if (Config.CachePath.empty())
78+
createCacheWithoutPath(const CASConfiguration &Config,
79+
DiagnosticsEngine &Diags) {
80+
if (Config.CASPath.empty())
8481
return llvm::cas::createInMemoryActionCache();
8582

83+
assert(Config.CASPath == "auto");
8684
// Compute the path.
87-
std::string Path = Config.CachePath;
88-
if (Path == "auto")
89-
Path = getDefaultOnDiskActionCachePath();
85+
std::string Path = getDefaultOnDiskActionCachePath();
9086

9187
// FIXME: Pass on the actual error from the CAS.
9288
if (auto MaybeCache =
@@ -119,7 +115,6 @@ void CASOptions::ensurePersistentCAS() {
119115
llvm_unreachable("Cannot ensure persistent CAS if it's unknown / frozen");
120116
case InMemoryCAS:
121117
CASPath = "auto";
122-
CachePath = "auto";
123118
break;
124119
case OnDiskCAS:
125120
break;
@@ -132,6 +127,17 @@ void CASOptions::initCache(DiagnosticsEngine &Diags) const {
132127
return;
133128

134129
Cache.Config = CurrentConfig;
135-
Cache.CAS = createObjectStore(Cache.Config, Diags);
136-
Cache.AC = createCache(*Cache.CAS, Cache.Config, Diags);
130+
StringRef CASPath = Cache.Config.CASPath;
131+
if (!CASPath.empty() && CASPath != "auto") {
132+
std::pair<std::unique_ptr<ObjectStore>, std::unique_ptr<ActionCache>> DBs;
133+
if (llvm::Error E =
134+
createOnDiskUnifiedCASDatabases(CASPath).moveInto(DBs)) {
135+
Diags.Report(diag::err_builtin_cas_cannot_be_initialized) << CASPath;
136+
return;
137+
}
138+
std::tie(Cache.CAS, Cache.AC) = std::move(DBs);
139+
} else {
140+
Cache.CAS = createObjectStoreWithoutPath(Cache.Config, Diags);
141+
Cache.AC = createCacheWithoutPath(Cache.Config, Diags);
142+
}
137143
}

clang/test/CAS/cached-diagnostics.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
// RUN: %clang_cc1 -triple x86_64-apple-macos12 -fsyntax-only %t/src/main.c -I %t/src/inc -Wunknown-pragmas 2> %t/regular-diags1.txt
66

77
// RUN: %clang -cc1depscan -fdepscan=inline -fdepscan-include-tree -fdepscan-prefix-map=%t/src=/^src -o %t/t1.rsp -cc1-args \
8-
// RUN: -cc1 -triple x86_64-apple-macos12 -fcas-path %t/cas -faction-cache-path %t/cache \
8+
// RUN: -cc1 -triple x86_64-apple-macos12 -fcas-path %t/cas \
99
// RUN: -emit-obj %t/src/main.c -o %t/out/output.o -I %t/src/inc -Wunknown-pragmas
1010

1111
// Compare diagnostics after a miss.
1212
// RUN: %clang @%t/t1.rsp 2> %t/diags1.txt
1313
// RUN: diff -u %t/regular-diags1.txt %t/diags1.txt
1414

1515
// RUN: %clang -cc1depscan -fdepscan=inline -fdepscan-include-tree -o %t/t1.noprefix.rsp -cc1-args \
16-
// RUN: -cc1 -triple x86_64-apple-macos12 -fcas-path %t/cas -faction-cache-path %t/cache \
16+
// RUN: -cc1 -triple x86_64-apple-macos12 -fcas-path %t/cas \
1717
// RUN: -emit-obj %t/src/main.c -o %t/out/output.o -I %t/src/inc -Wunknown-pragmas
1818

1919
// Compare diagnostics without prefix mappings.
@@ -42,7 +42,7 @@
4242
// RUN: %clang_cc1 -triple x86_64-apple-macos12 -fsyntax-only %t/src2/main.c -I %t/src2/inc -Wunknown-pragmas 2> %t/regular-diags2.txt
4343

4444
// RUN: %clang -cc1depscan -fdepscan=inline -fdepscan-include-tree -fdepscan-prefix-map=%t/src2=/^src -o %t/t2.rsp -cc1-args \
45-
// RUN: -cc1 -triple x86_64-apple-macos12 -fcas-path %t/cas -faction-cache-path %t/cache \
45+
// RUN: -cc1 -triple x86_64-apple-macos12 -fcas-path %t/cas \
4646
// RUN: -emit-obj %t/src2/main.c -o %t/out2/output.o -I %t/src2/inc -Wunknown-pragmas
4747
// RUN: %clang @%t/t2.rsp -Rcompile-job-cache 2> %t/diags-hit2.txt
4848

clang/test/CAS/daemon-cwd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
// RUN: -fdepscan-prefix-map=%t=/^build \
1212
// RUN: -fdepscan-prefix-map-toolchain=/^toolchain \
1313
// RUN: -fdepscan-daemon=%{clang-daemon-dir}/%basename_t \
14-
// RUN: -Xclang -fcas-path -Xclang %t/cas -Xclang -faction-cache-path -Xclang %t/cache \
14+
// RUN: -Xclang -fcas-path -Xclang %t/cas \
1515
// RUN: -MD -MF %t/test.d -Iinclude \
1616
// RUN: -fsyntax-only -x c %s >> %t/cmd.sh
1717
// RUN: chmod +x %t/cmd.sh
1818

1919
// RUN: %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t \
20-
// RUN: -cas-args -fcas-path %t/cas -faction-cache-path %t/cache -- %t/cmd.sh
20+
// RUN: -cas-args -fcas-path %t/cas -- %t/cmd.sh
2121
// RUN: (cd %t && %clang -target x86_64-apple-macos11 -MD -MF %t/test2.d \
2222
// RUN: -Iinclude -fsyntax-only -x c %s)
2323
// RUN: diff %t/test.d %t/test2.d

clang/test/CAS/depscan-dependency-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// RUN: split-file %s %t
33

44
// RUN: %clang -cc1depscan -fdepscan=inline -fdepscan-include-tree -o %t/t.rsp -cc1-args \
5-
// RUN: -cc1 -fcas-path %t/cas -faction-cache-path %t/cache -triple x86_64-apple-macos11 %t/main.c -emit-obj -o %t/output.o -isystem %t/sys \
5+
// RUN: -cc1 -fcas-path %t/cas -triple x86_64-apple-macos11 %t/main.c -emit-obj -o %t/output.o -isystem %t/sys \
66
// RUN: -MT deps -dependency-file %t/t.d
77
// RUN: FileCheck %s -input-file=%t/t.d -check-prefix=NOSYS
88
// RUN: FileCheck %s -input-file=%t/t.d -check-prefix=COMMON
99

1010
// Including system headers.
1111
// RUN: %clang -cc1depscan -fdepscan=inline -fdepscan-include-tree -o %t/t.rsp -cc1-args \
12-
// RUN: -cc1 -fcas-path %t/cas -faction-cache-path %t/cache -triple x86_64-apple-macos11 %t/main.c -emit-obj -o %t/output.o -isystem %t/sys \
12+
// RUN: -cc1 -fcas-path %t/cas -triple x86_64-apple-macos11 %t/main.c -emit-obj -o %t/output.o -isystem %t/sys \
1313
// RUN: -MT deps -sys-header-deps -dependency-file %t/t-sys.d
1414
// RUN: FileCheck %s -input-file=%t/t-sys.d -check-prefix=WITHSYS -check-prefix=COMMON
1515

clang/test/CAS/depscan-include-tree-daemon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
// RUN: split-file %s %t
44

55
// RUN: %clang -cc1depscan -o %t/inline.rsp -fdepscan=inline -fdepscan-include-tree -cc1-args -cc1 -triple x86_64-apple-macos11.0 \
6-
// RUN: -fsyntax-only %t/t.c -I %t/includes -isysroot %S/Inputs/SDK -fcas-path %t/cas -faction-cache-path %t/cache -DSOME_MACRO -dependency-file %t/inline.d -MT deps
6+
// RUN: -fsyntax-only %t/t.c -I %t/includes -isysroot %S/Inputs/SDK -fcas-path %t/cas -DSOME_MACRO -dependency-file %t/inline.d -MT deps
77

8-
// RUN: %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t -cas-args -fdepscan-include-tree -fcas-path %t/cas -faction-cache-path %t/cache -- \
8+
// RUN: %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t -cas-args -fdepscan-include-tree -fcas-path %t/cas -- \
99
// RUN: %clang -cc1depscan -o %t/daemon.rsp -fdepscan=daemon -fdepscan-daemon=%{clang-daemon-dir}/%basename_t -fdepscan-include-tree \
1010
// RUN: -cc1-args -cc1 -triple x86_64-apple-macos11.0 \
1111
// RUN: -fsyntax-only %t/t.c -I %t/includes -isysroot %S/Inputs/SDK -fcas-path %t/cas -DSOME_MACRO -dependency-file %t/daemon.d -MT deps

clang/test/CAS/depscan-prefix-map.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// RUN: -resource-dir %S/Inputs/toolchain_dir/usr/lib/clang/1000 \
1616
// RUN: -internal-isystem %S/Inputs/toolchain_dir/usr/lib/clang/1000/include \
1717
// RUN: -working-directory %t.d \
18-
// RUN: -fcas-path %t.d/cas -faction-cache-path %t.d/cache \
18+
// RUN: -fcas-path %t.d/cas \
1919
// RUN: | FileCheck %s -DPREFIX=%t.d
2020
// RUN: %clang -cc1depscan -dump-depscan-tree=%t.root -fdepscan=inline \
2121
// RUN: -fdepscan-prefix-map=%S=/^source \
@@ -28,10 +28,10 @@
2828
// RUN: -resource-dir %S/Inputs/toolchain_dir/lib/clang/1000 \
2929
// RUN: -internal-isystem %S/Inputs/toolchain_dir/lib/clang/1000/include \
3030
// RUN: -working-directory %t.d \
31-
// RUN: -fcas-path %t.d/cas -faction-cache-path %t.d/cache \
31+
// RUN: -fcas-path %t.d/cas \
3232
// RUN: | FileCheck %s -DPREFIX=%t.d
3333
// RUN: %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t \
34-
// RUN: -cas-args -fcas-path %t.d/cas -faction-cache-path %t.d/cache -- \
34+
// RUN: -cas-args -fcas-path %t.d/cas -- \
3535
// RUN: %clang -cc1depscan -dump-depscan-tree=%t.root -fdepscan=daemon \
3636
// RUN: -fdepscan-daemon=%{clang-daemon-dir}/%basename_t \
3737
// RUN: -fdepscan-prefix-map=%S=/^source \
@@ -44,7 +44,7 @@
4444
// RUN: -resource-dir %S/Inputs/toolchain_dir/usr/lib/clang/1000 \
4545
// RUN: -internal-isystem %S/Inputs/toolchain_dir/usr/lib/clang/1000/include \
4646
// RUN: -working-directory %t.d \
47-
// RUN: -fcas-path %t.d/cas -faction-cache-path %t.d/cache \
47+
// RUN: -fcas-path %t.d/cas \
4848
// RUN: | FileCheck %s -DPREFIX=%t.d
4949
//
5050
// CHECK: "-fcas-path" "[[PREFIX]]/cas"
@@ -65,32 +65,32 @@
6565
// CHECK-ROOT-NEXT: file {{.*}} /^toolchain/usr/lib/clang/1000/include/stdarg.h{{$}}
6666

6767
// RUN: not %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t \
68-
// RUN: -cas-args -fcas-path %t.d/cas -faction-cache-path %t.d/cache -- \
68+
// RUN: -cas-args -fcas-path %t.d/cas -- \
6969
// RUN: %clang -cc1depscan -dump-depscan-tree=%t.root -fdepscan=daemon \
7070
// RUN: -fdepscan-daemon=%{clang-daemon-dir}/%basename_t \
7171
// RUN: -fdepscan-prefix-map=/=/^foo \
7272
// RUN: -cc1-args -triple x86_64-apple-macos11.0 -x c %s -o %t.d/out.o \
73-
// RUN: -fcas-path %t.d/cas -faction-cache-path %t.d/cache \
73+
// RUN: -fcas-path %t.d/cas \
7474
// RUN: 2>&1 | FileCheck %s -DPREFIX=%t.d -check-prefix=ERROR_ROOT
7575
// ERROR_ROOT: invalid prefix map: '/=/^foo'
7676

7777
// RUN: not %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t \
78-
// RUN: -cas-args -fcas-path %t.d/cas -faction-cache-path %t.d/cache -- \
78+
// RUN: -cas-args -fcas-path %t.d/cas -- \
7979
// RUN: %clang -cc1depscan -dump-depscan-tree=%t.root -fdepscan=daemon \
8080
// RUN: -fdepscan-daemon=%{clang-daemon-dir}/%basename_t \
8181
// RUN: -fdepscan-prefix-map==/^foo \
8282
// RUN: -cc1-args -triple x86_64-apple-macos11.0 -x c %s -o %t.d/out.o \
83-
// RUN: -fcas-path %t.d/cas -faction-cache-path %t.d/cache \
83+
// RUN: -fcas-path %t.d/cas \
8484
// RUN: 2>&1 | FileCheck %s -DPREFIX=%t.d -check-prefix=ERROR_EMPTY
8585
// ERROR_EMPTY: invalid prefix map: '=/^foo'
8686

8787
// RUN: not %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t \
88-
// RUN: -cas-args -fcas-path %t.d/cas -faction-cache-path %t.d/cache -- \
88+
// RUN: -cas-args -fcas-path %t.d/cas -- \
8989
// RUN: %clang -cc1depscan -dump-depscan-tree=%t.root -fdepscan=daemon \
9090
// RUN: -fdepscan-daemon=%{clang-daemon-dir}/%basename_t \
9191
// RUN: -fdepscan-prefix-map=relative=/^foo \
9292
// RUN: -cc1-args -triple x86_64-apple-macos11.0 -x c %s -o %t.d/out.o \
93-
// RUN: -fcas-path %t.d/cas -faction-cache-path %t.d/cache \
93+
// RUN: -fcas-path %t.d/cas \
9494
// RUN: 2>&1 | FileCheck %s -DPREFIX=%t.d -check-prefix=ERROR_RELATIVE
9595
// ERROR_RELATIVE: invalid prefix map: 'relative=/^foo'
9696

clang/test/CAS/depscan-with-error.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// RUN: not env LLVM_CACHE_CAS_PATH=%t/cas %clang-cache \
1212
// RUN: %clang -target x86_64-apple-macos11 -c %s -o %t.o -Wl,-none --serialize-diagnostics %t/t2.diag \
1313
// RUN: 2>&1 | FileCheck %s -check-prefix=ERROR -check-prefix=DRIVER
14-
// RUN: not env LLVM_CACHE_CAS_PATH=%t/cas %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t -cas-args -fcas-path %t/cas/cas -faction-cache-path %t/cas/cache -- \
14+
// RUN: not env LLVM_CACHE_CAS_PATH=%t/cas %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t -cas-args -fcas-path %t/cas -- \
1515
// RUN: %clang-cache \
1616
// RUN: %clang -target x86_64-apple-macos11 -c %s -o %t.o -Wl,-none --serialize-diagnostics %t/t3.diag \
1717
// RUN: 2>&1 | FileCheck %s -check-prefix=ERROR -check-prefix=DRIVER
@@ -28,7 +28,7 @@
2828
// RUN: echo "int y;" > %t/b.c
2929
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas %clang-cache \
3030
// RUN: %clang -target x86_64-apple-macos11 -c %t/a.c -o %t.o --serialize-diagnostics %t/t2.diag
31-
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t -cas-args -fcas-path %t/cas/cas -faction-cache-path %t/cas/cache -- \
31+
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t -cas-args -fcas-path %t/cas -- \
3232
// RUN: %clang-cache \
3333
// RUN: %clang -target x86_64-apple-macos11 -c %t/b.c -o %t.o --serialize-diagnostics %t/t3.diag
3434

@@ -49,7 +49,7 @@
4949
// RUN: not env LLVM_CACHE_CAS_PATH=%t/cas %clang-cache \
5050
// RUN: %clang -target x86_64-apple-macos11 -c %s -o %t.o -fdiagnostics-color=always -fansi-escape-codes \
5151
// RUN: 2>&1 | FileCheck %s -check-prefix=COLOR-DIAG
52-
// RUN: not env LLVM_CACHE_CAS_PATH=%t/cas %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t -cas-args -fcas-path %t/cas/cas -faction-cache-path %t/cas/cache -- \
52+
// RUN: not env LLVM_CACHE_CAS_PATH=%t/cas %clang -cc1depscand -execute %{clang-daemon-dir}/%basename_t -cas-args -fcas-path %t/cas -- \
5353
// RUN: %clang-cache \
5454
// RUN: %clang -target x86_64-apple-macos11 -c %s -o %t.o -fdiagnostics-color=always -fansi-escape-codes \
5555
// RUN: 2>&1 | FileCheck %s -check-prefix=COLOR-DIAG

0 commit comments

Comments
 (0)