Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add comments
  • Loading branch information
pablogsal committed Sep 9, 2019
commit 22560ace09692061c12ce08100a42fecbd637317
15 changes: 13 additions & 2 deletions Python/peephole.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@
(ABSOLUTE_JUMP(_Py_OPCODE(arr[i])) ? 0 : i+1))
#define ISBASICBLOCK(blocks, start, end) \
(blocks[start]==blocks[end])
#define MAX_BYTECODE_OPT_ITERS 5

/* Maximum number of iterations of the main peephole optimizer function
* over the same bytecode object. Theretically, this number can be infinite
* as the peephole optimizer keeps the code object untouched or smaller but
* having a higher bound allows us to scope the performance impact of
* repeating the main peephole optimizer function while making sure than even
* if something goes wrong, the loop will always end. */

#define MAX_BYTECODE_OPT_ITERS 5

/* Scans back N consecutive LOAD_CONST instructions, skipping NOPs,
returns index of the Nth last's LOAD_CONST's EXTENDED_ARG prefix.
Expand Down Expand Up @@ -476,9 +483,13 @@ optimize_bytecode_once(PyObject *code, PyObject* consts, PyObject *names,
cum_orig_offset += lnotab[i];
assert(cum_orig_offset % sizeof(_Py_CODEUNIT) == 0);
index = cum_orig_offset / sizeof(_Py_CODEUNIT);
Comment thread
pablogsal marked this conversation as resolved.
if (index >= codelen) {
if (index == codelen) {
/* When running this function multiple times over the same bytecode
* *offset_delta* can be bigger than 255 when the index from the origin
* is exactly as big as the code. In that case we don't need to adjust. */
continue;
} else {
assert(index < codelen);
new_offset = blocks[index] * sizeof(_Py_CODEUNIT);
offset_delta = new_offset - last_offset;
assert(offset_delta < 255);
Expand Down