Skip to content

Commit 65f5ad0

Browse files
authored
[mono][aot] Enable dedup by default for iOS (#81319)
* Enable dedup in HelloiOS app * Disable call transformation for MONO_PATCH_INFO_METHOD as some callees require initialization * Fix build warnings * Enable dedup by default for ios
1 parent 9fcbeee commit 65f5ad0

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

src/mono/mono/mini/aot-compiler.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6589,6 +6589,8 @@ emit_and_reloc_code (MonoAotCompile *acfg, MonoMethod *method, guint8 *code, gui
65896589
direct_call_target = symbol;
65906590
patch_info->type = MONO_PATCH_INFO_NONE;
65916591
} else if ((m_class_get_image (patch_info->data.method->klass) == acfg->image) && !got_only && is_direct_callable (acfg, method, patch_info)) {
6592+
#if 0
6593+
// FIXME: Currently not used. It fails as some callees require initialization.
65926594
MonoCompile *callee_cfg = (MonoCompile *)g_hash_table_lookup (acfg->method_to_cfg, cmethod);
65936595

65946596
// Don't compile inflated methods if we're doing dedup
@@ -6602,6 +6604,7 @@ emit_and_reloc_code (MonoAotCompile *acfg, MonoMethod *method, guint8 *code, gui
66026604
patch_info->type = MONO_PATCH_INFO_NONE;
66036605
acfg->stats.direct_calls ++;
66046606
}
6607+
#endif
66056608
}
66066609

66076610
acfg->stats.all_calls ++;
@@ -14891,9 +14894,12 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
1489114894
TV_GETTIME (btv);
1489214895

1489314896
acfg->stats.jit_time = GINT64_TO_INT (TV_ELAPSED (atv, btv));
14894-
14897+
// Current implementation uses dedup_methods hash table for storing extra methods which are emitted in a dedup AOT image.
14898+
// Previously, cfg->skip flag in dedup_skip_methods is used for indicating if a method should be emitted in an AOT image.
14899+
// Method dedup_skip_methods is used only for wasm.
14900+
#ifdef TARGET_WASM
1489514901
dedup_skip_methods (acfg);
14896-
14902+
#endif
1489714903
if (acfg->dedup_collect_only) {
1489814904
/* We only collected methods from this assembly */
1489914905
acfg_free (acfg);

src/mono/mono/mini/aot-runtime.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4492,11 +4492,16 @@ inst_is_private (MonoGenericInst *inst)
44924492
gboolean
44934493
mono_aot_can_dedup (MonoMethod *method)
44944494
{
4495-
#ifdef TARGET_WASM
4495+
// Dedup enabled for wasm and iOS
4496+
#if defined(TARGET_WASM) || defined(TARGET_IOS)
44964497
/* Use a set of wrappers/instances which work and useful */
44974498
switch (method->wrapper_type) {
44984499
case MONO_WRAPPER_RUNTIME_INVOKE:
4500+
#ifdef TARGET_WASM
44994501
return TRUE;
4502+
#else
4503+
return FALSE;
4504+
#endif
45004505
break;
45014506
case MONO_WRAPPER_OTHER: {
45024507
WrapperInfo *info = mono_marshal_get_wrapper_info (method);

src/mono/msbuild/apple/build/AppleApp.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<!-- iOS/tvOS device + arm64 simulators need to AOT -->
33
<PropertyGroup Condition="'$(TargetOS)' == 'ios' or '$(TargetOS)' == 'tvos' or (('$(TargetOS)' == 'iossimulator' or '$(TargetOS)' == 'tvossimulator') And '$(TargetArchitecture)' == 'arm64')">
44
<RunAOTCompilation Condition="'$(RunAOTCompilation)' == ''">true</RunAOTCompilation>
5+
<iOSLikeDedup Condition="'$(RunAOTCompilation)' == 'true' and '$(TargetOS)' == 'ios'">true</iOSLikeDedup>
56
</PropertyGroup>
67

78
<!-- iOS/tvOS arm64 simulators do not support JIT, so force interpreter fallback, devices should FullAOT -->

src/mono/msbuild/apple/build/AppleApp.targets

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@
8888

8989
<MakeDir Directories="$(_MobileIntermediateOutputPath)" />
9090

91+
<PropertyGroup Condition="'$(iOSLikeDedup)' == 'true'">
92+
<_iOSLikeDedupAssembly>$(AppleAppDir)\aot-instances.dll</_iOSLikeDedupAssembly>
93+
</PropertyGroup>
94+
<WriteLinesToFile Condition="'$(iOSLikeDedup)' == 'true'" File="$(_MobileIntermediateOutputPath)/aot-instances.cs" Overwrite="true" Lines="" WriteOnlyWhenDifferent="true" />
95+
<Csc Condition="'$(iOSLikeDedup)' == 'true'"
96+
Sources="$(_MobileIntermediateOutputPath)\aot-instances.cs"
97+
OutputAssembly="$(_iOSLikeDedupAssembly)"
98+
TargetType="library"
99+
Deterministic="true"
100+
References="@(ReferencePath)"
101+
ToolExe="$(CscToolExe)"
102+
ToolPath="$(CscToolPath)" />
103+
<ItemGroup Condition="'$(iOSLikeDedup)' == 'true'">
104+
<_AotInputAssemblies Include="$(_iOSLikeDedupAssembly)">
105+
<AotArguments>@(MonoAOTCompilerDefaultAotArguments, ';')</AotArguments>
106+
<ProcessArguments>@(MonoAOTCompilerDefaultProcessArguments, ';')</ProcessArguments>
107+
</_AotInputAssemblies>
108+
</ItemGroup>
109+
91110
<MonoAOTCompiler Condition="'$(RunAOTCompilation)' == 'true'"
92111
CompilerBinaryPath="@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','$(TargetOS)-$(TargetArchitecture.ToLowerInvariant())'))"
93112
OutputDir="$(_MobileIntermediateOutputPath)"
@@ -98,6 +117,7 @@
98117
AotModulesTableLanguage="ObjC"
99118
UseLLVM="$(MonoEnableLLVM)"
100119
LLVMPath="$(MonoAotCrossDir)"
120+
DedupAssembly="$(_iOSLikeDedupAssembly)"
101121
IntermediateOutputPath="$(_MobileIntermediateOutputPath)">
102122
<Output TaskParameter="CompiledAssemblies" ItemName="_AppleAssembliesInternal" />
103123
</MonoAOTCompiler>

src/mono/sample/iOS/Program.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<TargetOS Condition="'$(TargetOS)' == ''">ios</TargetOS>
77
<TargetOS Condition="'$(TargetsiOSSimulator)' == 'true'">iossimulator</TargetOS>
88
<DeployAndRun Condition="'$(DeployAndRun)' == ''">true</DeployAndRun>
9+
<iOSLikeDedup Condition="'$(TargetOS)' == 'ios'">true</iOSLikeDedup>
910
<RuntimeIdentifier>$(TargetOS)-$(TargetArchitecture)</RuntimeIdentifier>
1011
<DefineConstants Condition="'$(ArchiveTests)' == 'true'">$(DefineConstants);CI_TEST</DefineConstants>
1112
<AppName>HelloiOS</AppName>
@@ -42,6 +43,19 @@
4243

4344
<RemoveDir Directories="$(AppDir)" />
4445

46+
<PropertyGroup Condition="'$(iOSLikeDedup)' == 'true'">
47+
<_iOSLikeDedupAssembly>$(MSBuildThisFileDirectory)$(PublishDir)\aot-instances.dll</_iOSLikeDedupAssembly>
48+
</PropertyGroup>
49+
<WriteLinesToFile Condition="'$(iOSLikeDedup)' == 'true'" File="$(MSBuildThisFileDirectory)$(PublishDir)/aot-instances.cs" Overwrite="true" Lines="" WriteOnlyWhenDifferent="true" />
50+
<Csc Condition="'$(iOSLikeDedup)' == 'true'"
51+
Sources="$(MSBuildThisFileDirectory)$(PublishDir)\aot-instances.cs"
52+
OutputAssembly="$(_iOSLikeDedupAssembly)"
53+
TargetType="library"
54+
Deterministic="true"
55+
References="@(ReferencePath)"
56+
ToolExe="$(CscToolExe)"
57+
ToolPath="$(CscToolPath)" />
58+
4559
<ItemGroup>
4660
<BundleAssemblies Condition="'$(RunAOTCompilation)' != 'true'" Include="$(MSBuildThisFileDirectory)$(PublishDir)\*.dll" />
4761
<AotInputAssemblies Condition="'$(RunAOTCompilation)' == 'true'" Include="$(MSBuildThisFileDirectory)$(PublishDir)\*.dll">
@@ -62,6 +76,7 @@
6276
Mode="$(AOTMode)"
6377
OutputType="AsmOnly"
6478
Assemblies="@(AotInputAssemblies)"
79+
DedupAssembly="$(_iOSLikeDedupAssembly)"
6580
AotModulesTablePath="$(AppDir)\modules.m"
6681
AotModulesTableLanguage="ObjC"
6782
OutputDir="$(PublishDir)"

0 commit comments

Comments
 (0)