Add code to calculate code buffer size based on devel time information. - lightning.git - Portable just-in-time compiler library

index : lightning.git
Portable just-in-time compiler library
summary refs log tree commit diff
path: root/lib/lightning.c
diff options
context:
space:
mode:
authorpcpa <paulo.cesar.pereira.de.andrade@gmail.com>2013年09月24日 03:31:54 -0300
committerpcpa <paulo.cesar.pereira.de.andrade@gmail.com>2013年09月24日 03:31:54 -0300
commitb768fab8b135a722a76dc26b2037d40cdbae9b35 (patch)
treefd86327fa4ec167586803276a5b0b88bd67e9031 /lib/lightning.c
parent95e3fbc8bc674a3d9ab745ae9d0a8ff630016fdf (diff)
downloadlightning-b768fab8b135a722a76dc26b2037d40cdbae9b35.tar.gz
Add code to calculate code buffer size based on devel time information.
* lib/jit_aarch64-sz.c, lib/jit_arm-sz.c, lib/jit_hppa-sz.c, lib/jit_ia64-sz.c, lib/jit_mips-sz.c, lib/jit_ppc-sz.c, lib/jit_s390x-sz.c, lib/jit_size.c, lib/jit_sparc-sz.c, lib/jit_x86-sz.c: New files implementing static tables with longest known instructions length generated to match a lightning instruction. These tables should make it easier to make it very unlikely to ever miscalculate, or by too much, the size of a code buffer. * lib/jit_size.c: New file that aids to either collect jit code size information, or use the information depending on build options. * size.c: New helper file that parses input for, and create an initial jit_$arch-sz.c file, that needs some minor edit for arches with multiple configurations. * configure.ac, Makefile.am: Add the new, devel mode only --enable-devel-get-jit-size configure option, that sets compile time flags to collect jit code size information, that will be used as input for the "noinst size program". * lib/jit_aarch64.c, lib/jit_arm.c, lib/jit_disasm.c, lib/jit_hppa.c, lib/jit_ia64.c, lib/jit_memory.c, lib/jit_mips.c, lib/jit_ppc.c, lib/jit_s390x.c, lib/jit_sparc.c, lib/jit_x86.c, lib/lightning.c: Minor changes for the --enable-devel-get-jit-size build mode, as well as the "production build mode" with jit code size information.
Diffstat (limited to 'lib/lightning.c')
-rw-r--r--lib/lightning.c 28
1 files changed, 23 insertions, 5 deletions
diff --git a/lib/lightning.c b/lib/lightning.c
index 817976c..e6c7f4b 100644
--- a/lib/lightning.c
+++ b/lib/lightning.c
@@ -180,12 +180,14 @@ init_jit(char *progname)
jit_progname = progname;
jit_get_cpu();
jit_init_debug();
+ jit_init_size();
}
void
finish_jit(void)
{
jit_finish_debug();
+ jit_finish_size();
}
jit_int32_t
@@ -1644,6 +1646,9 @@ _jit_reglive(jit_state_t *_jit, jit_node_t *node)
void
_jit_regarg_set(jit_state_t *_jit, jit_node_t *node, jit_int32_t value)
{
+#if GET_JIT_SIZE
+ jit_size_prepare();
+#endif
if (value & jit_cc_a0_reg) {
if (value & jit_cc_a0_rlh) {
jit_regset_setbit(&_jitc->regarg, jit_regno(node->u.q.l));
@@ -1661,6 +1666,9 @@ _jit_regarg_set(jit_state_t *_jit, jit_node_t *node, jit_int32_t value)
void
_jit_regarg_clr(jit_state_t *_jit, jit_node_t *node, jit_int32_t value)
{
+#if GET_JIT_SIZE
+ jit_size_collect(node);
+#endif
if (value & jit_cc_a0_reg) {
if (value & jit_cc_a0_rlh) {
jit_regset_clrbit(&_jitc->regarg, jit_regno(node->u.q.l));
@@ -1690,12 +1698,15 @@ _jit_emit(jit_state_t *_jit)
jit_epilog();
jit_optimize();
- /* Heuristic to guess code buffer size */
- _jitc->mult = 4;
-
_jitc->emit = 1;
+#if GET_JIT_SIZE
+ /* Heuristic to guess code buffer size */
+ _jitc->mult = 4;
_jit->code.length = _jitc->pool.length * 1024 * _jitc->mult;
+#else
+ _jit->code.length = jit_get_size();
+#endif
#if defined(__sgi)
mmap_fd = open("/dev/zero", O_RDWR);
@@ -1704,7 +1715,8 @@ _jit_emit(jit_state_t *_jit)
PROT_EXEC | PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, mmap_fd, 0);
assert(_jit->code.ptr != MAP_FAILED);
- _jitc->code.end = _jit->code.ptr + _jit->code.length - 64;
+ _jitc->code.end = _jit->code.ptr + _jit->code.length -
+ jit_get_max_instr();
_jit->pc.uc = _jit->code.ptr;
for (;;) {
@@ -1715,8 +1727,13 @@ _jit_emit(jit_state_t *_jit)
node->code == jit_code_epilog))
node->flag &= ~jit_flag_patch;
}
+#if GET_JIT_SIZE
++_jitc->mult;
length = _jitc->pool.length * 1024 * _jitc->mult;
+#else
+ /* Should only happen on very special cases */
+ length = _jit->code.length + 4096;
+#endif
#if !HAVE_MREMAP
munmap(_jit->code.ptr, _jit->code.length);
@@ -1738,7 +1755,8 @@ _jit_emit(jit_state_t *_jit)
assert(_jit->code.ptr != MAP_FAILED);
_jit->code.length = length;
- _jitc->code.end = _jit->code.ptr + _jit->code.length - 64;
+ _jitc->code.end = _jit->code.ptr + _jit->code.length -
+ jit_get_max_instr();
_jit->pc.uc = _jit->code.ptr;
_jitc->patches.offset = 0;
}
generated by cgit v1.2.3 (git 2.39.1) at 2025年10月01日 09:18:00 +0000

AltStyle によって変換されたページ (->オリジナル) /