Skip to content

Commit

Permalink
[mono][aot] Enable dedup by default for iOS (#81319)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kotlarmilos authored Feb 17, 2023
1 parent 9fcbeee commit 65f5ad0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -6589,6 +6589,8 @@ emit_and_reloc_code (MonoAotCompile *acfg, MonoMethod *method, guint8 *code, gui
direct_call_target = symbol;
patch_info->type = MONO_PATCH_INFO_NONE;
} else if ((m_class_get_image (patch_info->data.method->klass) == acfg->image) && !got_only && is_direct_callable (acfg, method, patch_info)) {
#if 0
// FIXME: Currently not used. It fails as some callees require initialization.
MonoCompile *callee_cfg = (MonoCompile *)g_hash_table_lookup (acfg->method_to_cfg, cmethod);

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

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

acfg->stats.jit_time = GINT64_TO_INT (TV_ELAPSED (atv, btv));

// Current implementation uses dedup_methods hash table for storing extra methods which are emitted in a dedup AOT image.
// Previously, cfg->skip flag in dedup_skip_methods is used for indicating if a method should be emitted in an AOT image.
// Method dedup_skip_methods is used only for wasm.
#ifdef TARGET_WASM
dedup_skip_methods (acfg);

#endif
if (acfg->dedup_collect_only) {
/* We only collected methods from this assembly */
acfg_free (acfg);
Expand Down
7 changes: 6 additions & 1 deletion src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -4492,11 +4492,16 @@ inst_is_private (MonoGenericInst *inst)
gboolean
mono_aot_can_dedup (MonoMethod *method)
{
#ifdef TARGET_WASM
// Dedup enabled for wasm and iOS
#if defined(TARGET_WASM) || defined(TARGET_IOS)
/* Use a set of wrappers/instances which work and useful */
switch (method->wrapper_type) {
case MONO_WRAPPER_RUNTIME_INVOKE:
#ifdef TARGET_WASM
return TRUE;
#else
return FALSE;
#endif
break;
case MONO_WRAPPER_OTHER: {
WrapperInfo *info = mono_marshal_get_wrapper_info (method);
Expand Down
1 change: 1 addition & 0 deletions src/mono/msbuild/apple/build/AppleApp.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<!-- iOS/tvOS device + arm64 simulators need to AOT -->
<PropertyGroup Condition="'$(TargetOS)' == 'ios' or '$(TargetOS)' == 'tvos' or (('$(TargetOS)' == 'iossimulator' or '$(TargetOS)' == 'tvossimulator') And '$(TargetArchitecture)' == 'arm64')">
<RunAOTCompilation Condition="'$(RunAOTCompilation)' == ''">true</RunAOTCompilation>
<iOSLikeDedup Condition="'$(RunAOTCompilation)' == 'true' and '$(TargetOS)' == 'ios'">true</iOSLikeDedup>
</PropertyGroup>

<!-- iOS/tvOS arm64 simulators do not support JIT, so force interpreter fallback, devices should FullAOT -->
Expand Down
20 changes: 20 additions & 0 deletions src/mono/msbuild/apple/build/AppleApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@

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

<PropertyGroup Condition="'$(iOSLikeDedup)' == 'true'">
<_iOSLikeDedupAssembly>$(AppleAppDir)\aot-instances.dll</_iOSLikeDedupAssembly>
</PropertyGroup>
<WriteLinesToFile Condition="'$(iOSLikeDedup)' == 'true'" File="$(_MobileIntermediateOutputPath)/aot-instances.cs" Overwrite="true" Lines="" WriteOnlyWhenDifferent="true" />
<Csc Condition="'$(iOSLikeDedup)' == 'true'"
Sources="$(_MobileIntermediateOutputPath)\aot-instances.cs"
OutputAssembly="$(_iOSLikeDedupAssembly)"
TargetType="library"
Deterministic="true"
References="@(ReferencePath)"
ToolExe="$(CscToolExe)"
ToolPath="$(CscToolPath)" />
<ItemGroup Condition="'$(iOSLikeDedup)' == 'true'">
<_AotInputAssemblies Include="$(_iOSLikeDedupAssembly)">
<AotArguments>@(MonoAOTCompilerDefaultAotArguments, ';')</AotArguments>
<ProcessArguments>@(MonoAOTCompilerDefaultProcessArguments, ';')</ProcessArguments>
</_AotInputAssemblies>
</ItemGroup>

<MonoAOTCompiler Condition="'$(RunAOTCompilation)' == 'true'"
CompilerBinaryPath="@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','$(TargetOS)-$(TargetArchitecture.ToLowerInvariant())'))"
OutputDir="$(_MobileIntermediateOutputPath)"
Expand All @@ -98,6 +117,7 @@
AotModulesTableLanguage="ObjC"
UseLLVM="$(MonoEnableLLVM)"
LLVMPath="$(MonoAotCrossDir)"
DedupAssembly="$(_iOSLikeDedupAssembly)"
IntermediateOutputPath="$(_MobileIntermediateOutputPath)">
<Output TaskParameter="CompiledAssemblies" ItemName="_AppleAssembliesInternal" />
</MonoAOTCompiler>
Expand Down
15 changes: 15 additions & 0 deletions src/mono/sample/iOS/Program.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<TargetOS Condition="'$(TargetOS)' == ''">ios</TargetOS>
<TargetOS Condition="'$(TargetsiOSSimulator)' == 'true'">iossimulator</TargetOS>
<DeployAndRun Condition="'$(DeployAndRun)' == ''">true</DeployAndRun>
<iOSLikeDedup Condition="'$(TargetOS)' == 'ios'">true</iOSLikeDedup>
<RuntimeIdentifier>$(TargetOS)-$(TargetArchitecture)</RuntimeIdentifier>
<DefineConstants Condition="'$(ArchiveTests)' == 'true'">$(DefineConstants);CI_TEST</DefineConstants>
<AppName>HelloiOS</AppName>
Expand Down Expand Up @@ -42,6 +43,19 @@

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

<PropertyGroup Condition="'$(iOSLikeDedup)' == 'true'">
<_iOSLikeDedupAssembly>$(MSBuildThisFileDirectory)$(PublishDir)\aot-instances.dll</_iOSLikeDedupAssembly>
</PropertyGroup>
<WriteLinesToFile Condition="'$(iOSLikeDedup)' == 'true'" File="$(MSBuildThisFileDirectory)$(PublishDir)/aot-instances.cs" Overwrite="true" Lines="" WriteOnlyWhenDifferent="true" />
<Csc Condition="'$(iOSLikeDedup)' == 'true'"
Sources="$(MSBuildThisFileDirectory)$(PublishDir)\aot-instances.cs"
OutputAssembly="$(_iOSLikeDedupAssembly)"
TargetType="library"
Deterministic="true"
References="@(ReferencePath)"
ToolExe="$(CscToolExe)"
ToolPath="$(CscToolPath)" />

<ItemGroup>
<BundleAssemblies Condition="'$(RunAOTCompilation)' != 'true'" Include="$(MSBuildThisFileDirectory)$(PublishDir)\*.dll" />
<AotInputAssemblies Condition="'$(RunAOTCompilation)' == 'true'" Include="$(MSBuildThisFileDirectory)$(PublishDir)\*.dll">
Expand All @@ -62,6 +76,7 @@
Mode="$(AOTMode)"
OutputType="AsmOnly"
Assemblies="@(AotInputAssemblies)"
DedupAssembly="$(_iOSLikeDedupAssembly)"
AotModulesTablePath="$(AppDir)\modules.m"
AotModulesTableLanguage="ObjC"
OutputDir="$(PublishDir)"
Expand Down

0 comments on commit 65f5ad0

Please sign in to comment.