Split generic virtual method slot use and impl tracking (#82222)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Mon, 27 Feb 2023 23:49:37 +0000 (08:49 +0900)
committerGitHub <noreply@github.com>
Mon, 27 Feb 2023 23:49:37 +0000 (08:49 +0900)
commit443c42baea596cbbeea348f6998f78eb085b1c09
treeeb1a88935e26eb55db74c2d8d8f1d28bd88cc861
parent3bbf29e9bc119b90cdb424666214537b123c6665
Split generic virtual method slot use and impl tracking (#82222)

* Split generic virtual method slot use and impl tracking

I'm looking at generic virtual method again because of #80602.

The analysis of generic virtual methods within the compiler is an N * M algorithm where N is the number of unique generic virtual method instantiations called and M is the number of types that implement generic virtual methods.

We use dynamic dependencies within the dependency analysis engine to model this relationship.

It is important to try to limit the N and M. Looking at things, I realized the N we're currently operating on is bigger than it needs to be:

```csharp
Foo f = new Bar();
f.Blah<int>();
f = new Baz();
f.Blah<double>();

class Foo { public virtual void Blah<T>() { } }
class Bar : Foo { public override void Blah<T> { } }
class Baz : Foo { public override void Blah<T> { } }
```

Previously, the analysis would see M = 3 and N = 6 because we would track each of the overrides as something that needs to be considered for each M. This changes the analysis to only look at the definition of the slot, i.e. N = 2 (one for int, other for double).

The result of the analysis will still be same, it will just take less time. The new GenericVirtualMethodImpl node responds false to HasDynamicDependencies and doesn't participate in expensive activities.
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GVMDependenciesNode.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericVirtualMethodImplNode.cs [new file with mode: 0644]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectedMethodNode.cs
src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj