Link Time Optimization (LTO)
The Link Time Optimization (LTO) feature is supported in IBM® Open XL Fortran for AIX® 17.1.3.
The LTO information generated by IBM Open XL
Fortran for AIX 17.1.3 is
incompatible with the Interprocedural Analysis (IPA) information of IBM XL Fortran for AIX 16.1.0 in the
following aspects:
- The IPA information in object files that are created by IBM XL Fortran for AIX 16.1.0 or earlier releases is silently ignored by IBM Open XL Fortran for AIX 17.1.3.
- Object files that are created by IBM XL Fortran for AIX 16.1.0 or earlier releases using the -qipa=noobject option contain only IPA information, so they are unusable in IBM Open XL Fortran for AIX 17.1.3.
- By default, object files that are created by IBM Open XL Fortran for AIX 17.1.3 using the -qlto option are not readable by IBM XL Fortran for AIX 16.1.0 or earlier releases.
To compile a program with LTO, specify the
-qlto option on both the
compile and link steps:
- When -qlto is specified on the compile step, the compiler generates LLVM IR instead of object code, in preparation for LTO on the link step.
- When -qlto is
specified on the link step, the compiler adds extra linker options such as
-bplugin:<path-to-libLTO.so> when
invoking the linker. The linker can handle a mixture of native XCOFF objects and LLVM IR objects,
and then invokes the LTO optimizations on the
LLVM IR objects via the
libLTO.soplugin. You can pass LLVM options such as -save-temps and -print-after-all to thelibLTO.soplugin through the -Wl,-bplugin_opt option; for example, -Wl,-bplugin_opt:-print-after-all. Specify --help and --help-hidden to see the full list of LLVM options that can be passed tolibLTO.so.
Attention:
- Pay attention to the system requirements when using LTO:
Table 1. System requirements of LTO Feature Minimum requirement for AIX 7.2 Minimum requirement for AIX 7.3 -qlto AIX 7.2 TL5 SP51 AIX 7.3 TL11 -qfat-lto-objects AIX 7.2 TL5 SP5 AIX 7.3 TL1 -qlto=thin AIX 7.2 TL5 SP7 AIX 7.3 TL2 Notes:- LTO is also supported on IBM AIX 7.2 TL5 SP4 or earlier, and IBM AIX 7.3 TL0 SP2 or earlier; however, note that non-default visibility symbols defined in the objects that are compiled with -qlto are not necessarily retained to satisfy references from the objects that are compiled without -qlto during linking.
- When both the -qlto and -qfat-lto-objects options are specified, object files that are created by IBM Open XL Fortran for AIX 17.1.3 are readable by IBM XL Fortran for AIX 16.1.0 and earlier releases, but the LTO information embedded in the object files is silently ignored.
Detecting LTO usage in object files
LTO works by storing LLVM bit code, which describes the program, into object files at the compile step. During the link step, the LLVM bitcode is used to perform link-time optimization.
Detecting LTO enablement in non-fat LTO object files
By default, if a source file is compiled with the -qlto option, only LLVM bitcode is stored into the object file. You can
identify files built this way using the following file command, which identifies the object file as
an LLVM IR bitcode file:
file file.o
file.o: LLVM IR bitcodeDetecting LTO enablement in fat LTO object files
If a source file is compiled with both the -qlto and -qfat-lto-objects options, the resulting object file is an XCOFF object
file that contains both native object code and LLVM bitcode. The LLVM bitcode is stored in the
.info section of the XCOFF object file and is labeled with
LLVMLTO. You can identify files built this way using the following file command:
strings -a file.o | grep 'LLVMLTO'
LLVMLTO
Alternatively, you can disassemble the object file and look for
LLVMLTO in the
.info section. Here is an example of a disassembled .info section
that contains LTO information:/opt/IBM/openxlf/17.1.3/exe/ibm-llvm-objdump --section=.info --full-contents file.o
Contents of section .info:
0000 ffffffff 00000000 00000aa4 4c4c564d ............LLVM
0010 4c544f00 00000018 4243c0de 35140000 LTO.....BC..5...
Note: If the object file does not contain LTO information, the ibm-llvm-objdump
utility either issues a warning message indicating the object file does not contain a
.info section or displays a .info section that does not contain
LLVMLTO.Detecting LTO during linking
To detect whether LTO occurs at link time, use one of the following methods:
- Specify the -bloadmap:<filename> or
-bnoquiet option during the link step, and look for
ltoin the output. All object files that participated in LTO will be displayed. - Specify the -bmap:<filename> option
during the link step, and look for
ld-temp.oin the generated file. Ifld-temp.ois found, it indicates some source files were compiled using -qlto, and their corresponding object files participated in LTO.