|
1 | 1 | #[cfg(feature = "master")]
|
2 | 2 | use gccjit::Context;
|
3 |
| -use rustc_codegen_ssa::codegen_attrs::check_tied_features; |
4 |
| -use rustc_codegen_ssa::errors::TargetFeatureDisableOrEnable; |
5 |
| -use rustc_data_structures::fx::FxHashMap; |
6 |
| -use rustc_data_structures::unord::UnordSet; |
| 3 | +use rustc_codegen_ssa::target_features; |
7 | 4 | use rustc_session::Session;
|
8 |
| -use rustc_session::features::{StabilityExt, retpoline_features_by_flags}; |
9 |
| -use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES; |
10 | 5 | use smallvec::{SmallVec, smallvec};
|
11 | 6 |
|
12 |
| -use crate::errors::{PossibleFeature, UnknownCTargetFeature, UnknownCTargetFeaturePrefix}; |
13 |
| - |
14 |
| -fn gcc_features_by_flags(sess: &Session) -> Vec<&str> { |
15 |
| - let mut features: Vec<&str> = Vec::new(); |
16 |
| - retpoline_features_by_flags(sess, &mut features); |
17 |
| - features |
| 7 | +fn gcc_features_by_flags(sess: &Session, features: &mut Vec<String>) { |
| 8 | + target_features::retpoline_features_by_flags(sess, features); |
18 | 9 | }
|
19 | 10 |
|
20 | 11 | /// The list of GCC features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
|
@@ -44,98 +35,31 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
|
44 | 35 | features.extend(sess.target.features.split(',').filter(|v| !v.is_empty()).map(String::from));
|
45 | 36 |
|
46 | 37 | // -Ctarget-features
|
47 |
| - let known_features = sess.target.rust_target_features(); |
48 |
| - let mut featsmap = FxHashMap::default(); |
49 |
| - |
50 |
| - // Compute implied features |
51 |
| - let mut all_rust_features = vec![]; |
52 |
| - for feature in sess.opts.cg.target_feature.split(',').chain(gcc_features_by_flags(sess)) { |
53 |
| - if let Some(feature) = feature.strip_prefix('+') { |
54 |
| - all_rust_features.extend( |
55 |
| - UnordSet::from(sess.target.implied_target_features(feature)) |
56 |
| - .to_sorted_stable_ord() |
57 |
| - .iter() |
58 |
| - .map(|&&s| (true, s)), |
59 |
| - ) |
60 |
| - } else if let Some(feature) = feature.strip_prefix('-') { |
61 |
| - // FIXME: Why do we not remove implied features on "-" here? |
62 |
| - // We do the equivalent above in `target_config`. |
63 |
| - // See <https://github.com/rust-lang/rust/issues/134792>. |
64 |
| - all_rust_features.push((false, feature)); |
65 |
| - } else if !feature.is_empty() && diagnostics { |
66 |
| - sess.dcx().emit_warn(UnknownCTargetFeaturePrefix { feature }); |
67 |
| - } |
68 |
| - } |
69 |
| - // Remove features that are meant for rustc, not codegen. |
70 |
| - all_rust_features.retain(|&(_, feature)| { |
71 |
| - // Retain if it is not a rustc feature |
72 |
| - !RUSTC_SPECIFIC_FEATURES.contains(&feature) |
73 |
| - }); |
74 |
| - |
75 |
| - // Check feature validity. |
76 |
| - if diagnostics { |
77 |
| - for &(enable, feature) in &all_rust_features { |
78 |
| - let feature_state = known_features.iter().find(|&&(v, _, _)| v == feature); |
79 |
| - match feature_state { |
80 |
| - None => { |
81 |
| - let rust_feature = known_features.iter().find_map(|&(rust_feature, _, _)| { |
82 |
| - let gcc_features = to_gcc_features(sess, rust_feature); |
83 |
| - if gcc_features.contains(&feature) && !gcc_features.contains(&rust_feature) |
84 |
| - { |
85 |
| - Some(rust_feature) |
86 |
| - } else { |
87 |
| - None |
88 |
| - } |
89 |
| - }); |
90 |
| - let unknown_feature = if let Some(rust_feature) = rust_feature { |
91 |
| - UnknownCTargetFeature { |
92 |
| - feature, |
93 |
| - rust_feature: PossibleFeature::Some { rust_feature }, |
94 |
| - } |
95 |
| - } else { |
96 |
| - UnknownCTargetFeature { feature, rust_feature: PossibleFeature::None } |
97 |
| - }; |
98 |
| - sess.dcx().emit_warn(unknown_feature); |
99 |
| - } |
100 |
| - Some(&(_, stability, _)) => { |
101 |
| - stability.verify_feature_enabled_by_flag(sess, enable, feature); |
102 |
| - } |
103 |
| - } |
104 |
| - |
105 |
| - // FIXME(nagisa): figure out how to not allocate a full hashset here. |
106 |
| - featsmap.insert(feature, enable); |
107 |
| - } |
108 |
| - } |
109 |
| - |
110 |
| - // Translate this into GCC features. |
111 |
| - let feats = |
112 |
| - all_rust_features.iter().flat_map(|&(enable, feature)| { |
113 |
| - let enable_disable = if enable { '+' } else { '-' }; |
| 38 | + target_features::flag_to_backend_features( |
| 39 | + sess, |
| 40 | + diagnostics, |
| 41 | + |feature| to_gcc_features(sess, feature), |
| 42 | + |feature, enable| { |
114 | 43 | // We run through `to_gcc_features` when
|
115 | 44 | // passing requests down to GCC. This means that all in-language
|
116 | 45 | // features also work on the command line instead of having two
|
117 | 46 | // different names when the GCC name and the Rust name differ.
|
118 |
| - to_gcc_features(sess, feature) |
119 |
| - .iter() |
120 |
| - .flat_map(|feat| to_gcc_features(sess, feat).into_iter()) |
121 |
| - .map(|feature| { |
122 |
| - if enable_disable == '-' { |
123 |
| - format!("-{}", feature) |
124 |
| - } else { |
125 |
| - feature.to_string() |
126 |
| - } |
127 |
| - }) |
128 |
| - .collect::<Vec<_>>() |
129 |
| - }); |
130 |
| - features.extend(feats); |
131 |
| - |
132 |
| - if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) { |
133 |
| - sess.dcx().emit_err(TargetFeatureDisableOrEnable { |
134 |
| - features: f, |
135 |
| - span: None, |
136 |
| - missing_features: None, |
137 |
| - }); |
138 |
| - } |
| 47 | + features.extend( |
| 48 | + to_gcc_features(sess, feature) |
| 49 | + .iter() |
| 50 | + .flat_map(|feat| to_gcc_features(sess, feat).into_iter()) |
| 51 | + .map( |
| 52 | + |feature| { |
| 53 | + if !enable { format!("-{}", feature) } else { feature.to_string() } |
| 54 | + }, |
| 55 | + ), |
| 56 | + ); |
| 57 | + }, |
| 58 | + ); |
| 59 | + |
| 60 | + gcc_features_by_flags(sess, &mut features); |
| 61 | + |
| 62 | + // FIXME: LLVM also sets +reserve-x18 here under some conditions. |
139 | 63 |
|
140 | 64 | features
|
141 | 65 | }
|
|
0 commit comments