@@ -22,7 +22,7 @@ import {
22
22
append_memmove_dest_src , try_append_memset_fast ,
23
23
try_append_memmove_fast , counters , getOpcodeTableValue ,
24
24
getMemberOffset , JiterpMember , BailoutReason ,
25
- isZeroPageReserved
25
+ isZeroPageReserved , CfgBranchType , append_safepoint
26
26
} from "./jiterpreter-support" ;
27
27
import { compileSimdFeatureDetect } from "./jiterpreter-feature-detect" ;
28
28
import {
@@ -1271,9 +1271,7 @@ export function generateWasmBody(
1271
1271
builder . local ( "index" ) ;
1272
1272
builder . ptr_const ( ra ) ;
1273
1273
builder . appendU8 ( WasmOpcode . i32_eq ) ;
1274
- builder . block ( WasmValtype . void , WasmOpcode . if_ ) ;
1275
- builder . cfg . branch ( ra , ra < ip , true ) ;
1276
- builder . endBlock ( ) ;
1274
+ builder . cfg . branch ( ra , ra < ip , CfgBranchType . Conditional ) ;
1277
1275
}
1278
1276
// If none of the comparisons succeeded we won't have branched anywhere, so bail out
1279
1277
// This shouldn't happen during non-exception-handling execution unless the trace doesn't
@@ -1889,11 +1887,10 @@ function append_ldloc_cknull(builder: WasmBuilder, localOffset: number, ip: Mint
1889
1887
return ;
1890
1888
}
1891
1889
1892
- builder . block ( ) ;
1893
1890
append_ldloc ( builder , localOffset , WasmOpcode . i32_load ) ;
1894
1891
builder . local ( "cknull_ptr" , WasmOpcode . tee_local ) ;
1895
- builder . appendU8 ( WasmOpcode . br_if ) ;
1896
- builder . appendULeb ( 0 ) ;
1892
+ builder . appendU8 ( WasmOpcode . i32_eqz ) ;
1893
+ builder . block ( WasmValtype . void , WasmOpcode . if_ ) ;
1897
1894
append_bailout ( builder , ip , BailoutReason . NullCheck ) ;
1898
1895
builder . endBlock ( ) ;
1899
1896
if ( leaveOnStack )
@@ -2697,7 +2694,7 @@ function emit_branch(
2697
2694
mono_log_info ( `performing backward branch to 0x${ destination . toString ( 16 ) } ` ) ;
2698
2695
if ( isCallHandler )
2699
2696
append_call_handler_store_ret_ip ( builder , ip , frame , opcode ) ;
2700
- builder . cfg . branch ( destination , true , false ) ;
2697
+ builder . cfg . branch ( destination , true , CfgBranchType . Unconditional ) ;
2701
2698
counters . backBranchesEmitted ++ ;
2702
2699
return true ;
2703
2700
} else {
@@ -2722,7 +2719,7 @@ function emit_branch(
2722
2719
builder . branchTargets . add ( destination ) ;
2723
2720
if ( isCallHandler )
2724
2721
append_call_handler_store_ret_ip ( builder , ip , frame , opcode ) ;
2725
- builder . cfg . branch ( destination , false , false ) ;
2722
+ builder . cfg . branch ( destination , false , CfgBranchType . Unconditional ) ;
2726
2723
return true ;
2727
2724
}
2728
2725
}
@@ -2735,20 +2732,19 @@ function emit_branch(
2735
2732
case MintOpcode . MINT_BRFALSE_I8_S : {
2736
2733
const is64 = ( opcode === MintOpcode . MINT_BRTRUE_I8_S ) ||
2737
2734
( opcode === MintOpcode . MINT_BRFALSE_I8_S ) ;
2738
- // Wrap the conditional branch in a block so we can skip the
2739
- // actual branch at the end of it
2740
- builder . block ( ) ;
2735
+
2736
+ // Load the condition
2741
2737
2742
2738
displacement = getArgI16 ( ip , 2 ) ;
2743
2739
append_ldloc ( builder , getArgU16 ( ip , 1 ) , is64 ? WasmOpcode . i64_load : WasmOpcode . i32_load ) ;
2744
2740
if (
2745
- ( opcode === MintOpcode . MINT_BRTRUE_I4_S ) ||
2746
- ( opcode === MintOpcode . MINT_BRTRUE_I4_SP )
2741
+ ( opcode === MintOpcode . MINT_BRFALSE_I4_S ) ||
2742
+ ( opcode === MintOpcode . MINT_BRFALSE_I4_SP )
2747
2743
)
2748
2744
builder . appendU8 ( WasmOpcode . i32_eqz ) ;
2749
- else if ( opcode === MintOpcode . MINT_BRTRUE_I8_S )
2750
- builder . appendU8 ( WasmOpcode . i64_eqz ) ;
2751
2745
else if ( opcode === MintOpcode . MINT_BRFALSE_I8_S ) {
2746
+ builder . appendU8 ( WasmOpcode . i64_eqz ) ;
2747
+ } else if ( opcode === MintOpcode . MINT_BRTRUE_I8_S ) {
2752
2748
// do (i64 == 0) == 0 because br_if can only branch on an i32 operand
2753
2749
builder . appendU8 ( WasmOpcode . i64_eqz ) ;
2754
2750
builder . appendU8 ( WasmOpcode . i32_eqz ) ;
@@ -2766,7 +2762,6 @@ function emit_branch(
2766
2762
if ( cwraps . mono_jiterp_get_opcode_info ( opcode , OpcodeInfoType . Length ) !== 4 )
2767
2763
throw new Error ( `Unsupported long branch opcode: ${ getOpcodeName ( opcode ) } ` ) ;
2768
2764
2769
- builder . appendU8 ( WasmOpcode . i32_eqz ) ;
2770
2765
break ;
2771
2766
}
2772
2767
}
@@ -2778,21 +2773,13 @@ function emit_branch(
2778
2773
2779
2774
const destination = < any > ip + ( displacement * 2 ) ;
2780
2775
2781
- // We generate a conditional branch that will skip past the rest of this
2782
- // tiny branch dispatch block to avoid performing the branch
2783
- builder . appendU8 ( WasmOpcode . br_if ) ;
2784
- builder . appendULeb ( 0 ) ;
2785
-
2786
2776
if ( displacement < 0 ) {
2787
- if ( isSafepoint )
2788
- append_safepoint ( builder , ip ) ;
2789
-
2790
2777
if ( builder . backBranchOffsets . indexOf ( destination ) >= 0 ) {
2791
2778
// We found a backwards branch target we can reach via our outer trace loop, so
2792
2779
// we update eip and branch out to the top of the loop block
2793
2780
if ( traceBackBranches > 1 )
2794
2781
mono_log_info ( `performing conditional backward branch to 0x${ destination . toString ( 16 ) } ` ) ;
2795
- builder . cfg . branch ( destination , true , true ) ;
2782
+ builder . cfg . branch ( destination , true , isSafepoint ? CfgBranchType . SafepointConditional : CfgBranchType . Conditional ) ;
2796
2783
counters . backBranchesEmitted ++ ;
2797
2784
} else {
2798
2785
if ( destination < builder . cfg . entryIp ) {
@@ -2804,19 +2791,17 @@ function emit_branch(
2804
2791
) ;
2805
2792
// We didn't find a loop to branch to, so bail out
2806
2793
cwraps . mono_jiterp_boost_back_branch_target ( destination ) ;
2794
+ builder . block ( WasmValtype . void , WasmOpcode . if_ ) ;
2807
2795
append_bailout ( builder , destination , BailoutReason . BackwardBranch ) ;
2796
+ builder . endBlock ( ) ;
2808
2797
counters . backBranchesNotEmitted ++ ;
2809
2798
}
2810
2799
} else {
2811
- // Do a safepoint *before* changing our IP, if necessary
2812
- if ( isSafepoint )
2813
- append_safepoint ( builder , ip ) ;
2814
2800
// Branching is enabled, so set eip and exit the current branch block
2815
2801
builder . branchTargets . add ( destination ) ;
2816
- builder . cfg . branch ( destination , false , true ) ;
2802
+ builder . cfg . branch ( destination , false , isSafepoint ? CfgBranchType . SafepointConditional : CfgBranchType . Conditional ) ;
2817
2803
}
2818
2804
2819
- builder . endBlock ( ) ;
2820
2805
return true ;
2821
2806
}
2822
2807
@@ -2838,10 +2823,6 @@ function emit_relop_branch(
2838
2823
if ( ! relopInfo && ! intrinsicFpBinop )
2839
2824
return false ;
2840
2825
2841
- // We have to wrap the computation of the branch condition inside the
2842
- // branch block because opening blocks destroys the contents of the
2843
- // wasm execution stack for some reason
2844
- builder . block ( ) ;
2845
2826
const displacement = getArgI16 ( ip , 3 ) ;
2846
2827
if ( traceBranchDisplacements )
2847
2828
mono_log_info ( `relop @${ ip } displacement=${ displacement } ` ) ;
@@ -3812,17 +3793,3 @@ function emit_simd_4(builder: WasmBuilder, ip: MintOpcodePtr, index: SimdIntrins
3812
3793
return false ;
3813
3794
}
3814
3795
}
3815
-
3816
- function append_safepoint ( builder : WasmBuilder , ip : MintOpcodePtr ) {
3817
- // Check whether a safepoint is required
3818
- builder . ptr_const ( cwraps . mono_jiterp_get_polling_required_address ( ) ) ;
3819
- builder . appendU8 ( WasmOpcode . i32_load ) ;
3820
- builder . appendMemarg ( 0 , 2 ) ;
3821
- // If the polling flag is set we call mono_jiterp_do_safepoint()
3822
- builder . block ( WasmValtype . void , WasmOpcode . if_ ) ;
3823
- builder . local ( "frame" ) ;
3824
- // Not ip_const, because we can't pass relative IP to do_safepoint
3825
- builder . i32_const ( ip ) ;
3826
- builder . callImport ( "safepoint" ) ;
3827
- builder . endBlock ( ) ;
3828
- }
0 commit comments