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

[dotnet-linker] Add OptimizeGeneratedCodeSubStep into the pipeline. #9608

Merged
merged 6 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/xharness/Harness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void AutoConfigureIOS ()
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" } });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dotnet", "iOS", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "link all.csproj"))) { Configurations = new string [] { "Debug", "Release" } });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "dotnet", "iOS", "link all.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true, Ignore = true });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "dotnet", "iOS", "link all.csproj"))) { Configurations = new string [] { "Debug" /*, "Release" */ }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "link sdk.csproj"))) { Configurations = new string [] { "Debug", "Release" } });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "dotnet", "iOS", "link sdk.csproj"))) { Configurations = new string [] { "Debug" /*, "Release" */ }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true });

Expand Down
1 change: 1 addition & 0 deletions tools/common/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ public void RunRegistrar ()

public IEnumerable<Abi> Abis {
get { return abis; }
set { abis = new List<Abi> (value); }
}

public bool IsArchEnabled (Abi arch)
Expand Down
8 changes: 7 additions & 1 deletion tools/dotnet-linker/Compat.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Compat.cs: might not be ideal but it eases code sharing with existing code during the initial implementation.
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

using Mono.Cecil;
using Mono.Linker;
Expand Down Expand Up @@ -160,9 +161,14 @@ public static IEnumerable<AssemblyDefinition> GetAssemblies (this LinkContext co
{
return LinkerConfiguration.GetInstance (context).Assemblies;
}

static ConditionalWeakTable<AnnotationStore, Dictionary<string, Dictionary<IMetadataTokenProvider, object>>> custom_annotations = new ConditionalWeakTable<AnnotationStore, Dictionary<string, Dictionary<IMetadataTokenProvider, object>>> ();
public static Dictionary<IMetadataTokenProvider, object> GetCustomAnnotations (this AnnotationStore self, string name)
{
throw new NotImplementedException ();
var store = custom_annotations.GetOrCreateValue (self);
if (!store.TryGetValue (name, out var dict))
store [name] = dict = new Dictionary<IMetadataTokenProvider, object> ();
return dict;
}
}
}
4 changes: 4 additions & 0 deletions tools/dotnet-linker/LinkerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ public static LinkerConfiguration GetInstance (LinkContext context)
Application.DeploymentTarget = DeploymentTarget;
Application.SdkVersion = SdkVersion;

DerivedLinkContext.Target = Target;
Target.Abis = Abis;
Application.Abis = Abis;

switch (Platform) {
case ApplePlatform.iOS:
case ApplePlatform.TVOS:
Expand Down
1 change: 1 addition & 0 deletions tools/dotnet-linker/SetupStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected override void Process ()
// [assembly: LinkSafe] attributes, which means we treat them as sdk assemblies and those may have
// Preserve attributes.
prelink_substeps.Add (new ApplyPreserveAttribute ());
prelink_substeps.Add (new OptimizeGeneratedCodeSubStep ());
prelink_substeps.Add (new MarkNSObjects ());
prelink_substeps.Add (new PreserveSmartEnumConversionsSubStep ());
}
Expand Down
9 changes: 9 additions & 0 deletions tools/dotnet-linker/dotnet-linker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
<Compile Include="..\linker\CustomSymbolWriter.cs">
<Link>external\tools\linker\CustomSymbolWriter.cs</Link>
</Compile>
<Compile Include="..\linker\CoreOptimizeGeneratedCode.cs">
<Link>external\tools\linker\CoreOptimizeGeneratedCode.cs</Link>
</Compile>
<Compile Include="..\..\src\ObjCRuntime\Registrar.cs">
<Link>external\src\ObjCRuntime\Registrar.cs</Link>
</Compile>
Expand Down Expand Up @@ -164,6 +167,12 @@
<Compile Include="..\..\builds\mono-ios-sdk-destdir\ios-sources\external\linker\src\linker\Linker\I18nAssemblies.cs">
<Link>external\mono-archive\Linker\I18nAssemblies.cs</Link>
</Compile>
<Compile Include="..\..\builds\mono-ios-sdk-destdir\ios-sources\external\linker\src\linker\Linker\MethodDefinitionExtensions.cs">
<Link>mono-archive\Linker\MethodDefinitionExtensions.cs</Link>
</Compile>
<Compile Include="..\..\builds\mono-ios-sdk-destdir\ios-sources\external\linker\src\linker\Linker\TypeReferenceExtensions.cs">
<Link>mono-archive\Linker\Linker\TypeReferenceExtensions.cs</Link>
</Compile>
<Compile Include="..\..\builds\mono-ios-sdk-destdir\ios-sources\external\linker\src\tuner\Mono.Tuner\CecilRocks.cs">
<Link>external\mono-archive\Mono.Tuner\CecilRocks.cs</Link>
</Compile>
Expand Down
2 changes: 1 addition & 1 deletion tools/linker/CoreOptimizeGeneratedCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ protected void EliminateDeadCode (MethodDefinition caller)
}
}
}
#if TRACE
#if false
Console.WriteLine ($"{caller.FullName}:");
for (int i = 0; i < reachable.Length; i++) {
Console.WriteLine ($"{(reachable [i] ? " " : "- ")} {instructions [i]}");
Expand Down