From 2c90da465a7ff601007b324f5ab4959ef6277a89 Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Tue, 28 Oct 2025 10:36:37 -0400 Subject: ZJIT: Count GuardType instructions We can measure how many we can remove by adding type information to C functions, etc. --- zjit.rb | 2 ++ zjit/src/codegen.rs | 1 + zjit/src/stats.rs | 3 +++ 3 files changed, 6 insertions(+) diff --git a/zjit.rb b/zjit.rb index 9ea83fe10f..b62d8e2b52 100644 --- a/zjit.rb +++ b/zjit.rb @@ -197,6 +197,8 @@ class << RubyVM::ZJIT :vm_write_to_parent_iseq_local_count, :vm_read_from_parent_iseq_local_count, + :guard_type_count, + :code_region_bytes, :side_exit_count, :total_insn_count, diff --git a/zjit/src/codegen.rs b/zjit/src/codegen.rs index bfbc8e88b9..2b71be0e15 100644 --- a/zjit/src/codegen.rs +++ b/zjit/src/codegen.rs @@ -1595,6 +1595,7 @@ fn gen_test(asm: &mut Assembler, val: lir::Opnd) -> lir::Opnd { /// Compile a type check with a side exit fn gen_guard_type(jit: &mut JITState, asm: &mut Assembler, val: lir::Opnd, guard_type: Type, state: &FrameState) -> lir::Opnd { + gen_incr_counter(asm, Counter::guard_type_count); if guard_type.is_subtype(types::Fixnum) { asm.test(val, Opnd::UImm(RUBY_FIXNUM_FLAG as u64)); asm.jz(side_exit(jit, state, GuardType(guard_type))); diff --git a/zjit/src/stats.rs b/zjit/src/stats.rs index 5ab81f9ac6..4874d0fe64 100644 --- a/zjit/src/stats.rs +++ b/zjit/src/stats.rs @@ -249,6 +249,9 @@ make_counters! { vm_read_from_parent_iseq_local_count, // TODO(max): Implement // vm_reify_stack_count, + + // The number of times we ran a dynamic check + guard_type_count, } /// Increase a counter by a specified amount -- cgit v1.2.3