Skip to content
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

YJIT: Compress TempMapping #7368

Merged
merged 1 commit into from Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions yjit/src/codegen.rs
Expand Up @@ -318,6 +318,7 @@ fn verify_ctx(jit: &JITState, ctx: &Context) {
}
}
TempMapping::MapToLocal(local_idx) => {
let local_idx: u8 = local_idx.into();
let local_val = jit.peek_at_local(local_idx.into());
if local_val != stack_val {
panic!(
Expand Down
48 changes: 46 additions & 2 deletions yjit/src/core.rs
Expand Up @@ -274,10 +274,54 @@ impl Type {
pub enum TempMapping {
MapToStack, // Normal stack value
MapToSelf, // Temp maps to the self operand
MapToLocal(u8), // Temp maps to a local variable with index
MapToLocal(LocalIndex), // Temp maps to a local variable with index
//ConstMapping, // Small constant (0, 1, 2, Qnil, Qfalse, Qtrue)
}

// Index used by MapToLocal. Using this instead of u8 makes TempMapping 1 byte.
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum LocalIndex {
Local0,
Local1,
Local2,
Local3,
Local4,
Local5,
Local6,
Local7,
}

impl From<LocalIndex> for u8 {
fn from(idx: LocalIndex) -> Self {
match idx {
LocalIndex::Local0 => 0,
LocalIndex::Local1 => 1,
LocalIndex::Local2 => 2,
LocalIndex::Local3 => 3,
LocalIndex::Local4 => 4,
LocalIndex::Local5 => 5,
LocalIndex::Local6 => 6,
LocalIndex::Local7 => 7,
}
}
}

impl From<u8> for LocalIndex {
fn from(idx: u8) -> Self {
match idx {
0 => LocalIndex::Local0,
1 => LocalIndex::Local1,
2 => LocalIndex::Local2,
3 => LocalIndex::Local3,
4 => LocalIndex::Local4,
5 => LocalIndex::Local5,
6 => LocalIndex::Local6,
7 => LocalIndex::Local7,
_ => unreachable!("{idx} was larger than {MAX_LOCAL_TYPES}"),
}
}
}

impl Default for TempMapping {
fn default() -> Self {
MapToStack
Expand Down Expand Up @@ -1205,7 +1249,7 @@ impl Context {
return self.stack_push(Type::Unknown);
}

return self.stack_push_mapping((MapToLocal(local_idx as u8), Type::Unknown));
return self.stack_push_mapping((MapToLocal((local_idx as u8).into()), Type::Unknown));
}

// Pop N values off the stack
Expand Down