[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/native-comp 489a79d 6/6: * Mitigate possible speed 3 miss-optimi

From: Andrea Corallo
Subject: feature/native-comp 489a79d 6/6: * Mitigate possible speed 3 miss-optimization
Date: Sat, 6 Jun 2020 17:38:10 -0400 (EDT)

branch: feature/native-comp
commit 489a79de96c7f90271e57b86b8162ef7ba500fed
Author: Andrea Corallo <akrl@sdf.org>
Commit: Andrea Corallo <akrl@sdf.org>

    * Mitigate possible speed 3 miss-optimization
    Do not perform trampoline optimization at speed 3 on function if their
    name is not unique inside the compilation unit.  Note that the
    function can still be redefined in any other way therefore this is a
        * lisp/emacs-lisp/comp.el (comp-func-unique-in-cu-p): New
        (comp-call-optim-form-call): Perform trampoline optimization
        for named functions only if they are unique within the current
        compilation unit.
 lisp/emacs-lisp/comp.el | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index f30409a..b8ab48a 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -399,6 +399,18 @@ structure.")
   "Type hint predicate for function name FUNC."
   (when (memq func comp-type-hints) t))
+(defun comp-func-unique-in-cu-p (func)
+  "Return t if FUNC is know to be unique in the current compilation unit."
+  (if (symbolp func)
+      (cl-loop with h = (make-hash-table :test #'eq)
+               for f being the hash-value in (comp-ctxt-funcs-h comp-ctxt)
+               for name = (comp-func-name f)
+               when (gethash name h)
+                 return nil
+               do (puthash name t h)
+               finally return t)
+    t))
 (defsubst comp-alloc-class-to-container (alloc-class)
   "Given ALLOC-CLASS return the data container for the current context.
 Assume allocaiton class 'd-default as default."
@@ -2018,7 +2030,8 @@ FUNCTION can be a function-name or byte compiled 
          ;; Intra compilation unit procedure call optimization.
          ;; Attention speed 3 triggers this for non self calls too!!
          ((and comp-func-callee
-               (or (>= comp-speed 3)
+               (or (and (>= comp-speed 3)
+                        (comp-func-unique-in-cu-p callee))
                    (and (>= comp-speed 2)
                         ;; Anonymous lambdas can't be redefined so are
                         ;; always safe to optimize.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]