Commit Graph

37 Commits

Author SHA1 Message Date
Nikita Popov
434e0fb3a5 Take pi defs into account when propagating defs
Previously pi placement happened after initial phi placement.
Afterwards a second phi placement pass was performed, however it
incorrectly only placed phis on the dominance frontier, rather
than the iterated dominance frontier.

This is fixed by moving pi placement before the propagation of
defs on the iterated DFs, and adding a def for each added pi.

While this ensures that we generate correct conservative SSA, there
is still one remaining case in which we may generate non-minimal
SSA form. Consider:

   |1|
    |pi
    v
   |2|<--\
    |    |
    \----/

The pi is semanically located along the edge 1->2, however we place
it (and its def point) in 2, thus leading to the generation of an
additional (trivial) phi in 2.

Conflicts:
	ext/opcache/Optimizer/zend_ssa.c
2016-04-24 21:46:20 +02:00
Nikita Popov
721be3e0c1 Make pi placement independent of phi placement
This interdependence is problematic because we can't propagate pi
def points in the initial dominance frontier propagation. The used
rule for multiple-predecessor blocks may also miss cases where
placing the pi would have been useful.

The new heuristic for pi placement checks that a) the variable is
live-in and b) for the "from" block that generated the pi, the
other successor does not dominate all other predecessors of the
"to" block.

The purpose of case b) may be illustrated with an example:

    if (is_int($i)) {
        // place pi here
    }
    // but don't place pi here

The reason we do not want to place the second pi is that we generally
place pis in positive+negative pairs, and in this case the pair
would merge in a phi and cancel out, so we get no useful information
out of it.
2016-04-24 21:45:22 +02:00
Nikita Popov
65faf0a5a2 Drop some unnecessary checks 2016-04-24 17:15:46 +02:00
Nikita Popov
cafe78d12a Introduce ZEND_BITSET_FOREACH macros 2016-04-24 17:05:13 +02:00
Nikita Popov
304e5ae3d6 Adjust DFG allocation size
Now we need one set less...
2016-04-21 23:49:37 +02:00
Nikita Popov
a5944f8dd5 Merge def and gen sets
For live-variable analysis it does not matter if def includes
variables that are previously use in the same block, the data flow
equations still have the same result. As such there is no need to
compute separate gen & def sets.

I'm keeping the name "def", because use of "gen" in this context is
pretty confusing (gen is usually the use set, not the def set).
2016-04-21 23:32:01 +02:00
Nikita Popov
4f726be682 Fix SSA for SEND_UNPACK 2016-04-16 22:38:52 +02:00
Dmitry Stogov
aed4249653 Fixed handling of return statement without a value. 2016-04-07 18:59:04 +03:00
Dmitry Stogov
8921449785 Added missing "break" 2016-04-07 18:27:49 +03:00
Dmitry Stogov
3444c1ae24 Use return type hints for type inference and eliminate useless VERIFY_RETRUN_TYPE opcodes. 2016-04-07 17:34:53 +03:00
Kalle Sommer Nielsen
fc49f1c411 Fix build 2016-03-17 03:53:01 +01:00
Dmitry Stogov
8c2d55962e Combine conditions 2016-02-11 23:11:19 +03:00
Dmitry Stogov
4095d5f245 Cleanup OP_DATA usage. Now only first operand of OP_DATA is used for ASSIGN_DIM, ASSIGN_OBJ and ASSIGN_OP (DIM/OBJ) instructions. 2016-02-09 13:12:57 +03:00
Nikita Popov
80c15ac784 Move pi placement into separate function
Non-functional change, just moving code. This makes it easier to
change the order of operations.
2016-02-02 17:39:59 +01:00
Nikita Popov
c2fea2a46d Respect RC_INFERENCE during DFG construction
To avoid inserting phis that are only relevant with rc inference
enabled. Suprisingly, this affects only 0.8% of phis.
2016-01-24 23:04:06 +01:00
Nikita Popov
cf6aa46dbd Fix SSA for ZEND_YIELD
Yield-by-ref defs a ref var, yield-by-var only defs an rc1/rcn var
if rc inference is used.

Also move BIND_LEXICAL where it belongs in DFG construction.
2016-01-24 23:03:50 +01:00
Nikita Popov
5662d73528 Add support for Pi type constraints
Supports TYPE_CHECK and IS_IDENTICAL for now.
2016-01-19 22:09:29 +01:00
Dmitry Stogov
6579e48417 Introduced BIND_STATIC opcode instead of FETCH_R/FETCH_W(static)+ASSIGN/ASSIGN_REF (similar to BIND_GLOBAL).
In the future we may refer to static variable by index instead of name, to eliminate hash lookup.
2016-01-12 12:20:35 +03:00
Nikita Popov
0e936db801 Make PI construction human-readable
Also makes it easy to add PIs for TI.
2016-01-11 21:53:22 +01:00
Lior Kaplan
71c1980025 Happy new year (Update copyright to 2016) 2016-01-01 20:06:12 +02:00
Nikita Popov
65e456f364 Introduce BIND_LEXICAL
This opcodes inserts a local CV into the closure static variable
table. This replaces the previous mechanism of having static
variables marked as LEXICAL, which perform a symtable lookup
during copying.

This means a) functions which contain closures no longer have to
rebuild their symtable (better performance) and b) we can now track
used variables in SSA.
2015-12-29 23:14:53 +01:00
Nikita Popov
33870c525a Don't reuse SSA var in UNSET_VAR
Instead use the SSA var that UNSET_VAR actually defines. Otherwise
we get issues trying to DCE unsets.
2015-12-26 23:33:58 +01:00
Dmitry Stogov
28a016a6dc Fixed SSA construction for CFG with unreachable BB 2015-12-23 03:52:38 +03:00
Nikita Popov
fdfbeeb296 Always create ARRAY_ELEM ssa var for ELEM_REF 2015-12-22 23:08:26 +01:00
Dmitry Stogov
a75c6d5fb2 Skip "useless" SSA variables for INIT_ARRAY, ADD_ARRAY_ELEMENT, FE_RESET_R 2015-12-22 17:35:08 +03:00
Dmitry Stogov
b4b6d58990 Add ability to prevent "useless" SSA variable creation for "refcounting inference". 2015-12-22 16:43:37 +03:00
Nikita Popov
420ff42bc0 Protect against overflows in pi constraints 2015-12-20 12:56:05 +01:00
Nikita Popov
0da1378a88 long -> zend_long in range inference 2015-12-20 00:06:12 +01:00
Nikita Popov
549d7d4876 Fix Pi constraint for -LONG_MIN adjustments
-LONG_MIN == LONG_MIN so bad things will happen.
Example of JIT miscompile:

    function test($n) {
	if ($n + PHP_INT_MIN == 0) {
	    $n2 = (int) ($n + PHP_INT_MAX);
	    var_dump($n2);
	}
    }
    test(PHP_INT_MAX + 1);
2015-12-20 00:06:12 +01:00
Nikita Popov
c9ea8fef96 Extrace find_adjusted_tmp_var() function
This code was duplicated for op1 and op2
2015-12-20 00:06:12 +01:00
Nikita Popov
fc68094497 Simplify bf/bt computation in pi placement
The meaning of the successors is well-defined, no need to check it.
2015-12-20 00:03:52 +01:00
Nikita Popov
d7424a5b04 Fix typo in pi placement 2015-12-20 00:03:52 +01:00
Dmitry Stogov
74daa98974 Added simple DFA optimisation pattern (just to prove the concept) 2015-12-16 13:14:31 +03:00
Dmitry Stogov
9044f491cc Use do_alloca() instead of alloca() 2015-12-16 04:59:05 +03:00
Dmitry Stogov
c88ffa9a56 Added e-SSA based DFA optimisation framework (incomplete) 2015-12-16 00:49:44 +03:00
Dmitry Stogov
1fdb63fbd9 ws fixes 2015-12-11 17:40:23 +03:00
Dmitry Stogov
f243aaf985 Added e-SSA based DFA optimisation framework (incomplete) 2015-12-11 17:24:55 +03:00