ruby-changes:50265
From: k0kubun <ko1@a...>
Date: Mon, 12 Feb 2018 15:54:31 +0900 (JST)
Subject: [ruby-changes:50265] k0kubun:r62383 (trunk): _mjit_compile_insn_line.erb: carve out macro expansion
k0kubun 2018-02-12 15:54:25 +0900 (Mon, 12 Feb 2018) New Revision: 62383 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62383 Log: _mjit_compile_insn_line.erb: carve out macro expansion in _mjit_compile_insn.erb to this file. As I'm going to add macro expansions later, I want to separate such complex things from whole insn compilation. _mjit_compile_insn.erb: _mjit_compile_insn_line.erb part was removed. common.mk: updated build system for them. Added files: trunk/tool/ruby_vm/views/_mjit_compile_insn_line.erb Modified files: trunk/common.mk trunk/tool/ruby_vm/views/_mjit_compile_insn.erb Index: common.mk =================================================================== --- common.mk (revision 62382) +++ common.mk (revision 62383) @@ -926,7 +926,9 @@ $(srcs_vpath)insns.inc: $(srcdir)/tool/r https://github.com/ruby/ruby/blob/trunk/common.mk#L926 $(srcs_vpath)insns_info.inc: $(srcdir)/tool/ruby_vm/views/insns_info.inc.erb $(srcs_vpath)vmtc.inc: $(srcdir)/tool/ruby_vm/views/vmtc.inc.erb $(srcs_vpath)vm.inc: $(srcdir)/tool/ruby_vm/views/vm.inc.erb -$(srcs_vpath)mjit_compile.inc: $(srcdir)/tool/ruby_vm/views/mjit_compile.inc.erb $(srcdir)/tool/ruby_vm/views/_mjit_compile_insn.erb $(srcdir)/tool/ruby_vm/views/_mjit_compile_send.erb +$(srcs_vpath)mjit_compile.inc: $(srcdir)/tool/ruby_vm/views/mjit_compile.inc.erb \ + $(srcdir)/tool/ruby_vm/views/_mjit_compile_insn.erb $(srcdir)/tool/ruby_vm/views/_mjit_compile_send.erb \ + $(srcdir)/tool/ruby_vm/views/_mjit_compile_insn_line.erb common-srcs: $(srcs_vpath)parse.c $(srcs_vpath)lex.c $(srcs_vpath)enc/trans/newline.c $(srcs_vpath)id.c \ srcs-lib srcs-ext incs Index: tool/ruby_vm/views/_mjit_compile_insn.erb =================================================================== --- tool/ruby_vm/views/_mjit_compile_insn.erb (revision 62382) +++ tool/ruby_vm/views/_mjit_compile_insn.erb (revision 62383) @@ -13,12 +13,6 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_mjit_compile_insn.erb#L13 % 'invokesuper', % ] % -% to_cstr = lambda do |line| -% normalized = line.gsub(/\t/, ' ' * 8) -% indented = normalized.sub(/\A(?!#)/, ' ') # avoid indenting preprocessor -% rstring2cstr(indented.rstrip).sub(/"\z/, '\\n"') -% end -% fprintf(f, "{\n"); { % # compiler: Prepare operands which may be used by `insn.call_attribute` @@ -68,44 +62,7 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_mjit_compile_insn.erb#L62 % % # JIT: Print insn body in insns.def % insn.expr.expr.each_line do |line| -% # Special macro expansion for ones that can't be resolved by macro redefinition. -% if line =~ /\A\s+DISPATCH_ORIGINAL_INSN\((?<insn_name>[^)]+)\);\s+\z/ - fprintf(f, " return Qundef; /* cancel JIT */\n"); -% elsif line =~ /\A\s+JUMP\((?<dest>[^)]+)\);\s+\z/ -% # Before we `goto` next insn, we need to set return values, especially for getinlinecache -% insn.rets.reverse_each.with_index do |ret, i| -% # TOPN(n) = ... - fprintf(f, " stack[%d] = <%= ret.fetch(:name) %>;\n", b->stack_size + (int)<%= insn.call_attribute('sp_inc') %> - <%= i + 1 %>); -% end -% -% dest = Regexp.last_match[:dest] -% if insn.name == 'opt_case_dispatch' # special case... TODO: use another macro to avoid checking name - { - struct case_dispatch_var arg; - arg.f = f; - arg.base_pos = pos + insn_len(insn); - arg.last_value = Qundef; - - fprintf(f, " switch (<%= dest %>) {\n"); - st_foreach(RHASH_TBL_RAW(hash), compile_case_dispatch_each, (VALUE)&arg); - fprintf(f, " case %lu:\n", else_offset); - fprintf(f, " goto label_%lu;\n", arg.base_pos + else_offset); - fprintf(f, " }\n"); - } -% else - next_pos = pos + insn_len(insn) + (unsigned int)<%= dest %>; - fprintf(f, " goto label_%d;\n", next_pos); -% end -% elsif line =~ /\A\s+RESTORE_REGS\(\);\s+\z/ # for `leave` only -#if OPT_CALL_THREADED_CODE - fprintf(f, " rb_ec_thread_ptr(ec)->retval = val;\n"); - fprintf(f, " return 0;\n"); -#else - fprintf(f, " return val;\n"); -#endif -% else - fprintf(f, <%= to_cstr.call(line) %>); -% end +<%= render 'mjit_compile_insn_line', locals: { line: line, insn: insn } -%> % end % % # JIT: Set return values Index: tool/ruby_vm/views/_mjit_compile_insn_line.erb =================================================================== --- tool/ruby_vm/views/_mjit_compile_insn_line.erb (nonexistent) +++ tool/ruby_vm/views/_mjit_compile_insn_line.erb (revision 62383) @@ -0,0 +1,52 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_mjit_compile_insn_line.erb#L1 +% # -*- mode:c; style:ruby; coding: utf-8; indent-tabs-mode: nil -*- +% # Copyright (c) 2018 Takashi Kokubun. All rights reserved. +% # +% # This file is a part of the programming language Ruby. Permission is hereby +% # granted, to either redistribute and/or modify this file, provided that the +% # conditions mentioned in the file COPYING are met. Consult the file for +% # details. +% +% to_cstr = lambda do |line| +% normalized = line.gsub(/\t/, ' ' * 8) +% indented = normalized.sub(/\A(?!#)/, ' ') # avoid indenting preprocessor +% rstring2cstr(indented.rstrip).sub(/"\z/, '\\n"') +% end +% +% # Special macro expansion for ones that can't be resolved by macro redefinition. +% if line =~ /\A\s+DISPATCH_ORIGINAL_INSN\((?<insn_name>[^)]+)\);\s+\z/ + fprintf(f, " return Qundef; /* cancel JIT */\n"); +% elsif line =~ /\A\s+JUMP\((?<dest>[^)]+)\);\s+\z/ +% # Before we `goto` next insn, we need to set return values, especially for getinlinecache +% insn.rets.reverse_each.with_index do |ret, i| +% # TOPN(n) = ... + fprintf(f, " stack[%d] = <%= ret.fetch(:name) %>;\n", b->stack_size + (int)<%= insn.call_attribute('sp_inc') %> - <%= i + 1 %>); +% end +% +% dest = Regexp.last_match[:dest] +% if insn.name == 'opt_case_dispatch' # special case... TODO: use another macro to avoid checking name + { + struct case_dispatch_var arg; + arg.f = f; + arg.base_pos = pos + insn_len(insn); + arg.last_value = Qundef; + + fprintf(f, " switch (<%= dest %>) {\n"); + st_foreach(RHASH_TBL_RAW(hash), compile_case_dispatch_each, (VALUE)&arg); + fprintf(f, " case %lu:\n", else_offset); + fprintf(f, " goto label_%lu;\n", arg.base_pos + else_offset); + fprintf(f, " }\n"); + } +% else + next_pos = pos + insn_len(insn) + (unsigned int)<%= dest %>; + fprintf(f, " goto label_%d;\n", next_pos); +% end +% elsif line =~ /\A\s+RESTORE_REGS\(\);\s+\z/ # for `leave` only +#if OPT_CALL_THREADED_CODE + fprintf(f, " rb_ec_thread_ptr(ec)->retval = val;\n"); + fprintf(f, " return 0;\n"); +#else + fprintf(f, " return val;\n"); +#endif +% else + fprintf(f, <%= to_cstr.call(line) %>); +% end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/