Skip to content

Commit 61d95e2

Browse files
committed
Implement a implicit target feature mechanism
1 parent eb0a444 commit 61d95e2

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-1
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+16
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,22 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
646646
}
647647
}
648648

649+
// This is a workaround for a LLVM bug that doesn't implicitly enable
650+
// `simd128` when `relaxed-simd` is.
651+
// See <https://github.com/llvm/llvm-project/pull/99803>, which didn't make
652+
// it into a released version of LLVM yet.
653+
//
654+
// This doesn't use the "implicit target feature" system because it is only
655+
// used for function attributes in other targets, which fixes this bug as
656+
// well on the function attribute level.
657+
if sess.target.families.contains(&"wasm".into()) {
658+
if features.iter().any(|f| f == "+relaxed-simd")
659+
&& !features.iter().any(|f| f == "+simd128")
660+
{
661+
features.push("+simd128".into());
662+
}
663+
}
664+
649665
if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
650666
sess.dcx().emit_err(TargetFeatureDisableOrEnable {
651667
features: f,

compiler/rustc_codegen_ssa/src/target_features.rs

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ pub fn from_target_feature(
9696
Some(Symbol::intern(feature))
9797
}));
9898
}
99+
100+
for (feature, requires) in tcx.sess.target.implicit_target_features() {
101+
if target_features.iter().any(|f| f.as_str() == *feature)
102+
&& !target_features.iter().any(|f| f.as_str() == *requires)
103+
{
104+
target_features.push(Symbol::intern(requires));
105+
}
106+
}
99107
}
100108

101109
/// Computes the set of target features used in a function for the purposes of

compiler/rustc_target/src/target_features.rs

+11
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ const WASM_ALLOWED_FEATURES: &[(&str, Stability)] = &[
336336
// tidy-alphabetical-end
337337
];
338338

339+
const WASM_IMPLICIT_FEATURES: &[(&str, &str)] = &[("relaxed-simd", "simd128")];
340+
339341
const BPF_ALLOWED_FEATURES: &[(&str, Stability)] = &[("alu32", Unstable(sym::bpf_target_feature))];
340342

341343
const CSKY_ALLOWED_FEATURES: &[(&str, Stability)] = &[
@@ -452,4 +454,13 @@ impl super::spec::Target {
452454
_ => &[],
453455
}
454456
}
457+
458+
/// Returns a list of target features. Each items first target feature
459+
/// implicitly enables the second one.
460+
pub fn implicit_target_features(&self) -> &'static [(&'static str, &'static str)] {
461+
match &*self.arch {
462+
"wasm32" | "wasm64" => WASM_IMPLICIT_FEATURES,
463+
_ => &[],
464+
}
465+
}
455466
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ only-wasm32-wasip1
2+
//@ compile-flags: -Ctarget-feature=+relaxed-simd --crate-type=lib
3+
//@ build-pass
4+
5+
use std::arch::wasm32::*;
6+
7+
pub fn test(a: v128, b: v128, m: v128) -> v128 {
8+
i64x2_relaxed_laneselect(a, b, m)
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ only-wasm32-wasip1
2+
//@ compile-flags: --crate-type=lib
3+
//@ build-pass
4+
5+
use std::arch::wasm32::*;
6+
7+
#[target_feature(enable = "relaxed-simd")]
8+
pub fn test(a: v128, b: v128, m: v128) -> v128 {
9+
i64x2_relaxed_laneselect(a, b, m)
10+
}

tests/ui/target-feature/wasm-relaxed-simd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ only-wasm32-wasip1
2-
//@ compile-flags: -Ctarget-feature=+relaxed-simd,+simd128 --crate-type=lib
2+
//@ compile-flags: -Ctarget-feature=+relaxed-simd --crate-type=lib
33
//@ build-pass
44

55
use std::arch::wasm32::*;

0 commit comments

Comments
 (0)