Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The BUILDCONFIG file sets this config on targets by default, which means when
- # building with ThinLTO, no optimization is performed in the link step.
- config("thinlto_optimize_default") {
- if (!is_debug && use_thin_lto && is_a_target_toolchain) {
- lto_opt_level = 2
- if (is_win) {
- ldflags = [ "/opt:lldlto=" + lto_opt_level ]
- } else {
- ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
- }
- }
- }
- # Use this to enable optimization in the ThinLTO link step for select targets
- # when thin_lto_enable_optimizations is set by doing:
- #
- # configs -= [ "//build/config/compiler:thinlto_optimize_default" ]
- # configs += [ "//build/config/compiler:thinlto_optimize_max" ]
- #
- # Since it makes linking significantly slower and more resource intensive, only
- # use it on important targets such as the main browser executable or dll.
- config("thinlto_optimize_max") {
- if (!is_debug && use_thin_lto && is_a_target_toolchain) {
- if (thin_lto_enable_optimizations) {
- lto_opt_level = 2
- } else {
- lto_opt_level = 2
- }
- if (is_win) {
- ldflags = [ "/opt:lldlto=" + lto_opt_level ]
- } else {
- ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
- }
- }
- }
- ----------------
- # Default "optimization on" config.
- config("optimize") {
- if (is_win) {
- if (chrome_pgo_phase != 2) {
- # Favor size over speed, /O1 must be before the common flags.
- # /O1 implies /Os and /GF.
- cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
- } else {
- # PGO requires all translation units to be compiled with /O2. The actual
- # optimization level will be decided based on the profiling data.
- cflags = [ "/O2" ] + common_optimize_on_cflags + [ "/Oi" ]
- }
- } else if (optimize_for_size) {
- # Favor size over speed.
- if (is_clang) {
- cflags = [ "-O2" ] + common_optimize_on_cflags
- } else {
- cflags = [ "-O2" ] + common_optimize_on_cflags
- }
- } else if (is_chromeos) {
- # TODO(gbiv): This is partially favoring size over speed. CrOS exclusively
- # uses clang, and -Os in clang is more of a size-conscious -O2 than "size at
- # any cost" (AKA -Oz). It'd be nice to:
- # - Make `optimize_for_size` apply to all platforms where we're optimizing
- # for size by default (so, also Windows)
- # - Investigate -Oz here, maybe just for ARM?
- cflags = [ "-Os" ] + common_optimize_on_cflags
- } else {
- cflags = [ "-O2" ] + common_optimize_on_cflags
- }
- if (optimize_for_size) {
- rustflags = [ "-Copt-level=2" ]
- } else {
- rustflags = [ "-Copt-level=3" ]
- }
- ldflags = common_optimize_on_ldflags
- }
- # Turn off optimizations.
- config("no_optimize") {
- if (is_win) {
- cflags = [
- "/Od", # Disable optimization.
- "/Ob0", # Disable all inlining (on by default).
- "/GF", # Enable string pooling (off by default).
- ]
- if (target_cpu == "arm64") {
- # Disable omitting frame pointers for no_optimize build because stack
- # traces on Windows ARM64 rely on it.
- cflags += [ "/Oy-" ]
- }
- } else if (is_android && !android_full_debug) {
- # On Android we kind of optimize some things that don't affect debugging
- # much even when optimization is disabled to get the binary size down.
- if (is_clang) {
- cflags = [ "-Oz" ] + common_optimize_on_cflags
- } else {
- cflags = [ "-Os" ] + common_optimize_on_cflags
- }
- if (!is_component_build) {
- # Required for library partitions. Without this all symbols just end up
- # in the base partition.
- ldflags = [ "-Wl,--gc-sections" ]
- }
- } else if (is_fuchsia) {
- # On Fuchsia, we optimize for size here to reduce the size of debug build
- # packages so they can be run in a KVM. See crbug.com/910243 for details.
- cflags = [ "-Og" ]
- } else {
- cflags = [ "-O0" ]
- ldflags = []
- }
- }
- # Turns up the optimization level. On Windows, this implies whole program
- # optimization and link-time code generation which is very expensive and should
- # be used sparingly.
- config("optimize_max") {
- if (is_nacl && is_nacl_irt) {
- # The NaCl IRT is a special case and always wants its own config.
- # Various components do:
- # if (!is_debug) {
- # configs -= [ "//build/config/compiler:default_optimization" ]
- # configs += [ "//build/config/compiler:optimize_max" ]
- # }
- # So this config has to have the selection logic just like
- # "default_optimization", below.
- configs = [ "//build/config/nacl:irt_optimize" ]
- } else {
- ldflags = common_optimize_on_ldflags
- if (is_win) {
- # Favor speed over size, /O2 must be before the common flags.
- # /O2 implies /Ot, /Oi, and /GF.
- cflags = [ "-Xclang", "-O3", ] + common_optimize_on_cflags
- } else if (optimize_for_fuzzing) {
- cflags = [ "-O1" ] + common_optimize_on_cflags
- } else {
- cflags = [ "-O3" ] + common_optimize_on_cflags
- }
- rustflags = [ "-Copt-level=3" ]
- }
- }
- # This config can be used to override the default settings for per-component
- # and whole-program optimization, optimizing the particular target for speed
- # instead of code size. This config is exactly the same as "optimize_max"
- # except that we use -O3 instead of -O2 on non-win, non-IRT platforms.
- #
- # TODO(crbug.com/621335) - rework how all of these configs are related
- # so that we don't need this disclaimer.
- config("optimize_speed") {
- if (is_nacl && is_nacl_irt) {
- # The NaCl IRT is a special case and always wants its own config.
- # Various components do:
- # if (!is_debug) {
- # configs -= [ "//build/config/compiler:default_optimization" ]
- # configs += [ "//build/config/compiler:optimize_max" ]
- # }
- # So this config has to have the selection logic just like
- # "default_optimization", below.
- configs = [ "//build/config/nacl:irt_optimize" ]
- } else {
- ldflags = common_optimize_on_ldflags
- if (is_win) {
- # Favor speed over size, /O2 must be before the common flags.
- # /O2 implies /Ot, /Oi, and /GF.
- cflags = [ "-Xclang", "-O3", ] + common_optimize_on_cflags
- } else if (optimize_for_fuzzing) {
- cflags = [ "-O1" ] + common_optimize_on_cflags
- } else {
- cflags = [ "-O3" ] + common_optimize_on_cflags
- }
- rustflags = [ "-Copt-level=3" ]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement