Skip to content

Commit

Permalink
[dotnet-linker] Add OptimizeGeneratedCodeSubStep into the pipeline. (#…
Browse files Browse the repository at this point in the history
…9608)

Fixes these linkall tests:

    Linker.Shared.OptimizeGeneratedCodeTest
        [FAIL] IsARM64CallingConvention :   optimized: no ldsfld instruction
        Expected: 0
        But was:  1
            at Linker.Shared.BaseOptimizeGeneratedCodeTest.IsARM64CallingConvention() in /Users/rolf/work/maccore/main/xamarin-macios/tests/linker/BaseOptimizeGeneratedCodeTest.cs:line 527

    [FAIL] SetupBlockPerfTest :   At least 6x speedup
        Expected: greater than 6
        But was:  1.0876440665344851d
            at Linker.Shared.BaseOptimizeGeneratedCodeTest.SetupBlockPerfTest() in /Users/rolf/work/maccore/main/xamarin-macios/tests/linker/BaseOptimizeGeneratedCodeTest.cs:line 120

And linkall is now green for .NET/Debug.
  • Loading branch information
rolfbjarne authored and mandel-macaque committed Oct 21, 2020
1 parent 282dbda commit 83fb8df
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
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 @@ -595,6 +595,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 @@ -101,9 +102,14 @@ public static IEnumerable<AssemblyDefinition> GetAssemblies (this LinkContext co
{
throw new NotImplementedException ();
}

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 @@ -176,6 +176,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
19 changes: 19 additions & 0 deletions tools/dotnet-linker/SetupStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ protected override void Process ()
// Don't use --custom-step to load each step, because this assembly
// is loaded into the current process once per --custom-step,
// which makes it very difficult to share state between steps.

// Load the list of assemblies loaded by the linker.
// This would not be needed of LinkContext.GetAssemblies () was exposed to us.
InsertAfter (new CollectAssembliesStep (), "LoadReferencesStep");

var prelink_substeps = new DotNetSubStepDispatcher ();
InsertAfter (prelink_substeps, "RemoveSecurityStep");

if (Configuration.LinkMode != LinkMode.None) {
// We need to run the ApplyPreserveAttribute step even we're only linking sdk assemblies, because even
// though we know that sdk assemblies will never have Preserve attributes, user assemblies may have
// [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 ());
}

Steps.Add (new LoadNonSkippedAssembliesStep ());
Steps.Add (new ExtractBindingLibrariesStep ());
Steps.Add (new GenerateMainStep ());
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 @@ -95,6 +95,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 @@ -146,6 +149,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 @@ -566,7 +566,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

0 comments on commit 83fb8df

Please sign in to comment.