Commit graph

87 commits

Author SHA1 Message Date
Yi Kong
2cd77d671c Enable MLGO inliner optimization for optimize_for_size cases
This helps reduce binary size for these projects by ~3%.

Test: presubmit
Bug: 342090838
Change-Id: Ie1e0586ddf5f40aa1e81fc2628a6499093de9699
2024-06-06 15:01:59 +09:00
Chungro Lee
139218906b Merge "Revert^3 "Enable full LTO optimization by default"" into main 2024-03-28 01:35:37 +00:00
Chungro Lee
97f68587ff Revert^3 "Enable full LTO optimization by default"
7549990a95

Reason for revert: b/331528903
Change-Id: Idb013e97c84aeaf969522dc77abf94f23f721181
2024-03-28 01:25:42 +00:00
Yi Kong
2590054333 Merge "Revert^2 "Enable full LTO optimization by default"" into main 2024-03-27 01:58:09 +00:00
Yi Kong
7549990a95 Revert^2 "Enable full LTO optimization by default"
55019c43f4

We set the default optimization mode to --lto-O0 for LTO enabled
projects, in order to save build time. This is missing some performance
optimizations, esp. related to vectorization. Now that we suggest eng
build for developers, we can enable full optimization by default.

When we introduced --lto-O0, we achieved a 4.2% saving in
system-processes-memory-direct. Enabling full LTO optimization will
trade some of the memory / binary size savings for better code
performance. For system-processes-memory-direct, it is 2.0% increase
compared to --lto-O0, or a net 2.2% saving compared to baseline.

Change-Id: I747939ac4d6e4a66e3ef776f4c36eebc7bf34c86
2024-03-27 01:57:22 +00:00
Yi Kong
55019c43f4 Revert "Enable full LTO optimization by default"
Revert submission 2988057-default-full-lto

Reason for revert: broken test

Reverted changes: /q/submissionid:2988057-default-full-lto
Bug: 330811070

Change-Id: I46487ad92d25741347c7f30e944a5794941d5d69
2024-03-22 05:51:09 +00:00
Yi Kong
e022cf58dd Remove ThinLTO workaround for VNDK
VNDK is deprecated. The build is passing without the workaround.

Test: presubmit
Bug: 169217596
Change-Id: I7cf2c33984c50d06f3e69ebc916ce6a89468204a
2024-03-21 16:34:56 +00:00
Yi Kong
ce23b9ba16 Enable full LTO optimization by default
We set the default optimization mode to --lto-O0 for LTO enabled
projects, in order to save build time. This is missing some performance
optimizations, esp. related to vectorization. Now that we suggest eng
build for developers, we can enable full optimization by default.

When we introduced --lto-O0, we achieved a 4.2% saving in
system-processes-memory-direct. Enabling full LTO optimization will
trade some of the memory / binary size savings for better code
performance. For system-processes-memory-direct, it is 2.0% increase
compared to --lto-O0, or a net 2.2% saving compared to baseline.

Test: presubmit
Bug: 328163089
Change-Id: Ia4d0f74e668ed057d6d9d6fc6c60196c2e355fb9
2024-03-07 07:02:45 +00:00
Colin Cross
3513fb17cd Remove fdoProfileMutator
Add the dependency on the fdo_profile module in afdoTransitionMutator
and read the provider in GenerateAndroidBuildActions.

This relands Ied8fd7b52d5694a3691652318e87b8fe14dda126 with a fix
to use the correct LTO ldflag when an afdo variant doesn't have a
profile.

Bug: 319288033
Bug: 324141705
Test: afdo_test.go
Change-Id: I024ca316cfb565b5fb0251793f05a54ce16cc1cb
2024-02-09 13:49:02 -08:00
Colin Cross
6ac83a8f85 Convert LTO mutators to TransitionMutator
Convert ltoDepsMutator and ltoMutator to a TransitionMutator as a
step towards variants-on-demand.

Bug: 319288033
Test: lto_test.go
Change-Id: I2c9af73fd526adf58ff626831ababea466338205
2024-01-26 11:06:45 -08:00
Yi Kong
9723e338ee Do not perform AFDO or optimizing LTO for eng builds
Afdo creates more variants to build, and optimizing LTO is costly to
perform. Turn off these two optimizations for eng builds for a faster
build speed.

This reduces total C/C++ invocation time for aosp_arm64-eng by 6.28%.

Test: presubmit
Bug: 307753064
Change-Id: Ibac4269c66a64e896dba2074b607d71a2da37546
2023-12-04 19:04:00 +09:00
Yi Kong
9c3f433426 Remove PGO build support
We have removed our final PGO enabled project, time to remove PGO build
support.

Test: presubmit
Change-Id: I14ccd0fc8e3fbb8b3015072245fafd0eebe3ec08
2023-11-24 17:14:27 +09:00
Yi Kong
8fb0b498db Remove unneeded MLGO cflag
For LTO compilation, we do not need MLGO flags in cflags, since codegen
happens during link only.

Fixes compiler warnings for unused command line argument.

Test: presubmit
Change-Id: I361e4292b10a3582fd5c69fa7b5678c654b44a0f
2023-11-22 06:06:36 +00:00
AdityaK
76c7385f22 Provide an environment variable to disable mlgo
Helps iterate on compiler that was build without mlgo. Building with mlgo requires a docker image

Change-Id: Ie2988ecaf15031cdb14411abf7b99530e3860cce
2023-11-14 10:24:59 -08:00
Yi Kong
0fa503da2e Only enable MLGO for ARM64 ThinLTO targets
The MLGO model we embed in the Android Clang is trained on ARM64
ThinLTO artefacts. Applying the model across architectures does not
necessarily translate to performance improvement. Therefore only enable
the optimisation on ARM64 ThinLTO for now.

Test: presubmit
Bug: 293827654
Change-Id: Ie64a65c11191cf700a463637a0746c8470d3aa3c
2023-11-07 14:12:51 +09:00
Yi Kong
b8eaee68b6 Add option to emit ThinLTO indexes and imports for MLGO training
Test: presubmit
Bug: 293827654
Change-Id: I8de1287543194d8e47ff5b57d4cabc7416048bbf
2023-10-31 21:59:45 +09:00
Yi Kong
950c17435d Remove GLOBAL_THINLTO build option
GLOBAL_THINLTO is now default, since it improves build speed, produces
more performant code and smaller binary. Remove the option to turn it
off since we no longer maintain that variation, and that simplifies the
logic (esp. for moving CFI builds to ThinLTO).

Also fixed a bug where ThinLTO is not propagated to its static deps on
non-default targets (32-bit or host).

Test: presubmit
Bug: 169004486
Change-Id: I31f41ba27c2b94a384d2ba5027049c307d6f4334
2023-10-09 10:56:14 +00:00
Yi Kong
577a73a22d Change lto_test to use GlobalThinLTO configuration
This is now the default, and we will be removing non-GlobalThinLTO configuration.

Also changed handling for lto: never, it doesn't need to create an
lto-none variant.

Change-Id: I971baa920df867fb762923d925eed22215a89c27
Test: presubmit
2023-10-05 05:05:40 +00:00
Yabin Cui
1aa29e6ca9 Revert "Disable Global ThinLTO by default"
This reverts commit 9c81c0cfd9.

Reason for revert: The ThinLTO problem has been fixed in https://android-review.git.corp.google.com/c/platform/bionic/+/2725997. So we can Re-enable Global ThinLTO.

Change-Id: I25dde4910692fd71124b48f45911da5b7b92a089
2023-09-01 17:22:58 +00:00
Yabin Cui
9c81c0cfd9 Disable Global ThinLTO by default
Because enabling ThinLTO makes some constructor functions not called
in arm64 executables.

Bug: 295944813
Test: build
Change-Id: Ic0cab5fd80aa86d0d9ca1131564b747a445c6e46
2023-08-14 15:47:36 -07:00
Yi Kong
d6ab48c660 Limit LTO inlining even when profile is present
Reduce the import instr limit from the LLVM default (100) to 40. This
helps reduce the binary size as well as improving performance slightly.

Size:
             Default(100)   40        30
libhwui.so   11059040       11058912  11060872
libart.so    10697576       10697160  10696568

Performance:
40 vs. default:  0.37% improvement
                 http://go/art-benchmark?p=BootImageProfileId:36054
30 vs. default:  0.36% improvement
                 http://go/art-benchmark?p=BootImageProfileId:36058

Test: presubmit
Change-Id: Id800ff7818cde908daab784bac0a312c6a71272d
2023-08-01 18:30:13 +00:00
Yi Kong
13beeedff7 Turn off Global ThinLTO for LP32 again
LP32 has many subtle issues and less test coverage.

Bug: 290859519
Bug: 169004486
Test: presubmit
Change-Id: I33fcf1a08b9e7a905ba81030250a9578532da5a0
2023-07-15 03:18:06 +09:00
Yi Kong
8f9ca23c1e Fix a typo. NFC.
Test upload from Cog...

Change-Id: I68964d14d0a01be2bdc0ad276bdfde9f879795f2
Test: N/A
2023-07-14 06:18:38 +00:00
Yi Kong
add6375a10 Turn on Global ThinLTO by default
Build C/C++ targets with ThinLTO with "--lto-O0" by default. This takes
advantage of better dead code elimination and CFG simplification due to
ThinLTO's global view of the program, but do not enable the costly LTO
optimizations. This also makes builds faster because we can avoid doing
codegen for the dead code.

Code size for panther-userdebug:
                   /system/bin  /system/lib  /system/lib64
Original           57648        86264        181700
Global ThinLTO     55764        84916        175728
                   -3.27%       -1.56%       -3.29%

Build time for aosp_arm64-userdebug:
                   clang time   linker time
Original           56993.87s    1712.36s
Global ThinLTO     52839.18s    3114.93s

saving 4.68% build time in total.

Bug: 169004486
Test: presubmit
Change-Id: Idb0f4675ca4750b8b12b24f4679579419d3448c8
2023-07-11 21:26:52 +09:00
Yi Kong
b9d5046d8b Simplify LTO flags handling
... and add more comments about the use of --lto-O0.

Test: presubmit
Change-Id: I2ef7bf4f100a8d7559a6b738e9211c596d579dc6
2023-07-03 17:16:42 +09:00
A. Cody Schuffelen
7188b90e69 Disable "-Wl,-plugin-opt,-import-instr-limit=5" on MacOS
This option is unsupported on the MacOS ld used in Android, leading to
compilation errors when LTO is enabled for binaries.

In particular the error includes:
```
ld64.lld: error: unknown argument '-plugin-opt'
ld64.lld: error: unknown argument '-import-instr-limit=5'
```

Test: m libc++ on a Mac OS machine
Bug: 288983988
Change-Id: I1873e0a77777832f833f211beb42633d462f04d5
2023-06-27 19:15:07 -07:00
Yi Kong
895d241013 Refactor LTO
We removed Full LTO support, now LTO is a binary choice. This allows us
to greatly simplify the LTO propagation logic.

Test: m
Test: GLBOAL_THINLTO=true m
Bug: 169004486
Change-Id: Ie4e453d7518c7069a7c755734dab1e776c16e656
2023-06-09 03:15:49 +00:00
Yi Kong
ed79fa382b Use a less hacky way to detect if a module is Fuzzer enabled
Bug: 169004486
Test: presubmit
Change-Id: I7fad86041622979b9befb7c86897a13f604bdf3d
2023-06-05 14:21:48 +09:00
Yi Kong
0713e336d9 Remove Full LTO support
We do not have any more projects directly depending on Full LTO (except
CFI which manages their own LTO flags), remove full LTO support from the
build system.

Test: presubmit
Bug: 169004486
Change-Id: I8d6b7999d716158b5d8fe34b2f197653d7bae8dd
2023-06-01 00:10:26 +00:00
Yi Kong
a7a345d55e Remove Use_clang_lld in lto
We have moved all LTO projects to LLD, this is unused.

Test: presubmit
Change-Id: I385b3302c04243be8fde80605b29df7646ec40ce
2023-05-30 15:19:06 +09:00
Aditya Kumar
efc36678a9 Enable LTO for riscv64
This partially reverts commit 1281b99495.

Bug: b/282584808, b/254713216

Reason for revert: LTO can be enabled as emultated tls is now globally disabled https://android-review.git.corp.google.com/c/platform/build/soong/+/2431153

Change-Id: I66c83b1116550179043490a11f66b8630c0e6b1b
2023-05-17 17:18:06 +00:00
Aditya Kumar
1281b99495 Disable LTO and CFI for riscv64
This reverts commit 24870216e9.

Reason for revert: b/282584808

Change-Id: I3808121b4437fdd01db5d305d8f0377e6ad7bd9e
2023-05-16 03:55:41 +00:00
Aditya Kumar
24870216e9 Revert "Disable LTO and CFI for riscv64"
This reverts commit ecf4e664e0.

Reason for revert: Not needed as emultated tls is now globally disabled https://android-review.git.corp.google.com/c/platform/build/soong/+/2431153

Change-Id: Idc3de2771afbbe2d5976f3c7974b3ffd15441b13
2023-05-12 18:46:42 +00:00
Aditya Kumar
4c660ae58e Revert "Build riscv64 with thin LTO"
This reverts commit 17c9c2a5b5.

Reason for revert: Wait until new toolchain with linker fix las landed (https://android-review.git.corp.google.com/c/toolchain/llvm_android/+/2424081)

Change-Id: I05b14c12ac93182dd93c5b490f260071c6d3a090
2023-02-15 01:32:22 +00:00
AdityaK
17c9c2a5b5 Build riscv64 with thin LTO
Depends on: https://android-review.git.corp.google.com/c/platform/system/libhwbinder/+/2336346

Bug: b/254713216
Change-Id: Id750cab796ddf8c180fa0570e46cab0161788974
2023-02-13 21:42:30 +00:00
Colin Cross
2c435a00ff Set -fno-emulated-tls for riscv64
Building for riscv64 fails with link errors on __thread variables.
Set -fno-emulated-tls to fix it.

Bug: 254713216
Test: lunch aosp_riscv64-userdebug && m ALLOW_MISSING_DEPENDENCIES=true ndk_sysroot
Change-Id: I3dca81dfd277d681b6c868a5e8385e3a37335a5f
2022-10-20 14:31:24 -07:00
Colin Cross
ecf4e664e0 Disable LTO and CFI for riscv64
Building with LTO and CFI enabled for riscv64 causes link failures:
ld.lld: error: lto.tmp: cannot link object files with different floating-point ABI
ld.lld: error: undefined symbol: guard variable for android::hardware::BufferedTextOutput::getBuffer() const::ts

Disable them for now.

Test: lunch aosp_riscv64-userdebug && m ALLOW_MISSING_DEPENDENCIES=true ndk_sysroot
Change-Id: I3489952abebeeb3f4de664fd3e436232aac298d7
2022-10-20 13:59:58 -07:00
Liz Kammer
729aaf4a10 Refactor lto mutator to not alter user-input props
Test: lto test
Change-Id: I700960c6fb6527123e08e8e3c90a15dea0987df3
2022-09-26 11:03:14 -04:00
Yi Kong
5e0f405abf Pass -flto to asflags as well
Although it has no effect, CFI mandates -flto in asflags.

Test: presubmit
Bug: 243476017
Change-Id: I33246488140c642894f3fbab65bc37bdd5de3024
2022-09-09 01:58:18 +08:00
Yi Kong
56fc1b6902 Do not enable global ThinLTO for tests
Tests are not shipped, no need to spend extra CPU cycles optimising them
during build.

Test: GLOBAL_THINLTO=true m
Bug: 169004486
Change-Id: I66ede9c01d43b574a7fe9f74f0bc6ba97f51be06
2022-09-06 16:24:00 +08:00
Yi Kong
b1a9aab987 Merge "Revert "Reland "Turn on Global ThinLTO by default""" 2022-08-23 11:36:02 +00:00
Yi Kong
7689c64f68 Revert "Reland "Turn on Global ThinLTO by default""
This reverts commit 4273c18a4f.

Bug: 243475788
Bug: 243490273
Change-Id: I5ea8c8e6a84408013bc7ed573776d8f5eebc091f
2022-08-23 09:24:48 +00:00
Treehugger Robot
8cab5906da Merge "Reland "Turn on Global ThinLTO by default"" 2022-08-23 00:47:28 +00:00
Yi Kong
4273c18a4f Reland "Turn on Global ThinLTO by default"
This reverts commit b90ff82772.

All the breakages are now fixed or mitigated.

Bug: 169004486
Change-Id: Ibec4b1f0a50c5ef6769bc6916a81721a4ce03c60
Test: presubmit
2022-08-22 08:18:03 +00:00
Yi Kong
c702ebd886 Do not enable ThinLTO for CFI enabled projects
CFI projects already use full LTO.

Test: GLOBAL_THINLTO=true m
Change-Id: I8a57efc237aed977f57dd4040500cc5f84843c3d
2022-08-19 16:05:14 +08:00
Yi Kong
b90ff82772 Revert "Turn on Global ThinLTO by default"
This reverts commit 406e7b725b.

Reason for revert: ndk_translation causes clang to crash

Change-Id: I61b262157f9f57c739391757d5a1f95299ddadca
2022-08-18 14:53:34 +00:00
Yi Kong
406e7b725b Turn on Global ThinLTO by default
Apply ThinLTO without optimization (--lto-O0) globally. This saves us
2.24% in binary size for system/lib64, as well as more than 4.68% build
time improvement.

Test: presubmit
Bug: 169004486
Change-Id: I1ed90c2058f9ff1fa8a2d3fd7ac1191c5d98dac1
2022-08-17 09:27:02 +08:00
Yi Kong
2121d16db8 Only enable global ThinLTO for LP64 targets
Due to the lack of engineering efforts into LP32 targets, do not enable
global ThinLTO for them by default.

Test: presubmit
Bug: 169004486
Change-Id: I79b77baecf16fda95ff5dccc5a401596a0557d5d
2022-08-17 09:22:07 +08:00
Treehugger Robot
5c8693f5d7 Merge "Revert "[cc_fuzz] Revert 'disable LTO' patches."" 2022-03-02 05:08:27 +00:00
Mitch Phillips
5007c4a06d Revert "[cc_fuzz] Revert 'disable LTO' patches."
Revert submission 1976512-revert-nolto-fuzzing

Reason for revert: b/222160662
Reverted Changes:
Iacee4fa29:[cc_fuzz] Revert 'disable LTO' patches.
Ic509b00a1:[cc_fuzz] Revert 'disable LTO' patches.
If85931f09:[cc_fuzz] Revert 'disable LTO' patches.

Change-Id: I84e01a4f84145e3331c2955836c8cc9bfa05c36b
2022-03-02 01:25:22 +00:00