Skip to content

Commit a990491

Browse files
committed
address review
1 parent 7720c40 commit a990491

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

Python/flowgraph.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,12 +1338,12 @@ add_const(PyObject *newconst, PyObject *consts, PyObject *const_cache)
13381338
}
13391339

13401340
/*
1341-
Walk basic block upwards starting from "start" trying to collect "size" number of
1341+
Walk basic block backwards starting from "start" trying to collect "size" number of
13421342
subsequent constants from instructions loading constants into new tuple ignoring NOP's in between.
13431343
1344-
Returns -1 on error and sets "seq" to NULL.
1345-
Returns 0 on success and sets "seq" to NULL if failed to collect requested number of constants.
1346-
Returns 0 on success and sets "seq" to resulting tuple if succeeded to collect requested number of constants.
1344+
Returns ERROR on error and sets "seq" to NULL.
1345+
Returns SUCCESS on success and sets "seq" to NULL if failed to collect requested number of constants.
1346+
Returns SUCCESS on success and sets "seq" to resulting tuple if succeeded to collect requested number of constants.
13471347
*/
13481348
static int
13491349
get_constant_sequence(basicblock *bb, int start, int size,
@@ -1353,7 +1353,7 @@ get_constant_sequence(basicblock *bb, int start, int size,
13531353
*seq = NULL;
13541354
PyObject *res = PyTuple_New((Py_ssize_t)size);
13551355
if (res == NULL) {
1356-
return -1;
1356+
return ERROR;
13571357
}
13581358
for (; start >= 0 && size > 0; start--) {
13591359
cfg_instr *instr = &bb->b_instr[start];
@@ -1366,7 +1366,7 @@ get_constant_sequence(basicblock *bb, int start, int size,
13661366
PyObject *constant = get_const_value(instr->i_opcode, instr->i_oparg, consts);
13671367
if (constant == NULL) {
13681368
Py_DECREF(res);
1369-
return -1;
1369+
return ERROR;
13701370
}
13711371
PyTuple_SET_ITEM(res, --size, constant);
13721372
}
@@ -1376,15 +1376,14 @@ get_constant_sequence(basicblock *bb, int start, int size,
13761376
else {
13771377
*seq = res;
13781378
}
1379-
return 0;
1379+
return SUCCESS;
13801380
}
13811381

13821382
/*
1383-
Walk basic block upwards starting from "start" and change "count" number of
1384-
non-NOP instructions to NOP's, returning index of first instruction before
1385-
last placed NOP. Returns -1 if last placed NOP was first instruction in the block.
1383+
Walk basic block backwards starting from "start" and change "count" number of
1384+
non-NOP instructions to NOP's.
13861385
*/
1387-
static int
1386+
static void
13881387
nop_out(basicblock *bb, int start, int count)
13891388
{
13901389
assert(start < bb->b_iused);
@@ -1397,7 +1396,6 @@ nop_out(basicblock *bb, int start, int count)
13971396
count--;
13981397
}
13991398
assert(start >= -1);
1400-
return start;
14011399
}
14021400

14031401
/* Replace LOAD_CONST c1, LOAD_CONST c2 ... LOAD_CONST cn, BUILD_TUPLE n
@@ -1424,7 +1422,7 @@ fold_tuple_of_constants(basicblock *bb, int n, PyObject *consts, PyObject *const
14241422
int index = add_const(newconst, consts, const_cache);
14251423
RETURN_IF_ERROR(index);
14261424
INSTR_SET_OP1(&bb->b_instr[n], LOAD_CONST, index);
1427-
(void)nop_out(bb, n-1, seq_size);
1425+
nop_out(bb, n-1, seq_size);
14281426
return SUCCESS;
14291427
}
14301428

@@ -1464,16 +1462,13 @@ optimize_if_const_list_or_set(basicblock *bb, int n, PyObject *consts, PyObject
14641462
RETURN_IF_ERROR(index);
14651463
INSTR_SET_OP1(&bb->b_instr[n], extend, 1);
14661464
INSTR_SET_OP1(&bb->b_instr[n-1], LOAD_CONST, index);
1467-
int i = nop_out(bb, n-2, seq_size-2);
1468-
for (; i > 0 && bb->b_instr[i].i_opcode == NOP; i--);
1469-
assert(i >= 0);
1470-
assert(loads_const(bb->b_instr[i].i_opcode));
1471-
INSTR_SET_OP1(&bb->b_instr[i], build, 0);
1465+
INSTR_SET_OP1(&bb->b_instr[n-2], build, 0);
1466+
nop_out(bb, n-3, seq_size-2);
14721467
return SUCCESS;
14731468
}
14741469

14751470
/*
1476-
Walk basic block upwards starting from "start" to collect instruction pair
1471+
Walk basic block backwards starting from "start" to collect instruction pair
14771472
that loads consts skipping NOP's in between.
14781473
*/
14791474
static bool

0 commit comments

Comments
 (0)