Skip to content

Commit

Permalink
rename known_target_features → rust_target_features
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 2, 2024
1 parent a147086 commit 319aafa
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 53 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/gcc_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
);

// -Ctarget-features
let known_features = sess.target.known_target_features();
let known_features = sess.target.rust_target_features();
let mut featsmap = FxHashMap::default();
let feats = sess
.opts
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ pub fn target_features(
) -> Vec<Symbol> {
// TODO(antoyo): use global_gcc_features.
sess.target
.known_target_features()
.rust_target_features()
.iter()
.filter_map(|&(feature, gate, _)| {
if sess.is_nightly_build() || allow_unstable || gate.is_stable() {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
// Compute which of the known target features are enabled in the 'base' target machine.
features.extend(
sess.target
.known_target_features()
.rust_target_features()
.iter()
.filter(|(feature, _, _)| {
// skip checking special features, as LLVM may not understands them
Expand Down Expand Up @@ -354,7 +354,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {

// Filter enabled features based on feature gates
sess.target
.known_target_features()
.rust_target_features()
.iter()
.filter_map(|&(feature, gate, _)| {
if sess.is_nightly_build() || allow_unstable || gate.is_stable() {
Expand Down Expand Up @@ -417,7 +417,7 @@ fn print_target_features(out: &mut String, sess: &Session, tm: &llvm::TargetMach
let mut known_llvm_target_features = FxHashSet::<&'static str>::default();
let mut rustc_target_features = sess
.target
.known_target_features()
.rust_target_features()
.iter()
.filter_map(|(feature, gate, _implied)| {
if matches!(gate, Stability::Forbidden) {
Expand Down Expand Up @@ -590,7 +590,7 @@ pub(crate) fn global_llvm_features(

// -Ctarget-features
if !only_base_features {
let known_features = sess.target.known_target_features();
let known_features = sess.target.rust_target_features();
let (llvm_major, _, _) = get_version();
let mut featsmap = FxHashMap::default();

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_BUILTINS;
}

let known_target_features = tcx.known_target_features(LOCAL_CRATE);
let rust_target_features = tcx.rust_target_features(LOCAL_CRATE);

let mut inline_span = None;
let mut link_ordinal_span = None;
Expand Down Expand Up @@ -301,7 +301,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
from_target_feature_attr(
tcx,
attr,
known_target_features,
rust_target_features,
&mut codegen_fn_attrs.target_features,
);
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::errors;
pub fn from_target_feature_attr(
tcx: TyCtxt<'_>,
attr: &ast::Attribute,
known_target_features: &UnordMap<String, target_features::Stability>,
rust_target_features: &UnordMap<String, target_features::Stability>,
target_features: &mut Vec<TargetFeature>,
) {
let Some(list) = attr.meta_item_list() else { return };
Expand Down Expand Up @@ -50,12 +50,12 @@ pub fn from_target_feature_attr(

// We allow comma separation to enable multiple features.
added_target_features.extend(value.as_str().split(',').filter_map(|feature| {
let Some(stability) = known_target_features.get(feature) else {
let Some(stability) = rust_target_features.get(feature) else {
let msg = format!("the feature named `{feature}` is not valid for this target");
let mut err = tcx.dcx().struct_span_err(item.span(), msg);
err.span_label(item.span(), format!("`{feature}` is not valid for this target"));
if let Some(stripped) = feature.strip_prefix('+') {
let valid = known_target_features.contains_key(stripped);
let valid = rust_target_features.contains_key(stripped);
if valid {
err.help("consider removing the leading `+` in the feature name");
}
Expand Down Expand Up @@ -197,7 +197,7 @@ pub fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_s

pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers {
known_target_features: |tcx, cnum| {
rust_target_features: |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
if tcx.sess.opts.actually_rustdoc {
// rustdoc needs to be able to document functions that use all the features, so
Expand All @@ -208,7 +208,7 @@ pub(crate) fn provide(providers: &mut Providers) {
} else {
tcx.sess
.target
.known_target_features()
.rust_target_features()
.iter()
.map(|&(a, b, _)| (a.to_string(), b))
.collect()
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2160,10 +2160,11 @@ rustc_queries! {
desc { "computing autoderef types for `{}`", goal.value.value }
}

query known_target_features(_: CrateNum) -> &'tcx UnordMap<String, rustc_target::target_features::Stability> {
/// Returns the Rust target features for the current target. These are not always the same as LLVM target features!
query rust_target_features(_: CrateNum) -> &'tcx UnordMap<String, rustc_target::target_features::Stability> {
arena_cache
eval_always
desc { "looking up known target features" }
desc { "looking up Rust target features" }
}

query implied_target_features(feature: Symbol) -> &'tcx Vec<Symbol> {
Expand Down
76 changes: 38 additions & 38 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Stability {

type ImpliedFeatures = &'static [&'static str];

const ARM_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
const ARM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("aclass", Unstable(sym::arm_target_feature), &[]),
("aes", Unstable(sym::arm_target_feature), &["neon"]),
Expand Down Expand Up @@ -116,7 +116,7 @@ const ARM_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-end
];

const AARCH64_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
const AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
// FEAT_AES & FEAT_PMULL
("aes", Stable, &["neon"]),
Expand Down Expand Up @@ -304,7 +304,7 @@ const AARCH64_TIED_FEATURES: &[&[&str]] = &[
&["paca", "pacg"], // Together these represent `pauth` in LLVM
];

const X86_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
const X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("adx", Stable, &[]),
("aes", Stable, &["sse2"]),
Expand Down Expand Up @@ -375,14 +375,14 @@ const X86_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-end
];

const HEXAGON_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
const HEXAGON_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("hvx", Unstable(sym::hexagon_target_feature), &[]),
("hvx-length128b", Unstable(sym::hexagon_target_feature), &["hvx"]),
// tidy-alphabetical-end
];

const POWERPC_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
const POWERPC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("altivec", Unstable(sym::powerpc_target_feature), &[]),
("power10-vector", Unstable(sym::powerpc_target_feature), &["power9-vector"]),
Expand All @@ -394,15 +394,15 @@ const POWERPC_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-end
];

const MIPS_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
const MIPS_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("fp64", Unstable(sym::mips_target_feature), &[]),
("msa", Unstable(sym::mips_target_feature), &[]),
("virt", Unstable(sym::mips_target_feature), &[]),
// tidy-alphabetical-end
];

const RISCV_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
const RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("a", Stable, &[]),
("c", Stable, &[]),
Expand Down Expand Up @@ -439,7 +439,7 @@ const RISCV_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-end
];

const WASM_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
const WASM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("atomics", Unstable(sym::wasm_target_feature), &[]),
("bulk-memory", Stable, &[]),
Expand All @@ -455,10 +455,10 @@ const WASM_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-end
];

const BPF_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] =
const BPF_FEATURES: &[(&str, Stability, ImpliedFeatures)] =
&[("alu32", Unstable(sym::bpf_target_feature), &[])];

const CSKY_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
const CSKY_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("10e60", Unstable(sym::csky_target_feature), &["7e10"]),
("2e3", Unstable(sym::csky_target_feature), &["e2"]),
Expand Down Expand Up @@ -505,7 +505,7 @@ const CSKY_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-end
];

const LOONGARCH_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
const LOONGARCH_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("d", Unstable(sym::loongarch_target_feature), &["f"]),
("f", Unstable(sym::loongarch_target_feature), &[]),
Expand All @@ -519,7 +519,7 @@ const LOONGARCH_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-end
];

const IBMZ_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
const IBMZ_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("backchain", Unstable(sym::s390x_target_feature), &[]),
("vector", Unstable(sym::s390x_target_feature), &[]),
Expand All @@ -532,37 +532,37 @@ const IBMZ_KNOWN_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
/// IMPORTANT: If you're adding another feature list above, make sure to add it to this iterator!
pub fn all_known_features() -> impl Iterator<Item = (&'static str, Stability)> {
std::iter::empty()
.chain(ARM_KNOWN_FEATURES.iter())
.chain(AARCH64_KNOWN_FEATURES.iter())
.chain(X86_KNOWN_FEATURES.iter())
.chain(HEXAGON_KNOWN_FEATURES.iter())
.chain(POWERPC_KNOWN_FEATURES.iter())
.chain(MIPS_KNOWN_FEATURES.iter())
.chain(RISCV_KNOWN_FEATURES.iter())
.chain(WASM_KNOWN_FEATURES.iter())
.chain(BPF_KNOWN_FEATURES.iter())
.chain(CSKY_KNOWN_FEATURES)
.chain(LOONGARCH_KNOWN_FEATURES)
.chain(IBMZ_KNOWN_FEATURES)
.chain(ARM_FEATURES.iter())
.chain(AARCH64_FEATURES.iter())
.chain(X86_FEATURES.iter())
.chain(HEXAGON_FEATURES.iter())
.chain(POWERPC_FEATURES.iter())
.chain(MIPS_FEATURES.iter())
.chain(RISCV_FEATURES.iter())
.chain(WASM_FEATURES.iter())
.chain(BPF_FEATURES.iter())
.chain(CSKY_FEATURES)
.chain(LOONGARCH_FEATURES)
.chain(IBMZ_FEATURES)
.cloned()
.map(|(f, s, _)| (f, s))
}

impl super::spec::Target {
pub fn known_target_features(&self) -> &'static [(&'static str, Stability, ImpliedFeatures)] {
pub fn rust_target_features(&self) -> &'static [(&'static str, Stability, ImpliedFeatures)] {
match &*self.arch {
"arm" => ARM_KNOWN_FEATURES,
"aarch64" | "arm64ec" => AARCH64_KNOWN_FEATURES,
"x86" | "x86_64" => X86_KNOWN_FEATURES,
"hexagon" => HEXAGON_KNOWN_FEATURES,
"mips" | "mips32r6" | "mips64" | "mips64r6" => MIPS_KNOWN_FEATURES,
"powerpc" | "powerpc64" => POWERPC_KNOWN_FEATURES,
"riscv32" | "riscv64" => RISCV_KNOWN_FEATURES,
"wasm32" | "wasm64" => WASM_KNOWN_FEATURES,
"bpf" => BPF_KNOWN_FEATURES,
"csky" => CSKY_KNOWN_FEATURES,
"loongarch64" => LOONGARCH_KNOWN_FEATURES,
"s390x" => IBMZ_KNOWN_FEATURES,
"arm" => ARM_FEATURES,
"aarch64" | "arm64ec" => AARCH64_FEATURES,
"x86" | "x86_64" => X86_FEATURES,
"hexagon" => HEXAGON_FEATURES,
"mips" | "mips32r6" | "mips64" | "mips64r6" => MIPS_FEATURES,
"powerpc" | "powerpc64" => POWERPC_FEATURES,
"riscv32" | "riscv64" => RISCV_FEATURES,
"wasm32" | "wasm64" => WASM_FEATURES,
"bpf" => BPF_FEATURES,
"csky" => CSKY_FEATURES,
"loongarch64" => LOONGARCH_FEATURES,
"s390x" => IBMZ_FEATURES,
_ => &[],
}
}
Expand All @@ -579,7 +579,7 @@ impl super::spec::Target {
base_features: impl Iterator<Item = Symbol>,
) -> FxHashSet<Symbol> {
let implied_features = self
.known_target_features()
.rust_target_features()
.iter()
.map(|(f, _, i)| (Symbol::intern(f), i))
.collect::<FxHashMap<_, _>>();
Expand Down

0 comments on commit 319aafa

Please sign in to comment.