-
Notifications
You must be signed in to change notification settings - Fork 204
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
NativeAOT-LLVM: RyuJIT IR -> LLVM for improved performance #647
NativeAOT-LLVM: RyuJIT IR -> LLVM for improved performance #647
Conversation
…orRunner} > clrjit_unix_x64_x64.dll!Compiler::getPrimitiveTypeForStruct(unsigned int structSize, CORINFO_CLASS_STRUCT_ * clsHnd, bool isVarArg) Line 723 C++ with Run-Time Check Failure dotnet#2 - Stack around the variable 'gcPtr' was corrupted.
Wasm64 has some macros defined, but otherwise not compiled Copied mostly from the xarch and AMD64 macros to get something to compile and run.
cc @EgorBo |
//InstructionSet_SSE3 = 4, | ||
//InstructionSet_SSSE3 = 5, | ||
//InstructionSet_SSE41 = 6, | ||
InstructionSet_SSE42 = 7, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not sound right that you have to define SSE2 and AVX2 for wasm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were getting used for the SIMD check
runtimelab/src/coreclr/jit/compiler.h
Line 8038 in fdc65fc
SIMDLevel getSIMDSupportLevel() |
assert
for Wasm and these instructions in corinfoinstructionset.h
are removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect Wasm to have its own wasm-specific names for SIMD levels, and not to reuse the x86/x64 ones. ARM does not reuse the x86/x64 ones either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. https://github.com/WebAssembly/simd isn't finalized yet, but when it is I'd expect we would look at introducing a new System.Runtime.Intrinsics.Wasm
namespace and corresponding ISAs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, for now I've just deleted this change. https://github.com/dotnet/runtimelab/pull/647/files#diff-5bc0c93aea7b72e9e37d8742e7a59ffb882ff206b746494f2e1f484bc3ef47c1
src/coreclr/jit/emit.h
Outdated
@@ -576,6 +576,10 @@ class emitter | |||
#elif defined(TARGET_ARM64) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeGen
and emitter
are late phases. They should be all replaced by the LLVM part. Is it possible to ifdef them out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think I should be able #if out the Lowering class? https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/src/coreclr/jit/lower.h
Edit... I will go for removing it as well as the lsra code as that seems to make sense as at least the SIMPLE_LOWERING is a late phase and assume Lowering
is part of that, or something later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have removed those + lsra + lower. There's a few places that require #ifdefs
to allow compilation to succeed. In some places where I'm not sure what's best I've left the wasm build throwing an assert
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think inst*
can be remove too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, removed.
wasm compilation will now complete, although has an issue with the dbg instruction in Array Resize
Some code alerts false where not sure what to do. Passes non-wasm tests locally.
Some code alerts false where not sure what to do. Passes non-wasm tests locally.
src/coreclr/jit/lsra.h
Outdated
@@ -735,7 +735,7 @@ class LinearScan : public LinearScanInterface | |||
// Hence the "SmallFPSet" has 5 elements. | |||
CLANG_FORMAT_COMMENT_ANCHOR; | |||
|
|||
#if defined(TARGET_AMD64) | |||
#if defined(TARGET_AMD64) || defined(TARGET_WASM) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There changes should not be needed now that the whole file is ifdefed out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
src/coreclr/jit/stacklevelsetter.cpp
Outdated
// The constructor reads this value to skip iterations that could set it if it is already set. | ||
compiler->codeGen->resetWritePhaseForFramePointerRequired(); | ||
#else | ||
assert(false); // Wasm - TODO can this be ignored? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to exclude the whole StackLevelSetter (it runs after lowering).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, yes, removed also.
remove stacklevelsetter with ifdef fix ifdef syntax
@jkotas For the wasm build, I need to build the clrjit for the host platform, initially win64. The gen-buildsys script at the moment uses |
I am not sure which one of these options will turn out better. I think either one can work fine. |
…oment attempt to add a second platform to the wasm yaml build fix problem where Array<T>.Resize has its code compiled twice.
At runtimelab/src/coreclr/inc/crosscomp.h Line 385 in fab1157
It defines T_CONTEXT . For windows this comes from winnt.h in the SDK, but for Wasm what should I do here? It looks like its mostly registers, so would an empty
Be somewhere to start? |
Yes, a dummy definitions like this sound like a good way to start. You can omit This whole header should not be really included by the JIT (there are only a very few things - if any - needed by the JIT from this header), but refactoring to fix that may be too involved. |
May also need before including any LLVM header files: #undef NumItems
…jit-llvm-imethodcodenode # Conflicts: # src/coreclr/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp # src/coreclr/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp # src/coreclr/inc/icorjitinfoimpl_generated.h # src/coreclr/inc/jiteeversionguid.h # src/coreclr/jit/ICorJitInfo_API_wrapper.hpp # src/coreclr/jit/instr.cpp # src/coreclr/jit/target.h # src/coreclr/tools/Common/JitInterface/CorInfoBase.cs # src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt # src/coreclr/tools/aot/ILCompiler.LLVM/Compiler/LLVMCodegenCompilation.cs # src/coreclr/tools/aot/ILCompiler.LLVM/Compiler/LLVMCodegenCompilationBuilder.cs # src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs # src/coreclr/tools/aot/jitinterface/jitinterface.h Workaround for min, max, and NumItems #defines.
Fix up some merge problems
additional exports for llvm clrjit
# Conflicts: # src/coreclr/jit/CMakeLists.txt
…that is the compression Llvm use) Add build of clrjit for Windows x64 Debug only. This means that WebAssembly can only be built on that combination (as is the tested case currently).
627c5b5
to
33a1b1a
Compare
enable linking from publish some refactor to allow the signature to be retrieved to create the externals for clrjit methods.
…jit-llvm-imethodcodenode # Conflicts: # src/coreclr/tools/aot/ILCompiler.LLVM/CodeGen/ILToLLVMImporter.cs
@jkotas This has gotten pretty long in number of commits, especially the attempts to get the CI working, which I tried to squash, but must have failed. Do you want me to squash the whole lot? Its ready for review now that the nuget package is working and the hard coded method is removed (it does 9 methods currently, which is all the From here I was going to suggest that coverage of LIR is done in smaller PRs, each one adding to the % of method coverage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pushing this forward!
src/coreclr/jit/codegencommon.cpp
Outdated
@@ -30,6 +30,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | |||
#include "patchpointinfo.h" | |||
|
|||
/*****************************************************************************/ | |||
#endif //!TARGET_WASM | |||
|
|||
const BYTE genTypeSizes[] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be nice to move this to compiler.cpp since they are declared in compiler.h/hpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This change can be pushed to dotnet/runtime as general goodness.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks,
If I've got this right at https://github.com/dotnet/runtimelab/pull/647/commits
/76fb9b5a3ffc78b4164526e4a4f706b4fac3cbe9 then I'll do the runtime PR
src/coreclr/inc/switches.h
Outdated
@@ -65,6 +65,8 @@ | |||
#define USE_UPPER_ADDRESS 0 | |||
#endif // !HOST_UNIX | |||
|
|||
#elif defined(TARGET_WASM) | |||
#define USE_UPPER_ADDRESS 0 // TODO : what's this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This controls how VM allocates memory for executable code. JIT should not really depend on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, have left it in, but updated the comment
src/coreclr/jit/compiler.cpp
Outdated
#if defined(TARGET_WASM) | ||
#include "llvm.h" | ||
#else | ||
// TODO: how to get different exports.def for the different clrjits? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a workaround. It should be a method on the JIT/EE interface eventually that will make this problem go away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I handled the exports.def in the CMakeLists.txt so deleted this comment.
src/coreclr/jit/compiler.cpp
Outdated
Llvm* llvm = new Llvm(); | ||
llvm->Compile(pCompiler); | ||
delete llvm; | ||
//assert(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//assert(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -3,7 +3,11 @@ | |||
|
|||
#define GCS EA_GCREF | |||
#define BRS EA_BYREF | |||
#if defined(TARGET_WASM) | |||
#define PS TARGET_POINTER_SIZE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be TARGET_POINTER_SIZE
unconditionally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, push to runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that may be nice.
src/coreclr/jit/unwindwasm.cpp
Outdated
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be only called from codegen. None of it should be needed (or be reachable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted
@@ -173,6 +175,74 @@ public ILImporter(LLVMCodegenCompilation compilation, MethodDesc method, MethodI | |||
_builder = Context.CreateBuilder(); | |||
} | |||
|
|||
// [DllImport(JitSupportLibrary)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, done, thanks
@@ -0,0 +1,200 @@ | |||
// // Licensed to the .NET Foundation under one or more agreements. | |||
// // The .NET Foundation licenses this file to you under the MIT license. | |||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete? The whole file is commented out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
[UnmanagedCallersOnly] | ||
public static byte* getMangledMethodName(IntPtr thisHandle, CORINFO_METHOD_STRUCT_* ftn) | ||
{ | ||
//var _this = GetThis(thisHandle); // TODO: this doesn't work, but how does it cope anyway with this being moved by the GC? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but how does it cope anyway with this being moved by the GC?
The IntPtr points to stack location where CorInfoImpl
reference is stored.
JIT/EE interface assumes that the JIT does not store the this pointer in a static. registerLlvmCallbacks
stores the this pointer in a static. I suspect that it is why it does not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, have done something similar so this now works without the static.
Co-authored-by: Jan Kotas <[email protected]>
…/runtimelab into ryujit-llvm-imethodcodenode
- Remove unnecessary ifdefs - Replace ifdefs with cmake exclusions - Fix passing of corinfo - remove some comments
Thanks @jkotas @SingleAccretion for the help. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Some mucking around to try to get something that can be played with. Copied a lot of clrjit macros and code from xarch/amd64 and deleted/changed to get compilation to succeed and run at least as far as compiling the first method. This is my attempt to tackle #313 and may be total garbage. The clrjit does nothing at the moment exception
assert(false)
at the appropriate phase. In theory it should be possible to catch this and revert to CIL -> LLVM allowing tests to run at an early stage of playing while adding IR support.