diff --git a/src/ILCompiler.ReadyToRun/src/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs b/src/ILCompiler.ReadyToRun/src/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs index 4a0a8c81042..4aefacd5f36 100644 --- a/src/ILCompiler.ReadyToRun/src/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs +++ b/src/ILCompiler.ReadyToRun/src/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs @@ -7,26 +7,20 @@ using System.Diagnostics; using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; -using System.Reflection.PortableExecutable; - using ILCompiler.DependencyAnalysis.ReadyToRun; using ILCompiler.DependencyAnalysisFramework; using Internal.JitInterface; using Internal.TypeSystem; -using Internal.TypeSystem.Ecma; namespace ILCompiler.DependencyAnalysis { - using System.Collections.Immutable; using ReadyToRunHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper; public sealed class ReadyToRunCodegenNodeFactory : NodeFactory { private Dictionary _importMethods; - private Dictionary _importStrings; - public ReadyToRunCodegenNodeFactory( CompilerTypeSystemContext context, CompilationModuleGroup compilationModuleGroup, @@ -48,8 +42,6 @@ public ReadyToRunCodegenNodeFactory( new ImportedNodeProviderThrowing()) { _importMethods = new Dictionary(); - _importStrings = new Dictionary(); - _r2rHelpers = new Dictionary>(); Resolver = moduleTokenResolver; InputModuleContext = signatureContext; @@ -93,6 +85,23 @@ public ReadyToRunCodegenNodeFactory( public ImportSectionNode PrecodeImports; + private readonly Dictionary _constructedHelpers = new Dictionary(); + + public ISymbolNode GetReadyToRunHelperCell(ReadyToRunHelper helperId) + { + if (!_constructedHelpers.TryGetValue(helperId, out ISymbolNode helperCell)) + { + helperCell = CreateReadyToRunHelperCell(helperId); + _constructedHelpers.Add(helperId, helperCell); + } + return helperCell; + } + + private ISymbolNode CreateReadyToRunHelperCell(ReadyToRunHelper helperId) + { + return new Import(EagerImports, new ReadyToRunHelperSignature(helperId)); + } + public IMethodNode MethodEntrypoint(MethodDesc targetMethod, TypeDesc constrainedType, MethodDesc originalMethod, SignatureContext signatureContext, bool isUnboxingStub = false) { return _methodEntrypoints.GetOrAdd(targetMethod, (m) => @@ -136,17 +145,6 @@ public IMethodNode StringAllocator(MethodDesc constructor, SignatureContext sign return MethodEntrypoint(constructor, constrainedType: null, originalMethod: null, signatureContext: signatureContext, isUnboxingStub: false); } - public ISymbolNode StringLiteral(ModuleToken token) - { - ISymbolNode stringNode; - if (!_importStrings.TryGetValue(token, out stringNode)) - { - stringNode = new StringImport(StringImports, token); - _importStrings.Add(token, stringNode); - } - return stringNode; - } - protected override ISymbolNode CreateReadyToRunHelperNode(ReadyToRunHelperKey helperCall) { throw new NotImplementedException(); @@ -158,141 +156,6 @@ public bool CanInline(MethodDesc callerMethod, MethodDesc calleeMethod) return CompilationModuleGroup.ContainsMethodBody(calleeMethod, unboxingStub: false); } - private readonly Dictionary> _r2rHelpers; - - public ISymbolNode ReadyToRunHelper(ReadyToRunHelperId id, object target, SignatureContext signatureContext) - { - if (id == ReadyToRunHelperId.NecessaryTypeHandle) - { - // We treat TypeHandle and NecessaryTypeHandle the same - don't emit two copies of the same import - id = ReadyToRunHelperId.TypeHandle; - } - - Dictionary helperNodeMap; - if (!_r2rHelpers.TryGetValue(id, out helperNodeMap)) - { - helperNodeMap = new Dictionary(); - _r2rHelpers.Add(id, helperNodeMap); - } - - ISymbolNode helperNode; - if (helperNodeMap.TryGetValue(target, out helperNode)) - { - return helperNode; - } - - switch (id) - { - case ReadyToRunHelperId.NewHelper: - helperNode = CreateNewHelper((TypeDesc)target, signatureContext); - break; - - case ReadyToRunHelperId.NewArr1: - helperNode = CreateNewArrayHelper((ArrayType)target, signatureContext); - break; - - case ReadyToRunHelperId.GetGCStaticBase: - helperNode = CreateGCStaticBaseHelper((TypeDesc)target, signatureContext); - break; - - case ReadyToRunHelperId.GetNonGCStaticBase: - helperNode = CreateNonGCStaticBaseHelper((TypeDesc)target, signatureContext); - break; - - case ReadyToRunHelperId.GetThreadStaticBase: - helperNode = CreateThreadGcStaticBaseHelper((TypeDesc)target, signatureContext); - break; - - case ReadyToRunHelperId.GetThreadNonGcStaticBase: - helperNode = CreateThreadNonGcStaticBaseHelper((TypeDesc)target, signatureContext); - break; - - case ReadyToRunHelperId.IsInstanceOf: - helperNode = CreateIsInstanceOfHelper((TypeDesc)target, signatureContext); - break; - - case ReadyToRunHelperId.CastClass: - helperNode = CreateCastClassHelper((TypeDesc)target, signatureContext); - break; - - case ReadyToRunHelperId.TypeHandle: - helperNode = CreateTypeHandleHelper((TypeDesc)target, signatureContext); - break; - - case ReadyToRunHelperId.FieldHandle: - helperNode = CreateFieldHandleHelper((FieldDesc)target, signatureContext); - break; - - case ReadyToRunHelperId.VirtualCall: - helperNode = CreateVirtualCallHelper((MethodDesc)target, signatureContext); - break; - - case ReadyToRunHelperId.DelegateCtor: - helperNode = CreateDelegateCtorHelper((DelegateCreationInfo)target, signatureContext); - break; - - default: - throw new NotImplementedException(); - } - - helperNodeMap.Add(target, helperNode); - return helperNode; - } - - private ISymbolNode CreateNewHelper(TypeDesc type, SignatureContext signatureContext) - { - return new DelayLoadHelperImport( - this, - HelperImports, - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, - new NewObjectFixupSignature(type, signatureContext)); - } - - private ISymbolNode CreateNewArrayHelper(ArrayType type, SignatureContext signatureContext) - { - return new DelayLoadHelperImport( - this, - HelperImports, - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, - new NewArrayFixupSignature(type, signatureContext)); - } - - private ISymbolNode CreateGCStaticBaseHelper(TypeDesc type, SignatureContext signatureContext) - { - return new DelayLoadHelperImport( - this, - HelperImports, - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, - new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_StaticBaseGC, type, signatureContext)); - } - - private ISymbolNode CreateNonGCStaticBaseHelper(TypeDesc type, SignatureContext signatureContext) - { - return new DelayLoadHelperImport( - this, - HelperImports, - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, - new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_StaticBaseNonGC, type, signatureContext)); - } - - private ISymbolNode CreateThreadGcStaticBaseHelper(TypeDesc type, SignatureContext signatureContext) - { - return new DelayLoadHelperImport( - this, - HelperImports, - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, - new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_ThreadStaticBaseGC, type, signatureContext)); - } - - private ISymbolNode CreateThreadNonGcStaticBaseHelper(TypeDesc type, SignatureContext signatureContext) - { - return new DelayLoadHelperImport( - this, - HelperImports, - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, - new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_ThreadStaticBaseNonGC, type, signatureContext)); - } - private ModuleToken GetTypeToken(ModuleToken token) { if (token.IsNull) @@ -340,536 +203,12 @@ private ModuleToken GetTypeToken(ModuleToken token) return typeToken; } - private ISymbolNode CreateIsInstanceOfHelper(TypeDesc type, SignatureContext signatureContext) - { - return new DelayLoadHelperImport( - this, - HelperImports, - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, - new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_IsInstanceOf, type, signatureContext)); - } - - private ISymbolNode CreateCastClassHelper(TypeDesc type, SignatureContext signatureContext) - { - return new DelayLoadHelperImport( - this, - HelperImports, - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper_Obj, - new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_ChkCast, type, signatureContext)); - } - - private ISymbolNode CreateTypeHandleHelper(TypeDesc type, SignatureContext signatureContext) - { - return new PrecodeHelperImport( - this, - new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_TypeHandle, type, signatureContext)); - } - - private ISymbolNode CreateFieldHandleHelper(FieldDesc field, SignatureContext signatureContext) - { - return new PrecodeHelperImport( - this, - new FieldFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_FieldHandle, field, signatureContext)); - } - - private ISymbolNode CreateVirtualCallHelper(MethodDesc method, SignatureContext signatureContext) - { - return new DelayLoadHelperImport( - this, - DispatchImports, - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper_Obj, - MethodSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_VirtualEntry, method, - constrainedType: null, signatureContext: signatureContext, isUnboxingStub: false, isInstantiatingStub: false)); - } - - private ISymbolNode CreateDelegateCtorHelper(DelegateCreationInfo info, SignatureContext signatureContext) - { - return info.Constructor; - } - - Dictionary _helperCache = new Dictionary(); - - public ISymbolNode ExternSymbol(ILCompiler.ReadyToRunHelper helper) - { - ISymbolNode result; - if (_helperCache.TryGetValue(helper, out result)) - { - return result; - } - - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper r2rHelper; - switch (helper) - { - // Exception handling helpers - case ILCompiler.ReadyToRunHelper.Throw: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Throw; - break; - - case ILCompiler.ReadyToRunHelper.Rethrow: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Rethrow; - break; - - case ILCompiler.ReadyToRunHelper.Overflow: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Overflow; - break; - - case ILCompiler.ReadyToRunHelper.RngChkFail: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_RngChkFail; - break; - - case ILCompiler.ReadyToRunHelper.FailFast: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_FailFast; - break; - - case ILCompiler.ReadyToRunHelper.ThrowNullRef: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ThrowNullRef; - break; - - case ILCompiler.ReadyToRunHelper.ThrowDivZero: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ThrowDivZero; - break; - - // Write barriers - case ILCompiler.ReadyToRunHelper.WriteBarrier: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier; - break; - - case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier; - break; - - case ILCompiler.ReadyToRunHelper.ByRefWriteBarrier: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ByRefWriteBarrier; - break; - - // Array helpers - case ILCompiler.ReadyToRunHelper.Stelem_Ref: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Stelem_Ref; - break; - - case ILCompiler.ReadyToRunHelper.Ldelema_Ref: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Ldelema_Ref; - break; - - case ILCompiler.ReadyToRunHelper.MemSet: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_MemSet; - break; - - case ILCompiler.ReadyToRunHelper.MemCpy: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_MemCpy; - break; - - // Get string handle lazily - case ILCompiler.ReadyToRunHelper.GetString: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GetString; - break; - - // Reflection helpers - case ILCompiler.ReadyToRunHelper.GetRuntimeTypeHandle: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GetRuntimeTypeHandle; - break; - - case ILCompiler.ReadyToRunHelper.GetRuntimeMethodHandle: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GetRuntimeMethodHandle; - break; - - case ILCompiler.ReadyToRunHelper.GetRuntimeFieldHandle: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GetRuntimeFieldHandle; - break; - - case ILCompiler.ReadyToRunHelper.Box: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Box; - break; - - case ILCompiler.ReadyToRunHelper.Box_Nullable: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Box_Nullable; - break; - - case ILCompiler.ReadyToRunHelper.Unbox: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Unbox; - break; - - case ILCompiler.ReadyToRunHelper.Unbox_Nullable: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Unbox_Nullable; - break; - - case ILCompiler.ReadyToRunHelper.NewMultiDimArr: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_NewMultiDimArr; - break; - - case ILCompiler.ReadyToRunHelper.NewMultiDimArr_NonVarArg: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_NewMultiDimArr_NonVarArg; - break; - - // Helpers used with generic handle lookup cases - case ILCompiler.ReadyToRunHelper.NewObject: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_NewObject; - break; - - case ILCompiler.ReadyToRunHelper.NewArray: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_NewArray; - break; - - case ILCompiler.ReadyToRunHelper.CheckCastAny: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckCastAny; - break; - - case ILCompiler.ReadyToRunHelper.CheckInstanceAny: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckInstanceAny; - break; - - case ILCompiler.ReadyToRunHelper.GenericGcStaticBase: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GenericGcStaticBase; - break; - - case ILCompiler.ReadyToRunHelper.GenericNonGcStaticBase: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GenericNonGcStaticBase; - break; - - case ILCompiler.ReadyToRunHelper.GenericGcTlsBase: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GenericGcTlsBase; - break; - - case ILCompiler.ReadyToRunHelper.GenericNonGcTlsBase: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GenericNonGcTlsBase; - break; - - case ILCompiler.ReadyToRunHelper.VirtualFuncPtr: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_VirtualFuncPtr; - break; - - // Long mul/div/shift ops - case ILCompiler.ReadyToRunHelper.LMul: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LMul; - break; - - case ILCompiler.ReadyToRunHelper.LMulOfv: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LMulOfv; - break; - - case ILCompiler.ReadyToRunHelper.ULMulOvf: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ULMulOvf; - break; - - case ILCompiler.ReadyToRunHelper.LDiv: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LDiv; - break; - - case ILCompiler.ReadyToRunHelper.LMod: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LMod; - break; - - case ILCompiler.ReadyToRunHelper.ULDiv: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ULDiv; - break; - - case ILCompiler.ReadyToRunHelper.ULMod: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ULMod; - break; - - case ILCompiler.ReadyToRunHelper.LLsh: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LLsh; - break; - - case ILCompiler.ReadyToRunHelper.LRsh: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LRsh; - break; - - case ILCompiler.ReadyToRunHelper.LRsz: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LRsz; - break; - - case ILCompiler.ReadyToRunHelper.Lng2Dbl: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Lng2Dbl; - break; - - case ILCompiler.ReadyToRunHelper.ULng2Dbl: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ULng2Dbl; - break; - - // 32-bit division helpers - case ILCompiler.ReadyToRunHelper.Div: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Div; - break; - - case ILCompiler.ReadyToRunHelper.Mod: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Mod; - break; - - case ILCompiler.ReadyToRunHelper.UDiv: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_UDiv; - break; - - case ILCompiler.ReadyToRunHelper.UMod: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_UMod; - break; - - // Floating point conversions - case ILCompiler.ReadyToRunHelper.Dbl2Int: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2Int; - break; - - case ILCompiler.ReadyToRunHelper.Dbl2IntOvf: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2IntOvf; - break; - - case ILCompiler.ReadyToRunHelper.Dbl2Lng: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2Lng; - break; - - case ILCompiler.ReadyToRunHelper.Dbl2LngOvf: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2LngOvf; - break; - - case ILCompiler.ReadyToRunHelper.Dbl2UInt: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2UInt; - break; - - case ILCompiler.ReadyToRunHelper.Dbl2UIntOvf: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2UIntOvf; - break; - - case ILCompiler.ReadyToRunHelper.Dbl2ULng: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2ULng; - break; - - case ILCompiler.ReadyToRunHelper.Dbl2ULngOvf: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2ULngOvf; - break; - - // Floating point ops - case ILCompiler.ReadyToRunHelper.DblRem: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DblRem; - break; - - case ILCompiler.ReadyToRunHelper.FltRem: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_FltRem; - break; - - case ILCompiler.ReadyToRunHelper.DblRound: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DblRound; - break; - - case ILCompiler.ReadyToRunHelper.FltRound: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_FltRound; - break; - - case ILCompiler.ReadyToRunHelper.GetRefAny: - // TODO-PERF: currently not implemented in Crossgen - ThrowHelper.ThrowInvalidProgramException(); - // ThrowInvalidProgramException should never return - throw new NotImplementedException(); - - // JIT32 x86-specific write barriers - case ILCompiler.ReadyToRunHelper.WriteBarrier_EAX: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier_EAX; - break; - - case ILCompiler.ReadyToRunHelper.WriteBarrier_EBX: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier_EBX; - break; - - case ILCompiler.ReadyToRunHelper.WriteBarrier_ECX: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier_ECX; - break; - - case ILCompiler.ReadyToRunHelper.WriteBarrier_ESI: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier_ESI; - break; - - case ILCompiler.ReadyToRunHelper.WriteBarrier_EDI: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier_EDI; - break; - - case ILCompiler.ReadyToRunHelper.WriteBarrier_EBP: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier_EBP; - break; - - case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier_EAX: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier_EAX; - break; - - case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier_EBX: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier_EBX; - break; - - case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier_ECX: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier_ECX; - break; - - case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier_ESI: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier_ESI; - break; - - case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier_EDI: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier_EDI; - break; - - case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier_EBP: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier_EBP; - break; - - case ILCompiler.ReadyToRunHelper.EndCatch: - r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_EndCatch; - break; - - default: - throw new NotImplementedException(helper.ToString()); - } - - result = GetReadyToRunHelperCell(r2rHelper); - _helperCache.Add(helper, result); - return result; - } - - public ISymbolNode HelperMethodEntrypoint(ILCompiler.ReadyToRunHelper helperId, MethodDesc method) - { - return ExternSymbol(helperId); - } - public IMethodNode CreateUnboxingStubNode(MethodDesc method, mdToken token) { throw new NotImplementedException(); } - struct MethodAndCallSite : IEquatable - { - public readonly MethodDesc Method; - public readonly string CallSite; - - public MethodAndCallSite(MethodDesc method, string callSite) - { - CallSite = callSite; - Method = method; - } - - public bool Equals(MethodAndCallSite other) - { - return CallSite == other.CallSite && Method == other.Method; - } - - public override bool Equals(object obj) - { - return obj is MethodAndCallSite other && Equals(other); - } - - public override int GetHashCode() - { - return (CallSite != null ? CallSite.GetHashCode() : 0) + unchecked(31 * Method.GetHashCode()); - } - } - - Dictionary _interfaceDispatchCells = new Dictionary(); - - public ISymbolNode InterfaceDispatchCell(MethodDesc method, SignatureContext signatureContext, bool isUnboxingStub, string callSite) - { - MethodAndCallSite cellKey = new MethodAndCallSite(method, callSite); - ISymbolNode dispatchCell; - if (!_interfaceDispatchCells.TryGetValue(cellKey, out dispatchCell)) - { - dispatchCell = new DelayLoadHelperImport( - this, - DispatchImports, - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_MethodCall | - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_FLAG_VSD, - MethodSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_VirtualEntry, method, - constrainedType: null, signatureContext: signatureContext, isUnboxingStub, isInstantiatingStub: false), - callSite); - - _interfaceDispatchCells.Add(cellKey, dispatchCell); - } - return dispatchCell; - } - - private Dictionary _constructedHelpers = new Dictionary(); - - public ISymbolNode GetReadyToRunHelperCell(ReadyToRunHelper helperId) - { - ISymbolNode helperCell; - if (!_constructedHelpers.TryGetValue(helperId, out helperCell)) - { - helperCell = CreateReadyToRunHelperCell(helperId); - _constructedHelpers.Add(helperId, helperCell); - } - return helperCell; - } - - private ISymbolNode CreateReadyToRunHelperCell(ReadyToRunHelper helperId) - { - return new Import(EagerImports, new ReadyToRunHelperSignature(helperId)); - } - - public ISymbolNode ComputeConstantLookup(ReadyToRunHelperId helperId, object entity, SignatureContext signatureContext) - { - return ReadyToRunHelper(helperId, entity, signatureContext); - } - - Dictionary _genericDictionaryCache = new Dictionary(); - - public ISortableSymbolNode MethodGenericDictionary(MethodDesc method, SignatureContext signatureContext) - { - ISortableSymbolNode genericDictionary; - if (!_genericDictionaryCache.TryGetValue(method, out genericDictionary)) - { - genericDictionary = new PrecodeHelperImport( - this, - MethodSignature( - ReadyToRunFixupKind.READYTORUN_FIXUP_MethodDictionary, - method, - constrainedType: null, - signatureContext: signatureContext, - isUnboxingStub: false, - isInstantiatingStub: true)); - _genericDictionaryCache.Add(method, genericDictionary); - } - return genericDictionary; - } - - Dictionary _constructedTypeSymbols = new Dictionary(); - - public ISymbolNode ConstructedTypeSymbol(TypeDesc type, SignatureContext signatureContext) - { - ISymbolNode symbol; - if (!_constructedTypeSymbols.TryGetValue(type, out symbol)) - { - symbol = new PrecodeHelperImport( - this, - new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_TypeDictionary, type, signatureContext)); - _constructedTypeSymbols.Add(type, symbol); - } - return symbol; - } - - struct MethodAndFixupKind : IEquatable - { - public readonly MethodDesc Method; - public readonly bool IsUnboxingStub; - public readonly ReadyToRunFixupKind FixupKind; - - public MethodAndFixupKind(MethodDesc method, bool isUnboxingStub, ReadyToRunFixupKind fixupKind) - { - Method = method; - IsUnboxingStub = isUnboxingStub; - FixupKind = fixupKind; - } - - public bool Equals(MethodAndFixupKind other) - { - return Method == other.Method && IsUnboxingStub == other.IsUnboxingStub && FixupKind == other.FixupKind; - } - - public override bool Equals(object obj) - { - return obj is MethodAndFixupKind other && Equals(other); - } - - public override int GetHashCode() - { - return (int)Method.GetHashCode() ^ unchecked(31 * (int)FixupKind) ^ (IsUnboxingStub ? -0x80000000 : 0); - } - } - - Dictionary> _methodSignatures = + private readonly Dictionary> _methodSignatures = new Dictionary>(); public MethodFixupSignature MethodSignature( @@ -1031,7 +370,7 @@ public IMethodNode ImportedMethodNode(MethodDesc method, TypeDesc constrainedTyp return methodImport; } - Dictionary _instantiatedMethodImports = new Dictionary(); + private readonly Dictionary _instantiatedMethodImports = new Dictionary(); private IMethodNode InstantiatedMethodNode(InstantiatedMethod method, TypeDesc constrainedType, SignatureContext signatureContext, bool isUnboxingStub) { @@ -1107,59 +446,6 @@ protected override IMethodNode CreateMethodEntrypointNode(MethodDesc method) protected override IMethodNode CreateUnboxingStubNode(MethodDesc method) { throw new NotImplementedException(); - } - - struct TypeAndMethod : IEquatable - { - public readonly TypeDesc Type; - public readonly MethodDesc Method; - public readonly bool IsUnboxingStub; - public readonly bool IsInstantiatingStub; - - public TypeAndMethod(TypeDesc type, MethodDesc method, bool isUnboxingStub, bool isInstantiatingStub) - { - Type = type; - Method = method; - IsUnboxingStub = isUnboxingStub; - IsInstantiatingStub = isInstantiatingStub; - } - - public bool Equals(TypeAndMethod other) - { - return Type == other.Type && - Method == other.Method && - IsUnboxingStub == other.IsUnboxingStub && - IsInstantiatingStub == other.IsInstantiatingStub; - } - - public override bool Equals(object obj) - { - return obj is TypeAndMethod other && Equals(other); - } - - public override int GetHashCode() - { - return (Type?.GetHashCode() ?? 0) ^ unchecked(Method.GetHashCode() * 31) ^ (IsUnboxingStub ? -0x80000000 : 0) ^ (IsInstantiatingStub ? 0x40000000 : 0); - } - } - - private Dictionary _delegateCtors = new Dictionary(); - - public ISymbolNode DelegateCtor(TypeDesc delegateType, MethodDesc targetMethod, SignatureContext signatureContext) - { - ISymbolNode ctorNode; - TypeAndMethod ctorKey = new TypeAndMethod(delegateType, targetMethod, isUnboxingStub: false, isInstantiatingStub: false); - if (!_delegateCtors.TryGetValue(ctorKey, out ctorNode)) - { - IMethodNode targetMethodNode = MethodEntrypoint(targetMethod, constrainedType: null, originalMethod: null, signatureContext: signatureContext, isUnboxingStub: false); - ctorNode = new DelayLoadHelperImport( - this, - HelperImports, - ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, - new DelegateCtorSignature(delegateType, targetMethodNode, signatureContext)); - _delegateCtors.Add(ctorKey, ctorNode); - } - return ctorNode; - } + } } } diff --git a/src/ILCompiler.ReadyToRun/src/Compiler/DependencyAnalysis/ReadyToRunSymbolNodeFactory.cs b/src/ILCompiler.ReadyToRun/src/Compiler/DependencyAnalysis/ReadyToRunSymbolNodeFactory.cs new file mode 100644 index 00000000000..9d6a1f92dcc --- /dev/null +++ b/src/ILCompiler.ReadyToRun/src/Compiler/DependencyAnalysis/ReadyToRunSymbolNodeFactory.cs @@ -0,0 +1,648 @@ +// 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.Collections.Generic; +using ILCompiler.DependencyAnalysis.ReadyToRun; +using Internal.TypeSystem; + +namespace ILCompiler.DependencyAnalysis +{ + using ReadyToRunHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper; + + public sealed class ReadyToRunSymbolNodeFactory + { + private readonly ReadyToRunCodegenNodeFactory _codegenNodeFactory; + + public ReadyToRunSymbolNodeFactory(ReadyToRunCodegenNodeFactory codegenNodeFactory) + { + _codegenNodeFactory = codegenNodeFactory; + } + + private readonly Dictionary _importStrings = new Dictionary(); + + public ISymbolNode StringLiteral(ModuleToken token) + { + if (!_importStrings.TryGetValue(token, out ISymbolNode stringNode)) + { + stringNode = new StringImport(_codegenNodeFactory.StringImports, token); + _importStrings.Add(token, stringNode); + } + return stringNode; + } + + private readonly Dictionary> _r2rHelpers = new Dictionary>(); + + public ISymbolNode ReadyToRunHelper(ReadyToRunHelperId id, object target, SignatureContext signatureContext) + { + if (id == ReadyToRunHelperId.NecessaryTypeHandle) + { + // We treat TypeHandle and NecessaryTypeHandle the same - don't emit two copies of the same import + id = ReadyToRunHelperId.TypeHandle; + } + + if (!_r2rHelpers.TryGetValue(id, out Dictionary helperNodeMap)) + { + helperNodeMap = new Dictionary(); + _r2rHelpers.Add(id, helperNodeMap); + } + + if (helperNodeMap.TryGetValue(target, out ISymbolNode helperNode)) + { + return helperNode; + } + + switch (id) + { + case ReadyToRunHelperId.NewHelper: + helperNode = CreateNewHelper((TypeDesc)target, signatureContext); + break; + + case ReadyToRunHelperId.NewArr1: + helperNode = CreateNewArrayHelper((ArrayType)target, signatureContext); + break; + + case ReadyToRunHelperId.GetGCStaticBase: + helperNode = CreateGCStaticBaseHelper((TypeDesc)target, signatureContext); + break; + + case ReadyToRunHelperId.GetNonGCStaticBase: + helperNode = CreateNonGCStaticBaseHelper((TypeDesc)target, signatureContext); + break; + + case ReadyToRunHelperId.GetThreadStaticBase: + helperNode = CreateThreadGcStaticBaseHelper((TypeDesc)target, signatureContext); + break; + + case ReadyToRunHelperId.GetThreadNonGcStaticBase: + helperNode = CreateThreadNonGcStaticBaseHelper((TypeDesc)target, signatureContext); + break; + + case ReadyToRunHelperId.IsInstanceOf: + helperNode = CreateIsInstanceOfHelper((TypeDesc)target, signatureContext); + break; + + case ReadyToRunHelperId.CastClass: + helperNode = CreateCastClassHelper((TypeDesc)target, signatureContext); + break; + + case ReadyToRunHelperId.TypeHandle: + helperNode = CreateTypeHandleHelper((TypeDesc)target, signatureContext); + break; + + case ReadyToRunHelperId.FieldHandle: + helperNode = CreateFieldHandleHelper((FieldDesc)target, signatureContext); + break; + + case ReadyToRunHelperId.VirtualCall: + helperNode = CreateVirtualCallHelper((MethodDesc)target, signatureContext); + break; + + case ReadyToRunHelperId.DelegateCtor: + helperNode = CreateDelegateCtorHelper((DelegateCreationInfo)target, signatureContext); + break; + + default: + throw new NotImplementedException(); + } + + helperNodeMap.Add(target, helperNode); + return helperNode; + } + + private ISymbolNode CreateNewHelper(TypeDesc type, SignatureContext signatureContext) + { + return new DelayLoadHelperImport( + _codegenNodeFactory, + _codegenNodeFactory.HelperImports, + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, + new NewObjectFixupSignature(type, signatureContext)); + } + + private ISymbolNode CreateNewArrayHelper(ArrayType type, SignatureContext signatureContext) + { + return new DelayLoadHelperImport( + _codegenNodeFactory, + _codegenNodeFactory.HelperImports, + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, + new NewArrayFixupSignature(type, signatureContext)); + } + + private ISymbolNode CreateGCStaticBaseHelper(TypeDesc type, SignatureContext signatureContext) + { + return new DelayLoadHelperImport( + _codegenNodeFactory, + _codegenNodeFactory.HelperImports, + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, + new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_StaticBaseGC, type, signatureContext)); + } + + private ISymbolNode CreateNonGCStaticBaseHelper(TypeDesc type, SignatureContext signatureContext) + { + return new DelayLoadHelperImport( + _codegenNodeFactory, + _codegenNodeFactory.HelperImports, + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, + new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_StaticBaseNonGC, type, signatureContext)); + } + + private ISymbolNode CreateThreadGcStaticBaseHelper(TypeDesc type, SignatureContext signatureContext) + { + return new DelayLoadHelperImport( + _codegenNodeFactory, + _codegenNodeFactory.HelperImports, + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, + new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_ThreadStaticBaseGC, type, signatureContext)); + } + + private ISymbolNode CreateThreadNonGcStaticBaseHelper(TypeDesc type, SignatureContext signatureContext) + { + return new DelayLoadHelperImport( + _codegenNodeFactory, + _codegenNodeFactory.HelperImports, + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, + new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_ThreadStaticBaseNonGC, type, signatureContext)); + } + + private ISymbolNode CreateIsInstanceOfHelper(TypeDesc type, SignatureContext signatureContext) + { + return new DelayLoadHelperImport( + _codegenNodeFactory, + _codegenNodeFactory.HelperImports, + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, + new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_IsInstanceOf, type, signatureContext)); + } + + private ISymbolNode CreateCastClassHelper(TypeDesc type, SignatureContext signatureContext) + { + return new DelayLoadHelperImport( + _codegenNodeFactory, + _codegenNodeFactory.HelperImports, + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper_Obj, + new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_ChkCast, type, signatureContext)); + } + + private ISymbolNode CreateTypeHandleHelper(TypeDesc type, SignatureContext signatureContext) + { + return new PrecodeHelperImport( + _codegenNodeFactory, + new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_TypeHandle, type, signatureContext)); + } + + private ISymbolNode CreateFieldHandleHelper(FieldDesc field, SignatureContext signatureContext) + { + return new PrecodeHelperImport( + _codegenNodeFactory, + new FieldFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_FieldHandle, field, signatureContext)); + } + + private ISymbolNode CreateVirtualCallHelper(MethodDesc method, SignatureContext signatureContext) + { + return new DelayLoadHelperImport( + _codegenNodeFactory, + _codegenNodeFactory.DispatchImports, + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper_Obj, + _codegenNodeFactory.MethodSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_VirtualEntry, method, + constrainedType: null, signatureContext: signatureContext, isUnboxingStub: false, isInstantiatingStub: false)); + } + + private ISymbolNode CreateDelegateCtorHelper(DelegateCreationInfo info, SignatureContext signatureContext) + { + return info.Constructor; + } + + private readonly Dictionary _helperCache = new Dictionary(); + + public ISymbolNode ExternSymbol(ILCompiler.ReadyToRunHelper helper) + { + if (_helperCache.TryGetValue(helper, out ISymbolNode result)) + { + return result; + } + + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper r2rHelper; + switch (helper) + { + // Exception handling helpers + case ILCompiler.ReadyToRunHelper.Throw: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Throw; + break; + + case ILCompiler.ReadyToRunHelper.Rethrow: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Rethrow; + break; + + case ILCompiler.ReadyToRunHelper.Overflow: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Overflow; + break; + + case ILCompiler.ReadyToRunHelper.RngChkFail: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_RngChkFail; + break; + + case ILCompiler.ReadyToRunHelper.FailFast: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_FailFast; + break; + + case ILCompiler.ReadyToRunHelper.ThrowNullRef: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ThrowNullRef; + break; + + case ILCompiler.ReadyToRunHelper.ThrowDivZero: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ThrowDivZero; + break; + + // Write barriers + case ILCompiler.ReadyToRunHelper.WriteBarrier: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier; + break; + + case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier; + break; + + case ILCompiler.ReadyToRunHelper.ByRefWriteBarrier: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ByRefWriteBarrier; + break; + + // Array helpers + case ILCompiler.ReadyToRunHelper.Stelem_Ref: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Stelem_Ref; + break; + + case ILCompiler.ReadyToRunHelper.Ldelema_Ref: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Ldelema_Ref; + break; + + case ILCompiler.ReadyToRunHelper.MemSet: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_MemSet; + break; + + case ILCompiler.ReadyToRunHelper.MemCpy: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_MemCpy; + break; + + // Get string handle lazily + case ILCompiler.ReadyToRunHelper.GetString: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GetString; + break; + + // Reflection helpers + case ILCompiler.ReadyToRunHelper.GetRuntimeTypeHandle: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GetRuntimeTypeHandle; + break; + + case ILCompiler.ReadyToRunHelper.GetRuntimeMethodHandle: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GetRuntimeMethodHandle; + break; + + case ILCompiler.ReadyToRunHelper.GetRuntimeFieldHandle: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GetRuntimeFieldHandle; + break; + + case ILCompiler.ReadyToRunHelper.Box: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Box; + break; + + case ILCompiler.ReadyToRunHelper.Box_Nullable: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Box_Nullable; + break; + + case ILCompiler.ReadyToRunHelper.Unbox: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Unbox; + break; + + case ILCompiler.ReadyToRunHelper.Unbox_Nullable: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Unbox_Nullable; + break; + + case ILCompiler.ReadyToRunHelper.NewMultiDimArr: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_NewMultiDimArr; + break; + + case ILCompiler.ReadyToRunHelper.NewMultiDimArr_NonVarArg: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_NewMultiDimArr_NonVarArg; + break; + + // Helpers used with generic handle lookup cases + case ILCompiler.ReadyToRunHelper.NewObject: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_NewObject; + break; + + case ILCompiler.ReadyToRunHelper.NewArray: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_NewArray; + break; + + case ILCompiler.ReadyToRunHelper.CheckCastAny: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckCastAny; + break; + + case ILCompiler.ReadyToRunHelper.CheckInstanceAny: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckInstanceAny; + break; + + case ILCompiler.ReadyToRunHelper.GenericGcStaticBase: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GenericGcStaticBase; + break; + + case ILCompiler.ReadyToRunHelper.GenericNonGcStaticBase: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GenericNonGcStaticBase; + break; + + case ILCompiler.ReadyToRunHelper.GenericGcTlsBase: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GenericGcTlsBase; + break; + + case ILCompiler.ReadyToRunHelper.GenericNonGcTlsBase: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_GenericNonGcTlsBase; + break; + + case ILCompiler.ReadyToRunHelper.VirtualFuncPtr: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_VirtualFuncPtr; + break; + + // Long mul/div/shift ops + case ILCompiler.ReadyToRunHelper.LMul: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LMul; + break; + + case ILCompiler.ReadyToRunHelper.LMulOfv: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LMulOfv; + break; + + case ILCompiler.ReadyToRunHelper.ULMulOvf: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ULMulOvf; + break; + + case ILCompiler.ReadyToRunHelper.LDiv: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LDiv; + break; + + case ILCompiler.ReadyToRunHelper.LMod: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LMod; + break; + + case ILCompiler.ReadyToRunHelper.ULDiv: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ULDiv; + break; + + case ILCompiler.ReadyToRunHelper.ULMod: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ULMod; + break; + + case ILCompiler.ReadyToRunHelper.LLsh: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LLsh; + break; + + case ILCompiler.ReadyToRunHelper.LRsh: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LRsh; + break; + + case ILCompiler.ReadyToRunHelper.LRsz: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_LRsz; + break; + + case ILCompiler.ReadyToRunHelper.Lng2Dbl: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Lng2Dbl; + break; + + case ILCompiler.ReadyToRunHelper.ULng2Dbl: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_ULng2Dbl; + break; + + // 32-bit division helpers + case ILCompiler.ReadyToRunHelper.Div: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Div; + break; + + case ILCompiler.ReadyToRunHelper.Mod: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Mod; + break; + + case ILCompiler.ReadyToRunHelper.UDiv: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_UDiv; + break; + + case ILCompiler.ReadyToRunHelper.UMod: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_UMod; + break; + + // Floating point conversions + case ILCompiler.ReadyToRunHelper.Dbl2Int: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2Int; + break; + + case ILCompiler.ReadyToRunHelper.Dbl2IntOvf: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2IntOvf; + break; + + case ILCompiler.ReadyToRunHelper.Dbl2Lng: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2Lng; + break; + + case ILCompiler.ReadyToRunHelper.Dbl2LngOvf: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2LngOvf; + break; + + case ILCompiler.ReadyToRunHelper.Dbl2UInt: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2UInt; + break; + + case ILCompiler.ReadyToRunHelper.Dbl2UIntOvf: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2UIntOvf; + break; + + case ILCompiler.ReadyToRunHelper.Dbl2ULng: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2ULng; + break; + + case ILCompiler.ReadyToRunHelper.Dbl2ULngOvf: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_Dbl2ULngOvf; + break; + + // Floating point ops + case ILCompiler.ReadyToRunHelper.DblRem: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DblRem; + break; + + case ILCompiler.ReadyToRunHelper.FltRem: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_FltRem; + break; + + case ILCompiler.ReadyToRunHelper.DblRound: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DblRound; + break; + + case ILCompiler.ReadyToRunHelper.FltRound: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_FltRound; + break; + + case ILCompiler.ReadyToRunHelper.GetRefAny: + // TODO-PERF: currently not implemented in Crossgen + ThrowHelper.ThrowInvalidProgramException(); + // ThrowInvalidProgramException should never return + throw new NotImplementedException(); + + // JIT32 x86-specific write barriers + case ILCompiler.ReadyToRunHelper.WriteBarrier_EAX: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier_EAX; + break; + case ILCompiler.ReadyToRunHelper.WriteBarrier_EBX: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier_EBX; + break; + case ILCompiler.ReadyToRunHelper.WriteBarrier_ECX: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier_ECX; + break; + case ILCompiler.ReadyToRunHelper.WriteBarrier_ESI: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier_ESI; + break; + case ILCompiler.ReadyToRunHelper.WriteBarrier_EDI: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier_EDI; + break; + case ILCompiler.ReadyToRunHelper.WriteBarrier_EBP: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_WriteBarrier_EBP; + break; + case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier_EAX: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier_EAX; + break; + case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier_EBX: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier_EBX; + break; + case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier_ECX: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier_ECX; + break; + case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier_ESI: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier_ESI; + break; + case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier_EDI: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier_EDI; + break; + case ILCompiler.ReadyToRunHelper.CheckedWriteBarrier_EBP: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_CheckedWriteBarrier_EBP; + break; + case ILCompiler.ReadyToRunHelper.EndCatch: + r2rHelper = ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_EndCatch; + break; + + default: + throw new NotImplementedException(helper.ToString()); + } + + result = _codegenNodeFactory.GetReadyToRunHelperCell(r2rHelper); + _helperCache.Add(helper, result); + return result; + } + + public ISymbolNode HelperMethodEntrypoint(ILCompiler.ReadyToRunHelper helperId, MethodDesc method) + { + return ExternSymbol(helperId); + } + + private readonly Dictionary _interfaceDispatchCells = new Dictionary(); + + public ISymbolNode InterfaceDispatchCell(MethodDesc method, SignatureContext signatureContext, bool isUnboxingStub, string callSite) + { + MethodAndCallSite cellKey = new MethodAndCallSite(method, callSite); + if (!_interfaceDispatchCells.TryGetValue(cellKey, out ISymbolNode dispatchCell)) + { + dispatchCell = new DelayLoadHelperImport( + _codegenNodeFactory, + _codegenNodeFactory.DispatchImports, + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_MethodCall | + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_FLAG_VSD, + _codegenNodeFactory.MethodSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_VirtualEntry, method, + null, signatureContext, isUnboxingStub, isInstantiatingStub: false), + callSite); + + _interfaceDispatchCells.Add(cellKey, dispatchCell); + } + return dispatchCell; + } + + public ISymbolNode ComputeConstantLookup(ReadyToRunHelperId helperId, object entity, SignatureContext signatureContext) + { + return ReadyToRunHelper(helperId, entity, signatureContext); + } + + private readonly Dictionary _genericDictionaryCache = new Dictionary(); + + public ISortableSymbolNode MethodGenericDictionary(MethodDesc method, SignatureContext signatureContext) + { + if (!_genericDictionaryCache.TryGetValue(method, out ISortableSymbolNode genericDictionary)) + { + genericDictionary = new PrecodeHelperImport( + _codegenNodeFactory, + _codegenNodeFactory.MethodSignature( + ReadyToRunFixupKind.READYTORUN_FIXUP_MethodDictionary, + method, + constrainedType: null, + signatureContext: signatureContext, + isUnboxingStub: false, + isInstantiatingStub: true)); + _genericDictionaryCache.Add(method, genericDictionary); + } + return genericDictionary; + } + + private readonly Dictionary _constructedTypeSymbols = new Dictionary(); + + public ISymbolNode ConstructedTypeSymbol(TypeDesc type, SignatureContext signatureContext) + { + if (!_constructedTypeSymbols.TryGetValue(type, out ISymbolNode symbol)) + { + symbol = new PrecodeHelperImport( + _codegenNodeFactory, + new TypeFixupSignature(ReadyToRunFixupKind.READYTORUN_FIXUP_TypeDictionary, type, signatureContext)); + _constructedTypeSymbols.Add(type, symbol); + } + return symbol; + } + + private readonly Dictionary _delegateCtors = new Dictionary(); + + public ISymbolNode DelegateCtor(TypeDesc delegateType, MethodDesc targetMethod, SignatureContext signatureContext) + { + TypeAndMethod ctorKey = new TypeAndMethod(delegateType, targetMethod, isUnboxingStub: false, isInstantiatingStub: false); + if (!_delegateCtors.TryGetValue(ctorKey, out ISymbolNode ctorNode)) + { + IMethodNode targetMethodNode = _codegenNodeFactory.MethodEntrypoint(targetMethod, constrainedType: null, originalMethod: null, signatureContext: signatureContext, isUnboxingStub: false); + + ctorNode = new DelayLoadHelperImport( + _codegenNodeFactory, + _codegenNodeFactory.HelperImports, + ILCompiler.DependencyAnalysis.ReadyToRun.ReadyToRunHelper.READYTORUN_HELPER_DelayLoad_Helper, + new DelegateCtorSignature(delegateType, targetMethodNode, signatureContext)); + _delegateCtors.Add(ctorKey, ctorNode); + } + return ctorNode; + } + + struct MethodAndCallSite : IEquatable + { + public readonly MethodDesc Method; + public readonly string CallSite; + + public MethodAndCallSite(MethodDesc method, string callSite) + { + CallSite = callSite; + Method = method; + } + + public bool Equals(MethodAndCallSite other) + { + return CallSite == other.CallSite && Method == other.Method; + } + + public override bool Equals(object obj) + { + return obj is MethodAndCallSite other && Equals(other); + } + + public override int GetHashCode() + { + return (CallSite != null ? CallSite.GetHashCode() : 0) + unchecked(31 * Method.GetHashCode()); + } + } + } +} diff --git a/src/ILCompiler.ReadyToRun/src/Compiler/DependencyAnalysis/TypeAndMethod.cs b/src/ILCompiler.ReadyToRun/src/Compiler/DependencyAnalysis/TypeAndMethod.cs new file mode 100644 index 00000000000..4e998897461 --- /dev/null +++ b/src/ILCompiler.ReadyToRun/src/Compiler/DependencyAnalysis/TypeAndMethod.cs @@ -0,0 +1,43 @@ +// 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 Internal.TypeSystem; + +namespace ILCompiler.DependencyAnalysis +{ + internal struct TypeAndMethod : IEquatable + { + public readonly TypeDesc Type; + public readonly MethodDesc Method; + public readonly bool IsUnboxingStub; + public readonly bool IsInstantiatingStub; + + public TypeAndMethod(TypeDesc type, MethodDesc method, bool isUnboxingStub, bool isInstantiatingStub) + { + Type = type; + Method = method; + IsUnboxingStub = isUnboxingStub; + IsInstantiatingStub = isInstantiatingStub; + } + + public bool Equals(TypeAndMethod other) + { + return Type == other.Type && + Method == other.Method && + IsUnboxingStub == other.IsUnboxingStub && + IsInstantiatingStub == other.IsInstantiatingStub; + } + + public override bool Equals(object obj) + { + return obj is TypeAndMethod other && Equals(other); + } + + public override int GetHashCode() + { + return (Type?.GetHashCode() ?? 0) ^ unchecked(Method.GetHashCode() * 31) ^ (IsUnboxingStub ? -0x80000000 : 0) ^ (IsInstantiatingStub ? 0x40000000 : 0); + } + } +} diff --git a/src/ILCompiler.ReadyToRun/src/Compiler/ReadyToRunCodegenCompilation.cs b/src/ILCompiler.ReadyToRun/src/Compiler/ReadyToRunCodegenCompilation.cs index 0e44b20a326..048bff2c8e7 100644 --- a/src/ILCompiler.ReadyToRun/src/Compiler/ReadyToRunCodegenCompilation.cs +++ b/src/ILCompiler.ReadyToRun/src/Compiler/ReadyToRunCodegenCompilation.cs @@ -37,6 +37,9 @@ public sealed class ReadyToRunCodegenCompilation : Compilation private readonly string _inputFilePath; public new ReadyToRunCodegenNodeFactory NodeFactory { get; } + + public ReadyToRunSymbolNodeFactory SymbolNodeFactory { get; } + internal ReadyToRunCodegenCompilation( DependencyAnalyzerBase dependencyGraph, ReadyToRunCodegenNodeFactory nodeFactory, @@ -50,6 +53,7 @@ internal ReadyToRunCodegenCompilation( : base(dependencyGraph, nodeFactory, roots, ilProvider, debugInformationProvider, devirtualizationManager, logger) { NodeFactory = nodeFactory; + SymbolNodeFactory = new ReadyToRunSymbolNodeFactory(nodeFactory); _corInfo = new Dictionary(); _jitConfigProvider = configProvider; diff --git a/src/ILCompiler.ReadyToRun/src/ILCompiler.ReadyToRun.csproj b/src/ILCompiler.ReadyToRun/src/ILCompiler.ReadyToRun.csproj index 5b1f0a8f507..ad5179a4611 100644 --- a/src/ILCompiler.ReadyToRun/src/ILCompiler.ReadyToRun.csproj +++ b/src/ILCompiler.ReadyToRun/src/ILCompiler.ReadyToRun.csproj @@ -73,6 +73,8 @@ + + diff --git a/src/ILCompiler.ReadyToRun/src/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/ILCompiler.ReadyToRun/src/JitInterface/CorInfoImpl.ReadyToRun.cs index d99204f4739..02b57e502a8 100644 --- a/src/ILCompiler.ReadyToRun/src/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/ILCompiler.ReadyToRun/src/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -106,7 +106,7 @@ private void ComputeLookup(ref CORINFO_RESOLVED_TOKEN pResolvedToken, object ent else { lookup.lookupKind.needsRuntimeLookup = false; - ISymbolNode constLookup = _compilation.NodeFactory.ComputeConstantLookup(helperId, entity, _signatureContext); + ISymbolNode constLookup = _compilation.SymbolNodeFactory.ComputeConstantLookup(helperId, entity, _signatureContext); lookup.constLookup = CreateConstLookupToSymbol(constLookup); } } @@ -122,7 +122,7 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref if (type.IsCanonicalSubtype(CanonicalFormKind.Any)) return false; - pLookup = CreateConstLookupToSymbol(_compilation.NodeFactory.ReadyToRunHelper(ReadyToRunHelperId.NewHelper, type, _signatureContext)); + pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.ReadyToRunHelper(ReadyToRunHelperId.NewHelper, type, _signatureContext)); } break; case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NEWARR_1: @@ -132,7 +132,7 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref if (type.IsCanonicalSubtype(CanonicalFormKind.Any)) return false; - pLookup = CreateConstLookupToSymbol(_compilation.NodeFactory.ReadyToRunHelper(ReadyToRunHelperId.NewArr1, type, _signatureContext)); + pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.ReadyToRunHelper(ReadyToRunHelperId.NewArr1, type, _signatureContext)); } break; case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_ISINSTANCEOF: @@ -145,7 +145,7 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref if (type.IsNullable) type = type.Instantiation[0]; - pLookup = CreateConstLookupToSymbol(_compilation.NodeFactory.ReadyToRunHelper(ReadyToRunHelperId.IsInstanceOf, type, _signatureContext)); + pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.ReadyToRunHelper(ReadyToRunHelperId.IsInstanceOf, type, _signatureContext)); } break; case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_CHKCAST: @@ -158,7 +158,7 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref if (type.IsNullable) type = type.Instantiation[0]; - pLookup = CreateConstLookupToSymbol(_compilation.NodeFactory.ReadyToRunHelper(ReadyToRunHelperId.CastClass, type, _signatureContext)); + pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.ReadyToRunHelper(ReadyToRunHelperId.CastClass, type, _signatureContext)); } break; case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_STATIC_BASE: @@ -167,7 +167,7 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref if (type.IsCanonicalSubtype(CanonicalFormKind.Any)) return false; - pLookup = CreateConstLookupToSymbol(_compilation.NodeFactory.ReadyToRunHelper(ReadyToRunHelperId.GetNonGCStaticBase, type, _signatureContext)); + pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.ReadyToRunHelper(ReadyToRunHelperId.GetNonGCStaticBase, type, _signatureContext)); } break; case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE: @@ -239,7 +239,7 @@ private void getReadyToRunDelegateCtorHelper(ref CORINFO_RESOLVED_TOKEN pTargetM */ { pLookup.lookupKind.needsRuntimeLookup = false; - pLookup.constLookup = CreateConstLookupToSymbol(_compilation.NodeFactory.DelegateCtor( + pLookup.constLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.DelegateCtor( delegateTypeDesc, targetMethod, _signatureContext)); } } @@ -523,7 +523,7 @@ private ISymbolNode GetHelperFtnUncached(CorInfoHelpFunc ftnNum) throw new NotImplementedException(ftnNum.ToString()); } - return _compilation.NodeFactory.ExternSymbol(id); + return _compilation.SymbolNodeFactory.ExternSymbol(id); } private void getFunctionEntryPoint(CORINFO_METHOD_STRUCT_* ftn, ref CORINFO_CONST_LOOKUP pResult, CORINFO_ACCESS_FLAGS accessFlags) @@ -539,14 +539,14 @@ private void getFunctionEntryPoint(CORINFO_METHOD_STRUCT_* ftn, ref CORINFO_CONS private InfoAccessType constructStringLiteral(CORINFO_MODULE_STRUCT_* module, mdToken metaTok, ref void* ppValue) { - ISymbolNode stringObject = _compilation.NodeFactory.StringLiteral(new ModuleToken(_tokenContext, metaTok)); + ISymbolNode stringObject = _compilation.SymbolNodeFactory.StringLiteral(new ModuleToken(_tokenContext, metaTok)); ppValue = (void*)ObjectToHandle(stringObject); return InfoAccessType.IAT_PPVALUE; } public ISymbolNode ComputeConstantLookup(ReadyToRunHelperId helperId, object entity, SignatureContext signatureContext) { - return _compilation.NodeFactory.ReadyToRunHelper(helperId, entity, signatureContext); + return _compilation.SymbolNodeFactory.ReadyToRunHelper(helperId, entity, signatureContext); } enum EHInfoFields diff --git a/src/JitInterface/src/CorInfoImpl.cs b/src/JitInterface/src/CorInfoImpl.cs index 9f578cbf39b..9a2c96cb0d9 100644 --- a/src/JitInterface/src/CorInfoImpl.cs +++ b/src/JitInterface/src/CorInfoImpl.cs @@ -1891,7 +1891,7 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET { pResult.fieldLookup = CreateConstLookupToSymbol( #if READYTORUN - _compilation.NodeFactory.ReadyToRunHelper(helperId, field.OwningType, _signatureContext) + _compilation.SymbolNodeFactory.ReadyToRunHelper(helperId, field.OwningType, _signatureContext) #else _compilation.NodeFactory.ReadyToRunHelper(helperId, field.OwningType) #endif @@ -2683,7 +2683,7 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO if (targetMethod.RequiresInstMethodDescArg()) { #if READYTORUN - instParam = _compilation.NodeFactory.MethodGenericDictionary(concreteMethod, _signatureContext); + instParam = _compilation.SymbolNodeFactory.MethodGenericDictionary(concreteMethod, _signatureContext); #else instParam = _compilation.NodeFactory.MethodGenericDictionary(concreteMethod); #endif @@ -2692,7 +2692,7 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO { // Ask for a constructed type symbol because we need the vtable to get to the dictionary #if READYTORUN - instParam = _compilation.NodeFactory.ConstructedTypeSymbol(concreteMethod.OwningType, _signatureContext); + instParam = _compilation.SymbolNodeFactory.ConstructedTypeSymbol(concreteMethod.OwningType, _signatureContext); #else instParam = _compilation.NodeFactory.ConstructedTypeSymbol(concreteMethod.OwningType); #endif @@ -2794,7 +2794,7 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO pResult.codePointerOrStubLookup.constLookup.accessType = InfoAccessType.IAT_PVALUE; pResult.codePointerOrStubLookup.constLookup.addr = (void*)ObjectToHandle( #if READYTORUN - _compilation.NodeFactory.InterfaceDispatchCell(targetMethod, _signatureContext, isUnboxingStub: false + _compilation.SymbolNodeFactory.InterfaceDispatchCell(targetMethod, _signatureContext, isUnboxingStub: false #else _compilation.NodeFactory.InterfaceDispatchCell(targetMethod #endif // READYTORUN