@@ -137,6 +137,27 @@ basicblock_append_instructions(basicblock *target, basicblock *source)
137
137
return SUCCESS ;
138
138
}
139
139
140
+ static cfg_instr *
141
+ basicblock_last_instr (const basicblock * b ) {
142
+ assert (b -> b_iused >= 0 );
143
+ if (b -> b_iused > 0 ) {
144
+ assert (b -> b_instr != NULL );
145
+ return & b -> b_instr [b -> b_iused - 1 ];
146
+ }
147
+ return NULL ;
148
+ }
149
+
150
+ static inline int
151
+ basicblock_nofallthrough (const _PyCfgBasicblock * b ) {
152
+ _PyCfgInstruction * last = basicblock_last_instr (b );
153
+ return (last &&
154
+ (IS_SCOPE_EXIT_OPCODE (last -> i_opcode ) ||
155
+ IS_UNCONDITIONAL_JUMP_OPCODE (last -> i_opcode )));
156
+ }
157
+
158
+ #define BB_NO_FALLTHROUGH (B ) (basicblock_nofallthrough(B))
159
+ #define BB_HAS_FALLTHROUGH (B ) (!basicblock_nofallthrough(B))
160
+
140
161
static basicblock *
141
162
copy_basicblock (cfg_builder * g , basicblock * block )
142
163
{
@@ -186,7 +207,7 @@ dump_instr(cfg_instr *i)
186
207
187
208
static inline int
188
209
basicblock_returns (const basicblock * b ) {
189
- cfg_instr * last = _PyCfg_BasicblockLastInstr (b );
210
+ cfg_instr * last = basicblock_last_instr (b );
190
211
return last && (last -> i_opcode == RETURN_VALUE || last -> i_opcode == RETURN_CONST );
191
212
}
192
213
@@ -228,26 +249,16 @@ cfg_builder_use_next_block(cfg_builder *g, basicblock *block)
228
249
return block ;
229
250
}
230
251
231
- cfg_instr *
232
- _PyCfg_BasicblockLastInstr (const basicblock * b ) {
233
- assert (b -> b_iused >= 0 );
234
- if (b -> b_iused > 0 ) {
235
- assert (b -> b_instr != NULL );
236
- return & b -> b_instr [b -> b_iused - 1 ];
237
- }
238
- return NULL ;
239
- }
240
-
241
252
static inline int
242
253
basicblock_exits_scope (const basicblock * b ) {
243
- cfg_instr * last = _PyCfg_BasicblockLastInstr (b );
254
+ cfg_instr * last = basicblock_last_instr (b );
244
255
return last && IS_SCOPE_EXIT_OPCODE (last -> i_opcode );
245
256
}
246
257
247
258
static bool
248
259
cfg_builder_current_block_is_terminated (cfg_builder * g )
249
260
{
250
- cfg_instr * last = _PyCfg_BasicblockLastInstr (g -> g_curblock );
261
+ cfg_instr * last = basicblock_last_instr (g -> g_curblock );
251
262
if (last && IS_TERMINATOR_OPCODE (last -> i_opcode )) {
252
263
return true;
253
264
}
@@ -371,7 +382,7 @@ no_empty_basic_blocks(cfg_builder *g) {
371
382
static bool
372
383
no_redundant_jumps (cfg_builder * g ) {
373
384
for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
374
- cfg_instr * last = _PyCfg_BasicblockLastInstr (b );
385
+ cfg_instr * last = basicblock_last_instr (b );
375
386
if (last != NULL ) {
376
387
if (IS_UNCONDITIONAL_JUMP_OPCODE (last -> i_opcode )) {
377
388
assert (last -> i_target != b -> b_next );
@@ -390,7 +401,7 @@ no_redundant_jumps(cfg_builder *g) {
390
401
391
402
static int
392
403
normalize_jumps_in_block (cfg_builder * g , basicblock * b ) {
393
- cfg_instr * last = _PyCfg_BasicblockLastInstr (b );
404
+ cfg_instr * last = basicblock_last_instr (b );
394
405
if (last == NULL || !is_jump (last ) ||
395
406
IS_UNCONDITIONAL_JUMP_OPCODE (last -> i_opcode )) {
396
407
return SUCCESS ;
@@ -953,7 +964,7 @@ remove_redundant_jumps(cfg_builder *g) {
953
964
*/
954
965
assert (no_empty_basic_blocks (g ));
955
966
for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
956
- cfg_instr * last = _PyCfg_BasicblockLastInstr (b );
967
+ cfg_instr * last = basicblock_last_instr (b );
957
968
assert (last != NULL );
958
969
assert (!IS_ASSEMBLER_OPCODE (last -> i_opcode ));
959
970
if (IS_UNCONDITIONAL_JUMP_OPCODE (last -> i_opcode )) {
@@ -979,7 +990,7 @@ remove_redundant_jumps(cfg_builder *g) {
979
990
*/
980
991
static int
981
992
inline_small_exit_blocks (basicblock * bb ) {
982
- cfg_instr * last = _PyCfg_BasicblockLastInstr (bb );
993
+ cfg_instr * last = basicblock_last_instr (bb );
983
994
if (last == NULL ) {
984
995
return 0 ;
985
996
}
@@ -1715,7 +1726,7 @@ scan_block_for_locals(basicblock *b, basicblock ***sp)
1715
1726
if (b -> b_next && BB_HAS_FALLTHROUGH (b )) {
1716
1727
maybe_push (b -> b_next , unsafe_mask , sp );
1717
1728
}
1718
- cfg_instr * last = _PyCfg_BasicblockLastInstr (b );
1729
+ cfg_instr * last = basicblock_last_instr (b );
1719
1730
if (last && is_jump (last )) {
1720
1731
assert (last -> i_target != NULL );
1721
1732
maybe_push (last -> i_target , unsafe_mask , sp );
@@ -2020,7 +2031,7 @@ push_cold_blocks_to_end(cfg_builder *g, int code_flags) {
2020
2031
b -> b_next = explicit_jump ;
2021
2032
2022
2033
/* set target */
2023
- cfg_instr * last = _PyCfg_BasicblockLastInstr (explicit_jump );
2034
+ cfg_instr * last = basicblock_last_instr (explicit_jump );
2024
2035
last -> i_target = explicit_jump -> b_next ;
2025
2036
}
2026
2037
}
@@ -2126,7 +2137,7 @@ duplicate_exits_without_lineno(cfg_builder *g)
2126
2137
*/
2127
2138
basicblock * entryblock = g -> g_entryblock ;
2128
2139
for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
2129
- cfg_instr * last = _PyCfg_BasicblockLastInstr (b );
2140
+ cfg_instr * last = basicblock_last_instr (b );
2130
2141
assert (last != NULL );
2131
2142
if (is_jump (last )) {
2132
2143
basicblock * target = last -> i_target ;
@@ -2150,7 +2161,7 @@ duplicate_exits_without_lineno(cfg_builder *g)
2150
2161
for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
2151
2162
if (BB_HAS_FALLTHROUGH (b ) && b -> b_next && b -> b_iused > 0 ) {
2152
2163
if (is_exit_without_lineno (b -> b_next )) {
2153
- cfg_instr * last = _PyCfg_BasicblockLastInstr (b );
2164
+ cfg_instr * last = basicblock_last_instr (b );
2154
2165
assert (last != NULL );
2155
2166
b -> b_next -> b_instr [0 ].i_loc = last -> i_loc ;
2156
2167
}
@@ -2170,7 +2181,7 @@ duplicate_exits_without_lineno(cfg_builder *g)
2170
2181
static void
2171
2182
propagate_line_numbers (basicblock * entryblock ) {
2172
2183
for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
2173
- cfg_instr * last = _PyCfg_BasicblockLastInstr (b );
2184
+ cfg_instr * last = basicblock_last_instr (b );
2174
2185
if (last == NULL ) {
2175
2186
continue ;
2176
2187
}
@@ -2210,7 +2221,7 @@ guarantee_lineno_for_exits(basicblock *entryblock, int firstlineno) {
2210
2221
int lineno = firstlineno ;
2211
2222
assert (lineno > 0 );
2212
2223
for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
2213
- cfg_instr * last = _PyCfg_BasicblockLastInstr (b );
2224
+ cfg_instr * last = basicblock_last_instr (b );
2214
2225
if (last == NULL ) {
2215
2226
continue ;
2216
2227
}
0 commit comments