-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin transition to dependency framework in illink (#101277)
Recreates the Process() loop in MarkStep with node that depends on a new copy of itself when the loop needs to be rerun. Within the loop, the new Method and Type nodes are added to the dependency framework analyzer as roots when MarkMethod and MarkType are called, which leads to the OnMarked methods to be called, which forwards to the ProcessType/Method method in MarkStep. The dependency analyzer doesn't do anything interesting yet. In a follow-up I'll move dependencies from the MarkX and ProcessX methods to the DependencyNode types. Makes ILCompiler.DependencyAnalysisFramework output path independent of target architecture. Removes TargetArchitecture and TargetOS from ILLink.Tasks project references. --------- Co-authored-by: vitek-karas <10670590+vitek-karas@users.noreply.github.com>
- Loading branch information
1 parent
1eb888b
commit fbb67a6
Showing
12 changed files
with
302 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/tools/illink/src/linker/Linker.Steps/MarkStep.MethodDefinitionNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using ILCompiler.DependencyAnalysisFramework; | ||
using Mono.Cecil; | ||
|
||
namespace Mono.Linker.Steps | ||
{ | ||
public partial class MarkStep | ||
{ | ||
internal sealed class MethodDefinitionNode : DependencyNodeCore<NodeFactory> | ||
{ | ||
readonly MethodDefinition method; | ||
readonly DependencyInfo reason; | ||
|
||
public MethodDefinitionNode (MethodDefinition method, DependencyInfo reason) | ||
{ | ||
this.method = method; | ||
this.reason = reason; | ||
} | ||
|
||
public override bool InterestingForDynamicDependencyAnalysis => false; | ||
|
||
public override bool HasDynamicDependencies => false; | ||
|
||
public override bool HasConditionalStaticDependencies => false; | ||
|
||
public override bool StaticDependenciesAreComputed => true; | ||
|
||
public override IEnumerable<DependencyListEntry>? GetStaticDependencies (NodeFactory context) | ||
{ | ||
context.MarkStep.ProcessMethod (method, reason); | ||
return null; | ||
} | ||
|
||
public override IEnumerable<CombinedDependencyListEntry>? GetConditionalStaticDependencies (NodeFactory context) => null; | ||
public override IEnumerable<CombinedDependencyListEntry>? SearchDynamicDependencies (List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => null; | ||
protected override string GetName (NodeFactory context) => method.GetDisplayName(); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/tools/illink/src/linker/Linker.Steps/MarkStep.NodeFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using Mono.Cecil; | ||
|
||
namespace Mono.Linker.Steps | ||
{ | ||
public partial class MarkStep | ||
{ | ||
internal sealed class NodeFactory (MarkStep markStep) | ||
{ | ||
public MarkStep MarkStep { get; } = markStep; | ||
readonly NodeCache<TypeDefinition, TypeDefinitionNode> _typeNodes = new (static t => new TypeDefinitionNode(t)); | ||
readonly NodeCache<MethodDefinition, MethodDefinitionNode> _methodNodes = new (static _ => throw new InvalidOperationException ("Creation of node requires more than the key.")); | ||
readonly NodeCache<TypeDefinition, TypeIsRelevantToVariantCastingNode> _typeIsRelevantToVariantCastingNodes = new (static (t) => new TypeIsRelevantToVariantCastingNode (t)); | ||
|
||
internal TypeDefinitionNode GetTypeNode (TypeDefinition definition) | ||
{ | ||
return _typeNodes.GetOrAdd (definition); | ||
} | ||
|
||
internal MethodDefinitionNode GetMethodDefinitionNode (MethodDefinition method, DependencyInfo reason) | ||
{ | ||
return _methodNodes.GetOrAdd (method, (k) => new MethodDefinitionNode (k, reason)); | ||
} | ||
|
||
internal TypeIsRelevantToVariantCastingNode GetTypeIsRelevantToVariantCastingNode (TypeDefinition type) | ||
{ | ||
return _typeIsRelevantToVariantCastingNodes.GetOrAdd (type); | ||
} | ||
|
||
struct NodeCache<TKey, TValue> where TKey : notnull | ||
{ | ||
// Change to concurrent dictionary if/when multithreaded marking is enabled | ||
readonly Dictionary<TKey, TValue> _cache; | ||
readonly Func<TKey, TValue> _creator; | ||
|
||
public NodeCache (Func<TKey, TValue> creator, IEqualityComparer<TKey> comparer) | ||
{ | ||
_creator = creator; | ||
_cache = new (comparer); | ||
} | ||
|
||
public NodeCache (Func<TKey, TValue> creator) | ||
{ | ||
_creator = creator; | ||
_cache = new (); | ||
} | ||
|
||
public TValue GetOrAdd (TKey key) | ||
{ | ||
return _cache.GetOrAdd (key, _creator); | ||
} | ||
|
||
public TValue GetOrAdd (TKey key, Func<TKey, TValue> creator) | ||
{ | ||
return _cache.GetOrAdd (key, creator); | ||
} | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/tools/illink/src/linker/Linker.Steps/MarkStep.ProcessCallbackNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using ILCompiler.DependencyAnalysisFramework; | ||
|
||
namespace Mono.Linker.Steps | ||
{ | ||
public partial class MarkStep | ||
{ | ||
sealed class ProcessCallbackNode : DependencyNodeCore<NodeFactory> | ||
{ | ||
Func<bool> _processAction; | ||
DependencyList? _dependencies; | ||
|
||
public ProcessCallbackNode (Func<bool> action) => _processAction = action; | ||
|
||
public void Process () | ||
{ | ||
_dependencies = new DependencyList (); | ||
if (_processAction ()) { | ||
_dependencies.Add (new ProcessCallbackNode (_processAction), "Some processing was done, continuation required"); | ||
} | ||
} | ||
|
||
public override bool InterestingForDynamicDependencyAnalysis => false; | ||
|
||
public override bool HasDynamicDependencies => false; | ||
|
||
public override bool HasConditionalStaticDependencies => false; | ||
|
||
public override bool StaticDependenciesAreComputed => _dependencies != null; | ||
|
||
public override IEnumerable<DependencyListEntry>? GetStaticDependencies (NodeFactory context) => _dependencies; | ||
|
||
public override IEnumerable<CombinedDependencyListEntry>? GetConditionalStaticDependencies (NodeFactory context) => null; | ||
public override IEnumerable<CombinedDependencyListEntry>? SearchDynamicDependencies (List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => null; | ||
protected override string GetName (NodeFactory context) => "Process"; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/tools/illink/src/linker/Linker.Steps/MarkStep.TypeDefinitionNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Generic; | ||
using ILCompiler.DependencyAnalysisFramework; | ||
using Mono.Cecil; | ||
|
||
namespace Mono.Linker.Steps | ||
{ | ||
public partial class MarkStep | ||
{ | ||
internal sealed class TypeDefinitionNode : DependencyNodeCore<NodeFactory> | ||
{ | ||
readonly TypeDefinition type; | ||
|
||
public TypeDefinitionNode (TypeDefinition type) | ||
{ | ||
this.type = type; | ||
} | ||
|
||
public override bool InterestingForDynamicDependencyAnalysis => false; | ||
|
||
public override bool HasDynamicDependencies => false; | ||
|
||
public override bool HasConditionalStaticDependencies => false; | ||
|
||
public override bool StaticDependenciesAreComputed => true; | ||
|
||
public override IEnumerable<DependencyListEntry>? GetStaticDependencies (NodeFactory context) | ||
{ | ||
context.MarkStep.ProcessType (type); | ||
return null; | ||
} | ||
|
||
public override IEnumerable<CombinedDependencyListEntry>? GetConditionalStaticDependencies (NodeFactory context) => null; | ||
public override IEnumerable<CombinedDependencyListEntry>? SearchDynamicDependencies (List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => null; | ||
protected override string GetName (NodeFactory context) => type.GetDisplayName(); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/tools/illink/src/linker/Linker.Steps/MarkStep.TypeIsRelevantToVariantCastingNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Generic; | ||
using ILCompiler.DependencyAnalysisFramework; | ||
using Mono.Cecil; | ||
|
||
namespace Mono.Linker.Steps | ||
{ | ||
public partial class MarkStep | ||
{ | ||
internal sealed class TypeIsRelevantToVariantCastingNode : DependencyNodeCore<NodeFactory> | ||
{ | ||
TypeDefinition type; | ||
public TypeIsRelevantToVariantCastingNode (TypeDefinition type) => this.type = type; | ||
|
||
public override bool InterestingForDynamicDependencyAnalysis => false; | ||
|
||
public override bool HasDynamicDependencies => false; | ||
|
||
public override bool HasConditionalStaticDependencies => false; | ||
|
||
public override bool StaticDependenciesAreComputed => true; | ||
|
||
public override IEnumerable<DependencyListEntry>? GetStaticDependencies (NodeFactory context) | ||
{ | ||
yield break; | ||
} | ||
|
||
public override IEnumerable<CombinedDependencyListEntry>? GetConditionalStaticDependencies (NodeFactory context) => null; | ||
public override IEnumerable<CombinedDependencyListEntry>? SearchDynamicDependencies (List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => null; | ||
protected override string GetName (NodeFactory context) => $"{type.GetDisplayName()} is relevant to variant casting"; | ||
protected override void OnMarked (NodeFactory context) | ||
{ | ||
context.MarkStep.Annotations.MarkRelevantToVariantCasting (type); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.