Skip to content

Commit 80b74d3

Browse files
committed
Implement a implicit target feature mechanism
1 parent 9052139 commit 80b74d3

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
@@ -97,6 +97,14 @@ pub fn from_target_feature(
9797
Some(Symbol::intern(feature))
9898
}));
9999
}
100+
101+
for (feature, requires) in tcx.sess.target.implicit_target_features() {
102+
if target_features.iter().any(|f| f.as_str() == *feature)
103+
&& !target_features.iter().any(|f| f.as_str() == *requires)
104+
{
105+
target_features.push(Symbol::intern(requires));
106+
}
107+
}
100108
}
101109

102110
/// 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
@@ -339,6 +339,8 @@ const WASM_ALLOWED_FEATURES: &[(&str, Stability)] = &[
339339
// tidy-alphabetical-end
340340
];
341341

342+
const WASM_IMPLICIT_FEATURES: &[(&str, &str)] = &[("relaxed-simd", "simd128")];
343+
342344
const BPF_ALLOWED_FEATURES: &[(&str, Stability)] = &[("alu32", Unstable(sym::bpf_target_feature))];
343345

344346
const CSKY_ALLOWED_FEATURES: &[(&str, Stability)] = &[
@@ -455,4 +457,13 @@ impl super::spec::Target {
455457
_ => &[],
456458
}
457459
}
460+
461+
/// Returns a list of target features. Each items first target feature
462+
/// implicitly enables the second one.
463+
pub fn implicit_target_features(&self) -> &'static [(&'static str, &'static str)] {
464+
match &*self.arch {
465+
"wasm32" | "wasm64" => WASM_IMPLICIT_FEATURES,
466+
_ => &[],
467+
}
468+
}
458469
}
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)