8000 GH-111848: Convert remaining jumps to deopts into tier 2 code. by markshannon · Pull Request #112045 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-111848: Convert remaining jumps to deopts into tier 2 code. #112045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 14, 2023
Merged
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
Address review comments
  • Loading branch information
markshannon committed Nov 12, 2023
commit 68d1b276894d3b1e1ea8beb3abd8c4717c56fd7a
16 changes: 3 additions & 13 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ _PyUop_Replacements[OPCODE_METADATA_SIZE] = {
};

static const uint16_t
BRANCH_TO_GUARDS[4][2] = {
BRANCH_TO_GUARD[4][2] = {
[POP_JUMP_IF_FALSE - POP_JUMP_IF_FALSE][0] = _GUARD_IS_TRUE_POP,
[POP_JUMP_IF_FALSE - POP_JUMP_IF_FALSE][1] = _GUARD_IS_FALSE_POP,
[POP_JUMP_IF_TRUE - POP_JUMP_IF_FALSE][0] = _GUARD_IS_FALSE_POP,
Expand Down Expand Up @@ -549,7 +549,7 @@ translate_bytecode_to_trace(
int counter = instr[1].cache;
int bitcount = _Py_popcount32(counter);
int jump_likely = bitcount > 8;
uint32_t uopcode = BRANCH_TO_GUARDS[opcode - POP_JUMP_IF_FALSE][jump_likely];
uint32_t uopcode = BRANCH_TO_GUARD[opcode - POP_JUMP_IF_FALSE][jump_likely];
_Py_CODEUNIT *next_instr = instr + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[opcode]];
DPRINTF(4, "%s(%d): counter=%x, bitcount=%d, likely=%d, uopcode=%s\n",
uop_name(opcode), oparg,
Expand Down Expand Up @@ -766,16 +766,6 @@ translate_bytecode_to_trace(
#define SET_BIT(array, bit) (array[(bit)>>5] |= (1<<((bit)&31)))
#define BIT_IS_SET(array, bit) (array[(bit)>>5] & (1<<((bit)&31)))

static bool
is_branch(int opcode) {
/* Currently there are no jumps in the buffer,
* but we expect the optimizer to add them
* in the future. */
assert(opcode != _POP_JUMP_IF_FALSE &&
opcode != _POP_JUMP_IF_TRUE);
return false;
}

/* Count the number of used uops, and mark them in the bit vector `used`.
* This can be done in a single pass using simple reachability analysis,
* as there are no backward jumps.
Expand All @@ -797,7 +787,7 @@ compute_used(_PyUOpInstruction *buffer, uint32_t *used)
}
/* All other micro-ops fall through, so i+1 is reachable */
SET_BIT(used, i+1);
if (is_branch(opcode)) {
if (OPCODE_HAS_JUMP(opcode)) {
/* Mark target as reachable */
SET_BIT(used, buffer[i].oparg);
}
Expand Down
0