Skip to content

Commit

Permalink
[clang][deps] NFC: Speed up canonical context hash computation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jansvoboda11 committed Aug 4, 2023
1 parent acd1ab8 commit 8fd56ea
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
Expand Up @@ -269,12 +269,13 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
HashBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR);

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

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

0 comments on commit 8fd56ea

Please sign in to comment.