Skip to content
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3ca87ce
Tail call VM
arnaud-lb Feb 13, 2025
140a3cd
Return opline directly from helpers with extra args (remove zend_vm_t…
arnaud-lb Aug 13, 2025
0563418
ZEND_VM_TAIL_CALL_DISPATCH -> ZEND_VM_KIND_TAILCALL
arnaud-lb Aug 13, 2025
09032b6
Split ZEND_OPCODE_HANDLER_CCONV in two macros so we do not have to re…
arnaud-lb Aug 13, 2025
a7ebc3c
Drop $variant, use $kind instead. Name tailcall handlers with _TAILCALL.
arnaud-lb Aug 13, 2025
f11f508
Generate CALL handlers first, then TAILCALL handlers
arnaud-lb Aug 13, 2025
cc294ed
Simplify dispatching from helpers with extra args
arnaud-lb Aug 13, 2025
3ff3588
Remove IR_OPCODE_HANDLER_FUNC
arnaud-lb Aug 13, 2025
169f6f1
Remove unnecessary case
arnaud-lb Aug 13, 2025
8c780d1
Fix return type
arnaud-lb Aug 13, 2025
79086d1
fixup
arnaud-lb Aug 14, 2025
67c58ad
Revert "Simplify dispatching from helpers with extra args"
arnaud-lb Aug 14, 2025
c1e0d52
fixup phpdbg
arnaud-lb Aug 14, 2025
7305116
Clean generated code wrt ZEND_VM_DISPATCH_NOTAIL
arnaud-lb Aug 14, 2025
0c3515a
Generate helpers with extra args, last
arnaud-lb Aug 14, 2025
707d942
Remove ZEND_VM_DISPATCH_TO_* macros
arnaud-lb Aug 14, 2025
764410c
Rework special casing of halt and leave helpers
arnaud-lb Aug 14, 2025
780ac6f
Cleanup gen_null_handler/gen_halt_handler: The generate-once conditio…
arnaud-lb Aug 14, 2025
ad283c4
WS
arnaud-lb Aug 14, 2025
1234e5c
Comment
arnaud-lb Aug 14, 2025
c5823ae
Generated file
arnaud-lb Aug 14, 2025
e77d83d
Lower fixed_stack_frame_size
arnaud-lb Aug 14, 2025
38688b2
Review
arnaud-lb Aug 19, 2025
1702d77
Reduce diff size
arnaud-lb Aug 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions Zend/Zend.m4
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ ZEND_CHECK_STACK_DIRECTION
ZEND_CHECK_FLOAT_PRECISION
ZEND_DLSYM_CHECK
ZEND_CHECK_GLOBAL_REGISTER_VARIABLES
ZEND_CHECK_PRESERVE_NONE
ZEND_CHECK_CPUID_COUNT

AC_MSG_CHECKING([whether to enable thread safety])
Expand Down Expand Up @@ -464,3 +465,103 @@ AS_VAR_IF([ZEND_MAX_EXECUTION_TIMERS], [yes],
AC_MSG_CHECKING([whether to enable Zend max execution timers])
AC_MSG_RESULT([$ZEND_MAX_EXECUTION_TIMERS])
])

dnl
dnl ZEND_CHECK_PRESERVE_NONE
dnl
dnl Check if the preserve_none calling convention is supported and matches our
dnl expectations.
dnl
AC_DEFUN([ZEND_CHECK_PRESERVE_NONE], [dnl
AC_CACHE_CHECK([for preserve_none calling convention],
[php_cv_preverve_none],
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#include <stdint.h>

const char * const1 = "str1";
const char * const2 = "str2";
const char * const3 = "str3";
uint64_t key = UINT64_C(0x9d7f71d2bd296364);

uintptr_t _a = 0;
uintptr_t _b = 0;

uintptr_t __attribute__((preserve_none)) fun(uintptr_t a, uintptr_t b) {
_a = a;
_b = b;
return (uintptr_t)const3;
}

uintptr_t __attribute__((preserve_none)) test(void) {
uintptr_t ret;

#if defined(__x86_64__)
__asm__ __volatile__(
/* XORing to make it unlikely the value exists in any other register */
"movq %1, %%r12\n"
"xorq %3, %%r12\n"
"movq %2, %%r13\n"
"xorq %3, %%r13\n"
"xorq %%rax, %%rax\n"
"call fun\n"
: "=a" (ret)
: "r" (const1), "r" (const2), "r" (key)
: "r12", "r13"
);
#elif defined(__aarch64__)
__asm__ __volatile__(
/* XORing to make it unlikely the value exists in any other register */
"eor x20, %1, %3\n"
"eor x21, %2, %3\n"
"eor x0, x0, x0\n"
"bl fun\n"
"mov %0, x0\n"
: "=r" (ret)
: "r" (const1), "r" (const2), "r" (key)
: "x0", "x21", "x22", "x30"
);
#else
# error
#endif

return ret;
}

int main(void) {

/* JIT is making the following expectations about preserve_none:
* - The registers used for integer args 1 and 2
* - The register used for a single integer return value
*
* We check these expectations here:
*/

uintptr_t ret = test();

if (_a != ((uintptr_t)const1 ^ key)) {
fprintf(stderr, "arg1 mismatch\n");
return 1;
}
if (_b != ((uintptr_t)const2 ^ key)) {
fprintf(stderr, "arg2 mismatch\n");
return 2;
}
if (ret != (uintptr_t)const3) {
fprintf(stderr, "ret mismatch\n");
return 3;
}

fprintf(stderr, "OK\n");

return 0;
}]])],
[php_cv_preserve_none=yes],
[php_cv_preserve_none=no],
[php_cv_preserve_none=no])
])
AS_VAR_IF([php_cv_preserve_none], [yes], [
AC_DEFINE([HAVE_PRESERVE_NONE], [1],
[Define to 1 if you have preserve_none support.])
])
])
9 changes: 9 additions & 0 deletions Zend/zend_portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ char *alloca();
# define ZEND_FASTCALL
#endif

#ifdef HAVE_PRESERVE_NONE
# define ZEND_PRESERVE_NONE __attribute__((preserve_none))
#endif

#if __has_attribute(musttail)
# define HAVE_MUSTTAIL
# define ZEND_MUSTTAIL __attribute__((musttail))
#endif

#if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(__APPLE__) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)) || __has_attribute(noreturn)
# define HAVE_NORETURN
# define ZEND_NORETURN __attribute__((noreturn))
Expand Down
9 changes: 6 additions & 3 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -2962,7 +2962,10 @@ ZEND_VM_HOT_HELPER(zend_leave_helper, ANY, ANY)
{
zend_execute_data *old_execute_data;
uint32_t call_info = EX_CALL_INFO();
#if ZEND_VM_KIND != ZEND_VM_KIND_TAILCALL
/* zend_leave_helper may be called with opline=call_leave_op in TAILCALL VM */
SAVE_OPLINE();
#endif

if (EXPECTED((call_info & (ZEND_CALL_CODE|ZEND_CALL_TOP|ZEND_CALL_HAS_SYMBOL_TABLE|ZEND_CALL_FREE_EXTRA_ARGS|ZEND_CALL_ALLOCATED|ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)) == 0)) {
EG(current_execute_data) = EX(prev_execute_data);
Expand Down Expand Up @@ -4917,7 +4920,7 @@ ZEND_VM_HOT_SEND_HANDLER(116, ZEND_SEND_VAL_EX, CONST|TMP, CONST|UNUSED|NUM, SPE
ZEND_VM_C_GOTO(send_val_by_ref);
}
} else if (ARG_MUST_BE_SENT_BY_REF(EX(call)->func, arg_num)) {
ZEND_VM_C_LABEL(send_val_by_ref):
ZEND_VM_C_LABEL(send_val_by_ref):;
ZEND_VM_DISPATCH_TO_HELPER(zend_cannot_pass_by_ref_helper, _arg_num, arg_num, _arg, arg);
}
value = GET_OP1_ZVAL_PTR(BP_VAR_R);
Expand Down Expand Up @@ -8240,9 +8243,9 @@ ZEND_VM_HANDLER(150, ZEND_USER_OPCODE, ANY, ANY)
case ZEND_USER_OPCODE_LEAVE:
ZEND_VM_LEAVE();
case ZEND_USER_OPCODE_DISPATCH:
ZEND_VM_DISPATCH(opline->opcode, opline);
ZEND_VM_DISPATCH_OPCODE(opline->opcode, opline);
default:
ZEND_VM_DISPATCH((uint8_t)(ret & 0xff), opline);
ZEND_VM_DISPATCH_OPCODE((uint8_t)(ret & 0xff), opline);
}
}

Expand Down
Loading