Skip to content

Commit 37635ba

Browse files
committed
Wire up PYTHONJITDUMPLIR env var for LIR dump output
Add shouldDumpLir() helper in gen_asm.cpp that checks both getConfig().log.dump_lir and the PYTHONJITDUMPLIR environment variable. The env var fallback is needed because the C++ FlagProcessor may not pick up -X options due to init ordering in Phoenix builds. The env var result is cached after first check (static local). All 4 JIT_LOGIF dump sites now use shouldDumpLir(). This is a permanent verification tool per Alex's directive — amortised cost over all future C++→C conversions.
1 parent 615cba2 commit 37635ba

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Python/jit/codegen/gen_asm.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ namespace jit::codegen {
6767

6868
namespace {
6969

70+
// Check if LIR dumping is enabled — respects both the config flag and
71+
// PYTHONJITDUMPLIR env var (needed when the C++ FlagProcessor doesn't
72+
// pick up the flag due to init ordering).
73+
static bool shouldDumpLir() {
74+
if (getConfig().log.dump_lir) {
75+
return true;
76+
}
77+
static int env_checked = -1;
78+
if (env_checked == -1) {
79+
const char* env = getenv("PYTHONJITDUMPLIR");
80+
env_checked = (env && env[0] != '\0' && env[0] != '0') ? 1 : 0;
81+
}
82+
return env_checked == 1;
83+
}
84+
7085
#define ASM_CHECK_THROW(exp) \
7186
{ \
7287
auto err = (exp); \
@@ -1263,7 +1278,7 @@ void* NativeGenerator::getVectorcallEntry() {
12631278
lir_func = lirgen.TranslateFunction())
12641279

12651280
JIT_LOGIF(
1266-
getConfig().log.dump_lir,
1281+
shouldDumpLir(),
12671282
"LIR for {} after generation:\n{}",
12681283
GetFunction()->fullname,
12691284
*lir_func);
@@ -1275,7 +1290,7 @@ void* NativeGenerator::getVectorcallEntry() {
12751290
post_gen.run())
12761291

12771292
JIT_LOGIF(
1278-
getConfig().log.dump_lir,
1293+
shouldDumpLir(),
12791294
"LIR for {} after postgen rewrites:\n{}",
12801295
GetFunction()->fullname,
12811296
*lir_func);
@@ -1309,7 +1324,7 @@ void* NativeGenerator::getVectorcallEntry() {
13091324
}
13101325

13111326
JIT_LOGIF(
1312-
getConfig().log.dump_lir,
1327+
shouldDumpLir(),
13131328
"LIR for {} after register allocation:\n{}",
13141329
GetFunction()->fullname,
13151330
*lir_func);
@@ -1321,7 +1336,7 @@ void* NativeGenerator::getVectorcallEntry() {
13211336
post_rewrite.run())
13221337

13231338
JIT_LOGIF(
1324-
getConfig().log.dump_lir,
1339+
shouldDumpLir(),
13251340
"LIR for {} after postalloc rewrites:\n{}",
13261341
GetFunction()->fullname,
13271342
*lir_func);

0 commit comments

Comments
 (0)