mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
GH-111848: Set the IP when de-optimizing (GH-112065)
* Replace jumps with deopts in tier 2 * Fewer special cases of uop names * Add target field to uop IR * Remove more redundant SET_IP and _CHECK_VALIDITY micro-ops * Extend whitelist of non-escaping API functions.
This commit is contained in:
parent
0cfdd6e3d1
commit
4bbb367ba6
6 changed files with 118 additions and 98 deletions
|
@ -17,21 +17,15 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
|
|||
{
|
||||
// Note that we don't enter stubs, those SET_IPs are needed.
|
||||
int last_set_ip = -1;
|
||||
bool need_ip = true;
|
||||
bool maybe_invalid = false;
|
||||
for (int pc = 0; pc < buffer_size; pc++) {
|
||||
int opcode = buffer[pc].opcode;
|
||||
if (opcode == _SET_IP) {
|
||||
if (!need_ip && last_set_ip >= 0) {
|
||||
buffer[last_set_ip].opcode = NOP;
|
||||
}
|
||||
need_ip = false;
|
||||
buffer[pc].opcode = NOP;
|
||||
last_set_ip = pc;
|
||||
}
|
||||
else if (opcode == _CHECK_VALIDITY) {
|
||||
if (maybe_invalid) {
|
||||
/* Exiting the trace requires that IP is correct */
|
||||
need_ip = true;
|
||||
maybe_invalid = false;
|
||||
}
|
||||
else {
|
||||
|
@ -42,12 +36,16 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
|
|||
break;
|
||||
}
|
||||
else {
|
||||
// If opcode has ERROR or DEOPT, set need_ip to true
|
||||
if (_PyOpcode_opcode_metadata[opcode].flags & (HAS_ERROR_FLAG | HAS_DEOPT_FLAG) || opcode == _PUSH_FRAME) {
|
||||
need_ip = true;
|
||||
}
|
||||
if (_PyOpcode_opcode_metadata[opcode].flags & HAS_ESCAPES_FLAG) {
|
||||
if (OPCODE_HAS_ESCAPES(opcode)) {
|
||||
maybe_invalid = true;
|
||||
if (last_set_ip >= 0) {
|
||||
buffer[last_set_ip].opcode = _SET_IP;
|
||||
}
|
||||
}
|
||||
if (OPCODE_HAS_ERROR(opcode) || opcode == _PUSH_FRAME) {
|
||||
if (last_set_ip >= 0) {
|
||||
buffer[last_set_ip].opcode = _SET_IP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue