@@ -1339,12 +1339,12 @@ add_const(PyObject *newconst, PyObject *consts, PyObject *const_cache)
1339
1339
}
1340
1340
1341
1341
/*
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
1343
1343
subsequent constants from instructions loading constants into new tuple ignoring NOP's in between.
1344
1344
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.
1348
1348
*/
1349
1349
static int
1350
1350
get_constant_sequence (basicblock * bb , int start , int size ,
@@ -1354,7 +1354,7 @@ get_constant_sequence(basicblock *bb, int start, int size,
1354
1354
* seq = NULL ;
1355
1355
PyObject * res = PyTuple_New ((Py_ssize_t )size );
1356
1356
if (res == NULL ) {
1357
- return -1 ;
1357
+ return ERROR ;
1358
1358
}
1359
1359
for (; start >= 0 && size > 0 ; start -- ) {
1360
1360
cfg_instr * instr = & bb -> b_instr [start ];
@@ -1367,7 +1367,7 @@ get_constant_sequence(basicblock *bb, int start, int size,
1367
1367
PyObject * constant = get_const_value (instr -> i_opcode , instr -> i_oparg , consts );
1368
1368
if (constant == NULL ) {
1369
1369
Py_DECREF (res );
1370
- return -1 ;
1370
+ return ERROR ;
1371
1371
}
1372
1372
PyTuple_SET_ITEM (res , -- size , constant );
1373
1373
}
@@ -1377,15 +1377,14 @@ get_constant_sequence(basicblock *bb, int start, int size,
1377
1377
else {
1378
1378
* seq = res ;
1379
1379
}
1380
- return 0 ;
1380
+ return SUCCESS ;
1381
1381
}
1382
1382
1383
1383
/*
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.
1387
1386
*/
1388
- static int
1387
+ static void
1389
1388
nop_out (basicblock * bb , int start , int count )
1390
1389
{
1391
1390
assert (start < bb -> b_iused );
@@ -1398,7 +1397,6 @@ nop_out(basicblock *bb, int start, int count)
1398
1397
count -- ;
1399
1398
}
1400
1399
assert (start >= -1 );
1401
- return start ;
1402
1400
}
1403
1401
1404
1402
/* 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
1425
1423
int index = add_const (newconst , consts , const_cache );
1426
1424
RETURN_IF_ERROR (index );
1427
1425
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 );
1429
1427
return SUCCESS ;
1430
1428
}
1431
1429
@@ -1465,16 +1463,13 @@ optimize_if_const_list_or_set(basicblock *bb, int n, PyObject *consts, PyObject
1465
1463
RETURN_IF_ERROR (index );
1466
1464
INSTR_SET_OP1 (& bb -> b_instr [n ], extend , 1 );
1467
1465
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 );
1473
1468
return SUCCESS ;
1474
1469
}
1475
1470
1476
1471
/*
1477
- Walk basic block upwards starting from "start" to collect instruction pair
1472
+ Walk basic block backwards starting from "start" to collect instruction pair
1478
1473
that loads consts skipping NOP's in between.
1479
1474
*/
1480
1475
static bool
0 commit comments