From 22da28cf6643b6293aa0255eca5f398dad23516d Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Sat, 14 Nov 2020 16:25:56 +0100 Subject: [PATCH] * 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'. --- lisp/emacs-lisp/comp.el | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index fa94d399eb5..ffd483108d3 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -670,6 +670,11 @@ Return the corresponding `comp-constraint' or `comp-constraint-f'." (when-let ((spec (gethash func comp-known-constraints-h))) (comp-constraint-range (comp-constraint-f-ret spec)))) +(defun comp-func-ret-valset (func) + "Return the valset returned by function FUNC." + (when-let ((spec (gethash func comp-known-constraints-h))) + (comp-constraint-valset (comp-constraint-f-ret spec)))) + (defun comp-func-unique-in-cu-p (func) "Return t if FUNC is known to be unique in the current compilation unit." (if (symbolp func) @@ -2601,26 +2606,29 @@ Return LVAL." (mapcar #'comp-mvar-range rhs-mvars)))) lval)) +(defun comp-fwprop-call (insn lval f args) + "Propagate on a call INSN into LVAL. +F is the function being called with arguments ARGS. +Fold the call in case." + (if-let ((range (comp-func-ret-range f))) + (setf (comp-mvar-range lval) range + (comp-mvar-typeset lval) nil) + (if-let ((valset (comp-func-ret-valset f))) + (setf (comp-mvar-valset lval) valset + (comp-mvar-typeset lval) nil) + (setf (comp-mvar-typeset lval) (comp-func-ret-typeset f)))) + (comp-function-call-maybe-fold insn f args)) + (defun comp-fwprop-insn (insn) "Propagate within INSN." (pcase insn (`(set ,lval ,rval) (pcase rval (`(,(or 'call 'callref) ,f . ,args) - (if-let ((range (comp-func-ret-range f))) - (setf (comp-mvar-range lval) range - (comp-mvar-typeset lval) nil) - (setf (comp-mvar-typeset lval) - (comp-func-ret-typeset f))) - (comp-function-call-maybe-fold insn f args)) + (comp-fwprop-call insn lval f args)) (`(,(or 'direct-call 'direct-callref) ,f . ,args) (let ((f (comp-func-name (gethash f (comp-ctxt-funcs-h comp-ctxt))))) - (if-let ((range (comp-func-ret-range f))) - (setf (comp-mvar-range lval) range - (comp-mvar-typeset lval) nil) - (setf (comp-mvar-typeset lval) - (comp-func-ret-typeset f))) - (comp-function-call-maybe-fold insn f args))) + (comp-fwprop-call insn lval f args))) (_ (comp-mvar-propagate lval rval)))) (`(assume ,lval ,rval ,kind) -- 2.39.5