From 6f1f638836629227d783604d00433e89746d9729 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Fri, 12 Sep 2025 15:42:09 -0700 Subject: [PATCH] Make the INTERP_DUMP macro useable throughout the compiler, even for methods in other classes which are used in the compiler --- src/coreclr/interpreter/compiler.cpp | 42 +++++++++++-------------- src/coreclr/interpreter/compiler.h | 28 ++++++++++++----- src/coreclr/interpreter/compileropt.cpp | 4 +-- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/coreclr/interpreter/compiler.cpp b/src/coreclr/interpreter/compiler.cpp index 602e89ebd61625..9402820e576035 100644 --- a/src/coreclr/interpreter/compiler.cpp +++ b/src/coreclr/interpreter/compiler.cpp @@ -9,6 +9,8 @@ #include // for std::bad_alloc +thread_local bool t_interpDump; + static const StackType g_stackTypeFromInterpType[] = { StackTypeI4, // I1 @@ -138,7 +140,7 @@ void InterpCompiler::CopyToInterpGenericLookup(InterpGenericLookup* dst, const C GetGenericLookupOffset(src, 2) > UINT16_MAX || GetGenericLookupOffset(src, 3) > UINT16_MAX) { #ifdef DEBUG - if (m_verbose) + if (t_interpDump) { printf("CopyToInterpGenericLookup: Offsets too large for generic lookup, unable to compile\n"); printf(" Indirections: %d\n", (int)src->indirections); @@ -1056,12 +1058,8 @@ class InterpGcSlotAllocator TArray m_liveRanges; - void InsertRange(InterpCompiler* pCompiler, uint32_t start, uint32_t end) + void InsertRange(uint32_t start, uint32_t end) { -#ifdef DEBUG - bool m_verbose = pCompiler->m_verbose; -#endif - ConservativeRange newRange(start, end); if (m_liveRanges.GetSize() != 0) @@ -1126,10 +1124,6 @@ class InterpGcSlotAllocator unsigned m_slotTableSize; -#ifdef DEBUG - bool m_verbose; -#endif - GcSlotId* LocateGcSlotTableEntry(uint32_t offsetBytes, GcSlotFlags flags) { GcSlotId *slotTable = m_slotTables[(flags & GC_SLOT_INTERIOR) == GC_SLOT_INTERIOR]; @@ -1144,9 +1138,6 @@ class InterpGcSlotAllocator , m_encoder(encoder) , m_conservativeRanges(compiler->GetMemPoolAllocator()) , m_slotTableSize(compiler->m_totalVarsStackSize / sizeof(void *)) -#ifdef DEBUG - , m_verbose(compiler->m_verbose) -#endif { for (int i = 0; i < 2; i++) { @@ -1210,7 +1201,7 @@ class InterpGcSlotAllocator { m_conservativeRanges.Set(slotIndex, new (m_compiler) ConservativeRanges(m_compiler)); } - m_conservativeRanges.Get(slotIndex)->InsertRange(m_compiler, startOffset, endOffset); + m_conservativeRanges.Get(slotIndex)->InsertRange(startOffset, endOffset); } void ReportConservativeRangesToGCEncoder() @@ -1564,9 +1555,15 @@ static void FreeInterpreterStackMap(void *key, void *value, void *userdata) InterpCompiler::InterpCompiler(COMP_HANDLE compHnd, CORINFO_METHOD_INFO* methodInfo) : - #ifdef DEBUG +#ifdef DEBUG +#ifdef TARGET_WASM + // enable verbose output on wasm temporarily + m_dumpScope(true), +#else + m_dumpScope(InterpConfig.InterpDump().contains(compHnd, methodInfo->ftn, compHnd->getMethodClass(methodInfo->ftn), &methodInfo->args)), +#endif m_methodName(GetMallocAllocator()), - #endif +#endif m_stackmapsByClass(FreeInterpreterStackMap) , m_pInitLocalsIns(nullptr) , m_hiddenArgumentVar(-1) @@ -1594,16 +1591,13 @@ InterpCompiler::InterpCompiler(COMP_HANDLE compHnd, /* includeSignature */ true, /* includeReturnType */ false, /* includeThis */ false); - - if (InterpConfig.InterpDump().contains(compHnd, m_methodHnd, m_classHnd, &m_methodInfo->args)) - m_verbose = true; #endif } InterpMethod* InterpCompiler::CompileMethod() { #ifdef DEBUG - if (m_verbose || InterpConfig.InterpList()) + if (t_interpDump || InterpConfig.InterpList()) { printf("Interpreter compile method %s\n", m_methodName.GetUnderlyingArray()); } @@ -1614,7 +1608,7 @@ InterpMethod* InterpCompiler::CompileMethod() GenerateCode(m_methodInfo); #ifdef DEBUG - if (m_verbose) + if (t_interpDump) { printf("\nUnoptimized IR:\n"); PrintCode(); @@ -1627,7 +1621,7 @@ InterpMethod* InterpCompiler::CompileMethod() EmitCode(); #ifdef DEBUG - if (m_verbose) + if (t_interpDump) { printf("\nCompiled method: "); PrintMethodName(m_methodHnd); @@ -2782,7 +2776,7 @@ bool InterpCompiler::EmitNamedIntrinsicCall(NamedIntrinsic ni, CORINFO_CLASS_HAN default: { #ifdef DEBUG - if (m_verbose) + if (t_interpDump) { const char* className = NULL; const char* namespaceName = NULL; @@ -4252,7 +4246,7 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo) m_ppOffsetToBB[insOffset] = m_pCBB; #ifdef DEBUG - if (m_verbose) + if (t_interpDump) { const uint8_t *ip = m_ip; printf("IL_%04x %-10s, sp %d, %s", diff --git a/src/coreclr/interpreter/compiler.h b/src/coreclr/interpreter/compiler.h index c26af21601026e..c2c2378c7ee51e 100644 --- a/src/coreclr/interpreter/compiler.h +++ b/src/coreclr/interpreter/compiler.h @@ -184,9 +184,26 @@ enum InterpType { }; #ifdef DEBUG +extern thread_local bool t_interpDump; + +class InterpDumpScope +{ + bool m_prev; + public: + InterpDumpScope(bool enable) + { + m_prev = t_interpDump; + t_interpDump = enable; + } + ~InterpDumpScope() + { + t_interpDump = m_prev; + } +}; + #define INTERP_DUMP(...) \ { \ - if (m_verbose) \ + if (t_interpDump) \ printf(__VA_ARGS__); \ } #else @@ -448,6 +465,9 @@ class InterpCompiler friend class InterpGcSlotAllocator; private: +#ifdef DEBUG + InterpDumpScope m_dumpScope; +#endif CORINFO_METHOD_HANDLE m_methodHnd; CORINFO_MODULE_HANDLE m_compScopeHnd; COMP_HANDLE m_compHnd; @@ -489,12 +509,6 @@ class InterpCompiler CORINFO_CLASS_HANDLE m_classHnd; #ifdef DEBUG TArray m_methodName; -#ifdef TARGET_WASM - // enable verbose output on wasm temporarily - bool m_verbose = true; -#else - bool m_verbose = false; -#endif // TARGET_WASM const char* PointerIsClassHandle = (const char*)0x1; const char* PointerIsMethodHandle = (const char*)0x2; diff --git a/src/coreclr/interpreter/compileropt.cpp b/src/coreclr/interpreter/compileropt.cpp index 92018b0d6a1845..66069842f770ca 100644 --- a/src/coreclr/interpreter/compileropt.cpp +++ b/src/coreclr/interpreter/compileropt.cpp @@ -310,7 +310,7 @@ void InterpCompiler::AllocOffsets() continue; #ifdef DEBUG - if (m_verbose) + if (t_interpDump) { printf("\tins_index %d\t", insIndex); PrintIns(pIns); @@ -376,7 +376,7 @@ void InterpCompiler::AllocOffsets() } #ifdef DEBUG - if (m_verbose) + if (t_interpDump) { printf("active vars:"); for (int i = 0; i < m_pActiveVars->GetSize(); i++)