Skip to content

[JIT] Read PGO instrumentation settings once per method - #138612

Open
pavelsavara wants to merge 1 commit into
mainfrom
pavelsavara/jit-pgo-instrumentation-refactor
Open

pavelsavara wants to merge 1 commit into
mainfrom
pavelsavara/jit-pgo-instrumentation-refactor

Conversation

@pavelsavara

Copy link
Copy Markdown
Member

Summary

Refactor JIT PGO instrumentation plumbing in preparation for Browser ReadyToRun PGO (#137502). Codegen should not change.

  • Read JitInterlockedProfiling, JitScalableProfiling, JitCounterPadding and the minimal-profiling settings once in fgPrepareToInstrumentMethod and keep them in new opts.compPgo* fields, instead of rereading JitConfig at every probe.
  • CreateCounterIncrement takes the counter base and offset separately, through a new GetProfileAddress helper.
  • ReadHistogramAndAdvance returns schema entries instead of raw addresses.
  • Synthesized-count writes go through fgShouldWriteSynthesizedCounts.
  • Inlinee compilers now copy compCollect64BitCounts from the inline root. On main, compInitOptions returns early for inlinees before the field is set, but inlinee instrumentation reads it to choose the counter width.

The follow-up in the stack adds R2R-specific addressing (counters reached through an import cell) behind these seams, so its JIT diff stays small.

Stack

This PR is the bottom layer of the Browser ReadyToRun PGO stack. #137502 is the integration PR on top.

Validation

Command Result
.\build.cmd -subset clr.alljits -c Debug Passed
.\build.cmd -os browser -subset clr.crossarchtools -c Debug /p:RuntimeFlavor=CoreCLR (Wasm cross JIT) Passed
clang-format 17.0.6 from eng\formatting\download-tools.ps1 on the changed JIT files Clean

I did not run SuperPMI asmdiffs locally. The CI superpmi-diffs legs should show no diffs.

Note

This PR description was drafted with GitHub Copilot.

Compute interlocked, scalable, minimal and counter-slot settings in
fgPrepareToInstrumentMethod and store them in opts, instead of rereading
JitConfig at each probe. Pass counter base and offset separately to
CreateCounterIncrement, return schema entries rather than raw addresses
from ReadHistogramAndAdvance, and route synthesized-count writes through
fgShouldWriteSynthesizedCounts.

Initialize compCollect64BitCounts for inlinee compilers from the inline
root. compInitOptions returns early for inlinees before the field was
set, yet inlinee instrumentation reads it to choose the counter width.

No codegen change is intended.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 1, 2026
@pavelsavara
pavelsavara added this pull request to stack #138617 December 1, 2026 21:38
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@pavelsavara pavelsavara added this to the 12.0.0 milestone Dec 2, 2026
@pavelsavara
pavelsavara requested review from AndyAyersMS and jkotas and removed request for jkotas December 2, 2026 15:41
@jkotas
jkotas requested a balanced review from Copilot December 2, 2026 17:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the PGO instrumentation refactor.

No open issues 🎉

What changed in this PR

Refactors JIT profile-guided optimization (PGO) instrumentation to prepare for Browser ReadyToRun PGO, with no intended code-generation changes.

Changes:

  • Caches profiling settings once per method.
  • Separates counter addressing from updates and centralizes synthesized-count write checks.
  • Makes inlinee compilers inherit the root compiler’s counter-width setting.
File Description
src/​coreclr/​jit/​fgprofile.cpp Caches settings and refactors counter addressing, histogram access, and synthesized-count checks.
src/​coreclr/​jit/​compiler.h Declares cached profiling options and the synthesized-count helper.
src/​coreclr/​jit/​compiler.cpp Initializes counter width earlier and copies it to inlinees.

Review effort: Balanced

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

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants