From 1fb4e28002327c1224c3ed32783160b011f14747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Mon, 13 Jul 2020 11:43:24 +0900 Subject: skip inlining cexpr! that are not attr! inline Requested by ko1. --- builtin.h | 2 +- tool/mk_builtin_loader.rb | 48 ++++++++++++---------- tool/ruby_vm/views/_mjit_compile_invokebuiltin.erb | 2 +- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/builtin.h b/builtin.h index 607458ea71..3b2f477654 100644 --- a/builtin.h +++ b/builtin.h @@ -13,7 +13,7 @@ struct rb_builtin_function { const char * const name; // for jit - void (*compiler)(FILE *, long, unsigned); + void (*compiler)(FILE *, long, unsigned, bool); }; #define RB_BUILTIN_FUNCTION(_i, _name, _fname, _arity, _compiler) {\ diff --git a/tool/mk_builtin_loader.rb b/tool/mk_builtin_loader.rb index 271c47f9ad..fd8085086e 100644 --- a/tool/mk_builtin_loader.rb +++ b/tool/mk_builtin_loader.rb @@ -285,35 +285,39 @@ def mk_builtin_header file } bs.each_pair{|func, (argc, cfunc_name)| + decl = ', VALUE' * argc + argv = argc \ + . times \ + . map {|i|", argv[#{i}]"} \ + . join('') f.puts %'static void' - f.puts %'mjit_compile_invokebuiltin_for_#{func}(FILE *f, long index, unsigned stack_size)' + f.puts %'mjit_compile_invokebuiltin_for_#{func}(FILE *f, long index, unsigned stack_size, bool inlinable_p)' f.puts %'{' + f.puts %' fprintf(f, " VALUE self = GET_SELF();\\n");' + f.puts %' fprintf(f, " typedef VALUE (*func)(rb_execution_context_t *, VALUE#{decl});\\n");' if inlines.has_key? cfunc_name - f.puts %' fprintf(f, " MAYBE_UNUSED(VALUE) self = GET_SELF();\\n");' body_lineno, text, locals, func_name = inlines[cfunc_name] lineno, str = generate_cexpr(ofile, lineno, line_file, body_lineno, text, locals, func_name) - str.each_line {|i| - f.printf(%' fprintf(f, "%%s", %s);\n', RubyVM::CEscape.rstring2cstr(i.sub(/^return\b/ , ' val ='))) + f.puts %' if (inlinable_p) {' + str.gsub(/^(?!#)/, ' ').each_line {|i| + j = RubyVM::CEscape.rstring2cstr(i).dup + j.sub!(/^ return\b/ , ' val =') + f.printf(%' fprintf(f, "%%s", %s);\n', j) } - else - decl = ', VALUE' * argc - argv = argc \ - . times \ - . map {|i|", argv[#{i}]"} \ - . join('') - f.puts %' fprintf(f, " typedef VALUE (*func)(rb_execution_context_t *, VALUE#{decl});\\n");' - if argc > 0 - f.puts %' if (index == -1) {' - f.puts %' fprintf(f, " const VALUE *argv = &stack[%d];\\n", stack_size - #{argc});' - f.puts %' }' - f.puts %' else {' - f.puts %' fprintf(f, " const unsigned int lnum = GET_ISEQ()->body->local_table_size;\\n");' - f.puts %' fprintf(f, " const VALUE *argv = GET_EP() - lnum - VM_ENV_DATA_SIZE + 1 + %ld;\\n", index);' - f.puts %' }' - end - f.puts %' fprintf(f, " func f = (func)%"PRIdPTR"; /* == #{cfunc_name} */\\n", (intptr_t)#{cfunc_name});' - f.puts %' fprintf(f, " val = f(ec, GET_SELF()#{argv});\\n");' + f.puts(%' return;') + f.puts(%' }') + end + if argc > 0 + f.puts %' if (index == -1) {' + f.puts %' fprintf(f, " const VALUE *argv = &stack[%d];\\n", stack_size - #{argc});' + f.puts %' }' + f.puts %' else {' + f.puts %' fprintf(f, " const unsigned int lnum = GET_ISEQ()->body->local_table_size;\\n");' + f.puts %' fprintf(f, " const VALUE *argv = GET_EP() - lnum - VM_ENV_DATA_SIZE + 1 + %ld;\\n", index);' + f.puts %' }' end + f.puts %' fprintf(f, " func f = (func)%"PRIdPTR"; /* == #{cfunc_name} */\\n", (intptr_t)#{cfunc_name});' + f.puts %' fprintf(f, " val = f(ec, self#{argv});\\n");' f.puts %'}' f.puts } diff --git a/tool/ruby_vm/views/_mjit_compile_invokebuiltin.erb b/tool/ruby_vm/views/_mjit_compile_invokebuiltin.erb index 9a9e53af40..a3796ffc5e 100644 --- a/tool/ruby_vm/views/_mjit_compile_invokebuiltin.erb +++ b/tool/ruby_vm/views/_mjit_compile_invokebuiltin.erb @@ -19,7 +19,7 @@ fprintf(f, " VALUE val;\n"); bf->compiler(f, <%= insn.name == 'invokebuiltin' ? '-1' : '(rb_num_t)operands[1]' - %>, b->stack_size); + %>, b->stack_size, body->builtin_inline_p); fprintf(f, " stack[%u] = val;\n", sp - 1); fprintf(f, "}\n"); % if insn.name != 'opt_invokebuiltin_delegate_leave' -- cgit v1.2.1