Skip to content

Commit

Permalink
YJIT: Move help descriptions to options.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Oct 4, 2023
1 parent 49d2743 commit 01c462c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
15 changes: 1 addition & 14 deletions ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,18 +391,6 @@ usage(const char *name, int help, int highlight, int columns)
M("experimental", "", "experimental features"),
M("performance", "", "performance issues"),
};
#if USE_YJIT
static const struct ruby_opt_message yjit_options[] = {
M("--yjit-stats", "", "Enable collecting YJIT statistics"),
M("--yjit-trace-exits", "", "Record Ruby source location when exiting from generated code"),
M("--yjit-trace-exits-sample-rate", "", "Trace exit locations only every Nth occurrence"),
M("--yjit-exec-mem-size=num", "", "Size of executable memory block in MiB (default: 128)"),
M("--yjit-call-threshold=num", "", "Number of calls to trigger JIT (default: 30)"),
M("--yjit-cold-threshold=num", "", "Global call after which ISEQs not compiled (default: 200K)"),
M("--yjit-max-versions=num", "", "Maximum number of versions per basic block (default: 4)"),
M("--yjit-greedy-versioning", "", "Greedy versioning mode (default: disabled)"),
};
#endif
#if USE_RJIT
extern const struct ruby_opt_message rb_rjit_option_messages[];
#endif
Expand Down Expand Up @@ -434,8 +422,7 @@ usage(const char *name, int help, int highlight, int columns)
SHOW(warn_categories[i]);
#if USE_YJIT
printf("%s""YJIT options:%s\n", sb, se);
for (i = 0; i < numberof(yjit_options); ++i)
SHOW(yjit_options[i]);
rb_yjit_print_options(help, highlight, w, columns);
#endif
#if USE_RJIT
printf("%s""RJIT options (experimental):%s\n", sb, se);
Expand Down
1 change: 1 addition & 0 deletions yjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void rb_yjit_iseq_free(void *payload);
void rb_yjit_before_ractor_spawn(void);
void rb_yjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic, unsigned insn_idx);
void rb_yjit_tracing_invalidate_all(void);
void rb_yjit_print_options(int help, int highlight, unsigned int w, int columns);

#else
// !USE_YJIT
Expand Down
28 changes: 27 additions & 1 deletion yjit/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::ffi::CStr;
use std::{ffi::{CStr, CString}, ptr::null};
use crate::backend::current::TEMP_REGS;
use std::os::raw::{c_char, c_int, c_uint};

// Command-line options
#[derive(Clone, PartialEq, Eq, Debug)]
Expand Down Expand Up @@ -79,6 +80,17 @@ pub static mut OPTIONS: Options = Options {
dump_iseq_disasm: None,
};

static YJIT_OPTIONS: [(&str, &str); 8] = [
("--yjit-stats", "Enable collecting YJIT statistics"),
("--yjit-trace-exits", "Record Ruby source location when exiting from generated code"),
("--yjit-trace-exits-sample-rate", "Trace exit locations only every Nth occurrence"),
("--yjit-exec-mem-size=num", "Size of executable memory block in MiB (default: 128)"),
("--yjit-call-threshold=num", "Number of calls to trigger JIT (default: 30)"),
("--yjit-cold-threshold=num", "Global call after which ISEQs not compiled (default: 200K)"),
("--yjit-max-versions=num", "Maximum number of versions per basic block (default: 4)"),
("--yjit-greedy-versioning", "Greedy versioning mode (default: disabled)"),
];

#[derive(Clone, PartialEq, Eq, Debug)]
pub enum DumpDisasm {
// Dump to stdout
Expand Down Expand Up @@ -231,3 +243,17 @@ pub fn parse_option(str_ptr: *const std::os::raw::c_char) -> Option<()> {
// Option successfully parsed
return Some(());
}

/// Print YJIT options for `ruby --help`.
#[no_mangle]
pub extern "C" fn rb_yjit_print_options(help: c_int, highlight: c_int, w: c_uint, columns: c_int) {
for &(name, description) in YJIT_OPTIONS.iter() {
extern "C" {
fn ruby_show_usage_line(name: *const c_char, secondary: *const c_char, description: *const c_char,
help: c_int, highlight: c_int, w: c_uint, columns: c_int);
}
let name = CString::new(name).unwrap();
let description = CString::new(description).unwrap();
unsafe { ruby_show_usage_line(name.as_ptr(), null(), description.as_ptr(), help, highlight, w, columns) }
}
}

0 comments on commit 01c462c

Please sign in to comment.