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. 

Important: IBM® Open XL Fortran for AIX® 17.1.2 supports the following operating systems:
  • IBM AIX 7.2: TL5 SP3 or later
  • IBM AIX 7.3: TL0 or later

However, to use PGO, your operating system must be IBM AIX 7.2 TL5 SP5 or later, or IBM AIX 7.3 TL1 or later.

If you use PGO on IBM AIX 7.2 TL5 SP4 or earlier, or IBM AIX 7.3 TL0 SP1 or earlier, you might encounter the following errors:
  • A segmentation fault when using the ibm-llvm-profdata utility:
    
    PLEASE submit a bug report to https://ibm.biz/openxlf-support and include the crash backtrace. 
    Stack dump: 
    0. Program arguments: /opt/IBM/openxlf/17.1.2/bin/ibm-llvm-profdata "ibm-llvm-profdata merge" -o default.profdata 
    default_15853201381331839107_0.profraw Location 0x0000e944 
    
    --- End of call chain --- 
    Segmentation fault(coredump)
    
  • Undefined symbols when linking:
    
    ld: 0711-317 ERROR: Undefined symbol: __start___llvm_prf_cnts
    ld: 0711-317 ERROR: Undefined symbol: __stop___llvm_prf_cnts
    ld: 0711-317 ERROR: Undefined symbol: __start___llvm_prf_data
    ld: 0711-317 ERROR: Undefined symbol: __stop___llvm_prf_data
    ld: 0711-317 ERROR: Undefined symbol: __stop___llvm_prf_names
    ld: 0711-317 ERROR: Undefined symbol: __start___llvm_prf_names
    ld: 0711-317 ERROR: Undefined symbol: __stop___llvm_prf_vnds
    ld: 0711-317 ERROR: Undefined symbol: __start___llvm_prf_vnds
  • Linker errors:
    ld: 0711-151 SEVERE ERROR: SETOPT: Invalid option name: NAMEDSECTS:ss

PGO is supported in IBM Open XL Fortran for AIX 17.1.2. 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 AIX 17.1.2 are incompatible with the PDF files of IBM XL Fortran for AIX 16.1.0 or earlier releases.

The cleanpdf, showpdf, and mergepdf commands are replaced by the ibm-llvm-profdata utility in IBM Open XL Fortran for AIX 17.1.2.

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.2/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.2/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.2/bin/xlf95 x.f -Ofast -qprofile-use
** main === End of Compilation 1 ===
1501-510 Compilation successful for file x.f.
$

For the detailed usage of the -qprofile-generate and -qprofile-use options, refer to -qprofile-generate and -qprofile-use.

Note: If the file directories specified in the -qprofile-generate and -qprofile-use options are different, specify the -mllvm -static-func-full-module-prefix=false option if you need to map counters to static functions.