8000 address review · python/cpython@d3768ac · GitHub
[go: up one dir, main page]

Skip to content

Commit d3768ac

Browse files
committed
address review
1 parent 0845cd7 commit d3768ac

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
@@ -1339,12 +1339,12 @@ add_const(PyObject *newconst, PyObject *consts, PyObject *const_cache)
13391339
}
13401340

13411341
/*
1342-
Walk basic block upwards starting from "start" trying to collect "size" number of
1342+
Walk basic block backwards starting from "start" trying to collect "size" number of
13431343
subsequent constants from instructions loading constants into new tuple ignoring NOP's in between.
13441344
1345-
Returns -1 on error and sets "seq" to NULL.
1346-
Returns 0 on success and sets "seq" to NULL if failed to collect requested number of constants.
1347-
Returns 0 on success and sets "seq" to resulting tuple if succeeded to collect requested number of constants.
1345+
Returns ERROR on error and sets "seq" to NULL.
1346+
Returns SUCCESS on success and sets "seq" to NULL if failed to collect requested number of constants.
1347+
Returns SUCCESS on success and sets "seq" to resulting tuple if succeeded to collect requested number of constants.
13481348
*/
13491349
static int
13501350
get_constant_sequence(basicblock *bb, int start, int size,
@@ -1354,7 +1354,7 @@ get_constant_sequence(basicblock *bb, int start, int size,
13541354
*seq = NULL;
13551355
PyObject *res = PyTuple_New((Py_ssize_t)size);
13561356
if (res == NULL) {
1357-
return -1;
1357+
return ERROR;
13581358
}
13591359
for (; start >= 0 && size > 0; start--) {
13601360
cfg_instr *instr = &bb->b_instr[start];
@@ -1367,7 +1367,7 @@ get_constant_sequence(basicblock *bb, int start, int size,
13671367
PyObject *constant = get_const_value(instr->i_opcode, instr->i_oparg, consts);
13681368
if (constant == NULL) {
13691369
Py_DECREF(res);
1370-
return -1;
1370+
return ERROR;
13711371
}
13721372
PyTuple_SET_ITEM(res, --size, constant);
13731373
}
@@ -1377,15 +1377,14 @@ get_constant_sequence(basicblock *bb, int start, int size,
13771377
else {
13781378
*seq = res;
13791379
}
1380-
return 0;
1380+
return SUCCESS;
13811381
}
13821382

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

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

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

14761471
/*
1477-
Walk basic block upwards starting from "start" to collect instruction pair
1472+
Walk basic block backwards starting from "start" to collect instruction pair
14781473
that loads consts skipping NOP's in between.
14791474
*/
14801475
static bool

0 commit comments

Comments
 (0)
0