Skip to content
Closed
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
29 changes: 14 additions & 15 deletions Zend/Optimizer/zend_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ static void zend_mark_reachable(zend_op *opcodes, zend_cfg *cfg, zend_basic_bloc
{
zend_basic_block *blocks = cfg->blocks;

while (1) {
zend_worklist work;
ALLOCA_FLAG(list_use_heap)
ZEND_WORKLIST_ALLOCA(&work, cfg->blocks_count, list_use_heap);

zend_worklist_push(&work, b - cfg->blocks);

while (zend_worklist_len(&work)) {
int i;
b = cfg->blocks + zend_worklist_pop(&work);

b->flags |= ZEND_BB_REACHABLE;
if (b->successors_count == 0) {
b->flags |= ZEND_BB_EXIT;
return;
continue;
}

for (i = 0; i < b->successors_count; i++) {
Expand Down Expand Up @@ -86,22 +93,14 @@ static void zend_mark_reachable(zend_op *opcodes, zend_cfg *cfg, zend_basic_bloc
succ->flags |= ZEND_BB_FOLLOW;
}

if (i == b->successors_count - 1) {
/* Tail call optimization */
if (succ->flags & ZEND_BB_REACHABLE) {
return;
}

b = succ;
break;
} else {
/* Recursively check reachability */
if (!(succ->flags & ZEND_BB_REACHABLE)) {
zend_mark_reachable(opcodes, cfg, succ);
}
/* Check reachability of successor */
if (!(succ->flags & ZEND_BB_REACHABLE)) {
zend_worklist_push(&work, succ - cfg->blocks);
}
}
}

ZEND_WORKLIST_FREE_ALLOCA(&work, list_use_heap);
}
/* }}} */

Expand Down