Bug 1411081 - Move --enable-optimize/MOZ_OPTIMIZE to moz.configure; r?glandium draft
authorGregory Szorc <gps@mozilla.com>
Tue, 24 Oct 2017 12:47:37 -0700
changeset 685687 ab7235e6a084eb10261ae409f938c0dcb6c159a8
parent 685686 891db95c9c1971bd9b50702240434acc76cfb041
child 685688 96d85c9cd9ae89c707f52cb7d9c2c29f356d8bd7
push id86013
push usergszorc@mozilla.com
push dateWed, 25 Oct 2017 01:20:42 +0000
reviewersglandium
bugs1411081
milestone58.0a1
Bug 1411081 - Move --enable-optimize/MOZ_OPTIMIZE to moz.configure; r?glandium The Rust optimization logic is tied to --enable-optimize/MOZ_OPTIMIZE and --enable-debug/MOZ_DEBUG. In order to more easily implement more customization, let's move --enable-optimize/MOZ_OPTIMIZE to moz.configure so its value can be consulted there. The logic here is a bit wonky. The option behaves like a boolean flag with an optional value. We convert this option to a namespace with a numeric level and string of compiler flags. The compiler flags string is passed to old-configure where it is used to populate MOZ_OPTIMIZE_FLAGS. We stop short of moving all references to MOZ_OPTIMIZE_FLAGS to moz.configure because there are random references throughout old-configure and I don't want to scope bloat. I verified that we don't use MOZ_OPTIMIZE_FLAGS for anything meaningful before we replace its old-configure derived value with the value from moz.configure. There is obviously a bunch of improvement that remains. Again, my immediate goal is unblocking some Rust optimization work, which doesn't require the scope bloat. MozReview-Commit-ID: 6iNDu2HwLGr
build/moz.configure/old.configure
build/moz.configure/toolchain.configure
js/src/old-configure.in
old-configure.in
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -208,17 +208,16 @@ def old_configure_options(*options):
     '--enable-memory-sanitizer',
     '--enable-mobile-optimize',
     '--enable-necko-wifi',
     '--enable-negotiateauth',
     '--enable-nfc',
     '--enable-nspr-build',
     '--enable-official-branding',
     '--enable-oom-breakpoint',
-    '--enable-optimize',
     '--enable-parental-controls',
     '--enable-pie',
     '--enable-posix-nspr-emulation',
     '--enable-pref-extensions',
     '--enable-pulseaudio',
     '--enable-raw',
     '--enable-readline',
     '--enable-reflow-perf',
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -6,16 +6,55 @@
 
 # PGO
 # ==============================================================
 option(env='MOZ_PGO', help='Build with profile guided optimizations')
 
 set_config('MOZ_PGO', depends('MOZ_PGO')(lambda x: bool(x)))
 add_old_configure_assignment('MOZ_PGO', depends('MOZ_PGO')(lambda x: bool(x)))
 
+# Code optimization
+# ==============================================================
+
+# Code optimization is enabled by default.
+# unset: no optimization
+# 1: basic optimization
+# 2: more optimization
+js_option('--enable-optimize',
+          nargs='?',
+          default='1',
+          help='Compiler optimization level (1 or 2) or flags')
+
+@depends('--enable-optimize')
+def moz_optimize(option):
+    flags = None
+
+    # Explicit value specified.
+    if len(option):
+        if option[0] in ('1', '2'):
+            val = option[0]
+        elif option[0] == '0':
+            val = None
+        else:
+            val = '2'
+            flags = option[0]
+    elif option:
+        val = '1'
+    else:
+        val = None
+
+    return namespace(
+        optimize=val,
+        flags=flags,
+    )
+
+set_config('MOZ_OPTIMIZE', moz_optimize.optimize)
+add_old_configure_assignment('MOZ_OPTIMIZE', moz_optimize.optimize)
+add_old_configure_assignment('MOZ_CONFIGURE_OPTIMIZE_FLAGS', moz_optimize.flags)
+
 # yasm detection
 # ==============================================================
 yasm = check_prog('YASM', ['yasm'], allow_missing=True)
 
 
 @depends_if(yasm)
 @checking('yasm version')
 def yasm_version(yasm):
--- a/js/src/old-configure.in
+++ b/js/src/old-configure.in
@@ -1432,28 +1432,21 @@ MOZ_ARG_HEADER(Debugging and Optimizatio
 
 dnl ========================================================
 dnl = Enable code optimization. ON by default.
 dnl ========================================================
 if test -z "$MOZ_OPTIMIZE_FLAGS"; then
 	MOZ_OPTIMIZE_FLAGS="-O"
 fi
 
-MOZ_ARG_ENABLE_STRING(optimize,
-[  --disable-optimize      Disable compiler optimization
-  --enable-optimize=[OPT] Specify compiler optimization flags [OPT=-O]],
-[ if test "$enableval" != "no"; then
-    MOZ_OPTIMIZE=1
-    if test -n "$enableval" -a "$enableval" != "yes"; then
-        MOZ_OPTIMIZE_FLAGS=`echo "$enableval" | sed -e 's|\\\ | |g'`
-        MOZ_OPTIMIZE=2
-    fi
-else
-    MOZ_OPTIMIZE=
-fi ], MOZ_OPTIMIZE=1)
+# 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
 
 MOZ_SET_FRAMEPTR_FLAGS
 
 if test "$COMPILE_ENVIRONMENT"; then
 if test -n "$MOZ_OPTIMIZE"; then
     AC_MSG_CHECKING([for valid optimization flags])
     _SAVE_CFLAGS=$CFLAGS
     CFLAGS="$CFLAGS $MOZ_OPTIMIZE_FLAGS"
@@ -1464,17 +1457,16 @@ if test -n "$MOZ_OPTIMIZE"; then
     AC_MSG_RESULT([$_results])
     if test "$_results" = "no"; then
         AC_MSG_ERROR([These compiler flags are invalid: $MOZ_OPTIMIZE_FLAGS])
     fi
     CFLAGS=$_SAVE_CFLAGS
 fi
 fi # COMPILE_ENVIRONMENT
 
-AC_SUBST(MOZ_OPTIMIZE)
 AC_SUBST(MOZ_FRAMEPTR_FLAGS)
 AC_SUBST(MOZ_OPTIMIZE_FLAGS)
 AC_SUBST(MOZ_OPTIMIZE_LDFLAGS)
 AC_SUBST(MOZ_PGO_OPTIMIZE_FLAGS)
 
 dnl ========================================================
 dnl = Trace logging. Enabled by default in DEBUG builds.
 dnl ========================================================
--- a/old-configure.in
+++ b/old-configure.in
@@ -3708,28 +3708,21 @@ fi
 
 dnl ========================================================
 dnl = Enable code optimization. ON by default.
 dnl ========================================================
 if test -z "$MOZ_OPTIMIZE_FLAGS"; then
     MOZ_OPTIMIZE_FLAGS="-O"
 fi
 
-MOZ_ARG_ENABLE_STRING(optimize,
-[  --disable-optimize      Disable compiler optimization
-  --enable-optimize=[OPT] Specify compiler optimization flags [OPT=-O]],
-[ if test "$enableval" != "no"; then
-    MOZ_OPTIMIZE=1
-    if test -n "$enableval" -a "$enableval" != "yes"; then
-        MOZ_OPTIMIZE_FLAGS=`echo "$enableval" | sed -e 's|\\\ | |g'`
-        MOZ_OPTIMIZE=2
-    fi
-else
-    MOZ_OPTIMIZE=
-fi ], MOZ_OPTIMIZE=1)
+# 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
 
 MOZ_SET_FRAMEPTR_FLAGS
 
 if test "$COMPILE_ENVIRONMENT"; then
 if test -n "$MOZ_OPTIMIZE"; then
     AC_MSG_CHECKING([for valid C compiler optimization flags])
     _SAVE_CFLAGS=$CFLAGS
     CFLAGS="$CFLAGS $MOZ_OPTIMIZE_FLAGS"
@@ -3740,17 +3733,16 @@ if test -n "$MOZ_OPTIMIZE"; then
     AC_MSG_RESULT([$_results])
     if test "$_results" = "no"; then
         AC_MSG_ERROR([These compiler flags for C are invalid: $MOZ_OPTIMIZE_FLAGS])
     fi
     CFLAGS=$_SAVE_CFLAGS
 fi
 fi # COMPILE_ENVIRONMENT
 
-AC_SUBST(MOZ_OPTIMIZE)
 AC_SUBST(MOZ_FRAMEPTR_FLAGS)
 AC_SUBST(MOZ_OPTIMIZE_FLAGS)
 AC_SUBST(MOZ_OPTIMIZE_LDFLAGS)
 AC_SUBST(MOZ_PGO_OPTIMIZE_FLAGS)
 
 dnl ========================================================
 dnl = Disable treating compiler warnings as errors
 dnl ========================================================