[lld] [llvm] [LLVM][LTO] Factor out RTLib calls and allow them to be dropped (PR #98512)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 13:17:49 PDT 2024


jhuber6 wrote:

> > So it will always be extracted from a static archive even if it's unused because it thinks the backend needs it.
> 
> If the function in the archive is compiled code, this should be cheap, so it doesn't really matter. If it's bitcode, LTO isn't really architected to handle it. I don't think we'd want to modify the way symbol lookup works. Maybe we can pull the bitcode files into the link, but delay actually compiling them until we know whether they're actually necessary. Or we can examine the bitcode inputs in more detail to determine which functions they can actually call.

This code only applies if the input is LLVM-IR bitcode, see the `lld` changes. Extracting them unconditionally is the current "solution" and this doesn't really change anything about how that works, just limits the scope of symbols it looks at. I think the only other way to handle this would be to somehow link the library twice, once before the backend and once after the backend. That would require rechecking the symbol table after the LTO pass to see if any new symbols appeared, which would probably be expensive since we'd then need to do LTO extraction *again*.
> 
> Some examples of heuristics we could use:
> 
>     * query target features for whether some specific operation needs to be emulated
> 
>     * scan the module for declarations of math intrinsics
> 
> 
> This patch doesn't address any of that, though; it just ensures that the linker agrees with the LLVM backend about which functions should actually be treated as "runtime functions" for a given triple (i.e. functions which can be called by the LLVM backend even if they aren't referenced in the IR), as opposed to using the same set for every triple.

This patch doesn't change anything about the existing solution, it just limits the number of libcalls it checks so that targets like `AMDGPU` can get away with doing LTO linking without these functions always being extracted even though they're not used by the backend.


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


More information about the llvm-commits mailing list