From a317620a52746ea4346eabf4559a1caac2b63011 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Wed, 18 Sep 2019 11:30:23 +0200 Subject: [PATCH] add comp-call-optim pass --- lisp/emacs-lisp/comp.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 076380732f9..8f93efd73ad 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -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) + +;;; 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) + ;;; Final pass specific code. -- 2.39.5