Skip to content

Add initial stubbed JIT interpreter target - #135775

Open
am11 wants to merge 4 commits into
dotnet:mainfrom
am11:feature/jit/interp-target
Open

am11 wants to merge 4 commits into
dotnet:mainfrom
am11:feature/jit/interp-target

Conversation

@am11

@am11 am11 commented Oct 14, 2026

Copy link
Copy Markdown
Member

Initial stubbed JIT interpreter target, following up on the design question in #132139: the JIT generates interpreter bytecode as its own target (TARGET_INTERP, built as clrjit_universal_interp_<host>), instead of a flag on the native JIT.

  • Target skeleton: a register-less target modeled on WASM, with its own calling convention (arguments in 8-byte interpreter stack slots), interpreter GC info encoding (gcinfo_universal_interp), and an on-demand clr.interpjit subset. After rationalization, compCompile hands the method to interpreter codegen; native lowering, register allocation and codegen don't run for this target yet.
  • Bytecode generation: ports the LIR-to-bytecode translation from Add skeleton interpreter backend to the jit compiler #132139 (int32 locals, constants, add, compare-and-branch, returns). Anything unsupported returns CORJIT_SKIPPED, and the VM falls back to the native JIT. Only existing opcodes are emitted, so no runtime changes are needed: DOTNET_InterpreterPath (or DOTNET_InterpreterName) points the VM at this JIT in place of clrinterpreter, and DOTNET_Interpreter selects the methods.
  • Result: the loop benchmark from Add skeleton interpreter backend to the jit compiler #132139 runs about 2.3x faster than under clrinterpreter (7.7 s vs 17.7 s on win-x64 Checked). The blt.i4.imm super-instruction from that PR is left for a follow-up.
    Open questions: should 32-bit hosts be a separate target (pointer size currently follows the runtime's target), and should this target eventually run its own lowering instead of skipping it?

Note

This PR description was drafted with AI assistance.

am11 and others added 2 commits October 14, 2026 18:13
Introduce an interpreter target to the JIT, built as its own standalone
binary (clrjit_universal_interp_<host>) instead of a flag on the native JIT.

- Build: new "interp" arch in create_standalone_jit, the matching
  gcinfo_universal_interp library, TARGET_INTERP (plus TARGET_64BIT when
  the runtime target is 64-bit) in clrdefinitions.cmake, and an on-demand
  clr.interpjit subset / interpjit component.
- Target model: like WASM, the interpreter has no register file, so the
  target defines a single REG_STK, no callee-saved/argument registers and
  an allocator that leaves every local on the stack.
- ABI: InterpClassifier passes every argument by value on the interpreter
  stack in 8-byte slots, matching how the interpreter lays out calls.
- GC info: TargetGcInfoEncoding is InterpreterGcInfoEncoding.
- Shared code: TARGET_INTERP joins the existing per-target chains, mostly
  on the same side as TARGET_WASM. The default NaN follows the host, since
  interpreter arithmetic runs on the host.
- compCompile hands the method to genInterpCode after rationalization and
  skips native lowering, register allocation, layout and codegen. Bytecode
  generation itself is NYI in this change.

Co-authored-by: Cursor <[email protected]>
Port the LIR-to-bytecode translation from dotnet#132139 onto the
interpreter target, as InterpCodeGen in codegeninterp.cpp. It handles int32
locals, constants, ADD, compare-and-branch, BBJ_ALWAYS/COND/RETURN blocks
and returns; anything else makes the JIT return CORJIT_SKIPPED so the VM
falls back to the next code generator.

- Emits only opcodes the interpreter already executes, so the JIT works
  with an unmodified runtime.
- Publishes the method through allocMem in the interpreter method-data
  layout and reports (empty) GC info, so the result goes through the
  normal UnsafeJitFunctionWorker / code manager path.
- Opt-in uses the same DOTNET_Interpreter method list as the interpreter
  library. Pointing DOTNET_InterpreterPath (or DOTNET_InterpreterName) at
  clrjit_universal_interp_<host> makes the VM use this JIT where it would
  use clrinterpreter.
- Moves InterpMethod / InterpByteCodeStart into interpmethod.h so the JIT
  can include them without the rest of interpretershared.h.
- Adds a DEBUG disassembler (interpdump.cpp) used by JitDump.

Co-authored-by: Vlad Brezae <[email protected]>
Co-authored-by: Cursor <[email protected]>
@am11
am11 requested review from BrzVlad and janvorli as code owners October 14, 2026 15:27
@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 Oct 14, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 14, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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

@am11
am11 requested a review from jkotas October 14, 2026 15:30
am11 added 2 commits October 14, 2026 19:05
- Guard the getInsExecutionCharacteristics stub with DEBUG || LATE_DISASM,
  matching its declaration.
- Stub the native prolog helpers that genFnProlog still references in
  Release builds.
- Give 32-bit TARGET_INTERP builds a USE_LAZY_PREFERRED_RANGE clause in
  switches.h.
@EgorBo

EgorBo commented Oct 14, 2026

Copy link
Copy Markdown
Member

note: this needs to be an officially funded implementation effort. Im not keen on adding another 2000 LOC of potentially unnecessary code to the JIT. Perhaps this should be done in runtimelab?

@jkotas

jkotas commented Oct 14, 2026

Copy link
Copy Markdown
Member

#132139 and the linked issue has the discussion as described in top post.

We do not have agreement across the stakeholders that this is worth it (or worth spending time on now at least) beyond that it is cool. @BrzVlad has been interested in this idea for wasm. I would leave it up to him whether he wants to push this forward as an experimental project.

Perhaps this should be done in runtimelab?

Yes, this can be an option.

clrjit_universal_interp64_ and clrjit_universal_interp32_ flavors

I would expect this to be only used in native runtime configuration like regular JIT, so it is not necessary for the target to be part of the name. Regular runtime JIT is always clrjit, so this can be similar.

@BrzVlad

BrzVlad commented Oct 16, 2026

Copy link
Copy Markdown
Member

Here is some more context that I should have added on my original PR about this approach. From the perspective of iOS, I believe this is the best option, good interpreter performance while reusing various bits from the JIT. Having a fixed app size increase of something like 500k (which is a rough estimate of a compressed aggressively trimmed down version of the jit) is not too bad. A better interpreter could also allow us to r2r less code while still having decent performance, which could lead to overall improvement also on the size front.

WASM however raises several problems

  • 500k increase in web app size is worse than the same for mobile app. The expectation is that web apps are much smaller than mobile apps.
  • the interpreter will be used to execute more code on browser, compared to iOS where everything is R2R. This means that the slower compilation time of the jit based interpreter (around 1.5x slower according to some initial measurements), could represent an additional source of perf regression for startup.
  • iOS doesn't have any better codegen alternative, so an optimizing interpreter would be nice to have. Wasm doesn't necessarily have this limitation, the plan is to tier up either to r2r code hosted by the server or to JIT inside the browser. If that is the case, then there is little motivation to have an intermediary tier via a separate interpreter compilation library, which is also bigger in size and slower in compilation for Tier0. Maintaining 2 interpreter libraries, one optimizing for iOS and a smaller one for wasm, is not really an acceptable option.

Having said that, I believe that this project is quite appealing since it has the potential to offer good enough perf in a simplistic configuration (some r2r + the rest interpreted). I believe it would be useful to have this experiment ongoing in the runtimelab. It could allow us to do some actual benchmarking comparison in the future and also allow us to more easily adjust direction towards it, if it is worth the effort.

@am11

am11 commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

Another potential use-case of interpreter is in AOT apps (desktop, mobile and browser alike) to enable dynamic code generation and overcome reflection constraints. Similarly, with pure interpreter mode, we could make R2R also emit interp bytecode for platforms, which are currently unsupported in coreclr (like ppc64le, s390x).

If you can sync https://github.com/dotnet/runtimelab/tree/feature/CoreclrInterpreter to dotnet/runtime's main branch, I can move this PR there.

@EgorBo

EgorBo commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

500k increase in web app size is worse than the same for mobile app. The expectation is that web apps are much smaller than mobile apps.

I guess if we can't make it work for wasm, do we really want an additional interpreter just for ios? Presumably any function that is a perf bottleneck with interpteter must be R2R'd

Another potential use-case of interpreter is in AOT apps (desktop, mobile and browser alike) to enable dynamic code generation and overcome reflection constraints.

I would have assumed this already worked for R2R in practice? For NativeAOT, I guess it doesn’t make much sense, since it undermines its main advantage - the closed-world assumption and precise dependency analysis

@am11

am11 commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

it doesn’t make much sense, since it undermines its main advantage

@EgorBo, coreclr had interpreter from the get go which was rebooted in runtimelab, then ported over to runtime last year, see #112748, so the premise has been set. If we list down all the limitations of NativeAOT (dynamic code generation, reflection.emit etc. used in MVC apps / razor view, roslyn itself and so on), those are pretty much declared never happening features in NativeAOT, we can imagine interpreter enabling all of them someday. This JIT backed interpert is just to make it appealing from perf viewpoint; provides same set of optimizations. In cases where app size doesn't matter; we can R2R the interp opcodes to avoid runtime JIT'in opcodes in AOT apps.

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

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