Skip to content

Commit cdde94f

Browse files
committed
remove i_target_label field from struct instr. Use i_oparg instead
1 parent 7e284d1 commit cdde94f

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

Python/compile.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585
(opcode) == SETUP_WITH || \
8686
(opcode) == SETUP_CLEANUP)
8787

88+
#define HAS_TARGET(opcode) \
89+
(IS_JUMP_OPCODE(opcode) || IS_BLOCK_PUSH_OPCODE(opcode))
90+
8891
/* opcodes that must be last in the basicblock */
8992
#define IS_TERMINATOR_OPCODE(opcode) \
9093
(IS_JUMP_OPCODE(opcode) || IS_SCOPE_EXIT_OPCODE(opcode))
@@ -159,14 +162,10 @@ static struct jump_target_label_ NO_LABEL = {-1};
159162
struct instr {
160163
int i_opcode;
161164
int i_oparg;
162-
/* target block (if jump instruction) -- we temporarily have both the label
163-
and the block in the instr. The label is set by front end, and the block
164-
is calculated by backend. */
165-
jump_target_label i_target_label;
166-
struct basicblock_ *i_target;
167-
/* target block when exception is raised, should not be set by front-end. */
168-
struct basicblock_ *i_except;
169165
struct location i_loc;
166+
/* The following fields should not be set by the front-end: */
167+
struct basicblock_ *i_target; /* target block (if jump instruction) */
168+
struct basicblock_ *i_except; /* target block when exception is raised */
170169
};
171170

172171
typedef struct exceptstack {
@@ -1299,8 +1298,12 @@ basicblock_addop(basicblock *b, int opcode, int oparg,
12991298
}
13001299
struct instr *i = &b->b_instr[off];
13011300
i->i_opcode = opcode;
1302-
i->i_oparg = oparg;
1303-
i->i_target_label = target;
1301+
if (HAS_TARGET(opcode)) {
1302+
i->i_oparg = target.id;
1303+
}
1304+
else {
1305+
i->i_oparg = oparg;
1306+
}
13041307
i->i_target = NULL;
13051308
i->i_loc = loc;
13061309

@@ -7085,7 +7088,7 @@ stackdepth(basicblock *entryblock, int code_flags)
70857088
maxdepth = new_depth;
70867089
}
70877090
assert(depth >= 0); /* invalid code or bug in stackdepth() */
7088-
if (is_jump(instr) || is_block_push(instr)) {
7091+
if (HAS_TARGET(instr->i_opcode)) {
70897092
effect = stack_effect(instr->i_opcode, instr->i_oparg, 1);
70907093
assert(effect != PY_INVALID_STACK_EFFECT);
70917094
int target_depth = depth + effect;
@@ -7412,7 +7415,6 @@ push_cold_blocks_to_end(cfg_builder *g, int code_flags) {
74127415
/* set target */
74137416
struct instr *last = basicblock_last_instr(explicit_jump);
74147417
last->i_target = explicit_jump->b_next;
7415-
last->i_target_label = NO_LABEL;
74167418
}
74177419
}
74187420

@@ -8218,12 +8220,9 @@ dump_instr(struct instr *i)
82188220
if (HAS_ARG(i->i_opcode)) {
82198221
sprintf(arg, "arg: %d ", i->i_oparg);
82208222
}
8221-
if (is_jump(i)) {
8223+
if (HAS_TARGET(i->i_opcode)) {
82228224
sprintf(arg, "target: %p ", i->i_target);
82238225
}
8224-
if (is_block_push(i)) {
8225-
sprintf(arg, "except_target: %p ", i->i_target);
8226-
}
82278226
fprintf(stderr, "line: %d, opcode: %d %s%s%s\n",
82288227
i->i_loc.lineno, i->i_opcode, arg, jabs, jrel);
82298228
}
@@ -8966,7 +8965,7 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
89668965
struct instr *inst = &bb->b_instr[i];
89678966
int oparg = inst->i_oparg;
89688967
int nextop = i+1 < bb->b_iused ? bb->b_instr[i+1].i_opcode : 0;
8969-
if (is_jump(inst) || is_block_push(inst)) {
8968+
if (HAS_TARGET(inst->i_opcode)) {
89708969
/* Skip over empty basic blocks. */
89718970
while (inst->i_target->b_iused == 0) {
89728971
inst->i_target = inst->i_target->b_next;
@@ -9371,7 +9370,7 @@ eliminate_empty_basic_blocks(basicblock *entryblock) {
93719370
}
93729371
for (int i = 0; i < b->b_iused; i++) {
93739372
struct instr *instr = &b->b_instr[i];
9374-
if (is_jump(instr) || is_block_push(instr)) {
9373+
if (HAS_TARGET(instr->i_opcode)) {
93759374
basicblock *target = instr->i_target;
93769375
while (target->b_iused == 0) {
93779376
target = target->b_next;
@@ -9450,14 +9449,13 @@ calculate_jump_targets(basicblock *entryblock)
94509449
for (int i = 0; i < b->b_iused; i++) {
94519450
struct instr *instr = &b->b_instr[i];
94529451
assert(instr->i_target == NULL);
9453-
if (is_jump(instr) || is_block_push(instr)) {
9454-
int lbl = instr->i_target_label.id;
9452+
if (HAS_TARGET(instr->i_opcode)) {
9453+
int lbl = instr->i_oparg;
94559454
assert(lbl >= 0 && lbl <= max_label);
94569455
instr->i_target = label2block[lbl];
94579456
assert(instr->i_target != NULL);
94589457
assert(instr->i_target->b_label == lbl);
94599458
}
9460-
instr->i_target_label = NO_LABEL;
94619459
}
94629460
}
94639461
PyMem_Free(label2block);

0 commit comments

Comments
 (0)