diff --git a/Cargo.lock b/Cargo.lock index 6ce7ebaecdd..658e3bf3dd7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -580,26 +580,29 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "529ffacce2249ac60edba2941672dfedf3d96558b415d0d8083cd007456e0f55" +checksum = "fc952b310b24444fc14ab8b9cbe3fafd7e7329e3eec84c3a9b11d2b5cf6f3be1" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "427d105f617efc8cb55f8d036a7fded2e227892d8780b4985e5551f8d27c4a92" +checksum = "e73470419b33011e50dbf0f6439cbccbaabe9381de172da4e1b6efcda4bb8fa7" dependencies = [ + "arrayvec 0.7.2", + "bumpalo", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", + "cranelift-egraph", "cranelift-entity", "cranelift-isle", "gimli 0.26.2", - "hashbrown 0.11.2", + "hashbrown 0.12.3", "log", "regalloc2", "smallvec", @@ -608,33 +611,47 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "551674bed85b838d45358e3eab4f0ffaa6790c70dc08184204b9a54b41cdb7d1" +checksum = "911a1872464108a11ac9965c2b079e61bbdf1bc2e0b9001264264add2e12a38f" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b3a63ae57498c3eb495360944a33571754241e15e47e3bcae6082f40fec5866" +checksum = "e036f3f07adb24a86fb46e977e8fe03b18bb16b1eada949cf2c48283e5f8a862" + +[[package]] +name = "cranelift-egraph" +version = "0.91.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d6c623f4b5d2a6bad32c403f03765d4484a827eb93ee78f8cb6219ef118fd59" +dependencies = [ + "cranelift-entity", + "fxhash", + "hashbrown 0.12.3", + "indexmap", + "log", + "smallvec", +] [[package]] name = "cranelift-entity" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11aa8aa624c72cc1c94ea3d0739fa61248260b5b14d3646f51593a88d67f3e6e" +checksum = "74385eb5e405b3562f0caa7bcc4ab9a93c7958dd5bcd0e910bffb7765eacd6fc" [[package]] name = "cranelift-frontend" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "544ee8f4d1c9559c9aa6d46e7aaeac4a13856d620561094f35527356c7d21bd0" +checksum = "8a4ac920422ee36bff2c66257fec861765e3d95a125cdf58d8c0f3bba7e40e61" dependencies = [ "cranelift-codegen", - "hashbrown 0.11.2", + "hashbrown 0.12.3", "log", "smallvec", "target-lexicon 0.12.5", @@ -642,9 +659,9 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed16b14363d929b8c37e3c557d0a7396791b383ecc302141643c054343170aad" +checksum = "c541263fb37ad2baa53ec8c37218ee5d02fa0984670d9419dedd8002ea68ff08" [[package]] name = "crc" @@ -2736,9 +2753,9 @@ checksum = "a0d51660a68078997855ba5602f73ab3a5031bd7ad480a9d4c90fbbf04e1fff0" [[package]] name = "regalloc2" -version = "0.3.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d43a209257d978ef079f3d446331d0f1794f5e0fc19b306a199983857833a779" +checksum = "300d4fbfb40c1c66a78ba3ddd41c1110247cf52f97b87d0f2fc9209bd49b030c" dependencies = [ "fxhash", "log", diff --git a/lib/compiler-cranelift/Cargo.toml b/lib/compiler-cranelift/Cargo.toml index 9e5a3a49207..12122ea3c69 100644 --- a/lib/compiler-cranelift/Cargo.toml +++ b/lib/compiler-cranelift/Cargo.toml @@ -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 } @@ -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] diff --git a/lib/compiler-cranelift/src/address_map.rs b/lib/compiler-cranelift/src/address_map.rs index 3f6e22c54a5..2fe92429fd7 100644 --- a/lib/compiler-cranelift/src/address_map.rs +++ b/lib/compiler-cranelift/src/address_map.rs @@ -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()), diff --git a/lib/compiler-cranelift/src/compiler.rs b/lib/compiler-cranelift/src/compiler.rs index 9f2481bb0a2..b2a880f6953 100644 --- a/lib/compiler-cranelift/src/compiler.rs +++ b/lib/compiler-cranelift/src/compiler.rs @@ -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")] @@ -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(); @@ -151,9 +161,9 @@ impl Compiler for CraneliftCompiler { let mut code_buf: Vec = 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() @@ -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(); @@ -252,9 +273,9 @@ impl Compiler for CraneliftCompiler { let mut code_buf: Vec = 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() @@ -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 { diff --git a/lib/compiler-cranelift/src/config.rs b/lib/compiler-cranelift/src/config.rs index 5c757c9ef76..dff2ba11919 100644 --- a/lib/compiler-cranelift/src/config.rs +++ b/lib/compiler-cranelift/src/config.rs @@ -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 diff --git a/lib/compiler-cranelift/src/func_environ.rs b/lib/compiler-cranelift/src/func_environ.rs index 0608b7add7b..d71153235b8 100644 --- a/lib/compiler-cranelift/src/func_environ.rs +++ b/lib/compiler-cranelift/src/func_environ.rs @@ -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. @@ -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( diff --git a/lib/compiler-cranelift/src/trampoline/dynamic_function.rs b/lib/compiler-cranelift/src/trampoline/dynamic_function.rs index 37ea9d46fa0..f7f84edc324 100644 --- a/lib/compiler-cranelift/src/trampoline/dynamic_function.rs +++ b/lib/compiler-cranelift/src/trampoline/dynamic_function.rs @@ -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; @@ -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, )); @@ -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(); diff --git a/lib/compiler-cranelift/src/trampoline/function_call.rs b/lib/compiler-cranelift/src/trampoline/function_call.rs index 12d8d2eb7d8..8d6741d3db4 100644 --- a/lib/compiler-cranelift/src/trampoline/function_call.rs +++ b/lib/compiler-cranelift/src/trampoline/function_call.rs @@ -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; @@ -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::(); { @@ -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(); diff --git a/lib/compiler-cranelift/src/translator/code_translator.rs b/lib/compiler-cranelift/src/translator/code_translator.rs index 6b42a8e6c6e..fb2de48eb27 100644 --- a/lib/compiler-cranelift/src/translator/code_translator.rs +++ b/lib/compiler-cranelift/src/translator/code_translator.rs @@ -124,7 +124,7 @@ pub fn translate_operator( * disappear in the Cranelift Code ***********************************************************************************/ Operator::LocalGet { local_index } => { - let val = builder.use_var(Variable::with_u32(*local_index)); + let val = builder.use_var(Variable::from_u32(*local_index)); state.push1(val); let label = ValueLabel::from_u32(*local_index); builder.set_val_label(val, label); @@ -138,7 +138,7 @@ pub fn translate_operator( val = optionally_bitcast_vector(val, I8X16, builder); } - builder.def_var(Variable::with_u32(*local_index), val); + builder.def_var(Variable::from_u32(*local_index), val); let label = ValueLabel::from_u32(*local_index); builder.set_val_label(val, label); } @@ -151,7 +151,7 @@ pub fn translate_operator( val = optionally_bitcast_vector(val, I8X16, builder); } - builder.def_var(Variable::with_u32(*local_index), val); + builder.def_var(Variable::from_u32(*local_index), val); let label = ValueLabel::from_u32(*local_index); builder.set_val_label(val, label); } @@ -368,8 +368,7 @@ pub fn translate_operator( Operator::End => { let frame = state.control_stack.pop().unwrap(); let next_block = frame.following_code(); - - if !builder.is_unreachable() || !builder.is_pristine() { + if !builder.is_unreachable() || builder.func.layout.first_inst(next_block).is_some() { let return_count = frame.num_return_values(); let return_args = state.peekn(return_count); canonicalise_then_jump(builder, frame.following_code(), return_args); @@ -519,11 +518,8 @@ pub fn translate_operator( state.reachable = false; } Operator::Return => { - let (return_count, br_destination) = { + let (return_count, _br_destination) = { let frame = &mut state.control_stack[0]; - if environ.return_mode() == ReturnMode::FallthroughReturn { - frame.set_branched_to_exit(); - } let return_count = frame.num_return_values(); (return_count, frame.br_destination()) }; @@ -536,9 +532,6 @@ pub fn translate_operator( bitcast_arguments(return_args, &return_types, builder); match environ.return_mode() { ReturnMode::NormalReturns => builder.ins().return_(return_args), - ReturnMode::FallthroughReturn => { - canonicalise_then_jump(builder, br_destination, return_args) - } }; } state.popn(return_count); @@ -861,19 +854,19 @@ pub fn translate_operator( } Operator::F32ReinterpretI32 => { let val = state.pop1(); - state.push1(builder.ins().bitcast(F32, val)); + state.push1(builder.ins().bitcast(F32, MemFlags::new(), val)); } Operator::F64ReinterpretI64 => { let val = state.pop1(); - state.push1(builder.ins().bitcast(F64, val)); + state.push1(builder.ins().bitcast(F64, MemFlags::new(), val)); } Operator::I32ReinterpretF32 => { let val = state.pop1(); - state.push1(builder.ins().bitcast(I32, val)); + state.push1(builder.ins().bitcast(I32, MemFlags::new(), val)); } Operator::I64ReinterpretF64 => { let val = state.pop1(); - state.push1(builder.ins().bitcast(I64, val)); + state.push1(builder.ins().bitcast(I64, MemFlags::new(), val)); } Operator::I32Extend8S => { let val = state.pop1(); @@ -1022,7 +1015,7 @@ pub fn translate_operator( Operator::I32Eqz | Operator::I64Eqz => { let arg = state.pop1(); let val = builder.ins().icmp_imm(IntCC::Equal, arg, 0); - state.push1(builder.ins().bint(I32, val)); + state.push1(builder.ins().uextend(I32, val)); } Operator::I32Eq | Operator::I64Eq => translate_icmp(IntCC::Equal, builder, state), Operator::F32Eq | Operator::F64Eq => translate_fcmp(FloatCC::Equal, builder, state), @@ -1583,7 +1576,7 @@ pub fn translate_operator( } Operator::I8x16MinS | Operator::I16x8MinS | Operator::I32x4MinS => { let (a, b) = pop2_with_bitcast(state, type_of(op), builder); - state.push1(builder.ins().imin(a, b)) + state.push1(builder.ins().smin(a, b)) } Operator::I8x16MinU | Operator::I16x8MinU | Operator::I32x4MinU => { let (a, b) = pop2_with_bitcast(state, type_of(op), builder); @@ -1591,7 +1584,7 @@ pub fn translate_operator( } Operator::I8x16MaxS | Operator::I16x8MaxS | Operator::I32x4MaxS => { let (a, b) = pop2_with_bitcast(state, type_of(op), builder); - state.push1(builder.ins().imax(a, b)) + state.push1(builder.ins().smax(a, b)) } Operator::I8x16MaxU | Operator::I16x8MaxU | Operator::I32x4MaxU => { let (a, b) = pop2_with_bitcast(state, type_of(op), builder); @@ -1672,7 +1665,7 @@ pub fn translate_operator( Operator::V128AnyTrue => { let a = pop1_with_bitcast(state, type_of(op), builder); let bool_result = builder.ins().vany_true(a); - state.push1(builder.ins().bint(I32, bool_result)) + state.push1(builder.ins().uextend(I32, bool_result)) } Operator::I8x16AllTrue | Operator::I16x8AllTrue @@ -1680,7 +1673,7 @@ pub fn translate_operator( | Operator::I64x2AllTrue => { let a = pop1_with_bitcast(state, type_of(op), builder); let bool_result = builder.ins().vall_true(a); - state.push1(builder.ins().bint(I32, bool_result)) + state.push1(builder.ins().uextend(I32, bool_result)) } Operator::I8x16Bitmask | Operator::I16x8Bitmask @@ -2253,7 +2246,9 @@ fn get_heap_addr( }; debug_assert!(adjusted_offset > 0); // want to bounds check at least 1 byte let check_size = u32::try_from(adjusted_offset).unwrap_or(u32::MAX); - let base = builder.ins().heap_addr(addr_ty, heap, addr32, check_size); + let base = builder + .ins() + .heap_addr(addr_ty, heap, addr32, 0u32, check_size as u8); // Native load/store instructions take a signed `Offset32` immediate, so adjust the base // pointer if necessary. @@ -2359,7 +2354,7 @@ fn mem_op_size(opcode: ir::Opcode, ty: Type) -> u32 { fn translate_icmp(cc: IntCC, builder: &mut FunctionBuilder, state: &mut FuncTranslationState) { let (arg0, arg1) = state.pop2(); let val = builder.ins().icmp(cc, arg0, arg1); - state.push1(builder.ins().bint(I32, val)); + state.push1(builder.ins().uextend(I32, val)); } fn fold_atomic_mem_addr( @@ -2375,12 +2370,10 @@ fn fold_atomic_mem_addr( let a = builder .ins() .iadd_imm(linear_mem_addr, memarg.offset as i64); - let cflags = builder.ins().ifcmp_imm(a, 0x1_0000_0000i64); - builder.ins().trapif( - IntCC::UnsignedGreaterThanOrEqual, - cflags, - ir::TrapCode::HeapOutOfBounds, - ); + let r = builder + .ins() + .icmp_imm(IntCC::UnsignedGreaterThanOrEqual, a, 0x1_0000_0000i64); + builder.ins().trapnz(r, ir::TrapCode::HeapOutOfBounds); builder.ins().ireduce(I32, a) } else { linear_mem_addr @@ -2391,10 +2384,8 @@ fn fold_atomic_mem_addr( .band_imm(final_lma, i64::from(access_ty_bytes - 1)); let f = builder .ins() - .ifcmp_imm(final_lma_misalignment, i64::from(0)); - builder - .ins() - .trapif(IntCC::NotEqual, f, ir::TrapCode::HeapMisaligned); + .icmp_imm(IntCC::Equal, final_lma_misalignment, i64::from(0)); + builder.ins().trapz(f, ir::TrapCode::HeapMisaligned); final_lma } @@ -2415,12 +2406,10 @@ fn finalise_atomic_mem_addr( let a = builder .ins() .iadd_imm(linear_mem_addr, memarg.offset as i64); - let cflags = builder.ins().ifcmp_imm(a, 0x1_0000_0000i64); - builder.ins().trapif( - IntCC::UnsignedGreaterThanOrEqual, - cflags, - ir::TrapCode::HeapOutOfBounds, - ); + let r = builder + .ins() + .icmp_imm(IntCC::UnsignedGreaterThanOrEqual, a, 0x1_0000_0000i64); + builder.ins().trapnz(r, ir::TrapCode::HeapOutOfBounds); builder.ins().ireduce(I32, a) } else { linear_mem_addr @@ -2433,10 +2422,8 @@ fn finalise_atomic_mem_addr( .band_imm(final_lma, i64::from(access_ty_bytes - 1)); let f = builder .ins() - .ifcmp_imm(final_lma_misalignment, i64::from(0)); - builder - .ins() - .trapif(IntCC::NotEqual, f, ir::TrapCode::HeapMisaligned); + .icmp_imm(IntCC::Equal, final_lma_misalignment, i64::from(0)); + builder.ins().trapz(f, ir::TrapCode::HeapMisaligned); } // Compute the final effective address. @@ -2647,7 +2634,7 @@ fn translate_vector_icmp( fn translate_fcmp(cc: FloatCC, builder: &mut FunctionBuilder, state: &mut FuncTranslationState) { let (arg0, arg1) = state.pop2(); let val = builder.ins().fcmp(cc, arg0, arg1); - state.push1(builder.ins().bint(I32, val)); + state.push1(builder.ins().uextend(I32, val)); } fn translate_vector_fcmp( @@ -2913,7 +2900,11 @@ fn optionally_bitcast_vector( builder: &mut FunctionBuilder, ) -> Value { if builder.func.dfg.value_type(value) != needed_type { - builder.ins().raw_bitcast(needed_type, value) + builder.ins().bitcast( + needed_type, + MemFlags::new().with_endianness(ir::Endianness::Little), + value, + ) } else { value } @@ -2921,10 +2912,7 @@ fn optionally_bitcast_vector( #[inline(always)] fn is_non_canonical_v128(ty: ir::Type) -> bool { - matches!( - ty, - B8X16 | B16X8 | B32X4 | B64X2 | I64X2 | I32X4 | I16X8 | F32X4 | F64X2 - ) + matches!(ty, I64X2 | I32X4 | I16X8 | F32X4 | F64X2) } /// Cast to I8X16, any vector values in `values` that are of "non-canonical" type (meaning, not @@ -2948,7 +2936,11 @@ fn canonicalise_v128_values<'a>( // Otherwise we'll have to cast, and push the resulting `Value`s into `canonicalised`. for v in values { tmp_canonicalised.push(if is_non_canonical_v128(builder.func.dfg.value_type(*v)) { - builder.ins().raw_bitcast(I8X16, *v) + builder.ins().bitcast( + I8X16, + MemFlags::new().with_endianness(ir::Endianness::Little), + *v, + ) } else { *v }); diff --git a/lib/compiler-cranelift/src/translator/func_environ.rs b/lib/compiler-cranelift/src/translator/func_environ.rs index 0ca674269ca..68b3a5c1dc4 100644 --- a/lib/compiler-cranelift/src/translator/func_environ.rs +++ b/lib/compiler-cranelift/src/translator/func_environ.rs @@ -46,8 +46,6 @@ pub enum GlobalVariable { pub enum ReturnMode { /// Use normal return instructions as needed. NormalReturns, - /// Use a single fallthrough return at the end of the function. - FallthroughReturn, } /// Environment affecting the translation of a WebAssembly. @@ -381,7 +379,7 @@ pub trait FuncEnvironment: TargetEnvironment { value: ir::Value, ) -> WasmResult { let is_null = pos.ins().is_null(value); - Ok(pos.ins().bint(ir::types::I64, is_null)) + Ok(pos.ins().uextend(ir::types::I64, is_null)) } /// Translate a `ref.func` WebAssembly instruction. diff --git a/lib/compiler-cranelift/src/translator/func_translator.rs b/lib/compiler-cranelift/src/translator/func_translator.rs index d8a4db96a60..47972a45af7 100644 --- a/lib/compiler-cranelift/src/translator/func_translator.rs +++ b/lib/compiler-cranelift/src/translator/func_translator.rs @@ -243,7 +243,7 @@ fn parse_function_body( // If the exit block is unreachable, it may not have the correct arguments, so we would // generate a return instruction that doesn't match the signature. if state.reachable { - debug_assert!(builder.is_pristine()); + //debug_assert!(builder.is_pristine()); if !builder.is_unreachable() { match environ.return_mode() { ReturnMode::NormalReturns => { @@ -253,7 +253,6 @@ fn parse_function_body( bitcast_arguments(&mut state.stack, &return_types, builder); builder.ins().return_(&state.stack) } - ReturnMode::FallthroughReturn => builder.ins().fallthrough_return(&state.stack), }; } } diff --git a/lib/compiler-cranelift/src/translator/unwind.rs b/lib/compiler-cranelift/src/translator/unwind.rs index 1aff474ddce..4de700b2d86 100644 --- a/lib/compiler-cranelift/src/translator/unwind.rs +++ b/lib/compiler-cranelift/src/translator/unwind.rs @@ -43,6 +43,8 @@ pub(crate) fn compiled_function_unwind_info( context: &Context, ) -> Result { let unwind_info = context + .compiled_code() + .unwrap() .create_unwind_info(isa) .map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;