Skip to content

Commit f06dd33

Browse files
committed
Implement a dependant target feature mechanism
1 parent eb0a444 commit f06dd33

File tree

6 files changed

+42
-1
lines changed

6 files changed

+42
-1
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,12 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
654654
});
655655
}
656656

657+
for (feature, requires) in sess.target.dependant_target_features() {
658+
if features.iter().any(|f| f == feature) && !features.iter().any(|f| f == requires) {
659+
features.push(format!("+{requires}"));
660+
}
661+
}
662+
657663
features
658664
}
659665

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ pub fn from_target_feature(
9696
Some(Symbol::intern(feature))
9797
}));
9898
}
99+
100+
for (feature, requires) in tcx.sess.target.dependant_target_features() {
101+
if target_features.iter().any(|f| f.as_str() == *feature) && !target_features.iter().any(|f| f.as_str() == *requires) {
102+
target_features.push(Symbol::intern(requires));
103+
}
104+
}
99105
}
100106

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

compiler/rustc_target/src/target_features.rs

Lines changed: 10 additions & 0 deletions
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_DEPENDANT_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,12 @@ impl super::spec::Target {
452454
_ => &[],
453455
}
454456
}
457+
458+
/// Returns a list of target features. Each items first target feature requires the second one.
459+
pub fn dependant_target_features(&self) -> &'static [(&'static str, &'static str)] {
460+
match &*self.arch {
461+
"wasm32" | "wasm64" => WASM_DEPENDANT_FEATURES,
462+
_ => &[],
463+
}
464+
}
455465
}
Lines changed: 9 additions & 0 deletions
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+
}
Lines changed: 10 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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)