Skip to content

Print the stmt html with IRPrinter (simplified alternative to #9690) - #9711

Open
mcourteaux wants to merge 1 commit into
mainfrom
mcourteaux/stmt-html-from-irprinter-alt
Open

mcourteaux wants to merge 1 commit into
mainfrom
mcourteaux/stmt-html-from-irprinter-alt

Conversation

@mcourteaux

@mcourteaux mcourteaux commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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

What this does

The html output is written by HTMLStmtPrinter, a subclass of IRPrinter, instead of by a separate printer of its own. It shows the IR exactly as the stmt output prints it. IRPrinter gets the hooks for that: begin_style()/end_style() around styled text, and begin_node()/end_node() around each Expr and Stmt.

The assembly is linked to the loops and produce/consume blocks by the names of their basic blocks, as before.

What is different from #9690

  • The cost model is removed, with its gutter boxes, toggle, styles and palette generator.
  • The assembly is written as plain text into a <script type='text/plain'>, which the page splits into lines, instead of as an array of JavaScript string literals. Long lines are still truncated while writing. Only the IR line of each assembly line is kept in memory.
  • IRPrinter is simplified:
    • The colors of the styles come from a table, instead of from a member per color.
    • StyledText only carries the style. The nesting depth of punctuation is the printer's, and how a style ends follows from the style.
    • A type in parentheses is printed by a function, not by a style that emits text.
    • Modules and LoweredFuncs are printed by member functions, which operator<< uses.
    • The binary operators share one helper, and chained ifs are printed recursively.
  • The variables of the loops over GPU threads (.thread_id_x, .thread_id_y and .thread_id_z) are red, green and blue, in the colored output of IRPrinter and in the html.
  • In StmtToHTML, the classes of the styles come from a table, the device code pane is written in place, and the lines are not copied to print them.

Screenshots

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

The line of a loop clicked, with the assembly of its basic block highlighted:

stmt html with the assembly of a loop highlighted

An OpenCL pipeline, with its device code pane. The variables of the loops over GPU threads have their own colors:

conceptual stmt html of an OpenCL pipeline, with .thread_id_x in red and .thread_id_y in green

Output

The plain output of IRPrinter is unchanged. I compared the IR that two tests print with HL_DEBUG_CODEGEN=2 against the code before the simplification: it differs only in pointer addresses and paths.

The colored output ends some styles (immediates, and types in parentheses) by resetting only the color (\033[39m) where it reset all attributes (\033[0m), which looks the same in a terminal.

Tests

correctness_stmt_to_html checks that the html shows the IR exactly as the stmt output prints it, that loops are linked to their assembly, and that the assembly text has one link per line.

🤖 Generated with Claude Code

https://claude.ai/code/session_011FRemhS639vq75urwV44oe

@alexreinking

Copy link
Copy Markdown
Member

Why remove the cost model?

@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.13158% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.47%. Comparing base (d7e0db3) to head (0a5e349).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/IRPrinter.cpp 89.65% 11 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9711      +/-   ##
==========================================
+ Coverage   73.25%   73.47%   +0.21%     
==========================================
  Files         266      266              
  Lines       83749    82593    -1156     
  Branches    20572    20482      -90     
==========================================
- Hits        61352    60685     -667     
+ Misses      15845    15395     -450     
+ Partials     6552     6513      -39     

☔ 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

Copy link
Copy Markdown
Contributor Author

Why remove the cost model?

Because I think nobody is using it. It's a poor visualization of how many bytes are moved (expressed as bits). Correct me if I'm wrong.

@abadams

abadams commented Nov 23, 2026

Copy link
Copy Markdown
Member

Code changes look reasonable but it took me a long time to figure out how to jump from the stmt to the assembly. The dotted underline on the line number is too subtle. Can the clickable lines be made clearer in some way? Personally I liked the arrows at the right end of the line, but if that's hard it could just be a different styling on the clickable line numbers.

Base automatically changed from mcourteaux/c-codegen-let-scope to main November 23, 2026 17:50
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
@abadams
abadams force-pushed the mcourteaux/stmt-html-from-irprinter-alt branch from e6e8fe2 to 0a5e349 Compare November 23, 2026 17:50
@mcourteaux

mcourteaux commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Code changes look reasonable but it took me a long time to figure out how to jump from the stmt to the assembly. The dotted underline on the line number is too subtle. Can the clickable lines be made clearer in some way? Personally I liked the arrows at the right end of the line, but if that's hard it could just be a different styling on the clickable line numbers.

I agree, but didn't bother because the follow-up PRs make every Expr clickable. I may perhaps bring back the jump-to-buttons on important things, like loops and ifs, if desirable. So I recommend you try the next PR too, and let me know what would be preferred.

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.

3 participants