Skip to content

Commit

Permalink
Auto merge of rust-lang#118908 - Urgau:check-cfg-target-features, r=T…
Browse files Browse the repository at this point in the history
…aKO8Ki

Add all known `target_feature` configs to check-cfg

This PR adds all the known `target_feature` from ~~`rustc_codegen_ssa`~~ `rustc_target` to the well known list of check-cfg.

It does so by moving the list from `rustc_codegen_ssa` to `rustc_target` ~~`rustc_session` (I not sure about this, but some of the moved function take a `Session`)~~, then using it the `fill_well_known` function.

This already proved to be useful since portable-simd had a bad cfg.

cc `@nnethercote` (since we discussed it in rust-lang#118494)
  • Loading branch information
bors committed Dec 14, 2023
2 parents 1aa6aef + fb9b31c commit b1dc6c0
Show file tree
Hide file tree
Showing 10 changed files with 482 additions and 460 deletions.
8 changes: 3 additions & 5 deletions compiler/rustc_codegen_gcc/src/gcc_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
use gccjit::Context;
use smallvec::{smallvec, SmallVec};

use rustc_codegen_ssa::target_features::{
supported_target_features, tied_target_features, RUSTC_SPECIFIC_FEATURES,
};
use rustc_data_structures::fx::FxHashMap;
use rustc_middle::bug;
use rustc_session::Session;
use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES;

use crate::errors::{PossibleFeature, TargetFeatureDisableOrEnable, UnknownCTargetFeature, UnknownCTargetFeaturePrefix};

Expand Down Expand Up @@ -44,7 +42,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
);

// -Ctarget-features
let supported_features = supported_target_features(sess);
let supported_features = sess.target.supported_target_features();
let mut featsmap = FxHashMap::default();
let feats = sess.opts.cg.target_feature
.split(',')
Expand Down Expand Up @@ -187,7 +185,7 @@ pub fn to_gcc_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]>
// Given a map from target_features to whether they are enabled or disabled,
// ensure only valid combinations are allowed.
pub fn check_tied_features(sess: &Session, features: &FxHashMap<&str, bool>) -> Option<&'static [&'static str]> {
for tied in tied_target_features(sess) {
for tied in sess.target.tied_target_features() {
// Tied features must be set to the same value, or not set at all
let mut tied_iter = tied.iter();
let enabled = features.get(tied_iter.next().unwrap());
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen};
use rustc_codegen_ssa::base::codegen_crate;
use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput, ModuleConfig, TargetMachineFactoryFn};
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
use rustc_codegen_ssa::target_features::supported_target_features;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync::IntoDynSyncSend;
use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, ThinBufferMethods, WriteBackendMethods};
Expand Down Expand Up @@ -397,7 +396,9 @@ fn to_gcc_opt_level(optlevel: Option<OptLevel>) -> OptimizationLevel {
}

pub fn target_features(sess: &Session, allow_unstable: bool, target_info: &LockedTargetInfo) -> Vec<Symbol> {
supported_target_features(sess)
sess
.target
.supported_target_features()
.iter()
.filter_map(
|&(feature, gate)| {
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ use crate::errors::{
};
use crate::llvm;
use libc::c_int;
use rustc_codegen_ssa::target_features::{
supported_target_features, tied_target_features, RUSTC_SPECIFIC_FEATURES,
};
use rustc_codegen_ssa::traits::PrintBackendInfo;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::small_c_str::SmallCStr;
Expand All @@ -17,6 +14,7 @@ use rustc_session::config::{PrintKind, PrintRequest};
use rustc_session::Session;
use rustc_span::symbol::Symbol;
use rustc_target::spec::{MergeFunctions, PanicStrategy};
use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES;

use std::ffi::{c_char, c_void, CStr, CString};
use std::path::Path;
Expand Down Expand Up @@ -278,7 +276,7 @@ pub fn check_tied_features(
features: &FxHashMap<&str, bool>,
) -> Option<&'static [&'static str]> {
if !features.is_empty() {
for tied in tied_target_features(sess) {
for tied in sess.target.tied_target_features() {
// Tied features must be set to the same value, or not set at all
let mut tied_iter = tied.iter();
let enabled = features.get(tied_iter.next().unwrap());
Expand All @@ -294,7 +292,8 @@ pub fn check_tied_features(
/// Must express features in the way Rust understands them
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
let target_machine = create_informational_target_machine(sess);
supported_target_features(sess)
sess.target
.supported_target_features()
.iter()
.filter_map(|&(feature, gate)| {
if sess.is_nightly_build() || allow_unstable || gate.is_stable() {
Expand Down Expand Up @@ -362,7 +361,9 @@ fn llvm_target_features(tm: &llvm::TargetMachine) -> Vec<(&str, &str)> {
fn print_target_features(out: &mut dyn PrintBackendInfo, sess: &Session, tm: &llvm::TargetMachine) {
let mut llvm_target_features = llvm_target_features(tm);
let mut known_llvm_target_features = FxHashSet::<&'static str>::default();
let mut rustc_target_features = supported_target_features(sess)
let mut rustc_target_features = sess
.target
.supported_target_features()
.iter()
.map(|(feature, _gate)| {
// LLVM asserts that these are sorted. LLVM and Rust both use byte comparison for these strings.
Expand Down Expand Up @@ -515,7 +516,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
);

// -Ctarget-features
let supported_features = supported_target_features(sess);
let supported_features = sess.target.supported_target_features();
let mut featsmap = FxHashMap::default();
let feats = sess
.opts
Expand Down
Loading

0 comments on commit b1dc6c0

Please sign in to comment.