Skip to content

Commit 39b092b

Browse files
committed
ext/opcache/jit/zend_jit_internal: add ZEND_OP_TRACE_INFO2()
Allows eliminating several local variables.
1 parent 0a59bdc commit 39b092b

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3243,11 +3243,8 @@ static int zend_jit_packed_guard(dasm_State **Dst, const zend_op *opline, uint32
32433243

32443244
static int zend_jit_trace_handler(dasm_State **Dst, const zend_op_array *op_array, const zend_op *opline, int may_throw, zend_jit_trace_rec *trace)
32453245
{
3246-
zend_jit_op_array_trace_extension *jit_extension =
3247-
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
3248-
size_t offset = jit_extension->offset;
32493246
const void *handler =
3250-
(zend_vm_opcode_handler_t)ZEND_OP_TRACE_INFO(opline, offset)->call_handler;
3247+
(zend_vm_opcode_handler_t)ZEND_OP_TRACE_INFO2(op_array, opline)->call_handler;
32513248

32523249
if (!zend_jit_set_valid_ip(Dst, opline)) {
32533250
return 0;

ext/opcache/jit/zend_jit_internal.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,22 @@ static zend_always_inline zend_op_trace_info *ZEND_OP_TRACE_INFO(const zend_op *
511511
return (zend_op_trace_info*)((char*)opline + offset);
512512
}
513513

514+
/**
515+
* Access the #zend_op_trace_info of an #zend_op by looking up the
516+
* offset from the specified #zend_op_array.
517+
*/
518+
static zend_always_inline zend_op_trace_info *ZEND_OP_TRACE_INFO2(const zend_op_array *op_array, const zend_op *opline)
519+
{
520+
/* the opline must be from the specified function */
521+
ZEND_ASSERT(opline >= op_array->opcodes);
522+
ZEND_ASSERT(opline < op_array->opcodes + op_array->last);
523+
524+
const zend_jit_op_array_trace_extension *jit_extension =
525+
(const zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
526+
ZEND_ASSERT(jit_extension != NULL);
527+
return ZEND_OP_TRACE_INFO(opline, jit_extension->offset);
528+
}
529+
514530
/* Recorder */
515531
typedef enum _zend_jit_trace_op {
516532
ZEND_JIT_TRACE_VM,

ext/opcache/jit/zend_jit_trace.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7969,13 +7969,11 @@ static int zend_jit_trace_hot_side(zend_execute_data *execute_data, uint32_t par
79697969
if (JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_START) {
79707970
const zend_op_array *op_array = trace_buffer[0].op_array;
79717971
const zend_op *opline = trace_buffer[1].opline;
7972-
zend_jit_op_array_trace_extension *jit_extension =
7973-
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
7974-
size_t offset = jit_extension->offset;
7972+
const zend_op_trace_info *trace_info = ZEND_OP_TRACE_INFO2(op_array, opline);
79757973

79767974
fprintf(stderr, "---- TRACE %d start (%s) %s%s%s() %s:%d\n",
79777975
trace_num,
7978-
zend_jit_trace_star_desc(ZEND_OP_TRACE_INFO(opline, offset)->trace_flags),
7976+
zend_jit_trace_star_desc(trace_info->trace_flags),
79797977
op_array->scope ? ZSTR_VAL(op_array->scope->name) : "",
79807978
op_array->scope ? "::" : "",
79817979
op_array->function_name ?
@@ -8197,7 +8195,6 @@ static int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registe
81978195
}
81988196

81998197
if (t->exit_info[exit_num].flags & ZEND_JIT_EXIT_INVALIDATE) {
8200-
zend_jit_op_array_trace_extension *jit_extension;
82018198
uint32_t num = trace_num;
82028199

82038200
while (t->root != num) {
@@ -8207,8 +8204,7 @@ static int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registe
82078204

82088205
zend_shared_alloc_lock();
82098206

8210-
jit_extension = (zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(t->op_array);
8211-
zend_op_trace_info *const trace_info = ZEND_OP_TRACE_INFO(t->opline, jit_extension->offset);
8207+
zend_op_trace_info *const trace_info = ZEND_OP_TRACE_INFO2(t->op_array, t->opline);
82128208

82138209
/* Checks under lock, just in case something has changed while we were waiting for the lock */
82148210
if (!(trace_info->trace_flags & (ZEND_JIT_TRACE_JITED|ZEND_JIT_TRACE_BLACKLISTED))) {

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,11 @@ zend_constant* ZEND_FASTCALL zend_jit_check_constant(const zval *key)
306306

307307
static zend_always_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_trace_counter_helper(uint32_t cost ZEND_OPCODE_HANDLER_ARGS_DC)
308308
{
309-
zend_jit_op_array_trace_extension *jit_extension =
310-
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(&EX(func)->op_array);
311309
#ifndef HAVE_GCC_GLOBAL_REGS
312310
const zend_op *opline = EX(opline);
313311
#endif
314312

315-
zend_op_trace_info *const trace_info = ZEND_OP_TRACE_INFO(opline, jit_extension->offset);
313+
zend_op_trace_info *const trace_info = ZEND_OP_TRACE_INFO2(&EX(func)->op_array, opline);
316314

317315
*(trace_info->counter) -= cost;
318316

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3594,11 +3594,8 @@ static int zend_jit_packed_guard(dasm_State **Dst, const zend_op *opline, uint32
35943594

35953595
static int zend_jit_trace_handler(dasm_State **Dst, const zend_op_array *op_array, const zend_op *opline, int may_throw, zend_jit_trace_rec *trace)
35963596
{
3597-
zend_jit_op_array_trace_extension *jit_extension =
3598-
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
3599-
size_t offset = jit_extension->offset;
36003597
const void *handler =
3601-
(zend_vm_opcode_handler_t)ZEND_OP_TRACE_INFO(opline, offset)->call_handler;
3598+
(zend_vm_opcode_handler_t)ZEND_OP_TRACE_INFO2(op_array, opline)->call_handler;
36023599

36033600
if (!zend_jit_set_valid_ip(Dst, opline)) {
36043601
return 0;

0 commit comments

Comments
 (0)