LTO Overview (GNU Compiler Collection (GCC) Internals) (2024)

Next: LTO file sections, Up: Link Time Optimization [Contents][Index]

25.1 Design Overview

Link time optimization is implemented as a GCC front end for abytecode representation of GIMPLE that is emitted in special sectionsof .o files. Currently, LTO support is enabled in mostELF-based systems, as well as darwin, cygwin and mingw systems.

By default, object files generated with LTO support contain only GIMPLEbytecode. Such objects are called “slim”, and they require thattools like ar and nm understand symbol tables of LTOsections. For most targets these tools have been extended to use theplugin infrastructure, so GCC can support “slim” objects consistingof the intermediate code alone.

GIMPLE bytecode could also be saved alongside final object code ifthe -ffat-lto-objects option is passed, or if no plugin supportis detected for ar and nm when GCC is configured. It makesthe object files generated with LTO support larger than regular objectfiles. This “fat” object format allows to ship one set of fatobjects which could be used both for development and the production ofoptimized builds. A, perhaps surprising, side effect of this featureis that any mistake in the toolchain leads to LTO information notbeing used (e.g. an older libtool calling ld directly).This is both an advantage, as the system is more robust, and adisadvantage, as the user is not informed that the optimization hasbeen disabled.

At the highest level, LTO splits the compiler in two. The first half(the “writer”) produces a streaming representation of all theinternal data structures needed to optimize and generate code. Thisincludes declarations, types, the callgraph and the GIMPLE representationof function bodies.

When -flto is given during compilation of a source file, thepass manager executes all the passes in all_lto_gen_passes.Currently, this phase is composed of two IPA passes:

  • pass_ipa_lto_gimple_outThis pass executes the function lto_output inlto-streamer-out.cc, which traverses the call graph encodingevery reachable declaration, type and function. This generates amemory representation of all the file sections described below.
  • pass_ipa_lto_finish_outThis pass executes the function produce_asm_for_decls inlto-streamer-out.cc, which takes the memory image built in theprevious pass and encodes it in the corresponding ELF file sections.

The second half of LTO support is the “reader”. This is implementedas the GCC front end lto1 in lto/lto.cc. Whencollect2 detects a link set of .o/.a files withLTO information and the -flto is enabled, it invokeslto1 which reads the set of files and aggregates them into asingle translation unit for optimization. The main entry point forthe reader is lto/lto.cc:lto_main.

  • LTO modes of operation

25.1.1 LTO modes of operation

One of the main goals of the GCC link-time infrastructure was to alloweffective compilation of large programs. For this reason GCC implements twolink-time compilation modes.

  1. LTO mode, in which the whole program is read into thecompiler at link-time and optimized in a similar way as if itwere a single source-level compilation unit.
  2. WHOPR or partitioned mode, designed to utilize multipleCPUs and/or a distributed compilation environment to quickly linklarge applications. WHOPR stands for WHOle Program optimizeR (not tobe confused with the semantics of -fwhole-program). Itpartitions the aggregated callgraph from many different .ofiles and distributes the compilation of the sub-graphs to differentCPUs.

    Note that distributed compilation is not implemented yet, but sincethe parallelism is facilitated via generating a Makefile, itwould be easy to implement.

WHOPR splits LTO into three main stages:

  1. Local generation (LGEN)This stage executes in parallel. Every file in the program is compiledinto the intermediate language and packaged together with the localcall-graph and summary information. This stage is the same for boththe LTO and WHOPR compilation mode.
  2. Whole Program Analysis (WPA)WPA is performed sequentially. The global call-graph is generated, anda global analysis procedure makes transformation decisions. The globalcall-graph is partitioned to facilitate parallel optimization duringphase 3. The results of the WPA stage are stored into new object fileswhich contain the partitions of program expressed in the intermediatelanguage and the optimization decisions.
  3. Local transformations (LTRANS)This stage executes in parallel. All the decisions made during phase 2are implemented locally in each partitioned object file, and the finalobject code is generated. Optimizations which cannot be decidedefficiently during the phase 2 may be performed on the localcall-graph partitions.

WHOPR can be seen as an extension of the usual LTO mode ofcompilation. In LTO, WPA and LTRANS are executed within a singleexecution of the compiler, after the whole program has been read intomemory.

When compiling in WHOPR mode, the callgraph is partitioned duringthe WPA stage. The whole program is split into a given number ofpartitions of roughly the same size. The compiler tries tominimize the number of references which cross partition boundaries.The main advantage of WHOPR is to allow the parallel execution ofLTRANS stages, which are the most time-consuming part of thecompilation process. Additionally, it avoids the need to load thewhole program into memory.

LTO Overview (GNU Compiler Collection (GCC) Internals) (2024)
Top Articles
Should You Learn TypeScript? Pros and Cons of TS Explained
Renters’ Rights under the Tenant Protection Act (2024).indd
No Hard Feelings (2023) Tickets & Showtimes
Thor Majestic 23A Floor Plan
Chris Provost Daughter Addie
1970 Chevrolet Chevelle SS - Skyway Classics
Atvs For Sale By Owner Craigslist
Fort Carson Cif Phone Number
South Park Season 26 Kisscartoon
Fully Enclosed IP20 Interface Modules To Ensure Safety In Industrial Environment
Pitt Authorized User
Lycoming County Docket Sheets
Visustella Battle Core
Tamilblasters 2023
Alaska Bücher in der richtigen Reihenfolge
Nier Automata Chapter Select Unlock
George The Animal Steele Gif
Viprow Golf
Condogames Xyz Discord
Highland Park, Los Angeles, Neighborhood Guide
Dirt Removal in Burnet, TX ~ Instant Upfront Pricing
Vrachtwagens in Nederland kopen - gebruikt en nieuw - TrucksNL
Gayla Glenn Harris County Texas Update
Epguides Strange New Worlds
Drift Boss 911
Theater X Orange Heights Florida
Bjerrum difference plots - Big Chemical Encyclopedia
Rochester Ny Missed Connections
Nesb Routing Number
Обзор Joxi: Что это такое? Отзывы, аналоги, сайт и инструкции | APS
Account Now Login In
Is Henry Dicarlo Leaving Ktla
Kaliii - Area Codes Lyrics
How rich were the McCallisters in 'Home Alone'? Family's income unveiled
+18886727547
Kattis-Solutions
Wake County Court Records | NorthCarolinaCourtRecords.us
Ixlggusd
What Time Does Walmart Auto Center Open
Wow Quest Encroaching Heat
How to Play the G Chord on Guitar: A Comprehensive Guide - Breakthrough Guitar | Online Guitar Lessons
Pekin Soccer Tournament
Alston – Travel guide at Wikivoyage
boston furniture "patio" - craigslist
Quick Base Dcps
Sound Of Freedom Showtimes Near Amc Mountainside 10
Pixel Gun 3D Unblocked Games
Tlc Africa Deaths 2021
Wood River, IL Homes for Sale & Real Estate
Marine Forecast Sandy Hook To Manasquan Inlet
Inside the Bestselling Medical Mystery 'Hidden Valley Road'
Sunset On November 5 2023
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 6279

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.