Skip to content

Commit 288271f

Browse files
committed
JIT support
1 parent c3dcb91 commit 288271f

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
@@ -10137,7 +10137,7 @@ static int zend_jit_do_fcall(zend_jit_ctx *jit, const zend_op *opline, const zen
1013710137
ir_GUARD_NOT(
1013810138
ir_AND_U32(
1013910139
ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, fn_flags))),
10140-
ir_CONST_U32(ZEND_ACC_DEPRECATED)),
10140+
ir_CONST_U32(ZEND_ACC_DEPRECATED|ZEND_ACC_NODISCARD)),
1014110141
ir_CONST_ADDR(exit_addr));
1014210142
}
1014310143
}
@@ -10177,16 +10177,46 @@ static int zend_jit_do_fcall(zend_jit_ctx *jit, const zend_op *opline, const zen
1017710177
}
1017810178
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
1017910179
ir_MERGE_WITH_EMPTY_FALSE(if_deprecated);
10180+
10181+
if (!RETURN_VALUE_USED(opline)) {
10182+
ir_ref if_nodiscard, ret;
10183+
10184+
if_nodiscard = ir_IF(ir_AND_U32(
10185+
ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, fn_flags))),
10186+
ir_CONST_U32(ZEND_ACC_NODISCARD)));
10187+
ir_IF_TRUE_cold(if_nodiscard);
10188+
10189+
if (GCC_GLOBAL_REGS) {
10190+
ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper));
10191+
} else {
10192+
ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper), rx);
10193+
}
10194+
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
10195+
ir_MERGE_WITH_EMPTY_FALSE(if_nodiscard);
10196+
}
1018010197
}
10181-
} else if (func->common.fn_flags & ZEND_ACC_DEPRECATED) {
10182-
ir_ref ret;
10198+
} else {
10199+
if (func->common.fn_flags & ZEND_ACC_DEPRECATED) {
10200+
ir_ref ret;
1018310201

10184-
if (GCC_GLOBAL_REGS) {
10185-
ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper));
10186-
} else {
10187-
ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper), rx);
10202+
if (GCC_GLOBAL_REGS) {
10203+
ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper));
10204+
} else {
10205+
ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper), rx);
10206+
}
10207+
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
10208+
}
10209+
10210+
if ((func->common.fn_flags & ZEND_ACC_NODISCARD) && !RETURN_VALUE_USED(opline)) {
10211+
ir_ref ret;
10212+
10213+
if (GCC_GLOBAL_REGS) {
10214+
ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper));
10215+
} else {
10216+
ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper), rx);
10217+
}
10218+
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
1018810219
}
10189-
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
1019010220
}
1019110221
}
1019210222

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)