Commit graph

500 commits

Author SHA1 Message Date
Stefan Kangas
cee6401c13 Various doc fixes for comp.el and comp.c
* 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.
2020-11-16 16:06:47 +01:00
Andrea Corallo
898f929215 Fix nativecomp cond-rw pass
* lisp/emacs-lisp/comp.el (comp-mvar-symbol-p): Improve it.
	(comp-cond-rw-func): Fix logic for multiple predecessor on target
	block.
	* test/src/comp-tests.el (comp-test-cond-rw-1): New test.
	* test/src/comp-test-funcs.el (comp-test-cond-rw-1-1-f)
	(comp-test-cond-rw-1-2-f): New functions.
2020-11-16 15:32:52 +01:00
Andrea Corallo
54f2e9c06d * Improve `comp-fwprop-call'
* lisp/emacs-lisp/comp.el (comp-function-call-maybe-fold):
	Document return value.
	(comp-fwprop-call): Simplify and improve.
2020-11-15 21:16:23 +01:00
Andrea Corallo
2f8d0fca88 * Add more type specifiers
* lisp/emacs-lisp/comp.el (comp-known-type-specifiers): Add more
	pure functions.
2020-11-15 18:51:06 +01:00
Andrea Corallo
f702426780 Add `comp-constraint-to-type-spec' and better handle boolean type spec
* lisp/emacs-lisp/comp.el (comp-constraint-to-type-spec): New
	function splitting out code from comp-ret-type-spec + better
	handle boolean type specifier.
	(comp-ret-type-spec): Rework to leverage
	`comp-constraint-to-type-spec'.
	* test/src/comp-tests.el (comp-tests-type-spec-tests): Add a
	testcase.
2020-11-14 22:06:31 +01:00
Andrea Corallo
bcecdedcb7 Handle correctly quoting in *Native-compile-Log* buffer
* lisp/emacs-lisp/comp.el (comp-log): Add `quoted' parameter and
	pass it to `comp-log-to-buffer'.
	(comp-log-to-buffer): Add `quoted' parameter and leverage `prin1'
	or `princ' accordingly.
2020-11-14 22:06:31 +01:00
Andrea Corallo
22da28cf66 * Split logic into comp-fwprop-call and improve it
* lisp/emacs-lisp/comp.el (comp-func-ret-valset)
	(comp-fwprop-call): New functions.
	(comp-fwprop-insn): Remove code duplicaiton and call
	`comp-fwprop-call'.
2020-11-14 22:06:31 +01:00
Andrea Corallo
aced2cf6ac * Add a number of type specifiers for pure function
* lisp/emacs-lisp/comp.el (comp-known-type-specifiers): Add 60
	pure function type specifiers.
2020-11-14 22:06:31 +01:00
Andrea Corallo
a467fa5c49 Characterize functions in terms of type specifiers
* lisp/emacs-lisp/comp.el (comp-known-type-specifiers): New const
	in place of `comp-known-ret-types' and `comp-known-ret-ranges'.
	(comp-constraint): New struct to separate the constraint side of
	an mvar.
	(comp-constraint-f): Analogous for functions.
	(comp-mvar): Rework and include `comp-constraint'.
	(comp-type-spec-to-constraint): New function.
	(comp-known-constraints-h): New const.
	(comp-func-ret-typeset, comp-func-ret-range): Rework.
	(comp-fwprop-insn): Fix.
	* test/src/comp-tests.el (destructure-type-spec): New testcase.
2020-11-14 22:06:31 +01:00
Andrea Corallo
c412d396b0 * lisp/emacs-lisp/comp.el (comp-mvar-value-vld-p): Fix logic. 2020-11-12 23:58:15 +01:00
Andrea Corallo
a37cc95e21 * Memoize `comp-common-supertype'
* lisp/emacs-lisp/comp.el (comp-ctxt): Add `common-supertype-mem'
	slot.
	(comp-common-supertype): Memoize.
2020-11-12 23:57:43 +01:00
Andrea Corallo
6f10e0f09f * Rework comp-ret-type-spec' in terms of comp-phi'
* lisp/emacs-lisp/comp.el (comp-ret-type-spec): Use `comp-func'
	not to duplicate logic plus add null type specifier support and
	some comments.
2020-11-12 23:55:49 +01:00
Andrea Corallo
c4749cebeb * Move phi function code into dedicated function and improve it
* lisp/emacs-lisp/comp.el (comp-phi): New function moving logic
	from `comp-fwprop-insn'.
2020-11-12 23:53:26 +01:00
Andrea Corallo
93a80a4fae * Add nativecomp derived return type specifier computation support
* lisp/emacs-lisp/comp.el (comp-post-pass-hooks): Nit.
	(comp-func): Add `ret-type-specifier' slot.
	(comp-ret-type-spec): New function.
	(comp-final): Call `comp-ret-type-spec'.
2020-11-12 00:55:37 +01:00
Andrea Corallo
6b7c257e0b * Unline some functions to optimize bootstrap time
* lisp/emacs-lisp/comp.el (comp-mvar-value-vld-p)
	(comp-mvar-value, comp-mvar-fixnum-p, comp-set-op-p)
	(comp-assign-op-p, comp-call-op-p, comp-type-hint-p)
	(comp-func-ret-typeset, comp-function-pure-p)
	(comp-alloc-class-to-container, comp-lex-byte-func-p)
	(comp-lap-eob-p, comp-lap-fall-through-p, comp-emit)
	(comp-emit-set-call, comp-mvar-propagate)
	(comp-function-foldable-p, comp-function-call-maybe-fold)
	(comp-trampoline-filename): Uninline functions.
2020-11-12 00:55:37 +01:00
Andrea Corallo
00b4e0a9bb * Fix limple-mode for new type and range limple semantic
* lisp/emacs-lisp/comp.el (comp-limple-branches, comp-limple-ops):
	New variables.
	(comp-limple-lock-keywords): Update value.
2020-11-12 00:55:36 +01:00
Andrea Corallo
e96cd4e82c Add initial nativecomp typeset and range propagation support
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.
2020-11-12 00:55:36 +01:00
Andrea Corallo
c3d0e2a09f * Rename two nativecomp functions
* lisp/emacs-lisp/comp.el (comp-function-foldable-p): Rename from
	comp-function-optimizable-p.
	(comp-function-call-maybe-fold): Same from
	comp-function-call-maybe-fold.
2020-11-12 00:54:46 +01:00
Andrea Corallo
e20cdf937e * lisp/emacs-lisp/comp.el (comp-fwprop-insn): Fix phi function. 2020-11-08 21:22:53 +01:00
Andrea Corallo
a5408d5715 * lisp/emacs-lisp/comp.el (comp-common-supertype-2): Fix null intersection 2020-11-07 21:11:39 +01:00
Andrea Corallo
4a69e953f3 Allow for native compilation qualities to be specified per input file
* 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.
2020-11-07 11:45:55 +01:00
Andrea Corallo
acf101c636 Handle type hierarchy in native compiler forward propagation
2020-11-07  Andrea Corallo  <andrea.corallo@arm.com>

	* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add fixnum
	and bignum.
	* lisp/emacs-lisp/comp.el (comp-ctxt): Add `supertype-memoize'
	slot.
	(comp-supertypes, comp-common-supertype-2)
	(comp-common-supertype): New functions.
	(comp-fwprop-insn): Make use of `comp-common-supertype' to
	identify the common supertype to be propagated.
2020-11-07 11:27:14 +01:00
Andrea Corallo
c6abe97f94 * A native compiler forward propagation fix
* lisp/emacs-lisp/comp.el (comp-fwprop-insn): Fix `comp-mvar'
	`const-vld' slot left unset while propagating in phis.
2020-11-05 22:34:12 +01:00
Andrea Corallo
3e3843512b * Fix 'comp-call-optim pass' for anonymous lambdas
* lisp/emacs-lisp/comp.el (comp-call-optim-func): Remove anonymous
	lambdas gate.
	(comp-call-optim-form-call): Add the correct missing condition.
2020-11-01 15:17:00 +01:00
Andrea Corallo
42970cceb9 Add new cond-rw pass to have forward propagation track cond branches
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.
2020-11-01 15:17:00 +01:00
Andrea Corallo
fd9e9308d2 Make native compiler tollerant to redefined primitives (bug#44221).
* lisp/emacs-lisp/comp.el (comp-emit-set-call-subr): Rework based
	on the fact that the subr can now be redefined.
	* test/src/comp-tests.el (primitive-redefine-compile-44221):
	New testcase.
2020-10-26 16:34:20 +00:00
Andrea Corallo
868d3ff9b8 * Report warnings and errors from native asynchronous compilation (bug#44168)
* lisp/emacs-lisp/comp.el (comp-last-scanned-async-output): New
	buffer local variable.
	(comp-accept-and-process-async-output): New function.
	(comp-run-async-workers): Use
	`comp-accept-and-process-async-output'.
2020-10-25 14:45:53 +00:00
Andrea Corallo
ada80d66d6 * Fix `comp-dry-run' effectiveness
* lisp/emacs-lisp/comp.el (comp-compile-ctxt-to-file): Remove
	`comp-dry-run' guard.
	(comp-final): And move it here so is effective for interactive
	sessions and non.
2020-10-25 10:56:18 +00:00
Andrea Corallo
3be93390fb Sanitize eln filename when native compiling single functions
* lisp/emacs-lisp/comp.el (comp-spill-lap-function): Fix
	temporary eln name generation.

	* test/src/comp-tests.el (free-fun-silly-name): New testcase.
2020-10-20 21:29:05 +01:00
Andrea Corallo
79ca25c085 * Have native-compile' do not expose with-late-load' parameter
This is really for internal use only by deferred compilation.

	* lisp/emacs-lisp/comp.el (comp-trampoline-compile)
	(comp-run-async-workers): Make use of `comp--native-compile'.
	(comp--native-compile): New function.
	(native-compile, batch-native-compile): Make use of
	`comp--native-compile'.
2020-10-20 21:24:58 +01:00
Andrea Corallo
03e98f93f7 Use form native compilation in `comp-trampoline-compile'
* 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'.
2020-10-14 11:04:36 +02:00
Andrea Corallo
4f0e879030 Rework `native-compile' interface so it can return compiled functions
* lisp/emacs-lisp/comp.el (native-compile): Return the compiled
	function when the input is a symbol or a form.
	* test/src/comp-tests.el (free-fun, tco, fw-prop): Update tests
	for new `native-compile' interface.
2020-10-14 11:04:36 +02:00
Andrea Corallo
8861ee8b08 Have `native-elisp-load' return the last registerd function
* 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.
2020-10-14 11:04:36 +02:00
Andrea Corallo
4bea0c0b1d * Allow for lambda forms as native compilation input
* lisp/emacs-lisp/comp.el (comp-spill-lap-function): Add new
	specialized method for compiling a lambda form.
2020-10-14 11:04:36 +02:00
Andrea Corallo
fda798808f * Move context output computation in `comp-spill-lap-function'
* lisp/emacs-lisp/comp.el (comp-spill-lap-function): Move
	output filename computation here.
	(native-compile): From here.
2020-10-14 11:04:36 +02:00
Andrea Corallo
4b924ef87d * As edges are indexed store them in an hash table
* lisp/emacs-lisp/comp.el (comp-edge): Update doc for 'number'
	slot.
	(comp-func): Rename 'edges' slot into 'edges-h'.
	(comp-log-edges): Update logic for edges in an hash table.
	(comp-clean-ssa, comp-compute-edges): Likewise.
2020-10-10 20:25:57 +02:00
Andrea Corallo
96f59a9faf * Add into phi l-value args basic block names
* lisp/emacs-lisp/comp.el (comp-ssa-rename-insn): Clean-up a
	leftover space.
	(comp-finalize-phis): Cons the blasic block name providing the
	mvar together with the mvar itself while forming the phi.
	(comp-fwprop-insn): Destructure correctly the phi.
2020-10-10 20:25:42 +02:00
Andrea Corallo
8b135af5bb Provide feature nativecomp and make use of it
* 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.
2020-10-10 18:47:45 +02:00
Andrea Corallo
77fa6befb4 * lisp/emacs-lisp/comp.el (comp-func): Fix doc for blocks slot. 2020-10-10 18:08:23 +02:00
Andrea Corallo
b8772e8b08 * Fix LIMPLE latch block name coloring in "*Native-compile-Log*"
* lisp/emacs-lisp/comp.el (comp-limple-lock-keywords): Fix
	latch block name coloring.
2020-10-10 15:15:49 +02:00
Brian Leung
51f5e487b2 Various typo fixes in native compiler related files
* 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.
2020-10-10 12:19:30 +02:00
Andrea Corallo
138990bbda * Fix failure when compiling a trampoline with no eln-cache dir (bug#43875)
* lisp/emacs-lisp/comp.el (comp-trampoline-compile): Try to create
	the eln-cache dir if this is not existing, if fails to do that
	move on to the next one.
2020-10-10 10:29:17 +02:00
Andrew Whatson
85450f03be * Fix typo name plus make error homogeneous in `comp-trampoline-compile'
* lisp/emacs-lisp/comp.el (comp-trampoline-compile): Fix typo
	renaming `comp-tampoline-compile' -> `comp-trampoline-compile'.
	Change error to be consistent.
	(comp-subr-trampoline-install): Use `comp-trampoline-compile'.
2020-10-10 10:29:14 +02:00
Andrea Corallo
7041c32ec2 * Fix some nits in comp.el
* lisp/emacs-lisp/comp.el (comp-spill-lap-function): Use
	`cl-defmethod' where correct in place of `cl-defgeneric'.
	(comp-tampoline-compile): Add missing #.
2020-10-07 20:43:00 +02:00
Andrea Corallo
58d85f4dbb * Do use echo area for async compilation started/finished messages
* lisp/emacs-lisp/comp.el (comp-run-async-workers)
	(native-compile-async): Do not write into the echo area.
2020-10-07 07:41:00 +02:00
Andrea Corallo
0b58be4941 Rename comp-subr-safe-advice -> comp-subr-trampoline-install 2020-10-05 21:32:38 +02:00
Andrea Corallo
36e0c3fb07 * When advising search in `comp-eln-load-path' the first writable dir
* lisp/emacs-lisp/comp.el (comp-tampoline-compile): Do not crash
	if we can't write in the first entry in `comp-eln-load-path' but
	search for another one.
2020-10-02 14:48:48 +02:00
Andrea Corallo
2cc82563d2 * lisp/emacs-lisp/comp.el (comp-c-func-name): Add autoload cookie. 2020-10-01 07:55:00 +02:00
Andrea Corallo
89f064104c * Some clean-up in comp.el
* lisp/emacs-lisp/comp.el (comp-emit-cond-jump, comp-emit-switch)
	(comp-limplify-block, comp-compute-edges)
	(comp-ssa-rename, comp-fwprop*, comp-effective-async-max-jobs)
	(comp-run-async-workers): Respect max 80 columns.
	(batch-byte-native-compile-for-bootstrap): Improve doc + remove
	some now unnecessary error handling.
2020-09-29 17:14:22 +02:00
Andrea Corallo
3129b3ffcb Rename in docstrings "non nil" into "non-nil"
* lisp/emacs-lisp/comp.el: Rename non nil -> non-nil in doc.

	* src/comp.c: Likewise.
2020-09-28 21:09:00 +02:00