@@ -263,8 +263,9 @@ dump_instr(cfg_instr *i)
263
263
if (HAS_TARGET (i -> i_opcode )) {
264
264
sprintf (arg , "target: %p [%d] " , i -> i_target , i -> i_oparg );
265
265
}
266
- fprintf (stderr , "line: %d, %s (%d) %s%s\n" ,
267
- i -> i_loc .lineno , _PyOpcode_OpName [i -> i_opcode ], i -> i_opcode , arg , jump );
266
+ fprintf (stderr , "line: %d%s, %s (%d) %s%s\n" ,
267
+ i -> i_loc .lineno , i -> i_loc_propagated ? "(<-)" : "" ,
268
+ _PyOpcode_OpName [i -> i_opcode ], i -> i_opcode , arg , jump );
268
269
}
269
270
270
271
static inline int
@@ -938,6 +939,15 @@ label_exception_targets(basicblock *entryblock) {
938
939
PyMem_Free (except_stack );
939
940
}
940
941
}
942
+
943
+ for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
944
+ for (int i = 0 ; i < b -> b_iused ; i ++ ) {
945
+ cfg_instr * instr = & b -> b_instr [i ];
946
+ if (instr -> i_opcode == POP_BLOCK ) {
947
+ INSTR_SET_OP0 (instr , NOP );
948
+ }
949
+ }
950
+ }
941
951
#ifdef Py_DEBUG
942
952
for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
943
953
assert (b -> b_exceptstack == NULL );
@@ -1006,8 +1016,9 @@ basicblock_remove_redundant_nops(basicblock *bb) {
1006
1016
int dest = 0 ;
1007
1017
int prev_lineno = -1 ;
1008
1018
for (int src = 0 ; src < bb -> b_iused ; src ++ ) {
1009
- int lineno = bb -> b_instr [src ].i_loc .lineno ;
1010
- if (bb -> b_instr [src ].i_opcode == NOP ) {
1019
+ cfg_instr * src_instr = & bb -> b_instr [src ];
1020
+ int lineno = src_instr -> i_loc .lineno ;
1021
+ if (src_instr -> i_opcode == NOP ) {
1011
1022
/* Eliminate no-op if it doesn't have a line number */
1012
1023
if (lineno < 0 ) {
1013
1024
continue ;
@@ -1018,30 +1029,35 @@ basicblock_remove_redundant_nops(basicblock *bb) {
1018
1029
}
1019
1030
/* or, if the next instruction has same line number or no line number */
1020
1031
if (src < bb -> b_iused - 1 ) {
1021
- int next_lineno = bb -> b_instr [src + 1 ].i_loc .lineno ;
1032
+ cfg_instr * next_instr = & bb -> b_instr [src + 1 ];
1033
+ int next_lineno = next_instr -> i_loc .lineno ;
1022
1034
if (next_lineno == lineno ) {
1035
+ next_instr -> i_loc_propagated = src_instr -> i_loc_propagated ;
1023
1036
continue ;
1024
1037
}
1025
1038
if (next_lineno < 0 ) {
1026
- bb -> b_instr [src + 1 ].i_loc = bb -> b_instr [src ].i_loc ;
1039
+ next_instr -> i_loc = src_instr -> i_loc ;
1040
+ next_instr -> i_loc_propagated = src_instr -> i_loc_propagated ;
1027
1041
continue ;
1028
1042
}
1029
1043
}
1030
1044
else {
1031
- basicblock * next = next_nonempty_block (bb -> b_next );
1032
1045
/* or if last instruction in BB and next BB has same line number */
1046
+ basicblock * next = next_nonempty_block (bb -> b_next );
1033
1047
if (next ) {
1034
- location next_loc = NO_LOCATION ;
1048
+ cfg_instr * next_instr = NULL ;
1035
1049
for (int next_i = 0 ; next_i < next -> b_iused ; next_i ++ ) {
1036
- cfg_instr * instr = & next -> b_instr [next_i ];
1037
- if (instr -> i_opcode == NOP && instr -> i_loc .lineno == NO_LOCATION .lineno ) {
1050
+ next_instr = & next -> b_instr [next_i ];
1051
+ if (next_instr -> i_opcode == NOP &&
1052
+ next_instr -> i_loc .lineno == NO_LOCATION .lineno )
1053
+ {
1038
1054
/* Skip over NOPs without location, they will be removed */
1039
1055
continue ;
1040
1056
}
1041
- next_loc = instr -> i_loc ;
1042
1057
break ;
1043
1058
}
1044
- if (lineno == next_loc .lineno ) {
1059
+ if (next_instr && lineno == next_instr -> i_loc .lineno ) {
1060
+ next_instr -> i_loc_propagated = src_instr -> i_loc_propagated ;
1045
1061
continue ;
1046
1062
}
1047
1063
}
@@ -2304,7 +2320,7 @@ convert_pseudo_ops(cfg_builder *g)
2304
2320
for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
2305
2321
for (int i = 0 ; i < b -> b_iused ; i ++ ) {
2306
2322
cfg_instr * instr = & b -> b_instr [i ];
2307
- if (is_block_push (instr ) || instr -> i_opcode == POP_BLOCK ) {
2323
+ if (is_block_push (instr )) {
2308
2324
INSTR_SET_OP0 (instr , NOP );
2309
2325
}
2310
2326
else if (instr -> i_opcode == LOAD_CLOSURE ) {
0 commit comments