Profile-directed feedback is a two-stage compilation process that lets you provide the compiler with data characteristic of typical program behavior. An instrumented executable is run in a number of different scenarios for an arbitrary amount of time, producing as a side effect a profile data file. A second compilation using the profile data produces an optimized executable.
PDF should be used mainly on code that has rarely executed conditional error handling or instrumentation. The technique has a neutral effect in the absence of firm profile information, but is not recommended if insufficient or uncharacteristic data is all that is available.
The following diagram illustrates the PDF process.
The two stages of the process are controlled by the compiler options -qpdf1 and -qpdf2. Stage 1 is a regular compilation using an arbitrary set of optimization options and -qpdf1, that produces an executable or shared object that can be run in a number of different scenarios for an arbitrary amount of time. Stage 2 is a recompilation using the same options, except -qpdf2 is used instead of -qpdf1, during which the compiler consumes previously collected data for the purpose of path-biased optimization.
You can optimize an application based on an analysis of how often it executes different sections of code, as follows:
If you want to see which functions are used the most often, do the following:
You can take more control of the PDF file generation, as follows:
mergepdf -r 53 path1 -r 32 path2 -r 15 path3
To erase the information in the PDF directory, use the cleanpdf or resetpdf utility.
The -qpdf option helps to fine-tune the areas around conditional branches so that the default choices correspond to the most likely execution paths. Sometimes instructions from the more likely execution path run before the branch, in parallel with other instructions so that there is no slowdown.
Because the -qpdf option requires some extra compilation overhead and sample execution that uses representative data, you should use it mainly near the end of the development cycle.