Skip to content

[browser][CoreCLR] Guard Wasm ReadyToRun interface and delegate calls from profile data - #138615

Open
pavelsavara wants to merge 1 commit into
pavelsavara/dotnet-pgo-merge-allocationsfrom
pavelsavara/browser-r2r-gdv-from-profile
Open

pavelsavara wants to merge 1 commit into
pavelsavara/dotnet-pgo-merge-allocationsfrom
pavelsavara/browser-r2r-gdv-from-profile

Conversation

@pavelsavara

Copy link
Copy Markdown
Member

Summary

Let Wasm ReadyToRun code use class and delegate profiles from a .mibc for guarded devirtualization. This works with any profile, without the new instrumentation in #137502.

  • Interface calls. Wasm ReadyToRun imports non-generic interface calls through ldvirtftn. The new GTF_CALL_M_R2R_INTERFACE_LDVIRTFTN flag makes them eligible for pickGDV and considerGuardedDevirtualization. SplitCall gains a fallbackUse parameter, so the ldvirtftn lookup, which can throw, runs only on the fallback path.
  • Delegate calls. On Wasm, a delegate holds the target's portable entry point. crossgen2 now implements getFunctionFixedEntryPoint for Wasm, and impTransformDevirtualizedCall uses it for delegate guards. The target is restricted to methods CanReferenceDelegateProfileTarget can name.
  • Profile filtering. On Wasm, profile types and delegate targets are filtered to entities the compilation can reference, so a speculative guard cannot make an otherwise compilable method fall back.

Exact-type devirtualization of these interface calls is unchanged in the default configuration: the control expression is CORINFO_HELP_VIRTUAL_FUNC_PTR, so IsGenericVirtual already made them candidates. The call keeps GTF_CALL_NULLCHECK, so a devirtualized call still throws on a null this.

Stack

Layer 4 of the Browser ReadyToRun PGO stack; #137502 is the integration PR on top.

Validation

The new tests use hand-written MIBC profiles and do not need the producer side:

  • ReadyToRunGuardsVirtualAndInterfaceReceiversFromProfile
  • ReadyToRunGuardsDelegateTargetsFromProfile
  • CastProfileDoesNotRequireUnreferencedTypes
Command Result
.\build.cmd -subset clr.alljits -c Debug Passed
.\build.cmd -os browser -subset clr.crossarchtools -c Debug /p:RuntimeFlavor=CoreCLR Passed
.\dotnet.cmd build src\coreclr\tools\aot\ILCompiler.ReadyToRun.Tests\ILCompiler.ReadyToRun.Tests.csproj -c Debug /p:TargetOS=browser /p:TargetArchitecture=wasm /p:RuntimeFlavor=CoreCLR '/t:Build;Test' 448 total: 406 passed, 0 failed, 42 skipped

Note

This PR description was drafted with GitHub Copilot.

Wasm ReadyToRun imports non-generic interface calls through ldvirtftn.
Mark them with GTF_CALL_M_R2R_INTERFACE_LDVIRTFTN so class profiles in
a .mibc can drive guarded devirtualization, and keep the ldvirtftn
lookup on the fallback path only. For delegate calls, crossgen2 now
implements getFunctionFixedEntryPoint on Wasm, where a delegate holds
the target's portable entry point, so method profiles can guard and
inline delegate targets.

Filter profile types and delegate targets to those the compilation can
reference, so a speculative guard cannot make an otherwise compilable
Wasm method fall back.

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

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@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.

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

arch-wasm WebAssembly architecture 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.

1 participant