ruby-changes:51838
From: k0kubun <ko1@a...>
Date: Wed, 25 Jul 2018 23:36:14 +0900 (JST)
Subject: [ruby-changes:51838] k0kubun:r64052 (trunk): mjit.c: split build stages for unix
k0kubun 2018-07-25 23:36:08 +0900 (Wed, 25 Jul 2018) New Revision: 64052 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64052 Log: mjit.c: split build stages for unix I'm going to build a large .so file that combines multiple .o files. For that change, I want to confirm the impact to performance by this change. So far, I haven't seen the significant change on the max performance. * before $ for i in 1 2 3 4 5 6 7 8 9 1 2; do ruby --jit ../../mame/optcarrot/bin/optcarrot --benchmark ../../mame/optcarrot/examples/Lan_Master.nes; done fps: 67.66058054621772 checksum: 59662 fps: 67.53138656233348 checksum: 59662 fps: 67.44109425628592 checksum: 59662 fps: 70.29423063961576 checksum: 59662 fps: 72.0147653358158 checksum: 59662 fps: 69.40157398157892 checksum: 59662 fps: 72.3984212467565 checksum: 59662 fps: 67.15473484463604 checksum: 59662 fps: 70.14142014098444 checksum: 59662 fps: 72.51761974327023 checksum: 59662 fps: 72.41086970333218 checksum: 59662 * after $ for i in 1 2 3 4 5 6 7 8 9 1 2; do ruby --jit ../../mame/optcarrot/bin/optcarrot --benchmark ../../mame/optcarrot/examples/Lan_Master.nes; done fps: 69.53134628999938 checksum: 59662 fps: 66.13157649232654 checksum: 59662 fps: 70.17474368971281 checksum: 59662 fps: 61.88316323809907 checksum: 59662 fps: 72.48731307319704 checksum: 59662 fps: 65.1180687907147 checksum: 59662 fps: 68.89553415996615 checksum: 59662 fps: 65.77342314036225 checksum: 59662 fps: 64.33337015048106 checksum: 59662 fps: 64.98152672793444 checksum: 59662 fps: 72.225729092625 checksum: 59662 Modified files: trunk/mjit.c Index: mjit.c =================================================================== --- mjit.c (revision 64051) +++ mjit.c (revision 64052) @@ -777,9 +777,9 @@ compile_c_to_so(const char *c_file, cons https://github.com/ruby/ruby/blob/trunk/mjit.c#L777 #else -/* Compile C file to so. It returns 1 if it succeeds. (non-mswin) */ +/* Compile .c file to .o file. It returns 1 if it succeeds. (non-mswin) */ static int -compile_c_to_so(const char *c_file, const char *so_file) +compile_c_to_o(const char *c_file, const char *o_file) { int exit_code; const char *files[] = { @@ -787,18 +787,43 @@ compile_c_to_so(const char *c_file, cons https://github.com/ruby/ruby/blob/trunk/mjit.c#L787 # ifdef __clang__ "-include-pch", NULL, # endif -# ifdef _WIN32 - libruby_pathflag, -# endif - NULL, + "-c", NULL }; char **args; + files[1] = o_file; + files[2] = c_file; # ifdef __clang__ files[4] = pch_file; # endif - files[2] = c_file; + args = form_args(5, CC_COMMON_ARGS, CC_CODEFLAG_ARGS, files, CC_LIBS, CC_DLDFLAGS_ARGS); + if (args == NULL) + return FALSE; + + exit_code = exec_process(cc_path, args); + free(args); + + if (exit_code != 0) + verbose(2, "compile_c_to_o: compile error: %d", exit_code); + return exit_code == 0; +} + +/* Compile .o file to .so file. It returns 1 if it succeeds. (non-mswin) */ +static int +compile_o_to_so(const char *o_file, const char *so_file) +{ + int exit_code; + const char *files[] = { + "-o", NULL, NULL, +# ifdef _WIN32 + libruby_pathflag, +# endif + NULL + }; + char **args; + files[1] = so_file; + files[2] = o_file; args = form_args(5, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS, files, CC_LIBS, CC_DLDFLAGS_ARGS); if (args == NULL) @@ -808,7 +833,7 @@ compile_c_to_so(const char *c_file, cons https://github.com/ruby/ruby/blob/trunk/mjit.c#L833 free(args); if (exit_code != 0) - verbose(2, "compile_c_to_so: compile error: %d", exit_code); + verbose(2, "compile_o_to_so: compile error: %d", exit_code); return exit_code == 0; } @@ -886,6 +911,10 @@ convert_unit_to_func(struct rb_mjit_unit https://github.com/ruby/ruby/blob/trunk/mjit.c#L911 O_BINARY| #endif O_WRONLY|O_EXCL|O_CREAT; +#ifndef _MSC_VER + static const char o_ext[] = ".o"; + char *o_file; +#endif c_file_len = sprint_uniq_filename(c_file_buff, c_file_len, unit->id, MJIT_TMP_PREFIX, c_ext); if (c_file_len >= (int)sizeof(c_file_buff)) { @@ -894,9 +923,16 @@ convert_unit_to_func(struct rb_mjit_unit https://github.com/ruby/ruby/blob/trunk/mjit.c#L923 c_file_len = sprint_uniq_filename(c_file, c_file_len, unit->id, MJIT_TMP_PREFIX, c_ext); } ++c_file_len; + +#ifndef _MSC_VER + o_file = alloca(c_file_len - sizeof(c_ext) + sizeof(o_ext)); + memcpy(o_file, c_file, c_file_len - sizeof(c_ext)); + memcpy(&o_file[c_file_len - sizeof(c_ext)], o_ext, sizeof(o_ext)); +#endif so_file = alloca(c_file_len - sizeof(c_ext) + sizeof(so_ext)); memcpy(so_file, c_file, c_file_len - sizeof(c_ext)); memcpy(&so_file[c_file_len - sizeof(c_ext)], so_ext, sizeof(so_ext)); + sprintf(funcname, "_mjit%d", unit->id); fd = rb_cloexec_open(c_file, access_mode, 0600); @@ -971,7 +1007,16 @@ convert_unit_to_func(struct rb_mjit_unit https://github.com/ruby/ruby/blob/trunk/mjit.c#L1007 } start_time = real_ms_time(); +#ifdef _MSC_VER success = compile_c_to_so(c_file, so_file); +#else + /* splitting .c -> .o and .o -> .so to cache .o files in the future */ + success = compile_c_to_o(c_file, o_file) + && compile_o_to_so(o_file, so_file); + + if (!mjit_opts.save_temps) + remove_file(o_file); +#endif end_time = real_ms_time(); if (!mjit_opts.save_temps) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/