1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-04 05:50:26 +02:00

Rework to better describe what is used only during jit generation.

* include/lightning/jit_private.h, lib/jit_arm-cpu.c,
	lib/jit_arm.c, lib/jit_disasm.c, lib/jit_mips-cpu.c,
	lib/jit_mips.c, lib/jit_note.c, lib/jit_ppc-cpu.c,
	lib/jit_ppc.c, lib/jit_print.c, lib/jit_sparc-cpu.c,
	lib/jit_sparc.c, lib/jit_x86-cpu.c, lib/jit_x86.c,
	lib/lightning.c: Add an extra structure for data storage
	during jit generation, and release it after generating
	jit, to reduce a bit memory usage, and also to make it
	easier to understand what data is available during
	jit runtime.
This commit is contained in:
pcpa 2013-03-06 16:49:26 -03:00
parent f39eee6694
commit 9afca85921
16 changed files with 1328 additions and 1299 deletions

View file

@ -273,11 +273,11 @@ _jit_init(jit_state_t *_jit)
static jit_bool_t first = 1;
#endif
_jit->reglen = jit_size(_rvs) - 1;
_jitc->reglen = jit_size(_rvs) - 1;
#if __WORDSIZE == 32
if (first) {
if (!jit_cpu.sse2) {
for (regno = _jit->reglen; regno >= 0; regno--) {
for (regno = _jitc->reglen; regno >= 0; regno--) {
if (_rvs[regno].spec & jit_class_xpr)
_rvs[regno].spec = 0;
}
@ -292,53 +292,53 @@ _jit_prolog(jit_state_t *_jit)
{
jit_int32_t offset;
if (_jit->function)
if (_jitc->function)
jit_epilog();
assert(jit_regset_cmp_ui(_jit->regarg, 0) == 0);
jit_regset_set_ui(_jit->regsav, 0);
offset = _jit->functions.offset;
if (offset >= _jit->functions.length) {
_jit->functions.ptr = realloc(_jit->functions.ptr,
(_jit->functions.length + 16) *
assert(jit_regset_cmp_ui(_jitc->regarg, 0) == 0);
jit_regset_set_ui(_jitc->regsav, 0);
offset = _jitc->functions.offset;
if (offset >= _jitc->functions.length) {
_jitc->functions.ptr = realloc(_jitc->functions.ptr,
(_jitc->functions.length + 16) *
sizeof(jit_function_t));
memset(_jit->functions.ptr + _jit->functions.length, 0,
memset(_jitc->functions.ptr + _jitc->functions.length, 0,
16 * sizeof(jit_function_t));
_jit->functions.length += 16;
_jitc->functions.length += 16;
}
_jit->function = _jit->functions.ptr + _jit->functions.offset++;
_jit->function->self.size = stack_framesize;
_jit->function->self.argi = _jit->function->self.argf =
_jit->function->self.aoff = _jit->function->self.alen = 0;
_jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
_jitc->function->self.size = stack_framesize;
_jitc->function->self.argi = _jitc->function->self.argf =
_jitc->function->self.aoff = _jitc->function->self.alen = 0;
/* sse/x87 conversion */
_jit->function->self.aoff = -8;
_jit->function->self.call = jit_call_default;
_jit->function->regoff = calloc(_jit->reglen, sizeof(jit_int32_t));
_jitc->function->self.aoff = -8;
_jitc->function->self.call = jit_call_default;
_jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
_jit->function->prolog = jit_new_node_no_link(jit_code_prolog);
jit_link(_jit->function->prolog);
_jit->function->prolog->w.w = offset;
_jit->function->epilog = jit_new_node_no_link(jit_code_epilog);
_jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
jit_link(_jitc->function->prolog);
_jitc->function->prolog->w.w = offset;
_jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
/* u: label value
* v: offset in blocks vector
* w: offset in functions vector
*/
_jit->function->epilog->w.w = offset;
_jitc->function->epilog->w.w = offset;
jit_regset_new(_jit->function->regset);
jit_regset_new(_jitc->function->regset);
}
jit_int32_t
_jit_allocai(jit_state_t *_jit, jit_int32_t length)
{
assert(_jit->function);
assert(_jitc->function);
switch (length) {
case 0: case 1: break;
case 2: _jit->function->self.aoff &= -2; break;
case 3: case 4: _jit->function->self.aoff &= -4; break;
default: _jit->function->self.aoff &= -8; break;
case 2: _jitc->function->self.aoff &= -2; break;
case 3: case 4: _jitc->function->self.aoff &= -4; break;
default: _jitc->function->self.aoff &= -8; break;
}
_jit->function->self.aoff -= length;
return (_jit->function->self.aoff);
_jitc->function->self.aoff -= length;
return (_jitc->function->self.aoff);
}
void
@ -346,11 +346,11 @@ _jit_ret(jit_state_t *_jit)
{
jit_node_t *instr;
assert(_jit->function);
assert(_jitc->function);
/* jump to epilog */
instr = jit_jmpi();
jit_patch_at(instr, _jit->function->epilog);
jit_patch_at(instr, _jitc->function->epilog);
}
void
@ -409,10 +409,10 @@ _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
void
_jit_epilog(jit_state_t *_jit)
{
assert(_jit->function);
assert(_jit->function->epilog->next == NULL);
jit_link(_jit->function->epilog);
_jit->function = NULL;
assert(_jitc->function);
assert(_jitc->function->epilog->next == NULL);
jit_link(_jitc->function->epilog);
_jitc->function = NULL;
}
jit_node_t *
@ -420,15 +420,15 @@ _jit_arg(jit_state_t *_jit)
{
jit_int32_t offset;
assert(_jit->function);
assert(_jitc->function);
#if __WORDSIZE == 64
if (_jit->function->self.argi < 6)
offset = _jit->function->self.argi++;
if (_jitc->function->self.argi < 6)
offset = _jitc->function->self.argi++;
else
#endif
{
offset = _jit->function->self.size;
_jit->function->self.size += sizeof(jit_word_t);
offset = _jitc->function->self.size;
_jitc->function->self.size += sizeof(jit_word_t);
}
return (jit_new_node_w(jit_code_arg, offset));
}
@ -448,18 +448,18 @@ _jit_arg_f(jit_state_t *_jit)
{
jit_int32_t offset;
assert(_jit->function);
assert(_jitc->function);
#if __WORDSIZE == 64
if (_jit->function->self.argf < 8)
offset = _jit->function->self.argf++;
if (_jitc->function->self.argf < 8)
offset = _jitc->function->self.argf++;
else
#endif
{
offset = _jit->function->self.size;
offset = _jitc->function->self.size;
#if __WORDSIZE == 32
_jit->function->self.size += sizeof(jit_float32_t);
_jitc->function->self.size += sizeof(jit_float32_t);
#else
_jit->function->self.size += sizeof(jit_float64_t);
_jitc->function->self.size += sizeof(jit_float64_t);
#endif
}
return (jit_new_node_w(jit_code_arg_f, offset));
@ -480,15 +480,15 @@ _jit_arg_d(jit_state_t *_jit)
{
jit_int32_t offset;
assert(_jit->function);
assert(_jitc->function);
#if __WORDSIZE == 64
if (_jit->function->self.argf < 8)
offset = _jit->function->self.argf++;
if (_jitc->function->self.argf < 8)
offset = _jitc->function->self.argf++;
else
#endif
{
offset = _jit->function->self.size;
_jit->function->self.size += sizeof(jit_float64_t);
offset = _jitc->function->self.size;
_jitc->function->self.size += sizeof(jit_float64_t);
}
return (jit_new_node_w(jit_code_arg_d, offset));
}
@ -599,17 +599,17 @@ _jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
void
_jit_pushargr(jit_state_t *_jit, jit_int32_t u)
{
assert(_jit->function);
assert(_jitc->function);
#if __WORDSIZE == 64
if (_jit->function->call.argi < 6) {
jit_movr(_RDI - _jit->function->call.argi, u);
++_jit->function->call.argi;
if (_jitc->function->call.argi < 6) {
jit_movr(_RDI - _jitc->function->call.argi, u);
++_jitc->function->call.argi;
}
else
#endif
{
jit_stxi(_jit->function->call.size, _RSP, u);
_jit->function->call.size += sizeof(jit_word_t);
jit_stxi(_jitc->function->call.size, _RSP, u);
_jitc->function->call.size += sizeof(jit_word_t);
}
}
@ -618,19 +618,19 @@ _jit_pushargi(jit_state_t *_jit, jit_word_t u)
{
jit_int32_t regno;
assert(_jit->function);
assert(_jitc->function);
#if __WORDSIZE == 64
if (_jit->function->call.argi < 6) {
jit_movi(_RDI - _jit->function->call.argi, u);
++_jit->function->call.argi;
if (_jitc->function->call.argi < 6) {
jit_movi(_RDI - _jitc->function->call.argi, u);
++_jitc->function->call.argi;
}
else
#endif
{
regno = jit_get_reg(jit_class_gpr);
jit_movi(regno, u);
jit_stxi(_jit->function->call.size, _RSP, regno);
_jit->function->call.size += sizeof(jit_word_t);
jit_stxi(_jitc->function->call.size, _RSP, regno);
_jitc->function->call.size += sizeof(jit_word_t);
jit_unget_reg(regno);
}
}
@ -638,17 +638,17 @@ _jit_pushargi(jit_state_t *_jit, jit_word_t u)
void
_jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
{
assert(_jit->function);
assert(_jitc->function);
#if __WORDSIZE == 64
if (_jit->function->call.argf < 8) {
jit_movr_f(_XMM0 - _jit->function->call.argf, u);
++_jit->function->call.argf;
if (_jitc->function->call.argf < 8) {
jit_movr_f(_XMM0 - _jitc->function->call.argf, u);
++_jitc->function->call.argf;
}
else
#endif
{
jit_stxi_f(_jit->function->call.size, _RSP, u);
_jit->function->call.size += sizeof(jit_word_t);
jit_stxi_f(_jitc->function->call.size, _RSP, u);
_jitc->function->call.size += sizeof(jit_word_t);
}
}
@ -657,19 +657,19 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
{
jit_int32_t regno;
assert(_jit->function);
assert(_jitc->function);
#if __WORDSIZE == 64
if (_jit->function->call.argf < 8) {
jit_movi_f(_XMM0 - _jit->function->call.argf, u);
++_jit->function->call.argf;
if (_jitc->function->call.argf < 8) {
jit_movi_f(_XMM0 - _jitc->function->call.argf, u);
++_jitc->function->call.argf;
}
else
#endif
{
regno = jit_get_reg(jit_class_fpr);
jit_movi_f(regno, u);
jit_stxi_f(_jit->function->call.size, _RSP, regno);
_jit->function->call.size += sizeof(jit_word_t);
jit_stxi_f(_jitc->function->call.size, _RSP, regno);
_jitc->function->call.size += sizeof(jit_word_t);
jit_unget_reg(regno);
}
}
@ -677,17 +677,17 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
void
_jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
{
assert(_jit->function);
assert(_jitc->function);
#if __WORDSIZE == 64
if (_jit->function->call.argf < 8) {
jit_movr_d(_XMM0 - _jit->function->call.argf, u);
++_jit->function->call.argf;
if (_jitc->function->call.argf < 8) {
jit_movr_d(_XMM0 - _jitc->function->call.argf, u);
++_jitc->function->call.argf;
}
else
#endif
{
jit_stxi_d(_jit->function->call.size, _RSP, u);
_jit->function->call.size += sizeof(jit_float64_t);
jit_stxi_d(_jitc->function->call.size, _RSP, u);
_jitc->function->call.size += sizeof(jit_float64_t);
}
}
@ -696,19 +696,19 @@ _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
{
jit_int32_t regno;
assert(_jit->function);
assert(_jitc->function);
#if __WORDSIZE == 64
if (_jit->function->call.argf < 8) {
jit_movi_d(_XMM0 - _jit->function->call.argf, u);
++_jit->function->call.argf;
if (_jitc->function->call.argf < 8) {
jit_movi_d(_XMM0 - _jitc->function->call.argf, u);
++_jitc->function->call.argf;
}
else
#endif
{
regno = jit_get_reg(jit_class_fpr);
jit_movi_d(regno, u);
jit_stxi_d(_jit->function->call.size, _RSP, regno);
_jit->function->call.size += sizeof(jit_float64_t);
jit_stxi_d(_jitc->function->call.size, _RSP, regno);
_jitc->function->call.size += sizeof(jit_float64_t);
jit_unget_reg(regno);
}
}
@ -743,17 +743,17 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
jit_node_t *call;
reg = r0;
assert(_jit->function);
if (_jit->function->self.alen < _jit->function->call.size)
_jit->function->self.alen = _jit->function->call.size;
assert(_jitc->function);
if (_jitc->function->self.alen < _jitc->function->call.size)
_jitc->function->self.alen = _jitc->function->call.size;
#if __WORDSIZE == 64
if (_jit->function->call.call & jit_call_varargs) {
if (_jitc->function->call.call & jit_call_varargs) {
if (jit_regno(reg) == _RAX) {
reg = jit_get_reg(jit_class_gpr);
jit_movr(reg, _RAX);
}
if (_jit->function->call.argf)
jit_movi(_RAX, _jit->function->call.argf);
if (_jitc->function->call.argf)
jit_movi(_RAX, _jitc->function->call.argf);
else
jit_movi(_RAX, 0);
if (reg != r0)
@ -761,11 +761,11 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
}
#endif
call = jit_callr(reg);
call->v.w = _jit->function->call.argi;
call->w.w = _jit->function->call.argf;
_jit->function->call.argi = _jit->function->call.argf =
_jit->function->call.size = 0;
_jit->prepare = 0;
call->v.w = _jitc->function->call.argi;
call->w.w = _jitc->function->call.argf;
_jitc->function->call.argi = _jitc->function->call.argf =
_jitc->function->call.size = 0;
_jitc->prepare = 0;
}
jit_node_t *
@ -776,30 +776,30 @@ _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
#endif
jit_node_t *node;
assert(_jit->function);
if (_jit->function->self.alen < _jit->function->call.size)
_jit->function->self.alen = _jit->function->call.size;
assert(_jitc->function);
if (_jitc->function->self.alen < _jitc->function->call.size)
_jitc->function->self.alen = _jitc->function->call.size;
#if __WORDSIZE == 64
/* FIXME preventing %rax allocation is good enough, but for consistency
* it should automatically detect %rax is dead, in case it has run out
* registers, and not save/restore it, what would be wrong if using the
* the return value, otherwise, just a needless noop */
/* >> prevent %rax from being allocated as the function pointer */
jit_regset_setbit(_jit->regarg, _RAX);
jit_regset_setbit(_jitc->regarg, _RAX);
reg = jit_get_reg(jit_class_gpr);
node = jit_movi(reg, (jit_word_t)i0);
jit_finishr(reg);
jit_unget_reg(reg);
/* << prevent %rax from being allocated as the function pointer */
jit_regset_clrbit(_jit->regarg, _RAX);
jit_regset_clrbit(_jitc->regarg, _RAX);
#else
node = jit_calli(i0);
node->v.w = _jit->function->call.argi;
node->w.w = _jit->function->call.argf;
node->v.w = _jitc->function->call.argi;
node->w.w = _jitc->function->call.argf;
#endif
_jit->function->call.argi = _jit->function->call.argf =
_jit->function->call.size = 0;
_jit->prepare = 0;
_jitc->function->call.argi = _jitc->function->call.argf =
_jitc->function->call.size = 0;
_jitc->prepare = 0;
return (node);
}
@ -889,7 +889,7 @@ _emit_code(jit_state_t *_jit)
jit_int32_t patch_offset;
} undo;
_jit->function = NULL;
_jitc->function = NULL;
jit_reglive_setup();
@ -1125,8 +1125,8 @@ _emit_code(jit_state_t *_jit)
patch(word, node); \
} \
break
for (node = _jit->head; node; node = node->next) {
if (_jit->pc.uc >= _jit->code.end)
for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end)
return (NULL);
value = jit_classify(node->code);
@ -1558,17 +1558,17 @@ _emit_code(jit_state_t *_jit)
calli(node->u.w);
break;
case jit_code_prolog:
_jit->function = _jit->functions.ptr + node->w.w;
_jitc->function = _jitc->functions.ptr + node->w.w;
undo.node = node;
undo.word = _jit->pc.w;
undo.patch_offset = _jit->patches.offset;
undo.patch_offset = _jitc->patches.offset;
restart_function:
_jit->again = 0;
_jitc->again = 0;
prolog(node);
break;
case jit_code_epilog:
assert(_jit->function == _jit->functions.ptr + node->w.w);
if (_jit->again) {
assert(_jitc->function == _jitc->functions.ptr + node->w.w);
if (_jitc->again) {
for (temp = undo.node->next;
temp != node; temp = temp->next) {
if (temp->code == jit_code_label ||
@ -1577,7 +1577,7 @@ _emit_code(jit_state_t *_jit)
}
node = undo.node;
_jit->pc.w = undo.word;
_jit->patches.offset = undo.patch_offset;
_jitc->patches.offset = undo.patch_offset;
goto restart_function;
}
if (node->link &&
@ -1587,7 +1587,7 @@ _emit_code(jit_state_t *_jit)
node->flag |= jit_flag_patch;
node->u.w = _jit->pc.w;
epilog(node);
_jit->function = NULL;
_jitc->function = NULL;
break;
#if __WORDSIZE == 32
case jit_code_x86_retval_f:
@ -1637,10 +1637,10 @@ _emit_code(jit_state_t *_jit)
#undef case_fr
#undef case_rr
for (offset = 0; offset < _jit->patches.offset; offset++) {
node = _jit->patches.ptr[offset].node;
for (offset = 0; offset < _jitc->patches.offset; offset++) {
node = _jitc->patches.ptr[offset].node;
word = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w;
patch_at(node, _jit->patches.ptr[offset].inst, word);
patch_at(node, _jitc->patches.ptr[offset].inst, word);
}
return (_jit->code.ptr);
@ -1693,17 +1693,17 @@ _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
else
flag = node->u.n->flag;
assert(!(flag & jit_flag_patch));
if (_jit->patches.offset >= _jit->patches.length) {
_jit->patches.ptr = realloc(_jit->patches.ptr,
(_jit->patches.length + 1024) *
if (_jitc->patches.offset >= _jitc->patches.length) {
_jitc->patches.ptr = realloc(_jitc->patches.ptr,
(_jitc->patches.length + 1024) *
sizeof(jit_patch_t));
memset(_jit->patches.ptr + _jit->patches.length, 0,
memset(_jitc->patches.ptr + _jitc->patches.length, 0,
1024 * sizeof(jit_patch_t));
_jit->patches.length += 1024;
_jitc->patches.length += 1024;
}
_jit->patches.ptr[_jit->patches.offset].inst = instr;
_jit->patches.ptr[_jit->patches.offset].node = node;
++_jit->patches.offset;
_jitc->patches.ptr[_jitc->patches.offset].inst = instr;
_jitc->patches.ptr[_jitc->patches.offset].node = node;
++_jitc->patches.offset;
}
static void