From 13e8543e7a78cabf84ce07b8491fd2f8252768b5 Mon Sep 17 00:00:00 2001 From: Fan Yang Date: Thu, 2 Feb 2023 16:19:09 -0500 Subject: [PATCH 1/3] Initial setup --- src/mono/mono/mini/aot-compiler.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index c11cacbb18dc34..74d0ddf59eabbb 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -188,6 +188,7 @@ typedef struct MonoAotOptions { char *llvm_outfile; char *data_outfile; char *export_symbols_outfile; + char *compiled_method_names_outpath; GList *profile_files; GList *mibc_profile_files; gboolean save_temps; @@ -404,6 +405,7 @@ typedef struct MonoAotCompile { FILE *logfile; FILE *instances_logfile; FILE *data_outfile; + FILE *compiled_method_names_outfile; int datafile_offset; int gc_name_offset; // In this mode, we are emitting dedupable methods that we encounter @@ -8433,6 +8435,8 @@ mono_aot_parse_options (const char *aot_options, MonoAotOptions *opts) opts->llvm_outfile = g_strdup (arg + strlen ("llvm-outfile=")); } else if (str_begins_with (arg, "export-symbols-outfile=")) { opts->export_symbols_outfile = g_strdup (arg + strlen ("export-symbols-outfile=")); + } else if (str_begins_with (arg, "compiled-method-names-outpath=")) { + opts->compiled_method_names_outpath = g_strdup (arg + strlen ("compiled-method-names-outpath=")); } else if (str_begins_with (arg, "temp-path=")) { opts->temp_path = clean_path (g_strdup (arg + strlen ("temp-path="))); } else if (str_begins_with (arg, "save-temps")) { @@ -9425,6 +9429,10 @@ compile_method (MonoAotCompile *acfg, MonoMethod *method) mono_acfg_unlock (acfg); mono_atomic_inc_i32 (&acfg->stats.ccount); + + if (acfg->aot_opts.compiled_method_names_outpath){ + fprintf (acfg->compiled_method_names_outfile, "%x\n", method->token); + } } static mono_thread_start_return_t WINAPI @@ -14142,6 +14150,14 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options) acfg->logfile = fopen (acfg->aot_opts.logfile, "a+"); } + if (acfg->aot_opts.compiled_method_names_outpath) { + char *assembly_file_name = g_path_get_basename (image->name); + g_strdelimit (assembly_file_name, '.', '_'); + char *filename = g_strconcat (assembly_file_name, "_compiled_method_names.txt", (const char*)NULL); + char *fullpath = g_strconcat (acfg->aot_opts.compiled_method_names_outpath, G_DIR_SEPARATOR_S, filename, (const char*)NULL); + acfg->compiled_method_names_outfile = fopen (fullpath, "w+"); + } + if (acfg->aot_opts.data_outfile) { acfg->data_outfile = fopen (acfg->aot_opts.data_outfile, "w+"); if (!acfg->data_outfile) { @@ -14455,6 +14471,10 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options) current_acfg = NULL; + if (acfg->aot_opts.compiled_method_names_outpath) { + fclose (acfg->compiled_method_names_outfile); + } + return emit_aot_image (acfg); } @@ -14818,6 +14838,13 @@ mono_aot_assemblies (MonoAssembly **assemblies, int nassemblies, guint32 jit_opt dedup_methods = g_hash_table_new (NULL, NULL); } + if (aot_opts.compiled_method_names_outpath) { + if (g_ensure_directory_exists (aot_opts.compiled_method_names_outpath) == FALSE) { + fprintf (stderr, "AOT : failed to create the directory to save the compiled method names: %s\n", aot_opts.compiled_method_names_outpath); + exit (1); + } + } + for (int i = 0; i < nassemblies; ++i) { res = aot_assembly (assemblies [i], jit_opts, &aot_opts); if (res != 0) { From 630c37598abce740174c729cab05312aec7e88fd Mon Sep 17 00:00:00 2001 From: Fan Yang Date: Thu, 2 Feb 2023 16:39:56 -0500 Subject: [PATCH 2/3] Exclude generics and update variable names --- src/mono/mono/mini/aot-compiler.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index 74d0ddf59eabbb..96daddfe63924f 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -188,7 +188,7 @@ typedef struct MonoAotOptions { char *llvm_outfile; char *data_outfile; char *export_symbols_outfile; - char *compiled_method_names_outpath; + char *compiled_methods_outpath; GList *profile_files; GList *mibc_profile_files; gboolean save_temps; @@ -405,7 +405,7 @@ typedef struct MonoAotCompile { FILE *logfile; FILE *instances_logfile; FILE *data_outfile; - FILE *compiled_method_names_outfile; + FILE *compiled_methods_outfile; int datafile_offset; int gc_name_offset; // In this mode, we are emitting dedupable methods that we encounter @@ -8435,8 +8435,8 @@ mono_aot_parse_options (const char *aot_options, MonoAotOptions *opts) opts->llvm_outfile = g_strdup (arg + strlen ("llvm-outfile=")); } else if (str_begins_with (arg, "export-symbols-outfile=")) { opts->export_symbols_outfile = g_strdup (arg + strlen ("export-symbols-outfile=")); - } else if (str_begins_with (arg, "compiled-method-names-outpath=")) { - opts->compiled_method_names_outpath = g_strdup (arg + strlen ("compiled-method-names-outpath=")); + } else if (str_begins_with (arg, "compiled-methods-outpath=")) { + opts->compiled_methods_outpath = g_strdup (arg + strlen ("compiled-methods-outpath=")); } else if (str_begins_with (arg, "temp-path=")) { opts->temp_path = clean_path (g_strdup (arg + strlen ("temp-path="))); } else if (str_begins_with (arg, "save-temps")) { @@ -9430,8 +9430,9 @@ compile_method (MonoAotCompile *acfg, MonoMethod *method) mono_atomic_inc_i32 (&acfg->stats.ccount); - if (acfg->aot_opts.compiled_method_names_outpath){ - fprintf (acfg->compiled_method_names_outfile, "%x\n", method->token); + if (acfg->aot_opts.compiled_methods_outpath){ + if (!mono_method_is_generic_impl (method)) + fprintf (acfg->compiled_methods_outfile, "%x\n", method->token); } } @@ -14150,12 +14151,12 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options) acfg->logfile = fopen (acfg->aot_opts.logfile, "a+"); } - if (acfg->aot_opts.compiled_method_names_outpath) { + if (acfg->aot_opts.compiled_methods_outpath) { char *assembly_file_name = g_path_get_basename (image->name); g_strdelimit (assembly_file_name, '.', '_'); - char *filename = g_strconcat (assembly_file_name, "_compiled_method_names.txt", (const char*)NULL); - char *fullpath = g_strconcat (acfg->aot_opts.compiled_method_names_outpath, G_DIR_SEPARATOR_S, filename, (const char*)NULL); - acfg->compiled_method_names_outfile = fopen (fullpath, "w+"); + char *filename = g_strconcat (assembly_file_name, "_compiled_methods.txt", (const char*)NULL); + char *fullpath = g_strconcat (acfg->aot_opts.compiled_methods_outpath, G_DIR_SEPARATOR_S, filename, (const char*)NULL); + acfg->compiled_methods_outfile = fopen (fullpath, "w+"); } if (acfg->aot_opts.data_outfile) { @@ -14471,8 +14472,8 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options) current_acfg = NULL; - if (acfg->aot_opts.compiled_method_names_outpath) { - fclose (acfg->compiled_method_names_outfile); + if (acfg->aot_opts.compiled_methods_outpath) { + fclose (acfg->compiled_methods_outfile); } return emit_aot_image (acfg); @@ -14838,9 +14839,9 @@ mono_aot_assemblies (MonoAssembly **assemblies, int nassemblies, guint32 jit_opt dedup_methods = g_hash_table_new (NULL, NULL); } - if (aot_opts.compiled_method_names_outpath) { - if (g_ensure_directory_exists (aot_opts.compiled_method_names_outpath) == FALSE) { - fprintf (stderr, "AOT : failed to create the directory to save the compiled method names: %s\n", aot_opts.compiled_method_names_outpath); + if (aot_opts.compiled_methods_outpath) { + if (g_ensure_directory_exists (aot_opts.compiled_methods_outpath) == FALSE) { + fprintf (stderr, "AOT : failed to create the directory to save the compiled method names: %s\n", aot_opts.compiled_methods_outpath); exit (1); } } From 7902195e83974ce92b09c3e880b868a8c70ab409 Mon Sep 17 00:00:00 2001 From: Fan Yang Date: Fri, 3 Feb 2023 17:37:06 -0500 Subject: [PATCH 3/3] Review feedbacks and error handling --- src/mono/mono/mini/aot-compiler.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index 96daddfe63924f..96a8a6468fc2bd 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -188,7 +188,7 @@ typedef struct MonoAotOptions { char *llvm_outfile; char *data_outfile; char *export_symbols_outfile; - char *compiled_methods_outpath; + char *compiled_methods_outfile; GList *profile_files; GList *mibc_profile_files; gboolean save_temps; @@ -8435,8 +8435,8 @@ mono_aot_parse_options (const char *aot_options, MonoAotOptions *opts) opts->llvm_outfile = g_strdup (arg + strlen ("llvm-outfile=")); } else if (str_begins_with (arg, "export-symbols-outfile=")) { opts->export_symbols_outfile = g_strdup (arg + strlen ("export-symbols-outfile=")); - } else if (str_begins_with (arg, "compiled-methods-outpath=")) { - opts->compiled_methods_outpath = g_strdup (arg + strlen ("compiled-methods-outpath=")); + } else if (str_begins_with (arg, "compiled-methods-outfile=")) { + opts->compiled_methods_outfile = g_strdup (arg + strlen ("compiled-methods-outfile=")); } else if (str_begins_with (arg, "temp-path=")) { opts->temp_path = clean_path (g_strdup (arg + strlen ("temp-path="))); } else if (str_begins_with (arg, "save-temps")) { @@ -9430,8 +9430,8 @@ compile_method (MonoAotCompile *acfg, MonoMethod *method) mono_atomic_inc_i32 (&acfg->stats.ccount); - if (acfg->aot_opts.compiled_methods_outpath){ - if (!mono_method_is_generic_impl (method)) + if (acfg->aot_opts.compiled_methods_outfile && acfg->compiled_methods_outfile != NULL) { + if (!mono_method_is_generic_impl (method) && method->token != 0) fprintf (acfg->compiled_methods_outfile, "%x\n", method->token); } } @@ -14151,12 +14151,10 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options) acfg->logfile = fopen (acfg->aot_opts.logfile, "a+"); } - if (acfg->aot_opts.compiled_methods_outpath) { - char *assembly_file_name = g_path_get_basename (image->name); - g_strdelimit (assembly_file_name, '.', '_'); - char *filename = g_strconcat (assembly_file_name, "_compiled_methods.txt", (const char*)NULL); - char *fullpath = g_strconcat (acfg->aot_opts.compiled_methods_outpath, G_DIR_SEPARATOR_S, filename, (const char*)NULL); - acfg->compiled_methods_outfile = fopen (fullpath, "w+"); + if (acfg->aot_opts.compiled_methods_outfile && !acfg->dedup_collect_only) { + acfg->compiled_methods_outfile = fopen (acfg->aot_opts.compiled_methods_outfile, "w+"); + if (!acfg->compiled_methods_outfile) + aot_printerrf (acfg, "Unable to open compiled-methods-outfile specified file %s\n", acfg->aot_opts.compiled_methods_outfile); } if (acfg->aot_opts.data_outfile) { @@ -14472,7 +14470,7 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options) current_acfg = NULL; - if (acfg->aot_opts.compiled_methods_outpath) { + if (acfg->compiled_methods_outfile) { fclose (acfg->compiled_methods_outfile); } @@ -14839,9 +14837,9 @@ mono_aot_assemblies (MonoAssembly **assemblies, int nassemblies, guint32 jit_opt dedup_methods = g_hash_table_new (NULL, NULL); } - if (aot_opts.compiled_methods_outpath) { - if (g_ensure_directory_exists (aot_opts.compiled_methods_outpath) == FALSE) { - fprintf (stderr, "AOT : failed to create the directory to save the compiled method names: %s\n", aot_opts.compiled_methods_outpath); + if (aot_opts.compiled_methods_outfile) { + if (g_ensure_directory_exists (aot_opts.compiled_methods_outfile) == FALSE) { + fprintf (stderr, "AOT : failed to create the directory to save the compiled method names: %s\n", aot_opts.compiled_methods_outfile); exit (1); } }