diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2023-10-18 19:36:42 -0400 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2023-10-19 11:50:36 -0400 |
commit | 9d9aa63e8240fe2226e756e59876d7b3fe908f1d (patch) | |
tree | 1ca386f17a1d8e0b1421521d38309f6ec13480f8 | |
parent | c2d4c92a98527f416f4f9d5987c22c4cc8f584e7 (diff) |
YJIT: Enable the dead_code lint and delete some dead code
-rw-r--r-- | yjit/src/backend/ir.rs | 69 | ||||
-rw-r--r-- | yjit/src/backend/tests.rs | 19 |
2 files changed, 6 insertions, 82 deletions
diff --git a/yjit/src/backend/ir.rs b/yjit/src/backend/ir.rs index 35eccd51cf..5de65f8ecb 100644 --- a/yjit/src/backend/ir.rs +++ b/yjit/src/backend/ir.rs @@ -1,7 +1,3 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -use std::cell::Cell; use std::collections::HashMap; use std::fmt; use std::convert::From; @@ -152,13 +148,6 @@ impl Opnd } } - pub fn is_some(&self) -> bool { - match *self { - Opnd::None => false, - _ => true, - } - } - /// Unwrap a register operand pub fn unwrap_reg(&self) -> Reg { match self { @@ -353,6 +342,7 @@ pub enum Insn { BakeString(String), // Trigger a debugger breakpoint + #[allow(dead_code)] Breakpoint, /// Add a comment into the IR at the point that this instruction is added. @@ -1152,7 +1142,7 @@ impl Assembler } match opnd { - Opnd::Stack { idx, num_bits, stack_size, sp_offset, reg_temps } => { + Opnd::Stack { reg_temps, .. } => { if opnd.stack_idx() < MAX_REG_TEMPS && reg_temps.unwrap().get(opnd.stack_idx()) { reg_opnd(opnd) } else { @@ -1551,11 +1541,6 @@ impl Assembler pub fn into_draining_iter(self) -> AssemblerDrainingIterator { AssemblerDrainingIterator::new(self) } - - /// Consume the assembler by creating a new lookback iterator. - pub fn into_lookback_iter(self) -> AssemblerLookbackIterator { - AssemblerLookbackIterator::new(self) - } } /// A struct that allows iterating through an assembler's instructions and @@ -1587,6 +1572,7 @@ impl AssemblerDrainingIterator { } /// Map an operand by using this iterator's list of mapped indices. + #[cfg(target_arch = "x86_64")] pub fn map_opnd(&self, opnd: Opnd) -> Opnd { opnd.map_index(&self.indices) } @@ -1618,52 +1604,6 @@ impl AssemblerDrainingIterator { } } -/// A struct that allows iterating through references to an assembler's -/// instructions without consuming them. -pub struct AssemblerLookbackIterator { - asm: Assembler, - index: Cell<usize> -} - -impl AssemblerLookbackIterator { - fn new(asm: Assembler) -> Self { - Self { asm, index: Cell::new(0) } - } - - /// Fetches a reference to an instruction at a specific index. - pub fn get(&self, index: usize) -> Option<&Insn> { - self.asm.insns.get(index) - } - - /// Fetches a reference to an instruction in the list relative to the - /// current cursor location of this iterator. - pub fn get_relative(&self, difference: i32) -> Option<&Insn> { - let index: Result<i32, _> = self.index.get().try_into(); - let relative: Result<usize, _> = index.and_then(|value| (value + difference).try_into()); - relative.ok().and_then(|value| self.asm.insns.get(value)) - } - - /// Fetches the previous instruction relative to the current cursor location - /// of this iterator. - pub fn get_previous(&self) -> Option<&Insn> { - self.get_relative(-1) - } - - /// Fetches the next instruction relative to the current cursor location of - /// this iterator. - pub fn get_next(&self) -> Option<&Insn> { - self.get_relative(1) - } - - /// Returns the next instruction in the list with the indices corresponding - /// to the previous list of instructions. - pub fn next_unmapped(&self) -> Option<(usize, &Insn)> { - let index = self.index.get(); - self.index.set(index + 1); - self.asm.insns.get(index).map(|insn| (index, insn)) - } -} - impl fmt::Debug for Assembler { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { writeln!(fmt, "Assembler")?; @@ -1695,6 +1635,7 @@ impl Assembler { self.push_insn(Insn::BakeString(text.to_string())); } + #[allow(dead_code)] pub fn breakpoint(&mut self) { self.push_insn(Insn::Breakpoint); } @@ -1847,6 +1788,7 @@ impl Assembler { self.push_insn(Insn::Jl(target)); } + #[allow(dead_code)] pub fn jg(&mut self, target: Target) { self.push_insn(Insn::Jg(target)); } @@ -1985,6 +1927,7 @@ impl Assembler { } #[must_use] + #[allow(dead_code)] pub fn urshift(&mut self, opnd: Opnd, shift: Opnd) -> Opnd { let out = self.next_opnd_out(Opnd::match_num_bits(&[opnd, shift])); self.push_insn(Insn::URShift { opnd, shift, out }); diff --git a/yjit/src/backend/tests.rs b/yjit/src/backend/tests.rs index 985e5a0e94..774a02dc6b 100644 --- a/yjit/src/backend/tests.rs +++ b/yjit/src/backend/tests.rs @@ -303,25 +303,6 @@ fn test_draining_iterator() { } #[test] -fn test_lookback_iterator() { - let mut asm = Assembler::new(); - - let _ = asm.load(Opnd::None); - asm.store(Opnd::None, Opnd::None); - asm.store(Opnd::None, Opnd::None); - - let iter = asm.into_lookback_iter(); - - while let Some((index, insn)) = iter.next_unmapped() { - if index > 0 { - let opnd_iter = iter.get_previous().unwrap().opnd_iter(); - assert_eq!(opnd_iter.take(1).next(), Some(&Opnd::None)); - assert!(matches!(insn, Insn::Store { .. })); - } - } -} - -#[test] fn test_cmp_8_bit() { let (mut asm, mut cb) = setup_asm(); let reg = Assembler::get_alloc_regs()[0]; |