Add support for GCC compiler command-line options

* lisp/emacs-lisp/comp.el ('native-comp-compiler-options): New option.
* lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Add support
for new 'native-comp-compiler-options'.
* src/comp.c (Fcomp_native_compiler_options_effective_p): New function.
(add_compiler_options): New function.
(Fcomp__compile_ctxt_to_file): Call 'add_compiler_options'.
This commit is contained in:
Arthur Miller 2021-09-10 20:57:19 +02:00 committed by Andrea Corallo
parent 6eba633ead
commit dea67939b6
3 changed files with 79 additions and 0 deletions

View file

@ -2257,6 +2257,9 @@ With argument ARG, insert value in current buffer after the form."
(push `(native-comp-speed . ,native-comp-speed) byte-native-qualities) (push `(native-comp-speed . ,native-comp-speed) byte-native-qualities)
(defvar native-comp-debug) (defvar native-comp-debug)
(push `(native-comp-debug . ,native-comp-debug) byte-native-qualities) (push `(native-comp-debug . ,native-comp-debug) byte-native-qualities)
(defvar native-comp-compiler-options)
(push `(native-comp-compiler-options . ,native-comp-compiler-options)
byte-native-qualities)
(defvar native-comp-driver-options) (defvar native-comp-driver-options)
(push `(native-comp-driver-options . ,native-comp-driver-options) (push `(native-comp-driver-options . ,native-comp-driver-options)
byte-native-qualities) byte-native-qualities)

View file

@ -166,6 +166,16 @@ if `confirm-kill-processes' is non-nil."
:type 'boolean :type 'boolean
:version "28.1") :version "28.1")
(defcustom native-comp-compiler-options nil
"Command line options passed verbatim to GCC compiler.
Note that not all options are meaningful and some options might even
break your Emacs. Use at own risk.
Passing these options is only available in libgccjit version 9
and above."
:type '(repeat string)
:version "28.1")
(defcustom native-comp-driver-options nil (defcustom native-comp-driver-options nil
"Options passed verbatim to the native compiler's back-end driver. "Options passed verbatim to the native compiler's back-end driver.
Note that not all options are meaningful; typically only the options Note that not all options are meaningful; typically only the options
@ -755,6 +765,8 @@ Returns ELT."
:documentation "Default speed for this compilation unit.") :documentation "Default speed for this compilation unit.")
(debug native-comp-debug :type number (debug native-comp-debug :type number
:documentation "Default debug level for this compilation unit.") :documentation "Default debug level for this compilation unit.")
(compiler-options native-comp-compiler-options :type list
:documentation "Options for the GCC compiler.")
(driver-options native-comp-driver-options :type list (driver-options native-comp-driver-options :type list
:documentation "Options for the GCC driver.") :documentation "Options for the GCC driver.")
(top-level-forms () :type list (top-level-forms () :type list
@ -1347,6 +1359,8 @@ clashes."
byte-native-qualities) byte-native-qualities)
(comp-ctxt-debug comp-ctxt) (alist-get 'native-comp-debug (comp-ctxt-debug comp-ctxt) (alist-get 'native-comp-debug
byte-native-qualities) byte-native-qualities)
(comp-ctxt-compiler-options comp-ctxt) (alist-get 'native-comp-compiler-options
byte-native-qualities)
(comp-ctxt-driver-options comp-ctxt) (alist-get 'native-comp-driver-options (comp-ctxt-driver-options comp-ctxt) (alist-get 'native-comp-driver-options
byte-native-qualities) byte-native-qualities)
(comp-ctxt-top-level-forms comp-ctxt) (comp-ctxt-top-level-forms comp-ctxt)
@ -3663,6 +3677,8 @@ Prepare every function for final compilation and drive the C back-end."
comp-libgccjit-reproducer ,comp-libgccjit-reproducer comp-libgccjit-reproducer ,comp-libgccjit-reproducer
comp-ctxt ,comp-ctxt comp-ctxt ,comp-ctxt
native-comp-eln-load-path ',native-comp-eln-load-path native-comp-eln-load-path ',native-comp-eln-load-path
native-comp-compiler-options
',native-comp-compiler-options
native-comp-driver-options native-comp-driver-options
',native-comp-driver-options ',native-comp-driver-options
load-path ',load-path) load-path ',load-path)
@ -3926,6 +3942,8 @@ display a message."
comp-libgccjit-reproducer ,comp-libgccjit-reproducer comp-libgccjit-reproducer ,comp-libgccjit-reproducer
comp-async-compilation t comp-async-compilation t
native-comp-eln-load-path ',native-comp-eln-load-path native-comp-eln-load-path ',native-comp-eln-load-path
native-comp-compiler-options
',native-comp-compiler-options
native-comp-driver-options native-comp-driver-options
',native-comp-driver-options ',native-comp-driver-options
load-path ',load-path load-path ',load-path

View file

@ -515,6 +515,7 @@ typedef struct {
typedef struct { typedef struct {
EMACS_INT speed; EMACS_INT speed;
EMACS_INT debug; EMACS_INT debug;
Lisp_Object compiler_options;
Lisp_Object driver_options; Lisp_Object driver_options;
gcc_jit_context *ctxt; gcc_jit_context *ctxt;
gcc_jit_type *void_type; gcc_jit_type *void_type;
@ -4383,6 +4384,22 @@ DEFUN ("comp-native-driver-options-effective-p",
} }
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#pragma GCC diagnostic ignored "-Waddress"
DEFUN ("comp-native-compiler-options-effective-p",
Fcomp_native_compiler_options_effective_p,
Scomp_native_compiler_options_effective_p,
0, 0, 0,
doc: /* Return t if `comp-native-compiler-options' is effective. */)
(void)
{
#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option)
if (gcc_jit_context_add_command_line_option)
return Qt;
#endif
return Qnil;
}
#pragma GCC diagnostic pop
static void static void
add_driver_options (void) add_driver_options (void)
{ {
@ -4422,6 +4439,43 @@ add_driver_options (void)
#endif #endif
} }
static void
add_compiler_options (void)
{
Lisp_Object options = Fsymbol_value (Qnative_comp_compiler_options);
#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option)
load_gccjit_if_necessary (true);
if (!NILP (Fcomp_native_compiler_options_effective_p ()))
FOR_EACH_TAIL (options)
gcc_jit_context_add_command_line_option (comp.ctxt,
/* FIXME: Need to encode
this, but how? either
ENCODE_FILE or
ENCODE_SYSTEM. */
SSDATA (XCAR (options)));
#endif
if (CONSP (options))
xsignal1 (Qnative_compiler_error,
build_string ("Customizing native compiler options"
" via `comp-native-compiler-options' is"
" only available on libgccjit version 9"
" and above."));
/* Captured `comp-native-compiler-options' because file-local. */
#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option)
options = comp.compiler_options;
if (!NILP (Fcomp_native_compiler_options_effective_p ()))
FOR_EACH_TAIL (options)
gcc_jit_context_add_command_line_option (comp.ctxt,
/* FIXME: Need to encode
this, but how? either
ENCODE_FILE or
ENCODE_SYSTEM. */
SSDATA (XCAR (options)));
#endif
}
DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file, DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file,
Scomp__compile_ctxt_to_file, Scomp__compile_ctxt_to_file,
1, 1, 0, 1, 1, 0,
@ -4467,6 +4521,7 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file,
comp.debug = XFIXNUM (CALL1I (comp-ctxt-debug, Vcomp_ctxt)); comp.debug = XFIXNUM (CALL1I (comp-ctxt-debug, Vcomp_ctxt));
eassert (comp.debug < INT_MAX); eassert (comp.debug < INT_MAX);
comp.driver_options = CALL1I (comp-ctxt-driver-options, Vcomp_ctxt); comp.driver_options = CALL1I (comp-ctxt-driver-options, Vcomp_ctxt);
comp.compiler_options = CALL1I (comp-ctxt-compiler-options, Vcomp_ctxt);
if (comp.debug) if (comp.debug)
gcc_jit_context_set_bool_option (comp.ctxt, gcc_jit_context_set_bool_option (comp.ctxt,
@ -4541,6 +4596,7 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file,
"-fdisable-tree-isolate-paths"); "-fdisable-tree-isolate-paths");
#endif #endif
add_compiler_options ();
add_driver_options (); add_driver_options ();
if (comp.debug > 1) if (comp.debug > 1)
@ -5248,6 +5304,7 @@ compiled one. */);
DEFSYM (Qnative_comp_speed, "native-comp-speed"); DEFSYM (Qnative_comp_speed, "native-comp-speed");
DEFSYM (Qnative_comp_debug, "native-comp-debug"); DEFSYM (Qnative_comp_debug, "native-comp-debug");
DEFSYM (Qnative_comp_driver_options, "native-comp-driver-options"); DEFSYM (Qnative_comp_driver_options, "native-comp-driver-options");
DEFSYM (Qnative_comp_compiler_options, "native-comp-compiler-options");
DEFSYM (Qcomp_libgccjit_reproducer, "comp-libgccjit-reproducer"); DEFSYM (Qcomp_libgccjit_reproducer, "comp-libgccjit-reproducer");
/* Limple instruction set. */ /* Limple instruction set. */
@ -5357,6 +5414,7 @@ compiled one. */);
defsubr (&Scomp_el_to_eln_rel_filename); defsubr (&Scomp_el_to_eln_rel_filename);
defsubr (&Scomp_el_to_eln_filename); defsubr (&Scomp_el_to_eln_filename);
defsubr (&Scomp_native_driver_options_effective_p); defsubr (&Scomp_native_driver_options_effective_p);
defsubr (&Scomp_native_compiler_options_effective_p);
defsubr (&Scomp__install_trampoline); defsubr (&Scomp__install_trampoline);
defsubr (&Scomp__init_ctxt); defsubr (&Scomp__init_ctxt);
defsubr (&Scomp__release_ctxt); defsubr (&Scomp__release_ctxt);