From a5803441934b5a128f02169c37e4e00b25b4fc10 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 10 Jun 2019 10:08:03 +0200 Subject: [PATCH] add speed parameter --- src/comp.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/comp.c b/src/comp.c index 0098b814581..7de222b5b2b 100644 --- a/src/comp.c +++ b/src/comp.c @@ -30,6 +30,8 @@ along with GNU Emacs. If not, see . */ #include "atimer.h" #include "window.h" +#define DEFAULT_SPEED 2 /* From 0 to 3 map to gcc -O */ + #define COMP_DEBUG 1 #define MAX_FUN_NAME 256 @@ -194,7 +196,7 @@ INLINE static void pop (unsigned n, gcc_jit_lvalue ***stack_ref, gcc_jit_rvalue *args[]); void emacs_native_compile (const char *lisp_f_name, const char *c_f_name, - Lisp_Object func, bool dump_asm); + Lisp_Object func, int opt_level, bool dump_asm); static void @@ -1461,7 +1463,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, void emacs_native_compile (const char *lisp_f_name, const char *c_f_name, - Lisp_Object func, bool dump_asm) + Lisp_Object func, int opt_level, bool dump_asm) { Lisp_Object bytestr = AREF (func, COMPILED_BYTECODE); CHECK_STRING (bytestr); @@ -1487,6 +1489,10 @@ emacs_native_compile (const char *lisp_f_name, const char *c_f_name, sigset_t oldset; block_atimers (&oldset); + gcc_jit_context_set_int_option (comp.ctxt, + GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, + opt_level); + comp_f_res_t comp_res = compile_f (c_f_name, bytestr_length, SDATA (bytestr), XFIXNAT (maxdepth) + 1, vectorp, ASIZE (vector), @@ -1512,9 +1518,9 @@ emacs_native_compile (const char *lisp_f_name, const char *c_f_name, } DEFUN ("native-compile", Fnative_compile, Snative_compile, - 1, 2, 0, + 1, 3, 0, doc: /* Compile as native code function FUNC and load it. */) /* FIXME doc */ - (Lisp_Object func, Lisp_Object disassemble) + (Lisp_Object func, Lisp_Object speed, Lisp_Object disassemble) { static char c_f_name[MAX_FUN_NAME]; char *lisp_f_name; @@ -1543,7 +1549,20 @@ DEFUN ("native-compile", Fnative_compile, Snative_compile, if (!COMPILEDP (func)) error ("Not a byte-compiled function"); - emacs_native_compile (lisp_f_name, c_f_name, func, disassemble != Qnil); + if (speed != Qnil && + (!FIXNUMP (speed) || + !(XFIXNUM (speed) >= 0 && + XFIXNUM (speed) <= 3))) + error ("opt-level must be number between 0 and 3"); + + int opt_level; + if (speed == Qnil) + opt_level = DEFAULT_SPEED; + else + opt_level = XFIXNUM (speed); + + emacs_native_compile (lisp_f_name, c_f_name, func, opt_level, + disassemble != Qnil); if (disassemble) { -- 2.39.5