Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: Enable LTO and multiple codegen units #44783

Closed

Commits on Sep 30, 2017

  1. rustc: Enable LTO and multiple codegen units

    This commit is a refactoring of the LTO backend in Rust to support compilations
    with multiple codegen units. The immediate result of this PR is to remove the
    artificial error emitted by rustc about `-C lto -C codegen-units-8`, but longer
    term this is intended to lay the groundwork for LTO with incremental compilation
    and ultimately be the underpinning of ThinLTO support.
    
    The problem here that needed solving is that when rustc is producing multiple
    codegen units in one compilation LTO needs to merge them all together.
    Previously only upstream dependencies were merged and it was inherently relied
    on that there was only one local codegen unit. Supporting this involved
    refactoring the optimization backend architecture for rustc, namely splitting
    the `optimize_and_codegen` function into `optimize` and `codegen`. After an LLVM
    module has been optimized it may be blocked and queued up for LTO, and only
    after LTO are modules code generated.
    
    Non-LTO compilations should look the same as they do today backend-wise, we'll
    spin up a thread for each codegen unit and optimize/codegen in that thread. LTO
    compilations will, however, send the LLVM module back to the coordinator thread
    once optimizations have finished. When all LLVM modules have finished optimizing
    the coordinator will invoke the LTO backend, producing a further list of LLVM
    modules. Currently this is always a list of one LLVM module. The coordinator
    then spawns further work to run LTO and code generation passes over each module.
    
    In the course of this refactoring a number of other pieces were refactored:
    
    * Management of the bytecode encoding in rlibs was centralized into one module
      instead of being scattered across LTO and linking.
    * Some internal refactorings on the link stage of the compiler was done to work
      directly from `CompiledModule` structures instead of lists of paths.
    * The trans time-graph output was tweaked a little to include a name on each
      bar and inflate the size of the bars a little
    alexcrichton committed Sep 30, 2017
    Configuration menu
    Copy the full SHA
    ded38db View commit details
    Browse the repository at this point in the history