From 65f5ad06c38fbd0a73583a46889419068534446a Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Fri, 17 Feb 2023 16:48:41 +0100 Subject: [PATCH] [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 --- src/mono/mono/mini/aot-compiler.c | 10 ++++++++-- src/mono/mono/mini/aot-runtime.c | 7 ++++++- src/mono/msbuild/apple/build/AppleApp.props | 1 + src/mono/msbuild/apple/build/AppleApp.targets | 20 +++++++++++++++++++ src/mono/sample/iOS/Program.csproj | 15 ++++++++++++++ 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index ae52c47a96f2d..605cec84cde5d 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -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 @@ -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 ++; @@ -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); diff --git a/src/mono/mono/mini/aot-runtime.c b/src/mono/mono/mini/aot-runtime.c index b763ca532c81b..f25c1f2d4485d 100644 --- a/src/mono/mono/mini/aot-runtime.c +++ b/src/mono/mono/mini/aot-runtime.c @@ -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); diff --git a/src/mono/msbuild/apple/build/AppleApp.props b/src/mono/msbuild/apple/build/AppleApp.props index 2d29b16a2ecb8..14045c53611f8 100644 --- a/src/mono/msbuild/apple/build/AppleApp.props +++ b/src/mono/msbuild/apple/build/AppleApp.props @@ -2,6 +2,7 @@ true + true diff --git a/src/mono/msbuild/apple/build/AppleApp.targets b/src/mono/msbuild/apple/build/AppleApp.targets index 7dd0c53d887a6..30d72c6b916a5 100644 --- a/src/mono/msbuild/apple/build/AppleApp.targets +++ b/src/mono/msbuild/apple/build/AppleApp.targets @@ -88,6 +88,25 @@ + + <_iOSLikeDedupAssembly>$(AppleAppDir)\aot-instances.dll + + + + + <_AotInputAssemblies Include="$(_iOSLikeDedupAssembly)"> + @(MonoAOTCompilerDefaultAotArguments, ';') + @(MonoAOTCompilerDefaultProcessArguments, ';') + + + diff --git a/src/mono/sample/iOS/Program.csproj b/src/mono/sample/iOS/Program.csproj index 00f7e447f0409..ec995073d11f0 100644 --- a/src/mono/sample/iOS/Program.csproj +++ b/src/mono/sample/iOS/Program.csproj @@ -6,6 +6,7 @@ ios iossimulator true + true $(TargetOS)-$(TargetArchitecture) $(DefineConstants);CI_TEST HelloiOS @@ -42,6 +43,19 @@ + + <_iOSLikeDedupAssembly>$(MSBuildThisFileDirectory)$(PublishDir)\aot-instances.dll + + + + @@ -62,6 +76,7 @@ Mode="$(AOTMode)" OutputType="AsmOnly" Assemblies="@(AotInputAssemblies)" + DedupAssembly="$(_iOSLikeDedupAssembly)" AotModulesTablePath="$(AppDir)\modules.m" AotModulesTableLanguage="ObjC" OutputDir="$(PublishDir)"