Skip to content

Conversation

@SingleAccretion
Copy link
Contributor

@SingleAccretion SingleAccretion commented Nov 4, 2025

Notable build system changes:

  1. Not included in clr.alljits yet. Build with clr.wasmjit.

Notable factoring choices:

  1. Introduce some new target defines for features which WASM won't need,
    like fixed size register mask support and GCInfo based on code metadata.
  2. For this initial commit, the amount of changes has been intentionally
    minimized. In the future, more things will be moved around and ifdefed out.

Contributes to #121208.

@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 Nov 4, 2025
@SingleAccretion SingleAccretion marked this pull request as draft November 4, 2025 16:55
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Nov 4, 2025
@SingleAccretion SingleAccretion changed the title [RuiJit/WASM] Create a WASM-targeting RyuJit [RuyJit/WASM] Create a WASM-targeting RyuJit Nov 4, 2025
@SingleAccretion SingleAccretion changed the title [RuyJit/WASM] Create a WASM-targeting RyuJit [RyuJit/WASM] Create a WASM-targeting RyuJit Nov 4, 2025
@SingleAccretion SingleAccretion force-pushed the WasmJit branch 2 times, most recently from 1ceabfa to e47623b Compare November 4, 2025 20:08
Comment on lines 43 to 44
#define EMIT_TRACK_STACK_DEPTH 1 // TODO-WASM: set to 0.
#define EMIT_GENERATE_GCINFO 0 // We don't (can't) use code metadata-based GCInfo on WASM
Copy link
Contributor Author

@SingleAccretion SingleAccretion Nov 4, 2025

Choose a reason for hiding this comment

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

Q: when should I use EMIT_GENERATE_GCINFO instead of TARGET_WASM?
A: use it when the code you are conditioning away relates to:

  1. Tracking GCness of variables and registers in codegen.
  2. Tracking GCness of variables and registers in emit.
  3. Emitting GCInfo via GcInfoEncoder in the emitter.

A useful mental test here is the hypothetical target of "CoreCLR interpreter bytecode", which would have HAS_FIXED_REGISTER_SET set to 0, but EMIT_GENERATE_GCINFO - 1 (it would need to use variable-size bitsets, something we don't need to deal with for WASM).

Alternatively, we can just go ahead and add it to alljits right now.
Notable build system changes:
 1) Not included in clr.alljits yet. Build with clr.wasmjit.

Notable factoring choices:
 1) Introduce some new target defines for features which WASM won't need,
    like fixed size register mask support and GCInfo based on code metadata.
 2) For this initial commit, the amount of changes has been intentionally
    minimized. In the future, more things will be moved around and ifdefed
    out.

if (CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_AMD64)
create_standalone_jit(TARGET clrjit_universal_arm64_${ARCH_HOST_NAME} OS universal ARCH arm64)
create_standalone_jit(TARGET clrjit_universal_wasm_${ARCH_HOST_NAME} OS universal ARCH wasm)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went back and forth a bit on whether to use the "more proper" wasm32 name for the target architecture. In the JIT source (and I expect in the broader /runtime source as well) TARGET_WASM will always mean TARGET_WASM32 || TARGET_WASM64 - a mismatch with _wasm being a TARGET_WASM32-only Jit. On the other hand, wasm32 would be a mismatch with Architecture.Wasm. Matching the Architecture enum seems more important.

Comment on lines +247 to +248
// TODO-WASM: implement the following functions in terms of a "locals registry" that would hold information
// about the registers.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking on this is that we will re-use the regNumber concept to denote WASM locals. So e. g. STORE_LCL_VAR GetRegNum() would return the register being defined for "enregistered" locals, and similar. So many of the properties that usual registers have (type aka register file) would also hold as well. There would just be an unlimited number of them, so we'd have a growable array for holding that metadata, or perhaps the type could be packed into the upper bits.

@SingleAccretion SingleAccretion marked this pull request as ready for review November 5, 2025 00:44
@SingleAccretion
Copy link
Contributor Author

@dotnet/jit-contrib

@jkotas jkotas added the arch-wasm WebAssembly architecture label Nov 5, 2025
@dotnet-policy-service
Copy link
Contributor

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

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 community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants