Skip to content

Commit e502aed

Browse files
committed
Merge branch 'master' into jit-dynasm
2 parents 461d023 + d042d1d commit e502aed

File tree

11 files changed

+41
-42
lines changed

11 files changed

+41
-42
lines changed

ext/opcache/Optimizer/block_pass.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ void zend_optimize_cfg(zend_op_array *op_array, zend_optimizer_ctx *ctx)
18901890

18911891
/* Build CFG */
18921892
checkpoint = zend_arena_checkpoint(ctx->arena);
1893-
if (zend_build_cfg(&ctx->arena, op_array, ZEND_CFG_SPLIT_AT_LIVE_RANGES, &cfg, NULL) != SUCCESS) {
1893+
if (zend_build_cfg(&ctx->arena, op_array, ZEND_CFG_SPLIT_AT_LIVE_RANGES, &cfg) != SUCCESS) {
18941894
zend_arena_release(&ctx->arena, checkpoint);
18951895
return;
18961896
}

ext/opcache/Optimizer/dce.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ int dce_optimize_op_array(zend_op_array *op_array, zend_ssa *ssa, zend_bool reor
553553
int removed_ops = 0;
554554

555555
/* DCE of CV operations that changes arguments may affect vararg functions. */
556-
zend_bool has_varargs = ssa->cfg.vararg;
556+
zend_bool has_varargs = (ssa->cfg.flags & ZEND_FUNC_VARARG) != 0;
557557

558558
context ctx;
559559
ctx.ssa = ssa;

ext/opcache/Optimizer/dfa_pass.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# include "ssa_integrity.c"
4040
#endif
4141

42-
int zend_dfa_analyze_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa, uint32_t *flags)
42+
int zend_dfa_analyze_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa)
4343
{
4444
uint32_t build_flags;
4545

@@ -51,12 +51,11 @@ int zend_dfa_analyze_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx,
5151
/* Build SSA */
5252
memset(ssa, 0, sizeof(zend_ssa));
5353

54-
if (zend_build_cfg(&ctx->arena, op_array,
55-
ZEND_CFG_NO_ENTRY_PREDECESSORS, &ssa->cfg, flags) != SUCCESS) {
54+
if (zend_build_cfg(&ctx->arena, op_array, ZEND_CFG_NO_ENTRY_PREDECESSORS, &ssa->cfg) != SUCCESS) {
5655
return FAILURE;
5756
}
5857

59-
if (*flags & ZEND_FUNC_INDIRECT_VAR_ACCESS) {
58+
if ((ssa->cfg.flags & ZEND_FUNC_INDIRECT_VAR_ACCESS)) {
6059
/* TODO: we can't analyze functions with indirect variable access ??? */
6160
return FAILURE;
6261
}
@@ -75,7 +74,7 @@ int zend_dfa_analyze_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx,
7574
}
7675

7776
/* Identify reducible and irreducible loops */
78-
if (zend_cfg_identify_loops(op_array, &ssa->cfg, flags) != SUCCESS) {
77+
if (zend_cfg_identify_loops(op_array, &ssa->cfg) != SUCCESS) {
7978
return FAILURE;
8079
}
8180

@@ -90,7 +89,7 @@ int zend_dfa_analyze_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx,
9089
if (ctx->debug_level & ZEND_DUMP_DFA_PHI) {
9190
build_flags |= ZEND_SSA_DEBUG_PHI_PLACEMENT;
9291
}
93-
if (zend_build_ssa(&ctx->arena, ctx->script, op_array, build_flags, ssa, flags) != SUCCESS) {
92+
if (zend_build_ssa(&ctx->arena, ctx->script, op_array, build_flags, ssa) != SUCCESS) {
9493
return FAILURE;
9594
}
9695

@@ -1189,10 +1188,9 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
11891188
void zend_optimize_dfa(zend_op_array *op_array, zend_optimizer_ctx *ctx)
11901189
{
11911190
void *checkpoint = zend_arena_checkpoint(ctx->arena);
1192-
uint32_t flags = 0;
11931191
zend_ssa ssa;
11941192

1195-
if (zend_dfa_analyze_op_array(op_array, ctx, &ssa, &flags) != SUCCESS) {
1193+
if (zend_dfa_analyze_op_array(op_array, ctx, &ssa) != SUCCESS) {
11961194
zend_arena_release(&ctx->arena, checkpoint);
11971195
return;
11981196
}

ext/opcache/Optimizer/zend_cfg.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void zend_mark_reachable(zend_op *opcodes, zend_cfg *cfg, zend_basic_bloc
4848
} else {
4949
succ->flags |= ZEND_BB_FOLLOW;
5050

51-
if (cfg->split_at_calls) {
51+
if ((cfg->flags & ZEND_CFG_STACKLESS)) {
5252
if (opcode == ZEND_INCLUDE_OR_EVAL ||
5353
opcode == ZEND_GENERATOR_CREATE ||
5454
opcode == ZEND_YIELD ||
@@ -59,7 +59,7 @@ static void zend_mark_reachable(zend_op *opcodes, zend_cfg *cfg, zend_basic_bloc
5959
succ->flags |= ZEND_BB_ENTRY;
6060
}
6161
}
62-
if (cfg->split_at_recv) {
62+
if ((cfg->flags & ZEND_CFG_RECV_ENTRY)) {
6363
if (opcode == ZEND_RECV ||
6464
opcode == ZEND_RECV_INIT) {
6565
succ->flags |= ZEND_BB_RECV_ENTRY;
@@ -149,7 +149,7 @@ static void zend_mark_reachable_blocks(const zend_op_array *op_array, zend_cfg *
149149
b = blocks + block_map[live_range->end];
150150
b->flags |= ZEND_BB_KILL_VAR;
151151
if (!(b->flags & (ZEND_BB_REACHABLE|ZEND_BB_UNREACHABLE_FREE))) {
152-
if (cfg->split_at_live_ranges) {
152+
if ((cfg->flags & ZEND_CFG_SPLIT_AT_LIVE_RANGES)) {
153153
changed = 1;
154154
zend_mark_reachable(op_array->opcodes, cfg, b);
155155
} else {
@@ -282,7 +282,7 @@ static void initialize_block(zend_basic_block *block) {
282282
block_map[i]++; \
283283
} while (0)
284284

285-
int zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t build_flags, zend_cfg *cfg, uint32_t *func_flags) /* {{{ */
285+
int zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t build_flags, zend_cfg *cfg) /* {{{ */
286286
{
287287
uint32_t flags = 0;
288288
uint32_t i;
@@ -294,17 +294,15 @@ int zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t b
294294
zval *zv;
295295
zend_bool extra_entry_block = 0;
296296

297-
cfg->split_at_live_ranges = (build_flags & ZEND_CFG_SPLIT_AT_LIVE_RANGES) != 0;
298-
cfg->split_at_calls = (build_flags & ZEND_CFG_STACKLESS) != 0;
299-
cfg->split_at_recv = (build_flags & ZEND_CFG_RECV_ENTRY) != 0;
297+
cfg->flags = build_flags & (ZEND_CFG_SPLIT_AT_LIVE_RANGES|ZEND_CFG_STACKLESS|ZEND_CFG_RECV_ENTRY);
300298

301299
cfg->map = block_map = zend_arena_calloc(arena, op_array->last, sizeof(uint32_t));
302300

303301
/* Build CFG, Step 1: Find basic blocks starts, calculate number of blocks */
304302
BB_START(0);
305303
for (i = 0; i < op_array->last; i++) {
306304
zend_op *opline = op_array->opcodes + i;
307-
switch(opline->opcode) {
305+
switch (opline->opcode) {
308306
case ZEND_RECV:
309307
case ZEND_RECV_INIT:
310308
if (build_flags & ZEND_CFG_RECV_ENTRY) {
@@ -443,6 +441,12 @@ int zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t b
443441
case ZEND_FUNC_GET_ARGS:
444442
flags |= ZEND_FUNC_VARARG;
445443
break;
444+
case ZEND_EXT_NOP:
445+
case ZEND_EXT_STMT:
446+
case ZEND_EXT_FCALL_BEGIN:
447+
case ZEND_EXT_FCALL_END:
448+
flags |= ZEND_FUNC_HAS_EXTENDED_INFO;
449+
break;
446450
}
447451
}
448452

@@ -452,7 +456,7 @@ int zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t b
452456
extra_entry_block = 1;
453457
}
454458

455-
if (cfg->split_at_live_ranges) {
459+
if ((cfg->flags & ZEND_CFG_SPLIT_AT_LIVE_RANGES)) {
456460
for (j = 0; j < op_array->last_live_range; j++) {
457461
BB_START(op_array->live_range[j].start);
458462
BB_START(op_array->live_range[j].end);
@@ -600,12 +604,7 @@ int zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t b
600604
/* Build CFG, Step 4, Mark Reachable Basic Blocks */
601605
zend_mark_reachable_blocks(op_array, cfg, 0);
602606

603-
cfg->dynamic = (flags & ZEND_FUNC_INDIRECT_VAR_ACCESS) != 0;
604-
cfg->vararg = (flags & ZEND_FUNC_VARARG) != 0;
605-
606-
if (func_flags) {
607-
*func_flags |= flags;
608-
}
607+
cfg->flags |= flags;
609608

610609
return SUCCESS;
611610
}
@@ -807,7 +806,7 @@ static void swap_blocks(block_info *a, block_info *b) {
807806
*b = tmp;
808807
}
809808

810-
int zend_cfg_identify_loops(const zend_op_array *op_array, zend_cfg *cfg, uint32_t *flags) /* {{{ */
809+
int zend_cfg_identify_loops(const zend_op_array *op_array, zend_cfg *cfg) /* {{{ */
811810
{
812811
int i, j, k, n;
813812
int time;
@@ -913,7 +912,8 @@ int zend_cfg_identify_loops(const zend_op_array *op_array, zend_cfg *cfg, uint32
913912
free_alloca(sorted_blocks, sorted_blocks_use_heap);
914913
free_alloca(entry_times, tree_use_heap);
915914
ZEND_WORKLIST_FREE_ALLOCA(&work, list_use_heap);
916-
*flags |= flag;
915+
916+
cfg->flags |= flag;
917917

918918
return SUCCESS;
919919
}

ext/opcache/Optimizer/zend_cfg.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ typedef struct _zend_cfg {
9090
zend_basic_block *blocks; /* array of basic blocks */
9191
int *predecessors;
9292
uint32_t *map;
93-
unsigned int split_at_live_ranges : 1;
94-
unsigned int split_at_calls : 1;
95-
unsigned int split_at_recv : 1;
96-
unsigned int dynamic : 1; /* accesses varables by name */
97-
unsigned int vararg : 1; /* uses func_get_args() */
93+
uint32_t flags;
9894
} zend_cfg;
9995

10096
/* Build Flags */
@@ -124,11 +120,11 @@ typedef struct _zend_cfg {
124120

125121
BEGIN_EXTERN_C()
126122

127-
int zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t build_flags, zend_cfg *cfg, uint32_t *func_flags);
123+
int zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t build_flags, zend_cfg *cfg);
128124
void zend_cfg_remark_reachable_blocks(const zend_op_array *op_array, zend_cfg *cfg);
129125
int zend_cfg_build_predecessors(zend_arena **arena, zend_cfg *cfg);
130126
int zend_cfg_compute_dominators_tree(const zend_op_array *op_array, zend_cfg *cfg);
131-
int zend_cfg_identify_loops(const zend_op_array *op_array, zend_cfg *cfg, uint32_t *flags);
127+
int zend_cfg_identify_loops(const zend_op_array *op_array, zend_cfg *cfg);
132128

133129
END_EXTERN_C()
134130

ext/opcache/Optimizer/zend_dump.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,9 @@ void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_flags, cons
895895
if (func_flags & ZEND_FUNC_NO_LOOPS) {
896896
fprintf(stderr, ", no_loops");
897897
}
898+
if (func_flags & ZEND_FUNC_HAS_EXTENDED_INFO) {
899+
fprintf(stderr, ", extended_info");
900+
}
898901
//TODO: this is useful only for JIT???
899902
#if 0
900903
if (info->flags & ZEND_JIT_FUNC_NO_IN_MEM_CVS) {
@@ -972,7 +975,7 @@ void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_flags, cons
972975
if (op_array->last_live_range) {
973976
fprintf(stderr, "LIVE RANGES:\n");
974977
for (i = 0; i < op_array->last_live_range; i++) {
975-
if (cfg->split_at_live_ranges) {
978+
if ((cfg->flags & ZEND_CFG_SPLIT_AT_LIVE_RANGES)) {
976979
fprintf(stderr, " %u: BB%u - BB%u ",
977980
EX_VAR_TO_NUM(op_array->live_range[i].var & ~ZEND_LIVE_MASK),
978981
cfg->map[op_array->live_range[i].start],

ext/opcache/Optimizer/zend_func_info.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
#include "zend_ssa.h"
2323

2424
/* func flags */
25-
#define ZEND_FUNC_INDIRECT_VAR_ACCESS (1<<0)
25+
#define ZEND_FUNC_INDIRECT_VAR_ACCESS (1<<0) /* accesses varables by name */
2626
#define ZEND_FUNC_HAS_CALLS (1<<1)
27-
#define ZEND_FUNC_VARARG (1<<2)
27+
#define ZEND_FUNC_VARARG (1<<2) /* uses func_get_args() */
2828
#define ZEND_FUNC_NO_LOOPS (1<<3)
2929
#define ZEND_FUNC_IRREDUCIBLE (1<<4)
3030
#define ZEND_FUNC_RECURSIVE (1<<7)
3131
#define ZEND_FUNC_RECURSIVE_DIRECTLY (1<<8)
3232
#define ZEND_FUNC_RECURSIVE_INDIRECTLY (1<<9)
33+
#define ZEND_FUNC_HAS_EXTENDED_INFO (1<<10)
3334

3435
/* The following flags are valid only for return values of internal functions
3536
* returned by zend_get_func_info()

ext/opcache/Optimizer/zend_optimizer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,8 @@ int zend_optimize_script(zend_script *script, zend_long optimization_level, zend
13651365
for (i = 0; i < call_graph.op_arrays_count; i++) {
13661366
func_info = ZEND_FUNC_INFO(call_graph.op_arrays[i]);
13671367
if (func_info) {
1368-
zend_dfa_analyze_op_array(call_graph.op_arrays[i], &ctx, &func_info->ssa, &func_info->flags);
1368+
zend_dfa_analyze_op_array(call_graph.op_arrays[i], &ctx, &func_info->ssa);
1369+
func_info->flags = func_info->ssa.cfg.flags;
13691370
}
13701371
}
13711372

ext/opcache/Optimizer/zend_optimizer_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void zend_optimizer_pass3(zend_op_array *op_array);
9999
void zend_optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx);
100100
void zend_optimize_cfg(zend_op_array *op_array, zend_optimizer_ctx *ctx);
101101
void zend_optimize_dfa(zend_op_array *op_array, zend_optimizer_ctx *ctx);
102-
int zend_dfa_analyze_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa, uint32_t *flags);
102+
int zend_dfa_analyze_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa);
103103
void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa, zend_call_info **call_map);
104104
void zend_optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_ctx *ctx);
105105
void zend_optimizer_nop_removal(zend_op_array *op_array);

ext/opcache/Optimizer/zend_ssa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ static int zend_ssa_rename(const zend_op_array *op_array, uint32_t build_flags,
859859
}
860860
/* }}} */
861861

862-
int zend_build_ssa(zend_arena **arena, const zend_script *script, const zend_op_array *op_array, uint32_t build_flags, zend_ssa *ssa, uint32_t *func_flags) /* {{{ */
862+
int zend_build_ssa(zend_arena **arena, const zend_script *script, const zend_op_array *op_array, uint32_t build_flags, zend_ssa *ssa) /* {{{ */
863863
{
864864
zend_basic_block *blocks = ssa->cfg.blocks;
865865
zend_ssa_block *ssa_blocks;
@@ -1115,7 +1115,7 @@ int zend_ssa_compute_use_def_chains(zend_arena **arena, const zend_op_array *op_
11151115

11161116
/* Mark indirectly accessed variables */
11171117
for (i = 0; i < op_array->last_var; i++) {
1118-
if (ssa->cfg.dynamic) {
1118+
if ((ssa->cfg.flags & ZEND_FUNC_INDIRECT_VAR_ACCESS)) {
11191119
ssa_vars[i].alias = SYMTABLE_ALIAS;
11201120
} else if (zend_string_equals_literal(op_array->vars[i], "php_errormsg")) {
11211121
ssa_vars[i].alias = PHP_ERRORMSG_ALIAS;

0 commit comments

Comments
 (0)