Profile Guided Optimization (PGO)

Profile guided optimization (PGO), also known as profile-directed feedback (PDF), is a compiler optimization technique in computer programming that uses profiling to improve program runtime performance. 

PGO is supported in IBM® Open XL Fortran for Linux® on Power® 17.1.1. There are two ways to generate and use profile data. For more information on PGO, refer to the "Profile Guided Optimization" section in Clang documentation. PGO data files generated in IBM Open XL Fortran for Linux on Power 17.1.1 are incompatible with the PDF files of IBM XL Fortran for Linux 16.1.1 or earlier releases.

The cleanpdf, showpdf, and mergepdf commands are replaced by the ibm-llvm-profdata utility in IBM Open XL Fortran for Linux on Power 17.1.1.

Example:
$ cat x.f
program main
   integer i
   read (*, *) i
   if (i > 5) then
      print *, 'i is bigger than 5'
   else
      print *, 'i is <= 5'
   end if
end program

Specify the -qprofile-generate option to instruct the compiler to instrument the code that is being compiled.

$ /opt/ibm/openxlf/17.1.1/bin/xlf95 x.f -Ofast -qprofile-generate
** main   === End of Compilation 1 ===
1501-510  Compilation successful for file x.f.
$ ./a.out 
43
i is bigger than 5
$ ls
a.out  default_15822680647147574778_0.profraw x.f

After the raw profile file is generated, run the ibm-llvm-profdata tool on the raw profile file to make it consumable by the compiler. If you have several raw profile files, use the merge command to combine these raw profile files into one file.


$ /opt/ibm/openxlf/17.1.1/bin/ibm-llvm-profdata merge -o default.profdata default_15822680647147574778_0.profraw
$ ls
a.out default_15822680647147574778_0.profraw default.profdata x.f
Specify the -qprofile-use option to instruct the compiler to optimize the program using the instrumentation data.

$ /opt/ibm/openxlf/17.1.1/bin/xlf95 x.f -Ofast -qprofile-use
** main === End of Compilation 1 ===
1501-510 Compilation successful for file x.f.
$