mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Normalize jumps in compiler. All forward jumps to use JUMP_FORWARD. (GH-28755)
This commit is contained in:
parent
c379bc5ec9
commit
f6eafe18c0
3 changed files with 37 additions and 14 deletions
|
@ -7220,6 +7220,26 @@ assemble_emit(struct assembler *a, struct instr *i)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
normalize_jumps(struct assembler *a)
|
||||
{
|
||||
for (basicblock *b = a->a_entry; b != NULL; b = b->b_next) {
|
||||
b->b_visited = 0;
|
||||
}
|
||||
for (basicblock *b = a->a_entry; b != NULL; b = b->b_next) {
|
||||
b->b_visited = 1;
|
||||
if (b->b_iused == 0) {
|
||||
continue;
|
||||
}
|
||||
struct instr *last = &b->b_instr[b->b_iused-1];
|
||||
if (last->i_opcode == JUMP_ABSOLUTE &&
|
||||
last->i_target->b_visited == 0
|
||||
) {
|
||||
last->i_opcode = JUMP_FORWARD;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
assemble_jump_offsets(struct assembler *a, struct compiler *c)
|
||||
{
|
||||
|
@ -7897,6 +7917,9 @@ assemble(struct compiler *c, int addNone)
|
|||
clean_basic_block(b);
|
||||
}
|
||||
|
||||
/* Order of basic blocks must have been determined by now */
|
||||
normalize_jumps(&a);
|
||||
|
||||
/* Can't modify the bytecode after computing jump offsets. */
|
||||
assemble_jump_offsets(&a, c);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue