rfc:jit-ir

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:jit-ir [2023/09/21 09:51] – mention the bus-facrtor (too many questions about it) dmitryrfc:jit-ir [2025/01/17 11:22] (current) – Link to correct merge commits, and fix typos/grammar theodorejb
Line 1: Line 1:
 ====== PHP RFC: A new JIT implementation based on IR Framework ====== ====== PHP RFC: A new JIT implementation based on IR Framework ======
-  * Version: 0.9+  * Version: 1.0
   * Date: 2023-09-20   * Date: 2023-09-20
   * Author: Dmitry Stogov, dmitry@php.net   * Author: Dmitry Stogov, dmitry@php.net
-  * Status: Under Discussion+  * Status: Accepted
   * First Published at: http://wiki.php.net/rfc/php-ir   * First Published at: http://wiki.php.net/rfc/php-ir
  
 ===== Introduction ===== ===== Introduction =====
-The first version of JIT for PHP was released in PHP-8.0 (https://wiki.php.net/rfc/jit). That time we took a quite simple approach. We are generating native code directly from Zend VM byte code. This approach allowed to deliver JIT in a quite short time, but it also created significant limitations in possible optimizations. Smart optimizations require a more formal and detailed **Intermediate Representation** (IR). The introduction of the AArch64 JIT back-end in PHP-8.1made the maintenance of JIT a bit more complex, because now we often have to update assembler code in two back-ends.+The first version of JIT for PHP was released in PHP-8.0 (https://wiki.php.net/rfc/jit). That time we took a quite simple approach. We are generating native code directly from Zend VM byte code. This approach allowed to deliver JIT in a quite short time, but it also created significant limitations in possible optimizations. Smart optimizations require a more formal and detailed **Intermediate Representation** (IR). The introduction of the AArch64 JIT back-end in PHP-8.1 made the maintenance of JIT a bit more complex, because now we often have to update assembler code in two back-ends.
    
-A smarter JIT compiler with some Intermediate Representation was planned a long time. The real work was started in January 2022.+A smarter JIT compiler with some Intermediate Representation was planned for a long time, and the real work was started in January 2022.
 This proposal is the result of these 1.75 years of work. This proposal is the result of these 1.75 years of work.
    
Line 29: Line 29:
 At the current state the PR doesn't remove the sources of the old JIT implementation. It is possible to switch to the old implementation by configuring PHP with **--disable-opcache-jit-ir**. At the current state the PR doesn't remove the sources of the old JIT implementation. It is possible to switch to the old implementation by configuring PHP with **--disable-opcache-jit-ir**.
  
-JIT is a quite complex subsystem. Its first implemention will likely have bugs, but I am confident that these can be addressed. We have more time to fix potential issuesthe sooner this proposal passes, and the patch is merged.+JIT is a quite complex subsystem. Its first implementation will likely have bugs, but I am confident that these can be addressed. We have more time to fix potential issues the sooner this proposal passes, and the patch is merged.
  
-The main goal of a separate IR Framework development is the collaboration with other compiler experts (sharing expertise, contribution, etc.). I'm doing my best to make the IR project interesting outside the PHP world and involve others. In case of success, this will reduce the PHP "bus-factor".+The main goal of a separate IR Framework development is the collaboration with other compiler experts (sharing expertise, contributions, etc.). I'm doing my best to make the IR project interesting outside the PHP world and involve others. In case of success, this will reduce the PHP "bus-factor".
  
 The necessary part of the IR Framework is embedded into the PHP source tree, and won't introduce any new external dependencies. The necessary part of the IR Framework is embedded into the PHP source tree, and won't introduce any new external dependencies.
  
-The details of the IR framework are complex, and I am working on a presentation with explanations to publish soonI have already shared this with a few core PHP developers     +The details of the IR framework are complex. This [[https://www.researchgate.net/publication/374470404_IR_JIT_Framework_a_base_for_the_next_generation_JIT_for_PHP|presentation]] explains design ideas and provides an overview of the most important implementation details.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 53: Line 53:
 Because the IR Framework provides more optimizations and has a smarter Register Allocator, the JIT produces a bit faster (5-10%) and smaller code. Because the IR Framework provides more optimizations and has a smarter Register Allocator, the JIT produces a bit faster (5-10%) and smaller code.
  
-This is visible with **bench.php** and **micro_bench.php**. The speed of the real-life applications is not affected.+This is visible with **bench.php** and **micro_bench.php**. The speed of real-life applications is not affected.
  
 The compilation speed of the Tracing JIT is almost the same. The compilation speed of the Function JIT is up to 4 times slower (tested on Wordpress). The compilation speed of the Tracing JIT is almost the same. The compilation speed of the Function JIT is up to 4 times slower (tested on Wordpress).
Line 72: Line 72:
 ==== php.ini Defaults ==== ==== php.ini Defaults ====
  
-The PR does not introduce new php.ini detectives or changes any default values.+The PR does not introduce new php.ini directives or change any default values.
  
 It adds few new IR related JIT debugging capabilities that may be enabled through **opcache.jit_debug** directive bits: It adds few new IR related JIT debugging capabilities that may be enabled through **opcache.jit_debug** directive bits:
Line 107: Line 107:
 ===== Future Scope ===== ===== Future Scope =====
  
-The usage of IR opens the door for more powerful optimizations. Some of these are going to be PHP independent (e.g.): the planned +The usage of IR opens the door for more powerful optimizations. Some of these are going to be PHP independent (e.g. the planned introduction of new loop optimization passes, improved LOAD/STORE motion and redundancy, and improvements to the code generator).
-introduction of new loop optimization passes, improvement in LOAD/STORE motion and redundancy, improvements to the code generator.+
  
 The other part is PHP specific (for example, we can extend CPU register usage for more instructions). The other part is PHP specific (for example, we can extend CPU register usage for more instructions).
Line 118: Line 117:
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
  
-Merge the new JIT implementation into PHP master?+Voting opened 2023-10-06 and closes 2023-10-19. 
 + 
 +<doodle title="Merge the new JIT implementation into PHP master?" auth="user" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle> 
 + 
 + 
 +Secondary vote: Should we keep the old JIT implementation for a while or remove it right after merge? 
 + 
 +Note, that old implementation is not going to be tested (by CI) and we can't guarantee its functionality anyway. 
 + 
 +<doodle title="Remove the old JIT implementation right after merging the new one?" auth="user" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle> 
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
Line 127: Line 142:
 ===== Implementation ===== ===== Implementation =====
  
-After the project is implemented, this section should contain  +   - merged into master via https://github.com/php/php-src/commit/caf102dfaef1ef4191c76a4502c6b4fef20cba46 
- +   old JIT implementation is removed via https://github.com/php/php-src/commit/be275433d936e41d95b2fd656464bcc4d7138b76
-  the version(s) it was merged into +
-  a link to the git commit(s) +
-  a link to the PHP manual entry for the feature +
-  a link to the language specification section (if any)+
  
 ===== References ===== ===== References =====
rfc/jit-ir.1695289908.txt.gz · Last modified: 2023/09/21 09:51 by dmitry