Skip to content

Commit

Permalink
Remove MJIT's builtin function compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 8, 2023
1 parent b67f07f commit e93e780
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 64 deletions.
6 changes: 1 addition & 5 deletions builtin.h
Expand Up @@ -11,17 +11,13 @@ struct rb_builtin_function {
// for load
const int index;
const char * const name;

// for jit
void (*compiler)(VALUE, long, unsigned, bool);
};

#define RB_BUILTIN_FUNCTION(_i, _name, _fname, _arity, _compiler) {\
#define RB_BUILTIN_FUNCTION(_i, _name, _fname, _arity) {\
.name = _i < 0 ? NULL : #_name, \
.func_ptr = (void *)_fname, \
.argc = _arity, \
.index = _i, \
.compiler = _compiler, \
}

void rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table);
Expand Down
11 changes: 0 additions & 11 deletions rjit_c.rb
Expand Up @@ -435,16 +435,6 @@ def rb_hash_values(cdhash_addr)
Primitive.cexpr! 'rb_hash_values((VALUE)NUM2PTR(cdhash_addr))'
end

def builtin_compiler(buf, bf_ptr, index, stack_size, builtin_inline_p)
_bf_addr = bf_ptr.to_i
# Call "rjit_compile_invokebuiltin_for_#{func}" in mk_builtin_loader.rb
Primitive.cstmt! %{
RB_BUILTIN bf = (RB_BUILTIN)NUM2PTR(_bf_addr);
bf->compiler(buf, NIL_P(index) ? -1 : NUM2LONG(index), NUM2UINT(stack_size), RTEST(builtin_inline_p));
return Qnil;
}
end

def has_cache_for_send(cc_ptr, insn)
_cc_addr = cc_ptr.to_i
Primitive.cstmt! %{
Expand Down Expand Up @@ -1169,7 +1159,6 @@ def C.rb_builtin_function
argc: [CType::Immediate.parse("int"), Primitive.cexpr!("OFFSETOF((*((struct rb_builtin_function *)NULL)), argc)")],
index: [CType::Immediate.parse("int"), Primitive.cexpr!("OFFSETOF((*((struct rb_builtin_function *)NULL)), index)")],
name: [CType::Pointer.new { CType::Immediate.parse("char") }, Primitive.cexpr!("OFFSETOF((*((struct rb_builtin_function *)NULL)), name)")],
compiler: [CType::Immediate.parse("void *"), Primitive.cexpr!("OFFSETOF((*((struct rb_builtin_function *)NULL)), compiler)")],
)
end

Expand Down
42 changes: 2 additions & 40 deletions tool/mk_builtin_loader.rb
Expand Up @@ -318,44 +318,6 @@ def mk_builtin_header file
end
}

bs.each_pair{|func, (argc, cfunc_name)|
decl = ', VALUE' * argc
argv = argc \
. times \
. map {|i|", argv[#{i}]"} \
. join('')
f.puts %'static void'
f.puts %'rjit_compile_invokebuiltin_for_#{func}(VALUE buf, long index, unsigned stack_size, bool inlinable_p)'
f.puts %'{'
f.puts %' rb_str_catf(buf, " VALUE self = GET_SELF();\\n");'
f.puts %' rb_str_catf(buf, " typedef VALUE (*func)(rb_execution_context_t *, VALUE#{decl});\\n");'
if inlines.has_key? cfunc_name
body_lineno, text, locals, func_name = inlines[cfunc_name]
lineno, str = generate_cexpr(ofile, lineno, line_file, body_lineno, text, locals, func_name)
f.puts %' if (inlinable_p) {'
str.gsub(/^(?!#)/, ' ').each_line {|i|
j = RubyVM::CEscape.rstring2cstr(i).dup
j.sub!(/^ return\b/ , ' val =')
f.printf(%' rb_str_catf(buf, "%%s", %s);\n', j)
}
f.puts(%' return;')
f.puts(%' }')
end
if argc > 0
f.puts %' if (index == -1) {'
f.puts %' rb_str_catf(buf, " const VALUE *argv = &stack[%d];\\n", stack_size - #{argc});'
f.puts %' }'
f.puts %' else {'
f.puts %' rb_str_catf(buf, " const unsigned int lnum = ISEQ_BODY(GET_ISEQ())->local_table_size;\\n");'
f.puts %' rb_str_catf(buf, " const VALUE *argv = GET_EP() - lnum - VM_ENV_DATA_SIZE + 1 + %ld;\\n", index);'
f.puts %' }'
end
f.puts %' rb_str_catf(buf, " func f = (func)%"PRIuVALUE"; /* == #{cfunc_name} */\\n", (VALUE)#{cfunc_name});'
f.puts %' rb_str_catf(buf, " val = f(ec, self#{argv});\\n");'
f.puts %'}'
f.puts
}

if SUBLIBS[base]
f.puts "// sub libraries"
SUBLIBS[base].each do |sub|
Expand All @@ -371,9 +333,9 @@ def mk_builtin_header file
f.puts " // table definition"
f.puts " static const struct rb_builtin_function #{table}[] = {"
bs.each.with_index{|(func, (argc, cfunc_name)), i|
f.puts " RB_BUILTIN_FUNCTION(#{i}, #{func}, #{cfunc_name}, #{argc}, rjit_compile_invokebuiltin_for_#{func}),"
f.puts " RB_BUILTIN_FUNCTION(#{i}, #{func}, #{cfunc_name}, #{argc}),"
}
f.puts " RB_BUILTIN_FUNCTION(-1, NULL, NULL, 0, 0),"
f.puts " RB_BUILTIN_FUNCTION(-1, NULL, NULL, 0),"
f.puts " };"

f.puts
Expand Down
8 changes: 0 additions & 8 deletions yjit/src/cruby_bindings.inc.rs
Expand Up @@ -848,14 +848,6 @@ pub struct rb_builtin_function {
pub argc: ::std::os::raw::c_int,
pub index: ::std::os::raw::c_int,
pub name: *const ::std::os::raw::c_char,
pub compiler: ::std::option::Option<
unsafe extern "C" fn(
arg1: VALUE,
arg2: ::std::os::raw::c_long,
arg3: ::std::os::raw::c_uint,
arg4: bool,
),
>,
}
pub const YARVINSN_nop: ruby_vminsn_type = 0;
pub const YARVINSN_getlocal: ruby_vminsn_type = 1;
Expand Down

0 comments on commit e93e780

Please sign in to comment.