Skip to content

Commit 4d92573

Browse files
ivayloenfacebook-github-bot
authored andcommitted
Add opt-in LTO for portable executor (#24001)
Summary: Add a generic, default-off `executorch.enable_lto` Buck configuration for the portable `program_no_prim_ops` target. When enabled, the target compiles with `-flto=thin` and exports `-flto=thin` to Buck-linked consumers. OSS builds and ATen variants remain unchanged. Thin mode is explicit so a target-local opt-in cannot override a product's ThinLTO pipeline with full LTO. Orca already has independently landed whole-XRA/Kymera ThinLTO from D125548482; enabling this setting there is mode-consistent and is not credited with product-wide LTO savings. Reviewed By: JacobSzwejbka Differential Revision: D125783739
1 parent d07c72b commit 4d92573

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎runtime/executor/targets.bzl‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ def _program_preprocessor_flags():
2828
fail("executorch.enable_program_verification must be one of 'true' or 'false'; saw '" +
2929
enable_verification + "'")
3030

31+
def _program_lto_flags(aten_mode):
32+
if runtime.is_oss or aten_mode:
33+
return []
34+
return select({
35+
"DEFAULT": [],
36+
"fbsource//xplat/executorch/tools/buck/constraints:executorch-lto-enabled": ["-flto=thin"],
37+
})
38+
3139
def define_common_targets():
3240
"""Defines targets that should be shared between fbcode and xplat.
3341
@@ -107,7 +115,8 @@ def define_common_targets():
107115
compiler_flags = select({
108116
"ovr_config//os:windows": [],
109117
"DEFAULT" :["-Wno-error=deprecated-declarations"]
110-
}),
118+
}) + _program_lto_flags(aten_mode),
119+
exported_linker_flags = _program_lto_flags(aten_mode),
111120
preprocessor_flags = _program_preprocessor_flags(),
112121
exported_deps = [
113122
":memory_manager",

‎tools/buck/constraints/BUCK‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ fb_native.constraint_value(
7575
visibility = ["PUBLIC"],
7676
)
7777

78+
fb_native.config_setting(
79+
name = "executorch-lto-enabled",
80+
values = {
81+
"executorch.enable_lto": "true",
82+
},
83+
visibility = ["PUBLIC"],
84+
)
85+
7886
fb_native.config_setting(
7987
name = "executorch-program-verification-disabled",
8088
constraint_values = [

0 commit comments

Comments
 (0)