Rate This Document
Findability
Accuracy
Completeness
Readability

Feature Description

Context

Traditional compilation processes, like those using GCC, compile and optimize individual source files (compilation units) into .o files containing assembly code. The linker then resolves symbols and relocates code from these object files to create an executable file. However, while the linker has access to cross-file function call information, it operates on assembly code, limiting its ability to perform optimizations. Other phases that can perform compilation optimization do not have such cross-file global information. This compilation framework, while efficient for incremental compilation, misses optimization opportunities that span multiple files.

LTO Process

Link-time optimization (LTO) highlights optimization at the link time when cross-compilation-unit function call information is available, to provide more optimization opportunities. To achieve this, LTO retains intermediate representation (IR) information needed for optimization to the link time. At the link time, the linker calls an LTO plug-in which performs program-wide analysis, resulting in more effective optimization decisions. The optimized IR is then transformed back into object files containing assembly code, and finally, the linker performs the usual linking process.

Partitioning and Parallelism

LTO often requires longer compilation time due to the need to analyze the global call graph. In some cases, the compilation time of LTO is several times that of non-LTO. To speed up LTO compilation, partitioning is introduced. In partitioning, the global call graph is divided into partitions based on module dependencies. Each partition is optimized independently in parallel, striking a balance between compilation time and optimization effectiveness.