Skip to content

Commit 7cc44af

Browse files
committed
JIT support
1 parent fac46db commit 7cc44af

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

ext/opcache/jit/zend_jit_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_counter_helper(ZEND_OPCODE_H
233233
void ZEND_FASTCALL zend_jit_copy_extra_args_helper(EXECUTE_DATA_D);
234234
void ZEND_FASTCALL zend_jit_copy_extra_args_helper_no_skip_recv(EXECUTE_DATA_D);
235235
bool ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D);
236+
bool ZEND_FASTCALL zend_jit_nodiscard_helper(OPLINE_D);
236237
void ZEND_FASTCALL zend_jit_undefined_long_key(EXECUTE_DATA_D);
237238
void ZEND_FASTCALL zend_jit_undefined_long_key_ex(zend_long key EXECUTE_DATA_DC);
238239
void ZEND_FASTCALL zend_jit_undefined_string_key(EXECUTE_DATA_D);

ext/opcache/jit/zend_jit_ir.c

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10128,7 +10128,7 @@ static int zend_jit_do_fcall(zend_jit_ctx *jit, const zend_op *opline, const zen
1012810128
ir_GUARD_NOT(
1012910129
ir_AND_U32(
1013010130
ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, fn_flags))),
10131-
ir_CONST_U32(ZEND_ACC_DEPRECATED)),
10131+
ir_CONST_U32(ZEND_ACC_DEPRECATED|ZEND_ACC_NODISCARD)),
1013210132
ir_CONST_ADDR(exit_addr));
1013310133
}
1013410134
}
@@ -10168,16 +10168,46 @@ static int zend_jit_do_fcall(zend_jit_ctx *jit, const zend_op *opline, const zen
1016810168
}
1016910169
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
1017010170
ir_MERGE_WITH_EMPTY_FALSE(if_deprecated);
10171+
10172+
if (!RETURN_VALUE_USED(opline)) {
10173+
ir_ref if_nodiscard, ret;
10174+
10175+
if_nodiscard = ir_IF(ir_AND_U32(
10176+
ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, fn_flags))),
10177+
ir_CONST_U32(ZEND_ACC_NODISCARD)));
10178+
ir_IF_TRUE_cold(if_nodiscard);
10179+
10180+
if (GCC_GLOBAL_REGS) {
10181+
ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper));
10182+
} else {
10183+
ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper), rx);
10184+
}
10185+
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
10186+
ir_MERGE_WITH_EMPTY_FALSE(if_nodiscard);
10187+
}
1017110188
}
10172-
} else if (func->common.fn_flags & ZEND_ACC_DEPRECATED) {
10173-
ir_ref ret;
10189+
} else {
10190+
if (func->common.fn_flags & ZEND_ACC_DEPRECATED) {
10191+
ir_ref ret;
1017410192

10175-
if (GCC_GLOBAL_REGS) {
10176-
ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper));
10177-
} else {
10178-
ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper), rx);
10193+
if (GCC_GLOBAL_REGS) {
10194+
ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper));
10195+
} else {
10196+
ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper), rx);
10197+
}
10198+
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
10199+
}
10200+
10201+
if ((func->common.fn_flags & ZEND_ACC_NODISCARD) && !RETURN_VALUE_USED(opline)) {
10202+
ir_ref ret;
10203+
10204+
if (GCC_GLOBAL_REGS) {
10205+
ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper));
10206+
} else {
10207+
ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper), rx);
10208+
}
10209+
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
1017910210
}
10180-
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
1018110211
}
1018210212
}
1018310213

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,34 @@ bool ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D)
204204
return 1;
205205
}
206206

207+
bool ZEND_FASTCALL zend_jit_nodiscard_helper(OPLINE_D)
208+
{
209+
zend_execute_data *call = (zend_execute_data *) opline;
210+
zend_function *fbc = call->func;
211+
212+
zend_nodiscard_function(fbc);
213+
214+
if (EG(exception)) {
215+
#ifndef HAVE_GCC_GLOBAL_REGS
216+
zend_execute_data *execute_data = EG(current_execute_data);
217+
#endif
218+
const zend_op *opline = EG(opline_before_exception);
219+
if (opline && RETURN_VALUE_USED(opline)) {
220+
ZVAL_UNDEF(EX_VAR(opline->result.var));
221+
}
222+
223+
zend_vm_stack_free_args(call);
224+
225+
if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS)) {
226+
OBJ_RELEASE(Z_OBJ(call->This));
227+
}
228+
229+
zend_vm_stack_free_call_frame(call);
230+
return 0;
231+
}
232+
return 1;
233+
}
234+
207235
void ZEND_FASTCALL zend_jit_undefined_long_key(EXECUTE_DATA_D)
208236
{
209237
const zend_op *opline = EX(opline);

0 commit comments

Comments
 (0)