From f32660261f2251b191319a39432fe914709ddcd0 Mon Sep 17 00:00:00 2001 From: Simon Nattress Date: Wed, 18 Jul 2018 18:33:49 -0700 Subject: [PATCH] Refactor RyuJit (#6098) * Refactor RyuJit Set up the consumption of RyuJit classes so that we can import CorInfoImpl.cs from multiple projects with different `#ifdef` settings for conditional compilation. * In CoreCLR ready-to-run compilation mode, we want the Jit interface implementation to know about ReadyToRunCodegenCompilation so that it can ask for nodes / services that are ready-to-run specific. We do not want to leak that stuff into the main ILCompiler.Compiler project, since vanilla CoreRT shouldn't have to know about such details. * Revert the class visibility of several JitInterface classes. We made some public to speed up the prototyping previousl. * Make the type visibility uniform in `CorInfoTypes.cs`. There was a mixture of public / internal structs / enums. I chose to make them all public so this file can be included in ILCompiler.RyuJit and its contents referenced from consuming libraries. * Define `READY_TO_RUN` when building `ILCompiler.ReadyToRun` so we can keep ready-to-run specific pieces under `#ifdef` * Split `CorInfoImpl` out into partial classes so the compiler front-end specific `Compilation` class can be customized. * Move Jit-specific classes to `ILCompiler.RyuJit`: `RyuJitNodeFactory`, `RyuJitCompilation`, `RyuJitCompilationBuilder`, `MethodCodeNode`, `IMethodCodeNode` --- .../Internal/Runtime/EETypeBuilderHelpers.cs | 23 --- .../src/Compiler/Compilation.cs | 2 +- .../Compiler/DependencyAnalysis/EETypeNode.cs | 2 +- .../DependencyAnalysis/ObjectNodeSection.cs | 4 + .../DependencyAnalysis/ObjectWriter.cs | 16 +- .../src/Compiler/JitHelper.cs | 4 +- .../src/Compiler/TypeExtensions.cs | 27 +++ .../src/IL/Stubs/PInvokeILProvider.cs | 2 +- .../src/ILCompiler.Compiler.csproj | 35 +--- .../tests/ILCompiler.Compiler.Tests.csproj | 1 + .../src/ILCompiler.ReadyToRun.csproj | 32 ++++ .../JitInterface/CorInfoImpl.ReadyToRun.cs | 24 +++ .../DependencyAnalysis/IMethodCodeNode.cs | 0 .../DependencyAnalysis/MethodCodeNode.cs | 11 +- .../DependencyAnalysis/RyuJitNodeFactory.cs | 0 .../src/Compiler/RyuJitCompilation.cs | 0 .../src/Compiler/RyuJitCompilationBuilder.cs | 0 .../src/ILCompiler.RyuJit.csproj | 77 +++++++++ .../src/JitInterface/CorInfoImpl.RyuJit.cs | 24 +++ .../src/CodeGen/WebAssemblyObjectWriter.cs | 1 - src/ILCompiler/ILCompiler.sln | 29 ++++ src/ILCompiler/desktop/desktop.csproj | 4 + src/ILCompiler/src/ILCompiler.csproj | 1 + src/JitInterface/src/CorInfoBase.cs | 2 +- .../src/CorInfoImpl.Intrinsics.cs | 2 +- src/JitInterface/src/CorInfoImpl.cs | 6 +- src/JitInterface/src/CorInfoTypes.VarInfo.cs | 163 ++++++++++++++++++ src/JitInterface/src/CorInfoTypes.cs | 152 +--------------- .../src}/MemoryHelper.cs | 6 +- .../src/System.Private.Jit.csproj | 7 +- 30 files changed, 420 insertions(+), 237 deletions(-) create mode 100644 src/ILCompiler.ReadyToRun/src/JitInterface/CorInfoImpl.ReadyToRun.cs rename src/{ILCompiler.Compiler => ILCompiler.RyuJit}/src/Compiler/DependencyAnalysis/IMethodCodeNode.cs (100%) rename src/{ILCompiler.Compiler => ILCompiler.RyuJit}/src/Compiler/DependencyAnalysis/MethodCodeNode.cs (87%) rename src/{ILCompiler.Compiler => ILCompiler.RyuJit}/src/Compiler/DependencyAnalysis/RyuJitNodeFactory.cs (100%) rename src/{ILCompiler.Compiler => ILCompiler.RyuJit}/src/Compiler/RyuJitCompilation.cs (100%) rename src/{ILCompiler.Compiler => ILCompiler.RyuJit}/src/Compiler/RyuJitCompilationBuilder.cs (100%) create mode 100644 src/ILCompiler.RyuJit/src/ILCompiler.RyuJit.csproj create mode 100644 src/ILCompiler.RyuJit/src/JitInterface/CorInfoImpl.RyuJit.cs create mode 100644 src/JitInterface/src/CorInfoTypes.VarInfo.cs rename src/{ILCompiler.Compiler/src/Compiler => JitInterface/src}/MemoryHelper.cs (80%) diff --git a/src/Common/src/Internal/Runtime/EETypeBuilderHelpers.cs b/src/Common/src/Internal/Runtime/EETypeBuilderHelpers.cs index 9f59b074e75..730ba484cf8 100644 --- a/src/Common/src/Internal/Runtime/EETypeBuilderHelpers.cs +++ b/src/Common/src/Internal/Runtime/EETypeBuilderHelpers.cs @@ -141,29 +141,6 @@ public static UInt16 ComputeFlags(TypeDesc type) return flags; } - public static bool ComputeRequiresAlign8(TypeDesc type) - { - if (type.Context.Target.Architecture != TargetArchitecture.ARM) - { - return false; - } - - if (type.IsArray) - { - var elementType = ((ArrayType)type).ElementType; - if ((elementType.IsValueType) && ((DefType)elementType).InstanceByteAlignment.AsInt > 4) - { - return true; - } - } - else if (type.IsDefType && ((DefType)type).InstanceByteAlignment.AsInt > 4) - { - return true; - } - - return false; - } - // These masks and paddings have been chosen so that the ValueTypePadding field can always fit in a byte of data // if the alignment is 8 bytes or less. If the alignment is higher then there may be a need for more bits to hold // the rest of the padding data. diff --git a/src/ILCompiler.Compiler/src/Compiler/Compilation.cs b/src/ILCompiler.Compiler/src/Compiler/Compilation.cs index 7df723cb5b7..915b4986eb9 100644 --- a/src/ILCompiler.Compiler/src/Compiler/Compilation.cs +++ b/src/ILCompiler.Compiler/src/Compiler/Compilation.cs @@ -31,7 +31,7 @@ public abstract class Compilation : ICompilation public NodeFactory NodeFactory => _nodeFactory; public CompilerTypeSystemContext TypeSystemContext => NodeFactory.TypeSystemContext; public Logger Logger => _logger; - internal PInvokeILProvider PInvokeILProvider { get; } + public PInvokeILProvider PInvokeILProvider { get; } private readonly TypeGetTypeMethodThunkCache _typeGetTypeMethodThunks; private readonly AssemblyGetExecutingAssemblyMethodThunkCache _assemblyGetExecutingAssemblyMethodThunks; diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/EETypeNode.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/EETypeNode.cs index 01b643a1142..cfc6df3335d 100644 --- a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/EETypeNode.cs +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/EETypeNode.cs @@ -907,7 +907,7 @@ void ComputeRareFlags(NodeFactory factory, bool relocsOnly) flags |= (uint)EETypeRareFlags.HasCctorFlag; } - if (EETypeBuilderHelpers.ComputeRequiresAlign8(_type)) + if (_type.RequiresAlign8()) { flags |= (uint)EETypeRareFlags.RequiresAlign8Flag; } diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectNodeSection.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectNodeSection.cs index e9eaf77c7ad..400e36e89a9 100644 --- a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectNodeSection.cs +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectNodeSection.cs @@ -49,5 +49,9 @@ public bool IsStandardSection public static readonly ObjectNodeSection FoldableReadOnlyDataSection = new ObjectNodeSection("rdata$F", SectionType.ReadOnly); public static readonly ObjectNodeSection TextSection = new ObjectNodeSection("text", SectionType.Executable); public static readonly ObjectNodeSection TLSSection = new ObjectNodeSection("TLS", SectionType.Writeable); + public static readonly ObjectNodeSection ManagedCodeStartSection = new ObjectNodeSection(".managedcode$A", SectionType.Executable); + public static readonly ObjectNodeSection ManagedCodeWindowsContentSection = new ObjectNodeSection(".managedcode$I", SectionType.Executable); + public static readonly ObjectNodeSection ManagedCodeUnixContentSection = new ObjectNodeSection("__managedcode", SectionType.Executable); + public static readonly ObjectNodeSection ManagedCodeEndSection = new ObjectNodeSection(".managedcode$Z", SectionType.Executable); } } diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectWriter.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectWriter.cs index 51b4d546885..76ca4f255ae 100644 --- a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectWriter.cs +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectWriter.cs @@ -21,7 +21,7 @@ namespace ILCompiler.DependencyAnalysis /// /// Object writer using src/Native/ObjWriter /// - internal class ObjectWriter : IDisposable, ITypesDebugInfoWriter + public class ObjectWriter : IDisposable, ITypesDebugInfoWriter { // This is used to build mangled names private Utf8StringBuilder _sb = new Utf8StringBuilder(); @@ -960,27 +960,27 @@ public static void EmitObject(string objectFilePath, IEnumerable ObjectNodeSection managedCodeSection; if (factory.Target.OperatingSystem == TargetOS.Windows) { - managedCodeSection = MethodCodeNode.WindowsContentSection; + managedCodeSection = ObjectNodeSection.ManagedCodeWindowsContentSection; // Emit sentinels for managed code section. ObjectNodeSection codeStartSection = factory.CompilationModuleGroup.IsSingleFileCompilation ? - MethodCodeNode.StartSection : - objectWriter.GetSharedSection(MethodCodeNode.StartSection, "__managedcode_a"); + ObjectNodeSection.ManagedCodeStartSection : + objectWriter.GetSharedSection(ObjectNodeSection.ManagedCodeStartSection, "__managedcode_a"); objectWriter.SetSection(codeStartSection); objectWriter.EmitSymbolDef(new Utf8StringBuilder().Append("__managedcode_a")); objectWriter.EmitIntValue(0, 1); ObjectNodeSection codeEndSection = factory.CompilationModuleGroup.IsSingleFileCompilation ? - MethodCodeNode.EndSection : - objectWriter.GetSharedSection(MethodCodeNode.EndSection, "__managedcode_z"); + ObjectNodeSection.ManagedCodeEndSection : + objectWriter.GetSharedSection(ObjectNodeSection.ManagedCodeEndSection, "__managedcode_z"); objectWriter.SetSection(codeEndSection); objectWriter.EmitSymbolDef(new Utf8StringBuilder().Append("__managedcode_z")); objectWriter.EmitIntValue(1, 1); } else { - managedCodeSection = MethodCodeNode.UnixContentSection; + managedCodeSection = ObjectNodeSection.ManagedCodeUnixContentSection; // TODO 2916: managed code section has to be created here, switch is not necessary. - objectWriter.SetSection(MethodCodeNode.UnixContentSection); + objectWriter.SetSection(ObjectNodeSection.ManagedCodeUnixContentSection); objectWriter.SetSection(LsdaSection); } objectWriter.SetCodeSectionAttribute(managedCodeSection); diff --git a/src/ILCompiler.Compiler/src/Compiler/JitHelper.cs b/src/ILCompiler.Compiler/src/Compiler/JitHelper.cs index e7c15c87bd7..74d919741f5 100644 --- a/src/ILCompiler.Compiler/src/Compiler/JitHelper.cs +++ b/src/ILCompiler.Compiler/src/Compiler/JitHelper.cs @@ -262,7 +262,7 @@ public static void GetEntryPoint(TypeSystemContext context, ReadyToRunHelper id, // public static string GetNewObjectHelperForType(TypeDesc type) { - if (EETypeBuilderHelpers.ComputeRequiresAlign8(type)) + if (type.RequiresAlign8()) { if (type.HasFinalizer) return "RhpNewFinalizableAlign8"; @@ -281,7 +281,7 @@ public static string GetNewObjectHelperForType(TypeDesc type) public static string GetNewArrayHelperForType(TypeDesc type) { - if (EETypeBuilderHelpers.ComputeRequiresAlign8(type)) + if (type.RequiresAlign8()) return "RhpNewArrayAlign8"; return "RhpNewArray"; diff --git a/src/ILCompiler.Compiler/src/Compiler/TypeExtensions.cs b/src/ILCompiler.Compiler/src/Compiler/TypeExtensions.cs index 99b0de66ce9..9e7fd34ee2a 100644 --- a/src/ILCompiler.Compiler/src/Compiler/TypeExtensions.cs +++ b/src/ILCompiler.Compiler/src/Compiler/TypeExtensions.cs @@ -194,5 +194,32 @@ public static bool IsArrayTypeWithoutGenericInterfaces(this TypeDesc type) TypeDesc elementType = arrayType.ElementType; return type.IsMdArray || elementType.IsPointer || elementType.IsFunctionPointer; } + + /// + /// Determines whether an object of type '' requires 8-byte alignment on + /// 32bit ARM architectures. + /// + public static bool RequiresAlign8(this TypeDesc type) + { + if (type.Context.Target.Architecture != TargetArchitecture.ARM) + { + return false; + } + + if (type.IsArray) + { + var elementType = ((ArrayType)type).ElementType; + if ((elementType.IsValueType) && ((DefType)elementType).InstanceByteAlignment.AsInt > 4) + { + return true; + } + } + else if (type.IsDefType && ((DefType)type).InstanceByteAlignment.AsInt > 4) + { + return true; + } + + return false; + } } } diff --git a/src/ILCompiler.Compiler/src/IL/Stubs/PInvokeILProvider.cs b/src/ILCompiler.Compiler/src/IL/Stubs/PInvokeILProvider.cs index 7ae483dbcc4..de4c555661e 100644 --- a/src/ILCompiler.Compiler/src/IL/Stubs/PInvokeILProvider.cs +++ b/src/ILCompiler.Compiler/src/IL/Stubs/PInvokeILProvider.cs @@ -14,7 +14,7 @@ namespace Internal.IL /// Wraps the API and configuration for a particular PInvoke IL emitter. Eventually this will /// allow ILProvider to switch out its PInvoke IL generator with another, such as MCG. /// - class PInvokeILProvider + public class PInvokeILProvider { private readonly PInvokeILEmitterConfiguration _pInvokeILEmitterConfiguration; private readonly InteropStateManager _interopStateManager; diff --git a/src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj b/src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj index c95ef823474..3e41451b8d1 100644 --- a/src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj +++ b/src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj @@ -85,12 +85,6 @@ IL\Stubs\TypeSystemThrowingILEmitter.cs - - JitInterface\JitConfigProvider.cs - - - JitInterface\TypeString.cs - @@ -208,7 +202,6 @@ - @@ -218,7 +211,6 @@ - @@ -233,7 +225,6 @@ - @@ -321,7 +312,6 @@ - @@ -334,8 +324,6 @@ - - @@ -417,6 +405,12 @@ IL\Stubs\UnsafeIntrinsics.cs + + JitInterface\CorInfoTypes.VarInfo.cs + + + JitInterface\MemoryHelper.cs + TypeSystem\TypesDebugInfoWriter\PrimitiveTypeDescriptor.cs @@ -427,22 +421,5 @@ TypeSystem\TypesDebugInfoWriter\DebugInfoWriter.cs - - - JitInterface\CorInfoBase.cs - - - JitInterface\CorInfoHelpFunc.cs - - - JitInterface\CorInfoImpl.cs - - - JitInterface\CorInfoImpl.Intrinsics.cs - - - JitInterface\CorInfoTypes.cs - - diff --git a/src/ILCompiler.Compiler/tests/ILCompiler.Compiler.Tests.csproj b/src/ILCompiler.Compiler/tests/ILCompiler.Compiler.Tests.csproj index 6e2a7f7f4ea..1629287fccd 100644 --- a/src/ILCompiler.Compiler/tests/ILCompiler.Compiler.Tests.csproj +++ b/src/ILCompiler.Compiler/tests/ILCompiler.Compiler.Tests.csproj @@ -16,6 +16,7 @@ + diff --git a/src/ILCompiler.ReadyToRun/src/ILCompiler.ReadyToRun.csproj b/src/ILCompiler.ReadyToRun/src/ILCompiler.ReadyToRun.csproj index 39dc5db1247..7f21188ac5b 100644 --- a/src/ILCompiler.ReadyToRun/src/ILCompiler.ReadyToRun.csproj +++ b/src/ILCompiler.ReadyToRun/src/ILCompiler.ReadyToRun.csproj @@ -6,6 +6,7 @@ ILCompiler.ReadyToRun netstandard1.3 true + READYTORUN @@ -14,6 +15,7 @@ + @@ -45,12 +47,42 @@ + + + + Common\ArrayBuilder.cs + + + + Compiler\JitHelper.cs + + + + IL\HelperExtensions.cs + + + JitInterface\TypeString.cs + + + JitInterface\CorInfoBase.cs + + + JitInterface\CorInfoImpl.cs + + + JitInterface\CorInfoImpl.Intrinsics.cs + + + JitInterface\MemoryHelper.cs + diff --git a/src/ILCompiler.ReadyToRun/src/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/ILCompiler.ReadyToRun/src/JitInterface/CorInfoImpl.ReadyToRun.cs new file mode 100644 index 00000000000..ccca2ef94bb --- /dev/null +++ b/src/ILCompiler.ReadyToRun/src/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics; + +using Internal.TypeSystem; + +using ILCompiler; + +namespace Internal.JitInterface +{ + partial class CorInfoImpl + { + private ReadyToRunCodegenCompilation _compilation; + + public CorInfoImpl(ReadyToRunCodegenCompilation compilation, JitConfigProvider jitConfig) + : this(jitConfig) + { + _compilation = compilation; + } + } +} diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/IMethodCodeNode.cs b/src/ILCompiler.RyuJit/src/Compiler/DependencyAnalysis/IMethodCodeNode.cs similarity index 100% rename from src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/IMethodCodeNode.cs rename to src/ILCompiler.RyuJit/src/Compiler/DependencyAnalysis/IMethodCodeNode.cs diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/MethodCodeNode.cs b/src/ILCompiler.RyuJit/src/Compiler/DependencyAnalysis/MethodCodeNode.cs similarity index 87% rename from src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/MethodCodeNode.cs rename to src/ILCompiler.RyuJit/src/Compiler/DependencyAnalysis/MethodCodeNode.cs index 2ad4dbd547d..6f54d607eaf 100644 --- a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/MethodCodeNode.cs +++ b/src/ILCompiler.RyuJit/src/Compiler/DependencyAnalysis/MethodCodeNode.cs @@ -12,11 +12,6 @@ namespace ILCompiler.DependencyAnalysis { public class MethodCodeNode : ObjectNode, IMethodBodyNode, INodeWithCodeInfo, INodeWithDebugInfo, IMethodCodeNode, ISpecialUnboxThunkNode { - public static readonly ObjectNodeSection StartSection = new ObjectNodeSection(".managedcode$A", SectionType.Executable); - public static readonly ObjectNodeSection WindowsContentSection = new ObjectNodeSection(".managedcode$I", SectionType.Executable); - public static readonly ObjectNodeSection UnixContentSection = new ObjectNodeSection("__managedcode", SectionType.Executable); - public static readonly ObjectNodeSection EndSection = new ObjectNodeSection(".managedcode$Z", SectionType.Executable); - private MethodDesc _method; private ObjectData _methodCode; private FrameInfo[] _frameInfos; @@ -47,7 +42,7 @@ public override ObjectNodeSection Section { get { - return _method.Context.Target.IsWindows ? WindowsContentSection : UnixContentSection; + return _method.Context.Target.IsWindows ? ObjectNodeSection.ManagedCodeWindowsContentSection : ObjectNodeSection.ManagedCodeUnixContentSection; } } @@ -161,9 +156,9 @@ public void InitializeDebugEHClauseInfos(DebugEHClauseInfo[] debugEHClauseInfos) _debugEHClauseInfos = debugEHClauseInfos; } - protected internal override int ClassCode => 788492407; + protected override int ClassCode => 788492407; - protected internal override int CompareToImpl(SortableDependencyNode other, CompilerComparer comparer) + protected override int CompareToImpl(SortableDependencyNode other, CompilerComparer comparer) { return comparer.Compare(_method, ((MethodCodeNode)other)._method); } diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/RyuJitNodeFactory.cs b/src/ILCompiler.RyuJit/src/Compiler/DependencyAnalysis/RyuJitNodeFactory.cs similarity index 100% rename from src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/RyuJitNodeFactory.cs rename to src/ILCompiler.RyuJit/src/Compiler/DependencyAnalysis/RyuJitNodeFactory.cs diff --git a/src/ILCompiler.Compiler/src/Compiler/RyuJitCompilation.cs b/src/ILCompiler.RyuJit/src/Compiler/RyuJitCompilation.cs similarity index 100% rename from src/ILCompiler.Compiler/src/Compiler/RyuJitCompilation.cs rename to src/ILCompiler.RyuJit/src/Compiler/RyuJitCompilation.cs diff --git a/src/ILCompiler.Compiler/src/Compiler/RyuJitCompilationBuilder.cs b/src/ILCompiler.RyuJit/src/Compiler/RyuJitCompilationBuilder.cs similarity index 100% rename from src/ILCompiler.Compiler/src/Compiler/RyuJitCompilationBuilder.cs rename to src/ILCompiler.RyuJit/src/Compiler/RyuJitCompilationBuilder.cs diff --git a/src/ILCompiler.RyuJit/src/ILCompiler.RyuJit.csproj b/src/ILCompiler.RyuJit/src/ILCompiler.RyuJit.csproj new file mode 100644 index 00000000000..18592e4473a --- /dev/null +++ b/src/ILCompiler.RyuJit/src/ILCompiler.RyuJit.csproj @@ -0,0 +1,77 @@ + + + + + Library + ILCompiler + ILCompiler.RyuJit + true + netstandard1.3 + 8002 + $(BaseOutputPath)$(OSPlatformConfig)/tools + + + + + + + + + + + + + + + + + + + + + + Common\ArrayBuilder.cs + + + Common\EEType.Constants.cs + + + Common\FormattingHelpers.cs + + + Compiler\JitHelper.cs + + + IL\HelperExtensions.cs + + + IL\Stubs\TypeSystemThrowingILEmitter.cs + + + JitInterface\JitConfigProvider.cs + + + JitInterface\TypeString.cs + + + JitInterface\CorInfoBase.cs + + + JitInterface\CorInfoHelpFunc.cs + + + JitInterface\CorInfoImpl.cs + + + JitInterface\CorInfoImpl.Intrinsics.cs + + + JitInterface\CorInfoTypes.cs + + + JitInterface\MemoryHelper.cs + + + + + diff --git a/src/ILCompiler.RyuJit/src/JitInterface/CorInfoImpl.RyuJit.cs b/src/ILCompiler.RyuJit/src/JitInterface/CorInfoImpl.RyuJit.cs new file mode 100644 index 00000000000..da09447417b --- /dev/null +++ b/src/ILCompiler.RyuJit/src/JitInterface/CorInfoImpl.RyuJit.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics; + +using Internal.TypeSystem; + +using ILCompiler; + +namespace Internal.JitInterface +{ + partial class CorInfoImpl + { + private Compilation _compilation; + + public CorInfoImpl(Compilation compilation, JitConfigProvider jitConfig) + : this(jitConfig) + { + _compilation = compilation; + } + } +} diff --git a/src/ILCompiler.WebAssembly/src/CodeGen/WebAssemblyObjectWriter.cs b/src/ILCompiler.WebAssembly/src/CodeGen/WebAssemblyObjectWriter.cs index cec8c05635d..aefaa775567 100644 --- a/src/ILCompiler.WebAssembly/src/CodeGen/WebAssemblyObjectWriter.cs +++ b/src/ILCompiler.WebAssembly/src/CodeGen/WebAssemblyObjectWriter.cs @@ -13,7 +13,6 @@ using Internal.Text; using Internal.TypeSystem; using Internal.TypeSystem.TypesDebugInfo; -using Internal.JitInterface; using ObjectData = ILCompiler.DependencyAnalysis.ObjectNode.ObjectData; using LLVMSharp; diff --git a/src/ILCompiler/ILCompiler.sln b/src/ILCompiler/ILCompiler.sln index 10e714c334d..3d57f5cd35a 100644 --- a/src/ILCompiler/ILCompiler.sln +++ b/src/ILCompiler/ILCompiler.sln @@ -31,6 +31,7 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILCompiler.Build.Tasks", "..\ILCompiler.Build.Tasks\src\ILCompiler.Build.Tasks.csproj", "{44DE7F7B-AD73-40EA-87CC-554F2F57C38A}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILCompiler.ReadyToRun", "..\ILCompiler.ReadyToRun\src\ILCompiler.ReadyToRun.csproj", "{5FB7EFC5-2E58-4A65-A611-C9B68CC6A78D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILCompiler.RyuJit", "..\ILCompiler.RyuJit\src\ILCompiler.RyuJit.csproj", "{69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}" EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution @@ -405,6 +406,34 @@ Global {5FB7EFC5-2E58-4A65-A611-C9B68CC6A78D}.Release|x64.Build.0 = Release|x64 {5FB7EFC5-2E58-4A65-A611-C9B68CC6A78D}.Release|x86.ActiveCfg = Release|x86 {5FB7EFC5-2E58-4A65-A611-C9B68CC6A78D}.Release|x86.Build.0 = Release|x86 + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|arm.ActiveCfg = Debug|arm + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|arm.Build.0 = Debug|arm + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|arm64.ActiveCfg = Debug|arm64 + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|arm64.Build.0 = Debug|arm64 + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|armel.ActiveCfg = Debug|Any CPU + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|armel.Build.0 = Debug|Any CPU + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|wasm.ActiveCfg = Debug|Any CPU + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|wasm.Build.0 = Debug|Any CPU + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|x64.ActiveCfg = Debug|x64 + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|x64.Build.0 = Debug|x64 + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|x86.ActiveCfg = Debug|x86 + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Debug|x86.Build.0 = Debug|x86 + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|Any CPU.Build.0 = Release|Any CPU + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|arm.ActiveCfg = Release|arm + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|arm.Build.0 = Release|arm + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|arm64.ActiveCfg = Release|arm64 + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|arm64.Build.0 = Release|arm64 + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|armel.ActiveCfg = Release|Any CPU + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|armel.Build.0 = Release|Any CPU + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|wasm.ActiveCfg = Release|Any CPU + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|wasm.Build.0 = Release|Any CPU + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|x64.ActiveCfg = Release|x64 + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|x64.Build.0 = Release|x64 + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|x86.ActiveCfg = Release|x86 + {69CB6CF1-9B6C-4617-A8B7-F0089CE474FB}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/ILCompiler/desktop/desktop.csproj b/src/ILCompiler/desktop/desktop.csproj index f535af0ff52..c13c30fe3a2 100644 --- a/src/ILCompiler/desktop/desktop.csproj +++ b/src/ILCompiler/desktop/desktop.csproj @@ -88,6 +88,10 @@ {971ae7e7-08c6-48b4-902a-63851e6dac66} ILCompiler.CppCodegen + + {69cb6cf1-9b6c-4617-a8b7-f0089ce474fb} + ILCompiler.RyuJit + {1a9df196-43a9-44bb-b2c6-d62aa56b0e49} ILCompiler.TypeSystem diff --git a/src/ILCompiler/src/ILCompiler.csproj b/src/ILCompiler/src/ILCompiler.csproj index 4f2d845693b..1b98e5c6c8f 100644 --- a/src/ILCompiler/src/ILCompiler.csproj +++ b/src/ILCompiler/src/ILCompiler.csproj @@ -17,6 +17,7 @@ + diff --git a/src/JitInterface/src/CorInfoBase.cs b/src/JitInterface/src/CorInfoBase.cs index f6ae80a13be..f9f78d97aa1 100644 --- a/src/JitInterface/src/CorInfoBase.cs +++ b/src/JitInterface/src/CorInfoBase.cs @@ -9,7 +9,7 @@ namespace Internal.JitInterface { - public unsafe partial class CorInfoImpl + unsafe partial class CorInfoImpl { [UnmanagedFunctionPointerAttribute(default(CallingConvention))] delegate uint __getMethodAttribs(IntPtr _this, IntPtr* ppException, CORINFO_METHOD_STRUCT_* ftn); diff --git a/src/JitInterface/src/CorInfoImpl.Intrinsics.cs b/src/JitInterface/src/CorInfoImpl.Intrinsics.cs index 0385c1a19d3..903ba093c99 100644 --- a/src/JitInterface/src/CorInfoImpl.Intrinsics.cs +++ b/src/JitInterface/src/CorInfoImpl.Intrinsics.cs @@ -9,7 +9,7 @@ namespace Internal.JitInterface { - public unsafe partial class CorInfoImpl + internal unsafe partial class CorInfoImpl { private struct IntrinsicKey { diff --git a/src/JitInterface/src/CorInfoImpl.cs b/src/JitInterface/src/CorInfoImpl.cs index 5834acff5d0..7891e588da6 100644 --- a/src/JitInterface/src/CorInfoImpl.cs +++ b/src/JitInterface/src/CorInfoImpl.cs @@ -29,7 +29,7 @@ namespace Internal.JitInterface { - public unsafe sealed partial class CorInfoImpl + internal unsafe sealed partial class CorInfoImpl { // // Global initialization and state @@ -99,15 +99,13 @@ private IntPtr AllocException(Exception ex) [DllImport("jitinterface")] private extern static char* GetExceptionMessage(IntPtr obj); - private Compilation _compilation; private JitConfigProvider _jitConfig; - public CorInfoImpl(Compilation compilation, JitConfigProvider jitConfig) + public CorInfoImpl(JitConfigProvider jitConfig) { // // Global initialization // - _compilation = compilation; _jitConfig = jitConfig; jitStartup(GetJitHost(_jitConfig.UnmanagedInstance)); diff --git a/src/JitInterface/src/CorInfoTypes.VarInfo.cs b/src/JitInterface/src/CorInfoTypes.VarInfo.cs new file mode 100644 index 00000000000..5dabdf029af --- /dev/null +++ b/src/JitInterface/src/CorInfoTypes.VarInfo.cs @@ -0,0 +1,163 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +// +// The types in this file are referenced directly from ILCompiler.Compiler +// so cannot be easily factored out into ILCompiler.RyuJit until we build +// some sort of abstraction. +// + +namespace Internal.JitInterface +{ + public struct NativeVarInfo + { + public uint startOffset; + public uint endOffset; + public uint varNumber; + public VarLoc varLoc; + }; + + // The following 16 bytes come from coreclr types. See comment below. + [StructLayout(LayoutKind.Sequential)] + public struct VarLoc + { + IntPtr A; // vlType + padding + int B; + int C; + int D; + + /* + Changes to the following types may require revisiting the above layout. + + In coreclr\src\inc\cordebuginfo.h + + enum VarLocType + { + VLT_REG, // variable is in a register + VLT_REG_BYREF, // address of the variable is in a register + VLT_REG_FP, // variable is in an fp register + VLT_STK, // variable is on the stack (memory addressed relative to the frame-pointer) + VLT_STK_BYREF, // address of the variable is on the stack (memory addressed relative to the frame-pointer) + VLT_REG_REG, // variable lives in two registers + VLT_REG_STK, // variable lives partly in a register and partly on the stack + VLT_STK_REG, // reverse of VLT_REG_STK + VLT_STK2, // variable lives in two slots on the stack + VLT_FPSTK, // variable lives on the floating-point stack + VLT_FIXED_VA, // variable is a fixed argument in a varargs function (relative to VARARGS_HANDLE) + + VLT_COUNT, + VLT_INVALID, + #ifdef MDIL + VLT_MDIL_SYMBOLIC = 0x20 + #endif + + }; + + struct VarLoc + { + VarLocType vlType; + + union + { + // VLT_REG/VLT_REG_FP -- Any pointer-sized enregistered value (TYP_INT, TYP_REF, etc) + // eg. EAX + // VLT_REG_BYREF -- the specified register contains the address of the variable + // eg. [EAX] + + struct + { + RegNum vlrReg; + } vlReg; + + // VLT_STK -- Any 32 bit value which is on the stack + // eg. [ESP+0x20], or [EBP-0x28] + // VLT_STK_BYREF -- the specified stack location contains the address of the variable + // eg. mov EAX, [ESP+0x20]; [EAX] + + struct + { + RegNum vlsBaseReg; + signed vlsOffset; + } vlStk; + + // VLT_REG_REG -- TYP_LONG with both DWords enregistred + // eg. RBM_EAXEDX + + struct + { + RegNum vlrrReg1; + RegNum vlrrReg2; + } vlRegReg; + + // VLT_REG_STK -- Partly enregistered TYP_LONG + // eg { LowerDWord=EAX UpperDWord=[ESP+0x8] } + + struct + { + RegNum vlrsReg; + struct + { + RegNum vlrssBaseReg; + signed vlrssOffset; + } vlrsStk; + } vlRegStk; + + // VLT_STK_REG -- Partly enregistered TYP_LONG + // eg { LowerDWord=[ESP+0x8] UpperDWord=EAX } + + struct + { + struct + { + RegNum vlsrsBaseReg; + signed vlsrsOffset; + } vlsrStk; + RegNum vlsrReg; + } vlStkReg; + + // VLT_STK2 -- Any 64 bit value which is on the stack, + // in 2 successsive DWords. + // eg 2 DWords at [ESP+0x10] + + struct + { + RegNum vls2BaseReg; + signed vls2Offset; + } vlStk2; + + // VLT_FPSTK -- enregisterd TYP_DOUBLE (on the FP stack) + // eg. ST(3). Actually it is ST("FPstkHeigth - vpFpStk") + + struct + { + unsigned vlfReg; + } vlFPstk; + + // VLT_FIXED_VA -- fixed argument of a varargs function. + // The argument location depends on the size of the variable + // arguments (...). Inspecting the VARARGS_HANDLE indicates the + // location of the first arg. This argument can then be accessed + // relative to the position of the first arg + + struct + { + unsigned vlfvOffset; + } vlFixedVarArg; + + // VLT_MEMORY + + struct + { + void *rpValue; // pointer to the in-process + // location of the value. + } vlMemory; + }; + }; + */ + }; +} diff --git a/src/JitInterface/src/CorInfoTypes.cs b/src/JitInterface/src/CorInfoTypes.cs index 6d0662be50b..3e212469425 100644 --- a/src/JitInterface/src/CorInfoTypes.cs +++ b/src/JitInterface/src/CorInfoTypes.cs @@ -432,7 +432,7 @@ public enum CorInfoOptions CORINFO_GENERICS_CTXT_KEEP_ALIVE = 0x00000100, // Keep the generics context alive throughout the method even if there is no explicit use, and report its location to the CLR } - internal enum CorInfoIntrinsics + public enum CorInfoIntrinsics { CORINFO_INTRINSIC_Sin, CORINFO_INTRINSIC_Cos, @@ -598,7 +598,7 @@ public enum CORINFO_ACCESS_FLAGS // these are the attribute flags for fields and methods (getMethodAttribs) [Flags] - internal enum CorInfoFlag : uint + public enum CorInfoFlag : uint { // CORINFO_FLG_UNUSED = 0x00000001, // CORINFO_FLG_UNUSED = 0x00000002, @@ -1251,154 +1251,6 @@ public struct ILVarInfo public uint varNumber; }; - public struct NativeVarInfo - { - public uint startOffset; - public uint endOffset; - public uint varNumber; - public VarLoc varLoc; - }; - - // The following 16 bytes come from coreclr types. See comment below. - [StructLayout(LayoutKind.Sequential)] - public struct VarLoc - { - IntPtr A; // vlType + padding - int B; - int C; - int D; - - /* - Changes to the following types may require revisiting the above layout. - - In coreclr\src\inc\cordebuginfo.h - - enum VarLocType - { - VLT_REG, // variable is in a register - VLT_REG_BYREF, // address of the variable is in a register - VLT_REG_FP, // variable is in an fp register - VLT_STK, // variable is on the stack (memory addressed relative to the frame-pointer) - VLT_STK_BYREF, // address of the variable is on the stack (memory addressed relative to the frame-pointer) - VLT_REG_REG, // variable lives in two registers - VLT_REG_STK, // variable lives partly in a register and partly on the stack - VLT_STK_REG, // reverse of VLT_REG_STK - VLT_STK2, // variable lives in two slots on the stack - VLT_FPSTK, // variable lives on the floating-point stack - VLT_FIXED_VA, // variable is a fixed argument in a varargs function (relative to VARARGS_HANDLE) - - VLT_COUNT, - VLT_INVALID, - #ifdef MDIL - VLT_MDIL_SYMBOLIC = 0x20 - #endif - - }; - - struct VarLoc - { - VarLocType vlType; - - union - { - // VLT_REG/VLT_REG_FP -- Any pointer-sized enregistered value (TYP_INT, TYP_REF, etc) - // eg. EAX - // VLT_REG_BYREF -- the specified register contains the address of the variable - // eg. [EAX] - - struct - { - RegNum vlrReg; - } vlReg; - - // VLT_STK -- Any 32 bit value which is on the stack - // eg. [ESP+0x20], or [EBP-0x28] - // VLT_STK_BYREF -- the specified stack location contains the address of the variable - // eg. mov EAX, [ESP+0x20]; [EAX] - - struct - { - RegNum vlsBaseReg; - signed vlsOffset; - } vlStk; - - // VLT_REG_REG -- TYP_LONG with both DWords enregistred - // eg. RBM_EAXEDX - - struct - { - RegNum vlrrReg1; - RegNum vlrrReg2; - } vlRegReg; - - // VLT_REG_STK -- Partly enregistered TYP_LONG - // eg { LowerDWord=EAX UpperDWord=[ESP+0x8] } - - struct - { - RegNum vlrsReg; - struct - { - RegNum vlrssBaseReg; - signed vlrssOffset; - } vlrsStk; - } vlRegStk; - - // VLT_STK_REG -- Partly enregistered TYP_LONG - // eg { LowerDWord=[ESP+0x8] UpperDWord=EAX } - - struct - { - struct - { - RegNum vlsrsBaseReg; - signed vlsrsOffset; - } vlsrStk; - RegNum vlsrReg; - } vlStkReg; - - // VLT_STK2 -- Any 64 bit value which is on the stack, - // in 2 successsive DWords. - // eg 2 DWords at [ESP+0x10] - - struct - { - RegNum vls2BaseReg; - signed vls2Offset; - } vlStk2; - - // VLT_FPSTK -- enregisterd TYP_DOUBLE (on the FP stack) - // eg. ST(3). Actually it is ST("FPstkHeigth - vpFpStk") - - struct - { - unsigned vlfReg; - } vlFPstk; - - // VLT_FIXED_VA -- fixed argument of a varargs function. - // The argument location depends on the size of the variable - // arguments (...). Inspecting the VARARGS_HANDLE indicates the - // location of the first arg. This argument can then be accessed - // relative to the position of the first arg - - struct - { - unsigned vlfvOffset; - } vlFixedVarArg; - - // VLT_MEMORY - - struct - { - void *rpValue; // pointer to the in-process - // location of the value. - } vlMemory; - }; - }; - */ - }; - - // This enum is used for JIT to tell EE where this token comes from. // E.g. Depending on different opcodes, we might allow/disallow certain types of tokens or // return different types of handles (e.g. boxed vs. regular entrypoints) diff --git a/src/ILCompiler.Compiler/src/Compiler/MemoryHelper.cs b/src/JitInterface/src/MemoryHelper.cs similarity index 80% rename from src/ILCompiler.Compiler/src/Compiler/MemoryHelper.cs rename to src/JitInterface/src/MemoryHelper.cs index a5632d00093..a9647f37fa7 100644 --- a/src/ILCompiler.Compiler/src/Compiler/MemoryHelper.cs +++ b/src/JitInterface/src/MemoryHelper.cs @@ -3,12 +3,8 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace ILCompiler +namespace Internal.JitInterface { internal static unsafe class MemoryHelper { diff --git a/src/System.Private.Jit/src/System.Private.Jit.csproj b/src/System.Private.Jit/src/System.Private.Jit.csproj index 39cb058ccf8..85b9175aa92 100644 --- a/src/System.Private.Jit/src/System.Private.Jit.csproj +++ b/src/System.Private.Jit/src/System.Private.Jit.csproj @@ -39,6 +39,7 @@ ..\..\System.Private.TypeLoader\src ..\..\Common\src ..\..\ILCompiler.Compiler\src + ..\..\ILCompiler.RyuJit\src ..\..\ILCompiler.DependencyAnalysisFramework\src ..\..\JitInterface\src @@ -117,7 +118,6 @@ - @@ -132,13 +132,14 @@ - + + @@ -147,7 +148,9 @@ + +