@@ -256,14 +256,6 @@ impl From<VALUE> for Opnd {
256256 }
257257}
258258
259- /// Set of things we need to restore for side exits.
260- #[ derive( Clone , Debug ) ]
261- pub struct SideExitContext {
262- pub pc : * const VALUE ,
263- pub stack : Vec < Opnd > ,
264- pub locals : Vec < Opnd > ,
265- }
266-
267259/// Branch target (something that we can jump to)
268260/// for branch instructions
269261#[ derive( Clone , Debug ) ]
@@ -275,9 +267,9 @@ pub enum Target
275267 Label ( Label ) ,
276268 /// Side exit to the interpreter
277269 SideExit {
278- /// Context to restore on regular side exits. None for side exits right
279- /// after JIT-to-JIT calls because we restore them before the JIT call.
280- context : Option < SideExitContext > ,
270+ pc : * const VALUE ,
271+ stack : Vec < Opnd > ,
272+ locals : Vec < Opnd > ,
281273 /// We use this to enrich asm comments.
282274 reason : SideExitReason ,
283275 /// Some if the side exit should write this label. We use it for patch points.
@@ -761,7 +753,7 @@ impl<'a> Iterator for InsnOpndIterator<'a> {
761753 Insn :: Label ( target) |
762754 Insn :: LeaJumpTarget { target, .. } |
763755 Insn :: PatchPoint ( target) => {
764- if let Target :: SideExit { context : Some ( SideExitContext { stack, locals, .. } ) , .. } = target {
756+ if let Target :: SideExit { stack, locals, .. } = target {
765757 let stack_idx = self . idx ;
766758 if stack_idx < stack. len ( ) {
767759 let opnd = & stack[ stack_idx] ;
@@ -786,7 +778,7 @@ impl<'a> Iterator for InsnOpndIterator<'a> {
786778 return Some ( opnd) ;
787779 }
788780
789- if let Target :: SideExit { context : Some ( SideExitContext { stack, locals, .. } ) , .. } = target {
781+ if let Target :: SideExit { stack, locals, .. } = target {
790782 let stack_idx = self . idx - 1 ;
791783 if stack_idx < stack. len ( ) {
792784 let opnd = & stack[ stack_idx] ;
@@ -917,7 +909,7 @@ impl<'a> InsnOpndMutIterator<'a> {
917909 Insn :: Label ( target) |
918910 Insn :: LeaJumpTarget { target, .. } |
919911 Insn :: PatchPoint ( target) => {
920- if let Target :: SideExit { context : Some ( SideExitContext { stack, locals, .. } ) , .. } = target {
912+ if let Target :: SideExit { stack, locals, .. } = target {
921913 let stack_idx = self . idx ;
922914 if stack_idx < stack. len ( ) {
923915 let opnd = & mut stack[ stack_idx] ;
@@ -942,7 +934,7 @@ impl<'a> InsnOpndMutIterator<'a> {
942934 return Some ( opnd) ;
943935 }
944936
945- if let Target :: SideExit { context : Some ( SideExitContext { stack, locals, .. } ) , .. } = target {
937+ if let Target :: SideExit { stack, locals, .. } = target {
946938 let stack_idx = self . idx - 1 ;
947939 if stack_idx < stack. len ( ) {
948940 let opnd = & mut stack[ stack_idx] ;
@@ -1555,8 +1547,7 @@ impl Assembler
15551547 }
15561548
15571549 /// Compile Target::SideExit and convert it into Target::CodePtr for all instructions
1558- #[ must_use]
1559- pub fn compile_side_exits ( & mut self ) -> Option < ( ) > {
1550+ pub fn compile_side_exits ( & mut self ) {
15601551 let mut targets = HashMap :: new ( ) ;
15611552 for ( idx, insn) in self . insns . iter ( ) . enumerate ( ) {
15621553 if let Some ( target @ Target :: SideExit { .. } ) = insn. target ( ) {
@@ -1567,7 +1558,7 @@ impl Assembler
15671558 for ( idx, target) in targets {
15681559 // Compile a side exit. Note that this is past the split pass and alloc_regs(),
15691560 // so you can't use a VReg or an instruction that needs to be split.
1570- if let Target :: SideExit { context , reason, label } = target {
1561+ if let Target :: SideExit { pc , stack , locals , reason, label } = target {
15711562 asm_comment ! ( self , "Exit: {reason}" ) ;
15721563 let side_exit_label = if let Some ( label) = label {
15731564 Target :: Label ( label)
@@ -1578,26 +1569,24 @@ impl Assembler
15781569
15791570 // Restore the PC and the stack for regular side exits. We don't do this for
15801571 // side exits right after JIT-to-JIT calls, which restore them before the call.
1581- if let Some ( SideExitContext { pc, stack, locals } ) = context {
1582- asm_comment ! ( self , "write stack slots: {stack:?}" ) ;
1583- for ( idx, & opnd) in stack. iter ( ) . enumerate ( ) {
1584- self . store ( Opnd :: mem ( 64 , SP , idx as i32 * SIZEOF_VALUE_I32 ) , opnd) ;
1585- }
1572+ asm_comment ! ( self , "write stack slots: {stack:?}" ) ;
1573+ for ( idx, & opnd) in stack. iter ( ) . enumerate ( ) {
1574+ self . store ( Opnd :: mem ( 64 , SP , idx as i32 * SIZEOF_VALUE_I32 ) , opnd) ;
1575+ }
15861576
1587- asm_comment ! ( self , "write locals: {locals:?}" ) ;
1588- for ( idx, & opnd) in locals. iter ( ) . enumerate ( ) {
1589- self . store ( Opnd :: mem ( 64 , SP , ( -local_size_and_idx_to_ep_offset ( locals. len ( ) , idx) - 1 ) * SIZEOF_VALUE_I32 ) , opnd) ;
1590- }
1577+ asm_comment ! ( self , "write locals: {locals:?}" ) ;
1578+ for ( idx, & opnd) in locals. iter ( ) . enumerate ( ) {
1579+ self . store ( Opnd :: mem ( 64 , SP , ( -local_size_and_idx_to_ep_offset ( locals. len ( ) , idx) - 1 ) * SIZEOF_VALUE_I32 ) , opnd) ;
1580+ }
15911581
1592- asm_comment ! ( self , "save cfp->pc" ) ;
1593- self . load_into ( Opnd :: Reg ( Assembler :: SCRATCH_REG ) , Opnd :: const_ptr ( pc) ) ;
1594- self . store ( Opnd :: mem ( 64 , CFP , RUBY_OFFSET_CFP_PC ) , Opnd :: Reg ( Assembler :: SCRATCH_REG ) ) ;
1582+ asm_comment ! ( self , "save cfp->pc" ) ;
1583+ self . load_into ( Opnd :: Reg ( Assembler :: SCRATCH_REG ) , Opnd :: const_ptr ( pc) ) ;
1584+ self . store ( Opnd :: mem ( 64 , CFP , RUBY_OFFSET_CFP_PC ) , Opnd :: Reg ( Assembler :: SCRATCH_REG ) ) ;
15951585
1596- asm_comment ! ( self , "save cfp->sp" ) ;
1597- self . lea_into ( Opnd :: Reg ( Assembler :: SCRATCH_REG ) , Opnd :: mem ( 64 , SP , stack. len ( ) as i32 * SIZEOF_VALUE_I32 ) ) ;
1598- let cfp_sp = Opnd :: mem ( 64 , CFP , RUBY_OFFSET_CFP_SP ) ;
1599- self . store ( cfp_sp, Opnd :: Reg ( Assembler :: SCRATCH_REG ) ) ;
1600- }
1586+ asm_comment ! ( self , "save cfp->sp" ) ;
1587+ self . lea_into ( Opnd :: Reg ( Assembler :: SCRATCH_REG ) , Opnd :: mem ( 64 , SP , stack. len ( ) as i32 * SIZEOF_VALUE_I32 ) ) ;
1588+ let cfp_sp = Opnd :: mem ( 64 , CFP , RUBY_OFFSET_CFP_SP ) ;
1589+ self . store ( cfp_sp, Opnd :: Reg ( Assembler :: SCRATCH_REG ) ) ;
16011590
16021591 asm_comment ! ( self , "exit to the interpreter" ) ;
16031592 self . frame_teardown ( & [ ] ) ; // matching the setup in :bb0-prologue:
@@ -1607,7 +1596,6 @@ impl Assembler
16071596 * self . insns [ idx] . target_mut ( ) . unwrap ( ) = side_exit_label;
16081597 }
16091598 }
1610- Some ( ( ) )
16111599 }
16121600}
16131601
0 commit comments