summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-25 14:36:08 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-25 14:36:08 +0000
commit218aa03c0f0b10152616b61939a18f3e479316ba (patch)
tree46d8c935fadc3968f665ef37a7a7ee5e8da9cc42
parent40bb70c7ebd53598582653f94d438e2b34ec627f (diff)
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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--mjit.c61
1 files changed, 53 insertions, 8 deletions
diff --git a/mjit.c b/mjit.c
index 3a5d8fb..36ffae4 100644
--- a/mjit.c
+++ b/mjit.c
@@ -777,9 +777,9 @@ compile_c_to_so(const char *c_file, const char *so_file)
#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, const char *so_file)
# 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, const char *so_file)
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 *unit)
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 *unit)
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 *unit)
}
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)