@@ -727,16 +727,14 @@ class LiftoffCompiler {
727727 }
728728
729729 void TierupCheck (FullDecoder* decoder, WasmCodePosition position,
730- int budget_used, Register scratch_reg ) {
730+ int budget_used) {
731731 if (for_debugging_ != kNoDebugging ) return ;
732732 CODE_COMMENT (" tierup check" );
733733 // We never want to blow the entire budget at once.
734734 const int kMax = FLAG_wasm_tiering_budget / 4 ;
735735 if (budget_used > kMax ) budget_used = kMax ;
736736
737- LiftoffRegister budget_reg = scratch_reg == no_reg
738- ? __ GetUnusedRegister (kGpReg , {})
739- : LiftoffRegister (scratch_reg);
737+ LiftoffRegister budget_reg = __ GetUnusedRegister (kGpReg , {});
740738 __ Fill (budget_reg, liftoff::kTierupBudgetOffset , ValueKind::kI32 );
741739 LiftoffRegList regs_to_save = __ cache_state ()->used_registers ;
742740 // The cached instance will be reloaded separately.
@@ -2241,7 +2239,8 @@ class LiftoffCompiler {
22412239
22422240 void TierupCheckOnExit (FullDecoder* decoder) {
22432241 if (!dynamic_tiering ()) return ;
2244- TierupCheck (decoder, decoder->position (), __ pc_offset (), no_reg);
2242+ TierupCheck (decoder, decoder->position (), __ pc_offset ());
2243+ CODE_COMMENT (" update tiering budget" );
22452244 LiftoffRegList pinned;
22462245 LiftoffRegister budget = pinned.set (__ GetUnusedRegister (kGpReg , pinned));
22472246 LiftoffRegister array = pinned.set (__ GetUnusedRegister (kGpReg , pinned));
@@ -2586,12 +2585,12 @@ class LiftoffCompiler {
25862585 __ PushRegister (kind, dst);
25872586 }
25882587
2589- void BrImpl (FullDecoder* decoder, Control* target, Register scratch_reg ) {
2588+ void BrImpl (FullDecoder* decoder, Control* target) {
25902589 if (dynamic_tiering ()) {
25912590 if (target->is_loop ()) {
25922591 DCHECK (target->label .get ()->is_bound ());
25932592 int jump_distance = __ pc_offset () - target->label .get ()->pos ();
2594- TierupCheck (decoder, decoder->position (), jump_distance, scratch_reg );
2593+ TierupCheck (decoder, decoder->position (), jump_distance);
25952594 } else {
25962595 // To estimate time spent in this function more accurately, we could
25972596 // increment the tiering budget on forward jumps. However, we don't
@@ -2612,14 +2611,14 @@ class LiftoffCompiler {
26122611
26132612 void BrOrRet (FullDecoder* decoder, uint32_t depth,
26142613 uint32_t /* drop_values */ ) {
2615- BrOrRetImpl (decoder, depth, no_reg );
2614+ BrOrRetImpl (decoder, depth);
26162615 }
26172616
2618- void BrOrRetImpl (FullDecoder* decoder, uint32_t depth, Register scratch_reg ) {
2617+ void BrOrRetImpl (FullDecoder* decoder, uint32_t depth) {
26192618 if (depth == decoder->control_depth () - 1 ) {
26202619 DoReturn (decoder, 0 );
26212620 } else {
2622- BrImpl (decoder, decoder->control_at (depth), scratch_reg );
2621+ BrImpl (decoder, decoder->control_at (depth));
26232622 }
26242623 }
26252624
@@ -2632,16 +2631,26 @@ class LiftoffCompiler {
26322631 decoder->control_at (depth)->br_merge ()->arity );
26332632 }
26342633
2635- Register scratch_reg = no_reg;
2636- if (dynamic_tiering ()) {
2637- scratch_reg = __ GetUnusedRegister (kGpReg , {}).gp ();
2638- }
26392634 Label cont_false;
26402635
26412636 // Test the condition on the value stack, jump to {cont_false} if zero.
26422637 JumpIfFalse (decoder, &cont_false);
26432638
2644- BrOrRetImpl (decoder, depth, scratch_reg);
2639+ // As a quickfix for https://crbug.com/1314184 we store the cache state
2640+ // before calling {BrOrRetImpl} under dynamic tiering, because the tier up
2641+ // check modifies the cache state (GetUnusedRegister,
2642+ // LoadInstanceIntoRegister).
2643+ // TODO(wasm): This causes significant overhead during compilation; try to
2644+ // avoid this, maybe by passing in scratch registers.
2645+ if (dynamic_tiering ()) {
2646+ LiftoffAssembler::CacheState old_cache_state;
2647+ old_cache_state.Split (*__ cache_state ());
2648+ BrOrRetImpl (decoder, depth);
2649+ __ cache_state ()->Steal (old_cache_state);
2650+ } else {
2651+ BrOrRetImpl (decoder, depth);
2652+ }
2653+
26452654 __ bind (&cont_false);
26462655 }
26472656
0 commit comments