Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 4 additions & 84 deletions ext/opcache/jit/zend_jit_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@
# define IR_OPCODE_HANDLER_RET IR_ADDR
#endif

#undef ir_CONST_ADDR
#define ir_CONST_ADDR(_addr) jit_CONST_ADDR(jit, (uintptr_t)(_addr))
#define ir_CONST_FUNC(_addr) jit_CONST_FUNC(jit, (uintptr_t)(_addr), 0)
#define ir_CONST_FC_FUNC(_addr) jit_CONST_FUNC(jit, (uintptr_t)(_addr), IR_FASTCALL_FUNC)
#define ir_CAST_FC_FUNC(_addr) ir_fold2(_ir_CTX, IR_OPT(IR_PROTO, IR_ADDR), (_addr), \
Expand All @@ -101,7 +99,7 @@
ir_proto_0(_ir_CTX, IR_FASTCALL_FUNC, IR_OPCODE_HANDLER_RET))

#define ir_CONST_FUNC_PROTO(_addr, _proto) \
jit_CONST_FUNC_PROTO(jit, (uintptr_t)(_addr), (_proto))
ir_const_func_addr(_ir_CTX, (uintptr_t)(_addr), (_proto))

#undef ir_ADD_OFFSET
#define ir_ADD_OFFSET(_addr, _offset) \
Expand Down Expand Up @@ -316,9 +314,6 @@ typedef struct _zend_jit_ctx {
zend_jit_reg_var *ra;
int delay_var;
ir_refs *delay_refs;
ir_ref eg_exception_addr;
HashTable addr_hash;
ir_ref stub_addr[jit_last_stub];
} zend_jit_ctx;

typedef int8_t zend_reg;
Expand Down Expand Up @@ -531,46 +526,6 @@ static ir_ref jit_TLS(zend_jit_ctx *jit)
}
#endif

static ir_ref jit_CONST_ADDR(zend_jit_ctx *jit, uintptr_t addr)
{
ir_ref ref;
zval *zv;

if (addr == 0) {
return IR_NULL;
}
zv = zend_hash_index_lookup(&jit->addr_hash, addr);
if (Z_TYPE_P(zv) == IS_LONG) {
ref = Z_LVAL_P(zv);
ZEND_ASSERT(jit->ctx.ir_base[ref].opt == IR_OPT(IR_ADDR, IR_ADDR));
} else {
ref = ir_unique_const_addr(&jit->ctx, addr);
ZVAL_LONG(zv, ref);
}
return ref;
}

static ir_ref jit_CONST_FUNC_PROTO(zend_jit_ctx *jit, uintptr_t addr, ir_ref proto)
{
ir_ref ref;
ir_insn *insn;
zval *zv;

ZEND_ASSERT(addr != 0);
zv = zend_hash_index_lookup(&jit->addr_hash, addr);
if (Z_TYPE_P(zv) == IS_LONG) {
ref = Z_LVAL_P(zv);
ZEND_ASSERT(jit->ctx.ir_base[ref].opt == IR_OPT(IR_FUNC_ADDR, IR_ADDR) && jit->ctx.ir_base[ref].proto == proto);
} else {
ref = ir_unique_const_addr(&jit->ctx, addr);
insn = &jit->ctx.ir_base[ref];
insn->optx = IR_OPT(IR_FUNC_ADDR, IR_ADDR);
insn->proto = proto;
ZVAL_LONG(zv, ref);
}
return ref;
}

static ir_ref jit_CONST_FUNC(zend_jit_ctx *jit, uintptr_t addr, uint16_t flags)
{
#if defined(IR_TARGET_X86)
Expand All @@ -580,7 +535,7 @@ static ir_ref jit_CONST_FUNC(zend_jit_ctx *jit, uintptr_t addr, uint16_t flags)
ir_ref proto = 0;
#endif

return jit_CONST_FUNC_PROTO(jit, addr, proto);
return ir_const_func_addr(&jit->ctx, addr, proto);
}

static ir_ref jit_CONST_OPCODE_HANDLER_FUNC(zend_jit_ctx *jit, zend_vm_opcode_handler_t handler)
Expand All @@ -598,48 +553,17 @@ static ir_ref jit_ADD_OFFSET(zend_jit_ctx *jit, ir_ref addr, uintptr_t offset)

static ir_ref jit_EG_exception(zend_jit_ctx *jit)
{
#ifdef ZTS
return jit_EG(exception);
#else
ir_ref ref = jit->eg_exception_addr;

if (UNEXPECTED(!ref)) {
ref = ir_unique_const_addr(&jit->ctx, (uintptr_t)&EG(exception));
jit->eg_exception_addr = ref;
}
return ref;
#endif
Comment on lines -603 to -611

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done to avoid repeatable hash lookup. You may keep the same code with iir_const_addr()

}

static ir_ref jit_STUB_ADDR(zend_jit_ctx *jit, jit_stub_id id)
{
ir_ref ref = jit->stub_addr[id];

if (UNEXPECTED(!ref)) {
ref = ir_unique_const_addr(&jit->ctx, (uintptr_t)zend_jit_stub_handlers[id]);
jit->stub_addr[id] = ref;
}
return ref;
return ir_CONST_ADDR(zend_jit_stub_handlers[id]);
Comment on lines -616 to +561

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same.

}

static ir_ref jit_STUB_FUNC_ADDR(zend_jit_ctx *jit, jit_stub_id id, uint16_t flags)
{
ir_ref ref = jit->stub_addr[id];
ir_insn *insn;

if (UNEXPECTED(!ref)) {
ref = ir_unique_const_addr(&jit->ctx, (uintptr_t)zend_jit_stub_handlers[id]);
insn = &jit->ctx.ir_base[ref];
insn->optx = IR_OPT(IR_FUNC_ADDR, IR_ADDR);
#if defined(IR_TARGET_X86)
/* TODO: dummy prototype (only flags matter) ??? */
insn->proto = flags ? ir_proto_0(&jit->ctx, flags, IR_I32) : 0;
#else
insn->proto = 0;
#endif
jit->stub_addr[id] = ref;
}
return ref;
return jit_CONST_FUNC(jit, (uintptr_t)zend_jit_stub_handlers[id], flags);
}

static void jit_SNAPSHOT(zend_jit_ctx *jit, ir_ref addr)
Expand Down Expand Up @@ -2841,9 +2765,6 @@ static void zend_jit_init_ctx(zend_jit_ctx *jit, uint32_t flags)
jit->ra = NULL;
jit->delay_var = -1;
jit->delay_refs = NULL;
jit->eg_exception_addr = 0;
zend_hash_init(&jit->addr_hash, 64, NULL, NULL, 0);
memset(jit->stub_addr, 0, sizeof(jit->stub_addr));

ir_START();
}
Expand All @@ -2853,7 +2774,6 @@ static int zend_jit_free_ctx(zend_jit_ctx *jit)
if (jit->name) {
zend_string_release(jit->name);
}
zend_hash_destroy(&jit->addr_hash);
ir_free(&jit->ctx);
return 1;
}
Expand Down
Loading