Repository navigation
Conversation
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]>
|
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. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
- 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.
|
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? |
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.
Yes, this can be an option.
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. |
|
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
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. |
|
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. |
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
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 |
@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 |
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 asclrjit_universal_interp_<host>), instead of a flag on the native JIT.gcinfo_universal_interp), and an on-demandclr.interpjitsubset. After rationalization,compCompilehands the method to interpreter codegen; native lowering, register allocation and codegen don't run for this target yet.CORJIT_SKIPPED, and the VM falls back to the native JIT. Only existing opcodes are emitted, so no runtime changes are needed:DOTNET_InterpreterPath(orDOTNET_InterpreterName) points the VM at this JIT in place ofclrinterpreter, andDOTNET_Interpreterselects the methods.clrinterpreter(7.7 s vs 17.7 s on win-x64 Checked). Theblt.i4.immsuper-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.