Hi,
We would like to add a caching system, similar to ThinLTO’s, for FullLTO’s parallel codegen feature.
Proposed Changes
Add a system that caches the output of TargetMachine::splitModule in LTOBackend.cpp:splitCodeGen.
This would be implemented the same way as the ThinLTO cache and reuse the same component (Support/Caching.h, Support/CachePruning.h). The main piece that is missing is how to get a stable module hash (see “Challenges” below).
Reasoning
This is very desirable for the AMDGPU backend, as the backend portion of the compiler is by far the most expensive (it’s generally where 2/3rds of the time is spent after the front-end, more in pathological cases). We are looking to optimize the backend in parallel, but that is a continuous effort with little low-hanging fruits left. AMDGPU is a very complex target, and the large amount of registers we have slow down RegisterCoalescer and RegAlloc quite a bit.
Another factor that does not help is that AMDGPU requires “whole module” compilation: we have to be able to see all functions called by a kernel to build the module. Thus, modules can get quite large (dozens if not hundreds of MBs in some cases), either due to the application’s structure, or because -fgpu-rdc (which enables Full LTO) is required. This is also something that we’re tracking, there are ongoing efforts to enable machine linking or maybe thin LTO (though neither of these are confirmed or have an ETA).
AMDGPUSplitModule was introduced fairly recently to help with big modules when using -fgpu-rdc, and it proved quite successful at that. We now propose enabling caching of module splitting results because it’s a fairly non-intrusive change that really helps in real-world scenarios, especially in the case of small incremental changes.
Challenges
How can we create stable LLVM IR module hashes for caching ? I believe the easiest way is to print the LLVM IR to a string and hash it, but I wonder if we could have issues with things like commit SHAs or module IDs constantly changing, and I am not sure how we could address that.
Thanks