]> git.eshelyaron.com Git - emacs.git/commitdiff
add comp-call-optim pass
authorAndrea Corallo <akrl@sdf.org>
Wed, 18 Sep 2019 09:30:23 +0000 (11:30 +0200)
committerAndrea Corallo <akrl@sdf.org>
Wed, 1 Jan 2020 10:37:50 +0000 (11:37 +0100)
lisp/emacs-lisp/comp.el

index 076380732f98ab297743228256597d8867b4f848..8f93efd73ad03d82f92c4e1be6ba29548e9132a9 100644 (file)
@@ -56,6 +56,7 @@
                         comp-limplify
                         comp-ssa
                         comp-propagate
+                        comp-call-optim
                         comp-final)
   "Passes to be executed in order.")
 
@@ -1320,6 +1321,31 @@ This can run just once."
              (comp-log-func comp-func)))
   funcs)
 
+\f
+;;; Call optimizer pass specific code.
+;; Try to avoid funcall trampoline use when possible.
+
+(defun comp-call-optim (funcs)
+  (cl-loop
+   for comp-func in funcs
+   for self = (comp-func-symbol-name comp-func)
+   for self-callref = (comp-nargs-p (comp-func-args comp-func))
+   when (and (>= comp-speed 2)
+             (not self-callref) ;; Could improve this
+             )
+   do (cl-loop
+       for b being each hash-value of (comp-func-blocks comp-func)
+       do (cl-loop
+           for insn-cell on (comp-block-insns b)
+           for insn = (car insn-cell)
+           do (pcase insn
+                (`(set ,lval (callref funcall ,f . ,rest))
+                 (when (eq self (comp-mvar-constant f))
+                   (setcar insn-cell
+                           `(set ,lval (call ,(comp-mvar-constant f) ,@rest))))))))
+   (comp-log-func comp-func))
+  funcs)
+
 \f
 ;;; Final pass specific code.