summaryrefslogtreecommitdiffstats
path: root/Python/optimizer_analysis.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-11-06 11:28:52 (GMT)
committerGitHub <noreply@github.com>2023-11-06 11:28:52 (GMT)
commitd78c872e0d680f6e63afa6661df5021775a03690 (patch)
tree2be2c8bd0caeedc4848e7919894cb0a26ece32a3 /Python/optimizer_analysis.c
parentc8faa3568afd255708096f6aa8df0afa80cf7697 (diff)
downloadcpython-d78c872e0d680f6e63afa6661df5021775a03690.zip
cpython-d78c872e0d680f6e63afa6661df5021775a03690.tar.gz
cpython-d78c872e0d680f6e63afa6661df5021775a03690.tar.bz2
GH-111646: Simplify optimizer, by compacting uops when making executor. (GH-111647)
Diffstat (limited to 'Python/optimizer_analysis.c')
-rw-r--r--Python/optimizer_analysis.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c
index 2d177f1..61bda80 100644
--- a/Python/optimizer_analysis.c
+++ b/Python/optimizer_analysis.c
@@ -13,13 +13,42 @@
#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;
+ 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;
+ last_set_ip = pc;
+ }
+ else if (opcode == _JUMP_TO_TOP || opcode == _EXIT_TRACE) {
+ 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;
+ }
+ }
+ }
+}
+
+
int
_Py_uop_analyze_and_optimize(
PyCodeObject *co,
- _PyUOpInstruction *trace,
- int trace_len,
+ _PyUOpInstruction *buffer,
+ int buffer_size,
int curr_stacklen
)
{
- return trace_len;
+ remove_unneeded_uops(buffer, buffer_size);
+ return 0;
}