@@ -139,17 +139,22 @@ struct location {
139
139
140
140
static struct location NO_LOCATION = {-1 , -1 , -1 , -1 };
141
141
142
- typedef struct basicblock_ * jump_target_label ;
142
+ typedef struct jump_target_label_ {
143
+ struct basicblock_ * block ;
144
+ } jump_target_label ;
145
+
146
+ static struct jump_target_label_ NO_LABEL = {NULL };
147
+
148
+ #define SAME_LABEL (L1 , L2 ) ((L1).block == (L2).block)
149
+ #define IS_LABEL (L ) (!SAME_LABEL((L), (NO_LABEL)))
143
150
144
151
#define NEW_JUMP_TARGET_LABEL (C , NAME ) \
145
- jump_target_label NAME = compiler_new_block(C); \
146
- if (NAME == NULL ) { \
152
+ jump_target_label NAME = { compiler_new_block(C)} ; \
153
+ if (!IS_LABEL( NAME) ) { \
147
154
return 0; \
148
155
}
149
156
150
- #define USE_LABEL (C , LBL ) compiler_use_next_block(C, LBL)
151
-
152
- #define NO_LABEL NULL
157
+ #define USE_LABEL (C , LBL ) compiler_use_next_block(C, (LBL).block)
153
158
154
159
struct instr {
155
160
int i_opcode ;
@@ -1275,10 +1280,10 @@ basicblock_addop(basicblock *b, int opcode, int oparg,
1275
1280
assert (!IS_ASSEMBLER_OPCODE (opcode ));
1276
1281
assert (HAS_ARG (opcode ) || oparg == 0 );
1277
1282
assert (0 <= oparg && oparg < (1 << 30 ));
1278
- assert ((target == NULL ) ||
1283
+ assert (! IS_LABEL (target ) ||
1279
1284
IS_JUMP_OPCODE (opcode ) ||
1280
1285
IS_BLOCK_PUSH_OPCODE (opcode ));
1281
- assert (oparg == 0 || target == NULL );
1286
+ assert (oparg == 0 || ! IS_LABEL ( target ) );
1282
1287
1283
1288
int off = basicblock_next_instr (b );
1284
1289
if (off < 0 ) {
@@ -1529,9 +1534,9 @@ cfg_builder_addop_i(cfg_builder *g, int opcode, Py_ssize_t oparg, struct locatio
1529
1534
}
1530
1535
1531
1536
static int
1532
- cfg_builder_addop_j (cfg_builder * g , int opcode , basicblock * target , struct location loc )
1537
+ cfg_builder_addop_j (cfg_builder * g , int opcode , jump_target_label target , struct location loc )
1533
1538
{
1534
- assert (target != NULL );
1539
+ assert (IS_LABEL ( target ) );
1535
1540
assert (IS_JUMP_OPCODE (opcode ) || IS_BLOCK_PUSH_OPCODE (opcode ));
1536
1541
return cfg_builder_addop (g , opcode , 0 , target , loc );
1537
1542
}
@@ -1879,7 +1884,7 @@ find_ann(asdl_stmt_seq *stmts)
1879
1884
*/
1880
1885
1881
1886
static int
1882
- compiler_push_fblock (struct compiler * c , enum fblocktype t , jump_target_label b ,
1887
+ compiler_push_fblock (struct compiler * c , enum fblocktype t , jump_target_label block_label ,
1883
1888
jump_target_label exit , void * datum )
1884
1889
{
1885
1890
struct fblockinfo * f ;
@@ -1888,20 +1893,20 @@ compiler_push_fblock(struct compiler *c, enum fblocktype t, jump_target_label b,
1888
1893
}
1889
1894
f = & c -> u -> u_fblock [c -> u -> u_nfblocks ++ ];
1890
1895
f -> fb_type = t ;
1891
- f -> fb_block = b ;
1896
+ f -> fb_block = block_label ;
1892
1897
f -> fb_exit = exit ;
1893
1898
f -> fb_datum = datum ;
1894
1899
return 1 ;
1895
1900
}
1896
1901
1897
1902
static void
1898
- compiler_pop_fblock (struct compiler * c , enum fblocktype t , jump_target_label b )
1903
+ compiler_pop_fblock (struct compiler * c , enum fblocktype t , jump_target_label block_label )
1899
1904
{
1900
1905
struct compiler_unit * u = c -> u ;
1901
1906
assert (u -> u_nfblocks > 0 );
1902
1907
u -> u_nfblocks -- ;
1903
1908
assert (u -> u_fblock [u -> u_nfblocks ].fb_type == t );
1904
- assert (u -> u_fblock [u -> u_nfblocks ].fb_block == b );
1909
+ assert (SAME_LABEL ( u -> u_fblock [u -> u_nfblocks ].fb_block , block_label ) );
1905
1910
}
1906
1911
1907
1912
static int
@@ -2855,7 +2860,7 @@ compiler_jump_if(struct compiler *c, expr_ty e, jump_target_label next, int cond
2855
2860
}
2856
2861
if (!compiler_jump_if (c , (expr_ty )asdl_seq_GET (s , n ), next , cond ))
2857
2862
return 0 ;
2858
- if (next2 != next ) {
2863
+ if (! SAME_LABEL ( next2 , next ) ) {
2859
2864
USE_LABEL (c , next2 );
2860
2865
}
2861
2866
return 1 ;
@@ -5123,12 +5128,12 @@ compiler_sync_comprehension_generator(struct compiler *c,
5123
5128
start = NO_LABEL ;
5124
5129
}
5125
5130
}
5126
- if (start != NO_LABEL ) {
5131
+ if (IS_LABEL ( start ) ) {
5127
5132
VISIT (c , expr , gen -> iter );
5128
5133
ADDOP (c , GET_ITER );
5129
5134
}
5130
5135
}
5131
- if (start != NO_LABEL ) {
5136
+ if (IS_LABEL ( start ) ) {
5132
5137
depth ++ ;
5133
5138
USE_LABEL (c , start );
5134
5139
ADDOP_JUMP (c , FOR_ITER , anchor );
@@ -5179,7 +5184,7 @@ compiler_sync_comprehension_generator(struct compiler *c,
5179
5184
}
5180
5185
5181
5186
USE_LABEL (c , if_cleanup );
5182
- if (start != NO_LABEL ) {
5187
+ if (IS_LABEL ( start ) ) {
5183
5188
ADDOP_JUMP (c , JUMP , start );
5184
5189
5185
5190
USE_LABEL (c , anchor );
@@ -7369,16 +7374,17 @@ push_cold_blocks_to_end(cfg_builder *g, int code_flags) {
7369
7374
if (explicit_jump == NULL ) {
7370
7375
return -1 ;
7371
7376
}
7372
- basicblock_addop (explicit_jump , JUMP , 0 , b -> b_next , NO_LOCATION );
7377
+ jump_target_label next_label = {b -> b_next };
7378
+ basicblock_addop (explicit_jump , JUMP , 0 , next_label , NO_LOCATION );
7373
7379
explicit_jump -> b_cold = 1 ;
7374
7380
explicit_jump -> b_next = b -> b_next ;
7375
7381
b -> b_next = explicit_jump ;
7376
7382
7377
7383
/* calculate target from target_label */
7378
7384
/* TODO: formalize an API for adding jumps in the backend */
7379
7385
struct instr * last = basicblock_last_instr (explicit_jump );
7380
- last -> i_target = last -> i_target_label ;
7381
- last -> i_target_label = NULL ;
7386
+ last -> i_target = last -> i_target_label . block ;
7387
+ last -> i_target_label = NO_LABEL ;
7382
7388
}
7383
7389
}
7384
7390
@@ -9398,8 +9404,8 @@ calculate_jump_targets(basicblock *entryblock)
9398
9404
for (int i = 0 ; i < b -> b_iused ; i ++ ) {
9399
9405
struct instr * instr = & b -> b_instr [i ];
9400
9406
assert (instr -> i_target == NULL );
9401
- instr -> i_target = instr -> i_target_label ;
9402
- instr -> i_target_label = NULL ;
9407
+ instr -> i_target = instr -> i_target_label . block ;
9408
+ instr -> i_target_label = NO_LABEL ;
9403
9409
if (is_jump (instr ) || is_block_push (instr )) {
9404
9410
assert (instr -> i_target != NULL );
9405
9411
}
0 commit comments