I’ve been looking into the LLVM build times, and in particular the build time of runtimes (compiler-rt, libunwind, libc++abi, libc++) and I’ve noticed that we spend a lot of time in CMake checks. In fact, at least in the case of our (Fuchsia) toolchain build, we spend more time running CMake checks than actually building the runtimes.
There are two main reasons:
- First, we use a lot of checks, some of which may be unnecessary. This was already brought up a few times in the past and we should do an audit of all the checks we use and eliminate the unnecessary ones.
- Second, we duplicate a lot of checks. For example, every runtime checks whether the compiler supports -nostdlib++, but because each runtime uses a different variable to hold the result, there’s no caching and we run that check once for each runtime.
I think the second issue can be solved by simply unifying the names of variables that are used for results of CMake checks. That is, instead of LIBUNWIND_SUPPORTS_NOSTDLIBXX_FLAG, LIBCXXABI_SUPPORTS_NOSTDLIBXX_FLAG, LIBCXX_SUPPORTS_NOSTDLIBXX_FLAG, etc. we would use CXX_SUPPORTS_NOSTDLIBXX_FLAG across all runtimes.
This would let CMake reuse the value of the previous check, so even if every runtime does this check, we are only going to execute the check once. If you build each runtime separately, this should have no impact.
I have a work-in-progress change https://reviews.llvm.org/D110005 that unifies many but not all of the checks and the improvement is already noticeable. In the case of our toolchain, the total build time went from 6m:10s to 5m:20s and I believe it can be further improved.
Do you think that this would be a worthwhile change? Can you think of any issues with this approach?
An open question is what naming scheme to use. In the change mentioned above, I followed the convention that’s used by LLVM which is:
C_SUPPORTS_ for the result of check_c_compiler_flag
CXX_SUPPORTS_ for the result of check_cxx_compiler_flag
HAVE_ for the result of check_library_exists
Do you have any other suggestions or preferences?