Skip to content

JIT: make funclet order correspond to EH clause order#127590

Merged
AndyAyersMS merged 6 commits intodotnet:mainfrom
AndyAyersMS:FuncletOrderMatchesReportedEHClauseOrder
May 2, 2026
Merged

JIT: make funclet order correspond to EH clause order#127590
AndyAyersMS merged 6 commits intodotnet:mainfrom
AndyAyersMS:FuncletOrderMatchesReportedEHClauseOrder

Conversation

@AndyAyersMS
Copy link
Copy Markdown
Member

For Wasm the JIT host will need to match up funclets with EH clauses without relying on the offset data in the EH clause.

To allow this, set things up so that the host can infer which funclets are associated with an EH clause by making the ordering of EH clauses and the order of funclets (reported via unwind info) correspond.

Note this is not 1-1 as EH clauses with filters will inspire two funclets. In those cases the JIT will always put the filter funclet before the catch funclet.

For Wasm the JIT host will need to match up funclets with EH clauses without
relying on the offset data in the EH clause.

To allow this, set things up so that the host can infer which funclets are
associated with an EH clause by making the ordering of EH clauses and the
order of funclets (reported via unwind info) correspond.

Note this is not 1-1 as EH clauses with filters will inspire two funclets.
In those cases the JIT will always put the filter funclet before the catch funclet.
Copilot AI review requested due to automatic review settings April 30, 2026 00:33
@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 Apr 30, 2026
@AndyAyersMS
Copy link
Copy Markdown
Member Author

@dotnet/jit-contrib PTAL

A handful of (zero size) diffs for methods where there are mutual protect trys where some catch clauses have EH in them -- those are the cases where the JIT's EH table and the EH info reported to the VM end up differently ordered.

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to make EH funclet ordering match the order that EH clauses are reported to the VM (specifically, the “VM EH clause order” derived from try-region ordering), so Wasm can associate funclets with EH clauses without depending on EH offset data. The implementation introduces a shared “EH clause order” mapping computed during funclet creation and reuses it during EH reporting and Wasm virtual-IP clause construction.

Changes:

  • Compute and store a VM-EH-clause-order mapping in fgCreateFunclets and publish it via a new Compiler::compEHorderTab.
  • Update EH clause reporting (genReportEH / genReportEHClauses) to use the precomputed clause order instead of sorting at report time.
  • Update Wasm EH virtual-IP clause prefill/update logic to (attempt to) respect VM clause order.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/coreclr/jit/flowgraph.cpp Builds and stores the EH-clause ordering map while creating funclets.
src/coreclr/jit/fgwasm.cpp Adjusts Wasm EH virtual-IP clause construction to use the new ordering map.
src/coreclr/jit/fgbasic.cpp Removes comment notes from fgRelocateEHRange header.
src/coreclr/jit/compiler.h Adds compEHorderTab to persist the ordering map.
src/coreclr/jit/codegencommon.cpp Switches EH reporting to use compEHorderTab rather than sorting clauses at report time.

Comment thread src/coreclr/jit/flowgraph.cpp Outdated
Comment thread src/coreclr/jit/codegencommon.cpp Outdated
Comment thread src/coreclr/jit/codegencommon.cpp Outdated
Comment thread src/coreclr/jit/fgwasm.cpp
Comment thread src/coreclr/jit/fgwasm.cpp
Comment thread src/coreclr/jit/fgwasm.cpp
Comment thread src/coreclr/jit/fgwasm.cpp
Comment thread src/coreclr/jit/compiler.h Outdated
@AndyAyersMS
Copy link
Copy Markdown
Member Author

Looks like we should keep both jit->vm and vm->jit mappings. Will revise this.

Copilot AI review requested due to automatic review settings April 30, 2026 02:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/jit/fgwasm.cpp Outdated
Comment thread src/coreclr/jit/codegencommon.cpp Outdated
Comment thread src/coreclr/jit/flowgraph.cpp Outdated
@AndyAyersMS
Copy link
Copy Markdown
Member Author

@adamperlin want to review this?

@AndyAyersMS AndyAyersMS requested a review from adamperlin April 30, 2026 20:59
Comment thread src/coreclr/jit/flowgraph.cpp Outdated
Comment thread src/coreclr/jit/fgbasic.cpp
Comment thread src/coreclr/jit/flowgraph.cpp
Comment thread src/coreclr/jit/flowgraph.cpp
Copilot AI review requested due to automatic review settings May 1, 2026 01:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/jit/fgwasm.cpp
@AndyAyersMS
Copy link
Copy Markdown
Member Author

@adamperlin any other feedback?

Copy link
Copy Markdown
Contributor

@adamperlin adamperlin left a comment

Choose a reason for hiding this comment

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

I think this looks good to me!

@AndyAyersMS AndyAyersMS merged commit eb1e2c3 into dotnet:main May 2, 2026
131 of 135 checks passed
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