@@ -87,6 +87,7 @@ pub struct Compiler {
8787 tunables : Tunables ,
8888 contexts : Mutex < Vec < CompilerContext > > ,
8989 isa : OwnedTargetIsa ,
90+ emit_debug_checks : bool ,
9091 linkopts : LinkOptions ,
9192 cache_store : Option < Arc < dyn CacheStore > > ,
9293 clif_dir : Option < path:: PathBuf > ,
@@ -127,6 +128,7 @@ impl Compiler {
127128 tunables : Tunables ,
128129 isa : OwnedTargetIsa ,
129130 cache_store : Option < Arc < dyn CacheStore > > ,
131+ emit_debug_checks : bool ,
130132 linkopts : LinkOptions ,
131133 clif_dir : Option < path:: PathBuf > ,
132134 wmemcheck : bool ,
@@ -136,6 +138,7 @@ impl Compiler {
136138 contexts : Default :: default ( ) ,
137139 tunables,
138140 isa,
141+ emit_debug_checks,
139142 linkopts,
140143 cache_store,
141144 clif_dir,
@@ -392,7 +395,7 @@ impl wasmtime_environ::Compiler for Compiler {
392395 //
393396 // Assert that we were really given a core Wasm vmctx, since that's
394397 // what we are assuming with our offsets below.
395- debug_assert_vmctx_kind ( isa , & mut builder, vmctx, wasmtime_environ:: VMCONTEXT_MAGIC ) ;
398+ self . debug_assert_vmctx_kind ( & mut builder, vmctx, wasmtime_environ:: VMCONTEXT_MAGIC ) ;
396399 let offsets = VMOffsets :: new ( isa. pointer_bytes ( ) , & translation. module ) ;
397400 let vm_store_context_offset = offsets. ptr . vmctx_store_context ( ) ;
398401 save_last_wasm_entry_fp (
@@ -456,8 +459,7 @@ impl wasmtime_environ::Compiler for Compiler {
456459 //
457460 // Assert that the caller vmctx really is a core Wasm vmctx, since
458461 // that's what we are assuming with our offsets below.
459- debug_assert_vmctx_kind (
460- isa,
462+ self . debug_assert_vmctx_kind (
461463 & mut builder,
462464 caller_vmctx,
463465 wasmtime_environ:: VMCONTEXT_MAGIC ,
@@ -707,7 +709,7 @@ impl wasmtime_environ::Compiler for Compiler {
707709 // Debug-assert that this is the right kind of vmctx, and then
708710 // additionally perform the "routine of the exit trampoline" of saving
709711 // fp/pc/etc.
710- debug_assert_vmctx_kind ( isa , & mut builder, vmctx, wasmtime_environ:: VMCONTEXT_MAGIC ) ;
712+ self . debug_assert_vmctx_kind ( & mut builder, vmctx, wasmtime_environ:: VMCONTEXT_MAGIC ) ;
711713 let vm_store_context = builder. ins ( ) . load (
712714 pointer_type,
713715 MemFlags :: trusted ( ) ,
@@ -1034,7 +1036,7 @@ impl Compiler {
10341036 values_vec_capacity : Value ,
10351037 ) {
10361038 debug_assert_eq ! ( types. len( ) , values. len( ) ) ;
1037- debug_assert_enough_capacity_for_length ( builder, types. len ( ) , values_vec_capacity) ;
1039+ self . debug_assert_enough_capacity_for_length ( builder, types. len ( ) , values_vec_capacity) ;
10381040
10391041 // Note that loads and stores are unconditionally done in the
10401042 // little-endian format rather than the host's native-endianness,
@@ -1074,7 +1076,7 @@ impl Compiler {
10741076 let isa = & * self . isa ;
10751077 let value_size = mem:: size_of :: < u128 > ( ) ;
10761078
1077- debug_assert_enough_capacity_for_length ( builder, types. len ( ) , values_vec_capacity) ;
1079+ self . debug_assert_enough_capacity_for_length ( builder, types. len ( ) , values_vec_capacity) ;
10781080
10791081 // Note that this is little-endian like `store_values_to_array` above,
10801082 // see notes there for more information.
@@ -1197,6 +1199,46 @@ impl Compiler {
11971199 pub fn tunables ( & self ) -> & Tunables {
11981200 & self . tunables
11991201 }
1202+
1203+ fn debug_assert_enough_capacity_for_length (
1204+ & self ,
1205+ builder : & mut FunctionBuilder ,
1206+ length : usize ,
1207+ capacity : ir:: Value ,
1208+ ) {
1209+ if !self . emit_debug_checks {
1210+ return ;
1211+ }
1212+ let enough_capacity = builder. ins ( ) . icmp_imm (
1213+ ir:: condcodes:: IntCC :: UnsignedGreaterThanOrEqual ,
1214+ capacity,
1215+ ir:: immediates:: Imm64 :: new ( length. try_into ( ) . unwrap ( ) ) ,
1216+ ) ;
1217+ builder. ins ( ) . trapz ( enough_capacity, TRAP_INTERNAL_ASSERT ) ;
1218+ }
1219+
1220+ fn debug_assert_vmctx_kind (
1221+ & self ,
1222+ builder : & mut FunctionBuilder ,
1223+ vmctx : ir:: Value ,
1224+ expected_vmctx_magic : u32 ,
1225+ ) {
1226+ if !self . emit_debug_checks {
1227+ return ;
1228+ }
1229+ let magic = builder. ins ( ) . load (
1230+ ir:: types:: I32 ,
1231+ MemFlags :: trusted ( ) . with_endianness ( self . isa . endianness ( ) ) ,
1232+ vmctx,
1233+ 0 ,
1234+ ) ;
1235+ let is_expected_vmctx = builder. ins ( ) . icmp_imm (
1236+ ir:: condcodes:: IntCC :: Equal ,
1237+ magic,
1238+ i64:: from ( expected_vmctx_magic) ,
1239+ ) ;
1240+ builder. ins ( ) . trapz ( is_expected_vmctx, TRAP_INTERNAL_ASSERT ) ;
1241+ }
12001242}
12011243
12021244struct FunctionCompiler < ' a > {
@@ -1381,43 +1423,6 @@ fn declare_and_call(
13811423 builder. ins ( ) . call ( callee, & args)
13821424}
13831425
1384- fn debug_assert_enough_capacity_for_length (
1385- builder : & mut FunctionBuilder ,
1386- length : usize ,
1387- capacity : ir:: Value ,
1388- ) {
1389- if cfg ! ( debug_assertions) {
1390- let enough_capacity = builder. ins ( ) . icmp_imm (
1391- ir:: condcodes:: IntCC :: UnsignedGreaterThanOrEqual ,
1392- capacity,
1393- ir:: immediates:: Imm64 :: new ( length. try_into ( ) . unwrap ( ) ) ,
1394- ) ;
1395- builder. ins ( ) . trapz ( enough_capacity, TRAP_INTERNAL_ASSERT ) ;
1396- }
1397- }
1398-
1399- fn debug_assert_vmctx_kind (
1400- isa : & dyn TargetIsa ,
1401- builder : & mut FunctionBuilder ,
1402- vmctx : ir:: Value ,
1403- expected_vmctx_magic : u32 ,
1404- ) {
1405- if cfg ! ( debug_assertions) {
1406- let magic = builder. ins ( ) . load (
1407- ir:: types:: I32 ,
1408- MemFlags :: trusted ( ) . with_endianness ( isa. endianness ( ) ) ,
1409- vmctx,
1410- 0 ,
1411- ) ;
1412- let is_expected_vmctx = builder. ins ( ) . icmp_imm (
1413- ir:: condcodes:: IntCC :: Equal ,
1414- magic,
1415- i64:: from ( expected_vmctx_magic) ,
1416- ) ;
1417- builder. ins ( ) . trapz ( is_expected_vmctx, TRAP_INTERNAL_ASSERT ) ;
1418- }
1419- }
1420-
14211426fn save_last_wasm_entry_fp (
14221427 builder : & mut FunctionBuilder ,
14231428 pointer_type : ir:: Type ,
0 commit comments