From c9034c3b3344287a1a636e43dbcb781bcfbd31af Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 11 Jan 2018 19:15:52 +0300 Subject: Get rid of zend_op_array.early_binding --- ext/opcache/Optimizer/block_pass.c | 22 ++++++---------------- ext/opcache/Optimizer/dfa_pass.c | 9 +++++---- ext/opcache/Optimizer/nop_removal.c | 7 ++++--- ext/opcache/Optimizer/zend_optimizer.c | 2 +- ext/opcache/Optimizer/zend_optimizer.h | 1 + ext/opcache/Optimizer/zend_optimizer_internal.h | 2 +- ext/opcache/ZendAccelerator.c | 4 ++++ ext/opcache/zend_accelerator_util_funcs.c | 4 ++-- 8 files changed, 24 insertions(+), 27 deletions(-) (limited to 'ext/opcache') diff --git a/ext/opcache/Optimizer/block_pass.c b/ext/opcache/Optimizer/block_pass.c index 8207eafa81..da4f7e5902 100644 --- a/ext/opcache/Optimizer/block_pass.c +++ b/ext/opcache/Optimizer/block_pass.c @@ -876,7 +876,7 @@ optimize_const_unary_op: } /* Rebuild plain (optimized) op_array from CFG */ -static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array) +static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array, zend_optimizer_ctx *ctx) { zend_basic_block *blocks = cfg->blocks; zend_basic_block *end = blocks + cfg->blocks_count; @@ -1093,20 +1093,10 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array) } /* adjust early binding list */ - if (op_array->early_binding != (uint32_t)-1) { - uint32_t *opline_num = &op_array->early_binding; - zend_op *end; - - opline = op_array->opcodes; - end = opline + op_array->last; - while (opline < end) { - if (opline->opcode == ZEND_DECLARE_INHERITED_CLASS_DELAYED) { - *opline_num = opline - op_array->opcodes; - opline_num = &opline->result.opline_num; - } - ++opline; - } - *opline_num = -1; + if (op_array->fn_flags & ZEND_ACC_EARLY_BINDING) { + ZEND_ASSERT(op_array == &ctx->script->main_op_array); + ctx->script->first_early_binding_opline = + zend_build_delayed_early_binding_list(op_array); } /* rebuild map (just for printing) */ @@ -1953,7 +1943,7 @@ void zend_optimize_cfg(zend_op_array *op_array, zend_optimizer_ctx *ctx) zend_bitset_clear(usage, bitset_len); zend_t_usage(&cfg, op_array, usage, ctx); - assemble_code_blocks(&cfg, op_array); + assemble_code_blocks(&cfg, op_array, ctx); if (ctx->debug_level & ZEND_DUMP_AFTER_BLOCK_PASS) { zend_dump_op_array(op_array, ZEND_DUMP_CFG | ZEND_DUMP_HIDE_UNREACHABLE, "after block pass", &cfg); diff --git a/ext/opcache/Optimizer/dfa_pass.c b/ext/opcache/Optimizer/dfa_pass.c index 61047e8064..f24d407eeb 100644 --- a/ext/opcache/Optimizer/dfa_pass.c +++ b/ext/opcache/Optimizer/dfa_pass.c @@ -125,7 +125,7 @@ int zend_dfa_analyze_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, return SUCCESS; } -static void zend_ssa_remove_nops(zend_op_array *op_array, zend_ssa *ssa) +static void zend_ssa_remove_nops(zend_op_array *op_array, zend_ssa *ssa, zend_optimizer_ctx *ctx) { zend_basic_block *blocks = ssa->cfg.blocks; zend_basic_block *end = blocks + ssa->cfg.blocks_count; @@ -263,9 +263,10 @@ static void zend_ssa_remove_nops(zend_op_array *op_array, zend_ssa *ssa) } /* update early binding list */ - if (op_array->early_binding != (uint32_t)-1) { - uint32_t *opline_num = &op_array->early_binding; + if (op_array->fn_flags & ZEND_ACC_EARLY_BINDING) { + uint32_t *opline_num = &ctx->script->first_early_binding_opline; + ZEND_ASSERT(op_array == &ctx->script->main_op_array); do { *opline_num -= shiftlist[*opline_num]; opline_num = &op_array->opcodes[*opline_num].result.opline_num; @@ -1177,7 +1178,7 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx #endif if (remove_nops) { - zend_ssa_remove_nops(op_array, ssa); + zend_ssa_remove_nops(op_array, ssa, ctx); #if ZEND_DEBUG_DFA ssa_verify_integrity(op_array, ssa, "after nop"); #endif diff --git a/ext/opcache/Optimizer/nop_removal.c b/ext/opcache/Optimizer/nop_removal.c index 9d8377cedc..c7ecad4d0e 100644 --- a/ext/opcache/Optimizer/nop_removal.c +++ b/ext/opcache/Optimizer/nop_removal.c @@ -31,7 +31,7 @@ #include "zend_execute.h" #include "zend_vm.h" -void zend_optimizer_nop_removal(zend_op_array *op_array) +void zend_optimizer_nop_removal(zend_op_array *op_array, zend_optimizer_ctx *ctx) { zend_op *end, *opline; uint32_t new_count, i, shift; @@ -98,9 +98,10 @@ void zend_optimizer_nop_removal(zend_op_array *op_array) } /* update early binding list */ - if (op_array->early_binding != (uint32_t)-1) { - uint32_t *opline_num = &op_array->early_binding; + if (op_array->fn_flags & ZEND_ACC_EARLY_BINDING) { + uint32_t *opline_num = &ctx->script->first_early_binding_opline; + ZEND_ASSERT(op_array == &ctx->script->main_op_array); do { *opline_num -= shiftlist[*opline_num]; opline_num = &op_array->opcodes[*opline_num].result.opline_num; diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c index d5975f1414..a5ac88651c 100644 --- a/ext/opcache/Optimizer/zend_optimizer.c +++ b/ext/opcache/Optimizer/zend_optimizer.c @@ -1055,7 +1055,7 @@ static void zend_optimize(zend_op_array *op_array, * - remove NOPs */ if (((ZEND_OPTIMIZER_PASS_10|ZEND_OPTIMIZER_PASS_5) & ctx->optimization_level) == ZEND_OPTIMIZER_PASS_10) { - zend_optimizer_nop_removal(op_array); + zend_optimizer_nop_removal(op_array, ctx); if (ctx->debug_level & ZEND_DUMP_AFTER_PASS_10) { zend_dump_op_array(op_array, 0, "after pass 10", NULL); } diff --git a/ext/opcache/Optimizer/zend_optimizer.h b/ext/opcache/Optimizer/zend_optimizer.h index 27b7cedd38..e1c96bec45 100644 --- a/ext/opcache/Optimizer/zend_optimizer.h +++ b/ext/opcache/Optimizer/zend_optimizer.h @@ -84,6 +84,7 @@ typedef struct _zend_script { zend_op_array main_op_array; HashTable function_table; HashTable class_table; + uint32_t first_early_binding_opline; /* the linked list of delayed declarations */ } zend_script; int zend_optimize_script(zend_script *script, zend_long optimization_level, zend_long debug_level); diff --git a/ext/opcache/Optimizer/zend_optimizer_internal.h b/ext/opcache/Optimizer/zend_optimizer_internal.h index 07decce3b4..914e6e717a 100644 --- a/ext/opcache/Optimizer/zend_optimizer_internal.h +++ b/ext/opcache/Optimizer/zend_optimizer_internal.h @@ -102,7 +102,7 @@ void zend_optimize_dfa(zend_op_array *op_array, zend_optimizer_ctx *ctx); int zend_dfa_analyze_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa); void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa, zend_call_info **call_map); void zend_optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_ctx *ctx); -void zend_optimizer_nop_removal(zend_op_array *op_array); +void zend_optimizer_nop_removal(zend_op_array *op_array, zend_optimizer_ctx *ctx); void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx *ctx); void zend_optimizer_compact_vars(zend_op_array *op_array); int zend_optimizer_is_disabled_func(const char *name, size_t len); diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 347b5d6ed4..aa84b318c3 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -1723,6 +1723,10 @@ static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handl further anyway. */ zend_accel_move_user_functions(&ZCG(function_table), &new_persistent_script->script.function_table); + new_persistent_script->script.first_early_binding_opline = + (op_array->fn_flags & ZEND_ACC_EARLY_BINDING) ? + zend_build_delayed_early_binding_list(op_array) : + (uint32_t)-1; new_persistent_script->script.main_op_array = *op_array; efree(op_array); /* we have valid persistent_script, so it's safe to free op_array */ diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c index ce0c8f4ada..1e9b5e9868 100644 --- a/ext/opcache/zend_accelerator_util_funcs.c +++ b/ext/opcache/zend_accelerator_util_funcs.c @@ -733,10 +733,10 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script, } } - if (op_array->early_binding != (uint32_t)-1) { + if (persistent_script->script.first_early_binding_opline != (uint32_t)-1) { zend_string *orig_compiled_filename = CG(compiled_filename); CG(compiled_filename) = persistent_script->script.filename; - zend_do_delayed_early_binding(op_array); + zend_do_delayed_early_binding(op_array, persistent_script->script.first_early_binding_opline); CG(compiled_filename) = orig_compiled_filename; } -- cgit v1.2.1