https://github.com/python/cpython/commit/26996b59ab21fb0a5a4a585f386bbb05935c9bd9
commit: 26996b59ab21fb0a5a4a585f386bbb05935c9bd9
branch: main
author: Hai Zhu <[email protected]>
committer: Fidget-Spinner <[email protected]>
date: 2026-01-29T16:58:01Z
summary:
gh-143946: Add more debug info in `optimize_uops` (GH-144262)
files:
M Python/optimizer_analysis.c
diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c
index 35d72e851af667..039aacf23ae3a3 100644
--- a/Python/optimizer_analysis.c
+++ b/Python/optimizer_analysis.c
@@ -52,8 +52,6 @@
#define DPRINTF(level, ...) \
if (get_lltrace() >= (level)) { printf(__VA_ARGS__); }
-
-
static void
dump_abstract_stack(_Py_UOpsAbstractFrame *frame, JitOptRef *stack_pointer)
{
@@ -83,8 +81,25 @@ dump_abstract_stack(_Py_UOpsAbstractFrame *frame, JitOptRef
*stack_pointer)
fflush(stdout);
}
+static void
+dump_uop(JitOptContext *ctx, const char *label, int index,
+ const _PyUOpInstruction *instr, JitOptRef *stack_pointer)
+{
+ if (get_lltrace() >= 3) {
+ printf("%4d %s: ", index, label);
+ _PyUOpPrint(instr);
+ printf("\n");
+ if (get_lltrace() >= 5 && ctx->frame->code != ((PyCodeObject
*)&_Py_InitCleanup)) {
+ dump_abstract_stack(ctx->frame, stack_pointer);
+ }
+ }
+}
+
+#define DUMP_UOP dump_uop
+
#else
#define DPRINTF(level, ...)
+ #define DUMP_UOP(ctx, label, index, instr, stack_pointer)
#endif
static int
@@ -347,19 +362,19 @@ get_code_with_logging(_PyUOpInstruction *op)
uint64_t push_operand = op->operand0;
if (push_operand & 1) {
co = (PyCodeObject *)(push_operand & ~1);
- DPRINTF(3, "code=%p ", co);
+ DPRINTF(3, " code=%p\n", co);
assert(PyCode_Check(co));
}
else {
PyFunctionObject *func = (PyFunctionObject *)push_operand;
- DPRINTF(3, "func=%p ", func);
+ DPRINTF(3, " func=%p ", func);
if (func == NULL) {
DPRINTF(3, "\n");
DPRINTF(1, "Missing function\n");
return NULL;
}
co = (PyCodeObject *)func->func_code;
- DPRINTF(3, "code=%p ", co);
+ DPRINTF(3, "code=%p\n", co);
}
return co;
}
@@ -493,16 +508,7 @@ optimize_uops(
stack_pointer = ctx->frame->stack_pointer;
}
-#ifdef Py_DEBUG
- if (get_lltrace() >= 3) {
- printf("%4d abs: ", (int)(this_instr - trace));
- _PyUOpPrint(this_instr);
- printf(" \n");
- if (get_lltrace() >= 5 && !CURRENT_FRAME_IS_INIT_SHIM()) {
- dump_abstract_stack(ctx->frame, stack_pointer);
- }
- }
-#endif
+ DUMP_UOP(ctx, "abs", this_instr - trace, this_instr, stack_pointer);
_PyUOpInstruction *out_ptr = ctx->out_buffer.next;
@@ -519,6 +525,7 @@ optimize_uops(
*(ctx->out_buffer.next++) = *this_instr;
}
assert(ctx->frame != NULL);
+ DUMP_UOP(ctx, "out", uop_buffer_length(&ctx->out_buffer) - 1, out_ptr,
stack_pointer);
if (!CURRENT_FRAME_IS_INIT_SHIM() && !ctx->done) {
DPRINTF(3, " stack_level %d\n", STACK_LEVEL());
ctx->frame->stack_pointer = stack_pointer;
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]