[clang] e8febb2 - [clang][deps] Remove CompilerInvocation from ModuleDeps
Ben Langmuir via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 24 19:51:28 PDT 2022
Author: Ben Langmuir
Date: 2022-08-24T19:51:12-07:00
New Revision: e8febb23a07bde8c02aee5545a0206e6f3851237
URL: https://github.com/llvm/llvm-project/commit/e8febb23a07bde8c02aee5545a0206e6f3851237
DIFF: https://github.com/llvm/llvm-project/commit/e8febb23a07bde8c02aee5545a0206e6f3851237.diff
LOG: [clang][deps] Remove CompilerInvocation from ModuleDeps
The invocation is only ever used to serialize cc1 arguments from, so
instead serialize the arguments inside the dep scanner to simplify the
interface.
Differential Revision: https://reviews.llvm.org/D132616
Added:
Modified:
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index a82355e60ee8..37eb4ef215b5 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -119,11 +119,9 @@ struct ModuleDeps {
// the primary TU.
bool ImportedByMainFile = false;
- /// Compiler invocation that can be used to build this module (without paths).
- CompilerInvocation BuildInvocation;
-
- /// Gets the canonical command line suitable for passing to clang.
- std::vector<std::string> getCanonicalCommandLine() const;
+ /// Compiler invocation that can be used to build this module. Does not
+ /// include argv[0].
+ std::vector<std::string> BuildArguments;
};
class ModuleDepCollector;
@@ -238,7 +236,7 @@ class ModuleDepCollector final : public DependencyCollector {
llvm::function_ref<void(CompilerInvocation &)> Optimize) const;
/// Add paths that require looking up outputs to the given dependencies.
- void addOutputPaths(ModuleDeps &Deps);
+ void addOutputPaths(CompilerInvocation &CI, ModuleDeps &Deps);
};
} // end namespace dependencies
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index ad2d9939896e..fe0de00f6244 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -52,9 +52,8 @@ static std::vector<std::string> splitString(std::string S, char Separator) {
return Result;
}
-void ModuleDepCollector::addOutputPaths(ModuleDeps &Deps) {
- CompilerInvocation &CI = Deps.BuildInvocation;
-
+void ModuleDepCollector::addOutputPaths(CompilerInvocation &CI,
+ ModuleDeps &Deps) {
// These are technically *inputs* to the compilation, but we populate them
// here in order to make \c getModuleContextHash() independent of
// \c lookupModuleOutput().
@@ -170,11 +169,8 @@ ModuleDepCollector::makeInvocationForModuleBuildWithoutOutputs(
return CI;
}
-std::vector<std::string> ModuleDeps::getCanonicalCommandLine() const {
- return BuildInvocation.getCC1CommandLine();
-}
-
static std::string getModuleContextHash(const ModuleDeps &MD,
+ const CompilerInvocation &CI,
bool EagerLoadModules) {
llvm::HashBuilder<llvm::TruncatedBLAKE3<16>,
llvm::support::endianness::native>
@@ -188,7 +184,7 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
// Hash the BuildInvocation without any input files.
SmallVector<const char *, 32> DummyArgs;
- MD.BuildInvocation.generateCC1CommandLine(DummyArgs, [&](const Twine &Arg) {
+ CI.generateCC1CommandLine(DummyArgs, [&](const Twine &Arg) {
Scratch.clear();
StringRef Str = Arg.toStringRef(Scratch);
HashBuilder.add(Str);
@@ -397,7 +393,7 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
llvm::DenseSet<const Module *> ProcessedModules;
addAllAffectingModules(M, MD, ProcessedModules);
- MD.BuildInvocation = MDC.makeInvocationForModuleBuildWithoutOutputs(
+ CompilerInvocation CI = MDC.makeInvocationForModuleBuildWithoutOutputs(
MD, [&](CompilerInvocation &BuildInvocation) {
if (MDC.OptimizeArgs)
optimizeHeaderSearchOpts(BuildInvocation.getHeaderSearchOpts(),
@@ -405,9 +401,12 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
});
// Compute the context hash from the inputs. Requires dependencies.
- MD.ID.ContextHash = getModuleContextHash(MD, MDC.EagerLoadModules);
+ MD.ID.ContextHash = getModuleContextHash(MD, CI, MDC.EagerLoadModules);
// Finish the compiler invocation. Requires dependencies and the context hash.
- MDC.addOutputPaths(MD);
+ MDC.addOutputPaths(CI, MD);
+
+ MD.BuildArguments = CI.getCC1CommandLine();
+
return MD.ID;
}
diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index a192d131c822..2d3415145bc6 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -304,7 +304,7 @@ class FullDeps {
{"file-deps", toJSONSorted(MD.FileDeps)},
{"clang-module-deps", toJSONSorted(MD.ClangModuleDeps)},
{"clang-modulemap-file", MD.ClangModuleMapFile},
- {"command-line", MD.getCanonicalCommandLine()},
+ {"command-line", MD.BuildArguments},
};
OutModules.push_back(std::move(O));
}
More information about the cfe-commits
mailing list