Skip to content

Commit d38caf1

Browse files
[Caching] Normalize DebugInfo flags in DWARF
Do not encode cache invariant command-line flags in DWARF since those flag should not affect code generation or diagnostics. This avoids generating conflicting cache entry when caching is enabled, and will make normal incremental builds more likely to hit fast skip codegen path. rdar://124222904
1 parent 85ea5ff commit d38caf1

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class CompilerInvocation {
156156
/// Serialize the command line arguments for emitting them
157157
/// to DWARF or CodeView and inject SDKPath if necessary.
158158
static void buildDebugFlags(std::string &Output,
159-
const ArrayRef<const char*> &Args,
159+
const llvm::opt::ArgList &Args,
160160
StringRef SDKPath,
161161
StringRef ResourceDir);
162162

lib/Frontend/CompilerInvocation.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,23 +2468,43 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
24682468
}
24692469

24702470
void CompilerInvocation::buildDebugFlags(std::string &Output,
2471-
const ArrayRef<const char*> &Args,
2471+
const ArgList &Args,
24722472
StringRef SDKPath,
24732473
StringRef ResourceDir) {
2474+
ArgStringList ReducedArgs;
2475+
for (auto *A : Args) {
2476+
// Do not encode cache invariant options, even for non-caching build.
2477+
// Those options do not affect compilation task thus do not need to be
2478+
// tracked.
2479+
if (A->getOption().hasFlag(options::CacheInvariant))
2480+
continue;
2481+
2482+
A->render(Args, ReducedArgs);
2483+
2484+
// If the argument is file list, the path itself is irrelevant.
2485+
if (A->getOption().hasFlag(options::ArgumentIsFileList)) {
2486+
assert(A->getValues().size() == 1 &&
2487+
A->getOption().getRenderStyle() == Option::RenderSeparateStyle &&
2488+
"filelist options all have one argument and are all Separate<>");
2489+
ReducedArgs.pop_back();
2490+
ReducedArgs.push_back("<filelist>");
2491+
}
2492+
}
2493+
24742494
// This isn't guaranteed to be the same temp directory as what the driver
24752495
// uses, but it's highly likely.
24762496
llvm::SmallString<128> TDir;
24772497
llvm::sys::path::system_temp_directory(true, TDir);
24782498

24792499
llvm::raw_string_ostream OS(Output);
2480-
interleave(Args,
2500+
interleave(ReducedArgs,
24812501
[&](const char *Argument) { PrintArg(OS, Argument, TDir.str()); },
24822502
[&] { OS << " "; });
24832503

24842504
// Inject the SDK path and resource dir if they are nonempty and missing.
24852505
bool haveSDKPath = SDKPath.empty();
24862506
bool haveResourceDir = ResourceDir.empty();
2487-
for (auto A : Args) {
2507+
for (auto A : ReducedArgs) {
24882508
StringRef Arg(A);
24892509
// FIXME: this should distinguish between key and value.
24902510
if (!haveSDKPath && Arg.equals("-sdk"))
@@ -2561,14 +2581,10 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
25612581
"unknown -g<kind> option");
25622582
}
25632583
if (Opts.DebugInfoLevel >= IRGenDebugInfoLevel::LineTables) {
2564-
if (Args.hasArg(options::OPT_debug_info_store_invocation)) {
2565-
ArgStringList RenderedArgs;
2566-
for (auto A : Args)
2567-
A->render(Args, RenderedArgs);
2584+
if (Args.hasArg(options::OPT_debug_info_store_invocation))
25682585
CompilerInvocation::buildDebugFlags(Opts.DebugFlags,
2569-
RenderedArgs, SDKPath,
2586+
Args, SDKPath,
25702587
ResourceDir);
2571-
}
25722588

25732589
if (const Arg *A = Args.getLastArg(OPT_file_compilation_dir))
25742590
Opts.DebugCompilationDir = A->getValue();

test/CAS/debuginfo_invariant.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache -O -g \
5+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
6+
// RUN: %t/main.swift -o %t/deps.json -swift-version 5 -cache-compile-job -cas-path %t/cas
7+
8+
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
9+
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
10+
11+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd
12+
13+
// RUN: echo %t/main.swift > %t/inputs.FileList
14+
// RUN: %target-swift-frontend -emit-ir -o %t/main.ll -g -O \
15+
// RUN: -cache-compile-job -cas-path %t/cas -swift-version 5 \
16+
// RUN: -disable-implicit-swift-modules -swift-version 5 -enable-cross-import-overlays \
17+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
18+
// RUN: -module-name Test -explicit-swift-module-map-file @%t/map.casid \
19+
// RUN: -filelist %t/inputs.FileList @%t/MyApp.cmd -debug-info-store-invocation -Rcache-compile-job
20+
21+
// RUN: %FileCheck %s --input-file=%t/main.ll
22+
23+
// CHECK: distinct !DICompileUnit(language: DW_LANG_Swift,
24+
// CHECK-SAME: flags:
25+
// CHECK-SAME: -filelist
26+
27+
/// option that should not be encoded
28+
// CHECK-NOT: -Rcache-compile-job
29+
// CHECK-NOT: inputs.FileList
30+
31+
//--- main.swift
32+
public func test() {}

0 commit comments

Comments
 (0)