diff options
| author | Andrea Corallo | 2020-07-12 11:11:41 +0200 |
|---|---|---|
| committer | Andrea Corallo | 2020-07-13 14:34:45 +0200 |
| commit | 527b697b2a1f57cf47ac74a28b7f89c91dddb1ab (patch) | |
| tree | 5b6946ffced1d200c783195a73eaaec570c5f63b /src | |
| parent | c389feede5f1138b23e43edb23564e6ef14d4170 (diff) | |
| download | emacs-527b697b2a1f57cf47ac74a28b7f89c91dddb1ab.tar.gz emacs-527b697b2a1f57cf47ac74a28b7f89c91dddb1ab.zip | |
* Rework frame allocation strategy
All frame slots are now simple automatic variables given the array
allocation and fill is done in 'emit_limple_call_ref'.
* src/comp.c (comp_t): Remove 'f_frame' 'arrays' slots, add
'frame'.
(emit_mvar_lval): Simplify to make use of 'comp.frame'.
(compile_function): Clean-up and add comp.frame initialization.
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp.c | 70 |
1 files changed, 9 insertions, 61 deletions
diff --git a/src/comp.c b/src/comp.c index 15c223c5641..8f7a48443cf 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -537,10 +537,9 @@ typedef struct { | |||
| 537 | gcc_jit_function *func; /* Current function being compiled. */ | 537 | gcc_jit_function *func; /* Current function being compiled. */ |
| 538 | bool func_has_non_local; /* From comp-func has-non-local slot. */ | 538 | bool func_has_non_local; /* From comp-func has-non-local slot. */ |
| 539 | EMACS_INT func_speed; /* From comp-func speed slot. */ | 539 | EMACS_INT func_speed; /* From comp-func speed slot. */ |
| 540 | gcc_jit_lvalue **f_frame; /* "Floating" frame for the current function. */ | ||
| 541 | gcc_jit_block *block; /* Current basic block being compiled. */ | 540 | gcc_jit_block *block; /* Current basic block being compiled. */ |
| 542 | gcc_jit_lvalue *scratch; /* Used as scratch slot for some code sequence (switch). */ | 541 | gcc_jit_lvalue *scratch; /* Used as scratch slot for some code sequence (switch). */ |
| 543 | gcc_jit_lvalue ***arrays; /* Array index -> gcc_jit_lvalue **. */ | 542 | gcc_jit_lvalue **frame; /* Frame slot n -> gcc_jit_lvalue *. */ |
| 544 | gcc_jit_rvalue *zero; | 543 | gcc_jit_rvalue *zero; |
| 545 | gcc_jit_rvalue *one; | 544 | gcc_jit_rvalue *one; |
| 546 | gcc_jit_rvalue *inttypebits; | 545 | gcc_jit_rvalue *inttypebits; |
| @@ -734,17 +733,7 @@ emit_mvar_lval (Lisp_Object mvar) | |||
| 734 | return comp.scratch; | 733 | return comp.scratch; |
| 735 | } | 734 | } |
| 736 | 735 | ||
| 737 | EMACS_INT arr_idx = XFIXNUM (CALL1I (comp-mvar-array-idx, mvar)); | 736 | return comp.frame[XFIXNUM (mvar_slot)]; |
| 738 | EMACS_INT slot_n = XFIXNUM (mvar_slot); | ||
| 739 | if (comp.func_has_non_local || (comp.func_speed < 2)) | ||
| 740 | return comp.arrays[arr_idx][slot_n]; | ||
| 741 | else | ||
| 742 | { | ||
| 743 | if (arr_idx) | ||
| 744 | return comp.arrays[arr_idx][slot_n]; | ||
| 745 | else | ||
| 746 | return comp.f_frame[slot_n]; | ||
| 747 | } | ||
| 748 | } | 737 | } |
| 749 | 738 | ||
| 750 | static void | 739 | static void |
| @@ -3767,54 +3756,13 @@ compile_function (Lisp_Object func) | |||
| 3767 | comp.func_has_non_local = !NILP (CALL1I (comp-func-has-non-local, func)); | 3756 | comp.func_has_non_local = !NILP (CALL1I (comp-func-has-non-local, func)); |
| 3768 | comp.func_speed = XFIXNUM (CALL1I (comp-func-speed, func)); | 3757 | comp.func_speed = XFIXNUM (CALL1I (comp-func-speed, func)); |
| 3769 | 3758 | ||
| 3770 | struct Lisp_Hash_Table *array_h = | 3759 | comp.frame = SAFE_ALLOCA (frame_size * sizeof (*comp.frame)); |
| 3771 | XHASH_TABLE (CALL1I (comp-func-array-h, func)); | 3760 | for (ptrdiff_t i = 0; i < frame_size; ++i) |
| 3772 | comp.arrays = SAFE_ALLOCA (array_h->count * sizeof (*comp.arrays)); | 3761 | comp.frame[i] = |
| 3773 | for (ptrdiff_t i = 0; i < array_h->count; i++) | 3762 | gcc_jit_function_new_local (comp.func, |
| 3774 | { | 3763 | NULL, |
| 3775 | EMACS_INT array_len = XFIXNUM (HASH_VALUE (array_h, i)); | 3764 | comp.lisp_obj_type, |
| 3776 | comp.arrays[i] = SAFE_ALLOCA (array_len * sizeof (**comp.arrays)); | 3765 | format_string ("slot_%td", i)); |
| 3777 | |||
| 3778 | gcc_jit_lvalue *arr = | ||
| 3779 | gcc_jit_function_new_local ( | ||
| 3780 | comp.func, | ||
| 3781 | NULL, | ||
| 3782 | gcc_jit_context_new_array_type (comp.ctxt, | ||
| 3783 | NULL, | ||
| 3784 | comp.lisp_obj_type, | ||
| 3785 | array_len), | ||
| 3786 | format_string ("arr_%td", i)); | ||
| 3787 | |||
| 3788 | for (ptrdiff_t j = 0; j < array_len; j++) | ||
| 3789 | comp.arrays[i][j] = | ||
| 3790 | gcc_jit_context_new_array_access ( | ||
| 3791 | comp.ctxt, | ||
| 3792 | NULL, | ||
| 3793 | gcc_jit_lvalue_as_rvalue (arr), | ||
| 3794 | gcc_jit_context_new_rvalue_from_int (comp.ctxt, | ||
| 3795 | comp.int_type, | ||
| 3796 | j)); | ||
| 3797 | } | ||
| 3798 | |||
| 3799 | /* | ||
| 3800 | The floating frame is a copy of the normal frame that can be used to store | ||
| 3801 | locals if the are not going to be used in a nargs call. | ||
| 3802 | This has two advantages: | ||
| 3803 | - Enable gcc for better reordering (frame array is clobbered every time is | ||
| 3804 | passed as parameter being involved into an nargs function call). | ||
| 3805 | - Allow gcc to trigger other optimizations that are prevented by memory | ||
| 3806 | referencing. | ||
| 3807 | */ | ||
| 3808 | if (comp.func_speed >= 2) | ||
| 3809 | { | ||
| 3810 | comp.f_frame = SAFE_ALLOCA (frame_size * sizeof (*comp.f_frame)); | ||
| 3811 | for (ptrdiff_t i = 0; i < frame_size; ++i) | ||
| 3812 | comp.f_frame[i] = | ||
| 3813 | gcc_jit_function_new_local (comp.func, | ||
| 3814 | NULL, | ||
| 3815 | comp.lisp_obj_type, | ||
| 3816 | format_string ("local%td", i)); | ||
| 3817 | } | ||
| 3818 | 3766 | ||
| 3819 | comp.scratch = NULL; | 3767 | comp.scratch = NULL; |
| 3820 | 3768 | ||