[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/native-comp 93a80a4 7/8: * Add nativecomp derived return type sp
From: |
Andrea Corallo |
Subject: |
feature/native-comp 93a80a4 7/8: * Add nativecomp derived return type specifier computation support |
Date: |
Wed, 11 Nov 2020 19:03:07 -0500 (EST) |
branch: feature/native-comp
commit 93a80a4fae2b90471a3a3cf4f17751ce48f4af2f
Author: Andrea Corallo <akrl@sdf.org>
Commit: Andrea Corallo <akrl@sdf.org>
* Add nativecomp derived return type specifier computation support
* lisp/emacs-lisp/comp.el (comp-post-pass-hooks): Nit.
(comp-func): Add `ret-type-specifier' slot.
(comp-ret-type-spec): New function.
(comp-final): Call `comp-ret-type-spec'.
---
lisp/emacs-lisp/comp.el | 54 +++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index e026d3b..c863c29 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -186,7 +186,7 @@ Can be one of: 'd-default', 'd-impure' or 'd-ephemeral'.
See `comp-ctxt'.")
"List of disabled passes.
For internal use only by the testsuite.")
-(defvar comp-post-pass-hooks ()
+(defvar comp-post-pass-hooks '()
"Alist PASS FUNCTIONS.
Each function in FUNCTIONS is run after PASS.
Useful to hook into pass checkers.")
@@ -421,7 +421,9 @@ CFG is mutated by a pass.")
(speed nil :type number
:documentation "Optimization level (see `comp-speed').")
(pure nil :type boolean
- :documentation "t if pure nil otherwise."))
+ :documentation "t if pure nil otherwise.")
+ (ret-type-specifier '(t) :type list
+ :documentation "Derived return type specifier."))
(cl-defstruct (comp-func-l (:include comp-func))
"Lexically-scoped function."
@@ -2768,6 +2770,53 @@ These are substituted with a normal 'set' op."
;;; Final pass specific code.
+(defun comp-ret-type-spec (_ func)
+ "Compute type specifier for `comp-func' FUNC.
+Set it into the `ret-type-specifier' slot."
+ (cl-loop
+ with res-typeset = nil
+ with res-valset = nil
+ with res-range = nil
+ for bb being the hash-value in (comp-func-blocks func)
+ do (cl-loop
+ for insn in (comp-block-insns bb)
+ do (pcase insn
+ (`(return ,mvar)
+ (when-let ((typeset (comp-mvar-typeset mvar)))
+ (setf res-typeset (comp-union-typesets res-typeset typeset)))
+ (when-let ((valset (comp-mvar-valset mvar)))
+ (setf res-valset (append res-valset valset)))
+ (when-let (range (comp-mvar-range mvar))
+ (setf res-range (comp-range-union res-range range))))))
+ finally
+ (when res-valset
+ (setf res-typeset
+ (cl-loop
+ with res = (copy-sequence res-typeset)
+ for type in res-typeset
+ for pred = (alist-get type comp-type-predicates)
+ when pred
+ do (cl-loop
+ for v in res-valset
+ when (funcall pred v)
+ do (setf res (remove type res)))
+ finally (cl-return res))))
+ (setf res-range (cl-loop for (l . h) in res-range
+ for low = (if (numberp l) l '*)
+ for high = (if (numberp h) h '*)
+ collect `(integer ,low , high))
+ res-valset (cl-remove-duplicates res-valset))
+ (let ((res (append res-typeset
+ (when res-valset
+ `((member ,@res-valset)))
+ res-range)))
+ (setf (comp-func-ret-type-specifier func)
+ (if (> (length res) 1)
+ `(or ,@res)
+ (if (consp (car res))
+ (car res)
+ res))))))
+
(defun comp-finalize-container (cont)
"Finalize data container CONT."
(setf (comp-data-container-l cont)
@@ -2867,6 +2916,7 @@ Prepare every function for final compilation and drive
the C back-end."
(defun comp-final (_)
"Final pass driving the C back-end for code emission."
+ (maphash #'comp-ret-type-spec (comp-ctxt-funcs-h comp-ctxt))
(unless comp-dry-run
(if noninteractive
(comp-final1)
- feature/native-comp updated (e20cdf9 -> 2435c10), Andrea Corallo, 2020/11/11
- feature/native-comp e96cd4e 2/8: Add initial nativecomp typeset and range propagation support, Andrea Corallo, 2020/11/11
- feature/native-comp 00b4e0a 4/8: * Fix limple-mode for new type and range limple semantic, Andrea Corallo, 2020/11/11
- feature/native-comp c3d0e2a 1/8: * Rename two nativecomp functions, Andrea Corallo, 2020/11/11
- feature/native-comp a214882 5/8: * Add to elisp-mode `emacs-lisp-native-compile-and-load', Andrea Corallo, 2020/11/11
- feature/native-comp 6b7c257 6/8: * Unline some functions to optimize bootstrap time, Andrea Corallo, 2020/11/11
- feature/native-comp 2435c10 8/8: * Nativecomp testsuite rework for derived return type specifiers, Andrea Corallo, 2020/11/11
- feature/native-comp 175efec 3/8: Add a nativecomp testcase, Andrea Corallo, 2020/11/11
- feature/native-comp 93a80a4 7/8: * Add nativecomp derived return type specifier computation support,
Andrea Corallo <=