-
Notifications
You must be signed in to change notification settings - Fork 8k
zend_cfg: use uint32_t type rather than int type #21542
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
Changes from all commits
222e2d6
4ac3c9a
beea690
629dd1f
31201ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -479,7 +479,7 @@ int zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa) | |||||||||||||||||||||||||||||||||
| return removed_ops; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| static zend_always_inline void take_successor_0(zend_ssa *ssa, int block_num, zend_basic_block *block) | ||||||||||||||||||||||||||||||||||
| static zend_always_inline void take_successor_0(zend_ssa *ssa, uint32_t block_num, zend_basic_block *block) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| if (block->successors_count == 2) { | ||||||||||||||||||||||||||||||||||
| if (block->successors[1] != block->successors[0]) { | ||||||||||||||||||||||||||||||||||
|
|
@@ -489,7 +489,7 @@ static zend_always_inline void take_successor_0(zend_ssa *ssa, int block_num, ze | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| static zend_always_inline void take_successor_1(zend_ssa *ssa, int block_num, zend_basic_block *block) | ||||||||||||||||||||||||||||||||||
| static zend_always_inline void take_successor_1(zend_ssa *ssa, uint32_t block_num, zend_basic_block *block) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| if (block->successors_count == 2) { | ||||||||||||||||||||||||||||||||||
| if (block->successors[1] != block->successors[0]) { | ||||||||||||||||||||||||||||||||||
|
|
@@ -500,11 +500,9 @@ static zend_always_inline void take_successor_1(zend_ssa *ssa, int block_num, ze | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| static zend_always_inline void take_successor_ex(zend_ssa *ssa, int block_num, zend_basic_block *block, int target_block) | ||||||||||||||||||||||||||||||||||
| static zend_always_inline void take_successor_ex(zend_ssa *ssa, uint32_t block_num, zend_basic_block *block, int target_block) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| int i; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| for (i = 0; i < block->successors_count; i++) { | ||||||||||||||||||||||||||||||||||
| for (uint32_t i = 0; i < block->successors_count; i++) { | ||||||||||||||||||||||||||||||||||
| if (block->successors[i] != target_block) { | ||||||||||||||||||||||||||||||||||
| zend_ssa_remove_predecessor(ssa, block_num, block->successors[i]); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -531,10 +529,9 @@ static void replace_predecessor(zend_ssa *ssa, int block_id, int old_pred, int n | |||||||||||||||||||||||||||||||||
| int *predecessors = &ssa->cfg.predecessors[block->predecessor_offset]; | ||||||||||||||||||||||||||||||||||
| zend_ssa_phi *phi; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| int i; | ||||||||||||||||||||||||||||||||||
| int old_pred_idx = -1; | ||||||||||||||||||||||||||||||||||
| int new_pred_idx = -1; | ||||||||||||||||||||||||||||||||||
| for (i = 0; i < block->predecessors_count; i++) { | ||||||||||||||||||||||||||||||||||
| for (uint32_t i = 0; i < block->predecessors_count; i++) { | ||||||||||||||||||||||||||||||||||
| if (predecessors[i] == old_pred) { | ||||||||||||||||||||||||||||||||||
| old_pred_idx = i; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -582,10 +579,9 @@ static void zend_ssa_replace_control_link(zend_op_array *op_array, zend_ssa *ssa | |||||||||||||||||||||||||||||||||
| zend_basic_block *src = &ssa->cfg.blocks[from]; | ||||||||||||||||||||||||||||||||||
| zend_basic_block *old = &ssa->cfg.blocks[to]; | ||||||||||||||||||||||||||||||||||
| zend_basic_block *dst = &ssa->cfg.blocks[new_to]; | ||||||||||||||||||||||||||||||||||
| int i; | ||||||||||||||||||||||||||||||||||
| zend_op *opline; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| for (i = 0; i < src->successors_count; i++) { | ||||||||||||||||||||||||||||||||||
| for (uint32_t i = 0; i < src->successors_count; i++) { | ||||||||||||||||||||||||||||||||||
| if (src->successors[i] == to) { | ||||||||||||||||||||||||||||||||||
| src->successors[i] = new_to; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -650,10 +646,10 @@ static void zend_ssa_replace_control_link(zend_op_array *op_array, zend_ssa *ssa | |||||||||||||||||||||||||||||||||
| replace_predecessor(ssa, new_to, to, from); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| static void zend_ssa_unlink_block(zend_op_array *op_array, zend_ssa *ssa, zend_basic_block *block, int block_num) | ||||||||||||||||||||||||||||||||||
| static void zend_ssa_unlink_block(zend_op_array *op_array, zend_ssa *ssa, zend_basic_block *block, uint32_t block_num) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| if (block->predecessors_count == 1 && ssa->blocks[block_num].phis == NULL) { | ||||||||||||||||||||||||||||||||||
| int *predecessors, i; | ||||||||||||||||||||||||||||||||||
| int *predecessors; | ||||||||||||||||||||||||||||||||||
| zend_basic_block *fe_fetch_block = NULL; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ZEND_ASSERT(block->successors_count == 1); | ||||||||||||||||||||||||||||||||||
|
|
@@ -669,7 +665,7 @@ static void zend_ssa_unlink_block(zend_op_array *op_array, zend_ssa *ssa, zend_b | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| for (i = 0; i < block->predecessors_count; i++) { | ||||||||||||||||||||||||||||||||||
| for (uint32_t i = 0; i < block->predecessors_count; i++) { | ||||||||||||||||||||||||||||||||||
| zend_ssa_replace_control_link(op_array, ssa, predecessors[i], block_num, block->successors[0]); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| zend_ssa_remove_block(op_array, ssa, block_num); | ||||||||||||||||||||||||||||||||||
|
|
@@ -686,7 +682,7 @@ static void zend_ssa_unlink_block(zend_op_array *op_array, zend_ssa *ssa, zend_b | |||||||||||||||||||||||||||||||||
| static int zend_dfa_optimize_jmps(zend_op_array *op_array, zend_ssa *ssa) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| int removed_ops = 0; | ||||||||||||||||||||||||||||||||||
| int block_num = 0; | ||||||||||||||||||||||||||||||||||
| uint32_t block_num = 0; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| for (block_num = 1; block_num < ssa->cfg.blocks_count; block_num++) { | ||||||||||||||||||||||||||||||||||
| zend_basic_block *block = &ssa->cfg.blocks[block_num]; | ||||||||||||||||||||||||||||||||||
|
|
@@ -706,7 +702,7 @@ static int zend_dfa_optimize_jmps(zend_op_array *op_array, zend_ssa *ssa) | |||||||||||||||||||||||||||||||||
| block_num++; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| while (block_num < ssa->cfg.blocks_count) { | ||||||||||||||||||||||||||||||||||
| int next_block_num = block_num + 1; | ||||||||||||||||||||||||||||||||||
| uint32_t next_block_num = block_num + 1; | ||||||||||||||||||||||||||||||||||
| zend_basic_block *block = &ssa->cfg.blocks[block_num]; | ||||||||||||||||||||||||||||||||||
| uint32_t op_num; | ||||||||||||||||||||||||||||||||||
| zend_op *opline; | ||||||||||||||||||||||||||||||||||
|
|
@@ -941,11 +937,13 @@ static int zend_dfa_optimize_jmps(zend_op_array *op_array, zend_ssa *ssa) | |||||||||||||||||||||||||||||||||
| if (block_num > 0) { | ||||||||||||||||||||||||||||||||||
| zend_ssa_unlink_block(op_array, ssa, block, block_num); | ||||||||||||||||||||||||||||||||||
| /* backtrack to previous basic block */ | ||||||||||||||||||||||||||||||||||
| int backtracking_block_num = block_num; | ||||||||||||||||||||||||||||||||||
| do { | ||||||||||||||||||||||||||||||||||
| block_num--; | ||||||||||||||||||||||||||||||||||
| } while (block_num >= 0 | ||||||||||||||||||||||||||||||||||
| && !(ssa->cfg.blocks[block_num].flags & ZEND_BB_REACHABLE)); | ||||||||||||||||||||||||||||||||||
| if (block_num >= 0) { | ||||||||||||||||||||||||||||||||||
| backtracking_block_num--; | ||||||||||||||||||||||||||||||||||
| } while (backtracking_block_num >= 0 | ||||||||||||||||||||||||||||||||||
| && !(ssa->cfg.blocks[backtracking_block_num].flags & ZEND_BB_REACHABLE)); | ||||||||||||||||||||||||||||||||||
| if (backtracking_block_num >= 0) { | ||||||||||||||||||||||||||||||||||
| block_num = backtracking_block_num; | ||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+940
to
947
Member
Author
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. I feel that there should be a better way to solve this but when I initially did:
Suggested change
it didn't behave as expected, so I guess I'm not fully grasping what is happening here.
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. I think that you had inverted the logic in But I find the original logic easier to follow.
Member
Author
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. Happy to keep the original logic, although I might add a comment explaining what is happening :) |
||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.