Skip to content

GH-93678: refactor compiler so that optimizer does not need the assembler and compiler structs #93842

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

Merged
merged 16 commits into from
Jun 21, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
duplicate_exits_without_lineno can use b_next links to iterate
  • Loading branch information
iritkatriel committed Jun 14, 2022
commit 36d241087e783cf85dd8439b73ff3d4e81a3fa64
12 changes: 6 additions & 6 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8251,7 +8251,7 @@ trim_unused_consts(basicblock *entryblock, PyObject *consts);

/* Duplicates exit BBs, so that line numbers can be propagated to them */
static int
duplicate_exits_without_lineno(struct compiler *c);
duplicate_exits_without_lineno(basicblock *entryblock, struct compiler *c);

static int
extend_block(basicblock *bb);
Expand Down Expand Up @@ -8576,7 +8576,7 @@ assemble(struct compiler *c, int addNone)
if (optimize_cfg(entryblock, consts, c->c_const_cache)) {
goto error;
}
if (duplicate_exits_without_lineno(c)) {
if (duplicate_exits_without_lineno(entryblock, c)) {
return NULL;
}
if (trim_unused_consts(entryblock, consts)) {
Expand Down Expand Up @@ -9495,11 +9495,11 @@ is_exit_without_lineno(basicblock *b) {
* copy the line number from the sole predecessor block.
*/
static int
duplicate_exits_without_lineno(struct compiler *c)
duplicate_exits_without_lineno(basicblock *entryblock, struct compiler *c)
{
/* Copy all exit blocks without line number that are targets of a jump.
*/
for (basicblock *b = c->u->u_blocks; b != NULL; b = b->b_list) {
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
if (b->b_iused > 0 && is_jump(&b->b_instr[b->b_iused-1])) {
basicblock *target = b->b_instr[b->b_iused-1].i_target;
if (is_exit_without_lineno(target) && target->b_predecessors > 1) {
Expand All @@ -9517,14 +9517,14 @@ duplicate_exits_without_lineno(struct compiler *c)
}
}
/* Eliminate empty blocks */
for (basicblock *b = c->u->u_blocks; b != NULL; b = b->b_list) {
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
while (b->b_next && b->b_next->b_iused == 0) {
b->b_next = b->b_next->b_next;
}
}
/* Any remaining reachable exit blocks without line number can only be reached by
* fall through, and thus can only have a single predecessor */
for (basicblock *b = c->u->u_blocks; b != NULL; b = b->b_list) {
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
if (BB_HAS_FALLTHROUGH(b) && b->b_next && b->b_iused > 0) {
if (is_exit_without_lineno(b->b_next)) {
assert(b->b_next->b_iused > 0);
Expand Down