summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir.cpp
diff options
context:
space:
mode:
authorCopilot <198982749+Copilot@users.noreply.github.com>2025-07-21 09:30:24 -0700
committerGitHub <noreply@github.com>2025-07-21 16:30:24 +0000
commit368ddbb7b99dfb939d20f53c35d05b2b4758bd64 (patch)
tree25f86c54c3949a5fe4dd11c704d67e63a6e7d4e3 /source/slang/slang-ir.cpp
parent7343c7110c38b3ce71d679222dccf438190865b0 (diff)
Add utility to trace creation of problematic IRInsts to assist LLM in debugging (#7820)
* Initial plan * Add SLANG_DEBUG_IR_BREAK environment variable support Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Apply code formatting to SLANG_DEBUG_IR_BREAK implementation Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Improve stack trace debugging with -rdynamic flag and backtrace_symbols Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Address PR feedback: use PlatformUtil::getEnvironmentVariable, remove -rdynamic flag, and delete fallback branch Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Address PR feedback: simplify env var parsing, move backtrace to PlatformUtil, use #if for SLANG_LINUX_FAMILY Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Address PR feedback: remove unneeded include, make backtrace() more generic by removing uid parameter Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Fix and clone source tracking. * Add python script to dump traces. * Update instructions. * Batch calls to addr2line * Cleanup claude instructions. * update claude action. * Remove duplicated build instructions from claude.yml workflow Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * fix build error. * Fix build errors --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> Co-authored-by: Yong He <yonghe@outlook.com> Co-authored-by: Gangzheng Tong <tonggangzheng@gmail.com>
Diffstat (limited to 'source/slang/slang-ir.cpp')
-rw-r--r--source/slang/slang-ir.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index 3c2d5d2d1..63d3766ab 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -2,6 +2,7 @@
#include "slang-ir.h"
#include "../core/slang-basic.h"
+#include "../core/slang-platform.h"
#include "../core/slang-writer.h"
#include "slang-ir-dominators.h"
#include "slang-ir-insts.h"
@@ -1738,8 +1739,21 @@ void IRBuilder::_maybeSetSourceLoc(IRInst* inst)
}
#if SLANG_ENABLE_IR_BREAK_ALLOC
-SLANG_API uint32_t _slangIRAllocBreak = 0xFFFFFFFF;
+uint32_t _slangIRAllocBreak = 0xFFFFFFFF;
+bool _slangIRPrintStackAtBreak = false;
static bool _slangIRAllocBreakFirst = true;
+static uint32_t _slangInstBeingCloned = 0xFFFFFFFF;
+
+void _debugSetInstBeingCloned(uint32_t uid)
+{
+ _slangInstBeingCloned = uid;
+}
+
+void _debugResetInstBeingCloned()
+{
+ _slangInstBeingCloned = 0xFFFFFFFF;
+}
+
uint32_t& _debugGetIRAllocCounter()
{
static uint32_t counter = 0;
@@ -1758,6 +1772,20 @@ uint32_t _debugGetAndIncreaseInstCounter()
#if _WIN32 && defined(_MSC_VER)
__debugbreak();
#endif
+ if (_slangIRPrintStackAtBreak)
+ {
+ fprintf(stdout, "BEGIN IR Trace\nInstruction #%u created at:\n", _slangIRAllocBreak);
+ PlatformUtil::backtrace();
+ if (_slangInstBeingCloned != 0xFFFFFFFF)
+ {
+ fprintf(
+ stdout,
+ "Inst #%u is a clone of Inst #%u.\n",
+ _slangIRAllocBreak,
+ _slangInstBeingCloned);
+ }
+ fprintf(stdout, "END IR Trace\n");
+ }
}
return _debugGetIRAllocCounter()++;
}