[php-src] PR #13750: [wip] DFA based func call optimizations

From: Date: Mon, 18 Mar 2024 18:30:30 +0000
Subject: [php-src] PR #13750: [wip] DFA based func call optimizations
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-25470@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/13750 Author: arnaud-lb The func call optimization pass update the INIT_FCALL, SEND_, and DO_FCALL opcodes to specialized variants when the function is known. In particular, there are variants of the SEND_ operands that never pass by ref, which I assume improves the effectiveness of later passes. Similarly, the call graph optimization builds a graph of known callers/callees that other passes can use. @kocsismate noticed that method calls were ignored by these passes unless op1 is $this, because the type of op1 is only known after these passes. This PR attempts to improve that updating the call graph during type inference, and by running the func call optimization pass again after that: - The call graph is updated to also include unknown callees - Type inference updates callees when possible - Type inference uses callees to determine if SEND_ ops may pass by ref instead of relying exclusively on the opcode - The func call optimization pass is executed again after callee inference The third point requires to run type inference before zend_mark_cv_references, otherwise we may narrow types, so we run zend_infer_types twice: Once for its effect on callees, and a second time after the func call optimization. The DFA needs to admit a dependency between the INIT_METHOD_CALL op1_use and the related SEND and DO_FCALL ops. Currently the SSA can not represent this: I've tried adding a fake operand to SEND and DO_FCALL ops, or adding fake use/defs; but I wasn't happy with either, so instead I've added a special case in add_usages(). Unfortunately the effectiveness of these changes is limited by the fact that we must ignore classes declared in other compilation units. Here is a comparison of the number of SEND opcodes emitted when executing the symfony demo before and after this change: ``` opcode before after SEND_FUNC_ARG 794 791 SEND_REF 13 14 SEND_UNPACK 26 26 SEND_USER 1 1 SEND_VAL 622 627 SEND_VAL_EX 4965 4960 SEND_VAR 1506 1523 SEND_VAR_EX 4068 4058 SEND_VAR_NO_REF_EX 1470 1465 ``` Benchmarks also show no noticeable improvement, so I don't plan on attempting to merge this as-is, but this may benefit other optimizations (or benefit from them) in the future.

« previous php.git-pulls (#25470) next »