aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Corallo2020-07-05 22:05:36 +0100
committerAndrea Corallo2020-07-09 16:22:48 +0100
commitb4de6baa7b5cc41d15bc94cfcdbea680af6dc7b8 (patch)
treee7375fe91efaf232ed36689e2823e770f495ecb6
parent7622740e2930fea33b3381337063d2e8fb834709 (diff)
downloademacs-b4de6baa7b5cc41d15bc94cfcdbea680af6dc7b8.tar.gz
emacs-b4de6baa7b5cc41d15bc94cfcdbea680af6dc7b8.zip
* Optimize pure functions defined by the compilation environment
* lisp/emacs-lisp/comp.el (comp-apply-in-env): New macro. (comp-function-call-maybe-remove): Update to make use of `comp-apply-in-env'.
-rw-r--r--lisp/emacs-lisp/comp.el34
1 files changed, 27 insertions, 7 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 000af0a8b34..5ff2e098371 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -1995,6 +1995,22 @@ PRE-LAMBDA and POST-LAMBDA are called in pre or post-order if non nil."
1995 (copy-comp-mvar insn) 1995 (copy-comp-mvar insn)
1996 insn))) 1996 insn)))
1997 1997
1998(defmacro comp-apply-in-env (func &rest args)
1999 "Apply FUNC to ARGS in the current compilation environment."
2000 `(let ((env (cl-loop
2001 for f being the hash-value in (comp-ctxt-funcs-h comp-ctxt)
2002 for func-name = (comp-func-name f)
2003 for byte-code = (comp-func-byte-func f)
2004 when func-name
2005 collect `(,func-name . ,(symbol-function func-name))
2006 and do
2007 (setf (symbol-function func-name) byte-code))))
2008 (unwind-protect
2009 (apply ,func ,@args)
2010 (cl-loop
2011 for (func-name . def) in env
2012 do (setf (symbol-function func-name) def)))))
2013
1998(defun comp-ref-args-to-array (args) 2014(defun comp-ref-args-to-array (args)
1999 "Given ARGS assign them to a dedicated array." 2015 "Given ARGS assign them to a dedicated array."
2000 (when args 2016 (when args
@@ -2064,13 +2080,17 @@ Here goes everything that can be done not iteratively (read once).
2064 (car args)))))) 2080 (car args))))))
2065 ((comp-function-optimizable-p f args) 2081 ((comp-function-optimizable-p f args)
2066 (ignore-errors 2082 (ignore-errors
2067 ;; No point to complain here because we should do basic block 2083 ;; No point to complain here in case of error because we
2068 ;; pruning in order to be sure that this is not dead-code. This 2084 ;; should do basic block pruning in order to be sure that this
2069 ;; is now left to gcc, to be implemented only if we want a 2085 ;; is not dead-code. This is now left to gcc, to be
2070 ;; reliable diagnostic here. 2086 ;; implemented only if we want a reliable diagnostic here.
2071 (rewrite-insn-as-setimm insn 2087 (let* ((f (if-let (f-in-ctxt (comp-symbol-func-to-fun f))
2072 (apply f 2088 ;; If the function is IN the compilation ctxt
2073 (mapcar #'comp-mvar-constant args)))))))) 2089 ;; and know to be pure.
2090 (comp-func-byte-func f-in-ctxt)
2091 f))
2092 (value (comp-apply-in-env f (mapcar #'comp-mvar-constant args))))
2093 (rewrite-insn-as-setimm insn value)))))))
2074 2094
2075(defun comp-propagate-insn (insn) 2095(defun comp-propagate-insn (insn)
2076 "Propagate within INSN." 2096 "Propagate within INSN."