Difference between revisions of "Whole Program Optimization"

From Lazarus wiki
Jump to navigationJump to search
(initial (incomplete) documentation for wpo)
 
m (Fixed typo)
Line 20: Line 20:
 
=How to use=
 
=How to use=
  
First of all, compile your program (or library) and all of its units as you would normally do, except that when compiling the program you add <tt>-FW/path/to/feedbackfile.wpo -OW<selected_wpo_options</tt>. The compiler will then, right after your program has been linked, collect all necessary information to perform the requiested ''wpo''s during a successive compilation run, and store this information in <tt>/path/to/feedbackfile.wpo</tt>
+
First of all, compile your program (or library) and all of its units as you would normally do, except that when compiling the program you add <tt>-FW/path/to/feedbackfile.wpo -OW<selected_wpo_options></tt>. The compiler will then, right after your program has been linked, collect all necessary information to perform the requiested ''wpo''s during a successive compilation run, and store this information in <tt>/path/to/feedbackfile.wpo</tt>
  
 
Next, to actually apply the ''wpo''s, recompile the program and all or some of the units that it uses, using <tt>-Fw/path/to/feedbackfile.wpo -Ow<selected_wpo_options</tt>. The compiler will then read the information collected about the program during the previous compiler run, and use it during the current compilation of units and/or program.
 
Next, to actually apply the ''wpo''s, recompile the program and all or some of the units that it uses, using <tt>-Fw/path/to/feedbackfile.wpo -Ow<selected_wpo_options</tt>. The compiler will then read the information collected about the program during the previous compiler run, and use it during the current compilation of units and/or program.

Revision as of 00:04, 7 December 2008

Overview

Traditionally, compilers optimise a program procedure by procedure, or at best compilation unit per compilation unit. Whole program optimisation (wpo) means that the compiler considers all compilation units that make up a program or library and optimises them using the combined knowledge of how they are used together in this particular case.

The way wpo generally works is as follows:

  • you compile the program normally, telling the compiler to store various bits of information into a feedback file
  • you recompile the program (and optionally all units that it uses) with wpo, providing the feedback file as extra input to the compiler

In some implementations, the compiler generates some kind of intermediary code (e.g., byte code) and the linker performs all wpo along with the translation to the target ISA. In case of FPC however, the scheme followed is the one described above.

wpo is currently only available in the fpc-wpo svn branch. This functionality will be merged to trunk in the foreseeable future.

General principles

A few general principles have been followed when designing the FPC implementation of wpo:

  • All information necessary to generate a wpo feedback file for a program is always stored in the ppu files. This means that you can e.g. use a generic RTL for wpo (even though the RTL itself will then not be optimised, your program and its units can be correctly optimised because the compiler knows everything it has to know about all RTL units);
  • The generated wpo feedback file is plain text. The idea is that it should be easy to inspect this file by hand, and to add information to it produced by external tools if desired (e.g., profile information);
  • The implementation of the wpo subsystem in the compiler is very modular, so it should be easy to plug in additional wpo information providers, or to choose at run time between different information providers for the same kind of information. At the same time, the interaction with the rest of the compiler is kept to a bare minimum to improve maintainability.

How to use

First of all, compile your program (or library) and all of its units as you would normally do, except that when compiling the program you add -FW/path/to/feedbackfile.wpo -OW<selected_wpo_options>. The compiler will then, right after your program has been linked, collect all necessary information to perform the requiested wpos during a successive compilation run, and store this information in /path/to/feedbackfile.wpo

Next, to actually apply the wpos, recompile the program and all or some of the units that it uses, using -Fw/path/to/feedbackfile.wpo -Ow<selected_wpo_options. The compiler will then read the information collected about the program during the previous compiler run, and use it during the current compilation of units and/or program.