Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion Python/optimizer_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#ifdef Py_DEBUG
extern const char *_PyUOpName(int index);
extern void _PyUOpPrint(const _PyUOpInstruction *uop);
extern void _PyUOpSymPrint(JitOptRef ref);
static const char *const DEBUG_ENV = "PYTHON_OPT_DEBUG";
static inline int get_lltrace(void) {
char *uop_debug = Py_GETENV(DEBUG_ENV);
Expand All @@ -50,6 +51,38 @@
}
#define DPRINTF(level, ...) \
if (get_lltrace() >= (level)) { printf(__VA_ARGS__); }



static void
dump_abstract_stack(_Py_UOpsAbstractFrame *frame, JitOptRef *stack_pointer)
{
JitOptRef *stack_base = frame->stack;
JitOptRef *locals_base = frame->locals;
printf(" locals=[");
for (JitOptRef *ptr = locals_base; ptr < stack_base; ptr++) {
if (ptr != locals_base) {
printf(", ");
}
_PyUOpSymPrint(*ptr);
}
printf("]\n");
if (stack_pointer < stack_base) {
printf(" stack=%d\n", (int)(stack_pointer - stack_base));
}
else {
printf(" stack=[");
for (JitOptRef *ptr = stack_base; ptr < stack_pointer; ptr++) {
if (ptr != stack_base) {
printf(", ");
}
_PyUOpSymPrint(*ptr);
}
printf("]\n");
}
fflush(stdout);
}

#else
#define DPRINTF(level, ...)
#endif
Expand Down Expand Up @@ -383,7 +416,10 @@ optimize_uops(
if (get_lltrace() >= 3) {
printf("%4d abs: ", (int)(this_instr - trace));
_PyUOpPrint(this_instr);
printf(" ");
printf(" \n");
if (get_lltrace() >= 5 && !CURRENT_FRAME_IS_INIT_SHIM()) {
dump_abstract_stack(ctx->frame, stack_pointer);
}
}
#endif

Expand Down
47 changes: 47 additions & 0 deletions Python/optimizer_symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,53 @@ static inline int get_lltrace(void) {
}
#define DPRINTF(level, ...) \
if (get_lltrace() >= (level)) { printf(__VA_ARGS__); }

void
_PyUOpSymPrint(JitOptRef ref)
{
if (PyJitRef_IsNull(ref)) {
printf("<JitRef NULL>");
return;
}
JitOptSymbol *sym = PyJitRef_Unwrap(ref);
switch (sym->tag) {
case JIT_SYM_UNKNOWN_TAG:
printf("<UNKNOWN at %p>", (void *)sym);
break;
case JIT_SYM_NULL_TAG:
printf("<NULL at %p>", (void *)sym);
break;
case JIT_SYM_NON_NULL_TAG:
printf("<!NULL at %p>", (void *)sym);
break;
case JIT_SYM_BOTTOM_TAG:
printf("<BOTTOM at %p>", (void *)sym);
break;
case JIT_SYM_TYPE_VERSION_TAG:
printf("<v%u at %p>", sym->version.version, (void *)sym);
break;
case JIT_SYM_KNOWN_CLASS_TAG:
printf("<%s at %p>", sym->cls.type->tp_name, (void *)sym);
break;
case JIT_SYM_KNOWN_VALUE_TAG:
printf("<%s val=%p at %p>", Py_TYPE(sym->value.value)->tp_name,
(void *)sym->value.value, (void *)sym);
break;
case JIT_SYM_TUPLE_TAG:
printf("<tuple[%d] at %p>", sym->tuple.length, (void *)sym);
break;
case JIT_SYM_TRUTHINESS_TAG:
printf("<truthiness%s at %p>", sym->truthiness.invert ? "!" : "", (void *)sym);
break;
case JIT_SYM_COMPACT_INT:
printf("<compact_int at %p>", (void *)sym);
break;
default:
printf("<tag=%d at %p>", sym->tag, (void *)sym);
break;
}
}

#else
#define DPRINTF(level, ...)
#endif
Expand Down
Loading