-
Notifications
You must be signed in to change notification settings - Fork 5.5k
ZJIT: Handle ZJIT options properly #13197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| use std::{ffi::CStr, os::raw::c_char}; | ||
| use std::{ffi::{CStr, CString}, ptr::null}; | ||
| use std::os::raw::{c_char, c_int, c_uint}; | ||
|
|
||
| /// Number of calls to start profiling YARV instructions. | ||
| /// They are profiled `rb_zjit_call_threshold - rb_zjit_profile_threshold` times, | ||
|
|
@@ -34,6 +35,25 @@ pub struct Options { | |
| pub dump_disasm: bool, | ||
| } | ||
|
|
||
| /// Return an Options with default values | ||
| pub fn init_options() -> Options { | ||
| Options { | ||
| num_profiles: 1, | ||
| debug: false, | ||
| dump_hir_init: None, | ||
| dump_hir_opt: None, | ||
| dump_lir: false, | ||
| dump_disasm: false, | ||
| } | ||
| } | ||
|
|
||
| /// `ruby --help` descriptions for user-facing options. Do not add options for ZJIT developers. | ||
| /// Note that --help allows only 80 chars per line, including indentation. 80-char limit --> | | ||
| pub const ZJIT_OPTIONS: &'static [(&str, &str)] = &[ | ||
| ("--zjit-call-threshold=num", "Number of calls to trigger JIT (default: 2)."), | ||
| ("--zjit-num-profiles=num", "Number of profiled calls before JIT (default: 1)."), | ||
| ]; | ||
|
|
||
| #[derive(Clone, Copy, Debug)] | ||
| pub enum DumpHIR { | ||
| // Dump High-level IR without Snapshot | ||
|
|
@@ -66,18 +86,6 @@ pub extern "C" fn rb_zjit_init_options() -> *const u8 { | |
| Box::into_raw(Box::new(options)) as *const u8 | ||
| } | ||
|
|
||
| /// Return an Options with default values | ||
| pub fn init_options() -> Options { | ||
| Options { | ||
| num_profiles: 1, | ||
| debug: false, | ||
| dump_hir_init: None, | ||
| dump_hir_opt: None, | ||
| dump_lir: false, | ||
| dump_disasm: false, | ||
| } | ||
| } | ||
|
|
||
| /// Parse a --zjit* command-line flag | ||
| #[unsafe(no_mangle)] | ||
| pub extern "C" fn rb_zjit_parse_option(options: *const u8, str_ptr: *const c_char) -> bool { | ||
|
|
@@ -155,6 +163,21 @@ fn update_profile_threshold(options: &Options) { | |
| } | ||
| } | ||
|
|
||
| /// Print YJIT options for `ruby --help`. `width` is width of option parts, and | ||
| /// `columns` is indent width of descriptions. | ||
| #[unsafe(no_mangle)] | ||
| pub extern "C" fn rb_zjit_show_usage(help: c_int, highlight: c_int, width: c_uint, columns: c_int) { | ||
| for &(name, description) in ZJIT_OPTIONS.iter() { | ||
| unsafe 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, width: c_uint, columns: c_int); | ||
| } | ||
| let name = CString::new(name).unwrap(); | ||
| let description = CString::new(description).unwrap(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert 80 cols here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The limitation is more tightly coupled to |
||
| unsafe { ruby_show_usage_line(name.as_ptr(), null(), description.as_ptr(), help, highlight, width, columns) } | ||
| } | ||
| } | ||
|
|
||
| /// Macro to print a message only when --zjit-debug is given | ||
| macro_rules! debug { | ||
| ($($msg:tt)*) => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.