Skip to content

Commit

Permalink
make target_feature cfg computation not iterate over the same vector …
Browse files Browse the repository at this point in the history
…again and again
  • Loading branch information
RalfJung committed Sep 2, 2024
1 parent 648e5e1 commit 191ef36
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub(crate) fn check_tied_features(
/// Used to generate cfg variables and apply features
/// Must express features in the way Rust understands them
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
let mut features = vec![];
let mut features: FxHashSet<Symbol> = Default::default();

// Add base features for the target.
// We do *not* add the -Ctarget-features there, and instead duplicate the logic for that below.
Expand All @@ -306,7 +306,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
// the target CPU, that is still expanded to target features (with all their implied features) by
// LLVM.
let target_machine = create_informational_target_machine(sess, true);
// Compute which of the known target features are enables in the 'base' target machine.
// Compute which of the known target features are enabled in the 'base' target machine.
features.extend(
sess.target
.known_target_features()
Expand Down Expand Up @@ -343,9 +343,12 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
if enabled {
features.extend(sess.target.implied_target_features(std::iter::once(feature)));
} else {
features.retain(|f| {
!sess.target.implied_target_features(std::iter::once(*f)).contains(&feature)
});
// We don't care about the order in `features` since the only thing we use it for is the
// `features.contains` below.
#[allow(rustc::potential_query_instability)]
for feature_to_remove in sess.target.implied_target_features(std::iter::once(feature)) {
features.remove(&feature_to_remove);
}
}
}

Expand Down

0 comments on commit 191ef36

Please sign in to comment.