Skip to content

[llvm-advisor] Add optimization remarks visualization: relational grid, heatmap, Code Explorer and snapshot diff - #218692

Open
kamini08 wants to merge 41 commits into
llvm:users/tobias-stadler/kamini08-minimal-advisor-basefrom
kamini08:minimal-advisor-remarks
Open

[llvm-advisor] Add optimization remarks visualization: relational grid, heatmap, Code Explorer and snapshot diff#218692
kamini08 wants to merge 41 commits into
llvm:users/tobias-stadler/kamini08-minimal-advisor-basefrom
kamini08:minimal-advisor-remarks

Conversation

@kamini08

Copy link
Copy Markdown

Add optimization remarks visualization: relational grid, heatmap, Code Explorer and snapshot diff

This PR is part of my GSoC 2026 project on llvm-advisor. It adds end-to-end support for visualizing and comparing Clang optimization remarks: importing -fsave-optimization-record files, analyzing them with new C++ analyzers, and exposing the results through CLI commands and a web UI with a heatmap, Code Explorer, triage grid, and snapshot diff.

What this adds

  • Import for -fsave-optimization-record YAML files. llvm-advisor import foo.opt.yaml parses a Clang optimization-record file, creates a snapshot and unit, runs the remarks analyzers, and stores the results in the CAS-backed store. The importer also reports clear errors for missing, empty, or malformed YAML, and preserves PGO Hotness values when present.

  • Four new C++ analyzers registered in the capability catalog:

    • llvm.remarks.summary - produces overview counts by pass, remark name, and remark type. These numbers back the dashboard cards and the overview page.
    • llvm.remarks.relational - builds a columnar table of every remark. Instead of returning a large array of objects, it returns integer-indexed columns plus deduplicated string tables for function, file, pass, and name, which keeps JSON payloads small and makes browser-side filtering fast even for millions of rows.
    • llvm.remarks.hotspot - aggregates remarks by function, file, and line, tracking total counts and max hotness. This powers the heatmap and the project stats sidebar.
    • llvm.remarks.detail - per-remark detail output used by the detail panel and Code Explorer badges.
  • Heatmap view (g h). A sortable table of hotspots that shows visual hotness bars, status chips (Critical / Moderate / Low), and a project stats sidebar, so you can see at a glance which functions and lines have the most actionable remarks.

  • Code Explorer (g e). Displays source files with remark counts overlaid on each line. It supports pass and function filters and is linked from the heatmap rows and the triage grid, so you can jump straight from a high-level hotspot to the exact source line that produced it.

  • Snapshot comparison. The CLI command llvm-advisor compare --before <snap> --after <snap> and the Compare UI tab (g c) show matched, changed, added, and removed units between two builds, plus an Optimization Impact table that breaks down per-function deltas in missed and passed remarks.

  • HTTP endpoints. The server exposes REST endpoints for relational remarks, hotspots, per-source-file remarks, and snapshot diffs. The front-end is a single-page app that consumes these endpoints and renders the overview, heatmap, triage grid, Code Explorer, and Compare views.

Testing

There are 9 lit tests under llvm/test/tools/llvm-advisor/ covering import, invalid input, relational/hotspot queries, snapshot compare, and the HTTP endpoints.

Documentation

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
… renderer

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
All six remark types (unknown, passed, missed, analysis, analysis-fp-commute,
analysis-aliasing, failure) are now uniformly named across the ingestion
pipeline:

- add remarkTypeKey() and allRemarkTypeKeys() in RemarksAnalysisUtils as
  the single source of truth for type -> JSON key mapping; replaces the
  direct use of LLVM's typeToStr() which returns CamelCase strings
  inconsistent with the rest of the JSON API
- RemarksAnalyzer (llvm.remarks.summary): pre-initialize all six keys at
  0 before iterating so the by_type object always has the same shape
  regardless of which types appear in the file
- RemarksDetailAnalyzer (llvm.remarks.detail): use canonical names
- PassImpact insight: update hit-rate lookup keys to lowercase
- OptimizationDelta insight: fix stale comment
- Remarks Explorer (views.js): decode relational type integers using the
  canonical name array; show all six types as table columns, hiding any
  column that is all-zero across the top 20 rows
- unit-detail.js: remove hardcoded type list from empty-state message

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…ache

llvm.remarks.summary and llvm.remarks.detail changed their output format
in the previous commit (lowercase type keys, all six pre-initialized).
Bump both to version 2 so the run-key hash changes and old cached results
with capitalized keys are not returned.

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…a header

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Use sys::fs::real_path in findBuildDir so that symlinked or relative
paths to compile_commands.json resolve to their actual directory.

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Add RemarksHotspotAnalyzer that aggregates optimization remarks by
function, file, and line to identify hotspots. Register the
builtin.remarks_hotspot runner and add the llvm.remarks.hotspot
capability to the catalog with dependency on llvm.remarks.summary.

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Add HeatmapView to render hotspot tables from llvm.remarks.hotspot.
Add heatmap icon to core.js and sidebar navigation to shell.js with
keyboard shortcut g h. Register the /heatmap route in bundle.py and
index.html.

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
When llvm.remarks.relational is available, render the full triage grid
in the unit detail Remarks tab instead of the limited findingList.
Add llvm.remarks.relational to the default capabilities queried for
units so the relational data is fetched.

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Use llvm::demangle() in RemarksRelationalAnalyzer and
RemarksHotspotAnalyzer so that mangled C++ function names are
presented as human-readable signatures in the UI.

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…ional endpoint

The relational endpoint now accepts query parameters:
- pass, name, function, file: substring filters on string columns
- type: exact match on remark type enum
- min_hotness: minimum hotness threshold
- offset, limit: pagination (default limit 10000, max 100000)

Server scans all units, builds merged columns, applies filters,
then writes only the requested slice. Response includes total
(filtered count) for pagination.

Frontend triage grid is rewritten as server-paginated: fetches
one page at a time, filter inputs debounce 300ms then re-fetch
from server, page controls step through results.

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…ering

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…-level comparison

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…nt empty snapshot

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…n + fix emitOptRemarks yaml

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…ashboard + red highlight for added remarks

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
… at source location

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…s to Code Explorer

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…rer filter wiring

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…s, and project stats sidebar

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…aders

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…le missing source gracefully in Code Explorer

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
…ap rows

Signed-off-by: kamini08 <kaminibanait03@gmail.com>
Signed-off-by: kamini08 <kaminibanait03@gmail.com>
@github-actions

Copy link
Copy Markdown

Hello @kamini08 👋

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

  • All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
  • The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.
  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.


Frequently asked questions

How do I add reviewers?

This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

What if there are no comments?

If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

Are any special GitHub settings required to contribute to LLVM?

We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.


If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

Thank you,
The LLVM Community

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