Skip to content

Commit

Permalink
JIT for FETCH_CONSTANT
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Sep 2, 2020
1 parent 508f828 commit 91edb90
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
5 changes: 5 additions & 0 deletions ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2982,6 +2982,11 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
goto jit_failure;
}
goto done;
case ZEND_FETCH_CONSTANT:
if (!zend_jit_fetch_constant(&dasm_state, opline)) {
goto jit_failure;
}
goto done;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions ext/opcache/jit/zend_jit_disasm_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ static int zend_jit_disasm_init(void)
REGISTER_HELPER(zend_runtime_jit);
REGISTER_HELPER(zend_jit_hot_func);
REGISTER_HELPER(zend_jit_check_constant);
REGISTER_HELPER(zend_jit_get_constant);
REGISTER_HELPER(zend_jit_array_free);
REGISTER_HELPER(zend_jit_zval_array_dup);
REGISTER_HELPER(zend_jit_add_arrays_helper);
Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/jit/zend_jit_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_counter_helper(ZEND_OPCODE_H
void ZEND_FASTCALL zend_jit_copy_extra_args_helper(EXECUTE_DATA_D);
zend_bool ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D);

void ZEND_FASTCALL zend_jit_get_constant(const zval *key, uint32_t flags);
int ZEND_FASTCALL zend_jit_check_constant(const zval *key);
int ZEND_FASTCALL zend_jit_get_constant(const zval *key, uint32_t flags);
int ZEND_FASTCALL zend_jit_check_constant(const zval *key);

/* Tracer */
#define zend_jit_opline_hash(opline) \
Expand Down
5 changes: 5 additions & 0 deletions ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -4574,6 +4574,11 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
goto jit_failure;
}
goto done;
case ZEND_FETCH_CONSTANT:
if (!zend_jit_fetch_constant(&dasm_state, opline)) {
goto jit_failure;
}
goto done;
case ZEND_INIT_METHOD_CALL:
case ZEND_INIT_DYNAMIC_CALL:
if (!zend_jit_trace_handler(&dasm_state, op_array, opline, zend_may_throw(opline, ssa_op, op_array, ssa), p + 1)) {
Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/jit/zend_jit_vm_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ static zend_always_inline int _zend_quick_get_constant(
return SUCCESS;
}

void ZEND_FASTCALL zend_jit_get_constant(const zval *key, uint32_t flags)
int ZEND_FASTCALL zend_jit_get_constant(const zval *key, uint32_t flags)
{
_zend_quick_get_constant(key, flags, 0);
return _zend_quick_get_constant(key, flags, 0);
}

int ZEND_FASTCALL zend_jit_check_constant(const zval *key)
Expand Down
41 changes: 38 additions & 3 deletions ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -12651,15 +12651,50 @@ static int zend_jit_fe_fetch(dasm_State **Dst, const zend_op *opline, const zend
} else {
| // ZVAL_COPY(res, value);
| ZVAL_COPY_VALUE var_addr, -1, val_addr, val_info, ZREG_R0, ZREG_FCARG1a
if (val_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF)) {
| TRY_ADDREF op1_info, ah, FCARG1a
}
| TRY_ADDREF val_info, ah, FCARG1a
}
}

return 1;
}

static int zend_jit_fetch_constant(dasm_State **Dst, const zend_op *opline)
{
zval *zv = RT_CONSTANT(opline, opline->op2) + 1;
zend_jit_addr res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var);
zend_jit_addr const_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FCARG1a, 0);

| // c = CACHED_PTR(opline->extended_value);
| mov FCARG1a, EX->run_time_cache
| mov FCARG1a, aword [FCARG1a + opline->extended_value]
| // if (c != NULL)
| test FCARG1a, FCARG1a
| jz >9
| // if (!IS_SPECIAL_CACHE_VAL(c))
| test FCARG1a, CACHE_SPECIAL
| jnz >9
| // ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value); (no dup)
| ZVAL_COPY_VALUE res_addr, MAY_BE_ANY, const_addr, MAY_BE_ANY, ZREG_R0, ZREG_FCARG2a
| TRY_ADDREF MAY_BE_ANY, ah, FCARG2a
|8:

|.cold_code
|9:
| // SAVE_OPLINE();
| SAVE_VALID_OPLINE opline, r0
| // zend_quick_get_constant(RT_CONSTANT(opline, opline->op2) + 1, opline->op1.num OPLINE_CC EXECUTE_DATA_CC);
| LOAD_ADDR FCARG1a, zv
| mov FCARG2a, opline->op1.num
| EXT_CALL zend_jit_get_constant, r0
| // ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
| test r0, r0
| jz <8
| jmp ->exception_handler
|.code

return 1;
}

static zend_bool zend_jit_noref_guard(dasm_State **Dst, const zend_op *opline, zend_jit_addr var_addr)
{
int32_t exit_point = zend_jit_trace_get_exit_point(opline, 0);
Expand Down

0 comments on commit 91edb90

Please sign in to comment.