aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Corallo2019-08-03 17:08:55 +0200
committerAndrea Corallo2020-01-01 11:33:56 +0100
commitbebe5a9791f7db3f088e0c07b2fd68e1d21bb161 (patch)
tree28ca1049e1c34459e85a40caa832747b583716d2
parent79f7d40fa850806450621f2fa4c73974399bd7f9 (diff)
downloademacs-bebe5a9791f7db3f088e0c07b2fd68e1d21bb161.tar.gz
emacs-bebe5a9791f7db3f088e0c07b2fd68e1d21bb161.zip
add limple switch support
-rw-r--r--lisp/emacs-lisp/comp.el33
-rw-r--r--src/comp.c9
-rw-r--r--test/src/comp-tests.el25
3 files changed, 41 insertions, 26 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 69f43822948..4841753172f 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -355,11 +355,11 @@ If DST-N is specified use it otherwise assume it to be the current slot."
355 (comp-block-sp (gethash block-name blocks))) 355 (comp-block-sp (gethash block-name blocks)))
356 (setf (comp-limplify-block-name comp-pass) block-name))) 356 (setf (comp-limplify-block-name comp-pass) block-name)))
357 357
358(defun comp-emit-cond-jump (target-offset lap-label negated) 358(defun comp-emit-cond-jump (a b target-offset lap-label negated)
359 "Emit a conditional jump to LAP-LABEL. 359 "Emit a conditional jump to LAP-LABEL when A and B satisfy EQ.
360TARGET-OFFSET is the positive offset on the SP when branching to the target 360TARGET-OFFSET is the positive offset on the SP when branching to the target
361block. 361block.
362If NEGATED non nil negate the test condition." 362If NEGATED non nil negate the tested condition."
363 (let ((blocks (comp-func-blocks comp-func)) 363 (let ((blocks (comp-func-blocks comp-func))
364 (bb (comp-new-block-sym))) ;; Fall through block 364 (bb (comp-new-block-sym))) ;; Fall through block
365 (puthash bb 365 (puthash bb
@@ -367,8 +367,8 @@ If NEGATED non nil negate the test condition."
367 blocks) 367 blocks)
368 (let ((target (comp-lap-to-limple-bb lap-label))) 368 (let ((target (comp-lap-to-limple-bb lap-label)))
369 (comp-emit (if negated 369 (comp-emit (if negated
370 (list 'cond-jump (comp-slot-next) target bb) 370 (list 'cond-jump a b target bb)
371 (list 'cond-jump (comp-slot-next) bb target))) 371 (list 'cond-jump a b bb target)))
372 (puthash target 372 (puthash target
373 (make-comp-block :sp (+ target-offset (comp-sp))) 373 (make-comp-block :sp (+ target-offset (comp-sp)))
374 blocks) 374 blocks)
@@ -423,6 +423,14 @@ If NEGATED non nil negate the test condition."
423 (comp-mark-block-closed) 423 (comp-mark-block-closed)
424 (comp-emit-block guarded-bb)))) 424 (comp-emit-block guarded-bb))))
425 425
426(defun comp-emit-switch (var m-hash)
427 "Emit a limple for a lap jump table given VAR and M-HASH."
428 (cl-assert (comp-mvar-const-vld m-hash))
429 (cl-loop for test being each hash-keys of (comp-mvar-constant m-hash)
430 using (hash-value target-label)
431 for m-test = (make-comp-mvar :constant test)
432 do (comp-emit-cond-jump var m-test 0 target-label nil)))
433
426(defmacro comp-op-case (&rest cases) 434(defmacro comp-op-case (&rest cases)
427 "Expand CASES into the corresponding pcase. 435 "Expand CASES into the corresponding pcase.
428This is responsible for generating the proper stack adjustment when known and 436This is responsible for generating the proper stack adjustment when known and
@@ -583,13 +591,17 @@ the annotation emission."
583 (byte-goto 591 (byte-goto
584 (comp-emit-jump (comp-lap-to-limple-bb (cl-third insn)))) 592 (comp-emit-jump (comp-lap-to-limple-bb (cl-third insn))))
585 (byte-goto-if-nil 593 (byte-goto-if-nil
586 (comp-emit-cond-jump 0 (cl-third insn) nil)) 594 (comp-emit-cond-jump (comp-slot-next) (make-comp-mvar :constant nil) 0
595 (cl-third insn) nil))
587 (byte-goto-if-not-nil 596 (byte-goto-if-not-nil
588 (comp-emit-cond-jump 0 (cl-third insn) t)) 597 (comp-emit-cond-jump (comp-slot-next) (make-comp-mvar :constant nil) 0
598 (cl-third insn) t))
589 (byte-goto-if-nil-else-pop 599 (byte-goto-if-nil-else-pop
590 (comp-emit-cond-jump 1 (cl-third insn) nil)) 600 (comp-emit-cond-jump (comp-slot-next) (make-comp-mvar :constant nil) 1
601 (cl-third insn) nil))
591 (byte-goto-if-not-nil-else-pop 602 (byte-goto-if-not-nil-else-pop
592 (comp-emit-cond-jump 1 (cl-third insn) t)) 603 (comp-emit-cond-jump (comp-slot-next) (make-comp-mvar :constant nil) 1
604 (cl-third insn) t))
593 (byte-return 605 (byte-return
594 (comp-emit (list 'return (comp-slot-next))) 606 (comp-emit (list 'return (comp-slot-next)))
595 (comp-mark-block-closed)) 607 (comp-mark-block-closed))
@@ -642,7 +654,8 @@ the annotation emission."
642 (byte-stack-set2) 654 (byte-stack-set2)
643 (byte-discardN 655 (byte-discardN
644 (comp-stack-adjust (- arg))) 656 (comp-stack-adjust (- arg)))
645 (byte-switch) 657 (byte-switch
658 (comp-emit-switch (comp-slot-next) (comp-slot-n (+ 2 (comp-sp)))))
646 (byte-constant 659 (byte-constant
647 (comp-emit-set-const arg)) 660 (comp-emit-set-const arg))
648 (byte-discardN-preserve-tos 661 (byte-discardN-preserve-tos
diff --git a/src/comp.c b/src/comp.c
index 6436a5db712..e4483ea4206 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -1128,11 +1128,12 @@ emit_limple_insn (Lisp_Object insn)
1128 else if (EQ (op, Qcond_jump)) 1128 else if (EQ (op, Qcond_jump))
1129 { 1129 {
1130 /* Conditional branch. */ 1130 /* Conditional branch. */
1131 gcc_jit_rvalue *test = emit_mvar_val (arg0); 1131 gcc_jit_rvalue *a = emit_mvar_val (arg0);
1132 gcc_jit_block *target1 = retrive_block (SECOND (args)); 1132 gcc_jit_rvalue *b = emit_mvar_val (SECOND (args));
1133 gcc_jit_block *target2 = retrive_block (THIRD (args)); 1133 gcc_jit_block *target1 = retrive_block (THIRD (args));
1134 gcc_jit_block *target2 = retrive_block (FORTH (args));
1134 1135
1135 emit_cond_jump (emit_NILP (test), target2, target1); 1136 emit_cond_jump (emit_EQ (a, b), target2, target1);
1136 } 1137 }
1137 else if (EQ (op, Qpush_handler)) 1138 else if (EQ (op, Qpush_handler))
1138 { 1139 {
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el
index ed3a9b2f9d0..58846ed50d0 100644
--- a/test/src/comp-tests.el
+++ b/test/src/comp-tests.el
@@ -200,18 +200,19 @@
200 200
201 (should (= (comp-tests-ffuncall-lambda-f 1) 2))) 201 (should (= (comp-tests-ffuncall-lambda-f 1) 2)))
202 202
203;; (ert-deftest comp-tests-jump-table () 203(ert-deftest comp-tests-jump-table ()
204;; "Testing jump tables" 204 "Testing jump tables"
205;; (defun comp-tests-jump-table-1-f (x) 205 (defun comp-tests-jump-table-1-f (x)
206;; (pcase x 206 (pcase x
207;; ('x 'a) 207 ('x 'a)
208;; ('y 'b) 208 ('y 'b)
209;; (_ 'c))) 209 (_ 'c)))
210 210
211 211 (native-compile #'comp-tests-jump-table-1-f)
212;; (should (eq (comp-tests-jump-table-1-f 'x) 'a)) 212
213;; (should (eq (comp-tests-jump-table-1-f 'y) 'b)) 213 (should (eq (comp-tests-jump-table-1-f 'x) 'a))
214;; (should (eq (comp-tests-jump-table-1-f 'xxx) 'c))) 214 (should (eq (comp-tests-jump-table-1-f 'y) 'b))
215 (should (eq (comp-tests-jump-table-1-f 'xxx) 'c)))
215 216
216(ert-deftest comp-tests-conditionals () 217(ert-deftest comp-tests-conditionals ()
217 "Testing conditionals." 218 "Testing conditionals."