Skip to content

Commit

Permalink
Merge pull request #3564 from wasmerio/update_cranelift_0_91
Browse files Browse the repository at this point in the history
Updated Cranelift to 0.91
  • Loading branch information
ptitSeb authored Feb 2, 2023
2 parents 16ce793 + 4e475a9 commit 899a2ac
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 99 deletions.
53 changes: 35 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/compiler-cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ edition = "2018"
[dependencies]
wasmer-compiler = { path = "../compiler", version = "=3.2.0-alpha.1", features = ["translator", "compiler"], default-features = false }
wasmer-types = { path = "../types", version = "=3.2.0-alpha.1", default-features = false, features = ["std"] }
cranelift-entity = { version = "0.86.1", default-features = false }
cranelift-codegen = { version = "0.86.1", default-features = false, features = ["x86", "arm64"] }
cranelift-frontend = { version = "0.86.1", default-features = false }
cranelift-entity = { version = "0.91.0", default-features = false }
cranelift-codegen = { version = "0.91.0", default-features = false, features = ["x86", "arm64"] }
cranelift-frontend = { version = "0.91.0", default-features = false }
tracing = "0.1"
hashbrown = { version = "0.11", optional = true }
rayon = { version = "1.5", optional = true }
Expand All @@ -26,7 +26,7 @@ smallvec = "1.6"
target-lexicon = { version = "0.12.2", default-features = false }

[dev-dependencies]
cranelift-codegen = { version = "0.86.1", features = ["all-arch"] }
cranelift-codegen = { version = "0.91.0", features = ["all-arch"] }
lazy_static = "1.4"

[badges]
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler-cranelift/src/address_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn get_function_address_map(

// New-style backend: we have a `MachCompileResult` that will give us `MachSrcLoc` mapping
// tuples.
let mcr = context.mach_compile_result.as_ref().unwrap();
let mcr = context.compiled_code().unwrap();
for &MachSrcLoc { start, end, loc } in mcr.buffer.get_srclocs_sorted() {
instructions.push(InstructionAddressMap {
srcloc: SourceLoc::new(loc.bits()),
Expand Down
43 changes: 32 additions & 11 deletions lib/compiler-cranelift/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use crate::translator::{
compiled_function_unwind_info, irlibcall_to_libcall, irreloc_to_relocationkind,
signature_to_cranelift_ir, CraneliftUnwindInfo, FuncTranslator,
};
use cranelift_codegen::ir::ExternalName;
use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::ir::{ExternalName, UserFuncName};
use cranelift_codegen::{ir, MachReloc};
use cranelift_codegen::{Context, MachTrap};
#[cfg(feature = "unwind")]
Expand Down Expand Up @@ -127,7 +126,18 @@ impl Compiler for CraneliftCompiler {
&memory_styles,
&table_styles,
);
context.func.name = get_function_name(func_index);
context.func.name = match get_function_name(func_index) {
ExternalName::User(nameref) => {
if context.func.params.user_named_funcs().is_valid(nameref) {
let name = &context.func.params.user_named_funcs()[nameref];
UserFuncName::User(name.clone())
} else {
UserFuncName::default()
}
}
ExternalName::TestCase(testcase) => UserFuncName::Testcase(testcase),
_ => UserFuncName::default(),
};
context.func.signature = signatures[module.functions[func_index]].clone();
// if generate_debug_info {
// context.func.collect_debug_info();
Expand All @@ -151,9 +161,9 @@ impl Compiler for CraneliftCompiler {
let mut code_buf: Vec<u8> = Vec::new();
context
.compile_and_emit(&*isa, &mut code_buf)
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
.map_err(|error| CompileError::Codegen(error.inner.to_string()))?;

let result = context.mach_compile_result.as_ref().unwrap();
let result = context.compiled_code().unwrap();
let func_relocs = result
.buffer
.relocs()
Expand Down Expand Up @@ -228,7 +238,18 @@ impl Compiler for CraneliftCompiler {
memory_styles,
table_styles,
);
context.func.name = get_function_name(func_index);
context.func.name = match get_function_name(func_index) {
ExternalName::User(nameref) => {
if context.func.params.user_named_funcs().is_valid(nameref) {
let name = &context.func.params.user_named_funcs()[nameref];
UserFuncName::User(name.clone())
} else {
UserFuncName::default()
}
}
ExternalName::TestCase(testcase) => UserFuncName::Testcase(testcase),
_ => UserFuncName::default(),
};
context.func.signature = signatures[module.functions[func_index]].clone();
// if generate_debug_info {
// context.func.collect_debug_info();
Expand All @@ -252,9 +273,9 @@ impl Compiler for CraneliftCompiler {
let mut code_buf: Vec<u8> = Vec::new();
context
.compile_and_emit(&*isa, &mut code_buf)
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
.map_err(|error| CompileError::Codegen(error.inner.to_string()))?;

let result = context.mach_compile_result.as_ref().unwrap();
let result = context.compiled_code().unwrap();
let func_relocs = result
.buffer
.relocs()
Expand Down Expand Up @@ -401,11 +422,11 @@ fn mach_reloc_to_reloc(module: &ModuleInfo, reloc: &MachReloc) -> Relocation {
ref name,
addend,
} = reloc;
let reloc_target = if let ExternalName::User { namespace, index } = *name {
debug_assert_eq!(namespace, 0);
let reloc_target = if let ExternalName::User(extname_ref) = *name {
//debug_assert_eq!(namespace, 0);
RelocationTarget::LocalFunc(
module
.local_func_index(FunctionIndex::from_u32(index))
.local_func_index(FunctionIndex::from_u32(extname_ref.as_u32()))
.expect("The provided function should be local"),
)
} else if let ExternalName::LibCall(libcall) = *name {
Expand Down
5 changes: 5 additions & 0 deletions lib/compiler-cranelift/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ impl Cranelift {
pub fn flags(&self) -> settings::Flags {
let mut flags = settings::builder();

// Enable probestack
flags
.enable("enable_probestack")
.expect("should be valid flag");

// There are two possible traps for division, and this way
// we get the proper one if code traps.
flags
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler-cranelift/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use wasmer_types::{WasmError, WasmResult};

/// Compute an `ir::ExternalName` for a given wasm function index.
pub fn get_function_name(func_index: FunctionIndex) -> ir::ExternalName {
ir::ExternalName::user(0, func_index.as_u32())
ir::ExternalName::user(ir::UserExternalNameRef::from_u32(func_index.as_u32()))
}

/// The type of the `current_elements` field.
Expand Down Expand Up @@ -1028,7 +1028,7 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro
_ => unreachable!(),
};

Ok(pos.ins().bint(ir::types::I32, bool_is_null))
Ok(pos.ins().uextend(ir::types::I32, bool_is_null))
}

fn translate_ref_func(
Expand Down
9 changes: 4 additions & 5 deletions lib/compiler-cranelift/src/trampoline/dynamic_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
use crate::translator::{compiled_function_unwind_info, signature_to_cranelift_ir};
use cranelift_codegen::ir;
use cranelift_codegen::ir::{
ExternalName, Function, InstBuilder, MemFlags, StackSlotData, StackSlotKind,
Function, InstBuilder, MemFlags, StackSlotData, StackSlotKind, UserFuncName,
};
use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::Context;
use std::cmp;
use std::mem;
Expand Down Expand Up @@ -43,9 +42,9 @@ pub fn make_trampoline_dynamic_function(
(value_size * cmp::max(signature.params.len() - 1, signature.returns.len())) as u32;

let mut context = Context::new();
context.func = Function::with_name_signature(ExternalName::user(0, 0), signature.clone());
context.func = Function::with_name_signature(UserFuncName::user(0, 0), signature.clone());

let ss = context.func.create_stack_slot(StackSlotData::new(
let ss = context.func.create_sized_stack_slot(StackSlotData::new(
StackSlotKind::ExplicitSlot,
values_vec_len,
));
Expand Down Expand Up @@ -107,7 +106,7 @@ pub fn make_trampoline_dynamic_function(
let mut code_buf = Vec::new();
context
.compile_and_emit(isa, &mut code_buf)
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
.map_err(|error| CompileError::Codegen(error.inner.to_string()))?;

let unwind_info = compiled_function_unwind_info(isa, &context)?.maybe_into_to_windows_unwind();

Expand Down
5 changes: 2 additions & 3 deletions lib/compiler-cranelift/src/trampoline/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::translator::{compiled_function_unwind_info, signature_to_cranelift_ir
use cranelift_codegen::ir;
use cranelift_codegen::ir::InstBuilder;
use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::Context;
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use std::mem;
Expand Down Expand Up @@ -42,7 +41,7 @@ pub fn make_trampoline_function_call(
wrapper_sig.params.push(ir::AbiParam::new(pointer_type));

let mut context = Context::new();
context.func = ir::Function::with_name_signature(ir::ExternalName::user(0, 0), wrapper_sig);
context.func = ir::Function::with_name_signature(ir::UserFuncName::user(0, 0), wrapper_sig);

let value_size = mem::size_of::<u128>();
{
Expand Down Expand Up @@ -105,7 +104,7 @@ pub fn make_trampoline_function_call(

context
.compile_and_emit(isa, &mut code_buf)
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
.map_err(|error| CompileError::Codegen(error.inner.to_string()))?;

let unwind_info = compiled_function_unwind_info(isa, &context)?.maybe_into_to_windows_unwind();

Expand Down
Loading

0 comments on commit 899a2ac

Please sign in to comment.