Skip to content

[Feature] Add an interactive IR lower-trace comparison viewer #2134

Description

@lyfne123

Summary

Add a developer tool that turns PyPTO per-pass IR snapshots into an interactive lowering trace, similar to TileLang IR Lower Trace. The tool should render terminal output and/or a self-contained HTML report with pass navigation, change statistics, and side-by-side before/after IR diffs.

The initial implementation should reuse the snapshots already produced by dump_passes=True under <output_dir>/passes_dump/ rather than introduce a second pass-instrumentation path.

Motivation / Use Case

PyPTO already writes 00_frontend.py followed by <index>_after_<PassName>.py snapshots, and .claude/skills/compare-codegen/scripts/diff_pto.py --include-passes can print unified diffs. However, inspecting a long lowering pipeline remains cumbersome: developers must open many files manually, unchanged passes add noise, and it is difficult to identify the first pass that introduced an unexpected IR change.

The viewer would make it easier to:

  • Find the first pass that changes a suspicious expression, type, layout, memory assignment, or control-flow structure.
  • Understand and review the effect of an individual pass.
  • Navigate pipelines with dozens of passes while filtering changed and no-op stages.
  • Share a portable report as a CI artifact or in an issue without requiring a running server.

Proposed API / Behavior

Start with a post-processing CLI over an existing dump directory:

# Generate a self-contained interactive report
pypto-ir-trace build_output/example/passes_dump \
  --mode html --output ir_trace.html

# Print compact colored diffs in the terminal
pypto-ir-trace build_output/example/passes_dump --mode terminal

A small Python API may expose the same functionality:

from pypto.tools import ir_trace

ir_trace.render(
    "build_output/example/passes_dump",
    mode="html",
    output="ir_trace.html",
)

Expected behavior for the MVP:

  1. Discover and order the existing pass snapshots by their numeric prefix.
  2. Treat 00_frontend.py as the input of the first pass and the previous pass snapshot as the input of each subsequent pass.
  3. Record the pass name, whether it changed the IR, and insertion/deletion counts.
  4. Generate a self-contained HTML file with:
    • a pass sidebar and changed/no-op status indicators;
    • changed/no-op filters and summary counts;
    • side-by-side before/after diffs with syntax-aware line highlighting;
    • collapsed unchanged context with an expand control;
    • copy-before and copy-after actions;
    • keyboard navigation and light/dark themes.
  5. Support a terminal mode for quick inspection.
  6. Surface matching per-pass warning .log files when present.
  7. Handle missing, malformed, or non-contiguous snapshots with clear diagnostics.
  8. Add focused tests for snapshot discovery/order, change classification, diff statistics, malformed input, and deterministic/self-contained HTML generation.

A follow-up can integrate report generation with the existing compare-codegen workflow so main/current-branch pass dumps can be explored using the same UI.

Alternatives Considered

  • Continue using raw passes_dump/ files and unified terminal diffs. This works for small cases but becomes difficult to navigate and share for long pipelines.
  • Build a hosted web application. A self-contained static HTML report is preferable initially because it has no service dependency, opens locally, and can be archived by CI.

Additional Context

Design reference: TileLang IR Lower Trace. Its useful interaction model includes phase/pass navigation, changed/no-op classification, before/after comparison, context expansion, copy controls, keyboard navigation, and a self-contained HTML report.

The reference compares textual IR, so the viewer should clearly describe diffs as textual evidence rather than semantic equivalence.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status
In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions