Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c94f97

Browse files
committed
Issue #26359: Add the --with-optimizations flag.
1 parent 653c850 commit 8c94f97

4 files changed

Lines changed: 103 additions & 17 deletions

File tree

Makefile.pre.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ LIBRARY_OBJS= \
481481
# Rules
482482

483483
# Default target
484-
all: build_all
484+
all: @DEF_MAKE_ALL_RULE@
485485
build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed python-config
486486

487487
# Compile a binary with profile guided optimization.
@@ -505,7 +505,7 @@ profile-opt:
505505
$(MAKE) profile-removal
506506

507507
build_all_generate_profile:
508-
$(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LIBS="$(LIBS)"
508+
$(MAKE) @DEF_MAKE_RULE@ CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LIBS="$(LIBS)"
509509

510510
run_profile_task:
511511
: # FIXME: can't run for a cross build
@@ -515,14 +515,14 @@ build_all_merge_profile:
515515
$(LLVM_PROF_MERGER)
516516

517517
build_all_use_profile:
518-
$(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) @LTOFLAGS@"
518+
$(MAKE) @DEF_MAKE_RULE@ CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) @LTOFLAGS@"
519519

520520
# Compile and run with gcov
521521
.PHONY=coverage coverage-lcov coverage-report
522522
coverage:
523523
@echo "Building with support for coverage checking:"
524524
$(MAKE) clean profile-removal
525-
$(MAKE) all CFLAGS="$(CFLAGS) -O0 -pg -fprofile-arcs -ftest-coverage" LIBS="$(LIBS) -lgcov"
525+
$(MAKE) @DEF_MAKE_RULE@ CFLAGS="$(CFLAGS) -O0 -pg -fprofile-arcs -ftest-coverage" LIBS="$(LIBS) -lgcov"
526526

527527
coverage-lcov:
528528
@echo "Creating Coverage HTML report with LCOV:"

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ Windows
256256
Build
257257
-----
258258

259+
- Issue #26359: Add the --with-optimizations configure flag.
260+
259261
- Issue #27713: Suppress spurious build warnings when updating importlib's
260262
bootstrap files. Patch by Xiang Zhang
261263

configure

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,8 @@ LLVM_PROF_MERGER
674674
PGO_PROF_USE_FLAG
675675
PGO_PROF_GEN_FLAG
676676
LTOFLAGS
677+
DEF_MAKE_RULE
678+
DEF_MAKE_ALL_RULE
677679
ABIFLAGS
678680
LN
679681
MKDIR_P
@@ -774,7 +776,6 @@ infodir
774776
docdir
775777
oldincludedir
776778
includedir
777-
runstatedir
778779
localstatedir
779780
sharedstatedir
780781
sysconfdir
@@ -808,6 +809,7 @@ with_suffix
808809
enable_shared
809810
enable_profiling
810811
with_pydebug
812+
with_optimizations
811813
with_lto
812814
with_hash_algorithm
813815
with_address_sanitizer
@@ -885,7 +887,6 @@ datadir='${datarootdir}'
885887
sysconfdir='${prefix}/etc'
886888
sharedstatedir='${prefix}/com'
887889
localstatedir='${prefix}/var'
888-
runstatedir='${localstatedir}/run'
889890
includedir='${prefix}/include'
890891
oldincludedir='/usr/include'
891892
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1138,15 +1139,6 @@ do
11381139
| -silent | --silent | --silen | --sile | --sil)
11391140
silent=yes ;;
11401141

1141-
-runstatedir | --runstatedir | --runstatedi | --runstated \
1142-
| --runstate | --runstat | --runsta | --runst | --runs \
1143-
| --run | --ru | --r)
1144-
ac_prev=runstatedir ;;
1145-
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
1146-
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
1147-
| --run=* | --ru=* | --r=*)
1148-
runstatedir=$ac_optarg ;;
1149-
11501142
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
11511143
ac_prev=sbindir ;;
11521144
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1284,7 +1276,7 @@ fi
12841276
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
12851277
datadir sysconfdir sharedstatedir localstatedir includedir \
12861278
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
1287-
libdir localedir mandir runstatedir
1279+
libdir localedir mandir
12881280
do
12891281
eval ac_val=\$$ac_var
12901282
# Remove trailing slashes.
@@ -1437,7 +1429,6 @@ Fine tuning of the installation directories:
14371429
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
14381430
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
14391431
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
1440-
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
14411432
--libdir=DIR object code libraries [EPREFIX/lib]
14421433
--includedir=DIR C header files [PREFIX/include]
14431434
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@@ -1500,6 +1491,8 @@ Optional Packages:
15001491
compiler
15011492
--with-suffix=.exe set executable suffix
15021493
--with-pydebug build with Py_DEBUG defined
1494+
--with-optimizations Enable all optimizations when available (LTO, PGO,
1495+
etc). Disabled by default.
15031496
--with-lto Enable Link Time Optimization in PGO builds.
15041497
Disabled by default.
15051498
--with-hash-algorithm=[fnv|siphash24]
@@ -6528,6 +6521,46 @@ $as_echo "no" >&6; }
65286521
fi
65296522

65306523

6524+
# Enable optimization flags
6525+
6526+
6527+
Py_OPT='false'
6528+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-optimizations" >&5
6529+
$as_echo_n "checking for --with-optimizations... " >&6; }
6530+
6531+
# Check whether --with-optimizations was given.
6532+
if test "${with_optimizations+set}" = set; then :
6533+
withval=$with_optimizations;
6534+
if test "$withval" != no
6535+
then
6536+
Py_OPT='true'
6537+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
6538+
$as_echo "yes" >&6; };
6539+
else
6540+
Py_OPT='false'
6541+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6542+
$as_echo "no" >&6; };
6543+
fi
6544+
else
6545+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6546+
$as_echo "no" >&6; }
6547+
fi
6548+
6549+
if test "$Py_OPT" = 'true' ; then
6550+
Py_LTO='true'
6551+
case $ac_sys_system in
6552+
Darwin*)
6553+
# At least on macOS El Capitan, LTO does not work with PGO.
6554+
Py_LTO='false'
6555+
;;
6556+
esac
6557+
DEF_MAKE_ALL_RULE="profile-opt"
6558+
DEF_MAKE_RULE="build_all"
6559+
else
6560+
DEF_MAKE_ALL_RULE="build_all"
6561+
DEF_MAKE_RULE="all"
6562+
fi
6563+
65316564
# Enable LTO flags
65326565

65336566
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-lto" >&5
@@ -17636,3 +17669,13 @@ $SHELL $srcdir/Modules/makesetup -c $srcdir/Modules/config.c.in \
1763617669
-s Modules Modules/Setup.config \
1763717670
Modules/Setup.local Modules/Setup
1763817671
mv config.c Modules
17672+
17673+
if test "$Py_OPT" = 'false' -a "$Py_DEBUG" != 'true'; then
17674+
echo "" >&6
17675+
echo "" >&6
17676+
echo "If you want a release build with all optimizations active (LTO, PGO, etc),"
17677+
echo "please run ./configure --with-optimizations" >&6
17678+
echo "" >&6
17679+
echo "" >&6
17680+
fi
17681+

configure.ac

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,37 @@ else AC_MSG_RESULT(no); Py_DEBUG='false'
12301230
fi],
12311231
[AC_MSG_RESULT(no)])
12321232

1233+
# Enable optimization flags
1234+
AC_SUBST(DEF_MAKE_ALL_RULE)
1235+
AC_SUBST(DEF_MAKE_RULE)
1236+
Py_OPT='false'
1237+
AC_MSG_CHECKING(for --with-optimizations)
1238+
AC_ARG_WITH(optimizations, AS_HELP_STRING([--with-optimizations], [Enable all optimizations when available (LTO, PGO, etc). Disabled by default.]),
1239+
[
1240+
if test "$withval" != no
1241+
then
1242+
Py_OPT='true'
1243+
AC_MSG_RESULT(yes);
1244+
else
1245+
Py_OPT='false'
1246+
AC_MSG_RESULT(no);
1247+
fi],
1248+
[AC_MSG_RESULT(no)])
1249+
if test "$Py_OPT" = 'true' ; then
1250+
Py_LTO='true'
1251+
case $ac_sys_system in
1252+
Darwin*)
1253+
# At least on macOS El Capitan, LTO does not work with PGO.
1254+
Py_LTO='false'
1255+
;;
1256+
esac
1257+
DEF_MAKE_ALL_RULE="profile-opt"
1258+
DEF_MAKE_RULE="build_all"
1259+
else
1260+
DEF_MAKE_ALL_RULE="build_all"
1261+
DEF_MAKE_RULE="all"
1262+
fi
1263+
12331264
# Enable LTO flags
12341265
AC_SUBST(LTOFLAGS)
12351266
AC_MSG_CHECKING(for --with-lto)
@@ -5299,3 +5330,13 @@ $SHELL $srcdir/Modules/makesetup -c $srcdir/Modules/config.c.in \
52995330
-s Modules Modules/Setup.config \
53005331
Modules/Setup.local Modules/Setup
53015332
mv config.c Modules
5333+
5334+
if test "$Py_OPT" = 'false' -a "$Py_DEBUG" != 'true'; then
5335+
echo "" >&AS_MESSAGE_FD
5336+
echo "" >&AS_MESSAGE_FD
5337+
echo "If you want a release build with all optimizations active (LTO, PGO, etc),"
5338+
echo "please run ./configure --with-optimizations" >&AS_MESSAGE_FD
5339+
echo "" >&AS_MESSAGE_FD
5340+
echo "" >&AS_MESSAGE_FD
5341+
fi
5342+

0 commit comments

Comments
 (0)