The LLVM Project Blog

LLVM Project News and Details from the Trenches

GSoC 2026: llvm-advisor - Optimization Remarks & Visualizations

This summer I worked on llvm-advisor, LLVM’s web-based compiler advisor, as part of Google Summer of Code 2026. llvm-advisor was started during last year’s GSoC by Miguel Cárdenas, and this year I extended it with optimization-remarks storage, search, heatmap, Code Explorer, PGO hotness, and snapshot diff. The goal was to make optimization remarks (the diagnostics emitted by clang -fsave-optimization-record) searchable, comparable, and visual.

Optimization remarks are the compiler’s way of explaining its decisions back to you. Every time Clang decides to vectorize a loop, inline a call, or give up on an optimization, it can emit a structured diagnostic tied to a source location. Without these remarks, the only way to reconstruct what happened is to read assembly or rely on intuition. With remarks however, you can ask targeted questions: “Why wasn’t this loop vectorized?”, “Did my change help?”, “Which missed remark is actually worth fixing?” Real projects can produce millions of these remarks, so you need a tool that can filter, aggregate, and visualize them. That’s what llvm-advisor does.

This matters whether you’re a compiler developer tuning inlining or vectorization heuristics, a user upgrading your toolchain and watching for regressions, or someone making performance-critical source changes. The example here is small for a walkthrough, but the workflow remains the same and similar bottlenecks show up in production code, and a large build can easily emit more remarks than a person can go through by hand. This is where the viewer helps: instead of drowning in raw remark data, you can narrow things down to the handful of diagnostics that actually point at a problem.

Let’s walk through an example to see how it works. I took a small C program that was missing a vectorization opportunity, used llvm-advisor to find the exact remark, changed one function from noinline to static inline, and measured the result.


The workflow: turning a missed vectorization into a faster loop

The baseline code

Here is baseline.c. The helper work is marked __attribute__((noinline)), so the loop in process has to call it on every iteration.

#include <stdlib.h>

__attribute__((noinline))
int work(int x) {
  return x * 3 + (x >> 2);
}

void process(int *a, int n) {
  for (int i = 0; i < n; ++i)
    a[i] = work(a[i]);
}

int main(int argc, char **argv) {
  int n = argc > 1 ? atoi(argv[1]) : 10000000;
  int *a = (int *)malloc(n * sizeof(int));
  for (int i = 0; i < n; ++i)
    a[i] = i & 0xff;
  for (int run = 0; run < 10; ++run)
    process(a, n);
  int sum = 0;
  for (int i = 0; i < n; ++i)
    sum += a[i];
  free(a);
  return sum & 1;
}

Compile it with remarks enabled:

clang -c baseline.c -O3 -g -fsave-optimization-record

This produces baseline.opt.yaml next to the object file.

Import the remark file into llvm-advisor

rm -rf /tmp/adv-baseline
llvm-advisor import baseline.opt.yaml \
  --source-root . \
  --store /tmp/adv-baseline

Then start the server:

llvm-advisor serve \
  --store /tmp/adv-baseline \
  --port 8080

Open http://127.0.0.1:8080 and press g r for the remarks view. The summary card shows 137 remarks, and the top pass/name table immediately surfaces the problem:

PassRemarkTotalMissedPassedAnalysis
loop-vectorizeCantVectorizeLibcall111100
loop-vectorizeMissedDetails111100

The heatmap shows the same thing grouped by function and line:

llvm-advisor heatmap for baseline.c showing process at baseline.c:10 with missed vectorization remarks

And the full remarks grid shows the row for process:

llvm-advisor remarks view showing CantVectorizeLibcall and MissedDetails for the process loop

Code Explorer: reading the source with the remark overlay

Press g e (or click Code Explorer in the sidebar), select baseline.c, and filter the pass dropdown to loop-vectorize. The loop header on line 9 and the assignment on line 10 are both highlighted with 11 missed remarks, exactly matching baseline.opt.yaml:

llvm-advisor Code Explorer for baseline.c with the loop-vectorize pass filter active

This is the same data as the remarks grid, but now it sits directly on the source line that produced it.

The raw remark

If you open baseline.opt.yaml, the relevant entry is:

---
!Missed
Pass: loop-vectorize
Name: CantVectorizeLibcall
DebugLoc: { File: "baseline.c", Line: 10, Column: 12 }
Function: process
Args:
  - String: "loop not vectorized: "
  - String: "call instruction cannot be vectorized"

Line 10 is the a[i] = work(a[i]) assignment. The loop cannot be vectorized because it contains a function call that the compiler is not allowed to inline.

The fix

Remove the noinline attribute and make work static inline so the compiler can fold the call into the loop body and then vectorize it:

#include <stdlib.h>

static inline int work(int x) {
  return x * 3 + (x >> 2);
}

void process(int *a, int n) {
  for (int i = 0; i < n; ++i)
    a[i] = work(a[i]);
}

/* main unchanged */

Recompile, re-import into a new snapshot, and look at the remarks again. The top pass/name table now shows:

PassRemarkTotalMissedPassedAnalysis
loop-vectorizeVectorized130130

llvm-advisor remarks view after the fix, showing loop-vectorize Vectorized for the process loop

The raw remark in optimized.opt.yaml confirms the loop was vectorized:

---
!Passed
Pass: loop-vectorize
Name: Vectorized
DebugLoc: { File: "optimized.c", Line: 8, Column: 3 }
Function: process
Args:
  - String: "vectorized "
  - String: ""
  - String: "loop (vectorization width: "
  - VectorizationFactor: "4"
  - String: ", interleaved count: "
  - InterleaveCount: "2"
  - String: ")"

Snapshot diff: before and after

Import both remark files into the same store and use the Compare view (g c):

rm -rf /tmp/adv-compare
mkdir baseline optimized
cp baseline.opt.yaml baseline/vectorize.opt.yaml
cp optimized.opt.yaml optimized/vectorize.opt.yaml

llvm-advisor import baseline/vectorize.opt.yaml \
  --source-root baseline \
  --store /tmp/adv-compare

llvm-advisor import optimized/vectorize.opt.yaml \
  --source-root optimized \
  --store /tmp/adv-compare

llvm-advisor serve \
  --store /tmp/adv-compare \
  --port 8080

Select the baseline snapshot as BASE and the optimized snapshot as CANDIDATE. The diff shows one changed unit and an Optimization Impact table that breaks down the per-function change. In this run main has new missed and passed remarks from the unrolled loop, while work is resolved because the call can now be inlined:

llvm-advisor Compare view showing the baseline vs optimized snapshot diff

The diff answers the question “What changed in the remarks between the two builds?” without re-parsing files or writing a custom script.

This diff workflow pinpoints exactly which remarks changed. On large projects, remarks can be overwhelming, but filtering, aggregation, and PGO hotness help you prioritize which ones to investigate.


PGO hotness: which remark matters most?

The vectorization example is tiny. In a real program, dozens of files can emit missed-remark warnings. PGO adds a profile-derived Hotness value to remarks, which gives you workload context and tells you which ones are worth fixing first.

Small walkthrough: hot and cold loops

To make the contrast easy to see, this small program calls hot_work one million times and cold_work one hundred times:

#include <stdio.h>
#include <stdlib.h>

int hot_work(int *a, int n) {
  int s = 0;
  for (int i = 0; i < n; ++i)
    s += a[i] * 2;
  return s;
}

int cold_work(int *a, int n) {
  int s = 0;
  for (int i = 0; i < n; ++i)
    s += a[i] * 3;
  return s;
}

int main(int argc, char **argv) {
  int n = argc > 1 ? atoi(argv[1]) : 100;
  int *a = (int *)malloc(n * sizeof(int));
  for (int i = 0; i < n; ++i)
    a[i] = i & 0xff;

  int total = 0;
  for (int run = 0; run < 1000000; ++run)
    total += hot_work(a, n);
  for (int run = 0; run < 100; ++run)
    total += cold_work(a, n);

  printf("%d\n", total);
  free(a);
  return 0;
}

Generate a profile, then compile with profile use and remarks enabled:

clang -fprofile-generate -O3 -g -fsave-optimization-record pgo_example.c -o pgo_train
./pgo_train
llvm-profdata merge default.profraw -o pgo_example.profdata
clang -fprofile-use=pgo_example.profdata -O3 -g -fsave-optimization-record \
  -c pgo_example.c -o pgo_example.o

Import pgo_example.opt.yaml and open the heatmap (g h). Clang inlines both helpers into main, so the hot loop at lines 6 and 7 appears under main and reaches 100% of the heatmap’s normalized scale. The cold_work loop is marked Low.

llvm-advisor heatmap for pgo_example.c showing the hot loop at 100% normalized hotness and the cold loop at low hotness

In Code Explorer, filter by loop-vectorize to inspect the remarks on both loops:

llvm-advisor Code Explorer for pgo_example.c with the loop-vectorize pass filter active

With hotness, you can sort by actual runtime cost instead of by file name.


How the tool makes this possible

Capabilities are analyzer endpoints that each expose a different view of the compiled program - relational tables, heatmap aggregations, snapshot diffs, IR views, debug info, and more. Three new C++ capability analyzers turn raw remark data into the views above:

CapabilityOutput
llvm.remarks.relationalA columnar table of every remark, with deduplicated string tables for function, file, pass, and name.
llvm.remarks.hotspotPer-function, per-file, per-line aggregations used by the heatmap.
llvm.remarks.diffA delta of added, removed, and changed remarks between two snapshots.

The relational endpoint uses integer-indexed columns instead of an array of objects. That keeps JSON payloads small and makes browser-side filtering fast for millions of rows.

High-level data flow from remark files through analyzers to the web UI


A few performance numbers

On real compiler output the analyzer sustains tens of thousands of remarks per second:

SourceRemarksParse timeThroughput
zstd_lazy.c41,5373.7 s11,265 r/s
sqlite3 amalgam429,07527 s15,655 r/s

Scale test: 572 translation units produced 10.7 million remarks in a single snapshot; the first relational query OOM-killed the server. Three fixes (splitting HTTP sends, per-unit fetching, streaming merger) reduced peak RSS from 10.7 GB to 5.3 GB.

Peak RSS across the three memory fixes

Those numbers are for YAML remark files. For large projects, Clang’s bitstream remark format (-pass-remarks-format=bitstream) is worth using instead:

FormatSourceRemarksSizeParse time
YAMLllvm/lib/Support/APFloat.cpp18,003~20 MB~22 s
Bitstreamllvm/lib/Support/APFloat.cpp18,003~2 MB<1 s

Bitstream avoids text parsing entirely, it’s already in a binary form the advisor can read directly. The gap compounds across a whole build. Building llvm-project with -fsave-optimization-record=bitstream across its ~800 translation units produces tens of millions of remarks. As YAML that would be hundreds of gigabytes of text to re-parse on every import; as bitstream it stays in the low single-digit gigabytes and can be memory-mapped, so the advisor can query it without a multi-minute parse step.


Thank you to my mentors Tobias Stadler and Henrik Olsson for guiding me through the summer, and to the LLVM community for the opportunity to contribute.

Special thanks to last year’s GSoC team: Miguel Cárdenas, with mentors Johannes Doerfert and Kevin Sala, for starting llvm-advisor (his post) and for the initial foundation this work builds on.