[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
This commit is contained in:
Steven Wu
2024-03-07 15:36:48 -08:00
parent 85ea5ffc46
commit d38caf15cf
3 changed files with 58 additions and 10 deletions

View File

@@ -2468,23 +2468,43 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
}
void CompilerInvocation::buildDebugFlags(std::string &Output,
const ArrayRef<const char*> &Args,
const ArgList &Args,
StringRef SDKPath,
StringRef ResourceDir) {
ArgStringList ReducedArgs;
for (auto *A : Args) {
// Do not encode cache invariant options, even for non-caching build.
// Those options do not affect compilation task thus do not need to be
// tracked.
if (A->getOption().hasFlag(options::CacheInvariant))
continue;
A->render(Args, ReducedArgs);
// If the argument is file list, the path itself is irrelevant.
if (A->getOption().hasFlag(options::ArgumentIsFileList)) {
assert(A->getValues().size() == 1 &&
A->getOption().getRenderStyle() == Option::RenderSeparateStyle &&
"filelist options all have one argument and are all Separate<>");
ReducedArgs.pop_back();
ReducedArgs.push_back("<filelist>");
}
}
// This isn't guaranteed to be the same temp directory as what the driver
// uses, but it's highly likely.
llvm::SmallString<128> TDir;
llvm::sys::path::system_temp_directory(true, TDir);
llvm::raw_string_ostream OS(Output);
interleave(Args,
interleave(ReducedArgs,
[&](const char *Argument) { PrintArg(OS, Argument, TDir.str()); },
[&] { OS << " "; });
// Inject the SDK path and resource dir if they are nonempty and missing.
bool haveSDKPath = SDKPath.empty();
bool haveResourceDir = ResourceDir.empty();
for (auto A : Args) {
for (auto A : ReducedArgs) {
StringRef Arg(A);
// FIXME: this should distinguish between key and value.
if (!haveSDKPath && Arg.equals("-sdk"))
@@ -2561,14 +2581,10 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
"unknown -g<kind> option");
}
if (Opts.DebugInfoLevel >= IRGenDebugInfoLevel::LineTables) {
if (Args.hasArg(options::OPT_debug_info_store_invocation)) {
ArgStringList RenderedArgs;
for (auto A : Args)
A->render(Args, RenderedArgs);
if (Args.hasArg(options::OPT_debug_info_store_invocation))
CompilerInvocation::buildDebugFlags(Opts.DebugFlags,
RenderedArgs, SDKPath,
Args, SDKPath,
ResourceDir);
}
if (const Arg *A = Args.getLastArg(OPT_file_compilation_dir))
Opts.DebugCompilationDir = A->getValue();