Skip to content

Add debug symbols that point into the stmt outputs (simplified alternative to #9611) - #9712

Draft
mcourteaux wants to merge 3 commits into
mcourteaux/stmt-html-from-irprinter-altfrom
mcourteaux/llvm-debug-symbols-alt
Draft

mcourteaux wants to merge 3 commits into
mcourteaux/stmt-html-from-irprinter-altfrom
mcourteaux/llvm-debug-symbols-alt

Conversation

@mcourteaux

@mcourteaux mcourteaux commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #9711, which is stacked on #9710. Draft: this is a simplified alternative to #9611, for comparing the two side by side.

What this does

  • The debug_symbols and debug_symbols_conceptual target features emit debug info (DWARF, or CodeView on Windows) that maps the generated code to the lines of the stmt or conceptual_stmt output, for ahead-of-time and JIT compiled code.
  • IRPrinter can record where it prints each IR node (print_with_source_map), which is what the debug info points into.
  • The html outputs link the IR to its assembly through this debug info, instead of through the names of basic blocks: by line, and within a line by the IR node each instruction was generated for.

In the page

  • Hovering IR or assembly shows what it is linked to. Double-clicking keeps that shown and goes there; double-clicking it again, or Escape, lets go of it. A click on a variable still highlights that variable everywhere.
  • Anywhere on a line links the line. On an operator, a keyword or a name, the node is linked too: that expression with all that is nested in it.
  • The line is marked faintly and the node strongly, in yellow while hovered and orange once selected. The selected expression has a line around it and under its operator, and the assembly of that operator itself has a bar in front of it.
  • With rainbow parentheses on, the selected assembly is colored by the node each instruction was generated for, in the colors of the punctuation of those nodes.
  • The toolbar says what is linked, and has an option to scroll smoothly when going there.
  • The backgrounds that mark lines are chosen per color scheme, by calculation: far enough from the background of the pane to be seen, in the color on which the text colors of the scheme keep the most contrast. Parallel and GPU loops are shown by a line along them, with a faint shade.

See doc/DebugSymbols.md.

What is different from #9611

  • No for_html_outputs. Lowering always copies the IR nodes that the stmt uses in more than one place, so that each is printed in one place only. The parameter is gone from Pipeline::compile_to_module, AbstractGenerator::build_module, lower() and the Python binding.
  • One debug source. Code generation takes a single printing to point into: of the Module, or of its conceptual Stmt. With the conceptual Stmt, a function starts where the first of its code that is in it does, so the Module is no longer printed just to find that.
  • Recording in IRPrinter. One IRPrinterRecord holds the locations of the nodes and where the functions start. The location of a node holds that of the node it is printed within, instead of a stack of them, and nothing is recorded when no record is set.
  • The anchor of the binary operators is set in their shared helper.
  • StmtSourceMap loses the fields nothing reads.
  • The debug location of a node is set by a scope guard in codegen().

Performance

Lowering time of the generators in apps/, with tools/benchmark_apps_generators.py (-e stmt, wall clock, mean of 3 runs, host target), main against this PR. Two of the 72 generators fail to build or run on both, and are left out.

  • In total: 7069 ms on main, 7107 ms with this PR (+38 ms, 1.005x). No generator and no lowering pass moves beyond the noise.
  • The pass that copies the shared nodes, which now always runs, takes 0.36% of the lowering time, summed over all generators.

lowering time on the host target, main against this PR

Screenshots

Taken with headless Chrome, of a small tiled and vectorized pipeline.

An operator double-clicked: the <= of a bounds check. The expression under it has a line around it, the assembly of all of it is marked strongly, and that of the rest of the line faintly. The bar is in front of the instructions of the <= itself:

stmt html with the assembly of an operator and what is nested in it selected

The same with rainbow parentheses on: each instruction has the color of the operator it was generated for, which the IR shows in that color.

the same with rainbow parentheses

In the classic dark color scheme:

the same in the classic dark color scheme

The conceptual stmt, with a store selected in a parallel loop and the line before it hovered:

conceptual stmt html with a line selected and one hovered in a parallel loop

Tests

correctness_debug_symbols checks that the html links assembly to lines of IR that exist, and to more IR nodes than lines. It and correctness_stmt_to_html pass. The other correctness tests passed before the page got its node-level links and its new interaction; I have not rerun them since, as lowering and code generation did not change.

🤖 Generated with Claude Code

https://claude.ai/code/session_011FRemhS639vq75urwV44oe

CodeGen_C printed a Let or LetStmt by substituting a variable named after
the id of the value into the body, which rebuilds the body once for every
let around it. It now remembers the id in a scope, where the Variable
looks it up, so the IR that is printed is the IR that was passed in.

A let of a handle and a For loop bind their own name, which hides a let of
the same name around them, as the substitution did.

The output is the same, except where an expression is simplified while it
is printed (e.g. the lowering of lerp): the simplifier orders the operands
of commutative operators by the names of variables, which are no longer
the ids.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011FRemhS639vq75urwV44oe
@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.10720% with 71 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.62%. Comparing base (e6e8fe2) to head (be10264).

Files with missing lines Patch % Lines
src/CodeGen_LLVM.cpp 87.14% 13 Missing and 19 partials ⚠️
src/JITModule.cpp 63.63% 9 Missing and 7 partials ⚠️
src/Module.cpp 85.00% 3 Missing and 6 partials ⚠️
src/IRPrinter.cpp 94.30% 1 Missing and 6 partials ⚠️
src/StmtToHTML.cpp 92.55% 0 Missing and 7 partials ⚠️
Additional details and impacted files
@@                             Coverage Diff                             @@
##           mcourteaux/stmt-html-from-irprinter-alt    #9712      +/-   ##
===========================================================================
+ Coverage                                    73.50%   73.62%   +0.11%     
===========================================================================
  Files                                          266      266              
  Lines                                        82513    83009     +496     
  Branches                                     20460    20589     +129     
===========================================================================
+ Hits                                         60652    61113     +461     
- Misses                                       15391    15399       +8     
- Partials                                      6470     6497      +27     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcourteaux
mcourteaux force-pushed the mcourteaux/llvm-debug-symbols-alt branch from b7c8f13 to c745296 Compare November 22, 2026 18:52
mcourteaux and others added 2 commits November 22, 2026 20:29
The html output is written by HTMLStmtPrinter, a subclass of IRPrinter,
through new hooks: begin_style()/end_style() for styled text, and
begin_node()/end_node() around each Expr and Stmt. It shows the IR exactly
as the stmt output prints it, which replaces the separate html printer.

IRPrinter is simplified along the way: the colors of the styles come from
a table, Modules and LoweredFuncs are printed by member functions that
operator<< uses, the binary operators share a helper, and chained ifs are
printed recursively. Colored output ends some styles by resetting only
the color where it reset all attributes; plain output is unchanged.

The variables of the loops over GPU threads (.thread_id_x, .thread_id_y
and .thread_id_z) are red, green and blue, in colored output and in the
html.

The assembly is linked to the loops and produce/consume blocks by the
names of their basic blocks. It is written as plain text into a
<script type='text/plain'>, which the page splits into lines and renders
as they come into view.

The cost model is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011FRemhS639vq75urwV44oe
The debug_symbols and debug_symbols_conceptual target features emit debug
info (DWARF, or CodeView on Windows) that maps the generated code to the
lines of the stmt or conceptual_stmt output, for ahead-of-time and JIT
compiled code. IRPrinter can record where it prints each IR node
(print_with_source_map), which is what the debug info points into.

Lowering always copies the IR nodes that the stmt uses in more than one
place, so that each is printed in one place only.

The html outputs link the IR to its assembly through this debug info,
instead of through the names of basic blocks: by line, and within a line
by the IR node each instruction was generated for.

- Hovering IR or assembly shows what it is linked to. Double-clicking
  keeps that shown and goes there; double-clicking it again, or Escape,
  lets go of it. A click on a variable still highlights it everywhere.
- Anywhere on a line links the line. On an operator, a keyword or a name,
  the node is linked too: that expression with all that is nested in it.
- The line is marked faintly and the node strongly, in yellow while
  hovered and orange once selected. With rainbow parentheses on, the
  selected assembly is colored by the node each instruction was generated
  for. The assembly of the selected node itself has a bar in front of it.
- The backgrounds that mark lines are chosen per color scheme, by
  calculation: far enough from the background of the pane to be seen, in
  the color on which the text colors keep the most contrast. Parallel and
  GPU loops are shown by a line along them, with a faint shade.
- The toolbar says what is linked, and has an option to scroll smoothly
  when going there, which is on by default.

See doc/DebugSymbols.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011FRemhS639vq75urwV44oe
@mcourteaux
mcourteaux force-pushed the mcourteaux/llvm-debug-symbols-alt branch from c745296 to be10264 Compare November 22, 2026 19:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant