[clang] [clang/DependencyScanning/ModuleDepCollector] Refactor part of `makeCommonInvocationForModuleBuild` into its own function, NFC (PR #88447)

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 11 15:02:22 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Argyrios Kyrtzidis (akyrtzi)

<details>
<summary>Changes</summary>

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
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.

``````````

</details>


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


More information about the cfe-commits mailing list