Author: Jan Svoboda Date: 2023-08-03T20:36:34-07:00 New Revision: 8fd56ea11256f220502fe9819b496b15582f8d1e
URL: https://github.com/llvm/llvm-project/commit/8fd56ea11256f220502fe9819b496b15582f8d1e DIFF: https://github.com/llvm/llvm-project/commit/8fd56ea11256f220502fe9819b496b15582f8d1e.diff LOG: [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 Added: Modified: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp Removed: ################################################################################ diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index 060c5389b06d26..fa75c83ef64017 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -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 diff er even if the invocation // is identical if they depend on the contents of the files in the TU -- for _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits