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 C/C++ 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 C/C++ for Linux on Power 17.1.1 are incompatible with the PDF files of IBM XL C/C++ 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 C/C++ for Linux on Power 17.1.1.

Example:
$ cat x.c
#include <stdio.h>
#include <stdlib.h>

int main( int argc, char *argv[] ) {
   long i = strtol(argv[1], NULL, 10);
   if (i > 5)
      printf( "i is bigger than 5\n");
   else
      printf( "i is <= 5\n");
   return 0;
}

To enable PGO instrumentation and instruct the compiler to instrument the code that is being compiled, specify the -fprofile-generate[=<directory>] option. If a directory is specified, the raw profile file is stored in that directory. Otherwise, it is stored in the current directory. The raw profile file is called default_%m.profraw.

$ ibm-clang x.c -Ofast -fprofile-generate
$ ./a.out 
43
i is bigger than 5
$ ls
a.out  default_15822678448124319226_0.profraw  x.c

After the raw profile file is generated, run the ibm-llvm-profdata utility on the raw profile file to make it consumable by the compiler. Note that this step is necessary even when there is only one raw profile, since the merge operation also changes the file format.

$ ibm-llvm-profdata merge -o default.profdata default_15822678448124319226_0.profraw
$ ls
a.out  default_15822678448124319226_0.profraw  default.profdata  x.c
To instruct the compiler to use the instrumentation data to optimize the program, specify the -fprofile-use[=<merge profile file path>] option, where merge profile file path is the file location of the merged profile file. If merge profile file path is a directory or omitted, the name of the merged profile file is assumed to be default.profdata.
$ ibm-clang x.c -Ofast -fprofile-use
$