Skip to content

Commit 388545d

Browse files
committed
ext/opcache/jit/trace: split zend_jit_trace_frame_size()
1 parent 37dcc86 commit 388545d

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
int ssa_ops_count = 0;
@@ -1200,7 +1215,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
12001215
ssa_ops_count += zend_jit_trace_op_len(p->opline);
12011216
} else if (p->op == ZEND_JIT_TRACE_INIT_CALL) {
12021217
call_level++;
1203-
stack_top += zend_jit_trace_frame_size(p->op_array);
1218+
stack_top += zend_jit_trace_function_frame_size(p->func);
12041219
if (stack_top > stack_size) {
12051220
stack_size = stack_top;
12061221
}
@@ -1213,7 +1228,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
12131228
ssa->cfg.flags |= ZEND_FUNC_INDIRECT_VAR_ACCESS;
12141229
}
12151230
}
1216-
const size_t frame_size = zend_jit_trace_frame_size(p->op_array);
1231+
const size_t frame_size = zend_jit_trace_function_frame_size(p->func);
12171232
if (call_level == 0) {
12181233
if (stack_top + frame_size > stack_size) {
12191234
stack_size = stack_top + frame_size;
@@ -1225,7 +1240,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
12251240
} else if (p->op == ZEND_JIT_TRACE_ENTER) {
12261241
op_array = p->op_array;
12271242
if (call_level == 0) {
1228-
stack_top += zend_jit_trace_frame_size(op_array);
1243+
stack_top += zend_jit_trace_op_array_frame_size(op_array);
12291244
if (stack_top > stack_size) {
12301245
stack_size = stack_top;
12311246
}
@@ -1250,7 +1265,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
12501265
}
12511266
} else if (p->op == ZEND_JIT_TRACE_BACK) {
12521267
if (level == 0) {
1253-
stack_bottom += zend_jit_trace_frame_size(p->op_array);
1268+
stack_bottom += zend_jit_trace_op_array_frame_size(p->op_array);
12541269
zend_jit_op_array_trace_extension *const jit_extension =
12551270
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
12561271
ssa = &jit_extension->func_info.ssa;
@@ -1267,7 +1282,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
12671282
ssa = zend_jit_trace_build_ssa(op_array, script);
12681283
}
12691284
} else {
1270-
stack_top -= zend_jit_trace_frame_size(op_array);
1285+
stack_top -= zend_jit_trace_op_array_frame_size(op_array);
12711286
level--;
12721287
}
12731288
op_array = p->op_array;
@@ -1366,7 +1381,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
13661381
idx++;
13671382
}
13681383
} else if (p->op == ZEND_JIT_TRACE_ENTER) {
1369-
frame = zend_jit_trace_call_frame(frame, op_array);
1384+
frame = zend_jit_trace_op_array_call_frame(frame, op_array);
13701385
stack = frame->stack;
13711386
op_array = p->op_array;
13721387
level++;
@@ -1379,7 +1394,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
13791394
}
13801395
} else if (p->op == ZEND_JIT_TRACE_BACK) {
13811396
op_array = p->op_array;
1382-
frame = zend_jit_trace_ret_frame(frame, op_array);
1397+
frame = zend_jit_trace_op_array_ret_frame(frame, op_array);
13831398
stack = frame->stack;
13841399
if (level == 0) {
13851400
if (ssa_vars_count >= ZEND_JIT_TRACE_MAX_SSA_VAR) {
@@ -1582,7 +1597,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
15821597
}
15831598

15841599
frame = JIT_G(current_frame);
1585-
zend_jit_trace_stack_frame *top = zend_jit_trace_call_frame(frame, op_array);
1600+
zend_jit_trace_stack_frame *top = zend_jit_trace_op_array_call_frame(frame, op_array);
15861601
TRACE_FRAME_INIT(frame, op_array, 0, 0);
15871602
TRACE_FRAME_SET_RETURN_SSA_VAR(frame, -1);
15881603
frame->used_stack = 0;
@@ -2275,7 +2290,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
22752290
call = top;
22762291
TRACE_FRAME_INIT(call, op_array, 0, 0);
22772292
call->used_stack = 0;
2278-
top = zend_jit_trace_call_frame(top, op_array);
2293+
top = zend_jit_trace_op_array_call_frame(top, op_array);
22792294
for (i = 0; i < op_array->last_var + op_array->T; i++) {
22802295
SET_STACK_TYPE(call->stack, i, IS_UNKNOWN, 1);
22812296
}
@@ -2397,7 +2412,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
23972412
ZEND_ASSERT(&frame->func->op_array == op_array);
23982413
} else {
23992414
max_used_stack = used_stack = -1;
2400-
frame = zend_jit_trace_ret_frame(frame, op_array);
2415+
frame = zend_jit_trace_op_array_ret_frame(frame, op_array);
24012416
TRACE_FRAME_INIT(frame, op_array, 0, 0);
24022417
TRACE_FRAME_SET_RETURN_SSA_VAR(frame, -1);
24032418
frame->used_stack = 0;
@@ -2412,9 +2427,9 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
24122427
call->prev = frame->call;
24132428
call->used_stack = 0;
24142429
frame->call = call;
2415-
top = zend_jit_trace_call_frame(top, p->op_array);
2430+
top = zend_jit_trace_function_call_frame(top, p->func);
24162431
if (p->func && p->func->type == ZEND_USER_FUNCTION) {
2417-
for (i = 0; i < p->op_array->last_var + p->op_array->T; i++) {
2432+
for (i = 0; i < p->func->op_array.last_var + p->func->op_array.T; i++) {
24182433
SET_STACK_INFO(call->stack, i, -1);
24192434
}
24202435
}
@@ -2961,7 +2976,7 @@ static zend_lifetime_interval** zend_jit_trace_allocate_registers(zend_jit_trace
29612976
/* New call frames */
29622977
zend_jit_trace_stack_frame *prev_frame = frame;
29632978

2964-
frame = zend_jit_trace_call_frame(frame, op_array);
2979+
frame = zend_jit_trace_op_array_call_frame(frame, op_array);
29652980
frame->prev = prev_frame;
29662981
frame->func = (const zend_function*)p->op_array;
29672982
stack = frame->stack;
@@ -2995,7 +3010,7 @@ static zend_lifetime_interval** zend_jit_trace_allocate_registers(zend_jit_trace
29953010
zend_jit_op_array_trace_extension *const jit_extension =
29963011
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
29973012
op_array_ssa = &jit_extension->func_info.ssa;
2998-
frame = zend_jit_trace_ret_frame(frame, op_array);
3013+
frame = zend_jit_trace_op_array_ret_frame(frame, op_array);
29993014
stack = frame->stack;
30003015
if (level == 0) {
30013016
/* New return frames */
@@ -3937,7 +3952,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
39373952
ZEND_ASSERT(p->op == ZEND_JIT_TRACE_START);
39383953
const zend_op_array *op_array = p->op_array;
39393954
zend_jit_trace_stack_frame *frame = JIT_G(current_frame);
3940-
zend_jit_trace_stack_frame *top = zend_jit_trace_call_frame(frame, op_array);
3955+
zend_jit_trace_stack_frame *top = zend_jit_trace_op_array_call_frame(frame, op_array);
39413956
TRACE_FRAME_INIT(frame, op_array, TRACE_FRAME_MASK_UNKNOWN_RETURN, -1);
39423957
int checked_stack;
39433958
int peek_checked_stack;
@@ -6489,7 +6504,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
64896504
stack = frame->stack;
64906505
ZEND_ASSERT(&frame->func->op_array == op_array);
64916506
} else {
6492-
frame = zend_jit_trace_ret_frame(frame, op_array);
6507+
frame = zend_jit_trace_op_array_ret_frame(frame, op_array);
64936508
TRACE_FRAME_INIT(frame, op_array, TRACE_FRAME_MASK_UNKNOWN_RETURN, -1);
64946509
frame->used_stack = checked_stack = peek_checked_stack = 0;
64956510
stack = frame->stack;
@@ -6575,40 +6590,40 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
65756590
}
65766591
}
65776592
frame->call = call;
6578-
top = zend_jit_trace_call_frame(top, p->op_array);
6593+
top = zend_jit_trace_function_call_frame(top, p->func);
65796594
if (p->func) {
65806595
if (p->func->type == ZEND_USER_FUNCTION) {
65816596
if (JIT_G(opt_level) >= ZEND_JIT_LEVEL_INLINE) {
65826597
zend_jit_op_array_trace_extension *jit_extension =
6583-
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(p->op_array);
6598+
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(&p->func->op_array);
65846599

65856600
uint32_t i = 0;
6586-
while (i < p->op_array->num_args) {
6601+
while (i < p->func->op_array.num_args) {
65876602
/* Types of arguments are going to be stored in abstract stack when processing SEV instruction */
65886603
SET_STACK_TYPE(call->stack, i, IS_UNKNOWN, 1);
65896604
i++;
65906605
}
6591-
while (i < p->op_array->last_var) {
6606+
while (i < p->func->op_array.last_var) {
65926607
if (jit_extension
6593-
&& zend_jit_var_may_alias(p->op_array, &jit_extension->func_info.ssa, i) != NO_ALIAS) {
6608+
&& zend_jit_var_may_alias(&p->func->op_array, &jit_extension->func_info.ssa, i) != NO_ALIAS) {
65946609
SET_STACK_TYPE(call->stack, i, IS_UNKNOWN, 1);
65956610
} else {
65966611
SET_STACK_TYPE(call->stack, i, IS_UNDEF, 1);
65976612
}
65986613
i++;
65996614
}
6600-
while (i < p->op_array->last_var + p->op_array->T) {
6615+
while (i < p->func->op_array.last_var + p->func->op_array.T) {
66016616
SET_STACK_TYPE(call->stack, i, IS_UNKNOWN, 1);
66026617
i++;
66036618
}
66046619
} else {
6605-
for (uint32_t i = 0; i < p->op_array->last_var + p->op_array->T; i++) {
6620+
for (uint32_t i = 0; i < p->func->op_array.last_var + p->func->op_array.T; i++) {
66066621
SET_STACK_TYPE(call->stack, i, IS_UNKNOWN, 1);
66076622
}
66086623
}
66096624
} else {
66106625
ZEND_ASSERT(p->func->type == ZEND_INTERNAL_FUNCTION);
6611-
for (uint32_t i = 0; i < p->op_array->num_args; i++) {
6626+
for (uint32_t i = 0; i < p->func->common.num_args; i++) {
66126627
SET_STACK_TYPE(call->stack, i, IS_UNKNOWN, 1);
66136628
}
66146629
}

0 commit comments

Comments
 (0)