This is an archive of the discontinued LLVM Phabricator instance.

[lld] A Unified LTO Bitcode Frontend
ClosedPublic

Authored by ormris on Apr 14 2022, 9:43 AM.

Details

Summary

The unified LTO pipeline creates a single LTO bitcode structure that can
be used by Thin or Full LTO. This means that the LTO mode can be chosen
at link time and that all LTO bitcode produced by the pipeline is
compatible, from an optimization perspective. This makes the behavior of
LTO a bit more predictable by normalizing the set of LTO features
supported by each LTO bitcode file.

Example usage:

# Compile and link. Select regular LTO at link time.
clang -flto -funified-lto -fuse-ld=lld foo.c

# Compile and link. Select ThinLTO at link time.
clang -flto=thin -funified-lto -fuse-ld=lld foo.c

# Link separately, using ThinLTO.
clang -c -flto -funified-lto foo.c  # -flto={full,thin} are identical in 
terms of compilation actions 
clang -flto=thin -fuse-ld=lld foo.o # pass --lto=thin to ld.lld

# Link separately, using regular LTO. 
clang -c -flto -funified-lto foo.c clang -flto -fuse-ld=lld foo.o  # pass --lto=full to ld.lld

The RFC discussing the details and rational for this change is here:
https://discourse.llvm.org/t/rfc-a-unified-lto-bitcode-frontend/61774

Diff Detail

Event Timeline

ormris created this revision.Apr 14 2022, 9:43 AM
Herald added a project: Restricted Project. · View Herald Transcript
ormris requested review of this revision.Apr 14 2022, 9:43 AM
ormris edited the summary of this revision. (Show Details)Apr 14 2022, 9:48 AM
ormris edited the summary of this revision. (Show Details)Apr 14 2022, 10:17 AM
ormris edited the summary of this revision. (Show Details)
ormris abandoned this revision.Apr 18 2022, 5:26 PM

The changes in this patch have been moved to here: https://reviews.llvm.org/D123804

ormris reclaimed this revision.Jul 10 2023, 1:31 PM

Re-opening this

MaskRay added inline comments.Jul 17 2023, 11:53 AM
lld/ELF/Driver.cpp
1502

This is untested. You can find some newer options added by me to check how we test errors.

lld/ELF/Options.td
581

def lto then use OPT_lto. The variable is derived from the option name.

New options don't use _eq.

lld/test/ELF/lto/unified-lto.ll
5

%0.
In newer tests, the linked output tries to use the same stem name as the main input file (%t0.o)

6

Prefer llvm-readelf -s for new tests. The tabular output is much easier to read.

ping

Sorry for the belated response. This patch needs to remove [WIP]

Here's a high level summary of the changes in this patch. For more information on rational, see the RFC (https://discourse.llvm.org/t/rfc-a-unified-lto-bitcode-frontend/61774).
Add flag to enable unified LTO in the desired mode.

Like what I suggested in the Clang patch, the description probably should mention how clang passes --lto= to lld.

ormris retitled this revision from [WIP][lld] A Unified LTO Bitcode Frontend to [lld] A Unified LTO Bitcode Frontend.Jul 17 2023, 12:13 PM
ormris updated this revision to Diff 541221.Jul 17 2023, 1:46 PM

Address comments. Description update incoming...

lld/ELF/Driver.cpp
1502

Fixed

lld/ELF/Options.td
581

Fixed

lld/test/ELF/lto/unified-lto.ll
5

Fixed

6

Fixed

ormris edited the summary of this revision. (Show Details)Jul 17 2023, 1:56 PM
ormris edited the summary of this revision. (Show Details)
MaskRay added inline comments.Jul 18 2023, 2:30 PM
lld/ELF/Config.h
21

This is a bit unfortunate, as we now get a lot of transitive includes to most *.cpp files in lld/ELF...

lld/ELF/Options.td
581

For new options, we prefer JJ to disallow single dashes like -lto=

lld/test/ELF/lto/unified-lto.ll
6

--symbols is identical to -s. Just use -s

ormris added inline comments.Jul 18 2023, 3:39 PM
lld/ELF/Config.h
21

I've eliminated this include using a mapping. Is removing this header worth the extra indirection?

lld/ELF/Options.td
581

Fixed

lld/test/ELF/lto/unified-lto.ll
6

Fixed

ormris updated this revision to Diff 541765.Jul 18 2023, 3:39 PM

Address comments

MaskRay accepted this revision.Jul 18 2023, 3:50 PM

LG, with the last few nits :)

lld/ELF/Config.h
21

I was on the fence. But you came up with a solution and it should work, I think it's fine to have the indirection. Thanks!

99

Since we don't allow --lto ... (JJ)

422

LtoKind ltoKind or LtoMode ltoMode should be a better name.

lld/ELF/LTO.cpp
209–215

constexpr

213

delete blank line

This revision is now accepted and ready to land.Jul 18 2023, 3:50 PM
ormris added inline comments.Jul 18 2023, 4:10 PM
lld/ELF/Config.h
99

Fixed

422

Fixed

lld/ELF/LTO.cpp
209–215

Fixed

213

Fixed

ormris updated this revision to Diff 541773.Jul 18 2023, 4:11 PM

Final changes

This revision was landed with ongoing or failed builds.Jul 18 2023, 4:20 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2023, 4:20 PM