Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit df2766c

Browse files
committedAug 3, 2022
Revert "remove the block from jump_target_label, calculate it from the label id"
This reverts commit 68963b5.
1 parent 09c699b commit df2766c

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed
 

‎Python/compile.c

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

142142
typedef struct jump_target_label_ {
143143
int id;
144+
struct basicblock_ *block;
144145
} jump_target_label;
145146

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

148149
#define SAME_LABEL(L1, L2) ((L1).id == (L2).id)
149150
#define IS_LABEL(L) (!SAME_LABEL((L), (NO_LABEL)))
150151

151152
#define NEW_JUMP_TARGET_LABEL(C, NAME) \
152-
jump_target_label NAME = {cfg_new_label_id(CFG_BUILDER(C))}; \
153+
jump_target_label NAME = {cfg_new_label_id(CFG_BUILDER(C)), cfg_builder_new_block(CFG_BUILDER(C))}; \
153154
if (!IS_LABEL(NAME)) { \
154155
return 0; \
155156
}
@@ -1321,12 +1322,18 @@ static int
13211322
cfg_builder_maybe_start_new_block(cfg_builder *g)
13221323
{
13231324
if (cfg_builder_current_block_is_terminated(g)) {
1324-
basicblock *b = cfg_builder_new_block(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+
}
13251334
if (b == NULL) {
13261335
return -1;
13271336
}
1328-
b->b_label = g->g_current_label.id;
1329-
g->g_current_label = NO_LABEL;
13301337
cfg_builder_use_next_block(g, b);
13311338
}
13321339
return 0;
@@ -7403,15 +7410,16 @@ push_cold_blocks_to_end(cfg_builder *g, int code_flags) {
74037410
if (explicit_jump == NULL) {
74047411
return -1;
74057412
}
7406-
jump_target_label next_label = {b->b_next->b_label};
7413+
jump_target_label next_label = {b->b_next->b_label, b->b_next};
74077414
basicblock_addop(explicit_jump, JUMP, 0, next_label, NO_LOCATION);
74087415
explicit_jump->b_cold = 1;
74097416
explicit_jump->b_next = b->b_next;
74107417
b->b_next = explicit_jump;
74117418

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

0 commit comments

Comments
 (0)
Please sign in to comment.