Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker dependency framework #101277

Merged
merged 42 commits into from
May 6, 2024
Merged

Conversation

jtschuster
Copy link
Member

@jtschuster jtschuster commented Apr 19, 2024

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.

@jtschuster jtschuster added NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) NO-REVIEW Experimental/testing PR, do NOT review it labels Apr 19, 2024
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Comment on lines 465 to 468
protected override void OnMarked (MarkStepNodeFactory context)
{
markStep.MarkTypeImpl (reference, reason, origin);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough of the DF to tell if this is the right place to do the heavy processing. But I guess for now it is.
I assume eventually all of this would move to GetDependencies and we would remove OnMarked, right?

Future thought: Try to figure out how the DF will play with Annotations and the notion of "marked item" which is used outside of the mark step in the trimmer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think ideally most of this moves to GetDependencies and this is minimal or removed.

My thought is that eventually the Annotations markings will forward to the analyzer markings, but that could get complicated if marking (not just IsMarked checks) happen outside of MarkStep. In the meantime, I think OnMarked will call Annotations.MarkX.

@@ -2759,7 +2849,7 @@ void MarkGenericArguments (IGenericInstance instance)
var argument = arguments[i];
var parameter = parameters[i];

TypeDefinition? argumentTypeDef = MarkType (argument, new DependencyInfo (DependencyKind.GenericArgumentType, instance));
var argumentTypeDef = MarkTypeImpl (argument, new DependencyInfo (DependencyKind.GenericArgumentType, instance));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the place where it gets interesting for TypeRef versus TypeDef :-)

@jtschuster jtschuster removed NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) NO-REVIEW Experimental/testing PR, do NOT review it labels Apr 22, 2024
src/tools/illink/src/linker/Linker.Steps/MarkStep.cs Outdated Show resolved Hide resolved
src/tools/illink/src/linker/Linker.Steps/MarkStep.cs Outdated Show resolved Hide resolved
src/tools/illink/src/linker/Linker.Steps/MarkStep.cs Outdated Show resolved Hide resolved
src/tools/illink/src/linker/Linker.Steps/MarkStep.cs Outdated Show resolved Hide resolved
@@ -2014,9 +2028,21 @@ internal void MarkStaticConstructorVisibleToReflection (TypeDefinition type, in
if (CheckProcessed (type))
return type;

if (type.HasMethods) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why this moved - at first glance it looks like it better belongs in ProcessType since it should happen just once per type definition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally I moved it up because it relied on the DependencyInfo, but I think that can condition can be removed and moved back to ProcessMethod. I think the check on the DependencyKind was only to prevent infinite recursion when marking cctors, which we won't hit with the dependency analyzer.

protected override string GetName (NodeFactory context) => $"{type.GetDisplayName()} is relevant to variant casting";
protected override void OnMarked (NodeFactory context)
{
context.MarkStep.Annotations.MarkRelevantToVariantCasting (type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do we use OnMarked vs GetStaticDependencies?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just used OnMarked arbitrarily for this since there aren't any dependencies. It looks like OnMarked will do work up front when the node is returned from another GetStaticDependencies, then it's added to a stack to later call GetStaticDependencies.

- Rename dependency analyzer
- Remove empty lines
- Remove methods queue
- Move static ctor marking
Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@vitek-karas
Copy link
Member

Did you try a simple perf measurement? I don't expect to see noticeable difference, but it does change how the main loop works... ;-)

@jtschuster
Copy link
Member Author

jtschuster commented May 3, 2024

Did you try a simple perf measurement? I don't expect to see noticeable difference, but it does change how the main loop works... ;-)

Yep, it looks like this has about the exact same speed performance. We allocate a bit more for all the Funcs used when producing nodes, but they're short lived and shouldn't impact max working set too much (and we can remove the allocation in a follow up).

eng/liveILLink.targets Outdated Show resolved Hide resolved
@jtschuster jtschuster requested a review from agocke May 6, 2024 20:03
@jtschuster jtschuster merged commit fbb67a6 into dotnet:main May 6, 2024
162 checks passed
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
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>
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
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>
@github-actions github-actions bot locked and limited conversation to collaborators Jun 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants