diff options
| author | Andrea Corallo | 2020-01-20 21:16:10 +0000 |
|---|---|---|
| committer | Andrea Corallo | 2020-01-21 22:06:19 +0000 |
| commit | 9e08edf98fdf1a2547eef7b5d9d3debdddb6e7c6 (patch) | |
| tree | 21a443424905431f6e10116bcddb8b733f558ab7 | |
| parent | fce1333c22d07c6b359f084b74316458f4187dc4 (diff) | |
| download | emacs-9e08edf98fdf1a2547eef7b5d9d3debdddb6e7c6.tar.gz emacs-9e08edf98fdf1a2547eef7b5d9d3debdddb6e7c6.zip | |
Extend propagation to a wider set of (non pure) functions
| -rw-r--r-- | lisp/emacs-lisp/comp.el | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 550fa7ddf2e..4ec84563f38 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el | |||
| @@ -1529,6 +1529,17 @@ PRE-LAMBDA and POST-LAMBDA are called in pre or post-order if non nil." | |||
| 1529 | ;; This is also responsible for removing function calls to pure functions if | 1529 | ;; This is also responsible for removing function calls to pure functions if |
| 1530 | ;; possible. | 1530 | ;; possible. |
| 1531 | 1531 | ||
| 1532 | (defvar comp-propagate-classes '(byte-optimize-associative-math | ||
| 1533 | byte-optimize-binary-predicate | ||
| 1534 | byte-optimize-concat | ||
| 1535 | byte-optimize-equal | ||
| 1536 | byte-optimize-identity | ||
| 1537 | byte-optimize-member | ||
| 1538 | byte-optimize-memq | ||
| 1539 | byte-optimize-predicate) | ||
| 1540 | "We optimize functions with 'byte-optimizer' property set to | ||
| 1541 | one of these symbols. See byte-opt.el.") | ||
| 1542 | |||
| 1532 | (defsubst comp-strict-type-of (obj) | 1543 | (defsubst comp-strict-type-of (obj) |
| 1533 | "Given OBJ return its type understanding fixnums." | 1544 | "Given OBJ return its type understanding fixnums." |
| 1534 | ;; Should be certainly smarter but now we take advantages just from fixnums. | 1545 | ;; Should be certainly smarter but now we take advantages just from fixnums. |
| @@ -1572,19 +1583,34 @@ This can run just once." | |||
| 1572 | (comp-mvar-constant lval) (comp-mvar-constant rval) | 1583 | (comp-mvar-constant lval) (comp-mvar-constant rval) |
| 1573 | (comp-mvar-type lval) (comp-mvar-type rval))) | 1584 | (comp-mvar-type lval) (comp-mvar-type rval))) |
| 1574 | 1585 | ||
| 1586 | ;; Here should fall most of (defun byte-optimize-* equivalents. | ||
| 1587 | (defsubst comp-function-optimizable (f args) | ||
| 1588 | "Given function F called with ARGS return non nil when optimizable." | ||
| 1589 | (when (cl-every #'comp-mvar-const-vld args) | ||
| 1590 | (or (get f 'pure) | ||
| 1591 | (memq (get f 'byte-optimizer) comp-propagate-classes) | ||
| 1592 | (let ((values (mapcar #'comp-mvar-constant args))) | ||
| 1593 | (pcase f | ||
| 1594 | ;; Simple integer operation. | ||
| 1595 | ;; Note: byte-opt uses `byte-opt--portable-numberp' | ||
| 1596 | ;; instead of just`fixnump'. | ||
| 1597 | ((or '+ '- '* '1+ '-1) (and (cl-every #'fixnump values) | ||
| 1598 | (fixnump (apply f values)))) | ||
| 1599 | ('/ (and (cl-every #'fixnump values) | ||
| 1600 | (not (= (car (last values)) 0))))))))) | ||
| 1601 | |||
| 1575 | (defsubst comp-function-call-remove (insn f args) | 1602 | (defsubst comp-function-call-remove (insn f args) |
| 1576 | "Given INSN when F is pure if all ARGS are known remove the function call." | 1603 | "Given INSN when F is pure if all ARGS are known remove the function call." |
| 1577 | (when (and (get f 'pure) ; Can we just optimize pure here? See byte-opt.el | 1604 | (when (comp-function-optimizable f args) |
| 1578 | (cl-every #'comp-mvar-const-vld args)) | ||
| 1579 | (ignore-errors | 1605 | (ignore-errors |
| 1580 | ;; No point to complain here because we should do basic block | 1606 | ;; No point to complain here because we should do basic block |
| 1581 | ;; pruning in order to be sure that this is not dead-code. This | 1607 | ;; pruning in order to be sure that this is not dead-code. This |
| 1582 | ;; is now left to gcc, to be implemented only if we want a | 1608 | ;; is now left to gcc, to be implemented only if we want a |
| 1583 | ;; reliable diagnostic here. | 1609 | ;; reliable diagnostic here. |
| 1584 | (let ((val (apply f (mapcar #'comp-mvar-constant args)))) | 1610 | (let ((values (apply f (mapcar #'comp-mvar-constant args)))) |
| 1585 | ;; See `comp-emit-set-const'. | 1611 | ;; See `comp-emit-set-const'. |
| 1586 | (setf (car insn) 'setimm | 1612 | (setf (car insn) 'setimm |
| 1587 | (cddr insn) (list (comp-add-const-to-relocs val) val)))))) | 1613 | (cddr insn) (list (comp-add-const-to-relocs values) values)))))) |
| 1588 | 1614 | ||
| 1589 | (defun comp-propagate-insn (insn) | 1615 | (defun comp-propagate-insn (insn) |
| 1590 | "Propagate within INSN." | 1616 | "Propagate within INSN." |