From 69cbf2b2f304f82c6d77cd663d4211bf125ebe74 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Tue, 17 Sep 2019 01:01:34 +0200 Subject: [PATCH] keep on fixing ssa --- lisp/emacs-lisp/comp.el | 25 +++++++++++++++++-------- src/comp.c | 19 +++++++++++++------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index f56a66a5666..c390225e064 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -70,7 +70,11 @@ (% . number)) "Alist used for type propagation.") -(defconst comp-limple-assignments '(set setimm set-par-to-local) +(defconst comp-limple-assignments '(set + setimm + set-par-to-local + set-args-to-local + set-rest-args-to-local) "Limple operators used to assign to mvars.") (defconst comp-mostly-pure-funcs @@ -148,7 +152,10 @@ into it.") (df (make-hash-table) :type hash-table :documentation "Dominance frontier set. Block-name -> block") (post-num nil :type number - :documentation "Post order number.")) + :documentation "Post order number.") + (final-frame nil :type vector + :documentation "This is a copy of the frame when leaving the block. +Is in use to help the SSA rename pass.")) (cl-defstruct (comp-edge (:copier nil) (:constructor make--comp-edge)) "An edge connecting two basic blocks." @@ -894,7 +901,7 @@ the annotation emission." "Emit the prologue for a narg function." (cl-loop for i below minarg do (progn - (comp-emit `(set-args-to-local ,i)) + (comp-emit `(set-args-to-local ,(comp-slot-n i))) (comp-emit '(inc-args)))) (cl-loop for i from minarg below nonrest for bb = (intern (format "entry_%s" i)) @@ -903,7 +910,7 @@ the annotation emission." (comp-emit `(cond-jump-narg-leq ,i ,bb ,fallback)) (comp-mark-block-closed) (comp-emit-block bb) - (comp-emit `(set-args-to-local ,i)) + (comp-emit `(set-args-to-local ,(comp-slot-n i))) (comp-emit '(inc-args))) finally (comp-emit-jump 'entry_rest_args)) (cl-loop for i from minarg below nonrest @@ -911,7 +918,7 @@ the annotation emission." (comp-emit-block (intern (format "entry_fallback_%s" i))) (comp-emit-set-const nil))) (comp-emit-block 'entry_rest_args) - (comp-emit `(set-rest-args-to-local ,nonrest))) + (comp-emit `(set-rest-args-to-local ,(comp-slot-n nonrest)))) (defun comp-limplify-finalize-function (func) "Reverse insns into all basic blocks of FUNC." @@ -1130,14 +1137,14 @@ Top level forms for the current context are rendered too." (cl-loop for i from 0 below (comp-func-frame-size comp-func) ;; List of blocks with a definition of mvar i - with defs-v = (cl-loop with blocks = (comp-func-blocks comp-func) + for defs-v = (cl-loop with blocks = (comp-func-blocks comp-func) for b being each hash-value of blocks when (slot-assigned-p i b) collect b) ;; Set of basic blocks where phi is added. - with f = () + for f = () ;; Worklist, set of basic blocks that contain definitions of v. - with w = defs-v + for w = defs-v do (while w (let ((x (pop w))) @@ -1203,6 +1210,8 @@ PRE-LAMBDA and POST-LAMBDA are called in pre or post-order if non nil." (puthash bb t visited) (cl-loop for insn in (comp-block-insns bb) do (comp-ssa-rename-insn insn in-frame)) + (setf (comp-block-final-frame bb) + (copy-sequence in-frame)) (when-let ((out-edges (comp-block-out-edges bb))) (cl-loop for ed in out-edges for child = (comp-edge-dst ed) diff --git a/src/comp.c b/src/comp.c index 2846037e5a0..8aadd5acc91 100644 --- a/src/comp.c +++ b/src/comp.c @@ -1265,6 +1265,10 @@ emit_limple_insn (Lisp_Object insn) n); emit_cond_jump (test, target2, target1); } + else if (EQ (op, Qphi)) + { + /* Nothing to do for phis into the backend. */ + } else if (EQ (op, Qpush_handler)) { EMACS_UINT clobber_slot = XFIXNUM (FUNCALL1 (comp-mvar-slot, arg0)); @@ -1350,7 +1354,7 @@ emit_limple_insn (Lisp_Object insn) else if (EQ (op, Qset_args_to_local)) { /* - Limple: (set-args-to-local 1) + Limple: (set-args-to-local #s(comp-mvar 1 6 nil nil nil nil)) C: local[1] = *args; */ gcc_jit_rvalue *gcc_args = @@ -1360,7 +1364,7 @@ emit_limple_insn (Lisp_Object insn) gcc_jit_rvalue *res = gcc_jit_lvalue_as_rvalue (gcc_jit_rvalue_dereference (gcc_args, NULL)); - EMACS_UINT slot_n = XFIXNUM (arg0); + EMACS_UINT slot_n = XFIXNUM (FUNCALL1 (comp-mvar-slot, arg0)); gcc_jit_block_add_assignment (comp.block, NULL, comp.frame[slot_n], @@ -1369,13 +1373,15 @@ emit_limple_insn (Lisp_Object insn) else if (EQ (op, Qset_rest_args_to_local)) { /* - Limple: (set-rest-args-to-local 3) - C: local[3] = list (nargs - 3, args); + Limple: (set-rest-args-to-local #s(comp-mvar 2 9 nil nil nil nil)) + C: local[2] = list (nargs - 2, args); */ + + EMACS_UINT slot_n = XFIXNUM (FUNCALL1 (comp-mvar-slot, arg0)); gcc_jit_rvalue *n = gcc_jit_context_new_rvalue_from_int (comp.ctxt, comp.ptrdiff_type, - XFIXNUM (arg0)); + slot_n); gcc_jit_lvalue *nargs = gcc_jit_param_as_lvalue (gcc_jit_function_get_param (comp.func, 0)); gcc_jit_lvalue *args = @@ -1395,7 +1401,7 @@ emit_limple_insn (Lisp_Object insn) gcc_jit_block_add_assignment (comp.block, NULL, - comp.frame[XFIXNUM (arg0)], + comp.frame[slot_n], res); } else if (EQ (op, Qinc_args)) @@ -3274,6 +3280,7 @@ syms_of_comp (void) DEFSYM (Qreturn, "return"); DEFSYM (Qcomp_mvar, "comp-mvar"); DEFSYM (Qcond_jump, "cond-jump"); + DEFSYM (Qphi, "phi"); /* In use for prologue emission. */ DEFSYM (Qset_par_to_local, "set-par-to-local"); DEFSYM (Qset_args_to_local, "set-args-to-local"); -- 2.39.5