Skip to content

Wasm funclet RA#126445

Merged
AndyAyersMS merged 28 commits intodotnet:mainfrom
AndyAyersMS:WasmFuncletRA
Apr 8, 2026
Merged

Wasm funclet RA#126445
AndyAyersMS merged 28 commits intodotnet:mainfrom
AndyAyersMS:WasmFuncletRA

Conversation

@AndyAyersMS
Copy link
Copy Markdown
Member

Implement register allocation for funclets, along with some funclet codegen.

Copilot AI review requested due to automatic review settings April 2, 2026 02:03
@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 2, 2026
@AndyAyersMS
Copy link
Copy Markdown
Member Author

FYI @dotnet/jit-contrib

Still a work in progress, but figured I'd ask for some feedback before getting too much further. Things I know of that are still to do:

  • We may need to handle case where an allocatable local is not live across a funclet boundary and ends up in different registers in different regions. Currently for STORE_LCL_VAR we always take the reg from the lcl var.
  • ABI classifier type support for funclet params?
  • Check if typeless catch won't actually get an ex obj from runtime (I suppose we can pass nullptr if necessary)
  • Codegen is still off -- there is a bogus block before funclet start, and no return
  • This won't validate (I'm pretty sure) until the jit host extracts the funclets into separate functions.

@SingleAccretion this may be more complex than what you had envisioned.

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 extends the WASM JIT backend to support funclets by introducing per-funclet (region) register allocation state, per-funclet locals declarations, and basic funclet prolog codegen so EH regions can be code-generated with their own Wasm-local layouts.

Changes:

  • Add per-funclet RA state (SP/FP/EX + reference tracking) and resolve/register publish logic per region.
  • Teach codegen/emitter to use per-funclet SP/FP and emit per-funclet local declarations / funclet prologs.
  • Update internal-register tracking to be per-funclet on targets without a fixed register set (WASM).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/coreclr/jit/regallocwasm.h Introduces per-region RA state (SP/FP/EX + ref tracking) and new catch-arg collection hook.
src/coreclr/jit/regallocwasm.cpp Implements per-funclet allocation, catch-arg rewriting, per-funclet internal-reg tables, and per-funclet locals decl generation/publishing.
src/coreclr/jit/lclvars.cpp Adjusts frame-location dumping to use region-0 SP/FP on non-fixed-reg targets.
src/coreclr/jit/emitwasm.cpp Extends wasm arg-count computation to support funclet signatures.
src/coreclr/jit/codegenwasm.cpp Uses per-funclet SP/FP accessors and implements funclet prolog local signature emission.
src/coreclr/jit/codegeninterface.h Makes SP/FP storage and internal-reg tracking per-funclet for non-fixed-reg targets; makes locals decls per-funclet.
src/coreclr/jit/codegencommon.cpp Implements non-fixed-reg per-funclet NodeInternalRegisters tables and initializes per-funclet SP/FP/locals storage.

Copy link
Copy Markdown
Contributor

@SingleAccretion SingleAccretion left a comment

Choose a reason for hiding this comment

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

Looks a lot like what I was thinking about too.

Left some high-level feedback.

@AndyAyersMS
Copy link
Copy Markdown
Member Author

@SingleAccretion 90066eb should cover most of your feedback except internal regs.

@am11 am11 added the arch-wasm WebAssembly architecture label Apr 2, 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.

Copy link
Copy Markdown
Contributor

@SingleAccretion SingleAccretion left a comment

Choose a reason for hiding this comment

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

Mostly small comments left from me. But we also need to be a bit more careful with lvRegNum mutations.

Copilot AI review requested due to automatic review settings April 2, 2026 20:53
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 9 out of 9 changed files in this pull request and generated 5 comments.

@AndyAyersMS
Copy link
Copy Markdown
Member Author

Hopefully closer now...

@SingleAccretion in the future maybe just point out one instance of a recurring pattern? Otherwise stuff may get overlooked.

@AndyAyersMS
Copy link
Copy Markdown
Member Author

AndyAyersMS commented Apr 2, 2026

There's still an issue where a node can be collected twice, eg if it both needs a register and also has internal registers, and double processing a collected node is not good.

We could have the collector mark nodes perhaps, use this to avoid a double collection, and unmark them when we process them later.

Also RequestInternalRegister can be called multiple times for the same node.

Copilot AI review requested due to automatic review settings April 2, 2026 23:15
Copilot AI review requested due to automatic review settings April 4, 2026 16:11
@AndyAyersMS
Copy link
Copy Markdown
Member Author

Ok, one more batch of updates:

  • rely on allocator's m_currentFunclet to track what assignments the lcl var dscs hold. If we think they're already correct, verify that they are, in debug.
  • remove need for LIR flag by remembering the last collected node
  • add node on why we don't need a debug live range update like LSRA has

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 11 out of 11 changed files in this pull request and generated 5 comments.

Copy link
Copy Markdown
Contributor

@SingleAccretion SingleAccretion left a comment

Choose a reason for hiding this comment

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

Looking pretty good, just a few comments!

There is also #126445 (comment) which looks valid but is pre-existing and can be addressed separately.

@AndyAyersMS AndyAyersMS marked this pull request as ready for review April 5, 2026 01:45
Copilot AI review requested due to automatic review settings April 5, 2026 01:45
@AndyAyersMS
Copy link
Copy Markdown
Member Author

@dotnet/jit-contrib PTAL

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 11 out of 11 changed files in this pull request and generated 2 comments.

@kg
Copy link
Copy Markdown
Member

kg commented Apr 8, 2026

LGTM but I don't understand all of it.

@AndyAyersMS
Copy link
Copy Markdown
Member Author

/ba-g infrastructure issues

@AndyAyersMS AndyAyersMS merged commit 5781c28 into dotnet:main Apr 8, 2026
131 of 137 checks passed
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.

5 participants