Skip to content

Commit b1dc6c0

Browse files
committed
Auto merge of rust-lang#118908 - Urgau:check-cfg-target-features, r=TaKO8Ki
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)
2 parents 1aa6aef + fb9b31c commit b1dc6c0

File tree

10 files changed

+482
-460
lines changed

10 files changed

+482
-460
lines changed

compiler/rustc_codegen_gcc/src/gcc_util.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
use gccjit::Context;
33
use smallvec::{smallvec, SmallVec};
44

5-
use rustc_codegen_ssa::target_features::{
6-
supported_target_features, tied_target_features, RUSTC_SPECIFIC_FEATURES,
7-
};
85
use rustc_data_structures::fx::FxHashMap;
96
use rustc_middle::bug;
107
use rustc_session::Session;
8+
use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES;
119

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

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

4644
// -Ctarget-features
47-
let supported_features = supported_target_features(sess);
45+
let supported_features = sess.target.supported_target_features();
4846
let mut featsmap = FxHashMap::default();
4947
let feats = sess.opts.cg.target_feature
5048
.split(',')
@@ -187,7 +185,7 @@ pub fn to_gcc_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]>
187185
// Given a map from target_features to whether they are enabled or disabled,
188186
// ensure only valid combinations are allowed.
189187
pub fn check_tied_features(sess: &Session, features: &FxHashMap<&str, bool>) -> Option<&'static [&'static str]> {
190-
for tied in tied_target_features(sess) {
188+
for tied in sess.target.tied_target_features() {
191189
// Tied features must be set to the same value, or not set at all
192190
let mut tied_iter = tied.iter();
193191
let enabled = features.get(tied_iter.next().unwrap());

compiler/rustc_codegen_gcc/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen};
9797
use rustc_codegen_ssa::base::codegen_crate;
9898
use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput, ModuleConfig, TargetMachineFactoryFn};
9999
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
100-
use rustc_codegen_ssa::target_features::supported_target_features;
101100
use rustc_data_structures::fx::FxIndexMap;
102101
use rustc_data_structures::sync::IntoDynSyncSend;
103102
use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, ThinBufferMethods, WriteBackendMethods};
@@ -397,7 +396,9 @@ fn to_gcc_opt_level(optlevel: Option<OptLevel>) -> OptimizationLevel {
397396
}
398397

399398
pub fn target_features(sess: &Session, allow_unstable: bool, target_info: &LockedTargetInfo) -> Vec<Symbol> {
400-
supported_target_features(sess)
399+
sess
400+
.target
401+
.supported_target_features()
401402
.iter()
402403
.filter_map(
403404
|&(feature, gate)| {

compiler/rustc_codegen_llvm/src/llvm_util.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ use crate::errors::{
55
};
66
use crate::llvm;
77
use libc::c_int;
8-
use rustc_codegen_ssa::target_features::{
9-
supported_target_features, tied_target_features, RUSTC_SPECIFIC_FEATURES,
10-
};
118
use rustc_codegen_ssa::traits::PrintBackendInfo;
129
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1310
use rustc_data_structures::small_c_str::SmallCStr;
@@ -17,6 +14,7 @@ use rustc_session::config::{PrintKind, PrintRequest};
1714
use rustc_session::Session;
1815
use rustc_span::symbol::Symbol;
1916
use rustc_target::spec::{MergeFunctions, PanicStrategy};
17+
use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES;
2018

2119
use std::ffi::{c_char, c_void, CStr, CString};
2220
use std::path::Path;
@@ -278,7 +276,7 @@ pub fn check_tied_features(
278276
features: &FxHashMap<&str, bool>,
279277
) -> Option<&'static [&'static str]> {
280278
if !features.is_empty() {
281-
for tied in tied_target_features(sess) {
279+
for tied in sess.target.tied_target_features() {
282280
// Tied features must be set to the same value, or not set at all
283281
let mut tied_iter = tied.iter();
284282
let enabled = features.get(tied_iter.next().unwrap());
@@ -294,7 +292,8 @@ pub fn check_tied_features(
294292
/// Must express features in the way Rust understands them
295293
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
296294
let target_machine = create_informational_target_machine(sess);
297-
supported_target_features(sess)
295+
sess.target
296+
.supported_target_features()
298297
.iter()
299298
.filter_map(|&(feature, gate)| {
300299
if sess.is_nightly_build() || allow_unstable || gate.is_stable() {
@@ -362,7 +361,9 @@ fn llvm_target_features(tm: &llvm::TargetMachine) -> Vec<(&str, &str)> {
362361
fn print_target_features(out: &mut dyn PrintBackendInfo, sess: &Session, tm: &llvm::TargetMachine) {
363362
let mut llvm_target_features = llvm_target_features(tm);
364363
let mut known_llvm_target_features = FxHashSet::<&'static str>::default();
365-
let mut rustc_target_features = supported_target_features(sess)
364+
let mut rustc_target_features = sess
365+
.target
366+
.supported_target_features()
366367
.iter()
367368
.map(|(feature, _gate)| {
368369
// LLVM asserts that these are sorted. LLVM and Rust both use byte comparison for these strings.
@@ -515,7 +516,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
515516
);
516517

517518
// -Ctarget-features
518-
let supported_features = supported_target_features(sess);
519+
let supported_features = sess.target.supported_target_features();
519520
let mut featsmap = FxHashMap::default();
520521
let feats = sess
521522
.opts

0 commit comments

Comments
 (0)