Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup more
  • Loading branch information
ShaharNaveh committed Apr 15, 2026
commit 64d722e62a8c45149661092628f1ac267ddbd630
43 changes: 11 additions & 32 deletions crates/codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2739,8 +2739,7 @@ enum JumpThreadKind {
fn jump_thread_kind(instr: AnyInstruction) -> Option<JumpThreadKind> {
Some(match instr.into() {
AnyOpcode::Pseudo(PseudoOpcode::Jump)
| AnyOpcode::Real(Opcode::JumpForward)
| AnyOpcode::Real(Opcode::JumpBackward) => JumpThreadKind::Plain,
| AnyOpcode::Real(Opcode::JumpForward | Opcode::JumpBackward) => JumpThreadKind::Plain,
AnyOpcode::Pseudo(PseudoOpcode::JumpNoInterrupt)
| AnyOpcode::Real(Opcode::JumpBackwardNoInterrupt) => JumpThreadKind::NoInterrupt,
_ => return None,
Expand All @@ -2761,19 +2760,11 @@ fn threaded_jump_instr(
if source_kind == JumpThreadKind::NoInterrupt {
return Some(source);
}
Some(match source {
AnyInstruction::Pseudo(_) => PseudoInstruction::Jump {
delta: Arg::marker(),
}
.into(),
AnyInstruction::Real(Instruction::JumpBackwardNoInterrupt { .. }) => {
Instruction::JumpBackward {
delta: Arg::marker(),
}
.into()
}
AnyInstruction::Real(Instruction::JumpForward { .. })
| AnyInstruction::Real(Instruction::JumpBackward { .. }) => source,

Some(match source.into() {
AnyOpcode::Pseudo(_) => PseudoOpcode::Jump.into(),
AnyOpcode::Real(Opcode::JumpBackwardNoInterrupt) => Opcode::JumpBackward.into(),
AnyOpcode::Real(Opcode::JumpForward | Opcode::JumpBackward) => source,
_ => return None,
})
}
Expand Down Expand Up @@ -2862,23 +2853,11 @@ fn is_conditional_jump(instr: &AnyInstruction) -> bool {

/// Invert a conditional jump opcode.
fn reversed_conditional(instr: &AnyInstruction) -> Option<AnyInstruction> {
Some(match instr.real()? {
Instruction::PopJumpIfFalse { .. } => Instruction::PopJumpIfTrue {
delta: Arg::marker(),
}
.into(),
Instruction::PopJumpIfTrue { .. } => Instruction::PopJumpIfFalse {
delta: Arg::marker(),
}
.into(),
Instruction::PopJumpIfNone { .. } => Instruction::PopJumpIfNotNone {
delta: Arg::marker(),
}
.into(),
Instruction::PopJumpIfNotNone { .. } => Instruction::PopJumpIfNone {
delta: Arg::marker(),
}
.into(),
Some(match AnyOpcode::from(*instr).real()? {
Opcode::PopJumpIfFalse => Opcode::PopJumpIfTrue.into(),
Opcode::PopJumpIfTrue => Opcode::PopJumpIfFalse.into(),
Opcode::PopJumpIfNone => Opcode::PopJumpIfNotNone.into(),
Opcode::PopJumpIfNotNone => Opcode::PopJumpIfNone.into(),
_ => return None,
})
}
Expand Down
16 changes: 14 additions & 2 deletions crates/compiler-core/src/bytecode/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1601,11 +1601,23 @@ impl TryFrom<u16> for AnyInstruction {
}
}

impl From<Opcode> for AnyInstruction {
fn from(value: Opcode) -> Self {
Self::Real(value.into())
}
}

impl From<PseudoOpcode> for AnyInstruction {
fn from(value: PseudoOpcode) -> Self {
Self::Pseudo(value.into())
}
}

impl From<AnyOpcode> for AnyInstruction {
fn from(value: AnyOpcode) -> Self {
match value {
AnyOpcode::Real(op) => Self::Real(op.into()),
AnyOpcode::Pseudo(op) => Self::Pseudo(op.into()),
AnyOpcode::Real(op) => op.into(),
AnyOpcode::Pseudo(op) => op.into(),
}
}
}
Expand Down
Loading