Handling Command-Line Options in LTO
Design Considerations
This design is driven by a simple key observation:
- If a build uses -flto on at least 1 input file, but has all LTO optimizations turned off, then this build should result in an identical binary as one built without -flto
Minor observations are:
- Depending on the LTO model, individual functions may move from one IR file to another.
- Command-line options may conflict in an LTO build.
Function Level Attributes
Depending on the LTO model, individual functions may move around from one IR file to another. This allows two design choices:
- Functions have the information from command-line options which didn't directly manifest in the IR available as function attributes. For example, fp relaxation rules are consumed by various backend optimizations, but have no representation in the IR itself.
- Do not move around (or inline) functions between files, if they have conflicting option settings. For example, do not inline a routine compiled with strict fp rules into a function with relaxed fp. Allow the other way round.
Option 2 appears simpler to implement and understand.
In regards to Option 1, specifying options explicitly for a function should be implemented, as it would allow building up more sophisticated infrastructure for exploratory search for performance potential, as well as automated bug triaging.
In the following, this assumes that function level attributes can be specified explicitly, and that such specification overrides other settings.
File Attributes
The command line options used to compile a whole file should additionally be stored in the resulting IR file, see below. Accessor functions to the actual string should be provided, as the options might need to be copied to the LTRANS invocations later.
Conflicting Command Line Options
Command-line options may conflict. If one IR file was compiled with -O2 and one with -O3, which optimization level should LTO use? Which optimization level should be used by LTRANS?
The rules for WPA
- use the default option setting, e.g. optimization level 4, any other assumptions. TODO: Specify these assumptions.
- Use the "special" options from the first, pivot input file. These options are stored in the object file (see above). For example, if -O2 was used in this first, pivot file, the optimization level for IPA should be 2.
- If additional command line options are passed to WPA, these settings override both the default and the file level settings.
- Function level options are ignored to control WPA's settings, however, individual transformations (inlining) might need to consult these options and will potentially bail on conflicts. It is usually up to the transformation to decide which set of options is to be considered incompatible.
The rules for LTRANS
- use default option settings.
- If special options were use to compile a file in LGEN, pass these options to LTRANS. This can be done via the parallel backend mechanism described in the driver design document.
- If multiple IR files are being passed to LTRANS, pick the options from the first, pivot file.
- If function level options were specified, use those for a given function.