diff options
| author | Andrea Corallo | 2020-06-03 22:06:26 +0100 |
|---|---|---|
| committer | Andrea Corallo | 2020-06-03 22:06:26 +0100 |
| commit | e4e6bb7fddaa3a4e82748c106366fe9113dc16d9 (patch) | |
| tree | 05ebce52da394b18823f0f5342c02d7037ea8044 | |
| parent | b619339b7a6c7952508bff72f07fc98c04e85f2c (diff) | |
| download | emacs-e4e6bb7fddaa3a4e82748c106366fe9113dc16d9.tar.gz emacs-e4e6bb7fddaa3a4e82748c106366fe9113dc16d9.zip | |
* Introduce `comp-loop-insn-in-block'
* lisp/emacs-lisp/comp.el (comp-loop-insn-in-block): New macro.
(comp-call-optim-func, comp-dead-assignments-func)
(comp-remove-type-hints-func): Use `comp-loop-insn-in-block'.
| -rw-r--r-- | lisp/emacs-lisp/comp.el | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 11539761d1e..5116f887220 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el | |||
| @@ -494,6 +494,16 @@ VERBOSITY is a number between 0 and 3." | |||
| 494 | "Output filename for SRC file being native compiled." | 494 | "Output filename for SRC file being native compiled." |
| 495 | (concat (comp-output-base-filename src) ".eln")) | 495 | (concat (comp-output-base-filename src) ".eln")) |
| 496 | 496 | ||
| 497 | (defmacro comp-loop-insn-in-block (basic-block &rest body) | ||
| 498 | "Loop over all insns in BASIC-BLOCK executning BODY. | ||
| 499 | Inside BODY `insn' can be used to read or set the current | ||
| 500 | instruction." | ||
| 501 | (declare (debug (form body)) | ||
| 502 | (indent defun)) | ||
| 503 | (let ((sym-cell (gensym "cell-"))) | ||
| 504 | `(cl-symbol-macrolet ((insn (car ,sym-cell))) | ||
| 505 | (cl-loop for ,sym-cell on (comp-block-insns ,basic-block) | ||
| 506 | do ,@body)))) | ||
| 497 | 507 | ||
| 498 | ;;; spill-lap pass specific code. | 508 | ;;; spill-lap pass specific code. |
| 499 | 509 | ||
| @@ -2012,18 +2022,16 @@ Backward propagate array placement properties." | |||
| 2012 | with self = (comp-func-name comp-func) | 2022 | with self = (comp-func-name comp-func) |
| 2013 | for b being each hash-value of (comp-func-blocks comp-func) | 2023 | for b being each hash-value of (comp-func-blocks comp-func) |
| 2014 | when self ;; FIXME add proper anonymous lambda support. | 2024 | when self ;; FIXME add proper anonymous lambda support. |
| 2015 | do (cl-loop | 2025 | do (comp-loop-insn-in-block b |
| 2016 | for insn-cell on (comp-block-insns b) | 2026 | (pcase insn |
| 2017 | for insn = (car insn-cell) | 2027 | (`(set ,lval (callref funcall ,f . ,rest)) |
| 2018 | do (pcase insn | 2028 | (when-let ((new-form (comp-call-optim-form-call |
| 2019 | (`(set ,lval (callref funcall ,f . ,rest)) | 2029 | (comp-mvar-constant f) rest))) |
| 2020 | (when-let ((new-form (comp-call-optim-form-call | 2030 | (setf insn `(set ,lval ,new-form)))) |
| 2021 | (comp-mvar-constant f) rest))) | 2031 | (`(callref funcall ,f . ,rest) |
| 2022 | (setcar insn-cell `(set ,lval ,new-form)))) | 2032 | (when-let ((new-form (comp-call-optim-form-call |
| 2023 | (`(callref funcall ,f . ,rest) | 2033 | (comp-mvar-constant f) rest))) |
| 2024 | (when-let ((new-form (comp-call-optim-form-call | 2034 | (setf insn new-form))))))) |
| 2025 | (comp-mvar-constant f) rest))) | ||
| 2026 | (setcar insn-cell new-form))))))) | ||
| 2027 | 2035 | ||
| 2028 | (defun comp-call-optim (_) | 2036 | (defun comp-call-optim (_) |
| 2029 | "Try to optimize out funcall trampoline usage when possible." | 2037 | "Try to optimize out funcall trampoline usage when possible." |
| @@ -2077,17 +2085,15 @@ Return the list of m-var ids nuked." | |||
| 2077 | 3) | 2085 | 3) |
| 2078 | (cl-loop | 2086 | (cl-loop |
| 2079 | for b being each hash-value of (comp-func-blocks comp-func) | 2087 | for b being each hash-value of (comp-func-blocks comp-func) |
| 2080 | do (cl-loop | 2088 | do (comp-loop-insn-in-block b |
| 2081 | for insn-cell on (comp-block-insns b) | 2089 | (cl-destructuring-bind (op &optional arg0 arg1 &rest rest) insn |
| 2082 | for insn = (car insn-cell) | 2090 | (when (and (comp-set-op-p op) |
| 2083 | for (op arg0 rest) = insn | 2091 | (memq (comp-mvar-id arg0) nuke-list)) |
| 2084 | when (and (comp-set-op-p op) | 2092 | (setf insn |
| 2085 | (memq (comp-mvar-id arg0) nuke-list)) | 2093 | (if (comp-limple-insn-call-p arg1) |
| 2086 | do (setcar insn-cell | 2094 | arg1 |
| 2087 | (if (comp-limple-insn-call-p rest) | 2095 | `(comment ,(format "optimized out: %s" |
| 2088 | rest | 2096 | insn)))))))) |
| 2089 | `(comment ,(format "optimized out: %s" | ||
| 2090 | insn)))))) | ||
| 2091 | nuke-list))) | 2097 | nuke-list))) |
| 2092 | 2098 | ||
| 2093 | (defun comp-dead-code (_) | 2099 | (defun comp-dead-code (_) |
| @@ -2154,12 +2160,10 @@ Return the list of m-var ids nuked." | |||
| 2154 | These are substituted with a normal 'set' op." | 2160 | These are substituted with a normal 'set' op." |
| 2155 | (cl-loop | 2161 | (cl-loop |
| 2156 | for b being each hash-value of (comp-func-blocks comp-func) | 2162 | for b being each hash-value of (comp-func-blocks comp-func) |
| 2157 | do (cl-loop | 2163 | do (comp-loop-insn-in-block b |
| 2158 | for insn-cell on (comp-block-insns b) | 2164 | (pcase insn |
| 2159 | for insn = (car insn-cell) | 2165 | (`(set ,l-val (call ,(pred comp-type-hint-p) ,r-val)) |
| 2160 | do (pcase insn | 2166 | (setf insn `(set ,l-val ,r-val))))))) |
| 2161 | (`(set ,l-val (call ,(pred comp-type-hint-p) ,r-val)) | ||
| 2162 | (setcar insn-cell `(set ,l-val ,r-val))))))) | ||
| 2163 | 2167 | ||
| 2164 | (defun comp-remove-type-hints (_) | 2168 | (defun comp-remove-type-hints (_) |
| 2165 | "Dead code elimination." | 2169 | "Dead code elimination." |