Skip to content

Commit 8fd56ea

Browse files
committed
[clang][deps] NFC: Speed up canonical context hash computation
This patch makes use of the infrastructure established in D157046 to speed up computation of the canonical context hash in the dependency scanner. This is somewhat hot code, since it's ran for all modules in the dependency graph of every TU. I also tried an alternative approach that tried to avoid allocations as much as possible (essentially doing `HashBuilder.add(Arg.toStringRef(ArgVec))`), but that turned out to be slower than approach in this patch. Note that this is not problematic in the same way command-line hashing used to be prior D143027. The lambda is now being called even for constant strings. Depends on D157046. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D157052
1 parent acd1ab8 commit 8fd56ea

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,13 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
269269
HashBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR);
270270

271271
// Hash the BuildInvocation without any input files.
272-
SmallVector<const char *, 32> Args;
273-
llvm::BumpPtrAllocator Alloc;
274-
llvm::StringSaver Saver(Alloc);
275-
CI.generateCC1CommandLine(
276-
Args, [&](const Twine &Arg) { return Saver.save(Arg).data(); });
277-
HashBuilder.addRange(Args);
272+
SmallString<0> ArgVec;
273+
ArgVec.reserve(4096);
274+
CI.generateCC1CommandLine([&](const Twine &Arg) {
275+
Arg.toVector(ArgVec);
276+
ArgVec.push_back('\0');
277+
});
278+
HashBuilder.add(ArgVec);
278279

279280
// Hash the module dependencies. These paths may differ even if the invocation
280281
// is identical if they depend on the contents of the files in the TU -- for

0 commit comments

Comments
 (0)