Skip to content

[Wasm RyuJit] annotate (some) local accesses with var nums#124880

Open
AndyAyersMS wants to merge 5 commits intodotnet:mainfrom
AndyAyersMS:WasmStackLocalEmitterNotes
Open

[Wasm RyuJit] annotate (some) local accesses with var nums#124880
AndyAyersMS wants to merge 5 commits intodotnet:mainfrom
AndyAyersMS:WasmStackLocalEmitterNotes

Conversation

@AndyAyersMS
Copy link
Member

This was an attempt to reproduce some of the extra annotations we see in native dumps, for locals that are spilled to the shadow stack.

This was an attempt to reproduce some of the extra annotations we
see in native dumps, for locals that are spilled to the shadow stack.
Copilot AI review requested due to automatic review settings February 26, 2026 01:59
@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 Feb 26, 2026
@dotnet-policy-service
Copy link
Contributor

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

Copy link
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

Adds extra disassembly annotations for WASM RyuJit to make shadow-stack local loads/stores easier to correlate with JIT locals, similar to what native dumps show.

Changes:

  • Teach emitIns_S (WASM) to attach local/offset metadata to emitted instructions when debug/disasm info is enabled.
  • Extend WASM instruction display (emitDispIns) to print local annotations for IF_MEMARG instructions.
  • Initialize instrDescDebugInfo::idVarRefOffs to BAD_VAR_NUM for WASM so local V00 can be distinguished from “no info”.

Reviewed changes

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

File Description
src/coreclr/jit/emitwasm.cpp Records local/offset metadata during emission and prints it in WASM disassembly for memory-argument instructions.
src/coreclr/jit/emit.cpp Sets a WASM-specific sentinel default for debug-only local-reference metadata.

@AndyAyersMS
Copy link
Member Author

This only annotates loads right now since stores do not go through emitIns_S, note the store to V04 below...

IN0001: 00001D      nop
IN0002: 00001E      local.get 0
IN0003: 000020      local.get 0
IN0004: 000022      i32.load 0 12      ;; V01
IN0005: 000025      local.get 0
IN0006: 000027      i32.load 0 12      ;; V01
IN0007: 00002A      i32.add
IN0008: 00002B      local.get 0
IN0009: 00002D      i32.load 0 8      ;; V02
IN000a: 000030      i32.add
IN000b: 000031      i32.store 0 0
IN000c: 000034      nop
IN000d: 000035      local.get 0
IN000e: 000037      i32.load 0 0      ;; V04

The debuginfo-only fields I am reusing seem largely dead. Maybe they should be cleaned up on other architectures.

@dotnet/jit-contrib worth doing anyways?

@SingleAccretion
Copy link
Contributor

worth doing anyways?

I think this is a good change, but we should add new fields instead of reusing/overloading the existing half-dead ones. E. g. unsigned idLclNum; unsigned idLclOffset.

AndyAyersMS and others added 3 commits February 26, 2026 07:41
Instead of reusing existing idVarRefOffs/idVarRefOffs2 fields, introduce
new idLclNum and idLclOffset fields in instrDescDebugInfo for WASM to
store local variable number and field offset.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Initialize idLclNum to 0, store varx+1 when setting, and subtract 1
when displaying. This avoids depending on BAD_VAR_NUM as a sentinel.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
instrDescDebugInfo is already fully zero-initialized via memset, so the
explicit assignment is unnecessary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AndyAyersMS AndyAyersMS marked this pull request as ready for review February 26, 2026 22:46
Copilot AI review requested due to automatic review settings February 26, 2026 22:46
@AndyAyersMS
Copy link
Member Author

@kg PTAL
fyi @dotnet/jit-contrib

Copy link
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 3 out of 3 changed files in this pull request and generated no new comments.

unsigned log2align = emitGetAlignHintLog2(id);
cnsval_ssize_t offset = emitGetInsSC(id);
printf(" %u %llu", log2align, (uint64_t)offset);
dispLclVarInfoIfAny();
Copy link
Contributor

Choose a reason for hiding this comment

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

The IF_ULEB128 family of formats should get the same treatment (used for local address offsets).

info->idNum = emitInsCount;
info->idSize = sz;

id->idDebugOnlyInfo(info);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: if we called the constructor for info properly here (using placement_t I suppose), and assigned the fields their default values via initializers, we wouldn't need the 'offset by one' trick, and could delete the asserts above too.

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.

4 participants