Skip to content

Commit

Permalink
Add --enable-optimized-module-limit=N configure option
Browse files Browse the repository at this point in the history
  • Loading branch information
feeley committed Nov 13, 2023
1 parent 63bcb0a commit 60baa5e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 8 deletions.
7 changes: 7 additions & 0 deletions INSTALL.txt
Expand Up @@ -195,6 +195,13 @@ The configure options which are specific to the Gambit system are:
compile each Scheme module as a single C function
when it has at most N control points (N defaults
to 30000, use N=0 to avoid a limit)
--enable-optimized-module-limit=N
set the maximal size of a module to use the normal C
compilation optimization level (N is the number of
control points in the module beyond which the
optimization level is lowered; N=0 deactivates the
lowering of the optimization level; N=20000 is the
default)
--enable-c-opt[=level] use higher C optimization level
--enable-trust-c-tco trust C compiler does TCO properly (default is NO)
--enable-gcc-opts use expensive GCC optimizations
Expand Down
37 changes: 37 additions & 0 deletions configure
Expand Up @@ -941,6 +941,9 @@ CONF_VOIDSTAR_WIDTH
EGREP
GREP
CONF_MAX_CHR
CONF_GNUC_HOST_FUNCTION_ATTRIBUTES_OPTIMIZED_MODULE
CONF_GNUC_HOST_FUNCTION_ATTRIBUTES_UNOPTIMIZED_MODULE
CONF_OPTIMIZED_MODULE_LIMIT
CONF_SINGLE_HOST_LIMIT
CONF_ACTIVITY_LOG
ENABLE_GUIDE
Expand Down Expand Up @@ -1044,6 +1047,7 @@ enable_coverage
enable_feedback1
enable_feedback2
enable_single_host
enable_optimized_module_limit
enable_lowlevel_exec
enable_inline_jumps
enable_trust_c_tco
Expand Down Expand Up @@ -1778,6 +1782,13 @@ Optional Features:
the maximum number of control points in the module
to use single host mode and the special case N=0
avoids a limit)
--enable-optimized-module-limit=N
set the maximal size of a module to use the normal C
compilation optimization level (N is the number of
control points in the module beyond which the
optimization level is lowered; N=0 deactivates the
lowering of the optimization level; N=20000 is the
default)
--enable-lowlevel-exec build system so C and machine code can be mixed
(default is NO)
--enable-inline-jumps generate inline code for jumps (default is NO)
Expand Down Expand Up @@ -5114,6 +5125,27 @@ fi
###############################################################################
#
# Determine the largest size of a module where the normal C compilation
# optimization level will be used. Beyond that limit the optimization level
# is lowered to keep the compilation time reasonable for large modules.
# A setting of 0 deactivates the lowering of the optimization level.
# Check whether --enable-optimized-module-limit was given.
if test "${enable_optimized_module_limit+set}" = set; then :
enableval=$enable_optimized_module_limit; ENABLE_OPTIMIZED_MODULE_LIMIT=$enableval
else
ENABLE_OPTIMIZED_MODULE_LIMIT=20000
fi
CONF_OPTIMIZED_MODULE_LIMIT="$ENABLE_OPTIMIZED_MODULE_LIMIT"
###############################################################################
#
# Check if the system must support mixing the execution of code generated
Expand Down Expand Up @@ -10945,6 +10977,11 @@ DASH_mpc64="$ac_cv_DASH_mpc64"
fi
if test "$DASH_fexpensive_optimizations" != ""; then
# turn off expensive optimizations when module is beyond normal limit
CONF_GNUC_HOST_FUNCTION_ATTRIBUTES_UNOPTIMIZED_MODULE="__attribute__ ((optimize (\"no-expensive-optimizations\")))"
fi
# preprocessor options:
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $C_COMPILER accepts -no-cpp-precomp" >&5
$as_echo_n "checking whether $C_COMPILER accepts -no-cpp-precomp... " >&6; }
Expand Down
24 changes: 24 additions & 0 deletions configure.ac
Expand Up @@ -511,6 +511,25 @@ fi

AC_SUBST(CONF_SINGLE_HOST_LIMIT)

###############################################################################
#
# Determine the largest size of a module where the normal C compilation
# optimization level will be used. Beyond that limit the optimization level
# is lowered to keep the compilation time reasonable for large modules.
# A setting of 0 deactivates the lowering of the optimization level.

AC_ARG_ENABLE(optimized-module-limit,
AS_HELP_STRING([--enable-optimized-module-limit=N],
[set the maximal size of a module to use the normal C compilation optimization level (N is the number of control points in the module beyond which the optimization level is lowered; N=0 deactivates the lowering of the optimization level; N=20000 is the default)]),
ENABLE_OPTIMIZED_MODULE_LIMIT=$enableval,
ENABLE_OPTIMIZED_MODULE_LIMIT=20000)

CONF_OPTIMIZED_MODULE_LIMIT="$ENABLE_OPTIMIZED_MODULE_LIMIT"

AC_SUBST(CONF_OPTIMIZED_MODULE_LIMIT)
AC_SUBST(CONF_GNUC_HOST_FUNCTION_ATTRIBUTES_UNOPTIMIZED_MODULE)
AC_SUBST(CONF_GNUC_HOST_FUNCTION_ATTRIBUTES_OPTIMIZED_MODULE)

###############################################################################
#
# Check if the system must support mixing the execution of code generated
Expand Down Expand Up @@ -2375,6 +2394,11 @@ if test "$C_COMP_GNUC" = yes; then

fi

if test "$DASH_fexpensive_optimizations" != ""; then
# turn off expensive optimizations when module is beyond normal limit
CONF_GNUC_HOST_FUNCTION_ATTRIBUTES_UNOPTIMIZED_MODULE="__attribute__ ((optimize (\"no-expensive-optimizations\")))"
fi

# preprocessor options:
AC_CHECK_C_COMPILER_OPT(-no-cpp-precomp,DASH_no_cpp_precomp)

Expand Down
32 changes: 24 additions & 8 deletions include/gambit.h.in
Expand Up @@ -1207,27 +1207,43 @@
* procedures (default) per Scheme module?
*/

#ifndef ___SINGLE_HOST_LIMIT
#define ___SINGLE_HOST_LIMIT @CONF_SINGLE_HOST_LIMIT@
#endif

#ifndef ___OPTIMIZED_MODULE_LIMIT
#define ___OPTIMIZED_MODULE_LIMIT @CONF_OPTIMIZED_MODULE_LIMIT@
#endif

#ifdef ___SINGLE_HOST
#ifdef ___MULTIPLE_HOSTS
#error "Define either ___SINGLE_HOST or ___MULTIPLE_HOSTS"
#endif
/* downgrade to multiple C host procedures when code is very big */
#ifdef ___LBLCOUNT
#ifndef ___SINGLE_HOST_LIMIT
#define ___SINGLE_HOST_LIMIT @CONF_SINGLE_HOST_LIMIT@
#endif
#if ___SINGLE_HOST_LIMIT > 0 && ___LBLCOUNT > ___SINGLE_HOST_LIMIT
/* downgrade to multiple C host procedures when single-host limit is exceeded */
#if defined(___LBLCOUNT) && ___SINGLE_HOST_LIMIT > 0 && ___LBLCOUNT > ___SINGLE_HOST_LIMIT
#undef ___SINGLE_HOST
#undef ___MULTIPLE_HOSTS
#define ___MULTIPLE_HOSTS
#endif
#endif
#else
#ifndef ___MULTIPLE_HOSTS
#define ___MULTIPLE_HOSTS
#endif
#endif

#ifndef ___GNUC_HOST_FUNCTION_ATTRIBUTES
#if !__clang__ && ___GNUC_VERSION >= 400000
/* downgrade optimization level when optimized-module limit is exceeded */
#if defined(___LBLCOUNT) && ___OPTIMIZED_MODULE_LIMIT > 0 && ___LBLCOUNT > ___OPTIMIZED_MODULE_LIMIT
#define ___GNUC_HOST_FUNCTION_ATTRIBUTES @CONF_GNUC_HOST_FUNCTION_ATTRIBUTES_UNOPTIMIZED_MODULE@
#else
#define ___GNUC_HOST_FUNCTION_ATTRIBUTES @CONF_GNUC_HOST_FUNCTION_ATTRIBUTES_OPTIMIZED_MODULE@
#endif
#else
#define ___GNUC_HOST_FUNCTION_ATTRIBUTES
#endif
#endif

/*
* Compiling for dynamic loading or not (default).
*/
Expand Down Expand Up @@ -5193,7 +5209,7 @@ ___SET_R0(___ps->handler_break)
#define ___W_ALL ___SM(___MW_ALL,___PW_ALL)

#define ___BEGIN_COD \
___HIDDEN void ___HOST_PROC ___P((___processor_state ___ps),(___ps) \
___HIDDEN void ___GNUC_HOST_FUNCTION_ATTRIBUTES ___HOST_PROC ___P((___processor_state ___ps),(___ps) \
___processor_state ___ps;) { \
___WORD ___pc; { ___WORD ___start, ___temp; \
___S32 ___s32_temp; /*******************/ \
Expand Down

2 comments on commit 60baa5e

@gambiteer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many control points are in the files in the Gambit runtime and compiler?

@feeley
Copy link
Member Author

@feeley feeley commented on 60baa5e Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ fgrep ___LBLCOUNT */_*.c | sed -e 's/\([^:]*\):.* \([0-9]*\)/\2 \1/' | sort -nr
6629 gsc/_t-univ-2.c
6387 lib/_io.c
6305 lib/_std.c
5853 lib/_num.c
4281 gsc/_prims.c
4220 gsc/_t-univ-4.c
3899 gsc/_t-univ-3.c
3426 gsc/_t-univ-1.c
3254 gsc/_t-c-2.c
2878 lib/_repl.c
2694 lib/_eval.c
2605 gsc/_front.c
2427 lib/_module.c
2354 lib/_nonstd.c
2262 gsc/_ptree1.c
2232 lib/_system.c
2127 gsc/_ptree2.c
2043 gsc/_gvm.c
2001 gsc/_t-cpu-backend-x86.c
1883 gsc/_x86.c
1807 gsc/_t-c-1.c
1729 gsc/_t-cpu-abstract-machine.c
1476 lib/_kernel.c
1155 lib/_thread.c
1150 gsc/_t-cpu-backend-arm.c
1043 gsc/_t-cpu-backend-riscv.c
1014 gsc/_arm.c
860 gsc/_source.c
858 gsc/_riscv.c
721 gsc/_asm.c
652 gsc/_utils.c
603 gsc/_t-cpu-primitives.c
464 gsc/_gsc.c
454 gsc/_t-c-3.c
350 gsc/_codegen.c
335 gsc/_gsclib.c
281 gsc/_back.c
280 gsc/_host.c
271 gsc/_env.c
267 gsc/_parms.c
183 gsi/_gsi.c
178 gsc/_t-cpu-object-desc.c
101 gsc/_t-cpu.c
24 gsc/_t-cpu-utils.c
18 gsc/_gscdebug.c
2 gsi/_gsilib.c
2 gsc/_assert.c

Please sign in to comment.