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