From 077d4755d940ee95a7e6a2c9528a56b705ec3b04 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 19 Apr 2023 14:22:25 -0500 Subject: [PATCH] Mark loads from `VMCallerCheckedAnyfunc` as readonly (#6243) This commit marks the loads of `*mut VMContext` and the callee function pointer as `readonly` in the context of indirect function calls and additionally calls to imported functions (which are indirect). Once a `VMCallerCheckedAnyfunc` is initialized it's never modified so it should be valid to mark these as readonly and if called in a loop should be hoistable outside of the loop. --- crates/cranelift/src/func_environ.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/cranelift/src/func_environ.rs b/crates/cranelift/src/func_environ.rs index 305d123551..bb3fc608f3 100644 --- a/crates/cranelift/src/func_environ.rs +++ b/crates/cranelift/src/func_environ.rs @@ -1595,7 +1595,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m .trapz(funcref_ptr, ir::TrapCode::IndirectCallToNull); // Dereference the funcref pointer to get the function address. - let mem_flags = ir::MemFlags::trusted(); + let mem_flags = ir::MemFlags::trusted().with_readonly(); let func_addr = builder.ins().load( pointer_type, mem_flags, @@ -1631,7 +1631,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m .load(sig_id_type, mem_flags, signatures, offset); // Load the callee ID. - let mem_flags = ir::MemFlags::trusted(); + let mem_flags = ir::MemFlags::trusted().with_readonly(); let callee_sig_id = builder.ins().load( sig_id_type, mem_flags, @@ -1703,7 +1703,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m let vmctx = self.vmctx(&mut pos.func); let base = pos.ins().global_value(pointer_type, vmctx); - let mem_flags = ir::MemFlags::trusted(); + let mem_flags = ir::MemFlags::trusted().with_readonly(); // Load the callee address. let body_offset =