Skip to content

Integrated Distributed ThinLTO (DTLTO): Design Overview #126654

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

bd1976bris
Copy link
Collaborator

@bd1976bris bd1976bris commented Feb 11, 2025

Initial DTLTO Support

This PR introduces initial support for Integrated Distributed ThinLTO (DTLTO). DTLTO was previously discussed in an RFC and during the LTO roundtable discussion at the October US 2024 LLVM conference. PlayStation has offered this feature as a proprietary technology for some time, and we would like to see support in LLVM.

Overview of DTLTO

DTLTO enables the distribution of backend ThinLTO compilations via external distribution systems, such as Incredibuild. Existing support for distributing ThinLTO compilations typically involves separate thin-link (--thinlto-index-only), backend compilation, and link steps coordinated by a modern build system, like Bazel. This "Bazel-style" distributed ThinLTO requires a modern build system as it must handle the dynamic dependencies specified in the summary index file shards. However, adopting a modern build system can be prohibitive for users with established build infrastructure.

In contrast, DTLTO manages distribution within LLVM during the traditional link step. This approach means that DTLTO is usable with any build process that supports in-process ThinLTO.

Documentation and Resources

Features of This Initial Commit

This commit provides a minimal but functional implementation of DTLTO, which will be expanded in subsequent commits. The current implementation includes:

  • COFF and ELF support.
  • Support for bitcode members in thin archives.
  • Basic support for distributing backend ThinLTO compilations.
  • A JSON interface that allows new distribution systems to be supported without modifying LLVM.

The goal of this initial commit is to demonstrate what will be required to support DTLTO while providing useful minimal functionality. Hopefully, having a concrete PR will facilitate discussion and review of the feature.

Performance

We have access to a large farm of computers on Windows. For a link of clang.exe on a modest Windows development machine (AMD64 16 cores, 64GB RAM) DTLTO (via sn-dbs.py) was approximately 4 times as fast as multi-threaded in-process ThinLTO.

To estimate the overhead from DTLTO vs in-process ThinLTO, we measured the difference in the time taken to link Clang with in-process ThinLTO using one thread per core, and DTLTO using one local process per core. On both Windows and Linux the overhead was approximately 6%.

Note that, to facilitate review, this PR elides performance optimizations where possible.

Planned Future Enhancements

The following features will be addressed in future commits:

  • Support for the ThinLTO cache.
  • Support for (non-thin) archives/libraries containing bitcode members.
  • Support for more LTO configuration states e.g., basic block sections.
  • Performance improvements. For example, improving the performance of the temporary file removal.

Discussion Points

  • Feature Name: The DTLTO name could potentially cause confusion with the existing Bazel-style distributed ThinLTO. At the LLVM roundtable discussion no one objected to the name, but we remain open to suggestions.
  • Backend Compilation Configuration: Currently, Clang is invoked to do the backend compilations and a minimal number of options are added to the Clang command line to ensure that the codegen is reasonable (for the testing we have done so far). However, it would be good to find a scalable solution for matching the code-generation state in the invoked external tool to the code-generation state if an in-process ThinLTO backend was in use.
  • Clang Error Handling: There is some precedent for compiler drivers handling options that only apply to specific linkers. Should Clang emit an error if DTLTO options are used and the linker isn't LLD?

Other approaches

We have experimented with other approaches for implementing DTLTO. In particular we have explored:

  • Not using a new ThinLTO backend.
  • Various ways to handle (non-thin) archives.
  • Use of dynamic library plugins instead of processes.

We have prepared another branch to demonstrate some of these ideas: integrated-DTLTO-no-backend

List of Child PRs:

(I intend to update this section as new PRs are filed.)

@llvmbot llvmbot added clang Clang issues not falling into any other category lld clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' lld:MachO lld:ELF lld:COFF lld:wasm platform:windows LTO Link time optimization (regular/full LTO or ThinLTO) llvm:support llvm:transforms labels Feb 11, 2025
@llvmbot

This comment was marked as spam.

@llvmbot

This comment was marked as spam.

Copy link

github-actions bot commented Feb 11, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@bd1976bris
Copy link
Collaborator Author

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
View the diff from clang-format here.

I believe this failure is OK as I have followed the (non-standard) formatting in the flagged file which the code for the other ThinLTO backends use.

bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 4, 2025
This patch introduces support for Integrated Distributed ThinLTO
(DTLTO) in ELF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

It is expected that users will invoke DTLTO through the compiler
driver (e.g., Clang) rather than calling LLD directly. A Clang-side
interface for DTLTO will be added in a follow-up patch.

Note: Bitcode members of non-thin archives are not currently
supported. This will be addressed in a future change.

Testing:
- ELF LLD `lit` test coverage has been added, using a mock distributor
  to avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see:
llvm#126654
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 4, 2025
This patch introduces support for Integrated Distributed ThinLTO
(DTLTO) in ELF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

It is expected that users will invoke DTLTO through the compiler
driver (e.g., Clang) rather than calling LLD directly. A Clang-side
interface for DTLTO will be added in a follow-up patch.

Note: Bitcode members of non-thin archives are not currently
supported. This will be addressed in a future change.

Testing:
- ELF LLD `lit` test coverage has been added, using a mock distributor
  to avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see:
llvm#126654
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 4, 2025
This patch introduces support for Integrated Distributed ThinLTO
(DTLTO) in ELF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

It is expected that users will invoke DTLTO through the compiler
driver (e.g., Clang) rather than calling LLD directly. A Clang-side
interface for DTLTO will be added in a follow-up patch.

Note: Bitcode members of non-thin archives are not currently
supported. This will be addressed in a future change.

Testing:
- ELF LLD `lit` test coverage has been added, using a mock distributor
  to avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see:
llvm#126654
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 4, 2025
This patch introduces support for Integrated Distributed ThinLTO
(DTLTO) in ELF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

It is expected that users will invoke DTLTO through the compiler
driver (e.g., Clang) rather than calling LLD directly. A Clang-side
interface for DTLTO will be added in a follow-up patch.

Note: Bitcode members of non-thin archives are not currently
supported. This will be addressed in a future change.

Testing:
- ELF LLD `lit` test coverage has been added, using a mock distributor
  to avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see:
llvm#126654
@bd1976bris
Copy link
Collaborator Author

bd1976bris commented Jun 4, 2025

I have put a PR for introducing support for Integrated Distributed ThinLTO (DTLTO) in ELF LLD: #142757. Once that's merged I will follow up with PRs for adding DTLTO support to Clang and adding DTLTO support to COFF LLD.

bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 6, 2025
This patch introduces support for Integrated Distributed ThinLTO
(DTLTO) in ELF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

It is expected that users will invoke DTLTO through the compiler
driver (e.g., Clang) rather than calling LLD directly. A Clang-side
interface for DTLTO will be added in a follow-up patch.

Note: Bitcode members of non-thin archives are not currently
supported. This will be addressed in a future change.

Testing:
- ELF LLD `lit` test coverage has been added, using a mock distributor
  to avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see:
llvm#126654
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 15, 2025
This patch introduces support for Integrated Distributed ThinLTO
(DTLTO) in ELF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

It is expected that users will invoke DTLTO through the compiler
driver (e.g., Clang) rather than calling LLD directly. A Clang-side
interface for DTLTO will be added in a follow-up patch.

Note: Bitcode members of non-thin archives are not currently
supported. This will be addressed in a future change.

Testing:
- ELF LLD `lit` test coverage has been added, using a mock distributor
  to avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see:
llvm#126654
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 15, 2025
This patch introduces support for Integrated Distributed ThinLTO
(DTLTO) in ELF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

It is expected that users will invoke DTLTO through the compiler
driver (e.g., Clang) rather than calling LLD directly. A Clang-side
interface for DTLTO will be added in a follow-up patch.

Note: Bitcode members of non-thin archives are not currently
supported. This will be addressed in a future change.

Testing:
- ELF LLD `lit` test coverage has been added, using a mock distributor
  to avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see:
llvm#126654
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 18, 2025
This patch introduces support for Integrated Distributed ThinLTO
(DTLTO) in ELF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

It is expected that users will invoke DTLTO through the compiler
driver (e.g., Clang) rather than calling LLD directly. A Clang-side
interface for DTLTO will be added in a follow-up patch.

Note: Bitcode members of archives (both thin and non-thin) are not
currently supported. This will be addressed in a future change.

Testing:
- ELF LLD `lit` test coverage has been added, using a mock distributor
  to avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see:
llvm#126654
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 18, 2025
This patch introduces support for Integrated Distributed ThinLTO
(DTLTO) in ELF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

It is expected that users will invoke DTLTO through the compiler
driver (e.g., Clang) rather than calling LLD directly. A Clang-side
interface for DTLTO will be added in a follow-up patch.

Note: Bitcode members of archives (both thin and non-thin) are not
currently supported. This will be addressed in a future change.

Testing:
- ELF LLD `lit` test coverage has been added, using a mock distributor
  to avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see:
llvm#126654
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 24, 2025
…tent

A thin archive is an archive/library format where the archive itself
contains only references to member object files on disk, rather than
embedding the file contents.

For the non-/wholearchive case, we use the path to the archive member
as the identifier for thin-archive members (see comments in
`enqueueArchiveMember`). This patch modifies the /wholearchive path to
behave the same way.

Apart from consistency, my motivation for fixing this is DTLTO
(llvm#126654), where having the
member identifier be the path on disk allows distribution of bitcode
members during ThinLTO.
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 24, 2025
…tent

A thin archive is an archive/library format where the archive itself
contains only references to member object files on disk, rather than
embedding the file contents.

For the non-/wholearchive case, we use the path to the archive member
as the identifier for thin-archive members (see comments in
`enqueueArchiveMember`). This patch modifies the /wholearchive path to
behave the same way.

Apart from consistency, my motivation for fixing this is DTLTO
(llvm#126654), where having the
member identifier be the path on disk allows distribution of bitcode
members during ThinLTO.

(cherry picked from commit 0a670a3)
Signed-off-by: Dunbobbin <[email protected]>
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 24, 2025
…tent

A thin archive is an archive/library format where the archive itself
contains only references to member object files on disk, rather than
embedding the file contents.

For the non-/wholearchive case, we use the path to the archive member
as the identifier for thin-archive members (see comments in
`enqueueArchiveMember`). This patch modifies the /wholearchive path to
behave the same way.

Apart from consistency, my motivation for fixing this is DTLTO
(llvm#126654), where having the
member identifier be the path on disk allows distribution of bitcode
members during ThinLTO.
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 24, 2025
…tent

A thin archive is an archive/library format where the archive itself
contains only references to member object files on disk, rather than
embedding the file contents.

For the non-/wholearchive case, we use the path to the archive member
as the identifier for thin-archive members (see comments in
`enqueueArchiveMember`). This patch modifies the /wholearchive path to
behave the same way.

Apart from consistency, my motivation for fixing this is DTLTO
(llvm#126654), where having the
member identifier be the path on disk allows distribution of bitcode
members during ThinLTO.
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 24, 2025
…tent

A thin archive is an archive/library format where the archive itself
contains only references to member object files on disk, rather than
embedding the file contents.

For the non-/wholearchive case, we use the path to the archive member
as the identifier for thin-archive members (see comments in
`enqueueArchiveMember`). This patch modifies the /wholearchive path to
behave the same way.

Apart from consistency, my motivation for fixing this is DTLTO
(llvm#126654), where having the
member identifier be the path on disk allows distribution of bitcode
members during ThinLTO.
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 24, 2025
…tent

A thin archive is an archive/library format where the archive itself
contains only references to member object files on disk, rather than
embedding the file contents.

For the non-/wholearchive case, we use the path to the archive member
as the identifier for thin-archive members (see comments in
`enqueueArchiveMember`). This patch modifies the /wholearchive path to
behave the same way.

Apart from consistency, my motivation for fixing this is DTLTO
(llvm#126654), where having the
member identifier be the path on disk allows distribution of bitcode
members during ThinLTO.
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jun 25, 2025
…tent

A thin archive is an archive/library format where the archive itself
contains only references to member object files on disk, rather than
embedding the file contents.

For the non-/wholearchive case, we use the path to the archive member
as the identifier for thin-archive members (see comments in
`enqueueArchiveMember`). This patch modifies the /wholearchive path to
behave the same way.

Apart from consistency, my motivation for fixing this is DTLTO
(llvm#126654), where having the
member identifier be the path on disk allows distribution of bitcode
members during ThinLTO.
bd1976bris added a commit that referenced this pull request Jul 2, 2025
…2757)

This patch introduces support for Integrated Distributed ThinLTO (DTLTO)
in ELF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

It is expected that users will invoke DTLTO through the compiler driver
(e.g., Clang) rather than calling LLD directly. A Clang-side interface
for DTLTO will be added in a follow-up patch.

Note: Bitcode members of archives (thin or non-thin) are not currently
supported. This will be addressed in a future change. As a consequence
of this lack of support, this patch is not sufficient to allow for
self-hosting an LLVM build with DTLTO. Theoretically,
--start-lib/--end-lib could be used instead of archives in a self-host
build. However, it's unclear how --start-lib/--end-lib can be easily
used with the LLVM build system.

Testing:
- ELF LLD `lit` test coverage has been added, using a mock distributor
  to avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see: #126654.
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jul 7, 2025
This patch introduces support for Integrated Distributed ThinLTO
(DTLTO) in Clang.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

Testing:
- `lit` test coverage has been added to Clang's Driver tests.
- The DTLTO cross-project tests will use this Clang support.

For the design discussion of the DTLTO feature, see:
llvm#126654

Note that I have removed the forwarding of -mllvm options to the
backend compilations which was discussed in the design review from
this patch. LTO configuration for DTLTO will be addressed in a
follow-up patch. In the meantime -mllvm options can be forwarded
manually if required.
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jul 14, 2025
This patch introduces support for Integrated Distributed ThinLTO
(DTLTO) in COFF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

Note: Bitcode members of non-thin archives are not currently
supported. This will be addressed in a future change. This patch is
sufficient to allow for self-hosting an LLVM build with DTLTO if
thin archives are used.

Testing:
- LLD `lit` test coverage has been added, using a mock distributor
  to avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see:
llvm#126654
bd1976bris added a commit that referenced this pull request Jul 15, 2025
This patch introduces support for Integrated Distributed ThinLTO (DTLTO)
in Clang.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

Testing:
- `lit` test coverage has been added to Clang's Driver tests.
- The DTLTO cross-project tests will use this Clang support.

For the design discussion of the DTLTO feature, see:
  #126654
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 15, 2025
…LTO (#147265)

This patch introduces support for Integrated Distributed ThinLTO (DTLTO)
in Clang.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

Testing:
- `lit` test coverage has been added to Clang's Driver tests.
- The DTLTO cross-project tests will use this Clang support.

For the design discussion of the DTLTO feature, see:
  llvm/llvm-project#126654
bd1976bris added a commit to bd1976bris/llvm-project that referenced this pull request Jul 17, 2025
This patch adds support for bitcode members of thin archives to
DTLTO (https://llvm.org/docs/DTLTO.html) in ELF LLD.

For DTLTO, bitcode identifiers must be valid paths to bitcode files
on disk. Clang does not support archive inputs for ThinLTO backend
compilations. This patch adjusts the identifier for bitcode members
of thin archives in DTLTO links so that it is the path to the member
file on disk, allowing such members to be supported in DTLTO.

This patch is sufficient to allow for self-hosting an LLVM build
with DTLTO when thin archives are used.

Note: Bitcode members of non-thin archives remain unsupported. This
will be addressed in a future change.

Testing:

- LLD lit test coverage has been added to check that the identifier
  is adjusted appropriately.
- A cross-project lit test has been added to show that a DTLTO link
  can succeed when linking bitcode members of thin archives.

For the design discussion of the DTLTO feature, see: llvm#126654.
bd1976bris added a commit that referenced this pull request Jul 20, 2025
…48594)

This patch introduces support for Integrated Distributed ThinLTO (DTLTO)
in COFF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

Note: Bitcode members of non-thin archives are not currently supported.
This will be addressed in a future change. This patch is sufficient to
allow for self-hosting an LLVM build with DTLTO if thin archives are
used.

Testing:
- LLD `lit` test coverage has been added, using a mock distributor to
avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see:
#126654
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 20, 2025
…ThinLTO (#148594)

This patch introduces support for Integrated Distributed ThinLTO (DTLTO)
in COFF LLD.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

Note: Bitcode members of non-thin archives are not currently supported.
This will be addressed in a future change. This patch is sufficient to
allow for self-hosting an LLVM build with DTLTO if thin archives are
used.

Testing:
- LLD `lit` test coverage has been added, using a mock distributor to
avoid requiring Clang.
- Cross-project `lit` tests cover integration with Clang.

For the design discussion of the DTLTO feature, see:
llvm/llvm-project#126654
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category lld:COFF lld:ELF lld:MachO lld:wasm lld llvm:support llvm:transforms LTO Link time optimization (regular/full LTO or ThinLTO) platform:windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.