Avoid creating SmallVec
s in global_llvm_features
This commit is contained in:
parent
c35035cefc
commit
b3cd892ae1
1 changed files with 37 additions and 33 deletions
|
@ -218,15 +218,17 @@ pub fn check_tied_features(
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
features: &FxHashMap<&str, bool>,
|
features: &FxHashMap<&str, bool>,
|
||||||
) -> Option<&'static [&'static str]> {
|
) -> Option<&'static [&'static str]> {
|
||||||
for tied in tied_target_features(sess) {
|
if !features.is_empty() {
|
||||||
// Tied features must be set to the same value, or not set at all
|
for tied in tied_target_features(sess) {
|
||||||
let mut tied_iter = tied.iter();
|
// Tied features must be set to the same value, or not set at all
|
||||||
let enabled = features.get(tied_iter.next().unwrap());
|
let mut tied_iter = tied.iter();
|
||||||
if tied_iter.any(|f| enabled != features.get(f)) {
|
let enabled = features.get(tied_iter.next().unwrap());
|
||||||
return Some(tied);
|
if tied_iter.any(|f| enabled != features.get(f)) {
|
||||||
|
return Some(tied);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to generate cfg variables and apply features
|
// Used to generate cfg variables and apply features
|
||||||
|
@ -440,6 +442,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
|
||||||
|
|
||||||
// -Ctarget-features
|
// -Ctarget-features
|
||||||
let supported_features = supported_target_features(sess);
|
let supported_features = supported_target_features(sess);
|
||||||
|
let mut featsmap = FxHashMap::default();
|
||||||
let feats = sess
|
let feats = sess
|
||||||
.opts
|
.opts
|
||||||
.cg
|
.cg
|
||||||
|
@ -485,35 +488,36 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
|
||||||
}
|
}
|
||||||
diag.emit();
|
diag.emit();
|
||||||
}
|
}
|
||||||
Some((enable_disable, feature))
|
|
||||||
})
|
|
||||||
.collect::<SmallVec<[(char, &str); 8]>>();
|
|
||||||
|
|
||||||
if diagnostics {
|
if diagnostics {
|
||||||
// FIXME(nagisa): figure out how to not allocate a full hashset here.
|
// FIXME(nagisa): figure out how to not allocate a full hashset here.
|
||||||
let featmap = feats.iter().map(|&(flag, feat)| (feat, flag == '+')).collect();
|
featsmap.insert(feature, enable_disable == '+');
|
||||||
if let Some(f) = check_tied_features(sess, &featmap) {
|
}
|
||||||
sess.err(&format!(
|
|
||||||
"target features {} must all be enabled or disabled together",
|
// rustc-specific features do not get passed down to LLVM…
|
||||||
f.join(", ")
|
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {
|
||||||
));
|
return None;
|
||||||
}
|
}
|
||||||
|
// ... otherwise though we run through `to_llvm_features` when
|
||||||
|
// passing requests down to LLVM. This means that all in-language
|
||||||
|
// features also work on the command line instead of having two
|
||||||
|
// different names when the LLVM name and the Rust name differ.
|
||||||
|
Some(
|
||||||
|
to_llvm_features(sess, feature)
|
||||||
|
.into_iter()
|
||||||
|
.map(move |f| format!("{}{}", enable_disable, f)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.flatten();
|
||||||
|
features.extend(feats);
|
||||||
|
|
||||||
|
if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
|
||||||
|
sess.err(&format!(
|
||||||
|
"target features {} must all be enabled or disabled together",
|
||||||
|
f.join(", ")
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
features.extend(feats.into_iter().flat_map(|(enable_disable, feature)| {
|
|
||||||
// rustc-specific features do not get passed down to LLVM…
|
|
||||||
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {
|
|
||||||
return SmallVec::<[_; 2]>::new();
|
|
||||||
}
|
|
||||||
// ... otherwise though we run through `to_llvm_features` when
|
|
||||||
// passing requests down to LLVM. This means that all in-language
|
|
||||||
// features also work on the command line instead of having two
|
|
||||||
// different names when the LLVM name and the Rust name differ.
|
|
||||||
to_llvm_features(sess, feature)
|
|
||||||
.into_iter()
|
|
||||||
.map(|f| format!("{}{}", enable_disable, f))
|
|
||||||
.collect()
|
|
||||||
}));
|
|
||||||
features
|
features
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue