diff --git a/cranelift/codegen/meta/src/isa/x86.rs b/cranelift/codegen/meta/src/isa/x86.rs index eec6ac105f53..67d84ae762c4 100644 --- a/cranelift/codegen/meta/src/isa/x86.rs +++ b/cranelift/codegen/meta/src/isa/x86.rs @@ -17,19 +17,22 @@ fn define_settings(shared: &SettingGroup) -> SettingGroup { "has_sse3", "Has support for SSE3.", "SSE3: CPUID.01H:ECX.SSE3[bit 0]", - false, + // Needed for default `enable_simd` setting. + true, ); let has_ssse3 = settings.add_bool( "has_ssse3", "Has support for SSSE3.", "SSSE3: CPUID.01H:ECX.SSSE3[bit 9]", - false, + // Needed for default `enable_simd` setting. + true, ); let has_sse41 = settings.add_bool( "has_sse41", "Has support for SSE4.1.", "SSE4.1: CPUID.01H:ECX.SSE4_1[bit 19]", - false, + // Needed for default `enable_simd` setting. + true, ); let has_sse42 = settings.add_bool( "has_sse42", diff --git a/cranelift/codegen/src/isa/aarch64/inst/unwind/systemv.rs b/cranelift/codegen/src/isa/aarch64/inst/unwind/systemv.rs index ade376778912..12651427b66f 100644 --- a/cranelift/codegen/src/isa/aarch64/inst/unwind/systemv.rs +++ b/cranelift/codegen/src/isa/aarch64/inst/unwind/systemv.rs @@ -85,7 +85,8 @@ mod tests { fn test_simple_func() { let isa = lookup(triple!("aarch64")) .expect("expect aarch64 ISA") - .finish(Flags::new(builder())); + .finish(Flags::new(builder())) + .expect("Creating compiler backend"); let mut context = Context::for_function(create_function( CallConv::SystemV, @@ -127,7 +128,8 @@ mod tests { fn test_multi_return_func() { let isa = lookup(triple!("aarch64")) .expect("expect aarch64 ISA") - .finish(Flags::new(builder())); + .finish(Flags::new(builder())) + .expect("Creating compiler backend"); let mut context = Context::for_function(create_multi_return_function(CallConv::SystemV)); diff --git a/cranelift/codegen/src/isa/aarch64/mod.rs b/cranelift/codegen/src/isa/aarch64/mod.rs index 53159b0d0ae9..2a1a4a42f356 100644 --- a/cranelift/codegen/src/isa/aarch64/mod.rs +++ b/cranelift/codegen/src/isa/aarch64/mod.rs @@ -172,7 +172,7 @@ pub fn isa_builder(triple: Triple) -> IsaBuilder { constructor: |triple, shared_flags, builder| { let isa_flags = aarch64_settings::Flags::new(&shared_flags, builder); let backend = AArch64Backend::new_with_flags(triple, shared_flags, isa_flags); - Box::new(backend) + Ok(Box::new(backend)) }, } } diff --git a/cranelift/codegen/src/isa/mod.rs b/cranelift/codegen/src/isa/mod.rs index 8b69315f2478..821b9627ea79 100644 --- a/cranelift/codegen/src/isa/mod.rs +++ b/cranelift/codegen/src/isa/mod.rs @@ -139,7 +139,8 @@ impl fmt::Display for LookupError { pub struct Builder { triple: Triple, setup: settings::Builder, - constructor: fn(Triple, settings::Flags, settings::Builder) -> Box, + constructor: + fn(Triple, settings::Flags, settings::Builder) -> CodegenResult>, } impl Builder { @@ -153,9 +154,13 @@ impl Builder { self.setup.iter() } - /// Combine the ISA-specific settings with the provided ISA-independent settings and allocate a - /// fully configured `TargetIsa` trait object. - pub fn finish(self, shared_flags: settings::Flags) -> Box { + /// Combine the ISA-specific settings with the provided + /// ISA-independent settings and allocate a fully configured + /// `TargetIsa` trait object. May return an error if some of the + /// flags are inconsistent or incompatible: for example, some + /// platform-independent features, like general SIMD support, may + /// need certain ISA extensions to be enabled. + pub fn finish(self, shared_flags: settings::Flags) -> CodegenResult> { (self.constructor)(self.triple, shared_flags, self.setup) } } diff --git a/cranelift/codegen/src/isa/s390x/inst/unwind/systemv.rs b/cranelift/codegen/src/isa/s390x/inst/unwind/systemv.rs index f5ff00cbd11f..a970c59c69d2 100644 --- a/cranelift/codegen/src/isa/s390x/inst/unwind/systemv.rs +++ b/cranelift/codegen/src/isa/s390x/inst/unwind/systemv.rs @@ -100,7 +100,8 @@ mod tests { fn test_simple_func() { let isa = lookup(triple!("s390x")) .expect("expect s390x ISA") - .finish(Flags::new(builder())); + .finish(Flags::new(builder())) + .expect("Creating compiler backend"); let mut context = Context::for_function(create_function( CallConv::SystemV, @@ -142,7 +143,8 @@ mod tests { fn test_multi_return_func() { let isa = lookup(triple!("s390x")) .expect("expect s390x ISA") - .finish(Flags::new(builder())); + .finish(Flags::new(builder())) + .expect("Creating compiler backend"); let mut context = Context::for_function(create_multi_return_function( CallConv::SystemV, diff --git a/cranelift/codegen/src/isa/s390x/mod.rs b/cranelift/codegen/src/isa/s390x/mod.rs index 6093cb1d9ed9..e9325c634189 100644 --- a/cranelift/codegen/src/isa/s390x/mod.rs +++ b/cranelift/codegen/src/isa/s390x/mod.rs @@ -179,7 +179,7 @@ pub fn isa_builder(triple: Triple) -> IsaBuilder { constructor: |triple, shared_flags, builder| { let isa_flags = s390x_settings::Flags::new(&shared_flags, builder); let backend = S390xBackend::new_with_flags(triple, shared_flags, isa_flags); - Box::new(backend) + Ok(Box::new(backend)) }, } } diff --git a/cranelift/codegen/src/isa/x64/inst/unwind/systemv.rs b/cranelift/codegen/src/isa/x64/inst/unwind/systemv.rs index 7119d5b26064..68575a18edc7 100644 --- a/cranelift/codegen/src/isa/x64/inst/unwind/systemv.rs +++ b/cranelift/codegen/src/isa/x64/inst/unwind/systemv.rs @@ -112,7 +112,8 @@ mod tests { fn test_simple_func() { let isa = lookup(triple!("x86_64")) .expect("expect x86 ISA") - .finish(Flags::new(builder())); + .finish(Flags::new(builder())) + .expect("expect backend creation to succeed"); let mut context = Context::for_function(create_function( CallConv::SystemV, @@ -154,7 +155,8 @@ mod tests { fn test_multi_return_func() { let isa = lookup(triple!("x86_64")) .expect("expect x86 ISA") - .finish(Flags::new(builder())); + .finish(Flags::new(builder())) + .expect("expect backend creation to succeed"); let mut context = Context::for_function(create_multi_return_function(CallConv::SystemV)); diff --git a/cranelift/codegen/src/isa/x64/mod.rs b/cranelift/codegen/src/isa/x64/mod.rs index 6063c03ecaec..e5d6bf952478 100644 --- a/cranelift/codegen/src/isa/x64/mod.rs +++ b/cranelift/codegen/src/isa/x64/mod.rs @@ -11,7 +11,7 @@ use crate::isa::Builder as IsaBuilder; use crate::machinst::{ compile, MachCompileResult, MachTextSectionBuilder, TextSectionBuilder, VCode, }; -use crate::result::CodegenResult; +use crate::result::{CodegenError, CodegenResult}; use crate::settings::{self as shared_settings, Flags}; use alloc::{boxed::Box, vec::Vec}; use core::fmt; @@ -174,10 +174,21 @@ fn isa_constructor( triple: Triple, shared_flags: Flags, builder: shared_settings::Builder, -) -> Box { +) -> CodegenResult> { let isa_flags = x64_settings::Flags::new(&shared_flags, builder); + + // Check for compatibility between flags and ISA level + // requested. In particular, SIMD support requires SSE4.1. + if shared_flags.enable_simd() { + if !isa_flags.has_sse3() || !isa_flags.has_ssse3() || !isa_flags.has_sse41() { + return Err(CodegenError::Unsupported( + "SIMD support requires SSE3, SSSE3, and SSE4.1 on x86_64.".into(), + )); + } + } + let backend = X64Backend::new_with_flags(triple, shared_flags, isa_flags); - Box::new(backend) + Ok(Box::new(backend)) } #[cfg(test)] @@ -332,4 +343,20 @@ mod test { assert_eq!(code, &golden[..]); } + + // Check that feature tests for SIMD work correctly. + #[test] + fn simd_required_features() { + let mut shared_flags_builder = settings::builder(); + shared_flags_builder.set("enable_simd", "true").unwrap(); + let shared_flags = settings::Flags::new(shared_flags_builder); + let mut isa_builder = crate::isa::lookup_by_name("x86_64").unwrap(); + isa_builder.set("has_sse3", "false").unwrap(); + isa_builder.set("has_ssse3", "false").unwrap(); + isa_builder.set("has_sse41", "false").unwrap(); + assert!(matches!( + isa_builder.finish(shared_flags), + Err(CodegenError::Unsupported(_)), + )); + } } diff --git a/cranelift/filetests/filetests/isa/x64/simd-lane-access-compile.clif b/cranelift/filetests/filetests/isa/x64/simd-lane-access-compile.clif index 64254c4e8d3b..e2cdd4dbe194 100644 --- a/cranelift/filetests/filetests/isa/x64/simd-lane-access-compile.clif +++ b/cranelift/filetests/filetests/isa/x64/simd-lane-access-compile.clif @@ -1,6 +1,6 @@ test compile precise-output set enable_simd -target x86_64 has_ssse3 has_sse41 +target x86_64 has_sse3 has_ssse3 has_sse41 ;; shuffle diff --git a/cranelift/filetests/filetests/runtests/simd-bitselect.clif b/cranelift/filetests/filetests/runtests/simd-bitselect.clif index 4ff5cd2e31b1..3d67ff290504 100644 --- a/cranelift/filetests/filetests/runtests/simd-bitselect.clif +++ b/cranelift/filetests/filetests/runtests/simd-bitselect.clif @@ -1,7 +1,7 @@ test run set enable_simd target aarch64 -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %bitselect_i32x4(i32x4, i32x4, i32x4) -> i32x4 { block0(v0: i32x4, v1: i32x4, v2: i32x4): diff --git a/cranelift/filetests/filetests/runtests/simd-comparison.clif b/cranelift/filetests/filetests/runtests/simd-comparison.clif index c704e5a3b527..cd8341127d3f 100644 --- a/cranelift/filetests/filetests/runtests/simd-comparison.clif +++ b/cranelift/filetests/filetests/runtests/simd-comparison.clif @@ -2,7 +2,7 @@ test run target aarch64 ; target s390x TODO: Not yet implemented on s390x set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %icmp_eq_i8x16() -> b8 { block0: diff --git a/cranelift/filetests/filetests/runtests/simd-conversion.clif b/cranelift/filetests/filetests/runtests/simd-conversion.clif index b950a9a2cd89..2903a34e1680 100644 --- a/cranelift/filetests/filetests/runtests/simd-conversion.clif +++ b/cranelift/filetests/filetests/runtests/simd-conversion.clif @@ -2,7 +2,7 @@ test run target aarch64 ; target s390x TODO: Not yet implemented on s390x set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %fcvt_from_sint(i32x4) -> f32x4 { block0(v0: i32x4): diff --git a/cranelift/filetests/filetests/runtests/simd-extractlane.clif b/cranelift/filetests/filetests/runtests/simd-extractlane.clif index 215d1c696b9d..6aba1c67ba61 100644 --- a/cranelift/filetests/filetests/runtests/simd-extractlane.clif +++ b/cranelift/filetests/filetests/runtests/simd-extractlane.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %extractlane_4(i8x16) -> i8 { block0(v0: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-iabs.clif b/cranelift/filetests/filetests/runtests/simd-iabs.clif index ee1db6762c32..95b53844c624 100644 --- a/cranelift/filetests/filetests/runtests/simd-iabs.clif +++ b/cranelift/filetests/filetests/runtests/simd-iabs.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %iabs_i8x16(i8x16) -> i8x16 { block0(v0: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-insertlane.clif b/cranelift/filetests/filetests/runtests/simd-insertlane.clif index a2642129a972..f3624f1bf19f 100644 --- a/cranelift/filetests/filetests/runtests/simd-insertlane.clif +++ b/cranelift/filetests/filetests/runtests/simd-insertlane.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %insertlane_15(i8x16, i8) -> i8x16 { block0(v0: i8x16, v1: i8): diff --git a/cranelift/filetests/filetests/runtests/simd-lane-access.clif b/cranelift/filetests/filetests/runtests/simd-lane-access.clif index 7510cd886575..0818bdd85b89 100644 --- a/cranelift/filetests/filetests/runtests/simd-lane-access.clif +++ b/cranelift/filetests/filetests/runtests/simd-lane-access.clif @@ -2,7 +2,7 @@ test run target aarch64 ; target s390x TODO: Not yet implemented on s390x set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 ;; shuffle diff --git a/cranelift/filetests/filetests/runtests/simd-logical.clif b/cranelift/filetests/filetests/runtests/simd-logical.clif index 9cdf8fdb69f0..081d4892de81 100644 --- a/cranelift/filetests/filetests/runtests/simd-logical.clif +++ b/cranelift/filetests/filetests/runtests/simd-logical.clif @@ -2,7 +2,7 @@ test run target aarch64 ; target s390x TODO: Not yet implemented on s390x set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %bnot() -> b32 { block0: diff --git a/cranelift/filetests/filetests/runtests/simd-saddsat.clif b/cranelift/filetests/filetests/runtests/simd-saddsat.clif index 473dcef83ec1..515cc83a4a2e 100644 --- a/cranelift/filetests/filetests/runtests/simd-saddsat.clif +++ b/cranelift/filetests/filetests/runtests/simd-saddsat.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %saddsat_i8x16(i8x16, i8x16) -> i8x16 { block0(v0: i8x16, v1: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-shuffle.clif b/cranelift/filetests/filetests/runtests/simd-shuffle.clif index 0f684314e4ee..b7850a578165 100644 --- a/cranelift/filetests/filetests/runtests/simd-shuffle.clif +++ b/cranelift/filetests/filetests/runtests/simd-shuffle.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %shuffle_i8x16(i8x16, i8x16) -> i8x16 { block0(v0: i8x16, v1: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-snarrow.clif b/cranelift/filetests/filetests/runtests/simd-snarrow.clif index 18d667f7434e..082e86c179f2 100644 --- a/cranelift/filetests/filetests/runtests/simd-snarrow.clif +++ b/cranelift/filetests/filetests/runtests/simd-snarrow.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %snarrow_i16x8(i16x8, i16x8) -> i8x16 { block0(v0: i16x8, v1: i16x8): diff --git a/cranelift/filetests/filetests/runtests/simd-splat.clif b/cranelift/filetests/filetests/runtests/simd-splat.clif index 0da9d65c207b..19892cb29b7c 100644 --- a/cranelift/filetests/filetests/runtests/simd-splat.clif +++ b/cranelift/filetests/filetests/runtests/simd-splat.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %splat_i8x16(i8) -> i8x16 { block0(v0: i8): diff --git a/cranelift/filetests/filetests/runtests/simd-sqmulroundsat.clif b/cranelift/filetests/filetests/runtests/simd-sqmulroundsat.clif index 1faa3592ad3e..723696d25a8f 100644 --- a/cranelift/filetests/filetests/runtests/simd-sqmulroundsat.clif +++ b/cranelift/filetests/filetests/runtests/simd-sqmulroundsat.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %sqmulrs_i16x8(i16x8, i16x8) -> i16x8 { block0(v0: i16x8, v1: i16x8): diff --git a/cranelift/filetests/filetests/runtests/simd-ssubsat.clif b/cranelift/filetests/filetests/runtests/simd-ssubsat.clif index 0226b5a3976b..8841f2275f66 100644 --- a/cranelift/filetests/filetests/runtests/simd-ssubsat.clif +++ b/cranelift/filetests/filetests/runtests/simd-ssubsat.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %ssubsat_i8x16(i8x16, i8x16) -> i8x16 { block0(v0: i8x16, v1: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-swidenhigh.clif b/cranelift/filetests/filetests/runtests/simd-swidenhigh.clif index 47d4229c61d4..1d9c15581b76 100644 --- a/cranelift/filetests/filetests/runtests/simd-swidenhigh.clif +++ b/cranelift/filetests/filetests/runtests/simd-swidenhigh.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %swidenhigh_i8x16(i8x16) -> i16x8 { block0(v0: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-swidenlow.clif b/cranelift/filetests/filetests/runtests/simd-swidenlow.clif index 997734702bef..bee577072d13 100644 --- a/cranelift/filetests/filetests/runtests/simd-swidenlow.clif +++ b/cranelift/filetests/filetests/runtests/simd-swidenlow.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %swidenlow_i8x16(i8x16) -> i16x8 { block0(v0: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-swizzle.clif b/cranelift/filetests/filetests/runtests/simd-swizzle.clif index 6375e0b0e8e7..390780879c77 100644 --- a/cranelift/filetests/filetests/runtests/simd-swizzle.clif +++ b/cranelift/filetests/filetests/runtests/simd-swizzle.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %swizzle_i8x16(i8x16, i8x16) -> i8x16 { block0(v0: i8x16, v1: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-uaddsat.clif b/cranelift/filetests/filetests/runtests/simd-uaddsat.clif index b904d9f8778d..d0af940abdee 100644 --- a/cranelift/filetests/filetests/runtests/simd-uaddsat.clif +++ b/cranelift/filetests/filetests/runtests/simd-uaddsat.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %uaddsat_i8x16(i8x16, i8x16) -> i8x16 { block0(v0: i8x16, v1: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-unarrow.clif b/cranelift/filetests/filetests/runtests/simd-unarrow.clif index 0725afd81120..e535df5e0778 100644 --- a/cranelift/filetests/filetests/runtests/simd-unarrow.clif +++ b/cranelift/filetests/filetests/runtests/simd-unarrow.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %unarrow_i16x8(i16x8, i16x8) -> i8x16 { block0(v0: i16x8, v1: i16x8): diff --git a/cranelift/filetests/filetests/runtests/simd-usubsat.clif b/cranelift/filetests/filetests/runtests/simd-usubsat.clif index d78190e0b1cd..ca8747c3e900 100644 --- a/cranelift/filetests/filetests/runtests/simd-usubsat.clif +++ b/cranelift/filetests/filetests/runtests/simd-usubsat.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %usubsat_i8x16(i8x16, i8x16) -> i8x16 { block0(v0: i8x16, v1: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-uwidenhigh.clif b/cranelift/filetests/filetests/runtests/simd-uwidenhigh.clif index d9e4b2b0e00f..959b6acd7336 100644 --- a/cranelift/filetests/filetests/runtests/simd-uwidenhigh.clif +++ b/cranelift/filetests/filetests/runtests/simd-uwidenhigh.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %uwidenhigh_i8x16(i8x16) -> i16x8 { block0(v0: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-uwidenlow.clif b/cranelift/filetests/filetests/runtests/simd-uwidenlow.clif index 6acf4e1a2b2c..fab64406b946 100644 --- a/cranelift/filetests/filetests/runtests/simd-uwidenlow.clif +++ b/cranelift/filetests/filetests/runtests/simd-uwidenlow.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %uwidenlow_i8x16(i8x16) -> i16x8 { block0(v0: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-vconst.clif b/cranelift/filetests/filetests/runtests/simd-vconst.clif index f1a98e7ea177..b2398b6ec01a 100644 --- a/cranelift/filetests/filetests/runtests/simd-vconst.clif +++ b/cranelift/filetests/filetests/runtests/simd-vconst.clif @@ -2,7 +2,7 @@ test run ; target s390x TODO: Not yet implemented on s390x target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %vconst_zeroes() -> b1 { diff --git a/cranelift/filetests/filetests/runtests/simd-vhighbits.clif b/cranelift/filetests/filetests/runtests/simd-vhighbits.clif index 2a9c5d1a75b8..e4ed0e42cf7e 100644 --- a/cranelift/filetests/filetests/runtests/simd-vhighbits.clif +++ b/cranelift/filetests/filetests/runtests/simd-vhighbits.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %vhighbits_i8x16(i8x16) -> i16 { block0(v0: i8x16): diff --git a/cranelift/filetests/filetests/runtests/simd-vselect.clif b/cranelift/filetests/filetests/runtests/simd-vselect.clif index 84a2479ca580..53ef6f6353d7 100644 --- a/cranelift/filetests/filetests/runtests/simd-vselect.clif +++ b/cranelift/filetests/filetests/runtests/simd-vselect.clif @@ -3,7 +3,7 @@ test run ; target s390x TODO: Not yet implemented on s390x target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %vselect_i8x16() -> i8x16 { block0: diff --git a/cranelift/filetests/filetests/runtests/simd-wideningpairwisedotproducts.clif b/cranelift/filetests/filetests/runtests/simd-wideningpairwisedotproducts.clif index 56987ef79d08..dcfaba0294a9 100644 --- a/cranelift/filetests/filetests/runtests/simd-wideningpairwisedotproducts.clif +++ b/cranelift/filetests/filetests/runtests/simd-wideningpairwisedotproducts.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %wpdps(i16x8, i16x8) -> i32x4 { block0(v0: i16x8, v1: i16x8): diff --git a/cranelift/filetests/filetests/runtests/smulhi.clif b/cranelift/filetests/filetests/runtests/smulhi.clif index ec855002a4eb..306ee70913f1 100644 --- a/cranelift/filetests/filetests/runtests/smulhi.clif +++ b/cranelift/filetests/filetests/runtests/smulhi.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %smulhi_i16(i16, i16) -> i16 { block0(v0: i16, v1: i16): diff --git a/cranelift/filetests/filetests/runtests/umulhi.clif b/cranelift/filetests/filetests/runtests/umulhi.clif index 272e40ca82d8..67bbf616e044 100644 --- a/cranelift/filetests/filetests/runtests/umulhi.clif +++ b/cranelift/filetests/filetests/runtests/umulhi.clif @@ -2,7 +2,7 @@ test interpret test run target aarch64 set enable_simd -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 target s390x function %umulhi_i16(i16, i16) -> i16 { diff --git a/cranelift/filetests/filetests/verifier/scalar-to-vector.clif b/cranelift/filetests/filetests/verifier/scalar-to-vector.clif index a955e55a68f2..de5274c98dde 100644 --- a/cranelift/filetests/filetests/verifier/scalar-to-vector.clif +++ b/cranelift/filetests/filetests/verifier/scalar-to-vector.clif @@ -1,7 +1,7 @@ test verifier set enable_simd=true target aarch64 -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %scalar_to_vector() { block0: diff --git a/cranelift/filetests/filetests/verifier/simd-lane-index.clif b/cranelift/filetests/filetests/verifier/simd-lane-index.clif index 99e04871f4e4..38ad19517a32 100644 --- a/cranelift/filetests/filetests/verifier/simd-lane-index.clif +++ b/cranelift/filetests/filetests/verifier/simd-lane-index.clif @@ -1,7 +1,7 @@ test verifier set enable_simd target aarch64 -target x86_64 +target x86_64 has_sse3 has_ssse3 has_sse41 function %insertlane_i32x4() { block0: diff --git a/cranelift/filetests/src/function_runner.rs b/cranelift/filetests/src/function_runner.rs index 116dd7377448..59b38a9aeb51 100644 --- a/cranelift/filetests/src/function_runner.rs +++ b/cranelift/filetests/src/function_runner.rs @@ -1,4 +1,5 @@ //! Provides functionality for compiling and running CLIF IR for `run` tests. +use anyhow::Result; use core::mem; use cranelift_codegen::data_value::DataValue; use cranelift_codegen::ir::{condcodes::IntCC, Function, InstBuilder, Signature}; @@ -27,7 +28,7 @@ use thiserror::Error; /// /// let code = "test run \n function %add(i32, i32) -> i32 { block0(v0:i32, v1:i32): v2 = iadd v0, v1 return v2 }".into(); /// let func = parse_functions(code).unwrap().into_iter().nth(0).unwrap(); -/// let mut compiler = SingleFunctionCompiler::with_default_host_isa(); +/// let mut compiler = SingleFunctionCompiler::with_default_host_isa().unwrap(); /// let compiled_func = compiler.compile(func).unwrap(); /// println!("Address of compiled function: {:p}", compiled_func.as_ptr()); /// ``` @@ -46,16 +47,16 @@ impl SingleFunctionCompiler { } /// Build a [SingleFunctionCompiler] using the host machine's ISA and the passed flags. - pub fn with_host_isa(flags: settings::Flags) -> Self { + pub fn with_host_isa(flags: settings::Flags) -> Result { let builder = builder_with_options(true).expect("Unable to build a TargetIsa for the current host"); - let isa = builder.finish(flags); - Self::new(isa) + let isa = builder.finish(flags)?; + Ok(Self::new(isa)) } /// Build a [SingleFunctionCompiler] using the host machine's ISA and the default flags for this /// ISA. - pub fn with_default_host_isa() -> Self { + pub fn with_default_host_isa() -> Result { let flags = settings::Flags::new(settings::builder()); Self::with_host_isa(flags) } @@ -135,7 +136,7 @@ impl Trampoline { /// /// let code = "test run \n function %add(i32, i32) -> i32 { block0(v0:i32, v1:i32): v2 = iadd v0, v1 return v2 }".into(); /// let func = parse_functions(code).unwrap().into_iter().nth(0).unwrap(); -/// let mut compiler = SingleFunctionCompiler::with_default_host_isa(); +/// let mut compiler = SingleFunctionCompiler::with_default_host_isa().unwrap(); /// let compiled_func = compiler.compile(func).unwrap(); /// /// let returned = compiled_func.call(&vec![DataValue::I32(2), DataValue::I32(40)]); @@ -377,7 +378,7 @@ mod test { let function = test_file.functions[0].0.clone(); // execute function - let mut compiler = SingleFunctionCompiler::with_default_host_isa(); + let mut compiler = SingleFunctionCompiler::with_default_host_isa().unwrap(); let compiled_function = compiler.compile(function).unwrap(); let returned = compiled_function.call(&[]); assert_eq!(returned, vec![DataValue::B(true)]) @@ -395,7 +396,7 @@ mod test { }", ); - let compiler = SingleFunctionCompiler::with_default_host_isa(); + let compiler = SingleFunctionCompiler::with_default_host_isa().unwrap(); let trampoline = make_trampoline(&function.signature, compiler.isa.as_ref()); assert!(format!("{}", trampoline).ends_with( "sig0 = (f32, i8, i64x2, b1) -> f32x4, b64 fast diff --git a/cranelift/filetests/src/test_run.rs b/cranelift/filetests/src/test_run.rs index 86b346e21be0..25cc49a0620d 100644 --- a/cranelift/filetests/src/test_run.rs +++ b/cranelift/filetests/src/test_run.rs @@ -51,7 +51,7 @@ impl SubTest for TestRun { let test_env = RuntestEnvironment::parse(&context.details.comments[..])?; - let mut compiler = SingleFunctionCompiler::with_host_isa(context.flags.clone()); + let mut compiler = SingleFunctionCompiler::with_host_isa(context.flags.clone())?; for comment in context.details.comments.iter() { if let Some(command) = parse_run_command(comment.text, &func.signature)? { trace!("Parsed run command: {}", command); diff --git a/cranelift/frontend/src/frontend.rs b/cranelift/frontend/src/frontend.rs index ee16400e1786..da3d60e8f85b 100644 --- a/cranelift/frontend/src/frontend.rs +++ b/cranelift/frontend/src/frontend.rs @@ -1355,7 +1355,8 @@ block0: let target = isa::lookup(triple) .ok() .map(|b| b.finish(shared_flags)) - .expect("This test requires x86_64 support."); + .expect("This test requires x86_64 support.") + .expect("Should be able to create backend with default flags"); let mut sig = Signature::new(target.default_call_conv()); sig.returns.push(AbiParam::new(I32)); @@ -1567,7 +1568,8 @@ block0: let target = isa::lookup(triple) .ok() .map(|b| b.finish(shared_flags)) - .expect("This test requires x86_64 support."); + .expect("This test requires x86_64 support.") + .expect("Should be able to create backend with default flags"); let mut sig = Signature::new(target.default_call_conv()); sig.returns.push(AbiParam::new(B1)); diff --git a/cranelift/jit/examples/jit-minimal.rs b/cranelift/jit/examples/jit-minimal.rs index 37ba2e228bb0..dc24df7c86f9 100644 --- a/cranelift/jit/examples/jit-minimal.rs +++ b/cranelift/jit/examples/jit-minimal.rs @@ -12,7 +12,9 @@ fn main() { let isa_builder = cranelift_native::builder().unwrap_or_else(|msg| { panic!("host machine is not supported: {}", msg); }); - let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let isa = isa_builder + .finish(settings::Flags::new(flag_builder)) + .unwrap(); let mut module = JITModule::new(JITBuilder::with_isa(isa, default_libcall_names())); let mut ctx = module.make_context(); diff --git a/cranelift/jit/src/backend.rs b/cranelift/jit/src/backend.rs index a1f63e694de2..82a38ec0d161 100644 --- a/cranelift/jit/src/backend.rs +++ b/cranelift/jit/src/backend.rs @@ -42,7 +42,9 @@ impl JITBuilder { /// enum to symbols. LibCalls are inserted in the IR as part of the legalization for certain /// floating point instructions, and for stack probes. If you don't know what to use for this /// argument, use `cranelift_module::default_libcall_names()`. - pub fn new(libcall_names: Box String + Send + Sync>) -> Self { + pub fn new( + libcall_names: Box String + Send + Sync>, + ) -> ModuleResult { let mut flag_builder = settings::builder(); // On at least AArch64, "colocated" calls use shorter-range relocations, // which might not reach all definitions; we can't handle that here, so @@ -52,8 +54,8 @@ impl JITBuilder { let isa_builder = cranelift_native::builder().unwrap_or_else(|msg| { panic!("host machine is not supported: {}", msg); }); - let isa = isa_builder.finish(settings::Flags::new(flag_builder)); - Self::with_isa(isa, libcall_names) + let isa = isa_builder.finish(settings::Flags::new(flag_builder))?; + Ok(Self::with_isa(isa, libcall_names)) } /// Create a new `JITBuilder` with an arbitrary target. This is mainly diff --git a/cranelift/jit/tests/basic.rs b/cranelift/jit/tests/basic.rs index a1a038f6fe4b..dc95a00e5018 100644 --- a/cranelift/jit/tests/basic.rs +++ b/cranelift/jit/tests/basic.rs @@ -16,7 +16,9 @@ fn error_on_incompatible_sig_in_declare_function() { let isa_builder = cranelift_native::builder().unwrap_or_else(|msg| { panic!("host machine is not supported: {}", msg); }); - let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let isa = isa_builder + .finish(settings::Flags::new(flag_builder)) + .unwrap(); let mut module = JITModule::new(JITBuilder::with_isa(isa, default_libcall_names())); let mut sig = Signature { @@ -70,7 +72,9 @@ fn panic_on_define_after_finalize() { let isa_builder = cranelift_native::builder().unwrap_or_else(|msg| { panic!("host machine is not supported: {}", msg); }); - let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let isa = isa_builder + .finish(settings::Flags::new(flag_builder)) + .unwrap(); let mut module = JITModule::new(JITBuilder::with_isa(isa, default_libcall_names())); define_simple_function(&mut module); @@ -159,7 +163,9 @@ fn libcall_function() { let isa_builder = cranelift_native::builder().unwrap_or_else(|msg| { panic!("host machine is not supported: {}", msg); }); - let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let isa = isa_builder + .finish(settings::Flags::new(flag_builder)) + .unwrap(); let mut module = JITModule::new(JITBuilder::with_isa(isa, default_libcall_names())); let sig = Signature { diff --git a/cranelift/native/src/lib.rs b/cranelift/native/src/lib.rs index 157a4f1e62eb..30c7a346e517 100644 --- a/cranelift/native/src/lib.rs +++ b/cranelift/native/src/lib.rs @@ -156,7 +156,9 @@ mod tests { fn test() { if let Ok(isa_builder) = builder() { let flag_builder = settings::builder(); - let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let isa = isa_builder + .finish(settings::Flags::new(flag_builder)) + .unwrap(); if cfg!(all(target_os = "macos", target_arch = "aarch64")) { assert_eq!(isa.default_call_conv(), CallConv::AppleAarch64); diff --git a/cranelift/object/tests/basic.rs b/cranelift/object/tests/basic.rs index 8a3764f9b8a5..508947b2e53e 100644 --- a/cranelift/object/tests/basic.rs +++ b/cranelift/object/tests/basic.rs @@ -11,7 +11,9 @@ use cranelift_object::*; fn error_on_incompatible_sig_in_declare_function() { let flag_builder = settings::builder(); let isa_builder = cranelift_codegen::isa::lookup_by_name("x86_64-unknown-linux-gnu").unwrap(); - let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let isa = isa_builder + .finish(settings::Flags::new(flag_builder)) + .unwrap(); let mut module = ObjectModule::new(ObjectBuilder::new(isa, "foo", default_libcall_names()).unwrap()); let mut sig = Signature { @@ -60,7 +62,9 @@ fn define_simple_function(module: &mut ObjectModule) -> FuncId { fn panic_on_define_after_finalize() { let flag_builder = settings::builder(); let isa_builder = cranelift_codegen::isa::lookup_by_name("x86_64-unknown-linux-gnu").unwrap(); - let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let isa = isa_builder + .finish(settings::Flags::new(flag_builder)) + .unwrap(); let mut module = ObjectModule::new(ObjectBuilder::new(isa, "foo", default_libcall_names()).unwrap()); @@ -145,7 +149,9 @@ fn switch_error() { fn libcall_function() { let flag_builder = settings::builder(); let isa_builder = cranelift_codegen::isa::lookup_by_name("x86_64-unknown-linux-gnu").unwrap(); - let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let isa = isa_builder + .finish(settings::Flags::new(flag_builder)) + .unwrap(); let mut module = ObjectModule::new(ObjectBuilder::new(isa, "foo", default_libcall_names()).unwrap()); @@ -199,7 +205,9 @@ fn libcall_function() { fn reject_nul_byte_symbol_for_func() { let flag_builder = settings::builder(); let isa_builder = cranelift_codegen::isa::lookup_by_name("x86_64-unknown-linux-gnu").unwrap(); - let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let isa = isa_builder + .finish(settings::Flags::new(flag_builder)) + .unwrap(); let mut module = ObjectModule::new(ObjectBuilder::new(isa, "foo", default_libcall_names()).unwrap()); @@ -221,7 +229,9 @@ fn reject_nul_byte_symbol_for_func() { fn reject_nul_byte_symbol_for_data() { let flag_builder = settings::builder(); let isa_builder = cranelift_codegen::isa::lookup_by_name("x86_64-unknown-linux-gnu").unwrap(); - let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let isa = isa_builder + .finish(settings::Flags::new(flag_builder)) + .unwrap(); let mut module = ObjectModule::new(ObjectBuilder::new(isa, "foo", default_libcall_names()).unwrap()); diff --git a/cranelift/reader/src/parser.rs b/cranelift/reader/src/parser.rs index 5850c2f9747b..92eeda39c167 100644 --- a/cranelift/reader/src/parser.rs +++ b/cranelift/reader/src/parser.rs @@ -1053,7 +1053,15 @@ impl<'a> Parser<'a> { specified_target = true; // Construct a trait object with the aggregate settings. - targets.push(isa_builder.finish(settings::Flags::new(flag_builder.clone()))); + targets.push( + isa_builder + .finish(settings::Flags::new(flag_builder.clone())) + .map_err(|e| ParseError { + location: loc, + message: format!("invalid ISA flags for '{}': {:?}", targ, e), + is_warning: false, + })?, + ); } if !specified_target { @@ -1122,7 +1130,18 @@ impl<'a> Parser<'a> { isaspec::parse_options(words, &mut isa_builder, self.loc)?; // Construct a trait object with the aggregate settings. - targets.push(isa_builder.finish(settings::Flags::new(flag_builder.clone()))); + targets.push( + isa_builder + .finish(settings::Flags::new(flag_builder.clone())) + .map_err(|e| ParseError { + location: loc, + message: format!( + "invalid ISA flags for '{}': {:?}", + target_name, e + ), + is_warning: false, + })?, + ); } _ => break, } diff --git a/cranelift/src/run.rs b/cranelift/src/run.rs index 2cfd0c9d4dea..f1249c3c9f59 100644 --- a/cranelift/src/run.rs +++ b/cranelift/src/run.rs @@ -110,7 +110,7 @@ fn create_target_isa(isa_spec: &IsaSpec) -> Result> { if let IsaSpec::None(flags) = isa_spec { // build an ISA for the current machine let builder = host_isa_builder().map_err(|s| anyhow::anyhow!("{}", s))?; - Ok(builder.finish(flags.clone())) + Ok(builder.finish(flags.clone())?) } else { anyhow::bail!( "A target ISA was specified in the file but should not have been--only \ diff --git a/cranelift/src/utils.rs b/cranelift/src/utils.rs index e02f675cc769..965b72cfdd49 100644 --- a/cranelift/src/utils.rs +++ b/cranelift/src/utils.rs @@ -99,7 +99,7 @@ pub fn parse_sets_and_triple( .map_err(ParseError::from)?; Ok(OwnedFlagsOrIsa::Isa( - isa_builder.finish(settings::Flags::new(flag_builder)), + isa_builder.finish(settings::Flags::new(flag_builder))?, )) } else { if !unknown_settings.is_empty() { diff --git a/crates/cranelift/src/builder.rs b/crates/cranelift/src/builder.rs index 905b3814bd41..9ccc6f64ca0f 100644 --- a/crates/cranelift/src/builder.rs +++ b/crates/cranelift/src/builder.rs @@ -101,12 +101,15 @@ impl CompilerBuilder for Builder { Ok(()) } - fn build(&self) -> Box { + fn build(&self) -> Result> { let isa = self .isa_flags .clone() - .finish(settings::Flags::new(self.flags.clone())); - Box::new(crate::compiler::Compiler::new(isa, self.linkopts.clone())) + .finish(settings::Flags::new(self.flags.clone()))?; + Ok(Box::new(crate::compiler::Compiler::new( + isa, + self.linkopts.clone(), + ))) } fn settings(&self) -> Vec { diff --git a/crates/environ/src/compilation.rs b/crates/environ/src/compilation.rs index fa909fc0961d..d091024e6615 100644 --- a/crates/environ/src/compilation.rs +++ b/crates/environ/src/compilation.rs @@ -104,7 +104,7 @@ pub trait CompilerBuilder: Send + Sync + fmt::Debug { fn settings(&self) -> Vec; /// Builds a new [`Compiler`] object from this configuration. - fn build(&self) -> Box; + fn build(&self) -> Result>; } /// Description of compiler settings returned by [`CompilerBuilder::settings`]. diff --git a/crates/wasmtime/src/engine.rs b/crates/wasmtime/src/engine.rs index 48420ff492fe..835923d9dacc 100644 --- a/crates/wasmtime/src/engine.rs +++ b/crates/wasmtime/src/engine.rs @@ -64,7 +64,7 @@ impl Engine { Ok(Engine { inner: Arc::new(EngineInner { #[cfg(compiler)] - compiler: config.compiler.build(), + compiler: config.compiler.build()?, config, allocator, signatures: registry, diff --git a/fuzz/fuzz_targets/cranelift-fuzzgen.rs b/fuzz/fuzz_targets/cranelift-fuzzgen.rs index 234feb8ea2c1..36b5cd2695e2 100644 --- a/fuzz/fuzz_targets/cranelift-fuzzgen.rs +++ b/fuzz/fuzz_targets/cranelift-fuzzgen.rs @@ -60,7 +60,7 @@ fuzz_target!(|testcase: TestCase| { }; // Native fn - let mut host_compiler = SingleFunctionCompiler::with_default_host_isa(); + let mut host_compiler = SingleFunctionCompiler::with_default_host_isa().unwrap(); let compiled_fn = host_compiler.compile(testcase.func.clone()).unwrap(); for args in &testcase.inputs { diff --git a/src/commands/settings.rs b/src/commands/settings.rs index 172ae6cba0d1..ad032d82846d 100644 --- a/src/commands/settings.rs +++ b/src/commands/settings.rs @@ -62,7 +62,7 @@ impl SettingsCommand { } if self.target.is_none() { - let compiler = builder.build(); + let compiler = builder.build()?; println!(); println!("Settings inferred for the current host:");