ruby-changes:73423
From: Takashi <ko1@a...>
Date: Mon, 5 Sep 2022 13:54:00 +0900 (JST)
Subject: [ruby-changes:73423] 3767c6a90d (master): Ruby MJIT (#6028)
https://git.ruby-lang.org/ruby.git/commit/?id=3767c6a90d From 3767c6a90d8970f9b39e9ed116a7b9bbac3f9f26 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Sun, 4 Sep 2022 21:53:46 -0700 Subject: Ruby MJIT (#6028) --- .gitignore | 1 + common.mk | 20 +- inits.c | 2 + lib/mjit/c_32.rb | 436 +++++++++ lib/mjit/c_64.rb | 437 +++++++++ lib/mjit/c_pointer.rb | 333 +++++++ lib/mjit/c_type.rb | 77 ++ lib/mjit/compiler.rb | 1019 ++++++++++++++++++++ mjit.c | 12 +- mjit_compiler.c | 572 ++--------- mjit_compiler.h | 58 ++ mjit_compiler.rb | 135 +++ ruby.c | 18 +- template/Makefile.in | 13 +- tool/mjit/.gitignore | 1 + tool/mjit/Gemfile | 4 + tool/mjit/bindgen.rb | 391 ++++++++ tool/ruby_vm/helpers/dumper.rb | 2 +- .../views/_mjit_compile_getconstant_path.erb | 30 - tool/ruby_vm/views/_mjit_compile_insn.erb | 92 -- tool/ruby_vm/views/_mjit_compile_insn_body.erb | 129 --- tool/ruby_vm/views/_mjit_compile_invokebuiltin.erb | 29 - tool/ruby_vm/views/_mjit_compile_ivar.erb | 110 --- tool/ruby_vm/views/_mjit_compile_pc_and_sp.erb | 38 - tool/ruby_vm/views/_mjit_compile_send.erb | 119 --- tool/ruby_vm/views/mjit_compile.inc.erb | 110 --- tool/ruby_vm/views/mjit_compile_attr.inc.erb | 17 + tool/ruby_vm/views/mjit_instruction.rb.erb | 40 + tool/update-deps | 2 +- win32/Makefile.sub | 6 +- 30 files changed, 3070 insertions(+), 1183 deletions(-) create mode 100644 lib/mjit/c_32.rb create mode 100644 lib/mjit/c_64.rb create mode 100644 lib/mjit/c_pointer.rb create mode 100644 lib/mjit/c_type.rb create mode 100644 lib/mjit/compiler.rb create mode 100644 mjit_compiler.h create mode 100644 mjit_compiler.rb create mode 100644 tool/mjit/.gitignore create mode 100644 tool/mjit/Gemfile create mode 100755 tool/mjit/bindgen.rb delete mode 100644 tool/ruby_vm/views/_mjit_compile_getconstant_path.erb delete mode 100644 tool/ruby_vm/views/_mjit_compile_insn.erb delete mode 100644 tool/ruby_vm/views/_mjit_compile_insn_body.erb delete mode 100644 tool/ruby_vm/views/_mjit_compile_invokebuiltin.erb delete mode 100644 tool/ruby_vm/views/_mjit_compile_ivar.erb delete mode 100644 tool/ruby_vm/views/_mjit_compile_pc_and_sp.erb delete mode 100644 tool/ruby_vm/views/_mjit_compile_send.erb delete mode 100644 tool/ruby_vm/views/mjit_compile.inc.erb create mode 100644 tool/ruby_vm/views/mjit_compile_attr.inc.erb create mode 100644 tool/ruby_vm/views/mjit_instruction.rb.erb diff --git a/.gitignore b/.gitignore index c12ec27782..52089ac21c 100644 --- a/.gitignore +++ b/.gitignore @@ -236,6 +236,7 @@ lcov*.info https://github.com/ruby/ruby/blob/trunk/.gitignore#L236 /rb_mjit_header.h /mjit_config.h /include/ruby-*/*/rb_mjit_min_header-*.h +/mjit_instruction.rb # /wasm/ /wasm/tests/*.wasm diff --git a/common.mk b/common.mk index d5e69750d4..ec0ccc5402 100644 --- a/common.mk +++ b/common.mk @@ -1049,11 +1049,7 @@ $(srcs_vpath)insns_info.inc: $(tooldir)/ruby_vm/views/insns_info.inc.erb $(inc_c https://github.com/ruby/ruby/blob/trunk/common.mk#L1049 $(srcs_vpath)vmtc.inc: $(tooldir)/ruby_vm/views/vmtc.inc.erb $(inc_common_headers) $(srcs_vpath)vm.inc: $(tooldir)/ruby_vm/views/vm.inc.erb $(inc_common_headers) \ $(tooldir)/ruby_vm/views/_insn_entry.erb $(tooldir)/ruby_vm/views/_trace_instruction.erb -$(srcs_vpath)mjit_compile.inc: $(tooldir)/ruby_vm/views/mjit_compile.inc.erb $(inc_common_headers) \ - $(tooldir)/ruby_vm/views/_mjit_compile_insn.erb $(tooldir)/ruby_vm/views/_mjit_compile_send.erb \ - $(tooldir)/ruby_vm/views/_mjit_compile_ivar.erb \ - $(tooldir)/ruby_vm/views/_mjit_compile_insn_body.erb $(tooldir)/ruby_vm/views/_mjit_compile_pc_and_sp.erb \ - $(tooldir)/ruby_vm/views/_mjit_compile_invokebuiltin.erb $(tooldir)/ruby_vm/views/_mjit_compile_getconstant_path.erb +$(srcs_vpath)mjit_compile_attr.inc: $(tooldir)/ruby_vm/views/mjit_compile_attr.inc.erb BUILTIN_RB_SRCS = \ $(srcdir)/ast.rb \ @@ -1063,6 +1059,8 @@ BUILTIN_RB_SRCS = \ https://github.com/ruby/ruby/blob/trunk/common.mk#L1059 $(srcdir)/io.rb \ $(srcdir)/marshal.rb \ $(srcdir)/mjit.rb \ + $(srcdir)/mjit_compiler.rb \ + $(srcdir)/mjit_instruction.rb \ $(srcdir)/pack.rb \ $(srcdir)/trace_point.rb \ $(srcdir)/warning.rb \ @@ -1154,7 +1152,7 @@ vm_call_iseq_optimized.inc: $(srcdir)/template/call_iseq_optimized.inc.tmpl https://github.com/ruby/ruby/blob/trunk/common.mk#L1152 $(ECHO) generating $@ $(Q) $(BASERUBY) $(tooldir)/generic_erb.rb -c -o $@ $(srcdir)/template/call_iseq_optimized.inc.tmpl -$(MINIPRELUDE_C): $(COMPILE_PRELUDE) $(BUILTIN_RB_SRCS) +$(MINIPRELUDE_C): $(COMPILE_PRELUDE) $(BUILTIN_RB_SRCS) $(srcdir)/mjit_instruction.rb $(ECHO) generating $@ $(Q) $(BASERUBY) $(tooldir)/generic_erb.rb -I$(srcdir) -o $@ \ $(srcdir)/template/prelude.c.tmpl $(BUILTIN_RB_SRCS) @@ -9280,6 +9278,7 @@ miniinit.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h https://github.com/ruby/ruby/blob/trunk/common.mk#L9278 miniinit.$(OBJEXT): $(CCAN_DIR)/list/list.h miniinit.$(OBJEXT): $(CCAN_DIR)/str/str.h miniinit.$(OBJEXT): $(hdrdir)/ruby/ruby.h +miniinit.$(OBJEXT): $(srcdir)/mjit_instruction.rb miniinit.$(OBJEXT): $(top_srcdir)/internal/array.h miniinit.$(OBJEXT): $(top_srcdir)/internal/compilers.h miniinit.$(OBJEXT): $(top_srcdir)/internal/gc.h @@ -9470,6 +9469,8 @@ miniinit.$(OBJEXT): {$(VPATH)}miniinit.c https://github.com/ruby/ruby/blob/trunk/common.mk#L9469 miniinit.$(OBJEXT): {$(VPATH)}miniprelude.c miniinit.$(OBJEXT): {$(VPATH)}missing.h miniinit.$(OBJEXT): {$(VPATH)}mjit.rb +miniinit.$(OBJEXT): {$(VPATH)}mjit_compiler.rb +miniinit.$(OBJEXT): {$(VPATH)}mjit_instruction.rb miniinit.$(OBJEXT): {$(VPATH)}nilclass.rb miniinit.$(OBJEXT): {$(VPATH)}node.h miniinit.$(OBJEXT): {$(VPATH)}numeric.rb @@ -9723,6 +9724,7 @@ mjit_compiler.$(OBJEXT): $(CCAN_DIR)/list/list.h https://github.com/ruby/ruby/blob/trunk/common.mk#L9724 mjit_compiler.$(OBJEXT): $(CCAN_DIR)/str/str.h mjit_compiler.$(OBJEXT): $(hdrdir)/ruby.h mjit_compiler.$(OBJEXT): $(hdrdir)/ruby/ruby.h +mjit_compiler.$(OBJEXT): $(srcdir)/mjit_instruction.rb mjit_compiler.$(OBJEXT): $(top_srcdir)/internal/array.h mjit_compiler.$(OBJEXT): $(top_srcdir)/internal/class.h mjit_compiler.$(OBJEXT): $(top_srcdir)/internal/compile.h @@ -9903,8 +9905,12 @@ mjit_compiler.$(OBJEXT): {$(VPATH)}iseq.h https://github.com/ruby/ruby/blob/trunk/common.mk#L9905 mjit_compiler.$(OBJEXT): {$(VPATH)}method.h mjit_compiler.$(OBJEXT): {$(VPATH)}missing.h mjit_compiler.$(OBJEXT): {$(VPATH)}mjit.h -mjit_compiler.$(OBJEXT): {$(VPATH)}mjit_compile.inc +mjit_compiler.$(OBJEXT): {$(VPATH)}mjit_compile_attr.inc mjit_compiler.$(OBJEXT): {$(VPATH)}mjit_compiler.c +mjit_compiler.$(OBJEXT): {$(VPATH)}mjit_compiler.h +mjit_compiler.$(OBJEXT): {$(VPATH)}mjit_compiler.rb +mjit_compiler.$(OBJEXT): {$(VPATH)}mjit_compiler.rbinc +mjit_compiler.$(OBJEXT): {$(VPATH)}mjit_instruction.rbinc mjit_compiler.$(OBJEXT): {$(VPATH)}mjit_unit.h mjit_compiler.$(OBJEXT): {$(VPATH)}node.h mjit_compiler.$(OBJEXT): {$(VPATH)}ruby_assert.h diff --git a/inits.c b/inits.c index 22ba6d5a8c..f43ece0e47 100644 --- a/inits.c +++ b/inits.c @@ -104,6 +104,8 @@ rb_call_builtin_inits(void) https://github.com/ruby/ruby/blob/trunk/inits.c#L104 BUILTIN(marshal); #if USE_MJIT BUILTIN(mjit); + BUILTIN(mjit_compiler); + BUILTIN(mjit_instruction); #endif Init_builtin_prelude(); } diff --git a/lib/mjit/c_32.rb b/lib/mjit/c_32.rb new file mode 100644 index 0000000000..ee8324ba4d --- /dev/null +++ b/lib/mjit/c_32.rb @@ -0,0 +1,436 @@ https://github.com/ruby/ruby/blob/trunk/lib/mjit/c_32.rb#L1 +require_relative 'c_type' + +module RubyVM::MJIT + C = Object.new + + def C.NOT_COMPILED_STACK_SIZE = - 1 + + def C.USE_LAZY_LOAD = false + + def C.USE_RVARGC = true + + def C.VM_CALL_KW_SPLAT = ( 0x01 << self.VM_CALL_KW_SPLAT_bit ) + + def C.VM_CALL_TAILCALL = ( 0x01 << self.VM_CALL_TAILCALL_bit ) + + def C.VM_METHOD_TYPE_CFUNC = 1 + + def C.VM_METHOD_TYPE_ISEQ = 0 + + def C.VM_CALL_KW_SPLAT_bit = 7 + + def C.VM_CALL_TAILCALL_bit = 8 + + def C.CALL_DATA + @CALL_DATA ||= self.rb_call_data + end + + def C.IC + @IC ||= self.iseq_inline_constant_cache + end + + def C.IVC + @IVC ||= self.iseq_inline_iv_cache_entry + end + + def C.RB_BUILTIN + @RB_BUILTIN ||= self.rb_builtin_function + end + + def C.VALUE + @VALUE ||= CType::Immediate.new(-5) + end + + def C.compile_branch + @compile_branch ||= CType::Struct.new( + "compile_branch", 8, + stack_size: [0, CType::Immediate.new(-4)], + finish_p: [32, self._Bool], + ) + end + + def C.compile_status + @compile_status ||= CType::Struct.new( + "compile_status", 68, + success: [0, self._Bool], + stack_size_for_pos: [32, CType::Pointer.new { CType::Immediate.new(4) }], + local_stack_p: [64, self._Bool], + is_entries: [96, CType::Pointer.new { self.iseq_inline_storage_entry }], + cc_entries_index: [128, CType::Immediate.new(4)], + compiled_iseq: [160, CType::Pointer.new { self.rb_iseq_constant_body }], + compiled_id: [192, CType::Immediate.new(4)], + compile_info: [224, CType::Pointer.new { self.rb_mjit_compile_info }], + merge_ivar_guards_p: [256, self._Bool], + ivar_serial: [288, self.rb_se (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/