Skip to content

Commit 7f40ae7

Browse files
committed
Add basic opcache optimizer support
1 parent 40b38cc commit 7f40ae7

File tree

12 files changed

+20
-2
lines changed

12 files changed

+20
-2
lines changed

Zend/tests/nullsafe_method_call/008.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
Test nullsafe property coalesce assignment error
3-
--SKIPIF--
4-
<?php if(extension_loaded("Zend OPcache")) die("skip with opcache because SSA incorrectly optimized"); ?>
53
--FILE--
64
<?php
75

ext/opcache/Optimizer/block_pass.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array, zend_op
10331033
case ZEND_JMP_SET:
10341034
case ZEND_COALESCE:
10351035
case ZEND_ASSERT_CHECK:
1036+
case ZEND_JMP_NULL:
10361037
ZEND_SET_OP_JMP_ADDR(opline, opline->op2, new_opcodes + blocks[b->successors[0]].start);
10371038
break;
10381039
case ZEND_CATCH:

ext/opcache/Optimizer/dce.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ static inline zend_bool may_have_side_effects(
139139
case ZEND_JMP_SET:
140140
case ZEND_COALESCE:
141141
case ZEND_ASSERT_CHECK:
142+
case ZEND_JMP_NULL:
142143
/* For our purposes a jumps and branches are side effects. */
143144
return 1;
144145
case ZEND_BEGIN_SILENCE:

ext/opcache/Optimizer/dfa_pass.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ static void zend_ssa_replace_control_link(zend_op_array *op_array, zend_ssa *ssa
623623
case ZEND_JMP_SET:
624624
case ZEND_COALESCE:
625625
case ZEND_ASSERT_CHECK:
626+
case ZEND_JMP_NULL:
626627
if (ZEND_OP2_JMP_ADDR(opline) == op_array->opcodes + old->start) {
627628
ZEND_SET_OP_JMP_ADDR(opline, opline->op2, op_array->opcodes + dst->start);
628629
}

ext/opcache/Optimizer/pass1.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
674674
case ZEND_JMP_SET:
675675
case ZEND_COALESCE:
676676
case ZEND_ASSERT_CHECK:
677+
case ZEND_JMP_NULL:
677678
collect_constants = 0;
678679
break;
679680
}

ext/opcache/Optimizer/sccp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,7 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
17731773
case ZEND_JMP_SET:
17741774
case ZEND_COALESCE:
17751775
case ZEND_COPY_TMP:
1776+
case ZEND_JMP_NULL:
17761777
SET_RESULT(result, op1);
17771778
break;
17781779
#if 0
@@ -1973,6 +1974,9 @@ static void sccp_mark_feasible_successors(
19731974
case ZEND_COALESCE:
19741975
s = (Z_TYPE_P(op1) == IS_NULL);
19751976
break;
1977+
case ZEND_JMP_NULL:
1978+
s = (Z_TYPE_P(op1) != IS_NULL);
1979+
break;
19761980
case ZEND_FE_RESET_R:
19771981
case ZEND_FE_RESET_RW:
19781982
/* A non-empty partial array is definitely non-empty, but an
@@ -2258,6 +2262,7 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
22582262
|| opline->opcode == ZEND_JMPNZ_EX
22592263
|| opline->opcode == ZEND_JMP_SET
22602264
|| opline->opcode == ZEND_COALESCE
2265+
|| opline->opcode == ZEND_JMP_NULL
22612266
|| opline->opcode == ZEND_FE_RESET_R
22622267
|| opline->opcode == ZEND_FE_RESET_RW
22632268
|| opline->opcode == ZEND_FE_FETCH_R

ext/opcache/Optimizer/zend_cfg.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ int zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t b
370370
case ZEND_JMP_SET:
371371
case ZEND_COALESCE:
372372
case ZEND_ASSERT_CHECK:
373+
case ZEND_JMP_NULL:
373374
BB_START(OP_JMP_ADDR(opline, opline->op2) - op_array->opcodes);
374375
BB_START(i + 1);
375376
break;
@@ -524,6 +525,7 @@ int zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t b
524525
case ZEND_JMP_SET:
525526
case ZEND_COALESCE:
526527
case ZEND_ASSERT_CHECK:
528+
case ZEND_JMP_NULL:
527529
block->successors_count = 2;
528530
block->successors[0] = block_map[OP_JMP_ADDR(opline, opline->op2) - op_array->opcodes];
529531
block->successors[1] = j + 1;

ext/opcache/Optimizer/zend_inference.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4404,6 +4404,7 @@ int zend_may_throw(const zend_op *opline, const zend_ssa_op *ssa_op, const zend_
44044404
case ZEND_JMPNZ_EX:
44054405
case ZEND_BOOL:
44064406
case ZEND_JMP_SET:
4407+
case ZEND_JMP_NULL:
44074408
return (t1 & MAY_BE_OBJECT);
44084409
case ZEND_BOOL_XOR:
44094410
return (t1 & MAY_BE_OBJECT) || (t2 & MAY_BE_OBJECT);

ext/opcache/Optimizer/zend_optimizer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ void zend_optimizer_migrate_jump(zend_op_array *op_array, zend_op *new_opline, z
674674
case ZEND_JMP_SET:
675675
case ZEND_COALESCE:
676676
case ZEND_ASSERT_CHECK:
677+
case ZEND_JMP_NULL:
677678
ZEND_SET_OP_JMP_ADDR(new_opline, new_opline->op2, ZEND_OP2_JMP_ADDR(opline));
678679
break;
679680
case ZEND_FE_FETCH_R:
@@ -718,6 +719,7 @@ void zend_optimizer_shift_jump(zend_op_array *op_array, zend_op *opline, uint32_
718719
case ZEND_JMP_SET:
719720
case ZEND_COALESCE:
720721
case ZEND_ASSERT_CHECK:
722+
case ZEND_JMP_NULL:
721723
ZEND_SET_OP_JMP_ADDR(opline, opline->op2, ZEND_OP2_JMP_ADDR(opline) - shiftlist[ZEND_OP2_JMP_ADDR(opline) - op_array->opcodes]);
722724
break;
723725
case ZEND_CATCH:
@@ -1094,6 +1096,7 @@ static void zend_redo_pass_two(zend_op_array *op_array)
10941096
case ZEND_FE_RESET_R:
10951097
case ZEND_FE_RESET_RW:
10961098
case ZEND_ASSERT_CHECK:
1099+
case ZEND_JMP_NULL:
10971100
opline->op2.jmp_addr = &op_array->opcodes[opline->op2.jmp_addr - old_opcodes];
10981101
break;
10991102
case ZEND_CATCH:
@@ -1214,6 +1217,7 @@ static void zend_redo_pass_two_ex(zend_op_array *op_array, zend_ssa *ssa)
12141217
case ZEND_FE_RESET_R:
12151218
case ZEND_FE_RESET_RW:
12161219
case ZEND_ASSERT_CHECK:
1220+
case ZEND_JMP_NULL:
12171221
opline->op2.jmp_addr = &op_array->opcodes[opline->op2.jmp_addr - old_opcodes];
12181222
break;
12191223
case ZEND_CATCH:

ext/opcache/Optimizer/zend_ssa.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ static void place_essa_pis(
259259
switch (opline->opcode) {
260260
case ZEND_JMPZ:
261261
case ZEND_JMPZNZ:
262+
case ZEND_JMP_NULL:
262263
bf = blocks[j].successors[0];
263264
bt = blocks[j].successors[1];
264265
break;

ext/opcache/zend_file_cache.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
536536
case ZEND_FE_RESET_R:
537537
case ZEND_FE_RESET_RW:
538538
case ZEND_ASSERT_CHECK:
539+
case ZEND_JMP_NULL:
539540
SERIALIZE_PTR(opline->op2.jmp_addr);
540541
break;
541542
case ZEND_CATCH:
@@ -1287,6 +1288,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
12871288
case ZEND_FE_RESET_R:
12881289
case ZEND_FE_RESET_RW:
12891290
case ZEND_ASSERT_CHECK:
1291+
case ZEND_JMP_NULL:
12901292
UNSERIALIZE_PTR(opline->op2.jmp_addr);
12911293
break;
12921294
case ZEND_CATCH:

ext/opcache/zend_persist.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
538538
case ZEND_FE_RESET_R:
539539
case ZEND_FE_RESET_RW:
540540
case ZEND_ASSERT_CHECK:
541+
case ZEND_JMP_NULL:
541542
opline->op2.jmp_addr = &new_opcodes[opline->op2.jmp_addr - op_array->opcodes];
542543
break;
543544
case ZEND_CATCH:

0 commit comments

Comments
 (0)