From ec21e8c31771a2a0ed2e7c755ae3e43e959ad7fd Mon Sep 17 00:00:00 2001 From: Alexander David Frick Date: Mon, 29 Aug 2022 19:33:22 -0500 Subject: [PATCH] Update BUILD.gn --- src/build/config/compiler/BUILD.gn | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/build/config/compiler/BUILD.gn b/src/build/config/compiler/BUILD.gn index 4fd78a9d..b2411d5c 100644 --- a/src/build/config/compiler/BUILD.gn +++ b/src/build/config/compiler/BUILD.gn @@ -757,6 +757,24 @@ config("compiler") { cflags += [ "-fcomplete-member-pointers" ] } + # MLGO specific flags. These flags enable an ML-based inliner trained on + # Chrome on Android (arm32) with ThinLTO enabled, optimizing for size. + # The "release" ML model is embedded into clang as part of its build. + # Currently, the ML inliner is only enabled when targeting Android due to: + # a) Android is where size matters the most. + # b) MLGO presently has the limitation of only being able to embed one model + # at a time; It is unclear if the embedded model is beneficial for + # non-Android targets. + # MLGO is only officially supported on linux. + if (use_ml_inliner && is_a_target_toolchain) { + assert( + is_android && host_os == "linux", + "MLGO is currently only supported for targeting Android on a linux host") + if (use_thin_lto) { + ldflags += [ "-Wl,-mllvm,-enable-ml-inliner=release" ] + } + } + # Pass the same C/C++ flags to the objective C/C++ compiler. cflags_objc += cflags_c cflags_objcc += cflags_cc @@ -1510,9 +1528,6 @@ config("default_warnings") { # TODO(thakis): https://crbug.com/617318 # Currently goma can not handle case sensitiveness for windows well. cflags += [ "-Wno-nonportable-include-path" ] - - # Warns in ATL headers; see https://crbug.com/1208419. - cflags += [ "-Wno-null-pointer-subtraction" ] } cflags += [ @@ -2134,6 +2149,13 @@ config("optimize") { # Favor size over speed. if (is_clang) { cflags = [ "-O3" ] + common_optimize_on_cflags + + if (use_ml_inliner && is_a_target_toolchain) { + cflags += [ + "-mllvm", + "-enable-ml-inliner=release", + ] + } } else { cflags = [ "-O3" ] + common_optimize_on_cflags }