>From d0c2b4f882fc67562de6ad67f6dcfdfe6378c32b Mon Sep 17 00:00:00 2001 From: Arthur Miller Date: Tue, 31 Aug 2021 07:15:01 +0200 Subject: [PATCH] Native comp: gcc cmdopts + rename driver-options to backend-options. --- lisp/emacs-lisp/bytecomp.el | 4 +- lisp/emacs-lisp/comp.el | 36 ++++++++--- src/comp.c | 122 ++++++++++++++++++++++++++---------- 3 files changed, 118 insertions(+), 44 deletions(-) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 145cdbaa6e..c2f7b951d9 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -2257,8 +2257,8 @@ byte-compile-from-buffer (push `(native-comp-speed . ,native-comp-speed) byte-native-qualities) (defvar native-comp-debug) (push `(native-comp-debug . ,native-comp-debug) byte-native-qualities) - (defvar native-comp-driver-options) - (push `(native-comp-driver-options . ,native-comp-driver-options) + (defvar native-comp-backend-options) + (push `(native-comp-backend-options . ,native-comp-backend-options) byte-native-qualities) (defvar no-native-compile) (push `(no-native-compile . ,no-native-compile) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 80a1da5ad8..dab34f89e4 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -166,14 +166,24 @@ native-comp-async-query-on-exit :type 'boolean :version "28.1") -(defcustom native-comp-driver-options nil +(defcustom native-comp-compiler-options nil + "Command line options passed to the 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-backend-options nil "Options passed verbatim to the native compiler's back-end driver. Note that not all options are meaningful; typically only the options affecting the assembler and linker are likely to be useful. Passing these options is only available in libgccjit version 9 and above." - :type '(repeat string) ; FIXME is this right? + :type '(repeat string) :version "28.1") (defcustom comp-libgccjit-reproducer nil @@ -755,8 +765,10 @@ comp-data-container :documentation "Default speed for this compilation unit.") (debug native-comp-debug :type number :documentation "Default debug level for this compilation unit.") - (driver-options native-comp-driver-options :type list - :documentation "Options for the GCC driver.") + (compiler-options native-comp-compiler-options :type list + :documentation "Options for the GCC C compiler.") + (backend-options native-comp-backend-options :type list + :documentation "Options for the GCC driver.") (top-level-forms () :type list :documentation "List of spilled top level forms.") (funcs-h (make-hash-table :test #'equal) :type hash-table @@ -1347,7 +1359,9 @@ comp-spill-lap-function byte-native-qualities) (comp-ctxt-debug comp-ctxt) (alist-get 'native-comp-debug byte-native-qualities) - (comp-ctxt-driver-options comp-ctxt) (alist-get 'native-comp-driver-options + (comp-ctxt-compiler-options comp-ctxt) (alist-get 'native-comp-compiler-options + byte-native-qualities) + (comp-ctxt-backend-options comp-ctxt) (alist-get 'native-comp-backend-options byte-native-qualities) (comp-ctxt-top-level-forms comp-ctxt) (cl-loop @@ -3663,8 +3677,10 @@ comp-final comp-libgccjit-reproducer ,comp-libgccjit-reproducer comp-ctxt ,comp-ctxt native-comp-eln-load-path ',native-comp-eln-load-path - native-comp-driver-options - ',native-comp-driver-options + native-comp-backend-options + ',native-comp-backend-options + native-comp-compiler-options + ',native-comp-compiler-options load-path ',load-path) ,native-comp-async-env-modifier-form (message "Compiling %s..." ',output) @@ -3926,8 +3942,10 @@ comp-run-async-workers comp-libgccjit-reproducer ,comp-libgccjit-reproducer comp-async-compilation t native-comp-eln-load-path ',native-comp-eln-load-path - native-comp-driver-options - ',native-comp-driver-options + native-comp-backend-options + ',native-comp-backend-options + native-comp-compiler-options + ',native-comp-compiler-options load-path ',load-path warning-fill-column most-positive-fixnum) ,native-comp-async-env-modifier-form diff --git a/src/comp.c b/src/comp.c index 3ea2836560..44cc3a7c76 100644 --- a/src/comp.c +++ b/src/comp.c @@ -509,7 +509,8 @@ #define NUM_CAST_TYPES 15 typedef struct { EMACS_INT speed; EMACS_INT debug; - Lisp_Object driver_options; + Lisp_Object backend_options; + Lisp_Object compiler_options; gcc_jit_context *ctxt; gcc_jit_type *void_type; gcc_jit_type *bool_type; @@ -4361,11 +4362,11 @@ DEFUN ("comp--release-ctxt", Fcomp__release_ctxt, Scomp__release_ctxt, } #pragma GCC diagnostic ignored "-Waddress" -DEFUN ("comp-native-driver-options-effective-p", - Fcomp_native_driver_options_effective_p, - Scomp_native_driver_options_effective_p, +DEFUN ("comp-native-backend-options-effective-p", + Fcomp_native_backend_options_effective_p, + Scomp_native_backend_options_effective_p, 0, 0, 0, - doc: /* Return t if `comp-native-driver-options' is effective. */) + doc: /* Return t if `comp-native-backend-options' is effective. */) (void) { #if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option) \ @@ -4377,43 +4378,95 @@ DEFUN ("comp-native-driver-options-effective-p", } #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 add_driver_options (void) { - Lisp_Object options = Fsymbol_value (Qnative_comp_driver_options); + Lisp_Object options = Fsymbol_value (Qnative_comp_backend_options); -#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option) \ - || defined (WINDOWSNT) - load_gccjit_if_necessary (true); - if (!NILP (Fcomp_native_driver_options_effective_p ())) + if (!NILP (Fcomp_native_backend_options_effective_p ())) + { + load_gccjit_if_necessary (true); + FOR_EACH_TAIL (options) + gcc_jit_context_add_driver_option (comp.ctxt, + /* FIXME: Need to encode + this, but how? either + ENCODE_FILE or + ENCODE_SYSTEM. */ + SSDATA (XCAR (options))); + } + + if (CONSP (options)) + xsignal1 (Qnative_compiler_error, + build_string ("Customizing native compiler options" + " via `comp-native-backend-options' is" + " only available on libgccjit version 9" + " and above.")); + + /* Captured `comp-native-backend-options' because file-local. */ + if (!NILP (Fcomp_native_backend_options_effective_p ())) + { + options = comp.backend_options; + FOR_EACH_TAIL (options) + gcc_jit_context_add_driver_option (comp.ctxt, + /* FIXME: Need to encode + this, but how? either + ENCODE_FILE or + ENCODE_SYSTEM. */ + SSDATA (XCAR (options))); + } +} + +static void +add_compiler_options (void) +{ + Lisp_Object options = Fsymbol_value (Qnative_comp_compiler_options); + + if (!NILP (Fcomp_native_compiler_options_effective_p ())) + { + load_gccjit_if_necessary (true); FOR_EACH_TAIL (options) - gcc_jit_context_add_driver_option (comp.ctxt, - /* FIXME: Need to encode - this, but how? either - ENCODE_FILE or - ENCODE_SYSTEM. */ - SSDATA (XCAR (options))); -#endif + 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))); + } if (CONSP (options)) xsignal1 (Qnative_compiler_error, build_string ("Customizing native compiler options" - " via `comp-native-driver-options' is" + " via `comp-native-compiler-options' is" " only available on libgccjit version 9" " and above.")); - /* Captured `comp-native-driver-options' because file-local. */ -#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option) \ - || defined (WINDOWSNT) - options = comp.driver_options; - if (!NILP (Fcomp_native_driver_options_effective_p ())) + /* Captured `comp-native-compiler-options' because file-local. */ + if (!NILP (Fcomp_native_compiler_options_effective_p ())) + { + options = comp.compiler_options; FOR_EACH_TAIL (options) - gcc_jit_context_add_driver_option (comp.ctxt, - /* FIXME: Need to encode - this, but how? either - ENCODE_FILE or - ENCODE_SYSTEM. */ - SSDATA (XCAR (options))); -#endif + 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))); + } } DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file, @@ -4460,7 +4513,7 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file, eassert (comp.speed < INT_MAX); comp.debug = XFIXNUM (CALL1I (comp-ctxt-debug, Vcomp_ctxt)); eassert (comp.debug < INT_MAX); - comp.driver_options = CALL1I (comp-ctxt-driver-options, Vcomp_ctxt); + comp.backend_options = CALL1I (comp-ctxt-backend-options, Vcomp_ctxt); if (comp.debug) gcc_jit_context_set_bool_option (comp.ctxt, @@ -4536,6 +4589,7 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file, #endif add_driver_options (); + add_compiler_options (); if (comp.debug > 1) gcc_jit_context_dump_to_file (comp.ctxt, @@ -5241,7 +5295,8 @@ syms_of_comp (void) DEFSYM (Qnative_comp_speed, "native-comp-speed"); DEFSYM (Qnative_comp_debug, "native-comp-debug"); - DEFSYM (Qnative_comp_driver_options, "native-comp-driver-options"); + DEFSYM (Qnative_comp_backend_options, "native-comp-backend-options"); + DEFSYM (Qnative_comp_compiler_options, "native-comp-compiler-options"); DEFSYM (Qcomp_libgccjit_reproducer, "comp-libgccjit-reproducer"); /* Limple instruction set. */ @@ -5350,7 +5405,8 @@ syms_of_comp (void) defsubr (&Scomp__subr_signature); defsubr (&Scomp_el_to_eln_rel_filename); defsubr (&Scomp_el_to_eln_filename); - defsubr (&Scomp_native_driver_options_effective_p); + defsubr (&Scomp_native_backend_options_effective_p); + defsubr (&Scomp_native_compiler_options_effective_p); defsubr (&Scomp__install_trampoline); defsubr (&Scomp__init_ctxt); defsubr (&Scomp__release_ctxt); -- 2.33.0