[llvm] [RFC][ThinLTO] Reduce the number of function name promotions (PR #178587)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 30 22:07:21 PST 2026


yonghong-song wrote:

> Thanks for the PR! I took a quick look but have a few questions and high level suggestions.
> 
> I'm not sure I follow how this works, since it looks like you are doing the analysis while importing for a given module. I am not sure how this will detect that there is a duplicate local name across different modules if they aren't being imported into the same place. Maybe I am missing something though, please let me know. But in any case I think you could probably do this in a simpler way.
> 
> It seems to me that what you need to know is whether there is any local that needs to be promoted due to importing somewhere in the target, that has the same name as another global or promoted local anywhere else in the target. We know whether a local is going to be promoted after importing here:
> 
> https://github.com/llvm/llvm-project/blob/f3d81d4110f3415eab3459e07b52043872b9e03b/llvm/lib/LTO/LTO.cpp#L488
> 
> That handling seems like the right place to detect this. Perhaps you could build a string map of name -> VI here, for any value that either originally is non-local, or is promoted in the line I reference above. Whenever you encounter a name already in the map, walk through the VI's summaries and mark them all as needing renaming while marking the new linkage type (and for the one in the map if it hasn't been updated yet).

You are right, my first attempt is not correct as it focus on per module with their import lists. But it is totally possible the same local name may be cross-module used in different functions and this will cause the problem.

Your suggestion in the above should resolve this issue and it is actually simpler. But I have a question below. For

```
  for (auto &S : VI.getSummaryList()) {
    // First see if we need to promote an internal value because it is not
    // exported.
    if (isExported(S->modulePath(), VI)) {
      if (GlobalValue::isLocalLinkage(S->linkage()))
        S->setLinkage(GlobalValue::ExternalLinkage);
      continue;
    }
    ...
  }
```

In the above, do we have to have name promotion for all summaries in the eligible `S->setLinkage(GlobalValue::ExternalLinkage)`? For example, there are 3 cases reaching `S->setLinkage(GlobalValue::ExternalLinkage)`. Can we have 1 case no promotion and the other 2 having name promotions?  For any subsequent VI's having the same name, they will of course all having name promotions.

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


More information about the llvm-commits mailing list