Skip to content

Commit 94a34c8

Browse files
committed
JIT support
1 parent 3089f93 commit 94a34c8

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

ext/opcache/jit/zend_jit_internal.h

+1
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

+38-8
Original file line numberDiff line numberDiff line change
@@ -10153,7 +10153,7 @@ static int zend_jit_do_fcall(zend_jit_ctx *jit, const zend_op *opline, const zen
1015310153
ir_GUARD_NOT(
1015410154
ir_AND_U32(
1015510155
ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, fn_flags))),
10156-
ir_CONST_U32(ZEND_ACC_DEPRECATED)),
10156+
ir_CONST_U32(ZEND_ACC_DEPRECATED|ZEND_ACC_NODISCARD)),
1015710157
ir_CONST_ADDR(exit_addr));
1015810158
}
1015910159
}
@@ -10193,16 +10193,46 @@ static int zend_jit_do_fcall(zend_jit_ctx *jit, const zend_op *opline, const zen
1019310193
}
1019410194
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
1019510195
ir_MERGE_WITH_EMPTY_FALSE(if_deprecated);
10196+
10197+
if (!RETURN_VALUE_USED(opline)) {
10198+
ir_ref if_nodiscard, ret;
10199+
10200+
if_nodiscard = ir_IF(ir_AND_U32(
10201+
ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, fn_flags))),
10202+
ir_CONST_U32(ZEND_ACC_NODISCARD)));
10203+
ir_IF_TRUE_cold(if_nodiscard);
10204+
10205+
if (GCC_GLOBAL_REGS) {
10206+
ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper));
10207+
} else {
10208+
ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper), rx);
10209+
}
10210+
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
10211+
ir_MERGE_WITH_EMPTY_FALSE(if_nodiscard);
10212+
}
1019610213
}
10197-
} else if (func->common.fn_flags & ZEND_ACC_DEPRECATED) {
10198-
ir_ref ret;
10214+
} else {
10215+
if (func->common.fn_flags & ZEND_ACC_DEPRECATED) {
10216+
ir_ref ret;
1019910217

10200-
if (GCC_GLOBAL_REGS) {
10201-
ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper));
10202-
} else {
10203-
ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper), rx);
10218+
if (GCC_GLOBAL_REGS) {
10219+
ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper));
10220+
} else {
10221+
ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper), rx);
10222+
}
10223+
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
10224+
}
10225+
10226+
if ((func->common.fn_flags & ZEND_ACC_NODISCARD) && !RETURN_VALUE_USED(opline)) {
10227+
ir_ref ret;
10228+
10229+
if (GCC_GLOBAL_REGS) {
10230+
ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper));
10231+
} else {
10232+
ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper), rx);
10233+
}
10234+
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
1020410235
}
10205-
ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler));
1020610236
}
1020710237
}
1020810238

ext/opcache/jit/zend_jit_vm_helpers.c

+28
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)