Bug 1906824 - Move MOZ_OPTIMIZE_FLAGS from old-configure to moz.configure r=glandium

As js has different flags compared to the remaining parts of the
codebase, set a specific variable (namely MOZ_JS_OPTIMIZE_FLAGS) and use
it instead of MOZ_OPTIMIZE_FLAGS using a specific hook in
python/mozbuild/mozbuild/frontend/context.py

Also:

- harmonize moz_optimize_flags type to always return a list.
- moz_optimize now either returns "1" or None (no use case distinguishes
  between returning 1 or 2)

Differential Revision: https://phabricator.services.mozilla.com/D216098
This commit is contained in:
serge-sans-paille 2024-08-13 22:04:33 +00:00
Родитель a7f029758f
Коммит 56ef5fe6c9
6 изменённых файлов: 91 добавлений и 133 удалений

Просмотреть файл

@ -41,12 +41,23 @@ add_old_configure_assignment("LDFLAGS", os_ldflags)
set_config("OS_LDFLAGS", os_ldflags)
@depends(linker_optimize_flags, moz_optimize_flags, lto, c_compiler)
def moz_optimize_ldflags(linker_optimize_flags, moz_optimize_flags, lto, c_compiler):
set_config("MOZ_OPTIMIZE_FLAGS", moz_optimize_flags, when=~js_build)
@depends(
linker_optimize_flags,
"MOZ_OPTIMIZE_FLAGS",
lto,
c_compiler,
)
@imports(_from="mozbuild.shellutil", _import="split")
def moz_optimize_ldflags(linker_optimize_flags, env_optimize_flags, lto, c_compiler):
flags = []
if linker_optimize_flags:
flags += linker_optimize_flags.ldflags
flags += moz_optimize_flags
if env_optimize_flags:
flags += split(env_optimize_flags[0])
# When using llvm-based LTO, non numeric optimization levels are
# not supported by the linker, so force the linker to use -O2 (
@ -58,3 +69,20 @@ def moz_optimize_ldflags(linker_optimize_flags, moz_optimize_flags, lto, c_compi
set_config("MOZ_OPTIMIZE_LDFLAGS", moz_optimize_ldflags)
@depends(
try_compile(
includes=["stdio.h"],
body='puts("demat");',
flags=moz_optimize_flags,
language="C",
check_msg="for valid C compiler optimization flags",
),
moz_optimize_flags,
when=moz_optimize,
)
@imports(_from="mozbuild.shellutil", _import="quote")
def check_optimization_flags(check_result, moz_optimize_flags):
if not check_result:
die(f"Invalid C compiler optimization flags: {quote(*moz_optimize_flags)}")

Просмотреть файл

@ -98,36 +98,42 @@ def forced_pgo_optimization_level(target):
return "-O3"
@depends("--enable-optimize")
def moz_optimize(option):
if len(option):
if "-O0" not in option[0]:
return "2"
elif option:
return "1"
@depends("--enable-optimize", forced_pgo_optimization_level)
@depends("--enable-optimize", "MOZ_OPTIMIZE_FLAGS")
@imports(_from="mozbuild.shellutil", _import="split")
def moz_optimize_flags(option, forced_pgo_optimization_level):
if len(option):
return split(option[0])
elif option and forced_pgo_optimization_level:
return [forced_pgo_optimization_level]
def configured_moz_optimize_flags(enable_optimize, env_flags):
if len(enable_optimize):
return split(enable_optimize[0])
if len(env_flags):
return split(env_flags[0])
@depends("--enable-optimize", "MOZ_OPTIMIZE_FLAGS")
def moz_optimize(enable_optimize, env_flags):
return "1" if enable_optimize or env_flags else None
set_config("MOZ_OPTIMIZE", moz_optimize)
add_old_configure_assignment("MOZ_OPTIMIZE", moz_optimize)
add_old_configure_assignment("MOZ_CONFIGURE_OPTIMIZE_FLAGS", moz_optimize_flags)
@depends_if("MOZ_OPTIMIZE_FLAGS")
@depends(
target, moz_optimize, configured_moz_optimize_flags, forced_pgo_optimization_level
)
@imports(_from="mozbuild.shellutil", _import="split")
def moz_optimize_flags(env_optimize_flags):
return split(env_optimize_flags[0])
def moz_optimize_flags(
target, moz_optimize, configured_moz_optimize_flags, forced_pgo_optimization_level
):
if configured_moz_optimize_flags:
return configured_moz_optimize_flags
if moz_optimize and forced_pgo_optimization_level:
return [forced_pgo_optimization_level]
add_old_configure_assignment("MOZ_OPTIMIZE_FLAGS", moz_optimize_flags)
if target.kernel == "Darwin":
return ["-O3"]
elif target.kernel in ("Linux", "WINNT"):
return ["-O2"]
else:
return ["-O"]
# Android NDK
@ -3878,20 +3884,3 @@ dtrace = check_header(
set_config("HAVE_DTRACE", True, when=dtrace)
set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
@depends(
try_compile(
includes=["stdio.h"],
body='puts("demat");',
flags=moz_optimize_flags,
language="C",
check_msg="for valid C compiler optimization flags",
),
moz_optimize_flags,
when=moz_optimize,
)
@imports(_from="mozbuild.shellutil", _import="quote")
def check_optimization_flags(check_result, moz_optimize_flags):
if not check_result:
die(f"Invalid C compiler optimization flags: {quote(*moz_optimize_flags)}")

Просмотреть файл

@ -1477,6 +1477,34 @@ with only_when(compile_environment):
)
# Optimization flags
# ==============================================================
@depends(
target,
c_compiler,
configured_moz_optimize_flags,
when="--enable-compile-environment",
)
@imports(_from="mozbuild.shellutil", _import="split")
def moz_js_optimize_flags(target, compiler, configured_moz_optimize_flags):
if configured_moz_optimize_flags:
return configured_moz_optimize_flags
if target.kernel in ("Darwin", "Linux"):
flags = ["-O3"]
if target.os == "Android" and compiler.type == "gcc":
flags += ["-fno-reorder-functions"]
return flags
elif target.kernel == "WINNT":
return ["-O2"]
else:
return ["-O"]
set_config("MOZ_JS_OPTIMIZE_FLAGS", moz_js_optimize_flags, when=~js_build)
set_config("MOZ_OPTIMIZE_FLAGS", moz_js_optimize_flags, when=js_build)
# link executables against mozglue
# ==============================================================
@depends(

Просмотреть файл

@ -44,53 +44,6 @@ fi
fi # COMPILE_ENVIRONMENT
dnl ========================================================
dnl System overrides of the defaults for target
dnl ========================================================
case "$target" in
*-darwin*)
MOZ_OPTIMIZE_FLAGS="-O3"
;;
*-android*|*-linuxandroid*)
MOZ_OPTIMIZE_FLAGS="-O3"
if test "$CC_TYPE" == gcc ; then
MOZ_OPTIMIZE_FLAGS="-fno-reorder-functions $MOZ_OPTIMIZE_FLAGS"
fi
;;
*-*linux*)
MOZ_OPTIMIZE_FLAGS="-O3"
;;
*-mingw*)
MOZ_OPTIMIZE_FLAGS="-O2"
;;
esac
if test -z "$MOZ_OPTIMIZE_FLAGS"; then
MOZ_OPTIMIZE_FLAGS="-O"
fi
dnl Mozilla specific options
dnl ========================================================
dnl The macros used for command line options
dnl are defined in build/autoconf/altoptions.m4.
dnl ========================================================
dnl = Enable code optimization. ON by default.
dnl ========================================================
# Use value from moz.configure if one is defined. Else use our computed
# value.
if test -n "${MOZ_CONFIGURE_OPTIMIZE_FLAGS}"; then
MOZ_OPTIMIZE_FLAGS=${MOZ_CONFIGURE_OPTIMIZE_FLAGS}
fi
AC_SUBST_LIST(MOZ_OPTIMIZE_FLAGS)
dnl ========================================================
dnl =

Просмотреть файл

@ -35,39 +35,6 @@ fi
fi # COMPILE_ENVIRONMENT
dnl ========================================================
dnl System overrides of the defaults for target
dnl ========================================================
case "$target" in
*-darwin*)
MOZ_OPTIMIZE_FLAGS="-O3"
;;
*-android*|*-linuxandroid*)
MOZ_OPTIMIZE_FLAGS="-O2"
;;
*-*linux*)
if test "$CC_TYPE" != clang-cl ; then
MOZ_OPTIMIZE_FLAGS="-O2"
fi
;;
*-mingw*)
MOZ_OPTIMIZE_FLAGS="-O2"
;;
esac
if test -z "$MOZ_OPTIMIZE_FLAGS"; then
MOZ_OPTIMIZE_FLAGS="-O"
fi
dnl Mozilla specific options
dnl ========================================================
dnl The macros used for command line options
dnl are defined in build/autoconf/altoptions.m4.
dnl ========================================================
dnl =
dnl = Application
@ -124,18 +91,6 @@ fi
AC_SUBST(MOZ_BRANDING_DIRECTORY)
dnl ========================================================
dnl = Enable code optimization. ON by default.
dnl ========================================================
# Use value from moz.configure if one is defined. Else use our computed
# value.
if test -n "${MOZ_CONFIGURE_OPTIMIZE_FLAGS}"; then
MOZ_OPTIMIZE_FLAGS=${MOZ_CONFIGURE_OPTIMIZE_FLAGS}
fi
AC_SUBST_LIST(MOZ_OPTIMIZE_FLAGS)
dnl ========================================================
dnl = Mac bundle name

Просмотреть файл

@ -514,6 +514,11 @@ class TargetCompileFlags(BaseCompileFlags):
def _optimize_flags(self):
if not self._context.config.substs.get("MOZ_OPTIMIZE"):
return []
# js/src/* have their own optimization flag.
if self._context.relsrcdir == "js/src" or self._context.relsrcdir.startswith(
"js/src/"
):
return self._context.config.substs.get("MOZ_JS_OPTIMIZE_FLAGS")
return self._context.config.substs.get("MOZ_OPTIMIZE_FLAGS")
def __setitem__(self, key, value):