Skip to content

Commit 68963b5

Browse files
committed
remove the block from jump_target_label, calculate it from the label id
1 parent 558b04c commit 68963b5

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

Python/compile.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,15 @@ static struct location NO_LOCATION = {-1, -1, -1, -1};
141141

142142
typedef struct jump_target_label_ {
143143
int id;
144-
struct basicblock_ *block;
145144
} jump_target_label;
146145

147-
static struct jump_target_label_ NO_LABEL = {-1, NULL};
146+
static struct jump_target_label_ NO_LABEL = {-1};
148147

149148
#define SAME_LABEL(L1, L2) ((L1).id == (L2).id)
150149
#define IS_LABEL(L) (!SAME_LABEL((L), (NO_LABEL)))
151150

152151
#define NEW_JUMP_TARGET_LABEL(C, NAME) \
153-
jump_target_label NAME = {cfg_new_label_id(CFG_BUILDER(C)), cfg_builder_new_block(CFG_BUILDER(C))}; \
152+
jump_target_label NAME = {cfg_new_label_id(CFG_BUILDER(C))}; \
154153
if (!IS_LABEL(NAME)) { \
155154
return 0; \
156155
}
@@ -1322,18 +1321,12 @@ static int
13221321
cfg_builder_maybe_start_new_block(cfg_builder *g)
13231322
{
13241323
if (cfg_builder_current_block_is_terminated(g)) {
1325-
basicblock *b;
1326-
if (IS_LABEL(g->g_current_label)) {
1327-
b = g->g_current_label.block;
1328-
b->b_label = g->g_current_label.id;
1329-
g->g_current_label = NO_LABEL;
1330-
}
1331-
else {
1332-
b = cfg_builder_new_block(g);
1333-
}
1324+
basicblock *b = cfg_builder_new_block(g);
13341325
if (b == NULL) {
13351326
return -1;
13361327
}
1328+
b->b_label = g->g_current_label.id;
1329+
g->g_current_label = NO_LABEL;
13371330
cfg_builder_use_next_block(g, b);
13381331
}
13391332
return 0;
@@ -7410,16 +7403,15 @@ push_cold_blocks_to_end(cfg_builder *g, int code_flags) {
74107403
if (explicit_jump == NULL) {
74117404
return -1;
74127405
}
7413-
jump_target_label next_label = {b->b_next->b_label, b->b_next};
7406+
jump_target_label next_label = {b->b_next->b_label};
74147407
basicblock_addop(explicit_jump, JUMP, 0, next_label, NO_LOCATION);
74157408
explicit_jump->b_cold = 1;
74167409
explicit_jump->b_next = b->b_next;
74177410
b->b_next = explicit_jump;
74187411

7419-
/* calculate target from target_label */
7420-
/* TODO: formalize an API for adding jumps in the backend */
7412+
/* set target */
74217413
struct instr *last = basicblock_last_instr(explicit_jump);
7422-
last->i_target = last->i_target_label.block;
7414+
last->i_target = b->b_next;
74237415
last->i_target_label = NO_LABEL;
74247416
}
74257417
}

0 commit comments

Comments
 (0)