summaryrefslogtreecommitdiff
path: root/src/comp.c
Commit message (Collapse)AuthorAgeFilesLines
...
* * Move diagnostic pragmas out of namespace-scope (bug#45303).Andrea Corallo2020-12-191-9/+6
| | | | | | | | | Pragmas in GCC don't work reliably within function: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92696> * src/comp.c (emit_static_object) (Fcomp_native_driver_options_effective_p) (Fcomp_libgccjit_version): Move pragmas out of name-scope.
* * Fix `load-history' causing a number of spurious compiler warningsAndrea Corallo2020-12-041-0/+3
| | | | | | * src/comp.c (Fcomp__register_subr): Fix missing entry into `load-history' indicating that the loaded function was already an autoload.
* * Reduce (half) the number of loads emitted for calling into C codeAndrea Corallo2020-12-041-10/+36
| | | | | | | | | | | | | | | As after each function call GCC clobbers the pointer to the function relocation table. This commit modify the code generation to create a local copy of it for each function. This reduces the average number of loads for each function call into C from two to one. * src/comp.c (comp_t): Add 'func_relocs_ptr_type' and 'func_relocs_local' fields. (emit_call): Use the local func_relocs pointer when possible. (emit_ctxt_code): Fill 'comp.func_relocs_ptr_type'. (compile_function): Declare 'func_relocs_ptr_local'. (compile_function): Assign 'func_relocs_ptr_local' from the global value in each function prologue.
* * Synthesize as const primitive function pointers and its container struct.Andrea Corallo2020-11-271-7/+10
| | | | | | * src/comp.c (declare_imported_func): Make const function pointer to primitive funcions. (emit_ctxt_code): Make struct 'comp.func_relocs' const.
* Make load argument of native-compile-async internalStefan Kangas2020-11-211-3/+3
| | | | | | | | * lisp/emacs-lisp/comp.el (native--compile-async): New defun extracted from native-compile-async. (native-compile-async): Remove load argument and use above new defun. * src/comp.c (maybe_defer_native_compilation): Use above new defun. (Bug#44676)
* ; Fix trivial typosStefan Kangas2020-11-201-6/+6
|
* * Fix eln file hasing for symlink paths (bug#44701)Andrea Corallo2020-11-181-1/+9
| | | | | * src/comp.c (Fcomp_el_to_eln_filename): Call `file-truename' in place of `expand-file-name' when available.
* Various doc fixes for comp.el and comp.cStefan Kangas2020-11-161-26/+24
| | | | | | | | | | | | | | * lisp/emacs-lisp/comp.el: Remove redundant :group args. (comp-async-cu-done-hook, comp-async-all-done-hook) (comp-async-env-modifier-form, comp-dry-run) (comp-ensure-native-compiler, comp-func-ret-typeset) (comp-func-ret-range, comp-limple-lock-keywords) (comp-make-curr-block): * src/comp.c (Fcomp_el_to_eln_filename, Fcomp__init_ctxt) (Fcomp_native_driver_options_effective_p) (Fcomp__compile_ctxt_to_file, Fcomp_libgccjit_version) (Fcomp__register_lambda, Fcomp__register_subr) (Fcomp__late_register_subr, Fnative_elisp_load, syms_of_comp): Doc fixes.
* * Fix debug symbol emissionAndrea Corallo2020-11-141-20/+19
| | | | | | * src/comp.c (Fcomp__compile_ctxt_to_file): Now that we do not rely anymore on globlal variables move logic in from 'Fcomp__init_ctxt' so comp.debug is already set correctly.
* Add initial nativecomp typeset and range propagation supportAndrea Corallo2020-11-121-11/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit add an initial support for a better type propagation and integer range propagation. Each mvar can be now characterized by a set of types, a set of values and an integral range. * lisp/emacs-lisp/comp.el (comp-known-ret-types): Store into typeset and remove fixnum. (comp-known-ret-ranges, comp-type-predicates): New variables. (comp-ctxt): Remove supertype-memoize slot and add union-typesets-mem. (comp-mvar): Remove const-vld, constant, type slots. Add typeset, valset, range slots. (comp-mvar-value-vld-p, comp-mvar-value, comp-mvar-fixnum-p) (comp-mvar-symbol-p, comp-mvar-cons-p) (comp-mvar-type-hint-match-p, comp-func-ret-typeset) (comp-func-ret-range): New functions. (make-comp-mvar, make-comp-ssa-mvar): Update logic. (comp--typeof-types): New variable. (comp-supertypes, comp-common-supertype): Logic update. (comp-subtype-p, comp-union-typesets, comp-range-1+) (comp-range-1-, comp-range-<, comp-range-union) (comp-range-intersection): New functions. (comp-fwprop-prologue, comp-mvar-propagate) (comp-function-foldable-p, comp-function-call-maybe-fold) (comp-fwprop-insn, comp-call-optim-func, comp-finalize-relocs): Logic update. * src/comp.c (emit_mvar_rval, emit_call_with_type_hint) (emit_call2_with_type_hint): Logic update. * lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Undo the add of fixnum and bignum as unnecessary. * test/src/comp-tests.el (comp-tests-mentioned-p-1, comp-tests-cond-rw-checker-val) (comp-tests-cond-rw-checker-type, cond-rw-1, cond-rw-2) (cond-rw-3, cond-rw-4, cond-rw-5): Update for new type interface. (range-simple-union, range-simple-intersection): New integer range tests. (union-types): New union type test.
* * Allow for manually bumbing new native compiler ABI versionsAndrea Corallo2020-11-071-3/+8
| | | | | | * src/comp.c (ABI_VERSION): Define macro. (hash_native_abi): Include ABI_VERSION in the hashing. (syms_of_comp): Tweak docstring.
* Allow for native compilation qualities to be specified per input fileAndrea Corallo2020-11-071-17/+15
| | | | | | | | | | | | | | | | | | | | | | | * lisp/emacs-lisp/bytecomp.el (byte-native-qualities): Define variable. (byte-compile-from-buffer): Spill compilation qualities. * lisp/emacs-lisp/comp.el (comp-speed, comp-debug): Make them file local variables. (comp-ctxt): Add `speed' and `debug' slots. (comp-spill-speed, comp-spill-lap-function): Make use of these. (comp-spill-lap-function): Spill qualities from `byte-native-qualities'. (comp-limplify-top-level): Do not use `comp-speed' but ctxt value unstead. (comp-final): Do not propagate qualities as they are already in the `comp-ctxt'. (comp--native-compile): Close on `byte-native-qualities'. * src/comp.c (comp_t): Add 'speed' and 'debug' fields. (emit_comment, emit_mvar_rval, emit_static_object) (emit_ctxt_code, Fcomp__init_ctxt): Use these instead of the global variables. (Fcomp__compile_ctxt_to_file): Set comp.speed and comp.debug and use them.
* Add new cond-rw pass to have forward propagation track cond branchesAndrea Corallo2020-11-011-2/+3
| | | | | | | | | | | | | | Add a new pass to rewrite conditional branches. This is introducing and placing a new LIMPLE operator 'assume' in use by fwprop to propagate conditional branch test informations on target basic blocks. * lisp/emacs-lisp/comp.el (comp-passes): Add `comp-cond-rw'. (comp-limple-assignments): Add `assume' operator. (comp-emit-assume, comp-cond-rw-target-slot, comp-cond-rw-func) (comp-cond-rw): Add new functions. (comp-fwprop-insn): Update to pattern match `assume' insns. * src/comp.c (emit_limple_insn): Add for `assume'. (syms_of_comp): Define 'Qassume' symbol.
* Use form native compilation in `comp-trampoline-compile'Andrea Corallo2020-10-141-2/+4
| | | | | | | | | | | | | | | | | | * lisp/emacs-lisp/comp.el (comp-trampoline-sym): Remove function. (comp-trampoline-filename): As we are introducing an ABI change in the eln trampoline format change the trampoline filename to disambiguate. (comp-trampoline-search): Rename from `comp-search-trampoline' and return directly the trampoline. (comp-trampoline-compile): Rework to use native form compilation in place of un-evaluating a function and return directly the trampoline. (comp-subr-trampoline-install): Update for `comp-trampoline-search' and `comp-trampoline-compile' new interfaces. * src/comp.c (Fcomp__install_trampoline): Store the trampoline itself as value in `comp-installed-trampolines-h'. (syms_of_comp): Doc update `comp-installed-trampolines-h'.
* Have `native-elisp-load' return the last registerd functionAndrea Corallo2020-10-141-6/+5
| | | | | | | | | | * lisp/emacs-lisp/comp.el (comp-emit-for-top-level): Synthesize 'top_level_run' so it returns the last value returned by `comp--register-subr'. * src/comp.c (load_comp_unit): Return what 'top_level_run' returns. (Fnative_elisp_load): Return what 'load_comp_unit' returns. * src/comp.h (load_comp_unit): Update signature.
* Provide feature nativecomp and make use of itAndrea Corallo2020-10-101-0/+1
| | | | | | | | | * lisp/emacs-lisp/comp.el (comp-ensure-native-compiler): Use `featurep' to identify if the native compiler is available. * lisp/emacs-lisp/nadvice.el (advice--add-function): Likewise. * lisp/emacs-lisp/package.el (package--delete-directory): Likewise. * lisp/loadup.el: Likewise. * src/comp.c (syms_of_comp): Provide feature nativecomp.
* Various typo fixes in native compiler related filesBrian Leung2020-10-101-1/+1
| | | | | | | | | | | | | | * lisp/emacs-lisp/comp.el (native-compiler-error-dyn-func) (comp-func, comp-func-l) (comp-func-d, comp-ensure-native-compiler, comp-type-hint-p) (comp-func-unique-in-cu-p, comp-alloc-class-to-container) (comp-limple-mode, comp-loop-insn-in-block) (comp-lex-byte-func-p, comp-c-func-name, comp-decrypt-arg-list) (comp-spill-lap-function, comp-intern-func-in-ctxt) (comp-spill-lap-function, comp-spill-lap, comp-emit-handler) (comp-prepare-args-for-top-level): Various typo fixes. * src/comp.c (Fcomp_el_to_eln_filename): Fix typo in error message.
* * Fix failure when eln-cache is removed (introduced by 4a1bb46260)Andrea Corallo2020-10-071-7/+37
| | | | | | | | * src/comp.c (make_directory_wrapper, make_directory_wrapper_1): New functions. (Fcomp_el_to_eln_filename): If base_dir is not specified and we are searching across `comp-load-path' try to create a directory if does not exists.
* * Native compiling do not target a directory with no write permissionAndrea Corallo2020-10-061-1/+15
| | | | | | * src/comp.c (Fcomp_el_to_eln_filename): Check for write permission while choosing the output directory in `comp-eln-load-path'.
* Make primitive redefinition effective through trampoline synthesisAndrea Corallo2020-10-051-0/+6
| | | | | | | | | | * lisp/loadup.el (dump-mode): Set `comp-enable-subr-trampolines' when finished bootstrap. * src/data.c (Ffset): Call `comp-enable-subr-trampolines' when redefining a subr. * src/comp.c (syms_of_comp): Define `comp-subr-trampoline-install' symbol. (syms_of_comp): Define `comp-enable-subr-trampolines' variable.
* Make filename hashing compatible with self contained builds (bug#43532)Andrea Corallo2020-10-041-17/+5
| | | | | | | | | | * Makefile.in (lispdirrel): Add replace template. (epaths-force): Form correctly 'PATH_REL_LOADSEARCH' into epath.h * configure.ac (lispdirrel): Define variable (relative path of the lisp files from the installation directory). * src/comp.c (Fcomp_el_to_eln_filename): Update algorithm not to rely on 'PATH_DUMPLOADSEARCH' but on 'PATH_REL_LOADSEARCH'. * src/epaths.in (PATH_REL_LOADSEARCH): Add macro template.
* * Improve some docstring in src/comp.cAndrea Corallo2020-09-301-10/+10
| | | | | | | * src/comp.c (Fcomp_el_to_eln_filename) (Fcomp__compile_ctxt_to_file): Improve docstring. (Fcomp__compile_ctxt_to_file): Rename 'file_name' -> 'filename'. (Fnative_comp_available_p): Improve docstring.
* Rename in docstrings "non nil" into "non-nil"Andrea Corallo2020-09-281-1/+1
| | | | | | * lisp/emacs-lisp/comp.el: Rename non nil -> non-nil in doc. * src/comp.c: Likewise.
* Do not install a subr trampoline twiceAndrea Corallo2020-09-241-0/+5
| | | | | | | | | * src/comp.c (syms_of_comp): Define and initialize 'Vcomp_installed_trampolines_h'. (Fcomp__install_trampoline): Fill 'Vcomp_installed_trampolines_h' * lisp/emacs-lisp/comp.el (comp--subr-safe-advice): Make use of `comp-installed-trampolines-h' to guard against installing a trampoline twice.
* * Add `comp--install-trampoline' machineryAndrea Corallo2020-09-231-0/+34
| | | | | | | | * src/comp.c (Fcomp__install_trampoline): New function to install a subr trampoline into the function relocation table. Once this is done any call from native compiled Lisp to the related primitive will go through the `funcall' trampoline making advicing effective.
* * Fix MacOS Emacs.app installation (bug#43532)Andrea Corallo2020-09-221-9/+21
| | | | | | * src/comp.c (Fcomp_el_to_eln_filename): Adapt the filename hashing algorithm to allow for producing a MacOS self-contained Emacs.app.
* * Better error handling after calling 'gcc_jit_context_compile_to_file'Andrea Corallo2020-09-151-0/+7
| | | | | | | | | Tipically errors are catched in 'compile_function' but in case libgccjit throw an error only afterwards while compiling the whole compilation unit we have to report it correctly. * src/comp.c (Fcomp__compile_ctxt_to_file): Catch libgccjit errors after calling 'gcc_jit_context_compile_to_file'.
* * src/comp.c (emit_static_object): Make use of ARRAYELTS.Andrea Corallo2020-09-111-1/+1
|
* * Make use of new 'gcc_jit_global_set_initializer' entry pointAndrea Corallo2020-09-111-3/+42
| | | | | | | | | | | | Use this brand new entry point to avoid the current workaround and its load-time memcpys. * src/comp.c (gcc_jit_global_set_initializer): Add to the dynamic load machinery. (static_obj_t): Remove const qualifier from the data field. (emit_static_object): Make use of 'gcc_jit_global_set_initializer' when available. (load_static_obj): Use the blob for loading if that was emitted.
* * Guard against trying to rename files into eln sys directoryAndrea Corallo2020-09-101-0/+13
| | | | | * src/comp.c (file_in_eln_sys_dir): New function. (Fnative_elisp_load): Make use of.
* * Fix rename file error when reloading the same file from an sys eln dir.Andrea Corallo2020-09-101-6/+13
| | | | | * src/comp.c (Fnative_elisp_load): Don't rename files we don't have the permission for.
* Revert "* src/comp.c (Fcomp__compile_ctxt_to_file): Don't cleanup caches at ↵Andrea Corallo2020-09-101-4/+1
| | | | | | bootstrap." This reverts commit 15acd27d1c0de8b56bab61daa0a8fcd4fef0fdc4.
* * src/comp.c (Fcomp__compile_ctxt_to_file): Don't cleanup caches at bootstrap.Andrea Corallo2020-09-081-1/+4
|
* * Name temp eln files as .eln.tmp so we can't clean-up them mistakenly.Andrea Corallo2020-09-081-3/+1
| | | | | * src/comp.c (Fcomp__compile_ctxt_to_file): Postfix temporary eln files as .eln.tmp.
* * src/comp.c (Fcomp__compile_ctxt_to_file): Rename a variable.Andrea Corallo2020-09-061-2/+2
|
* * src/comp.c (Fnative_elisp_load): Make recompilation always effective.Andrea Corallo2020-09-061-8/+23
| | | | | | When loading a file if in this session there was ever a file loaded with that name rename it before loading it to make sure we always get a new handle from the standard library.
* Rework eln deletion strategy for new eln-cache folder structureAndrea Corallo2020-09-061-210/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When recompiling remove the corresponding stale elns found in the `comp-eln-load-path'. When removing a package remove the corresponding elns too. On Windows both of these are performed only when possible, when it's not the file is renamed as .eln.old and a last attempt to remove this is performed closing the Emacs session. When a file being deleted was loaded by multiple Emacs sessions the last one being closed should delete it. * lisp/emacs-lisp/comp.el (comp-clean-up-stale-eln): New function. (comp-delete-or-replace-file): Rename from `comp--replace-output-file' and update so it can be used for replacing or deleting shared libs safetly. * lisp/emacs-lisp/package.el (package--delete-directory): When native compiled just call `comp-clean-up-stale-eln' for each eln file we want to clean-up. * src/alloc.c (cleanup_vector): Call directly the dynlib_close. * src/comp.c (syms_of_comp): Update for comp_u->cfile removal. Make 'all_loaded_comp_units_h' key-value weak as now the key will be the filename. (load_comp_unit): Register the compilation unit only when the load is fully completed. (register_native_comp_unit): Make the key of all_loaded_comp_units_h the load filename. (eln_load_path_final_clean_up): New function. (dispose_comp_unit) (finish_delayed_disposal_of_comp_units) (dispose_all_remaining_comp_units) (clean_package_user_dir_of_old_comp_units): Remove. (Fcomp__compile_ctxt_to_file): Update for `comp--replace-output-file' -> `comp-delete-or-replace-file' rename. * src/comp.h (dispose_comp_unit) (finish_delayed_disposal_of_comp_units) (dispose_all_remaining_comp_units) (clean_package_user_dir_of_old_comp_units): Remove. (eln_load_path_final_clean_up): Add. (struct Lisp_Native_Comp_Unit): Remove cfile field. * src/emacs.c (Fkill_emacs): Call 'eln_load_path_final_clean_up'. * src/pdumper.c (dump_do_dump_relocation): Do not set comp_u->cfile.
* Rename and move eln system directoryAndrea Corallo2020-09-041-18/+16
| | | | | | | | | | | | | | | | | | | | | | | | Rename eln sys directory into 'native-lisp' and move it from "$(DESTDIR)${libexecdir}/emacs/${version}/${configuration}/" to "$(DESTDIR)${libdir}/emacs/". Add to the directory name used to disambiguate the eln compatibility the Emacs version to have it more user friendly. * Makefile.in (clean, install-eln): Rename eln-cache into native-lisp. (ELN_DESTDIR): Move from '$(DESTDIR)${libexecdir}/emacs/${version}/${configuration}/' to '$(DESTDIR)${libdir}/emacs/'. * lisp/loadup.el: Update for comp-native-path-postfix -> comp-native-version-dir rename. * src/comp.c (syms_of_comp): Rename eln-cache -> native-lisp. (syms_of_comp, Fcomp_el_to_eln_filename): Rename comp-native-path-postfix -> comp-native-version-dir. (hash_native_abi): Rework and add emacs-version to comp-native-version-dir.
* Merge branch 'add_driver_option' into HEADAndrea Corallo2020-08-261-0/+50
|\
| * * Init gcc_jit_context_add_driver_option as optionalAndrea Corallo2020-08-261-1/+1
| | | | | | | | | | * src/comp.c (init_gccjit_functions): Use LOAD_DLL_FN_OPT to init 'gcc_jit_context_add_driver_option' as this is optional.
| * * Rename comp-native-driver-options-available-pAndrea Corallo2020-08-261-5/+7
| | | | | | | | | | | | | | | | * src/comp.c (Fcomp_native_driver_options_effective_p) Rename plus better doc. (add_driver_options, syms_of_comp): Rename `comp-native-driver-options-available-p' into comp-native-driver-options-effective-p.
| * * src/comp.c (add_driver_options): Fix missing condition + clean-up pragmaAndrea Corallo2020-08-261-5/+4
| |
| * * Add 'comp-native-driver-options-available-p'Andreas Fuchs2020-08-261-0/+18
| | | | | | | | | | * src/comp.c (comp-native-driver-options-available-p): New function that returns t if driver options can be used.
| * * Improve 'add_driver_options'Andrea Corallo2020-08-261-18/+10
| | | | | | | | | | * src/comp.c (add_driver_options): Use load_gccjit_if_necessary and FOR_EACH_TAIL + GNU style.
| * Fix windows NT handling for [...]_add_driver_optionsAndreas Fuchs2020-08-261-8/+19
| | | | | | | | | | | | | | | | | | | | * Instead of conditionalizing on the wrong preprocessor flag, now use the right one: LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option * Also perform the driver-option-adding step on win NT, but only if the function is non-NULL. * Make the function declaration for add_driver_options non-old-style.
| * Pass driver options to libgccjit where supportedAndreas Fuchs2020-08-191-0/+28
| | | | | | | | | | | | | | | | | | | | Add a customizable variable for driver options (such as linker flags) to pass to libgccjit (Bug #42761). * lisp/emacs-lisp/comp.el (comp-native-driver-options): New customization variable. * src/comp.c: Use comp-native-driver-options to set libgccjit's driver options, if supported on the library's ABI version.
* | Rework eln hash filename strategyAndrea Corallo2020-08-231-16/+145
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Generate eln filename hashing also the source file content in the form: /absolute/path/filename.el + content -> eln-cache/filename-path_hash-content_hash.eln * src/lread.c (maybe_swap_for_eln): Always call Fcomp_el_to_eln_filename on an existing source file. * src/comp.c (md5.h, sysstdio.h, zlib.h): New include. (comp_hash_string): Use md5 instead of sha512. (MD5_BLOCKSIZE): New macro. (accumulate_and_process_md5, final_process_md5, md5_gz_stream) (comp_hash_source_file): New functions. (Fcomp_el_to_eln_filename): Rework for hasing using also source file content. * src/lread.c (maybe_swap_for_eln): Rename el_name -> src_name as this can be also a have .el.gz extention.
* | Revert "Fix native code uneffective loads after recompilation" (bug#42944)Andrea Corallo2020-08-201-17/+2
|/ | | | | | This reverts commit 8a931a97b8dd19a38d6f719f810280a07ba76438. This introduced bug#42944.
* Fix native code uneffective loads after recompilationAndrea Corallo2020-08-191-2/+17
| | | | | | | | | | | | 'dlopen' can return the same handle if two shared with the same filename are loaded in two different times (even if the first was deleted!). To prevent this scenario the last modification time of the source file is included in the hashing algorithm. * src/comp.c (Fcomp_el_to_eln_filename): Update hashing algo to include the source last modification date. * src/lread.c (maybe_swap_for_eln): Do not check for eln newer then elc as this is now unnecessary.
* * Improve eln filename hashingAndrea Corallo2020-08-171-10/+52
| | | | | | | | | | | | Make eln filename hashing logic insensitive to the installation process. * src/comp.c (epaths.h): New include to have PATH_DUMPLOADSEARCH, PATH_LOADSEARCH definitions. (loadsearch_re_list): New static var. (Fcomp_el_to_eln_filename): Update logic to have the eln hashing insensitive to the installation process. (syms_of_comp): GC protect 'loadsearch_re_list'.