Skip to content

Remove old JIT implementation #12498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions build/Makefile.global
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ clean:
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp.la $(SAPI_CLI_PATH) $(SAPI_CGI_PATH) $(SAPI_LITESPEED_PATH) $(SAPI_FPM_PATH) $(OVERALL_TARGET) modules/* libs/*
rm -f ext/opcache/jit/zend_jit_x86.c
rm -f ext/opcache/jit/zend_jit_arm64.c
rm -f ext/opcache/minilua
rm -f ext/opcache/jit/ir/gen_ir_fold_hash
rm -f ext/opcache/jit/ir/minilua
rm -f ext/opcache/jit/ir/ir_fold_hash.h
Expand Down
58 changes: 2 additions & 56 deletions ext/opcache/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ PHP_ARG_WITH([capstone],,
[no],
[no])

PHP_ARG_ENABLE([opcache-jit-ir],
[whether to enable JIT based on IR framework],
[AS_HELP_STRING([--disable-opcache-jit-ir],
[Disable JIT based on IR framework (use old JIT)])],
[yes],
[no])

if test "$PHP_OPCACHE" != "no"; then

dnl Always build as shared extension
Expand All @@ -51,52 +44,7 @@ if test "$PHP_OPCACHE" != "no"; then
esac
fi

if test "$PHP_OPCACHE_JIT" = "yes" -a "$PHP_OPCACHE_JIT_IR" = "no" ; then
AC_DEFINE(HAVE_JIT, 1, [Define to enable JIT])
ZEND_JIT_SRC="jit/zend_jit.c jit/zend_jit_gdb.c jit/zend_jit_vm_helpers.c"

dnl Find out which ABI we are using.
case $host_alias in
x86_64-*-darwin*)
DASM_FLAGS="-D X64APPLE=1 -D X64=1"
DASM_ARCH="x86"
;;
x86_64*)
DASM_FLAGS="-D X64=1"
DASM_ARCH="x86"
;;
i[[34567]]86*)
DASM_ARCH="x86"
;;
x86*)
DASM_ARCH="x86"
;;
aarch64*)
DASM_FLAGS="-D ARM64=1"
DASM_ARCH="arm64"
;;
esac

if test "$PHP_THREAD_SAFETY" = "yes"; then
DASM_FLAGS="$DASM_FLAGS -D ZTS=1"
fi

AS_IF([test x"$with_capstone" = "xyes"],[
PKG_CHECK_MODULES([CAPSTONE],[capstone >= 3.0.0],[
AC_DEFINE([HAVE_CAPSTONE], [1], [Capstone is available])
PHP_EVAL_LIBLINE($CAPSTONE_LIBS, OPCACHE_SHARED_LIBADD)
PHP_EVAL_INCLINE($CAPSTONE_CFLAGS)
],[
AC_MSG_ERROR([capstone >= 3.0 required but not found])
])
])

PHP_SUBST(DASM_FLAGS)
PHP_SUBST(DASM_ARCH)

JIT_CFLAGS=

elif test "$PHP_OPCACHE_JIT" = "yes" -a "$PHP_OPCACHE_JIT_IR" = "yes"; then
if test "$PHP_OPCACHE_JIT" = "yes" ; then
AC_DEFINE(HAVE_JIT, 1, [Define to enable JIT])
AC_DEFINE(ZEND_JIT_IR, 1, [Use JIT IR framework])
ZEND_JIT_SRC="jit/zend_jit.c jit/zend_jit_vm_helpers.c jit/ir/ir.c jit/ir/ir_strtab.c \
Expand Down Expand Up @@ -383,9 +331,7 @@ int main(void) {

if test "$PHP_OPCACHE_JIT" = "yes"; then
PHP_ADD_BUILD_DIR([$ext_builddir/jit], 1)
if test "$PHP_OPCACHE_JIT_IR" = "yes"; then
PHP_ADD_BUILD_DIR([$ext_builddir/jit/ir], 1)
fi
PHP_ADD_BUILD_DIR([$ext_builddir/jit/ir], 1)
PHP_ADD_MAKEFILE_FRAGMENT($ext_srcdir/jit/Makefile.frag)
fi
PHP_SUBST(OPCACHE_SHARED_LIBADD)
Expand Down
23 changes: 1 addition & 22 deletions ext/opcache/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ if (PHP_OPCACHE != "no") {

ARG_ENABLE("opcache-jit", "whether to enable JIT", "yes");

ARG_ENABLE("opcache-jit-ir", "whether to enable JIT based on IR framework", "yes");

ZEND_EXTENSION('opcache', "\
ZendAccelerator.c \
zend_accelerator_blacklist.c \
Expand All @@ -20,26 +18,7 @@ if (PHP_OPCACHE != "no") {
zend_shared_alloc.c \
shared_alloc_win32.c", true, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");

if (PHP_OPCACHE_JIT == "yes" && PHP_OPCACHE_JIT_IR == "no") {
if (CHECK_HEADER_ADD_INCLUDE("dynasm/dasm_x86.h", "CFLAGS_OPCACHE", PHP_OPCACHE + ";ext\\opcache\\jit")) {
var dasm_flags = (X64 ? "-D X64=1" : "") + (X64 ? " -D X64WIN=1" : "") + " -D WIN=1";
if (PHP_ZTS == "yes") {
dasm_flags += " -D ZTS=1";
}
DEFINE("DASM_FLAGS", dasm_flags);
DEFINE("DASM_ARCH", "x86");

AC_DEFINE('HAVE_JIT', 1, 'Define to enable JIT');
/* XXX read this dynamically */
/*ADD_FLAG("CFLAGS_OPCACHE", "/D DASM_VERSION=10400");*/

ADD_MAKEFILE_FRAGMENT(configure_module_dirname + "\\jit\\Makefile.frag.w32");

ADD_SOURCES(configure_module_dirname + "\\jit", "zend_jit.c zend_jit_vm_helpers.c", "opcache", "ext\\opcache\\jit");
} else {
WARNING("JIT not enabled, headers not found");
}
} else if (PHP_OPCACHE_JIT == "yes" && PHP_OPCACHE_JIT_IR == "yes") {
if (PHP_OPCACHE_JIT == "yes") {
if (CHECK_HEADER_ADD_INCLUDE("ir/ir.h", "CFLAGS_OPCACHE", PHP_OPCACHE + ";ext\\opcache\\jit")) {
var dasm_flags = (X64 ? "-D X64=1" : "") + (X64 ? " -D X64WIN=1" : "") + " -D WIN=1";
var ir_target = (X64 ? "IR_TARGET_X64" : "IR_TARGET_X86");
Expand Down
22 changes: 0 additions & 22 deletions ext/opcache/jit/Makefile.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ifdef IR_TARGET
# New IR based JIT
$(builddir)/jit/ir/minilua: $(srcdir)/jit/ir/dynasm/minilua.c
$(BUILD_CC) $(srcdir)/jit/ir/dynasm/minilua.c -lm -o $@

Expand All @@ -22,26 +20,6 @@ $(builddir)/jit/zend_jit.lo: \
$(srcdir)/jit/zend_jit_helpers.c \
$(srcdir)/jit/zend_jit_ir.c

else
# Old DynAsm based JIT
$(builddir)/minilua: $(srcdir)/jit/dynasm/minilua.c
$(BUILD_CC) $(srcdir)/jit/dynasm/minilua.c -lm -o $@

$(builddir)/jit/zend_jit_$(DASM_ARCH).c: $(srcdir)/jit/zend_jit_$(DASM_ARCH).dasc $(srcdir)/jit/dynasm/*.lua $(builddir)/minilua
$(builddir)/minilua $(srcdir)/jit/dynasm/dynasm.lua $(DASM_FLAGS) -o $@ $(srcdir)/jit/zend_jit_$(DASM_ARCH).dasc

$(builddir)/jit/zend_jit.lo: \
$(builddir)/jit/zend_jit_$(DASM_ARCH).c \
$(srcdir)/jit/zend_jit_helpers.c \
$(srcdir)/jit/zend_jit_disasm.c \
$(srcdir)/jit/zend_jit_gdb.c \
$(srcdir)/jit/zend_jit_perf_dump.c \
$(srcdir)/jit/zend_jit_vtune.c \
$(srcdir)/jit/zend_jit_trace.c \
$(srcdir)/jit/zend_elf.c

endif

# For non-GNU make, jit/zend_jit.lo and ./jit/zend_jit.lo are considered distinct targets.
# Use this workaround to allow building from inside ext/opcache.
jit/zend_jit.lo: $(builddir)/jit/zend_jit.lo
24 changes: 0 additions & 24 deletions ext/opcache/jit/Makefile.frag.w32
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
!if "$(IR_TARGET)" != ""
# New IR based JIT

$(BUILD_DIR)\\minilua.exe: ext\opcache\jit\ir\dynasm\minilua.c
@if exist $(BUILD_DIR)\\minilua.exe del $(BUILD_DIR)\\minilua.exe
$(PHP_CL) /Fo$(BUILD_DIR)\ /Fd$(BUILD_DIR)\ /Fp$(BUILD_DIR)\ /FR$(BUILD_DIR) /Fe$(BUILD_DIR)\minilua.exe ext\opcache\jit\ir\dynasm\minilua.c
Expand Down Expand Up @@ -39,24 +36,3 @@ $(BUILD_DIR)\ext\opcache\jit\zend_jit.obj: \
ext\opcache\jit\zend_jit_helpers.c \
ext\opcache\jit\ir\ir.h \
ext\opcache\jit\ir\ir_builder.h

!else
# Old DynAsm based JIT

$(BUILD_DIR)\\minilua.exe: ext\opcache\jit\dynasm\minilua.c
@if exist $(BUILD_DIR)\\minilua.exe del $(BUILD_DIR)\\minilua.exe
$(PHP_CL) /Fo$(BUILD_DIR)\ /Fd$(BUILD_DIR)\ /Fp$(BUILD_DIR)\ /FR$(BUILD_DIR) /Fe$(BUILD_DIR)\minilua.exe ext\opcache\jit\dynasm\minilua.c

ext\opcache\jit\zend_jit_x86.c: ext\opcache\jit\zend_jit_x86.dasc $(BUILD_DIR)\\minilua.exe
@if exist ext\opcache\jit\zend_jit_x86.c del ext\opcache\jit\zend_jit_x86.c
$(BUILD_DIR)\\minilua.exe ext/opcache/jit/dynasm/dynasm.lua $(DASM_FLAGS) -o $@ ext/opcache/jit/zend_jit_x86.dasc

$(BUILD_DIR)\ext\opcache\jit\zend_jit.obj: \
ext/opcache/jit/zend_jit_x86.c \
ext/opcache/jit/zend_jit_helpers.c \
ext/opcache/jit/zend_jit_disasm.c \
ext/opcache/jit/zend_jit_gdb.c \
ext/opcache/jit/zend_jit_perf_dump.c \
ext/opcache/jit/zend_jit_trace.c \
ext/opcache/jit/zend_jit_vtune.c
!endif
32 changes: 0 additions & 32 deletions ext/opcache/jit/README-IR.md

This file was deleted.

42 changes: 4 additions & 38 deletions ext/opcache/jit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,10 @@ Opcache JIT
===========

This is the implementation of Opcache's JIT (Just-In-Time compiler),
This converts the PHP Virtual Machine's opcodes into x64/x86 assembly,
on POSIX platforms and Windows.

It generates native code directly from PHP byte-code and information collected
by the SSA static analysis framework (a part of the opcache optimizer).
Code is usually generated separately for each PHP byte-code instruction. Only
a few combinations are considered together (e.g. compare + conditional jump).

See [the JIT RFC](https://wiki.php.net/rfc/jit) for more details.

DynAsm
------

This uses [DynAsm](https://luajit.org/dynasm.html) (developed for LuaJIT project)
for the generation of native code. It's a very lightweight and advanced tool,
but does assume good, and very low-level development knowledge of target
assembler languages. In the past we tried LLVM, but its code generation speed
was almost 100 times slower, making it prohibitively expensive to use.

[The unofficial DynASM Documentation](https://corsix.github.io/dynasm-doc/tutorial.html)
has a tutorial, reference, and instruction listing.

In x86 builds, `zend_jit_x86.dasc` gets automatically converted to `zend_jit_x86.c` by the bundled
`dynasm` during `make`.

In arm64 builds, `zend_jit_arm64.dasc` gets automatically converted to `zend_jit_arm64.c` by the bundled
`dynasm` during `make`.
This converts the PHP Virtual Machine's opcodes into Intermediate
Representation and uses [IR - Lightweight JIT Compilation Framework](https://github.com/dstogov/ir)
to produce optimized native code. The necessary part of the IR
Framework is embedded into php-src.

Running tests of the JIT
------------------------
Expand Down Expand Up @@ -62,17 +39,6 @@ Note that the JIT supports 3 different architectures: `X86_64`, `i386`, and `arm
Miscellaneous
-------------

### Checking dasc files for in a different architecture

The following command can be run to manually check if the modified `.dasc code` is at least transpilable
for an architecture you're not using, e.g.:

For arm64: `ext/opcache/minilua ext/opcache/jit/dynasm/dynasm.lua -D ARM64=1 -o ext/opcache/jit/zend_jit_arm64.ignored.c ext/opcache/jit/zend_jit_arm64.dasc`

For x86_64: `ext/opcache/minilua ext/opcache/jit/dynasm/dynasm.lua -D X64=1 -o ext/opcache/jit/zend_jit_x86.ignored.c ext/opcache/jit/zend_jit_x86.dasc`

For i386 (i.e. 32-bit): `ext/opcache/minilua ext/opcache/jit/dynasm/dynasm.lua -o ext/opcache/jit/zend_jit_x86.ignored.c ext/opcache/jit/zend_jit_x86.dasc`

### How to build 32-bit builds on x86_64 environments

Refer to [../../../.github/workflows/push.yml](../../../.github/workflows/push.yml) for examples of
Expand Down
Loading