aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Corallo2019-11-10 10:17:24 +0100
committerAndrea Corallo2020-01-01 11:38:02 +0100
commit2ee2c67736cd76a52a2eb1002d0ec15e883082e0 (patch)
tree8650e5871c63eb76ee5077a9d5a29d5337d3a873
parent105e7180230dc22db91af2c8cbfa6fc3d2fee7e6 (diff)
downloademacs-2ee2c67736cd76a52a2eb1002d0ec15e883082e0.tar.gz
emacs-2ee2c67736cd76a52a2eb1002d0ec15e883082e0.zip
simplify non local exit handler mechanism
-rw-r--r--lisp/emacs-lisp/comp.el17
-rw-r--r--src/comp.c63
2 files changed, 36 insertions, 44 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index cb001bc884c..377886996ea 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -221,9 +221,7 @@ structure.")
221 (edge-cnt-gen (funcall #'comp-gen-counter) :type function 221 (edge-cnt-gen (funcall #'comp-gen-counter) :type function
222 :documentation "Generates edges numbers.") 222 :documentation "Generates edges numbers.")
223 (ssa-cnt-gen (funcall #'comp-gen-counter) :type function 223 (ssa-cnt-gen (funcall #'comp-gen-counter) :type function
224 :documentation "Counter to create ssa limple vars.") 224 :documentation "Counter to create ssa limple vars."))
225 (handler-cnt 0 :type number
226 :documentation "Number of non local handler buffers."))
227 225
228(defun comp-func-reset-generators (func) 226(defun comp-func-reset-generators (func)
229 "Reset unique id generators for FUNC." 227 "Reset unique id generators for FUNC."
@@ -648,17 +646,14 @@ Return value is the fall through block name."
648 (let* ((guarded-bb (comp-bb-maybe-add (1+ (comp-limplify-pc comp-pass)) 646 (let* ((guarded-bb (comp-bb-maybe-add (1+ (comp-limplify-pc comp-pass))
649 (comp-sp))) 647 (comp-sp)))
650 (handler-bb (comp-bb-maybe-add (comp-label-to-addr label-num) 648 (handler-bb (comp-bb-maybe-add (comp-label-to-addr label-num)
651 (1+ (comp-sp)))) 649 (1+ (comp-sp)))))
652 (handler-buff-n (comp-func-handler-cnt comp-func)))
653 (comp-emit (list 'push-handler 650 (comp-emit (list 'push-handler
654 handler-type 651 handler-type
655 (comp-slot+1) 652 (comp-slot+1)
656 handler-buff-n
657 (comp-block-name handler-bb) 653 (comp-block-name handler-bb)
658 (comp-block-name guarded-bb))) 654 (comp-block-name guarded-bb)))
659 (setf (comp-block-closed (comp-limplify-curr-block comp-pass)) t) 655 (setf (comp-block-closed (comp-limplify-curr-block comp-pass)) t)
660 (comp-emit-as-head `(fetch-handler ,(comp-slot+1) ,handler-buff-n) handler-bb) 656 (comp-emit-as-head `(fetch-handler ,(comp-slot+1)) handler-bb))))
661 (cl-incf (comp-func-handler-cnt comp-func)))))
662 657
663(defun comp-limplify-listn (n) 658(defun comp-limplify-listn (n)
664 "Limplify list N." 659 "Limplify list N."
@@ -1181,7 +1176,7 @@ Top level forms for the current context are rendered too."
1181 (cl-loop with blocks = (comp-func-blocks comp-func) 1176 (cl-loop with blocks = (comp-func-blocks comp-func)
1182 for bb being each hash-value of blocks 1177 for bb being each hash-value of blocks
1183 for last-insn = (car (last (comp-block-insns bb))) 1178 for last-insn = (car (last (comp-block-insns bb)))
1184 for (op first second third forth fifth) = last-insn 1179 for (op first second third forth) = last-insn
1185 do (cl-case op 1180 do (cl-case op
1186 (jump 1181 (jump
1187 (edge-add :src bb :dst (gethash first blocks))) 1182 (edge-add :src bb :dst (gethash first blocks)))
@@ -1192,8 +1187,8 @@ Top level forms for the current context are rendered too."
1192 (edge-add :src bb :dst (gethash second blocks)) 1187 (edge-add :src bb :dst (gethash second blocks))
1193 (edge-add :src bb :dst (gethash third blocks))) 1188 (edge-add :src bb :dst (gethash third blocks)))
1194 (push-handler 1189 (push-handler
1195 (edge-add :src bb :dst (gethash forth blocks)) 1190 (edge-add :src bb :dst (gethash third blocks))
1196 (edge-add :src bb :dst (gethash fifth blocks))) 1191 (edge-add :src bb :dst (gethash forth blocks)))
1197 (return) 1192 (return)
1198 (otherwise 1193 (otherwise
1199 (error "Block %s does not end with a branch in func %s" 1194 (error "Block %s does not end with a branch in func %s"
diff --git a/src/comp.c b/src/comp.c
index 07c35413dde..cce4f1d6e52 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -55,6 +55,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
55#define THIRD(x) \ 55#define THIRD(x) \
56 XCAR (XCDR (XCDR (x))) 56 XCAR (XCDR (XCDR (x)))
57 57
58/* FIXME with call1 */
58#define FUNCALL1(fun, arg) \ 59#define FUNCALL1(fun, arg) \
59 CALLN (Ffuncall, intern_c_string (STR(fun)), arg) 60 CALLN (Ffuncall, intern_c_string (STR(fun)), arg)
60 61
@@ -114,6 +115,7 @@ typedef struct {
114 gcc_jit_field *handler_val_field; 115 gcc_jit_field *handler_val_field;
115 gcc_jit_field *handler_next_field; 116 gcc_jit_field *handler_next_field;
116 gcc_jit_type *handler_ptr_type; 117 gcc_jit_type *handler_ptr_type;
118 gcc_jit_lvalue *loc_handler;
117 /* struct thread_state. */ 119 /* struct thread_state. */
118 gcc_jit_struct *thread_state_s; 120 gcc_jit_struct *thread_state_s;
119 gcc_jit_field *m_handlerlist; 121 gcc_jit_field *m_handlerlist;
@@ -161,7 +163,6 @@ typedef struct {
161 Lisp_Object func_blocks_h; /* blk_name -> gcc_block. */ 163 Lisp_Object func_blocks_h; /* blk_name -> gcc_block. */
162 Lisp_Object exported_funcs_h; /* subr_name -> gcc_jit_function *. */ 164 Lisp_Object exported_funcs_h; /* subr_name -> gcc_jit_function *. */
163 Lisp_Object imported_funcs_h; /* subr_name -> reloc_field. */ 165 Lisp_Object imported_funcs_h; /* subr_name -> reloc_field. */
164 Lisp_Object buffer_handler_vec; /* All locals used to store non local exit values. */
165 Lisp_Object emitter_dispatcher; 166 Lisp_Object emitter_dispatcher;
166 gcc_jit_rvalue *data_relocs; /* Synthesized struct holding data relocs. */ 167 gcc_jit_rvalue *data_relocs; /* Synthesized struct holding data relocs. */
167 gcc_jit_lvalue *func_relocs; /* Synthesized struct holding func relocs. */ 168 gcc_jit_lvalue *func_relocs; /* Synthesized struct holding func relocs. */
@@ -1145,25 +1146,23 @@ emit_limple_call_ref (Lisp_Object insn, bool direct)
1145 1146
1146static void 1147static void
1147emit_limple_push_handler (gcc_jit_rvalue *handler, gcc_jit_rvalue *handler_type, 1148emit_limple_push_handler (gcc_jit_rvalue *handler, gcc_jit_rvalue *handler_type,
1148 EMACS_UINT handler_buff_n, gcc_jit_block *handler_bb, 1149 gcc_jit_block *handler_bb, gcc_jit_block *guarded_bb,
1149 gcc_jit_block *guarded_bb, Lisp_Object clobbered_mvar) 1150 Lisp_Object clobbered_mvar)
1150{ 1151{
1151 /* struct handler *c = push_handler (POP, type); */ 1152 /* struct handler *c = push_handler (POP, type); */
1152 gcc_jit_lvalue *c =
1153 xmint_pointer (AREF (comp.buffer_handler_vec, handler_buff_n));
1154 1153
1155 gcc_jit_rvalue *args[] = { handler, handler_type }; 1154 gcc_jit_rvalue *args[] = { handler, handler_type };
1156 gcc_jit_block_add_assignment ( 1155 gcc_jit_block_add_assignment (
1157 comp.block, 1156 comp.block,
1158 NULL, 1157 NULL,
1159 c, 1158 comp.loc_handler,
1160 emit_call (intern_c_string ("push_handler"), 1159 emit_call (intern_c_string ("push_handler"),
1161 comp.handler_ptr_type, 2, args, false)); 1160 comp.handler_ptr_type, 2, args, false));
1162 1161
1163 args[0] = 1162 args[0] =
1164 gcc_jit_lvalue_get_address ( 1163 gcc_jit_lvalue_get_address (
1165 gcc_jit_rvalue_dereference_field ( 1164 gcc_jit_rvalue_dereference_field (
1166 gcc_jit_lvalue_as_rvalue (c), 1165 gcc_jit_lvalue_as_rvalue (comp.loc_handler),
1167 NULL, 1166 NULL,
1168 comp.handler_jmp_field), 1167 comp.handler_jmp_field),
1169 NULL); 1168 NULL);
@@ -1236,10 +1235,9 @@ emit_limple_insn (Lisp_Object insn)
1236 else if (EQ (op, Qpush_handler)) 1235 else if (EQ (op, Qpush_handler))
1237 { 1236 {
1238 /* (push-handler condition-case #s(comp-mvar 0 3 t (arith-error) cons nil) 1 bb_2 bb_1) */ 1237 /* (push-handler condition-case #s(comp-mvar 0 3 t (arith-error) cons nil) 1 bb_2 bb_1) */
1239 gcc_jit_rvalue *handler = emit_mvar_val (arg[1]);
1240 int h_num UNINIT; 1238 int h_num UNINIT;
1241 Lisp_Object handler_spec = arg[0]; 1239 Lisp_Object handler_spec = arg[0];
1242 EMACS_UINT handler_buff_n = XFIXNUM (arg[2]); 1240 gcc_jit_rvalue *handler = emit_mvar_val (arg[1]);
1243 if (EQ (handler_spec, Qcatcher)) 1241 if (EQ (handler_spec, Qcatcher))
1244 h_num = CATCHER; 1242 h_num = CATCHER;
1245 else if (EQ (handler_spec, Qcondition_case)) 1243 else if (EQ (handler_spec, Qcondition_case))
@@ -1250,10 +1248,10 @@ emit_limple_insn (Lisp_Object insn)
1250 gcc_jit_context_new_rvalue_from_int (comp.ctxt, 1248 gcc_jit_context_new_rvalue_from_int (comp.ctxt,
1251 comp.int_type, 1249 comp.int_type,
1252 h_num); 1250 h_num);
1253 gcc_jit_block *handler_bb = retrive_block (arg[3]); 1251 gcc_jit_block *handler_bb = retrive_block (arg[2]);
1254 gcc_jit_block *guarded_bb = retrive_block (arg[4]); 1252 gcc_jit_block *guarded_bb = retrive_block (arg[3]);
1255 emit_limple_push_handler (handler, handler_type, handler_buff_n, 1253 emit_limple_push_handler (handler, handler_type, handler_bb, guarded_bb,
1256 handler_bb, guarded_bb, arg[0]); 1254 arg[0]);
1257 } 1255 }
1258 else if (EQ (op, Qpop_handler)) 1256 else if (EQ (op, Qpop_handler))
1259 { 1257 {
@@ -1281,29 +1279,33 @@ emit_limple_insn (Lisp_Object insn)
1281 } 1279 }
1282 else if (EQ (op, Qfetch_handler)) 1280 else if (EQ (op, Qfetch_handler))
1283 { 1281 {
1284 EMACS_UINT handler_buff_n = XFIXNUM (arg[1]);
1285 gcc_jit_lvalue *c =
1286 xmint_pointer (AREF (comp.buffer_handler_vec, handler_buff_n));
1287 gcc_jit_lvalue *m_handlerlist = 1282 gcc_jit_lvalue *m_handlerlist =
1288 gcc_jit_rvalue_dereference_field ( 1283 gcc_jit_rvalue_dereference_field (
1289 gcc_jit_lvalue_as_rvalue ( 1284 gcc_jit_lvalue_as_rvalue (
1290 gcc_jit_rvalue_dereference (comp.current_thread_ref, NULL)), 1285 gcc_jit_rvalue_dereference (comp.current_thread_ref, NULL)),
1291 NULL, 1286 NULL,
1292 comp.m_handlerlist); 1287 comp.m_handlerlist);
1288 gcc_jit_block_add_assignment (comp.block,
1289 NULL,
1290 comp.loc_handler,
1291 gcc_jit_lvalue_as_rvalue (m_handlerlist));
1292
1293 gcc_jit_block_add_assignment ( 1293 gcc_jit_block_add_assignment (
1294 comp.block, 1294 comp.block,
1295 NULL, 1295 NULL,
1296 m_handlerlist, 1296 m_handlerlist,
1297 gcc_jit_lvalue_as_rvalue( 1297 gcc_jit_lvalue_as_rvalue(
1298 gcc_jit_rvalue_dereference_field (gcc_jit_lvalue_as_rvalue (c), 1298 gcc_jit_rvalue_dereference_field (
1299 NULL, 1299 gcc_jit_lvalue_as_rvalue (comp.loc_handler),
1300 comp.handler_next_field))); 1300 NULL,
1301 comp.handler_next_field)));
1301 emit_frame_assignment ( 1302 emit_frame_assignment (
1302 arg[0], 1303 arg[0],
1303 gcc_jit_lvalue_as_rvalue( 1304 gcc_jit_lvalue_as_rvalue(
1304 gcc_jit_rvalue_dereference_field (gcc_jit_lvalue_as_rvalue (c), 1305 gcc_jit_rvalue_dereference_field (
1305 NULL, 1306 gcc_jit_lvalue_as_rvalue (comp.loc_handler),
1306 comp.handler_val_field))); 1307 NULL,
1308 comp.handler_val_field)));
1307 } 1309 }
1308 else if (EQ (op, Qcall)) 1310 else if (EQ (op, Qcall))
1309 { 1311 {
@@ -2802,15 +2804,10 @@ compile_function (Lisp_Object func)
2802 format_string ("local%u", i)); 2804 format_string ("local%u", i));
2803 } 2805 }
2804 2806
2805 EMACS_UINT non_local_handlers = XFIXNUM (FUNCALL1 (comp-func-handler-cnt, func)); 2807 comp.loc_handler = gcc_jit_function_new_local (comp.func,
2806 comp.buffer_handler_vec = make_vector (non_local_handlers, Qnil); 2808 NULL,
2807 for (unsigned i = 0; i < non_local_handlers; ++i) 2809 comp.handler_ptr_type,
2808 ASET (comp.buffer_handler_vec, i, 2810 "handler");
2809 make_mint_ptr (
2810 gcc_jit_function_new_local (comp.func,
2811 NULL,
2812 comp.handler_ptr_type,
2813 format_string ("handler_%u", i))));
2814 2811
2815 comp.func_blocks_h = CALLN (Fmake_hash_table); 2812 comp.func_blocks_h = CALLN (Fmake_hash_table);
2816 2813