-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LLVM as a back-end for RyuJIT #313
Comments
Right, EH and GC are still enormous hurdles. I think you may be able to get pretty far with EH, perhaps only compromising on currently somewhat rare cases -- like filters that have side effects -- that require a true understanding of the order in which things can happen. I don't believe there is a viable strategy for precise GC with LLVM native codegen right now, especially if you start turning on parts of the LLVM optimizer. That being said, the Azul folks have something; I'm not sure if they've upstreamed the key parts. However, it's likely the story in Java is a bit simpler, as they don't have managed (interior) pointers. |
If I'm not mistaken, in Mono we decided to just IL-rewrite exception filters to normal I have no plans for precise GC at the moment as it's definitely too complicated for me. |
Yes, EH and GC are problems that require work. I would not worry about them initially. GC can be conservative first and EH filters are rare. Random thoughts:
|
In accordance with #313 (comment), I wrote up, briefly, where LLVM(for Wasm) filter handling order was wrong in CoreRT here dotnet/corert#8283, with an idea for fixing it. I've not looked at |
I'm curious about "build a transparent RyuJIT replacement is not necessarily the best option". I'm a bit out of my depth as far as extending RyuJit is concerned to be sure, but what would be your approach @jkotas ? Can it be done in c# or is it going to require what looks like a visitor pattern implemented in cpp as above? |
I had a read of https://github.com/dotnet/coreclr/blob/master/Documentation/botr/ryujit-tutorial.md. Looking at the "Backend phases": Would there be an intercept somewhere along this pipeline? |
I think the idea would be to convert Rationalized LIR to LLVM IR. @EgorBo Is rationalized IR where your prototype is plugged in? |
After runtimelab/src/coreclr/jit/compiler.cpp Line 4977 in 95de52e
|
Ah, sorry for the delayed response, yeah right there. After phases where Jit removes all the assertions/nullchecks/bound checks, GT_COMMAs 🙂 However, I didn't really need LIR (e.g. I didn't use |
Sounds great. Is there an opinion about where the LLVM generation should live, in c# in Ilc or in c++ land? |
LLVM C API (and hence the C# bindings) is more verbose and doesn't cover 100% of the API LLVM provides for C++ (in Mono we use mostly C API but had to switch to C++ for some things). I also had a script somewhere to generate C# bindings for JIT structures/classes (at least layouts) so in theory it can be done in C# as well 🙂 |
I think this should be a special build of the JIT that calls into LLVM C or C++ APIs. I do not see why we would need to expose JIT internals as public APIs for this. |
Thinking about how to structure this in Ilc, would it make sense to try to reuse |
I think so |
I made a couple of idea changes at https://github.com/yowl/runtimelab/tree/ryujit-llvm-imethodcodenode . Idea being to introduce an |
@EgorBo Did you have problems including LLVM headers into clrjit? E.g. at runtimelab/src/coreclr/inc/holder.h Lines 14 to 20 in fab1157
C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.28.29333\\include\\xtr1common
|
@yowl Sorry for the delayed replies - the notifications were turned off for me for this repo for some reason.
Yes, I couldn't solve them in a reasonable time, gave up and just did everything in a separate lib + added jit headers (stripped) |
Since dotnet/corert#8230 thread was archived recently, I'm creating a new one here to continue the discussion.
I'm trying to build a minimal dynamically-loaded extension for RyuJIT to generate LLVM IR (and compile it for tier1 (JIT) or use in AOT scenarios) from GenTrees (HIR/LIR) in order to benefit from RyuJIT's .net specific optimizations and SSA transformation for locals. Something like this:
(my local version is a bit more complicated but it's still just a very high-level prototype and is a mess)
Some of the challenges (too early to make a deep analysis):
Since there are LLILC and #247 efforts I wonder what can be shared/merged. Maybe it makes sense to bind all RyuJIT's structures/API to C# (e.g. via
CppAst.NET
) and continue IR -> LLVM IR transformation there using LLVMSharp (C# bindings for LLVM C-api). Maybe it's better to join #247 and just port RyuJIT's optimizations one-by-one there.Initially, I just wanted to make an extension for RyuJIT to replace tier1 with LLVM-JIT for HPC# code (a GC-free subset of C# in Unity's Burst for high-performance stuff) to generate vectorized loops, etc where RyuJIT currently doesn't perform well. But I see that there is a quite a demand for AOT. So maybe you have some thoughts regarding the direction it is better to move to to make it at least theoretically useful?
/cc @jkotas @MichalStrehovsky @yowl @AndyAyersMS
The text was updated successfully, but these errors were encountered: