@@ -18,7 +18,7 @@ pub use crate::backend::current::{
1818} ;
1919pub const SCRATCH_OPND : Opnd = Opnd :: Reg ( Assembler :: SCRATCH_REG ) ;
2020
21- pub static JIT_PRESERVED_REGS : & ' static [ Opnd ] = & [ CFP , SP , EC ] ;
21+ pub static JIT_PRESERVED_REGS : & [ Opnd ] = & [ CFP , SP , EC ] ;
2222
2323// Memory operand base
2424#[ derive( Clone , Copy , PartialEq , Eq , Debug ) ]
@@ -99,17 +99,17 @@ impl Opnd
9999 assert ! ( base_reg. num_bits == 64 ) ;
100100 Opnd :: Mem ( Mem {
101101 base : MemBase :: Reg ( base_reg. reg_no ) ,
102- disp : disp ,
103- num_bits : num_bits ,
102+ disp,
103+ num_bits,
104104 } )
105105 } ,
106106
107107 Opnd :: VReg { idx, num_bits : out_num_bits } => {
108108 assert ! ( num_bits <= out_num_bits) ;
109109 Opnd :: Mem ( Mem {
110110 base : MemBase :: VReg ( idx) ,
111- disp : disp ,
112- num_bits : num_bits ,
111+ disp,
112+ num_bits,
113113 } )
114114 } ,
115115
@@ -1215,8 +1215,8 @@ impl Assembler
12151215 }
12161216
12171217 // If we find any VReg from previous instructions, extend the live range to insn_idx
1218- let mut opnd_iter = insn. opnd_iter ( ) ;
1219- while let Some ( opnd) = opnd_iter. next ( ) {
1218+ let opnd_iter = insn. opnd_iter ( ) ;
1219+ for opnd in opnd_iter {
12201220 match * opnd {
12211221 Opnd :: VReg { idx, .. } |
12221222 Opnd :: Mem ( Mem { base : MemBase :: VReg ( idx) , .. } ) => {
@@ -1243,16 +1243,16 @@ impl Assembler
12431243
12441244 // Shuffle register moves, sometimes adding extra moves using SCRATCH_REG,
12451245 // so that they will not rewrite each other before they are used.
1246- pub fn resolve_parallel_moves ( old_moves : & Vec < ( Reg , Opnd ) > ) -> Vec < ( Reg , Opnd ) > {
1246+ pub fn resolve_parallel_moves ( old_moves : & [ ( Reg , Opnd ) ] ) -> Vec < ( Reg , Opnd ) > {
12471247 // Return the index of a move whose destination is not used as a source if any.
1248- fn find_safe_move ( moves : & Vec < ( Reg , Opnd ) > ) -> Option < usize > {
1248+ fn find_safe_move ( moves : & [ ( Reg , Opnd ) ] ) -> Option < usize > {
12491249 moves. iter ( ) . enumerate ( ) . find ( |& ( _, & ( dest_reg, _) ) | {
12501250 moves. iter ( ) . all ( |& ( _, src_opnd) | src_opnd != Opnd :: Reg ( dest_reg) )
12511251 } ) . map ( |( index, _) | index)
12521252 }
12531253
12541254 // Remove moves whose source and destination are the same
1255- let mut old_moves: Vec < ( Reg , Opnd ) > = old_moves. clone ( ) . into_iter ( )
1255+ let mut old_moves: Vec < ( Reg , Opnd ) > = old_moves. iter ( ) . copied ( )
12561256 . filter ( |& ( reg, opnd) | Opnd :: Reg ( reg) != opnd) . collect ( ) ;
12571257
12581258 let mut new_moves = vec ! [ ] ;
@@ -1386,19 +1386,19 @@ impl Assembler
13861386 Some ( Opnd :: VReg { idx, .. } ) => Some ( * idx) ,
13871387 _ => None ,
13881388 } ;
1389- if vreg_idx . is_some ( ) {
1390- if live_ranges[ vreg_idx. unwrap ( ) ] . end ( ) == index {
1391- debug ! ( "Allocating a register for VReg({}) at instruction index {} even though it does not live past this index" , vreg_idx. unwrap ( ) , index) ;
1389+ if let Some ( vreg_idx ) = vreg_idx {
1390+ if live_ranges[ vreg_idx] . end ( ) == index {
1391+ debug ! ( "Allocating a register for VReg({}) at instruction index {} even though it does not live past this index" , vreg_idx, index) ;
13921392 }
13931393 // This is going to be the output operand that we will set on the
13941394 // instruction. CCall and LiveReg need to use a specific register.
13951395 let mut out_reg = match insn {
13961396 Insn :: CCall { .. } => {
1397- Some ( pool. take_reg ( & C_RET_REG , vreg_idx. unwrap ( ) ) )
1397+ Some ( pool. take_reg ( & C_RET_REG , vreg_idx) )
13981398 }
13991399 Insn :: LiveReg { opnd, .. } => {
14001400 let reg = opnd. unwrap_reg ( ) ;
1401- Some ( pool. take_reg ( & reg, vreg_idx. unwrap ( ) ) )
1401+ Some ( pool. take_reg ( & reg, vreg_idx) )
14021402 }
14031403 _ => None
14041404 } ;
@@ -1414,7 +1414,7 @@ impl Assembler
14141414 if let Some ( Opnd :: VReg { idx, .. } ) = opnd_iter. next ( ) {
14151415 if live_ranges[ * idx] . end ( ) == index {
14161416 if let Some ( reg) = reg_mapping[ * idx] {
1417- out_reg = Some ( pool. take_reg ( & reg, vreg_idx. unwrap ( ) ) ) ;
1417+ out_reg = Some ( pool. take_reg ( & reg, vreg_idx) ) ;
14181418 }
14191419 }
14201420 }
@@ -1423,21 +1423,19 @@ impl Assembler
14231423 // Allocate a new register for this instruction if one is not
14241424 // already allocated.
14251425 if out_reg. is_none ( ) {
1426- out_reg = match & insn {
1427- _ => match pool. alloc_reg ( vreg_idx. unwrap ( ) ) {
1428- Some ( reg) => Some ( reg) ,
1429- None => {
1430- if get_option ! ( debug) {
1431- let mut insns = asm. insns ;
1426+ out_reg = match pool. alloc_reg ( vreg_idx) {
1427+ Some ( reg) => Some ( reg) ,
1428+ None => {
1429+ if get_option ! ( debug) {
1430+ let mut insns = asm. insns ;
1431+ insns. push ( insn) ;
1432+ for ( _, insn) in iterator. by_ref ( ) {
14321433 insns. push ( insn) ;
1433- while let Some ( ( _, insn) ) = iterator. next ( ) {
1434- insns. push ( insn) ;
1435- }
1436- dump_live_regs ( insns, live_ranges, regs. len ( ) , index) ;
14371434 }
1438- debug ! ( "Register spill not supported" ) ;
1439- return Err ( CompileError :: RegisterSpillOnAlloc ) ;
1435+ dump_live_regs ( insns, live_ranges, regs. len ( ) , index) ;
14401436 }
1437+ debug ! ( "Register spill not supported" ) ;
1438+ return Err ( CompileError :: RegisterSpillOnAlloc ) ;
14411439 }
14421440 } ;
14431441 }
@@ -1510,7 +1508,7 @@ impl Assembler
15101508 if is_ccall {
15111509 // On x86_64, maintain 16-byte stack alignment
15121510 if cfg ! ( target_arch = "x86_64" ) && saved_regs. len ( ) % 2 == 1 {
1513- asm. cpop_into ( Opnd :: Reg ( saved_regs. last ( ) . unwrap ( ) . 0 . clone ( ) ) ) ;
1511+ asm. cpop_into ( Opnd :: Reg ( saved_regs. last ( ) . unwrap ( ) . 0 ) ) ;
15141512 }
15151513 // Restore saved registers
15161514 for & ( reg, vreg_idx) in saved_regs. iter ( ) . rev ( ) {
@@ -1527,7 +1525,6 @@ impl Assembler
15271525
15281526 /// Compile the instructions down to machine code.
15291527 /// Can fail due to lack of code memory and inopportune code placement, among other reasons.
1530- #[ must_use]
15311528 pub fn compile ( self , cb : & mut CodeBlock ) -> Result < ( CodePtr , Vec < CodePtr > ) , CompileError > {
15321529 #[ cfg( feature = "disasm" ) ]
15331530 let start_addr = cb. get_write_ptr ( ) ;
@@ -2038,7 +2035,7 @@ mod tests {
20382035 assert ! ( matches!( opnd_iter. next( ) , Some ( Opnd :: None ) ) ) ;
20392036 assert ! ( matches!( opnd_iter. next( ) , Some ( Opnd :: None ) ) ) ;
20402037
2041- assert ! ( matches! ( opnd_iter. next( ) , None ) ) ;
2038+ assert ! ( opnd_iter. next( ) . is_none ( ) ) ;
20422039 }
20432040
20442041 #[ test]
@@ -2049,7 +2046,7 @@ mod tests {
20492046 assert ! ( matches!( opnd_iter. next( ) , Some ( Opnd :: None ) ) ) ;
20502047 assert ! ( matches!( opnd_iter. next( ) , Some ( Opnd :: None ) ) ) ;
20512048
2052- assert ! ( matches! ( opnd_iter. next( ) , None ) ) ;
2049+ assert ! ( opnd_iter. next( ) . is_none ( ) ) ;
20532050 }
20542051
20552052 #[ test]
0 commit comments