summaryrefslogtreecommitdiff
path: root/zjit/src/hir.rs
diff options
context:
space:
mode:
-rw-r--r--zjit/src/hir.rs103
1 files changed, 95 insertions, 8 deletions
@@ -206,6 +206,7 @@ impl<'a> std::fmt::Display for InvariantPrinter<'a> {
BOP_FREEZE => write!(f, "BOP_FREEZE")?,
BOP_UMINUS => write!(f, "BOP_UMINUS")?,
BOP_MAX => write!(f, "BOP_MAX")?,
_ => write!(f, "{bop}")?,
}
write!(f, ")")
@@ -1317,6 +1318,25 @@ impl Function {
}
}
/// Rewrite SendWithoutBlock opcodes into SendWithoutBlockDirect opcodes if we know the target
/// ISEQ statically. This removes run-time method lookups and opens the door for inlining.
fn optimize_direct_sends(&mut self) {
@@ -1351,6 +1371,8 @@ impl Function {
self.try_rewrite_freeze(block, insn_id, self_val),
Insn::SendWithoutBlock { self_val, call_info: CallInfo { method_name }, args, .. } if method_name == "-@" && args.len() == 0 =>
self.try_rewrite_uminus(block, insn_id, self_val),
Insn::SendWithoutBlock { mut self_val, call_info, cd, args, state } => {
let frame_state = self.frame_state(state);
let (klass, guard_equal_to) = if let Some(klass) = self.type_of(self_val).runtime_exact_ruby_class() {
@@ -1418,7 +1440,7 @@ impl Function {
if self.is_a(str, types::String) {
self.make_equal_to(insn_id, str);
} else {
- self.push_insn_id(block, insn_id);
}
}
_ => { self.push_insn_id(block, insn_id); }
@@ -2306,7 +2328,12 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
YARVINSN_putobject => { state.stack_push(fun.push_insn(block, Insn::Const { val: Const::Value(get_arg(pc, 0)) })); },
YARVINSN_putspecialobject => {
let value_type = SpecialObjectType::from(get_arg(pc, 0).as_u32());
- state.stack_push(fun.push_insn(block, Insn::PutSpecialObject { value_type }));
}
YARVINSN_putstring => {
let val = fun.push_insn(block, Insn::Const { val: Const::Value(get_arg(pc, 0)) });
@@ -3900,11 +3927,11 @@ mod tests {
assert_method_hir("test", expect![[r#"
fn test:
bb0(v0:BasicObject, v1:BasicObject):
- v3:BasicObject = PutSpecialObject VMCore
v5:HashExact = NewHash
v7:BasicObject = SendWithoutBlock v3, :core#hash_merge_kwd, v5, v1
- v8:BasicObject = PutSpecialObject VMCore
- v9:StaticSymbol[VALUE(0x1000)] = Const Value(VALUE(0x1000))
v10:Fixnum[1] = Const Value(1)
v12:BasicObject = SendWithoutBlock v8, :core#hash_merge_ptr, v7, v9, v10
SideExit
@@ -4352,10 +4379,10 @@ mod tests {
assert_method_hir_with_opcode("test", YARVINSN_putspecialobject, expect![[r#"
fn test:
bb0(v0:BasicObject):
- v2:BasicObject = PutSpecialObject VMCore
v3:BasicObject = PutSpecialObject CBase
- v4:StaticSymbol[VALUE(0x1000)] = Const Value(VALUE(0x1000))
- v5:StaticSymbol[VALUE(0x1008)] = Const Value(VALUE(0x1008))
v7:BasicObject = SendWithoutBlock v2, :core#set_method_alias, v3, v4, v5
Return v7
"#]]);
@@ -6068,4 +6095,64 @@ mod opt_tests {
SideExit
"#]]);
}
}