diff options
| author | Andrea Corallo | 2019-06-30 17:23:14 +0200 |
|---|---|---|
| committer | Andrea Corallo | 2020-01-01 11:33:48 +0100 |
| commit | c4b003f3c8d4a7e508b3f8d72e46829735ffbcbd (patch) | |
| tree | 568c66ef82bc08672d7523c94ad3ce9df0db9e60 | |
| parent | 9e71843f6301cff6e3f0d06e46c47bc5a5c7b177 (diff) | |
| download | emacs-c4b003f3c8d4a7e508b3f8d72e46829735ffbcbd.tar.gz emacs-c4b003f3c8d4a7e508b3f8d72e46829735ffbcbd.zip | |
add emit_assign_to_stack_slot
| -rw-r--r-- | src/comp.c | 133 |
1 files changed, 61 insertions, 72 deletions
diff --git a/src/comp.c b/src/comp.c index 73a76ea8911..3cd1c3c8dbb 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -42,42 +42,31 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 42 | #define CHECK_STACK \ | 42 | #define CHECK_STACK \ |
| 43 | eassert (stack >= stack_base && stack < stack_over) | 43 | eassert (stack >= stack_base && stack < stack_over) |
| 44 | 44 | ||
| 45 | #define PUSH_LVAL(obj) \ | 45 | #define PUSH_LVAL(obj) \ |
| 46 | do { \ | 46 | do { \ |
| 47 | CHECK_STACK; \ | 47 | CHECK_STACK; \ |
| 48 | gcc_jit_block_add_assignment (comp.block->gcc_bb, \ | 48 | emit_assign_to_stack_slot (comp.block, \ |
| 49 | NULL, \ | 49 | stack, \ |
| 50 | stack->gcc_lval, \ | 50 | gcc_jit_lvalue_as_rvalue (obj)); \ |
| 51 | gcc_jit_lvalue_as_rvalue(obj)); \ | 51 | stack++; \ |
| 52 | stack->type = -1; \ | ||
| 53 | stack->const_set = false; \ | ||
| 54 | stack++; \ | ||
| 55 | } while (0) | 52 | } while (0) |
| 56 | 53 | ||
| 57 | #define PUSH_RVAL(obj) \ | 54 | #define PUSH_RVAL(obj) \ |
| 58 | do { \ | 55 | do { \ |
| 59 | CHECK_STACK; \ | 56 | CHECK_STACK; \ |
| 60 | gcc_jit_block_add_assignment (comp.block->gcc_bb, \ | 57 | emit_assign_to_stack_slot (comp.block, stack, (obj)); \ |
| 61 | NULL, \ | 58 | stack++; \ |
| 62 | stack->gcc_lval, \ | ||
| 63 | (obj)); \ | ||
| 64 | stack->type = -1; \ | ||
| 65 | stack->const_set = false; \ | ||
| 66 | stack++; \ | ||
| 67 | } while (0) | 59 | } while (0) |
| 68 | 60 | ||
| 69 | /* This always happens in the first basic block. */ | 61 | /* This always happens in the first basic block. */ |
| 70 | 62 | ||
| 71 | #define PUSH_PARAM(obj) \ | 63 | #define PUSH_PARAM(obj) \ |
| 72 | do { \ | 64 | do { \ |
| 73 | CHECK_STACK; \ | 65 | CHECK_STACK; \ |
| 74 | gcc_jit_block_add_assignment (prologue_bb, \ | 66 | emit_assign_to_stack_slot (prologue, \ |
| 75 | NULL, \ | 67 | stack, \ |
| 76 | stack->gcc_lval, \ | 68 | gcc_jit_param_as_rvalue (obj)); \ |
| 77 | gcc_jit_param_as_rvalue(obj)); \ | 69 | stack++; \ |
| 78 | stack->type = -1; \ | ||
| 79 | stack->const_set = false; \ | ||
| 80 | stack++; \ | ||
| 81 | } while (0) | 70 | } while (0) |
| 82 | 71 | ||
| 83 | #define TOS (*(stack - 1)) | 72 | #define TOS (*(stack - 1)) |
| @@ -127,8 +116,8 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 127 | /* With most of the ops we need to do the same stuff so this macros are meant | 116 | /* With most of the ops we need to do the same stuff so this macros are meant |
| 128 | to save some typing. */ | 117 | to save some typing. */ |
| 129 | 118 | ||
| 130 | #define CASE(op) \ | 119 | #define CASE(op) \ |
| 131 | case op : \ | 120 | case op : \ |
| 132 | emit_comment (STR(op)) | 121 | emit_comment (STR(op)) |
| 133 | 122 | ||
| 134 | /* Pop from the meta-stack, emit the call and push the result */ | 123 | /* Pop from the meta-stack, emit the call and push the result */ |
| @@ -367,6 +356,23 @@ emit_comment (const char *str) | |||
| 367 | str); | 356 | str); |
| 368 | } | 357 | } |
| 369 | 358 | ||
| 359 | |||
| 360 | /* Assignments to the meta-stack slots should be emitted usign this to always */ | ||
| 361 | /* reset annotation fields. */ | ||
| 362 | |||
| 363 | static void | ||
| 364 | emit_assign_to_stack_slot(basic_block_t *block, stack_el_t *slot, | ||
| 365 | gcc_jit_rvalue *val) | ||
| 366 | { | ||
| 367 | gcc_jit_block_add_assignment (block->gcc_bb, | ||
| 368 | NULL, | ||
| 369 | slot->gcc_lval, | ||
| 370 | val); | ||
| 371 | slot->type = -1; | ||
| 372 | slot->const_set = false; | ||
| 373 | } | ||
| 374 | |||
| 375 | |||
| 370 | static gcc_jit_function * | 376 | static gcc_jit_function * |
| 371 | emit_func_declare (const char *f_name, gcc_jit_type *ret_type, | 377 | emit_func_declare (const char *f_name, gcc_jit_type *ret_type, |
| 372 | unsigned nargs, gcc_jit_rvalue **args, | 378 | unsigned nargs, gcc_jit_rvalue **args, |
| @@ -2103,14 +2109,13 @@ compile_f (const char *lisp_f_name, const char *c_f_name, | |||
| 2103 | comp.int_type, | 2109 | comp.int_type, |
| 2104 | i)); | 2110 | i)); |
| 2105 | 2111 | ||
| 2106 | gcc_jit_block *prologue_bb = | 2112 | DECL_AND_SAFE_ALLOCA_BLOCK(prologue, comp.func); |
| 2107 | gcc_jit_function_new_block (comp.func, "prologue"); | ||
| 2108 | 2113 | ||
| 2109 | basic_block_t *bb_map = compute_blocks (bytestr_length, bytestr_data); | 2114 | basic_block_t *bb_map = compute_blocks (bytestr_length, bytestr_data); |
| 2110 | 2115 | ||
| 2111 | for (ptrdiff_t i = 0; i < comp_res.max_args; ++i) | 2116 | for (ptrdiff_t i = 0; i < comp_res.max_args; ++i) |
| 2112 | PUSH_PARAM (gcc_jit_function_get_param (comp.func, i)); | 2117 | PUSH_PARAM (gcc_jit_function_get_param (comp.func, i)); |
| 2113 | gcc_jit_block_end_with_jump (prologue_bb, NULL, bb_map[0].gcc_bb); | 2118 | gcc_jit_block_end_with_jump (prologue->gcc_bb, NULL, bb_map[0].gcc_bb); |
| 2114 | 2119 | ||
| 2115 | comp.block = &bb_map[0]; | 2120 | comp.block = &bb_map[0]; |
| 2116 | gcc_jit_rvalue *nil = emit_lisp_obj_from_ptr (Qnil); | 2121 | gcc_jit_rvalue *nil = emit_lisp_obj_from_ptr (Qnil); |
| @@ -2322,7 +2327,7 @@ compile_f (const char *lisp_f_name, const char *c_f_name, | |||
| 2322 | args + 1); | 2327 | args + 1); |
| 2323 | } | 2328 | } |
| 2324 | } | 2329 | } |
| 2325 | /* Fall back to regular funcall dispatch. */ | 2330 | /* Fall back to regular funcall dispatch mechanism. */ |
| 2326 | if (!res) | 2331 | if (!res) |
| 2327 | res = emit_call_n_ref ("Ffuncall", nargs, stack->gcc_lval); | 2332 | res = emit_call_n_ref ("Ffuncall", nargs, stack->gcc_lval); |
| 2328 | 2333 | ||
| @@ -2438,14 +2443,14 @@ compile_f (const char *lisp_f_name, const char *c_f_name, | |||
| 2438 | gcc_jit_rvalue_dereference_field (comp.current_thread, | 2443 | gcc_jit_rvalue_dereference_field (comp.current_thread, |
| 2439 | NULL, | 2444 | NULL, |
| 2440 | comp.m_handlerlist); | 2445 | comp.m_handlerlist); |
| 2441 | gcc_jit_block_add_assignment(comp.block->gcc_bb, | 2446 | gcc_jit_block_add_assignment (comp.block->gcc_bb, |
| 2442 | NULL, | 2447 | NULL, |
| 2443 | m_handlerlist, | 2448 | m_handlerlist, |
| 2444 | gcc_jit_lvalue_as_rvalue( | 2449 | gcc_jit_lvalue_as_rvalue( |
| 2445 | gcc_jit_rvalue_dereference_field ( | 2450 | gcc_jit_rvalue_dereference_field ( |
| 2446 | gcc_jit_lvalue_as_rvalue (c), | 2451 | gcc_jit_lvalue_as_rvalue (c), |
| 2447 | NULL, | 2452 | NULL, |
| 2448 | comp.handler_next_field))); | 2453 | comp.handler_next_field))); |
| 2449 | /* PUSH (c->val); */ | 2454 | /* PUSH (c->val); */ |
| 2450 | PUSH_LVAL (gcc_jit_rvalue_dereference_field ( | 2455 | PUSH_LVAL (gcc_jit_rvalue_dereference_field ( |
| 2451 | gcc_jit_lvalue_as_rvalue (c), | 2456 | gcc_jit_lvalue_as_rvalue (c), |
| @@ -2593,11 +2598,9 @@ compile_f (const char *lisp_f_name, const char *c_f_name, | |||
| 2593 | basic_block_t *bb_orig = comp.block; | 2598 | basic_block_t *bb_orig = comp.block; |
| 2594 | 2599 | ||
| 2595 | comp.block = sub1_inline_block; | 2600 | comp.block = sub1_inline_block; |
| 2596 | gcc_jit_block_add_assignment (sub1_inline_block->gcc_bb, | 2601 | emit_assign_to_stack_slot (sub1_inline_block, |
| 2597 | NULL, | 2602 | &TOS, |
| 2598 | TOS.gcc_lval, | 2603 | emit_make_fixnum (sub1_inline_res)); |
| 2599 | emit_make_fixnum (sub1_inline_res)); | ||
| 2600 | |||
| 2601 | comp.block = sub1_fcall_block; | 2604 | comp.block = sub1_fcall_block; |
| 2602 | POP1; | 2605 | POP1; |
| 2603 | res = emit_call ("Fsub1", comp.lisp_obj_type, 1, args); | 2606 | res = emit_call ("Fsub1", comp.lisp_obj_type, 1, args); |
| @@ -2652,12 +2655,9 @@ compile_f (const char *lisp_f_name, const char *c_f_name, | |||
| 2652 | 2655 | ||
| 2653 | basic_block_t *bb_orig = comp.block; | 2656 | basic_block_t *bb_orig = comp.block; |
| 2654 | comp.block = add1_inline_block; | 2657 | comp.block = add1_inline_block; |
| 2655 | 2658 | emit_assign_to_stack_slot(add1_inline_block, | |
| 2656 | gcc_jit_block_add_assignment (add1_inline_block->gcc_bb | 2659 | &TOS, |
| 2657 | , | 2660 | emit_make_fixnum (add1_inline_res)); |
| 2658 | NULL, | ||
| 2659 | TOS.gcc_lval, | ||
| 2660 | emit_make_fixnum (add1_inline_res)); | ||
| 2661 | comp.block = add1_fcall_block; | 2661 | comp.block = add1_fcall_block; |
| 2662 | POP1; | 2662 | POP1; |
| 2663 | res = emit_call ("Fadd1", comp.lisp_obj_type, 1, args); | 2663 | res = emit_call ("Fadd1", comp.lisp_obj_type, 1, args); |
| @@ -2736,11 +2736,9 @@ compile_f (const char *lisp_f_name, const char *c_f_name, | |||
| 2736 | basic_block_t *bb_orig = comp.block; | 2736 | basic_block_t *bb_orig = comp.block; |
| 2737 | 2737 | ||
| 2738 | comp.block = negate_inline_block; | 2738 | comp.block = negate_inline_block; |
| 2739 | gcc_jit_block_add_assignment (negate_inline_block->gcc_bb, | 2739 | emit_assign_to_stack_slot (negate_inline_block, |
| 2740 | NULL, | 2740 | &TOS, |
| 2741 | TOS.gcc_lval, | 2741 | emit_make_fixnum (negate_inline_res)); |
| 2742 | emit_make_fixnum (negate_inline_res)); | ||
| 2743 | |||
| 2744 | comp.block = negate_fcall_block; | 2742 | comp.block = negate_fcall_block; |
| 2745 | EMIT_CALL_N_REF ("Fminus", 1); | 2743 | EMIT_CALL_N_REF ("Fminus", 1); |
| 2746 | 2744 | ||
| @@ -3113,19 +3111,13 @@ compile_f (const char *lisp_f_name, const char *c_f_name, | |||
| 3113 | op = FETCH; | 3111 | op = FETCH; |
| 3114 | POP1; | 3112 | POP1; |
| 3115 | if (op > 0) | 3113 | if (op > 0) |
| 3116 | gcc_jit_block_add_assignment (comp.block->gcc_bb, | 3114 | emit_assign_to_stack_slot (comp.block, stack - op, args[0]); |
| 3117 | NULL, | ||
| 3118 | (*(stack - op)).gcc_lval, | ||
| 3119 | args[0]); | ||
| 3120 | break; | 3115 | break; |
| 3121 | 3116 | ||
| 3122 | CASE (Bstack_set2); | 3117 | CASE (Bstack_set2); |
| 3123 | op = FETCH2; | 3118 | op = FETCH2; |
| 3124 | POP1; | 3119 | POP1; |
| 3125 | gcc_jit_block_add_assignment (comp.block->gcc_bb, | 3120 | emit_assign_to_stack_slot (comp.block, stack - op, args[0]); |
| 3126 | NULL, | ||
| 3127 | (*(stack - op)).gcc_lval, | ||
| 3128 | args[0]); | ||
| 3129 | break; | 3121 | break; |
| 3130 | 3122 | ||
| 3131 | CASE (BdiscardN); | 3123 | CASE (BdiscardN); |
| @@ -3134,10 +3126,7 @@ compile_f (const char *lisp_f_name, const char *c_f_name, | |||
| 3134 | { | 3126 | { |
| 3135 | op &= 0x7F; | 3127 | op &= 0x7F; |
| 3136 | POP1; | 3128 | POP1; |
| 3137 | gcc_jit_block_add_assignment (comp.block->gcc_bb, | 3129 | emit_assign_to_stack_slot (comp.block, stack - op - 1, args[0]); |
| 3138 | NULL, | ||
| 3139 | (*(stack - op - 1)).gcc_lval, | ||
| 3140 | args[0]); | ||
| 3141 | } | 3130 | } |
| 3142 | 3131 | ||
| 3143 | DISCARD (op); | 3132 | DISCARD (op); |