summaryrefslogtreecommitdiffstats
path: root/Python/optimizer_analysis.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/optimizer_analysis.c')
-rw-r--r--Python/optimizer_analysis.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c
index 61bda80..3c85964 100644
--- a/Python/optimizer_analysis.c
+++ b/Python/optimizer_analysis.c
@@ -12,13 +12,13 @@
#include <stddef.h>
#include "pycore_optimizer.h"
-
static void
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) {
@@ -28,6 +28,16 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
need_ip = false;
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 {
+ buffer[pc].opcode = NOP;
+ }
+ }
else if (opcode == _JUMP_TO_TOP || opcode == _EXIT_TRACE) {
break;
}
@@ -36,6 +46,9 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
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) {
+ maybe_invalid = true;
+ }
}
}
}