lightning.git - Portable just-in-time compiler library

index : lightning.git
Portable just-in-time compiler library
summary refs log tree commit diff
diff options
context:
space:
mode:
authorpcpa <paulo.cesar.pereira.de.andrade@gmail.com>2023年02月06日 11:35:24 -0300
committerpcpa <paulo.cesar.pereira.de.andrade@gmail.com>2023年02月06日 11:35:24 -0300
commitcf22f8f7667cbb2907dd92f1352451c263947536 (patch)
tree715fa3b1ad3ffd950262558cd13064e30122ac60
parent7e2b2154a35e86d16364a4fda8f74123a264c689 (diff)
downloadlightning-cf22f8f7667cbb2907dd92f1352451c263947536.tar.gz
arm: Take advantage of the need_return field for jit functions
This is done only for jit functions that only call jit_functions. For now this is a hardcoded safe mode assumption that there might be issues if a jit function does not create a frame pointer and calls a C function. Note that there is also the possible case of passing a jit function pointer to be called from a C function. It is assumed that in this case it is safe to have a leaf or optimized function as done in the patch.
Diffstat
-rw-r--r--lib/jit_arm-cpu.c 18
-rw-r--r--lib/jit_arm.c 17
2 files changed, 29 insertions, 6 deletions
diff --git a/lib/jit_arm-cpu.c b/lib/jit_arm-cpu.c
index a9ccd17..3f40948 100644
--- a/lib/jit_arm-cpu.c
+++ b/lib/jit_arm-cpu.c
@@ -3920,6 +3920,18 @@ _prolog(jit_state_t *_jit, jit_node_t *node)
_jitc->function->stack = ((_jitc->function->self.alen -
/* align stack at 8 bytes */
_jitc->function->self.aoff) + 7) & -8;
+ /* If this jit_check_frame() succeeds, it actually is just a need_stack,
+ * usually for arguments, so, allocai was not called, but pusharg*
+ * was called increasing stack size, for negative access offsets.
+ * This can be optimized for one less prolog instruction, that is,
+ * do not create the frame pointer, and only add _jitc->function->stack
+ * to sp, and on epilog, instead of moving fp to sp, just add negative
+ * value of _jitc->function->stack. Since this condition requires a
+ * large function body for excess arguments to called function, keep
+ * things a bit simpler for now, as this is the only place need_stack
+ * would be useful. */
+ if (_jitc->function->stack)
+ jit_check_frame();
for (reg = mask = count = 0; reg < jit_size(iregs); reg++) {
if (jit_regset_tstbit(&_jitc->function->regset, iregs[reg])) {
@@ -3936,7 +3948,7 @@ _prolog(jit_state_t *_jit, jit_node_t *node)
}
}
}
- if (_jitc->function->need_frame)
+ if (_jitc->function->need_frame || _jitc->function->need_return)
mask |= (1 << _FP_REGNO) | (1 << _LR_REGNO);
if (!jit_swf_p() && _jitc->function->save_reg_args &&
!(_jitc->function->self.call & jit_call_varargs))
@@ -4000,10 +4012,10 @@ _epilog(jit_state_t *_jit, jit_node_t *node)
}
}
}
- if (_jitc->function->need_frame) {
+ if (_jitc->function->need_frame || _jitc->function->need_return)
mask |= (1 << _FP_REGNO) | (1 << _LR_REGNO);
+ if (_jitc->function->need_frame)
movr(_SP_REGNO, _FP_REGNO);
- }
if (!jit_swf_p() && _jitc->function->save_reg_args &&
!(_jitc->function->self.call & jit_call_varargs))
addi(_SP_REGNO, _SP_REGNO, 16);
diff --git a/lib/jit_arm.c b/lib/jit_arm.c
index 478f9b7..ca9d9fa 100644
--- a/lib/jit_arm.c
+++ b/lib/jit_arm.c
@@ -63,6 +63,13 @@
} \
} while (0)
+#define CHECK_RETURN() \
+ do { \
+ if (!_jitc->function->need_frame && \
+ !_jitc->function->need_return) \
+ _jitc->again = _jitc->function->need_return = 1; \
+ } while (0)
+
/*
* Types
*/
@@ -278,7 +285,8 @@ _jit_prolog(jit_state_t *_jit)
_jitc->function->self.size = stack_framesize;
_jitc->function->self.argi = _jitc->function->self.argf =
_jitc->function->self.alen = _jitc->function->self.aoff = 0;
- _jitc->function->swf_offset = _jitc->function->save_reg_args = 0;
+ _jitc->function->swf_offset = _jitc->function->save_reg_args =
+ _jitc->function->need_return = 0;
_jitc->function->self.call = jit_call_default;
jit_alloc((jit_pointer_t *)&_jitc->function->regoff,
_jitc->reglen * sizeof(jit_int32_t));
@@ -1917,8 +1925,8 @@ _emit_code(jit_state_t *_jit)
callr(rn(node->u.w));
break;
case jit_code_calli:
- jit_check_frame();
if (node->flag & jit_flag_node) {
+ CHECK_RETURN();
temp = node->u.n;
assert(temp->code == jit_code_label ||
temp->code == jit_code_epilog);
@@ -1938,8 +1946,10 @@ _emit_code(jit_state_t *_jit)
arm_patch_call : arm_patch_word);
}
}
- else
+ else {
+ jit_check_frame();
calli(node->u.w, jit_exchange_p());
+ }
break;
case jit_code_prolog:
_jitc->function = _jitc->functions.ptr + node->w.w;
@@ -1981,6 +1991,7 @@ _emit_code(jit_state_t *_jit)
undo.func.self.aoff = _jitc->function->frame +
_jitc->function->self.aoff;
undo.func.need_frame = _jitc->function->need_frame;
+ undo.func.need_return = _jitc->function->need_return;
jit_regset_set(&undo.func.regset, &_jitc->function->regset);
/* allocar information also does not need to be undone */
undo.func.aoffoff = _jitc->function->aoffoff;
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月17日 18:21:02 +0000

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