Skip to content

Commit af3142d

Browse files
committed
Make SSA dump format controlled by opcache.jit_debug more readable (always print opcode number).
This doesn't affect dumps controlled by opcache.opt_debug_level.
1 parent c5fe1a1 commit af3142d

File tree

3 files changed

+104
-41
lines changed

3 files changed

+104
-41
lines changed

ext/opcache/Optimizer/zend_dump.c

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,10 @@ void zend_dump_op(const zend_op_array *op_array, const zend_basic_block *b, cons
603603
} else {
604604
uint32_t op1_flags = ZEND_VM_OP1_FLAGS(flags);
605605
if (ZEND_VM_OP_JMP_ADDR == (op1_flags & ZEND_VM_OP_MASK)) {
606-
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
607-
fprintf(stderr, " %04u", (uint32_t)(OP_JMP_ADDR(opline, opline->op1) - op_array->opcodes));
608-
} else if (b) {
606+
if (b) {
609607
fprintf(stderr, " BB%d", b->successors[n++]);
608+
} else if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
609+
fprintf(stderr, " %04u", (uint32_t)(OP_JMP_ADDR(opline, opline->op1) - op_array->opcodes));
610610
} else {
611611
fprintf(stderr, " L%u", (uint32_t)(OP_JMP_ADDR(opline, opline->op1) - op_array->opcodes));
612612
}
@@ -628,10 +628,10 @@ void zend_dump_op(const zend_op_array *op_array, const zend_basic_block *b, cons
628628
} else {
629629
fprintf(stderr, " " ZEND_LONG_FMT ":", num_key);
630630
}
631-
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
632-
fprintf(stderr, " %04u,", (uint32_t)ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv)));
633-
} else if (b) {
631+
if (b) {
634632
fprintf(stderr, " BB%d,", b->successors[n++]);
633+
} else if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
634+
fprintf(stderr, " %04u,", (uint32_t)ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv)));
635635
} else {
636636
fprintf(stderr, " L%u,", (uint32_t)ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv)));
637637
}
@@ -665,10 +665,10 @@ void zend_dump_op(const zend_op_array *op_array, const zend_basic_block *b, cons
665665
uint32_t op2_flags = ZEND_VM_OP2_FLAGS(flags);
666666
if (ZEND_VM_OP_JMP_ADDR == (op2_flags & ZEND_VM_OP_MASK)) {
667667
if (opline->opcode != ZEND_CATCH || !(opline->extended_value & ZEND_LAST_CATCH)) {
668-
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
669-
fprintf(stderr, " %04u", (uint32_t)(OP_JMP_ADDR(opline, opline->op2) - op_array->opcodes));
670-
} else if (b) {
668+
if (b) {
671669
fprintf(stderr, " BB%d", b->successors[n++]);
670+
} else if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
671+
fprintf(stderr, " %04u", (uint32_t)(OP_JMP_ADDR(opline, opline->op2) - op_array->opcodes));
672672
} else {
673673
fprintf(stderr, " L%u", (uint32_t)(OP_JMP_ADDR(opline, opline->op2) - op_array->opcodes));
674674
}
@@ -679,10 +679,10 @@ void zend_dump_op(const zend_op_array *op_array, const zend_basic_block *b, cons
679679
}
680680

681681
if (ZEND_VM_EXT_JMP_ADDR == (flags & ZEND_VM_EXT_MASK)) {
682-
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
683-
fprintf(stderr, " %04u", (uint32_t)ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value));
684-
} else if (b) {
682+
if (b) {
685683
fprintf(stderr, " BB%d", b->successors[n++]);
684+
} else if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
685+
fprintf(stderr, " %04u", (uint32_t)ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value));
686686
} else {
687687
fprintf(stderr, " L%u", (uint32_t)ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value));
688688
}
@@ -725,11 +725,14 @@ static void zend_dump_op_line(const zend_op_array *op_array, const zend_basic_bl
725725
zend_ssa_op *ssa_op = NULL;
726726

727727
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
728-
len = fprintf(stderr, "%04u:", (uint32_t)(opline - op_array->opcodes));
728+
len = fprintf(stderr, "%04u", (uint32_t)(opline - op_array->opcodes));
729+
fprintf(stderr, "%*c", 5-len, ' ');
729730
} else if (!b) {
730731
len = fprintf(stderr, "L%u (%u):", (uint32_t)(opline - op_array->opcodes), opline->lineno);
732+
fprintf(stderr, "%*c", 12-len, ' ');
733+
} else {
734+
fprintf(stderr, "%*c", 12-len, ' ');
731735
}
732-
fprintf(stderr, "%*c", 12-len, ' ');
733736

734737
if (dump_flags & ZEND_DUMP_SSA) {
735738
ssa = (const zend_ssa*)data;
@@ -747,6 +750,9 @@ static void zend_dump_block_info(const zend_cfg *cfg, int n, uint32_t dump_flags
747750
zend_basic_block *b = cfg->blocks + n;
748751

749752
fprintf(stderr, "BB%d:", n);
753+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
754+
fprintf(stderr, "\n ;");
755+
}
750756
if (b->flags & ZEND_BB_START) {
751757
fprintf(stderr, " start");
752758
}
@@ -800,6 +806,9 @@ static void zend_dump_block_info(const zend_cfg *cfg, int n, uint32_t dump_flags
800806
int *p = cfg->predecessors + b->predecessor_offset;
801807
int *end = p + b->predecessors_count;
802808

809+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
810+
fprintf(stderr, " ");
811+
}
803812
fprintf(stderr, " ; from=(BB%d", *p);
804813
for (p++; p < end; p++) {
805814
fprintf(stderr, ", BB%d", *p);
@@ -809,6 +818,9 @@ static void zend_dump_block_info(const zend_cfg *cfg, int n, uint32_t dump_flags
809818

810819
if (b->successors_count > 0) {
811820
int s;
821+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
822+
fprintf(stderr, " ");
823+
}
812824
fprintf(stderr, " ; to=(BB%d", b->successors[0]);
813825
for (s = 1; s < b->successors_count; s++) {
814826
fprintf(stderr, ", BB%d", b->successors[s]);
@@ -817,16 +829,28 @@ static void zend_dump_block_info(const zend_cfg *cfg, int n, uint32_t dump_flags
817829
}
818830

819831
if (b->idom >= 0) {
832+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
833+
fprintf(stderr, " ");
834+
}
820835
fprintf(stderr, " ; idom=BB%d\n", b->idom);
821836
}
822837
if (b->level >= 0) {
838+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
839+
fprintf(stderr, " ");
840+
}
823841
fprintf(stderr, " ; level=%d\n", b->level);
824842
}
825843
if (b->loop_header >= 0) {
844+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
845+
fprintf(stderr, " ");
846+
}
826847
fprintf(stderr, " ; loop_header=%d\n", b->loop_header);
827848
}
828849
if (b->children >= 0) {
829850
int j = b->children;
851+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
852+
fprintf(stderr, " ");
853+
}
830854
fprintf(stderr, " ; children=(BB%d", j);
831855
j = cfg->blocks[j].next_child;
832856
while (j >= 0) {
@@ -846,7 +870,11 @@ static void zend_dump_block_header(const zend_cfg *cfg, const zend_op_array *op_
846870
do {
847871
int j;
848872

849-
fprintf(stderr, " ");
873+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
874+
fprintf(stderr, " ");
875+
} else {
876+
fprintf(stderr, " ");
877+
}
850878
zend_dump_ssa_var(op_array, ssa, p->ssa_var, 0, p->var, dump_flags);
851879
if (p->pi < 0) {
852880
fprintf(stderr, " = Phi(");
@@ -917,7 +945,11 @@ void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_flags, cons
917945

918946
fprintf(stderr, "\n");
919947
zend_dump_op_array_name(op_array);
920-
fprintf(stderr, ": ; (lines=%d, args=%d",
948+
fprintf(stderr, ":");
949+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
950+
fprintf(stderr, "\n ");
951+
}
952+
fprintf(stderr, " ; (lines=%d, args=%d",
921953
op_array->last,
922954
op_array->num_args);
923955
if (func_info && func_info->num_args >= 0) {
@@ -976,14 +1008,23 @@ void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_flags, cons
9761008
}
9771009
fprintf(stderr, ")\n");
9781010
if (msg) {
1011+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
1012+
fprintf(stderr, " ");
1013+
}
9791014
fprintf(stderr, " ; (%s)\n", msg);
9801015
}
1016+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
1017+
fprintf(stderr, " ");
1018+
}
9811019
fprintf(stderr, " ; %s:%u-%u\n", op_array->filename->val, op_array->line_start, op_array->line_end);
9821020

9831021
if (func_info && func_info->num_args > 0) {
9841022
uint32_t j;
9851023

9861024
for (j = 0; j < MIN(op_array->num_args, func_info->num_args ); j++) {
1025+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
1026+
fprintf(stderr, " ");
1027+
}
9871028
fprintf(stderr, " ; arg %d ", j);
9881029
zend_dump_type_info(func_info->arg_info[j].info.type, func_info->arg_info[j].info.ce, func_info->arg_info[j].info.is_instanceof, dump_flags);
9891030
zend_dump_range(&func_info->arg_info[j].info.range);
@@ -992,6 +1033,9 @@ void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_flags, cons
9921033
}
9931034

9941035
if (func_info) {
1036+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
1037+
fprintf(stderr, " ");
1038+
}
9951039
fprintf(stderr, " ; return ");
9961040
zend_dump_type_info(func_info->return_info.type, func_info->return_info.ce, func_info->return_info.is_instanceof, dump_flags);
9971041
zend_dump_range(&func_info->return_info.range);
@@ -1000,6 +1044,9 @@ void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_flags, cons
10001044

10011045
if (ssa && ssa->var_info) {
10021046
for (i = 0; i < op_array->last_var; i++) {
1047+
if (dump_flags & ZEND_DUMP_NUMERIC_OPLINES) {
1048+
fprintf(stderr, " ");
1049+
}
10031050
fprintf(stderr, " ; ");
10041051
zend_dump_ssa_var(op_array, ssa, i, IS_CV, i, dump_flags);
10051052
fprintf(stderr, "\n");

ext/opcache/jit/zend_jit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3066,7 +3066,7 @@ static int zend_real_jit_func(zend_op_array *op_array, zend_script *script, cons
30663066
}
30673067

30683068
if (ZCG(accel_directives).jit_debug & ZEND_JIT_DEBUG_SSA) {
3069-
zend_dump_op_array(op_array, ZEND_DUMP_HIDE_UNREACHABLE|ZEND_DUMP_RC_INFERENCE|ZEND_DUMP_SSA, "JIT", &ssa);
3069+
zend_dump_op_array(op_array, ZEND_DUMP_NUMERIC_OPLINES|ZEND_DUMP_HIDE_UNREACHABLE|ZEND_DUMP_RC_INFERENCE|ZEND_DUMP_SSA, "JIT", &ssa);
30703070
}
30713071

30723072
if (zend_jit(op_array, &ssa, rt_opline) != SUCCESS) {
@@ -3380,7 +3380,7 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
33803380
}
33813381
info = ZEND_FUNC_INFO(call_graph.op_arrays[i]);
33823382
if (info) {
3383-
zend_dump_op_array(call_graph.op_arrays[i], ZEND_DUMP_HIDE_UNREACHABLE|ZEND_DUMP_RC_INFERENCE|ZEND_DUMP_SSA, "JIT", &info->ssa);
3383+
zend_dump_op_array(call_graph.op_arrays[i], ZEND_DUMP_NUMERIC_OPLINES|ZEND_DUMP_HIDE_UNREACHABLE|ZEND_DUMP_RC_INFERENCE|ZEND_DUMP_SSA, "JIT", &info->ssa);
33843384
}
33853385
}
33863386
}

ext/opcache/jit/zend_jit_trace.c

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ static const void **zend_jit_exit_groups = NULL;
2424
#define ZEND_JIT_EXIT_NUM zend_jit_traces[0].exit_count
2525
#define ZEND_JIT_EXIT_COUNTERS zend_jit_traces[0].exit_counters
2626

27+
#define ZEND_JIT_TRACE_STOP_DESCRIPTION(name, description) \
28+
description,
29+
30+
static const char * zend_jit_trace_stop_description[] = {
31+
ZEND_JIT_TRACE_STOP(ZEND_JIT_TRACE_STOP_DESCRIPTION)
32+
};
33+
34+
static zend_always_inline const char *zend_jit_trace_star_desc(uint8_t trace_flags)
35+
{
36+
if (trace_flags & ZEND_JIT_TRACE_START_LOOP) {
37+
return "loop";
38+
} else if (trace_flags & ZEND_JIT_TRACE_START_ENTER) {
39+
return "enter";
40+
} else if (trace_flags & ZEND_JIT_TRACE_START_RETURN) {
41+
return "return";
42+
} else {
43+
ZEND_ASSERT(0);
44+
return "???";
45+
}
46+
}
47+
2748
static int zend_jit_trace_startup(void)
2849
{
2950
zend_jit_traces = (zend_jit_trace_info*)zend_shared_alloc(sizeof(zend_jit_trace_info) * ZEND_JIT_TRACE_MAX_TRACES);
@@ -424,7 +445,7 @@ static zend_ssa *zend_jit_trace_build_ssa(const zend_op_array *op_array, zend_sc
424445
}
425446

426447
if (ZCG(accel_directives).jit_debug & ZEND_JIT_DEBUG_SSA) {
427-
zend_dump_op_array(op_array, ZEND_DUMP_HIDE_UNREACHABLE|ZEND_DUMP_RC_INFERENCE|ZEND_DUMP_SSA, "JIT", ssa);
448+
zend_dump_op_array(op_array, ZEND_DUMP_NUMERIC_OPLINES|ZEND_DUMP_HIDE_UNREACHABLE|ZEND_DUMP_RC_INFERENCE|ZEND_DUMP_SSA, "JIT", ssa);
428449
}
429450
return ssa;
430451
} while (0);
@@ -1620,8 +1641,24 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
16201641
}
16211642

16221643
if (UNEXPECTED(ZCG(accel_directives).jit_debug & ZEND_JIT_DEBUG_TRACE_TSSA)) {
1644+
fprintf(stderr, "---- TRACE %d TSSA start (%s) %s() %s:%d\n",
1645+
ZEND_JIT_TRACE_NUM,
1646+
zend_jit_trace_star_desc(trace_buffer->start),
1647+
trace_buffer->op_array->function_name ?
1648+
ZSTR_VAL(trace_buffer->op_array->function_name) : "$main",
1649+
ZSTR_VAL(trace_buffer->op_array->filename),
1650+
((zend_jit_trace_start_rec*)trace_buffer)->opline->lineno);
16231651
zend_jit_dump_trace(trace_buffer, tssa);
1624-
fprintf(stderr, "---- TRACE analysed\n");
1652+
if (trace_buffer->stop == ZEND_JIT_TRACE_STOP_LINK) {
1653+
uint32_t link_to = zend_jit_find_trace(EG(current_execute_data)->opline->handler);;
1654+
fprintf(stderr, "---- TRACE %d TSSA stop (link to %d)\n",
1655+
ZEND_JIT_TRACE_NUM,
1656+
link_to);
1657+
} else {
1658+
fprintf(stderr, "---- TRACE %d TSSA stop (%s)\n",
1659+
ZEND_JIT_TRACE_NUM,
1660+
zend_jit_trace_stop_description[trace_buffer->stop]);
1661+
}
16251662
}
16261663

16271664
return tssa;
@@ -3267,13 +3304,6 @@ static zend_bool zend_jit_trace_is_bad_root(const zend_op *opline, zend_jit_trac
32673304
return 0;
32683305
}
32693306

3270-
#define ZEND_JIT_TRACE_STOP_DESCRIPTION(name, description) \
3271-
description,
3272-
3273-
static const char * zend_jit_trace_stop_description[] = {
3274-
ZEND_JIT_TRACE_STOP(ZEND_JIT_TRACE_STOP_DESCRIPTION)
3275-
};
3276-
32773307
static void zend_jit_dump_trace(zend_jit_trace_rec *trace_buffer, zend_ssa *tssa)
32783308
{
32793309
zend_jit_trace_rec *p = trace_buffer;
@@ -3455,20 +3485,6 @@ static void zend_jit_dump_trace(zend_jit_trace_rec *trace_buffer, zend_ssa *tssa
34553485
}
34563486
}
34573487

3458-
static zend_always_inline const char *zend_jit_trace_star_desc(uint8_t trace_flags)
3459-
{
3460-
if (trace_flags & ZEND_JIT_TRACE_START_LOOP) {
3461-
return "loop";
3462-
} else if (trace_flags & ZEND_JIT_TRACE_START_ENTER) {
3463-
return "enter";
3464-
} else if (trace_flags & ZEND_JIT_TRACE_START_RETURN) {
3465-
return "return";
3466-
} else {
3467-
ZEND_ASSERT(0);
3468-
return "???";
3469-
}
3470-
}
3471-
34723488
int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const zend_op *opline)
34733489
{
34743490
const zend_op *orig_opline;

0 commit comments

Comments
 (0)