@@ -9,6 +9,7 @@ use crate::jit::inst_info::{InstInfo, Operand, Shift, ShiftValue};
99use crate :: jit:: reg:: { Reg , RegReserve } ;
1010use crate :: jit:: { Cond , MemoryAmount , ShiftType } ;
1111use bilge:: prelude:: * ;
12+ use std:: cell:: RefCell ;
1213use std:: fmt:: { Debug , Formatter } ;
1314use std:: ops:: { Deref , DerefMut } ;
1415use std:: ptr:: NonNull ;
@@ -75,28 +76,35 @@ pub struct BranchEncoding {
7576#[ derive( Clone ) ]
7677pub struct BlockInst {
7778 pub kind : BlockInstKind ,
79+ io_cache : RefCell < Option < ( BlockRegSet , BlockRegSet ) > > ,
7880}
7981
8082impl BlockInst {
8183 pub fn new ( kind : BlockInstKind ) -> Self {
82- BlockInst { kind }
84+ BlockInst { kind, io_cache : RefCell :: new ( None ) }
8385 }
8486
8587 pub fn get_io ( & self ) -> ( BlockRegSet , BlockRegSet ) {
86- self . kind . get_io ( )
88+ let mut cached_io = self . io_cache . borrow_mut ( ) ;
89+ match * cached_io {
90+ None => {
91+ let io = self . kind . get_io ( ) ;
92+ * cached_io = Some ( io) ;
93+ io
94+ }
95+ Some ( cache) => cache,
96+ }
8797 }
8898
8999 pub fn replace_input_regs ( & mut self , old : BlockReg , new : BlockReg ) {
100+ * self . io_cache . borrow_mut ( ) = None ;
90101 self . kind . replace_input_regs ( old, new) ;
91102 }
92103
93104 pub fn replace_output_regs ( & mut self , old : BlockReg , new : BlockReg ) {
105+ * self . io_cache . borrow_mut ( ) = None ;
94106 self . kind . replace_output_regs ( old, new) ;
95107 }
96-
97- pub fn replace_regs ( & mut self , old : BlockReg , new : BlockReg ) {
98- self . kind . replace_regs ( old, new) ;
99- }
100108}
101109
102110impl From < BlockInstKind > for BlockInst {
@@ -515,54 +523,6 @@ impl BlockInstKind {
515523 }
516524 }
517525
518- fn replace_regs ( & mut self , old : BlockReg , new : BlockReg ) {
519- match self {
520- BlockInstKind :: Alu3 { operands, .. } | BlockInstKind :: Mul { operands, .. } => Self :: replace_shift_operands ( operands, old, new) ,
521- BlockInstKind :: Alu2Op1 { operands, .. } => Self :: replace_shift_operands ( operands, old, new) ,
522- BlockInstKind :: Alu2Op0 { operands, .. } => Self :: replace_shift_operands ( operands, old, new) ,
523- BlockInstKind :: Transfer { operands, .. } => Self :: replace_shift_operands ( operands, old, new) ,
524- BlockInstKind :: TransferMultiple { operand, .. } => Self :: replace_reg ( operand, old, new) ,
525- BlockInstKind :: SystemReg { operand, .. } => Self :: replace_operand ( operand, old, new) ,
526- BlockInstKind :: Bfc { operand, .. } => Self :: replace_reg ( operand, old, new) ,
527- BlockInstKind :: Bfi { operands, .. } => {
528- Self :: replace_reg ( & mut operands[ 0 ] , old, new) ;
529- Self :: replace_reg ( & mut operands[ 1 ] , old, new) ;
530- }
531-
532- BlockInstKind :: SaveContext { .. } => {
533- unreachable ! ( )
534- }
535- BlockInstKind :: SaveReg { reg_mapped, thread_regs_addr_reg, .. } => {
536- Self :: replace_reg ( reg_mapped, old, new) ;
537- Self :: replace_reg ( thread_regs_addr_reg, old, new) ;
538- }
539- BlockInstKind :: RestoreReg {
540- reg_mapped,
541- thread_regs_addr_reg,
542- tmp_guest_cpsr_reg,
543- ..
544- } => {
545- Self :: replace_reg ( reg_mapped, old, new) ;
546- Self :: replace_reg ( thread_regs_addr_reg, old, new) ;
547- Self :: replace_reg ( tmp_guest_cpsr_reg, old, new) ;
548- }
549-
550- BlockInstKind :: Call { func_reg, .. } => Self :: replace_reg ( func_reg, old, new) ,
551- BlockInstKind :: GenericGuestInst { regs_mapping, .. } => {
552- for reg_mapping in regs_mapping {
553- Self :: replace_reg ( reg_mapping, old, new) ;
554- }
555- }
556- BlockInstKind :: CallCommon { .. }
557- | BlockInstKind :: Label { .. }
558- | BlockInstKind :: Branch { .. }
559- | BlockInstKind :: GuestPc ( _)
560- | BlockInstKind :: Bkpt ( _)
561- | BlockInstKind :: Prologue
562- | BlockInstKind :: Epilogue { .. } => { }
563- }
564- }
565-
566526 fn save_guest_cpsr ( opcodes : & mut Vec < u32 > , thread_regs_addr_reg : Reg , host_reg : Reg ) {
567527 opcodes. push ( Mrs :: cpsr ( host_reg, Cond :: AL ) ) ;
568528 // Only copy the cond flags from host cpsr
0 commit comments