Interprocedural Optimization

Let's learn about optimization in compiler and compiler features in CMake.

Usually, compilers optimize the code on the level of a single translation unit, which means that our .cpp file will be preprocessed, compiled, and then optimized. Later, these files will be passed to the linker to build a single binary. Modern compilers can perform optimization after linking (this is called link time optimization) so that all compilation units can be optimized as a single module. If our compiler supports interprocedural optimizationCompiler techniques to improve performance in programs containing many frequently used functions by analyzing the entire program. Its purpose is to remove duplicate calculations, to limit inefficient use of memory, and to simplify iterative code., it may be a good idea to use it. We'll follow the same method as previously. The default variable for this setting is called CMAKE_INTERPROCEDURAL_OPTIMIZATION. But before we set it, we need to make sure it is supported to avoid errors:

Get hands-on with 1400+ tech skills courses.