[CMake] PGO (Profile Guided Optimization)

Jan Wielemaker jan at swi-prolog.org
Tue Oct 30 04:20:09 EDT 2018


Hi,

I was wondering whether there is a module or skeleton floating around to
deal with Profile Guided Optimization using a cmake build. If this rings
a bell you probably know the sequence (assuming GCC):

   - compile using -fprofile-generate
   - run a benchmark suite, this generates .gcda files for each object,
     which may be placed in a different directory.
   - recompile using -fprofile-use

Targetting Ninja, I now use a shell-script that performs

   - ninja -t clean my-target
   - cmake -DPROFILE_GUIDED_OPTIMIZATION=GENERATE ..
   - ninja my-target
   - <run benchmark>
   - cmake -DPROFILE_GUIDED_OPTIMIZATION=USE ..
   - ninja -t clean my-target
   - ninja my-target

Where my-target is the time critical sub-project and
PROFILE_GUIDED_OPTIMIZATION is picked up by cmake and sets the compile
and link flags for the affected targets.

This isn't nice. I guess that ideally I'd have a separate build
subdirectory that always uses -fprofile-generate and the main build dir
using -fprofile-use. Does that make sense? Is there an
example/module/...?

	Thanks --- Jan


More information about the CMake mailing list