diff options
author | Mark Shannon <mark@hotpy.org> | 2021-01-13 15:05:04 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-13 15:05:04 +0000 |
commit | 1659ad1c644240d3db1d65e782c8c53b4c4e71ea (patch) | |
tree | 8e2317b1759a45345429aa59e254fc5975a91bea /Python | |
parent | bpo-42908: Mark cleanup code at end of try-except and with artificial (#24202) (diff) | |
download | cpython-1659ad1c644240d3db1d65e782c8c53b4c4e71ea.tar.gz cpython-1659ad1c644240d3db1d65e782c8c53b4c4e71ea.tar.bz2 cpython-1659ad1c644240d3db1d65e782c8c53b4c4e71ea.zip |
Eliminate NOPs in extended blocks. (GH-24209)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Python/compile.c b/Python/compile.c index 268c5aa9eab..d373d8a4061 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -6328,10 +6328,9 @@ error: static void -clean_basic_block(basicblock *bb) { - /* Remove NOPs. */ +clean_basic_block(basicblock *bb, int prev_lineno) { + /* Remove NOPs when legal to do so. */ int dest = 0; - int prev_lineno = -1; for (int src = 0; src < bb->b_iused; src++) { int lineno = bb->b_instr[src].i_lineno; if (bb->b_instr[src].i_opcode == NOP) { @@ -6531,7 +6530,7 @@ optimize_cfg(struct assembler *a, PyObject *consts) if (optimize_basic_block(b, consts)) { return -1; } - clean_basic_block(b); + clean_basic_block(b, -1); assert(b->b_predecessors == 0); } if (mark_reachable(a)) { @@ -6544,6 +6543,15 @@ optimize_cfg(struct assembler *a, PyObject *consts) b->b_nofallthrough = 0; } } + basicblock *pred = NULL; + for (basicblock *b = a->a_entry; b != NULL; b = b->b_next) { + int prev_lineno = -1; + if (pred && pred->b_iused) { + prev_lineno = pred->b_instr[pred->b_iused-1].i_lineno; + } + clean_basic_block(b, prev_lineno); + pred = b->b_nofallthrough ? NULL : b; + } eliminate_empty_basic_blocks(a->a_entry); /* Delete jump instructions made redundant by previous step. If a non-empty block ends with a jump instruction, check if the next non-empty block @@ -6571,7 +6579,7 @@ optimize_cfg(struct assembler *a, PyObject *consts) case JUMP_ABSOLUTE: case JUMP_FORWARD: b_last_instr->i_opcode = NOP; - clean_basic_block(b); + clean_basic_block(b, -1); maybe_empty_blocks = 1; break; } |