diff options
| author | bors <bors@rust-lang.org> | 2024-08-05 09:25:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-08-05 09:25:50 +0000 |
| commit | 9179d9b334e3f5e8772e1a563308dc95a1cde960 (patch) | |
| tree | 11366ba48f6b11c94fcc1d9f875a5bcbaef50a35 | |
| parent | 4d48a6be74d46304cacb93cb8eb60d70d733b862 (diff) | |
| parent | 80b74d397fffc9deaafd2b44552ba3a9107b4d5b (diff) | |
| download | rust-9179d9b334e3f5e8772e1a563308dc95a1cde960.tar.gz rust-9179d9b334e3f5e8772e1a563308dc95a1cde960.zip | |
Auto merge of #117468 - daxpedda:wasm-relaxed-simd, r=alexcrichton
Stabilize Wasm relaxed SIMD This PR stabilizes [Wasm relaxed SIMD](https://github.com/WebAssembly/relaxed-simd) which has already reached [phase 4](https://github.com/WebAssembly/proposals/tree/04fa8c810e1dc99ab399e41052a6e427ee988180?tab=readme-ov-file#phase-4---standardize-the-feature-wg). Tracking issue: #111196 Implementation PR: https://github.com/rust-lang/stdarch/pull/1393 Documentation: https://github.com/rust-lang/reference/pull/1421 Stdarch: https://github.com/rust-lang/stdarch/pull/1494 Closes #111196.
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/llvm_util.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/target_features.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_target/src/target_features.rs | 13 | ||||
| -rw-r--r-- | tests/ui/target-feature/implicit-features-cli.rs | 9 | ||||
| -rw-r--r-- | tests/ui/target-feature/implicit-features.rs | 10 | ||||
| -rw-r--r-- | tests/ui/target-feature/wasm-relaxed-simd.rs | 9 |
6 files changed, 64 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index dc21b92a95f..af8a9be1ccb 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -646,6 +646,22 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str } } + // This is a workaround for a LLVM bug that doesn't implicitly enable + // `simd128` when `relaxed-simd` is. + // See <https://github.com/llvm/llvm-project/pull/99803>, which didn't make + // it into a released version of LLVM yet. + // + // This doesn't use the "implicit target feature" system because it is only + // used for function attributes in other targets, which fixes this bug as + // well on the function attribute level. + if sess.target.families.contains(&"wasm".into()) { + if features.iter().any(|f| f == "+relaxed-simd") + && !features.iter().any(|f| f == "+simd128") + { + features.push("+simd128".into()); + } + } + if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) { sess.dcx().emit_err(TargetFeatureDisableOrEnable { features: f, diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index b52e6259944..127244a34f8 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -97,6 +97,14 @@ pub fn from_target_feature( Some(Symbol::intern(feature)) })); } + + for (feature, requires) in tcx.sess.target.implicit_target_features() { + if target_features.iter().any(|f| f.as_str() == *feature) + && !target_features.iter().any(|f| f.as_str() == *requires) + { + target_features.push(Symbol::intern(requires)); + } + } } /// Computes the set of target features used in a function for the purposes of diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index e52f2fc06df..4e2617c4679 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -333,12 +333,14 @@ const WASM_ALLOWED_FEATURES: &[(&str, Stability)] = &[ ("mutable-globals", Stable), ("nontrapping-fptoint", Stable), ("reference-types", Unstable(sym::wasm_target_feature)), - ("relaxed-simd", Unstable(sym::wasm_target_feature)), + ("relaxed-simd", Stable), ("sign-ext", Stable), ("simd128", Stable), // tidy-alphabetical-end ]; +const WASM_IMPLICIT_FEATURES: &[(&str, &str)] = &[("relaxed-simd", "simd128")]; + const BPF_ALLOWED_FEATURES: &[(&str, Stability)] = &[("alu32", Unstable(sym::bpf_target_feature))]; const CSKY_ALLOWED_FEATURES: &[(&str, Stability)] = &[ @@ -455,4 +457,13 @@ impl super::spec::Target { _ => &[], } } + + /// Returns a list of target features. Each items first target feature + /// implicitly enables the second one. + pub fn implicit_target_features(&self) -> &'static [(&'static str, &'static str)] { + match &*self.arch { + "wasm32" | "wasm64" => WASM_IMPLICIT_FEATURES, + _ => &[], + } + } } diff --git a/tests/ui/target-feature/implicit-features-cli.rs b/tests/ui/target-feature/implicit-features-cli.rs new file mode 100644 index 00000000000..34e7c3d5066 --- /dev/null +++ b/tests/ui/target-feature/implicit-features-cli.rs @@ -0,0 +1,9 @@ +//@ only-wasm32-wasip1 +//@ compile-flags: -Ctarget-feature=+relaxed-simd --crate-type=lib +//@ build-pass + +use std::arch::wasm32::*; + +pub fn test(a: v128, b: v128, m: v128) -> v128 { + i64x2_relaxed_laneselect(a, b, m) +} diff --git a/tests/ui/target-feature/implicit-features.rs b/tests/ui/target-feature/implicit-features.rs new file mode 100644 index 00000000000..b9c48b0822d --- /dev/null +++ b/tests/ui/target-feature/implicit-features.rs @@ -0,0 +1,10 @@ +//@ only-wasm32-wasip1 +//@ compile-flags: --crate-type=lib +//@ build-pass + +use std::arch::wasm32::*; + +#[target_feature(enable = "relaxed-simd")] +pub fn test(a: v128, b: v128, m: v128) -> v128 { + i64x2_relaxed_laneselect(a, b, m) +} diff --git a/tests/ui/target-feature/wasm-relaxed-simd.rs b/tests/ui/target-feature/wasm-relaxed-simd.rs new file mode 100644 index 00000000000..34e7c3d5066 --- /dev/null +++ b/tests/ui/target-feature/wasm-relaxed-simd.rs @@ -0,0 +1,9 @@ +//@ only-wasm32-wasip1 +//@ compile-flags: -Ctarget-feature=+relaxed-simd --crate-type=lib +//@ build-pass + +use std::arch::wasm32::*; + +pub fn test(a: v128, b: v128, m: v128) -> v128 { + i64x2_relaxed_laneselect(a, b, m) +} |
