]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-143946: Add more debug info in `optimize_uops` (GH-144262)
authorHai Zhu <haiizhu@outlook.com>
Thu, 29 Jan 2026 16:58:01 +0000 (00:58 +0800)
committerGitHub <noreply@github.com>
Thu, 29 Jan 2026 16:58:01 +0000 (16:58 +0000)
Python/optimizer_analysis.c

index 35d72e851af667523b2324c64b1949de0a7112f0..039aacf23ae3a3ec62d9dce6f7b61829c7260563 100644 (file)
@@ -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;