@@ -5,7 +5,7 @@ use crate::jit::assembler::block_reg_set::BlockRegSet;
55use crate :: jit:: assembler:: { BlockAsmBuf , BlockInst } ;
66use crate :: jit:: reg:: { Reg , RegReserve } ;
77use crate :: jit:: { MemoryAmount , ShiftType } ;
8- use crate :: utils :: { BuildNoHasher , NoHashSet } ;
8+ use crate :: IS_DEBUG ;
99use std:: fmt:: { Debug , Formatter } ;
1010
1111pub struct BasicBlock {
@@ -18,8 +18,8 @@ pub struct BasicBlock {
1818 pub regs_live_ranges : Vec < BlockRegSet > ,
1919 pub used_regs : Vec < BlockRegSet > ,
2020
21- pub enter_blocks : NoHashSet < usize > ,
22- pub exit_blocks : NoHashSet < usize > ,
21+ pub enter_blocks : Vec < usize > ,
22+ pub exit_blocks : Vec < usize > ,
2323
2424 pub insts_link : BlockInstList ,
2525
@@ -38,8 +38,8 @@ impl BasicBlock {
3838 regs_live_ranges : Vec :: new ( ) ,
3939 used_regs : Vec :: new ( ) ,
4040
41- enter_blocks : NoHashSet :: default ( ) ,
42- exit_blocks : NoHashSet :: with_capacity_and_hasher ( 2 , BuildNoHasher ) ,
41+ enter_blocks : Vec :: new ( ) ,
42+ exit_blocks : Vec :: with_capacity ( 2 ) ,
4343
4444 insts_link : BlockInstList :: new ( ) ,
4545
@@ -63,11 +63,7 @@ impl BasicBlock {
6363 let mut add_inst = true ;
6464 let mut guest_regs_outputs = RegReserve :: new ( ) ;
6565 match & mut asm. buf . insts [ i] {
66- BlockInst :: Label { guest_pc, .. } => {
67- if let Some ( pc) = guest_pc {
68- last_pc = * pc;
69- }
70- }
66+ BlockInst :: Label { guest_pc : Some ( pc) , .. } => last_pc = * pc,
7167 BlockInst :: GuestPc ( pc) => last_pc = * pc,
7268 _ => match asm. buf . insts [ i] {
7369 BlockInst :: SaveContext {
@@ -130,6 +126,7 @@ impl BasicBlock {
130126 Reg :: PC => {
131127 if !pc_initialized {
132128 pc_initialized = true ;
129+ last_pc_reg = Reg :: PC . into ( ) ;
133130 self . insts_link . insert_end ( asm. buf . insts . len ( ) ) ;
134131 asm. buf . insts . push ( BlockInst :: Alu2Op0 {
135132 op : BlockAluOp :: Mov ,
@@ -242,6 +239,10 @@ impl BasicBlock {
242239 }
243240 }
244241
242+ if outputs. contains ( Reg :: PC . into ( ) ) {
243+ pc_initialized = false ;
244+ }
245+
245246 guest_regs_outputs = outputs. get_guests ( ) ;
246247 initialized_guest_regs += outputs. get_guests ( ) ;
247248 }
@@ -376,13 +377,13 @@ impl BasicBlock {
376377 }
377378 }
378379
379- pub fn emit_opcodes ( & self , asm : & mut BlockAsm , branch_placeholders : & mut Vec < usize > , opcodes_offset : usize ) -> Vec < u32 > {
380+ pub fn emit_opcodes ( & self , asm : & mut BlockAsm , branch_placeholders : & mut Vec < usize > , opcodes_offset : usize , used_host_regs : RegReserve ) -> Vec < u32 > {
380381 let mut opcodes = Vec :: new ( ) ;
381382 let mut inst_opcodes = Vec :: new ( ) ;
382383 for entry in self . insts_link . iter ( ) {
383384 let inst = & mut asm. buf . insts [ entry. value ] ;
384385
385- if unsafe { BLOCK_LOG } {
386+ if IS_DEBUG && unsafe { BLOCK_LOG } {
386387 match inst {
387388 BlockInst :: GuestPc ( pc) => {
388389 println ! ( "(0x{:x}, 0x{pc:x})," , opcodes. len( ) + opcodes_offset) ;
@@ -397,7 +398,7 @@ impl BasicBlock {
397398 }
398399
399400 inst_opcodes. clear ( ) ;
400- inst. emit_opcode ( & mut inst_opcodes, opcodes. len ( ) , branch_placeholders, opcodes_offset) ;
401+ inst. emit_opcode ( & mut inst_opcodes, opcodes. len ( ) , branch_placeholders, opcodes_offset, used_host_regs ) ;
401402 opcodes. extend ( & inst_opcodes) ;
402403 }
403404 opcodes
0 commit comments