@@ -512,7 +512,7 @@ static int compiler_match(struct compiler *, stmt_ty);
512
512
static int compiler_pattern_subpattern (struct compiler * ,
513
513
pattern_ty , pattern_context * );
514
514
515
- static void remove_redundant_nops (basicblock * bb );
515
+ static int remove_redundant_nops (basicblock * bb );
516
516
517
517
static PyCodeObject * assemble (struct compiler * , int addNone );
518
518
@@ -8666,6 +8666,17 @@ static void
8666
8666
propagate_line_numbers (basicblock * entryblock );
8667
8667
8668
8668
#ifndef NDEBUG
8669
+
8670
+ static bool
8671
+ no_redundant_nops (cfg_builder * g ) {
8672
+ for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
8673
+ if (remove_redundant_nops (b ) != 0 ) {
8674
+ return false;
8675
+ }
8676
+ }
8677
+ return true;
8678
+ }
8679
+
8669
8680
static bool
8670
8681
no_redundant_jumps (cfg_builder * g ) {
8671
8682
for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
@@ -9435,7 +9446,7 @@ inline_small_exit_blocks(basicblock *bb) {
9435
9446
return 0 ;
9436
9447
}
9437
9448
9438
- static void
9449
+ static int
9439
9450
remove_redundant_nops (basicblock * bb ) {
9440
9451
/* Remove NOPs when legal to do so. */
9441
9452
int dest = 0 ;
@@ -9483,7 +9494,9 @@ remove_redundant_nops(basicblock *bb) {
9483
9494
prev_lineno = lineno ;
9484
9495
}
9485
9496
assert (dest <= bb -> b_iused );
9497
+ int num_removed = bb -> b_iused - dest ;
9486
9498
bb -> b_iused = dest ;
9499
+ return num_removed ;
9487
9500
}
9488
9501
9489
9502
static int
@@ -9694,10 +9707,11 @@ optimize_cfg(cfg_builder *g, PyObject *consts, PyObject *const_cache)
9694
9707
b -> b_iused = 0 ;
9695
9708
}
9696
9709
}
9697
- eliminate_empty_basic_blocks (g );
9698
9710
for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
9699
9711
remove_redundant_nops (b );
9700
9712
}
9713
+ eliminate_empty_basic_blocks (g );
9714
+ assert (no_redundant_nops (g ));
9701
9715
if (remove_redundant_jumps (g ) < 0 ) {
9702
9716
return -1 ;
9703
9717
}
0 commit comments