1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-02 04:40:29 +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

@ -95,7 +95,7 @@ jit_get_cpu(void)
void
_jit_init(jit_state_t *_jit)
{
_jit->reglen = jit_size(_rvs) - 1;
_jitc->reglen = jit_size(_rvs) - 1;
}
void
@ -103,53 +103,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;
/* float 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
@ -157,11 +157,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
@ -218,22 +218,22 @@ _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 *
_jit_arg(jit_state_t *_jit)
{
jit_int32_t offset;
assert(_jit->function);
if (_jit->function->self.argi < 6)
offset = _jit->function->self.argi++;
assert(_jitc->function);
if (_jitc->function->self.argi < 6)
offset = _jitc->function->self.argi++;
else {
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));
}
@ -248,12 +248,12 @@ jit_node_t *
_jit_arg_f(jit_state_t *_jit)
{
jit_int32_t offset;
assert(_jit->function);
if (_jit->function->self.argi < 6)
offset = _jit->function->self.argi++;
assert(_jitc->function);
if (_jitc->function->self.argi < 6)
offset = _jitc->function->self.argi++;
else {
offset = _jit->function->self.size;
_jit->function->self.size += sizeof(jit_float32_t);
offset = _jitc->function->self.size;
_jitc->function->self.size += sizeof(jit_float32_t);
}
return (jit_new_node_w(jit_code_arg_f, offset));
}
@ -268,18 +268,18 @@ jit_node_t *
_jit_arg_d(jit_state_t *_jit)
{
jit_int32_t offset;
assert(_jit->function);
if (_jit->function->self.argi < 5) {
offset = _jit->function->self.argi;
_jit->function->self.argi += 2;
assert(_jitc->function);
if (_jitc->function->self.argi < 5) {
offset = _jitc->function->self.argi;
_jitc->function->self.argi += 2;
}
else if (_jit->function->self.argi < 6) {
offset = _jit->function->self.argi++;
_jit->function->self.size += sizeof(jit_float32_t);
else if (_jitc->function->self.argi < 6) {
offset = _jitc->function->self.argi++;
_jitc->function->self.size += sizeof(jit_float32_t);
}
else {
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));
}
@ -350,7 +350,7 @@ _jit_getarg_i(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
void
_jit_getarg_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
{
assert(_jit->function);
assert(_jitc->function);
if (v->u.w < 6) {
jit_stxi(-4, JIT_FP, _I0 + v->u.w);
jit_ldxi_f(u, JIT_FP, -4);
@ -362,7 +362,7 @@ _jit_getarg_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
void
_jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
{
assert(_jit->function);
assert(_jitc->function);
if (v->u.w < 5) {
jit_stxi(-8, JIT_FP, _I0 + v->u.w);
jit_stxi(-4, JIT_FP, _I0 + v->u.w + 1);
@ -380,13 +380,13 @@ _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)
{
if (_jit->function->call.argi < 6) {
jit_movr(_O0 + _jit->function->call.argi, u);
++_jit->function->call.argi;
if (_jitc->function->call.argi < 6) {
jit_movr(_O0 + _jitc->function->call.argi, u);
++_jitc->function->call.argi;
}
else {
jit_stxi(_jit->function->call.size + stack_framesize, JIT_SP, u);
_jit->function->call.size += sizeof(jit_word_t);
jit_stxi(_jitc->function->call.size + stack_framesize, JIT_SP, u);
_jitc->function->call.size += sizeof(jit_word_t);
}
}
@ -394,30 +394,30 @@ void
_jit_pushargi(jit_state_t *_jit, jit_word_t u)
{
jit_int32_t regno;
if (_jit->function->call.argi < 6) {
jit_movi(_O0 + _jit->function->call.argi, u);
++_jit->function->call.argi;
if (_jitc->function->call.argi < 6) {
jit_movi(_O0 + _jitc->function->call.argi, u);
++_jitc->function->call.argi;
}
else {
regno = jit_get_reg(jit_class_gpr);
jit_movi(regno, u);
jit_stxi(_jit->function->call.size + stack_framesize, JIT_SP, regno);
jit_stxi(_jitc->function->call.size + stack_framesize, JIT_SP, regno);
jit_unget_reg(regno);
_jit->function->call.size += sizeof(jit_word_t);
_jitc->function->call.size += sizeof(jit_word_t);
}
}
void
_jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
{
if (_jit->function->call.argi < 6) {
if (_jitc->function->call.argi < 6) {
jit_stxi_f(-4, JIT_FP, u);
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -4);
++_jit->function->call.argi;
jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -4);
++_jitc->function->call.argi;
}
else {
jit_stxi_f(_jit->function->call.size + stack_framesize, JIT_SP, u);
_jit->function->call.size += sizeof(jit_float32_t);
jit_stxi_f(_jitc->function->call.size + stack_framesize, JIT_SP, u);
_jitc->function->call.size += sizeof(jit_float32_t);
}
}
@ -427,14 +427,14 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
jit_int32_t regno;
regno = jit_get_reg(jit_class_fpr);
jit_movi_f(regno, u);
if (_jit->function->call.argi < 6) {
if (_jitc->function->call.argi < 6) {
jit_stxi_f(-4, JIT_FP, regno);
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -4);
++_jit->function->call.argi;
jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -4);
++_jitc->function->call.argi;
}
else {
jit_stxi_f(_jit->function->call.size + stack_framesize, JIT_SP, regno);
_jit->function->call.size += sizeof(jit_float32_t);
jit_stxi_f(_jitc->function->call.size + stack_framesize, JIT_SP, regno);
_jitc->function->call.size += sizeof(jit_float32_t);
}
jit_unget_reg(regno);
}
@ -442,22 +442,22 @@ _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
void
_jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
{
if (_jit->function->call.argi < 5) {
if (_jitc->function->call.argi < 5) {
jit_stxi_d(-8, JIT_FP, u);
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -8);
jit_ldxi(_O0 + _jit->function->call.argi + 1, JIT_FP, -4);
_jit->function->call.argi += 2;
jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -8);
jit_ldxi(_O0 + _jitc->function->call.argi + 1, JIT_FP, -4);
_jitc->function->call.argi += 2;
}
else if (_jit->function->call.argi < 6) {
else if (_jitc->function->call.argi < 6) {
jit_stxi_f(-8, JIT_FP, u);
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -8);
++_jit->function->call.argi;
jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -8);
++_jitc->function->call.argi;
jit_stxi_f(stack_framesize, JIT_SP, u + 1);
_jit->function->call.size += sizeof(jit_float32_t);
_jitc->function->call.size += sizeof(jit_float32_t);
}
else {
jit_stxi_d(_jit->function->call.size + stack_framesize, JIT_SP, u);
_jit->function->call.size += sizeof(jit_float64_t);
jit_stxi_d(_jitc->function->call.size + stack_framesize, JIT_SP, u);
_jitc->function->call.size += sizeof(jit_float64_t);
}
}
@ -467,22 +467,22 @@ _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
jit_int32_t regno;
regno = jit_get_reg(jit_class_fpr);
jit_movi_d(regno, u);
if (_jit->function->call.argi < 5) {
if (_jitc->function->call.argi < 5) {
jit_stxi_d(-8, JIT_FP, regno);
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -8);
jit_ldxi(_O0 + _jit->function->call.argi + 1, JIT_FP, -4);
_jit->function->call.argi += 2;
jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -8);
jit_ldxi(_O0 + _jitc->function->call.argi + 1, JIT_FP, -4);
_jitc->function->call.argi += 2;
}
else if (_jit->function->call.argi < 6) {
else if (_jitc->function->call.argi < 6) {
jit_stxi_f(-8, JIT_FP, regno);
jit_ldxi(_O0 + _jit->function->call.argi, JIT_FP, -8);
++_jit->function->call.argi;
jit_ldxi(_O0 + _jitc->function->call.argi, JIT_FP, -8);
++_jitc->function->call.argi;
jit_stxi_f(stack_framesize, JIT_SP, regno + 1);
_jit->function->call.size += sizeof(jit_float32_t);
_jitc->function->call.size += sizeof(jit_float32_t);
}
else {
jit_stxi_d(_jit->function->call.size + stack_framesize, JIT_SP, regno);
_jit->function->call.size += sizeof(jit_float64_t);
jit_stxi_d(_jitc->function->call.size + stack_framesize, JIT_SP, regno);
_jitc->function->call.size += sizeof(jit_float64_t);
}
jit_unget_reg(regno);
}
@ -508,15 +508,15 @@ _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
{
jit_node_t *call;
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;
call = jit_callr(r0);
call->v.w = _jit->function->self.argi;
call->w.w = _jit->function->self.argf;
_jit->function->call.argi = _jit->function->call.argf =
_jit->function->call.size = 0;
_jit->prepare = 0;
call->v.w = _jitc->function->self.argi;
call->w.w = _jitc->function->self.argf;
_jitc->function->call.argi = _jitc->function->call.argf =
_jitc->function->call.size = 0;
_jitc->prepare = 0;
}
jit_node_t *
@ -524,15 +524,15 @@ _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
{
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;
node = jit_calli(i0);
node->v.w = _jit->function->call.argi;
node->w.w = _jit->function->call.argf;
_jit->function->call.argi = _jit->function->call.argf =
_jit->function->call.size = 0;
_jit->prepare = 0;
node->v.w = _jitc->function->call.argi;
node->w.w = _jitc->function->call.argf;
_jitc->function->call.argi = _jitc->function->call.argf =
_jitc->function->call.size = 0;
_jitc->prepare = 0;
return (node);
}
@ -595,7 +595,7 @@ _emit_code(jit_state_t *_jit)
jit_int32_t patch_offset;
} undo;
_jit->function = NULL;
_jitc->function = NULL;
jit_reglive_setup();
@ -692,8 +692,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);
@ -1059,17 +1059,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 ||
@ -1078,14 +1078,14 @@ _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;
}
/* remember label is defined */
node->flag |= jit_flag_patch;
node->u.w = _jit->pc.w;
epilog(node);
_jit->function = NULL;
_jitc->function = NULL;
break;
case jit_code_live:
case jit_code_arg:
@ -1112,10 +1112,10 @@ _emit_code(jit_state_t *_jit)
#undef case_rw
#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(_jit->patches.ptr[offset].inst, word);
patch_at(_jitc->patches.ptr[offset].inst, word);
}
return (_jit->code.ptr);
@ -1161,15 +1161,15 @@ _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;
}