summaryrefslogtreecommitdiff
path: root/yjit
diff options
context:
space:
mode:
authorNoah Gibbs (and/or Benchmark CI) <noah.gibbs@shopify.com>2022-05-25 16:31:38 +0000
committerAlan Wu <XrXr@users.noreply.github.com>2022-05-26 13:06:47 -0400
commitba88787087b0d979f806e6b58cfbc3886d942968 (patch)
tree1ed25c3452df88940c8471c994f4d2c550237ab6 /yjit
parentbd472ef36f22de176a886cbe789480e84990b82b (diff)
Use bindgen to import CRuby constants for YARV instruction bytecodes
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5948
Diffstat (limited to 'yjit')
-rw-r--r--yjit/bindgen/src/main.rs3
-rw-r--r--yjit/src/codegen.rs182
-rw-r--r--yjit/src/cruby.rs110
-rw-r--r--yjit/src/cruby_bindings.inc.rs204
-rw-r--r--yjit/src/invariants.rs6
-rw-r--r--yjit/src/stats.rs7
6 files changed, 307 insertions, 205 deletions
diff --git a/yjit/bindgen/src/main.rs b/yjit/bindgen/src/main.rs
index 7049688e1f..26717d018c 100644
--- a/yjit/bindgen/src/main.rs
+++ b/yjit/bindgen/src/main.rs
@@ -56,6 +56,9 @@ fn main() {
// Prune these types since they are system dependant and we don't use them
.blocklist_type("__.*")
+ // Import YARV bytecode instruction constants
+ .allowlist_type("ruby_vminsn_type")
+
// From include/ruby/internal/intern/string.h
.allowlist_function("rb_utf8_str_new")
.allowlist_function("rb_str_append")
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs
index 3591e05b3d..782d87a144 100644
--- a/yjit/src/codegen.rs
+++ b/yjit/src/codegen.rs
@@ -1,3 +1,6 @@
+// We use the YARV bytecode constants which have a CRuby-style name
+#![allow(non_upper_case_globals)]
+
use crate::asm::x86_64::*;
use crate::asm::*;
use crate::core::*;
@@ -728,7 +731,7 @@ pub fn gen_single_block(
// opt_getinlinecache wants to be in a block all on its own. Cut the block short
// if we run into it. See gen_opt_getinlinecache() for details.
- if opcode == OP_OPT_GETINLINECACHE && insn_idx > starting_insn_idx {
+ if opcode == YARVINSN_opt_getinlinecache.as_usize() && insn_idx > starting_insn_idx {
jump_to_next_insn(&mut jit, &ctx, cb, ocb);
break;
}
@@ -988,7 +991,7 @@ fn gen_putobject_int2fix(
_ocb: &mut OutlinedCb,
) -> CodegenStatus {
let opcode = jit.opcode;
- let cst_val: usize = if opcode == OP_PUTOBJECT_INT2FIX_0_ {
+ let cst_val: usize = if opcode == YARVINSN_putobject_INT2FIX_0_.as_usize() {
0
} else {
1
@@ -5811,95 +5814,96 @@ fn gen_opt_invokebuiltin_delegate(
/// Maps a YARV opcode to a code generation function (if supported)
fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> {
let VALUE(opcode) = opcode;
+ let opcode = opcode as ruby_vminsn_type;
assert!(opcode < VM_INSTRUCTION_SIZE);
match opcode {
- OP_NOP => Some(gen_nop),
- OP_POP => Some(gen_pop),
- OP_DUP => Some(gen_dup),
- OP_DUPN => Some(gen_dupn),
- OP_SWAP => Some(gen_swap),
- OP_PUTNIL => Some(gen_putnil),
- OP_PUTOBJECT => Some(gen_putobject),
- OP_PUTOBJECT_INT2FIX_0_ => Some(gen_putobject_int2fix),
- OP_PUTOBJECT_INT2FIX_1_ => Some(gen_putobject_int2fix),
- OP_PUTSELF => Some(gen_putself),
- OP_PUTSPECIALOBJECT => Some(gen_putspecialobject),
- OP_SETN => Some(gen_setn),
- OP_TOPN => Some(gen_topn),
- OP_ADJUSTSTACK => Some(gen_adjuststack),
- OP_GETLOCAL => Some(gen_getlocal),
- OP_GETLOCAL_WC_0 => Some(gen_getlocal_wc0),
- OP_GETLOCAL_WC_1 => Some(gen_getlocal_wc1),
- OP_SETLOCAL => Some(gen_setlocal),
- OP_SETLOCAL_WC_0 => Some(gen_setlocal_wc0),
- OP_SETLOCAL_WC_1 => Some(gen_setlocal_wc1),
- OP_OPT_PLUS => Some(gen_opt_plus),
- OP_OPT_MINUS => Some(gen_opt_minus),
- OP_OPT_AND => Some(gen_opt_and),
- OP_OPT_OR => Some(gen_opt_or),
- OP_NEWHASH => Some(gen_newhash),
- OP_DUPHASH => Some(gen_duphash),
- OP_NEWARRAY => Some(gen_newarray),
- OP_DUPARRAY => Some(gen_duparray),
- OP_CHECKTYPE => Some(gen_checktype),
- OP_OPT_LT => Some(gen_opt_lt),
- OP_OPT_LE => Some(gen_opt_le),
- OP_OPT_GT => Some(gen_opt_gt),
- OP_OPT_GE => Some(gen_opt_ge),
- OP_OPT_MOD => Some(gen_opt_mod),
- OP_OPT_STR_FREEZE => Some(gen_opt_str_freeze),
- OP_OPT_STR_UMINUS => Some(gen_opt_str_uminus),
- OP_SPLATARRAY => Some(gen_splatarray),
- OP_NEWRANGE => Some(gen_newrange),
- OP_PUTSTRING => Some(gen_putstring),
- OP_EXPANDARRAY => Some(gen_expandarray),
- OP_DEFINED => Some(gen_defined),
- OP_CHECKKEYWORD => Some(gen_checkkeyword),
- OP_CONCATSTRINGS => Some(gen_concatstrings),
- OP_GETINSTANCEVARIABLE => Some(gen_getinstancevariable),
- OP_SETINSTANCEVARIABLE => Some(gen_setinstancevariable),
-
- OP_OPT_EQ => Some(gen_opt_eq),
- OP_OPT_NEQ => Some(gen_opt_neq),
- OP_OPT_AREF => Some(gen_opt_aref),
- OP_OPT_ASET => Some(gen_opt_aset),
- OP_OPT_MULT => Some(gen_opt_mult),
- OP_OPT_DIV => Some(gen_opt_div),
- OP_OPT_LTLT => Some(gen_opt_ltlt),
- OP_OPT_NIL_P => Some(gen_opt_nil_p),
- OP_OPT_EMPTY_P => Some(gen_opt_empty_p),
- OP_OPT_SUCC => Some(gen_opt_succ),
- OP_OPT_NOT => Some(gen_opt_not),
- OP_OPT_SIZE => Some(gen_opt_size),
- OP_OPT_LENGTH => Some(gen_opt_length),
- OP_OPT_REGEXPMATCH2 => Some(gen_opt_regexpmatch2),
- OP_OPT_GETINLINECACHE => Some(gen_opt_getinlinecache),
- OP_INVOKEBUILTIN => Some(gen_invokebuiltin),
- OP_OPT_INVOKEBUILTIN_DELEGATE => Some(gen_opt_invokebuiltin_delegate),
- OP_OPT_INVOKEBUILTIN_DELEGATE_LEAVE => Some(gen_opt_invokebuiltin_delegate),
- OP_OPT_CASE_DISPATCH => Some(gen_opt_case_dispatch),
- OP_BRANCHIF => Some(gen_branchif),
- OP_BRANCHUNLESS => Some(gen_branchunless),
- OP_BRANCHNIL => Some(gen_branchnil),
- OP_JUMP => Some(gen_jump),
-
- OP_GETBLOCKPARAMPROXY => Some(gen_getblockparamproxy),
- OP_GETBLOCKPARAM => Some(gen_getblockparam),
- OP_OPT_SEND_WITHOUT_BLOCK => Some(gen_opt_send_without_block),
- OP_SEND => Some(gen_send),
- OP_INVOKESUPER => Some(gen_invokesuper),
- OP_LEAVE => Some(gen_leave),
-
- OP_GETGLOBAL => Some(gen_getglobal),
- OP_SETGLOBAL => Some(gen_setglobal),
- OP_ANYTOSTRING => Some(gen_anytostring),
- OP_OBJTOSTRING => Some(gen_objtostring),
- OP_INTERN => Some(gen_intern),
- OP_TOREGEXP => Some(gen_toregexp),
- OP_GETSPECIAL => Some(gen_getspecial),
- OP_GETCLASSVARIABLE => Some(gen_getclassvariable),
- OP_SETCLASSVARIABLE => Some(gen_setclassvariable),
+ YARVINSN_nop => Some(gen_nop),
+ YARVINSN_pop => Some(gen_pop),
+ YARVINSN_dup => Some(gen_dup),
+ YARVINSN_dupn => Some(gen_dupn),
+ YARVINSN_swap => Some(gen_swap),
+ YARVINSN_putnil => Some(gen_putnil),
+ YARVINSN_putobject => Some(gen_putobject),
+ YARVINSN_putobject_INT2FIX_0_ => Some(gen_putobject_int2fix),
+ YARVINSN_putobject_INT2FIX_1_ => Some(gen_putobject_int2fix),
+ YARVINSN_putself => Some(gen_putself),
+ YARVINSN_putspecialobject => Some(gen_putspecialobject),
+ YARVINSN_setn => Some(gen_setn),
+ YARVINSN_topn => Some(gen_topn),
+ YARVINSN_adjuststack => Some(gen_adjuststack),
+ YARVINSN_getlocal => Some(gen_getlocal),
+ YARVINSN_getlocal_WC_0 => Some(gen_getlocal_wc0),
+ YARVINSN_getlocal_WC_1 => Some(gen_getlocal_wc1),
+ YARVINSN_setlocal => Some(gen_setlocal),
+ YARVINSN_setlocal_WC_0 => Some(gen_setlocal_wc0),
+ YARVINSN_setlocal_WC_1 => Some(gen_setlocal_wc1),
+ YARVINSN_opt_plus => Some(gen_opt_plus),
+ YARVINSN_opt_minus => Some(gen_opt_minus),
+ YARVINSN_opt_and => Some(gen_opt_and),
+ YARVINSN_opt_or => Some(gen_opt_or),
+ YARVINSN_newhash => Some(gen_newhash),
+ YARVINSN_duphash => Some(gen_duphash),
+ YARVINSN_newarray => Some(gen_newarray),
+ YARVINSN_duparray => Some(gen_duparray),
+ YARVINSN_checktype => Some(gen_checktype),
+ YARVINSN_opt_lt => Some(gen_opt_lt),
+ YARVINSN_opt_le => Some(gen_opt_le),
+ YARVINSN_opt_gt => Some(gen_opt_gt),
+ YARVINSN_opt_ge => Some(gen_opt_ge),
+ YARVINSN_opt_mod => Some(gen_opt_mod),
+ YARVINSN_opt_str_freeze => Some(gen_opt_str_freeze),
+ YARVINSN_opt_str_uminus => Some(gen_opt_str_uminus),
+ YARVINSN_splatarray => Some(gen_splatarray),
+ YARVINSN_newrange => Some(gen_newrange),
+ YARVINSN_putstring => Some(gen_putstring),
+ YARVINSN_expandarray => Some(gen_expandarray),
+ YARVINSN_defined => Some(gen_defined),
+ YARVINSN_checkkeyword => Some(gen_checkkeyword),
+ YARVINSN_concatstrings => Some(gen_concatstrings),
+ YARVINSN_getinstancevariable => Some(gen_getinstancevariable),
+ YARVINSN_setinstancevariable => Some(gen_setinstancevariable),
+
+ YARVINSN_opt_eq => Some(gen_opt_eq),
+ YARVINSN_opt_neq => Some(gen_opt_neq),
+ YARVINSN_opt_aref => Some(gen_opt_aref),
+ YARVINSN_opt_aset => Some(gen_opt_aset),
+ YARVINSN_opt_mult => Some(gen_opt_mult),
+ YARVINSN_opt_div => Some(gen_opt_div),
+ YARVINSN_opt_ltlt => Some(gen_opt_ltlt),
+ YARVINSN_opt_nil_p => Some(gen_opt_nil_p),
+ YARVINSN_opt_empty_p => Some(gen_opt_empty_p),
+ YARVINSN_opt_succ => Some(gen_opt_succ),
+ YARVINSN_opt_not => Some(gen_opt_not),
+ YARVINSN_opt_size => Some(gen_opt_size),
+ YARVINSN_opt_length => Some(gen_opt_length),
+ YARVINSN_opt_regexpmatch2 => Some(gen_opt_regexpmatch2),
+ YARVINSN_opt_getinlinecache => Some(gen_opt_getinlinecache),
+ YARVINSN_invokebuiltin => Some(gen_invokebuiltin),
+ YARVINSN_opt_invokebuiltin_delegate => Some(gen_opt_invokebuiltin_delegate),
+ YARVINSN_opt_invokebuiltin_delegate_leave => Some(gen_opt_invokebuiltin_delegate),
+ YARVINSN_opt_case_dispatch => Some(gen_opt_case_dispatch),
+ YARVINSN_branchif => Some(gen_branchif),
+ YARVINSN_branchunless => Some(gen_branchunless),
+ YARVINSN_branchnil => Some(gen_branchnil),
+ YARVINSN_jump => Some(gen_jump),
+
+ YARVINSN_getblockparamproxy => Some(gen_getblockparamproxy),
+ YARVINSN_getblockparam => Some(gen_getblockparam),
+ YARVINSN_opt_send_without_block => Some(gen_opt_send_without_block),
+ YARVINSN_send => Some(gen_send),
+ YARVINSN_invokesuper => Some(gen_invokesuper),
+ YARVINSN_leave => Some(gen_leave),
+
+ YARVINSN_getglobal => Some(gen_getglobal),
+ YARVINSN_setglobal => Some(gen_setglobal),
+ YARVINSN_anytostring => Some(gen_anytostring),
+ YARVINSN_objtostring => Some(gen_objtostring),
+ YARVINSN_intern => Some(gen_intern),
+ YARVINSN_toregexp => Some(gen_toregexp),
+ YARVINSN_getspecial => Some(gen_getspecial),
+ YARVINSN_getclassvariable => Some(gen_getclassvariable),
+ YARVINSN_setclassvariable => Some(gen_setclassvariable),
// Unimplemented opcode, YJIT won't generate code for this yet
_ => None,
@@ -6311,7 +6315,7 @@ mod tests {
#[test]
fn test_int2fix() {
let (mut jit, mut context, mut cb, mut ocb) = setup_codegen();
- jit.opcode = OP_PUTOBJECT_INT2FIX_0_;
+ jit.opcode = YARVINSN_putobject_INT2FIX_0_.as_usize();
let status = gen_putobject_int2fix(&mut jit, &mut context, &mut cb, &mut ocb);
let (_, tmp_type_top) = context.get_opnd_mapping(StackOpnd(0));
diff --git a/yjit/src/cruby.rs b/yjit/src/cruby.rs
index 20091bf77a..e86e451643 100644
--- a/yjit/src/cruby.rs
+++ b/yjit/src/cruby.rs
@@ -815,113 +815,3 @@ mod manual_defs {
pub const RUBY_OFFSET_ICE_VALUE: i32 = 8;
}
pub use manual_defs::*;
-
-#[allow(unused)]
-mod vm_opcodes {
- // TODO: need to dynamically autogenerate constants for all the YARV opcodes from insns.def
- // TODO: typing of these adds unnecessary casting
- pub const OP_NOP: usize = 0;
- pub const OP_GETLOCAL: usize = 1;
- pub const OP_SETLOCAL: usize = 2;
- pub const OP_GETBLOCKPARAM: usize = 3;
- pub const OP_SETBLOCKPARAM: usize = 4;
- pub const OP_GETBLOCKPARAMPROXY: usize = 5;
- pub const OP_GETSPECIAL: usize = 6;
- pub const OP_SETSPECIAL: usize = 7;
- pub const OP_GETINSTANCEVARIABLE: usize = 8;
- pub const OP_SETINSTANCEVARIABLE: usize = 9;
- pub const OP_GETCLASSVARIABLE: usize = 10;
- pub const OP_SETCLASSVARIABLE: usize = 11;
- pub const OP_GETCONSTANT: usize = 12;
- pub const OP_SETCONSTANT: usize = 13;
- pub const OP_GETGLOBAL: usize = 14;
- pub const OP_SETGLOBAL: usize = 15;
- pub const OP_PUTNIL: usize = 16;
- pub const OP_PUTSELF: usize = 17;
- pub const OP_PUTOBJECT: usize = 18;
- pub const OP_PUTSPECIALOBJECT: usize = 19;
- pub const OP_PUTSTRING: usize = 20;
- pub const OP_CONCATSTRINGS: usize = 21;
- pub const OP_ANYTOSTRING: usize = 22;
- pub const OP_TOREGEXP: usize = 23;
- pub const OP_INTERN: usize = 24;
- pub const OP_NEWARRAY: usize = 25;
- pub const OP_NEWARRAYKWSPLAT: usize = 26;
- pub const OP_DUPARRAY: usize = 27;
- pub const OP_DUPHASH: usize = 28;
- pub const OP_EXPANDARRAY: usize = 29;
- pub const OP_CONCATARRAY: usize = 30;
- pub const OP_SPLATARRAY: usize = 31;
- pub const OP_NEWHASH: usize = 32;
- pub const OP_NEWRANGE: usize = 33;
- pub const OP_POP: usize = 34;
- pub const OP_DUP: usize = 35;
- pub const OP_DUPN: usize = 36;
- pub const OP_SWAP: usize = 37;
- pub const OP_TOPN: usize = 38;
- pub const OP_SETN: usize = 39;
- pub const OP_ADJUSTSTACK: usize = 40;
- pub const OP_DEFINED: usize = 41;
- pub const OP_CHECKMATCH: usize = 42;
- pub const OP_CHECKKEYWORD: usize = 43;
- pub const OP_CHECKTYPE: usize = 44;
- pub const OP_DEFINECLASS: usize = 45;
- pub const OP_DEFINEMETHOD: usize = 46;
- pub const OP_DEFINESMETHOD: usize = 47;
- pub const OP_SEND: usize = 48;
- pub const OP_OPT_SEND_WITHOUT_BLOCK: usize = 49;
- pub const OP_OBJTOSTRING: usize = 50;
- pub const OP_OPT_STR_FREEZE: usize = 51;
- pub const OP_OPT_NIL_P: usize = 52;
- pub const OP_OPT_STR_UMINUS: usize = 53;
- pub const OP_OPT_NEWARRAY_MAX: usize = 54;
- pub const OP_OPT_NEWARRAY_MIN: usize = 55;
- pub const OP_INVOKESUPER: usize = 56;
- pub const OP_INVOKEBLOCK: usize = 57;
- pub const OP_LEAVE: usize = 58;
- pub const OP_THROW: usize = 59;
- pub const OP_JUMP: usize = 60;
- pub const OP_BRANCHIF: usize = 61;
- pub const OP_BRANCHUNLESS: usize = 62;
- pub const OP_BRANCHNIL: usize = 63;
- pub const OP_OPT_GETINLINECACHE: usize = 64;
- pub const OP_OPT_SETINLINECACHE: usize = 65;
- pub const OP_ONCE: usize = 66;
- pub const OP_OPT_CASE_DISPATCH: usize = 67;
- pub const OP_OPT_PLUS: usize = 68;
- pub const OP_OPT_MINUS: usize = 69;
- pub const OP_OPT_MULT: usize = 70;
- pub const OP_OPT_DIV: usize = 71;
- pub const OP_OPT_MOD: usize = 72;
- pub const OP_OPT_EQ: usize = 73;
- pub const OP_OPT_NEQ: usize = 74;
- pub const OP_OPT_LT: usize = 75;
- pub const OP_OPT_LE: usize = 76;
- pub const OP_OPT_GT: usize = 77;
- pub const OP_OPT_GE: usize = 78;
- pub const OP_OPT_LTLT: usize = 79;
- pub const OP_OPT_AND: usize = 80;
- pub const OP_OPT_OR: usize = 81;
- pub const OP_OPT_AREF: usize = 82;
- pub const OP_OPT_ASET: usize = 83;
- pub const OP_OPT_ASET_WITH: usize = 84;
- pub const OP_OPT_AREF_WITH: usize = 85;
- pub const OP_OPT_LENGTH: usize = 86;
- pub const OP_OPT_SIZE: usize = 87;
- pub const OP_OPT_EMPTY_P: usize = 88;
- pub const OP_OPT_SUCC: usize = 89;
- pub const OP_OPT_NOT: usize = 90;
- pub const OP_OPT_REGEXPMATCH2: usize = 91;
- pub const OP_INVOKEBUILTIN: usize = 92;
- pub const OP_OPT_INVOKEBUILTIN_DELEGATE: usize = 93;
- pub const OP_OPT_INVOKEBUILTIN_DELEGATE_LEAVE: usize = 94;
- pub const OP_GETLOCAL_WC_0: usize = 95;
- pub const OP_GETLOCAL_WC_1: usize = 96;
- pub const OP_SETLOCAL_WC_0: usize = 97;
- pub const OP_SETLOCAL_WC_1: usize = 98;
- pub const OP_PUTOBJECT_INT2FIX_0_: usize = 99;
- pub const OP_PUTOBJECT_INT2FIX_1_: usize = 100;
-
- pub const VM_INSTRUCTION_SIZE: usize = 202;
-}
-pub use vm_opcodes::*;
diff --git a/yjit/src/cruby_bindings.inc.rs b/yjit/src/cruby_bindings.inc.rs
index d1bba429d0..d68605bf2e 100644
--- a/yjit/src/cruby_bindings.inc.rs
+++ b/yjit/src/cruby_bindings.inc.rs
@@ -680,6 +680,210 @@ pub struct rb_builtin_function {
),
>,
}
+pub const YARVINSN_nop: ruby_vminsn_type = 0;
+pub const YARVINSN_getlocal: ruby_vminsn_type = 1;
+pub const YARVINSN_setlocal: ruby_vminsn_type = 2;
+pub const YARVINSN_getblockparam: ruby_vminsn_type = 3;
+pub const YARVINSN_setblockparam: ruby_vminsn_type = 4;
+pub const YARVINSN_getblockparamproxy: ruby_vminsn_type = 5;
+pub const YARVINSN_getspecial: ruby_vminsn_type = 6;
+pub const YARVINSN_setspecial: ruby_vminsn_type = 7;
+pub const YARVINSN_getinstancevariable: ruby_vminsn_type = 8;
+pub const YARVINSN_setinstancevariable: ruby_vminsn_type = 9;
+pub const YARVINSN_getclassvariable: ruby_vminsn_type = 10;
+pub const YARVINSN_setclassvariable: ruby_vminsn_type = 11;
+pub const YARVINSN_getconstant: ruby_vminsn_type = 12;
+pub const YARVINSN_setconstant: ruby_vminsn_type = 13;
+pub const YARVINSN_getglobal: ruby_vminsn_type = 14;
+pub const YARVINSN_setglobal: ruby_vminsn_type = 15;
+pub const YARVINSN_putnil: ruby_vminsn_type = 16;
+pub const YARVINSN_putself: ruby_vminsn_type = 17;
+pub const YARVINSN_putobject: ruby_vminsn_type = 18;
+pub const YARVINSN_putspecialobject: ruby_vminsn_type = 19;
+pub const YARVINSN_putstring: ruby_vminsn_type = 20;
+pub const YARVINSN_concatstrings: ruby_vminsn_type = 21;
+pub const YARVINSN_anytostring: ruby_vminsn_type = 22;
+pub const YARVINSN_toregexp: ruby_vminsn_type = 23;
+pub const YARVINSN_intern: ruby_vminsn_type = 24;
+pub const YARVINSN_newarray: ruby_vminsn_type = 25;
+pub const YARVINSN_newarraykwsplat: ruby_vminsn_type = 26;
+pub const YARVINSN_duparray: ruby_vminsn_type = 27;
+pub const YARVINSN_duphash: ruby_vminsn_type = 28;
+pub const YARVINSN_expandarray: ruby_vminsn_type = 29;
+pub const YARVINSN_concatarray: ruby_vminsn_type = 30;
+pub const YARVINSN_splatarray: ruby_vminsn_type = 31;
+pub const YARVINSN_newhash: ruby_vminsn_type = 32;
+pub const YARVINSN_newrange: ruby_vminsn_type = 33;
+pub const YARVINSN_pop: ruby_vminsn_type = 34;
+pub const YARVINSN_dup: ruby_vminsn_type = 35;
+pub const YARVINSN_dupn: ruby_vminsn_type = 36;
+pub const YARVINSN_swap: ruby_vminsn_type = 37;
+pub const YARVINSN_topn: ruby_vminsn_type = 38;
+pub const YARVINSN_setn: ruby_vminsn_type = 39;
+pub const YARVINSN_adjuststack: ruby_vminsn_type = 40;
+pub const YARVINSN_defined: ruby_vminsn_type = 41;
+pub const YARVINSN_checkmatch: ruby_vminsn_type = 42;
+pub const YARVINSN_checkkeyword: ruby_vminsn_type = 43;
+pub const YARVINSN_checktype: ruby_vminsn_type = 44;
+pub const YARVINSN_defineclass: ruby_vminsn_type = 45;
+pub const YARVINSN_definemethod: ruby_vminsn_type = 46;
+pub const YARVINSN_definesmethod: ruby_vminsn_type = 47;
+pub const YARVINSN_send: ruby_vminsn_type = 48;
+pub const YARVINSN_opt_send_without_block: ruby_vminsn_type = 49;
+pub const YARVINSN_objtostring: ruby_vminsn_type = 50;
+pub const YARVINSN_opt_str_freeze: ruby_vminsn_type = 51;
+pub const YARVINSN_opt_nil_p: ruby_vminsn_type = 52;
+pub const YARVINSN_opt_str_uminus: ruby_vminsn_type = 53;
+pub const YARVINSN_opt_newarray_max: ruby_vminsn_type = 54;
+pub const YARVINSN_opt_newarray_min: ruby_vminsn_type = 55;
+pub const YARVINSN_invokesuper: ruby_vminsn_type = 56;
+pub const YARVINSN_invokeblock: ruby_vminsn_type = 57;
+pub const YARVINSN_leave: ruby_vminsn_type = 58;
+pub const YARVINSN_throw: ruby_vminsn_type = 59;
+pub const YARVINSN_jump: ruby_vminsn_type = 60;
+pub const YARVINSN_branchif: ruby_vminsn_type = 61;
+pub const YARVINSN_branchunless: ruby_vminsn_type = 62;
+pub const YARVINSN_branchnil: ruby_vminsn_type = 63;
+pub const YARVINSN_opt_getinlinecache: ruby_vminsn_type = 64;
+pub const YARVINSN_opt_setinlinecache: ruby_vminsn_type = 65;
+pub const YARVINSN_once: ruby_vminsn_type = 66;
+pub const YARVINSN_opt_case_dispatch: ruby_vminsn_type = 67;
+pub const YARVINSN_opt_plus: ruby_vminsn_type = 68;
+pub const YARVINSN_opt_minus: ruby_vminsn_type = 69;
+pub const YARVINSN_opt_mult: ruby_vminsn_type = 70;
+pub const YARVINSN_opt_div: ruby_vminsn_type = 71;
+pub const YARVINSN_opt_mod: ruby_vminsn_type = 72;
+pub const YARVINSN_opt_eq: ruby_vminsn_type = 73;
+pub const YARVINSN_opt_neq: ruby_vminsn_type = 74;
+pub const YARVINSN_opt_lt: ruby_vminsn_type = 75;
+pub const YARVINSN_opt_le: ruby_vminsn_type = 76;
+pub const YARVINSN_opt_gt: ruby_vminsn_type = 77;
+pub const YARVINSN_opt_ge: ruby_vminsn_type = 78;
+pub const YARVINSN_opt_ltlt: ruby_vminsn_type = 79;
+pub const YARVINSN_opt_and: ruby_vminsn_type = 80;
+pub const YARVINSN_opt_or: ruby_vminsn_type = 81;
+pub const YARVINSN_opt_aref: ruby_vminsn_type = 82;
+pub const YARVINSN_opt_aset: ruby_vminsn_type = 83;
+pub const YARVINSN_opt_aset_with: ruby_vminsn_type = 84;
+pub const YARVINSN_opt_aref_with: ruby_vminsn_type = 85;
+pub const YARVINSN_opt_length: ruby_vminsn_type = 86;
+pub const YARVINSN_opt_size: ruby_vminsn_type = 87;
+pub const YARVINSN_opt_empty_p: ruby_vminsn_type = 88;
+pub const YARVINSN_opt_succ: ruby_vminsn_type = 89;
+pub const YARVINSN_opt_not: ruby_vminsn_type = 90;
+pub const YARVINSN_opt_regexpmatch2: ruby_vminsn_type = 91;
+pub const YARVINSN_invokebuiltin: ruby_vminsn_type = 92;
+pub const YARVINSN_opt_invokebuiltin_delegate: ruby_vminsn_type = 93;
+pub const YARVINSN_opt_invokebuiltin_delegate_leave: ruby_vminsn_type = 94;
+pub const YARVINSN_getlocal_WC_0: ruby_vminsn_type = 95;
+pub const YARVINSN_getlocal_WC_1: ruby_vminsn_type = 96;
+pub const YARVINSN_setlocal_WC_0: ruby_vminsn_type = 97;
+pub const YARVINSN_setlocal_WC_1: ruby_vminsn_type = 98;
+pub const YARVINSN_putobject_INT2FIX_0_: ruby_vminsn_type = 99;
+pub const YARVINSN_putobject_INT2FIX_1_: ruby_vminsn_type = 100;
+pub const YARVINSN_trace_nop: ruby_vminsn_type = 101;
+pub const YARVINSN_trace_getlocal: ruby_vminsn_type = 102;
+pub const YARVINSN_trace_setlocal: ruby_vminsn_type = 103;
+pub const YARVINSN_trace_getblockparam: ruby_vminsn_type = 104;
+pub const YARVINSN_trace_setblockparam: ruby_vminsn_type = 105;
+pub const YARVINSN_trace_getblockparamproxy: ruby_vminsn_type = 106;
+pub const YARVINSN_trace_getspecial: ruby_vminsn_type = 107;
+pub const YARVINSN_trace_setspecial: ruby_vminsn_type = 108;
+pub const YARVINSN_trace_getinstancevariable: ruby_vminsn_type = 109;
+pub const YARVINSN_trace_setinstancevariable: ruby_vminsn_type = 110;
+pub const YARVINSN_trace_getclassvariable: ruby_vminsn_type = 111;
+pub const YARVINSN_trace_setclassvariable: ruby_vminsn_type = 112;
+pub const YARVINSN_trace_getconstant: ruby_vminsn_type = 113;
+pub const YARVINSN_trace_setconstant: ruby_vminsn_type = 114;
+pub const YARVINSN_trace_getglobal: ruby_vminsn_type = 115;
+pub const YARVINSN_trace_setglobal: ruby_vminsn_type = 116;
+pub const YARVINSN_trace_putnil: ruby_vminsn_type = 117;
+pub const YARVINSN_trace_putself: ruby_vminsn_type = 118;
+pub const YARVINSN_trace_putobject: ruby_vminsn_type = 119;
+pub const YARVINSN_trace_putspecialobject: ruby_vminsn_type = 120;
+pub const YARVINSN_trace_putstring: ruby_vminsn_type = 121;
+pub const YARVINSN_trace_concatstrings: ruby_vminsn_type = 122;
+pub const YARVINSN_trace_anytostring: ruby_vminsn_type = 123;
+pub const YARVINSN_trace_toregexp: ruby_vminsn_type = 124;
+pub const YARVINSN_trace_intern: ruby_vminsn_type = 125;
+pub const YARVINSN_trace_newarray: ruby_vminsn_type = 126;
+pub const YARVINSN_trace_newarraykwsplat: ruby_vminsn_type = 127;
+pub const YARVINSN_trace_duparray: ruby_vminsn_type = 128;
+pub const YARVINSN_trace_duphash: ruby_vminsn_type = 129;
+pub const YARVINSN_trace_expandarray: ruby_vminsn_type = 130;
+pub const YARVINSN_trace_concatarray: ruby_vminsn_type = 131;
+pub const YARVINSN_trace_splatarray: ruby_vminsn_type = 132;
+pub const YARVINSN_trace_newhash: ruby_vminsn_type = 133;
+pub const YARVINSN_trace_newrange: ruby_vminsn_type = 134;
+pub const YARVINSN_trace_pop: ruby_vminsn_type = 135;
+pub const YARVINSN_trace_dup: ruby_vminsn_type = 136;
+pub const YARVINSN_trace_dupn: ruby_vminsn_type = 137;
+pub const YARVINSN_trace_swap: ruby_vminsn_type = 138;
+pub const YARVINSN_trace_topn: ruby_vminsn_type = 139;
+pub const YARVINSN_trace_setn: ruby_vminsn_type = 140;
+pub const YARVINSN_trace_adjuststack: ruby_vminsn_type = 141;
+pub const YARVINSN_trace_defined: ruby_vminsn_type = 142;
+pub const YARVINSN_trace_checkmatch: ruby_vminsn_type = 143;
+pub const YARVINSN_trace_checkkeyword: ruby_vminsn_type = 144;
+pub const YARVINSN_trace_checktype: ruby_vminsn_type = 145;
+pub const YARVINSN_trace_defineclass: ruby_vminsn_type = 146;
+pub const YARVINSN_trace_definemethod: ruby_vminsn_type = 147;
+pub const YARVINSN_trace_definesmethod: ruby_vminsn_type = 148;
+pub const YARVINSN_trace_send: ruby_vminsn_type = 149;
+pub const YARVINSN_trace_opt_send_without_block: ruby_vminsn_type = 150;
+pub const YARVINSN_trace_objtostring: ruby_vminsn_type = 151;
+pub const YARVINSN_trace_opt_str_freeze: ruby_vminsn_type = 152;
+pub const YARVINSN_trace_opt_nil_p: ruby_vminsn_type = 153;
+pub const YARVINSN_trace_opt_str_uminus: ruby_vminsn_type = 154;
+pub const YARVINSN_trace_opt_newarray_max: ruby_vminsn_type = 155;
+pub const YARVINSN_trace_opt_newarray_min: ruby_vminsn_type = 156;
+pub const YARVINSN_trace_invokesuper: ruby_vminsn_type = 157;
+pub const YARVINSN_trace_invokeblock: ruby_vminsn_type = 158;
+pub const YARVINSN_trace_leave: ruby_vminsn_type = 159;
+pub const YARVINSN_trace_throw: ruby_vminsn_type = 160;
+pub const YARVINSN_trace_jump: ruby_vminsn_type = 161;
+pub const YARVINSN_trace_branchif: ruby_vminsn_type = 162;
+pub const YARVINSN_trace_branchunless: ruby_vminsn_type = 163;
+pub const YARVINSN_trace_branchnil: ruby_vminsn_type = 164;
+pub const YARVINSN_trace_opt_getinlinecache: ruby_vminsn_type = 165;
+pub const YARVINSN_trace_opt_setinlinecache: ruby_vminsn_type = 166;
+pub const YARVINSN_trace_once: ruby_vminsn_type = 167;
+pub const YARVINSN_trace_opt_case_dispatch: ruby_vminsn_type = 168;
+pub const YARVINSN_trace_opt_plus: ruby_vminsn_type = 169;
+pub const YARVINSN_trace_opt_minus: ruby_vminsn_type = 170;
+pub const YARVINSN_trace_opt_mult: ruby_vminsn_type = 171;
+pub const YARVINSN_trace_opt_div: ruby_vminsn_type = 172;
+pub const YARVINSN_trace_opt_mod: ruby_vminsn_type = 173;
+pub const YARVINSN_trace_opt_eq: ruby_vminsn_type = 174;
+pub const YARVINSN_trace_opt_neq: ruby_vminsn_type = 175;
+pub const YARVINSN_trace_opt_lt: ruby_vminsn_type = 176;
+pub const YARVINSN_trace_opt_le: ruby_vminsn_type = 177;
+pub const YARVINSN_trace_opt_gt: ruby_vminsn_type = 178;
+pub const YARVINSN_trace_opt_ge: ruby_vminsn_type = 179;
+pub const YARVINSN_trace_opt_ltlt: ruby_vminsn_type = 180;
+pub const YARVINSN_trace_opt_and: ruby_vminsn_type = 181;
+pub const YARVINSN_trace_opt_or: ruby_vminsn_type = 182;
+pub const YARVINSN_trace_opt_aref: ruby_vminsn_type = 183;
+pub const YARVINSN_trace_opt_aset: ruby_vminsn_type = 184;
+pub const YARVINSN_trace_opt_aset_with: ruby_vminsn_type = 185;
+pub const YARVINSN_trace_opt_aref_with: ruby_vminsn_type = 186;
+pub const YARVINSN_trace_opt_length: ruby_vminsn_type = 187;
+pub const YARVINSN_trace_opt_size: ruby_vminsn_type = 188;
+pub const YARVINSN_trace_opt_empty_p: ruby_vminsn_type = 189;
+pub const YARVINSN_trace_opt_succ: ruby_vminsn_type = 190;
+pub const YARVINSN_trace_opt_not: ruby_vminsn_type = 191;
+pub const YARVINSN_trace_opt_regexpmatch2: ruby_vminsn_type = 192;
+pub const YARVINSN_trace_invokebuiltin: ruby_vminsn_type = 193;
+pub const YARVINSN_trace_opt_invokebuiltin_delegate: ruby_vminsn_type = 194;
+pub const YARVINSN_trace_opt_invokebuiltin_delegate_leave: ruby_vminsn_type = 195;
+pub const YARVINSN_trace_getlocal_WC_0: ruby_vminsn_type = 196;
+pub const YARVINSN_trace_getlocal_WC_1: ruby_vminsn_type = 197;
+pub const YARVINSN_trace_setlocal_WC_0: ruby_vminsn_type = 198;
+pub const YARVINSN_trace_setlocal_WC_1: ruby_vminsn_type = 199;
+pub const YARVINSN_trace_putobject_INT2FIX_0_: ruby_vminsn_type = 200;
+pub const YARVINSN_trace_putobject_INT2FIX_1_: ruby_vminsn_type = 201;
+pub const VM_INSTRUCTION_SIZE: ruby_vminsn_type = 202;
+pub type ruby_vminsn_type = u32;
extern "C" {
pub fn rb_vm_insn_addr2opcode(addr: *const ::std::os::raw::c_void) -> ::std::os::raw::c_int;
}
diff --git a/yjit/src/invariants.rs b/yjit/src/invariants.rs
index c31f0ccedc..16843c163f 100644
--- a/yjit/src/invariants.rs
+++ b/yjit/src/invariants.rs
@@ -182,11 +182,11 @@ pub fn assume_stable_constant_names(jit: &mut JITState, ocb: &mut OutlinedCb) {
index: u64,
data: *mut c_void,
) -> bool {
- if insn.as_usize() == OP_OPT_SETINLINECACHE {
+ if insn.as_u32() == YARVINSN_opt_setinlinecache {
return false;
}
- if insn.as_usize() == OP_GETCONSTANT {
+ if insn.as_u32() == YARVINSN_getconstant {
let jit = &mut *(data as *mut JITState);
// The first operand to GETCONSTANT is always the ID associated with
@@ -474,7 +474,7 @@ pub extern "C" fn rb_yjit_constant_ic_update(iseq: *const rb_iseq_t, ic: IC) {
let translated_opcode: VALUE = opcode_pc.read();
rb_vm_insn_decode(translated_opcode)
},
- OP_OPT_GETINLINECACHE.try_into().unwrap()
+ YARVINSN_opt_getinlinecache.try_into().unwrap()
);
// Find the matching opt_getinlinecache and invalidate all the blocks there
diff --git a/yjit/src/stats.rs b/yjit/src/stats.rs
index 7fbf132e18..3b7a3f31d9 100644
--- a/yjit/src/stats.rs
+++ b/yjit/src/stats.rs
@@ -9,7 +9,8 @@ use crate::options::*;
use crate::yjit::yjit_enabled_p;
// YJIT exit counts for each instruction type
-static mut EXIT_OP_COUNT: [u64; VM_INSTRUCTION_SIZE] = [0; VM_INSTRUCTION_SIZE];
+const VM_INSTRUCTION_SIZE_USIZE:usize = VM_INSTRUCTION_SIZE as usize;
+static mut EXIT_OP_COUNT: [u64; VM_INSTRUCTION_SIZE_USIZE] = [0; VM_INSTRUCTION_SIZE_USIZE];
// Macro to declare the stat counters
macro_rules! make_counters {
@@ -218,7 +219,7 @@ fn rb_yjit_gen_stats_dict() -> VALUE {
// For each entry in exit_op_count, add a stats entry with key "exit_INSTRUCTION_NAME"
// and the value is the count of side exits for that instruction.
- for op_idx in 0..VM_INSTRUCTION_SIZE {
+ for op_idx in 0..VM_INSTRUCTION_SIZE_USIZE {
let op_name = insn_name(op_idx);
let key_string = "exit_".to_owned() + &op_name;
let key = rust_str_to_sym(&key_string);
@@ -234,7 +235,7 @@ fn rb_yjit_gen_stats_dict() -> VALUE {
#[no_mangle]
pub extern "C" fn rb_yjit_reset_stats_bang(_ec: EcPtr, _ruby_self: VALUE) -> VALUE {
unsafe {
- EXIT_OP_COUNT = [0; VM_INSTRUCTION_SIZE];
+ EXIT_OP_COUNT = [0; VM_INSTRUCTION_SIZE_USIZE];
COUNTERS = Counters::default();
}