From d406b731dbc004d4f86f48ecc97c00504ec1ac34 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 4 Jul 2023 15:20:06 +0900 Subject: [PATCH] Remove conservative generic scanning logic (#88360) @EgorBo's #88025 made it possible to undo conservative scanning logic added in dotnet/corert#7618. Saves 0.4% in size for Stage1 and Stage2 apps. --- .../tools/Common/JitInterface/CorInfoImpl.cs | 3 +- .../ILCompiler.Compiler/IL/ILImporter.Scanner.cs | 53 ---------------------- 2 files changed, 1 insertion(+), 55 deletions(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 10749a4..13fd08e 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -1202,13 +1202,12 @@ namespace Internal.JitInterface } } -#if READYTORUN // Add an early CanInline check to see if referring to the IL of the target methods is // permitted from within this MethodBeingCompiled, the full CanInline check will be performed // later. if (!_compilation.CanInline(MethodBeingCompiled, method)) return false; -#endif + MethodIL methodIL = method.IsUnboxingThunk() ? null : _compilation.GetMethodIL(method); return Get_CORINFO_METHOD_INFO(method, methodIL, info); } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs index 8ea05d0..dbe3be8 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs @@ -601,33 +601,6 @@ namespace Internal.IL _dependencies.Add(instParam, reason); } - if (instParam == null - && !targetMethod.OwningType.IsValueType - && !_factory.TypeSystemContext.IsSpecialUnboxingThunk(_canonMethod)) - { - // We have a call to a shared instance method and we're already in a shared context. - // e.g. this is a call to Foo.Method() and we're about to add Foo<__Canon>.Method() - // to the dependency graph). - // - // We will pretend the runtime determined owning type (Foo) got allocated as well. - // This is because RyuJIT might end up inlining the shared method body, making it concrete again, - // without actually having to go through a dictionary. - // (This would require inlining across two generic contexts, but RyuJIT does that.) - // - // If we didn't have a constructed type for this at the scanning time, we wouldn't - // know the dictionary dependencies at the inlined site, leading to a compile failure. - // (Remember that dictionary dependencies of instance methods on generic reference types - // are tied to the owning type.) - // - // This is not ideal, because if e.g. Foo never got allocated otherwise, this code is - // unreachable and we're making the scanner scan more of it. - // - // Technically, we could get away with injecting a RuntimeDeterminedMethodNode here - // but that introduces more complexities and doesn't seem worth it at this time. - Debug.Assert(targetMethod.AcquiresInstMethodTableFromThis()); - _dependencies.Add(GetGenericLookupHelper(ReadyToRunHelperId.TypeHandle, runtimeDeterminedMethod.OwningType), reason + " - inlining protection"); - } - _dependencies.Add(_factory.CanonicalEntrypoint(targetMethod), reason); } else @@ -669,32 +642,6 @@ namespace Internal.IL _dependencies.Add(instParam, reason); } - if (instParam == null - && concreteMethod != targetMethod - && targetMethod.OwningType.NormalizeInstantiation() == targetMethod.OwningType - && !targetMethod.OwningType.IsValueType) - { - // We have a call to a shared instance method and we still know the concrete - // type of the generic instance (e.g. this is a call to Foo.Method() - // and we're about to add Foo<__Canon>.Method() to the dependency graph). - // - // We will pretend the concrete type got allocated as well. This is because RyuJIT might - // end up inlining the shared method body, making it concrete again. - // - // If we didn't have a constructed type for this at the scanning time, we wouldn't - // know the dictionary dependencies at the inlined site, leading to a compile failure. - // (Remember that dictionary dependencies of instance methods on generic reference types - // are tied to the owning type.) - // - // This is not ideal, because if Foo never got allocated otherwise, this code is - // unreachable and we're making the scanner scan more of it. - // - // Technically, we could get away with injecting a ShadowConcreteMethod for the concrete - // method, but that's more complex and doesn't seem worth it at this time. - Debug.Assert(targetMethod.AcquiresInstMethodTableFromThis()); - _dependencies.Add(_compilation.NodeFactory.MaximallyConstructableType(concreteMethod.OwningType), reason + " - inlining protection"); - } - _dependencies.Add(GetMethodEntrypoint(targetMethod), reason); } } -- 2.7.4