Skip to content

Commit b78b569

Browse files
[CAS] Consolidate compile cache flags
Rename `-enable-cas` to `-compile-cache-job` to align with clang option names and promote that to a new driver only flag. Few other additions to driver flag for caching behaviors: * `-compile-cache-remarks`: now cache hit/miss remarks are guarded behind this flag * `-compile-cache-skip`: skip replaying from the cache. Useful as a debugging tool to do the compilation using CAS inputs even the output is a hit from the cache.
1 parent 744e01e commit b78b569

24 files changed

+104
-82
lines changed

include/swift/Frontend/CachingUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool replayCachedCompilerOutputs(
3939
llvm::cas::ObjectStore &CAS, llvm::cas::ActionCache &Cache,
4040
llvm::cas::ObjectRef BaseKey, DiagnosticEngine &Diag,
4141
const FrontendInputsAndOutputs &InputsAndOutputs,
42-
CachingDiagnosticsProcessor &CDP);
42+
CachingDiagnosticsProcessor &CDP, bool CacheRemarks);
4343

4444
/// Load the cached compile result from cache.
4545
std::unique_ptr<llvm::MemoryBuffer> loadCachedCompileResultFromCacheKey(

include/swift/Frontend/FrontendOptions.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,14 @@ class FrontendOptions {
123123
/// The module for which we should verify all of the generic signatures.
124124
std::string VerifyGenericSignaturesInModule;
125125

126-
/// Use CAS.
127-
bool EnableCAS = false;
126+
/// Enable compiler caching.
127+
bool EnableCaching = false;
128+
129+
/// Enable compiler caching remarks.
130+
bool EnableCachingRemarks = false;
131+
132+
/// Skip replaying outputs from cache.
133+
bool CacheSkipReplay = false;
128134

129135
/// CASOptions
130136
clang::CASOptions CASOpts;

include/swift/Option/FrontendOptions.td

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,23 @@ def always_compile_output_files :
12171217
Flag<["-"], "always-compile-output-files">,
12181218
HelpText<"Always compile output files even it might not change the results">;
12191219

1220+
// CAS/Caching related options.
1221+
def allow_unstable_cache_key_for_testing: Flag<["-"], "allow-unstable-cache-key-for-testing">,
1222+
HelpText<"Allow compilation caching with unstable inputs for testing purpose">;
1223+
1224+
def bridging_header_pch_key : Separate<["-"], "bridging-header-pch-key">,
1225+
HelpText<"Cache Key for bridging header pch">;
1226+
1227+
def clang_include_tree: Flag<["-"], "clang-include-tree">,
1228+
HelpText<"Use clang include tree">;
1229+
1230+
def cas_fs: Separate<["-"], "cas-fs">,
1231+
HelpText<"Root CASID for CAS FileSystem">, MetaVarName<"<cas-id>">;
1232+
1233+
def clang_include_tree_root: Separate<["-"], "clang-include-tree-root">,
1234+
HelpText<"Clang Include Tree CASID">, MetaVarName<"<cas-id>">;
1235+
1236+
12201237
def experimental_spi_only_imports :
12211238
Flag<["-"], "experimental-spi-only-imports">,
12221239
HelpText<"Enable use of @_spiOnly imports">;

include/swift/Option/Options.td

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,18 @@ def gcc_toolchain: Separate<["-"], "gcc-toolchain">,
18121812
MetaVarName<"<path>">,
18131813
HelpText<"Specify a directory where the clang importer and clang linker can find headers and libraries">;
18141814

1815+
def cache_compile_job: Flag<["-"], "cache-compile-job">,
1816+
Flags<[FrontendOption, NewDriverOnlyOption]>,
1817+
HelpText<"Enable compiler caching">;
1818+
1819+
def cache_remarks: Flag<["-"], "cache-remarks">,
1820+
Flags<[FrontendOption, NewDriverOnlyOption]>,
1821+
HelpText<"Show remarks for compiler caching">;
1822+
1823+
def cache_disable_replay: Flag<["-"], "cache-disable-replay">,
1824+
Flags<[FrontendOption, NewDriverOnlyOption]>,
1825+
HelpText<"Skip loading the compilation result from cache">;
1826+
18151827
def cas_path: Separate<["-"], "cas-path">,
18161828
Flags<[FrontendOption, NewDriverOnlyOption]>,
18171829
HelpText<"Path to CAS">, MetaVarName<"<path>">;
@@ -1824,33 +1836,9 @@ def cas_plugin_option: Separate<["-"], "cas-plugin-option">,
18241836
Flags<[FrontendOption, NewDriverOnlyOption]>,
18251837
HelpText<"Option pass to CAS Plugin">, MetaVarName<"<name>=<option>">;
18261838

1827-
def allow_unstable_cache_key_for_testing: Flag<["-"], "allow-unstable-cache-key-for-testing">,
1828-
Flags<[FrontendOption, HelpHidden, NoDriverOption]>,
1829-
HelpText<"Allow compilation caching with unstable inputs for testing purpose">;
1830-
1831-
def bridging_header_pch_key : Separate<["-"], "bridging-header-pch-key">,
1832-
Flags<[FrontendOption, HelpHidden, ArgumentIsPath]>,
1833-
HelpText<"Cache Key for bridging header pch">;
1834-
1835-
def clang_include_tree: Flag<["-"], "clang-include-tree">,
1836-
Flags<[FrontendOption, NoDriverOption]>,
1837-
HelpText<"Use clang include tree">;
1838-
18391839

18401840
// END ONLY SUPPORTED IN NEW DRIVER
18411841

1842-
def enable_cas: Flag<["-"], "enable-cas">,
1843-
Flags<[FrontendOption, NoDriverOption]>,
1844-
HelpText<"Enable CAS for swift-frontend">;
1845-
1846-
def cas_fs: Separate<["-"], "cas-fs">,
1847-
Flags<[FrontendOption, NoDriverOption]>,
1848-
HelpText<"Root CASID for CAS FileSystem">, MetaVarName<"<cas-id>">;
1849-
1850-
def clang_include_tree_root: Separate<["-"], "clang-include-tree-root">,
1851-
Flags<[FrontendOption, NoDriverOption]>,
1852-
HelpText<"Clang Include Tree CASID">, MetaVarName<"<cas-id>">;
1853-
18541842

18551843
def plugin_search_Group : OptionGroup<"<plugin search options>">;
18561844

lib/AST/ModuleDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ void SwiftDependencyScanningService::overlaySharedFilesystemCacheForCompilation(
419419

420420
bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
421421
CompilerInstance &Instance) {
422-
if (!Instance.getInvocation().getFrontendOptions().EnableCAS)
422+
if (!Instance.getInvocation().getFrontendOptions().EnableCaching)
423423
return false;
424424

425425
if (CASOpts) {

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ static llvm::Error resolveExplicitModuleInputs(
421421
dependencyInfoCopy.updateCommandLine(commandLine);
422422

423423
// Handle CAS options.
424-
if (instance.getInvocation().getFrontendOptions().EnableCAS) {
424+
if (instance.getInvocation().getFrontendOptions().EnableCaching) {
425425
// Merge CASFS from clang dependency.
426426
auto &CASFS = cache.getScanService().getSharedCachingFS();
427427
auto &CAS = CASFS.getCAS();

lib/DriverTool/swift_cache_tool_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class SwiftCacheToolInvocation {
194194
MainExecutablePath))
195195
return true;
196196

197-
if (!Invocation.getFrontendOptions().EnableCAS) {
197+
if (!Invocation.getFrontendOptions().EnableCaching) {
198198
llvm::errs() << "Requested command-line arguments do not enable CAS\n";
199199
return true;
200200
}

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,9 @@ bool ArgsToFrontendOptionsConverter::convert(
351351
Opts.BlocklistConfigFilePaths.push_back(A);
352352
}
353353

354-
Opts.EnableCAS = Args.hasArg(OPT_enable_cas);
354+
Opts.EnableCaching = Args.hasArg(OPT_cache_compile_job);
355+
Opts.EnableCachingRemarks = Args.hasArg(OPT_cache_remarks);
356+
Opts.CacheSkipReplay = Args.hasArg(OPT_cache_disable_replay);
355357
Opts.CASOpts.CASPath =
356358
Args.getLastArgValue(OPT_cas_path, llvm::cas::getDefaultOnDiskCASPath());
357359
Opts.CASOpts.PluginPath = Args.getLastArgValue(OPT_cas_plugin_path);
@@ -365,7 +367,7 @@ bool ArgsToFrontendOptionsConverter::convert(
365367
Opts.CASFSRootIDs = Args.getAllArgValues(OPT_cas_fs);
366368
Opts.ClangIncludeTrees = Args.getAllArgValues(OPT_clang_include_tree_root);
367369

368-
if (Opts.EnableCAS && Opts.CASFSRootIDs.empty() &&
370+
if (Opts.EnableCaching && Opts.CASFSRootIDs.empty() &&
369371
Opts.ClangIncludeTrees.empty() &&
370372
FrontendOptions::supportCompilationCaching(Opts.RequestedAction)) {
371373
if (!Args.hasArg(OPT_allow_unstable_cache_key_for_testing)) {

lib/Frontend/CachedDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ CachingDiagnosticsProcessor::CachingDiagnosticsProcessor(
728728
: Impl(*new Implementation(Instance)) {
729729
Impl.serializedOutputCallback = [&](StringRef Output) {
730730
LLVM_DEBUG(llvm::dbgs() << Output << "\n";);
731-
if (!Instance.getInvocation().getFrontendOptions().EnableCAS)
731+
if (!Instance.getInvocation().getFrontendOptions().EnableCaching)
732732
return false;
733733

734734
// compress the YAML file.

lib/Frontend/CachingUtils.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ createSwiftCachingOutputBackend(
142142
bool replayCachedCompilerOutputs(
143143
ObjectStore &CAS, ActionCache &Cache, ObjectRef BaseKey,
144144
DiagnosticEngine &Diag, const FrontendInputsAndOutputs &InputsAndOutputs,
145-
CachingDiagnosticsProcessor &CDP) {
145+
CachingDiagnosticsProcessor &CDP, bool CacheRemarks) {
146146
clang::cas::CompileJobResultSchema Schema(CAS);
147147
bool CanReplayAllOutput = true;
148148
struct OutputEntry {
@@ -173,8 +173,9 @@ bool replayCachedCompilerOutputs(
173173
return None;
174174
}
175175
if (!*Lookup) {
176-
Diag.diagnose(SourceLoc(), diag::output_cache_miss, OutputPath,
177-
OutputKeyID.toString());
176+
if (CacheRemarks)
177+
Diag.diagnose(SourceLoc(), diag::output_cache_miss, OutputPath,
178+
OutputKeyID.toString());
178179
return None;
179180
}
180181
auto OutputRef = CAS.getReference(**Lookup);
@@ -261,7 +262,8 @@ bool replayCachedCompilerOutputs(
261262
toString(std::move(E)));
262263
continue;
263264
}
264-
Diag.diagnose(SourceLoc(), diag::replay_output, Output.Path, Output.Key);
265+
if (CacheRemarks)
266+
Diag.diagnose(SourceLoc(), diag::replay_output, Output.Path, Output.Key);
265267
}
266268

267269
return true;

0 commit comments

Comments
 (0)