[llvm] [FunctionSpecialization] Preserve call counts of specialized functions (PR #157768)

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 9 16:52:52 PDT 2025


================
@@ -784,9 +784,25 @@ bool FunctionSpecializer::run() {
 
     // Update the known call sites to call the clone.
     for (CallBase *Call : S.CallSites) {
+      Function *Clone = S.Clone;
       LLVM_DEBUG(dbgs() << "FnSpecialization: Redirecting " << *Call
-                        << " to call " << S.Clone->getName() << "\n");
+                        << " to call " << Clone->getName() << "\n");
       Call->setCalledFunction(S.Clone);
+      if (std::optional<uint64_t> Count =
+              GetBFI(*Call->getFunction())
----------------
mtrofin wrote:

nit: pull out the BFI (just more readable):

```
auto &BFI = GetBFI(*Call->getFunction);
if (auto Count = BFI.getBlockProfileCount(Call->getParent()) {
...
```

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


More information about the llvm-commits mailing list