Skip to content

Use LTO for LLVM AOT to avoid the need for code generation in iree-opt/iree-translate #3736

Open

Description

@benvanik

Today we are generating native object .o files (x86/arm/etc) that we then pass out to the linker (lld/ld/link) - that means we need to be able to generate those native object files with the IREE binary and as such have to bring in all target backends (ARM/x86/wasm/etc) we want to support to our binary. Instead, using LTO lets us write LLVM bitcode files (the .o files we emit would just be .bc with a different extension) and then have the linker perform the actual code generation. Especially in cases where we will be statically linking our generated files together with other files (potentially other IREE outputs or user code) using LTO will give us critical benefits (deduping across all models compiled into the same binary, etc) but also mean that we can drop our iree-opt/iree-translate binary sizes/compile time by a significant amount.

LTO is compatible with lld and gold (with a plugin) on both linux and mac and I believe lld-link on Windows. We could keep the non-LTO path available as a CMake option for incompatible linkers (MSVC link, weird vendor linkers, etc) but strip it all out in most of our builds.

https://llvm.org/docs/LinkTimeOptimization.html

This post has good info: http://johanengelen.github.io/ldc/2016/11/10/Link-Time-Optimization-LDC.html (including how to work on linux/mac with gold and lld), and their linked PR has a lot of the LLVM object file manipulation we'd need: https://github.com/ldc-developers/ldc/pull/1840/files

This would entail:

  • manually verify by tweaking LLVMAOTTarget.cpp which targets support it
  • add an LTO cmake option and do not link in/include x86/arm/etc backends when enabled
  • make LLVMAOTTarget.cpp use the cmake option (by way of a define) to choose how it emits object files (as writing LLVM bitcode and naming it a .o or by actually writing native object files)

Activity

  1. added
    help wanted
    compiler/dialects
    codegen
    performance ⚡
    on Nov 5, 2020
  2. benvanik commented on Nov 5, 2020

    @benvanik
    CollaboratorAuthor

    Basically, I want these to be an order of magnitude smaller :)
    image

  3. benvanik commented on Nov 20, 2020

    @benvanik
    CollaboratorAuthor

    Note that we need full LTO, not thin LTO. Thin LTO is useful if linking thousands of compilation units (and is akin to Microsoft's incremental linking (those .ilk files in the above screenshot); we are linking one file and want it to be as small/fast/etc as possible :)

    relevant: rust-lang/rust#47745

    good watch: https://www.youtube.com/watch?v=p9nH2vZ2mNo

  4. moved this from Not Started to Backlog in (Deprecated) IREEon May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegencompiler/dialectshelp wantedperformance ⚡

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions