summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-08-02 07:15:29 -0700
committerGitHub <noreply@github.com>2023-08-02 10:15:29 -0400
commitd405410e3c6ecfdefe345f2b78cf740effe784a1 (patch)
tree6e329cfb607a2be620e4669e4b7e24eb873d294f
parent1d096c1e53581ed9fe94694c9760babd1e12e580 (diff)
YJIT: Move ROBJECT_OFFSET_* to yjit.c (#8157)
Notes
Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
-rw-r--r--include/ruby/internal/core/robject.h7
-rw-r--r--yjit.c7
-rw-r--r--yjit/bindgen/src/main.rs5
-rw-r--r--yjit/src/codegen.rs8
-rw-r--r--yjit/src/cruby_bindings.inc.rs7
5 files changed, 18 insertions, 16 deletions
diff --git a/include/ruby/internal/core/robject.h b/include/ruby/internal/core/robject.h
index dc1faad89f..c2bcae6306 100644
--- a/include/ruby/internal/core/robject.h
+++ b/include/ruby/internal/core/robject.h
@@ -119,13 +119,6 @@ struct RObject {
} as;
};
-/* Offsets for YJIT */
-#ifndef __cplusplus
-static const int32_t ROBJECT_OFFSET_AS_HEAP_IVPTR = offsetof(struct RObject, as.heap.ivptr);
-static const int32_t ROBJECT_OFFSET_AS_HEAP_IV_INDEX_TBL = offsetof(struct RObject, as.heap.iv_index_tbl);
-static const int32_t ROBJECT_OFFSET_AS_ARY = offsetof(struct RObject, as.ary);
-#endif
-
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
/**
diff --git a/yjit.c b/yjit.c
index 50dcecae96..132c2f0959 100644
--- a/yjit.c
+++ b/yjit.c
@@ -38,6 +38,13 @@
#include <errno.h>
+// Field offsets for the RObject struct
+enum robject_offsets {
+ ROBJECT_OFFSET_AS_HEAP_IVPTR = offsetof(struct RObject, as.heap.ivptr),
+ ROBJECT_OFFSET_AS_HEAP_IV_INDEX_TBL = offsetof(struct RObject, as.heap.iv_index_tbl),
+ ROBJECT_OFFSET_AS_ARY = offsetof(struct RObject, as.ary),
+};
+
// Field offsets for the RString struct
enum rstring_offsets {
RUBY_OFFSET_RSTRING_LEN = offsetof(struct RString, len)
diff --git a/yjit/bindgen/src/main.rs b/yjit/bindgen/src/main.rs
index 461786b8aa..d83e948776 100644
--- a/yjit/bindgen/src/main.rs
+++ b/yjit/bindgen/src/main.rs
@@ -84,7 +84,7 @@ fn main() {
// From include/ruby/internal/core/rbasic.h
.allowlist_type("RBasic")
- .allowlist_type("rstring_offsets")
+ // From include/ruby/internal/core/rstring.h
.allowlist_type("ruby_rstring_flags")
// From internal.h
@@ -179,7 +179,6 @@ fn main() {
// From include/ruby/internal/core/robject.h
.allowlist_type("ruby_robject_flags")
- .allowlist_var("ROBJECT_OFFSET_.*")
// From include/ruby/internal/core/rarray.h
.allowlist_type("ruby_rarray_flags")
@@ -327,6 +326,8 @@ fn main() {
.allowlist_function("rb_yjit_assert_holding_vm_lock")
.allowlist_function("rb_yjit_sendish_sp_pops")
.allowlist_function("rb_yjit_invokeblock_sp_pops")
+ .allowlist_type("robject_offsets")
+ .allowlist_type("rstring_offsets")
// from vm_sync.h
.allowlist_function("rb_vm_barrier")
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs
index f8c52e58a8..daf898c3cd 100644
--- a/yjit/src/codegen.rs
+++ b/yjit/src/codegen.rs
@@ -2054,7 +2054,7 @@ fn gen_get_ivar(
// See ROBJECT_IVPTR() from include/ruby/internal/core/robject.h
// Load the variable
- let offs = ROBJECT_OFFSET_AS_ARY + (ivar_index * SIZEOF_VALUE) as i32;
+ let offs = ROBJECT_OFFSET_AS_ARY as i32 + (ivar_index * SIZEOF_VALUE) as i32;
let ivar_opnd = Opnd::mem(64, recv, offs);
// Push the ivar on the stack
@@ -2064,7 +2064,7 @@ fn gen_get_ivar(
// Compile time value is *not* embedded.
// Get a pointer to the extended table
- let tbl_opnd = asm.load(Opnd::mem(64, recv, ROBJECT_OFFSET_AS_HEAP_IVPTR));
+ let tbl_opnd = asm.load(Opnd::mem(64, recv, ROBJECT_OFFSET_AS_HEAP_IVPTR as i32));
// Read the ivar from the extended table
let ivar_opnd = Opnd::mem(64, tbl_opnd, (SIZEOF_VALUE * ivar_index) as i32);
@@ -2126,7 +2126,7 @@ fn gen_write_iv(
if embed_test_result {
// Find the IV offset
- let offs = ROBJECT_OFFSET_AS_ARY + (ivar_index * SIZEOF_VALUE) as i32;
+ let offs = ROBJECT_OFFSET_AS_ARY as i32 + (ivar_index * SIZEOF_VALUE) as i32;
let ivar_opnd = Opnd::mem(64, recv, offs);
// Write the IV
@@ -2136,7 +2136,7 @@ fn gen_write_iv(
// Compile time value is *not* embedded.
// Get a pointer to the extended table
- let tbl_opnd = asm.load(Opnd::mem(64, recv, ROBJECT_OFFSET_AS_HEAP_IVPTR));
+ let tbl_opnd = asm.load(Opnd::mem(64, recv, ROBJECT_OFFSET_AS_HEAP_IVPTR as i32));
// Write the ivar in to the extended table
let ivar_opnd = Opnd::mem(64, tbl_opnd, (SIZEOF_VALUE * ivar_index) as i32);
diff --git a/yjit/src/cruby_bindings.inc.rs b/yjit/src/cruby_bindings.inc.rs
index 7c4ecc5143..94a9335042 100644
--- a/yjit/src/cruby_bindings.inc.rs
+++ b/yjit/src/cruby_bindings.inc.rs
@@ -251,9 +251,6 @@ pub const RMODULE_IS_REFINEMENT: ruby_rmodule_flags = 32768;
pub type ruby_rmodule_flags = u32;
pub const ROBJECT_EMBED: ruby_robject_flags = 8192;
pub type ruby_robject_flags = u32;
-pub const ROBJECT_OFFSET_AS_HEAP_IVPTR: i32 = 16;
-pub const ROBJECT_OFFSET_AS_HEAP_IV_INDEX_TBL: i32 = 24;
-pub const ROBJECT_OFFSET_AS_ARY: i32 = 16;
pub type rb_block_call_func = ::std::option::Option<
unsafe extern "C" fn(
yielded_arg: VALUE,
@@ -1060,6 +1057,10 @@ pub type ruby_vminsn_type = u32;
pub type rb_iseq_callback = ::std::option::Option<
unsafe extern "C" fn(arg1: *const rb_iseq_t, arg2: *mut ::std::os::raw::c_void),
>;
+pub const ROBJECT_OFFSET_AS_HEAP_IVPTR: robject_offsets = 16;
+pub const ROBJECT_OFFSET_AS_HEAP_IV_INDEX_TBL: robject_offsets = 24;
+pub const ROBJECT_OFFSET_AS_ARY: robject_offsets = 16;
+pub type robject_offsets = u32;
pub const RUBY_OFFSET_RSTRING_LEN: rstring_offsets = 16;
pub type rstring_offsets = u32;
pub type rb_seq_param_keyword_struct = rb_iseq_constant_body__bindgen_ty_1_rb_iseq_param_keyword;