diff options
| author | Andrea Corallo | 2019-11-10 10:17:24 +0100 |
|---|---|---|
| committer | Andrea Corallo | 2020-01-01 11:38:02 +0100 |
| commit | 2ee2c67736cd76a52a2eb1002d0ec15e883082e0 (patch) | |
| tree | 8650e5871c63eb76ee5077a9d5a29d5337d3a873 /src | |
| parent | 105e7180230dc22db91af2c8cbfa6fc3d2fee7e6 (diff) | |
| download | emacs-2ee2c67736cd76a52a2eb1002d0ec15e883082e0.tar.gz emacs-2ee2c67736cd76a52a2eb1002d0ec15e883082e0.zip | |
simplify non local exit handler mechanism
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp.c | 63 |
1 files changed, 30 insertions, 33 deletions
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 | ||
| 1146 | static void | 1147 | static void |
| 1147 | emit_limple_push_handler (gcc_jit_rvalue *handler, gcc_jit_rvalue *handler_type, | 1148 | emit_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 | ||