-
Notifications
You must be signed in to change notification settings - Fork 8.2k
JIT: Use interned constants for offsets in jit_ADD_OFFSET() #23952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ndossche
wants to merge
2
commits into
php:master
Choose a base branch
from
ndossche:jit-add-offset-interned-const
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4
−84
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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), \ | ||
|
|
@@ -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) \ | ||
|
|
@@ -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; | ||
|
|
@@ -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) | ||
|
|
@@ -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) | ||
|
|
@@ -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 | ||
| } | ||
|
|
||
| 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
@@ -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(); | ||
| } | ||
|
|
@@ -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; | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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()