[clang] [clang/DependencyScanning/ModuleDepCollector] Refactor part of `makeCommonInvocationForModuleBuild` into its own function, NFC (PR #88447)
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 11 15:01:50 PDT 2024
https://github.com/akyrtzi created https://github.com/llvm/llvm-project/pull/88447
The function is named `removeUnnecessaryDependencies` and is a bit more general that could be used from other places as well.
>From 0344d1890028b178d54d69fba239149b7d96fa30 Mon Sep 17 00:00:00 2001
From: Argyrios Kyrtzidis <kyrtzidis at apple.com>
Date: Thu, 11 Apr 2024 14:57:40 -0700
Subject: [PATCH] [clang/DependencyScanning/ModuleDepCollector] Refactor part
of `makeCommonInvocationForModuleBuild` into its own function, NFC
The function is named `removeUnnecessaryDependencies` and is a bit more general that could be used from other places as well.
---
.../DependencyScanning/ModuleDepCollector.h | 3 +++
.../DependencyScanning/ModuleDepCollector.cpp | 25 ++++++++++++-------
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index 081899cc2c8503..b971269c4983ed 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -308,6 +308,9 @@ class ModuleDepCollector final : public DependencyCollector {
ModuleDeps &Deps);
};
+/// Resets some options that introduce dependencies unnecessarily.
+void removeUnnecessaryDependencies(CompilerInvocation &CI, bool ForModuleBuild);
+
} // end namespace dependencies
} // end namespace tooling
} // end namespace clang
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 94ccbd3351b09d..fd425ff7c4cafe 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -154,6 +154,20 @@ void ModuleDepCollector::addOutputPaths(CowCompilerInvocation &CI,
}
}
+void dependencies::removeUnnecessaryDependencies(CompilerInvocation &CI,
+ bool ForModuleBuild) {
+ if (CI.getFrontendOpts().ProgramAction == frontend::GeneratePCH ||
+ (ForModuleBuild && !CI.getLangOpts().ModulesCodegen)) {
+ CI.getCodeGenOpts().DebugCompilationDir.clear();
+ CI.getCodeGenOpts().CoverageCompilationDir.clear();
+ CI.getCodeGenOpts().CoverageDataFile.clear();
+ CI.getCodeGenOpts().CoverageNotesFile.clear();
+ CI.getCodeGenOpts().ProfileInstrumentUsePath.clear();
+ CI.getCodeGenOpts().SampleProfileFile.clear();
+ CI.getCodeGenOpts().ProfileRemappingFile.clear();
+ }
+}
+
static CowCompilerInvocation
makeCommonInvocationForModuleBuild(CompilerInvocation CI) {
CI.resetNonModularOptions();
@@ -170,15 +184,8 @@ makeCommonInvocationForModuleBuild(CompilerInvocation CI) {
// TODO: Figure out better way to set options to their default value.
CI.getCodeGenOpts().MainFileName.clear();
CI.getCodeGenOpts().DwarfDebugFlags.clear();
- if (!CI.getLangOpts().ModulesCodegen) {
- CI.getCodeGenOpts().DebugCompilationDir.clear();
- CI.getCodeGenOpts().CoverageCompilationDir.clear();
- CI.getCodeGenOpts().CoverageDataFile.clear();
- CI.getCodeGenOpts().CoverageNotesFile.clear();
- CI.getCodeGenOpts().ProfileInstrumentUsePath.clear();
- CI.getCodeGenOpts().SampleProfileFile.clear();
- CI.getCodeGenOpts().ProfileRemappingFile.clear();
- }
+
+ removeUnnecessaryDependencies(CI, /*ForModuleBuild=*/true);
// Map output paths that affect behaviour to "-" so their existence is in the
// context hash. The final path will be computed in addOutputPaths.
More information about the cfe-commits
mailing list