Implement an incremental compilation cache for Cranelift (#4551)
This is the implementation of https://github.com/bytecodealliance/wasmtime/issues/4155, using the "inverted API" approach suggested by @cfallin (thanks!) in Cranelift, and trait object to provide a backend for an all-included experience in Wasmtime. After the suggestion of Chris, `Function` has been split into mostly two parts: - on the one hand, `FunctionStencil` contains all the fields required during compilation, and that act as a compilation cache key: if two function stencils are the same, then the result of their compilation (`CompiledCodeBase<Stencil>`) will be the same. This makes caching trivial, as the only thing to cache is the `FunctionStencil`. - on the other hand, `FunctionParameters` contain the... function parameters that are required to finalize the result of compilation into a `CompiledCode` (aka `CompiledCodeBase<Final>`) with proper final relocations etc., by applying fixups and so on. Most changes are here to accomodate those requirements, in particular that `FunctionStencil` should be `Hash`able to be used as a key in the cache: - most source locations are now relative to a base source location in the function, and as such they're encoded as `RelSourceLoc` in the `FunctionStencil`. This required changes so that there's no need to explicitly mark a `SourceLoc` as the base source location, it's automatically detected instead the first time a non-default `SourceLoc` is set. - user-defined external names in the `FunctionStencil` (aka before this patch `ExternalName::User { namespace, index }`) are now references into an external table of `UserExternalNameRef -> UserExternalName`, present in the `FunctionParameters`, and must be explicitly declared using `Function::declare_imported_user_function`. - some refactorings have been made for function names: - `ExternalName` was used as the type for a `Function`'s name; while it thus allowed `ExternalName::Libcall` in this place, this would have been quite confusing to use it there. Instead, a new enum `UserFuncName` is introduced for this name, that's either a user-defined function name (the above `UserExternalName`) or a test case name. - The future of `ExternalName` is likely to become a full reference into the `FunctionParameters`'s mapping, instead of being "either a handle for user-defined external names, or the thing itself for other variants". I'm running out of time to do this, and this is not trivial as it implies touching ISLE which I'm less familiar with. The cache computes a sha256 hash of the `FunctionStencil`, and uses this as the cache key. No equality check (using `PartialEq`) is performed in addition to the hash being the same, as we hope that this is sufficient data to avoid collisions. A basic fuzz target has been introduced that tries to do the bare minimum: - check that a function successfully compiled and cached will be also successfully reloaded from the cache, and returns the exact same function. - check that a trivial modification in the external mapping of `UserExternalNameRef -> UserExternalName` hits the cache, and that other modifications don't hit the cache. - This last check is less efficient and less likely to happen, so probably should be rethought a bit. Thanks to both @alexcrichton and @cfallin for your very useful feedback on Zulip. Some numbers show that for a large wasm module we're using internally, this is a 20% compile-time speedup, because so many `FunctionStencil`s are the same, even within a single module. For a group of modules that have a lot of code in common, we get hit rates up to 70% when they're used together. When a single function changes in a wasm module, every other function is reloaded; that's still slower than I expect (between 10% and 50% of the overall compile time), so there's likely room for improvement. Fixes #4155.
This commit is contained in:
@@ -28,3 +28,4 @@ thiserror = "1.0.4"
|
||||
[features]
|
||||
all-arch = ["cranelift-codegen/all-arch"]
|
||||
component-model = ["wasmtime-environ/component-model"]
|
||||
incremental-cache = ["cranelift-codegen/incremental-cache"]
|
||||
|
||||
@@ -7,12 +7,14 @@ use anyhow::Result;
|
||||
use cranelift_codegen::isa;
|
||||
use cranelift_codegen::settings::{self, Configurable, SetError};
|
||||
use std::fmt;
|
||||
use wasmtime_environ::{CompilerBuilder, Setting, SettingKind};
|
||||
use std::sync::Arc;
|
||||
use wasmtime_environ::{CacheStore, CompilerBuilder, Setting, SettingKind};
|
||||
|
||||
struct Builder {
|
||||
flags: settings::Builder,
|
||||
isa_flags: isa::Builder,
|
||||
linkopts: LinkOptions,
|
||||
cache_store: Option<Arc<dyn CacheStore>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
@@ -46,6 +48,7 @@ pub fn builder() -> Box<dyn CompilerBuilder> {
|
||||
flags,
|
||||
isa_flags: cranelift_native::builder().expect("host machine is not a supported target"),
|
||||
linkopts: LinkOptions::default(),
|
||||
cache_store: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -103,6 +106,7 @@ impl CompilerBuilder for Builder {
|
||||
.finish(settings::Flags::new(self.flags.clone()))?;
|
||||
Ok(Box::new(crate::compiler::Compiler::new(
|
||||
isa,
|
||||
self.cache_store.clone(),
|
||||
self.linkopts.clone(),
|
||||
)))
|
||||
}
|
||||
@@ -123,6 +127,13 @@ impl CompilerBuilder for Builder {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn enable_incremental_compilation(
|
||||
&mut self,
|
||||
cache_store: Arc<dyn wasmtime_environ::CacheStore>,
|
||||
) {
|
||||
self.cache_store = Some(cache_store);
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Builder {
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
use crate::builder::LinkOptions;
|
||||
use crate::debug::{DwarfSectionRelocTarget, ModuleMemoryOffset};
|
||||
use crate::func_environ::{get_func_name, FuncEnvironment};
|
||||
use crate::func_environ::FuncEnvironment;
|
||||
use crate::obj::ModuleTextBuilder;
|
||||
use crate::{
|
||||
blank_sig, func_signature, indirect_signature, value_type, wasmtime_call_conv,
|
||||
CompiledFunction, CompiledFunctions, FunctionAddressMap, Relocation, RelocationTarget,
|
||||
};
|
||||
use anyhow::{Context as _, Result};
|
||||
use cranelift_codegen::ir::{self, ExternalName, InstBuilder, MemFlags, Value};
|
||||
use cranelift_codegen::ir::{
|
||||
self, ExternalName, Function, InstBuilder, MemFlags, UserExternalName, UserFuncName, Value,
|
||||
};
|
||||
use cranelift_codegen::isa::TargetIsa;
|
||||
use cranelift_codegen::print_errors::pretty_error;
|
||||
use cranelift_codegen::Context;
|
||||
use cranelift_codegen::{settings, MachReloc, MachTrap};
|
||||
use cranelift_codegen::{MachSrcLoc, MachStackMap};
|
||||
use cranelift_codegen::{CompiledCode, MachSrcLoc, MachStackMap};
|
||||
use cranelift_entity::{EntityRef, PrimaryMap};
|
||||
use cranelift_frontend::FunctionBuilder;
|
||||
use cranelift_wasm::{
|
||||
@@ -27,19 +29,28 @@ use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::mem;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use wasmtime_environ::{
|
||||
AddressMapSection, CompileError, FilePos, FlagValue, FunctionBodyData, FunctionInfo,
|
||||
InstructionAddressMap, Module, ModuleTranslation, ModuleTypes, PtrSize, StackMapInformation,
|
||||
Trampoline, TrapCode, TrapEncodingBuilder, TrapInformation, Tunables, VMOffsets,
|
||||
AddressMapSection, CacheStore, CompileError, FilePos, FlagValue, FunctionBodyData,
|
||||
FunctionInfo, InstructionAddressMap, Module, ModuleTranslation, ModuleTypes, PtrSize,
|
||||
StackMapInformation, Trampoline, TrapCode, TrapEncodingBuilder, TrapInformation, Tunables,
|
||||
VMOffsets,
|
||||
};
|
||||
|
||||
#[cfg(feature = "component-model")]
|
||||
mod component;
|
||||
|
||||
struct IncrementalCacheContext {
|
||||
#[cfg(feature = "incremental-cache")]
|
||||
cache_store: Arc<dyn CacheStore>,
|
||||
num_hits: usize,
|
||||
num_cached: usize,
|
||||
}
|
||||
|
||||
struct CompilerContext {
|
||||
func_translator: FuncTranslator,
|
||||
codegen_context: Context,
|
||||
incremental_cache_ctx: Option<IncrementalCacheContext>,
|
||||
}
|
||||
|
||||
impl Default for CompilerContext {
|
||||
@@ -47,6 +58,7 @@ impl Default for CompilerContext {
|
||||
Self {
|
||||
func_translator: FuncTranslator::new(),
|
||||
codegen_context: Context::new(),
|
||||
incremental_cache_ctx: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,14 +69,48 @@ pub(crate) struct Compiler {
|
||||
contexts: Mutex<Vec<CompilerContext>>,
|
||||
isa: Box<dyn TargetIsa>,
|
||||
linkopts: LinkOptions,
|
||||
cache_store: Option<Arc<dyn CacheStore>>,
|
||||
}
|
||||
|
||||
impl Drop for Compiler {
|
||||
fn drop(&mut self) {
|
||||
if self.cache_store.is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut num_hits = 0;
|
||||
let mut num_cached = 0;
|
||||
for ctx in self.contexts.lock().unwrap().iter() {
|
||||
if let Some(ref cache_ctx) = ctx.incremental_cache_ctx {
|
||||
num_hits += cache_ctx.num_hits;
|
||||
num_cached += cache_ctx.num_cached;
|
||||
}
|
||||
}
|
||||
|
||||
let total = num_hits + num_cached;
|
||||
if num_hits + num_cached > 0 {
|
||||
log::trace!(
|
||||
"Incremental compilation cache stats: {}/{} = {}% (hits/lookup)\ncached: {}",
|
||||
num_hits,
|
||||
total,
|
||||
(num_hits as f32) / (total as f32) * 100.0,
|
||||
num_cached
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Compiler {
|
||||
pub(crate) fn new(isa: Box<dyn TargetIsa>, linkopts: LinkOptions) -> Compiler {
|
||||
pub(crate) fn new(
|
||||
isa: Box<dyn TargetIsa>,
|
||||
cache_store: Option<Arc<dyn CacheStore>>,
|
||||
linkopts: LinkOptions,
|
||||
) -> Compiler {
|
||||
Compiler {
|
||||
contexts: Default::default(),
|
||||
isa,
|
||||
linkopts,
|
||||
cache_store,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +121,17 @@ impl Compiler {
|
||||
ctx.codegen_context.clear();
|
||||
ctx
|
||||
})
|
||||
.unwrap_or_else(Default::default)
|
||||
.unwrap_or_else(|| CompilerContext {
|
||||
#[cfg(feature = "incremental-cache")]
|
||||
incremental_cache_ctx: self.cache_store.as_ref().map(|cache_store| {
|
||||
IncrementalCacheContext {
|
||||
cache_store: cache_store.clone(),
|
||||
num_hits: 0,
|
||||
num_cached: 0,
|
||||
}
|
||||
}),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn save_context(&self, ctx: CompilerContext) {
|
||||
@@ -141,10 +197,15 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
let CompilerContext {
|
||||
mut func_translator,
|
||||
codegen_context: mut context,
|
||||
incremental_cache_ctx: mut cache_ctx,
|
||||
} = self.take_context();
|
||||
|
||||
context.func.name = get_func_name(func_index);
|
||||
context.func.signature = func_signature(isa, translation, types, func_index);
|
||||
context.func.name = UserFuncName::User(UserExternalName {
|
||||
namespace: 0,
|
||||
index: func_index.as_u32(),
|
||||
});
|
||||
|
||||
if tunables.generate_native_debuginfo {
|
||||
context.func.collect_debug_info();
|
||||
}
|
||||
@@ -210,16 +271,14 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
&mut func_env,
|
||||
)?;
|
||||
|
||||
let mut code_buf: Vec<u8> = Vec::new();
|
||||
let compiled_code = context
|
||||
.compile_and_emit(isa, &mut code_buf)
|
||||
.map_err(|error| CompileError::Codegen(pretty_error(&error.func, error.inner)))?;
|
||||
let (_, code_buf) = compile_maybe_cached(&mut context, isa, cache_ctx.as_mut())?;
|
||||
|
||||
let compiled_code = context.compiled_code().unwrap();
|
||||
let func_relocs = compiled_code
|
||||
.buffer
|
||||
.relocs()
|
||||
.into_iter()
|
||||
.map(mach_reloc_to_reloc)
|
||||
.map(|item| mach_reloc_to_reloc(&context.func, item))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let traps = compiled_code
|
||||
@@ -259,6 +318,7 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
self.save_context(CompilerContext {
|
||||
func_translator,
|
||||
codegen_context: context,
|
||||
incremental_cache_ctx: cache_ctx,
|
||||
});
|
||||
|
||||
Ok(Box::new(CompiledFunction {
|
||||
@@ -403,6 +463,74 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "incremental-cache")]
|
||||
mod incremental_cache {
|
||||
use super::*;
|
||||
|
||||
struct CraneliftCacheStore(Arc<dyn CacheStore>);
|
||||
|
||||
impl cranelift_codegen::incremental_cache::CacheKvStore for CraneliftCacheStore {
|
||||
fn get(&self, key: &[u8]) -> Option<std::borrow::Cow<[u8]>> {
|
||||
self.0.get(key)
|
||||
}
|
||||
fn insert(&mut self, key: &[u8], val: Vec<u8>) {
|
||||
self.0.insert(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn compile_maybe_cached<'a>(
|
||||
context: &'a mut Context,
|
||||
isa: &dyn TargetIsa,
|
||||
cache_ctx: Option<&mut IncrementalCacheContext>,
|
||||
) -> Result<(&'a CompiledCode, Vec<u8>), CompileError> {
|
||||
let mut code_buf = Vec::new();
|
||||
let cache_ctx = match cache_ctx {
|
||||
Some(ctx) => ctx,
|
||||
None => {
|
||||
let compiled_code =
|
||||
context
|
||||
.compile_and_emit(isa, &mut code_buf)
|
||||
.map_err(|error| {
|
||||
CompileError::Codegen(pretty_error(&error.func, error.inner))
|
||||
})?;
|
||||
return Ok((compiled_code, code_buf));
|
||||
}
|
||||
};
|
||||
|
||||
let mut cache_store = CraneliftCacheStore(cache_ctx.cache_store.clone());
|
||||
let (compiled_code, from_cache) = context
|
||||
.compile_with_cache(isa, &mut cache_store)
|
||||
.map_err(|error| CompileError::Codegen(pretty_error(&error.func, error.inner)))?;
|
||||
|
||||
if from_cache {
|
||||
cache_ctx.num_hits += 1;
|
||||
} else {
|
||||
cache_ctx.num_cached += 1;
|
||||
}
|
||||
|
||||
code_buf.resize(compiled_code.code_info().total_size as _, 0);
|
||||
code_buf.copy_from_slice(compiled_code.code_buffer());
|
||||
|
||||
Ok((compiled_code, code_buf))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "incremental-cache")]
|
||||
use incremental_cache::*;
|
||||
|
||||
#[cfg(not(feature = "incremental-cache"))]
|
||||
fn compile_maybe_cached<'a>(
|
||||
context: &'a mut Context,
|
||||
isa: &dyn TargetIsa,
|
||||
_cache_ctx: Option<&mut IncrementalCacheContext>,
|
||||
) -> Result<(&'a CompiledCode, Vec<u8>), CompileError> {
|
||||
let mut code_buf = Vec::new();
|
||||
let compiled_code = context
|
||||
.compile_and_emit(isa, &mut code_buf)
|
||||
.map_err(|error| CompileError::Codegen(pretty_error(&error.func, error.inner)))?;
|
||||
return Ok((compiled_code, code_buf));
|
||||
}
|
||||
|
||||
fn to_flag_value(v: &settings::Value) -> FlagValue {
|
||||
match v.kind() {
|
||||
settings::SettingKind::Enum => FlagValue::Enum(v.as_enum().unwrap().into()),
|
||||
@@ -431,9 +559,11 @@ impl Compiler {
|
||||
let CompilerContext {
|
||||
mut func_translator,
|
||||
codegen_context: mut context,
|
||||
incremental_cache_ctx: mut cache_ctx,
|
||||
} = self.take_context();
|
||||
|
||||
context.func = ir::Function::with_name_signature(ExternalName::user(0, 0), host_signature);
|
||||
// The name doesn't matter here.
|
||||
context.func = ir::Function::with_name_signature(UserFuncName::default(), host_signature);
|
||||
|
||||
// This trampoline will load all the parameters from the `values_vec`
|
||||
// that is passed in and then call the real function (also passed
|
||||
@@ -493,10 +623,11 @@ impl Compiler {
|
||||
builder.ins().return_(&[]);
|
||||
builder.finalize();
|
||||
|
||||
let func = self.finish_trampoline(&mut context, isa)?;
|
||||
let func = self.finish_trampoline(&mut context, cache_ctx.as_mut(), isa)?;
|
||||
self.save_context(CompilerContext {
|
||||
func_translator,
|
||||
codegen_context: context,
|
||||
incremental_cache_ctx: cache_ctx,
|
||||
});
|
||||
Ok(func)
|
||||
}
|
||||
@@ -541,10 +672,11 @@ impl Compiler {
|
||||
let CompilerContext {
|
||||
mut func_translator,
|
||||
codegen_context: mut context,
|
||||
incremental_cache_ctx: mut cache_ctx,
|
||||
} = self.take_context();
|
||||
|
||||
context.func =
|
||||
ir::Function::with_name_signature(ir::ExternalName::user(0, 0), wasm_signature);
|
||||
// The name doesn't matter here.
|
||||
context.func = ir::Function::with_name_signature(Default::default(), wasm_signature);
|
||||
|
||||
let mut builder = FunctionBuilder::new(&mut context.func, func_translator.context());
|
||||
let block0 = builder.create_block();
|
||||
@@ -570,10 +702,11 @@ impl Compiler {
|
||||
|
||||
self.wasm_to_host_load_results(ty, &mut builder, values_vec_ptr_val);
|
||||
|
||||
let func = self.finish_trampoline(&mut context, isa)?;
|
||||
let func = self.finish_trampoline(&mut context, cache_ctx.as_mut(), isa)?;
|
||||
self.save_context(CompilerContext {
|
||||
func_translator,
|
||||
codegen_context: context,
|
||||
incremental_cache_ctx: cache_ctx,
|
||||
});
|
||||
Ok(func)
|
||||
}
|
||||
@@ -668,12 +801,10 @@ impl Compiler {
|
||||
fn finish_trampoline(
|
||||
&self,
|
||||
context: &mut Context,
|
||||
cache_ctx: Option<&mut IncrementalCacheContext>,
|
||||
isa: &dyn TargetIsa,
|
||||
) -> Result<CompiledFunction, CompileError> {
|
||||
let mut code_buf = Vec::new();
|
||||
let compiled_code = context
|
||||
.compile_and_emit(isa, &mut code_buf)
|
||||
.map_err(|error| CompileError::Codegen(pretty_error(&error.func, error.inner)))?;
|
||||
let (compiled_code, code_buf) = compile_maybe_cached(context, isa, cache_ctx)?;
|
||||
|
||||
// Processing relocations isn't the hardest thing in the world here but
|
||||
// no trampoline should currently generate a relocation, so assert that
|
||||
@@ -858,14 +989,15 @@ fn collect_address_maps(
|
||||
}
|
||||
}
|
||||
|
||||
fn mach_reloc_to_reloc(reloc: &MachReloc) -> Relocation {
|
||||
fn mach_reloc_to_reloc(func: &Function, reloc: &MachReloc) -> Relocation {
|
||||
let &MachReloc {
|
||||
offset,
|
||||
kind,
|
||||
ref name,
|
||||
addend,
|
||||
} = reloc;
|
||||
let reloc_target = if let ExternalName::User { namespace, index } = *name {
|
||||
let reloc_target = if let ExternalName::User(user_func_ref) = *name {
|
||||
let UserExternalName { namespace, index } = func.params.user_named_funcs()[user_func_ref];
|
||||
debug_assert_eq!(namespace, 0);
|
||||
RelocationTarget::UserFunc(FuncIndex::from_u32(index))
|
||||
} else if let ExternalName::LibCall(libcall) = *name {
|
||||
|
||||
@@ -31,10 +31,11 @@ impl ComponentCompiler for Compiler {
|
||||
let CompilerContext {
|
||||
mut func_translator,
|
||||
codegen_context: mut context,
|
||||
mut incremental_cache_ctx,
|
||||
} = self.take_context();
|
||||
|
||||
context.func = ir::Function::with_name_signature(
|
||||
ir::ExternalName::user(0, 0),
|
||||
ir::UserFuncName::user(0, 0),
|
||||
crate::indirect_signature(isa, ty),
|
||||
);
|
||||
|
||||
@@ -149,10 +150,12 @@ impl ComponentCompiler for Compiler {
|
||||
// `values_vec_ptr_val` and then returned.
|
||||
self.wasm_to_host_load_results(ty, &mut builder, values_vec_ptr_val);
|
||||
|
||||
let func: CompiledFunction = self.finish_trampoline(&mut context, isa)?;
|
||||
let func: CompiledFunction =
|
||||
self.finish_trampoline(&mut context, incremental_cache_ctx.as_mut(), isa)?;
|
||||
self.save_context(CompilerContext {
|
||||
func_translator,
|
||||
codegen_context: context,
|
||||
incremental_cache_ctx,
|
||||
});
|
||||
Ok(Box::new(func))
|
||||
}
|
||||
@@ -162,9 +165,10 @@ impl ComponentCompiler for Compiler {
|
||||
let CompilerContext {
|
||||
mut func_translator,
|
||||
codegen_context: mut context,
|
||||
mut incremental_cache_ctx,
|
||||
} = self.take_context();
|
||||
context.func = ir::Function::with_name_signature(
|
||||
ir::ExternalName::user(0, 0),
|
||||
ir::UserFuncName::user(0, 0),
|
||||
crate::indirect_signature(isa, ty),
|
||||
);
|
||||
let mut builder = FunctionBuilder::new(&mut context.func, func_translator.context());
|
||||
@@ -177,10 +181,12 @@ impl ComponentCompiler for Compiler {
|
||||
.trap(ir::TrapCode::User(super::ALWAYS_TRAP_CODE));
|
||||
builder.finalize();
|
||||
|
||||
let func: CompiledFunction = self.finish_trampoline(&mut context, isa)?;
|
||||
let func: CompiledFunction =
|
||||
self.finish_trampoline(&mut context, incremental_cache_ctx.as_mut(), isa)?;
|
||||
self.save_context(CompilerContext {
|
||||
func_translator,
|
||||
codegen_context: context,
|
||||
incremental_cache_ctx,
|
||||
});
|
||||
Ok(Box::new(func))
|
||||
}
|
||||
@@ -198,10 +204,11 @@ impl ComponentCompiler for Compiler {
|
||||
let CompilerContext {
|
||||
mut func_translator,
|
||||
codegen_context: mut context,
|
||||
mut incremental_cache_ctx,
|
||||
} = self.take_context();
|
||||
|
||||
context.func = ir::Function::with_name_signature(
|
||||
ir::ExternalName::user(0, 0),
|
||||
ir::UserFuncName::user(0, 0),
|
||||
crate::indirect_signature(isa, ty),
|
||||
);
|
||||
|
||||
@@ -213,10 +220,12 @@ impl ComponentCompiler for Compiler {
|
||||
|
||||
self.translate_transcode(&mut builder, &offsets, transcoder, block0);
|
||||
|
||||
let func: CompiledFunction = self.finish_trampoline(&mut context, isa)?;
|
||||
let func: CompiledFunction =
|
||||
self.finish_trampoline(&mut context, incremental_cache_ctx.as_mut(), isa)?;
|
||||
self.save_context(CompilerContext {
|
||||
func_translator,
|
||||
codegen_context: context,
|
||||
incremental_cache_ctx,
|
||||
});
|
||||
Ok(Box::new(func))
|
||||
}
|
||||
|
||||
@@ -21,11 +21,6 @@ use wasmtime_environ::{
|
||||
};
|
||||
use wasmtime_environ::{FUNCREF_INIT_BIT, FUNCREF_MASK};
|
||||
|
||||
/// Compute an `ir::ExternalName` for a given wasm function index.
|
||||
pub fn get_func_name(func_index: FuncIndex) -> ir::ExternalName {
|
||||
ir::ExternalName::user(0, func_index.as_u32())
|
||||
}
|
||||
|
||||
macro_rules! declare_function_signatures {
|
||||
(
|
||||
$(
|
||||
@@ -1509,7 +1504,11 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
|
||||
) -> WasmResult<ir::FuncRef> {
|
||||
let sig = crate::func_signature(self.isa, self.translation, self.types, index);
|
||||
let signature = func.import_signature(sig);
|
||||
let name = get_func_name(index);
|
||||
let name =
|
||||
ir::ExternalName::User(func.declare_imported_user_function(ir::UserExternalName {
|
||||
namespace: 0,
|
||||
index: index.as_u32(),
|
||||
}));
|
||||
Ok(func.import_function(ir::ExtFuncData {
|
||||
name,
|
||||
signature,
|
||||
|
||||
Reference in New Issue
Block a user