summaryrefslogtreecommitdiff
path: root/src/comp.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Allow for native compiling .el.gz filesAndrea Corallo2020-08-171-1/+7
| | | | | | | | | | | | | This is needed for installed instances compiled with NATIVE_FAST_BOOT * src/comp.c (maybe_defer_native_compilation): Search for .el.gz too as a source if the .el is not found. (Fcomp_el_to_eln_filename): Remove the .gz in case to generate the hash. * lisp/emacs-lisp/comp.el (comp-valid-source-re): New defconst. (comp-run-async-workers, native-compile-async): Make use of `comp-valid-source-re'.
* Make install target functional for new eln-cache directory arrangementAndrea Corallo2020-08-171-0/+21
| | | | | | | | | | | | | | | | | | | | | | * src/comp.h (fixup_eln_load_path): New extern. * src/comp.c (fixup_eln_load_path): New function. * src/pdumper.c (dump_do_dump_relocation): Update to make use of 'fixup_eln_load_path'. * lisp/loadup.el: Update to store in the compilation unit the correct eln-cache installed path. Rename --lisp-dest -> --eln-dest and. * Makefile.in: Pass the eln destination directory to src/Makefile. Rename LISP_DESTDIR -> ELN_DESTDIR. (ELN_DESTDIR): Define. (install-eln): New target. (install): Add install-eln as prerequisite. * src/Makefile.in: Rename --lisp-dest -> --eln-dest and LISP_DESTDIR -> ELN_DESTDIR.
* Make comp-deferred-compilation a simple global and set it on by defaultAndrea Corallo2020-08-171-1/+7
| | | | | | | | * src/comp.c (comp_deferred_compilation): Doc update and set it to true by default. * lisp/emacs-lisp/comp.el (comp-deferred-compilation): Remove customize.
* Move eln files into dedicated cache directoriesAndrea Corallo2020-08-171-11/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When loading a elc file search for a corresponding eln one into `comp-eln-load-path' directories and load it if available. `comp-eln-load-path' contains by default two directory (user and system one). * src/pdumper.c (dump_do_dump_relocation): While resurrecting from load set eln cache sys dir in `Vcomp_eln_load_path'. * src/lread.c (maybe_swap_for_eln): New function. (Fload): Clean-up some now unnecessary code going back to the master one. (Fload): Make use of Vcomp_eln_to_el_h for the reverse file look-up. (openp_add_middle_dir_to_suffixes) (openp_max_middledir_and_suffix_len, openp_fill_filename_buffer): Remove functions. (openp): As for Fload revert code modifications. (openp): When a .elc file is being loaded check if a corresponding eln can be loaded in place. * src/comp.c (ELN_FILENAME_HASH_LEN): New macro. (comp_hash_string): New function. (hash_native_abi): Make use of 'comp_hash_string'. (hash_native_abi): Change `comp-native-path-postfix' format. (Fcomp_el_to_eln_filename): New function. (Fcomp__compile_ctxt_to_file): Have file_name as a input. (Vcomp_eln_to_el_h, Vcomp_eln_load_path): New global varaibles. * lisp/startup.el (normal-top-level): Add user eln cache directory in `comp-eln-load-path'. * lisp/help-fns.el (find-lisp-object-file-name): Reverse look-up files using `comp-eln-to-el-h'. * lisp/files.el (locate-file): Likewise. * lisp/emacs-lisp/find-func.el (find-library-name): Likewise. * lisp/emacs-lisp/comp.el (comp-output-directory) (comp-output-base-filename, comp-output-filename): Remove function. (comp-compile-ctxt-to-file): Create parent directories if necessary. (comp-run-async-workers, native-compile, native-compile-async): Make use `comp-el-to-eln-filename'.
* * Fix bug#42360Andrea Corallo2020-07-151-6/+41
| | | | | | | * src/comp.c (compile_function): Allocate function frame as array if non local exits are present to retain correct Elisp semantic. (emit_limple_call_ref): Directly use the frame array for ref calls to have GCC spills into it before calling.
* * Rework frame allocation strategyAndrea Corallo2020-07-131-61/+9
| | | | | | | | | | All frame slots are now simple automatic variables given the array allocation and fill is done in 'emit_limple_call_ref'. * src/comp.c (comp_t): Remove 'f_frame' 'arrays' slots, add 'frame'. (emit_mvar_lval): Simplify to make use of 'comp.frame'. (compile_function): Clean-up and add comp.frame initialization.
* * Rework the backend to allocate arument arrays for call by referencesAndrea Corallo2020-07-131-20/+40
| | | | | | | * src/comp.c (comp_t): Add 'zero' field. (emit_limple_call_ref): Allocate an array to host the parametes and generate the code moving values into. (Fcomp__init_ctxt): Initialize comp.zero.
* Revert "* src/comp.c (Fcomp__register_subr): Remove code duplication using ↵Andrea Corallo2020-06-291-1/+11
| | | | | | Fdefalias." This reverts commit 6c7f615ae59b636efe5012f761a25acfd956480d.
* * Enable deferred compilation for dynamic scoped codeAndrea Corallo2020-06-281-1/+8
| | | | | * src/comp.c (maybe_defer_native_compilation): Trigger for dynamic code and add a comment.
* * src/comp.c (Fcomp__register_subr): Remove code duplication using Fdefalias.Andrea Corallo2020-06-281-11/+1
|
* * Setup correctly the printer while dumping objs in native CU (bug#42088)Andrea Corallo2020-06-281-0/+12
| | | | | | | * src/comp.c (emit_static_object): Bind a bunch of special variables to setup `prin1-to-string' as `byte-compile-output-file-form' does. This to preserve uninterned symbols.
* src/comp.c (Fcomp__register_subr): Handle advice activation (bug#42038).Andrea Corallo2020-06-271-1/+9
|
* ;* src/comp.c (define_maybe_gc_or_quit): Fix a comment.Andrea Corallo2020-06-221-2/+2
|
* * src/comp.c (Fcomp__compile_ctxt_to_file): Confine gcc optim level in [0, 3].Andrea Corallo2020-06-221-1/+2
|
* Allow per function speed declarationAndrea Corallo2020-06-221-4/+6
| | | | | | | | | | | | | | | | | | | | | * src/comp.c (COMP_SPEED): Rename. (comp_t): Add 'func_speed' field. (emit_mvar_lval, compile_function): Update for per function speed. (Fcomp__compile_ctxt_to_file): COMP_SPEED renamed. * lisp/emacs-lisp/comp.el (comp-speed): Doc update. (comp-func): New 'speed' slot. (comp-spill-speed): New function. (comp-spill-lap-function, comp-intern-func-in-ctxt): Fill 'speed' slot. (comp-spill-lap-function): Gate -1 speed functions for native compilation and emit bytecode instead. (comp-spill-lap): Close over `byte-to-native-plist-environment'. (comp-latch-make-fill): Update for per function speed. (comp-limplify-top-level): Fill speed. (comp-propagate1, comp-call-optim-form-call, comp-call-optim) (comp-dead-code, comp-tco, comp-remove-type-hints): Update for per function speed.
* Add native compiler dynamic scope supportAndrea Corallo2020-06-191-21/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add an initial implementation to support dynamic scope. Arg parsing/binding it's done using the existing code in use for bytecode (no ad-hoc code is synthetized for that). * src/lisp.h (struct Lisp_Subr): Add lambda_list field. (SUBR_NATIVE_COMPILED_DYNP): New inliner. * src/alloc.c (mark_object): Update for Add lambda_list field. * src/eval.c (eval_sub, Ffuncall, funcall_lambda): Handle native compiled dynamic scope * src/comp.c (declare_lex_function): Rename from declare_function and rework. (declare_function): New function. (make_subr): Handle daynamic scope * src/pdumper.c (dump_subr): Update for lambda_list field. * lisp/emacs-lisp/comp.el (comp-func): Remove args slot. (comp-func-l, comp-func-d): New classes deriving from `comp-func'. (comp-spill-lap-function): Rework. (comp-prepare-args-for-top-level): New function. (comp-emit-for-top-level, comp-emit-lambda-for-top-level): Make use of `comp-prepare-args-for-top-level'. (comp-limplify-top-level): Use `comp-func-l'. (comp-limplify-function): Emit arg prologue only for dynamic scoped functions. (comp-call-optim-form-call): Use `comp-func-l'. (comp-call-optim, comp-tco): Do not optimize dynamic scoped code.
* * Implement 'maybe_gc_or_quit' to allow correct GC in compiled Lisp.Andrea Corallo2020-06-131-1/+108
| | | | | | | | | | | | | | | | Implement the backend side of 'maybe_gc_or_quit' so that every time a call to it is emitted we render it accordingly. This allow GC to kicks in during long loops in Lisp code. * src/comp.c (comp_t): Add 'maybe_gc_or_quit' field. (helper_link_table): Add 'maybe_gc', 'maybe_quit'. (emit_maybe_gc_or_quit): New function. (declare_runtime_imported_funcs): Import 'maybe_gc', 'maybe_quit' functions. (define_maybe_gc_or_quit): New function. (Fcomp__init_ctxt): Register emitter. (Fcomp__compile_ctxt_to_file): Call 'define_maybe_gc_or_quit'. (syms_of_comp): Define Qcomp_maybe_gc_or_quit.
* Fix recursive load for non cons hashed 'data_ephemeral_vec' contentAndrea Corallo2020-06-111-7/+32
| | | | | | | | | | | | | | Removing `Vcomp_sym_subr_c_name_h' all c_name functions are GC markable only through 'data_ephemeral_vec'. A recursive load must not overide its content otherwise a previously activated load will have the original content collected before it's used. * src/comp.h (struct Lisp_Native_Comp_Unit): Add 'load_ongoing' field. * src/comp.c (unset_cu_load_ongoing): New function. (load_comp_unit): Update logic to detect and handle recursive loads.
* Remove `Vcomp_sym_subr_c_name_h'Andrea Corallo2020-06-111-8/+1
| | | | | | | | | | | | | | | | | | | Given there's no more unique relation symbol-name -> c-name remove `Vcomp_sym_subr_c_name_h' and store the c_name directly in struct Lisp_Subr. The old approach would have failed dumping two functions with the same symbol-name. * src/lisp.h (struct Lisp_Subr): Add 'native_c_name' field. * src/pdumper.c (dump_subr): Update hash + dump 'native_c_name'. (dump_cold_native_subr): dump 'native_c_name'. (dump_do_dump_relocation): Update logic for reviving using 'native_c_name'. * src/comp.c (make_subr): Update for 'native_c_name' field. (Fcomp__register_lambda, Fcomp__register_subr): Clean-up code for 'Vcomp_sym_subr_c_name_h' removal. (syms_of_comp): Remove 'Vcomp_sym_subr_c_name_h'.
* * Remove unused 'helper_save_window_excursion'Andrea Corallo2020-06-101-12/+1
| | | | | * src/comp.c (helper_unwind_protect): Remove definition and declaration.
* Rename lambda_gc_guard -> lambda_gc_guard_hAndrea Corallo2020-06-081-3/+3
| | | | | | | | | | * src/comp.h (struct Lisp_Native_Comp_Unit): Rename lambda_gc_guard -> lambda_gc_guard_h * src/pdumper.c (dump_do_dump_relocation): Likewise. * src/comp.c (check_comp_unit_relocs, Fcomp__register_lambda) (Fnative_elisp_load): Likewise.
* * Fix load logic for the reloading CU case (bug#41754)Andrea Corallo2020-06-081-0/+2
| | | | | | | | | * src/comp.c (load_comp_unit): When swapping the compilation unit abandoning the new one for the original do not forget to set its loaded_once field to true because is in use by `comp--register-lambda'. (Fcomp__register_lambda): Add sanity a check to spot early if we are trying to load the same lambda twice.
* * Clean-up unnecessary lisp_X context definitionAndrea Corallo2020-06-061-8/+6
| | | | | * src/comp.c (Fcomp__init_ctxt, comp_t): Remove lisp_X definition as is used only locally.
* Change 'direct-call' 'direct-callref' LIMPLE ops sematincAndrea Corallo2020-06-061-22/+16
| | | | | | | | | | | | | | | Is cleaner to have the function c-name as first argument of 'direct-call' 'direct-callref'. This is preparatory to anonymous lambdas optimization. * lisp/emacs-lisp/comp.el (comp-propagate-insn): Use c-name when gathering the comp-func definition for direct calls. (comp-call-optim-form-call): Add put c-name as first argument of direct-call direct-callref when optimizing. * src/comp.c (emit_call): Update logic for having c-name as first arg of direct calls. (emit_call_ref): Rename 'subr_sym' into 'func'.
* * Fix build for --enable-check-lisp-object-type=yes (bug#41703)Andrea Corallo2020-06-041-0/+1
| | | | * src/comp.c (emit_coerce): Add missing declaration.
* Fix DLL imports of gccjit version functions.Nicolás Bértolo2020-06-021-6/+12
| | | | | | | | * src/comp.c (init_gccjit_functions): Use LOAD_DLL_FN_OPT macro to load gcc_jit_version_major, gcc_jit_version_major and gcc_jit_version_patchlevel. * src/w32common.h (LOAD_DLL_FN_OPT): Add macro optionally load a function from a DLL.
* * Throw an ICE when asked to emit a cast with sign extension.Nicolás Bértolo2020-06-011-21/+49
| | | | | | | | | | * src/comp.c (cast_kind_of_type): Enum that specifies the kind of type in the cast enum (unsigned, signed, pointer). (emit_coerce): Throw an ICE when asked to emit a cast with sign extension. (define_cast_from_to): Return NULL for casts involving sign extension. (define_cast_functions): Specify the kind of each type in the cast union.
* * Define casts using functions.Nicolás Bértolo2020-06-011-173/+136
| | | | | | | This is to dump prettier C files. This does not affect compilation times in my tests. * src/comp.c: Define a 15x15 cast matrix. Use it in emit_coerce().
* * Remove unnecessary DLL load of gcc_jit_block_add_assignment_op.Nicolás Bértolo2020-06-011-7/+0
| | | | | * src/comp.c (gcc_jit_block_add_assignment_op): Remove unnecessary func import.
* Store libgccjit version into generated codeAndrea Corallo2020-05-311-2/+5
| | | | | | | | * src/comp.c (emit_ctxt_code): Add libgccjit version into stored optimize qualities. (syms_of_comp): Define Qgccjit here. * src/w32fns.c (syms_of_w32fns): Move out Qgccjit definition.
* * Optimize 'emit_static_object' for load-timeAndrea Corallo2020-05-311-13/+17
| | | | | | | * src/comp.c (emit_static_object): Use a chunck size of 200 bytes on bugged GCCs and a longer one (1024) in sane ones. Rename str in buff to disambiguate and prefer xmalloc to a VLA given the buffer is not that small.
* * Add `comp-libgccjit-version' subrAndrea Corallo2020-05-311-0/+30
| | | | | | | * src/comp.c (gcc_jit_version_major, gcc_jit_version_minor) (gcc_jit_version_patchlevel): Import. (Fcomp_libgccjit_version): New Lisp function. (syms_of_comp): Update for 'comp-libgccjit-version'.
* * Cut down compile-time emitting static data as string literalsNicolás Bértolo2020-05-311-15/+105
| | | | | | | | | | | | | | | | | This change drastically reduce compile time. Apparently GCC optimizer does not scale up well at all for long sequences of assignments into a single array. Nicolás Bértolo <nicolasbertolo@gmail.com> Andrea Corallo <akrl@sdf.org> * src/comp.c (gcc_jit_context_new_string_literal) (gcc_jit_block_add_assignment_op): New imports. (comp_t): New 'size_t_type' 'memcpy' fields. (emit_static_object): Define static objects using string literals and memcpy. (define_memcpy): New function. (Fcomp__init_ctxt): Define 'size_t_type' and 'memcpy'.
* * Emit better debug comments in emit_static_objectAndrea Corallo2020-05-311-2/+9
| | | | | * src/comp.c (emit_static_object): Do not truncate debug comments at the first NULL character.
* Do not call `gensym' too early when loading a dump file.Nicolás Bértolo2020-05-311-1/+6
| | | | | | | | | | This happened when subr.eln was not the first native compilation unit to be loaded. register_native_comp_unit() is called when loading a native compilation unit and that in turn used to call `gensym', which was not loaded yet. This led to a SIGSEGV. * src/comp.c (register_native_comp_unit): Replace the call to `gensym' with an ad-hoc counter.
* ; Ease ifdef navigation in native-comp filesAndrea Corallo2020-05-241-1/+2
| | | | | | | * src/comp.c (syms_of_comp): Add a comment to ease #endif understading. * src/comp.h: Likewise.
* Fix GNU styleAndrea Corallo2020-05-241-78/+73
| | | | | | | | | | * src/comp.h: Fix GNU style. * src/comp.c (Fcomp__compile_ctxt_to_file): Likewise. * lisp/emacs-lisp/comp.el (comp--replace-output-file): Likewise. * src/pdumper.c (dump_do_dump_relocation): Likewise.
* Improve handling of native compilation units still in use in WindowsNicolás Bértolo2020-05-251-10/+250
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When closing emacs will inspect all directories from which it loaded native compilation units. If it finds a ".eln.old" file it will try to delete it, if it fails that means that another Emacs instance is using it. When compiling a file we rename the file that was in the output path in case it has been loaded into another Emacs instance. When deleting a package we move any ".eln" or ".eln.old" files in the package folder that we can't delete to `package-user-dir`. Emacs will check that directory when closing and delete them. * lisp/emacs-lisp/comp.el (comp--replace-output-file): Function called from C code to finish the compilation process. It performs renaming of the old file if necessary. * lisp/emacs-lisp/package.el (package--delete-directory): Function to delete a package directory. It moves native compilation units that it can't delete to `package-user-dir'. * src/alloc.c (cleanup_vector): Call dispose_comp_unit(). (garbage_collect): Call finish_delayed_disposal_of_comp_units(). * src/comp.c: Restore the signal mask using unwind-protect. Store loaded native compilation units in a hash table for disposal on close. Store filenames of native compilation units GC'd in a linked list to finish their disposal when the GC is over. (clean_comp_unit_directory): Delete all *.eln.old files in a directory. (clean_package_user_dir_of_old_comp_units): Delete all *.eln.old files in `package-user-dir'. (dispose_all_remaining_comp_units): Dispose of native compilation units that are still loaded. (dispose_comp_unit): Close handle and cleanup directory or arrange for later cleanup if DELAY is true. (finish_delayed_disposal_of_comp_units): Dispose of native compilation units that were GC'd. (register_native_comp_unit): Register native compilation unit for disposal when Emacs closes. * src/comp.h: Introduce cfile member in Lisp_Native_Comp_Unit. Add declarations of functions that: clean directories of unused native compilation units, handle disposal of native compilation units. * src/emacs.c (kill-emacs): Dispose all remaining compilation units right right before calling exit(). * src/eval.c (internal_condition_case_3, internal_condition_case_4): Add functions. * src/lisp.h (internal_condition_case_3, internal_condition_case_4): Add functions. * src/pdumper.c (dump_do_dump_relocation): Set cfile to a copy of the Lisp string specifying the file path.
* * src/comp.c: Aesthetic, GNU style fixes.Andrea Corallo2020-05-231-66/+64
|
* Load libgccjit dynamically in Windows.Nicolás Bértolo2020-05-231-3/+371
| | | | | | | | | | | | | | | | | | | * configure.ac: don't add linker flags if compiling on Windows. Compile dynlib.c if modules or native compilation are enabled. Always compile comp.c * lisp/term/w32-win.el: Map 'gccjit to "libgccjit.dll" in `dynamic-library-alist`. * src/Makefile.in: Update comments. Update to handle changes in configure.ac. * src/comp.c: Add declarations of used libgccjit functions using DEF_DLL_FN. Add calls to load_gccjit_if_necessary() where necessary. Add `native-comp-available-p` * src/comp.h: Remove Fnative_elisp_load. Add syms_of_comp(). * src/emacs.c (main): Always call syms_of_comp() * src/w32.c (globals_of_w32): Clear Vlibrary_cache when starting because the libraries loaded when dumping will not be loaded when starting. * src/w32fns.c: Add Qgccjit symbol.
* * src/comp.c: Fix 32bit wide-int.Andrea Corallo2020-05-221-6/+6
| | | | | * src/comp.c (emit_XFIXNUM): Make right shift for MSB_TAG arithmetic too to preserve sign bit.
* * src/comp.c: Fix i386 --enable-check-lisp-object-typeAndrea Corallo2020-05-221-1/+1
| | | | | * src/comp.c (load_comp_unit): Fix return type, on i386 influence parameter passing!
* * src/comp.c: Some aesthetic code clean-up.Andrea Corallo2020-05-221-69/+35
| | | | | | | | | | | | | * src/comp.c (comp_t): Remove 'lisp_X_s' field. (emit_coerce): Respect 80 columns limit. (emit_rvalue_from_emacs_uint): GNU style, unnecessary brackets. (emit_rvalue_from_emacs_int): Likewise. (emit_rvalue_from_lisp_word_tag): Likewise. (emit_rvalue_from_lisp_word): Likewise. (emit_lval_XLI): Remove unused function. (emit_lval_XLP): Remove commented out code. (define_add1_sub1): Respect 80 columns limit. (Fcomp__init_ctxt): Reflect 'lisp_X_s' field removal.
* Handle LISP_WORDS_ARE_POINTERS and CHECK_LISP_OBJECT_TYPE.Nicolás Bértolo2020-05-201-104/+215
| | | | | | | | | | | | | | * src/comp.c: Introduce the Lisp_X, Lisp_Word, and Lisp_Word_tag types. These types are used instead of long or long long. Use emacs_int_type and emacs_uint_types where appropriate. (emit_coerce): Add special logic that handles the case when Lisp_Object is a struct. This is necessary for handling the --enable-check-lisp-object-type configure option. * src/lisp.h: Since libgccjit does not support opaque unions, change Lisp_X to be struct. This is done to ensure that the same types are used in the same binary. It is probably unnecessary since only a pointer to it is used.
* * Remove a layer of indirection for access to pure storage.Nicolás Bértolo2020-05-201-7/+6
| | | | | | | | * src/comp.c: Taking the address of an array is the same as casting it to a pointer. Therefore, the C expression `(EMACS_INT **) &pure` is in fact adding a layer of indirection that is not necessary. The fix is to cast the `pure` array to a pointer and store that in a void pointer that is part of the compiled shared library.
* * src/comp.c (emit_setjmp): Aesthetic, respect 80 columns limit.Andrea Corallo2020-05-201-6/+9
|
* * Handle setjmp() taking two arguments in Windows.Nicolás Bértolo2020-05-201-6/+41
| | | | | | | | | | | * src/comp.c: Add `define_setjmp_deps()` and `emit_setjmp()` which abstract over this difference in behavior between operating systems. WARNING: Not all cases are handled by this patch. The Mingw-64 setjmp.h header deals with many other combinations. I don't think it is a good idea to replicate the logic of that header inside emacs. (Maybe a few lines in the configure script could be added to handle this problem?)
* Do not block SIGIO in platforms that don't have it.Nicolás Bértolo2020-05-201-0/+2
| | | | | | | * src/comp.c (comp--compile-ctxt-to-file): Add a preprocessor check to avoid blocking SIGIO in platforms that don't have it. Signed-off-by: Andrea Corallo <akrl@sdf.org>
* * Fix bug#41346 assertion triggered while loading dumpAndrea Corallo2020-05-171-2/+1
| | | | | | * src/comp.c (load_comp_unit): While loading from dump lambda fixups are still to happen here. Verify relocation coherency only after 'top_level_run' execution.
* * Add check_comp_unit_relocsAndrea Corallo2020-05-151-0/+33
| | | | | | * src/comp.c (check_comp_unit_relocs): Add function to verify relocation coherency. (load_comp_unit): Call it.