@@ -727,16 +727,14 @@ class LiftoffCompiler {
727
727
}
728
728
729
729
void TierupCheck (FullDecoder* decoder, WasmCodePosition position,
730
- int budget_used, Register scratch_reg ) {
730
+ int budget_used) {
731
731
if (for_debugging_ != kNoDebugging ) return ;
732
732
CODE_COMMENT (" tierup check" );
733
733
// We never want to blow the entire budget at once.
734
734
const int kMax = FLAG_wasm_tiering_budget / 4 ;
735
735
if (budget_used > kMax ) budget_used = kMax ;
736
736
737
- LiftoffRegister budget_reg = scratch_reg == no_reg
738
- ? __ GetUnusedRegister (kGpReg , {})
739
- : LiftoffRegister (scratch_reg);
737
+ LiftoffRegister budget_reg = __ GetUnusedRegister (kGpReg , {});
740
738
__ Fill (budget_reg, liftoff::kTierupBudgetOffset , ValueKind::kI32 );
741
739
LiftoffRegList regs_to_save = __ cache_state ()->used_registers ;
742
740
// The cached instance will be reloaded separately.
@@ -2241,7 +2239,8 @@ class LiftoffCompiler {
2241
2239
2242
2240
void TierupCheckOnExit (FullDecoder* decoder) {
2243
2241
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" );
2245
2244
LiftoffRegList pinned;
2246
2245
LiftoffRegister budget = pinned.set (__ GetUnusedRegister (kGpReg , pinned));
2247
2246
LiftoffRegister array = pinned.set (__ GetUnusedRegister (kGpReg , pinned));
@@ -2586,12 +2585,12 @@ class LiftoffCompiler {
2586
2585
__ PushRegister (kind, dst);
2587
2586
}
2588
2587
2589
- void BrImpl (FullDecoder* decoder, Control* target, Register scratch_reg ) {
2588
+ void BrImpl (FullDecoder* decoder, Control* target) {
2590
2589
if (dynamic_tiering ()) {
2591
2590
if (target->is_loop ()) {
2592
2591
DCHECK (target->label .get ()->is_bound ());
2593
2592
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);
2595
2594
} else {
2596
2595
// To estimate time spent in this function more accurately, we could
2597
2596
// increment the tiering budget on forward jumps. However, we don't
@@ -2612,14 +2611,14 @@ class LiftoffCompiler {
2612
2611
2613
2612
void BrOrRet (FullDecoder* decoder, uint32_t depth,
2614
2613
uint32_t /* drop_values */ ) {
2615
- BrOrRetImpl (decoder, depth, no_reg );
2614
+ BrOrRetImpl (decoder, depth);
2616
2615
}
2617
2616
2618
- void BrOrRetImpl (FullDecoder* decoder, uint32_t depth, Register scratch_reg ) {
2617
+ void BrOrRetImpl (FullDecoder* decoder, uint32_t depth) {
2619
2618
if (depth == decoder->control_depth () - 1 ) {
2620
2619
DoReturn (decoder, 0 );
2621
2620
} else {
2622
- BrImpl (decoder, decoder->control_at (depth), scratch_reg );
2621
+ BrImpl (decoder, decoder->control_at (depth));
2623
2622
}
2624
2623
}
2625
2624
@@ -2632,16 +2631,26 @@ class LiftoffCompiler {
2632
2631
decoder->control_at (depth)->br_merge ()->arity );
2633
2632
}
2634
2633
2635
- Register scratch_reg = no_reg;
2636
- if (dynamic_tiering ()) {
2637
- scratch_reg = __ GetUnusedRegister (kGpReg , {}).gp ();
2638
- }
2639
2634
Label cont_false;
2640
2635
2641
2636
// Test the condition on the value stack, jump to {cont_false} if zero.
2642
2637
JumpIfFalse (decoder, &cont_false);
2643
2638
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
+
2645
2654
__ bind (&cont_false);
2646
2655
}
2647
2656
0 commit comments