Skip to content

Commit a51e74d

Browse files
committed
Basic JIT support
1 parent fec19c0 commit a51e74d

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

Zend/zend_frameless_function.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
#include <stddef.h>
2020

21+
#include "php_config.h"
22+
2123
size_t zend_flf_count = 0;
2224
size_t zend_flf_capacity = 0;
23-
void **zend_flf_handlers = NULL;
25+
ZEND_API void **zend_flf_handlers = NULL;
2426
zend_function **zend_flf_functions = NULL;

ext/opcache/jit/zend_jit_ir.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16644,6 +16644,72 @@ static bool zend_jit_may_be_in_reg(const zend_op_array *op_array, zend_ssa *ssa,
1664416644
return 1;
1664516645
}
1664616646

16647+
static void jit_frameless_icall0(zend_jit_ctx *jit, const zend_op *opline)
16648+
{
16649+
void *function = zend_flf_handlers[opline->extended_value];
16650+
zend_jit_addr res_addr = RES_ADDR();
16651+
ir_ref res_ref = jit_ZVAL_ADDR(jit, res_addr);
16652+
ir_CALL_1(IR_VOID, ir_CONST_ADDR((size_t)function), res_ref);
16653+
zend_jit_check_exception(jit);
16654+
}
16655+
16656+
static void jit_frameless_icall1(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info)
16657+
{
16658+
void *function = zend_flf_handlers[opline->extended_value];
16659+
zend_jit_addr res_addr = RES_ADDR();
16660+
zend_jit_addr op1_addr = OP1_ADDR();
16661+
ir_ref res_ref = jit_ZVAL_ADDR(jit, res_addr);
16662+
ir_ref op1_ref = jit_ZVAL_ADDR(jit, op1_addr);
16663+
zend_jit_zval_check_undef(jit, op1_ref, opline->op1.var, opline, 1);
16664+
op1_ref = jit_ZVAL_DEREF_ref(jit, op1_ref);
16665+
ir_CALL_2(IR_VOID, ir_CONST_ADDR((size_t)function), res_ref, op1_ref);
16666+
jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, NULL);
16667+
zend_jit_check_exception(jit);
16668+
}
16669+
16670+
static void jit_frameless_icall2(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, uint32_t op2_info)
16671+
{
16672+
void *function = zend_flf_handlers[opline->extended_value];
16673+
zend_jit_addr res_addr = RES_ADDR();
16674+
zend_jit_addr op1_addr = OP1_ADDR();
16675+
zend_jit_addr op2_addr = OP2_ADDR();
16676+
ir_ref res_ref = jit_ZVAL_ADDR(jit, res_addr);
16677+
ir_ref op1_ref = jit_ZVAL_ADDR(jit, op1_addr);
16678+
ir_ref op2_ref = jit_ZVAL_ADDR(jit, op2_addr);
16679+
zend_jit_zval_check_undef(jit, op1_ref, opline->op1.var, opline, 1);
16680+
zend_jit_zval_check_undef(jit, op2_ref, opline->op2.var, opline, 1);
16681+
op1_ref = jit_ZVAL_DEREF_ref(jit, op1_ref);
16682+
op2_ref = jit_ZVAL_DEREF_ref(jit, op2_ref);
16683+
ir_CALL_3(IR_VOID, ir_CONST_ADDR((size_t)function), res_ref, op1_ref, op2_ref);
16684+
jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, NULL);
16685+
jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, NULL);
16686+
zend_jit_check_exception(jit);
16687+
}
16688+
16689+
static void jit_frameless_icall3(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, uint32_t op2_info, uint32_t op1_data_info)
16690+
{
16691+
void *function = zend_flf_handlers[opline->extended_value];
16692+
zend_jit_addr res_addr = RES_ADDR();
16693+
zend_jit_addr op1_addr = OP1_ADDR();
16694+
zend_jit_addr op2_addr = OP2_ADDR();
16695+
zend_jit_addr op3_addr = OP1_DATA_ADDR();
16696+
ir_ref res_ref = jit_ZVAL_ADDR(jit, res_addr);
16697+
ir_ref op1_ref = jit_ZVAL_ADDR(jit, op1_addr);
16698+
ir_ref op2_ref = jit_ZVAL_ADDR(jit, op2_addr);
16699+
ir_ref op3_ref = jit_ZVAL_ADDR(jit, op3_addr);
16700+
zend_jit_zval_check_undef(jit, op1_ref, opline->op1.var, opline, 1);
16701+
zend_jit_zval_check_undef(jit, op2_ref, opline->op2.var, opline, 1);
16702+
zend_jit_zval_check_undef(jit, op3_ref, (opline+1)->op1.var, opline, 1);
16703+
op1_ref = jit_ZVAL_DEREF_ref(jit, op1_ref);
16704+
op2_ref = jit_ZVAL_DEREF_ref(jit, op2_ref);
16705+
op3_ref = jit_ZVAL_DEREF_ref(jit, op3_ref);
16706+
ir_CALL_4(IR_VOID, ir_CONST_ADDR((size_t)function), res_ref, op1_ref, op2_ref, op3_ref);
16707+
jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, NULL);
16708+
jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, NULL);
16709+
jit_FREE_OP(jit, (opline+1)->op1_type, (opline+1)->op1, op1_data_info, NULL);
16710+
zend_jit_check_exception(jit);
16711+
}
16712+
1664716713
/*
1664816714
* Local variables:
1664916715
* tab-width: 4

ext/opcache/jit/zend_jit_trace.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6085,6 +6085,18 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
60856085
goto jit_failure;
60866086
}
60876087
goto done;
6088+
case ZEND_FRAMELESS_ICALL_0:
6089+
jit_frameless_icall0(jit, opline);
6090+
goto done;
6091+
case ZEND_FRAMELESS_ICALL_1:
6092+
jit_frameless_icall1(jit, opline, op1_info);
6093+
goto done;
6094+
case ZEND_FRAMELESS_ICALL_2:
6095+
jit_frameless_icall2(jit, opline, op1_info, op2_info);
6096+
goto done;
6097+
case ZEND_FRAMELESS_ICALL_3:
6098+
jit_frameless_icall3(jit, opline, op1_info, op2_info, OP1_DATA_INFO());
6099+
goto done;
60886100
default:
60896101
break;
60906102
}

0 commit comments

Comments
 (0)