Skip to content

Commit f9ee036

Browse files
committed
ext/opcache/jit/trace: split zend_jit_trace_frame_size()
1 parent a5e4f8b commit f9ee036

File tree

1 file changed

+48
-33
lines changed

1 file changed

+48
-33
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -451,25 +451,40 @@ static zend_always_inline void zend_jit_trace_add_op_guard(zend_ssa
451451
#define CHECK_OP1_DATA_TRACE_TYPE() \
452452
CHECK_OP_TRACE_TYPE((opline+1)->op1.var, (ssa_op+1)->op1_use, op1_data_info, op3_type)
453453

454-
static zend_always_inline size_t zend_jit_trace_frame_size(const zend_op_array *op_array)
454+
static zend_always_inline size_t zend_jit_trace_op_array_frame_size(const zend_op_array *op_array)
455455
{
456-
if (op_array && op_array->type == ZEND_USER_FUNCTION) {
456+
if (op_array) {
457+
assert(op_array->type == ZEND_USER_FUNCTION);
457458
return ZEND_MM_ALIGNED_SIZE(offsetof(zend_jit_trace_stack_frame, stack) + ZEND_MM_ALIGNED_SIZE((op_array->last_var + op_array->T) * sizeof(zend_jit_trace_stack)));
458-
} else if (op_array) {
459-
return ZEND_MM_ALIGNED_SIZE(offsetof(zend_jit_trace_stack_frame, stack) + ZEND_MM_ALIGNED_SIZE(op_array->num_args * sizeof(zend_jit_trace_stack)));
460459
} else {
461460
return ZEND_MM_ALIGNED_SIZE(offsetof(zend_jit_trace_stack_frame, stack));
462461
}
463462
}
464463

465-
static zend_jit_trace_stack_frame* zend_jit_trace_call_frame(zend_jit_trace_stack_frame *frame, const zend_op_array *op_array)
464+
static zend_always_inline size_t zend_jit_trace_function_frame_size(const zend_function *func)
466465
{
467-
return (zend_jit_trace_stack_frame*)((char*)frame + zend_jit_trace_frame_size(op_array));
466+
if (func && func->type == ZEND_USER_FUNCTION) {
467+
return zend_jit_trace_op_array_frame_size(&func->op_array);
468+
} else if (func) {
469+
return ZEND_MM_ALIGNED_SIZE(offsetof(zend_jit_trace_stack_frame, stack) + ZEND_MM_ALIGNED_SIZE(func->common.num_args * sizeof(zend_jit_trace_stack)));
470+
} else {
471+
return ZEND_MM_ALIGNED_SIZE(offsetof(zend_jit_trace_stack_frame, stack));
472+
}
473+
}
474+
475+
static zend_jit_trace_stack_frame* zend_jit_trace_op_array_call_frame(zend_jit_trace_stack_frame *frame, const zend_op_array *op_array)
476+
{
477+
return (zend_jit_trace_stack_frame*)((char*)frame + zend_jit_trace_op_array_frame_size(op_array));
478+
}
479+
480+
static zend_jit_trace_stack_frame* zend_jit_trace_function_call_frame(zend_jit_trace_stack_frame *frame, const zend_function *func)
481+
{
482+
return (zend_jit_trace_stack_frame*)((char*)frame + zend_jit_trace_function_frame_size(func));
468483
}
469484

470-
static zend_jit_trace_stack_frame* zend_jit_trace_ret_frame(zend_jit_trace_stack_frame *frame, const zend_op_array *op_array)
485+
static zend_jit_trace_stack_frame* zend_jit_trace_op_array_ret_frame(zend_jit_trace_stack_frame *frame, const zend_op_array *op_array)
471486
{
472-
return (zend_jit_trace_stack_frame*)((char*)frame - zend_jit_trace_frame_size(op_array));
487+
return (zend_jit_trace_stack_frame*)((char*)frame - zend_jit_trace_op_array_frame_size(op_array));
473488
}
474489

475490
static void zend_jit_trace_send_type(const zend_op *opline, zend_jit_trace_stack_frame *call, zend_uchar type)
@@ -1160,7 +1175,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
11601175
* Calculate size of abstract stack;
11611176
* Construct regular SSA for involved op_array */
11621177
const zend_op_array *op_array = trace_buffer->op_array;
1163-
size_t stack_size = zend_jit_trace_frame_size(op_array);
1178+
size_t stack_size = zend_jit_trace_op_array_frame_size(op_array);
11641179
size_t stack_top = stack_size;
11651180
size_t stack_bottom = 0;
11661181
zend_jit_trace_rec *p = trace_buffer + ZEND_JIT_TRACE_START_REC_SIZE;
@@ -1201,7 +1216,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
12011216
ssa_ops_count += zend_jit_trace_op_len(p->opline);
12021217
} else if (p->op == ZEND_JIT_TRACE_INIT_CALL) {
12031218
call_level++;
1204-
stack_top += zend_jit_trace_frame_size(p->op_array);
1219+
stack_top += zend_jit_trace_function_frame_size(p->func);
12051220
if (stack_top > stack_size) {
12061221
stack_size = stack_top;
12071222
}
@@ -1214,7 +1229,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
12141229
ssa->cfg.flags |= ZEND_FUNC_INDIRECT_VAR_ACCESS;
12151230
}
12161231
}
1217-
const size_t frame_size = zend_jit_trace_frame_size(p->op_array);
1232+
const size_t frame_size = zend_jit_trace_function_frame_size(p->func);
12181233
if (call_level == 0) {
12191234
if (stack_top + frame_size > stack_size) {
12201235
stack_size = stack_top + frame_size;
@@ -1226,7 +1241,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
12261241
} else if (p->op == ZEND_JIT_TRACE_ENTER) {
12271242
op_array = p->op_array;
12281243
if (call_level == 0) {
1229-
stack_top += zend_jit_trace_frame_size(op_array);
1244+
stack_top += zend_jit_trace_op_array_frame_size(op_array);
12301245
if (stack_top > stack_size) {
12311246
stack_size = stack_top;
12321247
}
@@ -1251,7 +1266,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
12511266
}
12521267
} else if (p->op == ZEND_JIT_TRACE_BACK) {
12531268
if (level == 0) {
1254-
stack_bottom += zend_jit_trace_frame_size(p->op_array);
1269+
stack_bottom += zend_jit_trace_op_array_frame_size(p->op_array);
12551270
zend_jit_op_array_trace_extension *const jit_extension =
12561271
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
12571272
ssa = &jit_extension->func_info.ssa;
@@ -1268,7 +1283,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
12681283
ssa = zend_jit_trace_build_ssa(op_array, script);
12691284
}
12701285
} else {
1271-
stack_top -= zend_jit_trace_frame_size(op_array);
1286+
stack_top -= zend_jit_trace_op_array_frame_size(op_array);
12721287
level--;
12731288
}
12741289
op_array = p->op_array;
@@ -1368,7 +1383,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
13681383
idx++;
13691384
}
13701385
} else if (p->op == ZEND_JIT_TRACE_ENTER) {
1371-
frame = zend_jit_trace_call_frame(frame, op_array);
1386+
frame = zend_jit_trace_op_array_call_frame(frame, op_array);
13721387
stack = frame->stack;
13731388
op_array = p->op_array;
13741389
level++;
@@ -1381,7 +1396,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
13811396
}
13821397
} else if (p->op == ZEND_JIT_TRACE_BACK) {
13831398
op_array = p->op_array;
1384-
frame = zend_jit_trace_ret_frame(frame, op_array);
1399+
frame = zend_jit_trace_op_array_ret_frame(frame, op_array);
13851400
stack = frame->stack;
13861401
if (level == 0) {
13871402
if (ssa_vars_count >= ZEND_JIT_TRACE_MAX_SSA_VAR) {
@@ -1586,7 +1601,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
15861601
}
15871602

15881603
frame = JIT_G(current_frame);
1589-
zend_jit_trace_stack_frame *top = zend_jit_trace_call_frame(frame, op_array);
1604+
zend_jit_trace_stack_frame *top = zend_jit_trace_op_array_call_frame(frame, op_array);
15901605
TRACE_FRAME_INIT(frame, op_array, 0, 0);
15911606
TRACE_FRAME_SET_RETURN_SSA_VAR(frame, -1);
15921607
frame->used_stack = 0;
@@ -2280,7 +2295,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
22802295
call = top;
22812296
TRACE_FRAME_INIT(call, op_array, 0, 0);
22822297
call->used_stack = 0;
2283-
top = zend_jit_trace_call_frame(top, op_array);
2298+
top = zend_jit_trace_op_array_call_frame(top, op_array);
22842299
for (i = 0; i < op_array->last_var + op_array->T; i++) {
22852300
SET_STACK_TYPE(call->stack, i, IS_UNKNOWN, 1);
22862301
}
@@ -2402,7 +2417,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
24022417
ZEND_ASSERT(&frame->func->op_array == op_array);
24032418
} else {
24042419
max_used_stack = used_stack = -1;
2405-
frame = zend_jit_trace_ret_frame(frame, op_array);
2420+
frame = zend_jit_trace_op_array_ret_frame(frame, op_array);
24062421
TRACE_FRAME_INIT(frame, op_array, 0, 0);
24072422
TRACE_FRAME_SET_RETURN_SSA_VAR(frame, -1);
24082423
frame->used_stack = 0;
@@ -2417,9 +2432,9 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
24172432
call->prev = frame->call;
24182433
call->used_stack = 0;
24192434
frame->call = call;
2420-
top = zend_jit_trace_call_frame(top, p->op_array);
2435+
top = zend_jit_trace_function_call_frame(top, p->func);
24212436
if (p->func && p->func->type == ZEND_USER_FUNCTION) {
2422-
for (i = 0; i < p->op_array->last_var + p->op_array->T; i++) {
2437+
for (i = 0; i < p->func->op_array.last_var + p->func->op_array.T; i++) {
24232438
SET_STACK_INFO(call->stack, i, -1);
24242439
}
24252440
}
@@ -2966,7 +2981,7 @@ static zend_lifetime_interval** zend_jit_trace_allocate_registers(zend_jit_trace
29662981
/* New call frames */
29672982
zend_jit_trace_stack_frame *prev_frame = frame;
29682983

2969-
frame = zend_jit_trace_call_frame(frame, op_array);
2984+
frame = zend_jit_trace_op_array_call_frame(frame, op_array);
29702985
frame->prev = prev_frame;
29712986
frame->func = (const zend_function*)p->op_array;
29722987
stack = frame->stack;
@@ -3000,7 +3015,7 @@ static zend_lifetime_interval** zend_jit_trace_allocate_registers(zend_jit_trace
30003015
zend_jit_op_array_trace_extension *const jit_extension =
30013016
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
30023017
op_array_ssa = &jit_extension->func_info.ssa;
3003-
frame = zend_jit_trace_ret_frame(frame, op_array);
3018+
frame = zend_jit_trace_op_array_ret_frame(frame, op_array);
30043019
stack = frame->stack;
30053020
if (level == 0) {
30063021
/* New return frames */
@@ -3942,7 +3957,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
39423957
ZEND_ASSERT(p->op == ZEND_JIT_TRACE_START);
39433958
const zend_op_array *op_array = p->op_array;
39443959
zend_jit_trace_stack_frame *frame = JIT_G(current_frame);
3945-
zend_jit_trace_stack_frame *top = zend_jit_trace_call_frame(frame, op_array);
3960+
zend_jit_trace_stack_frame *top = zend_jit_trace_op_array_call_frame(frame, op_array);
39463961
TRACE_FRAME_INIT(frame, op_array, TRACE_FRAME_MASK_UNKNOWN_RETURN, -1);
39473962
int checked_stack;
39483963
int peek_checked_stack;
@@ -6494,7 +6509,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
64946509
stack = frame->stack;
64956510
ZEND_ASSERT(&frame->func->op_array == op_array);
64966511
} else {
6497-
frame = zend_jit_trace_ret_frame(frame, op_array);
6512+
frame = zend_jit_trace_op_array_ret_frame(frame, op_array);
64986513
TRACE_FRAME_INIT(frame, op_array, TRACE_FRAME_MASK_UNKNOWN_RETURN, -1);
64996514
frame->used_stack = checked_stack = peek_checked_stack = 0;
65006515
stack = frame->stack;
@@ -6580,40 +6595,40 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
65806595
}
65816596
}
65826597
frame->call = call;
6583-
top = zend_jit_trace_call_frame(top, p->op_array);
6598+
top = zend_jit_trace_function_call_frame(top, p->func);
65846599
if (p->func) {
65856600
if (p->func->type == ZEND_USER_FUNCTION) {
65866601
if (JIT_G(opt_level) >= ZEND_JIT_LEVEL_INLINE) {
65876602
zend_jit_op_array_trace_extension *jit_extension =
6588-
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(p->op_array);
6603+
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(&p->func->op_array);
65896604

65906605
uint32_t i = 0;
6591-
while (i < p->op_array->num_args) {
6606+
while (i < p->func->op_array.num_args) {
65926607
/* Types of arguments are going to be stored in abstract stack when processing SEV instruction */
65936608
SET_STACK_TYPE(call->stack, i, IS_UNKNOWN, 1);
65946609
i++;
65956610
}
6596-
while (i < p->op_array->last_var) {
6611+
while (i < p->func->op_array.last_var) {
65976612
if (jit_extension
6598-
&& zend_jit_var_may_alias(p->op_array, &jit_extension->func_info.ssa, i) != NO_ALIAS) {
6613+
&& zend_jit_var_may_alias(&p->func->op_array, &jit_extension->func_info.ssa, i) != NO_ALIAS) {
65996614
SET_STACK_TYPE(call->stack, i, IS_UNKNOWN, 1);
66006615
} else {
66016616
SET_STACK_TYPE(call->stack, i, IS_UNDEF, 1);
66026617
}
66036618
i++;
66046619
}
6605-
while (i < p->op_array->last_var + p->op_array->T) {
6620+
while (i < p->func->op_array.last_var + p->func->op_array.T) {
66066621
SET_STACK_TYPE(call->stack, i, IS_UNKNOWN, 1);
66076622
i++;
66086623
}
66096624
} else {
6610-
for (uint32_t i = 0; i < p->op_array->last_var + p->op_array->T; i++) {
6625+
for (uint32_t i = 0; i < p->func->op_array.last_var + p->func->op_array.T; i++) {
66116626
SET_STACK_TYPE(call->stack, i, IS_UNKNOWN, 1);
66126627
}
66136628
}
66146629
} else {
66156630
ZEND_ASSERT(p->func->type == ZEND_INTERNAL_FUNCTION);
6616-
for (uint32_t i = 0; i < p->op_array->num_args; i++) {
6631+
for (uint32_t i = 0; i < p->func->common.num_args; i++) {
66176632
SET_STACK_TYPE(call->stack, i, IS_UNKNOWN, 1);
66186633
}
66196634
}

0 commit comments

Comments
 (0)