Auto merge of #137586 - nnethercote:SetImpliedBits, r=bjorn3

Speed up target feature computation

The LLVM backend calls `LLVMRustHasFeature` twice for every feature. In short-running rustc invocations, this accounts for a surprising amount of work.

r? `@bjorn3`
This commit is contained in:
bors 2025-03-11 12:05:16 +00:00
commit ebf0cf75d3
9 changed files with 120 additions and 113 deletions

View file

@ -768,17 +768,15 @@ impl Target {
}
}
pub fn implied_target_features<'a>(
&self,
base_features: impl Iterator<Item = &'a str>,
) -> FxHashSet<&'a str> {
// Note: the returned set includes `base_feature`.
pub fn implied_target_features<'a>(&self, base_feature: &'a str) -> FxHashSet<&'a str> {
let implied_features =
self.rust_target_features().iter().map(|(f, _, i)| (f, i)).collect::<FxHashMap<_, _>>();
// implied target features have their own implied target features, so we traverse the
// map until there are no more features to add
// Implied target features have their own implied target features, so we traverse the
// map until there are no more features to add.
let mut features = FxHashSet::default();
let mut new_features = base_features.collect::<Vec<&str>>();
let mut new_features = vec![base_feature];
while let Some(new_feature) = new_features.pop() {
if features.insert(new_feature) {
if let Some(implied_features) = implied_features.get(&new_feature) {