Skip to content

[clang/DependencyScanning/ModuleDepCollector] Refactor part of makeCommonInvocationForModuleBuild into its own function #88447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

akyrtzi
Copy link
Contributor

@akyrtzi akyrtzi commented Apr 11, 2024

The new function is about clearing out benign codegen options and can be applied for PCH invocations as well.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Apr 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 11, 2024

@llvm/pr-subscribers-clang

Author: Argyrios Kyrtzidis (akyrtzi)

Changes

The function is named removeUnnecessaryDependencies and is a bit more general that could be used from other places as well.


Full diff: https://github.com/llvm/llvm-project/pull/88447.diff

2 Files Affected:

  • (modified) clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h (+3)
  • (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (+16-9)
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.

@akyrtzi akyrtzi force-pushed the akyrtzi/pr/refactor-deps-removal-from-makeCommonInvocationForModuleBuild branch from 0344d18 to f96eadb Compare April 11, 2024 23:42
Copy link
Contributor

@jansvoboda11 jansvoboda11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I assume you'll call resetBenignCodeGenOptions() from ModuleDepCollector::applyDiscoveredDependencies() in a follow-up, non-NFC patch, right? (So that it applies to the primary invocation, i.e. the actual PCH.) Maybe leaving a FIXME behind would be nice, just to make the intent clear.

…ommonInvocationForModuleBuild` into its own function

The new function is about clearing out benign codegen options and can be applied for PCH invocations as well.
@akyrtzi akyrtzi force-pushed the akyrtzi/pr/refactor-deps-removal-from-makeCommonInvocationForModuleBuild branch from f96eadb to 8b21183 Compare April 15, 2024 18:26
@akyrtzi akyrtzi changed the title [clang/DependencyScanning/ModuleDepCollector] Refactor part of makeCommonInvocationForModuleBuild into its own function, NFC [clang/DependencyScanning/ModuleDepCollector] Refactor part of makeCommonInvocationForModuleBuild into its own function Apr 15, 2024
@akyrtzi
Copy link
Contributor Author

akyrtzi commented Apr 15, 2024

I assume you'll call resetBenignCodeGenOptions() from ModuleDepCollector::applyDiscoveredDependencies() in a follow-up, non-NFC patch, right?

@jansvoboda11 see updated commit, I made the change per your suggestion.

Copy link
Contributor

@jansvoboda11 jansvoboda11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Still LGTM.

@akyrtzi akyrtzi merged commit 6331024 into llvm:main Apr 15, 2024
3 of 4 checks passed
@akyrtzi akyrtzi deleted the akyrtzi/pr/refactor-deps-removal-from-makeCommonInvocationForModuleBuild branch April 15, 2024 22:05
aniplcc pushed a commit to aniplcc/llvm-project that referenced this pull request Apr 15, 2024
…ommonInvocationForModuleBuild` into its own function (llvm#88447)

The new function is about clearing out benign codegen options and can be
applied for PCH invocations as well.
bnbarham pushed a commit to swiftlang/llvm-project that referenced this pull request Apr 19, 2024
…ommonInvocationForModuleBuild` into its own function (llvm#88447)

The new function is about clearing out benign codegen options and can be
applied for PCH invocations as well.

(cherry picked from commit 6331024)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants