aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/optimizer_analysis.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-11-15 15:48:58 +0000
committerGitHub <noreply@github.com>2023-11-15 15:48:58 +0000
commit4bbb367ba65e1df7307f7c6a33afd3c369592188 (patch)
treef771937bb812896de63e1a4252ee6c3217644690 /Python/optimizer_analysis.c
parent0cfdd6e3d17fee8c1c1f4b42b2146abcb43aa34b (diff)
downloadcpython-4bbb367ba65e1df7307f7c6a33afd3c369592188.tar.gz
cpython-4bbb367ba65e1df7307f7c6a33afd3c369592188.zip
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.
Diffstat (limited to 'Python/optimizer_analysis.c')
-rw-r--r--Python/optimizer_analysis.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c
index 3c8596463fd..0f9bc085f22 100644
--- a/Python/optimizer_analysis.c
+++ b/Python/optimizer_analysis.c
@@ -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;
+ }
}
}
}