Skip to content

Commit 093b520

Browse files
alexcrichtondicej
andauthored
Further refactor TrampolineCompiler for the wasm ABI (#11939)
* Further refactor `TrampolineCompiler` for the wasm ABI This is a follow-up to #11932 where the `TrampolineCompiler` type is further specialized to just working with the wasm ABI instead of trying to multiplex two ABIs now that the array ABI is handled by calling the wasm ABI. This involved purging the `self.abi` field and updating all callers as appropriate. This then performed some small refactoring to use `TrampolineCompiler` for compiler intrinsics. Unsafe intrinsics also now have the same strategy of calling the wasm ABI trampoline when compiling for the array ABI. This should ensure that all entry trampolines are going through the same function. * Refactor short-circuit in inlining * Update crates/wasmtime/src/compile.rs Co-authored-by: Joel Dice <joel.dice@fermyon.com> --------- Co-authored-by: Joel Dice <joel.dice@fermyon.com>
1 parent 23b9f3b commit 093b520

File tree

6 files changed

+214
-319
lines changed

6 files changed

+214
-319
lines changed

crates/cranelift/src/compiler.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ use wasmtime_environ::{
3636
Abi, AddressMapSection, BuiltinFunctionIndex, CacheStore, CompileError, CompiledFunctionBody,
3737
DefinedFuncIndex, FlagValue, FrameInstPos, FrameStackShape, FrameStateSlotBuilder,
3838
FrameTableBuilder, FuncKey, FunctionBodyData, FunctionLoc, HostCall, InliningCompiler,
39-
ModuleInternedTypeIndex, ModuleTranslation, ModuleTypesBuilder, PtrSize, StackMapSection,
40-
StaticModuleIndex, TrapEncodingBuilder, TrapSentinel, TripleExt, Tunables, WasmFuncType,
41-
WasmValType,
39+
ModuleTranslation, ModuleTypesBuilder, PtrSize, StackMapSection, StaticModuleIndex,
40+
TrapEncodingBuilder, TrapSentinel, TripleExt, Tunables, WasmFuncType, WasmValType,
4241
};
4342
use wasmtime_unwinder::ExceptionTableBuilder;
4443

@@ -363,8 +362,7 @@ impl wasmtime_environ::Compiler for Compiler {
363362
self.array_to_wasm_trampoline(
364363
key,
365364
FuncKey::DefinedWasmFunction(module_index, def_func_index),
366-
types,
367-
sig,
365+
types[sig].unwrap_func(),
368366
symbol,
369367
self.isa.pointer_bytes().vmctx_store_context().into(),
370368
wasmtime_environ::VMCONTEXT_MAGIC,
@@ -1231,19 +1229,16 @@ impl Compiler {
12311229
&self,
12321230
trampoline_key: FuncKey,
12331231
callee_key: FuncKey,
1234-
types: &ModuleTypesBuilder,
1235-
callee_sig: ModuleInternedTypeIndex,
1232+
callee_sig: &WasmFuncType,
12361233
symbol: &str,
12371234
vm_store_context_offset: u32,
12381235
expected_vmctx_magic: u32,
12391236
) -> Result<CompiledFunctionBody, CompileError> {
12401237
log::trace!("compiling array-to-wasm trampoline: {trampoline_key:?} = {symbol:?}");
12411238

1242-
let wasm_func_ty = types[callee_sig].unwrap_func();
1243-
12441239
let isa = &*self.isa;
12451240
let pointer_type = isa.pointer_type();
1246-
let wasm_call_sig = wasm_call_signature(isa, wasm_func_ty, &self.tunables);
1241+
let wasm_call_sig = wasm_call_signature(isa, callee_sig, &self.tunables);
12471242
let array_call_sig = array_call_signature(isa);
12481243

12491244
let mut compiler = self.function_compiler();
@@ -1261,7 +1256,7 @@ impl Compiler {
12611256

12621257
// First load the actual arguments out of the array.
12631258
let mut args = self.load_values_from_array(
1264-
wasm_func_ty.params(),
1259+
callee_sig.params(),
12651260
&mut builder,
12661261
values_vec_ptr,
12671262
values_vec_len,
@@ -1340,7 +1335,7 @@ impl Compiler {
13401335
builder.switch_to_block(normal_return);
13411336
self.store_values_to_array(
13421337
&mut builder,
1343-
wasm_func_ty.returns(),
1338+
callee_sig.returns(),
13441339
&normal_return_values,
13451340
values_vec_ptr,
13461341
values_vec_len,

0 commit comments

Comments
 (0)