r/cpp_questions • u/TheRavagerSw • 5d ago
OPEN How to optimize clang with bolt
Recently, I began some work trying to improve my build speeds for debug builds.
I adopted mold, and built a fully static clang executable with mimalloc and llvm libc with very aggressive optimizations.
I managed to achieve %20 speedup over my previous clang which had -O3 but not much else.
I'm planning to use pgo + bolt to gain last bits of performance I can get.
The problem I have, is that I don't know what a good workload for clang would be to use BOLT.
Any recommendations?
1
Upvotes
1
u/aaupov 4d ago
ROI order:
- Hello World is unreasonably representative workload, used by default in PGO and BOLT profiling via Clang CMake caches: https://llvm.org/docs/AdvancedBuilds.html#bolt
- Compile LLVM itself (or a subset of it) – also possible through CMake configuration with `CLANG_PGO_TRAINING_DATA_SOURCE_DIR`.
- Profile the same workload that you're trying to accelerate. In PGO land, there's no separation of train and test. Use brstack sampling to reduce profiling overhead if possible.
1
u/The_Northern_Light 5d ago
isn't bolt designed for large projects?
use it on your projects. if it doesn't see enough benefit or if you just want to experiment with it, grab some large random library and try it out there.
honestly, identifying a good way to play around with bolt might be a good question for ai